@knapsack/package-bundler 4.101.0--canary.8110.15bba7c.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/.lintstagedrc.mjs +11 -0
- package/INSTRUCTIONS-FOR-CUSTOMERS.md +130 -0
- package/dist/bundle.d.ts +41 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +348 -0
- package/dist/bundle.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +165 -0
- package/dist/cli.js.map +1 -0
- package/dist/errors.d.ts +63 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +155 -0
- package/dist/errors.js.map +1 -0
- package/dist/help-text.d.ts +16 -0
- package/dist/help-text.d.ts.map +1 -0
- package/dist/help-text.js +180 -0
- package/dist/help-text.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +42 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +114 -0
- package/dist/log.js.map +1 -0
- package/dist/metadata.d.ts +112 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +204 -0
- package/dist/metadata.js.map +1 -0
- package/dist/prompts.d.ts +54 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +125 -0
- package/dist/prompts.js.map +1 -0
- package/dist/resolve-entries.d.ts +56 -0
- package/dist/resolve-entries.d.ts.map +1 -0
- package/dist/resolve-entries.js +333 -0
- package/dist/resolve-entries.js.map +1 -0
- package/dist/resolve-source.d.ts +53 -0
- package/dist/resolve-source.d.ts.map +1 -0
- package/dist/resolve-source.js +174 -0
- package/dist/resolve-source.js.map +1 -0
- package/dist/run.d.ts +52 -0
- package/dist/run.d.ts.map +1 -0
- package/dist/run.js +276 -0
- package/dist/run.js.map +1 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +62 -0
- package/dist/types.js.map +1 -0
- package/dist/vendor.d.ts +59 -0
- package/dist/vendor.d.ts.map +1 -0
- package/dist/vendor.js +134 -0
- package/dist/vendor.js.map +1 -0
- package/dist/verify-bundle.d.ts +59 -0
- package/dist/verify-bundle.d.ts.map +1 -0
- package/dist/verify-bundle.js +238 -0
- package/dist/verify-bundle.js.map +1 -0
- package/dist/write-output.d.ts +82 -0
- package/dist/write-output.d.ts.map +1 -0
- package/dist/write-output.js +214 -0
- package/dist/write-output.js.map +1 -0
- package/package.json +53 -0
- package/readme.md +127 -0
- package/tsconfig.json +9 -0
- package/tsconfig.test.json +13 -0
- package/vitest.config.ts +9 -0
package/dist/types.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Shared shapes for the bundling pipeline. */
|
|
2
|
+
/** Why a package ended up outside the bundle. */
|
|
3
|
+
export const EXTERNAL_REASONS = {
|
|
4
|
+
/** Declared in `peerDependencies` — the consumer supplies it. */
|
|
5
|
+
peerDependency: 'peerDependency',
|
|
6
|
+
/** A UI framework we never inline, even when listed as a regular dependency. */
|
|
7
|
+
framework: 'framework',
|
|
8
|
+
/** The user asked for it via `--external`. */
|
|
9
|
+
requested: 'requested',
|
|
10
|
+
/** Ships a native `.node` binding. */
|
|
11
|
+
nativeBinding: 'nativeBinding',
|
|
12
|
+
/** Builds a native addon at install time. */
|
|
13
|
+
nativeBuild: 'nativeBuild',
|
|
14
|
+
/** Runs code in a worker thread from a separate entry file. */
|
|
15
|
+
workerThread: 'workerThread',
|
|
16
|
+
/** `--strategy vendor`: nothing gets inlined. */
|
|
17
|
+
vendorStrategy: 'vendorStrategy',
|
|
18
|
+
};
|
|
19
|
+
/** Human-readable explanation per reason, for the README and metadata. */
|
|
20
|
+
export const EXTERNAL_REASON_LABELS = {
|
|
21
|
+
peerDependency: 'declared as a peer dependency; the consumer provides it',
|
|
22
|
+
framework: 'UI framework — inlining it would give consumers a duplicate copy',
|
|
23
|
+
requested: 'excluded by --external',
|
|
24
|
+
nativeBinding: 'ships a native .node binding, which cannot be bundled',
|
|
25
|
+
nativeBuild: 'compiles a native addon at install time',
|
|
26
|
+
workerThread: 'loads a worker from a separate entry file the bundler cannot follow',
|
|
27
|
+
vendorStrategy: 'vendored because --strategy vendor was used',
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* UI frameworks are never inlined, even when a package lists them under
|
|
31
|
+
* `dependencies` rather than `peerDependencies` (which design systems often do).
|
|
32
|
+
* Two copies of React in one process is a broken app, so the safer default is to
|
|
33
|
+
* leave them out and record them as required. `--inline <pkg>` overrides.
|
|
34
|
+
*/
|
|
35
|
+
export const NEVER_INLINE_BY_DEFAULT = [
|
|
36
|
+
'react',
|
|
37
|
+
'react-dom',
|
|
38
|
+
'react/jsx-runtime',
|
|
39
|
+
'react/jsx-dev-runtime',
|
|
40
|
+
'vue',
|
|
41
|
+
'@vue/runtime-core',
|
|
42
|
+
'@vue/runtime-dom',
|
|
43
|
+
'svelte',
|
|
44
|
+
'@angular/core',
|
|
45
|
+
'@angular/common',
|
|
46
|
+
];
|
|
47
|
+
/**
|
|
48
|
+
* Packages whose styling is resolved by a build-time transform. Re-bundling their
|
|
49
|
+
* output leaves the runtime half without its compile-time half, and the failure shows
|
|
50
|
+
* up as an unhelpful throw on import — so we warn up front instead.
|
|
51
|
+
*/
|
|
52
|
+
export const BUILD_TIME_CSS_PACKAGES = [
|
|
53
|
+
'@vanilla-extract/css',
|
|
54
|
+
'@vanilla-extract/recipes',
|
|
55
|
+
'@vanilla-extract/dynamic',
|
|
56
|
+
'@linaria/core',
|
|
57
|
+
'@linaria/react',
|
|
58
|
+
'linaria',
|
|
59
|
+
'@compiled/react',
|
|
60
|
+
'@emotion/babel-plugin',
|
|
61
|
+
];
|
|
62
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAE/C,iDAAiD;AACjD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,iEAAiE;IACjE,cAAc,EAAE,gBAAgB;IAChC,gFAAgF;IAChF,SAAS,EAAE,WAAW;IACtB,8CAA8C;IAC9C,SAAS,EAAE,WAAW;IACtB,sCAAsC;IACtC,aAAa,EAAE,eAAe;IAC9B,6CAA6C;IAC7C,WAAW,EAAE,aAAa;IAC1B,+DAA+D;IAC/D,YAAY,EAAE,cAAc;IAC5B,iDAAiD;IACjD,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAKX,0EAA0E;AAC1E,MAAM,CAAC,MAAM,sBAAsB,GAAmC;IACpE,cAAc,EAAE,yDAAyD;IACzE,SAAS,EAAE,kEAAkE;IAC7E,SAAS,EAAE,wBAAwB;IACnC,aAAa,EAAE,uDAAuD;IACtE,WAAW,EAAE,yCAAyC;IACtD,YAAY,EACV,qEAAqE;IACvE,cAAc,EAAE,6CAA6C;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAsB;IACxD,OAAO;IACP,WAAW;IACX,mBAAmB;IACnB,uBAAuB;IACvB,KAAK;IACL,mBAAmB;IACnB,kBAAkB;IAClB,QAAQ;IACR,eAAe;IACf,iBAAiB;CAClB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAsB;IACxD,sBAAsB;IACtB,0BAA0B;IAC1B,0BAA0B;IAC1B,eAAe;IACf,gBAAgB;IAChB,SAAS;IACT,iBAAiB;IACjB,uBAAuB;CACxB,CAAC"}
|
package/dist/vendor.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy packages that cannot be inlined into the bundle as real directories.
|
|
3
|
+
*
|
|
4
|
+
* This is the escape hatch that keeps the whole approach honest. Some packages resist
|
|
5
|
+
* bundling no matter which bundler you use — native `.node` bindings, `require.resolve`
|
|
6
|
+
* of a file inside their own package, worker entry files that form their own module
|
|
7
|
+
* graph. `apps/api/lambdas-for-tf/tsup.config.cjs` handles exactly these by hand for
|
|
8
|
+
* playwright and jsdom; this generalizes it.
|
|
9
|
+
*
|
|
10
|
+
* The copy dereferences symlinks, because pnpm's `node_modules` is a symlink farm and a
|
|
11
|
+
* copied symlink would point at a store that does not exist on the target machine.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Find a package's real directory as resolved from `fromDir`.
|
|
15
|
+
*
|
|
16
|
+
* Resolving `<name>/package.json` rather than the package's main entry is deliberate:
|
|
17
|
+
* many packages do not export their main from an `exports` map that Node can resolve
|
|
18
|
+
* without conditions, but `package.json` is almost always reachable, and it is the file
|
|
19
|
+
* whose directory we actually want.
|
|
20
|
+
*/
|
|
21
|
+
export declare function findPackageDir({ name, fromDir, }: {
|
|
22
|
+
name: string;
|
|
23
|
+
fromDir: string;
|
|
24
|
+
}): string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Is `src` inside a `node_modules` folder *within* the package being copied?
|
|
27
|
+
*
|
|
28
|
+
* Uses the path relative to the package and `path.sep`, so it is correct on Windows and
|
|
29
|
+
* unaffected by however many `node_modules` segments appear above the package itself.
|
|
30
|
+
*/
|
|
31
|
+
export declare function hasNestedNodeModules({ sourceDir, src, }: {
|
|
32
|
+
sourceDir: string;
|
|
33
|
+
src: string;
|
|
34
|
+
}): boolean;
|
|
35
|
+
export interface VendorResult {
|
|
36
|
+
/** Package names successfully copied, including transitive dependencies. */
|
|
37
|
+
readonly vendored: readonly {
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly version?: string;
|
|
40
|
+
}[];
|
|
41
|
+
/** Names we were asked to vendor but could not find. */
|
|
42
|
+
readonly missing: readonly string[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Copy each named package, plus its own production dependency closure, into
|
|
46
|
+
* `<bundleDir>/node_modules/`.
|
|
47
|
+
*
|
|
48
|
+
* The layout is flat, which is what a modern Node resolver expects and what keeps the
|
|
49
|
+
* result small. Version conflicts between two vendored packages' dependencies are
|
|
50
|
+
* possible in principle; in practice the vendored set is a handful of packages, and a
|
|
51
|
+
* conflict would surface in the verify step rather than silently.
|
|
52
|
+
*/
|
|
53
|
+
export declare function vendorPackages({ names, fromDir, bundleDir, }: {
|
|
54
|
+
names: readonly string[];
|
|
55
|
+
/** Directory to resolve the top-level packages from — normally the source package. */
|
|
56
|
+
fromDir: string;
|
|
57
|
+
bundleDir: string;
|
|
58
|
+
}): VendorResult;
|
|
59
|
+
//# sourceMappingURL=vendor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vendor.d.ts","sourceRoot":"","sources":["../src/vendor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAcH;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,EAC7B,IAAI,EACJ,OAAO,GACR,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,GAAG,SAAS,CAiBrB;AAYD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,SAAS,EACT,GAAG,GACJ,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,OAAO,CAIV;AAED,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,QAAQ,CAAC,QAAQ,EAAE,SAAS;QAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;KAC3B,EAAE,CAAC;IACJ,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,OAAO,EACP,SAAS,GACV,EAAE;IACD,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,sFAAsF;IACtF,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,YAAY,CAiEf"}
|
package/dist/vendor.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy packages that cannot be inlined into the bundle as real directories.
|
|
3
|
+
*
|
|
4
|
+
* This is the escape hatch that keeps the whole approach honest. Some packages resist
|
|
5
|
+
* bundling no matter which bundler you use — native `.node` bindings, `require.resolve`
|
|
6
|
+
* of a file inside their own package, worker entry files that form their own module
|
|
7
|
+
* graph. `apps/api/lambdas-for-tf/tsup.config.cjs` handles exactly these by hand for
|
|
8
|
+
* playwright and jsdom; this generalizes it.
|
|
9
|
+
*
|
|
10
|
+
* The copy dereferences symlinks, because pnpm's `node_modules` is a symlink farm and a
|
|
11
|
+
* copied symlink would point at a store that does not exist on the target machine.
|
|
12
|
+
*/
|
|
13
|
+
import { cpSync, existsSync, readFileSync, realpathSync } from 'node:fs';
|
|
14
|
+
import { createRequire } from 'node:module';
|
|
15
|
+
import { dirname, join, relative, sep } from 'node:path';
|
|
16
|
+
import { ensureDirSync } from '@knapsack/file-utils';
|
|
17
|
+
/**
|
|
18
|
+
* Find a package's real directory as resolved from `fromDir`.
|
|
19
|
+
*
|
|
20
|
+
* Resolving `<name>/package.json` rather than the package's main entry is deliberate:
|
|
21
|
+
* many packages do not export their main from an `exports` map that Node can resolve
|
|
22
|
+
* without conditions, but `package.json` is almost always reachable, and it is the file
|
|
23
|
+
* whose directory we actually want.
|
|
24
|
+
*/
|
|
25
|
+
export function findPackageDir({ name, fromDir, }) {
|
|
26
|
+
const require = createRequire(join(fromDir, 'noop.js'));
|
|
27
|
+
try {
|
|
28
|
+
return dirname(realpathSync(require.resolve(`${name}/package.json`)));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Packages without `./package.json` in their exports map need the manual walk.
|
|
32
|
+
}
|
|
33
|
+
let current = fromDir;
|
|
34
|
+
for (;;) {
|
|
35
|
+
const candidate = join(current, 'node_modules', name);
|
|
36
|
+
if (existsSync(join(candidate, 'package.json')))
|
|
37
|
+
return realpathSync(candidate);
|
|
38
|
+
const parent = dirname(current);
|
|
39
|
+
if (parent === current)
|
|
40
|
+
return undefined;
|
|
41
|
+
current = parent;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function readManifest(pkgDir) {
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(readFileSync(join(pkgDir, 'package.json'), 'utf8'));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Is `src` inside a `node_modules` folder *within* the package being copied?
|
|
54
|
+
*
|
|
55
|
+
* Uses the path relative to the package and `path.sep`, so it is correct on Windows and
|
|
56
|
+
* unaffected by however many `node_modules` segments appear above the package itself.
|
|
57
|
+
*/
|
|
58
|
+
export function hasNestedNodeModules({ sourceDir, src, }) {
|
|
59
|
+
const rel = relative(sourceDir, src);
|
|
60
|
+
if (!rel)
|
|
61
|
+
return false;
|
|
62
|
+
return rel.split(sep).includes('node_modules');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Copy each named package, plus its own production dependency closure, into
|
|
66
|
+
* `<bundleDir>/node_modules/`.
|
|
67
|
+
*
|
|
68
|
+
* The layout is flat, which is what a modern Node resolver expects and what keeps the
|
|
69
|
+
* result small. Version conflicts between two vendored packages' dependencies are
|
|
70
|
+
* possible in principle; in practice the vendored set is a handful of packages, and a
|
|
71
|
+
* conflict would surface in the verify step rather than silently.
|
|
72
|
+
*/
|
|
73
|
+
export function vendorPackages({ names, fromDir, bundleDir, }) {
|
|
74
|
+
const vendored = [];
|
|
75
|
+
const missing = [];
|
|
76
|
+
const done = new Set();
|
|
77
|
+
// Each queue entry remembers where to resolve from. A transitive dependency must be
|
|
78
|
+
// looked up from the package that depends on it, not from the root: pnpm does not
|
|
79
|
+
// hoist, so `date-fns`'s own `@babel/runtime` is reachable from inside `date-fns`
|
|
80
|
+
// and nowhere else. Resolving everything from the root silently loses the closure
|
|
81
|
+
// and produces a bundle that throws MODULE_NOT_FOUND on the customer's machine.
|
|
82
|
+
const queue = names.map((name) => ({
|
|
83
|
+
name,
|
|
84
|
+
resolveFrom: fromDir,
|
|
85
|
+
}));
|
|
86
|
+
while (queue.length > 0) {
|
|
87
|
+
const next = queue.shift();
|
|
88
|
+
if (!next || done.has(next.name))
|
|
89
|
+
continue;
|
|
90
|
+
done.add(next.name);
|
|
91
|
+
const sourceDir = findPackageDir({ name: next.name, fromDir: next.resolveFrom }) ??
|
|
92
|
+
// Fall back to the root, which covers a flat (npm/yarn) layout where the
|
|
93
|
+
// dependency was hoisted above the package that declares it.
|
|
94
|
+
findPackageDir({ name: next.name, fromDir });
|
|
95
|
+
if (!sourceDir) {
|
|
96
|
+
missing.push(next.name);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const target = join(bundleDir, 'node_modules', next.name);
|
|
100
|
+
ensureDirSync(dirname(target));
|
|
101
|
+
cpSync(sourceDir, target, {
|
|
102
|
+
recursive: true,
|
|
103
|
+
// Follow symlinks — a pnpm store path means nothing on another machine.
|
|
104
|
+
dereference: true,
|
|
105
|
+
// Skip nested node_modules so everything lands flat. The test has to be against
|
|
106
|
+
// the path *relative to the package*, not the absolute path: the package itself
|
|
107
|
+
// almost always lives under a `node_modules` segment (more than one, under
|
|
108
|
+
// pnpm), so matching anywhere in the absolute path excludes every file in the
|
|
109
|
+
// package and copies an empty directory.
|
|
110
|
+
filter: (src) => !hasNestedNodeModules({ sourceDir, src }),
|
|
111
|
+
});
|
|
112
|
+
const manifest = readManifest(sourceDir);
|
|
113
|
+
vendored.push({ name: next.name, version: manifest.version });
|
|
114
|
+
for (const dependency of Object.keys(manifest.dependencies ?? {})) {
|
|
115
|
+
if (!done.has(dependency)) {
|
|
116
|
+
queue.push({ name: dependency, resolveFrom: sourceDir });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Optional dependencies are best-effort: a missing one is normal, so it does not
|
|
120
|
+
// count toward `missing`.
|
|
121
|
+
for (const dependency of Object.keys(manifest.optionalDependencies ?? {})) {
|
|
122
|
+
if (done.has(dependency))
|
|
123
|
+
continue;
|
|
124
|
+
if (findPackageDir({ name: dependency, fromDir: sourceDir })) {
|
|
125
|
+
queue.push({ name: dependency, resolveFrom: sourceDir });
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
done.add(dependency);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { vendored, missing };
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=vendor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vendor.js","sourceRoot":"","sources":["../src/vendor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AASrD;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,IAAI,EACJ,OAAO,GAIR;IACC,MAAM,OAAO,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;IACxD,IAAI,CAAC;QACH,OAAO,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,eAAe,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC;IAAC,MAAM,CAAC;QACP,+EAA+E;IACjF,CAAC;IAED,IAAI,OAAO,GAAG,OAAO,CAAC;IACtB,SAAS,CAAC;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AAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;QAE9D,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,CAAC;YAClE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC1B,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;QACD,iFAAiF;QACjF,0BAA0B;QAC1B,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,oBAAoB,IAAI,EAAE,CAAC,EAAE,CAAC;YAC1E,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC;gBAAE,SAAS;YACnC,IAAI,cAAc,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;gBAC7D,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC;YAC3D,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prove the bundle is actually self-contained.
|
|
3
|
+
*
|
|
4
|
+
* This exists because of a specific, verified Vite behaviour: in SSR mode Vite silently
|
|
5
|
+
* leaves bare imports it *cannot resolve* as external, on the assumption Node will
|
|
6
|
+
* resolve them at runtime. No warning, no error — the build reports success. Bundling a
|
|
7
|
+
* React design system this way produced an artifact with 24 leaked imports (`react`
|
|
8
|
+
* among them) that threw on import.
|
|
9
|
+
*
|
|
10
|
+
* For our purposes that assumption is exactly backwards: an import we failed to inline
|
|
11
|
+
* is the one thing the bundle must not contain. So every run ends here.
|
|
12
|
+
*
|
|
13
|
+
* The checks are split by what they can actually prove. A React or Vue design system
|
|
14
|
+
* generally cannot be imported in bare Node — its framework peer is intentionally
|
|
15
|
+
* absent, its components touch `document` at module scope — so *executing* it is a poor
|
|
16
|
+
* test and would fail loudest on the packages this tool exists for. The static import
|
|
17
|
+
* audit holds regardless.
|
|
18
|
+
*/
|
|
19
|
+
/** An import that survived into the output, and what it resolves to. */
|
|
20
|
+
export interface ClassifiedImport {
|
|
21
|
+
readonly specifier: string;
|
|
22
|
+
/** The bare package name, e.g. `lodash` for `lodash/merge`. */
|
|
23
|
+
readonly packageName: string;
|
|
24
|
+
readonly chunk: string;
|
|
25
|
+
readonly classification: 'builtin' | 'peer' | 'vendored' | 'leaked';
|
|
26
|
+
}
|
|
27
|
+
export interface VerifyReport {
|
|
28
|
+
readonly chunksChecked: number;
|
|
29
|
+
readonly imports: readonly ClassifiedImport[];
|
|
30
|
+
readonly leaked: readonly ClassifiedImport[];
|
|
31
|
+
/** Entry subpaths that imported cleanly. */
|
|
32
|
+
readonly importable: readonly string[];
|
|
33
|
+
/** Entries that threw, with the error classified as expected or not. */
|
|
34
|
+
readonly importFailures: readonly {
|
|
35
|
+
readonly entry: string;
|
|
36
|
+
readonly message: string;
|
|
37
|
+
readonly expected: boolean;
|
|
38
|
+
}[];
|
|
39
|
+
}
|
|
40
|
+
/** Strip a subpath to its package name: `lodash/merge` -> `lodash`, scopes preserved. */
|
|
41
|
+
export declare function toPackageName(specifier: string): string;
|
|
42
|
+
export declare function verifyBundle({ bundleDir, emittedImports, peerDependencies, vendoredPackages, strict, }: {
|
|
43
|
+
bundleDir: string;
|
|
44
|
+
/**
|
|
45
|
+
* What the output actually imports, as reported by Rollup during the build.
|
|
46
|
+
* Authoritative — unlike scanning the emitted text, which cannot distinguish an
|
|
47
|
+
* import from a comment that looks like one.
|
|
48
|
+
*/
|
|
49
|
+
emittedImports: readonly {
|
|
50
|
+
readonly specifier: string;
|
|
51
|
+
readonly chunk: string;
|
|
52
|
+
}[];
|
|
53
|
+
/** Names allowed to remain external because the consumer supplies them. */
|
|
54
|
+
peerDependencies: readonly string[];
|
|
55
|
+
/** Names shipped as real directories in `bundle/node_modules/`. */
|
|
56
|
+
vendoredPackages: readonly string[];
|
|
57
|
+
strict: boolean;
|
|
58
|
+
}): VerifyReport;
|
|
59
|
+
//# sourceMappingURL=verify-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-bundle.d.ts","sourceRoot":"","sources":["../src/verify-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAgBH,wEAAwE;AACxE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,cAAc,EAAE,SAAS,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAC;CACrE;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC9C,QAAQ,CAAC,MAAM,EAAE,SAAS,gBAAgB,EAAE,CAAC;IAC7C,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,wEAAwE;IACxE,QAAQ,CAAC,cAAc,EAAE,SAAS;QAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QACzB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;KAC5B,EAAE,CAAC;CACL;AAED,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAMvD;AAiJD,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,MAAM,GACP,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,cAAc,EAAE,SAAS;QACvB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;KACxB,EAAE,CAAC;IACJ,2EAA2E;IAC3E,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,mEAAmE;IACnE,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,MAAM,EAAE,OAAO,CAAC;CACjB,GAAG,YAAY,CAqHf"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prove the bundle is actually self-contained.
|
|
3
|
+
*
|
|
4
|
+
* This exists because of a specific, verified Vite behaviour: in SSR mode Vite silently
|
|
5
|
+
* leaves bare imports it *cannot resolve* as external, on the assumption Node will
|
|
6
|
+
* resolve them at runtime. No warning, no error — the build reports success. Bundling a
|
|
7
|
+
* React design system this way produced an artifact with 24 leaked imports (`react`
|
|
8
|
+
* among them) that threw on import.
|
|
9
|
+
*
|
|
10
|
+
* For our purposes that assumption is exactly backwards: an import we failed to inline
|
|
11
|
+
* is the one thing the bundle must not contain. So every run ends here.
|
|
12
|
+
*
|
|
13
|
+
* The checks are split by what they can actually prove. A React or Vue design system
|
|
14
|
+
* generally cannot be imported in bare Node — its framework peer is intentionally
|
|
15
|
+
* absent, its components touch `document` at module scope — so *executing* it is a poor
|
|
16
|
+
* test and would fail loudest on the packages this tool exists for. The static import
|
|
17
|
+
* audit holds regardless.
|
|
18
|
+
*/
|
|
19
|
+
import { execFileSync } from 'node:child_process';
|
|
20
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
21
|
+
import { builtinModules } from 'node:module';
|
|
22
|
+
import { join, relative } from 'node:path';
|
|
23
|
+
import { BundlerError, ERROR_CODES } from './errors.js';
|
|
24
|
+
/** The stub `@rollup/plugin-commonjs` emits when dynamic requires aren't allowed. */
|
|
25
|
+
const DYNAMIC_REQUIRE_STUB = 'Could not dynamically require';
|
|
26
|
+
const BUILTINS = new Set([
|
|
27
|
+
...builtinModules,
|
|
28
|
+
...builtinModules.map((name) => `node:${name}`),
|
|
29
|
+
]);
|
|
30
|
+
/** Strip a subpath to its package name: `lodash/merge` -> `lodash`, scopes preserved. */
|
|
31
|
+
export function toPackageName(specifier) {
|
|
32
|
+
if (specifier.startsWith('@')) {
|
|
33
|
+
const parts = specifier.split('/');
|
|
34
|
+
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : specifier;
|
|
35
|
+
}
|
|
36
|
+
return specifier.split('/')[0] ?? specifier;
|
|
37
|
+
}
|
|
38
|
+
function listChunks(bundleDir) {
|
|
39
|
+
const chunks = [];
|
|
40
|
+
const walk = (dir) => {
|
|
41
|
+
for (const dirent of readdirSync(dir, { withFileTypes: true })) {
|
|
42
|
+
const full = join(dir, dirent.name);
|
|
43
|
+
if (dirent.isDirectory()) {
|
|
44
|
+
// Vendored packages are real dependencies, not our output.
|
|
45
|
+
if (dirent.name === 'node_modules')
|
|
46
|
+
continue;
|
|
47
|
+
walk(full);
|
|
48
|
+
}
|
|
49
|
+
else if (/\.(mjs|js|cjs)$/.test(dirent.name)) {
|
|
50
|
+
chunks.push(full);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
walk(bundleDir);
|
|
55
|
+
return chunks;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A vendored package counts only if its files are really there.
|
|
59
|
+
*
|
|
60
|
+
* Checking the directory alone is not enough: a copy that silently produced an empty
|
|
61
|
+
* folder would pass, and the bundle would fail at import time on the customer's
|
|
62
|
+
* machine. `package.json` is the file Node needs to resolve the package at all, so its
|
|
63
|
+
* presence is the cheapest honest proof that the copy worked.
|
|
64
|
+
*/
|
|
65
|
+
function isUsableVendoredPackage({ bundleDir, packageName, }) {
|
|
66
|
+
return existsSync(join(bundleDir, 'node_modules', packageName, 'package.json'));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Every dependency a vendored package declares must also be present.
|
|
70
|
+
*
|
|
71
|
+
* Without this the self-containment claim only covers our own emitted chunks. A
|
|
72
|
+
* vendored package whose closure was incompletely copied still throws
|
|
73
|
+
* MODULE_NOT_FOUND at import time, and the run would have reported success — the exact
|
|
74
|
+
* class of silent failure the rest of this module exists to prevent.
|
|
75
|
+
*/
|
|
76
|
+
function findMissingVendoredDependencies({ bundleDir, vendoredPackages, peerDependencies, }) {
|
|
77
|
+
const peers = new Set(peerDependencies);
|
|
78
|
+
const gaps = [];
|
|
79
|
+
for (const name of vendoredPackages) {
|
|
80
|
+
const manifestPath = join(bundleDir, 'node_modules', name, 'package.json');
|
|
81
|
+
if (!existsSync(manifestPath))
|
|
82
|
+
continue;
|
|
83
|
+
let dependencies = {};
|
|
84
|
+
try {
|
|
85
|
+
dependencies =
|
|
86
|
+
JSON.parse(readFileSync(manifestPath, 'utf8')).dependencies ?? {};
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
for (const dependency of Object.keys(dependencies)) {
|
|
92
|
+
if (BUILTINS.has(dependency) || peers.has(dependency))
|
|
93
|
+
continue;
|
|
94
|
+
if (isUsableVendoredPackage({ bundleDir, packageName: dependency }))
|
|
95
|
+
continue;
|
|
96
|
+
gaps.push({ missing: dependency, requiredBy: name });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return gaps;
|
|
100
|
+
}
|
|
101
|
+
/** Errors that mean "this package needs a browser or a peer", not "the bundle is broken". */
|
|
102
|
+
function isExpectedRuntimeError(message) {
|
|
103
|
+
return [
|
|
104
|
+
'is not defined', // document/window/navigator at module scope
|
|
105
|
+
'ERR_MODULE_NOT_FOUND', // an intentionally external peer
|
|
106
|
+
'Cannot find package',
|
|
107
|
+
'ERR_UNSUPPORTED_DIR_IMPORT',
|
|
108
|
+
].some((marker) => message.includes(marker));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Try actually importing each entry. Advisory: a design system that reaches for
|
|
112
|
+
* `document` at module scope is not a broken bundle, so failures are classified rather
|
|
113
|
+
* than fatal.
|
|
114
|
+
*/
|
|
115
|
+
function probeImports({ bundleDir }) {
|
|
116
|
+
const pkgJsonPath = join(bundleDir, 'package.json');
|
|
117
|
+
if (!existsSync(pkgJsonPath))
|
|
118
|
+
return { importable: [], importFailures: [] };
|
|
119
|
+
const entryFiles = listChunks(bundleDir).filter((chunk) => !relative(bundleDir, chunk).startsWith('chunks/'));
|
|
120
|
+
const importable = [];
|
|
121
|
+
const importFailures = [];
|
|
122
|
+
for (const file of entryFiles) {
|
|
123
|
+
const entry = relative(bundleDir, file);
|
|
124
|
+
try {
|
|
125
|
+
execFileSync(process.execPath, ['--input-type=module', '-e', `await import(${JSON.stringify(file)});`], { stdio: 'pipe', encoding: 'utf8', timeout: 30_000, cwd: bundleDir });
|
|
126
|
+
importable.push(entry);
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
const stderr = error && typeof error === 'object' && 'stderr' in error
|
|
130
|
+
? String(error.stderr ?? '')
|
|
131
|
+
: String(error);
|
|
132
|
+
const message = (stderr.split('\n').find((line) => line.trim()) ?? 'unknown error')
|
|
133
|
+
.trim()
|
|
134
|
+
.slice(0, 200);
|
|
135
|
+
importFailures.push({
|
|
136
|
+
entry,
|
|
137
|
+
message,
|
|
138
|
+
expected: isExpectedRuntimeError(stderr),
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { importable, importFailures };
|
|
143
|
+
}
|
|
144
|
+
export function verifyBundle({ bundleDir, emittedImports, peerDependencies, vendoredPackages, strict, }) {
|
|
145
|
+
const chunks = listChunks(bundleDir);
|
|
146
|
+
const peers = new Set(peerDependencies);
|
|
147
|
+
const vendored = new Set(vendoredPackages);
|
|
148
|
+
const imports = [];
|
|
149
|
+
const invalidChunks = [];
|
|
150
|
+
const dynamicRequireStubs = [];
|
|
151
|
+
for (const chunk of chunks) {
|
|
152
|
+
const relativeChunk = relative(bundleDir, chunk);
|
|
153
|
+
const code = readFileSync(chunk, 'utf8');
|
|
154
|
+
// Syntax gate. Catches output corruption and the one plausible banner collision —
|
|
155
|
+
// a bundled module declaring its own top-level `require`.
|
|
156
|
+
try {
|
|
157
|
+
execFileSync(process.execPath, ['--check', chunk], { stdio: 'pipe' });
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
invalidChunks.push(relativeChunk);
|
|
161
|
+
}
|
|
162
|
+
if (code.includes(DYNAMIC_REQUIRE_STUB)) {
|
|
163
|
+
dynamicRequireStubs.push(relativeChunk);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
for (const { specifier, chunk } of emittedImports) {
|
|
167
|
+
// Relative specifiers point at other files inside the bundle.
|
|
168
|
+
if (specifier.startsWith('.') || specifier.startsWith('/'))
|
|
169
|
+
continue;
|
|
170
|
+
const packageName = toPackageName(specifier);
|
|
171
|
+
const classification = BUILTINS.has(specifier)
|
|
172
|
+
? 'builtin'
|
|
173
|
+
: peers.has(packageName)
|
|
174
|
+
? 'peer'
|
|
175
|
+
: vendored.has(packageName) &&
|
|
176
|
+
isUsableVendoredPackage({ bundleDir, packageName })
|
|
177
|
+
? 'vendored'
|
|
178
|
+
: 'leaked';
|
|
179
|
+
imports.push({ specifier, packageName, chunk, classification });
|
|
180
|
+
}
|
|
181
|
+
if (invalidChunks.length > 0) {
|
|
182
|
+
throw new BundlerError({
|
|
183
|
+
code: ERROR_CODES.ERR_INVALID_OUTPUT,
|
|
184
|
+
message: 'The bundler produced JavaScript that Node cannot parse.',
|
|
185
|
+
details: invalidChunks.map((chunk) => `Invalid syntax in ${chunk}`),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (dynamicRequireStubs.length > 0) {
|
|
189
|
+
throw new BundlerError({
|
|
190
|
+
code: ERROR_CODES.ERR_BUILD_FAILED,
|
|
191
|
+
message: 'The bundle contains a dynamic-require stub that throws when reached at runtime.',
|
|
192
|
+
details: dynamicRequireStubs.map((chunk) => `${chunk} contains a "${DYNAMIC_REQUIRE_STUB}" stub`),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
const leaked = imports.filter((entry) => entry.classification === 'leaked');
|
|
196
|
+
if (leaked.length > 0) {
|
|
197
|
+
// Group by package so the message names packages, not every subpath of each.
|
|
198
|
+
const byPackage = new Map();
|
|
199
|
+
for (const entry of leaked) {
|
|
200
|
+
const chunksFor = byPackage.get(entry.packageName) ?? new Set();
|
|
201
|
+
chunksFor.add(entry.chunk);
|
|
202
|
+
byPackage.set(entry.packageName, chunksFor);
|
|
203
|
+
}
|
|
204
|
+
throw new BundlerError({
|
|
205
|
+
code: ERROR_CODES.ERR_NOT_SELF_CONTAINED,
|
|
206
|
+
message: `The bundle still imports ${byPackage.size} package${byPackage.size === 1 ? '' : 's'} that will not exist on the target machine.`,
|
|
207
|
+
details: [...byPackage.entries()].map(([name, chunksFor]) => `${name} — imported by ${[...chunksFor].join(', ')}`),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
const vendorGaps = findMissingVendoredDependencies({
|
|
211
|
+
bundleDir,
|
|
212
|
+
vendoredPackages,
|
|
213
|
+
peerDependencies,
|
|
214
|
+
});
|
|
215
|
+
if (vendorGaps.length > 0) {
|
|
216
|
+
throw new BundlerError({
|
|
217
|
+
code: ERROR_CODES.ERR_NOT_SELF_CONTAINED,
|
|
218
|
+
message: `${vendorGaps.length} package(s) copied into the bundle are missing their own dependencies.`,
|
|
219
|
+
details: vendorGaps.map((gap) => `${gap.missing} — required by the vendored ${gap.requiredBy}`),
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
const { importable, importFailures } = probeImports({ bundleDir });
|
|
223
|
+
if (strict && importFailures.length > 0) {
|
|
224
|
+
throw new BundlerError({
|
|
225
|
+
code: ERROR_CODES.ERR_STRICT_WARNINGS,
|
|
226
|
+
message: `--strict is set and ${importFailures.length} entry point(s) failed to import.`,
|
|
227
|
+
details: importFailures.map((failure) => `${failure.entry}: ${failure.message}`),
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
chunksChecked: chunks.length,
|
|
232
|
+
imports,
|
|
233
|
+
leaked,
|
|
234
|
+
importable,
|
|
235
|
+
importFailures,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=verify-bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-bundle.js","sourceRoot":"","sources":["../src/verify-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAExD,qFAAqF;AACrF,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAE7D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC;IACvB,GAAG,cAAc;IACjB,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,IAAI,EAAE,CAAC;CAChD,CAAC,CAAC;AAyBH,yFAAyF;AACzF,MAAM,UAAU,aAAa,CAAC,SAAiB;IAC7C,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;Q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