Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler): add "exports" to marko.json #2062

Merged
merged 4 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/grumpy-kids-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@marko/compiler": minor
"marko": minor
---

Add "exports" to marko.json
2 changes: 1 addition & 1 deletion packages/compiler/src/taglib/finder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function find(dirname, registeredTaglibs) {
nodePath.join(name, "marko.json")
);
if (taglibPath) {
var taglib = taglibLoader.loadTaglibFromFile(taglibPath);
var taglib = taglibLoader.loadTaglibFromFile(taglibPath, true);
helper.addTaglib(taglib);
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler/src/taglib/loader/Taglib.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ function handleImport(taglib, importedTaglib) {
}

class Taglib {
constructor(filePath) {
constructor(filePath, isFromPackageJson) {
ok(filePath, '"filePath" expected');
this.filePath = this.path /* deprecated */ = this.id = filePath;
this.isFromPackageJson = isFromPackageJson === true;
this.dirname = path.dirname(this.filePath);
this.scriptLang = undefined;
this.tags = {};
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/src/taglib/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function loadTaglibFromProps(taglib, taglibProps) {
return loaders.loadTaglibFromProps(taglib, taglibProps);
}

function loadTaglibFromFile(filePath) {
return loaders.loadTaglibFromFile(filePath);
function loadTaglibFromFile(filePath, isFromPackageJson) {
return loaders.loadTaglibFromFile(filePath, isFromPackageJson);
}

function loadTaglibFromDir(filePath) {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler/src/taglib/loader/loadTaglibFromFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ var loaders = require("./loaders");

var ok = require("assert").ok;

function loadFromFile(filePath) {
function loadFromFile(filePath, isFromPackageJson) {
ok(filePath, '"filePath" is required');

var taglib = cache.get(filePath);

// Only load a taglib once by caching the loaded taglibs using the file
// system file path as the key
if (!taglib) {
taglib = new types.Taglib(filePath);
taglib = new types.Taglib(filePath, isFromPackageJson);
cache.put(filePath, taglib);

var taglibProps = jsonFileReader.readFileSync(filePath);
Expand Down
18 changes: 18 additions & 0 deletions packages/compiler/src/taglib/loader/loadTaglibFromProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,24 @@ class TaglibLoader {
}
}

exports(dir) {
var taglib = this.taglib;
var path = this.filePath;
var dirname = this.dirname;

if (taglib.isFromPackageJson) {
taglib.tagsDir = false;

scanTagsDir(
path,
dirname,
dir,
taglib,
this.dependencyChain.append(`exports`)
);
}
}

taglibImports(imports) {
// The "taglib-imports" property allows another taglib to be imported
// into this taglib so that the tags defined in the imported taglib
Expand Down
1 change: 1 addition & 0 deletions packages/marko/docs/marko-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Similar to [`marko-tag.json`](#single-component-definition), this file is discov
```js
{
"taglib-id": "my-custom-tag-library", // Names the component library, for better errors.
"exports": "./dist", // Where to export the compiled components.
"tags-dir": "./ui-modules", // What directory to crawl to autodiscover components. Default:`./components/`
"taglib-imports": ["./some-folder/marko.json", "./other-folder/marko.json"], // Creates a _combined_ tag library by referencing others.

Expand Down
3 changes: 3 additions & 0 deletions packages/marko/test/taglib-finder/fixtures/exports/marko.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exports": "_dist/components"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "taglib-finder-test",
"version": "0.0.0",
"dependencies": {
"included-dependency": "0.0.1"
}
}
11 changes: 11 additions & 0 deletions packages/marko/test/taglib-finder/fixtures/exports/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var expect = require("chai").expect;

exports.check = function (taglibFinder) {
const discoveredTags = taglibFinder
.find(__dirname, [])
.flatMap((taglib) => Object.keys(taglib.tags));

expect(discoveredTags).to.include("included-tag");
expect(discoveredTags).to.include("dev-tag");
expect(discoveredTags).to.not.include("dist-tag");
};
Loading