@@ -20,6 +20,7 @@ import { nodeExternalsPlugin } from 'esbuild-node-externals'
20
20
import { entryChunksPlugin } from 'esbuild-plugin-entry-chunks'
21
21
import { hybridExportPlugin } from 'esbuild-plugin-hybrid-export'
22
22
import { transformHookPlugin } from 'esbuild-plugin-transform-hook'
23
+ import { extractHelpersPlugin } from 'esbuild-plugin-extract-helpers'
23
24
import minimist from 'minimist'
24
25
import glob from 'fast-glob'
25
26
@@ -50,30 +51,7 @@ const {
50
51
cwd : _cwd ,
51
52
} = argv
52
53
53
- const plugins = [
54
- transformHookPlugin ( {
55
- hooks : [
56
- {
57
- on : 'end' ,
58
- pattern : / \. c j s / ,
59
- transform ( contents ) {
60
- const annotationIdx = contents . indexOf (
61
- '// Annotate the CommonJS export names for ESM import in node:'
62
- )
63
- return contents
64
- . slice ( 0 , annotationIdx > 0 ? annotationIdx : contents . length )
65
- . replaceAll ( '"node:' , '"' )
66
- . replaceAll (
67
- 'require("stream/promises")' ,
68
- 'require("stream").promises'
69
- )
70
- . replaceAll ( 'require("fs/promises")' , 'require("fs").promises' )
71
- . replaceAll ( '}).prototype' , '}).prototype || {}' )
72
- } ,
73
- } ,
74
- ] ,
75
- } ) ,
76
- ]
54
+ const plugins = [ ]
77
55
const cwd = Array . isArray ( _cwd ) ? _cwd [ _cwd . length - 1 ] : _cwd
78
56
const entries = entry . split ( / , \s ? / )
79
57
const entryPoints = entry . includes ( '*' )
@@ -103,6 +81,32 @@ if (hybrid) {
103
81
)
104
82
}
105
83
84
+ plugins . push (
85
+ transformHookPlugin ( {
86
+ hooks : [
87
+ {
88
+ on : 'end' ,
89
+ pattern : / \. c j s / ,
90
+ transform ( contents ) {
91
+ return contents
92
+ . toString ( )
93
+ . replaceAll ( '"node:' , '"' )
94
+ . replaceAll (
95
+ 'require("stream/promises")' ,
96
+ 'require("stream").promises'
97
+ )
98
+ . replaceAll ( 'require("fs/promises")' , 'require("fs").promises' )
99
+ . replaceAll ( '}).prototype' , '}).prototype || {}' )
100
+ } ,
101
+ } ,
102
+ ] ,
103
+ } ) ,
104
+ extractHelpersPlugin ( {
105
+ cwd : 'build' ,
106
+ include : / \. c j s / ,
107
+ } )
108
+ )
109
+
106
110
const formats = format . split ( ',' )
107
111
const banner =
108
112
argv . banner && bundle === 'all'
0 commit comments