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

feat(externals): add flag to not throw if externals semver have mismatch #591

Merged
merged 3 commits into from
Oct 23, 2021
Merged
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
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);
});

Matthew-Mallimo marked this conversation as resolved.
Show resolved Hide resolved
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