From 6f505317ef598df0ff92c18f7e100aaa89ca242a Mon Sep 17 00:00:00 2001 From: patrickpircher Date: Fri, 13 Sep 2024 13:27:41 +0200 Subject: [PATCH 1/5] fail test --- tests/scenarios/vite-internals-test.ts | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/scenarios/vite-internals-test.ts b/tests/scenarios/vite-internals-test.ts index 60cb58542..365ab23d7 100644 --- a/tests/scenarios/vite-internals-test.ts +++ b/tests/scenarios/vite-internals-test.ts @@ -76,6 +76,12 @@ appScenarios `, 'epsilon.hbs': `
Epsilon
`, 'fancy-button.hbs': `

I'm fancy

`, + 'delta.js': ` + import Component from '@glimmer/component'; + export default class extends Component { + message = "delta"; + } + `, }, templates: { 'application.hbs': ` @@ -90,11 +96,17 @@ appScenarios lib: { 'app-lib-one.js': ` globalThis.appLibOneLoaded = (globalThis.appLibOneLoaded ?? 0) + 1; - export default function() { return 'app-lib-one'; } + const localObject = { + message: 'app-lib-one' + }; + export default function() { return localObject; } `, 'app-lib-two.js': ` globalThis.appLibTwoLoaded = (globalThis.appLibTwoLoaded ?? 0) + 1; - export default function() { return 'app-lib-two'; } + const localObject = { + message: 'app-lib-two' + }; + export default function() { return localObject; } `, }, }, @@ -136,6 +148,11 @@ appScenarios assert.dom('.epsilon').hasText('Epsilon'); }); + test("paired component between app and addon", async function (assert) { + await render(hbs\`\`); + 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'); @@ -179,6 +196,13 @@ appScenarios import appLibTwo from 'app-template/lib/app-lib-two'; export { appLibOne, appLibTwo }; `, + templates: { + components: { + 'delta.hbs': ` +
delta
+ `, + }, + }, components: { 'beta.js': ` export { default } from 'v1-example-addon/components/beta'; From 0cbfaf9457a823252c8c077e895b0278d96432e4 Mon Sep 17 00:00:00 2001 From: patrick Date: Mon, 16 Sep 2024 10:04:05 +0200 Subject: [PATCH 2/5] fix --- packages/vite/src/esbuild-resolver.ts | 3 +++ tests/scenarios/vite-internals-test.ts | 10 ++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/vite/src/esbuild-resolver.ts b/packages/vite/src/esbuild-resolver.ts index c712e2099..420275534 100644 --- a/packages/vite/src/esbuild-resolver.ts +++ b/packages/vite/src/esbuild-resolver.ts @@ -157,6 +157,9 @@ function detectPhase(build: PluginBuild): 'bundling' | 'scanning' { return 'bundling'; } else if (plugins.includes('vite:dep-scan')) { return 'scanning'; + } else if (plugins.includes('embroider-esbuild-resolver') && plugins.length === 1) { + // export scanning + return 'scanning'; } else { throw new Error(`cannot identify what phase vite is in. Saw plugins: ${plugins.join(', ')}`); } diff --git a/tests/scenarios/vite-internals-test.ts b/tests/scenarios/vite-internals-test.ts index 365ab23d7..765e1ab9b 100644 --- a/tests/scenarios/vite-internals-test.ts +++ b/tests/scenarios/vite-internals-test.ts @@ -96,17 +96,11 @@ appScenarios lib: { 'app-lib-one.js': ` globalThis.appLibOneLoaded = (globalThis.appLibOneLoaded ?? 0) + 1; - const localObject = { - message: 'app-lib-one' - }; - export default function() { return localObject; } + export default function() { return 'app-lib-one'; } `, 'app-lib-two.js': ` globalThis.appLibTwoLoaded = (globalThis.appLibTwoLoaded ?? 0) + 1; - const localObject = { - message: 'app-lib-two' - }; - export default function() { return localObject; } + export default function() { return 'app-lib-two'; } `, }, }, From 7b5b773af41f654527f454ebd1bd5ac1b5da1714 Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Fri, 20 Sep 2024 10:21:49 +0200 Subject: [PATCH 3/5] no length check --- packages/vite/src/esbuild-resolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/esbuild-resolver.ts b/packages/vite/src/esbuild-resolver.ts index 420275534..fd29d4429 100644 --- a/packages/vite/src/esbuild-resolver.ts +++ b/packages/vite/src/esbuild-resolver.ts @@ -157,7 +157,7 @@ function detectPhase(build: PluginBuild): 'bundling' | 'scanning' { return 'bundling'; } else if (plugins.includes('vite:dep-scan')) { return 'scanning'; - } else if (plugins.includes('embroider-esbuild-resolver') && plugins.length === 1) { + } else if (plugins.includes('embroider-esbuild-resolver')) { // export scanning return 'scanning'; } else { From 2c1067abffdd042b54c708967a4c4c103285cf2f Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 24 Sep 2024 09:48:26 -0400 Subject: [PATCH 4/5] reducing phase detection to "bundling" vs "other" --- packages/vite/src/esbuild-request.ts | 4 ++-- packages/vite/src/esbuild-resolver.ts | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/vite/src/esbuild-request.ts b/packages/vite/src/esbuild-request.ts index 59d63a05a..d05f5c70f 100644 --- a/packages/vite/src/esbuild-request.ts +++ b/packages/vite/src/esbuild-request.ts @@ -11,7 +11,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, @@ -41,7 +41,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, diff --git a/packages/vite/src/esbuild-resolver.ts b/packages/vite/src/esbuild-resolver.ts index fd29d4429..8eab80820 100644 --- a/packages/vite/src/esbuild-resolver.ts +++ b/packages/vite/src/esbuild-resolver.ts @@ -151,17 +151,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 if (plugins.includes('embroider-esbuild-resolver')) { - // export scanning - return 'scanning'; } else { - throw new Error(`cannot identify what phase vite is in. Saw plugins: ${plugins.join(', ')}`); + throw 'other'; } } From 265500885d814744d1961fd6b70bee132bb5353e Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 24 Sep 2024 12:17:40 -0400 Subject: [PATCH 5/5] Fix typo (return vs throw) --- packages/vite/src/esbuild-resolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/esbuild-resolver.ts b/packages/vite/src/esbuild-resolver.ts index 8eab80820..c00d99d4f 100644 --- a/packages/vite/src/esbuild-resolver.ts +++ b/packages/vite/src/esbuild-resolver.ts @@ -156,7 +156,7 @@ function detectPhase(build: PluginBuild): 'bundling' | 'other' { if (plugins.includes('vite:dep-pre-bundle')) { return 'bundling'; } else { - throw 'other'; + return 'other'; } }