@canopy-iiif/app 1.8.8 → 1.8.10

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.
package/lib/build/mdx.js CHANGED
@@ -72,6 +72,15 @@ function buildCompileOptions(overrides = {}) {
72
72
  const yaml = require("js-yaml");
73
73
  const {getPageContext} = require("../page-context");
74
74
 
75
+ const UI_PACKAGE_SPEC = "@canopy-iiif/app/ui";
76
+ const UI_SERVER_SPEC = "@canopy-iiif/app/ui/server";
77
+ const UI_SPEC_REGEX = new RegExp(`(['"])${UI_PACKAGE_SPEC.replace(/\//g, '\\/')}(['"])`, "g");
78
+
79
+ function rewriteUiImportsForServer(source) {
80
+ if (typeof source !== "string" || !source.includes(UI_PACKAGE_SPEC)) return source;
81
+ return source.replace(UI_SPEC_REGEX, ($0, open, close) => `${open}${UI_SERVER_SPEC}${close}`);
82
+ }
83
+
75
84
  function parseFrontmatter(src) {
76
85
  let input = String(src || "");
77
86
  // Strip UTF-8 BOM if present
@@ -591,6 +600,13 @@ async function compileCustomComponentModule(entryPath, signature) {
591
600
  ],
592
601
  allowOverwrite: true,
593
602
  });
603
+ try {
604
+ const built = fs.readFileSync(tmpFile, "utf8");
605
+ const rewritten = rewriteUiImportsForServer(built);
606
+ if (rewritten !== built) {
607
+ fs.writeFileSync(tmpFile, rewritten, "utf8");
608
+ }
609
+ } catch (_) {}
594
610
  } catch (err) {
595
611
  const msg = err && (err.message || err.stack) ? err.message || err.stack : err;
596
612
  throw new Error(
@@ -870,7 +886,8 @@ async function loadAppWrapper() {
870
886
  const {compile} = await import("@mdx-js/mdx");
871
887
  const raw = await fsp.readFile(appPath, "utf8");
872
888
  const {content: source} = parseFrontmatter(raw);
873
- let code = String(await compile(source, buildCompileOptions()));
889
+ const safeSource = rewriteUiImportsForServer(source);
890
+ let code = String(await compile(safeSource, buildCompileOptions()));
874
891
  // MDX v3 default export (MDXContent) does not forward external children.
875
892
  // When present, expose the underlying layout function as __MDXLayout for wrapping.
876
893
  if (
@@ -918,7 +935,8 @@ async function compileMdxFile(filePath, outPath, Layout, extraProps = {}) {
918
935
  const {compile} = await import("@mdx-js/mdx");
919
936
  const raw = await fsp.readFile(filePath, "utf8");
920
937
  const {content: source} = parseFrontmatter(raw);
921
- const compiled = await compile(source, buildCompileOptions());
938
+ const safeSource = rewriteUiImportsForServer(source);
939
+ const compiled = await compile(safeSource, buildCompileOptions());
922
940
  const code = String(compiled);
923
941
  ensureDirSync(CACHE_DIR);
924
942
  const relCacheName =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopy-iiif/app",
3
- "version": "1.8.8",
3
+ "version": "1.8.10",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "author": "Mat Jordan <mat@northwestern.edu>",
@@ -62,11 +62,13 @@
62
62
  "access": "public"
63
63
  },
64
64
  "dependencies": {
65
+ "@allmaps/leaflet": "^1.0.0-beta.53",
65
66
  "@iiif/helpers": "^1.4.0",
66
67
  "@mdx-js/mdx": "^3.1.0",
67
68
  "@mdx-js/react": "^3.1.0",
68
69
  "@radix-ui/colors": "^3.0.0",
69
70
  "charm": "^1.0.2",
71
+ "hast-util-to-html": "^9.0.5",
70
72
  "js-yaml": "^4.1.0",
71
73
  "leaflet": "^1.9.4",
72
74
  "leaflet.markercluster": "^1.5.3",
@@ -75,7 +77,6 @@
75
77
  "mdast-util-to-hast": "^13.2.0",
76
78
  "mdast-util-to-string": "^4.0.0",
77
79
  "micromark-extension-gfm-footnote": "^2.1.0",
78
- "hast-util-to-html": "^9.0.5",
79
80
  "react-masonry-css": "^1.0.16",
80
81
  "remark-gfm": "^4.0.0",
81
82
  "sass": "^1.77.0",