From a1af02eceada86d236c1be950d55f0c3962de978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=9D?= Date: Fri, 17 Jun 2022 22:16:23 +0800 Subject: [PATCH] fix: add libc fields only to platforms that have libc --- scripts/build-npm.js | 62 ++++++++++++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/scripts/build-npm.js b/scripts/build-npm.js index b2f7d8e3..4b851097 100644 --- a/scripts/build-npm.js +++ b/scripts/build-npm.js @@ -2,15 +2,37 @@ const fs = require('fs'); const pkg = require('../package.json'); const dir = `${__dirname}/..`; + +// Add `libc` fields only to platforms that have libc(Standard C library). const triples = [ - 'x86_64-apple-darwin', - 'x86_64-unknown-linux-gnu', - 'x86_64-pc-windows-msvc', - 'aarch64-apple-darwin', - 'aarch64-unknown-linux-gnu', - 'armv7-unknown-linux-gnueabihf', - 'aarch64-unknown-linux-musl', - 'x86_64-unknown-linux-musl' + { + name: 'x86_64-apple-darwin', + }, + { + name: 'x86_64-unknown-linux-gnu', + libc: 'glibc', + }, + { + name: 'x86_64-pc-windows-msvc', + }, + { + name: 'aarch64-apple-darwin', + }, + { + name: 'aarch64-unknown-linux-gnu', + libc: 'glibc', + }, + { + name: 'armv7-unknown-linux-gnueabihf', + }, + { + name: 'aarch64-unknown-linux-musl', + libc: 'musl', + }, + { + name: 'x86_64-unknown-linux-musl', + libc: 'musl', + }, ]; const cpuToNodeArch = { x86_64: 'x64', @@ -24,9 +46,6 @@ const sysToNodePlatform = { darwin: 'darwin', windows: 'win32', }; -const abiToNodeLibc = { - gnu: 'glibc', -}; let optionalDependencies = {}; let cliOptionalDependencies = {}; @@ -36,7 +55,10 @@ try { } catch (err) {} for (let triple of triples) { - let [cpu, , os, abi] = triple.split('-'); + // Add the libc field to package.json to avoid downloading both + // `gnu` and `musl` packages in Linux. + const libc = triple.libc; + let [cpu, , os, abi] = triple.name.split('-'); cpu = cpuToNodeArch[cpu] || cpu; os = sysToNodePlatform[os] || os; @@ -45,8 +67,8 @@ for (let triple of triples) { t += '-' + abi; } - buildNode(triple, cpu, os, abi, t); - buildCLI(triple, cpu, os, abi, t); + buildNode(triple.name, cpu, os, libc, t); + buildCLI(triple.name, cpu, os, libc, t); } pkg.optionalDependencies = optionalDependencies; @@ -71,15 +93,15 @@ cliPkg.scripts = { fs.writeFileSync(`${dir}/cli/package.json`, JSON.stringify(cliPkg, false, 2) + '\n'); fs.copyFileSync(`${dir}/README.md`, `${dir}/cli/README.md`); -function buildNode(triple, cpu, os, abi, t) { +function buildNode(triple, cpu, os, libc, t) { let name = `parcel-css.${t}.node`; let pkg2 = {...pkg}; pkg2.name += '-' + t; pkg2.os = [os]; pkg2.cpu = [cpu]; - if (abi && os !== "win32") { - pkg2.libc = [abiToNodeLibc[abi] || abi]; + if (libc) { + pkg2.libc = [libc]; } pkg2.main = name; pkg2.files = [name]; @@ -101,15 +123,15 @@ function buildNode(triple, cpu, os, abi, t) { fs.writeFileSync(`${dir}/npm/node-${t}/README.md`, `This is the ${triple} build of @parcel/css. See https://github.com/parcel-bundler/parcel-css for details.`); } -function buildCLI(triple, cpu, os, abi, t) { +function buildCLI(triple, cpu, os, libc, t) { let binary = os === 'win32' ? 'parcel_css.exe' : 'parcel_css'; let pkg2 = {...pkg}; pkg2.name += '-cli-' + t; pkg2.os = [os]; pkg2.cpu = [cpu]; pkg2.files = [binary]; - if (abi && os !== "win32") { - pkg2.libc = [abiToNodeLibc[abi] || abi]; + if (libc) { + pkg2.libc = [libc]; } delete pkg2.main; delete pkg2.napi;