Skip to content

Commit d4e3caf

Browse files
Node 16 upgrade and peer dependency cleanup (#250)
* feat: drop support for Node 12 and add support for Node 16 BREAKING CHANGE: The Open edX platform is collectively moving towards Node 16. By doing so in this repository, we can now use NPM workspaces in place of Lerna in many places. Lerna is still used for publishing to NPM, updating CHANGELOGs and package.json files upon released. But NPM workspace commands can now be used instead of Lerna commands for the developer experience, which is more performant, easier to reason about, and natively supported by NPM.
1 parent 938dfdc commit d4e3caf

26 files changed

Lines changed: 89545 additions & 60327 deletions

.github/workflows/bump-all-major.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Nodejs
1919
uses: actions/setup-node@v1
2020
with:
21-
node-version: 12
21+
node-version: 16
2222
# lerna expects to be authenticated for publishing to NPM. This step will fail CI if NPM is not authenticated
2323
- name: Check NPM authentication
2424
run: |
@@ -35,7 +35,7 @@ jobs:
3535
run: npm run test
3636
- name: Coverage Report
3737
uses: codecov/codecov-action@v1
38-
- name:
38+
- name: Force publish major versions
3939
run: lerna version major --force-publish --yes
4040
env:
4141
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/ci.yml

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
11
name: CI
22

3-
on: [push]
3+
on: [pull_request]
44

55
jobs:
6-
build:
6+
tests:
77
name: Build
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Checkout
11-
uses: actions/checkout@v2
12-
with:
13-
# pulls all commits (needed for lerna / semantic release to correctly version)
14-
fetch-depth: 0
15-
# pulls all tags (needed for lerna / semantic release to correctly version)
16-
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
17-
- name: Setup Nodejs
18-
uses: actions/setup-node@v1
19-
with:
20-
node-version: 12
21-
# lerna expects to be authenticated for publishing to NPM. This step will fail CI if NPM is not
22-
# authenticated, even though this build does _not_ attempt to publish, as an extra check before merge
23-
# that Lerna is set to publish.
24-
- name: Check NPM authentication
25-
run: |
26-
echo "//registry.npmjs.org/:_authToken=${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}" >> .npmrc
27-
npm whoami
28-
- name: Install and Setup Dependencies
29-
run: |
30-
npm install
31-
lerna bootstrap --include-dependencies --include-dependents --since origin/master
32-
# build must come before running linting and tests for the `dist` directory to exist.
33-
- name: Build
34-
run: lerna run build --include-dependencies --include-dependents --since origin/master --parallel
35-
- name: Lint
36-
run: lerna run lint --include-dependencies --include-dependents --since origin/master --parallel
37-
- name: Test
38-
run: lerna run test --include-dependencies --include-dependents --since origin/master --parallel
39-
- name: Coverage Report
40-
uses: codecov/codecov-action@v1
41-
- name: Extract branch name
42-
shell: bash
43-
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
44-
id: extract_branch
45-
- name: Preview Updated Versions (dry run)
46-
run: lerna version --allow-branch ${{ steps.extract_branch.outputs.branch }} --no-git-tag-version --no-changelog --no-push --yes
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
with:
13+
# pulls all commits (needed for lerna / semantic release to correctly version)
14+
fetch-depth: 0
15+
# pulls all tags (needed for lerna / semantic release to correctly version)
16+
- name: Pull all tags
17+
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
18+
- name: Setup Nodejs
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: 16
22+
# lerna expects to be authenticated for publishing to NPM. This step will fail CI if NPM is not
23+
# authenticated, even though this build does _not_ attempt to publish, as an extra check before merge
24+
# that Lerna is set to publish.
25+
- name: Check NPM authentication
26+
run: |
27+
echo "//registry.npmjs.org/:_authToken=${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}" >> .npmrc
28+
npm whoami
29+
- name: Install and Setup Dependencies
30+
run: npm run setup
31+
# build must come before running linting and tests for the `dist` directory to exist.
32+
- name: Build
33+
run: npm run build
34+
- name: Lint
35+
run: npm run lint
36+
- name: Test
37+
run: npm run test
38+
- name: Coverage Report
39+
uses: codecov/codecov-action@v2
40+
- name: Preview Updated Versions (dry run)
41+
# switch from detatched head to a real branch so we can pass it to `--allow-branch`
42+
run: |
43+
git switch -c "actual-branch-not-detached-head"
44+
lerna version --allow-branch actual-branch-not-detached-head --no-git-tag-version --no-changelog --no-push --yes

.github/workflows/publish-from-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Nodejs
1919
uses: actions/setup-node@v1
2020
with:
21-
node-version: 12
21+
node-version: 16
2222
# lerna expects to be authenticated for publishing to NPM. This step will fail CI if NPM is not authenticated
2323
- name: Check NPM authentication
2424
run: |

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- name: Setup Nodejs
2222
uses: actions/setup-node@v1
2323
with:
24-
node-version: 12
24+
node-version: 16
2525
# lerna expects to be authenticated for publishing to NPM. This step will fail CI if NPM is not authenticated
2626
- name: Check NPM authentication
2727
run: |

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12
1+
16

README.rst

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ To get started with ``frontend-enterprise`` local development, clone the repo an
1919
::
2020

2121
npm run setup
22-
npm run dev
2322

24-
The above commands will install package dependencies, symlinking local packages rather than installing from NPM directly. However, since (most of) the packages in this monorepo contain a build step for Babel transpilation, it necessary to watch changes in the ``src`` directories of each package to re-run the relevant build script(s) as needed (``npm run dev``).
25-
26-
Each package is configured to only publish the contents of the generated ``dist`` directory to NPM; this behavior gets replicated in the local symlinking of packages as well, which is why it is necessary to watch the source files for changes and re-build the ``dist`` directory when they do change. This ensures the symlinked packages will always contain the correct packages. It is recommended to run ``npm run dev`` in a separate terminal tab or window so you may run other commands as needed while source files are still being watched/transpiled.
23+
The above command will install package dependencies using NPM workspaces, hoisting all packages to `node_modules` at the root of the repository for performance reasons (e.g., there will only be one copy of React). By using NPM workspaces, `npm install` knows that when importing a package that is part of this monorepo (e.g., `@edx/frontend-enterprise-utils`), it should look at the local package folder and creates symlinks accordingly.
2724

2825
Other useful commands for linting and testing may include:
2926

@@ -32,20 +29,18 @@ Other useful commands for linting and testing may include:
3229
npm run lint
3330
npm run test
3431

35-
The above NPM scripts are running Lerna commands behind-the-scenes. By default, it will run the associated NPM command in each package in the monorepo. However, Lerna provides a mechanism to only run tests for a specific package(s), for example:
32+
The above NPM scripts are run via NPM workspaces behind-the-scenes. By default, it will run the associated NPM command in each package in the monorepo. However, NPM workspaces does provide a mechanism to only run tests for a specific package, for example:
3633

3734
::
3835

39-
lerna run test --scope=@edx/frontend-enterprise-catalog-search
36+
npm run test -w @edx/frontend-enterprise-catalog-search
4037

4138
To clean your local monorepo of any installed ``node_modules`` and symlinked packages to start fresh, you may run:
4239

4340
::
4441

4542
npm run clean
4643

47-
See https://github.com/lerna/lerna for full documentation of Lerna commands.
48-
4944
Installing local monorepo package(s) from an edX micro-frontend
5045
-----
5146

@@ -83,9 +78,7 @@ Each package in the monorepo contains its own package.json file and unique set o
8378

8479
To get around this issue of common/shared dependencies, we can rely on how NPM finds installed packages. If a package does not exist in ``node_modules`` for an individual package, NPM will look in ``node_modules`` further up the directory tree until it finds the package, or gets to the root of the repository.
8580

86-
By installing these common dependencies at the root package.json file, they will be accessible to any package in the monorepo to ensure there is only one copy of them used throughout. These dependencies are still noted in each individual package.json file as a peer dependency but not as a dev dependency since they are already installed in ``node_modules`` at the root of the repository.
87-
88-
As such, we should pay extra attention to managing dependencies in each packages, making informed decisions about whether a dependency should be included in an individual package's package.json file or the package.json file at the root of the repository.
81+
NPM workspaces helps with this by hoisting installed packages to the root `node_modules` folder where they will be accessible to any package in the monorepo to ensure there is only one copy used throughout. These dependencies are still noted in each individual package.json file as both a peer dependency and a dev dependency.
8982

9083
Writing a commit
9184
-----
@@ -96,6 +89,8 @@ There is a precommit plugin (commitlint) which requires commit messages formatte
9689

9790
where type must be one of ``[build, ci, docs, feat, fix, perf, refactor, revert, style, test]``
9891

92+
Note: only `fix`, `feat`, and `perf` will trigger a new NPM release, as this is the default behavior for semantic-release.
93+
9994
Versioning and releases
10095
*****
10196

@@ -108,7 +103,7 @@ To publish the packages that had their versions incremented, you must manually t
108103
Preview changed packages in CI with Github Actions
109104
-----
110105

111-
As a convenience, the ``lerna changed`` command is run for each push to determine which packages in the monorepo will be published should a PR get merged.
106+
As a convenience, a dry run of the ``lerna version`` command is run for each push to determine which packages in the monorepo will be published should a PR get merged.
112107

113108
.. |Build Status| image:: https://github.com/edx/frontend-enterprise/actions/workflows/release.yml/badge.svg
114109
:target: https://github.com/edx/frontend-enterprise/actions

common/extendESLintConfig.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const path = require('path');
2+
3+
const extendESLintConfig = (config) => {
4+
const importNoUnresolved = config.rules['import/no-unresolved'];
5+
if (importNoUnresolved ) {
6+
const originalIgnore = importNoUnresolved[1].ignore;
7+
if (!originalIgnore.includes('@edx/frontend-enterprise-*')) {
8+
importNoUnresolved[1].ignore = [...originalIgnore, '@edx/frontend-enterprise-*'];
9+
}
10+
}
11+
};
12+
13+
module.exports = extendESLintConfig;

common/extendJestConfig.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const extendJestConfig = (config) => {
2+
const modulePathsToIgnore = ['<rootDir>/dist'];
3+
config.modulePathIgnorePatterns = config.modulePathIgnorePatterns ? [...config.modulePathIgnorePatterns, ...modulePathsToIgnore] : modulePathsToIgnore;
4+
config.moduleNameMapper = {
5+
...config.moduleNameMapper,
6+
'@edx/frontend-enterprise-(.*)': '<rootDir>/../$1/src',
7+
};
8+
};
9+
10+
module.exports = extendJestConfig;

0 commit comments

Comments
 (0)