@yahoo/uds-create-loader 5.42.3 → 5.43.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 +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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yahoo/uds-create-loader",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.43.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"files": [
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test:update": "bun test src/ --update-snapshots"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@yahoo/uds-create-config": "5.
|
|
41
|
+
"@yahoo/uds-create-config": "5.43.0",
|
|
42
42
|
"@babel/parser": "^7.29.0",
|
|
43
43
|
"@babel/traverse": "^7.29.0",
|
|
44
44
|
"@babel/types": "^7.29.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"optional": true
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"udsSchemaVersion":
|
|
66
|
+
"udsSchemaVersion": 20261020183330
|
|
67
67
|
}
|
package/src/loader.test.ts
CHANGED
|
@@ -90,8 +90,8 @@ export function Demo() {
|
|
|
90
90
|
|
|
91
91
|
it("runs a linked system's source import as the module the build emitted for it", () => {
|
|
92
92
|
const source = `
|
|
93
|
-
import { Avatar } from '@/uds/
|
|
94
|
-
import { useTone } from "@/uds/
|
|
93
|
+
import { Avatar } from '@/uds/linked/yos/avatar';
|
|
94
|
+
import { useTone } from "@/uds/linked/yahoo-os-v3-bridge/hooks/use-tone";
|
|
95
95
|
|
|
96
96
|
export function Demo() {
|
|
97
97
|
return <Avatar tone={useTone()} />;
|
|
@@ -103,7 +103,7 @@ export function Demo() {
|
|
|
103
103
|
expect(output).toContain(
|
|
104
104
|
'from "#uds/components/_linked/yahoo-os-v3-bridge/hooks/use-tone"',
|
|
105
105
|
);
|
|
106
|
-
expect(output).not.toContain('@/uds/
|
|
106
|
+
expect(output).not.toContain('@/uds/linked/');
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
it('follows the aliases the system declares', () => {
|
|
@@ -113,14 +113,14 @@ export function Demo() {
|
|
|
113
113
|
})
|
|
114
114
|
.toJSON() as SerializedConfig;
|
|
115
115
|
const source = `
|
|
116
|
-
import { Avatar } from '~/ds/
|
|
117
|
-
import { Stale } from '@/uds/
|
|
116
|
+
import { Avatar } from '~/ds/linked/yos/avatar';
|
|
117
|
+
import { Stale } from '@/uds/linked/yos/stale';
|
|
118
118
|
`;
|
|
119
119
|
const output = runLoader(source, config);
|
|
120
120
|
|
|
121
121
|
expect(output).toContain("from '#ds/components/_linked/yos/avatar'");
|
|
122
122
|
// Not this system's alias, so not this loader's to rewrite.
|
|
123
|
-
expect(output).toContain("from '@/uds/
|
|
123
|
+
expect(output).toContain("from '@/uds/linked/yos/stale'");
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
it('does not rewrite relative imports', () => {
|
|
@@ -294,13 +294,13 @@ export function Demo() {
|
|
|
294
294
|
expect(output).toBe(source);
|
|
295
295
|
});
|
|
296
296
|
|
|
297
|
-
it('skips an explicit build.
|
|
297
|
+
it('skips an explicit build.linkedDir', () => {
|
|
298
298
|
const box = makeBoxConfig();
|
|
299
299
|
const config = {
|
|
300
300
|
...box,
|
|
301
301
|
items: {
|
|
302
302
|
...box.items,
|
|
303
|
-
settings: { settings: { build: {
|
|
303
|
+
settings: { settings: { build: { linkedDir: 'vendor/linked' } } },
|
|
304
304
|
},
|
|
305
305
|
};
|
|
306
306
|
const source = `
|
package/src/loader.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { parse } from '@babel/parser';
|
|
2
2
|
import _traverse from '@babel/traverse';
|
|
3
3
|
import {
|
|
4
|
+
resolveLinkedAlias,
|
|
5
|
+
resolveLinkedDir,
|
|
4
6
|
resolveOutputAlias,
|
|
5
|
-
|
|
6
|
-
resolveSourceAlias,
|
|
7
|
+
type resolveSourceAlias,
|
|
7
8
|
} from '@yahoo/uds-create-config';
|
|
8
9
|
import type { LoaderDefinitionFunction } from 'webpack';
|
|
9
10
|
import {
|
|
@@ -74,26 +75,26 @@ const transformLoader: LoaderDefinitionFunction = function (source) {
|
|
|
74
75
|
const config = loadUdsConfig(dataPath, isDev);
|
|
75
76
|
if (!config) return source;
|
|
76
77
|
|
|
77
|
-
// Configurable registry location (`build.
|
|
78
|
+
// Configurable registry location (`build.linkedDir`) — same skip rationale as above. The
|
|
78
79
|
// settings are one item of the `settings` kind in a serialized config, keyed by the kind.
|
|
79
80
|
const build = (
|
|
80
81
|
config as {
|
|
81
82
|
items?: {
|
|
82
83
|
settings?: {
|
|
83
84
|
settings?: {
|
|
84
|
-
build?: Parameters<typeof
|
|
85
|
+
build?: Parameters<typeof resolveLinkedDir>[0] &
|
|
85
86
|
Parameters<typeof resolveSourceAlias>[0];
|
|
86
87
|
};
|
|
87
88
|
};
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
).items?.settings?.settings?.build;
|
|
91
|
-
const
|
|
92
|
+
const linkedRel = resolveLinkedDir(build);
|
|
92
93
|
// The prefixes the system declares: its sources' (`@/uds`) and its build output's (`#uds`). A linked
|
|
93
|
-
// system's source is imported beneath the first, `<sourceAlias>/
|
|
94
|
+
// system's source is imported beneath the first, `<sourceAlias>/linked/<slug>/…`.
|
|
94
95
|
const outputAlias = resolveOutputAlias(build);
|
|
95
|
-
const linkedAlias =
|
|
96
|
-
if (resourcePath.replace(/\\/g, '/').includes(`/${
|
|
96
|
+
const linkedAlias = resolveLinkedAlias(build);
|
|
97
|
+
if (resourcePath.replace(/\\/g, '/').includes(`/${linkedRel}/`)) {
|
|
97
98
|
return source;
|
|
98
99
|
}
|
|
99
100
|
|
|
@@ -152,7 +153,7 @@ const transformLoader: LoaderDefinitionFunction = function (source) {
|
|
|
152
153
|
const importSource: string | undefined = nodePath.node.source?.value;
|
|
153
154
|
if (!importSource) return;
|
|
154
155
|
|
|
155
|
-
// A linked system's source, imported by its alias for the types (`@/uds/
|
|
156
|
+
// A linked system's source, imported by its alias for the types (`@/uds/linked/yos/avatar`),
|
|
156
157
|
// runs as the module the build emitted from it — the same path under `components/_linked/`.
|
|
157
158
|
if (importSource.startsWith(linkedAlias)) {
|
|
158
159
|
const sourceNode = nodePath.node.source;
|
package/src/next.test.ts
CHANGED
|
@@ -7,12 +7,12 @@ import { withUds } from './next';
|
|
|
7
7
|
const TMP = path.join(import.meta.dir, '../dist/.test-tmp/next-registry-deps');
|
|
8
8
|
|
|
9
9
|
// The default registry, beside the conventional components root.
|
|
10
|
-
const REGISTRY_REL = 'src/uds/
|
|
10
|
+
const REGISTRY_REL = 'src/uds/linked';
|
|
11
11
|
|
|
12
12
|
function writeFixture(args: {
|
|
13
13
|
registryDeps?: Record<string, string>;
|
|
14
14
|
consumerHas?: string[];
|
|
15
|
-
build?: {
|
|
15
|
+
build?: { linkedDir?: string };
|
|
16
16
|
}): string {
|
|
17
17
|
const root = path.join(TMP, `proj-${Math.random().toString(36).slice(2, 8)}`);
|
|
18
18
|
|
|
@@ -25,13 +25,10 @@ function writeFixture(args: {
|
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
if (args.registryDeps) {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
args.build?.registryDir ?? REGISTRY_REL,
|
|
31
|
-
);
|
|
32
|
-
mkdirSync(path.join(registryDir, 'node_modules'), { recursive: true });
|
|
28
|
+
const linkedDir = path.join(root, args.build?.linkedDir ?? REGISTRY_REL);
|
|
29
|
+
mkdirSync(path.join(linkedDir, 'node_modules'), { recursive: true });
|
|
33
30
|
writeFileSync(
|
|
34
|
-
path.join(
|
|
31
|
+
path.join(linkedDir, 'package.json'),
|
|
35
32
|
JSON.stringify({
|
|
36
33
|
name: '@yahoo/uds-linked-runtime-deps',
|
|
37
34
|
private: true,
|
|
@@ -39,7 +36,7 @@ function writeFixture(args: {
|
|
|
39
36
|
}),
|
|
40
37
|
);
|
|
41
38
|
for (const name of Object.keys(args.registryDeps)) {
|
|
42
|
-
const pkgDir = path.join(
|
|
39
|
+
const pkgDir = path.join(linkedDir, 'node_modules', name);
|
|
43
40
|
mkdirSync(pkgDir, { recursive: true });
|
|
44
41
|
writeFileSync(
|
|
45
42
|
path.join(pkgDir, 'package.json'),
|
|
@@ -145,17 +142,17 @@ describe('withUds — linked-registry dependency resolution', () => {
|
|
|
145
142
|
).toBeUndefined();
|
|
146
143
|
});
|
|
147
144
|
|
|
148
|
-
it('honors a custom build.
|
|
145
|
+
it('honors a custom build.linkedDir', () => {
|
|
149
146
|
const root = writeFixture({
|
|
150
147
|
registryDeps: { clsx: '^2.0.0' },
|
|
151
|
-
build: {
|
|
148
|
+
build: { linkedDir: 'src/uds/linked' },
|
|
152
149
|
});
|
|
153
150
|
|
|
154
151
|
const config = applyIn(root, () => withUds({}));
|
|
155
152
|
|
|
156
153
|
const aliases = (config as { turbopack?: { resolveAlias?: unknown } })
|
|
157
154
|
.turbopack?.resolveAlias as Record<string, string>;
|
|
158
|
-
expect(aliases.clsx).toBe('./src/uds/
|
|
155
|
+
expect(aliases.clsx).toBe('./src/uds/linked/node_modules/clsx');
|
|
159
156
|
});
|
|
160
157
|
|
|
161
158
|
it('preserves caller-provided resolveAlias entries', () => {
|
package/src/next.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { resolveLinkedDir } from '@yahoo/uds-create-config';
|
|
4
4
|
import type { NextConfig } from 'next';
|
|
5
5
|
|
|
6
6
|
export interface WithUdsOptions {
|
|
@@ -22,12 +22,12 @@ function resolveLoaderPath(): string {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
/** The linked
|
|
25
|
+
/** The linked directory + its dep names, read from the manifest
|
|
26
26
|
* `uds pull` generates. Null when the project has no linked runtime deps. */
|
|
27
|
-
function
|
|
27
|
+
function readLinkedDeps(
|
|
28
28
|
outputDir: string,
|
|
29
|
-
): {
|
|
30
|
-
let buildOptions: {
|
|
29
|
+
): { linkedDirRel: string; nodeModules: string; deps: string[] } | null {
|
|
30
|
+
let buildOptions: { linkedDir?: string } | undefined;
|
|
31
31
|
try {
|
|
32
32
|
buildOptions = (
|
|
33
33
|
JSON.parse(
|
|
@@ -43,13 +43,13 @@ function readRegistryDeps(
|
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const
|
|
46
|
+
const linkedDirRel = resolveLinkedDir(buildOptions);
|
|
47
47
|
|
|
48
48
|
let deps: string[];
|
|
49
49
|
try {
|
|
50
50
|
const manifest = JSON.parse(
|
|
51
51
|
readFileSync(
|
|
52
|
-
path.resolve(process.cwd(),
|
|
52
|
+
path.resolve(process.cwd(), linkedDirRel, 'package.json'),
|
|
53
53
|
'utf-8',
|
|
54
54
|
),
|
|
55
55
|
) as { dependencies?: Record<string, string> };
|
|
@@ -60,21 +60,17 @@ function readRegistryDeps(
|
|
|
60
60
|
|
|
61
61
|
if (deps.length === 0) return null;
|
|
62
62
|
|
|
63
|
-
const nodeModules = path.resolve(
|
|
64
|
-
process.cwd(),
|
|
65
|
-
registryDirRel,
|
|
66
|
-
'node_modules',
|
|
67
|
-
);
|
|
63
|
+
const nodeModules = path.resolve(process.cwd(), linkedDirRel, 'node_modules');
|
|
68
64
|
if (!existsSync(nodeModules)) return null;
|
|
69
65
|
|
|
70
|
-
return {
|
|
66
|
+
return { linkedDirRel, nodeModules, deps };
|
|
71
67
|
}
|
|
72
68
|
|
|
73
69
|
/** Turbopack has no resolve.modules equivalent, so alias each registry dep
|
|
74
70
|
* to its installed path — only when the consumer's own install lacks it
|
|
75
71
|
* (the consumer's version must always win). */
|
|
76
|
-
function
|
|
77
|
-
registry: NonNullable<ReturnType<typeof
|
|
72
|
+
function buildLinkedAliasMap(
|
|
73
|
+
registry: NonNullable<ReturnType<typeof readLinkedDeps>>,
|
|
78
74
|
): Record<string, string> {
|
|
79
75
|
const aliases: Record<string, string> = {};
|
|
80
76
|
|
|
@@ -83,7 +79,7 @@ function buildRegistryAliasMap(
|
|
|
83
79
|
if (existsSync(consumerCopy)) continue;
|
|
84
80
|
|
|
85
81
|
if (existsSync(path.join(registry.nodeModules, dep))) {
|
|
86
|
-
aliases[dep] = `./${registry.
|
|
82
|
+
aliases[dep] = `./${registry.linkedDirRel}/node_modules/${dep}`;
|
|
87
83
|
}
|
|
88
84
|
}
|
|
89
85
|
|
|
@@ -132,20 +128,20 @@ function applyUds(
|
|
|
132
128
|
}
|
|
133
129
|
}
|
|
134
130
|
|
|
135
|
-
// Linked-system runtime deps live in `<
|
|
131
|
+
// Linked-system runtime deps live in `<linkedDir>/node_modules` (written
|
|
136
132
|
// by `uds pull`), off the walk-up path of the downleveled `.uds` modules
|
|
137
133
|
// that import them.
|
|
138
|
-
const registry =
|
|
139
|
-
const
|
|
134
|
+
const registry = readLinkedDeps(outputDir);
|
|
135
|
+
const linkedAliases = registry ? buildLinkedAliasMap(registry) : {};
|
|
140
136
|
|
|
141
137
|
return {
|
|
142
138
|
...nextConfig,
|
|
143
139
|
turbopack: {
|
|
144
140
|
...turbopack,
|
|
145
|
-
...(Object.keys(
|
|
141
|
+
...(Object.keys(linkedAliases).length > 0
|
|
146
142
|
? {
|
|
147
143
|
resolveAlias: {
|
|
148
|
-
...
|
|
144
|
+
...linkedAliases,
|
|
149
145
|
...turbopack.resolveAlias,
|
|
150
146
|
},
|
|
151
147
|
}
|