@@ -123,6 +123,59 @@ test('--ignore excludes glob matches', async () => {
123123 }
124124} )
125125
126+ test ( 'glob expansion excludes directories' , async ( ) => {
127+ const temp = await mkdtemp ( join ( tmpdir ( ) , 'module-cli-glob-nodir-' ) )
128+ const nested = join ( temp , 'nested' )
129+ const input = join ( temp , 'input.cjs' )
130+
131+ await mkdir ( nested , { recursive : true } )
132+ await copyFile ( fixture , input )
133+
134+ try {
135+ const result = runCli ( [ '--list' , '--target' , 'module' , '--cwd' , temp , '*' ] )
136+
137+ assert . equal ( result . status , 0 )
138+ assert . ok ( result . stdout . includes ( 'input.cjs' ) )
139+ assert . ok ( ! result . stdout . includes ( 'nested' ) )
140+ } finally {
141+ await rm ( temp , { recursive : true , force : true } )
142+ }
143+ } )
144+
145+ test ( 'windows: backslash glob and ignore patterns are honored' , async ( ) => {
146+ if ( process . platform !== 'win32' ) return
147+
148+ const temp = await mkdtemp ( join ( tmpdir ( ) , 'module-cli-win-glob-' ) )
149+ const srcDir = join ( temp , 'src' )
150+ const keep = join ( srcDir , 'keep.cjs' )
151+ const ignoredDir = join ( temp , 'node_modules' , 'pkg' )
152+ const ignored = join ( ignoredDir , 'index.cjs' )
153+
154+ await mkdir ( srcDir , { recursive : true } )
155+ await mkdir ( ignoredDir , { recursive : true } )
156+ await copyFile ( fixture , keep )
157+ await copyFile ( fixture , ignored )
158+
159+ try {
160+ const result = runCli ( [
161+ '--list' ,
162+ '--target' ,
163+ 'module' ,
164+ '--cwd' ,
165+ temp ,
166+ 'src\\**\\*.cjs' ,
167+ '--ignore' ,
168+ 'node_modules\\**' ,
169+ ] )
170+
171+ assert . equal ( result . status , 0 )
172+ assert . ok ( result . stdout . includes ( 'keep.cjs' ) )
173+ assert . ok ( ! result . stdout . includes ( 'node_modules' ) )
174+ } finally {
175+ await rm ( temp , { recursive : true , force : true } )
176+ }
177+ } )
178+
126179test ( '-H error exits on dual package hazard' , async ( ) => {
127180 const temp = await mkdtemp ( join ( tmpdir ( ) , 'module-cli-dual-hazard-' ) )
128181 const file = join ( temp , 'entry.mjs' )
@@ -670,6 +723,74 @@ test('globals-only pre-tsc flow matches README example', async () => {
670723 }
671724} )
672725
726+ test ( 'globals-only pre-tsc flow with README glob pattern' , async ( ) => {
727+ const temp = await mkdtemp ( join ( tmpdir ( ) , 'module-cli-pre-tsc-glob-' ) )
728+ const srcDir = join ( temp , 'src' )
729+ const nestedDir = join ( srcDir , 'nested' )
730+ const file = join ( nestedDir , 'index.ts' )
731+
732+ await mkdir ( nestedDir , { recursive : true } )
733+ await writeFile (
734+ join ( temp , 'tsconfig.json' ) ,
735+ JSON . stringify (
736+ {
737+ compilerOptions : {
738+ target : 'ES2020' ,
739+ module : 'commonjs' ,
740+ outDir : 'dist' ,
741+ strict : false ,
742+ esModuleInterop : true ,
743+ types : [ 'node' ] ,
744+ typeRoots : [ join ( projectRoot , 'node_modules' , '@types' ) ] ,
745+ } ,
746+ include : [ 'src' ] ,
747+ } ,
748+ null ,
749+ 2 ,
750+ ) ,
751+ 'utf8' ,
752+ )
753+ await writeFile (
754+ file ,
755+ [
756+ "import fs from 'node:fs'" ,
757+ 'export const meta = import.meta.url' ,
758+ 'export const size = fs.statSync(__filename).size' ,
759+ '' ,
760+ ] . join ( '\n' ) ,
761+ 'utf8' ,
762+ )
763+
764+ try {
765+ const before = spawnSync ( process . execPath , [ tscBin , '-p' , temp ] , { encoding : 'utf8' } )
766+ assert . notEqual ( before . status , 0 )
767+
768+ const result = runCli (
769+ [
770+ '--target' ,
771+ 'commonjs' ,
772+ '--transform-syntax' ,
773+ 'globals-only' ,
774+ '--ignore' ,
775+ 'node_modules/**' ,
776+ '--in-place' ,
777+ 'src/**/*.{ts,js,mts,cts}' ,
778+ ] ,
779+ undefined ,
780+ { cwd : temp } ,
781+ )
782+
783+ assert . equal ( result . status , 0 )
784+ const transformed = await readFile ( file , 'utf8' )
785+ assert . ok ( ! transformed . includes ( 'import.meta' ) )
786+
787+ const after = spawnSync ( process . execPath , [ tscBin , '-p' , temp ] , { encoding : 'utf8' } )
788+ assert . equal ( after . status , 0 , after . stderr || after . stdout )
789+ } finally {
790+ await rm ( temp , { recursive : true , force : true } )
791+ }
792+ } )
793+
673794test ( '--dry-run does not create outputs when out-dir provided' , async ( ) => {
674795 const temp = await mkdtemp ( join ( tmpdir ( ) , 'module-cli-' ) )
675796 const outDir = join ( temp , 'out' )
0 commit comments