|
1 | | -// Build verification, run after `npm run build`. (1) Gzips each public entry's local |
| 1 | +// Bundle-size budget guard, run after `npm run build`. Gzips each public entry's local |
2 | 2 | // closure (the entry file plus the dist chunks it imports; peer deps are external and |
3 | | -// never counted) and fails if any entry exceeds its budget. (2) Loads every public |
4 | | -// subpath per its export conditions, so an entry that resolves but throws at load (e.g. |
5 | | -// a CJS bundle requiring an ESM-only peer) fails here, not at the consumer. |
| 3 | +// never counted) and fails if any entry exceeds its budget. Export loadability is guarded |
| 4 | +// separately by ../../scripts/check-exports.mjs (the `check:exports` script). |
6 | 5 |
|
7 | 6 | import { existsSync, readFileSync } from 'node:fs' |
8 | | -import { createRequire } from 'node:module' |
9 | 7 | import { dirname, join } from 'node:path' |
10 | 8 | import { fileURLToPath } from 'node:url' |
11 | 9 | import { gzipSync } from 'node:zlib' |
@@ -58,26 +56,4 @@ const allWithinBudget = Object.entries(BUDGETS).map(([entry, budget]) => { |
58 | 56 | console.log(`${ok ? '✓' : '✗'} ${entry}: ${size} B gzip (budget ${budget} B)`) |
59 | 57 | return ok |
60 | 58 | }) |
61 | | -// Load every public subpath the way its export map advertises it. |
62 | | -const require = createRequire(import.meta.url) |
63 | | -const pkg = JSON.parse(readFileSync(join(DIST, '..', 'package.json'), 'utf8')) |
64 | | -const load = { require: (spec) => require(spec), import: (spec) => import(spec) } |
65 | | -const exportsLoad = [] |
66 | | -for (const [subpath, conditions] of Object.entries(pkg.exports)) { |
67 | | - const spec = subpath === '.' ? pkg.name : `${pkg.name}/${subpath.slice(2)}` |
68 | | - for (const condition of ['require', 'import']) { |
69 | | - if (conditions[condition] === undefined) { |
70 | | - continue |
71 | | - } |
72 | | - try { |
73 | | - await load[condition](spec) |
74 | | - console.log(`✓ ${spec} [${condition}] loads`) |
75 | | - exportsLoad.push(true) |
76 | | - } catch (error) { |
77 | | - console.error(`✗ ${spec} [${condition}]: ${error.code ?? error.message}`) |
78 | | - exportsLoad.push(false) |
79 | | - } |
80 | | - } |
81 | | -} |
82 | | - |
83 | | -process.exit([...allWithinBudget, ...exportsLoad].every(Boolean) ? 0 : 1) |
| 59 | +process.exit(allWithinBudget.every(Boolean) ? 0 : 1) |
0 commit comments