@marko/vite 3.1.3 → 3.1.5
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/dist/babel-plugin-cjs-interop.d.ts +31 -0
- package/dist/babel-plugin-cjs-interop.js +117 -0
- package/dist/babel-plugin-cjs-interop.mjs +7 -0
- package/dist/chunk-4NVOXZG5.mjs +93 -0
- package/dist/chunk-XYEU3RSG.mjs +61 -0
- package/dist/index.js +27 -26
- package/dist/index.mjs +38 -33
- package/dist/resolve.d.ts +2 -0
- package/dist/resolve.js +94 -0
- package/dist/resolve.mjs +8 -0
- package/dist/store/index.mjs +3 -3
- package/package.json +7 -3
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PluginObj } from "@babel/core";
|
|
2
|
+
/**
|
|
3
|
+
* This plugin is designed to transform imports within Marko files to interop between ESM and CJS.
|
|
4
|
+
* In Node, ESM files cannot reliably use named imports and default imports from CJS files.
|
|
5
|
+
* Additionally, modules which are transpiled from ESM to CJS will use a `__esModule` property to
|
|
6
|
+
* signal that the consuming ESM code should treat `exports.default` as the default import.
|
|
7
|
+
* This plugin only modifies imports it determined to be for CJS modules
|
|
8
|
+
*
|
|
9
|
+
* Examples
|
|
10
|
+
* 1. Source: ```import { bar as baz } from 'foo';```
|
|
11
|
+
* Becomes:```
|
|
12
|
+
* import _foo from 'foo';
|
|
13
|
+
* const { bar: baz } = _foo
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* 2. Source: ```import myFoo from 'foo';```
|
|
17
|
+
* Becomes: ```
|
|
18
|
+
* import * as _myFoo from 'foo';
|
|
19
|
+
* const myFoo = _myFoo?.__esModule ? _myFoo.default : _myFoo;
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* 3. Source: ```import foo, * as nsFoo from 'foo';```
|
|
23
|
+
* Becomes: ```
|
|
24
|
+
* import nsFoo from 'foo';
|
|
25
|
+
* const myFoo = nsFoo?.__esModule ? nsFoo.default : nsFoo
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export default function plugin(options: {
|
|
29
|
+
extensions: string[];
|
|
30
|
+
conditions: string[];
|
|
31
|
+
}): PluginObj;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var babel_plugin_cjs_interop_exports = {};
|
|
30
|
+
__export(babel_plugin_cjs_interop_exports, {
|
|
31
|
+
default: () => plugin
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(babel_plugin_cjs_interop_exports);
|
|
34
|
+
var t = __toESM(require("@babel/types"));
|
|
35
|
+
var import_resolve = require("./resolve");
|
|
36
|
+
function plugin(options) {
|
|
37
|
+
return {
|
|
38
|
+
name: "marko-import-interop",
|
|
39
|
+
visitor: {
|
|
40
|
+
ImportDeclaration(path) {
|
|
41
|
+
if (!path.node.specifiers.length || /\.(?:mjs|marko)$|\?/.test(path.node.source.value)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const resolved = (0, import_resolve.resolve)(
|
|
46
|
+
path.node.source.value,
|
|
47
|
+
path.hub.file.opts.filename,
|
|
48
|
+
options.extensions,
|
|
49
|
+
options.conditions
|
|
50
|
+
);
|
|
51
|
+
if (!/\.c?js$/.test(resolved) || !(0, import_resolve.isCJSModule)(resolved)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
} catch (_) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
let namespaceId;
|
|
58
|
+
let defaultImportId;
|
|
59
|
+
let imports;
|
|
60
|
+
for (const s of path.node.specifiers) {
|
|
61
|
+
if (t.isImportSpecifier(s)) {
|
|
62
|
+
(imports || (imports = [])).push({
|
|
63
|
+
name: t.isStringLiteral(s.imported) ? s.imported.value : s.imported.name,
|
|
64
|
+
alias: s.local.name
|
|
65
|
+
});
|
|
66
|
+
} else if (t.isImportDefaultSpecifier(s)) {
|
|
67
|
+
defaultImportId = s.local;
|
|
68
|
+
} else if (t.isImportNamespaceSpecifier(s)) {
|
|
69
|
+
namespaceId = s.local;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
namespaceId || (namespaceId = path.scope.generateUidIdentifier(
|
|
73
|
+
(defaultImportId == null ? void 0 : defaultImportId.name) || path.node.source.value
|
|
74
|
+
));
|
|
75
|
+
path.node.specifiers = [t.importDefaultSpecifier(namespaceId)];
|
|
76
|
+
if (defaultImportId) {
|
|
77
|
+
path.insertAfter(
|
|
78
|
+
t.variableDeclaration("const", [
|
|
79
|
+
t.variableDeclarator(
|
|
80
|
+
defaultImportId,
|
|
81
|
+
t.conditionalExpression(
|
|
82
|
+
t.optionalMemberExpression(
|
|
83
|
+
namespaceId,
|
|
84
|
+
t.identifier("__esModule"),
|
|
85
|
+
false,
|
|
86
|
+
true
|
|
87
|
+
),
|
|
88
|
+
t.memberExpression(namespaceId, t.identifier("default")),
|
|
89
|
+
namespaceId
|
|
90
|
+
)
|
|
91
|
+
)
|
|
92
|
+
])
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
if (imports) {
|
|
96
|
+
path.insertAfter(
|
|
97
|
+
t.variableDeclaration("const", [
|
|
98
|
+
t.variableDeclarator(
|
|
99
|
+
t.objectPattern(
|
|
100
|
+
imports.map(
|
|
101
|
+
({ name, alias }) => t.objectProperty(
|
|
102
|
+
t.identifier(name),
|
|
103
|
+
t.identifier(alias),
|
|
104
|
+
false,
|
|
105
|
+
name === alias
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
),
|
|
109
|
+
namespaceId
|
|
110
|
+
)
|
|
111
|
+
])
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isCJSModule,
|
|
3
|
+
resolve
|
|
4
|
+
} from "./chunk-XYEU3RSG.mjs";
|
|
5
|
+
|
|
6
|
+
// src/babel-plugin-cjs-interop.ts
|
|
7
|
+
import * as t from "@babel/types";
|
|
8
|
+
function plugin(options) {
|
|
9
|
+
return {
|
|
10
|
+
name: "marko-import-interop",
|
|
11
|
+
visitor: {
|
|
12
|
+
ImportDeclaration(path) {
|
|
13
|
+
if (!path.node.specifiers.length || /\.(?:mjs|marko)$|\?/.test(path.node.source.value)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const resolved = resolve(
|
|
18
|
+
path.node.source.value,
|
|
19
|
+
path.hub.file.opts.filename,
|
|
20
|
+
options.extensions,
|
|
21
|
+
options.conditions
|
|
22
|
+
);
|
|
23
|
+
if (!/\.c?js$/.test(resolved) || !isCJSModule(resolved)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
} catch (_) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let namespaceId;
|
|
30
|
+
let defaultImportId;
|
|
31
|
+
let imports;
|
|
32
|
+
for (const s of path.node.specifiers) {
|
|
33
|
+
if (t.isImportSpecifier(s)) {
|
|
34
|
+
(imports || (imports = [])).push({
|
|
35
|
+
name: t.isStringLiteral(s.imported) ? s.imported.value : s.imported.name,
|
|
36
|
+
alias: s.local.name
|
|
37
|
+
});
|
|
38
|
+
} else if (t.isImportDefaultSpecifier(s)) {
|
|
39
|
+
defaultImportId = s.local;
|
|
40
|
+
} else if (t.isImportNamespaceSpecifier(s)) {
|
|
41
|
+
namespaceId = s.local;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
namespaceId || (namespaceId = path.scope.generateUidIdentifier(
|
|
45
|
+
(defaultImportId == null ? void 0 : defaultImportId.name) || path.node.source.value
|
|
46
|
+
));
|
|
47
|
+
path.node.specifiers = [t.importDefaultSpecifier(namespaceId)];
|
|
48
|
+
if (defaultImportId) {
|
|
49
|
+
path.insertAfter(
|
|
50
|
+
t.variableDeclaration("const", [
|
|
51
|
+
t.variableDeclarator(
|
|
52
|
+
defaultImportId,
|
|
53
|
+
t.conditionalExpression(
|
|
54
|
+
t.optionalMemberExpression(
|
|
55
|
+
namespaceId,
|
|
56
|
+
t.identifier("__esModule"),
|
|
57
|
+
false,
|
|
58
|
+
true
|
|
59
|
+
),
|
|
60
|
+
t.memberExpression(namespaceId, t.identifier("default")),
|
|
61
|
+
namespaceId
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
])
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (imports) {
|
|
68
|
+
path.insertAfter(
|
|
69
|
+
t.variableDeclaration("const", [
|
|
70
|
+
t.variableDeclarator(
|
|
71
|
+
t.objectPattern(
|
|
72
|
+
imports.map(
|
|
73
|
+
({ name, alias }) => t.objectProperty(
|
|
74
|
+
t.identifier(name),
|
|
75
|
+
t.identifier(alias),
|
|
76
|
+
false,
|
|
77
|
+
name === alias
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
),
|
|
81
|
+
namespaceId
|
|
82
|
+
)
|
|
83
|
+
])
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export {
|
|
92
|
+
plugin
|
|
93
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/resolve.ts
|
|
2
|
+
import { exports } from "resolve.exports";
|
|
3
|
+
import * as Resolve from "resolve";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
var exportsMainFile = `__package_exports__`;
|
|
7
|
+
var modulePathReg = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/;
|
|
8
|
+
var cjsModuleLookup = /* @__PURE__ */ new Map();
|
|
9
|
+
function isCJSModule(id) {
|
|
10
|
+
var _a;
|
|
11
|
+
const modulePath = (_a = modulePathReg.exec(id)) == null ? void 0 : _a[0];
|
|
12
|
+
if (modulePath) {
|
|
13
|
+
const pkgPath = modulePath + "package.json";
|
|
14
|
+
let isCJS = cjsModuleLookup.get(pkgPath);
|
|
15
|
+
if (isCJS === void 0) {
|
|
16
|
+
try {
|
|
17
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
18
|
+
isCJS = pkg.type !== "module" && !pkg.exports;
|
|
19
|
+
} catch {
|
|
20
|
+
isCJS = false;
|
|
21
|
+
}
|
|
22
|
+
cjsModuleLookup.set(pkgPath, isCJS);
|
|
23
|
+
}
|
|
24
|
+
return isCJS;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
function resolve(id, from, extensions, conditions) {
|
|
29
|
+
return Resolve.sync(id, {
|
|
30
|
+
basedir: path.dirname(from),
|
|
31
|
+
filename: from,
|
|
32
|
+
pathFilter,
|
|
33
|
+
packageFilter,
|
|
34
|
+
extensions
|
|
35
|
+
});
|
|
36
|
+
function pathFilter(pkg, pkgFile, relativePath) {
|
|
37
|
+
var _a;
|
|
38
|
+
cjsModuleLookup.set(pkgFile, pkg.type !== "module" && !pkg.exports);
|
|
39
|
+
if (pkg.exports) {
|
|
40
|
+
return (_a = exports(
|
|
41
|
+
pkg,
|
|
42
|
+
relativePath === exportsMainFile ? "." : relativePath,
|
|
43
|
+
{
|
|
44
|
+
conditions
|
|
45
|
+
}
|
|
46
|
+
)) == null ? void 0 : _a[0];
|
|
47
|
+
}
|
|
48
|
+
return relativePath;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function packageFilter(pkg) {
|
|
52
|
+
if (pkg.exports) {
|
|
53
|
+
pkg.main = exportsMainFile;
|
|
54
|
+
}
|
|
55
|
+
return pkg;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
isCJSModule,
|
|
60
|
+
resolve
|
|
61
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -41,13 +41,15 @@ var import_server_entry_template = __toESM(require("./server-entry-template"));
|
|
|
41
41
|
var import_manifest_generator = require("./manifest-generator");
|
|
42
42
|
var import_esbuild_plugin = __toESM(require("./esbuild-plugin"));
|
|
43
43
|
var import_store = require("./store");
|
|
44
|
+
var import_babel_plugin_cjs_interop = __toESM(require("./babel-plugin-cjs-interop"));
|
|
45
|
+
var import_resolve = require("./resolve");
|
|
44
46
|
__reExport(src_exports, require("./store"), module.exports);
|
|
45
47
|
const import_meta = {};
|
|
46
48
|
const POSIX_SEP = "/";
|
|
47
49
|
const WINDOWS_SEP = "\\";
|
|
48
50
|
const normalizePath = import_path.default.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
49
51
|
const virtualFiles = /* @__PURE__ */ new Map();
|
|
50
|
-
const queryReg = /\?marko
|
|
52
|
+
const queryReg = /\?marko-[^?]+$/;
|
|
51
53
|
const browserEntryQuery = "?marko-browser-entry";
|
|
52
54
|
const serverEntryQuery = "?marko-server-entry";
|
|
53
55
|
const virtualFileQuery = "?marko-virtual";
|
|
@@ -73,13 +75,12 @@ function markoPlugin(opts = {}) {
|
|
|
73
75
|
let basePathVar;
|
|
74
76
|
let baseConfig;
|
|
75
77
|
let ssrConfig;
|
|
78
|
+
let ssrCjsConfig;
|
|
76
79
|
let domConfig;
|
|
77
80
|
let hydrateConfig;
|
|
78
81
|
const resolveVirtualDependency = (from, dep) => {
|
|
79
|
-
const query = `${virtualFileQuery}&id=${encodeURIComponent(
|
|
80
|
-
normalizePath(dep.virtualPath)
|
|
81
|
-
)}`;
|
|
82
82
|
const normalizedFrom = normalizePath(from);
|
|
83
|
+
const query = `${virtualFileQuery}&id=${Buffer.from(dep.virtualPath).toString("base64url") + import_path.default.extname(dep.virtualPath)}`;
|
|
83
84
|
const id = normalizePath(normalizedFrom) + query;
|
|
84
85
|
if (devServer) {
|
|
85
86
|
const prev = virtualFiles.get(id);
|
|
@@ -249,6 +250,19 @@ function markoPlugin(opts = {}) {
|
|
|
249
250
|
},
|
|
250
251
|
configResolved(config) {
|
|
251
252
|
basePath = config.base;
|
|
253
|
+
ssrCjsConfig = {
|
|
254
|
+
...ssrConfig,
|
|
255
|
+
//modules: 'cjs'
|
|
256
|
+
babelConfig: {
|
|
257
|
+
...ssrConfig.babelConfig,
|
|
258
|
+
plugins: (ssrConfig.babelConfig.plugins || []).concat(
|
|
259
|
+
(0, import_babel_plugin_cjs_interop.default)({
|
|
260
|
+
extensions: config.resolve.extensions,
|
|
261
|
+
conditions: config.resolve.conditions
|
|
262
|
+
})
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
};
|
|
252
266
|
},
|
|
253
267
|
configureServer(_server) {
|
|
254
268
|
ssrConfig.hot = domConfig.hot = true;
|
|
@@ -415,8 +429,15 @@ function markoPlugin(opts = {}) {
|
|
|
415
429
|
if (linked) {
|
|
416
430
|
cachedSources.set(id, source);
|
|
417
431
|
}
|
|
418
|
-
if (!query) {
|
|
419
|
-
if (
|
|
432
|
+
if (!query && (0, import_resolve.isCJSModule)(id)) {
|
|
433
|
+
if (isBuild) {
|
|
434
|
+
const { code: code2, map: map2 } = await compiler.compile(
|
|
435
|
+
source,
|
|
436
|
+
id,
|
|
437
|
+
ssrCjsConfig
|
|
438
|
+
);
|
|
439
|
+
return { code: code2, map: map2, meta: { source } };
|
|
440
|
+
} else {
|
|
420
441
|
const { ast } = await compiler.compile(source, id, {
|
|
421
442
|
cache,
|
|
422
443
|
ast: true,
|
|
@@ -650,26 +671,6 @@ function isEmpty(obj) {
|
|
|
650
671
|
}
|
|
651
672
|
return true;
|
|
652
673
|
}
|
|
653
|
-
const cjsModuleLookup = /* @__PURE__ */ new Map();
|
|
654
|
-
function isCJSModule(id) {
|
|
655
|
-
var _a;
|
|
656
|
-
const modulePath = (_a = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/.exec(id)) == null ? void 0 : _a[0];
|
|
657
|
-
if (modulePath) {
|
|
658
|
-
let isCJS = cjsModuleLookup.get(modulePath);
|
|
659
|
-
if (isCJS === void 0) {
|
|
660
|
-
const pkgPath = modulePath + "package.json";
|
|
661
|
-
try {
|
|
662
|
-
const pkg = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf8"));
|
|
663
|
-
isCJS = pkg.type !== "module" && !pkg.exports;
|
|
664
|
-
} catch {
|
|
665
|
-
isCJS = false;
|
|
666
|
-
}
|
|
667
|
-
cjsModuleLookup.set(modulePath, isCJS);
|
|
668
|
-
}
|
|
669
|
-
return isCJS;
|
|
670
|
-
}
|
|
671
|
-
return false;
|
|
672
|
-
}
|
|
673
674
|
function stripVersionAndTimeStamp(id) {
|
|
674
675
|
const queryStart = id.indexOf("?");
|
|
675
676
|
if (queryStart === -1)
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import "./chunk-KIYHBIE6.mjs";
|
|
2
|
+
import {
|
|
3
|
+
FileStore
|
|
4
|
+
} from "./chunk-FCWFM7VD.mjs";
|
|
5
|
+
import {
|
|
6
|
+
MemoryStore
|
|
7
|
+
} from "./chunk-DCBMHGK4.mjs";
|
|
8
|
+
import {
|
|
9
|
+
plugin
|
|
10
|
+
} from "./chunk-4NVOXZG5.mjs";
|
|
1
11
|
import {
|
|
2
12
|
esbuildPlugin
|
|
3
13
|
} from "./chunk-HR4PYNIR.mjs";
|
|
@@ -5,17 +15,13 @@ import {
|
|
|
5
15
|
generateDocManifest,
|
|
6
16
|
generateInputDoc
|
|
7
17
|
} from "./chunk-2E5QX7AF.mjs";
|
|
18
|
+
import {
|
|
19
|
+
isCJSModule
|
|
20
|
+
} from "./chunk-XYEU3RSG.mjs";
|
|
8
21
|
import "./chunk-NTHVNXFC.mjs";
|
|
9
22
|
import {
|
|
10
23
|
server_entry_template_default
|
|
11
24
|
} from "./chunk-6IJ5UJ3N.mjs";
|
|
12
|
-
import "./chunk-KIYHBIE6.mjs";
|
|
13
|
-
import {
|
|
14
|
-
MemoryStore
|
|
15
|
-
} from "./chunk-DCBMHGK4.mjs";
|
|
16
|
-
import {
|
|
17
|
-
FileStore
|
|
18
|
-
} from "./chunk-FCWFM7VD.mjs";
|
|
19
25
|
|
|
20
26
|
// src/index.ts
|
|
21
27
|
import fs from "fs";
|
|
@@ -27,7 +33,7 @@ var POSIX_SEP = "/";
|
|
|
27
33
|
var WINDOWS_SEP = "\\";
|
|
28
34
|
var normalizePath = path.sep === WINDOWS_SEP ? (id) => id.replace(/\\/g, POSIX_SEP) : (id) => id;
|
|
29
35
|
var virtualFiles = /* @__PURE__ */ new Map();
|
|
30
|
-
var queryReg = /\?marko
|
|
36
|
+
var queryReg = /\?marko-[^?]+$/;
|
|
31
37
|
var browserEntryQuery = "?marko-browser-entry";
|
|
32
38
|
var serverEntryQuery = "?marko-server-entry";
|
|
33
39
|
var virtualFileQuery = "?marko-virtual";
|
|
@@ -53,13 +59,12 @@ function markoPlugin(opts = {}) {
|
|
|
53
59
|
let basePathVar;
|
|
54
60
|
let baseConfig;
|
|
55
61
|
let ssrConfig;
|
|
62
|
+
let ssrCjsConfig;
|
|
56
63
|
let domConfig;
|
|
57
64
|
let hydrateConfig;
|
|
58
65
|
const resolveVirtualDependency = (from, dep) => {
|
|
59
|
-
const query = `${virtualFileQuery}&id=${encodeURIComponent(
|
|
60
|
-
normalizePath(dep.virtualPath)
|
|
61
|
-
)}`;
|
|
62
66
|
const normalizedFrom = normalizePath(from);
|
|
67
|
+
const query = `${virtualFileQuery}&id=${Buffer.from(dep.virtualPath).toString("base64url") + path.extname(dep.virtualPath)}`;
|
|
63
68
|
const id = normalizePath(normalizedFrom) + query;
|
|
64
69
|
if (devServer) {
|
|
65
70
|
const prev = virtualFiles.get(id);
|
|
@@ -229,6 +234,19 @@ function markoPlugin(opts = {}) {
|
|
|
229
234
|
},
|
|
230
235
|
configResolved(config) {
|
|
231
236
|
basePath = config.base;
|
|
237
|
+
ssrCjsConfig = {
|
|
238
|
+
...ssrConfig,
|
|
239
|
+
//modules: 'cjs'
|
|
240
|
+
babelConfig: {
|
|
241
|
+
...ssrConfig.babelConfig,
|
|
242
|
+
plugins: (ssrConfig.babelConfig.plugins || []).concat(
|
|
243
|
+
plugin({
|
|
244
|
+
extensions: config.resolve.extensions,
|
|
245
|
+
conditions: config.resolve.conditions
|
|
246
|
+
})
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
};
|
|
232
250
|
},
|
|
233
251
|
configureServer(_server) {
|
|
234
252
|
ssrConfig.hot = domConfig.hot = true;
|
|
@@ -395,8 +413,15 @@ function markoPlugin(opts = {}) {
|
|
|
395
413
|
if (linked) {
|
|
396
414
|
cachedSources.set(id, source);
|
|
397
415
|
}
|
|
398
|
-
if (!query) {
|
|
399
|
-
if (
|
|
416
|
+
if (!query && isCJSModule(id)) {
|
|
417
|
+
if (isBuild) {
|
|
418
|
+
const { code: code2, map: map2 } = await compiler.compile(
|
|
419
|
+
source,
|
|
420
|
+
id,
|
|
421
|
+
ssrCjsConfig
|
|
422
|
+
);
|
|
423
|
+
return { code: code2, map: map2, meta: { source } };
|
|
424
|
+
} else {
|
|
400
425
|
const { ast } = await compiler.compile(source, id, {
|
|
401
426
|
cache,
|
|
402
427
|
ast: true,
|
|
@@ -630,26 +655,6 @@ function isEmpty(obj) {
|
|
|
630
655
|
}
|
|
631
656
|
return true;
|
|
632
657
|
}
|
|
633
|
-
var cjsModuleLookup = /* @__PURE__ */ new Map();
|
|
634
|
-
function isCJSModule(id) {
|
|
635
|
-
var _a;
|
|
636
|
-
const modulePath = (_a = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/.exec(id)) == null ? void 0 : _a[0];
|
|
637
|
-
if (modulePath) {
|
|
638
|
-
let isCJS = cjsModuleLookup.get(modulePath);
|
|
639
|
-
if (isCJS === void 0) {
|
|
640
|
-
const pkgPath = modulePath + "package.json";
|
|
641
|
-
try {
|
|
642
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
643
|
-
isCJS = pkg.type !== "module" && !pkg.exports;
|
|
644
|
-
} catch {
|
|
645
|
-
isCJS = false;
|
|
646
|
-
}
|
|
647
|
-
cjsModuleLookup.set(modulePath, isCJS);
|
|
648
|
-
}
|
|
649
|
-
return isCJS;
|
|
650
|
-
}
|
|
651
|
-
return false;
|
|
652
|
-
}
|
|
653
658
|
function stripVersionAndTimeStamp(id) {
|
|
654
659
|
const queryStart = id.indexOf("?");
|
|
655
660
|
if (queryStart === -1)
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var resolve_exports = {};
|
|
30
|
+
__export(resolve_exports, {
|
|
31
|
+
isCJSModule: () => isCJSModule,
|
|
32
|
+
resolve: () => resolve
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(resolve_exports);
|
|
35
|
+
var import_resolve = require("resolve.exports");
|
|
36
|
+
var Resolve = __toESM(require("resolve"));
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_fs = __toESM(require("fs"));
|
|
39
|
+
const exportsMainFile = `__package_exports__`;
|
|
40
|
+
const modulePathReg = /^.*[/\\]node_modules[/\\](?:@[^/\\]+[/\\])?[^/\\]+[/\\]/;
|
|
41
|
+
const cjsModuleLookup = /* @__PURE__ */ new Map();
|
|
42
|
+
function isCJSModule(id) {
|
|
43
|
+
var _a;
|
|
44
|
+
const modulePath = (_a = modulePathReg.exec(id)) == null ? void 0 : _a[0];
|
|
45
|
+
if (modulePath) {
|
|
46
|
+
const pkgPath = modulePath + "package.json";
|
|
47
|
+
let isCJS = cjsModuleLookup.get(pkgPath);
|
|
48
|
+
if (isCJS === void 0) {
|
|
49
|
+
try {
|
|
50
|
+
const pkg = JSON.parse(import_fs.default.readFileSync(pkgPath, "utf8"));
|
|
51
|
+
isCJS = pkg.type !== "module" && !pkg.exports;
|
|
52
|
+
} catch {
|
|
53
|
+
isCJS = false;
|
|
54
|
+
}
|
|
55
|
+
cjsModuleLookup.set(pkgPath, isCJS);
|
|
56
|
+
}
|
|
57
|
+
return isCJS;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
function resolve(id, from, extensions, conditions) {
|
|
62
|
+
return Resolve.sync(id, {
|
|
63
|
+
basedir: import_path.default.dirname(from),
|
|
64
|
+
filename: from,
|
|
65
|
+
pathFilter,
|
|
66
|
+
packageFilter,
|
|
67
|
+
extensions
|
|
68
|
+
});
|
|
69
|
+
function pathFilter(pkg, pkgFile, relativePath) {
|
|
70
|
+
var _a;
|
|
71
|
+
cjsModuleLookup.set(pkgFile, pkg.type !== "module" && !pkg.exports);
|
|
72
|
+
if (pkg.exports) {
|
|
73
|
+
return (_a = (0, import_resolve.exports)(
|
|
74
|
+
pkg,
|
|
75
|
+
relativePath === exportsMainFile ? "." : relativePath,
|
|
76
|
+
{
|
|
77
|
+
conditions
|
|
78
|
+
}
|
|
79
|
+
)) == null ? void 0 : _a[0];
|
|
80
|
+
}
|
|
81
|
+
return relativePath;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function packageFilter(pkg) {
|
|
85
|
+
if (pkg.exports) {
|
|
86
|
+
pkg.main = exportsMainFile;
|
|
87
|
+
}
|
|
88
|
+
return pkg;
|
|
89
|
+
}
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
isCJSModule,
|
|
93
|
+
resolve
|
|
94
|
+
});
|
package/dist/resolve.mjs
ADDED
package/dist/store/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@marko/vite",
|
|
3
3
|
"description": "A Marko plugin for Vite",
|
|
4
|
-
"version": "3.1.
|
|
4
|
+
"version": "3.1.5",
|
|
5
5
|
"author": "Dylan Piercey <dpiercey@ebay.com>",
|
|
6
6
|
"bugs": "https://github.com/marko-js/vite/issues",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"anymatch": "^3.1.3",
|
|
9
9
|
"domelementtype": "^2.3.0",
|
|
10
10
|
"domhandler": "^5.0.3",
|
|
11
|
-
"htmlparser2": "^9.0.0"
|
|
11
|
+
"htmlparser2": "^9.0.0",
|
|
12
|
+
"resolve": "^1.22.8",
|
|
13
|
+
"resolve.exports": "^2.0.2"
|
|
12
14
|
},
|
|
13
15
|
"devDependencies": {
|
|
14
16
|
"@changesets/changelog-github": "^0.4.8",
|
|
@@ -16,9 +18,11 @@
|
|
|
16
18
|
"@marko/compiler": "^5.33.2",
|
|
17
19
|
"@marko/fixture-snapshots": "^2.2.1",
|
|
18
20
|
"@marko/testing-library": "^6.1.4",
|
|
21
|
+
"@types/babel__core": "^7.20.3",
|
|
19
22
|
"@types/jsdom": "^21.1.3",
|
|
20
23
|
"@types/mocha": "^10.0.2",
|
|
21
24
|
"@types/node": "^20.8.2",
|
|
25
|
+
"@types/resolve": "^1.20.4",
|
|
22
26
|
"@types/serve-handler": "^6.1.2",
|
|
23
27
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
24
28
|
"@typescript-eslint/parser": "^6.7.4",
|
|
@@ -38,7 +42,7 @@
|
|
|
38
42
|
"playwright": "^1.38.1",
|
|
39
43
|
"prettier": "^2.8.8",
|
|
40
44
|
"serve-handler": "^6.1.5",
|
|
41
|
-
"tsx": "^3.
|
|
45
|
+
"tsx": "^3.14.0",
|
|
42
46
|
"typescript": "^5.2.2",
|
|
43
47
|
"vite": "^4.4.11"
|
|
44
48
|
},
|