@prosopo/config 3.3.5 → 3.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/.turbo/turbo-build$colon$cjs.log +3 -3
  2. package/.turbo/turbo-build$colon$tsc.log +4 -4
  3. package/.turbo/turbo-build.log +4 -4
  4. package/CHANGELOG.md +13 -0
  5. package/dist/cjs/vite/vite.test.config.cjs +3 -1
  6. package/dist/dependencies.test.d.ts +2 -0
  7. package/dist/dependencies.test.d.ts.map +1 -0
  8. package/dist/dependencies.test.js +160 -0
  9. package/dist/dependencies.test.js.map +1 -0
  10. package/dist/getDependencies.test.d.ts +2 -0
  11. package/dist/getDependencies.test.d.ts.map +1 -0
  12. package/dist/getDependencies.test.js +258 -0
  13. package/dist/getDependencies.test.js.map +1 -0
  14. package/dist/vite/bundleConfigs.test.d.ts +2 -0
  15. package/dist/vite/bundleConfigs.test.d.ts.map +1 -0
  16. package/dist/vite/bundleConfigs.test.js +252 -0
  17. package/dist/vite/bundleConfigs.test.js.map +1 -0
  18. package/dist/vite/configs.test.d.ts +2 -0
  19. package/dist/vite/configs.test.d.ts.map +1 -0
  20. package/dist/vite/configs.test.js +163 -0
  21. package/dist/vite/configs.test.js.map +1 -0
  22. package/dist/vite/plugins.test.d.ts +2 -0
  23. package/dist/vite/plugins.test.d.ts.map +1 -0
  24. package/dist/vite/plugins.test.js +232 -0
  25. package/dist/vite/plugins.test.js.map +1 -0
  26. package/dist/vite/translations.test.d.ts +2 -0
  27. package/dist/vite/translations.test.d.ts.map +1 -0
  28. package/dist/vite/translations.test.js +96 -0
  29. package/dist/vite/translations.test.js.map +1 -0
  30. package/dist/vite/vite.test.config.d.ts.map +1 -1
  31. package/dist/vite/vite.test.config.js +3 -1
  32. package/dist/vite/vite.test.config.js.map +1 -1
  33. package/package.json +4 -3
  34. package/src/dependencies.test.ts +249 -0
  35. package/src/getDependencies.test.ts +385 -0
  36. package/src/vite/bundleConfigs.test.ts +405 -0
  37. package/src/vite/configs.test.ts +217 -0
  38. package/src/vite/plugins.test.ts +348 -0
  39. package/src/vite/translations.test.ts +164 -0
  40. package/src/vite/vite.test.config.ts +5 -0
  41. package/tsconfig.tsbuildinfo +1 -1
  42. package/vite.test.config.ts +37 -0
@@ -0,0 +1,249 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import fs from "node:fs";
16
+ import os from "node:os";
17
+ import path from "node:path";
18
+ import { afterEach, beforeEach, describe, expect, it } from "vitest";
19
+ import {
20
+ filterDependencies,
21
+ getExternalsFromReferences,
22
+ getTsConfigs,
23
+ } from "./dependencies.js";
24
+
25
+ let root: string;
26
+
27
+ /** Write a tsconfig, and optionally a sibling package.json, under `root`. */
28
+ const writeProject = (
29
+ dir: string,
30
+ references: string[],
31
+ packageName?: string,
32
+ ): string => {
33
+ const absolute = path.join(root, dir);
34
+ fs.mkdirSync(absolute, { recursive: true });
35
+ const tsConfigPath = path.join(absolute, "tsconfig.json");
36
+ fs.writeFileSync(
37
+ tsConfigPath,
38
+ JSON.stringify({ references: references.map((p) => ({ path: p })) }),
39
+ );
40
+ if (packageName) {
41
+ fs.writeFileSync(
42
+ path.join(absolute, "package.json"),
43
+ JSON.stringify({ name: packageName }),
44
+ );
45
+ }
46
+ return tsConfigPath;
47
+ };
48
+
49
+ beforeEach(() => {
50
+ root = fs.mkdtempSync(path.join(os.tmpdir(), "prosopo-config-test-"));
51
+ });
52
+
53
+ afterEach(() => {
54
+ fs.rmSync(root, { recursive: true, force: true });
55
+ });
56
+
57
+ describe("getTsConfigs", () => {
58
+ it("returns just the starting config when it has no references", () => {
59
+ const entry = writeProject("a", []);
60
+ expect(getTsConfigs(entry)).toEqual([entry]);
61
+ });
62
+
63
+ it("returns nothing when the starting config is excluded and has no references", () => {
64
+ const entry = writeProject("a", []);
65
+ expect(getTsConfigs(entry, [], [], false)).toEqual([]);
66
+ });
67
+
68
+ it("walks references transitively", () => {
69
+ const c = writeProject("c", []);
70
+ const b = writeProject("b", ["../c"]);
71
+ const a = writeProject("a", ["../b"]);
72
+
73
+ expect(getTsConfigs(a, [/nothing-matches/], []).sort()).toEqual(
74
+ [a, b, c].sort(),
75
+ );
76
+ });
77
+
78
+ it("skips references matching an ignore pattern, and everything under them", () => {
79
+ writeProject("keep", []);
80
+ writeProject("skip", []);
81
+ const a = writeProject("a", ["../keep/", "../skip/"]);
82
+
83
+ expect(getTsConfigs(a, [/skip/], [])).toEqual([
84
+ a,
85
+ path.join(root, "keep", "tsconfig.json"),
86
+ ]);
87
+ });
88
+
89
+ it("builds the ignore expression from the stringified patterns, delimiters included", () => {
90
+ // `ignorePatterns.join("|")` calls `toString()` on each RegExp, so the
91
+ // enclosing slashes end up in the pattern. `/skip/` therefore matches
92
+ // the *path segment* "/skip/" rather than the bare word, which is why
93
+ // callers pass directory-shaped patterns.
94
+ writeProject("skip", []);
95
+ const a = writeProject("a", ["../skip"]);
96
+
97
+ // No trailing slash on the reference, so "/skip/" does not match and
98
+ // the reference is followed after all.
99
+ expect(getTsConfigs(a, [/skip/], [])).toHaveLength(2);
100
+ });
101
+
102
+ it("drops every reference when no ignore pattern is given", () => {
103
+ writeProject("b", []);
104
+ const a = writeProject("a", ["../b"]);
105
+ expect(getTsConfigs(a)).toEqual([a]);
106
+ });
107
+
108
+ it("appends tsconfig.json to a reference that names a directory", () => {
109
+ writeProject("b", []);
110
+ const a = writeProject("a", ["../b"]);
111
+ expect(getTsConfigs(a, [/\.\./], [])).toContain(
112
+ path.join(root, "b", "tsconfig.json"),
113
+ );
114
+ });
115
+
116
+ it("honours a reference that names a config file explicitly", () => {
117
+ fs.mkdirSync(path.join(root, "b"), { recursive: true });
118
+ const explicit = path.join(root, "b", "tsconfig.build.json");
119
+ fs.writeFileSync(explicit, JSON.stringify({ references: [] }));
120
+ const a = writeProject("a", ["../b/tsconfig.build.json"]);
121
+
122
+ expect(getTsConfigs(a, [/\.\./], [])).toContain(explicit);
123
+ });
124
+
125
+ it("does not loop forever on a reference cycle", () => {
126
+ // A cycle in the project graph would otherwise recurse until the stack
127
+ // blew, which is a build hang rather than a readable error.
128
+ const a = path.join(root, "a", "tsconfig.json");
129
+ const b = path.join(root, "b", "tsconfig.json");
130
+ writeProject("a", ["../b"]);
131
+ writeProject("b", ["../a"]);
132
+
133
+ expect(getTsConfigs(a, [/\.\./], []).sort()).toEqual([a, b].sort());
134
+ });
135
+
136
+ it("visits a diamond dependency only once", () => {
137
+ writeProject("d", []);
138
+ writeProject("b", ["../d"]);
139
+ writeProject("c", ["../d"]);
140
+ const a = writeProject("a", ["../b", "../c"]);
141
+
142
+ const result = getTsConfigs(a, [/\.\./], []);
143
+ expect(new Set(result).size).toBe(result.length);
144
+ expect(result).toHaveLength(4);
145
+ });
146
+
147
+ it("keeps configs that were already accumulated", () => {
148
+ const existing = "/already/seen/tsconfig.json";
149
+ const a = writeProject("a", []);
150
+ expect(getTsConfigs(a, [], [existing])).toEqual([existing, a]);
151
+ });
152
+
153
+ it("returns the accumulator untouched when the config was already seen", () => {
154
+ const a = writeProject("a", []);
155
+ expect(getTsConfigs(a, [], [a])).toEqual([a]);
156
+ });
157
+
158
+ it("throws for a config path that does not exist", () => {
159
+ expect(() => getTsConfigs(path.join(root, "missing.json"))).toThrow();
160
+ });
161
+
162
+ it("throws for a config that is not valid JSON", () => {
163
+ const broken = path.join(root, "broken.json");
164
+ fs.writeFileSync(broken, "{ not json");
165
+ expect(() => getTsConfigs(broken)).toThrow();
166
+ });
167
+ });
168
+
169
+ describe("getExternalsFromReferences", () => {
170
+ it("returns the package name of every referenced project", async () => {
171
+ writeProject("b", [], "@prosopo/b");
172
+ writeProject("c", [], "@prosopo/c");
173
+ const a = writeProject("a", ["../b", "../c"], "@prosopo/a");
174
+
175
+ // The starting project is excluded, so a package never externalises
176
+ // itself.
177
+ await expect(getExternalsFromReferences(a, [/\.\./])).resolves.toEqual([
178
+ "@prosopo/b",
179
+ "@prosopo/c",
180
+ ]);
181
+ });
182
+
183
+ it("returns nothing when there are no followed references", async () => {
184
+ const a = writeProject("a", [], "@prosopo/a");
185
+ await expect(getExternalsFromReferences(a)).resolves.toEqual([]);
186
+ });
187
+
188
+ it("rejects when a referenced project has no package.json", async () => {
189
+ writeProject("b", []);
190
+ const a = writeProject("a", ["../b"], "@prosopo/a");
191
+ await expect(getExternalsFromReferences(a, [/\.\./])).rejects.toBeDefined();
192
+ });
193
+ });
194
+
195
+ describe("filterDependencies", () => {
196
+ it("splits on the filter patterns, sorted", () => {
197
+ expect(
198
+ filterDependencies(["zod", "@prosopo/util", "axios"], ["@prosopo"]),
199
+ ).toEqual({
200
+ internal: ["axios", "zod"],
201
+ external: ["@prosopo/util"],
202
+ });
203
+ });
204
+
205
+ it("treats the filters as alternatives in a single expression", () => {
206
+ expect(
207
+ filterDependencies(["a-one", "b-two", "c-three"], ["one", "two"]),
208
+ ).toEqual({ internal: ["c-three"], external: ["a-one", "b-two"] });
209
+ });
210
+
211
+ it("deduplicates before splitting", () => {
212
+ expect(
213
+ filterDependencies(["zod", "zod", "zod"], ["nope"]).internal,
214
+ ).toEqual(["zod"]);
215
+ });
216
+
217
+ it("drops empty strings", () => {
218
+ // `npm ls` output can yield blank captures; an empty external pattern
219
+ // would otherwise match everything downstream.
220
+ expect(filterDependencies(["", "zod", ""], ["nope"])).toEqual({
221
+ internal: ["zod"],
222
+ external: [],
223
+ });
224
+ });
225
+
226
+ it("returns two empty lists for no dependencies", () => {
227
+ expect(filterDependencies([], ["@prosopo"])).toEqual({
228
+ internal: [],
229
+ external: [],
230
+ });
231
+ });
232
+
233
+ it("puts everything in external when a filter matches all", () => {
234
+ expect(filterDependencies(["a", "b"], [""]).external).toEqual(["a", "b"]);
235
+ });
236
+
237
+ it("puts everything in internal when no filter is supplied", () => {
238
+ // An empty filter list joins to an empty pattern, which matches
239
+ // everything — so this is the same all-external case, documented so
240
+ // the surprise is not discovered during a build.
241
+ expect(filterDependencies(["a", "b"], []).external).toEqual(["a", "b"]);
242
+ });
243
+
244
+ it("does not mutate the input", () => {
245
+ const deps = ["zod", "axios"];
246
+ filterDependencies(deps, ["zod"]);
247
+ expect(deps).toEqual(["zod", "axios"]);
248
+ });
249
+ });
@@ -0,0 +1,385 @@
1
+ // Copyright 2021-2026 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import type { ExecException } from "node:child_process";
16
+ import path from "node:path";
17
+ import { promisify } from "node:util";
18
+ import type { UserConfig } from "vite";
19
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
20
+
21
+ /** What `npm ls` handed back for a given command. */
22
+ interface ExecResult {
23
+ stdout: string;
24
+ stderr: string;
25
+ }
26
+
27
+ type ExecCallback = (
28
+ error: ExecException | null,
29
+ stdout: string,
30
+ stderr: string,
31
+ ) => void;
32
+
33
+ /** Commands seen, in order, so the tests can assert on what was run. */
34
+ let commands: string[] = [];
35
+ /** Queue of responses, consumed one per `exec` call. */
36
+ let responses: (ExecResult | Error)[] = [];
37
+
38
+ const fakeExec = (command: string, callback: ExecCallback): void => {
39
+ commands.push(command);
40
+ const next = responses.shift();
41
+ if (next === undefined) {
42
+ throw new Error(`unexpected exec: ${command}`);
43
+ }
44
+ if (next instanceof Error) {
45
+ callback(next, "", "");
46
+ return;
47
+ }
48
+ callback(null, next.stdout, next.stderr);
49
+ };
50
+
51
+ // `util.promisify` honours this symbol, which is how the real
52
+ // `child_process.exec` resolves to `{ stdout, stderr }` rather than to stdout
53
+ // alone. The mock has to provide it or the promisified call shape differs from
54
+ // production.
55
+ Object.defineProperty(fakeExec, promisify.custom, {
56
+ value: (command: string): Promise<ExecResult> =>
57
+ new Promise((resolve, reject) => {
58
+ fakeExec(command, (error, stdout, stderr) => {
59
+ if (error) {
60
+ reject(error);
61
+ } else {
62
+ resolve({ stdout, stderr });
63
+ }
64
+ });
65
+ }),
66
+ });
67
+
68
+ vi.mock("node:child_process", () => ({ default: { exec: fakeExec } }));
69
+
70
+ const { getDependencies } = await import("./dependencies.js");
71
+
72
+ beforeEach(() => {
73
+ commands = [];
74
+ responses = [];
75
+ });
76
+
77
+ afterEach(() => {
78
+ expect(responses).toEqual([]);
79
+ });
80
+
81
+ const ok = (stdout: string, stderr = ""): ExecResult => ({ stdout, stderr });
82
+
83
+ /** `util.promisify` reads stdout/stderr off the error for a failing exec. */
84
+ const failing = (stdout: string, stderr = ""): Error => {
85
+ const error: ExecException & { stdout?: string; stderr?: string } =
86
+ Object.assign(new Error("npm ls exited 1"), { stdout, stderr });
87
+ return error;
88
+ };
89
+
90
+ const TREE = [
91
+ "@prosopo/root@1.0.0 /repo",
92
+ "├─┬ mongodb@6.3.0",
93
+ "│ └── bson@6.2.0",
94
+ "└── zod@3.22.4",
95
+ ].join("\n");
96
+
97
+ describe("getDependencies", () => {
98
+ it("parses every package name out of the npm ls tree", async () => {
99
+ responses = [ok(TREE)];
100
+ const { dependencies } = await getDependencies();
101
+ expect(dependencies).toEqual(["mongodb", "bson", "zod"]);
102
+ });
103
+
104
+ it("does not treat the root package line as a dependency", async () => {
105
+ // The root line has no leading whitespace, which is what the regex keys
106
+ // off — a package must never externalise itself.
107
+ responses = [ok(TREE)];
108
+ const { dependencies } = await getDependencies();
109
+ expect(dependencies).not.toContain("@prosopo/root");
110
+ });
111
+
112
+ it("collects unmet optional peers separately", async () => {
113
+ responses = [
114
+ ok(
115
+ [
116
+ "│ ├── UNMET OPTIONAL DEPENDENCY bufferutil@^4.0.1",
117
+ "│ ├── UNMET OPTIONAL DEPENDENCY utf-8-validate@^5.0.2",
118
+ "└── zod@3.22.4",
119
+ ].join("\n"),
120
+ ),
121
+ ];
122
+ const { dependencies, optionalPeerDependencies } = await getDependencies();
123
+ expect(optionalPeerDependencies).toEqual(["bufferutil", "utf-8-validate"]);
124
+ expect(dependencies).toEqual(["zod"]);
125
+ });
126
+
127
+ it("deduplicates packages that appear all over the tree", async () => {
128
+ responses = [ok(["├── zod@3.22.4", "│ └── zod@3.22.4"].join("\n"))];
129
+ await expect(getDependencies()).resolves.toEqual({
130
+ dependencies: ["zod"],
131
+ optionalPeerDependencies: [],
132
+ });
133
+ });
134
+
135
+ it("returns empty lists for an empty tree", async () => {
136
+ responses = [ok("")];
137
+ await expect(getDependencies()).resolves.toEqual({
138
+ dependencies: [],
139
+ optionalPeerDependencies: [],
140
+ });
141
+ });
142
+
143
+ it("omits dev dependencies when asked for a production tree", async () => {
144
+ responses = [ok(TREE)];
145
+ await getDependencies(undefined, true);
146
+ expect(commands[0]).toContain("--omit=dev");
147
+ });
148
+
149
+ it("keeps dev dependencies otherwise", async () => {
150
+ responses = [ok(TREE)];
151
+ await getDependencies(undefined, false);
152
+ expect(commands[0]).not.toContain("--omit=dev");
153
+ });
154
+
155
+ it("resolves the package directory first and runs npm ls inside it", async () => {
156
+ responses = [ok("/repo/packages/server\n"), ok(TREE)];
157
+ await getDependencies("@prosopo/server");
158
+ expect(commands[0]).toBe("npm list @prosopo/server -ap");
159
+ expect(commands[1]).toContain("cd /repo/packages/server &&");
160
+ });
161
+
162
+ it("prefixes a bare package name with the scope", async () => {
163
+ responses = [ok("/repo/packages/server\n"), ok(TREE)];
164
+ await getDependencies("server");
165
+ expect(commands[0]).toBe("npm list @prosopo/server -ap");
166
+ });
167
+
168
+ it("leaves an already-scoped name alone", async () => {
169
+ responses = [ok("/repo/packages/server\n"), ok(TREE)];
170
+ await getDependencies("@prosopo/server");
171
+ expect(commands[0]).toBe("npm list @prosopo/server -ap");
172
+ });
173
+
174
+ it("falls back to the working directory when npm prints no path", async () => {
175
+ responses = [ok(" \n"), ok(TREE)];
176
+ await getDependencies("@prosopo/server");
177
+ expect(commands[1]).toContain(`cd ${process.cwd()} &&`);
178
+ });
179
+
180
+ it("rejects when the package cannot be located", async () => {
181
+ responses = [ok("", "npm ERR! code E404")];
182
+ await expect(getDependencies("@prosopo/absent")).rejects.toThrow(
183
+ "CONFIG.INVALID_PACKAGE_DIR",
184
+ );
185
+ });
186
+
187
+ it("tolerates npm warnings on stderr that are not errors", async () => {
188
+ responses = [
189
+ ok("/repo/packages/server\n", "npm warn deprecated"),
190
+ ok(TREE),
191
+ ];
192
+ await expect(getDependencies("@prosopo/server")).resolves.toMatchObject({
193
+ dependencies: ["mongodb", "bson", "zod"],
194
+ });
195
+ });
196
+
197
+ it("still parses the tree when npm ls exits non-zero", async () => {
198
+ // `npm ls` exits 1 for any unmet or extraneous dependency but still
199
+ // prints the whole tree, so the build must not be blocked by it.
200
+ responses = [failing(TREE)];
201
+ const { dependencies } = await getDependencies();
202
+ expect(dependencies).toEqual(["mongodb", "bson", "zod"]);
203
+ });
204
+
205
+ it("rethrows when a failing npm ls produced no output at all", async () => {
206
+ const error: ExecException = new Error("npm not found");
207
+ responses = [error];
208
+ await expect(getDependencies()).rejects.toThrow("npm not found");
209
+ });
210
+
211
+ it("reads stderr as well as stdout, since npm splits the tree across both", async () => {
212
+ responses = [ok("├── zod@3.22.4", "\n└── axios@1.6.0")];
213
+ const { dependencies } = await getDependencies();
214
+ expect(dependencies).toEqual(["zod", "axios"]);
215
+ });
216
+ });
217
+
218
+ const { default: ViteBackendConfig } = await import(
219
+ "./vite/vite.backend.config.js"
220
+ );
221
+
222
+ /** Every backend config starts with the same two npm ls calls. */
223
+ const npmLsResponses = (): (ExecResult | Error)[] => [
224
+ ok("/repo/packages/server\n"),
225
+ ok(TREE),
226
+ ];
227
+
228
+ const externalsOf = (config: UserConfig): string[] => {
229
+ const external = config.build?.rollupOptions?.external;
230
+ if (!Array.isArray(external)) {
231
+ throw new Error("expected an array of externals");
232
+ }
233
+ return external.map(String);
234
+ };
235
+
236
+ // Hand-rolled rather than `.flat(Infinity)`: a non-literal depth makes tsc
237
+ // expand FlatArray until it gives up with TS2589.
238
+ const flattenDeep = (value: unknown): unknown[] =>
239
+ Array.isArray(value) ? value.flatMap(flattenDeep) : [value];
240
+
241
+ const pluginNamesOf = (plugins: UserConfig["plugins"]): string[] =>
242
+ flattenDeep(plugins ?? []).map((plugin) => {
243
+ if (plugin && typeof plugin === "object" && "name" in plugin) {
244
+ return String(plugin.name);
245
+ }
246
+ return "";
247
+ });
248
+
249
+ describe("ViteBackendConfig", () => {
250
+ const build = (
251
+ command?: string,
252
+ mode?: string,
253
+ outputDir?: string,
254
+ ): Promise<UserConfig> => {
255
+ responses = npmLsResponses();
256
+ return ViteBackendConfig(
257
+ "@prosopo/server",
258
+ "1.2.3",
259
+ "server",
260
+ "/repo/packages/server",
261
+ "src/index.ts",
262
+ command,
263
+ mode,
264
+ outputDir,
265
+ );
266
+ };
267
+
268
+ it("emits an esm bundle named after the bundle name", async () => {
269
+ const config = await build();
270
+ expect(config.build?.lib).toMatchObject({
271
+ name: "server",
272
+ formats: ["es"],
273
+ fileName: "server.[name].bundle.js",
274
+ });
275
+ expect(config.build?.rollupOptions?.output).toMatchObject({
276
+ entryFileNames: "server.[name].bundle.js",
277
+ });
278
+ });
279
+
280
+ it("defaults the output to dist/bundle inside the package", async () => {
281
+ const config = await build();
282
+ expect(config.build?.outDir).toBe(
283
+ path.resolve("/repo/packages/server", "dist/bundle"),
284
+ );
285
+ });
286
+
287
+ it("honours an explicit output directory", async () => {
288
+ const config = await build(undefined, undefined, "/tmp/out");
289
+ expect(config.build?.outDir).toBe(path.resolve("/tmp/out"));
290
+ });
291
+
292
+ it("minifies only in production", async () => {
293
+ await expect(build(undefined, "production")).resolves.toMatchObject({
294
+ build: { minify: true },
295
+ });
296
+ await expect(build(undefined, "development")).resolves.toMatchObject({
297
+ build: { minify: false },
298
+ });
299
+ });
300
+
301
+ it("bakes the package version into the bundle", async () => {
302
+ const config = await build();
303
+ expect(config.define).toMatchObject({
304
+ "process.env.PROSOPO_PACKAGE_VERSION": '"1.2.3"',
305
+ });
306
+ });
307
+
308
+ it("stubs out the optional websocket native helpers", async () => {
309
+ // bufferutil and utf-8-validate are optional native deps; without these
310
+ // flags ws tries to require them and the bundle dies at boot.
311
+ const config = await build();
312
+ expect(config.define).toMatchObject({
313
+ "process.env.WS_NO_BUFFER_UTIL": "true",
314
+ "process.env.WS_NO_UTF_8_VALIDATE": "true",
315
+ });
316
+ });
317
+
318
+ it("bundles punycode rather than externalising it", async () => {
319
+ // The provider image ships no node_modules, so an external deep import
320
+ // like "punycode/punycode.es6.js" is an immediate boot failure.
321
+ const config = await build();
322
+ expect(externalsOf(config)).not.toContain("punycode");
323
+ expect(externalsOf(config)).toContain("node:punycode");
324
+ });
325
+
326
+ it("externalises the remaining node builtins", async () => {
327
+ const list = externalsOf(await build());
328
+ expect(list).toContain("fs");
329
+ expect(list).toContain("node:fs");
330
+ });
331
+
332
+ it("resolves the entry against the package directory", async () => {
333
+ const config = await build();
334
+ expect(config.build?.lib).toMatchObject({
335
+ entry: [path.resolve("/repo/packages/server", "src/index.ts")],
336
+ });
337
+ });
338
+
339
+ it("resolves a list of entries", async () => {
340
+ responses = npmLsResponses();
341
+ const config = await ViteBackendConfig(
342
+ "@prosopo/server",
343
+ "1.2.3",
344
+ "server",
345
+ "/repo/packages/server",
346
+ ["src/a.ts", "src/b.ts"],
347
+ );
348
+ expect(config.build?.lib).toMatchObject({
349
+ entry: [
350
+ path.resolve("/repo/packages/server", "src/a.ts"),
351
+ path.resolve("/repo/packages/server", "src/b.ts"),
352
+ ],
353
+ });
354
+ });
355
+
356
+ it("resolves a named entry map", async () => {
357
+ responses = npmLsResponses();
358
+ const config = await ViteBackendConfig(
359
+ "@prosopo/server",
360
+ "1.2.3",
361
+ "server",
362
+ "/repo/packages/server",
363
+ { cli: "src/cli.ts" },
364
+ );
365
+ expect(config.build?.lib).toMatchObject({
366
+ entry: { cli: path.resolve("/repo/packages/server", "src/cli.ts") },
367
+ });
368
+ });
369
+
370
+ it("skips the close plugin while serving, so the dev server stays up", async () => {
371
+ const serving = (await build("serve")).plugins ?? [];
372
+ const building = (await build("build")).plugins ?? [];
373
+ expect(pluginNamesOf(serving)).not.toContain("close-plugin");
374
+ expect(pluginNamesOf(building)).toContain("close-plugin");
375
+ });
376
+
377
+ it("keeps module side effects when treeshaking", async () => {
378
+ // Dropping them broke polyfills that register themselves on import.
379
+ const config = await build();
380
+ expect(config.build?.rollupOptions?.treeshake).toMatchObject({
381
+ annotations: true,
382
+ moduleSideEffects: true,
383
+ });
384
+ });
385
+ });