Skip to content

Commit 4ba24d5

Browse files
refactor: use node prefix (#9)
1 parent d82d7f0 commit 4ba24d5

34 files changed

+60
-60
lines changed

src/@types/module.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'module';
1+
import 'node:module';
22

33
declare global {
44
namespace NodeJS {
@@ -8,7 +8,7 @@ declare global {
88
}
99
}
1010

11-
declare module 'module' {
11+
declare module 'node:module' {
1212
// https://nodejs.org/api/module.html#loadurl-context-nextload
1313
interface LoadHookContext {
1414
importAttributes: ImportAssertions;

src/cjs/api/global-require-patch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Module from 'module';
1+
import Module from 'node:module';
22
import { extensions } from './module-extensions.js';
33
import { resolveFilename } from './module-resolve-filename.js';
44

src/cjs/api/module-extensions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from 'fs';
2-
import Module from 'module';
1+
import fs from 'node:fs';
2+
import Module from 'node:module';
33
import { createFilesMatcher } from 'get-tsconfig';
44
import type { TransformOptions } from 'esbuild';
55
import { transformSync } from '../../utils/transform/index.js';

src/cjs/api/module-resolve-filename.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path';
2-
import Module from 'module';
1+
import path from 'node:path';
2+
import Module from 'node:module';
33
import { createPathsMatcher } from 'get-tsconfig';
44
import { resolveTsPath } from '../../utils/resolve-ts-path.js';
55
import type { NodeError } from '../../types.js';

src/cjs/api/require.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import { fileURLToPath } from 'node:url';
33
import { register } from './global-require-patch.js';
44
import { resolveFilename } from './module-resolve-filename.js';

src/cjs/api/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import {
33
getTsconfig,
44
parseTsconfig,

src/cli.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { constants as osConstants } from 'os';
2-
import type { ChildProcess, Serializable } from 'child_process';
3-
import type { Server } from 'net';
1+
import { constants as osConstants } from 'node:os';
2+
import type { ChildProcess, Serializable } from 'node:child_process';
3+
import type { Server } from 'node:net';
44
import { cli } from 'cleye';
55
import {
66
transformSync as esbuildTransformSync,

src/esm/hook/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { GlobalPreloadHook, InitializeHook } from 'module';
1+
import type { GlobalPreloadHook, InitializeHook } from 'node:module';
22

33
export const initialize: InitializeHook = async (data) => {
44
if (!data) {

src/esm/hook/load.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { fileURLToPath } from 'url';
2-
import type { LoadHook } from 'module';
1+
import { fileURLToPath } from 'node:url';
2+
import type { LoadHook } from 'node:module';
33
import type { TransformOptions } from 'esbuild';
44
import { transform } from '../../utils/transform/index.js';
55
import { transformDynamicImport } from '../../utils/transform/transform-dynamic-import.js';

src/esm/hook/package-json.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from 'fs';
2-
import { fileURLToPath } from 'url';
1+
import fs from 'node:fs';
2+
import { fileURLToPath } from 'node:url';
33
import type { PackageJson } from 'type-fest';
44

55
const packageJsonCache = new Map<string, PackageJson | undefined>();

src/esm/hook/resolve.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import path from 'path';
2-
import { pathToFileURL } from 'url';
1+
import path from 'node:path';
2+
import { pathToFileURL } from 'node:url';
33
import type {
44
ResolveFnOutput, ResolveHookContext,
5-
} from 'module';
5+
} from 'node:module';
66
import { resolveTsPath } from '../../utils/resolve-ts-path.js';
77
import type { NodeError } from '../../types.js';
88
import { isRelativePathPattern } from '../../utils/is-relative-path-pattern.js';

src/esm/hook/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path';
2-
import type { ModuleFormat } from 'module';
1+
import path from 'node:path';
2+
import type { ModuleFormat } from 'node:module';
33
import {
44
getTsconfig,
55
parseTsconfig,

src/patch-repl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import repl, { type REPLServer, type REPLEval } from 'repl';
1+
import repl, { type REPLServer, type REPLEval } from 'node:repl';
22
import { transform } from 'esbuild';
33

44
const patchEval = (nodeRepl: REPLServer) => {

src/preflight.cts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { constants as osConstants } from 'os';
1+
import { constants as osConstants } from 'node:os';
22
import { isMainThread } from 'node:worker_threads';
33
import { connectingToServer } from './utils/ipc/client.js';
44
import './suppress-warnings.cjs';

src/repl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Deprecated: Delete entry-point in next major in favor of patch-repl.ts
22

3-
import repl, { type REPLEval } from 'repl';
3+
import repl, { type REPLEval } from 'node:repl';
44
import { version } from '../package.json';
55
import { transform } from './utils/transform/index.js';
66

src/run.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { StdioOptions } from 'child_process';
2-
import { pathToFileURL } from 'url';
1+
import type { StdioOptions } from 'node:child_process';
2+
import { pathToFileURL } from 'node:url';
33
import spawn from 'cross-spawn';
44
import { isFeatureSupported, moduleRegister } from './utils/node-features';
55

src/utils/ipc/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import net from 'net';
1+
import net from 'node:net';
22
import { getPipePath } from './get-pipe-path.js';
33

44
export type SendToParent = (data: Record<string, unknown>) => void;

src/utils/ipc/get-pipe-path.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import { tmpdir } from '../temporary-directory.js';
33
import { isWindows } from '../is-windows.js';
44

src/utils/ipc/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import net from 'net';
2-
import fs from 'fs';
1+
import net from 'node:net';
2+
import fs from 'node:fs';
33
import { tmpdir } from '../temporary-directory.js';
44
import { isWindows } from '../is-windows.js';
55
import { getPipePath } from './get-pipe-path.js';

src/utils/read-json-file.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from 'fs';
1+
import fs from 'node:fs';
22

33
export const readJsonFile = <JsonType>(
44
filePath: string,

src/utils/resolve-ts-path.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22

33
const tsExtensions: Record<string, string[]> = Object.create(null);
44
tsExtensions['.js'] = ['.ts', '.tsx', '.js', '.jsx'];

src/utils/sha1.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import crypto from 'crypto';
1+
import crypto from 'node:crypto';
22

33
export const sha1 = (data: string) => (
44
crypto

src/utils/temporary-directory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path';
2-
import os from 'os';
1+
import path from 'node:path';
2+
import os from 'node:os';
33

44
/**
55
* Cache directory is based on the user's identifier

src/utils/transform/cache.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import fs from 'fs';
2-
import path from 'path';
3-
import os from 'os';
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import os from 'node:os';
44
import { readJsonFile } from '../read-json-file.js';
55
import { tmpdir } from '../temporary-directory.js';
66
import type { Transformed } from './apply-transformers.js';

src/utils/transform/get-esbuild-options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import type { TransformOptions, TransformResult } from 'esbuild';
33
import type { SourceMap } from '@ampproject/remapping';
44

src/utils/transform/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { pathToFileURL } from 'url';
1+
import { pathToFileURL } from 'node:url';
22
import {
33
transform as esbuildTransform,
44
transformSync as esbuildTransformSync,

src/watch/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { ChildProcess } from 'child_process';
2-
import { fileURLToPath } from 'url';
3-
import { constants as osConstants } from 'os';
4-
import path from 'path';
1+
import type { ChildProcess } from 'node:child_process';
2+
import { fileURLToPath } from 'node:url';
3+
import { constants as osConstants } from 'node:os';
4+
import path from 'node:path';
55
import { command } from 'cleye';
66
import { watch } from 'chokidar';
77
import { lightMagenta, lightGreen, yellow } from 'kolorist';

tests/specs/api.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import { execaNode } from 'execa';
33
import { testSuite, expect } from 'manten';
44
import { createFixture } from 'fs-fixture';
@@ -114,11 +114,11 @@ export default testSuite(({ describe }, node: NodeApis) => {
114114
});
115115
});
116116

117-
describe('Module', ({ test }) => {
117+
describe('node:module', ({ test }) => {
118118
if (node.supports.moduleRegister) {
119119
test('module.register', async ({ onTestFinish }) => {
120120
const fixture = await createFixture({
121-
'package.json': JSON.stringify({ type: 'module' }),
121+
'package.json': JSON.stringify({ type: 'node:module' }),
122122
'module-register.mjs': `
123123
import { register } from 'node:module';
124124

tests/specs/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import { setTimeout } from 'timers/promises';
33
import { testSuite, expect } from 'manten';
44
import { createFixture } from 'fs-fixture';

tests/specs/loaders.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export default testSuite(({ describe }, node: NodeApis) => {
99
'package.json': JSON.stringify({ type: 'module' }),
1010

1111
'ts.ts': `
12-
import fs from 'fs';
12+
import fs from 'node:fs';
1313
1414
console.log(Boolean(fs) as unknown as string);
1515
`,
1616
'mts.mts': `
17-
import fs from 'fs';
17+
import fs from 'node:fs';
1818
1919
console.log(JSON.stringify([Boolean(fs) as unknown as string, import.meta.url]));
2020
`,
@@ -53,17 +53,17 @@ export default testSuite(({ describe }, node: NodeApis) => {
5353
'package.json': JSON.stringify({ type: 'commonjs' }),
5454

5555
'ts.ts': `
56-
import fs from 'fs';
56+
import fs from 'node:fs';
5757
5858
console.log(Boolean(fs) as unknown as string);
5959
`,
6060
'cts.cts': `
61-
import fs from 'fs';
61+
import fs from 'node:fs';
6262
6363
console.log(Boolean(fs) as unknown as string);
6464
`,
6565
'mts.mts': `
66-
import fs from 'fs';
66+
import fs from 'node:fs';
6767
6868
console.log(Boolean(fs) as unknown as string, import.meta.url);
6969
`,

tests/specs/smoke.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from 'path';
2-
import { pathToFileURL } from 'url';
1+
import path from 'node:path';
2+
import { pathToFileURL } from 'node:url';
33
import { testSuite, expect } from 'manten';
44
import { createFixture } from 'fs-fixture';
55
import outdent from 'outdent';
@@ -82,7 +82,7 @@ const sourcemap = {
8282
// Adding the dynamic import helps test the import transformation's source map
8383
test: (
8484
extension: string,
85-
) => `import('fs');\nconst { stack } = new Error(); const searchString = 'index.${extension}:SOURCEMAP_LINE'; assert(stack.includes(searchString), \`Expected \${searchString} in stack: \${stack}\`)`,
85+
) => `import('node:fs');\nconst { stack } = new Error(); const searchString = 'index.${extension}:SOURCEMAP_LINE'; assert(stack.includes(searchString), \`Expected \${searchString} in stack: \${stack}\`)`,
8686
tag: (
8787
strings: TemplateStringsArray,
8888
...values: string[]

tests/specs/watch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import path from 'path';
1+
import path from 'node:path';
22
import { setTimeout } from 'timers/promises';
33
import { testSuite, expect } from 'manten';
44
import { createFixture } from 'fs-fixture';

tests/utils/pty-shell/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { setTimeout } from 'timers/promises';
2-
import { fileURLToPath } from 'url';
2+
import { fileURLToPath } from 'node:url';
33
import { execaNode, type NodeOptions } from 'execa';
44
import stripAnsi from 'strip-ansi';
55
import split from 'split2';

tests/utils/tsx.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fileURLToPath } from 'url';
1+
import { fileURLToPath } from 'node:url';
22
import { execaNode, type NodeOptions } from 'execa';
33
import getNode from 'get-node';
44
import {

0 commit comments

Comments
 (0)