1- import { readFile , writeFile } from 'node:fs/promises'
2- import { readFile as fsReadFile , stat , realpath } from 'node:fs/promises'
3- import { resolve } from 'node:path'
4- import { resolve as pathResolve , dirname as pathDirname , extname , join } from 'node:path'
1+ import { readFile , writeFile , stat , realpath } from 'node:fs/promises'
2+ import { resolve , dirname , extname , join } from 'node:path'
53
64import type MagicString from 'magic-string'
7- import type { SourceMap } from 'magic-string'
85import type { TemplateLiteral } from 'oxc-parser'
96
107import {
@@ -14,9 +11,7 @@ import {
1411 type PackageUsage ,
1512} from './format.js'
1613import { parse } from './parse.js'
17- import { parse as parseModule } from './parse.js'
18- import { specifier } from './specifier.js'
19- import type { Spec } from './specifier.js'
14+ import { specifier , type Spec } from './specifier.js'
2015import type { ModuleOptions , Diagnostic } from './types.js'
2116import { builtinSpecifiers } from './utils/builtinSpecifiers.js'
2217import { collectModuleIdentifiers } from './utils/identifiers.js'
@@ -25,6 +20,7 @@ import { walk } from './walk.js'
2520
2621type AppendJsExtensionMode = NonNullable < ModuleOptions [ 'appendJsExtension' ] >
2722type DetectCircularRequires = NonNullable < ModuleOptions [ 'detectCircularRequires' ] >
23+ type SourceMap = import ( 'magic-string' ) . SourceMap
2824
2925const collapseSpecifier = ( value : string ) => value . replace ( / [ ' " ` + ) \s ] | n e w S t r i n g \( / g, '' )
3026
@@ -110,11 +106,11 @@ const fileExists = async (candidate: string) => {
110106 }
111107}
112108
113- const normalizePath = async ( p : string ) => pathResolve ( await realpath ( p ) . catch ( ( ) => p ) )
109+ const normalizePath = async ( p : string ) => resolve ( await realpath ( p ) . catch ( ( ) => p ) )
114110
115111const resolveRequirePath = async ( fromFile : string , spec : string , dirIndex : string ) => {
116112 if ( ! spec . startsWith ( './' ) && ! spec . startsWith ( '../' ) ) return null
117- const base = pathResolve ( pathDirname ( fromFile ) , spec )
113+ const base = resolve ( dirname ( fromFile ) , spec )
118114 const ext = extname ( base )
119115 const candidates : string [ ] = [ ]
120116
@@ -140,8 +136,8 @@ const resolveRequirePath = async (fromFile: string, spec: string, dirIndex: stri
140136}
141137
142138const collectStaticRequires = async ( filePath : string , dirIndex : string ) => {
143- const src = await fsReadFile ( filePath , 'utf8' )
144- const ast = parseModule ( filePath , src )
139+ const src = await readFile ( filePath , 'utf8' )
140+ const ast = parse ( filePath , src )
145141 const specs : string [ ] = [ ]
146142
147143 await walk ( ast . program , {
@@ -240,7 +236,7 @@ const collectProjectDualPackageHazards = async (files: string[], opts: ModuleOpt
240236
241237 for ( const file of files ) {
242238 const code = await readFile ( file , 'utf8' )
243- const ast = parseModule ( file , code )
239+ const ast = parse ( file , code )
244240 const moduleIdentifiers = await collectModuleIdentifiers ( ast . program )
245241 const shadowedBindings = new Set (
246242 [ ...moduleIdentifiers . entries ( ) ]
0 commit comments