Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(build): Fix ESM output (#7357) #7358

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
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
62 changes: 12 additions & 50 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Node CI

on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]

Expand All @@ -28,73 +26,37 @@ jobs:
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
node-version: [18.x, 20.x]
fail-fast: true
if: ${{ needs.changes.outputs.cms == 'true' }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js {{ matrix.node-version }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
check-latest: true
cache: 'npm'
- name: log versions
run: node --version && npm --version && yarn --version
- name: install dependecies
run: npm install
- name: install dependencies
run: npm ci
- name: run unit tests
run: npm run test:ci
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
- name: build demo site
run: npm run build:demo
- name: run e2e tests
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x'
run: npm run test:e2e:run-ci
env:
NODE_OPTIONS: --max-old-space-size=4096
- uses: actions/upload-artifact@master
with:
name: dev-test-website-${{ runner.os }}-${{ matrix.node-version }}
path: dev-test

e2e-with-cypress:
needs: [changes, build]
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]
fail-fast: false

if: ${{ needs.changes.outputs.cms == 'true' }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- uses: actions/download-artifact@master
with:
name: dev-test-website-${{ runner.os }}-18.x
path: dev-test
- name: npm install
run: |
node --version
npm --version
yarn --version
npm install
- name: e2e test
run: |
npm run test:e2e:run-ci
env:
IS_FORK: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true }}
IS_FORK: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true || github.repository_owner != 'decaporg' }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
NODE_OPTIONS: --max-old-space-size=4096
MACHINE_COUNT: 2
MACHINE_INDEX: ${{ matrix.node-version }}
TZ: Europe/Amsterdam
- uses: actions/upload-artifact@v3
if: ${{ always() }}
if: matrix.os == 'ubuntu-latest' && matrix.node-version == '20.x' && failure()
with:
name: cypress-results-${{ matrix.node-version }}
name: cypress-results
path: |
cypress/screenshots
cypress/videos

2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const svgo = {
function presets() {
return [
'@babel/preset-react',
'@babel/preset-env',
['@babel/preset-env', isESM ? { modules: false } : {}],
[
'@emotion/babel-preset-css-prop',
{
Expand Down
42 changes: 21 additions & 21 deletions cypress/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ import execa from 'execa';
import { globby } from 'globby';

async function runCypress() {
const args = ['run', '--browser', 'chrome', '--headless'];

const specs = await globby(['cypress/e2e/*spec*.js']);
if (specs.length === 0) {
console.log('No test files found in cypress/e2e/*spec*.js');
process.exit(1);
}

if (process.env.IS_FORK === 'true') {
const machineIndex = parseInt(process.env.MACHINE_INDEX);
const machineCount = parseInt(process.env.MACHINE_COUNT);
const specs = await globby(['cypress/integration/*spec*.js']);
const specsPerMachine = Math.floor(specs.length / machineCount);
const start = (machineIndex - 1) * specsPerMachine;
const machineSpecs =
machineIndex === machineCount
? specs.slice(start)
: specs.slice(start, start + specsPerMachine);

await execa(
'cypress',
['run', '--browser', 'chrome', '--headless', '--spec', machineSpecs.join(',')],
{ stdio: 'inherit', preferLocal: true },
);
args.push('--spec', machineSpecs.join(','));
} else {
await execa(
'cypress',
[
'run',
'--browser',
'chrome',
'--headless',
'--record',
'--parallel',
'--ci-build-id',
process.env.GITHUB_SHA,
'--group',
'GitHub CI',
],
{ stdio: 'inherit', preferLocal: true },
args.push(
'--record',
'--parallel',
'--ci-build-id',
process.env.GITHUB_SHA,
'--group',
'GitHub CI',
'--spec',
specs.join(','),
);
}

console.log('Running Cypress with args:', args.join(' '));
await execa('cypress', args, { stdio: 'inherit', preferLocal: true });
}

runCypress();
6 changes: 6 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ addMatchImageSnapshotCommand({
Cypress.on('uncaught:exception', () => false);

import './commands';

afterEach(function () {
if (this.currentTest.state === 'failed') {
Cypress.runner.stop();
}
});
6 changes: 4 additions & 2 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"targetDefaults": {
"build:esm": {
"cache": true
"cache": true,
"dependsOn": ["^build:esm"]
},
"build": {
"cache": true
"cache": true,
"dependsOn": ["^build"]
}
},
"namedInputs": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build-preview": "npm run build && nx run decap-cms:build-preview --output-style=stream",
"type-check": "tsc --noEmit",
"type-check:watch": "npm run type-check -- --watch",
"clean": "rimraf \"packages/*/dist\" dev-test/dist \"packages/*/node_modules\"",
"clean": "rimraf \"packages/*/dist\" dev-test/dist \"packages/*/node_modules\" \".nx/cache\"",
"reset": "npm run clean",
"test": "npm run lint && npm run type-check && npm run test:unit",
"test:all": "npm run test && npm run test:e2e",
Expand Down
2 changes: 2 additions & 0 deletions packages/decap-cms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"homepage": "https://www.decapcms.org",
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-app",
"bugs": "https://github.com/decaporg/decap-cms/issues",
"module": "dist/esm/index.js",
"main": "dist/decap-cms-app.js",
"files": [
"src/",
Expand Down Expand Up @@ -34,6 +35,7 @@
"decap-cms-backend-azure": "^3.1.3",
"decap-cms-backend-bitbucket": "^3.1.4",
"decap-cms-backend-git-gateway": "^3.2.2",
"decap-cms-backend-gitea": "^3.1.5",
"decap-cms-backend-github": "^3.2.2",
"decap-cms-backend-gitlab": "^3.2.2",
"decap-cms-backend-proxy": "^3.1.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms/src/extensions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DecapCmsApp as CMS } from 'decap-cms-app/dist/esm';
import { DecapCmsApp as CMS } from 'decap-cms-app';
// Media libraries
import uploadcare from 'decap-cms-media-library-uploadcare';
import cloudinary from 'decap-cms-media-library-cloudinary';
Expand Down
2 changes: 1 addition & 1 deletion packages/decap-cms/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createReactClass from 'create-react-class';
import React from 'react';
import { DecapCmsApp as CMS } from 'decap-cms-app/dist/esm';
import { DecapCmsApp as CMS } from 'decap-cms-app';
import './extensions';

/**
Expand Down
Loading