Skip to content

Commit

Permalink
refactor: rename getNodejsCompatMode() to getNodejsCompat()
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin committed Sep 25, 2024
1 parent c58dd21 commit 1bad3bd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions packages/miniflare/src/plugins/core/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { z } from "zod";
import { Worker_Module } from "../../runtime";
import { globsToRegExps, MiniflareCoreError, PathSchema } from "../../shared";
import { MatcherRegExps, testRegExps } from "../../workers";
import { getNodeCompatMode, NodeJSCompatMode } from "./node-compat";
import { getNodeCompat, NodeJSCompatMode } from "./node-compat";
import type estree from "estree";

const SUGGEST_BUNDLE =
Expand Down Expand Up @@ -157,7 +157,7 @@ function getResolveErrorPrefix(referencingPath: string): string {

export class ModuleLocator {
readonly #compiledRules: CompiledModuleRule[];
readonly #nodejsCompat: NodeJSCompatMode;
readonly #nodejsCompatMode: NodeJSCompatMode;
readonly #visitedPaths = new Set<string>();
readonly modules: Worker_Module[] = [];

Expand All @@ -171,7 +171,7 @@ export class ModuleLocator {
// Implicit shallow-copy to avoid mutating argument
rules = rules.concat(DEFAULT_MODULE_RULES);
this.#compiledRules = compileModuleRules(rules);
this.#nodejsCompat = getNodeCompatMode(
this.#nodejsCompatMode = getNodeCompat(
compatibilityDate,
compatibilityFlags ?? []
).mode;
Expand Down Expand Up @@ -297,12 +297,12 @@ ${dim(modulesConfig)}`;
spec.startsWith("cloudflare:") ||
spec.startsWith("workerd:") ||
// Node.js compat v1 requires imports to be prefixed with `node:`
(this.#nodejsCompat === "v1" && spec.startsWith("node:")) ||
(this.#nodejsCompatMode === "v1" && spec.startsWith("node:")) ||
// Node.js compat modules and v2 can also handle non-prefixed imports
((this.#nodejsCompat === "v2" || isNodeJsCompatModule) &&
((this.#nodejsCompatMode === "v2" || isNodeJsCompatModule) &&
builtinModulesWithPrefix.includes(spec)) ||
// Async Local Storage mode (node_als) only deals with `node:async_hooks` imports
(this.#nodejsCompat === "als" && spec === "node:async_hooks") ||
(this.#nodejsCompatMode === "als" && spec === "node:async_hooks") ||
// Any "additional" external modules can be ignored
this.additionalModuleNames.includes(spec)
) {
Expand Down
2 changes: 1 addition & 1 deletion packages/miniflare/src/plugins/core/node-compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type NodeJSCompatMode = "legacy" | "als" | "v1" | "v2" | null;
* @param opts.nodeCompat Whether the legacy node_compat arg is being used
* @returns the mode and flags to indicate specific configuration for validating.
*/
export function getNodeCompatMode(
export function getNodeCompat(
compatibilityDate: string = "2000-01-01", // Default to some arbitrary old date
compatibilityFlags: string[],
opts?: {
Expand Down
2 changes: 1 addition & 1 deletion packages/miniflare/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export {
ProxyClient,
getFreshSourceMapSupport,
kCurrentWorker,
getNodeCompatMode,
getNodeCompat,
} from "./core";
export type {
CompiledModuleRule,
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/deployment-bundle/node-compat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getNodeCompatMode } from "miniflare";
import { getNodeCompat } from "miniflare";
import { UserError } from "../errors";
import { logger } from "../logger";
import type { NodeJSCompatMode } from "miniflare";
Expand Down Expand Up @@ -32,7 +32,7 @@ import type { NodeJSCompatMode } from "miniflare";
hasNodejsCompatFlag,
hasNodejsCompatV2Flag,
hasExperimentalNodejsCompatV2Flag,
} = getNodeCompatMode(compatibilityDateStr, compatibilityFlags, {
} = getNodeCompat(compatibilityDateStr, compatibilityFlags, {
nodeCompat: legacy,
});

Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/type-generation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from "node:fs";
import { basename, dirname, extname, join, relative, resolve } from "node:path";
import * as esmLexer from "es-module-lexer";
import { findUpSync } from "find-up";
import { getNodeCompatMode } from "miniflare";
import { getNodeCompat } from "miniflare";
import { findWranglerToml, readConfig } from "../config";
import { getEntry } from "../deployment-bundle/entry";
import { getVarsForDev } from "../dev/dev-vars";
Expand Down Expand Up @@ -92,7 +92,7 @@ export async function typesHandler(
const tsconfigPath =
config.tsconfig ?? join(dirname(configPath), "tsconfig.json");
const tsconfigTypes = readTsconfigTypes(tsconfigPath);
const mode = getNodeCompatMode(
const { mode } = getNodeCompat(
config.compatibility_date,
config.compatibility_flags,
{
Expand Down

0 comments on commit 1bad3bd

Please sign in to comment.