Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
fix: postbuild script
Browse files Browse the repository at this point in the history
  • Loading branch information
iCrawl committed Nov 12, 2021
1 parent 3bfaebf commit 644af95
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test": "jest --pass-with-no-tests",
"test:ci": "jest --no-stack-trace --verbose --pass-with-no-tests",
"prebuild": "npm run lint",
"build": "tsup --format cjs --clean && tsup --dts --format esm",
"build": "tsup",
"postbuild": "node scripts/postbuild.mjs",
"lint": "eslint src --ext mjs,js,ts",
"lint:fix": "eslint src --ext mjs,js,ts --fix",
"format": "prettier --write **/*.{ts,js,json,yml,yaml}",
Expand Down
7 changes: 7 additions & 0 deletions scripts/postbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { readFile, writeFile } from 'node:fs/promises';

const data = await readFile('./dist/index.mjs', 'utf-8');
await writeFile(
'./dist/index.mjs',
`import{createRequire as topLevelCreateRequire}from"module";const require=topLevelCreateRequire(import.meta.url);${data}`,
);
23 changes: 9 additions & 14 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { defineConfig } from 'tsup';

export default defineConfig((options) => {
return {
banner: {
js:
options.format[0] === 'esm'
? 'import{resolve as requireResolve}from"path";import{createRequire as topLevelCreateRequire}from"module";const require=topLevelCreateRequire(requireResolve(""));'
: '',
},
entryPoints: ['src/index.ts'],
minify: true,
skipNodeModulesBundle: true,
sourcemap: true,
target: 'es2021',
};
export default defineConfig({
clean: true,
dts: true,
entryPoints: ['src/index.ts'],
format: ['esm', 'cjs'],
minify: true,
skipNodeModulesBundle: true,
sourcemap: true,
target: 'es2021',
});

0 comments on commit 644af95

Please sign in to comment.