Skip to content

Commit

Permalink
feat: support registering global taglibs from jest config
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Aug 11, 2023
1 parent 7cf4b68 commit bfdda6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ module.exports = {
## Customizing the Marko compiler

You can override the default [Marko compiler options](https://markojs.com/docs/compiler/#options) by adding a Jest "globals" config with a `marko` property.
An additional `taglib` property can be set which supports an `excludeDirs` and `excludePackages` array which will prevent Marko from discovering taglibs in a directory or package respectively.
An additional `taglib` property can be set which supports `excludeDirs` and `excludePackages` arrays which will prevent Marko from discovering taglibs in a directory or package respectively. You can also specify a `register` array on this object which will cause a taglib to be registered unconditionally for every template.

**jest.config.js**

Expand All @@ -119,6 +119,7 @@ module.exports = {
marko: {
ignoreUnrecognizedTags: true,
taglib: {
register: ["@marko/compat-v4"],
excludePackages: ["@scope/package-name"],
},
},
Expand Down
11 changes: 11 additions & 0 deletions src/transform/create-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ export default ({ browser }: { browser: boolean }) => {
taglib.excludePackage(name);
}
}

const register = taglibConfig.register;
if (register) {
for (const name of register) {
if (typeof name === "string") {
taglib.register(name);
} else if (Array.isArray(name) && name.length === 2) {
taglib.register(name[0], name[1]);
}
}
}
}
}
}
Expand Down

0 comments on commit bfdda6c

Please sign in to comment.