| 79 | } |
| 80 | |
| 81 | export async function build(name) { |
| 82 | let dir = buildPath(name); |
| 83 | await fs.mkdir(path.dirname(dir), {recursive: true}); |
| 84 | // Named snapshots are immutable, so a baseline cannot be overwritten by accident. |
| 85 | await fs.mkdir(dir); |
| 86 | try { |
| 87 | console.log(`Building production snapshot ${name}…`); |
| 88 | let bundler = new parcel.Parcel({ |
| 89 | entries: path.join(root, 'perf/app/index.html'), |
| 90 | config: path.join(root, 'perf/.parcelrc'), |
| 91 | mode: 'production', |
| 92 | env: {NODE_ENV: 'production'}, |
| 93 | shouldAutoInstall: false, |
| 94 | cacheDir: path.join(local, 'cache'), |
| 95 | targets: { |
| 96 | benchmark: { |
| 97 | context: 'browser', |
| 98 | distDir: dir, |
| 99 | publicUrl: './', |
| 100 | outputFormat: 'esmodule', |
| 101 | includeNodeModules: true, |
| 102 | optimize: true, |
| 103 | scopeHoist: true, |
| 104 | sourceMap: false, |
| 105 | engines: {browsers: ['Chrome >= 120']} |
| 106 | } |
| 107 | } |
| 108 | }); |
| 109 | let {bundleGraph} = await bundler.run(); |
| 110 | let assets = new Set(); |
| 111 | for (let bundle of bundleGraph.getBundles()) { |
| 112 | bundle.traverseAssets(asset => |
| 113 | assets.add(path.relative(root, asset.filePath).replaceAll('\\', '/')) |
| 114 | ); |
| 115 | } |
| 116 | let reactAssets = [...assets].filter(file => /node_modules\/react(-dom)?\//.test(file)); |
| 117 | if ( |
| 118 | !reactAssets.some(file => file.endsWith('react-dom-client.production.js')) || |
| 119 | reactAssets.some(file => file.endsWith('.development.js')) |
| 120 | ) { |
| 121 | throw new Error( |
| 122 | 'The bundle must contain production React DOM and no development React modules.' |
| 123 | ); |
| 124 | } |
| 125 | for (let pkg of ['react-aria-components', 'react-aria', 'react-stately']) { |
| 126 | if (![...assets].some(file => file.startsWith(`packages/${pkg}/src/`))) { |
| 127 | throw new Error(`Expected ${pkg} to resolve to source in this checkout.`); |
| 128 | } |
| 129 | } |
| 130 | let git = (...args) => |
| 131 | execFileSync('git', args, {cwd: root, encoding: 'utf8', maxBuffer: 32 * 1024 * 1024}).trim(); |
| 132 | let manifest = { |
| 133 | schema: 1, |
| 134 | name, |
| 135 | created: new Date().toISOString(), |
| 136 | source: { |
| 137 | sha: git('rev-parse', 'HEAD'), |
| 138 | branch: git('branch', '--show-current'), |