Skip to content

Commit

Permalink
feat(compiler): add "exports" to marko.json
Browse files Browse the repository at this point in the history
  • Loading branch information
LuLaValva committed Nov 16, 2023
1 parent 21c0eea commit 54d35a0
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 6 deletions.
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
Empty file.
Empty file.
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"
}
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");
};

0 comments on commit 54d35a0

Please sign in to comment.