Skip to content

Commit

Permalink
fix: lasso deps in hydrate output (#2368)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Nov 19, 2024
1 parent 01a571b commit bb44af0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/soft-donuts-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@marko/translator-default": patch
"@marko/compiler": patch
"marko": patch
---

Fix issue with "package: " deps (used for lasso) not being hoisted when building the hydrate output.
29 changes: 23 additions & 6 deletions packages/translator-default/src/util/add-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ export default (entryFile, isHydrate) => {
const programNode = program.node;

if (!isHydrate) {
const imports = new Set();
const body = [];
addBrowserImports(imports, body, entryFile, entryFile);
addBrowserImports(new Set(), undefined, body, entryFile, entryFile);
if (body.length) {
programNode.body = body.concat(programNode.body);
}
Expand Down Expand Up @@ -54,6 +53,10 @@ export const entryBuilder = {
const entryMarkoMeta = entryFile.metadata.marko;
const { body } = state;
entryMarkoMeta.watchFiles = Array.from(state.watchFiles);
entryMarkoMeta.deps = Array.from(
state.lassoDeps,
(dep) => `package: ${dep}`,
);

if (state.hasComponents) {
const initId = t.identifier("init");
Expand Down Expand Up @@ -92,12 +95,13 @@ export const entryBuilder = {
shouldIncludeImport: toTestFn(file.markoOpts.hydrateIncludeImports),
watchFiles: new Set(),
imports: new Set(),
lassoDeps: new Set(),
hasComponents: false,
splitComponentIndex: 0,
body: [],
});

const { watchFiles, imports, body } = state;
const { watchFiles, imports, lassoDeps, body } = state;

if (fileMeta.component) {
state.hasComponents = true;
Expand All @@ -115,7 +119,7 @@ export const entryBuilder = {
watchFiles.add(watchFile);
}

addBrowserImports(imports, body, file, entryFile);
addBrowserImports(imports, lassoDeps, body, file, entryFile);

for (const child of file.path.node.body) {
if (t.isImportDeclaration(child)) {
Expand Down Expand Up @@ -167,7 +171,7 @@ export const entryBuilder = {
},
};

function addBrowserImports(seenImports, body, file, entryFile) {
function addBrowserImports(seenImports, lassoDeps, body, file, entryFile) {
const { filename, sourceMaps } = file.opts;
let s;

Expand Down Expand Up @@ -204,7 +208,12 @@ function addBrowserImports(seenImports, body, file, entryFile) {
if (!dep) {
continue;
}
} else if (dep.startsWith("package:")) {
} else if (isLassoDep(dep)) {
if (lassoDeps) {
lassoDeps.add(
resolveRelativeToEntry(entryFile, file, lassoManifestDepToPath(dep)),
);
}
continue;
}

Expand Down Expand Up @@ -294,3 +303,11 @@ function toTestFn(val) {

return val.test.bind(val);
}

function isLassoDep(dep) {
return dep.startsWith("package: ");
}

function lassoManifestDepToPath(dep) {
return dep.slice(9);
}

0 comments on commit bb44af0

Please sign in to comment.