Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

build.mjs

47 lines1.2 KB

1import { spawnSync } from 'node:child_process'
2import path from 'node:path'
3import { fileURLToPath, pathToFileURL } from 'node:url'
4​
5const repoRoot = fileURLToPath(new URL('../../../', import.meta.url))
6​
7/**
8 * Run report generation outside Nx so it also runs after a cache hit.
9 * @param {string[]} args
10 * @param {import('./run.mjs').Execute} [execute]
11 */
12export function build(args, execute = spawnSync) {
13 const pnpmPath = process.env.npm_execpath
14 /** @type {import('./run.mjs').CommandOptions} */
15 const options = { cwd: repoRoot, env: process.env, stdio: 'inherit' }
16 const result = execute(
17 pnpmPath
18 ? process.execPath
19 : process.platform === 'win32'
20 ? 'pnpm.cmd'
21 : 'pnpm',
22 [
23 ...(pnpmPath ? [pnpmPath] : []),
24 'nx',
25 'run',
26 '@benchmarks/bundle-size:measure',
27 ...args,
28 ],
29 options,
30 )
31 if (result.status !== 0) {
32 return result.status || 1
33 }
34 const report = execute(
35 process.execPath,
36 [fileURLToPath(new URL('./report.mjs', import.meta.url))],
37 options,
38 )
39 return report.status ?? 1
41​
42if (
43 process.argv[1] &&
44 import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href
45) {
46 process.exitCode = build(process.argv.slice(2))