diff --git a/schema/app.config.yaml.schema.json b/schema/app.config.yaml.schema.json index 4b764b5..092c543 100644 --- a/schema/app.config.yaml.schema.json +++ b/schema/app.config.yaml.schema.json @@ -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" } }, diff --git a/src/index.js b/src/index.js index 40b98cd..aa0c775 100644 --- a/src/index.js +++ b/src/index.js @@ -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', @@ -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 @@ -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' } @@ -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) { @@ -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 @@ -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 } @@ -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 diff --git a/test/data-mocks/config-loader.js b/test/data-mocks/config-loader.js index 6eb135c..ccc76d8 100644 --- a/test/data-mocks/config-loader.js +++ b/test/data-mocks/config-loader.js @@ -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: { @@ -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: {}, @@ -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: { @@ -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: { diff --git a/test/index.test.js b/test/index.test.js index 116ca01..95df47d 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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( { diff --git a/test/jest.setup.js b/test/jest.setup.js index 64ceb18..22ea6fb 100644 --- a/test/jest.setup.js +++ b/test/jest.setup.js @@ -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 } }