Skip to content

Commit 6cd7cb3

Browse files
fix(build): Fix ESM output (#7357) (#7358)
* fix: leave modules untouched in ESM build This prevents Babel from converting the ESM module syntax to CommonJS. * fix: include clearing the Nx cache in the clean script Otherwise a "clean" build will still use old artefacts from the cache. * fix: don't build dependant packages in parallel This ensures that any local dependencies are built first. * fix: don't import from dist/esm Thanks to the other changes in this PR, we can now safely import from the decap-cms-app. * fix(ci): use actions/setup-node cache option This will hopefully fix the error we get on Windows during `npm install` * chore(ci): fix typo and output matrix.node-version * ci: run e2e tests in same container * ci: fail fast to reduce build time and save cpu cycles * ci: run on all branches * ci: set IS_FORK=true if the repo owner is not decaporg * ci: use afterEach hook to fail fast * fix(app): add module field to package.json * fix(app): add missing decap-cms-backend-gitea dependency --------- Co-authored-by: Martin Jagodic <[email protected]>
1 parent b41e43a commit 6cd7cb3

File tree

9 files changed

+49
-77
lines changed

9 files changed

+49
-77
lines changed

.github/workflows/nodejs.yml

+12-50
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Node CI
22

33
on:
44
push:
5-
branches:
6-
- main
75
pull_request:
86
types: [opened, synchronize, reopened]
97

@@ -28,73 +26,37 @@ jobs:
2826
matrix:
2927
os: [macos-latest, windows-latest, ubuntu-latest]
3028
node-version: [18.x, 20.x]
29+
fail-fast: true
3130
if: ${{ needs.changes.outputs.cms == 'true' }}
3231
steps:
3332
- uses: actions/checkout@v3
34-
- name: Use Node.js {{ matrix.node-version }}
33+
- name: Use Node.js ${{ matrix.node-version }}
3534
uses: actions/setup-node@v3
3635
with:
3736
node-version: ${{ matrix.node-version }}
3837
check-latest: true
38+
cache: 'npm'
3939
- name: log versions
4040
run: node --version && npm --version && yarn --version
41-
- name: install dependecies
42-
run: npm install
41+
- name: install dependencies
42+
run: npm ci
4343
- name: run unit tests
4444
run: npm run test:ci
45-
env:
46-
CI: true
47-
NODE_OPTIONS: --max-old-space-size=4096
4845
- name: build demo site
4946
run: npm run build:demo
47+
- name: run e2e tests
48+
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x'
49+
run: npm run test:e2e:run-ci
5050
env:
51-
NODE_OPTIONS: --max-old-space-size=4096
52-
- uses: actions/upload-artifact@master
53-
with:
54-
name: dev-test-website-${{ runner.os }}-${{ matrix.node-version }}
55-
path: dev-test
56-
57-
e2e-with-cypress:
58-
needs: [changes, build]
59-
runs-on: ubuntu-latest
60-
61-
strategy:
62-
matrix:
63-
node-version: [18.x, 20.x]
64-
fail-fast: false
65-
66-
if: ${{ needs.changes.outputs.cms == 'true' }}
67-
steps:
68-
- uses: actions/checkout@v3
69-
- name: Use Node.js
70-
uses: actions/setup-node@v3
71-
with:
72-
node-version: ${{ matrix.node-version }}
73-
check-latest: true
74-
- uses: actions/download-artifact@master
75-
with:
76-
name: dev-test-website-${{ runner.os }}-18.x
77-
path: dev-test
78-
- name: npm install
79-
run: |
80-
node --version
81-
npm --version
82-
yarn --version
83-
npm install
84-
- name: e2e test
85-
run: |
86-
npm run test:e2e:run-ci
87-
env:
88-
IS_FORK: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true }}
51+
IS_FORK: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true || github.repository_owner != 'decaporg' }}
8952
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
9053
NODE_OPTIONS: --max-old-space-size=4096
91-
MACHINE_COUNT: 2
92-
MACHINE_INDEX: ${{ matrix.node-version }}
9354
TZ: Europe/Amsterdam
9455
- uses: actions/upload-artifact@v3
95-
if: ${{ always() }}
56+
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x' && failure()
9657
with:
97-
name: cypress-results-${{ matrix.node-version }}
58+
name: cypress-results
9859
path: |
9960
cypress/screenshots
10061
cypress/videos
62+

babel.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const svgo = {
4242
function presets() {
4343
return [
4444
'@babel/preset-react',
45-
'@babel/preset-env',
45+
['@babel/preset-env', isESM ? { modules: false } : {}],
4646
[
4747
'@emotion/babel-preset-css-prop',
4848
{

cypress/run.mjs

+21-21
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,40 @@ import execa from 'execa';
22
import { globby } from 'globby';
33

44
async function runCypress() {
5+
const args = ['run', '--browser', 'chrome', '--headless'];
6+
7+
const specs = await globby(['cypress/e2e/*spec*.js']);
8+
if (specs.length === 0) {
9+
console.log('No test files found in cypress/e2e/*spec*.js');
10+
process.exit(1);
11+
}
12+
513
if (process.env.IS_FORK === 'true') {
614
const machineIndex = parseInt(process.env.MACHINE_INDEX);
715
const machineCount = parseInt(process.env.MACHINE_COUNT);
8-
const specs = await globby(['cypress/integration/*spec*.js']);
916
const specsPerMachine = Math.floor(specs.length / machineCount);
1017
const start = (machineIndex - 1) * specsPerMachine;
1118
const machineSpecs =
1219
machineIndex === machineCount
1320
? specs.slice(start)
1421
: specs.slice(start, start + specsPerMachine);
1522

16-
await execa(
17-
'cypress',
18-
['run', '--browser', 'chrome', '--headless', '--spec', machineSpecs.join(',')],
19-
{ stdio: 'inherit', preferLocal: true },
20-
);
23+
args.push('--spec', machineSpecs.join(','));
2124
} else {
22-
await execa(
23-
'cypress',
24-
[
25-
'run',
26-
'--browser',
27-
'chrome',
28-
'--headless',
29-
'--record',
30-
'--parallel',
31-
'--ci-build-id',
32-
process.env.GITHUB_SHA,
33-
'--group',
34-
'GitHub CI',
35-
],
36-
{ stdio: 'inherit', preferLocal: true },
25+
args.push(
26+
'--record',
27+
'--parallel',
28+
'--ci-build-id',
29+
process.env.GITHUB_SHA,
30+
'--group',
31+
'GitHub CI',
32+
'--spec',
33+
specs.join(','),
3734
);
3835
}
36+
37+
console.log('Running Cypress with args:', args.join(' '));
38+
await execa('cypress', args, { stdio: 'inherit', preferLocal: true });
3939
}
4040

4141
runCypress();

cypress/support/e2e.js

+6
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ addMatchImageSnapshotCommand({
2626
Cypress.on('uncaught:exception', () => false);
2727

2828
import './commands';
29+
30+
afterEach(function () {
31+
if (this.currentTest.state === 'failed') {
32+
Cypress.runner.stop();
33+
}
34+
});

nx.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{
22
"targetDefaults": {
33
"build:esm": {
4-
"cache": true
4+
"cache": true,
5+
"dependsOn": ["^build:esm"]
56
},
67
"build": {
7-
"cache": true
8+
"cache": true,
9+
"dependsOn": ["^build"]
810
}
911
},
1012
"namedInputs": {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build-preview": "npm run build && nx run decap-cms:build-preview --output-style=stream",
99
"type-check": "tsc --noEmit",
1010
"type-check:watch": "npm run type-check -- --watch",
11-
"clean": "rimraf \"packages/*/dist\" dev-test/dist \"packages/*/node_modules\"",
11+
"clean": "rimraf \"packages/*/dist\" dev-test/dist \"packages/*/node_modules\" \".nx/cache\"",
1212
"reset": "npm run clean",
1313
"test": "npm run lint && npm run type-check && npm run test:unit",
1414
"test:all": "npm run test && npm run test:e2e",

packages/decap-cms-app/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"homepage": "https://www.decapcms.org",
66
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-app",
77
"bugs": "https://github.com/decaporg/decap-cms/issues",
8+
"module": "dist/esm/index.js",
89
"main": "dist/decap-cms-app.js",
910
"files": [
1011
"src/",
@@ -34,6 +35,7 @@
3435
"decap-cms-backend-azure": "^3.1.3",
3536
"decap-cms-backend-bitbucket": "^3.1.4",
3637
"decap-cms-backend-git-gateway": "^3.2.2",
38+
"decap-cms-backend-gitea": "^3.1.5",
3739
"decap-cms-backend-github": "^3.2.2",
3840
"decap-cms-backend-gitlab": "^3.2.2",
3941
"decap-cms-backend-proxy": "^3.1.4",

packages/decap-cms/src/extensions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DecapCmsApp as CMS } from 'decap-cms-app/dist/esm';
1+
import { DecapCmsApp as CMS } from 'decap-cms-app';
22
// Media libraries
33
import uploadcare from 'decap-cms-media-library-uploadcare';
44
import cloudinary from 'decap-cms-media-library-cloudinary';

packages/decap-cms/src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import createReactClass from 'create-react-class';
22
import React from 'react';
3-
import { DecapCmsApp as CMS } from 'decap-cms-app/dist/esm';
3+
import { DecapCmsApp as CMS } from 'decap-cms-app';
44
import './extensions';
55

66
/**

0 commit comments

Comments
 (0)