@marko/compiler 5.27.8-next.0 → 5.27.8
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/package.json +3 -3
- package/src/config.js +0 -152
- package/src/index.js +0 -136
- package/src/register.js +0 -30
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/compiler",
|
|
3
3
|
"description": "Marko template to JS compiler.",
|
|
4
|
-
"version": "5.27.8
|
|
4
|
+
"version": "5.27.8",
|
|
5
5
|
"author": "Dylan Piercey <dpiercey@ebay.com>",
|
|
6
6
|
"bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md",
|
|
7
7
|
"dependencies": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"strip-json-comments": "^3.1.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@marko/translator-default": "^5.25.8
|
|
32
|
+
"@marko/translator-default": "^5.25.8"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"dist",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"plugin"
|
|
52
52
|
],
|
|
53
53
|
"license": "MIT",
|
|
54
|
-
"main": "
|
|
54
|
+
"main": "dist/index.js",
|
|
55
55
|
"main:dev": "src/index.js",
|
|
56
56
|
"main:npm": "dist/index.js",
|
|
57
57
|
"publishConfig": {
|
package/src/config.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { getRootPackage } from "lasso-package-root";
|
|
3
|
-
|
|
4
|
-
const config = {
|
|
5
|
-
// The default output mode for compiled templates
|
|
6
|
-
output: "html",
|
|
7
|
-
|
|
8
|
-
// Override the runtimeid used when calling `marko/components.init` in the `hydrate` output.
|
|
9
|
-
runtimeId: null,
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Remove all typescript types from the output.
|
|
13
|
-
* By default, the compiler will remove types from the output if the
|
|
14
|
-
* `output` option is not `source` or `migrate`.
|
|
15
|
-
*/
|
|
16
|
-
stripTypes: undefined,
|
|
17
|
-
|
|
18
|
-
// Have Marko provide the final AST in the compile result.
|
|
19
|
-
ast: false,
|
|
20
|
-
|
|
21
|
-
// Set the false to have Marko not generate the final code string, useful if just reading metadata or AST.
|
|
22
|
-
code: true,
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Whether the version should be written to the template as a comment e.g.
|
|
26
|
-
* // Compiled using marko@x.x.x - DO NOT EDIT
|
|
27
|
-
*/
|
|
28
|
-
writeVersionComment: true,
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Whether unrecognized tags should be ignored or not. This flag will
|
|
32
|
-
* be enabled by default when compiling XML.
|
|
33
|
-
*/
|
|
34
|
-
ignoreUnrecognizedTags: false,
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Whether source maps should be output with the compiled templates.
|
|
38
|
-
* When `true` a `map` property will be available on the compile result.
|
|
39
|
-
* When `"inline"` the sourcemap will be inlined as a comment in the output code.
|
|
40
|
-
* When `"both"` both of the above will be used.
|
|
41
|
-
*/
|
|
42
|
-
sourceMaps: false,
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* This option inlines all of the meta data in the template.
|
|
46
|
-
* You can also access this metadata via `compile(...).meta`.
|
|
47
|
-
* This API is sticking around for compatibility purposes.
|
|
48
|
-
*/
|
|
49
|
-
meta: false,
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Allows configuring Marko to compile to different runtimes.
|
|
53
|
-
*/
|
|
54
|
-
translator: (() => {
|
|
55
|
-
const translatorReg = /^(@marko\/|marko-)translator-/;
|
|
56
|
-
let translator;
|
|
57
|
-
let pkg;
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
pkg = getRootPackage(process.cwd());
|
|
61
|
-
// eslint-disable-next-line no-empty
|
|
62
|
-
} catch {}
|
|
63
|
-
|
|
64
|
-
if (pkg) {
|
|
65
|
-
for (const name in pkg.dependencies) {
|
|
66
|
-
if (translatorReg.test(name)) {
|
|
67
|
-
if (translator && translator !== name) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
translator = name;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
for (const name in pkg.peerDependencies) {
|
|
76
|
-
if (translatorReg.test(name)) {
|
|
77
|
-
if (translator && translator !== name) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
translator = name;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
for (const name in pkg.devDependencies) {
|
|
86
|
-
if (translatorReg.test(name)) {
|
|
87
|
-
if (translator && translator !== name) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
translator = name;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return translator || "@marko/translator-default";
|
|
97
|
-
})(),
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Use a different file system object, eg webpacks CachedInputFileSystem or lasso-caching-fs
|
|
101
|
-
*/
|
|
102
|
-
fileSystem: fs,
|
|
103
|
-
/**
|
|
104
|
-
* By default Marko 5 outputs esm, you can optionally specify commonjs.
|
|
105
|
-
*
|
|
106
|
-
* Valid options: esm | cjs
|
|
107
|
-
*/
|
|
108
|
-
modules: "esm",
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Enables production mode optimizations if true, or not if false.
|
|
112
|
-
* If left as undefined checks for env === "production".
|
|
113
|
-
*/
|
|
114
|
-
optimize: undefined,
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* This option should be set if `hydrate` output is specified.
|
|
118
|
-
* Maps a virtual dependency to a resolved file which can be implemented
|
|
119
|
-
* for specific bundlers.
|
|
120
|
-
*/
|
|
121
|
-
resolveVirtualDependency: null,
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Compiling a Marko template may require other (used) Marko templates to compile.
|
|
125
|
-
* To prevent compiling templates more than once, most of the compilation is cached.
|
|
126
|
-
*
|
|
127
|
-
* The default cache strategy is to clear the cache on every macrotask.
|
|
128
|
-
* If the default cache is overwritten it is up to the user to determine when the
|
|
129
|
-
* cache is cleared.
|
|
130
|
-
*/
|
|
131
|
-
cache: new Map(),
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* A regexp or function that receives an import path that matches file types known to be client side assets.
|
|
135
|
-
*/
|
|
136
|
-
hydrateIncludeImports:
|
|
137
|
-
/\.(css|less|s[ac]ss|styl|png|jpe?g|gif|svg|ico|webp|avif|mp4|webm|ogg|mp3|wav|flac|aac|woff2?|eot|ttf|otf)$/,
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Set to true in order to bring in the hot module replacement runtime.
|
|
141
|
-
*/
|
|
142
|
-
hot: false
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
if (process.env.MARKO_CONFIG) {
|
|
146
|
-
Object.assign(config, JSON.parse(process.env.MARKO_CONFIG));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export default config;
|
|
150
|
-
|
|
151
|
-
import taglibConfig from "./taglib/config";
|
|
152
|
-
taglibConfig.fs = config.fileSystem;
|
package/src/index.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
export * as types from "./babel-types";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import * as babel from "@babel/core";
|
|
4
|
-
import cjsPlugin from "@babel/plugin-transform-modules-commonjs";
|
|
5
|
-
import tsSyntaxPlugin from "@babel/plugin-syntax-typescript";
|
|
6
|
-
import tsTransformPlugin from "@babel/plugin-transform-typescript";
|
|
7
|
-
import corePlugin from "./babel-plugin";
|
|
8
|
-
import defaultConfig from "./config";
|
|
9
|
-
import * as taglib from "./taglib";
|
|
10
|
-
import shouldOptimize from "./util/should-optimize";
|
|
11
|
-
import tryLoadTranslator from "./util/try-load-translator";
|
|
12
|
-
export { taglib };
|
|
13
|
-
|
|
14
|
-
let globalConfig = { ...defaultConfig };
|
|
15
|
-
export function configure(newConfig) {
|
|
16
|
-
globalConfig = { ...defaultConfig, ...newConfig };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export async function compile(src, filename, config) {
|
|
20
|
-
const babelConfig = loadBabelConfig(filename, config);
|
|
21
|
-
const babelResult = await babel.transformAsync(src, babelConfig);
|
|
22
|
-
scheduleDefaultClear(config);
|
|
23
|
-
return buildResult(babelResult);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function compileSync(src, filename, config) {
|
|
27
|
-
const babelConfig = loadBabelConfig(filename, config);
|
|
28
|
-
const babelResult = babel.transformSync(src, babelConfig);
|
|
29
|
-
scheduleDefaultClear(config);
|
|
30
|
-
return buildResult(babelResult);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export async function compileFile(filename, config) {
|
|
34
|
-
return new Promise((resolve, reject) => {
|
|
35
|
-
getFs(config).readFile(filename, "utf-8", (err, src) => {
|
|
36
|
-
if (err) {
|
|
37
|
-
return reject(err);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return resolve(compile(src, filename, config));
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function compileFileSync(filename, config) {
|
|
46
|
-
const src = getFs(config).readFileSync(filename, "utf-8");
|
|
47
|
-
return compileSync(src, filename, config);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getRuntimeEntryFiles(output, requestedTranslator) {
|
|
51
|
-
const translator = tryLoadTranslator(requestedTranslator);
|
|
52
|
-
if (translator && translator.getRuntimeEntryFiles) {
|
|
53
|
-
return translator.getRuntimeEntryFiles(output, shouldOptimize());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function loadBabelConfig(filename, config) {
|
|
60
|
-
const markoConfig = { ...globalConfig, ...config, babelConfig: undefined };
|
|
61
|
-
|
|
62
|
-
if (markoConfig.stripTypes === undefined) {
|
|
63
|
-
markoConfig.stripTypes =
|
|
64
|
-
markoConfig.output !== "source" && markoConfig.output !== "migrate";
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const requiredPlugins = [
|
|
68
|
-
[corePlugin, markoConfig],
|
|
69
|
-
[
|
|
70
|
-
markoConfig.stripTypes ? tsTransformPlugin : tsSyntaxPlugin,
|
|
71
|
-
{
|
|
72
|
-
isTSX: false,
|
|
73
|
-
allowNamespaces: true,
|
|
74
|
-
allowDeclareFields: true,
|
|
75
|
-
optimizeConstEnums: true,
|
|
76
|
-
onlyRemoveTypeImports: true,
|
|
77
|
-
disallowAmbiguousJSXLike: false
|
|
78
|
-
}
|
|
79
|
-
]
|
|
80
|
-
];
|
|
81
|
-
const baseBabelConfig = {
|
|
82
|
-
filenameRelative: filename
|
|
83
|
-
? path.relative(process.cwd(), filename)
|
|
84
|
-
: undefined,
|
|
85
|
-
sourceFileName: filename ? path.basename(filename) : undefined,
|
|
86
|
-
...(config && config.babelConfig),
|
|
87
|
-
filename,
|
|
88
|
-
sourceType: "module",
|
|
89
|
-
sourceMaps: markoConfig.sourceMaps,
|
|
90
|
-
code: markoConfig.code,
|
|
91
|
-
ast: markoConfig.ast
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
if (markoConfig.modules === "cjs") {
|
|
95
|
-
requiredPlugins.push([cjsPlugin, { loose: true }]);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
baseBabelConfig.plugins = requiredPlugins.concat(
|
|
99
|
-
baseBabelConfig.plugins || []
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
return babel.loadPartialConfig(baseBabelConfig).options;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function buildResult(babelResult) {
|
|
106
|
-
const {
|
|
107
|
-
ast,
|
|
108
|
-
map,
|
|
109
|
-
code,
|
|
110
|
-
metadata: { marko: meta }
|
|
111
|
-
} = babelResult;
|
|
112
|
-
return { ast, map, code, meta };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
let clearingDefaultCache = false;
|
|
116
|
-
function scheduleDefaultClear(config) {
|
|
117
|
-
if (
|
|
118
|
-
!clearingDefaultCache &&
|
|
119
|
-
(clearingDefaultCache = isDefaultCache(config))
|
|
120
|
-
) {
|
|
121
|
-
setImmediate(_clearDefaults);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function _clearDefaults() {
|
|
126
|
-
clearingDefaultCache = false;
|
|
127
|
-
globalConfig.cache.clear();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function isDefaultCache(config) {
|
|
131
|
-
return !config.cache || config.cache === globalConfig.cache;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function getFs(config) {
|
|
135
|
-
return config.fileSystem || globalConfig.fileSystem;
|
|
136
|
-
}
|
package/src/register.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const compiler = require(".");
|
|
4
|
-
const shouldOptimize = require("./util/should-optimize").default;
|
|
5
|
-
const requiredOptions = { modules: "cjs" };
|
|
6
|
-
const isDev = !shouldOptimize();
|
|
7
|
-
|
|
8
|
-
module.exports = register;
|
|
9
|
-
register();
|
|
10
|
-
|
|
11
|
-
function register({ extensions = require.extensions, ...options } = {}) {
|
|
12
|
-
extensions[".marko"] = (module, filename) =>
|
|
13
|
-
module._compile(
|
|
14
|
-
compiler.compileFileSync(
|
|
15
|
-
filename,
|
|
16
|
-
Object.assign(
|
|
17
|
-
{
|
|
18
|
-
meta: true,
|
|
19
|
-
hot: process.env.BROWSER_REFRESH_URL !== undefined,
|
|
20
|
-
// eslint-disable-next-line no-constant-condition
|
|
21
|
-
sourceMaps: isDev ? "inline" : false
|
|
22
|
-
},
|
|
23
|
-
options,
|
|
24
|
-
requiredOptions
|
|
25
|
-
)
|
|
26
|
-
).code,
|
|
27
|
-
filename
|
|
28
|
-
);
|
|
29
|
-
return extensions;
|
|
30
|
-
}
|