vite-node 0.17.1 → 0.19.0

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