File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,13 +72,13 @@ export const getPkgConfig = (
7272 dynamicImportVars ( {
7373 warnOnError : true ,
7474 } ) ,
75+ esmInjectCreateRequire ( ) ,
7576 ...(
7677 options . minify
7778 ? [ esbuildMinify ( esbuildConfig ) ]
7879 : [ ]
7980 ) ,
8081 patchBinary ( executablePaths ) ,
81- esmInjectCreateRequire ( ) ,
8282 ] ,
8383 output : [ ] as unknown as Output ,
8484 external : [ ] as ( string | RegExp ) [ ] ,
Original file line number Diff line number Diff line change @@ -59,5 +59,25 @@ export default testSuite(({ describe }, nodePath: string) => {
5959 expect ( await fixture . exists ( 'dist/index.mjs' ) ) . toBe ( true ) ;
6060 expect ( await fixture . exists ( 'dist/index.js' ) ) . toBe ( true ) ;
6161 } ) ;
62+
63+ test ( 'hashbang gets inserted at the top (despite other injections e.g. createRequire)' , async ( ) => {
64+ await using fixture = await createFixture ( {
65+ 'src/dynamic-require.ts' : 'require((() => \'fs\')());' ,
66+ 'package.json' : createPackageJson ( {
67+ bin : './dist/dynamic-require.mjs' ,
68+ } ) ,
69+ } ) ;
70+
71+ const pkgrollProcess = await pkgroll ( [ ] , {
72+ cwd : fixture . path ,
73+ nodePath,
74+ } ) ;
75+
76+ expect ( pkgrollProcess . exitCode ) . toBe ( 0 ) ;
77+ expect ( pkgrollProcess . stderr ) . toBe ( '' ) ;
78+
79+ const content = await fixture . readFile ( 'dist/dynamic-require.mjs' , 'utf8' ) ;
80+ expect ( content . startsWith ( '#!/usr/bin/env node' ) ) . toBeTruthy ( ) ;
81+ } ) ;
6282 } ) ;
6383} ) ;
You can’t perform that action at this time.
0 commit comments