|
| 1 | +import { readFile, writeFile } from 'node:fs/promises'; |
| 2 | +import path from 'node:path'; |
| 3 | + |
| 4 | +const root = path.resolve(path.join(path.dirname(new URL(import.meta.url).pathname), '..')); |
| 5 | +const packageJson = JSON.parse(await readFile(path.join(root, 'package.json'), 'utf-8')); |
| 6 | +const variants = JSON.parse(await readFile(path.join(root, 'variants.json'), 'utf-8')); |
| 7 | + |
| 8 | +const { devDependencies, ...commonPackageJsonProperties } = packageJson; |
| 9 | + |
| 10 | +await Promise.all( |
| 11 | + variants.map(async variant => { |
| 12 | + const libcName = variant.libc === 'glibc' ? 'gnu' : variant.libc; |
| 13 | + const variantName = [variant.os, variant.cpu, libcName] |
| 14 | + .filter(part => part !== undefined) |
| 15 | + .join('-'); |
| 16 | + const nativeBindingFile = `exec.${variantName}.node`; |
| 17 | + await writeFile( |
| 18 | + path.join(root, 'npm', variantName, 'package.json'), |
| 19 | + JSON.stringify( |
| 20 | + { |
| 21 | + name: `${packageJson.name}-${variantName}`, |
| 22 | + version: packageJson.version, |
| 23 | + description: packageJson.description, |
| 24 | + author: packageJson.author, |
| 25 | + keywords: packageJson.keywords, |
| 26 | + license: packageJson.license, |
| 27 | + repository: packageJson.repository, |
| 28 | + main: nativeBindingFile, |
| 29 | + files: [nativeBindingFile], |
| 30 | + os: toArray(variant.os), |
| 31 | + cpu: toArray(variant.cpu), |
| 32 | + libc: toArray(variant.libc), |
| 33 | + engines: packageJson.engines |
| 34 | + }, |
| 35 | + undefined, |
| 36 | + 2 |
| 37 | + ), |
| 38 | + 'utf8' |
| 39 | + ); |
| 40 | + }) |
| 41 | +); |
| 42 | + |
| 43 | +function toArray(value) { |
| 44 | + if (value === undefined) { |
| 45 | + return undefined; |
| 46 | + } |
| 47 | + |
| 48 | + return Array.isArray(value) ? value : [value]; |
| 49 | +} |
0 commit comments