vite-node 0.9.4 → 0.10.2
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/cli.cjs +3 -3
- package/dist/cli.js +3 -3
- package/dist/client-b20a0596.js +214 -0
- package/dist/client-e24a0d42.js +240 -0
- package/dist/client.cjs +10 -233
- package/dist/client.js +7 -212
- package/dist/server-4791181c.js +195 -0
- package/dist/server-d9fc65e0.js +191 -0
- package/dist/server.cjs +8 -190
- package/dist/server.js +5 -191
- package/dist/utils-0290448b.js +39 -0
- package/dist/utils-5d86aff6.js +47 -0
- package/dist/utils.cjs +10 -42
- package/dist/utils.js +3 -39
- package/package.json +3 -4
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { join } from 'pathe';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
3
|
+
import { isNodeBuiltin, isValidNodeImport } from 'mlly';
|
|
4
|
+
import { s as slash, t as toFilePath, w as withInlineSourcemap } from './utils-0290448b.js';
|
|
5
|
+
|
|
6
|
+
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
|
|
7
|
+
const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
|
|
8
|
+
const defaultInline = [
|
|
9
|
+
/virtual:/,
|
|
10
|
+
/\.ts$/
|
|
11
|
+
];
|
|
12
|
+
const depsExternal = [
|
|
13
|
+
/\.cjs\.js$/,
|
|
14
|
+
/\.mjs$/
|
|
15
|
+
];
|
|
16
|
+
function guessCJSversion(id) {
|
|
17
|
+
if (id.match(ESM_EXT_RE)) {
|
|
18
|
+
for (const i of [
|
|
19
|
+
id.replace(ESM_EXT_RE, ".mjs"),
|
|
20
|
+
id.replace(ESM_EXT_RE, ".umd.js"),
|
|
21
|
+
id.replace(ESM_EXT_RE, ".cjs.js"),
|
|
22
|
+
id.replace(ESM_EXT_RE, ".js")
|
|
23
|
+
]) {
|
|
24
|
+
if (existsSync(i))
|
|
25
|
+
return i;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (id.match(ESM_FOLDER_RE)) {
|
|
29
|
+
for (const i of [
|
|
30
|
+
id.replace(ESM_FOLDER_RE, "/umd/$1"),
|
|
31
|
+
id.replace(ESM_FOLDER_RE, "/cjs/$1"),
|
|
32
|
+
id.replace(ESM_FOLDER_RE, "/$1")
|
|
33
|
+
]) {
|
|
34
|
+
if (existsSync(i))
|
|
35
|
+
return i;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
|
|
40
|
+
if (!cache.has(id))
|
|
41
|
+
cache.set(id, _shouldExternalize(id, options));
|
|
42
|
+
return cache.get(id);
|
|
43
|
+
}
|
|
44
|
+
async function _shouldExternalize(id, options) {
|
|
45
|
+
if (isNodeBuiltin(id))
|
|
46
|
+
return id;
|
|
47
|
+
if (id.startsWith("data:"))
|
|
48
|
+
return id;
|
|
49
|
+
id = patchWindowsImportPath(id);
|
|
50
|
+
if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
|
|
51
|
+
return false;
|
|
52
|
+
if (matchExternalizePattern(id, options == null ? void 0 : options.external))
|
|
53
|
+
return id;
|
|
54
|
+
const isNodeModule = id.includes("/node_modules/");
|
|
55
|
+
const guessCJS = isNodeModule && (options == null ? void 0 : options.fallbackCJS);
|
|
56
|
+
id = guessCJS ? guessCJSversion(id) || id : id;
|
|
57
|
+
if (matchExternalizePattern(id, defaultInline))
|
|
58
|
+
return false;
|
|
59
|
+
if (matchExternalizePattern(id, depsExternal))
|
|
60
|
+
return id;
|
|
61
|
+
const isDist = id.includes("/dist/");
|
|
62
|
+
if ((isNodeModule || isDist) && await isValidNodeImport(id))
|
|
63
|
+
return id;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
function matchExternalizePattern(id, patterns) {
|
|
67
|
+
if (!patterns)
|
|
68
|
+
return false;
|
|
69
|
+
for (const ex of patterns) {
|
|
70
|
+
if (typeof ex === "string") {
|
|
71
|
+
if (id.includes(`/node_modules/${ex}/`))
|
|
72
|
+
return true;
|
|
73
|
+
} else {
|
|
74
|
+
if (ex.test(id))
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
function patchWindowsImportPath(path) {
|
|
81
|
+
if (path.match(/^\w:\\/))
|
|
82
|
+
return `file:///${slash(path)}`;
|
|
83
|
+
else if (path.match(/^\w:\//))
|
|
84
|
+
return `file:///${path}`;
|
|
85
|
+
else
|
|
86
|
+
return path;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var __defProp = Object.defineProperty;
|
|
90
|
+
var __defProps = Object.defineProperties;
|
|
91
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
92
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
93
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
94
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
95
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
96
|
+
var __spreadValues = (a, b) => {
|
|
97
|
+
for (var prop in b || (b = {}))
|
|
98
|
+
if (__hasOwnProp.call(b, prop))
|
|
99
|
+
__defNormalProp(a, prop, b[prop]);
|
|
100
|
+
if (__getOwnPropSymbols)
|
|
101
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
102
|
+
if (__propIsEnum.call(b, prop))
|
|
103
|
+
__defNormalProp(a, prop, b[prop]);
|
|
104
|
+
}
|
|
105
|
+
return a;
|
|
106
|
+
};
|
|
107
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
108
|
+
const RealDate = Date;
|
|
109
|
+
class ViteNodeServer {
|
|
110
|
+
constructor(server, options = {}) {
|
|
111
|
+
this.server = server;
|
|
112
|
+
this.options = options;
|
|
113
|
+
this.fetchPromiseMap = /* @__PURE__ */ new Map();
|
|
114
|
+
this.transformPromiseMap = /* @__PURE__ */ new Map();
|
|
115
|
+
this.fetchCache = /* @__PURE__ */ new Map();
|
|
116
|
+
}
|
|
117
|
+
shouldExternalize(id) {
|
|
118
|
+
return shouldExternalize(id, this.options.deps);
|
|
119
|
+
}
|
|
120
|
+
async resolveId(id, importer) {
|
|
121
|
+
if (importer && !importer.startsWith(this.server.config.root))
|
|
122
|
+
importer = join(this.server.config.root, importer);
|
|
123
|
+
return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
|
|
124
|
+
}
|
|
125
|
+
async fetchModule(id) {
|
|
126
|
+
if (!this.fetchPromiseMap.has(id)) {
|
|
127
|
+
this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
|
|
128
|
+
return this.options.sourcemap !== true ? __spreadProps(__spreadValues({}, r), { map: void 0 }) : r;
|
|
129
|
+
}).finally(() => {
|
|
130
|
+
this.fetchPromiseMap.delete(id);
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
return this.fetchPromiseMap.get(id);
|
|
134
|
+
}
|
|
135
|
+
async transformRequest(id) {
|
|
136
|
+
if (!this.transformPromiseMap.has(id)) {
|
|
137
|
+
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
|
|
138
|
+
this.transformPromiseMap.delete(id);
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
return this.transformPromiseMap.get(id);
|
|
142
|
+
}
|
|
143
|
+
getTransformMode(id) {
|
|
144
|
+
var _a, _b, _c, _d;
|
|
145
|
+
const withoutQuery = id.split("?")[0];
|
|
146
|
+
if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r)))
|
|
147
|
+
return "web";
|
|
148
|
+
if ((_d = (_c = this.options.transformMode) == null ? void 0 : _c.ssr) == null ? void 0 : _d.some((r) => withoutQuery.match(r)))
|
|
149
|
+
return "ssr";
|
|
150
|
+
if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/))
|
|
151
|
+
return "ssr";
|
|
152
|
+
return "web";
|
|
153
|
+
}
|
|
154
|
+
async _fetchModule(id) {
|
|
155
|
+
let result;
|
|
156
|
+
const filePath = toFilePath(id, this.server.config.root);
|
|
157
|
+
const module = this.server.moduleGraph.getModuleById(id);
|
|
158
|
+
const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || RealDate.now();
|
|
159
|
+
const cache = this.fetchCache.get(filePath);
|
|
160
|
+
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
161
|
+
return cache.result;
|
|
162
|
+
const externalize = await this.shouldExternalize(filePath);
|
|
163
|
+
if (externalize) {
|
|
164
|
+
result = { externalize };
|
|
165
|
+
} else {
|
|
166
|
+
const r = await this._transformRequest(id);
|
|
167
|
+
result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
|
|
168
|
+
}
|
|
169
|
+
this.fetchCache.set(filePath, {
|
|
170
|
+
timestamp,
|
|
171
|
+
result
|
|
172
|
+
});
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
async _transformRequest(id) {
|
|
176
|
+
let result = null;
|
|
177
|
+
if (this.getTransformMode(id) === "web") {
|
|
178
|
+
result = await this.server.transformRequest(id);
|
|
179
|
+
if (result)
|
|
180
|
+
result = await this.server.ssrTransform(result.code, result.map, id);
|
|
181
|
+
} else {
|
|
182
|
+
result = await this.server.transformRequest(id, { ssr: true });
|
|
183
|
+
}
|
|
184
|
+
const sourcemap = this.options.sourcemap ?? "inline";
|
|
185
|
+
if (sourcemap === "inline" && result && !id.includes("node_modules"))
|
|
186
|
+
withInlineSourcemap(result);
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export { ViteNodeServer as V, guessCJSversion as g, shouldExternalize as s };
|
package/dist/server.cjs
CHANGED
|
@@ -2,197 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
var server = require('./server-4791181c.js');
|
|
6
|
+
require('pathe');
|
|
7
|
+
require('fs');
|
|
8
|
+
require('mlly');
|
|
9
|
+
require('./utils-5d86aff6.js');
|
|
9
10
|
require('url');
|
|
10
11
|
|
|
11
|
-
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
|
|
12
|
-
const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
|
|
13
|
-
const defaultInline = [
|
|
14
|
-
/virtual:/,
|
|
15
|
-
/\.ts$/
|
|
16
|
-
];
|
|
17
|
-
const depsExternal = [
|
|
18
|
-
/\.cjs\.js$/,
|
|
19
|
-
/\.mjs$/
|
|
20
|
-
];
|
|
21
|
-
function guessCJSversion(id) {
|
|
22
|
-
if (id.match(ESM_EXT_RE)) {
|
|
23
|
-
for (const i of [
|
|
24
|
-
id.replace(ESM_EXT_RE, ".mjs"),
|
|
25
|
-
id.replace(ESM_EXT_RE, ".umd.js"),
|
|
26
|
-
id.replace(ESM_EXT_RE, ".cjs.js"),
|
|
27
|
-
id.replace(ESM_EXT_RE, ".js")
|
|
28
|
-
]) {
|
|
29
|
-
if (fs.existsSync(i))
|
|
30
|
-
return i;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (id.match(ESM_FOLDER_RE)) {
|
|
34
|
-
for (const i of [
|
|
35
|
-
id.replace(ESM_FOLDER_RE, "/umd/$1"),
|
|
36
|
-
id.replace(ESM_FOLDER_RE, "/cjs/$1"),
|
|
37
|
-
id.replace(ESM_FOLDER_RE, "/$1")
|
|
38
|
-
]) {
|
|
39
|
-
if (fs.existsSync(i))
|
|
40
|
-
return i;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
|
|
45
|
-
if (!cache.has(id))
|
|
46
|
-
cache.set(id, _shouldExternalize(id, options));
|
|
47
|
-
return cache.get(id);
|
|
48
|
-
}
|
|
49
|
-
async function _shouldExternalize(id, options) {
|
|
50
|
-
if (mlly.isNodeBuiltin(id))
|
|
51
|
-
return id;
|
|
52
|
-
if (id.startsWith("data:"))
|
|
53
|
-
return id;
|
|
54
|
-
id = patchWindowsImportPath(id);
|
|
55
|
-
if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
|
|
56
|
-
return false;
|
|
57
|
-
if (matchExternalizePattern(id, options == null ? void 0 : options.external))
|
|
58
|
-
return id;
|
|
59
|
-
const isNodeModule = id.includes("/node_modules/");
|
|
60
|
-
const guessCJS = isNodeModule && (options == null ? void 0 : options.fallbackCJS);
|
|
61
|
-
id = guessCJS ? guessCJSversion(id) || id : id;
|
|
62
|
-
if (matchExternalizePattern(id, defaultInline))
|
|
63
|
-
return false;
|
|
64
|
-
if (matchExternalizePattern(id, depsExternal))
|
|
65
|
-
return id;
|
|
66
|
-
const isDist = id.includes("/dist/");
|
|
67
|
-
if ((isNodeModule || isDist) && await mlly.isValidNodeImport(id))
|
|
68
|
-
return id;
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
function matchExternalizePattern(id, patterns) {
|
|
72
|
-
if (!patterns)
|
|
73
|
-
return false;
|
|
74
|
-
for (const ex of patterns) {
|
|
75
|
-
if (typeof ex === "string") {
|
|
76
|
-
if (id.includes(`/node_modules/${ex}/`))
|
|
77
|
-
return true;
|
|
78
|
-
} else {
|
|
79
|
-
if (ex.test(id))
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
function patchWindowsImportPath(path) {
|
|
86
|
-
if (path.match(/^\w:\\/))
|
|
87
|
-
return `file:///${utils.slash(path)}`;
|
|
88
|
-
else if (path.match(/^\w:\//))
|
|
89
|
-
return `file:///${path}`;
|
|
90
|
-
else
|
|
91
|
-
return path;
|
|
92
|
-
}
|
|
93
12
|
|
|
94
|
-
var __defProp = Object.defineProperty;
|
|
95
|
-
var __defProps = Object.defineProperties;
|
|
96
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
97
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
98
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
99
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
100
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
101
|
-
var __spreadValues = (a, b) => {
|
|
102
|
-
for (var prop in b || (b = {}))
|
|
103
|
-
if (__hasOwnProp.call(b, prop))
|
|
104
|
-
__defNormalProp(a, prop, b[prop]);
|
|
105
|
-
if (__getOwnPropSymbols)
|
|
106
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
107
|
-
if (__propIsEnum.call(b, prop))
|
|
108
|
-
__defNormalProp(a, prop, b[prop]);
|
|
109
|
-
}
|
|
110
|
-
return a;
|
|
111
|
-
};
|
|
112
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
113
|
-
const RealDate = Date;
|
|
114
|
-
class ViteNodeServer {
|
|
115
|
-
constructor(server, options = {}) {
|
|
116
|
-
this.server = server;
|
|
117
|
-
this.options = options;
|
|
118
|
-
this.fetchPromiseMap = /* @__PURE__ */ new Map();
|
|
119
|
-
this.transformPromiseMap = /* @__PURE__ */ new Map();
|
|
120
|
-
this.fetchCache = /* @__PURE__ */ new Map();
|
|
121
|
-
}
|
|
122
|
-
shouldExternalize(id) {
|
|
123
|
-
return shouldExternalize(id, this.options.deps);
|
|
124
|
-
}
|
|
125
|
-
async resolveId(id, importer) {
|
|
126
|
-
if (importer && !importer.startsWith(this.server.config.root))
|
|
127
|
-
importer = pathe.join(this.server.config.root, importer);
|
|
128
|
-
return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
|
|
129
|
-
}
|
|
130
|
-
async fetchModule(id) {
|
|
131
|
-
if (!this.fetchPromiseMap.has(id)) {
|
|
132
|
-
this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
|
|
133
|
-
return this.options.sourcemap !== true ? __spreadProps(__spreadValues({}, r), { map: void 0 }) : r;
|
|
134
|
-
}).finally(() => {
|
|
135
|
-
this.fetchPromiseMap.delete(id);
|
|
136
|
-
}));
|
|
137
|
-
}
|
|
138
|
-
return this.fetchPromiseMap.get(id);
|
|
139
|
-
}
|
|
140
|
-
async transformRequest(id) {
|
|
141
|
-
if (!this.transformPromiseMap.has(id)) {
|
|
142
|
-
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
|
|
143
|
-
this.transformPromiseMap.delete(id);
|
|
144
|
-
}));
|
|
145
|
-
}
|
|
146
|
-
return this.transformPromiseMap.get(id);
|
|
147
|
-
}
|
|
148
|
-
getTransformMode(id) {
|
|
149
|
-
var _a, _b, _c, _d;
|
|
150
|
-
const withoutQuery = id.split("?")[0];
|
|
151
|
-
if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r)))
|
|
152
|
-
return "web";
|
|
153
|
-
if ((_d = (_c = this.options.transformMode) == null ? void 0 : _c.ssr) == null ? void 0 : _d.some((r) => withoutQuery.match(r)))
|
|
154
|
-
return "ssr";
|
|
155
|
-
if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/))
|
|
156
|
-
return "ssr";
|
|
157
|
-
return "web";
|
|
158
|
-
}
|
|
159
|
-
async _fetchModule(id) {
|
|
160
|
-
let result;
|
|
161
|
-
const filePath = utils.toFilePath(id, this.server.config.root);
|
|
162
|
-
const module = this.server.moduleGraph.getModuleById(id);
|
|
163
|
-
const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || RealDate.now();
|
|
164
|
-
const cache = this.fetchCache.get(filePath);
|
|
165
|
-
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
166
|
-
return cache.result;
|
|
167
|
-
const externalize = await this.shouldExternalize(filePath);
|
|
168
|
-
if (externalize) {
|
|
169
|
-
result = { externalize };
|
|
170
|
-
} else {
|
|
171
|
-
const r = await this._transformRequest(id);
|
|
172
|
-
result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
|
|
173
|
-
}
|
|
174
|
-
this.fetchCache.set(filePath, {
|
|
175
|
-
timestamp,
|
|
176
|
-
result
|
|
177
|
-
});
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
async _transformRequest(id) {
|
|
181
|
-
let result = null;
|
|
182
|
-
if (this.getTransformMode(id) === "web") {
|
|
183
|
-
result = await this.server.transformRequest(id);
|
|
184
|
-
if (result)
|
|
185
|
-
result = await this.server.ssrTransform(result.code, result.map, id);
|
|
186
|
-
} else {
|
|
187
|
-
result = await this.server.transformRequest(id, { ssr: true });
|
|
188
|
-
}
|
|
189
|
-
const sourcemap = this.options.sourcemap ?? "inline";
|
|
190
|
-
if (sourcemap === "inline" && result && !id.includes("node_modules"))
|
|
191
|
-
utils.withInlineSourcemap(result);
|
|
192
|
-
return result;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
13
|
|
|
196
|
-
exports.ViteNodeServer = ViteNodeServer;
|
|
197
|
-
exports.guessCJSversion = guessCJSversion;
|
|
198
|
-
exports.shouldExternalize = shouldExternalize;
|
|
14
|
+
exports.ViteNodeServer = server.ViteNodeServer;
|
|
15
|
+
exports.guessCJSversion = server.guessCJSversion;
|
|
16
|
+
exports.shouldExternalize = server.shouldExternalize;
|
package/dist/server.js
CHANGED
|
@@ -1,192 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
export { V as ViteNodeServer, g as guessCJSversion, s as shouldExternalize } from './server-d9fc65e0.js';
|
|
2
|
+
import 'pathe';
|
|
3
|
+
import 'fs';
|
|
4
|
+
import 'mlly';
|
|
5
|
+
import './utils-0290448b.js';
|
|
5
6
|
import 'url';
|
|
6
|
-
|
|
7
|
-
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
|
|
8
|
-
const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
|
|
9
|
-
const defaultInline = [
|
|
10
|
-
/virtual:/,
|
|
11
|
-
/\.ts$/
|
|
12
|
-
];
|
|
13
|
-
const depsExternal = [
|
|
14
|
-
/\.cjs\.js$/,
|
|
15
|
-
/\.mjs$/
|
|
16
|
-
];
|
|
17
|
-
function guessCJSversion(id) {
|
|
18
|
-
if (id.match(ESM_EXT_RE)) {
|
|
19
|
-
for (const i of [
|
|
20
|
-
id.replace(ESM_EXT_RE, ".mjs"),
|
|
21
|
-
id.replace(ESM_EXT_RE, ".umd.js"),
|
|
22
|
-
id.replace(ESM_EXT_RE, ".cjs.js"),
|
|
23
|
-
id.replace(ESM_EXT_RE, ".js")
|
|
24
|
-
]) {
|
|
25
|
-
if (existsSync(i))
|
|
26
|
-
return i;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (id.match(ESM_FOLDER_RE)) {
|
|
30
|
-
for (const i of [
|
|
31
|
-
id.replace(ESM_FOLDER_RE, "/umd/$1"),
|
|
32
|
-
id.replace(ESM_FOLDER_RE, "/cjs/$1"),
|
|
33
|
-
id.replace(ESM_FOLDER_RE, "/$1")
|
|
34
|
-
]) {
|
|
35
|
-
if (existsSync(i))
|
|
36
|
-
return i;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async function shouldExternalize(id, options, cache = /* @__PURE__ */ new Map()) {
|
|
41
|
-
if (!cache.has(id))
|
|
42
|
-
cache.set(id, _shouldExternalize(id, options));
|
|
43
|
-
return cache.get(id);
|
|
44
|
-
}
|
|
45
|
-
async function _shouldExternalize(id, options) {
|
|
46
|
-
if (isNodeBuiltin(id))
|
|
47
|
-
return id;
|
|
48
|
-
if (id.startsWith("data:"))
|
|
49
|
-
return id;
|
|
50
|
-
id = patchWindowsImportPath(id);
|
|
51
|
-
if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
|
|
52
|
-
return false;
|
|
53
|
-
if (matchExternalizePattern(id, options == null ? void 0 : options.external))
|
|
54
|
-
return id;
|
|
55
|
-
const isNodeModule = id.includes("/node_modules/");
|
|
56
|
-
const guessCJS = isNodeModule && (options == null ? void 0 : options.fallbackCJS);
|
|
57
|
-
id = guessCJS ? guessCJSversion(id) || id : id;
|
|
58
|
-
if (matchExternalizePattern(id, defaultInline))
|
|
59
|
-
return false;
|
|
60
|
-
if (matchExternalizePattern(id, depsExternal))
|
|
61
|
-
return id;
|
|
62
|
-
const isDist = id.includes("/dist/");
|
|
63
|
-
if ((isNodeModule || isDist) && await isValidNodeImport(id))
|
|
64
|
-
return id;
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
function matchExternalizePattern(id, patterns) {
|
|
68
|
-
if (!patterns)
|
|
69
|
-
return false;
|
|
70
|
-
for (const ex of patterns) {
|
|
71
|
-
if (typeof ex === "string") {
|
|
72
|
-
if (id.includes(`/node_modules/${ex}/`))
|
|
73
|
-
return true;
|
|
74
|
-
} else {
|
|
75
|
-
if (ex.test(id))
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
function patchWindowsImportPath(path) {
|
|
82
|
-
if (path.match(/^\w:\\/))
|
|
83
|
-
return `file:///${slash(path)}`;
|
|
84
|
-
else if (path.match(/^\w:\//))
|
|
85
|
-
return `file:///${path}`;
|
|
86
|
-
else
|
|
87
|
-
return path;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
var __defProp = Object.defineProperty;
|
|
91
|
-
var __defProps = Object.defineProperties;
|
|
92
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
93
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
94
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
95
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
96
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
97
|
-
var __spreadValues = (a, b) => {
|
|
98
|
-
for (var prop in b || (b = {}))
|
|
99
|
-
if (__hasOwnProp.call(b, prop))
|
|
100
|
-
__defNormalProp(a, prop, b[prop]);
|
|
101
|
-
if (__getOwnPropSymbols)
|
|
102
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
103
|
-
if (__propIsEnum.call(b, prop))
|
|
104
|
-
__defNormalProp(a, prop, b[prop]);
|
|
105
|
-
}
|
|
106
|
-
return a;
|
|
107
|
-
};
|
|
108
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
109
|
-
const RealDate = Date;
|
|
110
|
-
class ViteNodeServer {
|
|
111
|
-
constructor(server, options = {}) {
|
|
112
|
-
this.server = server;
|
|
113
|
-
this.options = options;
|
|
114
|
-
this.fetchPromiseMap = /* @__PURE__ */ new Map();
|
|
115
|
-
this.transformPromiseMap = /* @__PURE__ */ new Map();
|
|
116
|
-
this.fetchCache = /* @__PURE__ */ new Map();
|
|
117
|
-
}
|
|
118
|
-
shouldExternalize(id) {
|
|
119
|
-
return shouldExternalize(id, this.options.deps);
|
|
120
|
-
}
|
|
121
|
-
async resolveId(id, importer) {
|
|
122
|
-
if (importer && !importer.startsWith(this.server.config.root))
|
|
123
|
-
importer = join(this.server.config.root, importer);
|
|
124
|
-
return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
|
|
125
|
-
}
|
|
126
|
-
async fetchModule(id) {
|
|
127
|
-
if (!this.fetchPromiseMap.has(id)) {
|
|
128
|
-
this.fetchPromiseMap.set(id, this._fetchModule(id).then((r) => {
|
|
129
|
-
return this.options.sourcemap !== true ? __spreadProps(__spreadValues({}, r), { map: void 0 }) : r;
|
|
130
|
-
}).finally(() => {
|
|
131
|
-
this.fetchPromiseMap.delete(id);
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
return this.fetchPromiseMap.get(id);
|
|
135
|
-
}
|
|
136
|
-
async transformRequest(id) {
|
|
137
|
-
if (!this.transformPromiseMap.has(id)) {
|
|
138
|
-
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
|
|
139
|
-
this.transformPromiseMap.delete(id);
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
return this.transformPromiseMap.get(id);
|
|
143
|
-
}
|
|
144
|
-
getTransformMode(id) {
|
|
145
|
-
var _a, _b, _c, _d;
|
|
146
|
-
const withoutQuery = id.split("?")[0];
|
|
147
|
-
if ((_b = (_a = this.options.transformMode) == null ? void 0 : _a.web) == null ? void 0 : _b.some((r) => withoutQuery.match(r)))
|
|
148
|
-
return "web";
|
|
149
|
-
if ((_d = (_c = this.options.transformMode) == null ? void 0 : _c.ssr) == null ? void 0 : _d.some((r) => withoutQuery.match(r)))
|
|
150
|
-
return "ssr";
|
|
151
|
-
if (withoutQuery.match(/\.([cm]?[jt]sx?|json)$/))
|
|
152
|
-
return "ssr";
|
|
153
|
-
return "web";
|
|
154
|
-
}
|
|
155
|
-
async _fetchModule(id) {
|
|
156
|
-
let result;
|
|
157
|
-
const filePath = toFilePath(id, this.server.config.root);
|
|
158
|
-
const module = this.server.moduleGraph.getModuleById(id);
|
|
159
|
-
const timestamp = (module == null ? void 0 : module.lastHMRTimestamp) || RealDate.now();
|
|
160
|
-
const cache = this.fetchCache.get(filePath);
|
|
161
|
-
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
162
|
-
return cache.result;
|
|
163
|
-
const externalize = await this.shouldExternalize(filePath);
|
|
164
|
-
if (externalize) {
|
|
165
|
-
result = { externalize };
|
|
166
|
-
} else {
|
|
167
|
-
const r = await this._transformRequest(id);
|
|
168
|
-
result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
|
|
169
|
-
}
|
|
170
|
-
this.fetchCache.set(filePath, {
|
|
171
|
-
timestamp,
|
|
172
|
-
result
|
|
173
|
-
});
|
|
174
|
-
return result;
|
|
175
|
-
}
|
|
176
|
-
async _transformRequest(id) {
|
|
177
|
-
let result = null;
|
|
178
|
-
if (this.getTransformMode(id) === "web") {
|
|
179
|
-
result = await this.server.transformRequest(id);
|
|
180
|
-
if (result)
|
|
181
|
-
result = await this.server.ssrTransform(result.code, result.map, id);
|
|
182
|
-
} else {
|
|
183
|
-
result = await this.server.transformRequest(id, { ssr: true });
|
|
184
|
-
}
|
|
185
|
-
const sourcemap = this.options.sourcemap ?? "inline";
|
|
186
|
-
if (sourcemap === "inline" && result && !id.includes("node_modules"))
|
|
187
|
-
withInlineSourcemap(result);
|
|
188
|
-
return result;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export { ViteNodeServer, guessCJSversion, shouldExternalize };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
2
|
+
import { dirname, resolve } from 'pathe';
|
|
3
|
+
|
|
4
|
+
const isWindows = process.platform === "win32";
|
|
5
|
+
function slash(str) {
|
|
6
|
+
return str.replace(/\\/g, "/");
|
|
7
|
+
}
|
|
8
|
+
function normalizeRequestId(id, base) {
|
|
9
|
+
if (base && id.startsWith(base))
|
|
10
|
+
id = `/${id.slice(base.length)}`;
|
|
11
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?+$/, "");
|
|
12
|
+
}
|
|
13
|
+
function normalizeModuleId(id) {
|
|
14
|
+
return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
|
|
15
|
+
}
|
|
16
|
+
function isPrimitive(v) {
|
|
17
|
+
return v !== Object(v);
|
|
18
|
+
}
|
|
19
|
+
function toFilePath(id, root) {
|
|
20
|
+
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(dirname(root)) && dirname(root) !== "/" ? id : id.startsWith("/") ? slash(resolve(root, id.slice(1))) : id;
|
|
21
|
+
if (absolute.startsWith("//"))
|
|
22
|
+
absolute = absolute.slice(1);
|
|
23
|
+
return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
24
|
+
}
|
|
25
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
26
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
27
|
+
async function withInlineSourcemap(result) {
|
|
28
|
+
const { code, map } = result;
|
|
29
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
30
|
+
return result;
|
|
31
|
+
if (map)
|
|
32
|
+
result.code = `${code}
|
|
33
|
+
|
|
34
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
35
|
+
`;
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { normalizeRequestId as a, isWindows as b, isPrimitive as i, normalizeModuleId as n, slash as s, toFilePath as t, withInlineSourcemap as w };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var url = require('url');
|
|
4
|
+
var pathe = require('pathe');
|
|
5
|
+
|
|
6
|
+
const isWindows = process.platform === "win32";
|
|
7
|
+
function slash(str) {
|
|
8
|
+
return str.replace(/\\/g, "/");
|
|
9
|
+
}
|
|
10
|
+
function normalizeRequestId(id, base) {
|
|
11
|
+
if (base && id.startsWith(base))
|
|
12
|
+
id = `/${id.slice(base.length)}`;
|
|
13
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^(node|file):/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?+$/, "");
|
|
14
|
+
}
|
|
15
|
+
function normalizeModuleId(id) {
|
|
16
|
+
return id.replace(/\\/g, "/").replace(/^\/@fs\//, "/").replace(/^file:\//, "/").replace(/^\/+/, "/");
|
|
17
|
+
}
|
|
18
|
+
function isPrimitive(v) {
|
|
19
|
+
return v !== Object(v);
|
|
20
|
+
}
|
|
21
|
+
function toFilePath(id, root) {
|
|
22
|
+
let absolute = slash(id).startsWith("/@fs/") ? id.slice(4) : id.startsWith(pathe.dirname(root)) && pathe.dirname(root) !== "/" ? id : id.startsWith("/") ? slash(pathe.resolve(root, id.slice(1))) : id;
|
|
23
|
+
if (absolute.startsWith("//"))
|
|
24
|
+
absolute = absolute.slice(1);
|
|
25
|
+
return isWindows && absolute.startsWith("/") ? url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
26
|
+
}
|
|
27
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
28
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
29
|
+
async function withInlineSourcemap(result) {
|
|
30
|
+
const { code, map } = result;
|
|
31
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
32
|
+
return result;
|
|
33
|
+
if (map)
|
|
34
|
+
result.code = `${code}
|
|
35
|
+
|
|
36
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
37
|
+
`;
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.isPrimitive = isPrimitive;
|
|
42
|
+
exports.isWindows = isWindows;
|
|
43
|
+
exports.normalizeModuleId = normalizeModuleId;
|
|
44
|
+
exports.normalizeRequestId = normalizeRequestId;
|
|
45
|
+
exports.slash = slash;
|
|
46
|
+
exports.toFilePath = toFilePath;
|
|
47
|
+
exports.withInlineSourcemap = withInlineSourcemap;
|