From fd4f6ea013a2428faf7f88a7facd763eeadc804e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Sep 2025 13:13:44 +0000 Subject: [PATCH 1/3] Initial plan From 92c069123838b87b89c185433e19fef63ce203b0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Sep 2025 13:23:09 +0000 Subject: [PATCH 2/3] Initial analysis complete - identified INIT_CWD undefined issue Co-authored-by: kdy1 <29931815+kdy1@users.noreply.github.com> --- bindings/binding_es_ast_viewer/package.json | 2 +- packages/core/scripts/npm/darwin-arm64/package.json | 2 +- packages/core/scripts/npm/darwin-x64/package.json | 2 +- packages/core/scripts/npm/linux-arm-gnueabihf/package.json | 2 +- packages/core/scripts/npm/linux-arm64-gnu/package.json | 2 +- packages/core/scripts/npm/linux-arm64-musl/package.json | 2 +- packages/core/scripts/npm/linux-x64-gnu/package.json | 2 +- packages/core/scripts/npm/linux-x64-musl/package.json | 2 +- packages/core/scripts/npm/win32-arm64-msvc/package.json | 2 +- packages/core/scripts/npm/win32-ia32-msvc/package.json | 2 +- packages/core/scripts/npm/win32-x64-msvc/package.json | 2 +- packages/html/scripts/npm/darwin-arm64/package.json | 2 +- packages/html/scripts/npm/darwin-x64/package.json | 2 +- packages/html/scripts/npm/linux-arm-gnueabihf/package.json | 2 +- packages/html/scripts/npm/linux-arm64-gnu/package.json | 2 +- packages/html/scripts/npm/linux-arm64-musl/package.json | 2 +- packages/html/scripts/npm/linux-x64-gnu/package.json | 2 +- packages/html/scripts/npm/linux-x64-musl/package.json | 2 +- packages/html/scripts/npm/win32-arm64-msvc/package.json | 2 +- packages/html/scripts/npm/win32-ia32-msvc/package.json | 2 +- packages/html/scripts/npm/win32-x64-msvc/package.json | 2 +- packages/minifier/scripts/npm/darwin-arm64/package.json | 2 +- packages/minifier/scripts/npm/darwin-x64/package.json | 2 +- packages/minifier/scripts/npm/linux-arm-gnueabihf/package.json | 2 +- packages/minifier/scripts/npm/linux-arm64-gnu/package.json | 2 +- packages/minifier/scripts/npm/linux-arm64-musl/package.json | 2 +- packages/minifier/scripts/npm/linux-x64-gnu/package.json | 2 +- packages/minifier/scripts/npm/linux-x64-musl/package.json | 2 +- packages/minifier/scripts/npm/win32-arm64-msvc/package.json | 2 +- packages/minifier/scripts/npm/win32-ia32-msvc/package.json | 2 +- packages/minifier/scripts/npm/win32-x64-msvc/package.json | 2 +- packages/react-compiler/scripts/npm/darwin-arm64/package.json | 2 +- packages/react-compiler/scripts/npm/darwin-x64/package.json | 2 +- .../react-compiler/scripts/npm/linux-arm-gnueabihf/package.json | 2 +- .../react-compiler/scripts/npm/linux-arm64-gnu/package.json | 2 +- .../react-compiler/scripts/npm/linux-arm64-musl/package.json | 2 +- packages/react-compiler/scripts/npm/linux-x64-gnu/package.json | 2 +- packages/react-compiler/scripts/npm/linux-x64-musl/package.json | 2 +- .../react-compiler/scripts/npm/win32-arm64-msvc/package.json | 2 +- .../react-compiler/scripts/npm/win32-ia32-msvc/package.json | 2 +- packages/react-compiler/scripts/npm/win32-x64-msvc/package.json | 2 +- 41 files changed, 41 insertions(+), 41 deletions(-) diff --git a/bindings/binding_es_ast_viewer/package.json b/bindings/binding_es_ast_viewer/package.json index 150d51366a1a..c6fc18a2397e 100644 --- a/bindings/binding_es_ast_viewer/package.json +++ b/bindings/binding_es_ast_viewer/package.json @@ -2,4 +2,4 @@ "devDependencies": { "jest": "^29.7.0" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/darwin-arm64/package.json b/packages/core/scripts/npm/darwin-arm64/package.json index b9e544c7f5be..077aefb7202d 100644 --- a/packages/core/scripts/npm/darwin-arm64/package.json +++ b/packages/core/scripts/npm/darwin-arm64/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/darwin-x64/package.json b/packages/core/scripts/npm/darwin-x64/package.json index f9da422d705e..ada2a5629c7d 100644 --- a/packages/core/scripts/npm/darwin-x64/package.json +++ b/packages/core/scripts/npm/darwin-x64/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/linux-arm-gnueabihf/package.json b/packages/core/scripts/npm/linux-arm-gnueabihf/package.json index 517d6631a5b7..10ea53b95f85 100644 --- a/packages/core/scripts/npm/linux-arm-gnueabihf/package.json +++ b/packages/core/scripts/npm/linux-arm-gnueabihf/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/linux-arm64-gnu/package.json b/packages/core/scripts/npm/linux-arm64-gnu/package.json index 7abdd1932859..e4f0d3cece34 100644 --- a/packages/core/scripts/npm/linux-arm64-gnu/package.json +++ b/packages/core/scripts/npm/linux-arm64-gnu/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/linux-arm64-musl/package.json b/packages/core/scripts/npm/linux-arm64-musl/package.json index d26db2f101d1..5ac405b30b2c 100644 --- a/packages/core/scripts/npm/linux-arm64-musl/package.json +++ b/packages/core/scripts/npm/linux-arm64-musl/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/linux-x64-gnu/package.json b/packages/core/scripts/npm/linux-x64-gnu/package.json index 8197dee8f7c2..e8936ba98c26 100644 --- a/packages/core/scripts/npm/linux-x64-gnu/package.json +++ b/packages/core/scripts/npm/linux-x64-gnu/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/linux-x64-musl/package.json b/packages/core/scripts/npm/linux-x64-musl/package.json index 2faf169adf3d..2b52d08ad7ea 100644 --- a/packages/core/scripts/npm/linux-x64-musl/package.json +++ b/packages/core/scripts/npm/linux-x64-musl/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/win32-arm64-msvc/package.json b/packages/core/scripts/npm/win32-arm64-msvc/package.json index 277f21678086..ce0a2b2fc748 100644 --- a/packages/core/scripts/npm/win32-arm64-msvc/package.json +++ b/packages/core/scripts/npm/win32-arm64-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/win32-ia32-msvc/package.json b/packages/core/scripts/npm/win32-ia32-msvc/package.json index 37a5acbca0d5..44bf50b17030 100644 --- a/packages/core/scripts/npm/win32-ia32-msvc/package.json +++ b/packages/core/scripts/npm/win32-ia32-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/core/scripts/npm/win32-x64-msvc/package.json b/packages/core/scripts/npm/win32-x64-msvc/package.json index c8c4a657b8a9..d71dd100a5df 100644 --- a/packages/core/scripts/npm/win32-x64-msvc/package.json +++ b/packages/core/scripts/npm/win32-x64-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/darwin-arm64/package.json b/packages/html/scripts/npm/darwin-arm64/package.json index 8278fa3e702f..c3b55c7567a6 100644 --- a/packages/html/scripts/npm/darwin-arm64/package.json +++ b/packages/html/scripts/npm/darwin-arm64/package.json @@ -37,4 +37,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/darwin-x64/package.json b/packages/html/scripts/npm/darwin-x64/package.json index e8cfa1c5845f..47a8991dc352 100644 --- a/packages/html/scripts/npm/darwin-x64/package.json +++ b/packages/html/scripts/npm/darwin-x64/package.json @@ -37,4 +37,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/linux-arm-gnueabihf/package.json b/packages/html/scripts/npm/linux-arm-gnueabihf/package.json index 6ad1e8318e51..1605f9048d71 100644 --- a/packages/html/scripts/npm/linux-arm-gnueabihf/package.json +++ b/packages/html/scripts/npm/linux-arm-gnueabihf/package.json @@ -37,4 +37,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/linux-arm64-gnu/package.json b/packages/html/scripts/npm/linux-arm64-gnu/package.json index bbb0f82778e1..f482ad49faf3 100644 --- a/packages/html/scripts/npm/linux-arm64-gnu/package.json +++ b/packages/html/scripts/npm/linux-arm64-gnu/package.json @@ -40,4 +40,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/linux-arm64-musl/package.json b/packages/html/scripts/npm/linux-arm64-musl/package.json index 0d696f4a5e4f..48b81065e1ac 100644 --- a/packages/html/scripts/npm/linux-arm64-musl/package.json +++ b/packages/html/scripts/npm/linux-arm64-musl/package.json @@ -40,4 +40,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/linux-x64-gnu/package.json b/packages/html/scripts/npm/linux-x64-gnu/package.json index 12224eadbc5b..49f694d3feb8 100644 --- a/packages/html/scripts/npm/linux-x64-gnu/package.json +++ b/packages/html/scripts/npm/linux-x64-gnu/package.json @@ -40,4 +40,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/linux-x64-musl/package.json b/packages/html/scripts/npm/linux-x64-musl/package.json index 53fb5ebc2108..2c9ce65e23e1 100644 --- a/packages/html/scripts/npm/linux-x64-musl/package.json +++ b/packages/html/scripts/npm/linux-x64-musl/package.json @@ -40,4 +40,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/win32-arm64-msvc/package.json b/packages/html/scripts/npm/win32-arm64-msvc/package.json index 787ceb9add78..1aa5f7836354 100644 --- a/packages/html/scripts/npm/win32-arm64-msvc/package.json +++ b/packages/html/scripts/npm/win32-arm64-msvc/package.json @@ -37,4 +37,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/win32-ia32-msvc/package.json b/packages/html/scripts/npm/win32-ia32-msvc/package.json index b4ab873fa4f1..015117041f29 100644 --- a/packages/html/scripts/npm/win32-ia32-msvc/package.json +++ b/packages/html/scripts/npm/win32-ia32-msvc/package.json @@ -37,4 +37,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/html/scripts/npm/win32-x64-msvc/package.json b/packages/html/scripts/npm/win32-x64-msvc/package.json index e7275698b64e..0715f879a8cc 100644 --- a/packages/html/scripts/npm/win32-x64-msvc/package.json +++ b/packages/html/scripts/npm/win32-x64-msvc/package.json @@ -37,4 +37,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/darwin-arm64/package.json b/packages/minifier/scripts/npm/darwin-arm64/package.json index 5cdb5f28b5ab..480bd216d7df 100644 --- a/packages/minifier/scripts/npm/darwin-arm64/package.json +++ b/packages/minifier/scripts/npm/darwin-arm64/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/darwin-x64/package.json b/packages/minifier/scripts/npm/darwin-x64/package.json index 7b6adb215ec3..f3197f6a2b3c 100644 --- a/packages/minifier/scripts/npm/darwin-x64/package.json +++ b/packages/minifier/scripts/npm/darwin-x64/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/linux-arm-gnueabihf/package.json b/packages/minifier/scripts/npm/linux-arm-gnueabihf/package.json index 2ed908dc8412..0f2c9c8d4687 100644 --- a/packages/minifier/scripts/npm/linux-arm-gnueabihf/package.json +++ b/packages/minifier/scripts/npm/linux-arm-gnueabihf/package.json @@ -35,4 +35,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/linux-arm64-gnu/package.json b/packages/minifier/scripts/npm/linux-arm64-gnu/package.json index a5c9bc01477b..2247f0862cbd 100644 --- a/packages/minifier/scripts/npm/linux-arm64-gnu/package.json +++ b/packages/minifier/scripts/npm/linux-arm64-gnu/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/linux-arm64-musl/package.json b/packages/minifier/scripts/npm/linux-arm64-musl/package.json index cc8ba56ae0cf..9b6169a7b512 100644 --- a/packages/minifier/scripts/npm/linux-arm64-musl/package.json +++ b/packages/minifier/scripts/npm/linux-arm64-musl/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/linux-x64-gnu/package.json b/packages/minifier/scripts/npm/linux-x64-gnu/package.json index d6859e734b3d..58b1bb9b3209 100644 --- a/packages/minifier/scripts/npm/linux-x64-gnu/package.json +++ b/packages/minifier/scripts/npm/linux-x64-gnu/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/linux-x64-musl/package.json b/packages/minifier/scripts/npm/linux-x64-musl/package.json index 20bd5193df38..d05c38789e66 100644 --- a/packages/minifier/scripts/npm/linux-x64-musl/package.json +++ b/packages/minifier/scripts/npm/linux-x64-musl/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/win32-arm64-msvc/package.json b/packages/minifier/scripts/npm/win32-arm64-msvc/package.json index 3ac02040c803..1b17f679ef78 100644 --- a/packages/minifier/scripts/npm/win32-arm64-msvc/package.json +++ b/packages/minifier/scripts/npm/win32-arm64-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/win32-ia32-msvc/package.json b/packages/minifier/scripts/npm/win32-ia32-msvc/package.json index f784600837a5..62a6a88472a6 100644 --- a/packages/minifier/scripts/npm/win32-ia32-msvc/package.json +++ b/packages/minifier/scripts/npm/win32-ia32-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/minifier/scripts/npm/win32-x64-msvc/package.json b/packages/minifier/scripts/npm/win32-x64-msvc/package.json index f104c9b7b022..2a39a64edf3e 100644 --- a/packages/minifier/scripts/npm/win32-x64-msvc/package.json +++ b/packages/minifier/scripts/npm/win32-x64-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/darwin-arm64/package.json b/packages/react-compiler/scripts/npm/darwin-arm64/package.json index 60a227130193..33d75ea6d5b2 100644 --- a/packages/react-compiler/scripts/npm/darwin-arm64/package.json +++ b/packages/react-compiler/scripts/npm/darwin-arm64/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/darwin-x64/package.json b/packages/react-compiler/scripts/npm/darwin-x64/package.json index c0778395cbf3..fde60474999d 100644 --- a/packages/react-compiler/scripts/npm/darwin-x64/package.json +++ b/packages/react-compiler/scripts/npm/darwin-x64/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/linux-arm-gnueabihf/package.json b/packages/react-compiler/scripts/npm/linux-arm-gnueabihf/package.json index 60b57e80fa64..11f312c579ff 100644 --- a/packages/react-compiler/scripts/npm/linux-arm-gnueabihf/package.json +++ b/packages/react-compiler/scripts/npm/linux-arm-gnueabihf/package.json @@ -35,4 +35,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/linux-arm64-gnu/package.json b/packages/react-compiler/scripts/npm/linux-arm64-gnu/package.json index 8b7a5d4be4f5..7d97909fa5b3 100644 --- a/packages/react-compiler/scripts/npm/linux-arm64-gnu/package.json +++ b/packages/react-compiler/scripts/npm/linux-arm64-gnu/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/linux-arm64-musl/package.json b/packages/react-compiler/scripts/npm/linux-arm64-musl/package.json index 9f138804a7b6..5eadb72c8d8c 100644 --- a/packages/react-compiler/scripts/npm/linux-arm64-musl/package.json +++ b/packages/react-compiler/scripts/npm/linux-arm64-musl/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/linux-x64-gnu/package.json b/packages/react-compiler/scripts/npm/linux-x64-gnu/package.json index d7562bd2edf1..40a2ac96f815 100644 --- a/packages/react-compiler/scripts/npm/linux-x64-gnu/package.json +++ b/packages/react-compiler/scripts/npm/linux-x64-gnu/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/linux-x64-musl/package.json b/packages/react-compiler/scripts/npm/linux-x64-musl/package.json index c1b779cb8058..dfb2a8f48d77 100644 --- a/packages/react-compiler/scripts/npm/linux-x64-musl/package.json +++ b/packages/react-compiler/scripts/npm/linux-x64-musl/package.json @@ -42,4 +42,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/win32-arm64-msvc/package.json b/packages/react-compiler/scripts/npm/win32-arm64-msvc/package.json index 8fcccb5f4924..a1c114cb67bd 100644 --- a/packages/react-compiler/scripts/npm/win32-arm64-msvc/package.json +++ b/packages/react-compiler/scripts/npm/win32-arm64-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/win32-ia32-msvc/package.json b/packages/react-compiler/scripts/npm/win32-ia32-msvc/package.json index 339071c7d46e..6f2ba9480e0c 100644 --- a/packages/react-compiler/scripts/npm/win32-ia32-msvc/package.json +++ b/packages/react-compiler/scripts/npm/win32-ia32-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} diff --git a/packages/react-compiler/scripts/npm/win32-x64-msvc/package.json b/packages/react-compiler/scripts/npm/win32-x64-msvc/package.json index 647ea47b4643..1729dcdd1084 100644 --- a/packages/react-compiler/scripts/npm/win32-x64-msvc/package.json +++ b/packages/react-compiler/scripts/npm/win32-x64-msvc/package.json @@ -39,4 +39,4 @@ "bugs": { "url": "https://github.com/swc-project/swc/issues" } -} \ No newline at end of file +} From 1dc3cbd405578100cb4e0eb0b191e01e2781d07d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Sep 2025 13:26:02 +0000 Subject: [PATCH 3/3] Fix INIT_CWD undefined issue in postinstall script Co-authored-by: kdy1 <29931815+kdy1@users.noreply.github.com> --- packages/core/postinstall.js | 226 +++++++++++++++++-------------- packages/core/src/postinstall.ts | 12 +- 2 files changed, 131 insertions(+), 107 deletions(-) diff --git a/packages/core/postinstall.js b/packages/core/postinstall.js index 4a1fab0cdcdf..fdf7f1d58eb2 100644 --- a/packages/core/postinstall.js +++ b/packages/core/postinstall.js @@ -1,26 +1,14 @@ "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } @@ -31,6 +19,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (g && (g = 0, op[0] && (_ = 0)), _) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; Object.defineProperty(exports, "__esModule", { value: true }); /** * A postinstall script runs after `@swc/core` is installed. @@ -38,19 +53,20 @@ Object.defineProperty(exports, "__esModule", { value: true }); * It checks if corresponding optional dependencies for native binary is installed and can be loaded properly. * If it fails, it'll internally try to install `@swc/wasm` as fallback. */ -const fs_1 = require("fs"); -const assert = __importStar(require("assert")); -const path = __importStar(require("path")); -const child_process = __importStar(require("child_process")); -const fs = __importStar(require("fs")); +var fs_1 = require("fs"); +var assert = require("assert"); +var path = require("path"); +var child_process = require("child_process"); +var fs = require("fs"); function removeRecursive(dir) { - for (const entry of fs.readdirSync(dir)) { - const entryPath = path.join(dir, entry); - let stats; + for (var _i = 0, _a = fs.readdirSync(dir); _i < _a.length; _i++) { + var entry = _a[_i]; + var entryPath = path.join(dir, entry); + var stats = void 0; try { stats = fs.lstatSync(entryPath); } - catch (_a) { + catch (_b) { continue; // Guard against https://github.com/nodejs/node/issues/4760 } if (stats.isDirectory()) @@ -63,86 +79,86 @@ function removeRecursive(dir) { /** * Trying to validate @swc/core's native binary installation, then installs if it is not supported. */ -const validateBinary = () => __awaiter(void 0, void 0, void 0, function* () { +var validateBinary = function () { return __awaiter(void 0, void 0, void 0, function () { + var name_1, binding, triple, wasmBinding, env, version, coreDir, installDir, installedBinPath; var _a; - try { - const { name } = require(path.resolve(process.env.INIT_CWD, "package.json")); - if (name === "@swc/core" || name === "@swc/workspace") { - return; + return __generator(this, function (_b) { + try { + if (!process.env.INIT_CWD) { + // If INIT_CWD is not set, we can't determine the package name, so skip the check + // This can happen with some package managers or in certain environments + return [2 /*return*/]; + } + name_1 = require(path.resolve(process.env.INIT_CWD, "package.json")).name; + if (name_1 === "@swc/core" || name_1 === "@swc/workspace") { + return [2 /*return*/]; + } } - } - catch (_) { - return; - } - // TODO: We do not take care of the case if user try to install with `--no-optional`. - // For now, it is considered as deliberate decision. - let binding; - try { - binding = require("./binding.js"); - // Check if binding binary actually works. - // For the latest version, checks target triple. If it's old version doesn't have target triple, use parseSync instead. - const triple = binding.getTargetTriple - ? binding.getTargetTriple() - : binding.parseSync("console.log()", Buffer.from(JSON.stringify({ syntax: "ecmascript" }))); - assert.ok(triple, "Failed to read target triple from native binary."); - } - catch (error) { - // if error is unsupported architecture, ignore to display. - if (!((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes("Unsupported architecture"))) { - console.warn(error); + catch (_) { + return [2 /*return*/]; } - console.warn(`@swc/core was not able to resolve native bindings installation. It'll try to use @swc/wasm as fallback instead.`); - } - if (!!binding) { - return; - } - // User choose to override the binary installation. Skip remanining validation. - if (!!process.env["SWC_BINARY_PATH"]) { - console.warn(`@swc/core could not resolve native bindings installation, but found manual override config SWC_BINARY_PATH specified. Skipping remaning validation.`); - return; - } - // Check if top-level package.json installs @swc/wasm separately already - let wasmBinding; - try { - wasmBinding = require.resolve(`@swc/wasm`); - } - catch (_) { } - if (!!wasmBinding && (0, fs_1.existsSync)(wasmBinding)) { - return; - } - const env = Object.assign(Object.assign({}, process.env), { npm_config_global: undefined }); - const { version } = require(path.join(path.dirname(require.resolve("@swc/core")), "package.json")); - // We want to place @swc/wasm next to the @swc/core as if normal installation was done, - // but can't directly set cwd to INIT_CWD as npm seems to acquire lock to the working dir. - // Instead, create a temporary inner and move it out. - const coreDir = path.dirname(require.resolve("@swc/core")); - const installDir = path.join(coreDir, "npm-install"); - try { - fs.mkdirSync(installDir); - fs.writeFileSync(path.join(installDir, "package.json"), "{}"); - // Instead of carrying over own dependencies to download & resolve package which increases installation sizes of `@swc/core`, - // assume & relies on system's npm installation. - child_process.execSync(`npm install --no-save --loglevel=error --prefer-offline --no-audit --progress=false @swc/wasm@${version}`, { cwd: installDir, stdio: "pipe", env }); - const installedBinPath = path.join(installDir, "node_modules", `@swc/wasm`); - // INIT_CWD is injected via npm. If it doesn't exists, can't proceed. - fs.renameSync(installedBinPath, path.resolve(process.env.INIT_CWD, "node_modules", `@swc/wasm`)); - } - catch (error) { - console.error(error); - console.error(`Failed to install fallback @swc/wasm@${version}. @swc/core will not properly. -Please install @swc/wasm manually, or retry whole installation. -If there are unexpected errors, please report at https://github.com/swc-project/swc/issues`); - } - finally { try { - removeRecursive(installDir); + binding = require("./binding.js"); + triple = binding.getTargetTriple + ? binding.getTargetTriple() + : binding.parseSync("console.log()", Buffer.from(JSON.stringify({ syntax: "ecmascript" }))); + assert.ok(triple, "Failed to read target triple from native binary."); } - catch (_) { - // Gracefully ignore any failures. This'll make few leftover files but it shouldn't block installation. + catch (error) { + // if error is unsupported architecture, ignore to display. + if (!((_a = error.message) === null || _a === void 0 ? void 0 : _a.includes("Unsupported architecture"))) { + console.warn(error); + } + console.warn("@swc/core was not able to resolve native bindings installation. It'll try to use @swc/wasm as fallback instead."); } - } -}); -validateBinary().catch((error) => { + if (!!binding) { + return [2 /*return*/]; + } + // User choose to override the binary installation. Skip remanining validation. + if (!!process.env["SWC_BINARY_PATH"]) { + console.warn("@swc/core could not resolve native bindings installation, but found manual override config SWC_BINARY_PATH specified. Skipping remaning validation."); + return [2 /*return*/]; + } + try { + wasmBinding = require.resolve("@swc/wasm"); + } + catch (_) { } + if (!!wasmBinding && (0, fs_1.existsSync)(wasmBinding)) { + return [2 /*return*/]; + } + env = __assign(__assign({}, process.env), { npm_config_global: undefined }); + version = require(path.join(path.dirname(require.resolve("@swc/core")), "package.json")).version; + coreDir = path.dirname(require.resolve("@swc/core")); + installDir = path.join(coreDir, "npm-install"); + try { + fs.mkdirSync(installDir); + fs.writeFileSync(path.join(installDir, "package.json"), "{}"); + // Instead of carrying over own dependencies to download & resolve package which increases installation sizes of `@swc/core`, + // assume & relies on system's npm installation. + child_process.execSync("npm install --no-save --loglevel=error --prefer-offline --no-audit --progress=false @swc/wasm@".concat(version), { cwd: installDir, stdio: "pipe", env: env }); + installedBinPath = path.join(installDir, "node_modules", "@swc/wasm"); + // INIT_CWD is injected via npm. If it doesn't exists, can't proceed. + if (!process.env.INIT_CWD) { + throw new Error("INIT_CWD environment variable is not set. This is required for the fallback wasm installation to work properly."); + } + fs.renameSync(installedBinPath, path.resolve(process.env.INIT_CWD, "node_modules", "@swc/wasm")); + } + catch (error) { + console.error(error); + console.error("Failed to install fallback @swc/wasm@".concat(version, ". @swc/core will not properly.\nPlease install @swc/wasm manually, or retry whole installation.\nIf there are unexpected errors, please report at https://github.com/swc-project/swc/issues")); + } + finally { + try { + removeRecursive(installDir); + } + catch (_) { + // Gracefully ignore any failures. This'll make few leftover files but it shouldn't block installation. + } + } + return [2 /*return*/]; + }); +}); }; +validateBinary().catch(function (error) { // for now just throw the error as-is. throw error; }); diff --git a/packages/core/src/postinstall.ts b/packages/core/src/postinstall.ts index cb6e0d53ef9b..ac5cec43f07b 100644 --- a/packages/core/src/postinstall.ts +++ b/packages/core/src/postinstall.ts @@ -30,8 +30,13 @@ function removeRecursive(dir: string): void { */ const validateBinary = async () => { try { + if (!process.env.INIT_CWD) { + // If INIT_CWD is not set, we can't determine the package name, so skip the check + // This can happen with some package managers or in certain environments + return; + } const { name } = require(path.resolve( - process.env.INIT_CWD!, + process.env.INIT_CWD, "package.json" )); if (name === "@swc/core" || name === "@swc/workspace") { @@ -118,9 +123,12 @@ const validateBinary = async () => { `@swc/wasm` ); // INIT_CWD is injected via npm. If it doesn't exists, can't proceed. + if (!process.env.INIT_CWD) { + throw new Error("INIT_CWD environment variable is not set. This is required for the fallback wasm installation to work properly."); + } fs.renameSync( installedBinPath, - path.resolve(process.env.INIT_CWD!, "node_modules", `@swc/wasm`) + path.resolve(process.env.INIT_CWD, "node_modules", `@swc/wasm`) ); } catch (error) { console.error(error);