@yahoo/uds-create-loader 5.42.2 → 5.42.4
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 +4 -4
- package/dist/next.js +13 -13
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/loader.test.ts +8 -8
- package/src/loader.ts +10 -9
- package/src/next.test.ts +9 -12
- package/src/next.ts +17 -21
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 {
|
|
4
|
+
import { resolveLinkedAlias, resolveLinkedDir, resolveOutputAlias } from "@yahoo/uds-create-config";
|
|
5
5
|
//#region src/loader.ts
|
|
6
6
|
const traverse = _traverse.default ?? _traverse;
|
|
7
7
|
/**
|
|
@@ -30,10 +30,10 @@ const transformLoader = function(source) {
|
|
|
30
30
|
const config = loadUdsConfig(dataPath, isDev);
|
|
31
31
|
if (!config) return source;
|
|
32
32
|
const build = config.items?.settings?.settings?.build;
|
|
33
|
-
const
|
|
33
|
+
const linkedRel = resolveLinkedDir(build);
|
|
34
34
|
const outputAlias = resolveOutputAlias(build);
|
|
35
|
-
const linkedAlias =
|
|
36
|
-
if (resourcePath.replace(/\\/g, "/").includes(`/${
|
|
35
|
+
const linkedAlias = resolveLinkedAlias(build);
|
|
36
|
+
if (resourcePath.replace(/\\/g, "/").includes(`/${linkedRel}/`)) return source;
|
|
37
37
|
const projection = getLoaderProjection(config);
|
|
38
38
|
let hasComponentReference = source.includes(linkedAlias);
|
|
39
39
|
for (const name of projection.componentNames) if (source.includes(name)) {
|
package/dist/next.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __require } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveLinkedDir } from "@yahoo/uds-create-config";
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
//#region src/next.ts
|
|
@@ -10,28 +10,28 @@ function resolveLoaderPath() {
|
|
|
10
10
|
return path.join(import.meta.dirname, "loader.ts");
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
/** The linked
|
|
13
|
+
/** The linked directory + its dep names, read from the manifest
|
|
14
14
|
* `uds pull` generates. Null when the project has no linked runtime deps. */
|
|
15
|
-
function
|
|
15
|
+
function readLinkedDeps(outputDir) {
|
|
16
16
|
let buildOptions;
|
|
17
17
|
try {
|
|
18
18
|
buildOptions = JSON.parse(readFileSync(path.resolve(process.cwd(), outputDir, "config.json"), "utf-8")).items?.settings?.settings?.build;
|
|
19
19
|
} catch {
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
|
-
const
|
|
22
|
+
const linkedDirRel = resolveLinkedDir(buildOptions);
|
|
23
23
|
let deps;
|
|
24
24
|
try {
|
|
25
|
-
const manifest = JSON.parse(readFileSync(path.resolve(process.cwd(),
|
|
25
|
+
const manifest = JSON.parse(readFileSync(path.resolve(process.cwd(), linkedDirRel, "package.json"), "utf-8"));
|
|
26
26
|
deps = Object.keys(manifest.dependencies ?? {});
|
|
27
27
|
} catch {
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
if (deps.length === 0) return null;
|
|
31
|
-
const nodeModules = path.resolve(process.cwd(),
|
|
31
|
+
const nodeModules = path.resolve(process.cwd(), linkedDirRel, "node_modules");
|
|
32
32
|
if (!existsSync(nodeModules)) return null;
|
|
33
33
|
return {
|
|
34
|
-
|
|
34
|
+
linkedDirRel,
|
|
35
35
|
nodeModules,
|
|
36
36
|
deps
|
|
37
37
|
};
|
|
@@ -39,11 +39,11 @@ function readRegistryDeps(outputDir) {
|
|
|
39
39
|
/** Turbopack has no resolve.modules equivalent, so alias each registry dep
|
|
40
40
|
* to its installed path — only when the consumer's own install lacks it
|
|
41
41
|
* (the consumer's version must always win). */
|
|
42
|
-
function
|
|
42
|
+
function buildLinkedAliasMap(registry) {
|
|
43
43
|
const aliases = {};
|
|
44
44
|
for (const dep of registry.deps) {
|
|
45
45
|
if (existsSync(path.resolve(process.cwd(), "node_modules", dep))) continue;
|
|
46
|
-
if (existsSync(path.join(registry.nodeModules, dep))) aliases[dep] = `./${registry.
|
|
46
|
+
if (existsSync(path.join(registry.nodeModules, dep))) aliases[dep] = `./${registry.linkedDirRel}/node_modules/${dep}`;
|
|
47
47
|
}
|
|
48
48
|
return aliases;
|
|
49
49
|
}
|
|
@@ -73,14 +73,14 @@ function applyUds(nextConfig, options) {
|
|
|
73
73
|
if (existingRules[key]) udsRules[udsKey] = { loaders: [udsLoader] };
|
|
74
74
|
else udsRules[key] = { loaders: [udsLoader] };
|
|
75
75
|
}
|
|
76
|
-
const registry =
|
|
77
|
-
const
|
|
76
|
+
const registry = readLinkedDeps(outputDir);
|
|
77
|
+
const linkedAliases = registry ? buildLinkedAliasMap(registry) : {};
|
|
78
78
|
return {
|
|
79
79
|
...nextConfig,
|
|
80
80
|
turbopack: {
|
|
81
81
|
...turbopack,
|
|
82
|
-
...Object.keys(
|
|
83
|
-
...
|
|
82
|
+
...Object.keys(linkedAliases).length > 0 ? { resolveAlias: {
|
|
83
|
+
...linkedAliases,
|
|
84
84
|
...turbopack.resolveAlias
|
|
85
85
|
} } : {},
|
|
86
86
|
rules: {
|