Skip to content

Commit

Permalink
fix: use rollup wasm version when rollup fails to load
Browse files Browse the repository at this point in the history
In some cases the native rollup binary are not available which will cause rollup to exit with errors like `Cannot find module @rollup/rollup-linux-x64-gnu`

Closes #2722
  • Loading branch information
alan-agius4 committed Nov 20, 2023
1 parent 335d3ef commit 1ed0dc9
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 69 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"dependencies": {
"@rollup/plugin-json": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/wasm-node": "^4.5.0",
"ajv": "^8.12.0",
"ansi-colors": "^4.1.3",
"autoprefixer": "^10.4.16",
Expand All @@ -53,12 +54,12 @@
"piscina": "^4.1.0",
"postcss": "^8.4.31",
"postcss-url": "^10.1.3",
"rollup": "^4.2.0",
"rxjs": "^7.8.1",
"sass": "^1.69.5"
},
"optionalDependencies": {
"esbuild": "^0.19.0"
"esbuild": "^0.19.0",
"rollup": "^4.5.0"
},
"peerDependencies": {
"@angular/compiler-cli": "^17.0.0 || ^17.1.0-next.0",
Expand Down
24 changes: 21 additions & 3 deletions src/lib/flatten/rollup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import rollupJson from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import * as path from 'path';
import * as rollup from 'rollup';
import type { OutputAsset, OutputChunk, RollupCache } from 'rollup';
import { OutputFileCache } from '../ng-package/nodes';
import { readCacheEntry, saveCacheEntry } from '../utils/cache';
import * as log from '../utils/log';
Expand All @@ -18,16 +18,20 @@ export interface RollupOptions {
entryName: string;
dir: string;
sourceRoot: string;
cache?: rollup.RollupCache;
cache?: RollupCache;
cacheDirectory?: string | false;
fileCache: OutputFileCache;
cacheKey: string;
}

let rollup: typeof import('rollup') | undefined;

/** Runs rollup over the given entry file, writes a bundle file. */
export async function rollupBundleFile(
opts: RollupOptions,
): Promise<{ cache: rollup.RollupCache; files: (rollup.OutputChunk | rollup.OutputAsset)[] }> {
): Promise<{ cache: RollupCache; files: (OutputChunk | OutputAsset)[] }> {
await ensureRollup();

log.debug(`rollup (v${rollup.VERSION}) ${opts.entry} to ${opts.dir}`);

const cacheDirectory = opts.cacheDirectory;
Expand Down Expand Up @@ -82,6 +86,20 @@ export async function rollupBundleFile(
};
}

async function ensureRollup(): Promise<void> {
if (rollup) {
return;
}

try {
rollup = await import('rollup');
log.debug(`rollup using native version.`);
} catch {
rollup = await import('@rollup/wasm-node');
log.debug(`rollup using wasm version.`);
}
}

function isExternalDependency(moduleId: string): boolean {
// more information about why we don't check for 'node_modules' path
// https://github.com/rollup/rollup-plugin-node-resolve/issues/110#issuecomment-350353632
Expand Down
135 changes: 71 additions & 64 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1575,65 +1575,72 @@
estree-walker "^2.0.2"
picomatch "^2.3.1"

"@rollup/rollup-android-arm-eabi@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.2.0.tgz#b945a7044afce5de03d03a55aef3503a50d92586"
integrity sha512-8PlggAxGxavr+pkCNeV1TM2wTb2o+cUWDg9M1cm9nR27Dsn287uZtSLYXoQqQcmq+sYfF7lHfd3sWJJinH9GmA==
"@rollup/rollup-android-arm-eabi@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.5.0.tgz#5984f98288150a2c34928de023bbd122d61ce754"
integrity sha512-OINaBGY+Wc++U0rdr7BLuFClxcoWaVW3vQYqmQq6B3bqQ/2olkaoz+K8+af/Mmka/C2yN5j+L9scBkv4BtKsDA==

"@rollup/rollup-android-arm64@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.2.0.tgz#416abdc076810cde6f84f05b0fc9decd2d7c319f"
integrity sha512-+71T85hbMFrJI+zKQULNmSYBeIhru55PYoF/u75MyeN2FcxE4HSPw20319b+FcZ4lWx2Nx/Ql9tN+hoaD3GH/A==
"@rollup/rollup-android-arm64@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.5.0.tgz#8456a8c623cca4042ae4bf2ce03d875a02433191"
integrity sha512-UdMf1pOQc4ZmUA/NTmKhgJTBimbSKnhPS2zJqucqFyBRFPnPDtwA8MzrGNTjDeQbIAWfpJVAlxejw+/lQyBK/w==

"@rollup/rollup-darwin-arm64@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.2.0.tgz#4c468e8fce7ffa121c8b2067d5f3feb1bbeefec6"
integrity sha512-IIIQLuG43QIElT1JZqUP/zqIdiJl4t9U/boa0GZnQTw9m1X0k3mlBuysbgYXeloLT1RozdL7bgw4lpSaI8GOXw==
"@rollup/rollup-darwin-arm64@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.5.0.tgz#76be6832eee21dabc28f84f9f54fbfcc66615992"
integrity sha512-L0/CA5p/idVKI+c9PcAPGorH6CwXn6+J0Ys7Gg1axCbTPgI8MeMlhA6fLM9fK+ssFhqogMHFC8HDvZuetOii7w==

"@rollup/rollup-darwin-x64@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.2.0.tgz#3e8dee93e01f60f380a8d3828acf6eb07c356b1b"
integrity sha512-BXcXvnLaea1Xz900omrGJhxHFJfH9jZ0CpJuVsbjjhpniJ6qiLXz3xA8Lekaa4MuhFcJd4f0r+Ky1G4VFbYhWw==
"@rollup/rollup-darwin-x64@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.5.0.tgz#66bd162a3fea48cb1cef50cedccfbeee5685b444"
integrity sha512-QZCbVqU26mNlLn8zi/XDDquNmvcr4ON5FYAHQQsyhrHx8q+sQi/6xduoznYXwk/KmKIXG5dLfR0CvY+NAWpFYQ==

"@rollup/rollup-linux-arm-gnueabihf@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.2.0.tgz#d4913e0d66ca9ae10863c2b81300bd0c79386390"
integrity sha512-f4K3MKw9Y4AKi4ANGnmPIglr+S+8tO858YrGVuqAHXxJdVghBmz9CPU9kDpOnGvT4g4vg5uNyIFpOOFvffXyMA==
"@rollup/rollup-linux-arm-gnueabihf@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.5.0.tgz#a0e6b2a1d67a4ba0c2a61985175f65c05abc5f73"
integrity sha512-VpSQ+xm93AeV33QbYslgf44wc5eJGYfYitlQzAi3OObu9iwrGXEnmu5S3ilkqE3Pr/FkgOiJKV/2p0ewf4Hrtg==

"@rollup/rollup-linux-arm64-gnu@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.2.0.tgz#811ec171fcf75dfcab59b1a04502c62c8410235e"
integrity sha512-bNsTYQBgp4H7w6cT7FZhesxpcUPahsSIy4NgdZjH1ZwEoZHxi4XKglj+CsSEkhsKi+x6toVvMylhjRKhEMYfnA==
"@rollup/rollup-linux-arm64-gnu@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.5.0.tgz#5434b844a47ba4e35602ee312de9f39b38b1777b"
integrity sha512-OrEyIfpxSsMal44JpEVx9AEcGpdBQG1ZuWISAanaQTSMeStBW+oHWwOkoqR54bw3x8heP8gBOyoJiGg+fLY8qQ==

"@rollup/rollup-linux-arm64-musl@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.2.0.tgz#9291c7ec1a3572e9d3f395bcfff388ff173626ca"
integrity sha512-Jp1NxBJpGLuxRU2ihrQk4IZ+ia5nffobG6sOFUPW5PMYkF0kQtxEbeDuCa69Xif211vUOcxlOnf5IOEIpTEySA==
"@rollup/rollup-linux-arm64-musl@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.5.0.tgz#149cab95107821fe4ae46d5f2c0658c5b0e56b9c"
integrity sha512-1H7wBbQuE6igQdxMSTjtFfD+DGAudcYWhp106z/9zBA8OQhsJRnemO4XGavdzHpGhRtRxbgmUGdO3YQgrWf2RA==

"@rollup/rollup-linux-x64-gnu@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.2.0.tgz#30fb4756ebf5c7e059a12bdf42d900c38041e04d"
integrity sha512-3p3iRtQmv2aXw+vtKNyZMLOQ+LSRsqArXjKAh2Oj9cqwfIRe7OXvdkOzWfZOIp1F/x5KJzVAxGxnniF4cMbnsQ==
"@rollup/rollup-linux-x64-gnu@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.5.0.tgz#6929bf3013e9d599605953ea1bc51f35376bfff7"
integrity sha512-FVyFI13tXw5aE65sZdBpNjPVIi4Q5mARnL/39UIkxvSgRAIqCo5sCpCELk0JtXHGee2owZz5aNLbWNfBHzr71Q==

"@rollup/rollup-linux-x64-musl@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.2.0.tgz#e5d4f4529142ba7873071d4661d37eb50e211a45"
integrity sha512-atih7IF/reUZe4LBLC5Izd44hth2tfDIG8LaPp4/cQXdHh9jabcZEvIeRPrpDq0i/Uu487Qu5gl5KwyAnWajnw==
"@rollup/rollup-linux-x64-musl@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.5.0.tgz#a17f5decabf05b74aad684de56cf43a72a289a0b"
integrity sha512-eBPYl2sLpH/o8qbSz6vPwWlDyThnQjJfcDOGFbNjmjb44XKC1F5dQfakOsADRVrXCNzM6ZsSIPDG5dc6HHLNFg==

"@rollup/rollup-win32-arm64-msvc@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.2.0.tgz#0047005faab99cdea50b594f76388ed09ed44650"
integrity sha512-vYxF3tKJeUE4ceYzpNe2p84RXk/fGK30I8frpRfv/MyPStej/mRlojztkN7Jtd1014HHVeq/tYaMBz/3IxkxZw==
"@rollup/rollup-win32-arm64-msvc@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.5.0.tgz#f145f10c33aa187a11fd60933465be46667e6e42"
integrity sha512-xaOHIfLOZypoQ5U2I6rEaugS4IYtTgP030xzvrBf5js7p9WI9wik07iHmsKaej8Z83ZDxN5GyypfoyKV5O5TJA==

"@rollup/rollup-win32-ia32-msvc@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.2.0.tgz#da08f1d2b0a6c58ca59aea026c2ffc5592ee8194"
integrity sha512-1LZJ6zpl93SaPQvas618bMFarVwufWTaczH4ESAbFcwiC4OtznA6Ym+hFPyIGaJaGEB8uMWWac0uXGPXOg5FGA==
"@rollup/rollup-win32-ia32-msvc@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.5.0.tgz#798614b191f9ce1dc58079d1dfbc234c71df9e0e"
integrity sha512-Al6quztQUrHwcOoU2TuFblUQ5L+/AmPBXFR6dUvyo4nRj2yQRK0WIUaGMF/uwKulvRcXkpHe3k9A8Vf93VDktA==

"@rollup/rollup-win32-x64-msvc@4.2.0":
version "4.2.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.2.0.tgz#c01c43de5a3e786b603b37555961870fa5db2e1c"
integrity sha512-dgQfFdHCNg08nM5zBmqxqc9vrm0DVzhWotpavbPa0j4//MAOKZEB75yGAfzQE9fUJ+4pvM1239Y4IhL8f6sSog==
"@rollup/rollup-win32-x64-msvc@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.5.0.tgz#748970e066839e33ed8c935061e370c4ab050517"
integrity sha512-8kdW+brNhI/NzJ4fxDufuJUjepzINqJKLGHuxyAtpPG9bMbn8P5mtaCcbOm0EzLJ+atg+kF9dwg8jpclkVqx5w==

"@rollup/wasm-node@^4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@rollup/wasm-node/-/wasm-node-4.5.0.tgz#e36a3d0ce2d272fa4077956cb066727981133e08"
integrity sha512-4+yhud+39o9SwwR7SjhHL0mtZtRTFZfPAKEZD2oWzgfCV3yeZlRq3jpLjCM0aoavDyoPF+YfMRqBOIrz2Mvxmg==
optionalDependencies:
fsevents "~2.3.2"

"@tsconfig/node10@^1.0.7":
version "1.0.9"
Expand Down Expand Up @@ -5268,23 +5275,23 @@ rimraf@^5.0.0:
dependencies:
glob "^10.0.0"

rollup@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-4.2.0.tgz#c726e4004ebf1c7f74dc7b7d51d3a34db84e4f95"
integrity sha512-deaMa9Z+jPVeBD2dKXv+h7EbdKte9++V2potc/ADqvVgEr6DEJ3ia9u0joarjC2lX/ubaCRYz3QVx0TzuVqAJA==
rollup@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-4.5.0.tgz#358ee6947fe0e4c8bacdae6896539cade3107655"
integrity sha512-41xsWhzxqjMDASCxH5ibw1mXk+3c4TNI2UjKbLxe6iEzrSQnqOzmmK8/3mufCPbzHNJ2e04Fc1ddI35hHy+8zg==
optionalDependencies:
"@rollup/rollup-android-arm-eabi" "4.2.0"
"@rollup/rollup-android-arm64" "4.2.0"
"@rollup/rollup-darwin-arm64" "4.2.0"
"@rollup/rollup-darwin-x64" "4.2.0"
"@rollup/rollup-linux-arm-gnueabihf" "4.2.0"
"@rollup/rollup-linux-arm64-gnu" "4.2.0"
"@rollup/rollup-linux-arm64-musl" "4.2.0"
"@rollup/rollup-linux-x64-gnu" "4.2.0"
"@rollup/rollup-linux-x64-musl" "4.2.0"
"@rollup/rollup-win32-arm64-msvc" "4.2.0"
"@rollup/rollup-win32-ia32-msvc" "4.2.0"
"@rollup/rollup-win32-x64-msvc" "4.2.0"
"@rollup/rollup-android-arm-eabi" "4.5.0"
"@rollup/rollup-android-arm64" "4.5.0"
"@rollup/rollup-darwin-arm64" "4.5.0"
"@rollup/rollup-darwin-x64" "4.5.0"
"@rollup/rollup-linux-arm-gnueabihf" "4.5.0"
"@rollup/rollup-linux-arm64-gnu" "4.5.0"
"@rollup/rollup-linux-arm64-musl" "4.5.0"
"@rollup/rollup-linux-x64-gnu" "4.5.0"
"@rollup/rollup-linux-x64-musl" "4.5.0"
"@rollup/rollup-win32-arm64-msvc" "4.5.0"
"@rollup/rollup-win32-ia32-msvc" "4.5.0"
"@rollup/rollup-win32-x64-msvc" "4.5.0"
fsevents "~2.3.2"

run-parallel@^1.1.9:
Expand Down

0 comments on commit 1ed0dc9

Please sign in to comment.