Skip to content

Commit

Permalink
♻️ Move packages to ESM (#852)
Browse files Browse the repository at this point in the history
* 🔧 Migrate repo scripts to ESM

* ♻ Migrate @percy/env to ESM

* ♻ Migrate @percy/logger to ESM

* ✅ Fix test usage of logger mocking helper

* ✅ Fix test usage of core test helper

* ♻ Migrate @percy/client to ESM

* ✅ Fix test usage of client test helper

* ♻ Migrate @percy/config to ESM

* ♻ Migrate @percy/core to ESM

* ➖ Remove nock dependency

* ♻ Migrate @percy/cli-command to ESM

* ♻ Migrate @percy/cli to ESM

* ♻ Migrate @percy/cli-build to ESM

* ♻ Migrate @percy/cli-config to ESM

* ♻ Migrate @percy/cli-upload to ESM

* ♻ Migrate @percy/cli-exec to ESM

* ♻ Migrate @percy/cli-snapshot to ESM

* ➖ Remove babel-plugin-module-resolver dependency

* ♻ Migrate @percy/sdk-utils to ESM

* 💚 Update CI workflows

* ✅ Fix flakey tests

* ✅ Use different test port to work around Windows CI

* 🐛 Specify extension and use commonjs for CLI bin

* 🐛 Reference dist in package import aliases

And subsequently rewrite import aliases from dist to src in development

* 🔨 Fix clean script
  • Loading branch information
wwilsman authored Mar 31, 2022
1 parent fabb11a commit 674b290
Show file tree
Hide file tree
Showing 159 changed files with 1,221 additions and 1,063 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ jobs:
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
- run: yarn
env:
PERCY_POSTINSTALL_BROWSER: true
- run: yarn lint
10 changes: 4 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
node-version: 14
- uses: actions/cache@v3
with:
path: |
node_modules
packages/*/node_modules
packages/core/.local-chromium
key: >
${{ runner.os }}/node-12/
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
${{ hashFiles('**/yarn.lock') }}
restore-keys: >
${{ runner.os }}/node-12/
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
- run: yarn
env:
PERCY_POSTINSTALL_BROWSER: true
- run: yarn build
- uses: actions/upload-artifact@v2
with:
Expand All @@ -41,7 +39,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node: [12]
node: [14]
package:
- '@percy/env'
- '@percy/client'
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,19 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
node-version: 14
- uses: actions/cache@v3
with:
path: |
node_modules
packages/*/node_modules
packages/core/.local-chromium
key: >
${{ runner.os }}/node-12/
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
${{ hashFiles('**/yarn.lock') }}
restore-keys: >
${{ runner.os }}/node-12/
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
- run: yarn
env:
PERCY_POSTINSTALL_BROWSER: true
- run: yarn test:types
14 changes: 6 additions & 8 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
node-version: 14
- uses: actions/cache@v3
with:
path: |
node_modules
packages/*/node_modules
packages/core/.local-chromium
key: >
${{ runner.os }}/node-12/
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
${{ hashFiles('**/yarn.lock') }}
restore-keys: >
${{ runner.os }}/node-12/
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
- run: yarn
env:
PERCY_POSTINSTALL_BROWSER: true
- run: yarn build
- uses: actions/upload-artifact@v2
with:
Expand Down Expand Up @@ -61,19 +59,19 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
node-version: 14
- uses: actions/cache@v3
with:
path: |
node_modules
packages/*/node_modules
packages/core/.local-chromium
key: >
${{ runner.os }}/node-12/
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
${{ hashFiles('**/yarn.lock') }}
restore-keys: >
${{ runner.os }}/node-12/
${{ runner.os }}/node-14/
${{ hashFiles('.github/.cache-key') }}/
- uses: actions/download-artifact@v2
with:
Expand Down
29 changes: 29 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const cwd = process.cwd();
const path = require('path');
const pkg = require(`${cwd}/package.json`);

module.exports = {
overrides: [{
exclude: pkg.files && (
pkg.files.map(f => (
path.join(cwd, f)
))),
presets: [
['@babel/env', {
modules: false,
targets: {
node: '14'
}
}]
]
}],
env: {
test: {
plugins: [
['istanbul', {
exclude: ['dist', 'test']
}]
]
}
}
};
46 changes: 0 additions & 46 deletions babel.config.js

This file was deleted.

72 changes: 72 additions & 0 deletions karma.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module.exports = async config => {
const rollup = await import('./rollup.config.js');

return config.set({
basePath: process.cwd(),
frameworks: ['jasmine'],
reporters: ['mocha'],
singleRun: true,
concurrency: 1,

browsers: [
'ChromeHeadless',
'FirefoxHeadless'
],

files: [
// common files
{ pattern: require.resolve('regenerator-runtime/runtime'), watched: false },
{ pattern: require.resolve('./scripts/test-helpers'), type: 'module', watched: false },
// local package files
{ pattern: 'src/index.js', type: 'module', watched: false },
{ pattern: 'test/helpers.js', type: 'module', watched: false },
{ pattern: 'test/**/*.test.js', type: 'module', watched: false },
{ pattern: 'test/assets/**', watched: false, included: false }
],

proxies: {
// useful when the contents of a fake asset do not matter
'/_/': 'localhost/'
},

// create dedicated bundles for src, test helpers, and each test suite
preprocessors: {
'src/index.js': ['rollup'],
'test/helpers.js': ['rollupTestHelpers'],
'test/**/*.test.js': ['rollupTestFiles']
},

client: {
env: {
// used in the test helper to add failed test debug logs
DUMP_FAILED_TEST_LOGS: process.env.DUMP_FAILED_TEST_LOGS
},
// reports look better when not randomized
jasmine: {
random: false
}
},

// (see rollup.config.js)
rollupPreprocessor: rollup.test,

customPreprocessors: {
rollupTestHelpers: {
base: 'rollup',
options: rollup.testHelpers
},
rollupTestFiles: {
base: 'rollup',
options: rollup.testFiles
}
},

plugins: [
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-jasmine',
'karma-mocha-reporter',
'karma-rollup-preprocessor'
]
});
};
70 changes: 0 additions & 70 deletions karma.config.js

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"private": true,
"type": "module",
"workspaces": [
"packages/*"
],
Expand All @@ -12,7 +13,7 @@
"build:watch": "lerna run build --stream -- --watch",
"bump-version": "lerna version --exact --no-git-tag-version --no-push",
"chromium-revision": "./scripts/chromium-revision",
"clean": "git clean -Xdf --exclude !node_modules",
"clean": "git clean -Xdf -e !node_modules -e !**/node_modules/**",
"lint": "eslint --ignore-path .gitignore .",
"readme": "lerna run --parallel readme",
"postinstall": "lerna run --stream postinstall",
Expand All @@ -31,7 +32,6 @@
"@rollup/plugin-commonjs": "^21.0.0",
"@rollup/plugin-node-resolve": "^13.0.1",
"babel-plugin-istanbul": "^6.0.0",
"babel-plugin-module-resolver": "^4.0.0",
"cross-env": "^7.0.2",
"eslint": "^7.30.0",
"eslint-config-standard": "^16.0.2",
Expand All @@ -50,7 +50,6 @@
"karma-rollup-preprocessor": "^7.0.5",
"lerna": "^4.0.0",
"memfs": "^3.4.0",
"nock": "^13.1.1",
"nyc": "^15.1.0",
"rollup": "^2.53.2",
"tsd": "^0.19.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/cli-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
"access": "public"
},
"engines": {
"node": ">=12"
"node": ">=14"
},
"files": [
"./dist"
],
"main": "./dist/index.js",
"type": "module",
"exports": "./dist/index.js",
"scripts": {
"build": "node ../../scripts/build",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli-build/src/build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import command from '@percy/cli-command';

import finalize from './finalize';
import wait from './wait';
import finalize from './finalize.js';
import wait from './wait.js';

export const build = command('build', {
description: 'Finalize and wait on Percy builds',
Expand Down
Loading

0 comments on commit 674b290

Please sign in to comment.