@yahoo/uds-create-loader 4.46.1 → 4.47.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/loader.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { getLoaderProjection, loadUdsConfig } from "./loader/artifacts.js";
2
2
  import { parse } from "@babel/parser";
3
3
  import _traverse from "@babel/traverse";
4
- import { resolveRegistryDir } from "@yahoo/uds-create-config";
4
+ import { resolveOutputAlias, resolveRegistryDir, resolveSourceAlias } from "@yahoo/uds-create-config";
5
5
  //#region src/loader.ts
6
6
  const traverse = _traverse.default ?? _traverse;
7
7
  /**
@@ -29,10 +29,13 @@ const transformLoader = function(source) {
29
29
  if (!skipWatchDependencies) loaderContext.addDependency?.(dataPath);
30
30
  const config = loadUdsConfig(dataPath, isDev);
31
31
  if (!config) return source;
32
- const registryRel = resolveRegistryDir(config.items?.settings?.settings?.build);
32
+ const build = config.items?.settings?.settings?.build;
33
+ const registryRel = resolveRegistryDir(build);
34
+ const outputAlias = resolveOutputAlias(build);
35
+ const linkedAlias = `${resolveSourceAlias(build)}/registry/`;
33
36
  if (resourcePath.replace(/\\/g, "/").includes(`/${registryRel}/`)) return source;
34
37
  const projection = getLoaderProjection(config);
35
- let hasComponentReference = false;
38
+ let hasComponentReference = source.includes(linkedAlias);
36
39
  for (const name of projection.componentNames) if (source.includes(name)) {
37
40
  hasComponentReference = true;
38
41
  break;
@@ -56,6 +59,17 @@ const transformLoader = function(source) {
56
59
  traverse(ast, { ImportDeclaration(nodePath) {
57
60
  const importSource = nodePath.node.source?.value;
58
61
  if (!importSource) return;
62
+ if (importSource.startsWith(linkedAlias)) {
63
+ const sourceNode = nodePath.node.source;
64
+ if (typeof sourceNode.start !== "number" || typeof sourceNode.end !== "number") return;
65
+ const quote = source[sourceNode.start] ?? "'";
66
+ edits.push({
67
+ start: sourceNode.start,
68
+ end: sourceNode.end,
69
+ value: `${quote}${outputAlias}/components/_linked/${importSource.slice(linkedAlias.length)}${quote}`
70
+ });
71
+ return;
72
+ }
59
73
  if (!(!importSource.startsWith(".") && !importSource.startsWith("/"))) return;
60
74
  let shouldRewriteSource = false;
61
75
  for (const specifier of nodePath.node.specifiers) {
@@ -76,7 +90,7 @@ const transformLoader = function(source) {
76
90
  edits.push({
77
91
  start: sourceNode.start,
78
92
  end: sourceNode.end,
79
- value: `${quote}#uds/components/${segmentMatch[1]}${quote}`
93
+ value: `${quote}${outputAlias}/components/${segmentMatch[1]}${quote}`
80
94
  });
81
95
  }
82
96
  } });