From f7664e7f8e5906fa8536f6bcfc0e9fa37865c5d5 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 21 Mar 2024 19:21:33 +0100 Subject: [PATCH 1/5] fix(externals): check explicit inlines on resolved id --- package.json | 1 + pnpm-lock.yaml | 13 +++++++++++++ src/rollup/plugins/externals.ts | 29 ++++++++++++++++++++++------- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 610b8f4f82..f1207167f6 100644 --- a/package.json +++ b/package.json @@ -153,6 +153,7 @@ "get-port-please": "^3.1.2", "miniflare": "^3.20240304.2", "prettier": "^3.2.5", + "shiki": "^1.2.0", "typescript": "^5.4.2", "unbuild": "^2.0.0", "undici": "^6.9.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7e1530d5d0..a2db0a3d7d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -289,6 +289,9 @@ importers: prettier: specifier: ^3.2.5 version: 3.2.5 + shiki: + specifier: ^1.2.0 + version: 1.2.0 typescript: specifier: ^5.4.2 version: 5.4.2 @@ -2179,6 +2182,10 @@ packages: requiresBuild: true optional: true + /@shikijs/core@1.2.0: + resolution: {integrity: sha512-OlFvx+nyr5C8zpcMBnSGir0YPD6K11uYhouqhNmm1qLiis4GA7SsGtu07r9gKS9omks8RtQqHrJL4S+lqWK01A==} + dev: true + /@sideway/address@4.1.5: resolution: {integrity: sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==} dependencies: @@ -8226,6 +8233,12 @@ packages: resolution: {integrity: sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==} dev: true + /shiki@1.2.0: + resolution: {integrity: sha512-xLhiTMOIUXCv5DqJ4I70GgQCtdlzsTqFLZWcMHHG3TAieBUbvEGthdrlPDlX4mL/Wszx9C6rEcxU6kMlg4YlxA==} + dependencies: + '@shikijs/core': 1.2.0 + dev: true + /side-channel@1.0.6: resolution: {integrity: sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==} engines: {node: '>= 0.4'} diff --git a/src/rollup/plugins/externals.ts b/src/rollup/plugins/externals.ts index 6e17b3cb7a..18ae74da31 100644 --- a/src/rollup/plugins/externals.ts +++ b/src/rollup/plugins/externals.ts @@ -61,6 +61,19 @@ export function externals(opts: NodeExternalsOptions): Plugin { .map((p) => normalizeMatcher(p)) .sort((a, b) => b.score - a.score); + // Utility to check explicit inlines + const isExplicitInline = (id: string, importer: string) => { + const inlineMatch = inlineMatchers.find((m) => m(id, importer)); + const externalMatch = externalMatchers.find((m) => m(id, importer)); + if ( + inlineMatch && + (!externalMatch || + (externalMatch && inlineMatch.score > externalMatch.score)) + ) { + return true; + } + }; + return { name: "node-externals", async resolveId(originalId, importer, options) { @@ -83,13 +96,7 @@ export function externals(opts: NodeExternalsOptions): Plugin { const id = normalize(originalId); // Check for explicit inlines and externals - const inlineMatch = inlineMatchers.find((m) => m(id, importer)); - const externalMatch = externalMatchers.find((m) => m(id, importer)); - if ( - inlineMatch && - (!externalMatch || - (externalMatch && inlineMatch.score > externalMatch.score)) - ) { + if (isExplicitInline(id, importer)) { return null; } @@ -98,6 +105,11 @@ export function externals(opts: NodeExternalsOptions): Plugin { id, }; + // Check for explicit inlines and externals + if (isExplicitInline(resolved.id, importer)) { + return null; + } + // Try resolving with mlly as fallback if ( !isAbsolute(resolved.id) || @@ -138,6 +150,7 @@ export function externals(opts: NodeExternalsOptions): Plugin { if (!isAbsolute(originalId)) { const fullPath = await _resolve(originalId); trackedExternals.add(fullPath); + console.log("[externals]", id); return { id: originalId, external: true, @@ -157,6 +170,7 @@ export function externals(opts: NodeExternalsOptions): Plugin { (await _resolve(join(pkgName, guessedSubpath)).catch(() => null)); if (resolvedGuess === originalId) { trackedExternals.add(resolvedGuess); + console.log("[externals]", join(pkgName, guessedSubpath)); return { id: join(pkgName, guessedSubpath), external: true, @@ -167,6 +181,7 @@ export function externals(opts: NodeExternalsOptions): Plugin { } } + console.log("[externals]", pkgName); trackedExternals.add(resolved.id); return { id: pkgName, From bb96852ce31aa75b702f6a158b924fdf97637b42 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 21 Mar 2024 19:24:54 +0100 Subject: [PATCH 2/5] revert dep change --- package.json | 3 +-- pnpm-lock.yaml | 13 ------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/package.json b/package.json index f1207167f6..165424d454 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,6 @@ "get-port-please": "^3.1.2", "miniflare": "^3.20240304.2", "prettier": "^3.2.5", - "shiki": "^1.2.0", "typescript": "^5.4.2", "unbuild": "^2.0.0", "undici": "^6.9.0", @@ -182,4 +181,4 @@ ] } } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a2db0a3d7d..7e1530d5d0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -289,9 +289,6 @@ importers: prettier: specifier: ^3.2.5 version: 3.2.5 - shiki: - specifier: ^1.2.0 - version: 1.2.0 typescript: specifier: ^5.4.2 version: 5.4.2 @@ -2182,10 +2179,6 @@ packages: requiresBuild: true optional: true - /@shikijs/core@1.2.0: - resolution: {integrity: sha512-OlFvx+nyr5C8zpcMBnSGir0YPD6K11uYhouqhNmm1qLiis4GA7SsGtu07r9gKS9omks8RtQqHrJL4S+lqWK01A==} - dev: true - /@sideway/address@4.1.5: resolution: {integrity: sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==} dependencies: @@ -8233,12 +8226,6 @@ packages: resolution: {integrity: sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==} dev: true - /shiki@1.2.0: - resolution: {integrity: sha512-xLhiTMOIUXCv5DqJ4I70GgQCtdlzsTqFLZWcMHHG3TAieBUbvEGthdrlPDlX4mL/Wszx9C6rEcxU6kMlg4YlxA==} - dependencies: - '@shikijs/core': 1.2.0 - dev: true - /side-channel@1.0.6: resolution: {integrity: sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==} engines: {node: '>= 0.4'} From 79da14f970b949087cbc0662e8a240adb88ae032 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 21 Mar 2024 19:25:43 +0100 Subject: [PATCH 3/5] remove logs --- src/rollup/plugins/externals.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/rollup/plugins/externals.ts b/src/rollup/plugins/externals.ts index 18ae74da31..fb1fe869fc 100644 --- a/src/rollup/plugins/externals.ts +++ b/src/rollup/plugins/externals.ts @@ -150,7 +150,6 @@ export function externals(opts: NodeExternalsOptions): Plugin { if (!isAbsolute(originalId)) { const fullPath = await _resolve(originalId); trackedExternals.add(fullPath); - console.log("[externals]", id); return { id: originalId, external: true, @@ -170,7 +169,6 @@ export function externals(opts: NodeExternalsOptions): Plugin { (await _resolve(join(pkgName, guessedSubpath)).catch(() => null)); if (resolvedGuess === originalId) { trackedExternals.add(resolvedGuess); - console.log("[externals]", join(pkgName, guessedSubpath)); return { id: join(pkgName, guessedSubpath), external: true, @@ -181,7 +179,6 @@ export function externals(opts: NodeExternalsOptions): Plugin { } } - console.log("[externals]", pkgName); trackedExternals.add(resolved.id); return { id: pkgName, From 4e02f6090a87c3213b51bc039cbd61eabd4cd374 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 21 Mar 2024 19:26:20 +0100 Subject: [PATCH 4/5] revert newline --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 165424d454..f1207167f6 100644 --- a/package.json +++ b/package.json @@ -153,6 +153,7 @@ "get-port-please": "^3.1.2", "miniflare": "^3.20240304.2", "prettier": "^3.2.5", + "shiki": "^1.2.0", "typescript": "^5.4.2", "unbuild": "^2.0.0", "undici": "^6.9.0", @@ -181,4 +182,4 @@ ] } } -} +} \ No newline at end of file From 49259d5ef6e301d976a3ced4fbc0df4a82600c7d Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 21 Mar 2024 19:27:01 +0100 Subject: [PATCH 5/5] revert package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index f1207167f6..610b8f4f82 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,6 @@ "get-port-please": "^3.1.2", "miniflare": "^3.20240304.2", "prettier": "^3.2.5", - "shiki": "^1.2.0", "typescript": "^5.4.2", "unbuild": "^2.0.0", "undici": "^6.9.0",