Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,18 @@ const browserAliasPlugin = {

/**
* Node extension configuration
* Uses ESM format for native ES module support, following the pattern from
* https://github.com/microsoft/vscode-github-issue-notebooks
* @type {import('esbuild').BuildOptions}
*/
const nodeConfig = {
entryPoints: ["src/extension.ts"],
bundle: true,
format: "esm",
format: "cjs",
minify: production,
sourcemap: true,
platform: "neutral",
target: ["node22"],
sourcemap: !production,
sourcesContent: false,
platform: "node",
outfile: "dist/extension.js",
// Keep vscode external - provided by the VS Code extension host
// Keep prettier external - loaded dynamically at runtime
// Keep Node.js built-ins external - available in the extension host runtime
external: [
"vscode",
"prettier",
"fs",
"fs/promises",
"path",
"os",
"url",
"util",
"module",
"child_process",
],
external: ["vscode", "prettier"],
define: {
"process.env.EXTENSION_NAME": JSON.stringify(
`${extensionPackage.publisher}.${extensionPackage.name}`,
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"url": "https://github.com/prettier/prettier-vscode.git"
},
"license": "MIT",
"type": "module",
"bugs": {
"url": "https://github.com/prettier/prettier-vscode/issues"
},
Expand Down
4 changes: 3 additions & 1 deletion src/utils/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRequire } from "module";
import * as path from "path";
import { pathToFileURL } from "url";
import { PrettierOptions } from "../types.js";

/**
Expand All @@ -12,7 +13,8 @@ function resolveNodeModule(
): string | undefined {
try {
// Create a require function rooted at the parent directory
const require = createRequire(parent);
// On Windows, createRequire needs a file:// URL for ESM compatibility
const require = createRequire(pathToFileURL(parent).href);
return require.resolve(moduleName);
} catch {
return undefined;
Expand Down