From 8ae92acb6e63d4708fab0f0558dbb64f5ed8414f Mon Sep 17 00:00:00 2001 From: irmo Date: Thu, 6 Feb 2025 15:04:37 +0800 Subject: [PATCH 1/2] fix: replace `import.meta.resolve` with `require.resolve` for Node compatibility --- tools/tsp-client/src/utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/tsp-client/src/utils.ts b/tools/tsp-client/src/utils.ts index 20766ad2349..31376a939c3 100644 --- a/tools/tsp-client/src/utils.ts +++ b/tools/tsp-client/src/utils.ts @@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url"; import { Logger } from "./log.js"; import { TspLocation } from "./typespec.js"; import { normalizeDirectory } from "./fs.js"; +import { createRequire } from "module"; export function formatAdditionalDirectories(additionalDirectories?: string[]): string { let additionalDirOutput = "\n"; @@ -61,7 +62,8 @@ export function getServiceDir(configYaml: any, emitter: string): string { */ export async function getPathToDependency(dependency: string): Promise { // Example: /home/user/foo/node_modules/@autorest/bar/dist/index.js - const entrypoint = fileURLToPath(import.meta.resolve(dependency)); + const require = createRequire(import.meta.url); + const entrypoint = require.resolve(dependency); // Walk up directory tree to first folder containing "package.json" let currentDir = dirname(entrypoint); From 0ec3c9d80088bace7bd9f6b5ff2d7853f4cdb1d4 Mon Sep 17 00:00:00 2001 From: irmo Date: Thu, 6 Feb 2025 15:10:25 +0800 Subject: [PATCH 2/2] Remove FileURLToPath Remove useless import --- tools/tsp-client/src/utils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/tsp-client/src/utils.ts b/tools/tsp-client/src/utils.ts index 31376a939c3..9205d8615a6 100644 --- a/tools/tsp-client/src/utils.ts +++ b/tools/tsp-client/src/utils.ts @@ -2,7 +2,6 @@ import { joinPaths, normalizeSlashes } from "@typespec/compiler"; import { randomUUID } from "node:crypto"; import { access, constants, mkdir, writeFile } from "node:fs/promises"; import { dirname, join } from "node:path"; -import { fileURLToPath } from "node:url"; import { Logger } from "./log.js"; import { TspLocation } from "./typespec.js"; import { normalizeDirectory } from "./fs.js";