jamdesk 1.1.96 → 1.1.98

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 (58) hide show
  1. package/dist/__tests__/integration/migrate.integration.test.js +17 -0
  2. package/dist/__tests__/integration/migrate.integration.test.js.map +1 -1
  3. package/dist/__tests__/unit/deps-sync.test.js +4 -1
  4. package/dist/__tests__/unit/deps-sync.test.js.map +1 -1
  5. package/dist/__tests__/unit/migrate-convert.test.js +91 -0
  6. package/dist/__tests__/unit/migrate-convert.test.js.map +1 -1
  7. package/dist/__tests__/unit/migrate-detect.test.js +49 -2
  8. package/dist/__tests__/unit/migrate-detect.test.js.map +1 -1
  9. package/dist/__tests__/unit/migrate-resolve-theme.test.d.ts +2 -0
  10. package/dist/__tests__/unit/migrate-resolve-theme.test.d.ts.map +1 -0
  11. package/dist/__tests__/unit/migrate-resolve-theme.test.js +29 -0
  12. package/dist/__tests__/unit/migrate-resolve-theme.test.js.map +1 -0
  13. package/dist/__tests__/unit/openapi-license-identifier.test.d.ts +2 -0
  14. package/dist/__tests__/unit/openapi-license-identifier.test.d.ts.map +1 -0
  15. package/dist/__tests__/unit/openapi-license-identifier.test.js +42 -0
  16. package/dist/__tests__/unit/openapi-license-identifier.test.js.map +1 -0
  17. package/dist/__tests__/unit/openapi-schema-patch-sync.test.d.ts +2 -0
  18. package/dist/__tests__/unit/openapi-schema-patch-sync.test.d.ts.map +1 -0
  19. package/dist/__tests__/unit/openapi-schema-patch-sync.test.js +56 -0
  20. package/dist/__tests__/unit/openapi-schema-patch-sync.test.js.map +1 -0
  21. package/dist/commands/migrate/convert.d.ts +2 -1
  22. package/dist/commands/migrate/convert.d.ts.map +1 -1
  23. package/dist/commands/migrate/convert.js +30 -2
  24. package/dist/commands/migrate/convert.js.map +1 -1
  25. package/dist/commands/migrate/detect.d.ts +6 -0
  26. package/dist/commands/migrate/detect.d.ts.map +1 -1
  27. package/dist/commands/migrate/detect.js +32 -0
  28. package/dist/commands/migrate/detect.js.map +1 -1
  29. package/dist/commands/migrate/index.d.ts +7 -1
  30. package/dist/commands/migrate/index.d.ts.map +1 -1
  31. package/dist/commands/migrate/index.js +37 -17
  32. package/dist/commands/migrate/index.js.map +1 -1
  33. package/dist/lib/deps.d.ts +27 -19
  34. package/dist/lib/deps.d.ts.map +1 -1
  35. package/dist/lib/deps.js +41 -30
  36. package/dist/lib/deps.js.map +1 -1
  37. package/package.json +1 -1
  38. package/scripts/patch-openapi-schemas.js +52 -32
  39. package/vendored/components/mdx/Mermaid.tsx +50 -13
  40. package/vendored/components/navigation/Sidebar.tsx +1 -1
  41. package/vendored/lib/navigation-resolver.ts +15 -0
  42. package/vendored/workspace-package-lock.json +15 -15
  43. package/dist/__tests__/unit/dev-workspace-symlinks.test.d.ts +0 -2
  44. package/dist/__tests__/unit/dev-workspace-symlinks.test.d.ts.map +0 -1
  45. package/dist/__tests__/unit/dev-workspace-symlinks.test.js +0 -112
  46. package/dist/__tests__/unit/dev-workspace-symlinks.test.js.map +0 -1
  47. package/dist/__tests__/unit/language-filter.test.d.ts +0 -2
  48. package/dist/__tests__/unit/language-filter.test.d.ts.map +0 -1
  49. package/dist/__tests__/unit/language-filter.test.js +0 -166
  50. package/dist/__tests__/unit/language-filter.test.js.map +0 -1
  51. package/dist/__tests__/unit/output.test.d.ts +0 -2
  52. package/dist/__tests__/unit/output.test.d.ts.map +0 -1
  53. package/dist/__tests__/unit/output.test.js +0 -61
  54. package/dist/__tests__/unit/output.test.js.map +0 -1
  55. package/dist/lib/language-filter.d.ts +0 -31
  56. package/dist/lib/language-filter.d.ts.map +0 -1
  57. package/dist/lib/language-filter.js +0 -14
  58. package/dist/lib/language-filter.js.map +0 -1
@@ -1,24 +1,31 @@
1
1
  #!/usr/bin/env node
2
2
  /**
3
- * Patch a typo in @apidevtools/openapi-schemas@2.1.0.
3
+ * Patch two defects in @apidevtools/openapi-schemas@2.1.0's bundled
4
+ * OpenAPI 3.1 meta-schema. Both are idempotent and self-cleaning once
5
+ * upstream ships fixes (https://github.com/APIDevTools/openapi-schemas):
4
6
  *
5
- * The bundled OpenAPI 3.1 meta-schema defines `server-variable.properties`
6
- * as `{ enum, default, descriptions }` but the OpenAPI 3.1 spec says the
7
- * third property is `description` (singular). Combined with
8
- * `unevaluatedProperties: false` on the same definition, any spec-valid
9
- * `description` field on a server variable is rejected with:
7
+ * 1. server-variable typo: `properties` declares `descriptions` (plural)
8
+ * instead of `description`. With `unevaluatedProperties: false` on the
9
+ * same def, a spec-valid `description` is rejected with:
10
+ * #/servers/0/variables/<name> must NOT have unevaluated properties
10
11
  *
11
- * #/servers/0/variables/<name> must NOT have unevaluated properties
12
- *
13
- * We swap the typo at install time so swagger-parser accepts the spec.
14
- * Idempotent safe to run multiple times. Deletes itself cleanly once
15
- * upstream ships a fix:
16
- *
17
- * https://github.com/APIDevTools/openapi-schemas
12
+ * 2. license over-constraint: the `license` def carries
13
+ * "oneOf": [ {"required":["identifier"]}, {"required":["url"]} ]
14
+ * which forces every license to have an `identifier` or a `url`. The
15
+ * OpenAPI 3.1 spec (§4.8.4) only requires `name`; `identifier` and
16
+ * `url` are optional and merely mutually exclusive. A `{ name }`-only
17
+ * license is valid (Mintlify accepts it; `jamdesk migrate`'s
18
+ * auto-discovered Mintlify starter spec uses `{ "name": "MIT" }`).
19
+ * The correct constraint is `not: { required: [identifier, url] }`.
18
20
  *
19
21
  * This file runs as an npm `postinstall` script in the package root, so
20
22
  * `__dirname` is always `<package>/scripts/` and `node_modules` resolves
21
23
  * one level up.
24
+ *
25
+ * The CLI's *workspace* install (~/.jamdesk) is patched separately and
26
+ * identically by patchWorkspaceOpenApiSchemas() in src/lib/deps.ts — if
27
+ * you change the patch logic here, mirror it there (and in
28
+ * build-service/scripts/patch-openapi-schemas.js).
22
29
  */
23
30
 
24
31
  import fs from 'fs';
@@ -55,30 +62,45 @@ try {
55
62
  process.exit(0);
56
63
  }
57
64
 
58
- const defs = schema && schema.$defs;
59
- const serverVariable = defs && defs['server-variable'];
60
- const props = serverVariable && serverVariable.properties;
61
-
62
- if (!props) {
63
- // Schema shape changed upstream — bail out quietly.
64
- process.exit(0);
65
+ /**
66
+ * Fix 1: server-variable `descriptions` -> `description`.
67
+ * Returns true if it changed the schema.
68
+ */
69
+ function patchServerVariable(s) {
70
+ const props = s?.$defs?.['server-variable']?.properties;
71
+ if (!props) return false; // Shape changed upstream — leave alone.
72
+ if (props.description) return false; // Already patched / upstream fixed.
73
+ if (!props.descriptions) return false; // No typo to fix.
74
+ props.description = props.descriptions;
75
+ delete props.descriptions;
76
+ return true;
65
77
  }
66
78
 
67
- if (props.description) {
68
- // Already patched (or upstream fixed it). Either way, no work to do.
69
- process.exit(0);
79
+ /**
80
+ * Fix 2: license over-constraint. Replace the bad `oneOf` with the
81
+ * spec-correct mutual-exclusivity guard. Returns true if it changed.
82
+ */
83
+ function patchLicense(s) {
84
+ const license = s?.$defs?.license;
85
+ if (!license || typeof license !== 'object') return false;
86
+ if (!Array.isArray(license.oneOf)) return false; // Already patched / fixed.
87
+ delete license.oneOf;
88
+ license.not = { required: ['identifier', 'url'] };
89
+ return true;
70
90
  }
71
91
 
72
- if (!props.descriptions) {
73
- // No typo to fix. Quietly no-op.
92
+ const patched = [];
93
+ if (patchServerVariable(schema)) patched.push('server-variable typo (descriptions description)');
94
+ if (patchLicense(schema)) patched.push('license oneOf → not(identifier+url)');
95
+
96
+ if (patched.length === 0) {
74
97
  process.exit(0);
75
98
  }
76
99
 
77
- props.description = props.descriptions;
78
- delete props.descriptions;
79
-
80
100
  try {
81
- fs.writeFileSync(schemaPath, JSON.stringify(schema, null, 2));
101
+ // Trailing newline keeps this byte-identical to fs-extra's writeJson
102
+ // (jsonfile finalEOL) used by the runtime patch in src/lib/deps.ts.
103
+ fs.writeFileSync(schemaPath, JSON.stringify(schema, null, 2) + '\n');
82
104
  } catch (err) {
83
105
  console.warn(
84
106
  '[jamdesk] patch-openapi-schemas: failed to write patch, skipping:',
@@ -86,6 +108,4 @@ try {
86
108
  );
87
109
  process.exit(0);
88
110
  }
89
- console.log(
90
- '[jamdesk] patched openapi-schemas 3.1 server-variable typo (descriptions → description)'
91
- );
111
+ console.log(`[jamdesk] patched openapi-schemas 3.1: ${patched.join('; ')}`);
@@ -1,17 +1,26 @@
1
1
  'use client';
2
2
 
3
3
  import dynamic from 'next/dynamic';
4
- import { useMemo, useState } from 'react';
4
+ import { useMemo, useRef, useState } from 'react';
5
5
  import { readCachedHeight } from './mermaidCache';
6
6
  import { useIsomorphicLayoutEffect } from '../../hooks/useIsomorphicLayoutEffect';
7
7
 
8
8
  // Neutral floor reserved in the SSR markup itself (present on the browser's
9
9
  // first paint, before any JS) so a cache miss / pre-hydration window shows
10
10
  // correctly-sized empty space instead of a collapse or a grey pulse. Roughly
11
- // the prior skeleton footprint; refined to the exact diagram height on a
12
- // cache hit by the layout effect below.
11
+ // the prior skeleton footprint; a cache hit refines it to the exact diagram
12
+ // height pre-paint, and once the diagram renders the floor is released
13
+ // entirely (see the layout effect below).
13
14
  const DEFAULT_MERMAID_RESERVE_PX = 192;
14
15
 
16
+ // Sentinel: floor released, MermaidInner's own min-height governs the box.
17
+ const FLOOR_RELEASED_PX = 0;
18
+
19
+ // A rendered diagram (or the error box) is always taller than this; the empty
20
+ // pre-render container is 0px. Distinguishes "content has painted" from "still
21
+ // reserving the gap" so the floor is released only once it is dead weight.
22
+ const RENDERED_FLOOR_RELEASE_PX = 8;
23
+
15
24
  const MermaidInner = dynamic(
16
25
  () => import('./MermaidInner').then(mod => ({ default: mod.MermaidInner })),
17
26
  { ssr: false, loading: () => null }
@@ -25,21 +34,49 @@ interface MermaidProps {
25
34
  }
26
35
 
27
36
  export function Mermaid({ children, className, minWidth }: MermaidProps) {
37
+ const wrapperRef = useRef<HTMLDivElement>(null);
38
+
28
39
  // Server + first (hydration) render emit the constant default — identical
29
40
  // markup, so no hydration mismatch. The sessionStorage read happens only
30
41
  // in the post-hydration layout effect, never in this initializer.
31
42
  const [reservedPx, setReservedPx] = useState(DEFAULT_MERMAID_RESERVE_PX);
32
43
 
33
- // Fires once, after the hydration commit, synchronously before that
34
- // commit's paint and BEFORE the MermaidInner chunk has resolved or
35
- // injected anything. On a cache hit, refine the reserved space to the
36
- // exact diagram height so the SVG paints into already-exact space.
37
- // Distinct from the reverted spike: one pre-paint settle before injection,
38
- // never a re-render around an already-injected node. minWidth still flows
39
- // to MermaidInner unchanged; the wrapper owns height only.
44
+ // The reserved min-height only bridges the pre-render gap; it must never
45
+ // outlive the diagram or it leaves dead space under any diagram shorter
46
+ // than the floor (the cache-miss path never refines it down).
40
47
  useIsomorphicLayoutEffect(() => {
41
- const h = readCachedHeight(children);
42
- if (h > 0) setReservedPx(h);
48
+ const wrapper = wrapperRef.current;
49
+
50
+ // Relies on MermaidInner rendering exactly one HTMLElement root (the
51
+ // diagram container or the error box); if that contract changes, this
52
+ // height probe silently targets the wrong node.
53
+ const releaseIfRendered = (): boolean => {
54
+ const content = wrapper?.firstElementChild as HTMLElement | null;
55
+ if (content && content.clientHeight > RENDERED_FLOOR_RELEASE_PX) {
56
+ setReservedPx(FLOOR_RELEASED_PX);
57
+ return true;
58
+ }
59
+ return false;
60
+ };
61
+
62
+ // Already painted (warm soft-nav: SVG hydrated synchronously from cache) —
63
+ // the floor is already dead weight, skip the cache refine entirely.
64
+ if (releaseIfRendered()) return;
65
+
66
+ // Not yet painted: cache hit → reserve the exact height pre-paint (zero
67
+ // shift); cache miss / new diagram → hold the default floor for its gap.
68
+ const cached = readCachedHeight(children);
69
+ setReservedPx(cached > 0 ? cached : DEFAULT_MERMAID_RESERVE_PX);
70
+
71
+ if (!wrapper || typeof MutationObserver === 'undefined') return;
72
+ // childList only — no `attributes`: MermaidInner's post-commit style pass
73
+ // mutates SVG child styles heavily; observing attributes would fire a
74
+ // callback storm. The SVG-insert is a childList mutation, all we need.
75
+ const mo = new MutationObserver(() => {
76
+ if (releaseIfRendered()) mo.disconnect();
77
+ });
78
+ mo.observe(wrapper, { childList: true, subtree: true });
79
+ return () => mo.disconnect();
43
80
  }, [children]);
44
81
 
45
82
  // Stable element identity across reservedPx changes. The pre-paint
@@ -63,7 +100,7 @@ export function Mermaid({ children, className, minWidth }: MermaidProps) {
63
100
  );
64
101
 
65
102
  return (
66
- <div data-testid="mermaid-wrapper" style={{ minHeight: reservedPx }}>
103
+ <div ref={wrapperRef} data-testid="mermaid-wrapper" style={{ minHeight: reservedPx }}>
67
104
  {inner}
68
105
  </div>
69
106
  );
@@ -539,7 +539,7 @@ export function Sidebar({ config, layout = 'header-logo', tabsPosition: tabsPosi
539
539
  <div className="flex flex-col gap-1 px-4 pt-4">
540
540
  {resolvedNav.externalAnchors.map((anchor) => (
541
541
  <a
542
- key={anchor.name}
542
+ key={`${anchor.href}|${anchor.name}`}
543
543
  href={anchor.href}
544
544
  target="_blank"
545
545
  rel="noopener noreferrer"
@@ -460,6 +460,21 @@ export function resolveNavigation(
460
460
  }
461
461
  }
462
462
 
463
+ // Dedupe exact (name+href) repeats. `jamdesk migrate` historically emitted
464
+ // external anchors in BOTH config.anchors and navigation.global.anchors, so
465
+ // the resolver would otherwise return the same link twice. Keyed on
466
+ // name+href (not name alone) so two genuinely distinct anchors that share a
467
+ // label are preserved — Sidebar.tsx keys them by href|name, so distinct
468
+ // hrefs no longer collide as React keys. First occurrence wins, so
469
+ // top-level config.anchors takes precedence over global.anchors.
470
+ const seenAnchors = new Set<string>();
471
+ result.externalAnchors = result.externalAnchors.filter((anchor) => {
472
+ const dedupeKey = `${anchor.name}\0${anchor.href}`;
473
+ if (seenAnchors.has(dedupeKey)) return false;
474
+ seenAnchors.add(dedupeKey);
475
+ return true;
476
+ });
477
+
463
478
  // Resolve top-level tabs
464
479
  if (navigation.tabs) {
465
480
  result.tabs = navigation.tabs.map(resolveTab);
@@ -1921,9 +1921,9 @@
1921
1921
  }
1922
1922
  },
1923
1923
  "node_modules/@types/node": {
1924
- "version": "25.8.0",
1925
- "resolved": "https://registry.npmjs.org/@types/node/-/node-25.8.0.tgz",
1926
- "integrity": "sha512-TCFSk8IZh+iLX1xtksoBVtdmgL+1IX0fC9BeU4QqFSuNdN/K+HUlhqOzEmSYYpZUVsLYcPqc9KX+60iDuninSQ==",
1924
+ "version": "25.9.0",
1925
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.0.tgz",
1926
+ "integrity": "sha512-AOQwYUNolgy3VosiRqXrACUXTN8nJUtPl7FJXMqZVyxiiCLhQuG3jXKvCS1ALr+Y2OmZhzzLVlYPEqJaiqkaJQ==",
1927
1927
  "license": "MIT",
1928
1928
  "dependencies": {
1929
1929
  "undici-types": ">=7.24.0 <7.24.7"
@@ -2134,9 +2134,9 @@
2134
2134
  }
2135
2135
  },
2136
2136
  "node_modules/baseline-browser-mapping": {
2137
- "version": "2.10.30",
2138
- "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.30.tgz",
2139
- "integrity": "sha512-xjOFN16Ha1+Rz4nFYKqHU/LSB+gx/Vi3yQLX7r7sAW+Wa+8hhF2h4pvqTrTMc8+WcDBEunnUurr46Jvv0jk3Vg==",
2137
+ "version": "2.10.31",
2138
+ "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.31.tgz",
2139
+ "integrity": "sha512-MujYO3eP72uvmSE0i4wltsodRfIpZATP3jvzRNRGGxgzId7aVocVJJV3nf01qnzzKFGxQVC9bpWxl5cjxTr/7Q==",
2140
2140
  "license": "Apache-2.0",
2141
2141
  "bin": {
2142
2142
  "baseline-browser-mapping": "dist/cli.cjs"
@@ -2913,9 +2913,9 @@
2913
2913
  }
2914
2914
  },
2915
2915
  "node_modules/dompurify": {
2916
- "version": "3.4.4",
2917
- "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.4.tgz",
2918
- "integrity": "sha512-r8K7KGKEcztXfA/nfabSYB2hg9tDphORJTdf8xprN/luSLGmNhOBN8dm1/SYjqLLet6YUFEXOcrdTuwryp/Bew==",
2916
+ "version": "3.4.5",
2917
+ "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.5.tgz",
2918
+ "integrity": "sha512-OrwIBKsdNSVEeubdJ1HBv/wNENRM9ytAVCv7YXt//A3vPdVMNuACRqK9mXCGCBW2ln7BT/A4X0jXHo2Gu89miA==",
2919
2919
  "license": "(MPL-2.0 OR Apache-2.0)",
2920
2920
  "optionalDependencies": {
2921
2921
  "@types/trusted-types": "^2.0.7"
@@ -2934,9 +2934,9 @@
2934
2934
  "license": "ISC"
2935
2935
  },
2936
2936
  "node_modules/enhanced-resolve": {
2937
- "version": "5.21.3",
2938
- "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.21.3.tgz",
2939
- "integrity": "sha512-QyL119InA+XXEkNLNTPCXPugSvOfhwv0JOlGNzvxs0hZaiHLNvXSpudUWsOlsXGWJh8G6ckCScEkVHfX3kw/2Q==",
2937
+ "version": "5.21.4",
2938
+ "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.21.4.tgz",
2939
+ "integrity": "sha512-wE4fDO8OjJhrPFH69HUQStq5oKvGRTNXEyW+k5C/pUQLASSsTu7obd2V3GvCDgPcY9AWjhJ4jz9Kh7iRvrxhJg==",
2940
2940
  "license": "MIT",
2941
2941
  "dependencies": {
2942
2942
  "graceful-fs": "^4.2.4",
@@ -4067,9 +4067,9 @@
4067
4067
  }
4068
4068
  },
4069
4069
  "node_modules/lru-cache": {
4070
- "version": "11.3.6",
4071
- "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.3.6.tgz",
4072
- "integrity": "sha512-Gf/KoL3C/MlI7Bt0PGI9I+TeTC/I6r/csU58N4BSNc4lppLBeKsOdFYkK+dX0ABDUMJNfCHTyPpzwwO21Awd3A==",
4070
+ "version": "11.4.0",
4071
+ "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.4.0.tgz",
4072
+ "integrity": "sha512-W+R+kFL4HgVxONq2bhXPi3bGpzGe/yEhVOp233qw9wCRtgncJ15P3bC+e4zZMu4Cq7d+WAJjXGW0uUkifhcatA==",
4073
4073
  "license": "BlueOak-1.0.0",
4074
4074
  "engines": {
4075
4075
  "node": "20 || >=22"
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=dev-workspace-symlinks.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dev-workspace-symlinks.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/unit/dev-workspace-symlinks.test.ts"],"names":[],"mappings":""}
@@ -1,112 +0,0 @@
1
- /**
2
- * @vitest-environment node
3
- *
4
- * Tests prepareProjectWorkspaceLinks — replaces the single
5
- * <workspace>/projects/<name> -> <projectDir> symlink with per-entry
6
- * symlinks that skip non-active language directories. This is what
7
- * actually reduces Turbopack's filesystem scan from 403 MDX files to
8
- * 135 on jamdesk-docs.
9
- */
10
- import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
11
- import fs from 'fs-extra';
12
- import path from 'path';
13
- import { tmpdir } from 'os';
14
- import { prepareProjectWorkspaceLinks } from '../../commands/dev.js';
15
- import { output } from '../../lib/output.js';
16
- describe('prepareProjectWorkspaceLinks', () => {
17
- let tmpRoot;
18
- let projectDir;
19
- let workspaceProjectDir;
20
- beforeEach(() => {
21
- tmpRoot = fs.mkdtempSync(path.join(tmpdir(), 'jam-ws-'));
22
- projectDir = path.join(tmpRoot, 'project');
23
- workspaceProjectDir = path.join(tmpRoot, 'ws', 'projects', 'project');
24
- // Set up a project layout that mirrors a multi-language docs project:
25
- // project/
26
- // ai/intro.mdx (en at root)
27
- // development/foo.mdx (en at root)
28
- // es/ai/intro.mdx (spanish)
29
- // fr/ai/intro.mdx (french)
30
- // docs.json
31
- // images/logo.png
32
- fs.mkdirpSync(path.join(projectDir, 'ai'));
33
- fs.writeFileSync(path.join(projectDir, 'ai', 'intro.mdx'), '# en');
34
- fs.mkdirpSync(path.join(projectDir, 'development'));
35
- fs.writeFileSync(path.join(projectDir, 'development', 'foo.mdx'), '# en');
36
- fs.mkdirpSync(path.join(projectDir, 'es', 'ai'));
37
- fs.writeFileSync(path.join(projectDir, 'es', 'ai', 'intro.mdx'), '# es');
38
- fs.mkdirpSync(path.join(projectDir, 'fr', 'ai'));
39
- fs.writeFileSync(path.join(projectDir, 'fr', 'ai', 'intro.mdx'), '# fr');
40
- fs.writeFileSync(path.join(projectDir, 'docs.json'), '{}');
41
- fs.mkdirpSync(path.join(projectDir, 'images'));
42
- fs.writeFileSync(path.join(projectDir, 'images', 'logo.png'), '');
43
- });
44
- afterEach(() => {
45
- fs.removeSync(tmpRoot);
46
- });
47
- it('symlinks every top-level entry when skip set is empty', async () => {
48
- await prepareProjectWorkspaceLinks(projectDir, workspaceProjectDir, new Set());
49
- expect(fs.existsSync(path.join(workspaceProjectDir, 'ai', 'intro.mdx'))).toBe(true);
50
- expect(fs.existsSync(path.join(workspaceProjectDir, 'es', 'ai', 'intro.mdx'))).toBe(true);
51
- expect(fs.existsSync(path.join(workspaceProjectDir, 'fr', 'ai', 'intro.mdx'))).toBe(true);
52
- });
53
- it('does not symlink docs.json (caller writes a filtered copy)', async () => {
54
- // docs.json must not be symlinked — the caller writes a per-language
55
- // filtered copy, and fs.writeFile through a symlink would clobber the
56
- // user's source docs.json.
57
- await prepareProjectWorkspaceLinks(projectDir, workspaceProjectDir, new Set());
58
- expect(fs.existsSync(path.join(workspaceProjectDir, 'docs.json'))).toBe(false);
59
- });
60
- it('skips entries whose names are in the skip set', async () => {
61
- await prepareProjectWorkspaceLinks(projectDir, workspaceProjectDir, new Set(['es', 'fr']));
62
- expect(fs.existsSync(path.join(workspaceProjectDir, 'ai', 'intro.mdx'))).toBe(true);
63
- expect(fs.existsSync(path.join(workspaceProjectDir, 'development', 'foo.mdx'))).toBe(true);
64
- expect(fs.existsSync(path.join(workspaceProjectDir, 'images', 'logo.png'))).toBe(true);
65
- // Skipped:
66
- expect(fs.existsSync(path.join(workspaceProjectDir, 'es'))).toBe(false);
67
- expect(fs.existsSync(path.join(workspaceProjectDir, 'fr'))).toBe(false);
68
- // docs.json not symlinked — caller writes a filtered copy.
69
- expect(fs.existsSync(path.join(workspaceProjectDir, 'docs.json'))).toBe(false);
70
- });
71
- it('rebuilds the workspace links from scratch on subsequent calls', async () => {
72
- // First call: no skip
73
- await prepareProjectWorkspaceLinks(projectDir, workspaceProjectDir, new Set());
74
- expect(fs.existsSync(path.join(workspaceProjectDir, 'es'))).toBe(true);
75
- // Second call: skip es
76
- await prepareProjectWorkspaceLinks(projectDir, workspaceProjectDir, new Set(['es']));
77
- expect(fs.existsSync(path.join(workspaceProjectDir, 'es'))).toBe(false);
78
- expect(fs.existsSync(path.join(workspaceProjectDir, 'fr'))).toBe(true);
79
- expect(fs.existsSync(path.join(workspaceProjectDir, 'ai', 'intro.mdx'))).toBe(true);
80
- });
81
- it('handles a pre-existing single symlink at workspaceProjectDir (legacy layout)', async () => {
82
- // Pre-create the legacy single-symlink layout
83
- fs.mkdirpSync(path.dirname(workspaceProjectDir));
84
- fs.symlinkSync(projectDir, workspaceProjectDir, 'junction');
85
- await prepareProjectWorkspaceLinks(projectDir, workspaceProjectDir, new Set(['es', 'fr']));
86
- const lstat = fs.lstatSync(workspaceProjectDir);
87
- expect(lstat.isDirectory()).toBe(true);
88
- expect(fs.existsSync(path.join(workspaceProjectDir, 'ai', 'intro.mdx'))).toBe(true);
89
- expect(fs.existsSync(path.join(workspaceProjectDir, 'es'))).toBe(false);
90
- });
91
- it('surfaces friendly error (not raw stack trace) when fs.rm throws ENOTEMPTY', async () => {
92
- // Regression: before safeRemoveCache, fs.remove raised an unfriendly stack
93
- // trace when Turbopack still held open files. Now safeRemoveCache detects
94
- // the race and calls process.exit(1) with a human-readable message.
95
- const rmSpy = vi.spyOn(fs, 'rm');
96
- const exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code) => {
97
- throw new Error(`process.exit:${code}`);
98
- }));
99
- const errorSpy = vi.spyOn(output, 'error').mockImplementation(() => undefined);
100
- const enotempty = Object.assign(new Error('ENOTEMPTY'), { code: 'ENOTEMPTY' });
101
- // fs.rm will be called by safeRemoveCache; make it fail with ENOTEMPTY
102
- // even after the internal maxRetries — simulate persistent race condition.
103
- rmSpy.mockRejectedValue(enotempty);
104
- await expect(prepareProjectWorkspaceLinks(projectDir, workspaceProjectDir, new Set())).rejects.toThrow('process.exit:1');
105
- const msg = errorSpy.mock.calls[0]?.[0] ?? '';
106
- expect(msg).toContain('Another `jamdesk dev` instance');
107
- expect(msg).toContain('pkill -f');
108
- expect(exitSpy).toHaveBeenCalledWith(1);
109
- vi.restoreAllMocks();
110
- });
111
- });
112
- //# sourceMappingURL=dev-workspace-symlinks.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dev-workspace-symlinks.test.js","sourceRoot":"","sources":["../../../src/__tests__/unit/dev-workspace-symlinks.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,IAAI,OAAe,CAAC;IACpB,IAAI,UAAkB,CAAC;IACvB,IAAI,mBAA2B,CAAC;IAEhC,UAAU,CAAC,GAAG,EAAE;QACd,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC;QACzD,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC3C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C,CAAC;QAEpC,MAAM,GAAG,GAAY,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAY,IAAI,EAAE,CAAC;QAClE,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,gCAAgC,CAAC,CAAC;QACxD,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAClC,MAAM,CAAC,OAAO,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;QAExC,EAAE,CAAC,eAAe,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=language-filter.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"language-filter.test.d.ts","sourceRoot":"","sources":["../../../src/__tests__/unit/language-filter.test.ts"],"names":[],"mappings":""}
@@ -1,166 +0,0 @@
1
- /**
2
- * @vitest-environment node
3
- *
4
- * Tests for getActiveLanguageFilter — pure helper that decides which
5
- * top-level language directories to skip when symlinking project content
6
- * into the dev workspace. Multi-language sites' non-default languages
7
- * inflate Turbopack's filesystem scan and balloon cold compile time
8
- * (jamdesk-docs: 67s with 3 langs vs. 12.5s with 1 lang).
9
- */
10
- import { describe, it, expect } from 'vitest';
11
- import { getActiveLanguageFilter, isPageInSkippedLanguage, filterConfigByActiveLanguage, } from '../../lib/language-filter.js';
12
- const config = (langs) => ({
13
- navigation: { languages: langs.map(l => ({ language: l.language, default: l.default })) },
14
- });
15
- describe('getActiveLanguageFilter', () => {
16
- it('returns null filter when project has no languages array', () => {
17
- const result = getActiveLanguageFilter({ navigation: {} }, undefined, false);
18
- expect(result).toEqual({ active: null, skip: new Set() });
19
- });
20
- it('returns null filter when project has only one language', () => {
21
- const result = getActiveLanguageFilter(config([{ language: 'en', default: true }]), undefined, false);
22
- expect(result).toEqual({ active: 'en', skip: new Set() });
23
- });
24
- it('skips non-default languages when active is the default', () => {
25
- const result = getActiveLanguageFilter(config([
26
- { language: 'en', default: true },
27
- { language: 'es' },
28
- { language: 'fr' },
29
- ]), undefined, false);
30
- expect(result.active).toBe('en');
31
- expect(result.skip).toEqual(new Set(['es', 'fr']));
32
- });
33
- it('falls back to first language when none is marked default', () => {
34
- const result = getActiveLanguageFilter(config([{ language: 'en' }, { language: 'es' }, { language: 'fr' }]), undefined, false);
35
- expect(result.active).toBe('en');
36
- expect(result.skip).toEqual(new Set(['es', 'fr']));
37
- });
38
- it('accepts --lang matching the default language (no-op equivalence)', () => {
39
- const result = getActiveLanguageFilter(config([
40
- { language: 'en', default: true },
41
- { language: 'es' },
42
- ]), 'en', false);
43
- expect(result.active).toBe('en');
44
- expect(result.skip).toEqual(new Set(['es']));
45
- });
46
- it('throws on --lang for a non-default language (initial release scope)', () => {
47
- // Non-default-language layouts mix root-level default-lang content with
48
- // <lang>/ subdirs for translations; correctly stripping the default
49
- // content while keeping <lang>/ takes more work and is deferred to a
50
- // follow-up. For now, surface the workaround clearly.
51
- expect(() => getActiveLanguageFilter(config([
52
- { language: 'en', default: true },
53
- { language: 'es' },
54
- { language: 'fr' },
55
- ]), 'es', false)).toThrow(/--lang es: previewing non-default languages.*--all-langs/i);
56
- });
57
- it('returns empty skip set when --all-langs is set', () => {
58
- const result = getActiveLanguageFilter(config([
59
- { language: 'en', default: true },
60
- { language: 'es' },
61
- ]), undefined, true);
62
- expect(result.active).toBe('en');
63
- expect(result.skip).toEqual(new Set());
64
- });
65
- it('throws on --lang code that does not exist in docs.json', () => {
66
- expect(() => getActiveLanguageFilter(config([{ language: 'en', default: true }, { language: 'es' }]), 'de', false)).toThrow(/--lang de.*not.*docs\.json.*Available: en, es/);
67
- });
68
- it('handles malformed languages array (entries missing language field) by ignoring them', () => {
69
- const malformed = {
70
- navigation: {
71
- languages: [
72
- { language: 'en', default: true },
73
- { default: false }, // missing language: ignored
74
- { language: 'es' },
75
- { language: 42 }, // wrong type: ignored
76
- ],
77
- },
78
- };
79
- const result = getActiveLanguageFilter(malformed, undefined, false);
80
- expect(result.active).toBe('en');
81
- expect(result.skip).toEqual(new Set(['es']));
82
- });
83
- it('returns null active when no valid language entries exist', () => {
84
- const result = getActiveLanguageFilter({ navigation: { languages: [{ default: true }] } }, undefined, false);
85
- expect(result).toEqual({ active: null, skip: new Set() });
86
- });
87
- it('rejects empty-string --lang as an invalid code (commander passes "" through)', () => {
88
- // commander.js treats `--lang ""` as a value, not as missing — so
89
- // langOption is "" (defined, but empty). Empty string is never a valid
90
- // language code; surface it as a clear error rather than silently
91
- // falling back to the default.
92
- expect(() => getActiveLanguageFilter(config([{ language: 'en', default: true }, { language: 'es' }]), '', false)).toThrow(/--lang.*not.*docs\.json/);
93
- });
94
- });
95
- describe('isPageInSkippedLanguage', () => {
96
- it('returns false when skip set is empty', () => {
97
- expect(isPageInSkippedLanguage('fr/introduction', new Set())).toBe(false);
98
- });
99
- it('returns true when first path segment is a skipped language', () => {
100
- expect(isPageInSkippedLanguage('fr/introduction', new Set(['fr']))).toBe(true);
101
- });
102
- it('returns true for nested paths inside a skipped language', () => {
103
- expect(isPageInSkippedLanguage('fr/setup/connecting-github', new Set(['fr', 'de']))).toBe(true);
104
- });
105
- it('returns false when first segment is the active language', () => {
106
- expect(isPageInSkippedLanguage('en/introduction', new Set(['fr']))).toBe(false);
107
- });
108
- it('returns false for unprefixed root pages', () => {
109
- expect(isPageInSkippedLanguage('introduction', new Set(['fr']))).toBe(false);
110
- });
111
- it('does not match when the skip code is a prefix-substring of a different segment', () => {
112
- // Guard against startsWith('fr/') matching e.g. 'fr-something/foo'
113
- expect(isPageInSkippedLanguage('fr-something/foo', new Set(['fr']))).toBe(false);
114
- });
115
- it('returns true for a path with a fragment anchor in a skipped language', () => {
116
- // Broken-anchor warnings from validate-links.cjs surface as link values
117
- // like `fr/introduction#missing-section` — the fragment lives past the
118
- // first segment so the language check still works.
119
- expect(isPageInSkippedLanguage('fr/introduction#setup', new Set(['fr']))).toBe(true);
120
- });
121
- });
122
- describe('filterConfigByActiveLanguage', () => {
123
- it('returns the input unchanged (same reference) when skip is empty', () => {
124
- const config = { name: 'foo', navigation: { languages: [{ language: 'en' }] } };
125
- const result = filterConfigByActiveLanguage(config, { active: 'en', skip: new Set() });
126
- expect(result).toBe(config);
127
- });
128
- it('drops skipped languages from navigation.languages', () => {
129
- const config = {
130
- name: 'jamdesk-docs',
131
- navigation: {
132
- languages: [
133
- { language: 'en', default: true, tabs: [{ tab: 'Guide' }] },
134
- { language: 'fr', tabs: [{ tab: 'Guide' }] },
135
- { language: 'de', tabs: [{ tab: 'Guide' }] },
136
- ],
137
- },
138
- };
139
- const result = filterConfigByActiveLanguage(config, {
140
- active: 'en',
141
- skip: new Set(['fr', 'de']),
142
- });
143
- expect(result.navigation.languages).toEqual([
144
- { language: 'en', default: true, tabs: [{ tab: 'Guide' }] },
145
- ]);
146
- // Top-level fields preserved.
147
- expect(result.name).toBe('jamdesk-docs');
148
- // Original config untouched.
149
- expect(config.navigation.languages).toHaveLength(3);
150
- });
151
- it('preserves other navigation fields (tabs, global, anchors, etc.)', () => {
152
- const config = {
153
- navigation: {
154
- languages: [{ language: 'en' }, { language: 'fr' }],
155
- global: { anchors: [{ anchor: 'Support' }] },
156
- },
157
- };
158
- const result = filterConfigByActiveLanguage(config, {
159
- active: 'en',
160
- skip: new Set(['fr']),
161
- });
162
- expect(result.navigation.global).toEqual({ anchors: [{ anchor: 'Support' }] });
163
- expect(result.navigation.languages).toHaveLength(1);
164
- });
165
- });
166
- //# sourceMappingURL=language-filter.test.js.map