@forsakringskassan/docs-generator 2.20.0 → 2.21.0

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/dist/index.d.ts CHANGED
@@ -19,7 +19,7 @@ export declare interface CompileOptions {
19
19
  *
20
20
  * - `head` - the asset is injected in `<head>`
21
21
  * - `body` - the asset is injected in `<body>`
22
- * - `none` (default) - the asset is not injected.
22
+ * - `none` (default) - the asset is not injected (but is available in importmap)
23
23
  */
24
24
  appendTo: "none" | "head" | "body";
25
25
  /**
@@ -510,8 +510,9 @@ export declare interface ProcessorContext {
510
510
  /* Excluded from this release type: hasTemplate */
511
511
  setTopNavigation(root: NavigationSection): void;
512
512
  setSideNavigation(root: NavigationSection): void;
513
- getAllTemplateData(): Record<string, unknown>;
513
+ getAllTemplateData(): TemplateData & Record<string, unknown>;
514
514
  getTemplateData<K extends keyof TemplateData>(key: K): TemplateData[K] | undefined;
515
+ getTemplateData<K extends keyof TemplateData>(key: K, defaultValue: TemplateData[K]): TemplateData[K];
515
516
  getTemplateData(key: string): unknown;
516
517
  setTemplateData<K extends keyof TemplateData>(key: string, value: TemplateData[K]): void;
517
518
  setTemplateData(key: string, value: unknown): void;
package/dist/index.js CHANGED
@@ -1616,9 +1616,9 @@ function cssAssetProcessor(assetFolder, assets, options) {
1616
1616
  name: "css-asset-processor",
1617
1617
  after: "assets",
1618
1618
  async handler(context) {
1619
- const assetInfo = context.getTemplateData("assets") ?? {};
1620
- const head = context.getTemplateData("injectHead") ?? [];
1621
- const body = context.getTemplateData("injectBody") ?? [];
1619
+ const assetInfo = context.getTemplateData("assets", {});
1620
+ const head = context.getTemplateData("injectHead", []);
1621
+ const body = context.getTemplateData("injectBody", []);
1622
1622
  for (const asset of toSorted$1(assets, byPriority$1)) {
1623
1623
  const info = await compileStyle(
1624
1624
  assetFolder,
@@ -1628,7 +1628,10 @@ function cssAssetProcessor(assetFolder, assets, options) {
1628
1628
  );
1629
1629
  const attrs = serializeAttrs(asset.options.attributes);
1630
1630
  const inject = { ...info, attrs: Array.from(attrs).join(" ") };
1631
- assetInfo[asset.name] = info;
1631
+ assetInfo[asset.name] = {
1632
+ ...info,
1633
+ importmap: false
1634
+ };
1632
1635
  switch (asset.options.appendTo) {
1633
1636
  case "none":
1634
1637
  break;
@@ -1639,11 +1642,8 @@ function cssAssetProcessor(assetFolder, assets, options) {
1639
1642
  body.push(inject);
1640
1643
  break;
1641
1644
  }
1642
- context.setTemplateData("injectHead", head);
1643
- context.setTemplateData("injectBody", body);
1644
1645
  context.log(info.filename, formatSize(info.size));
1645
1646
  }
1646
- context.setTemplateData("assets", assetInfo);
1647
1647
  }
1648
1648
  };
1649
1649
  }
@@ -1652,11 +1652,16 @@ function esbuild(options) {
1652
1652
  return esbuild$1.build(options);
1653
1653
  }
1654
1654
 
1655
+ function toExternalVendor(vendor) {
1656
+ return typeof vendor === "string" ? vendor : vendor.package;
1657
+ }
1655
1658
  async function compileScript(options) {
1656
1659
  const {
1657
1660
  assetFolder,
1658
1661
  name,
1659
1662
  src,
1663
+ assets,
1664
+ vendor,
1660
1665
  buildOptions,
1661
1666
  fs: fs$1 = fs
1662
1667
  } = options;
@@ -1664,13 +1669,14 @@ async function compileScript(options) {
1664
1669
  try {
1665
1670
  const entryPoints = [src instanceof URL ? node_url.fileURLToPath(src) : src];
1666
1671
  const outfile = path$1.join("temp", `asset-${name}.js`);
1672
+ const external = [...assets, ...vendor.map(toExternalVendor)];
1667
1673
  await esbuild({
1668
1674
  entryPoints,
1669
1675
  outfile,
1670
1676
  bundle: true,
1671
- format: "iife",
1677
+ format: "esm",
1672
1678
  platform: "browser",
1673
- external: ["vue", "@fkui/vue"],
1679
+ external,
1674
1680
  tsconfig: path$1.join(__dirname, "../tsconfig-examples.json"),
1675
1681
  ...buildOptions,
1676
1682
  define: {
@@ -1706,24 +1712,33 @@ function byPriority({ options: a }, { options: b }) {
1706
1712
  function toSorted(values, comparator) {
1707
1713
  return [...values].sort(comparator);
1708
1714
  }
1709
- function jsAssetProcessor(assetFolder, assets) {
1715
+ function isExternal(asset) {
1716
+ return asset.options.appendTo === "none";
1717
+ }
1718
+ function jsAssetProcessor(assetFolder, assets, vendor) {
1719
+ const externalAssets = assets.filter(isExternal).map((it) => it.name);
1710
1720
  return {
1711
1721
  name: "js-asset-processor",
1712
1722
  after: "assets",
1713
1723
  async handler(context) {
1714
- const assetInfo = context.getTemplateData("assets") ?? {};
1715
- const head = context.getTemplateData("injectHead") ?? [];
1716
- const body = context.getTemplateData("injectBody") ?? [];
1724
+ const assetInfo = context.getTemplateData("assets", {});
1725
+ const head = context.getTemplateData("injectHead", []);
1726
+ const body = context.getTemplateData("injectBody", []);
1717
1727
  for (const asset of toSorted(assets, byPriority)) {
1718
1728
  const info = await compileScript({
1719
1729
  assetFolder,
1720
1730
  name: asset.name,
1721
1731
  src: asset.src,
1732
+ assets: externalAssets,
1733
+ vendor,
1722
1734
  buildOptions: asset.buildOptions
1723
1735
  });
1724
1736
  const attrs = serializeAttrs(asset.options.attributes);
1725
1737
  const inject = { ...info, attrs: Array.from(attrs).join(" ") };
1726
- assetInfo[asset.name] = info;
1738
+ assetInfo[asset.name] = {
1739
+ ...info,
1740
+ importmap: externalAssets.includes(asset.name)
1741
+ };
1727
1742
  switch (asset.options.appendTo) {
1728
1743
  case "none":
1729
1744
  break;
@@ -1734,8 +1749,6 @@ function jsAssetProcessor(assetFolder, assets) {
1734
1749
  body.push(inject);
1735
1750
  break;
1736
1751
  }
1737
- context.setTemplateData("injectHead", head);
1738
- context.setTemplateData("injectBody", body);
1739
1752
  context.log(info.filename, formatSize(info.size));
1740
1753
  }
1741
1754
  }
@@ -2262,16 +2275,25 @@ async function render(doc, docs, nav, vendors, options) {
2262
2275
  sidenav,
2263
2276
  vendors,
2264
2277
  importmap(doc2) {
2265
- const imports = Object.fromEntries(
2266
- vendors.map((it) => {
2278
+ const assets = Object.values(templateData.assets).filter(
2279
+ (it) => it.importmap
2280
+ );
2281
+ const imports = Object.fromEntries([
2282
+ ...vendors.map((it) => {
2267
2283
  return [it.package, relative(it.publicPath, doc2)];
2284
+ }),
2285
+ ...assets.map((it) => {
2286
+ return [it.name, relative(it.publicPath, doc2)];
2268
2287
  })
2269
- );
2270
- const integrity = Object.fromEntries(
2271
- vendors.map((it) => {
2288
+ ]);
2289
+ const integrity = Object.fromEntries([
2290
+ ...vendors.map((it) => {
2291
+ return [relative(it.publicPath, doc2), it.integrity];
2292
+ }),
2293
+ ...assets.map((it) => {
2272
2294
  return [relative(it.publicPath, doc2), it.integrity];
2273
2295
  })
2274
- );
2296
+ ]);
2275
2297
  const importmap = { imports, integrity };
2276
2298
  return JSON.stringify(importmap, null, 2);
2277
2299
  }
@@ -2717,7 +2739,7 @@ function createContext(outputFolder, templateLoader) {
2717
2739
  children: [],
2718
2740
  visible: true
2719
2741
  };
2720
- const templateData = {};
2742
+ const templateData = /* @__PURE__ */ new Map();
2721
2743
  return {
2722
2744
  get docs() {
2723
2745
  return docs;
@@ -2769,13 +2791,20 @@ function createContext(outputFolder, templateLoader) {
2769
2791
  sidenav = root;
2770
2792
  },
2771
2793
  getAllTemplateData() {
2772
- return templateData;
2794
+ return Object.fromEntries(templateData.entries());
2773
2795
  },
2774
- getTemplateData(key) {
2775
- return templateData[key];
2796
+ getTemplateData(key, defaultValue) {
2797
+ if (templateData.has(key)) {
2798
+ return templateData.get(key);
2799
+ } else if (defaultValue) {
2800
+ templateData.set(key, defaultValue);
2801
+ return defaultValue;
2802
+ } else {
2803
+ return void 0;
2804
+ }
2776
2805
  },
2777
2806
  setTemplateData(key, value) {
2778
- templateData[key] = value;
2807
+ templateData.set(key, value);
2779
2808
  }
2780
2809
  };
2781
2810
  }
@@ -2896,7 +2925,7 @@ class Generator {
2896
2925
  redirectProcessor(),
2897
2926
  vendorProcessor(assetFolder, this.vendor),
2898
2927
  cssAssetProcessor(assetFolder, this.styles, { cwd }),
2899
- jsAssetProcessor(assetFolder, this.scripts),
2928
+ jsAssetProcessor(assetFolder, this.scripts, this.vendor),
2900
2929
  staticResourcesProcessor(assetFolder, this.resources),
2901
2930
  navigationProcessor(),
2902
2931
  nunjucksProcessor({