Skip to content

Commit

Permalink
Migrate package to ECMAScript modules
Browse files Browse the repository at this point in the history
BREAKING CHANGE: parse-domain will now be released as native ECMAScript module. There's no CommonJS build anymore. If you're still using CommonJS, you need to import it asynchronously using `await import("parse-domain")`. If you're still using Node 12, you may need to update it to the latest 12.x version.
  • Loading branch information
jhnns committed Jan 23, 2022
1 parent 371b07f commit 42f54e8
Show file tree
Hide file tree
Showing 42 changed files with 597 additions and 4,572 deletions.
7 changes: 0 additions & 7 deletions .eslintrc.js

This file was deleted.

12 changes: 12 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": [
"peerigon/presets/prettier-typescript.js",
// See https://github.com/peerigon/eslint-config-peerigon#peerigonstylesno-default-export
"peerigon/styles/no-default-export",
"peerigon/styles/no-null"
],
"env": {
"node": true
},
"root": true
}
11 changes: 6 additions & 5 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ jobs:
- name: 🛑 Cancel Previous Runs
uses: styfle/cancel-workflow-action@a40b8845c0683271d9f53dfcb887a7e181d3918b # pin@0.9.1
- name: ⬇️ Checkout repo
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # pin@v2
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # pin@v2
- name: ⎔ Setup node ${{ matrix.node-version }}
uses: actions/setup-node@25316bbc1f10ac9d8798711f44914b1cf3c4e954 # pin@v2
uses: actions/setup-node@1f8c6b94b26d0feae1e387ca63ccbdc44d27b561 # pin@v2
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: 🗄 Cache node_modules
id: cache-node_modules
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353 # pin@v2
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # pin@v2
with:
path: "**/node_modules"
key: node_modules-${{ runner.os }}-node-${{ matrix.node-version }}-${{
hashFiles('**/package-lock.json') }}
- name: 🗄 Cache .eslintcache
uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353 # pin@v2
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed # pin@v2
with:
path: .eslintcache
key: eslintcache-${{ runner.os }}-node-${{ matrix.node-version }}-${{
Expand All @@ -45,7 +45,8 @@ jobs:
npm ci --ignore-scripts
- name: 🧪 Test
run: |
npm run test
npm run prepare:build
npm test
env:
CI: true
- name: ⬆️ Upload coverage report
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ coverage
# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
node_modules
Expand All @@ -36,7 +34,7 @@ node_modules
.node_repl_history

# We don't check in compiled files. They are created upon npm publish and npm install.
build-esm
build-cjs
build
serialized-tries

.eslintcache
19 changes: 8 additions & 11 deletions bin/update.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
#!/usr/bin/env node

"use strict";

const { EOL } = require("os");
import { EOL } from "os";

(async () => {
process.argv.push(
"--",
"../../serialized-tries",
"../../../build-esm/serialized-tries"
);
process.argv.push("--", "../../serialized-tries");

const updateTries = await import("../build/scripts/update-tries.js");

await require("../build-cjs/src/scripts/update-tries.js").done;
await updateTries.done;

process.stderr.write("Running smoke test... ");

require("../build-cjs/src/smoke-test.js").runSmokeTest();
const smokeTest = await import("../build/smoke-test.js");

smokeTest.runSmokeTest();

process.stdout.write("ok" + EOL);
})().catch((error) => {
console.error(`parse-domain update failed: ${error}`);
// eslint-disable-next-line no-process-exit, node/no-process-exit
process.exit(1);
});
11 changes: 7 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"use strict";

module.exports = {
// eslint-disable-next-line import/no-default-export
export default {
roots: ["<rootDir>/src"],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
extensionsToTreatAsEsm: [".ts"],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
globals: {
"ts-jest": {
diagnostics: false,
useESM: true,
},
},
collectCoverage: true,
Expand Down

0 comments on commit 42f54e8

Please sign in to comment.