Skip to content

Commit a642f91

Browse files
committed
perf: drop unneeded node imports on fast path
1 parent fab29e4 commit a642f91

3 files changed

Lines changed: 2 additions & 22 deletions

File tree

packages/nuxi/bin/nuxi.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
import inspector from 'node:inspector'
43
import nodeModule from 'node:module'
54
import process from 'node:process'
65
import { fileURLToPath } from 'node:url'
@@ -34,7 +33,7 @@ if (
3433
process.argv.includes('--profile')
3534
|| process.argv.some(a => a.startsWith('--profile='))
3635
) {
37-
const session = new inspector.Session()
36+
const session = new (process.getBuiltinModule('node:inspector').Session)()
3837
session.connect()
3938
// eslint-disable-next-line antfu/no-top-level-await
4039
await new Promise((resolve) => {

packages/nuxi/src/main.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { CommandDef } from 'citty'
22

3-
import nodeCrypto from 'node:crypto'
4-
import { builtinModules, createRequire } from 'node:module'
53
import { resolve } from 'node:path'
64
import process from 'node:process'
75

@@ -17,22 +15,6 @@ import { debug, logger } from '../../nuxt-cli/src/utils/logger'
1715
import { findInPath, withLocalBinPath } from '../../nuxt-cli/src/utils/path-env'
1816
import { description, name, version } from '../package.json'
1917

20-
// globalThis.crypto support for Node.js 18
21-
if (!globalThis.crypto) {
22-
globalThis.crypto = nodeCrypto.webcrypto as unknown as Crypto
23-
}
24-
25-
// Node.js below v22.3.0, v20.16.0
26-
if (!process.getBuiltinModule) {
27-
const _require = createRequire(import.meta.url)
28-
// @ts-expect-error we are overriding with inferior types
29-
process.getBuiltinModule = (name: string) => {
30-
if (name.startsWith('node:') || builtinModules.includes(name)) {
31-
return _require.resolve(name)
32-
}
33-
}
34-
}
35-
3618
const commands = {
3719
init: () => import('../../create-nuxt/src/init').then(m => m.default || m),
3820
} as const

packages/nuxt-cli/bin/nuxi.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
import inspector from 'node:inspector'
43
import nodeModule from 'node:module'
54
import { homedir } from 'node:os'
65
import { join } from 'node:path'
@@ -42,7 +41,7 @@ if (
4241
process.argv.includes('--profile')
4342
|| process.argv.some(a => a.startsWith('--profile='))
4443
) {
45-
const session = new inspector.Session()
44+
const session = new (process.getBuiltinModule('node:inspector').Session)()
4645
session.connect()
4746

4847
try {

0 commit comments

Comments
 (0)