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
4 changes: 0 additions & 4 deletions schema/app.config.yaml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@
"s3bucket": { "type": "string" },
"events": { "$ref": "#/definitions/events" },
"hostname": { "type": "string" },
"htmlcacheduration": { "type": "number" },
"jscacheduration": { "type": "number" },
"csscacheduration": { "type": "number" },
"imagecacheduration": { "type": "number" },
"hooks": { "$ref": "#/definitions/hooks" },
"web": { "$ref": "#/definitions/web" }
},
Expand Down
24 changes: 9 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,17 @@ const path = require('path')
const yaml = require('js-yaml')
const fs = require('fs-extra')
const aioConfigLoader = require('@adobe/aio-lib-core-config')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-lib-app-config', { provider: 'debug' })
const debugLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-lib-app-config', { provider: 'debug' })
const Ajv = require('ajv')
const ajvAddFormats = require('ajv-formats')

// eslint-disable-next-line node/no-unpublished-require
const schema = require('../schema/app.config.yaml.schema.json')

// give or take daylight savings, and leap seconds ...
const AboutAWeekInSeconds = '604800'
const defaults = {
defaultAppHostname: 'adobeio-static.net',
defaultTvmUrl: 'https://firefly-tvm.adobe.io',
defaultOwApihost: 'https://adobeioruntime.net',
defaultHTMLCacheDuration: '60',
defaultJSCacheDuration: AboutAWeekInSeconds,
defaultCSSCacheDuration: AboutAWeekInSeconds,
defaultImageCacheDuration: AboutAWeekInSeconds,
stageAppHostname: 'dev.runtime.adobe.io',
USER_CONFIG_FILE: 'app.config.yaml',
LEGACY_RUNTIME_MANIFEST: 'manifest.yml',
Expand Down Expand Up @@ -392,7 +386,7 @@ async function legacyToAppConfig (commonConfig) {
if (commonConfig.aio.cna !== undefined || commonConfig.aio.app !== undefined) {
// this might have never have been seen in the wild as we don't know
// what log-level users have set
aioLogger.error('App config in \'.aio\' file is deprecated. Please move your \'.aio.app\' or \'.aio.cna\' to \'app.config.yaml\'.')
console.error('Warning: [@adobe/aio-cli-lib-app-config] App config in \'.aio\' file is deprecated. Please move your \'.aio.app\' or \'.aio.cna\' to \'app.config.yaml\'.')
const appConfig = { ...commonConfig.aio.app, ...commonConfig.aio.cna }
Object.entries(appConfig).forEach(([k, v]) => {
legacyAppConfig[k] = v
Expand Down Expand Up @@ -434,7 +428,7 @@ async function legacyToAppConfig (commonConfig) {

// todo: new val usingLegacyHooks:Boolean
if (Object.keys(hooks).length > 0) {
aioLogger.error('hooks in \'package.json\' are deprecated. Please move your hooks to \'app.config.yaml\' under the \'hooks\' key')
console.error('Warning: [@adobe/aio-cli-lib-app-config] hooks in \'package.json\' are deprecated. Please move your hooks to \'app.config.yaml\' under the \'hooks\' key')
legacyAppConfig.hooks = hooks
// build index
includeIndex[`${defaults.APPLICATION_CONFIG_KEY}.hooks`] = { file: 'package.json', key: 'scripts' }
Expand Down Expand Up @@ -507,7 +501,7 @@ async function mergeLegacyAppConfig (appConfigWithIncludeIndex, legacyAppConfigW
if (application && legacyApplication) {
// for simplicity runtimeManifest is not merged, it's one or the other
if (legacyApplication.runtimeManifest && application.runtimeManifest) {
aioLogger.warn('\'manifest.yml\' is ignored in favor of key \'runtimeManifest\' in \'app.config.yaml\'.')
console.error('Warning: [@adobe/aio-cli-lib-app-config] \'manifest.yml\' is ignored in favor of key \'runtimeManifest\' in \'app.config.yaml\'.')
}
// hooks are merged
if (legacyApplication.hooks && application.hooks) {
Expand Down Expand Up @@ -586,6 +580,10 @@ async function buildSingleConfig (configName, singleUserConfig, commonConfig, in
name: configName
}

if (singleUserConfig.htmlCacheDuration || singleUserConfig.jsCacheDuration || singleUserConfig.cssCacheDuration || singleUserConfig.imageCacheDuration) {
console.error('Warning: [@adobe/aio-cli-lib-app-config] htmlCacheDuration, jsCacheDuration, cssCacheDuration, and imageCacheDuration are ignored. Please use cache-control response-headers instead.')
}

if (!includeIndex[fullKeyPrefix]) {
// config does not exist, return empty config
return config
Expand Down Expand Up @@ -650,7 +648,7 @@ async function buildSingleConfig (configName, singleUserConfig, commonConfig, in
config.manifest.packagePlaceholder = '__APP_PACKAGE__'
config.manifest.package = config.manifest.full.packages && config.manifest.full.packages[config.manifest.packagePlaceholder]
if (config.manifest.package) {
aioLogger.debug(`Use of ${config.manifest.packagePlaceholder} in manifest.yml.`)
debugLogger.debug(`Use of ${config.manifest.packagePlaceholder} in manifest.yml.`)
}
// Note: we should set the config.manifest.package also if it's not using a placeholder
}
Expand Down Expand Up @@ -688,10 +686,6 @@ async function buildSingleConfig (configName, singleUserConfig, commonConfig, in

config.app.defaultHostname = getCliEnv() === STAGE_ENV ? defaults.stageAppHostname : defaults.defaultAppHostname
config.app.hostname = singleUserConfig.hostname || config.app.defaultHostname
config.app.htmlCacheDuration = singleUserConfig.htmlcacheduration || defaults.defaultHTMLCacheDuration
config.app.jsCacheDuration = singleUserConfig.jscacheduration || defaults.defaultJSCacheDuration
config.app.cssCacheDuration = singleUserConfig.csscacheduration || defaults.defaultCSSCacheDuration
config.app.imageCacheDuration = singleUserConfig.imagecacheduration || defaults.defaultImageCacheDuration
config.hooks = singleUserConfig.hooks || {}

config.imsOrgId = commonConfig.imsOrgId
Expand Down
24 changes: 4 additions & 20 deletions test/data-mocks/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,7 @@ const excSingleConfig = {
hasFrontend: true,
dist: winCompat(`${root}dist/dx-excshell-1`),
defaultHostname: 'adobeio-static.net',
hostname: 'adobeio-static.net',
htmlCacheDuration: '60',
jsCacheDuration: '604800',
cssCacheDuration: '604800',
imageCacheDuration: '604800'
hostname: 'adobeio-static.net'
},
ow,
s3: {
Expand Down Expand Up @@ -196,11 +192,7 @@ const nuiSingleConfig = {
hasFrontend: false,
dist: winCompat(`${root}dist/dx-asset-compute-worker-1`),
defaultHostname: 'adobeio-static.net',
hostname: 'adobeio-static.net',
htmlCacheDuration: '60',
jsCacheDuration: '604800',
cssCacheDuration: '604800',
imageCacheDuration: '604800'
hostname: 'adobeio-static.net'
},
ow,
s3: {},
Expand Down Expand Up @@ -245,11 +237,7 @@ const applicationSingleConfig = {
hasFrontend: true,
dist: winCompat(`${root}dist/application`),
defaultHostname: 'adobeio-static.net',
hostname: 'adobeio-static.net',
htmlCacheDuration: '60',
jsCacheDuration: '604800',
cssCacheDuration: '604800',
imageCacheDuration: '604800'
hostname: 'adobeio-static.net'
},
ow,
s3: {
Expand Down Expand Up @@ -303,11 +291,7 @@ const applicationNoActionsSingleConfig = {
hasFrontend: true,
dist: winCompat(`${root}dist/application`),
defaultHostname: 'adobeio-static.net',
hostname: 'adobeio-static.net',
htmlCacheDuration: '60',
jsCacheDuration: '604800',
cssCacheDuration: '604800',
imageCacheDuration: '604800'
hostname: 'adobeio-static.net'
},
ow,
s3: {
Expand Down
20 changes: 20 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,26 @@ application:
expect(config.all.application.web['response-headers']).toEqual({ '/*': { testHeader: 'foo' } })
})

test('deprecated cache duration config triggers warning', async () => {
global.fakeFileSystem.addJson(
{
'/package.json': '{}',
'/app.config.yaml': `
application:
htmlCacheDuration: 60000
jsCacheDuration: 60000
cssCacheDuration: 60000
imageCacheDuration: 60000
runtimeManifest:
packages: {}
`
}
)
config = await appConfig.load({})
// The deprecated config should still be processed but a warning should be logged
expect(config.all.application).toBeDefined()
})

test('valid configSchema with two fields', async () => {
global.fakeFileSystem.addJson(
{
Expand Down
7 changes: 0 additions & 7 deletions test/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,6 @@ global.fakeConfig = {
awsaccesskeyid: 'fakeAwsKeyId',
awssecretaccesskey: 'fakeAwsSecretKey'
}
},
// todo delete those should not be passed via aio now
app: {
htmlCacheDuration: 60,
jsCacheDuration: 604800,
cssCacheDuration: 604800,
imageCacheDuration: 604800
}
}

Expand Down