11import fs from 'node:fs' ;
22import path from 'node:path' ;
3+ import { fileURLToPath } from 'node:url' ;
34
45import del from 'del' ;
56import { it , expect , afterAll } from 'vitest' ;
67import { rollup } from 'rollup' ;
78import nodeResolve from '@rollup/plugin-node-resolve' ;
89
9- import autoInstall from '~package' ;
10+ // IMPORTANT: Don't import the plugin at module scope. The plugin requires Node ≥20.19
11+ // (uses import.meta.dirname). Dynamically import it inside gated tests only.
1012
11- const DIR = import . meta. dirname ;
13+ const DIR = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
1214const cwd = path . join ( DIR , 'fixtures/npm' ) ;
1315const file = path . join ( cwd , 'output/bundle.js' ) ;
1416const input = path . join ( cwd , '../input.js' ) ;
@@ -18,12 +20,14 @@ const PREV_CWD = process.cwd();
1820const [ NODE_MAJOR , NODE_MINOR ] = process . versions . node . split ( '.' ) . map ( Number ) ;
1921const RUN_ON_THIS_NODE = NODE_MAJOR > 20 || ( NODE_MAJOR === 20 && NODE_MINOR >= 19 ) ;
2022
21- it . runIf ( RUN_ON_THIS_NODE ) ( 'invalid manager' , ( ) => {
23+ it . runIf ( RUN_ON_THIS_NODE ) ( 'invalid manager' , async ( ) => {
24+ const { default : autoInstall } = await import ( '~package' ) ;
2225 expect ( ( ) => autoInstall ( { pkgFile, manager : 'foo' as any } ) ) . toThrow ( RangeError ) ;
2326} ) ;
2427
2528it . runIf ( RUN_ON_THIS_NODE ) ( 'npm' , async ( ) => {
2629 process . chdir ( cwd ) ;
30+ const { default : autoInstall } = await import ( '~package' ) ;
2731 const bundle = await rollup ( {
2832 input,
2933 // @ts -expect-error - rollup() ignores output here but tests kept it historically
0 commit comments