Skip to content

Commit

Permalink
Merge pull request #163 from ext/feature/esm
Browse files Browse the repository at this point in the history
feat: migrate to esm
  • Loading branch information
ext committed Apr 15, 2023
2 parents 975631d + 51b4f90 commit 0e834cc
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js → .eslintrc.cjs
Expand Up @@ -3,6 +3,10 @@ require("@html-validate/eslint-config/patch/modern-module-resolution");
module.exports = {
extends: ["@html-validate"],

rules: {
"import/extensions": "off",
},

overrides: [
{
files: "*.ts",
Expand All @@ -13,5 +17,12 @@ module.exports = {
excludedFiles: ["cypress/**", "tests/e2e/**"],
extends: ["@html-validate/jest"],
},
{
files: "bin/*.js",
rules: {
/* should lint without errors even if project isn't compiled */
"import/no-unresolved": "off",
},
},
],
};
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
npm pack
npm run self-test
- name: Jest
run: npm test
run: npm --ignore-scripts test
env:
CI: true
- name: Coveralls
Expand Down
2 changes: 1 addition & 1 deletion bin/index.js
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require("../dist/index");
import "../dist/index.js";
29 changes: 29 additions & 0 deletions build.mjs
@@ -0,0 +1,29 @@
import * as esbuild from "esbuild";

const cjsCompat = `
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
`;

async function run() {
const result = await esbuild.build({
entryPoints: ["src/index.ts"],
outdir: "dist",
sourcemap: true,
bundle: true,
platform: "node",
target: "node14",
format: "esm",
banner: {
js: cjsCompat,
},
metafile: true,
logLevel: "info",
});
console.log(await esbuild.analyzeMetafile(result.metafile));
}

run().catch((err) => {
console.error(err);
process.exitCode = 1;
});
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -18,6 +18,7 @@
"author": "David Sveningsson <ext@sidvind.com>",
"main": "dist/index.js",
"bin": "bin/index.js",
"type": "module",
"files": [
"bin",
"dist",
Expand All @@ -26,7 +27,7 @@
],
"scripts": {
"prebuild": "tsc",
"build": "esbuild src/index.ts --bundle --platform=node --target=node14.0 --analyze --sourcemap --outdir=dist",
"build": "node build.mjs",
"eslint": "eslint .",
"eslint:fix": "eslint --fix .",
"prepack": "release-prepack package.json --bundle",
Expand All @@ -37,6 +38,7 @@
"prettier:write": "prettier --write .",
"postpublish": "release-postpublish package.json",
"self-test": "node bin/index.js",
"pretest": "npm run prettier:check && npm run eslint",
"test": "jest"
},
"commitlint": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
@@ -1,7 +1,7 @@
/* eslint-disable no-console, no-process-exit -- this is a cli tool */

import { existsSync, createWriteStream, promises as fs } from "fs";
import path from "path";
import { existsSync, createWriteStream, promises as fs } from "node:fs";
import path from "node:path";
import { ArgumentParser } from "argparse";
import findUp from "find-up";
import tmp from "tmp";
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -6,7 +6,8 @@
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"lib": ["es2020"],
"module": "commonjs",
"module": "esnext",
"moduleResolution": "bundler",
"noImplicitAny": true,
"noEmit": true,
"outDir": "dist",
Expand Down

0 comments on commit 0e834cc

Please sign in to comment.