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

Commit

Permalink
Merge branch 'main' into fix/externals-esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
dogpatch626 authored Sep 15, 2023
2 parents a8be702 + cd83ead commit a22bc5b
Show file tree
Hide file tree
Showing 129 changed files with 2,051 additions and 353 deletions.
2 changes: 2 additions & 0 deletions jest.esm.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ module.exports = {
'!**/node_modules/**',
'!**/build/**',
'!packages/*/test-results/**',
'!packages/*/jest.esm.setup.js',
// Despite it not being in the root, coverage reports see this package
'!packages/one-app-locale-bundler/**',
'!packages/one-app-dev-bundler/index.js',
],
roots: [
'packages/one-app-dev-bundler',
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"cross-env": "^7.0.2",
"enzyme": "^3.11.0",
"enzyme-to-json": "^3.2.2",
"eslint": "8",
"eslint": "8.29.0",
"eslint-config-amex": "^15.2.1",
"eslint-plugin-jest": "^25.3.4",
"eslint-plugin-jest-dom": "^4.0.1",
Expand All @@ -52,4 +52,4 @@
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
}
11 changes: 11 additions & 0 deletions packages/holocron-dev-server/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [0.2.0](https://github.com/americanexpress/one-app-cli/compare/@americanexpress/[email protected]...@americanexpress/[email protected]) (2023-09-14)


### Features

* external fallbacks ([#536](https://github.com/americanexpress/one-app-cli/issues/536)) ([523898d](https://github.com/americanexpress/one-app-cli/commit/523898deb9a1a4bcce6ba43915c852b02b7bb3a5))





## [0.1.14](https://github.com/americanexpress/one-app-cli/compare/@americanexpress/[email protected]...@americanexpress/[email protected]) (2023-06-13)

**Note:** Version bump only for package @americanexpress/holocron-dev-server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import parrot from 'parrot-middleware';

import createMocksMiddleware, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import {
loadLanguagePacks,
loadModuleLanguagePack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import { modulesBundleName } from '../../../src/constants';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';

import {
createResolverConfigFragment,
Expand Down
4 changes: 2 additions & 2 deletions packages/holocron-dev-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@americanexpress/holocron-dev-server",
"version": "0.1.14",
"version": "0.2.0",
"description": "A micro-frontend dev server for Holocron Modules",
"license": "Apache-2.0",
"keywords": [
Expand Down Expand Up @@ -38,7 +38,7 @@
"module": "src/index.js",
"dependencies": {
"@americanexpress/fetch-enhancers": "^1.0.3",
"@americanexpress/one-app-bundler": "^6.20.0",
"@americanexpress/one-app-bundler": "^6.21.0",
"@americanexpress/one-app-ducks": "^4.1.1",
"@americanexpress/one-app-router": "^1.1.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.0-beta.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import express from 'express';
import parrot from 'parrot-middleware';

Expand Down
2 changes: 1 addition & 1 deletion packages/holocron-dev-server/src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import readPkgUp from 'read-pkg-up';

import { defaultLogLevel, errorReportingUrlFragment, oneAppDockerImageName } from '../constants';
Expand Down
2 changes: 1 addition & 1 deletion packages/holocron-dev-server/src/utils/language-packs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import jsonParse from 'json-parse-context';

import { volume, ufs } from './virtual-file-system';
Expand Down
2 changes: 1 addition & 1 deletion packages/holocron-dev-server/src/utils/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';

import { modulesBundleName } from '../constants';

Expand Down
2 changes: 1 addition & 1 deletion packages/holocron-dev-server/src/utils/statics.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import { execSync, execFileSync, spawnSync } from 'child_process';

import { ufs } from './virtual-file-system';
Expand Down
4 changes: 2 additions & 2 deletions packages/holocron-dev-server/src/utils/virtual-file-system.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* under the License.
*/

import fs from 'fs';
import path from 'path';
import fs from 'node:fs';
import path from 'node:path';
import { Union } from 'unionfs';
import { Volume, createFsFromVolume } from 'memfs';

Expand Down
2 changes: 1 addition & 1 deletion packages/holocron-dev-server/src/utils/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import chokidar from 'chokidar';

import { logLocaleAction, logLocaleModuleNamesBeingWatched, warnOnLocaleWatchError } from './logs';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* under the License.
*/

import path from 'path';
import path from 'node:path';
import merge from 'webpack-merge';

import {
Expand Down
11 changes: 11 additions & 0 deletions packages/one-app-bundler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

# [6.21.0](https://github.com/americanexpress/one-app-cli/compare/@americanexpress/[email protected]...@americanexpress/[email protected]) (2023-09-14)


### Features

* external fallbacks ([#536](https://github.com/americanexpress/one-app-cli/issues/536)) ([523898d](https://github.com/americanexpress/one-app-cli/commit/523898deb9a1a4bcce6ba43915c852b02b7bb3a5))





# [6.20.0](https://github.com/americanexpress/one-app-cli/compare/@americanexpress/[email protected]...@americanexpress/[email protected]) (2023-06-13)


Expand Down
64 changes: 57 additions & 7 deletions packages/one-app-bundler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,40 @@ In order to avoid duplicate code in your One App instance, you may want to
share a dependency across all your modules that is not already provided by One
App. These dependencies can be provided to your modules by your root
module. The root module should include in its configuration
`providedExternals`, which is an array of external dependencies to be bundled
with it and provided to other modules.
`providedExternals`. This will include and make the listed dependencies
available to be consumed by child modules. Child modules will use `requiredExternals`
to consume dependencies provided by the root modules `providedExternals`, this will also remove
the dependency from the child modules bundle.

Modules shouldn't configure both `providedExternals` and `requiredExternals`.
Remember `providedExternals` are dependencies which your root module will make available to child modules. `requiredExternals` are a list of dependencies the child module will need to be made available by the root module.
Remember `providedExternals` are dependencies which your root module will make available to child modules.
`requiredExternals` are a list of dependencies the child module will need to be made available by the root module.

All modules `requiredExternals` are validated at runtime against the root modules list of `providedExternals`. If the external dependency is not provided One App will throw an error. This will either result in the One App server not starting or, if it is already running, One App will not load that module. For example, if your child module requires `^2.1.0` of a dependency but your root module provides `2.0.0`, this will result in One App not loading that child module as the provided dependencies version does not satisfy the required semantic range.
All modules `requiredExternals` are validated at runtime against the root modules list of `providedExternals`.
By default if the external dependency is not provided One App will throw an error. This will either result in the
One App server not starting or, if it is already running, One App will not load that module. For example, if your
child module requires `^2.1.0` of a dependency but your root module provides `2.0.0`, this will result in One App
not loading that child module as the provided dependencies version does not satisfy the required semantic range.

This ensures that all of the listed dependencies features potentially required by the child module to work will be provided which could result in hard to debug bugs.
This ensures that all of the listed dependencies features, potentially required by the child module to work, will be provided which could result in hard to debug bugs.

If you attempt to include one of the [dependencies](https://github.com/americanexpress/one-app-cli/blob/main/packages/one-app-bundler/webpack/webpack.common.js#L102-L155) provided by One App in your `providedExternals` or `requiredExternals`, your build will fail.


##### Externals Fallbacks

External fallbacks were added to help reduce the impact of some of the cons listed below.
For each dependency listed in `requiredExternals` fallback bundles(browser and server) will
be created. If the root module permits these fallbacks will be used to enable that child
module to load when there is no valid provided external dependency. This can be helpful when
transitioning between major versions of a externals dependency.

To enable fallbacks the root module will need to set the `fallbackEnabled` option to `true` for each
provided external and the `enableUnlistedExternalFallbacks` to allow fallbacks for unlisted
dependencies.

##### Usage

First make sure to add your dependency to your module's `package.json`:

```bash
Expand All @@ -137,7 +159,14 @@ Then configure `one-app-bundler` to provide that dependency (and any others) as
{
"one-amex": {
"bundler": {
"providedExternals": ["some-dependency", "another-dependency"]
"providedExternals": {
"some-dependency": {
"fallbackEnabled": true
},
"another-dependency": {
"fallbackEnabled": false
}
}
}
}
}
Expand Down Expand Up @@ -179,6 +208,24 @@ npm install some-dependency
* Couples your child and root module together
* Increases complexity when managing updates to the provided and required dependency


#### `enableUnlistedExternalFallbacks`

To allow child modules to load when a `requiredExternal` is not listed as a `providedExternal` use the `enableUnlistedExternalFallbacks` option.
The child module must provide a fallback bundle for the missing required external to load when this option is set.

`enableUnlistedExternalFallbacks` defaults to false if unset.

```json
{
"one-amex": {
"bundler": {
"enableUnlistedExternalFallbacks": true
}
}
}
```

#### `performanceBudget`

Set a custom [performance budget](https://webpack.js.org/configuration/performance/#performancemaxassetsize)
Expand Down Expand Up @@ -326,7 +373,7 @@ before enabling any of the following:
#### Legacy browser support

`disableDevelopmentLegacyBundle` can be added to your bundler config and set to *true* to opt out of bundling the `legacy` assets. This will reduce bundle size and build times. This is only configured to be removed when in `development`. `production` builds will not skip the `legacy` build.
**Caution as this will remove legacy browser support from your module.**
**Caution as this will remove legacy browser support from your module.**

```json
{
Expand All @@ -337,6 +384,9 @@ before enabling any of the following:
}
}
```
### TypeScript

TypeScript in One App modules needs no extra configuration within `one-app-bundler` to work. `one-app-bundler` is set up to ignore `TypeScript` features leaving `tsc` to focus on typechecking only.

#### Specify what version of One App your module is compatible with

Expand Down
77 changes: 77 additions & 0 deletions packages/one-app-bundler/__mocks__/node:fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2019 American Express Travel Related Services Company, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations
* under the License.
*/

let files = {};

const fs = {
_: {
setFiles: (configuredFiles) => {
files = configuredFiles || {};
},

getFiles: () => files,
},

accessSync: jest.fn((filePath) => {
if (!files[filePath]) {
throw new Error(`Couldn't access file ${filePath}`);
}
}),

readFileSync: jest.fn((filePath) => {
if (!files[filePath]) {
throw new Error(`Couldn't read file ${filePath}`);
}
return files[filePath];
}),

readFile: jest.fn((filePath, cb) => {
if (!files[filePath]) {
cb(new Error(`Couldn't read file ${filePath}`));
} else {
cb(undefined, files[filePath]);
}
}),

writeFileSync: jest.fn((filePath, content) => {
files[filePath] = content;
}),

rmdirSync: jest.fn((dirPath) => {
if (!files[dirPath]) {
throw new Error(`Couldn't delete dir ${dirPath}`);
}
delete files[dirPath];
}),

mkdirSync: jest.fn(),

symlinkSync: jest.fn(),

unlinkSync: jest.fn(),

closeSync: jest.fn(),

stat: jest.fn(),

statSync: jest.fn(),

readlink: jest.fn(),

readlinkSync: jest.fn(),

readdirSync: jest.fn(),
};

module.exports = fs;
Loading

0 comments on commit a22bc5b

Please sign in to comment.