vite-node 0.1.25 → 0.2.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/client.d.ts +3 -2
- package/dist/cli.cjs +51 -27
- package/dist/cli.js +51 -27
- package/dist/server.cjs +51 -28
- package/dist/server.js +52 -28
- package/dist/utils.cjs +14 -0
- package/dist/utils.js +14 -1
- package/index.d.ts +4 -3
- package/package.json +1 -1
- package/server.d.ts +12 -11
- package/utils.d.ts +4 -1
package/client.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
interface FetchResult {
|
|
2
2
|
code?: string;
|
|
3
3
|
externalize?: string;
|
|
4
|
-
}
|
|
4
|
+
}
|
|
5
|
+
declare type FetchFunction = (id: string) => Promise<FetchResult>;
|
|
5
6
|
declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
|
|
6
7
|
interface ModuleCache {
|
|
7
8
|
promise?: Promise<any>;
|
package/dist/cli.cjs
CHANGED
|
@@ -51,6 +51,19 @@ function toFilePath(id, root) {
|
|
|
51
51
|
absolute = absolute.slice(1);
|
|
52
52
|
return isWindows && absolute.startsWith("/") ? url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
53
53
|
}
|
|
54
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
55
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
56
|
+
async function withInlineSourcemap(result) {
|
|
57
|
+
const { code, map } = result;
|
|
58
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
59
|
+
return result;
|
|
60
|
+
if (map)
|
|
61
|
+
result.code = `${code}
|
|
62
|
+
|
|
63
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
64
|
+
`;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
54
67
|
|
|
55
68
|
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
|
|
56
69
|
const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
|
|
@@ -135,34 +148,35 @@ function patchWindowsImportPath(path) {
|
|
|
135
148
|
return path;
|
|
136
149
|
}
|
|
137
150
|
|
|
138
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
139
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
140
151
|
class ViteNodeServer {
|
|
141
152
|
constructor(server, options = {}) {
|
|
142
153
|
this.server = server;
|
|
143
154
|
this.options = options;
|
|
144
|
-
this.
|
|
155
|
+
this.fetchPromiseMap = new Map();
|
|
156
|
+
this.transformPromiseMap = new Map();
|
|
157
|
+
this.fetchCache = new Map();
|
|
145
158
|
}
|
|
146
159
|
shouldExternalize(id) {
|
|
147
160
|
return shouldExternalize(id, this.options.deps);
|
|
148
161
|
}
|
|
149
|
-
async fetchModule(id) {
|
|
150
|
-
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
|
|
151
|
-
if (externalize)
|
|
152
|
-
return { externalize };
|
|
153
|
-
const r = await this.transformRequest(id);
|
|
154
|
-
return { code: r == null ? void 0 : r.code };
|
|
155
|
-
}
|
|
156
162
|
async resolveId(id, importer) {
|
|
157
163
|
return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
|
|
158
164
|
}
|
|
165
|
+
async fetchModule(id) {
|
|
166
|
+
if (!this.fetchPromiseMap.has(id)) {
|
|
167
|
+
this.fetchPromiseMap.set(id, this._fetchModule(id).finally(() => {
|
|
168
|
+
this.fetchPromiseMap.delete(id);
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
return this.fetchPromiseMap.get(id);
|
|
172
|
+
}
|
|
159
173
|
async transformRequest(id) {
|
|
160
|
-
if (!this.
|
|
161
|
-
this.
|
|
162
|
-
this.
|
|
174
|
+
if (!this.transformPromiseMap.has(id)) {
|
|
175
|
+
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
|
|
176
|
+
this.transformPromiseMap.delete(id);
|
|
163
177
|
}));
|
|
164
178
|
}
|
|
165
|
-
return this.
|
|
179
|
+
return this.transformPromiseMap.get(id);
|
|
166
180
|
}
|
|
167
181
|
getTransformMode(id) {
|
|
168
182
|
var _a, _b, _c, _d;
|
|
@@ -175,10 +189,31 @@ class ViteNodeServer {
|
|
|
175
189
|
return "ssr";
|
|
176
190
|
return "web";
|
|
177
191
|
}
|
|
192
|
+
async _fetchModule(id) {
|
|
193
|
+
var _a;
|
|
194
|
+
let result;
|
|
195
|
+
const timestamp = (_a = this.server.moduleGraph.getModuleById(id)) == null ? void 0 : _a.lastHMRTimestamp;
|
|
196
|
+
const cache = this.fetchCache.get(id);
|
|
197
|
+
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
198
|
+
return cache.result;
|
|
199
|
+
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
|
|
200
|
+
if (externalize) {
|
|
201
|
+
result = { externalize };
|
|
202
|
+
} else {
|
|
203
|
+
const r = await this._transformRequest(id);
|
|
204
|
+
result = { code: r == null ? void 0 : r.code };
|
|
205
|
+
}
|
|
206
|
+
if (timestamp) {
|
|
207
|
+
this.fetchCache.set(id, {
|
|
208
|
+
timestamp,
|
|
209
|
+
result
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
178
214
|
async _transformRequest(id) {
|
|
179
215
|
let result = null;
|
|
180
|
-
|
|
181
|
-
if (mode === "web") {
|
|
216
|
+
if (this.getTransformMode(id) === "web") {
|
|
182
217
|
result = await this.server.transformRequest(id);
|
|
183
218
|
if (result)
|
|
184
219
|
result = await this.server.ssrTransform(result.code, result.map, id);
|
|
@@ -190,17 +225,6 @@ class ViteNodeServer {
|
|
|
190
225
|
return result;
|
|
191
226
|
}
|
|
192
227
|
}
|
|
193
|
-
async function withInlineSourcemap(result) {
|
|
194
|
-
const { code, map } = result;
|
|
195
|
-
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
196
|
-
return result;
|
|
197
|
-
if (map)
|
|
198
|
-
result.code = `${code}
|
|
199
|
-
|
|
200
|
-
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
201
|
-
`;
|
|
202
|
-
return result;
|
|
203
|
-
}
|
|
204
228
|
|
|
205
229
|
const DEFAULT_REQUEST_STUBS = {
|
|
206
230
|
"/@vite/client": {
|
package/dist/cli.js
CHANGED
|
@@ -26,6 +26,19 @@ function toFilePath(id, root) {
|
|
|
26
26
|
absolute = absolute.slice(1);
|
|
27
27
|
return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
28
28
|
}
|
|
29
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
30
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
31
|
+
async function withInlineSourcemap(result) {
|
|
32
|
+
const { code, map } = result;
|
|
33
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
34
|
+
return result;
|
|
35
|
+
if (map)
|
|
36
|
+
result.code = `${code}
|
|
37
|
+
|
|
38
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
39
|
+
`;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
29
42
|
|
|
30
43
|
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
|
|
31
44
|
const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
|
|
@@ -110,34 +123,35 @@ function patchWindowsImportPath(path) {
|
|
|
110
123
|
return path;
|
|
111
124
|
}
|
|
112
125
|
|
|
113
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
114
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
115
126
|
class ViteNodeServer {
|
|
116
127
|
constructor(server, options = {}) {
|
|
117
128
|
this.server = server;
|
|
118
129
|
this.options = options;
|
|
119
|
-
this.
|
|
130
|
+
this.fetchPromiseMap = new Map();
|
|
131
|
+
this.transformPromiseMap = new Map();
|
|
132
|
+
this.fetchCache = new Map();
|
|
120
133
|
}
|
|
121
134
|
shouldExternalize(id) {
|
|
122
135
|
return shouldExternalize(id, this.options.deps);
|
|
123
136
|
}
|
|
124
|
-
async fetchModule(id) {
|
|
125
|
-
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
|
|
126
|
-
if (externalize)
|
|
127
|
-
return { externalize };
|
|
128
|
-
const r = await this.transformRequest(id);
|
|
129
|
-
return { code: r == null ? void 0 : r.code };
|
|
130
|
-
}
|
|
131
137
|
async resolveId(id, importer) {
|
|
132
138
|
return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
|
|
133
139
|
}
|
|
140
|
+
async fetchModule(id) {
|
|
141
|
+
if (!this.fetchPromiseMap.has(id)) {
|
|
142
|
+
this.fetchPromiseMap.set(id, this._fetchModule(id).finally(() => {
|
|
143
|
+
this.fetchPromiseMap.delete(id);
|
|
144
|
+
}));
|
|
145
|
+
}
|
|
146
|
+
return this.fetchPromiseMap.get(id);
|
|
147
|
+
}
|
|
134
148
|
async transformRequest(id) {
|
|
135
|
-
if (!this.
|
|
136
|
-
this.
|
|
137
|
-
this.
|
|
149
|
+
if (!this.transformPromiseMap.has(id)) {
|
|
150
|
+
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
|
|
151
|
+
this.transformPromiseMap.delete(id);
|
|
138
152
|
}));
|
|
139
153
|
}
|
|
140
|
-
return this.
|
|
154
|
+
return this.transformPromiseMap.get(id);
|
|
141
155
|
}
|
|
142
156
|
getTransformMode(id) {
|
|
143
157
|
var _a, _b, _c, _d;
|
|
@@ -150,10 +164,31 @@ class ViteNodeServer {
|
|
|
150
164
|
return "ssr";
|
|
151
165
|
return "web";
|
|
152
166
|
}
|
|
167
|
+
async _fetchModule(id) {
|
|
168
|
+
var _a;
|
|
169
|
+
let result;
|
|
170
|
+
const timestamp = (_a = this.server.moduleGraph.getModuleById(id)) == null ? void 0 : _a.lastHMRTimestamp;
|
|
171
|
+
const cache = this.fetchCache.get(id);
|
|
172
|
+
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
173
|
+
return cache.result;
|
|
174
|
+
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
|
|
175
|
+
if (externalize) {
|
|
176
|
+
result = { externalize };
|
|
177
|
+
} else {
|
|
178
|
+
const r = await this._transformRequest(id);
|
|
179
|
+
result = { code: r == null ? void 0 : r.code };
|
|
180
|
+
}
|
|
181
|
+
if (timestamp) {
|
|
182
|
+
this.fetchCache.set(id, {
|
|
183
|
+
timestamp,
|
|
184
|
+
result
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return result;
|
|
188
|
+
}
|
|
153
189
|
async _transformRequest(id) {
|
|
154
190
|
let result = null;
|
|
155
|
-
|
|
156
|
-
if (mode === "web") {
|
|
191
|
+
if (this.getTransformMode(id) === "web") {
|
|
157
192
|
result = await this.server.transformRequest(id);
|
|
158
193
|
if (result)
|
|
159
194
|
result = await this.server.ssrTransform(result.code, result.map, id);
|
|
@@ -165,17 +200,6 @@ class ViteNodeServer {
|
|
|
165
200
|
return result;
|
|
166
201
|
}
|
|
167
202
|
}
|
|
168
|
-
async function withInlineSourcemap(result) {
|
|
169
|
-
const { code, map } = result;
|
|
170
|
-
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
171
|
-
return result;
|
|
172
|
-
if (map)
|
|
173
|
-
result.code = `${code}
|
|
174
|
-
|
|
175
|
-
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
176
|
-
`;
|
|
177
|
-
return result;
|
|
178
|
-
}
|
|
179
203
|
|
|
180
204
|
const DEFAULT_REQUEST_STUBS = {
|
|
181
205
|
"/@vite/client": {
|
package/dist/server.cjs
CHANGED
|
@@ -17,6 +17,19 @@ function toFilePath(id, root) {
|
|
|
17
17
|
absolute = absolute.slice(1);
|
|
18
18
|
return isWindows && absolute.startsWith("/") ? url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
19
19
|
}
|
|
20
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
21
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
22
|
+
async function withInlineSourcemap(result) {
|
|
23
|
+
const { code, map } = result;
|
|
24
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
25
|
+
return result;
|
|
26
|
+
if (map)
|
|
27
|
+
result.code = `${code}
|
|
28
|
+
|
|
29
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
30
|
+
`;
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
20
33
|
|
|
21
34
|
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
|
|
22
35
|
const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
|
|
@@ -101,34 +114,35 @@ function patchWindowsImportPath(path) {
|
|
|
101
114
|
return path;
|
|
102
115
|
}
|
|
103
116
|
|
|
104
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
105
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
106
117
|
class ViteNodeServer {
|
|
107
118
|
constructor(server, options = {}) {
|
|
108
119
|
this.server = server;
|
|
109
120
|
this.options = options;
|
|
110
|
-
this.
|
|
121
|
+
this.fetchPromiseMap = new Map();
|
|
122
|
+
this.transformPromiseMap = new Map();
|
|
123
|
+
this.fetchCache = new Map();
|
|
111
124
|
}
|
|
112
125
|
shouldExternalize(id) {
|
|
113
126
|
return shouldExternalize(id, this.options.deps);
|
|
114
127
|
}
|
|
115
|
-
async fetchModule(id) {
|
|
116
|
-
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
|
|
117
|
-
if (externalize)
|
|
118
|
-
return { externalize };
|
|
119
|
-
const r = await this.transformRequest(id);
|
|
120
|
-
return { code: r == null ? void 0 : r.code };
|
|
121
|
-
}
|
|
122
128
|
async resolveId(id, importer) {
|
|
123
129
|
return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
|
|
124
130
|
}
|
|
131
|
+
async fetchModule(id) {
|
|
132
|
+
if (!this.fetchPromiseMap.has(id)) {
|
|
133
|
+
this.fetchPromiseMap.set(id, this._fetchModule(id).finally(() => {
|
|
134
|
+
this.fetchPromiseMap.delete(id);
|
|
135
|
+
}));
|
|
136
|
+
}
|
|
137
|
+
return this.fetchPromiseMap.get(id);
|
|
138
|
+
}
|
|
125
139
|
async transformRequest(id) {
|
|
126
|
-
if (!this.
|
|
127
|
-
this.
|
|
128
|
-
this.
|
|
140
|
+
if (!this.transformPromiseMap.has(id)) {
|
|
141
|
+
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
|
|
142
|
+
this.transformPromiseMap.delete(id);
|
|
129
143
|
}));
|
|
130
144
|
}
|
|
131
|
-
return this.
|
|
145
|
+
return this.transformPromiseMap.get(id);
|
|
132
146
|
}
|
|
133
147
|
getTransformMode(id) {
|
|
134
148
|
var _a, _b, _c, _d;
|
|
@@ -141,10 +155,31 @@ class ViteNodeServer {
|
|
|
141
155
|
return "ssr";
|
|
142
156
|
return "web";
|
|
143
157
|
}
|
|
158
|
+
async _fetchModule(id) {
|
|
159
|
+
var _a;
|
|
160
|
+
let result;
|
|
161
|
+
const timestamp = (_a = this.server.moduleGraph.getModuleById(id)) == null ? void 0 : _a.lastHMRTimestamp;
|
|
162
|
+
const cache = this.fetchCache.get(id);
|
|
163
|
+
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
164
|
+
return cache.result;
|
|
165
|
+
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
|
|
166
|
+
if (externalize) {
|
|
167
|
+
result = { externalize };
|
|
168
|
+
} else {
|
|
169
|
+
const r = await this._transformRequest(id);
|
|
170
|
+
result = { code: r == null ? void 0 : r.code };
|
|
171
|
+
}
|
|
172
|
+
if (timestamp) {
|
|
173
|
+
this.fetchCache.set(id, {
|
|
174
|
+
timestamp,
|
|
175
|
+
result
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
144
180
|
async _transformRequest(id) {
|
|
145
181
|
let result = null;
|
|
146
|
-
|
|
147
|
-
if (mode === "web") {
|
|
182
|
+
if (this.getTransformMode(id) === "web") {
|
|
148
183
|
result = await this.server.transformRequest(id);
|
|
149
184
|
if (result)
|
|
150
185
|
result = await this.server.ssrTransform(result.code, result.map, id);
|
|
@@ -156,19 +191,7 @@ class ViteNodeServer {
|
|
|
156
191
|
return result;
|
|
157
192
|
}
|
|
158
193
|
}
|
|
159
|
-
async function withInlineSourcemap(result) {
|
|
160
|
-
const { code, map } = result;
|
|
161
|
-
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
162
|
-
return result;
|
|
163
|
-
if (map)
|
|
164
|
-
result.code = `${code}
|
|
165
|
-
|
|
166
|
-
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
167
|
-
`;
|
|
168
|
-
return result;
|
|
169
|
-
}
|
|
170
194
|
|
|
171
195
|
exports.ViteNodeServer = ViteNodeServer;
|
|
172
196
|
exports.guessCJSversion = guessCJSversion;
|
|
173
197
|
exports.shouldExternalize = shouldExternalize;
|
|
174
|
-
exports.withInlineSourcemap = withInlineSourcemap;
|
package/dist/server.js
CHANGED
|
@@ -13,6 +13,19 @@ function toFilePath(id, root) {
|
|
|
13
13
|
absolute = absolute.slice(1);
|
|
14
14
|
return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
15
15
|
}
|
|
16
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
17
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
18
|
+
async function withInlineSourcemap(result) {
|
|
19
|
+
const { code, map } = result;
|
|
20
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
21
|
+
return result;
|
|
22
|
+
if (map)
|
|
23
|
+
result.code = `${code}
|
|
24
|
+
|
|
25
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
26
|
+
`;
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
16
29
|
|
|
17
30
|
const ESM_EXT_RE = /\.(es|esm|esm-browser|esm-bundler|es6|module)\.js$/;
|
|
18
31
|
const ESM_FOLDER_RE = /\/esm\/(.*\.js)$/;
|
|
@@ -97,34 +110,35 @@ function patchWindowsImportPath(path) {
|
|
|
97
110
|
return path;
|
|
98
111
|
}
|
|
99
112
|
|
|
100
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
101
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
102
113
|
class ViteNodeServer {
|
|
103
114
|
constructor(server, options = {}) {
|
|
104
115
|
this.server = server;
|
|
105
116
|
this.options = options;
|
|
106
|
-
this.
|
|
117
|
+
this.fetchPromiseMap = new Map();
|
|
118
|
+
this.transformPromiseMap = new Map();
|
|
119
|
+
this.fetchCache = new Map();
|
|
107
120
|
}
|
|
108
121
|
shouldExternalize(id) {
|
|
109
122
|
return shouldExternalize(id, this.options.deps);
|
|
110
123
|
}
|
|
111
|
-
async fetchModule(id) {
|
|
112
|
-
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
|
|
113
|
-
if (externalize)
|
|
114
|
-
return { externalize };
|
|
115
|
-
const r = await this.transformRequest(id);
|
|
116
|
-
return { code: r == null ? void 0 : r.code };
|
|
117
|
-
}
|
|
118
124
|
async resolveId(id, importer) {
|
|
119
125
|
return this.server.pluginContainer.resolveId(id, importer, { ssr: true });
|
|
120
126
|
}
|
|
127
|
+
async fetchModule(id) {
|
|
128
|
+
if (!this.fetchPromiseMap.has(id)) {
|
|
129
|
+
this.fetchPromiseMap.set(id, this._fetchModule(id).finally(() => {
|
|
130
|
+
this.fetchPromiseMap.delete(id);
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
return this.fetchPromiseMap.get(id);
|
|
134
|
+
}
|
|
121
135
|
async transformRequest(id) {
|
|
122
|
-
if (!this.
|
|
123
|
-
this.
|
|
124
|
-
this.
|
|
136
|
+
if (!this.transformPromiseMap.has(id)) {
|
|
137
|
+
this.transformPromiseMap.set(id, this._transformRequest(id).finally(() => {
|
|
138
|
+
this.transformPromiseMap.delete(id);
|
|
125
139
|
}));
|
|
126
140
|
}
|
|
127
|
-
return this.
|
|
141
|
+
return this.transformPromiseMap.get(id);
|
|
128
142
|
}
|
|
129
143
|
getTransformMode(id) {
|
|
130
144
|
var _a, _b, _c, _d;
|
|
@@ -137,10 +151,31 @@ class ViteNodeServer {
|
|
|
137
151
|
return "ssr";
|
|
138
152
|
return "web";
|
|
139
153
|
}
|
|
154
|
+
async _fetchModule(id) {
|
|
155
|
+
var _a;
|
|
156
|
+
let result;
|
|
157
|
+
const timestamp = (_a = this.server.moduleGraph.getModuleById(id)) == null ? void 0 : _a.lastHMRTimestamp;
|
|
158
|
+
const cache = this.fetchCache.get(id);
|
|
159
|
+
if (timestamp && cache && cache.timestamp >= timestamp)
|
|
160
|
+
return cache.result;
|
|
161
|
+
const externalize = await this.shouldExternalize(toFilePath(id, this.server.config.root));
|
|
162
|
+
if (externalize) {
|
|
163
|
+
result = { externalize };
|
|
164
|
+
} else {
|
|
165
|
+
const r = await this._transformRequest(id);
|
|
166
|
+
result = { code: r == null ? void 0 : r.code };
|
|
167
|
+
}
|
|
168
|
+
if (timestamp) {
|
|
169
|
+
this.fetchCache.set(id, {
|
|
170
|
+
timestamp,
|
|
171
|
+
result
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
140
176
|
async _transformRequest(id) {
|
|
141
177
|
let result = null;
|
|
142
|
-
|
|
143
|
-
if (mode === "web") {
|
|
178
|
+
if (this.getTransformMode(id) === "web") {
|
|
144
179
|
result = await this.server.transformRequest(id);
|
|
145
180
|
if (result)
|
|
146
181
|
result = await this.server.ssrTransform(result.code, result.map, id);
|
|
@@ -152,16 +187,5 @@ class ViteNodeServer {
|
|
|
152
187
|
return result;
|
|
153
188
|
}
|
|
154
189
|
}
|
|
155
|
-
async function withInlineSourcemap(result) {
|
|
156
|
-
const { code, map } = result;
|
|
157
|
-
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
158
|
-
return result;
|
|
159
|
-
if (map)
|
|
160
|
-
result.code = `${code}
|
|
161
|
-
|
|
162
|
-
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
163
|
-
`;
|
|
164
|
-
return result;
|
|
165
|
-
}
|
|
166
190
|
|
|
167
|
-
export { ViteNodeServer, guessCJSversion, shouldExternalize
|
|
191
|
+
export { ViteNodeServer, guessCJSversion, shouldExternalize };
|
package/dist/utils.cjs
CHANGED
|
@@ -23,9 +23,23 @@ function toFilePath(id, root) {
|
|
|
23
23
|
absolute = absolute.slice(1);
|
|
24
24
|
return isWindows && absolute.startsWith("/") ? url.fileURLToPath(url.pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
25
25
|
}
|
|
26
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
27
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
28
|
+
async function withInlineSourcemap(result) {
|
|
29
|
+
const { code, map } = result;
|
|
30
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
31
|
+
return result;
|
|
32
|
+
if (map)
|
|
33
|
+
result.code = `${code}
|
|
34
|
+
|
|
35
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
36
|
+
`;
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
26
39
|
|
|
27
40
|
exports.isPrimitive = isPrimitive;
|
|
28
41
|
exports.isWindows = isWindows;
|
|
29
42
|
exports.normalizeId = normalizeId;
|
|
30
43
|
exports.slash = slash;
|
|
31
44
|
exports.toFilePath = toFilePath;
|
|
45
|
+
exports.withInlineSourcemap = withInlineSourcemap;
|
package/dist/utils.js
CHANGED
|
@@ -19,5 +19,18 @@ function toFilePath(id, root) {
|
|
|
19
19
|
absolute = absolute.slice(1);
|
|
20
20
|
return isWindows && absolute.startsWith("/") ? fileURLToPath(pathToFileURL(absolute.slice(1)).href) : absolute;
|
|
21
21
|
}
|
|
22
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
23
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
24
|
+
async function withInlineSourcemap(result) {
|
|
25
|
+
const { code, map } = result;
|
|
26
|
+
if (code.includes(`${SOURCEMAPPING_URL}=`))
|
|
27
|
+
return result;
|
|
28
|
+
if (map)
|
|
29
|
+
result.code = `${code}
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
//# ${SOURCEMAPPING_URL}=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(map), "utf-8").toString("base64")}
|
|
32
|
+
`;
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { isPrimitive, isWindows, normalizeId, slash, toFilePath, withInlineSourcemap };
|
package/index.d.ts
CHANGED
|
@@ -7,10 +7,11 @@ interface DepsHandlingOptions {
|
|
|
7
7
|
*/
|
|
8
8
|
fallbackCJS?: boolean;
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
interface FetchResult {
|
|
11
11
|
code?: string;
|
|
12
12
|
externalize?: string;
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
|
+
declare type FetchFunction = (id: string) => Promise<FetchResult>;
|
|
14
15
|
declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
|
|
15
16
|
interface ModuleCache {
|
|
16
17
|
promise?: Promise<any>;
|
|
@@ -52,4 +53,4 @@ interface ViteNodeServerOptions {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
export { DepsHandlingOptions, FetchFunction, ModuleCache, ResolveIdFunction, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions };
|
|
56
|
+
export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, ResolveIdFunction, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions };
|
package/package.json
CHANGED
package/server.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { ViteDevServer, TransformResult } from 'vite';
|
|
2
2
|
|
|
3
|
+
interface FetchResult {
|
|
4
|
+
code?: string;
|
|
5
|
+
externalize?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
interface DepsHandlingOptions {
|
|
4
9
|
external?: (string | RegExp)[];
|
|
5
10
|
inline?: (string | RegExp)[];
|
|
@@ -41,21 +46,17 @@ declare function shouldExternalize(id: string, options?: DepsHandlingOptions, ca
|
|
|
41
46
|
declare class ViteNodeServer {
|
|
42
47
|
server: ViteDevServer;
|
|
43
48
|
options: ViteNodeServerOptions;
|
|
44
|
-
|
|
49
|
+
private fetchPromiseMap;
|
|
50
|
+
private transformPromiseMap;
|
|
51
|
+
private fetchCache;
|
|
45
52
|
constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
|
|
46
53
|
shouldExternalize(id: string): Promise<string | false>;
|
|
47
|
-
fetchModule(id: string): Promise<{
|
|
48
|
-
externalize: string;
|
|
49
|
-
code?: undefined;
|
|
50
|
-
} | {
|
|
51
|
-
code: string | undefined;
|
|
52
|
-
externalize?: undefined;
|
|
53
|
-
}>;
|
|
54
54
|
resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
|
|
55
|
+
fetchModule(id: string): Promise<FetchResult>;
|
|
55
56
|
transformRequest(id: string): Promise<TransformResult | null | undefined>;
|
|
56
|
-
|
|
57
|
+
getTransformMode(id: string): "web" | "ssr";
|
|
58
|
+
private _fetchModule;
|
|
57
59
|
private _transformRequest;
|
|
58
60
|
}
|
|
59
|
-
declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
|
|
60
61
|
|
|
61
|
-
export { ViteNodeServer, guessCJSversion, shouldExternalize
|
|
62
|
+
export { ViteNodeServer, guessCJSversion, shouldExternalize };
|
package/utils.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { TransformResult } from 'vite';
|
|
2
|
+
|
|
1
3
|
declare const isWindows: boolean;
|
|
2
4
|
declare function slash(str: string): string;
|
|
3
5
|
declare function normalizeId(id: string, base?: string): string;
|
|
4
6
|
declare function isPrimitive(v: any): boolean;
|
|
5
7
|
declare function toFilePath(id: string, root: string): string;
|
|
8
|
+
declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
|
|
6
9
|
|
|
7
|
-
export { isPrimitive, isWindows, normalizeId, slash, toFilePath };
|
|
10
|
+
export { isPrimitive, isWindows, normalizeId, slash, toFilePath, withInlineSourcemap };
|