Skip to content

Commit 7d0a6a3

Browse files
n0mahdclaude
andcommitted
fix(server): bundle jsonc-parser's ESM build and import the package as before
Importing jsonc-parser/lib/esm/main.js got the bundle to start, but that build imports its own files without extensions, so the server no longer started from source under Node. The import is back to "jsonc-parser", which Node and the tests load as they did, and the bundle config points the bundler at the ESM build. Both the bundled server and the one run from source now start. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f790f5d commit 7d0a6a3

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎apps/server/src/skills/JsoncSettings.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@
1616
*/
1717
import * as Effect from "effect/Effect";
1818
import * as FileSystem from "effect/FileSystem";
19-
// The ESM build: the package's `main` is UMD, whose `require("./impl/format")` calls the server
20-
// bundler can't follow, so the bundled server fails to start.
21-
import {
22-
applyEdits,
23-
modify,
24-
parse,
25-
type FormattingOptions,
26-
type ParseError,
27-
} from "jsonc-parser/lib/esm/main.js";
19+
import { applyEdits, modify, parse, type FormattingOptions, type ParseError } from "jsonc-parser";
2820
import { writeFileStringAtomically } from "@t3tools/shared/atomicWrite";
2921

3022
/** Keys of objects, and positions in arrays. */

‎apps/server/vite.config.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import "vite-plus/test/config";
2+
import * as NodeModule from "node:module";
3+
24
import { defineConfig, mergeConfig } from "vite-plus";
35

46
import baseConfig from "../../vite.config.ts";
@@ -22,6 +24,13 @@ import {
2224
export { shouldBundleCliDependency };
2325

2426
const repoEnv = loadRepoEnv();
27+
28+
// jsonc-parser's `main` is UMD, whose `require("./impl/format")` calls the bundler can't follow,
29+
// so the bundle takes the package's ESM build. Node and the tests load the `main` entry as it is.
30+
const jsoncParserEsm = NodeModule.createRequire(import.meta.url)
31+
.resolve("jsonc-parser/package.json")
32+
.replace(/package\.json$/, "lib/esm/main.js");
33+
2534
const cliBuildChannel = /^[^-+]+-(?:nightly|preview)\./.test(packageJson.version)
2635
? "nightly"
2736
: "latest";
@@ -107,6 +116,7 @@ export default mergeConfig(
107116
neverBundle: (id: string) => isExternalCliDependency(id),
108117
onlyBundle: false,
109118
},
119+
alias: { "jsonc-parser": jsoncParserEsm },
110120
banner: {
111121
js: "#!/usr/bin/env node\n",
112122
},

0 commit comments

Comments
 (0)