Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
feat(externals): added flag to not throw if externals versions have a…
Browse files Browse the repository at this point in the history
… mismatch (#591)
  • Loading branch information
Matthew-Mallimo authored Oct 23, 2021
1 parent d2f9d5c commit 232d83e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
14 changes: 14 additions & 0 deletions __tests__/server/utils/onModuleLoad.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
26 changes: 26 additions & 0 deletions docs/api/server/Environment-Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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**
Expand Down
7 changes: 6 additions & 1 deletion src/server/utils/onModuleLoad.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});

Expand Down

0 comments on commit 232d83e

Please sign in to comment.