@yahoo/uds-create-loader 2.25.1 → 2.27.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/next.js +55 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/next.test.ts +169 -0
- package/src/next.ts +101 -1
package/dist/next.js
CHANGED
|
@@ -1,8 +1,51 @@
|
|
|
1
1
|
import { __require } from "./_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { resolveRegistryDir } from "@yahoo/uds-create-config";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
4
|
import path from "node:path";
|
|
3
5
|
//#region src/next.ts
|
|
4
6
|
function resolveLoaderPath() {
|
|
5
|
-
|
|
7
|
+
try {
|
|
8
|
+
return __require.resolve("@yahoo/uds-create-loader/loader");
|
|
9
|
+
} catch {
|
|
10
|
+
return path.join(import.meta.dirname, "loader.ts");
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** The linked registry's install root + dep names, read from the manifest
|
|
14
|
+
* `uds pull` generates. Null when the project has no linked runtime deps. */
|
|
15
|
+
function readRegistryDeps(outputDir) {
|
|
16
|
+
let buildOptions;
|
|
17
|
+
try {
|
|
18
|
+
buildOptions = JSON.parse(readFileSync(path.resolve(process.cwd(), outputDir, "config.json"), "utf-8")).buildOptions;
|
|
19
|
+
} catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const registryDirRel = resolveRegistryDir(buildOptions);
|
|
23
|
+
let deps;
|
|
24
|
+
try {
|
|
25
|
+
const manifest = JSON.parse(readFileSync(path.resolve(process.cwd(), registryDirRel, "package.json"), "utf-8"));
|
|
26
|
+
deps = Object.keys(manifest.dependencies ?? {});
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (deps.length === 0) return null;
|
|
31
|
+
const nodeModules = path.resolve(process.cwd(), registryDirRel, "node_modules");
|
|
32
|
+
if (!existsSync(nodeModules)) return null;
|
|
33
|
+
return {
|
|
34
|
+
registryDirRel,
|
|
35
|
+
nodeModules,
|
|
36
|
+
deps
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/** Turbopack has no resolve.modules equivalent, so alias each registry dep
|
|
40
|
+
* to its installed path — only when the consumer's own install lacks it
|
|
41
|
+
* (the consumer's version must always win). */
|
|
42
|
+
function buildRegistryAliasMap(registry) {
|
|
43
|
+
const aliases = {};
|
|
44
|
+
for (const dep of registry.deps) {
|
|
45
|
+
if (existsSync(path.resolve(process.cwd(), "node_modules", dep))) continue;
|
|
46
|
+
if (existsSync(path.join(registry.nodeModules, dep))) aliases[dep] = `./${registry.registryDirRel}/node_modules/${dep}`;
|
|
47
|
+
}
|
|
48
|
+
return aliases;
|
|
6
49
|
}
|
|
7
50
|
function applyUds(nextConfig, options) {
|
|
8
51
|
const outputDir = options?.outputDir ?? ".uds";
|
|
@@ -30,10 +73,16 @@ function applyUds(nextConfig, options) {
|
|
|
30
73
|
if (existingRules[key]) udsRules[udsKey] = { loaders: [udsLoader] };
|
|
31
74
|
else udsRules[key] = { loaders: [udsLoader] };
|
|
32
75
|
}
|
|
76
|
+
const registry = readRegistryDeps(outputDir);
|
|
77
|
+
const registryAliases = registry ? buildRegistryAliasMap(registry) : {};
|
|
33
78
|
return {
|
|
34
79
|
...nextConfig,
|
|
35
80
|
turbopack: {
|
|
36
81
|
...turbopack,
|
|
82
|
+
...Object.keys(registryAliases).length > 0 ? { resolveAlias: {
|
|
83
|
+
...registryAliases,
|
|
84
|
+
...turbopack.resolveAlias
|
|
85
|
+
} } : {},
|
|
37
86
|
rules: {
|
|
38
87
|
...existingRules,
|
|
39
88
|
...udsRules
|
|
@@ -51,6 +100,11 @@ function applyUds(nextConfig, options) {
|
|
|
51
100
|
}
|
|
52
101
|
}]
|
|
53
102
|
});
|
|
103
|
+
if (registry) {
|
|
104
|
+
config.resolve ??= {};
|
|
105
|
+
config.resolve.modules ??= ["node_modules"];
|
|
106
|
+
if (!config.resolve.modules.includes(registry.nodeModules)) config.resolve.modules.push(registry.nodeModules);
|
|
107
|
+
}
|
|
54
108
|
if (skipWatch) {
|
|
55
109
|
const existing = config.watchOptions?.ignored;
|
|
56
110
|
config.watchOptions = {
|