11'use strict' ;
22
3- const fs = require ( 'node:fs' ) ;
4- const path = require ( 'node:path' ) ;
53const { spawnSyncAndAssert } = require ( '../common/child_process' ) ;
6- const tmpdir = require ( '../common/tmpdir ' ) ;
4+ const fixtures = require ( '../common/fixtures ' ) ;
75
8- tmpdir . refresh ( ) ;
6+ const commonjsDir = fixtures . path ( 'es-modules' , 'extensionless-esm-commonjs' ) ;
97
10- const commonjsDir = tmpdir . resolve ( 'extensionless-esm-commonjs' ) ;
11- fs . mkdirSync ( commonjsDir , { recursive : true } ) ;
12-
13- // package.json with type: commonjs
14- fs . writeFileSync (
15- path . join ( commonjsDir , 'package.json' ) ,
16- '{\n "type": "commonjs"\n}\n' ,
17- 'utf8'
18- ) ;
19-
20- // Extensionless executable with shebang + ESM syntax.
21- // NOTE: Execute via process.execPath to avoid PATH/env differences.
22- const commonjsScriptPath = path . join ( commonjsDir , 'script' ) ; // no extension
23- fs . writeFileSync (
24- commonjsScriptPath ,
25- '#!/usr/bin/env node\n' +
26- "console.log('script STARTED')\n" +
27- "import { version } from 'node:process'\n" +
28- 'console.log(version)\n' ,
29- 'utf8'
30- ) ;
31- fs . chmodSync ( commonjsScriptPath , 0o755 ) ;
32-
33- spawnSyncAndAssert ( process . execPath , [ './script' ] , {
8+ spawnSyncAndAssert ( process . execPath , [ '--no-experimental-detect-module' , './script' ] , {
349 cwd : commonjsDir ,
3510 encoding : 'utf8' ,
3611} , {
@@ -39,28 +14,9 @@ spawnSyncAndAssert(process.execPath, ['./script'], {
3914 trim : true ,
4015} ) ;
4116
42- const moduleDir = tmpdir . resolve ( 'extensionless-esm-module' ) ;
43- fs . mkdirSync ( moduleDir , { recursive : true } ) ;
44-
45- // package.json with type: module
46- fs . writeFileSync (
47- path . join ( moduleDir , 'package.json' ) ,
48- '{\n "type": "module"\n}\n' ,
49- 'utf8'
50- ) ;
51-
52- const moduleScriptPath = path . join ( moduleDir , 'script' ) ; // no extension
53- fs . writeFileSync (
54- moduleScriptPath ,
55- '#!/usr/bin/env node\n' +
56- "console.log('script STARTED')\n" +
57- "import { version } from 'node:process'\n" +
58- 'console.log(version)\n' ,
59- 'utf8'
60- ) ;
61- fs . chmodSync ( moduleScriptPath , 0o755 ) ;
17+ const moduleDir = fixtures . path ( 'es-modules' , 'extensionless-esm-module' ) ;
6218
63- spawnSyncAndAssert ( process . execPath , [ './script' ] , {
19+ spawnSyncAndAssert ( process . execPath , [ '--no-experimental-detect-module' , ' ./script'] , {
6420 cwd : moduleDir ,
6521 encoding : 'utf8' ,
6622} , {
0 commit comments