Skip to content

Commit

Permalink
Tags directory (#2438)
Browse files Browse the repository at this point in the history
* feat: support tags directory

* feat: tags dir forces Tags API

* chore: update snapshots

* chore: remove script that was accidentally committed

* chore: add changeset

* fix: use system path separators

* refactor: better filename check for tags/components?

* refactor: micro-optimize tags dir detection
  • Loading branch information
mlrawlings authored Dec 20, 2024
1 parent a364d1e commit 4b6c613
Show file tree
Hide file tree
Showing 457 changed files with 1,005 additions and 603 deletions.
8 changes: 8 additions & 0 deletions .changeset/chatty-maps-enjoy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@marko/translator-interop-class-tags": patch
"marko": patch
"@marko/runtime-tags": patch
"@marko/compiler": patch
---

use tags/ instead of components/ for runtime-tags
14 changes: 9 additions & 5 deletions packages/compiler/src/taglib/finder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getAllDependencyNames(pkg) {
return Object.keys(map);
}

function find(dirname, registeredTaglibs) {
function find(dirname, registeredTaglibs, tagDiscoveryDirs) {
var found = findCache[dirname];
if (found) {
return found;
Expand Down Expand Up @@ -92,10 +92,14 @@ function find(dirname, registeredTaglibs) {
}

if (!taglib || taglib.tagsDir === undefined) {
const componentsPath = nodePath.join(curDirname, "components");

if (existsSync(componentsPath) && !excludedDirs[componentsPath]) {
helper.addTaglib(taglibLoader.loadTaglibFromDir(curDirname));
for (const tagDiscoveryDir of tagDiscoveryDirs) {
const componentsPath = nodePath.join(curDirname, tagDiscoveryDir);

if (existsSync(componentsPath) && !excludedDirs[componentsPath]) {
helper.addTaglib(
taglibLoader.loadTaglibFromDir(curDirname, tagDiscoveryDir),
);
}
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler/src/taglib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export function buildLookup(dirname, requestedTranslator, onError) {
}

runAndCatchErrors(() => {
taglibsForDir = finder.find(dirname, taglibsForDir);
taglibsForDir = finder.find(
dirname,
taglibsForDir,
translator.tagDiscoveryDirs,
);
}, onError);

const cacheKey = taglibsForDir
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 @@ -12,8 +12,8 @@ function loadTaglibFromFile(filePath, isFromPackageJson) {
return loaders.loadTaglibFromFile(filePath, isFromPackageJson);
}

function loadTaglibFromDir(filePath) {
return loaders.loadTaglibFromDir(filePath);
function loadTaglibFromDir(filePath, tagDiscoveryDir) {
return loaders.loadTaglibFromDir(filePath, tagDiscoveryDir);
}

function clearCache() {
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/src/taglib/loader/loadTaglibFromDir.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ var DependencyChain = require("./DependencyChain");
var scanTagsDir = require("./scanTagsDir");
var types = require("./types");

function loadFromDir(dir) {
function loadFromDir(dir, tagDiscoveryDir) {
ok(dir, '"dir" is required');

var componentsPath = nodePath.join(dir, "components");
var componentsPath = nodePath.join(dir, tagDiscoveryDir);
var taglib = cache.get(componentsPath);

// Only load a taglib once by caching the loaded taglibs using the file
Expand All @@ -19,7 +19,7 @@ function loadFromDir(dir) {
scanTagsDir(
componentsPath,
dir,
"components",
tagDiscoveryDir,
taglib,
new DependencyChain([componentsPath]),
);
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-class/src/translator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import getComponentFiles from "./util/get-component-files";
import { optimizeHTMLWrites } from "./util/optimize-html-writes";
import { analyzeStaticVDOM } from "./util/optimize-vdom-create";

export const tagDiscoveryDirs = ["components"];
export { optionalTaglibs, default as taglibs } from "./taglib";
export { entryBuilder as internalEntryBuilder } from "./util/add-dependencies";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var expect = require("chai").expect;

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

expect(discoveredTags).to.include("included-tag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports.check = function (taglibFinder) {
var finderDir = nodePath.join(__dirname, "a/b/c");

function getPaths() {
return taglibFinder.find(finderDir, []).map((taglib) => {
return taglibFinder.find(finderDir, [], ["components"]).map((taglib) => {
return taglib.path;
});
}
Expand Down
16 changes: 9 additions & 7 deletions packages/runtime-class/test/taglib-finder/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ autotest("fixtures", (fixture) => {
}

var finderDir = resolve(test.dir);
var found = taglibFinder.find(finderDir, []).map((taglib) => {
if (taglib.path.startsWith(dir)) {
return taglib.path.substring(dir.length).replace(/[\\]/g, "/");
} else {
return "BAD:" + taglib.path;
}
});
var found = taglibFinder
.find(finderDir, [], ["components"])
.map((taglib) => {
if (taglib.path.startsWith(dir)) {
return taglib.path.substring(dir.length).replace(/[\\]/g, "/");
} else {
return "BAD:" + taglib.path;
}
});

snapshot(found, ".json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ export const _pattern__ = /* @__PURE__ */_$.value("_pattern_", (_scope, _pattern
}, () => _content_);
export const _input_ = /* @__PURE__ */_$.value("input", (_scope, input) => _pattern__(_scope, input.thing), () => _pattern__);
export const _params__ = /* @__PURE__ */_$.value("_params_", (_scope, _params_) => _input_(_scope, _params_[0]), () => _input_);
export default /* @__PURE__ */_$.createTemplate("__tests__/components/custom-tag/index.marko", _template_, _walks_, _setup_, void 0, () => _params__);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/custom-tag/index.marko", _template_, _walks_, _setup_, void 0, () => _params__);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const _template_ = `<!>${_customTag_template}`;
export const _walks_ = /* beginChild, _customTag_walks, endChild */`D/${_customTag_walks}&`;
import { _setup_ as _customTag, _pattern__ as _customTag_input_thing, _template_ as _customTag_template, _walks_ as _customTag_walks } from "./components/custom-tag/index.marko";
import { _setup_ as _customTag, _pattern__ as _customTag_input_thing, _template_ as _customTag_template, _walks_ as _customTag_walks } from "./tags/custom-tag/index.marko";
import * as _$ from "@marko/runtime-tags/debug/dom";
const _thing_content2 = _$.register("__tests__/template.marko_2_renderer", /* @__PURE__ */_$.createRendererWithOwner("Goodbye", ""));
const _thing_content = _$.register("__tests__/template.marko_1_renderer", /* @__PURE__ */_$.createRendererWithOwner("Hello", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
"#text/0(": _$.normalizeDynamicRenderer(content)
});
});
export default /* @__PURE__ */_$.createTemplate("__tests__/components/custom-tag/index.marko", _renderer);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/custom-tag/index.marko", _renderer);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _$ from "@marko/runtime-tags/debug/html";
import _customTag from "./components/custom-tag/index.marko";
import _customTag from "./tags/custom-tag/index.marko";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
const {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as _$ from "@marko/runtime-tags/debug/html";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
_$.write("<div></div>");
});
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/hello/index.marko", _renderer);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _hello from "./components/hello/index.marko";
import _hello from "./tags/hello/index.marko";
import * as _$ from "@marko/runtime-tags/debug/html";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as _$ from "@marko/runtime-tags/debug/html";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
_$.write("<div></div>");
});
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/hello/index.marko", _renderer);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _$ from "@marko/runtime-tags/debug/html";
import _hello from "./components/hello/index.marko";
import _hello from "./tags/hello/index.marko";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
const {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as _$ from "@marko/runtime-tags/debug/html";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
_$.write("<div></div>");
});
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/hello/index.marko", _renderer);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _$ from "@marko/runtime-tags/debug/html";
import _hello from "./components/hello/index.marko";
import _hello from "./tags/hello/index.marko";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
const _childScope = _$.peekNextScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ const _dynamicTagName = /* @__PURE__ */_$.conditional("#text/0", _scope => _inpu
export const _input_foo_ = /* @__PURE__ */_$.value("input_foo", (_scope, input_foo) => _dynamicTagName(_scope, input_foo), () => _dynamicTagName);
export const _input_ = /* @__PURE__ */_$.value("input", (_scope, input) => _input_foo_(_scope, input.foo), () => _input_foo_);
export const _params__ = /* @__PURE__ */_$.value("_params_", (_scope, _params_) => _input_(_scope, _params_[0]), () => _input_);
export default /* @__PURE__ */_$.createTemplate("__tests__/components/hello/index.marko", _template_, _walks_, _setup_, void 0, () => _params__);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/hello/index.marko", _template_, _walks_, _setup_, void 0, () => _params__);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const _template_ = `<!>${_hello_template}<!>`;
export const _walks_ = /* beginChild, _hello_walks, endChild */`D/${_hello_walks}&D`;
import { _setup_ as _hello, _input_foo_ as _hello_input_foo, _template_ as _hello_template, _walks_ as _hello_walks } from "./components/hello/index.marko";
import { _setup_ as _hello, _input_foo_ as _hello_input_foo, _template_ as _hello_template, _walks_ as _hello_walks } from "./tags/hello/index.marko";
import * as _$ from "@marko/runtime-tags/debug/dom";
const _foo_content = _$.register("__tests__/template.marko_1_renderer", /* @__PURE__ */_$.createRendererWithOwner("Foo!", ""));
export function _setup_(_scope) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
"#text/0(": _$.normalizeDynamicRenderer(input.foo)
});
});
export default /* @__PURE__ */_$.createTemplate("__tests__/components/hello/index.marko", _renderer);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/hello/index.marko", _renderer);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _$ from "@marko/runtime-tags/debug/html";
import _hello from "./components/hello/index.marko";
import _hello from "./tags/hello/index.marko";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
const _childScope = _$.peekNextScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import * as _$ from "@marko/runtime-tags/debug/dom";
export const _className_ = /* @__PURE__ */_$.value("className", (_scope, className) => _$.classAttr(_scope["#div/0"], className));
export const _input_ = /* @__PURE__ */_$.value("input", (_scope, input) => _className_(_scope, input.class));
export const _params__ = /* @__PURE__ */_$.value("_params_", (_scope, _params_) => _input_(_scope, _params_[0]));
export default /* @__PURE__ */_$.createTemplate("__tests__/components/custom-tag.marko", _template_, _walks_, _setup_, void 0, () => _params__);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/custom-tag.marko", _template_, _walks_, _setup_, void 0, () => _params__);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const _template_ = `<div></div><div class="a b"></div><div class="a b c"></div>${_customTag_template}${_customTag_template}<!><!>`;
export const _walks_ = /* get, over(3), beginChild, _customTag_walks, endChild, beginChild, _customTag_walks, endChild, replace, over(1) */` d/${_customTag_walks}&/${_customTag_walks}&%bD`;
import * as _$ from "@marko/runtime-tags/debug/dom";
import { _setup_ as _customTag, _className_ as _customTag_input_class, _template_ as _customTag_template, _walks_ as _customTag_walks } from "./components/custom-tag.marko";
import { _setup_ as _customTag, _className_ as _customTag_input_class, _template_ as _customTag_template, _walks_ as _customTag_walks } from "./tags/custom-tag.marko";
const _test_content = _$.register("__tests__/template.marko_1_renderer", /* @__PURE__ */_$.createRendererWithOwner("Hello", ""));
const _inputTest_input = _$.dynamicTagAttrs("#text/3");
const _expr_Text_c_d = /* @__PURE__ */_$.intersection(3, _scope => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
} = input;
_$.write(`<div${_$.classAttr(className)}></div>${_$.markResumeNode(_scope0_id, "#div/0")}`);
});
export default /* @__PURE__ */_$.createTemplate("__tests__/components/custom-tag.marko", _renderer);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/custom-tag.marko", _renderer);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _$ from "@marko/runtime-tags/debug/html";
import _customTag from "./components/custom-tag.marko";
import _customTag from "./tags/custom-tag.marko";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import * as _$ from "@marko/runtime-tags/debug/dom";
export const _style_ = /* @__PURE__ */_$.value("style", (_scope, style) => _$.styleAttr(_scope["#div/0"], style));
export const _input_ = /* @__PURE__ */_$.value("input", (_scope, input) => _style_(_scope, input.style));
export const _params__ = /* @__PURE__ */_$.value("_params_", (_scope, _params_) => _input_(_scope, _params_[0]));
export default /* @__PURE__ */_$.createTemplate("__tests__/components/custom-tag.marko", _template_, _walks_, _setup_, void 0, () => _params__);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/custom-tag.marko", _template_, _walks_, _setup_, void 0, () => _params__);
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const _template_ = `<div></div><div style=width:100px></div><div style="color: green"></div>${_customTag_template}${_customTag_template}${_customTag_template}<!><!>`;
export const _walks_ = /* get, over(3), beginChild, _customTag_walks, endChild, beginChild, _customTag_walks, endChild, beginChild, _customTag_walks, endChild, replace, over(1) */` d/${_customTag_walks}&/${_customTag_walks}&/${_customTag_walks}&%bD`;
import * as _$ from "@marko/runtime-tags/debug/dom";
import { _setup_ as _customTag, _style_ as _customTag_input_style, _template_ as _customTag_template, _walks_ as _customTag_walks } from "./components/custom-tag.marko";
import { _setup_ as _customTag, _style_ as _customTag_input_style, _template_ as _customTag_template, _walks_ as _customTag_walks } from "./tags/custom-tag.marko";
const _test_content = _$.register("__tests__/template.marko_1_renderer", /* @__PURE__ */_$.createRendererWithOwner("Hello", ""));
const _test_input = _$.dynamicTagAttrs("#text/4");
const _dynamicTagName = /* @__PURE__ */_$.conditional("#text/4", _scope => _test_input(_scope, () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
} = input;
_$.write(`<div${_$.styleAttr(style)}></div>${_$.markResumeNode(_scope0_id, "#div/0")}`);
});
export default /* @__PURE__ */_$.createTemplate("__tests__/components/custom-tag.marko", _renderer);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/custom-tag.marko", _renderer);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _$ from "@marko/runtime-tags/debug/html";
import _customTag from "./components/custom-tag.marko";
import _customTag from "./tags/custom-tag.marko";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const _walks_ = /* get, next(1), get, out(1) */" D l";
export const _setup_ = () => {};
import * as _$ from "@marko/runtime-tags/debug/dom";
export const _text_ = /* @__PURE__ */_$.value("text", (_scope, text) => _$.data(_scope["#text/1"], text));
const _onClick__effect = _$.effect("__tests__/components/my-button.marko_0_onClick", (_scope, {
const _onClick__effect = _$.effect("__tests__/tags/my-button.marko_0_onClick", (_scope, {
onClick
}) => _$.on(_scope["#button/0"], "click", onClick));
export const _onClick_ = /* @__PURE__ */_$.value("onClick", (_scope, onClick) => _onClick__effect(_scope));
Expand All @@ -12,4 +12,4 @@ export const _input_ = /* @__PURE__ */_$.value("input", (_scope, input) => {
_text_(_scope, input.text);
});
export const _params__ = /* @__PURE__ */_$.value("_params_", (_scope, _params_) => _input_(_scope, _params_[0]));
export default /* @__PURE__ */_$.createTemplate("__tests__/components/my-button.marko", _template_, _walks_, _setup_, void 0, () => _params__);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/my-button.marko", _template_, _walks_, _setup_, void 0, () => _params__);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const _template_ = _myButton_template;
export const _walks_ = /* beginChild, _myButton_walks, endChild */`/${_myButton_walks}&`;
import { _setup_ as _myButton, _text_ as _myButton_input_text, _onClick_ as _myButton_input_onClick, _template_ as _myButton_template, _walks_ as _myButton_walks } from "./components/my-button.marko";
import { _setup_ as _myButton, _text_ as _myButton_input_text, _onClick_ as _myButton_input_onClick, _template_ as _myButton_template, _walks_ as _myButton_walks } from "./tags/my-button.marko";
import * as _$ from "@marko/runtime-tags/debug/dom";
const _clickCount = /* @__PURE__ */_$.state("clickCount", (_scope, clickCount) => {
_myButton_input_text(_scope["#childScope/0"], clickCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
text
} = input;
_$.write(`<button>${_$.escapeXML(text)}${_$.markResumeNode(_scope0_id, "#text/1")}</button>${_$.markResumeNode(_scope0_id, "#button/0")}`);
_$.writeEffect(_scope0_id, "__tests__/components/my-button.marko_0_onClick");
_$.writeEffect(_scope0_id, "__tests__/tags/my-button.marko_0_onClick");
_$.writeScope(_scope0_id, {
"onClick": onClick
});
});
export default /* @__PURE__ */_$.createTemplate("__tests__/components/my-button.marko", _renderer);
export default /* @__PURE__ */_$.createTemplate("__tests__/tags/my-button.marko", _renderer);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import _myButton from "./components/my-button.marko";
import _myButton from "./tags/my-button.marko";
import * as _$ from "@marko/runtime-tags/debug/html";
const _renderer = /* @__PURE__ */_$.createRenderer((input, _tagVar) => {
const _scope0_id = _$.nextScopeId();
Expand Down
Loading

0 comments on commit 4b6c613

Please sign in to comment.