Skip to content

Commit

Permalink
feat: support taglib register with just module id
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Aug 9, 2023
1 parent 9aede28 commit 6ba268c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-pandas-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@marko/compiler": minor
---

Support registering a taglib in the compiler by just passing in a module id.
1 change: 1 addition & 0 deletions packages/compiler/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function getRuntimeEntryFiles(
export namespace taglib {
export function excludeDir(dirname: string): void;
export function excludePackage(packageName: string): void;
export function register(id: string): void;
export function register(id: string, props: { [x: string]: unknown }): void;
export function buildLookup(
dirname: string,
Expand Down
18 changes: 18 additions & 0 deletions packages/compiler/src/taglib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from "path";
import loader from "./loader";
import finder from "./finder";
import Lookup from "./lookup";
import taglibConfig from "./config";
import markoModules from "../../modules";
import tryLoadTranslator from "../util/try-load-translator";

export const excludeDir = finder.excludeDir;
Expand Down Expand Up @@ -77,6 +79,22 @@ export function buildLookup(dirname, requestedTranslator, onError) {
}

export function register(id, props) {
if (typeof props === "undefined") {
switch (id[0]) {
case ".":
case "/":
case "\\":
break;
default:
if (!id.endsWith(".json")) {
id = path.join(id, "marko.json");
}
break;
}
id = markoModules.require.resolve(id);
props = markoModules.require(id);
}

registeredTaglibs.push(loadTaglib(id, props));
}

Expand Down

0 comments on commit 6ba268c

Please sign in to comment.