11import { defineConfig , Options } from 'tsup' ;
2- import fs , { readFile , writeFile } from 'node:fs/promises' ;
2+ import fs from 'node:fs/promises' ;
33import path from 'node:path' ;
44import packageJson from './package.json' ;
55
@@ -28,28 +28,21 @@ export default defineConfig([
2828 await fs . writeFile ( path . join ( CWD , 'dist' , 'esm' , 'package.json' ) , '{"type": "module"}' ) ;
2929 await fs . writeFile (
3030 path . join ( CWD , 'dist' , 'package.json' ) ,
31- JSON . stringify ( { ...packageJson , devDependencies : undefined } ) . replaceAll ( 'dist/' , '' ) ,
31+ JSON . stringify (
32+ {
33+ ...packageJson ,
34+ devDependencies : undefined ,
35+ scripts : undefined ,
36+ } ,
37+ null ,
38+ 2 ,
39+ ) . replaceAll ( 'dist/' , '' ) ,
3240 ) ;
33-
34- const filePaths = [
41+ addCreateRequireBanner ( [
3542 'estree-converter/utils.js' ,
3643 'rules/graphql-js-validation.js' ,
3744 'testkit.js' ,
38- ] ;
39- await Promise . all (
40- filePaths . map ( async filePath => {
41- const fullPath = path . join ( CWD , 'dist' , 'esm' , filePath ) ;
42- const content = await readFile ( fullPath , 'utf8' ) ;
43- await writeFile (
44- fullPath ,
45- `
46- import { createRequire } from 'module';
47- const require = createRequire(import.meta.url);
48- ${ content } `. trimStart ( ) ,
49- ) ;
50- } ) ,
51- ) ;
52-
45+ ] ) ;
5346 console . log ( '✅ Success!' ) ;
5447 } ,
5548 } ,
@@ -59,3 +52,18 @@ ${content}`.trimStart(),
5952 outDir : 'dist/cjs' ,
6053 } ,
6154] ) ;
55+
56+ async function addCreateRequireBanner ( filePaths : string [ ] ) : Promise < void > {
57+ await Promise . all (
58+ filePaths . map ( async filePath => {
59+ const fullPath = path . join ( CWD , 'dist' , 'esm' , filePath ) ;
60+ const content = await fs . readFile ( fullPath , 'utf8' ) ;
61+ await fs . writeFile (
62+ fullPath ,
63+ `import { createRequire } from 'module';
64+ const require = createRequire(import.meta.url);
65+ ${ content } `,
66+ ) ;
67+ } ) ,
68+ ) ;
69+ }
0 commit comments