From a40e0d81bca524671c38ef0813d3e5a51d85d992 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 5 Sep 2024 16:59:51 +0200 Subject: [PATCH] wip --- packages/vite/src/esbuild-resolver.ts | 10 ++++++++++ packages/vite/tests/optimize-deps.test.ts | 2 +- test-packages/support/audit-assertions.ts | 13 ++++++++----- test-packages/support/rebuilder.ts | 1 - tests/scenarios/vite-dep-optimizer-test.ts | 4 ++-- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/esbuild-resolver.ts b/packages/vite/src/esbuild-resolver.ts index e3d710d4b6..1f6a2fb644 100644 --- a/packages/vite/src/esbuild-resolver.ts +++ b/packages/vite/src/esbuild-resolver.ts @@ -66,6 +66,16 @@ export function esBuildResolver(): EsBuildPlugin { switch (resolution.type) { case 'found': case 'ignored': + // _app_ files in addons are part of the app, they should not be externalized + if (resolution.result.path) { + let pkg = resolverLoader.resolver.packageCache.ownerOfFile(resolution.result.path); + if (pkg?.isV2Addon()) { + resolverLoader.resolver.reverseSearchAppTree(pkg, resolution.result.path); + if (resolution.result.path?.includes('_app_')) { + resolution.result.external = false; + } + } + } return resolution.result; case 'not_found': return resolution.err; diff --git a/packages/vite/tests/optimize-deps.test.ts b/packages/vite/tests/optimize-deps.test.ts index f32deea62c..9cd0aa2be2 100644 --- a/packages/vite/tests/optimize-deps.test.ts +++ b/packages/vite/tests/optimize-deps.test.ts @@ -2,7 +2,7 @@ import { optimizeDeps } from '../src/optimize-deps'; describe('optimizeDeps', function () { test('should produce default output when invoked without arguments', function () { - const actual = optimizeDeps(); + const actual = optimizeDeps({ appExtensions: ['.hbs'] }); expect(actual).toMatchInlineSnapshot( { diff --git a/test-packages/support/audit-assertions.ts b/test-packages/support/audit-assertions.ts index 23eb495d94..21e519cc7f 100644 --- a/test-packages/support/audit-assertions.ts +++ b/test-packages/support/audit-assertions.ts @@ -158,7 +158,7 @@ export class ExpectModule { } private emitMissingModule() { - const showNearMisses = 4; + const showNearMisses = 10; let actuals = sortBy(Object.keys(this.expectAudit.result.modules), candidate => distance(candidate, this.outputName) ); @@ -180,14 +180,14 @@ export class ExpectModule { }); } - withContents(fn: (src: string, imports: Import[]) => boolean, message?: string) { + withContents(fn: (src: string, imports: Import[]) => boolean, message?: string): PublicAPI { if (!this.module) { this.emitMissingModule(); - return; + return this; } if (this.module.type === 'unparseable') { this.emitUnparsableModule(message); - return; + return this; } const result = fn(this.module.content, this.module.imports); this.expectAudit.assert.pushResult({ @@ -196,6 +196,7 @@ export class ExpectModule { expected: true, message: message ?? `Expected passed function to return true for the contents of ${this.inputName}`, }); + return this; } private emitUnparsableModule(message?: string) { @@ -344,7 +345,9 @@ class EmptyExpectModule implements PublicAPI { doesNotExist() {} codeEquals() {} codeContains() {} - withContents() {} + withContents() { + return this; + } resolves(): PublicAPI { return new EmptyExpectResolution() as PublicAPI; diff --git a/test-packages/support/rebuilder.ts b/test-packages/support/rebuilder.ts index c215ec796b..75bb2e179a 100644 --- a/test-packages/support/rebuilder.ts +++ b/test-packages/support/rebuilder.ts @@ -58,7 +58,6 @@ export class Rebuilder { } private captureStream(data: string) { - console.log(data.toString()); this.combinedBuffer.push(data); } diff --git a/tests/scenarios/vite-dep-optimizer-test.ts b/tests/scenarios/vite-dep-optimizer-test.ts index d9573cbd7b..7956ada4ef 100644 --- a/tests/scenarios/vite-dep-optimizer-test.ts +++ b/tests/scenarios/vite-dep-optimizer-test.ts @@ -160,8 +160,8 @@ app.forEachScenario(scenario => { let pageTitleImports = imports.filter(imp => /page-title/.test(imp.source)); assert.strictEqual(pageTitleImports.length, 2, 'found two uses of page-title addon'); assert.ok( - pageTitleImports.every(isOptimizedImport), - `every page-title module is optimized but we saw ${pageTitleImports.map(i => i.source).join(', ')}` + pageTitleImports.every(x => !isOptimizedImport(x)), + `every page-title module is not optimized but we saw ${pageTitleImports.map(i => i.source).join(', ')}` ); return true; });