@astryxdesign/build 0.7.6-canary.f73623d → 0.7.6-canary.f77aaf2
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/package.json +16 -2
- package/src/index.js +12 -8
- package/src/babel.test.mjs +0 -111
- package/src/next.test.mjs +0 -753
- package/src/packed-consumer.test.mjs +0 -186
- package/src/postcss.data-defaults.test.mjs +0 -168
- package/src/postcss.test.mjs +0 -135
- package/src/postcss.workspace-links.test.mjs +0 -163
- package/src/vite.build.test.ts +0 -476
- package/src/vite.test.ts +0 -329
package/src/next.test.mjs
DELETED
|
@@ -1,753 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file next.test.mjs
|
|
5
|
-
* @description Verifies that `withAstryx()` routes an app's own
|
|
6
|
-
* `@astryxdesign/*` imports to the packages' `source` entries. The scoped
|
|
7
|
-
* module rule only governs requests issued from inside node_modules, so
|
|
8
|
-
* without the aliases an app resolves the library through `default` to dist
|
|
9
|
-
* and renders unstyled against source-compiled CSS.
|
|
10
|
-
*
|
|
11
|
-
* Resolution is asserted through `enhanced-resolve` — the resolver webpack
|
|
12
|
-
* itself runs — because alias precedence is an ordering property of the
|
|
13
|
-
* resolver, not of the config object. Reading keys back out of
|
|
14
|
-
* `config.resolve.alias` cannot tell a winning entry from a shadowed one.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import {describe, it, expect, beforeAll, afterAll, afterEach, vi} from 'vitest';
|
|
18
|
-
import * as fs from 'node:fs';
|
|
19
|
-
import * as os from 'node:os';
|
|
20
|
-
import * as path from 'node:path';
|
|
21
|
-
import {createRequire} from 'node:module';
|
|
22
|
-
|
|
23
|
-
const require = createRequire(import.meta.url);
|
|
24
|
-
const {withAstryx} = require('./next.js');
|
|
25
|
-
const {ResolverFactory, CachedInputFileSystem} = require('enhanced-resolve');
|
|
26
|
-
|
|
27
|
-
let appDir;
|
|
28
|
-
|
|
29
|
-
/** Files the fixture package needs on disk for the resolver to accept them. */
|
|
30
|
-
const CORE_FILES = [
|
|
31
|
-
'src/index.ts',
|
|
32
|
-
'src/AlertDialog/index.ts',
|
|
33
|
-
'dist/index.js',
|
|
34
|
-
'dist/AlertDialog/index.js',
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A consumer app with `@astryxdesign/core` installed the way npm lays it out,
|
|
39
|
-
* so the helper resolves real manifests rather than the workspace it lives in.
|
|
40
|
-
*/
|
|
41
|
-
beforeAll(() => {
|
|
42
|
-
// Canonical, not the `mkdtemp` path: on macOS `os.tmpdir()` is under `/var`,
|
|
43
|
-
// a symlink to `/private/var`, and the resolver reports the real path.
|
|
44
|
-
appDir = fs.realpathSync(
|
|
45
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-next-')),
|
|
46
|
-
);
|
|
47
|
-
const coreDir = path.join(appDir, 'node_modules/@astryxdesign/core');
|
|
48
|
-
for (const file of CORE_FILES) {
|
|
49
|
-
const target = path.join(coreDir, file);
|
|
50
|
-
fs.mkdirSync(path.dirname(target), {recursive: true});
|
|
51
|
-
fs.writeFileSync(target, '');
|
|
52
|
-
}
|
|
53
|
-
fs.writeFileSync(
|
|
54
|
-
path.join(coreDir, 'package.json'),
|
|
55
|
-
JSON.stringify({
|
|
56
|
-
name: '@astryxdesign/core',
|
|
57
|
-
exports: {
|
|
58
|
-
'.': {
|
|
59
|
-
source: './src/index.ts',
|
|
60
|
-
default: './dist/index.js',
|
|
61
|
-
},
|
|
62
|
-
'./AlertDialog': {
|
|
63
|
-
source: './src/AlertDialog/index.ts',
|
|
64
|
-
default: './dist/AlertDialog/index.js',
|
|
65
|
-
},
|
|
66
|
-
'./reset.css': {default: './src/reset.css'},
|
|
67
|
-
'./generated/*': {source: './src/generated/*'},
|
|
68
|
-
},
|
|
69
|
-
}),
|
|
70
|
-
);
|
|
71
|
-
fs.mkdirSync(path.join(appDir, 'src'), {recursive: true});
|
|
72
|
-
fs.writeFileSync(path.join(appDir, 'src/page.tsx'), '');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
afterAll(() => {
|
|
76
|
-
fs.rmSync(appDir, {recursive: true, force: true});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
/** Run the helper's webpack hook the way Next.js does. */
|
|
80
|
-
function resolveConfig(nextConfig = {}, config = {resolve: {}}) {
|
|
81
|
-
return withAstryx(nextConfig).webpack(config, {dir: appDir});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Resolve a request from the app's own source, through the resolver webpack
|
|
86
|
-
* uses, under the config `withAstryx()` produced.
|
|
87
|
-
*/
|
|
88
|
-
function resolveFromApp(request, callerResolve = {}) {
|
|
89
|
-
const {resolve} = resolveConfig({}, {resolve: callerResolve});
|
|
90
|
-
const resolver = ResolverFactory.createResolver({
|
|
91
|
-
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
92
|
-
extensions: ['.ts', '.tsx', '.js'],
|
|
93
|
-
conditionNames: ['import', 'default'],
|
|
94
|
-
alias: resolve.alias,
|
|
95
|
-
useSyncFileSystemCalls: true,
|
|
96
|
-
});
|
|
97
|
-
return resolver.resolveSync({}, path.join(appDir, 'src'), request);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* The same, for an alias the caller contributes from its own `webpack` hook —
|
|
102
|
-
* the composition path a Next config takes when it wraps `withAstryx()`.
|
|
103
|
-
*/
|
|
104
|
-
function resolveFromAppWithHook(request, hookAlias) {
|
|
105
|
-
const {resolve} = withAstryx({
|
|
106
|
-
webpack: cfg => {
|
|
107
|
-
Object.assign(cfg.resolve.alias, hookAlias);
|
|
108
|
-
return cfg;
|
|
109
|
-
},
|
|
110
|
-
}).webpack({resolve: {alias: {}}}, {dir: appDir});
|
|
111
|
-
const resolver = ResolverFactory.createResolver({
|
|
112
|
-
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
113
|
-
extensions: ['.ts', '.tsx', '.js'],
|
|
114
|
-
conditionNames: ['import', 'default'],
|
|
115
|
-
alias: resolve.alias,
|
|
116
|
-
useSyncFileSystemCalls: true,
|
|
117
|
-
});
|
|
118
|
-
return resolver.resolveSync({}, path.join(appDir, 'src'), request);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/** The installed fixture's absolute path for one of its files. */
|
|
122
|
-
function corePath(...segments) {
|
|
123
|
-
return path.join(appDir, 'node_modules/@astryxdesign/core', ...segments);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
describe('withAstryx', () => {
|
|
127
|
-
// Every case in this block is a config that resolves successfully, so none of
|
|
128
|
-
// them may warn. Asserting it here rather than per-test means a future
|
|
129
|
-
// coverage check that misreads a working alias — as one did for wildcards —
|
|
130
|
-
// fails the suite instead of quietly logging into it.
|
|
131
|
-
let warned;
|
|
132
|
-
beforeEach(() => {
|
|
133
|
-
warned = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
134
|
-
});
|
|
135
|
-
afterEach(() => {
|
|
136
|
-
expect(warned).not.toHaveBeenCalled();
|
|
137
|
-
vi.restoreAllMocks();
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('resolves the package root to its source entry', () => {
|
|
141
|
-
expect(resolveFromApp('@astryxdesign/core')).toBe(corePath('src/index.ts'));
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('resolves documented subpath entry points, not just the root', () => {
|
|
145
|
-
expect(resolveFromApp('@astryxdesign/core/AlertDialog')).toBe(
|
|
146
|
-
corePath('src/AlertDialog/index.ts'),
|
|
147
|
-
);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('lets a caller prefix alias win over the generated entries', () => {
|
|
151
|
-
const custom = path.join(appDir, 'custom');
|
|
152
|
-
fs.mkdirSync(custom, {recursive: true});
|
|
153
|
-
fs.writeFileSync(path.join(custom, 'index.js'), '');
|
|
154
|
-
|
|
155
|
-
expect(
|
|
156
|
-
resolveFromApp('@astryxdesign/core', {
|
|
157
|
-
alias: {'@astryxdesign/core': custom},
|
|
158
|
-
}),
|
|
159
|
-
).toBe(path.join(custom, 'index.js'));
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('lets a caller prefix alias win for subpaths too', () => {
|
|
163
|
-
const custom = path.join(appDir, 'custom');
|
|
164
|
-
fs.mkdirSync(path.join(custom, 'AlertDialog'), {recursive: true});
|
|
165
|
-
fs.writeFileSync(path.join(custom, 'AlertDialog/index.js'), '');
|
|
166
|
-
|
|
167
|
-
expect(
|
|
168
|
-
resolveFromApp('@astryxdesign/core/AlertDialog', {
|
|
169
|
-
alias: {'@astryxdesign/core': custom},
|
|
170
|
-
}),
|
|
171
|
-
).toBe(path.join(custom, 'AlertDialog/index.js'));
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('lets a caller wildcard alias win over the generated entries', () => {
|
|
175
|
-
const custom = path.join(appDir, 'custom');
|
|
176
|
-
fs.mkdirSync(custom, {recursive: true});
|
|
177
|
-
fs.writeFileSync(path.join(custom, 'index.js'), '');
|
|
178
|
-
|
|
179
|
-
expect(
|
|
180
|
-
resolveFromApp('@astryxdesign/core', {
|
|
181
|
-
alias: {'@astryxdesign/*': custom},
|
|
182
|
-
}),
|
|
183
|
-
).toBe(path.join(custom, 'index.js'));
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('lets a caller wildcard alias win for subpaths too', () => {
|
|
187
|
-
const custom = path.join(appDir, 'custom');
|
|
188
|
-
fs.mkdirSync(path.join(custom, 'core/AlertDialog'), {recursive: true});
|
|
189
|
-
fs.writeFileSync(path.join(custom, 'core/AlertDialog/index.js'), '');
|
|
190
|
-
|
|
191
|
-
// A wildcard target substitutes the matched part, so the subpath survives;
|
|
192
|
-
// a plain target collapses every request onto the one directory.
|
|
193
|
-
expect(
|
|
194
|
-
resolveFromApp('@astryxdesign/core/AlertDialog', {
|
|
195
|
-
alias: {'@astryxdesign/*': path.join(custom, '*')},
|
|
196
|
-
}),
|
|
197
|
-
).toBe(path.join(custom, 'core/AlertDialog/index.js'));
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it('resolves through a symlinked app root', () => {
|
|
201
|
-
const link = path.join(
|
|
202
|
-
path.dirname(appDir),
|
|
203
|
-
`${path.basename(appDir)}-link`,
|
|
204
|
-
);
|
|
205
|
-
try {
|
|
206
|
-
fs.symlinkSync(appDir, link, 'dir');
|
|
207
|
-
} catch {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const {resolve} = withAstryx({}).webpack({resolve: {}}, {dir: link});
|
|
211
|
-
const resolver = ResolverFactory.createResolver({
|
|
212
|
-
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
213
|
-
extensions: ['.ts', '.tsx', '.js'],
|
|
214
|
-
conditionNames: ['import', 'default'],
|
|
215
|
-
alias: resolve.alias,
|
|
216
|
-
useSyncFileSystemCalls: true,
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
expect(
|
|
220
|
-
resolver.resolveSync({}, path.join(link, 'src'), '@astryxdesign/core'),
|
|
221
|
-
).toBe(corePath('src/index.ts'));
|
|
222
|
-
|
|
223
|
-
fs.unlinkSync(link);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('lets a caller exact alias win for the bare specifier', () => {
|
|
227
|
-
const pinned = corePath('dist/index.js');
|
|
228
|
-
|
|
229
|
-
expect(
|
|
230
|
-
resolveFromApp('@astryxdesign/core', {
|
|
231
|
-
alias: {'@astryxdesign/core$': pinned},
|
|
232
|
-
}),
|
|
233
|
-
).toBe(pinned);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('keeps the generated subpaths when the caller pins only the root', () => {
|
|
237
|
-
expect(
|
|
238
|
-
resolveFromApp('@astryxdesign/core/AlertDialog', {
|
|
239
|
-
alias: {'@astryxdesign/core$': corePath('dist/index.js')},
|
|
240
|
-
}),
|
|
241
|
-
).toBe(corePath('src/AlertDialog/index.ts'));
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
it('preserves an array-shaped caller alias', () => {
|
|
245
|
-
const pinned = corePath('dist/index.js');
|
|
246
|
-
const {resolve} = resolveConfig(
|
|
247
|
-
{},
|
|
248
|
-
{resolve: {alias: [{name: '@astryxdesign/core', alias: pinned}]}},
|
|
249
|
-
);
|
|
250
|
-
|
|
251
|
-
expect(Array.isArray(resolve.alias)).toBe(true);
|
|
252
|
-
expect(resolve.alias[0]).toEqual({
|
|
253
|
-
name: '@astryxdesign/core',
|
|
254
|
-
alias: pinned,
|
|
255
|
-
});
|
|
256
|
-
expect(
|
|
257
|
-
resolve.alias.some(
|
|
258
|
-
entry => entry.name === '@astryxdesign/core/AlertDialog',
|
|
259
|
-
),
|
|
260
|
-
).toBe(false);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('skips export keys that ship no source condition', () => {
|
|
264
|
-
const {resolve} = resolveConfig();
|
|
265
|
-
|
|
266
|
-
expect(resolve.alias).not.toHaveProperty('@astryxdesign/core/reset.css$');
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it('skips wildcard subpaths, which an exact alias cannot express', () => {
|
|
270
|
-
const {resolve} = resolveConfig();
|
|
271
|
-
|
|
272
|
-
const wildcards = Object.keys(resolve.alias).filter(request =>
|
|
273
|
-
request.includes('*'),
|
|
274
|
-
);
|
|
275
|
-
expect(wildcards).toEqual([]);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('leaves non-astryx requests to their normal resolution', () => {
|
|
279
|
-
const {resolve} = resolveConfig();
|
|
280
|
-
|
|
281
|
-
const foreign = Object.keys(resolve.alias).filter(
|
|
282
|
-
request => !request.startsWith('@astryxdesign/'),
|
|
283
|
-
);
|
|
284
|
-
expect(foreign).toEqual([]);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('keeps the global conditions as Next resolved them', () => {
|
|
288
|
-
const {resolve} = resolveConfig(
|
|
289
|
-
{},
|
|
290
|
-
{resolve: {conditionNames: ['import']}},
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
expect(resolve.conditionNames).toEqual(['import']);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it('still scopes the source condition to astryx modules', () => {
|
|
297
|
-
const {module: mod} = resolveConfig();
|
|
298
|
-
|
|
299
|
-
expect(mod.rules[0].resolve.conditionNames).toEqual(['source', '...']);
|
|
300
|
-
expect('@astryxdesign/core'.match(mod.rules[0].test)).toBeNull();
|
|
301
|
-
expect(
|
|
302
|
-
'/app/node_modules/@astryxdesign/core/src/index.ts'.match(
|
|
303
|
-
mod.rules[0].test,
|
|
304
|
-
),
|
|
305
|
-
).not.toBeNull();
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('lets a prefix alias from the caller webpack hook win', () => {
|
|
309
|
-
const custom = path.join(appDir, 'custom');
|
|
310
|
-
fs.mkdirSync(path.join(custom, 'AlertDialog'), {recursive: true});
|
|
311
|
-
fs.writeFileSync(path.join(custom, 'index.js'), '');
|
|
312
|
-
fs.writeFileSync(path.join(custom, 'AlertDialog/index.js'), '');
|
|
313
|
-
|
|
314
|
-
expect(
|
|
315
|
-
resolveFromAppWithHook('@astryxdesign/core', {
|
|
316
|
-
'@astryxdesign/core': custom,
|
|
317
|
-
}),
|
|
318
|
-
).toBe(path.join(custom, 'index.js'));
|
|
319
|
-
expect(
|
|
320
|
-
resolveFromAppWithHook('@astryxdesign/core/AlertDialog', {
|
|
321
|
-
'@astryxdesign/core': custom,
|
|
322
|
-
}),
|
|
323
|
-
).toBe(path.join(custom, 'AlertDialog/index.js'));
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it('lets a wildcard alias from the caller webpack hook win', () => {
|
|
327
|
-
const custom = path.join(appDir, 'custom');
|
|
328
|
-
fs.mkdirSync(path.join(custom, 'core/AlertDialog'), {recursive: true});
|
|
329
|
-
fs.writeFileSync(path.join(custom, 'core/index.js'), '');
|
|
330
|
-
fs.writeFileSync(path.join(custom, 'core/AlertDialog/index.js'), '');
|
|
331
|
-
|
|
332
|
-
expect(
|
|
333
|
-
resolveFromAppWithHook('@astryxdesign/core', {
|
|
334
|
-
'@astryxdesign/*': path.join(custom, '*'),
|
|
335
|
-
}),
|
|
336
|
-
).toBe(path.join(custom, 'core/index.js'));
|
|
337
|
-
expect(
|
|
338
|
-
resolveFromAppWithHook('@astryxdesign/core/AlertDialog', {
|
|
339
|
-
'@astryxdesign/*': path.join(custom, '*'),
|
|
340
|
-
}),
|
|
341
|
-
).toBe(path.join(custom, 'core/AlertDialog/index.js'));
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('lets an exact alias from the caller webpack hook win', () => {
|
|
345
|
-
const pinned = corePath('dist/index.js');
|
|
346
|
-
|
|
347
|
-
expect(
|
|
348
|
-
resolveFromAppWithHook('@astryxdesign/core', {
|
|
349
|
-
'@astryxdesign/core$': pinned,
|
|
350
|
-
}),
|
|
351
|
-
).toBe(pinned);
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('still applies the generated entries the hook did not claim', () => {
|
|
355
|
-
expect(
|
|
356
|
-
resolveFromAppWithHook('@astryxdesign/core', {'other-pkg': '/elsewhere'}),
|
|
357
|
-
).toBe(corePath('src/index.ts'));
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
it('tolerates a caller webpack hook that returns nothing', () => {
|
|
361
|
-
const config = withAstryx({webpack: () => {}}).webpack(
|
|
362
|
-
{resolve: {alias: {}}},
|
|
363
|
-
{dir: appDir},
|
|
364
|
-
);
|
|
365
|
-
|
|
366
|
-
expect(config.resolve.alias['@astryxdesign/core$']).toBe(
|
|
367
|
-
corePath('src/index.ts'),
|
|
368
|
-
);
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
it('runs the caller webpack hook last', () => {
|
|
372
|
-
const config = resolveConfig({
|
|
373
|
-
webpack: cfg => ({...cfg, marker: true}),
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
expect(config.marker).toBe(true);
|
|
377
|
-
expect(config.resolve.alias['@astryxdesign/core$']).toBeDefined();
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
describe('withAstryx bundler guard', () => {
|
|
382
|
-
afterEach(() => {
|
|
383
|
-
delete process.env.TURBOPACK;
|
|
384
|
-
vi.restoreAllMocks();
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it('refuses to build a config under Turbopack', () => {
|
|
388
|
-
process.env.TURBOPACK = '1';
|
|
389
|
-
expect(() => withAstryx()).toThrow(/requires the webpack bundler/);
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
it('names both ways out in the message', () => {
|
|
393
|
-
process.env.TURBOPACK = '1';
|
|
394
|
-
// The two supported routes: keep the source build and pick webpack, or drop
|
|
395
|
-
// the source build entirely and consume the pre-built package.
|
|
396
|
-
expect(() => withAstryx()).toThrow(/--webpack/);
|
|
397
|
-
expect(() => withAstryx()).toThrow(/astryx\.css/);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it('refuses before touching the caller config', () => {
|
|
401
|
-
process.env.TURBOPACK = '1';
|
|
402
|
-
const webpack = vi.fn();
|
|
403
|
-
expect(() => withAstryx({webpack})).toThrow();
|
|
404
|
-
expect(webpack).not.toHaveBeenCalled();
|
|
405
|
-
});
|
|
406
|
-
|
|
407
|
-
it('builds normally when Turbopack is not in play', () => {
|
|
408
|
-
expect(() => withAstryx()).not.toThrow();
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
describe('withAstryx alias coverage', () => {
|
|
413
|
-
afterEach(() => {
|
|
414
|
-
vi.restoreAllMocks();
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
it('warns when nothing routes the packages at all', () => {
|
|
418
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
419
|
-
// Nothing installed and no caller alias, so the merged map claims none of
|
|
420
|
-
// the packages — the pre-0.5.3 config, rather than a partial one.
|
|
421
|
-
const empty = fs.realpathSync(
|
|
422
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-none-')),
|
|
423
|
-
);
|
|
424
|
-
try {
|
|
425
|
-
withAstryx().webpack({resolve: {}}, {dir: empty});
|
|
426
|
-
expect(warn).toHaveBeenCalledOnce();
|
|
427
|
-
expect(warn.mock.calls[0][0]).toMatch(/no alias routes/);
|
|
428
|
-
} finally {
|
|
429
|
-
fs.rmSync(empty, {recursive: true, force: true});
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
|
|
433
|
-
it('stays quiet when at least one package resolves', () => {
|
|
434
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
435
|
-
// Only @astryxdesign/core is installed in the fixture; theme-neutral and
|
|
436
|
-
// lab are absent and skipped. A partial map is the normal case, not a fault.
|
|
437
|
-
resolveConfig();
|
|
438
|
-
expect(warn).not.toHaveBeenCalled();
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it('stays quiet when a caller alias already routes the packages', () => {
|
|
442
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
443
|
-
// Nothing installed, so this helper generates nothing — but the caller has
|
|
444
|
-
// routed the packages itself, which is a working config with nothing to
|
|
445
|
-
// warn about. The check is on the merged alias map, not on what we
|
|
446
|
-
// generated.
|
|
447
|
-
const empty = fs.realpathSync(
|
|
448
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-caller-')),
|
|
449
|
-
);
|
|
450
|
-
try {
|
|
451
|
-
withAstryx().webpack(
|
|
452
|
-
{
|
|
453
|
-
resolve: {
|
|
454
|
-
alias: {'@astryxdesign/core': path.join(empty, 'vendored')},
|
|
455
|
-
},
|
|
456
|
-
},
|
|
457
|
-
{dir: empty},
|
|
458
|
-
);
|
|
459
|
-
expect(warn).not.toHaveBeenCalled();
|
|
460
|
-
} finally {
|
|
461
|
-
fs.rmSync(empty, {recursive: true, force: true});
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
it('stays quiet for an array-shaped caller alias too', () => {
|
|
466
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
467
|
-
const empty = fs.realpathSync(
|
|
468
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-caller-arr-')),
|
|
469
|
-
);
|
|
470
|
-
try {
|
|
471
|
-
withAstryx().webpack(
|
|
472
|
-
{
|
|
473
|
-
resolve: {
|
|
474
|
-
alias: [
|
|
475
|
-
{
|
|
476
|
-
name: '@astryxdesign/core',
|
|
477
|
-
onlyModule: false,
|
|
478
|
-
alias: path.join(empty, 'vendored'),
|
|
479
|
-
},
|
|
480
|
-
],
|
|
481
|
-
},
|
|
482
|
-
},
|
|
483
|
-
{dir: empty},
|
|
484
|
-
);
|
|
485
|
-
expect(warn).not.toHaveBeenCalled();
|
|
486
|
-
} finally {
|
|
487
|
-
fs.rmSync(empty, {recursive: true, force: true});
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
// A scope-level key matches no package name as a string, but webpack resolves
|
|
492
|
-
// `@astryxdesign/core` through it — the key is an ancestor of the request.
|
|
493
|
-
// An exact key restricted to the bare scope matches only `@astryxdesign`,
|
|
494
|
-
// which nothing imports, so it routes no package and must not buy silence.
|
|
495
|
-
// These need an app with nothing installed: with a package present the
|
|
496
|
-
// generated entries route it and there is correctly nothing to report.
|
|
497
|
-
const ineffective = (label, build) =>
|
|
498
|
-
it(`warns for an exact scope-only alias ${label}`, () => {
|
|
499
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
500
|
-
const dir = fs.realpathSync(
|
|
501
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-exact-')),
|
|
502
|
-
);
|
|
503
|
-
try {
|
|
504
|
-
build(dir, path.join(dir, 'customRoot'));
|
|
505
|
-
expect(warn).toHaveBeenCalledOnce();
|
|
506
|
-
expect(warn.mock.calls[0][0]).toMatch(/no alias routes/);
|
|
507
|
-
} finally {
|
|
508
|
-
fs.rmSync(dir, {recursive: true, force: true});
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
ineffective('in the config', (dir, target) =>
|
|
513
|
-
withAstryx().webpack({resolve: {alias: {'@astryxdesign$': target}}}, {dir}),
|
|
514
|
-
);
|
|
515
|
-
|
|
516
|
-
ineffective('in array form', (dir, target) =>
|
|
517
|
-
withAstryx().webpack(
|
|
518
|
-
{
|
|
519
|
-
resolve: {
|
|
520
|
-
alias: [{name: '@astryxdesign', onlyModule: true, alias: target}],
|
|
521
|
-
},
|
|
522
|
-
},
|
|
523
|
-
{dir},
|
|
524
|
-
),
|
|
525
|
-
);
|
|
526
|
-
|
|
527
|
-
ineffective('from the caller webpack hook', (dir, target) =>
|
|
528
|
-
withAstryx({
|
|
529
|
-
webpack: cfg => {
|
|
530
|
-
cfg.resolve.alias['@astryxdesign$'] = target;
|
|
531
|
-
return cfg;
|
|
532
|
-
},
|
|
533
|
-
}).webpack({resolve: {alias: {}}}, {dir}),
|
|
534
|
-
);
|
|
535
|
-
|
|
536
|
-
// The boundary: exactness removes the ancestor case and only that one, so an
|
|
537
|
-
// exact key at or below a package still routes a real request.
|
|
538
|
-
const effectiveExact = (label, build) =>
|
|
539
|
-
it(`stays quiet for an exact alias ${label}`, () => {
|
|
540
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
541
|
-
const dir = fs.realpathSync(
|
|
542
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-exact-ok-')),
|
|
543
|
-
);
|
|
544
|
-
try {
|
|
545
|
-
build(dir, path.join(dir, 'customRoot'));
|
|
546
|
-
expect(warn).not.toHaveBeenCalled();
|
|
547
|
-
} finally {
|
|
548
|
-
fs.rmSync(dir, {recursive: true, force: true});
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
effectiveExact('on the package itself', (dir, target) =>
|
|
553
|
-
withAstryx().webpack(
|
|
554
|
-
{resolve: {alias: {'@astryxdesign/core$': target}}},
|
|
555
|
-
{dir},
|
|
556
|
-
),
|
|
557
|
-
);
|
|
558
|
-
|
|
559
|
-
effectiveExact('on the package, array form', (dir, target) =>
|
|
560
|
-
withAstryx().webpack(
|
|
561
|
-
{
|
|
562
|
-
resolve: {
|
|
563
|
-
alias: [
|
|
564
|
-
{name: '@astryxdesign/core', onlyModule: true, alias: target},
|
|
565
|
-
],
|
|
566
|
-
},
|
|
567
|
-
},
|
|
568
|
-
{dir},
|
|
569
|
-
),
|
|
570
|
-
);
|
|
571
|
-
|
|
572
|
-
effectiveExact('on a subpath under the package', (dir, target) =>
|
|
573
|
-
withAstryx().webpack(
|
|
574
|
-
{resolve: {alias: {'@astryxdesign/core/Badge$': target}}},
|
|
575
|
-
{dir},
|
|
576
|
-
),
|
|
577
|
-
);
|
|
578
|
-
|
|
579
|
-
const scoped = (label, build) =>
|
|
580
|
-
it(`stays quiet for a scope-prefix alias ${label}`, () => {
|
|
581
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
582
|
-
const dir = fs.realpathSync(
|
|
583
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-scope-')),
|
|
584
|
-
);
|
|
585
|
-
try {
|
|
586
|
-
build(dir, path.join(dir, 'customRoot'));
|
|
587
|
-
expect(warn).not.toHaveBeenCalled();
|
|
588
|
-
} finally {
|
|
589
|
-
fs.rmSync(dir, {recursive: true, force: true});
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
scoped('in the config', (dir, target) =>
|
|
594
|
-
withAstryx().webpack({resolve: {alias: {'@astryxdesign': target}}}, {dir}),
|
|
595
|
-
);
|
|
596
|
-
|
|
597
|
-
scoped('in array form', (dir, target) =>
|
|
598
|
-
withAstryx().webpack(
|
|
599
|
-
{
|
|
600
|
-
resolve: {
|
|
601
|
-
alias: [{name: '@astryxdesign', onlyModule: false, alias: target}],
|
|
602
|
-
},
|
|
603
|
-
},
|
|
604
|
-
{dir},
|
|
605
|
-
),
|
|
606
|
-
);
|
|
607
|
-
|
|
608
|
-
scoped('from the caller webpack hook', (dir, target) =>
|
|
609
|
-
withAstryx({
|
|
610
|
-
webpack: cfg => {
|
|
611
|
-
cfg.resolve.alias['@astryxdesign'] = target;
|
|
612
|
-
return cfg;
|
|
613
|
-
},
|
|
614
|
-
}).webpack({resolve: {alias: {}}}, {dir}),
|
|
615
|
-
);
|
|
616
|
-
|
|
617
|
-
it('stays quiet when the caller routes them from its webpack hook', () => {
|
|
618
|
-
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
619
|
-
const empty = fs.realpathSync(
|
|
620
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-caller-hook-')),
|
|
621
|
-
);
|
|
622
|
-
try {
|
|
623
|
-
withAstryx({
|
|
624
|
-
webpack: cfg => {
|
|
625
|
-
cfg.resolve.alias['@astryxdesign/core'] = path.join(
|
|
626
|
-
empty,
|
|
627
|
-
'vendored',
|
|
628
|
-
);
|
|
629
|
-
return cfg;
|
|
630
|
-
},
|
|
631
|
-
}).webpack({resolve: {alias: {}}}, {dir: empty});
|
|
632
|
-
expect(warn).not.toHaveBeenCalled();
|
|
633
|
-
} finally {
|
|
634
|
-
fs.rmSync(empty, {recursive: true, force: true});
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
|
|
639
|
-
describe('withAstryx under symlinked installs', () => {
|
|
640
|
-
let root;
|
|
641
|
-
|
|
642
|
-
/** Write files under `dir`, creating directories as needed. */
|
|
643
|
-
function writeFiles(dir, files) {
|
|
644
|
-
for (const [file, contents] of Object.entries(files)) {
|
|
645
|
-
fs.mkdirSync(path.dirname(path.join(dir, file)), {recursive: true});
|
|
646
|
-
fs.writeFileSync(path.join(dir, file), contents);
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
/** A minimal `@astryxdesign/core` whose source imports a dependency. */
|
|
651
|
-
const coreFiles = {
|
|
652
|
-
'package.json': JSON.stringify({
|
|
653
|
-
name: '@astryxdesign/core',
|
|
654
|
-
exports: {'.': {source: './src/index.ts', default: './dist/index.js'}},
|
|
655
|
-
}),
|
|
656
|
-
'src/index.ts': "import 'intl-messageformat';\n",
|
|
657
|
-
'dist/index.js': '',
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
/** Link `target` at `link`, the way pnpm links a package. */
|
|
661
|
-
function link(target, linkPath) {
|
|
662
|
-
fs.mkdirSync(path.dirname(linkPath), {recursive: true});
|
|
663
|
-
fs.symlinkSync(target, linkPath, 'junction');
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
/** Resolve `request` from `dir` with the resolver options webpack gets. */
|
|
667
|
-
function resolveWith(resolve, dir, request) {
|
|
668
|
-
const resolver = ResolverFactory.createResolver({
|
|
669
|
-
fileSystem: new CachedInputFileSystem(fs, 4000),
|
|
670
|
-
extensions: ['.ts', '.tsx', '.js'],
|
|
671
|
-
conditionNames: ['import', 'default'],
|
|
672
|
-
alias: resolve.alias,
|
|
673
|
-
...('symlinks' in resolve ? {symlinks: resolve.symlinks} : {}),
|
|
674
|
-
useSyncFileSystemCalls: true,
|
|
675
|
-
});
|
|
676
|
-
return resolver.resolveSync({}, dir, request);
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
beforeAll(() => {
|
|
680
|
-
root = fs.realpathSync(
|
|
681
|
-
fs.mkdtempSync(path.join(os.tmpdir(), 'astryx-next-links-')),
|
|
682
|
-
);
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
afterAll(() => {
|
|
686
|
-
fs.rmSync(root, {recursive: true, force: true});
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
it("resolves a package's own dependencies under pnpm's isolated layout", () => {
|
|
690
|
-
// pnpm keeps each package and its dependencies side by side in its store,
|
|
691
|
-
// and links only the app's direct dependencies into `node_modules`.
|
|
692
|
-
const app = path.join(root, 'isolated');
|
|
693
|
-
const store = path.join(
|
|
694
|
-
app,
|
|
695
|
-
'node_modules/.pnpm/@astryxdesign+core@1.0.0/node_modules',
|
|
696
|
-
);
|
|
697
|
-
writeFiles(path.join(store, '@astryxdesign/core'), coreFiles);
|
|
698
|
-
writeFiles(path.join(store, 'intl-messageformat'), {
|
|
699
|
-
'package.json': JSON.stringify({name: 'intl-messageformat'}),
|
|
700
|
-
'index.js': '',
|
|
701
|
-
});
|
|
702
|
-
link(
|
|
703
|
-
path.join(store, '@astryxdesign/core'),
|
|
704
|
-
path.join(app, 'node_modules/@astryxdesign/core'),
|
|
705
|
-
);
|
|
706
|
-
fs.mkdirSync(path.join(app, 'src'));
|
|
707
|
-
|
|
708
|
-
const {resolve} = withAstryx({}).webpack({resolve: {}}, {dir: app});
|
|
709
|
-
const entry = resolveWith(
|
|
710
|
-
resolve,
|
|
711
|
-
path.join(app, 'src'),
|
|
712
|
-
'@astryxdesign/core',
|
|
713
|
-
);
|
|
714
|
-
|
|
715
|
-
expect(
|
|
716
|
-
resolveWith(resolve, path.dirname(entry), 'intl-messageformat'),
|
|
717
|
-
).toBe(path.join(store, 'intl-messageformat/index.js'));
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
it("scopes the source condition to a workspace link's real path", () => {
|
|
721
|
-
// A workspace package links from outside any `node_modules`, so its real
|
|
722
|
-
// path has no `node_modules/@astryxdesign/` segment.
|
|
723
|
-
const workspace = path.join(root, 'workspace');
|
|
724
|
-
const app = path.join(workspace, 'apps/site');
|
|
725
|
-
writeFiles(path.join(workspace, 'packages/core'), coreFiles);
|
|
726
|
-
link(
|
|
727
|
-
path.join(workspace, 'packages/core'),
|
|
728
|
-
path.join(app, 'node_modules/@astryxdesign/core'),
|
|
729
|
-
);
|
|
730
|
-
|
|
731
|
-
const config = withAstryx({}).webpack({resolve: {}}, {dir: app});
|
|
732
|
-
const [rule] = config.module.rules;
|
|
733
|
-
// Webpack's condition semantics: a RegExp tests the path, a string
|
|
734
|
-
// matches it as a prefix.
|
|
735
|
-
const matches = file =>
|
|
736
|
-
[rule.test]
|
|
737
|
-
.flat()
|
|
738
|
-
.some(condition =>
|
|
739
|
-
typeof condition === 'string'
|
|
740
|
-
? file.startsWith(condition)
|
|
741
|
-
: condition.test(file),
|
|
742
|
-
);
|
|
743
|
-
|
|
744
|
-
expect(rule.resolve.conditionNames).toEqual(['source', '...']);
|
|
745
|
-
expect(matches(path.join(workspace, 'packages/core/src/index.ts'))).toBe(
|
|
746
|
-
true,
|
|
747
|
-
);
|
|
748
|
-
expect(matches(path.join(workspace, 'packages/core-x/src/index.ts'))).toBe(
|
|
749
|
-
false,
|
|
750
|
-
);
|
|
751
|
-
expect(matches(path.join(app, 'src/page.tsx'))).toBe(false);
|
|
752
|
-
});
|
|
753
|
-
});
|