Skip to content

Commit 11c593b

Browse files
refactor: address pr comments.
1 parent 1cc38cb commit 11c593b

4 files changed

Lines changed: 13 additions & 19 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@
100100
"lint-staged": {
101101
"*.{js,ts,tsx,jsx,cjs,mjs}": [
102102
"prettier -c",
103-
"oxlint --config oxlint.json",
104-
"eslint src test --ext .ts"
103+
"oxlint --config oxlint.json"
105104
],
105+
"*.ts": "eslint --ext .ts",
106106
"*.{json,md,yml,yaml,css,scss,html}": "prettier -c"
107107
}
108108
}

src/helpers/async.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { isAstNode } from './ast.js'
2-
import type { Node, ProgramNode } from './ast.js'
1+
import { isAstNode, type Node, type ProgramNode } from './ast.js'
32

43
const hasTopLevelAwait = (program: ProgramNode) => {
54
let found = false

src/module.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
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

64
import type MagicString from 'magic-string'
7-
import type { SourceMap } from 'magic-string'
85
import type { TemplateLiteral } from 'oxc-parser'
96

107
import {
@@ -14,9 +11,7 @@ import {
1411
type PackageUsage,
1512
} from './format.js'
1613
import { 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'
2015
import type { ModuleOptions, Diagnostic } from './types.js'
2116
import { builtinSpecifiers } from './utils/builtinSpecifiers.js'
2217
import { collectModuleIdentifiers } from './utils/identifiers.js'
@@ -25,6 +20,7 @@ import { walk } from './walk.js'
2520

2621
type AppendJsExtensionMode = NonNullable<ModuleOptions['appendJsExtension']>
2722
type DetectCircularRequires = NonNullable<ModuleOptions['detectCircularRequires']>
23+
type SourceMap = import('magic-string').SourceMap
2824

2925
const collapseSpecifier = (value: string) => value.replace(/['"`+)\s]|new String\(/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

115111
const 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

142138
const 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()]

src/walk.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { visitorKeys } from 'oxc-parser'
2-
import type { Node } from 'oxc-parser'
1+
import { visitorKeys, type Node } from 'oxc-parser'
32

43
/**
54
* Using visitorKeys instead of oxc Visitor to keep

0 commit comments

Comments
 (0)