Skip to content

Commit

Permalink
Reduce install size for linux glibc/musl (#32850)
Browse files Browse the repository at this point in the history
In Next.js [12.0.1](
https://packagephobia.com/result?p=next@12.0.1), musl support was added which caused linux to install both glibc and musl binaries.

This PR adds the `install` script to prevent installing unused binaries, reducing the install size by 47MB.

We originally thought this could be added to Node.js core and thus npm but [it was rejected](nodejs/node#41338).

Note getReport() works on Node.js [`>=11.8.0`](https://nodejs.org/api/process.html#processreportgetreporterr) which is safe to use since Next.js requires [`"node": ">=12.22.0"`](https://github.com/vercel/next.js/blob/265f71e225ed18fcb099c28cf1b5c83519acc3b0/packages/next/package.json#L280).
  • Loading branch information
styfle authored Jan 3, 2022
1 parent d0e72fd commit a5fab84
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/next-swc/crates/napi/npm/linux-arm64-gnu/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { glibcVersionRuntime } = process.report.getReport().header;
process.exit(glibcVersionRuntime ? 0 : 1);
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
],
"main": "next-swc.linux-arm64-gnu.node",
"files": [
"next-swc.linux-arm64-gnu.node"
"next-swc.linux-arm64-gnu.node",
"install.js"
],
"scripts": {
"install": "node install.js"
},
"license": "MIT",
"engines": {
"node": ">= 10"
Expand Down
2 changes: 2 additions & 0 deletions packages/next-swc/crates/napi/npm/linux-arm64-musl/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { glibcVersionRuntime } = process.report.getReport().header;
process.exit(glibcVersionRuntime ? 1 : 0);
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
],
"main": "next-swc.linux-arm64-musl.node",
"files": [
"next-swc.linux-arm64-musl.node"
"next-swc.linux-arm64-musl.node",
"install.js"
],
"scripts": {
"install": "node install.js"
},
"license": "MIT",
"engines": {
"node": ">= 10"
Expand Down
2 changes: 2 additions & 0 deletions packages/next-swc/crates/napi/npm/linux-x64-gnu/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { glibcVersionRuntime } = process.report.getReport().header;
process.exit(glibcVersionRuntime ? 0 : 1);
6 changes: 5 additions & 1 deletion packages/next-swc/crates/napi/npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
],
"main": "next-swc.linux-x64-gnu.node",
"files": [
"next-swc.linux-x64-gnu.node"
"next-swc.linux-x64-gnu.node",
"install.js"
],
"scripts": {
"install": "node install.js"
},
"license": "MIT",
"engines": {
"node": ">= 10"
Expand Down
2 changes: 2 additions & 0 deletions packages/next-swc/crates/napi/npm/linux-x64-musl/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const { glibcVersionRuntime } = process.report.getReport().header;
process.exit(glibcVersionRuntime ? 1 : 0);
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
],
"main": "next-swc.linux-x64-musl.node",
"files": [
"next-swc.linux-x64-musl.node"
"next-swc.linux-x64-musl.node",
"install.js"
],
"scripts": {
"install": "node install.js"
},
"license": "MIT",
"engines": {
"node": ">= 10"
Expand Down

0 comments on commit a5fab84

Please sign in to comment.