Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vite: do not optimize dynamic addons #1850

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/compat/src/v1-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,12 @@ export default class V1Addon {
);
}

hasCustomizedTree(): boolean {
return this.customizes(...dynamicTreeHooks);
}

hasAnyTrees(): boolean {
return Boolean(stockTreeNames.find(name => this.hasStockTree(name))) || this.customizes(...dynamicTreeHooks);
return Boolean(stockTreeNames.find(name => this.hasStockTree(name))) || this.hasCustomizedTree();
}

// we keep all these here to ensure that we always apply the same options to
Expand Down Expand Up @@ -557,6 +561,7 @@ export default class V1Addon {
version: 2,
'auto-upgraded': true,
type: 'addon',
'is-dynamic': this.hasCustomizedTree(),
},
built.staticMeta,
...built.dynamicMeta.map(d => d())
Expand Down
1 change: 1 addition & 0 deletions packages/shared-internals/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface AddonMeta {
main?: string;
'order-index'?: number;
'lazy-engine'?: boolean;
'is-dynamic'?: boolean;

'auto-upgraded'?: true;
'app-js'?: { [appName: string]: Filename };
Expand Down
23 changes: 21 additions & 2 deletions packages/vite/src/optimize-deps.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
import { esBuildResolver } from './esbuild-resolver';
import { ResolverLoader } from '@embroider/core';

export interface OptimizeDeps {
exclude?: string[];
[key: string]: unknown;
}

export function optimizeDeps(): OptimizeDeps {
return {
exclude: ['@embroider/macros'],
let resolverLoader = new ResolverLoader(process.cwd());

const res = {
extensions: ['.hbs', '.gjs', '.gts'],
esbuildOptions: {
plugins: [esBuildResolver()],
},
};

Object.defineProperty(res, 'exclude', {
get() {
const addons: string[] = [];
for (const engine of resolverLoader.resolver.options.engines) {
for (const activeAddon of engine.activeAddons) {
const pkg = resolverLoader.resolver.packageCache.get(activeAddon.root);
if (pkg.isV2Addon() && pkg.meta['is-dynamic']) {
addons.push(pkg.name);
}
}
}
return ['@embroider/macros', ...addons];
},
});

return res;
}
3 changes: 0 additions & 3 deletions packages/vite/tests/optimize-deps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ describe('optimizeDeps', function () {
Any<Object>,
],
},
"exclude": [
"@embroider/macros",
],
"extensions": [
".hbs",
".gjs",
Expand Down
Loading