1
1
import { defineConfig , Options } from 'tsup' ;
2
- import fs , { readFile , writeFile } from 'node:fs/promises' ;
2
+ import fs from 'node:fs/promises' ;
3
3
import path from 'node:path' ;
4
4
import packageJson from './package.json' ;
5
5
@@ -28,28 +28,21 @@ export default defineConfig([
28
28
await fs . writeFile ( path . join ( CWD , 'dist' , 'esm' , 'package.json' ) , '{"type": "module"}' ) ;
29
29
await fs . writeFile (
30
30
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/' , '' ) ,
32
40
) ;
33
-
34
- const filePaths = [
41
+ addCreateRequireBanner ( [
35
42
'estree-converter/utils.js' ,
36
43
'rules/graphql-js-validation.js' ,
37
44
'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
+ ] ) ;
53
46
console . log ( '✅ Success!' ) ;
54
47
} ,
55
48
} ,
@@ -59,3 +52,18 @@ ${content}`.trimStart(),
59
52
outDir : 'dist/cjs' ,
60
53
} ,
61
54
] ) ;
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