diff --git a/__tests__/server/utils/onModuleLoad.spec.jsx b/__tests__/server/utils/onModuleLoad.spec.jsx index b0d34ee2..fc445d82 100644 --- a/__tests__/server/utils/onModuleLoad.spec.jsx +++ b/__tests__/server/utils/onModuleLoad.spec.jsx @@ -253,6 +253,20 @@ describe('onModuleLoad', () => { expect(() => onModuleLoad({ module: { [CONFIGURATION_KEY]: configuration, [META_DATA_KEY]: { version: '1.0.11' } }, moduleName: 'my-awesome-module' })).toThrowErrorMatchingSnapshot(); }); + it('logs a warning if the root module provides an incompatible version of a required external and ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS is set to true', () => { + process.env.ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS = true; + RootModule[CONFIGURATION_KEY].providedExternals = { + 'dep-a': { version: '2.1.0', module: () => 0 }, + }; + const configuration = { + requiredExternals: { + 'dep-a': '^2.1.1', + }, + }; + expect(() => onModuleLoad({ module: { [CONFIGURATION_KEY]: configuration, [META_DATA_KEY]: { version: '1.0.10' } }, moduleName: 'my-awesome-module' })).not.toThrow(); + expect(consoleWarnSpy).toHaveBeenCalledTimes(1); + }); + it('keeps track of the externals a module is using', () => { RootModule[CONFIGURATION_KEY] = { providedExternals: { diff --git a/docs/api/server/Environment-Variables.md b/docs/api/server/Environment-Variables.md index e334bc06..a5780ad3 100644 --- a/docs/api/server/Environment-Variables.md +++ b/docs/api/server/Environment-Variables.md @@ -33,6 +33,7 @@ One App can be configured via Environment Variables: * [`NODE_ENV`](#node_env) ⚠️ * [`ONE_CLIENT_ROOT_MODULE_NAME`](#one_client_root_module_name) ⚠️ * [`ONE_CONFIG_ENV`](#one_config_env) ⚠️ + * [`ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS`](#ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS) * Server Settings * [`HOLOCRON_SERVER_MAX_MODULES_RETRY`](#holocron_server_max_modules_retry) * [`HOLOCRON_SERVER_MAX_SIM_MODULES_FETCH`](#holocron_server_max_sim_modules_fetch) @@ -510,6 +511,31 @@ ONE_CONFIG_ENV=staging ONE_CONFIG_ENV=undefined ``` +## `ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS` + +**Runs In** +* ✅ Production +* ✅ Development + +If set to `true`, one-app will not throw an error when externals provided by the root module and externals required by child modules have conflicting semver ranges. +This flag is meant to ease the transition to newer versions of externals. It should not be kept on for long as mismatching versions of packages can cause unexpected issues. + +**Shape** +```bash +ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS=true +``` + +**Example** +```bash +ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS=true +``` + +**Default Value** +```bash +ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS=undefined +``` + + ## `ONE_ENABLE_POST_TO_MODULE_ROUTES` **Runs In** diff --git a/src/server/utils/onModuleLoad.js b/src/server/utils/onModuleLoad.js index 46a1a0c6..fafd72d9 100644 --- a/src/server/utils/onModuleLoad.js +++ b/src/server/utils/onModuleLoad.js @@ -147,7 +147,12 @@ export default function onModuleLoad({ if (!providedExternal) { messages.push(`External '${externalName}' is required by ${moduleName}, but is not provided by the root module`); } else if (!semver.satisfies(providedExternal.version, requestedExternalVersion)) { - messages.push(`${externalName}@${requestedExternalVersion} is required by ${moduleName}, but the root module provides ${providedExternal.version}`); + const failedExternalMessage = `${externalName}@${requestedExternalVersion} is required by ${moduleName}, but the root module provides ${providedExternal.version}`; + if (process.env.ONE_DANGEROUSLY_ACCEPT_BREAKING_EXTERNALS) { + console.warn(failedExternalMessage); + } else { + messages.push(failedExternalMessage); + } } });