Skip to content

Commit

Permalink
fix: export metadata even if no frontmatter found
Browse files Browse the repository at this point in the history
Otherwise doing
`import.meta.glob('...', { import: 'metadata', eager: true })`
becomes rather difficult.
  • Loading branch information
nvlang committed Jul 18, 2024
1 parent 2b81d16 commit 6cc4dfb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/base/Sveltex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ export class Sveltex<

if (attributes['context'] === 'module') {
// From frontmatter
script.push(...(this.scriptModuleLines[filename] ?? []));
script.push(
...(this.scriptModuleLines[filename] ?? [
'export const metadata = undefined;',
]),
);
} else {
script.push(...tcInfos.map((info) => TexComponent.importSvg(info)));

Expand Down
4 changes: 3 additions & 1 deletion tests/unit/base/Sveltex/sveltex.script.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ describe('Sveltex', () => {
markup: markupOut?.code ?? '',
filename: '6f85b451-6ae9-42c4-a03b-cca772ef7455.sveltex',
});
expect(scriptModuleOut).toBeUndefined();
expect(scriptModuleOut?.code).toMatch(
/^\s*export const metadata = undefined;\s*$/,
);
existsSync.mockReset();
});

Expand Down

0 comments on commit 6cc4dfb

Please sign in to comment.