Skip to content

Commit

Permalink
refactor: use node prefix (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored May 1, 2024
1 parent d82d7f0 commit 4ba24d5
Show file tree
Hide file tree
Showing 34 changed files with 60 additions and 60 deletions.
4 changes: 2 additions & 2 deletions src/@types/module.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'module';
import 'node:module';

declare global {
namespace NodeJS {
Expand All @@ -8,7 +8,7 @@ declare global {
}
}

declare module 'module' {
declare module 'node:module' {
// https://nodejs.org/api/module.html#loadurl-context-nextload
interface LoadHookContext {
importAttributes: ImportAssertions;
Expand Down
2 changes: 1 addition & 1 deletion src/cjs/api/global-require-patch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Module from 'module';
import Module from 'node:module';
import { extensions } from './module-extensions.js';
import { resolveFilename } from './module-resolve-filename.js';

Expand Down
4 changes: 2 additions & 2 deletions src/cjs/api/module-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import Module from 'module';
import fs from 'node:fs';
import Module from 'node:module';
import { createFilesMatcher } from 'get-tsconfig';
import type { TransformOptions } from 'esbuild';
import { transformSync } from '../../utils/transform/index.js';
Expand Down
4 changes: 2 additions & 2 deletions src/cjs/api/module-resolve-filename.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import Module from 'module';
import path from 'node:path';
import Module from 'node:module';
import { createPathsMatcher } from 'get-tsconfig';
import { resolveTsPath } from '../../utils/resolve-ts-path.js';
import type { NodeError } from '../../types.js';
Expand Down
2 changes: 1 addition & 1 deletion src/cjs/api/require.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { register } from './global-require-patch.js';
import { resolveFilename } from './module-resolve-filename.js';
Expand Down
2 changes: 1 addition & 1 deletion src/cjs/api/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import {
getTsconfig,
parseTsconfig,
Expand Down
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { constants as osConstants } from 'os';
import type { ChildProcess, Serializable } from 'child_process';
import type { Server } from 'net';
import { constants as osConstants } from 'node:os';
import type { ChildProcess, Serializable } from 'node:child_process';
import type { Server } from 'node:net';
import { cli } from 'cleye';
import {
transformSync as esbuildTransformSync,
Expand Down
2 changes: 1 addition & 1 deletion src/esm/hook/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GlobalPreloadHook, InitializeHook } from 'module';
import type { GlobalPreloadHook, InitializeHook } from 'node:module';

export const initialize: InitializeHook = async (data) => {
if (!data) {
Expand Down
4 changes: 2 additions & 2 deletions src/esm/hook/load.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fileURLToPath } from 'url';
import type { LoadHook } from 'module';
import { fileURLToPath } from 'node:url';
import type { LoadHook } from 'node:module';
import type { TransformOptions } from 'esbuild';
import { transform } from '../../utils/transform/index.js';
import { transformDynamicImport } from '../../utils/transform/transform-dynamic-import.js';
Expand Down
4 changes: 2 additions & 2 deletions src/esm/hook/package-json.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import { fileURLToPath } from 'url';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
import type { PackageJson } from 'type-fest';

const packageJsonCache = new Map<string, PackageJson | undefined>();
Expand Down
6 changes: 3 additions & 3 deletions src/esm/hook/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import { pathToFileURL } from 'url';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import type {
ResolveFnOutput, ResolveHookContext,
} from 'module';
} from 'node:module';
import { resolveTsPath } from '../../utils/resolve-ts-path.js';
import type { NodeError } from '../../types.js';
import { isRelativePathPattern } from '../../utils/is-relative-path-pattern.js';
Expand Down
4 changes: 2 additions & 2 deletions src/esm/hook/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import type { ModuleFormat } from 'module';
import path from 'node:path';
import type { ModuleFormat } from 'node:module';
import {
getTsconfig,
parseTsconfig,
Expand Down
2 changes: 1 addition & 1 deletion src/patch-repl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import repl, { type REPLServer, type REPLEval } from 'repl';
import repl, { type REPLServer, type REPLEval } from 'node:repl';
import { transform } from 'esbuild';

const patchEval = (nodeRepl: REPLServer) => {
Expand Down
2 changes: 1 addition & 1 deletion src/preflight.cts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { constants as osConstants } from 'os';
import { constants as osConstants } from 'node:os';
import { isMainThread } from 'node:worker_threads';
import { connectingToServer } from './utils/ipc/client.js';
import './suppress-warnings.cjs';
Expand Down
2 changes: 1 addition & 1 deletion src/repl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Deprecated: Delete entry-point in next major in favor of patch-repl.ts

import repl, { type REPLEval } from 'repl';
import repl, { type REPLEval } from 'node:repl';
import { version } from '../package.json';
import { transform } from './utils/transform/index.js';

Expand Down
4 changes: 2 additions & 2 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { StdioOptions } from 'child_process';
import { pathToFileURL } from 'url';
import type { StdioOptions } from 'node:child_process';
import { pathToFileURL } from 'node:url';
import spawn from 'cross-spawn';
import { isFeatureSupported, moduleRegister } from './utils/node-features';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/ipc/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import net from 'net';
import net from 'node:net';
import { getPipePath } from './get-pipe-path.js';

export type SendToParent = (data: Record<string, unknown>) => void;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ipc/get-pipe-path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { tmpdir } from '../temporary-directory.js';
import { isWindows } from '../is-windows.js';

Expand Down
4 changes: 2 additions & 2 deletions src/utils/ipc/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import net from 'net';
import fs from 'fs';
import net from 'node:net';
import fs from 'node:fs';
import { tmpdir } from '../temporary-directory.js';
import { isWindows } from '../is-windows.js';
import { getPipePath } from './get-pipe-path.js';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/read-json-file.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from 'fs';
import fs from 'node:fs';

export const readJsonFile = <JsonType>(
filePath: string,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/resolve-ts-path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';

const tsExtensions: Record<string, string[]> = Object.create(null);
tsExtensions['.js'] = ['.ts', '.tsx', '.js', '.jsx'];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/sha1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import crypto from 'crypto';
import crypto from 'node:crypto';

export const sha1 = (data: string) => (
crypto
Expand Down
4 changes: 2 additions & 2 deletions src/utils/temporary-directory.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import os from 'os';
import path from 'node:path';
import os from 'node:os';

/**
* Cache directory is based on the user's identifier
Expand Down
6 changes: 3 additions & 3 deletions src/utils/transform/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import { readJsonFile } from '../read-json-file.js';
import { tmpdir } from '../temporary-directory.js';
import type { Transformed } from './apply-transformers.js';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/transform/get-esbuild-options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import type { TransformOptions, TransformResult } from 'esbuild';
import type { SourceMap } from '@ampproject/remapping';

Expand Down
2 changes: 1 addition & 1 deletion src/utils/transform/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pathToFileURL } from 'url';
import { pathToFileURL } from 'node:url';
import {
transform as esbuildTransform,
transformSync as esbuildTransformSync,
Expand Down
8 changes: 4 additions & 4 deletions src/watch/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { ChildProcess } from 'child_process';
import { fileURLToPath } from 'url';
import { constants as osConstants } from 'os';
import path from 'path';
import type { ChildProcess } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { constants as osConstants } from 'node:os';
import path from 'node:path';
import { command } from 'cleye';
import { watch } from 'chokidar';
import { lightMagenta, lightGreen, yellow } from 'kolorist';
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { execaNode } from 'execa';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
Expand Down Expand Up @@ -114,11 +114,11 @@ export default testSuite(({ describe }, node: NodeApis) => {
});
});

describe('Module', ({ test }) => {
describe('node:module', ({ test }) => {
if (node.supports.moduleRegister) {
test('module.register', async ({ onTestFinish }) => {
const fixture = await createFixture({
'package.json': JSON.stringify({ type: 'module' }),
'package.json': JSON.stringify({ type: 'node:module' }),
'module-register.mjs': `
import { register } from 'node:module';
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { setTimeout } from 'timers/promises';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
Expand Down
10 changes: 5 additions & 5 deletions tests/specs/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ export default testSuite(({ describe }, node: NodeApis) => {
'package.json': JSON.stringify({ type: 'module' }),

'ts.ts': `
import fs from 'fs';
import fs from 'node:fs';
console.log(Boolean(fs) as unknown as string);
`,
'mts.mts': `
import fs from 'fs';
import fs from 'node:fs';
console.log(JSON.stringify([Boolean(fs) as unknown as string, import.meta.url]));
`,
Expand Down Expand Up @@ -53,17 +53,17 @@ export default testSuite(({ describe }, node: NodeApis) => {
'package.json': JSON.stringify({ type: 'commonjs' }),

'ts.ts': `
import fs from 'fs';
import fs from 'node:fs';
console.log(Boolean(fs) as unknown as string);
`,
'cts.cts': `
import fs from 'fs';
import fs from 'node:fs';
console.log(Boolean(fs) as unknown as string);
`,
'mts.mts': `
import fs from 'fs';
import fs from 'node:fs';
console.log(Boolean(fs) as unknown as string, import.meta.url);
`,
Expand Down
6 changes: 3 additions & 3 deletions tests/specs/smoke.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { pathToFileURL } from 'url';
import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import outdent from 'outdent';
Expand Down Expand Up @@ -82,7 +82,7 @@ const sourcemap = {
// Adding the dynamic import helps test the import transformation's source map
test: (
extension: string,
) => `import('fs');\nconst { stack } = new Error(); const searchString = 'index.${extension}:SOURCEMAP_LINE'; assert(stack.includes(searchString), \`Expected \${searchString} in stack: \${stack}\`)`,
) => `import('node:fs');\nconst { stack } = new Error(); const searchString = 'index.${extension}:SOURCEMAP_LINE'; assert(stack.includes(searchString), \`Expected \${searchString} in stack: \${stack}\`)`,
tag: (
strings: TemplateStringsArray,
...values: string[]
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/watch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';
import { setTimeout } from 'timers/promises';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/pty-shell/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setTimeout } from 'timers/promises';
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { execaNode, type NodeOptions } from 'execa';
import stripAnsi from 'strip-ansi';
import split from 'split2';
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/tsx.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fileURLToPath } from 'url';
import { fileURLToPath } from 'node:url';
import { execaNode, type NodeOptions } from 'execa';
import getNode from 'get-node';
import {
Expand Down

0 comments on commit 4ba24d5

Please sign in to comment.