Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/commands/app/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { Flags } = require('@oclif/core')
const { runInProcess, writeConfig } = require('../../lib/app-helper')
const RuntimeLib = require('@adobe/aio-lib-runtime')
const { bundle } = require('@adobe/aio-lib-web')
const coreConfig = require('@adobe/aio-lib-core-config')
const fs = require('fs-extra')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:build', { provider: 'debug' })

Expand Down Expand Up @@ -68,6 +69,7 @@ class Build extends BaseCommand {
} catch (err) {
this.log(err)
}
coreConfig.reload()

if (flags.actions) {
// removed flags['force-build'] || as it is always forced at this point, we need to check to decide what to build
Expand Down Expand Up @@ -117,7 +119,7 @@ class Build extends BaseCommand {
const bundleOptions = {
shouldDisableCache: true,
shouldContentHash: flags['content-hash'],
shouldOptimize: flags['web-optimize'],
shouldOptimize: flags['web-optimize'] ?? process.env.NODE_ENV === 'production',
logLevel: flags.verbose ? 'verbose' : 'warn'
}
// empty the dist folder to prevent an S3 explosion
Expand Down Expand Up @@ -179,8 +181,8 @@ Build.flags = {
allowNo: true
}),
'web-optimize': Flags.boolean({
description: '[default: false] Enable optimization (minification) of js/css/html',
default: false
description: '[default: true if NODE_ENV=production, false otherwise] Enable optimization (minification) of js/css/html',
allowNo: true
}),
extension: Flags.string({
description: 'Build only a specific extension point, the flags can be specified multiple times',
Expand Down
5 changes: 3 additions & 2 deletions src/commands/app/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class Deploy extends BuildCommand {
} catch (err) {
this.error(err)
}
aioConfigLoader.reload()

// provision database if configured
if (config.manifest?.full?.database?.['auto-provision'] === true) {
Expand Down Expand Up @@ -487,8 +488,8 @@ Deploy.flags = {
exclusive: ['action', 'publish'] // no-publish is excluded
}),
'web-optimize': Flags.boolean({
description: '[default: false] Enable optimization (minification) of web js/css/html',
default: false
description: '[default: true if NODE_ENV=production, false otherwise] Enable optimization (minification) of web js/css/html',
allowNo: true
}),
'log-forwarding-update': Flags.boolean({
description: '[default: true] Update log forwarding configuration on server',
Expand Down
1 change: 1 addition & 0 deletions src/commands/app/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Run extends BaseCommand {
} catch (err) {
this.log(err)
}
coreConfig.reload()

// check if there are certificates available, and generate them if not ...
// only care about certificates if the application has a UI
Expand Down
2 changes: 2 additions & 0 deletions src/commands/app/undeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const BaseCommand = require('../../BaseCommand')
const webLib = require('@adobe/aio-lib-web')
const { runInProcess, buildExtensionPointPayloadWoMetadata } = require('../../lib/app-helper')
const rtLib = require('@adobe/aio-lib-runtime')
const coreConfig = require('@adobe/aio-lib-core-config')
const { sendAppAssetsUndeployedAuditLog, sendAppUndeployAuditLog } = require('../../lib/audit-logger')
const { setRuntimeApiHostAndAuthHandler, getAccessToken } = require('../../lib/auth-helper')

Expand Down Expand Up @@ -136,6 +137,7 @@ class Undeploy extends BaseCommand {
} catch (err) {
this.log(err)
}
coreConfig.reload()

if (flags.actions) {
if (config.app.hasBackend) {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/build-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ governing permissions and limitations under the License.

const { runInProcess } = require('./app-helper')
const { buildActions } = require('@adobe/aio-lib-runtime')
const coreConfig = require('@adobe/aio-lib-core-config')

/**
* Builds actions.
Expand All @@ -22,6 +23,7 @@ const { buildActions } = require('@adobe/aio-lib-runtime')
*/
module.exports = async (config, filterActions, forceBuild = false) => {
await runInProcess(config.hooks['pre-app-build'], config)
coreConfig.reload()
const script = await runInProcess(config.hooks['build-actions'], { config, options: { filterActions, forceBuild } })
if (!script) {
await buildActions(config, filterActions, forceBuild)
Expand Down
2 changes: 2 additions & 0 deletions src/lib/deploy-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ governing permissions and limitations under the License.
const { runInProcess } = require('./app-helper')
const { deployActions } = require('@adobe/aio-lib-runtime')
const logActions = require('./log-actions')
const coreConfig = require('@adobe/aio-lib-core-config')

/**
* Deploys actions.
Expand All @@ -31,6 +32,7 @@ module.exports = async ({
inprocHook
}) => {
await runInProcess(config.hooks['pre-app-deploy'], config)
coreConfig.reload()

const hookFilterEntities = Array.isArray(deployConfig.filterEntities?.actions) ? deployConfig.filterEntities.actions : []
const hookData = {
Expand Down
32 changes: 32 additions & 0 deletions test/commands/app/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,38 @@ describe('run', () => {
expect(mockBundleFunc).toHaveBeenCalledTimes(1)
})

test('reloads config after pre-app-build and before building', async () => {
const mockConfig = require('@adobe/aio-lib-core-config')
mockConfig.reload.mockClear()
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))

await command.run()
expect(mockConfig.reload).toHaveBeenCalledTimes(1)
expect(helpers.runInProcess.mock.invocationCallOrder[0]).toBeLessThan(mockConfig.reload.mock.invocationCallOrder[0])
expect(mockConfig.reload.mock.invocationCallOrder[0]).toBeLessThan(mockRuntimeLib.buildActions.mock.invocationCallOrder[0])
})

test.each([
[[], 'production', true],
[[], 'development', false],
[[], undefined, false],
[['--web-optimize'], undefined, true],
[['--no-web-optimize'], 'production', false]
])('web-optimize %j with NODE_ENV=%s optimizes: %s', async (argv, nodeEnv, expected) => {
const originalNodeEnv = process.env.NODE_ENV
if (nodeEnv) process.env.NODE_ENV = nodeEnv
else delete process.env.NODE_ENV
try {
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
command.argv = argv
await command.run()
expect(mockWebLib.bundle).toHaveBeenCalledWith(expect.any(String), expect.any(String),
expect.objectContaining({ shouldOptimize: expected }), expect.any(Function))
} finally {
process.env.NODE_ENV = originalNodeEnv
}
})

test('build & deploy an App with --no-content-hash', async () => {
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))

Expand Down
13 changes: 7 additions & 6 deletions test/commands/app/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,12 @@ describe('run', () => {
command.argv = ['--no-web-assets']
await command.run()

expect(mockConfig.reload).toHaveBeenCalledTimes(1)
const reloadOrder = mockConfig.reload.mock.invocationCallOrder
expect(mockRuntimeLib.deployActions).toHaveBeenCalledTimes(1)
expect(mockConfig.reload.mock.invocationCallOrder[0]).toBeLessThan(
// reloaded after pre-app-deploy and again just before deploying actions
expect(reloadOrder.length).toBeGreaterThanOrEqual(2)
expect(helpers.runInProcess.mock.invocationCallOrder[0]).toBeLessThan(reloadOrder[0])
expect(reloadOrder[reloadOrder.length - 1]).toBeLessThan(
mockRuntimeLib.deployActions.mock.invocationCallOrder[0]
)
})
Expand Down Expand Up @@ -1368,8 +1371,7 @@ describe('run', () => {
'log-forwarding-update': true,
open: false,
publish: false,
'web-assets': true,
'web-optimize': false
'web-assets': true
},
env: mockEnv,
opItems: [
Expand Down Expand Up @@ -1492,8 +1494,7 @@ describe('run', () => {
'log-forwarding-update': true,
open: false,
publish: false,
'web-assets': true,
'web-optimize': false
'web-assets': true
},
env: mockEnv,
opItems: [
Expand Down
17 changes: 17 additions & 0 deletions test/commands/app/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,21 @@ describe('run', () => {
expect(scriptSequence[0]).toEqual('pre-app-run')
expect(scriptSequence[1]).toEqual('post-app-run')
})

test('reloads config after pre-app-run and before starting the dev environment', async () => {
mockFSExists([PRIVATE_KEY_PATH, PUB_CERT_PATH])
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))

command.argv = []
await command.run()

expect(mockConfig.reload).toHaveBeenCalledTimes(1)
expect(mockRunDev).toHaveBeenCalledTimes(1)
expect(helpers.runInProcess.mock.invocationCallOrder[0]).toBeLessThan(
mockConfig.reload.mock.invocationCallOrder[0]
)
expect(mockConfig.reload.mock.invocationCallOrder[0]).toBeLessThan(
mockRunDev.mock.invocationCallOrder[0]
)
})
})
10 changes: 10 additions & 0 deletions test/commands/app/undeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ describe('run', () => {
expect(mockWebLib.undeployWeb).toHaveBeenCalledTimes(1)
})

test('reloads config after pre-app-undeploy and before undeploying', async () => {
const mockConfig = require('@adobe/aio-lib-core-config')
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig())

await command.run()
expect(mockConfig.reload).toHaveBeenCalledTimes(1)
expect(helpers.runInProcess.mock.invocationCallOrder[0]).toBeLessThan(mockConfig.reload.mock.invocationCallOrder[0])
expect(mockConfig.reload.mock.invocationCallOrder[0]).toBeLessThan(mockRuntimeLib.undeployActions.mock.invocationCallOrder[0])
})

test('undeploy an App with no flags with hooks', async () => {
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig())
__setupMockHooks()
Expand Down
10 changes: 10 additions & 0 deletions test/commands/lib/build-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ beforeEach(() => {
utils.runInProcess.mockReset()
})

test('reloads config after pre-app-build', async () => {
const coreConfig = require('@adobe/aio-lib-core-config')
coreConfig.reload.mockClear()
utils.runInProcess.mockImplementation(script => script === 'build-actions' ? {} : undefined)
await buildActions(extensionConfig)
expect(coreConfig.reload).toHaveBeenCalledTimes(1)
expect(utils.runInProcess.mock.invocationCallOrder[0]).toBeLessThan(coreConfig.reload.mock.invocationCallOrder[0])
expect(coreConfig.reload.mock.invocationCallOrder[0]).toBeLessThan(utils.runInProcess.mock.invocationCallOrder[1])
})

test('exports', () => {
expect(typeof buildActions).toEqual('function')
})
Expand Down
9 changes: 9 additions & 0 deletions test/commands/lib/deploy-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ test('exports', () => {
expect(typeof deployActions).toEqual('function')
})

test('reloads config after pre-app-deploy', async () => {
const coreConfig = require('@adobe/aio-lib-core-config')
coreConfig.reload.mockClear()
await deployActions({ config: { hooks: {} } })
expect(coreConfig.reload).toHaveBeenCalledTimes(1)
expect(utils.runInProcess.mock.invocationCallOrder[0]).toBeLessThan(coreConfig.reload.mock.invocationCallOrder[0])
expect(coreConfig.reload.mock.invocationCallOrder[0]).toBeLessThan(rtDeployActions.mock.invocationCallOrder[0])
})

test('deploy-actions app hook available', async () => {
utils.runInProcess.mockImplementation(script => {
if (script === 'deploy-actions') {
Expand Down
Loading