Skip to content

Commit

Permalink
fix(cli): embedded alpha module dependencies not hoisted. (#1170)
Browse files Browse the repository at this point in the history
Signed-off-by: David Festal <[email protected]>
  • Loading branch information
davidfestal authored Feb 5, 2024
1 parent 1d7986f commit 063b343
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
10 changes: 8 additions & 2 deletions packages/cli/src/commands/export-dynamic-plugin/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export async function backend(
if (commonPackage !== pkg.name) {
mergeWithOutput.push(commonPackage);
}
const nodePackage = pkg.name.replace(/-backend$/, '-node');
if (nodePackage !== pkg.name) {
mergeWithOutput.push(nodePackage);
}

if (opts.embedPackage !== undefined) {
for (const pkgToEmbed of opts.embedPackage as string[]) {
Expand All @@ -102,8 +106,10 @@ export async function backend(
if (relatedCommonPackage !== pkgToEmbed) {
mergeWithOutput.push(relatedCommonPackage);
}
const relatedAlphaPackage = pkgToEmbed.concat('/alpha');
mergeWithOutput.push(relatedAlphaPackage);
const relatedNodePackage = pkgToEmbed.replace(/-backend$/, '-node');
if (relatedNodePackage !== pkgToEmbed) {
mergeWithOutput.push(relatedNodePackage);
}
}
}

Expand Down
13 changes: 6 additions & 7 deletions packages/cli/src/lib/builder/embedPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ export function embedModules(options: EmbedModulesOptions): Plugin {
return;
}
for (const e of embedded) {
if (e.endsWith('/alpha')) {
continue;
}
const mod = await this.resolve(
path.join(e, 'package.json'),
undefined,
Expand Down Expand Up @@ -84,11 +81,13 @@ export function embedModules(options: EmbedModulesOptions): Plugin {
// We decorate any existing `external` option with our own way of determining
// if a module should be external.
const external: InputOptions['external'] = (id, importer, isResolved) => {
const importedId = id.replace(/\/alpha$/, '');

// The piece that we're adding
if (filter(id) && importer !== undefined) {
if (!embedded.has(id)) {
embedded.add(id);
console.log(`Embedding module ${id}`);
if (filter(importedId) && importer !== undefined) {
if (!embedded.has(importedId)) {
embedded.add(importedId);
console.log(`Embedding module ${importedId}`);
}
return false;
}
Expand Down

0 comments on commit 063b343

Please sign in to comment.