Skip to content

Commit

Permalink
feat!: migrate to native esm
Browse files Browse the repository at this point in the history
- use "type": "module" in all packages
- convert commonjs to esm
- adjust imports to contain extension for native node compatibility
- move ci to Node 22
- upgrade @types/node to v22
- upgrade esm-only deps and regenerate lock file
  • Loading branch information
AviVahl committed Dec 17, 2024
1 parent 9dd6f71 commit a288300
Show file tree
Hide file tree
Showing 41 changed files with 570 additions and 431 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ updates:
ignore:
- dependency-name: '@types/node'
versions:
- '>=21'
- '>=23'
4 changes: 2 additions & 2 deletions .github/workflows/next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
registry-url: 'https://registry.npmjs.org/'
- run: npm ci
- run: npm run build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
registry-url: 'https://registry.npmjs.org/'
- run: npm ci
- run: npm run build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20]
node-version: [22]
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
22
2 changes: 1 addition & 1 deletion empty-object.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = {};
export {};
16 changes: 8 additions & 8 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// @ts-chec
// @ts-check

import { fileURLToPath } from 'node:url';
import { builtinModules as nativeNodeApis } from 'node:module';

// Used as a polyfill for node apis when they aren't available.
// The key is the node api name and the value is the stand-in object.
const emptyModulePath = require.resolve(`./empty-object.js`);
const utilModulePath = require.resolve(`./micro-util-nofill.js`);
const emptyModulePath = fileURLToPath(import.meta.resolve(`./empty-object.js`));
const utilModulePath = fileURLToPath(import.meta.resolve(`./micro-util-nofill.js`));

// get all native node apis

const nativeNodeApis = require('module').builtinModules;

/** @type {Record<string, string>} */
const alias = {};
for (const nodeApi of nativeNodeApis) {
if (nodeApi === 'util') {
Expand All @@ -21,8 +22,7 @@ for (const nodeApi of nativeNodeApis) {
}

/** @type {import('esbuild').BuildOptions} */
module.exports = {
plugins: [],
export default {
alias,
loader: {
'.jpg': 'file',
Expand Down
Loading

0 comments on commit a288300

Please sign in to comment.