Skip to content

Commit

Permalink
Merge pull request #2110 from patricklx/fix-app-deps
Browse files Browse the repository at this point in the history
fix issue with paired component between app and addon
  • Loading branch information
ef4 authored Sep 24, 2024
2 parents db5651b + 2655008 commit f33728f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/vite/src/esbuild-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type PackageCache = PublicAPI<_PackageCache>;
export class EsBuildModuleRequest implements ModuleRequest {
static from(
packageCache: PackageCache,
phase: 'bundling' | 'scanning',
phase: 'bundling' | 'other',
context: PluginBuild,
kind: ImportKind,
source: string,
Expand Down Expand Up @@ -42,7 +42,7 @@ export class EsBuildModuleRequest implements ModuleRequest {

private constructor(
private packageCache: PackageCache,
private phase: 'bundling' | 'scanning',
private phase: 'bundling' | 'other',
private context: PluginBuild,
private kind: ImportKind,
readonly specifier: string,
Expand Down
6 changes: 2 additions & 4 deletions packages/vite/src/esbuild-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,12 @@ export function esBuildResolver(): EsBuildPlugin {
};
}

function detectPhase(build: PluginBuild): 'bundling' | 'scanning' {
function detectPhase(build: PluginBuild): 'bundling' | 'other' {
let plugins = (build.initialOptions.plugins ?? []).map(p => p.name);
if (plugins.includes('vite:dep-pre-bundle')) {
return 'bundling';
} else if (plugins.includes('vite:dep-scan')) {
return 'scanning';
} else {
throw new Error(`cannot identify what phase vite is in. Saw plugins: ${plugins.join(', ')}`);
return 'other';
}
}

Expand Down
18 changes: 18 additions & 0 deletions tests/scenarios/vite-internals-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ appScenarios
`,
'epsilon.hbs': `<div class="epsilon">Epsilon</div>`,
'fancy-button.hbs': `<h1>I'm fancy</h1>`,
'delta.js': `
import Component from '@glimmer/component';
export default class extends Component {
message = "delta";
}
`,
},
templates: {
'application.hbs': `
Expand Down Expand Up @@ -136,6 +142,11 @@ appScenarios
assert.dom('.epsilon').hasText('Epsilon');
});
test("paired component between app and addon", async function (assert) {
await render(hbs\`<Delta />\`);
assert.dom('.delta').hasText('delta');
});
test("addon depends on an app's module via relative import", async function (assert) {
assert.strictEqual(appLibOne(), libOneViaAddon(), 'lib one works the same');
assert.strictEqual(globalThis.appLibOneLoaded, 1, 'app lib one loaded once');
Expand Down Expand Up @@ -179,6 +190,13 @@ appScenarios
import appLibTwo from 'app-template/lib/app-lib-two';
export { appLibOne, appLibTwo };
`,
templates: {
components: {
'delta.hbs': `
<div class="delta">delta</div>
`,
},
},
components: {
'beta.js': `
export { default } from 'v1-example-addon/components/beta';
Expand Down

0 comments on commit f33728f

Please sign in to comment.