Skip to content

Commit

Permalink
chore: expose compiler metadata about which templates were analyzed
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Nov 14, 2023
1 parent 79446a7 commit 15ada15
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .changeset/lovely-seahorses-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@marko/babel-utils": patch
"@marko/compiler": patch
"marko": patch
"@marko/translator-default": patch
---

Expose meta data about which child Marko templates were analyzed for a given compilation.
16 changes: 16 additions & 0 deletions packages/babel-utils/src/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ export function loadFileForTag(tag) {
const filename = def && def.template;

if (filename) {
const markoMeta = file.metadata.marko;
const { analyzedTags } = markoMeta;
if (analyzedTags) {
analyzedTags.push(filename);
} else {
markoMeta.analyzedTags = [filename];
}

return file.___getMarkoFile(
fs.readFileSync(filename).toString("utf-8"),
createNewFileOpts(file.opts, filename),
Expand All @@ -253,6 +261,14 @@ export function loadFileForImport(file, request) {
relativeRequest[0] === "."
? resolve(file.opts.filename, "..", relativeRequest)
: resolveFrom(dirname(file.opts.filename), relativeRequest);
const markoMeta = file.metadata.marko;
const { analyzedTags } = markoMeta;
if (analyzedTags) {
analyzedTags.push(filename);
} else {
markoMeta.analyzedTags = [filename];
}

return file.___getMarkoFile(
fs.readFileSync(filename).toString("utf-8"),
createNewFileOpts(file.opts, filename),
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface MarkoMeta {
watchFiles: string[];
tags?: string[];
deps: Array<string | Dep | VirtualDep>;
analyzedTags?: [string, ...string[]];
diagnostics: Diagnostic[];
}

Expand Down
3 changes: 3 additions & 0 deletions packages/compiler/src/babel-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,7 @@ function isMarkoOutput(output) {

function finalizeMeta(meta) {
meta.watchFiles = [...new Set(meta.watchFiles)];
if (meta.analyzedTags) {
meta.analyzedTags = [...new Set(meta.analyzedTags)];
}
}

0 comments on commit 15ada15

Please sign in to comment.