Skip to content

Commit

Permalink
refactor: explicit imports with extension (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Feb 6, 2025
1 parent d62cf31 commit 5fcc6ff
Show file tree
Hide file tree
Showing 101 changed files with 316 additions and 295 deletions.
2 changes: 1 addition & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { resolvePathSync, type ResolveOptions } from "mlly";
import type { Preset, Environment, CreateEnvOptions } from "../lib/index.d.mts";
import nodeCompatPreset from "./presets/nodeless";
import nodeCompatPreset from "./presets/nodeless.ts";

/**
* Configure a target environment.
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { defineEnv } from "./env";
export { defineEnv } from "./env.ts";
2 changes: 1 addition & 1 deletion src/presets/node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { builtinModules } from "../runtime/node/module";
import { builtinModules } from "../runtime/node/module.ts";
import type { Preset } from "../../lib/index.d.mts";
import { version } from "../../package.json";

Expand Down
4 changes: 2 additions & 2 deletions src/presets/nodeless.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mapArrToVal } from "./utils";
import { builtinModules } from "../runtime/node/module";
import { mapArrToVal } from "./utils.ts";
import { builtinModules } from "../runtime/node/module.ts";
import type { Preset } from "../../lib/index.d.mts";
import { version } from "../../package.json";

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/_internal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HeadersObject } from "./types";
import type { HeadersObject } from "./types.ts";

/*@__NO_SIDE_EFFECTS__*/
export function rawHeaders(headers: HeadersObject) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import type nodeAssert from "node:assert";

import { isEqual as _ohashIsEqual } from "ohash";
import { notImplementedClass } from "../_internal/utils";
import { notImplementedClass } from "../_internal/utils.ts";

// TODO: Implement Error classes
const ERR_AMBIGUOUS_ARGUMENT = Error;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/assert/strict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
notStrictEqual as notEqual,
deepStrictEqual,
deepStrictEqual as deepEqual,
} from "../assert";
} from "../assert.ts";

export {
AssertionError,
Expand All @@ -44,7 +44,7 @@ export {
notStrictEqual as notEqual,
deepStrictEqual,
deepStrictEqual as deepEqual,
} from "../assert";
} from "../assert.ts";

export default Object.assign(ok, {
AssertionError,
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/node/async_hooks.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// https://nodejs.org/api/events.html
import type asyncHooks from "node:async_hooks";

import { AsyncLocalStorage } from "./internal/async_hooks/async-local-storage";
import { AsyncResource } from "./internal/async_hooks/async-resource";
import { AsyncLocalStorage } from "./internal/async_hooks/async-local-storage.ts";
import { AsyncResource } from "./internal/async_hooks/async-resource.ts";

import * as asyncHook from "./internal/async_hooks/async-hook";
import * as asyncHook from "./internal/async_hooks/async-hook.ts";

export { AsyncLocalStorage } from "./internal/async_hooks/async-local-storage";
export { AsyncResource } from "./internal/async_hooks/async-resource";
export { AsyncLocalStorage } from "./internal/async_hooks/async-local-storage.ts";
export { AsyncResource } from "./internal/async_hooks/async-resource.ts";

export * from "./internal/async_hooks/async-hook";
export * from "./internal/async_hooks/async-hook.ts";

export default {
AsyncLocalStorage,
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/node/buffer.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// https://nodejs.org/api/buffer.html
import type buffer from "node:buffer";
import { notImplemented } from "../_internal/utils";
import { notImplemented } from "../_internal/utils.ts";
import {
Buffer as _Buffer,
kMaxLength,
INSPECT_MAX_BYTES,
SlowBuffer,
} from "./internal/buffer/buffer";
import { File } from "./internal/buffer/file";
} from "./internal/buffer/buffer.ts";
import { File } from "./internal/buffer/file.ts";

export {
kMaxLength,
INSPECT_MAX_BYTES,
SlowBuffer,
} from "./internal/buffer/buffer";
} from "./internal/buffer/buffer.ts";

export const Buffer = globalThis.Buffer || _Buffer;

export { File } from "./internal/buffer/file";
export { File } from "./internal/buffer/file.ts";

// @ts-expect-eerror https://github.com/unjs/unenv/issues/64
export const Blob = globalThis.Blob as unknown as typeof buffer.Blob;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/child_process.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { notImplemented, notImplementedClass } from "../_internal/utils";
import { notImplemented, notImplementedClass } from "../_internal/utils.ts";
import type child_process from "node:child_process";

export const ChildProcess: typeof child_process.ChildProcess =
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Reference: https://github.com/nodejs/node/blob/main/lib/internal/cluster/primary.js
import mock from "../mock/proxy";
import { notImplemented } from "../_internal/utils";
import mock from "../mock/proxy.ts";
import { notImplemented } from "../_internal/utils.ts";
import type nodeCluster from "node:cluster";
import type {
Cluster as NodeCluster,
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/node/console.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type console from "node:console";
import { Writable } from "node:stream";
import mock from "../mock/proxy";
import noop from "../mock/noop";
import { notImplemented } from "../_internal/utils";
import mock from "../mock/proxy.ts";
import noop from "../mock/noop.ts";
import { notImplemented } from "../_internal/utils.ts";

const _console = globalThis.console;

Expand Down Expand Up @@ -49,7 +49,7 @@ export const timeStamp: typeof console.timeStamp = _console?.timeStamp ?? noop;
export const Console: typeof console.Console =
_console?.Console ?? mock.__createMock__("console.Console");

export { default as _times } from "../mock/proxy";
export { default as _times } from "../mock/proxy.ts";

export function context() {
// TODO: Should be Console with all the methods
Expand All @@ -59,7 +59,7 @@ export function context() {
export {
default as _stdoutErrorHandler,
default as _stderrErrorHandler,
} from "../mock/noop";
} from "../mock/noop.ts";

export default {
assert,
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/node/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Mostly taken from: https://github.com/nodejs/node/blob/main/typings/internalBinding/constants.d.ts

import type constants from "node:constants";
import * as os from "./internal/constants/os";
import * as fs from "./internal/constants/fs";
import * as crypto from "./internal/constants/crypto";
import * as os from "./internal/constants/os.ts";
import * as fs from "./internal/constants/fs.ts";
import * as crypto from "./internal/constants/crypto.ts";

export * from "./internal/constants/os";
export * from "./internal/constants/fs";
export * from "./internal/constants/crypto";
export * from "./internal/constants/os.ts";
export * from "./internal/constants/fs.ts";
export * from "./internal/constants/crypto.ts";

export default <typeof constants>{
...crypto,
Expand Down
12 changes: 6 additions & 6 deletions src/runtime/node/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type nodeCrypto from "node:crypto";

import * as web from "./internal/crypto/web";
import * as node from "./internal/crypto/node";
import constants from "./internal/crypto/constants";
import * as web from "./internal/crypto/web.ts";
import * as node from "./internal/crypto/node.ts";
import constants from "./internal/crypto/constants.ts";

export * from "./internal/crypto/web";
export * from "./internal/crypto/node";
export { default as constants } from "./internal/crypto/constants";
export * from "./internal/crypto/web.ts";
export * from "./internal/crypto/node.ts";
export { default as constants } from "./internal/crypto/constants.ts";

export default {
...web,
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/node/dgram.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import noop from "../mock/noop";
import noop from "../mock/noop.ts";
import type dgram from "node:dgram";
import { Socket } from "./internal/dgram/socket";
import { Socket } from "./internal/dgram/socket.ts";

export { Socket } from "./internal/dgram/socket";
export { Socket } from "./internal/dgram/socket.ts";

export const _createSocketHandle = noop;

Expand Down
9 changes: 6 additions & 3 deletions src/runtime/node/diagnostics_channel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import type diagnostics_channel from "node:diagnostics_channel";
import { Channel, getChannels } from "./internal/diagnostics_channel/channel";
import { TracingChannel } from "./internal/diagnostics_channel/tracing-channel";
import {
Channel,
getChannels,
} from "./internal/diagnostics_channel/channel.ts";
import { TracingChannel } from "./internal/diagnostics_channel/tracing-channel.ts";

export { Channel } from "./internal/diagnostics_channel/channel";
export { Channel } from "./internal/diagnostics_channel/channel.ts";

export const channel: typeof diagnostics_channel.channel = function (name) {
const channels = getChannels();
Expand Down
14 changes: 7 additions & 7 deletions src/runtime/node/dns.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import noop from "../mock/noop";
import mock from "../mock/proxy";
import { notImplemented, notImplementedAsync } from "../_internal/utils";
import noop from "../mock/noop.ts";
import mock from "../mock/proxy.ts";
import { notImplemented, notImplementedAsync } from "../_internal/utils.ts";
import type dns from "node:dns";
import promises from "./dns/promises";
import * as constants from "./internal/dns/constants";
import promises from "./dns/promises.ts";
import * as constants from "./internal/dns/constants.ts";

export * from "./internal/dns/constants";
export * as promises from "./dns/promises";
export * from "./internal/dns/constants.ts";
export * as promises from "./dns/promises.ts";

export const Resolver: typeof dns.Resolver =
mock.__createMock__("dns.Resolver");
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/node/dns/promises.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import noop from "../../mock/noop";
import mock from "../../mock/proxy";
import { notImplemented, notImplementedAsync } from "../../_internal/utils";
import noop from "../../mock/noop.ts";
import mock from "../../mock/proxy.ts";
import { notImplemented, notImplementedAsync } from "../../_internal/utils.ts";
import type dns from "node:dns/promises";
import * as constants from "../internal/dns/constants";
export * from "../internal/dns/constants";
import * as constants from "../internal/dns/constants.ts";
export * from "../internal/dns/constants.ts";

export const Resolver: typeof dns.Resolver =
mock.__createMock__("dns.Resolver");
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/domain.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type domain from "node:domain";
import { Domain } from "./internal/domain/domain";
import { Domain } from "./internal/domain/domain.ts";

export { Domain } from "./internal/domain/domain";
export { Domain } from "./internal/domain/domain.ts";

export const create: typeof domain.create = function () {
return new Domain();
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// https://nodejs.org/api/events.html
import type nodeEvents from "node:events";

import { _EventEmitter } from "./internal/events/events";
import { _EventEmitter } from "./internal/events/events.ts";

export {
_EventEmitter as EventEmitter,
Expand All @@ -11,7 +11,7 @@ export {
getMaxListeners,
on,
once,
} from "./internal/events/events";
} from "./internal/events/events.ts";

export const usingDomains = _EventEmitter.usingDomains;
export const captureRejectionSymbol = _EventEmitter.captureRejectionSymbol;
Expand Down
14 changes: 7 additions & 7 deletions src/runtime/node/fs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// https://nodejs.org/api/fs.html
import type nodeFS from "node:fs";

import * as _classes from "./internal/fs/classes";
import * as _constants from "./internal/fs/constants";
import * as _fs from "./internal/fs/fs";
import * as _classes from "./internal/fs/classes.ts";
import * as _constants from "./internal/fs/constants.ts";
import * as _fs from "./internal/fs/fs.ts";

import * as _promises from "./internal/fs/promises";
import * as _promises from "./internal/fs/promises.ts";

export * from "./internal/fs/classes";
export * from "./internal/fs/constants";
export * from "./internal/fs/fs";
export * from "./internal/fs/classes.ts";
export * from "./internal/fs/constants.ts";
export * from "./internal/fs/fs.ts";

export const promises = _promises;

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/fs/promises.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type fsp from "node:fs/promises";

import * as _promises from "../internal/fs/promises";
import * as _promises from "../internal/fs/promises.ts";

export * from "../internal/fs/promises";
export * from "../internal/fs/promises.ts";

export default <typeof fsp>{
..._promises,
Expand Down
16 changes: 8 additions & 8 deletions src/runtime/node/http.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// https://nodejs.org/api/http.html
import type http from "node:http";
import { notImplemented, notImplementedClass } from "../_internal/utils";
import mock from "../mock/proxy";
import * as consts from "./internal/http/consts";
import { IncomingMessage } from "./internal/http/request";
import { ServerResponse } from "./internal/http/response";
import { notImplemented, notImplementedClass } from "../_internal/utils.ts";
import mock from "../mock/proxy.ts";
import * as consts from "./internal/http/consts.ts";
import { IncomingMessage } from "./internal/http/request.ts";
import { ServerResponse } from "./internal/http/response.ts";

export * from "./internal/http/consts";
export * from "./internal/http/request";
export * from "./internal/http/response";
export * from "./internal/http/consts.ts";
export * from "./internal/http/request.ts";
export * from "./internal/http/response.ts";

export const createServer =
/*@__PURE__*/ notImplemented<typeof http.createServer>("http.createServer");
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/node/http2.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import mock from "../mock/proxy";
import mock from "../mock/proxy.ts";
import type http2 from "node:http2";
import { notImplemented } from "../_internal/utils";
import { constants } from "./internal/http2/constants";
import { notImplemented } from "../_internal/utils.ts";
import { constants } from "./internal/http2/constants.ts";

export { constants } from "./internal/http2/constants";
export { constants } from "./internal/http2/constants.ts";

export const createSecureServer = /*@__PURE__*/ notImplemented<
typeof http2.createSecureServer
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/https.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// https://nodejs.org/api/https.html
import type nodeHttps from "node:https";
import { notImplemented, notImplementedClass } from "../_internal/utils";
import mock from "../mock/proxy";
import { notImplemented, notImplementedClass } from "../_internal/utils.ts";
import mock from "../mock/proxy.ts";

export const Server: typeof nodeHttps.Server =
/*@__PURE__*/ notImplementedClass("https.Server");
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/inspector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://nodejs.org/api/inspector.html
import noop from "../mock/noop";
import mock from "../mock/proxy";
import noop from "../mock/noop.ts";
import mock from "../mock/proxy.ts";
import type inspector from "node:inspector";

export const close: typeof inspector.close = noop;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/node/internal/async_hooks/async-resource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type asyncHooks from "node:async_hooks";
import { executionAsyncId } from "./async-hook";
import { executionAsyncId } from "./async-hook.ts";

// https://nodejs.org/api/async_context.html#class-asyncresource

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/node/internal/buffer/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* @license MIT
*/

import * as base64 from "./base64";
import * as ieee754 from "./ieee754";
import * as base64 from "./base64.ts";
import * as ieee754 from "./ieee754.ts";

const customInspectSymbol =
typeof Symbol === "function" && typeof Symbol["for"] === "function"
Expand Down
Loading

0 comments on commit 5fcc6ff

Please sign in to comment.