Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Sep 10, 2024
1 parent b76a1e0 commit a40e0d8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
10 changes: 10 additions & 0 deletions packages/vite/src/esbuild-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/tests/optimize-deps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand Down
13 changes: 8 additions & 5 deletions test-packages/support/audit-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand All @@ -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<this> {
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({
Expand All @@ -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) {
Expand Down Expand Up @@ -344,7 +345,9 @@ class EmptyExpectModule implements PublicAPI<ExpectModule> {
doesNotExist() {}
codeEquals() {}
codeContains() {}
withContents() {}
withContents() {
return this;
}

resolves(): PublicAPI<ExpectResolution> {
return new EmptyExpectResolution() as PublicAPI<ExpectResolution>;
Expand Down
1 change: 0 additions & 1 deletion test-packages/support/rebuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export class Rebuilder {
}

private captureStream(data: string) {
console.log(data.toString());
this.combinedBuffer.push(data);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/scenarios/vite-dep-optimizer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down

0 comments on commit a40e0d8

Please sign in to comment.