@marko/compiler 5.40.2 → 5.41.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/babel-utils.d.ts +9 -1
- package/dist/babel-utils/imports.js +33 -2
- package/dist/babel-utils/tags.js +2 -1
- package/dist/index.js +15 -6
- package/dist/taglib/finder/index.js +3 -1
- package/dist/taglib/loader/Taglib.js +19 -1
- package/dist/taglib/loader/index.js +2 -2
- package/dist/taglib/loader/loadTaglibFromFile.js +6 -2
- package/dist/util/agent-fix-guide.js +51 -0
- package/dist/util/try-load-translator.js +16 -4
- package/package.json +3 -3
package/babel-utils.d.ts
CHANGED
|
@@ -54,6 +54,10 @@ export interface TagDefinition {
|
|
|
54
54
|
isRepeated?: boolean;
|
|
55
55
|
targetProperty?: string;
|
|
56
56
|
taglibId: string;
|
|
57
|
+
/** Set when the taglib was discovered by resolving an installed package. */
|
|
58
|
+
packageName?: string;
|
|
59
|
+
/** The root directory of `packageName`, which contains all files for this tag. */
|
|
60
|
+
packageRoot?: string;
|
|
57
61
|
types?: string;
|
|
58
62
|
template?: string;
|
|
59
63
|
renderer?: string;
|
|
@@ -303,7 +307,11 @@ export function parseTemplateLiteral(
|
|
|
303
307
|
sourceEnd?: null | number,
|
|
304
308
|
): t.TemplateLiteral;
|
|
305
309
|
|
|
306
|
-
export function resolveRelativePath(
|
|
310
|
+
export function resolveRelativePath(
|
|
311
|
+
file: t.BabelFile,
|
|
312
|
+
request: string,
|
|
313
|
+
tagDef?: TagDefinition,
|
|
314
|
+
): string;
|
|
307
315
|
export function importDefault(
|
|
308
316
|
file: t.BabelFile,
|
|
309
317
|
request: string,
|
|
@@ -5,10 +5,13 @@ var _relativeImportPath = require("relative-import-path");function _interopRequi
|
|
|
5
5
|
|
|
6
6
|
const IMPORTS_KEY = Symbol();
|
|
7
7
|
const FS_START = _path.default.sep === "/" ? _path.default.sep : /^(.*?:)/.exec(_modules.cwd)[1];
|
|
8
|
+
const REG_NODE_MODULES = /[\\/]node_modules[\\/]/;
|
|
8
9
|
|
|
9
|
-
function resolveRelativePath(file, request) {
|
|
10
|
+
function resolveRelativePath(file, request, tagDef) {
|
|
10
11
|
if (request.startsWith(FS_START)) {
|
|
11
|
-
request =
|
|
12
|
+
request =
|
|
13
|
+
packageImportPath(file.opts.filename, tagDef, request) ||
|
|
14
|
+
(0, _relativeImportPath.relativeImportPath)(file.opts.filename, request);
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
if (file.markoOpts.optimize) {
|
|
@@ -21,6 +24,34 @@ function resolveRelativePath(file, request) {
|
|
|
21
24
|
return request;
|
|
22
25
|
}
|
|
23
26
|
|
|
27
|
+
/**
|
|
28
|
+
* A tag installed into `node_modules` is imported through the name its package was
|
|
29
|
+
* resolved by, since its path is a realpath which may not be importable at all.
|
|
30
|
+
*/
|
|
31
|
+
function packageImportPath(from, tagDef, request) {
|
|
32
|
+
if (!tagDef?.packageName || !REG_NODE_MODULES.test(request)) return;
|
|
33
|
+
|
|
34
|
+
const { packageRoot } = tagDef;
|
|
35
|
+
// Within the package we stay relative, both because it always resolves and
|
|
36
|
+
// because a self reference would only work if the package exports the tag.
|
|
37
|
+
if (!isWithin(packageRoot, request) || isWithin(packageRoot, from)) return;
|
|
38
|
+
|
|
39
|
+
const subPath = _path.default.relative(packageRoot, request);
|
|
40
|
+
return `${tagDef.packageName}/${subPath.split(_path.default.sep).join("/")}`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isWithin(dir, filename) {
|
|
44
|
+
const rel = _path.default.relative(dir, filename);
|
|
45
|
+
// `path.relative` walks out of the dir with `..`, or returns an absolute path
|
|
46
|
+
// when it cannot relate the two at all, eg across windows drives.
|
|
47
|
+
return (
|
|
48
|
+
!!rel &&
|
|
49
|
+
rel !== ".." &&
|
|
50
|
+
!rel.startsWith(`..${_path.default.sep}`) &&
|
|
51
|
+
!_path.default.isAbsolute(rel));
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
24
55
|
function importDefault(file, request, nameHint) {
|
|
25
56
|
const imports = getImports(file);
|
|
26
57
|
request = resolveRelativePath(file, request);
|
package/dist/babel-utils/tags.js
CHANGED
|
@@ -347,7 +347,8 @@ function resolveTagImport(path, request) {
|
|
|
347
347
|
const tagName = request.slice(1, -1);
|
|
348
348
|
const tagDef = (0, _taglib.getTagDefForTagName)(file, tagName);
|
|
349
349
|
const tagEntry = tagDef && (tagDef.renderer || tagDef.template);
|
|
350
|
-
const relativePath =
|
|
350
|
+
const relativePath =
|
|
351
|
+
tagEntry && (0, _imports.resolveRelativePath)(file, tagEntry, tagDef);
|
|
351
352
|
|
|
352
353
|
if (!relativePath) {
|
|
353
354
|
throw path.buildCodeFrameError(
|
package/dist/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
13
13
|
var _babelPlugin = _interopRequireDefault(require("./babel-plugin"));
|
|
14
14
|
var _config = _interopRequireDefault(require("./config"));
|
|
15
15
|
var taglib = _interopRequireWildcard(require("./taglib"));exports.taglib = taglib;
|
|
16
|
+
var _agentFixGuide = _interopRequireDefault(require("./util/agent-fix-guide"));
|
|
16
17
|
var _buildCodeFrame = require("./util/build-code-frame");
|
|
17
18
|
var _mergeErrors = _interopRequireDefault(require("./util/merge-errors"));
|
|
18
19
|
var _shouldOptimize = _interopRequireDefault(require("./util/should-optimize"));
|
|
@@ -32,16 +33,24 @@ function configure(newConfig) {
|
|
|
32
33
|
|
|
33
34
|
async function compile(src, filename, config) {
|
|
34
35
|
const markoConfig = loadMarkoConfig(config);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
try {
|
|
37
|
+
const babelConfig = await loadBabelConfig(filename, markoConfig);
|
|
38
|
+
const babelResult = await (0, _babel.transformAsync)(src, babelConfig);
|
|
39
|
+
return buildResult(src, filename, markoConfig.errorRecovery, babelResult);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
throw (0, _agentFixGuide.default)(err, markoConfig.translator);
|
|
42
|
+
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
function compileSync(src, filename, config) {
|
|
41
46
|
const markoConfig = loadMarkoConfig(config);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
try {
|
|
48
|
+
const babelConfig = loadBabelConfigSync(filename, markoConfig);
|
|
49
|
+
const babelResult = (0, _babel.transformSync)(src, babelConfig);
|
|
50
|
+
return buildResult(src, filename, markoConfig.errorRecovery, babelResult);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
throw (0, _agentFixGuide.default)(err, markoConfig.translator);
|
|
53
|
+
}
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
async function compileFile(filename, config) {
|
|
@@ -124,7 +124,9 @@ function find(dirname, registeredTaglibs, tagDiscoveryDirs) {
|
|
|
124
124
|
rootPkg.__dirname
|
|
125
125
|
);
|
|
126
126
|
if (taglibPath) {
|
|
127
|
-
|
|
127
|
+
// Resolving realpaths the taglib, which for a virtual store (eg pnpm) bears
|
|
128
|
+
// no relation to how it is imported, so hold onto the name it resolved by.
|
|
129
|
+
var taglib = taglibLoader.loadTaglibFromFile(taglibPath, true, name);
|
|
128
130
|
addTaglib(taglib);
|
|
129
131
|
}
|
|
130
132
|
}
|
|
@@ -26,11 +26,12 @@ function handleImport(taglib, importedTaglib) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
class Taglib {
|
|
29
|
-
constructor(filePath, isFromPackageJson) {
|
|
29
|
+
constructor(filePath, isFromPackageJson, packageName) {
|
|
30
30
|
ok(filePath, '"filePath" expected');
|
|
31
31
|
this.filePath = this.path /* deprecated */ = this.id = filePath;
|
|
32
32
|
this.isFromPackageJson = isFromPackageJson === true;
|
|
33
33
|
this.dirname = path.dirname(this.filePath);
|
|
34
|
+
this.packageName = packageName;
|
|
34
35
|
this.scriptLang = undefined;
|
|
35
36
|
this.tags = {};
|
|
36
37
|
this.migrators = [];
|
|
@@ -72,6 +73,23 @@ class Taglib {
|
|
|
72
73
|
}
|
|
73
74
|
this.tags[tag.name] = tag;
|
|
74
75
|
tag.taglibId = this.id || this.path;
|
|
76
|
+
this.setTagPackage(tag);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
setPackageName(packageName) {
|
|
80
|
+
this.packageName = packageName;
|
|
81
|
+
for (var name in this.tags) {
|
|
82
|
+
if (hasOwnProperty.call(this.tags, name)) {
|
|
83
|
+
this.setTagPackage(this.tags[name]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setTagPackage(tag) {
|
|
89
|
+
if (this.packageName) {
|
|
90
|
+
tag.packageName = this.packageName;
|
|
91
|
+
tag.packageRoot = this.dirname;
|
|
92
|
+
}
|
|
75
93
|
}
|
|
76
94
|
|
|
77
95
|
addImport(path) {
|
|
@@ -8,8 +8,8 @@ function loadTaglibFromProps(taglib, taglibProps) {
|
|
|
8
8
|
return loaders.loadTaglibFromProps(taglib, taglibProps);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function loadTaglibFromFile(filePath, isFromPackageJson) {
|
|
12
|
-
return loaders.loadTaglibFromFile(filePath, isFromPackageJson);
|
|
11
|
+
function loadTaglibFromFile(filePath, isFromPackageJson, packageName) {
|
|
12
|
+
return loaders.loadTaglibFromFile(filePath, isFromPackageJson, packageName);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function loadTaglibFromDir(filePath, tagDiscoveryDir) {
|
|
@@ -4,7 +4,7 @@ var jsonFileReader = require("./json-file-reader");
|
|
|
4
4
|
var loaders = require("./loaders");
|
|
5
5
|
var types = require("./types");
|
|
6
6
|
|
|
7
|
-
function loadFromFile(filePath, isFromPackageJson) {
|
|
7
|
+
function loadFromFile(filePath, isFromPackageJson, packageName) {
|
|
8
8
|
ok(filePath, '"filePath" is required');
|
|
9
9
|
|
|
10
10
|
var taglib = cache.get(filePath);
|
|
@@ -12,11 +12,15 @@ function loadFromFile(filePath, isFromPackageJson) {
|
|
|
12
12
|
// Only load a taglib once by caching the loaded taglibs using the file
|
|
13
13
|
// system file path as the key
|
|
14
14
|
if (!taglib) {
|
|
15
|
-
taglib = new types.Taglib(filePath, isFromPackageJson);
|
|
15
|
+
taglib = new types.Taglib(filePath, isFromPackageJson, packageName);
|
|
16
16
|
cache.put(filePath, taglib);
|
|
17
17
|
|
|
18
18
|
var taglibProps = jsonFileReader.readFileSync(filePath);
|
|
19
19
|
loaders.loadTaglibFromProps(taglib, taglibProps);
|
|
20
|
+
} else if (packageName && !taglib.packageName) {
|
|
21
|
+
// The taglib may have first been loaded by walking up from a file within the
|
|
22
|
+
// package itself, in which case we did not yet know the name it is installed as.
|
|
23
|
+
taglib.setPackageName(packageName);
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
return taglib;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";exports.__esModule = true;exports.default = appendAgentFixGuide;var _tryLoadTranslator = _interopRequireDefault(require("./try-load-translator"));function _interopRequireDefault(e) {return e && e.__esModule ? e : { default: e };}
|
|
2
|
+
|
|
3
|
+
const applied = Symbol("markoAgentFixGuide");
|
|
4
|
+
|
|
5
|
+
function appendAgentFixGuide(error, translator) {
|
|
6
|
+
if (error instanceof Error && !error[applied] && isCodingAgent()) {
|
|
7
|
+
const guide = fixGuide(translator);
|
|
8
|
+
if (guide) {
|
|
9
|
+
// `message` is locked against Babel mutations, so redefine rather than assign.
|
|
10
|
+
error[applied] = true;
|
|
11
|
+
Object.defineProperty(error, "message", {
|
|
12
|
+
value: error.message + guide,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
configurable: true
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return error;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Env markers terminal coding agents set.
|
|
24
|
+
function isCodingAgent() {
|
|
25
|
+
return (
|
|
26
|
+
typeof process === "object" && (
|
|
27
|
+
process.env.CLAUDECODE ||
|
|
28
|
+
process.env.CLAUDE_CODE ||
|
|
29
|
+
process.env.CURSOR_AGENT ||
|
|
30
|
+
process.env.GEMINI_CLI ||
|
|
31
|
+
process.env.CODEX_SANDBOX ||
|
|
32
|
+
process.env.CODEX_THREAD_ID ||
|
|
33
|
+
process.env.AI_AGENT));
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function fixGuide(translator) {
|
|
38
|
+
// Only resolved specifiers expose a cheat sheet; inline objects (tests,
|
|
39
|
+
// embedders) opt out.
|
|
40
|
+
if (typeof translator !== "string") return undefined;
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const cheatsheet = (0, _tryLoadTranslator.default)(translator)?.cheatsheet;
|
|
44
|
+
return cheatsheet ?
|
|
45
|
+
`\n\nFix guide: READ ${cheatsheet} before writing a fix.` :
|
|
46
|
+
undefined;
|
|
47
|
+
} catch {
|
|
48
|
+
// Leave the real compile error untouched if the translator can't load.
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
"use strict";exports.__esModule = true;exports.default = _default;var _modules = _interopRequireDefault(require("@marko/compiler/modules"));
|
|
2
|
+
var _path = _interopRequireDefault(require("path"));
|
|
2
3
|
|
|
3
4
|
var _config = _interopRequireDefault(require("../config"));function _interopRequireDefault(e) {return e && e.__esModule ? e : { default: e };}
|
|
4
5
|
const cache = {};
|
|
5
6
|
|
|
6
7
|
function _default(requested = _config.default.translator) {
|
|
7
8
|
if (typeof requested === "string") {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
let translator = cache[requested];
|
|
10
|
+
if (!translator) {
|
|
11
|
+
const file = _modules.default.resolve(requested);
|
|
12
|
+
translator = _modules.default.require(file);
|
|
13
|
+
// The translator declares its LLM cheat sheet relative to its own module;
|
|
14
|
+
// resolve it to a cwd-relative path an agent can read directly.
|
|
15
|
+
if (typeof translator.cheatsheet === "string") {
|
|
16
|
+
translator.cheatsheet = _path.default.relative(
|
|
17
|
+
_modules.default.cwd,
|
|
18
|
+
_path.default.resolve(_path.default.dirname(file), translator.cheatsheet)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
cache[requested] = translator;
|
|
22
|
+
}
|
|
23
|
+
return translator;
|
|
12
24
|
}
|
|
13
25
|
|
|
14
26
|
return requested;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/compiler",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.41.1",
|
|
4
4
|
"description": "Marko template to JS compiler.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"babel",
|
|
@@ -77,13 +77,13 @@
|
|
|
77
77
|
"lasso-package-root": "^1.0.1",
|
|
78
78
|
"raptor-regexp": "^1.0.1",
|
|
79
79
|
"raptor-util": "^3.2.0",
|
|
80
|
-
"relative-import-path": "^1.0.
|
|
80
|
+
"relative-import-path": "^1.0.1",
|
|
81
81
|
"resolve-from": "^5.0.0",
|
|
82
82
|
"self-closing-tags": "^1.0.1",
|
|
83
83
|
"source-map-support": "^0.5.21"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"marko": "^5.39.
|
|
86
|
+
"marko": "^5.39.18"
|
|
87
87
|
},
|
|
88
88
|
"engines": {
|
|
89
89
|
"node": "18 || 20 || >=22"
|