Skip to content

Commit 60da2b5

Browse files
authored
fix: add libc fields only to platforms that have libc (parcel-bundler#210)
1 parent 43ea3ea commit 60da2b5

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

scripts/build-npm.js

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,37 @@ const fs = require('fs');
22
const pkg = require('../package.json');
33

44
const dir = `${__dirname}/..`;
5+
6+
// Add `libc` fields only to platforms that have libc(Standard C library).
57
const triples = [
6-
'x86_64-apple-darwin',
7-
'x86_64-unknown-linux-gnu',
8-
'x86_64-pc-windows-msvc',
9-
'aarch64-apple-darwin',
10-
'aarch64-unknown-linux-gnu',
11-
'armv7-unknown-linux-gnueabihf',
12-
'aarch64-unknown-linux-musl',
13-
'x86_64-unknown-linux-musl'
8+
{
9+
name: 'x86_64-apple-darwin',
10+
},
11+
{
12+
name: 'x86_64-unknown-linux-gnu',
13+
libc: 'glibc',
14+
},
15+
{
16+
name: 'x86_64-pc-windows-msvc',
17+
},
18+
{
19+
name: 'aarch64-apple-darwin',
20+
},
21+
{
22+
name: 'aarch64-unknown-linux-gnu',
23+
libc: 'glibc',
24+
},
25+
{
26+
name: 'armv7-unknown-linux-gnueabihf',
27+
},
28+
{
29+
name: 'aarch64-unknown-linux-musl',
30+
libc: 'musl',
31+
},
32+
{
33+
name: 'x86_64-unknown-linux-musl',
34+
libc: 'musl',
35+
},
1436
];
1537
const cpuToNodeArch = {
1638
x86_64: 'x64',
@@ -24,9 +46,6 @@ const sysToNodePlatform = {
2446
darwin: 'darwin',
2547
windows: 'win32',
2648
};
27-
const abiToNodeLibc = {
28-
gnu: 'glibc',
29-
};
3049

3150
let optionalDependencies = {};
3251
let cliOptionalDependencies = {};
@@ -36,7 +55,10 @@ try {
3655
} catch (err) {}
3756

3857
for (let triple of triples) {
39-
let [cpu, , os, abi] = triple.split('-');
58+
// Add the libc field to package.json to avoid downloading both
59+
// `gnu` and `musl` packages in Linux.
60+
const libc = triple.libc;
61+
let [cpu, , os, abi] = triple.name.split('-');
4062
cpu = cpuToNodeArch[cpu] || cpu;
4163
os = sysToNodePlatform[os] || os;
4264

@@ -45,8 +67,8 @@ for (let triple of triples) {
4567
t += '-' + abi;
4668
}
4769

48-
buildNode(triple, cpu, os, abi, t);
49-
buildCLI(triple, cpu, os, abi, t);
70+
buildNode(triple.name, cpu, os, libc, t);
71+
buildCLI(triple.name, cpu, os, libc, t);
5072
}
5173

5274
pkg.optionalDependencies = optionalDependencies;
@@ -71,15 +93,15 @@ cliPkg.scripts = {
7193
fs.writeFileSync(`${dir}/cli/package.json`, JSON.stringify(cliPkg, false, 2) + '\n');
7294
fs.copyFileSync(`${dir}/README.md`, `${dir}/cli/README.md`);
7395

74-
function buildNode(triple, cpu, os, abi, t) {
96+
function buildNode(triple, cpu, os, libc, t) {
7597
let name = `parcel-css.${t}.node`;
7698

7799
let pkg2 = {...pkg};
78100
pkg2.name += '-' + t;
79101
pkg2.os = [os];
80102
pkg2.cpu = [cpu];
81-
if (abi && os !== "win32") {
82-
pkg2.libc = [abiToNodeLibc[abi] || abi];
103+
if (libc) {
104+
pkg2.libc = [libc];
83105
}
84106
pkg2.main = name;
85107
pkg2.files = [name];
@@ -101,15 +123,15 @@ function buildNode(triple, cpu, os, abi, t) {
101123
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.`);
102124
}
103125

104-
function buildCLI(triple, cpu, os, abi, t) {
126+
function buildCLI(triple, cpu, os, libc, t) {
105127
let binary = os === 'win32' ? 'parcel_css.exe' : 'parcel_css';
106128
let pkg2 = {...pkg};
107129
pkg2.name += '-cli-' + t;
108130
pkg2.os = [os];
109131
pkg2.cpu = [cpu];
110132
pkg2.files = [binary];
111-
if (abi && os !== "win32") {
112-
pkg2.libc = [abiToNodeLibc[abi] || abi];
133+
if (libc) {
134+
pkg2.libc = [libc];
113135
}
114136
delete pkg2.main;
115137
delete pkg2.napi;

0 commit comments

Comments
 (0)