This PR bumps the repo to pnpm v11 (from v9). I kept running into weird Windows specific issues for the integration tests due to some shims but they all pass right now. Bumping to pnpm v11 also meant that everything is driven by a `pnpm-workspace.yaml` file, and changes applied via the `pnpm` field in the `package.json` don't work anymore. This also moved the `node-linker` setup that was defined in the `.npmrc` file for the wasm oxide build into the `pnpm-workspace.yaml` file. Ideally this is scoped to just this package, but I couldn't get that to work, so it's applied to all packages right now. [ci-all]
74 lines
2.2 KiB
JavaScript
74 lines
2.2 KiB
JavaScript
import { exec, execSync } from 'node:child_process'
|
|
import fs from 'node:fs/promises'
|
|
import { platform } from 'node:os'
|
|
import path, { dirname } from 'node:path'
|
|
import url from 'node:url'
|
|
|
|
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
|
|
let root = path.resolve(__dirname, '..')
|
|
|
|
let command = platform() === 'win32' ? 'cd' : 'pwd'
|
|
let rawPaths = execSync(`pnpm --silent --filter=!./playgrounds/* -r exec ${command}`).toString()
|
|
|
|
let paths = rawPaths
|
|
.trim()
|
|
.split(/\r?\n/)
|
|
.map((x) => path.join(x, 'package.json'))
|
|
|
|
let workspaces = new Map()
|
|
|
|
// Track all the workspaces
|
|
for (let path of paths) {
|
|
let pkg = await fs.readFile(path, 'utf8').then(JSON.parse)
|
|
if (pkg.private) continue
|
|
workspaces.set(pkg.name, {
|
|
version: pkg.version ?? '',
|
|
dir: dirname(path),
|
|
hasBundledDependencies: pkg.bundledDependencies?.length > 0 ?? false,
|
|
})
|
|
}
|
|
|
|
// Clean dist folder
|
|
await fs.rm(path.join(root, 'dist'), { recursive: true, force: true })
|
|
|
|
Promise.all(
|
|
[...workspaces.entries()].map(async ([name, { dir, hasBundledDependencies }]) => {
|
|
function pack() {
|
|
return new Promise((resolve) => {
|
|
// `bundledDependencies` can only be packed with the hoisted node linker
|
|
// since pnpm v10. We opt into it for those packages only, instead of
|
|
// changing the node linker for the entire workspace.
|
|
exec(
|
|
`pnpm pack --pack-gzip-level=0 --pack-destination="${path.join(root, 'dist').replace(/\\/g, '\\\\')}"${hasBundledDependencies ? ' --config.node-linker=hoisted' : ''}`,
|
|
{ cwd: dir },
|
|
(err, stdout, stderr) => {
|
|
if (err) {
|
|
console.error(err, stdout, stderr)
|
|
}
|
|
|
|
resolve(lastLine(stdout.trim()))
|
|
},
|
|
)
|
|
})
|
|
}
|
|
|
|
let filename = await pack()
|
|
// Remove version suffix
|
|
await fs.rename(
|
|
path.join(root, 'dist', path.basename(filename)),
|
|
path.join(root, 'dist', pkgToFilename(name)),
|
|
)
|
|
}),
|
|
).then(() => {
|
|
console.log('Done.')
|
|
})
|
|
|
|
function pkgToFilename(name) {
|
|
return `${name.replace('@', '').replace('/', '-')}.tgz`
|
|
}
|
|
|
|
function lastLine(str) {
|
|
let index = str.lastIndexOf('\n')
|
|
if (index === -1) return str
|
|
return str.slice(index + 1)
|
|
}
|