vite-node 0.34.0 → 0.34.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 CHANGED
@@ -25,7 +25,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
25
25
  var cac__default = /*#__PURE__*/_interopDefaultLegacy(cac);
26
26
  var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
27
27
 
28
- var version = "0.34.0";
28
+ var version = "0.34.2";
29
29
 
30
30
  const cli = cac__default["default"]("vite-node");
31
31
  cli.option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
package/dist/cli.mjs CHANGED
@@ -18,7 +18,7 @@ import 'node:path';
18
18
  import 'node:vm';
19
19
  import 'node:events';
20
20
 
21
- var version = "0.34.0";
21
+ var version = "0.34.2";
22
22
 
23
23
  const cli = cac("vite-node");
24
24
  cli.option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
package/dist/client.cjs CHANGED
@@ -63,6 +63,7 @@ const clientStub = {
63
63
  removeStyle: () => {
64
64
  }
65
65
  };
66
+ const env = utils.createImportMetaEnvProxy();
66
67
  const DEFAULT_REQUEST_STUBS = {
67
68
  "/@vite/client": clientStub,
68
69
  "@vite/client": clientStub
@@ -275,7 +276,7 @@ ${getStack()}`), 2e3);
275
276
  const { Object: Object2, Reflect: Reflect2, Symbol: Symbol2 } = this.getContextPrimitives();
276
277
  const modulePath = utils.cleanUrl(moduleId);
277
278
  const href = node_url.pathToFileURL(modulePath).href;
278
- const meta = { url: href };
279
+ const meta = { url: href, env };
279
280
  const exports = Object2.create(null);
280
281
  Object2.defineProperty(exports, Symbol2.toStringTag, {
281
282
  value: "Module",
package/dist/client.mjs CHANGED
@@ -4,7 +4,7 @@ import { pathToFileURL, fileURLToPath } from 'node:url';
4
4
  import vm from 'node:vm';
5
5
  import { resolve } from 'pathe';
6
6
  import createDebug from 'debug';
7
- import { normalizeModuleId, slash, isInternalRequest, isNodeBuiltin, VALID_ID_PREFIX, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
7
+ import { createImportMetaEnvProxy, normalizeModuleId, slash, isInternalRequest, isNodeBuiltin, VALID_ID_PREFIX, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
8
8
  import { extractSourceMap } from './source-map.mjs';
9
9
  import 'node:fs';
10
10
 
@@ -36,6 +36,7 @@ const clientStub = {
36
36
  removeStyle: () => {
37
37
  }
38
38
  };
39
+ const env = createImportMetaEnvProxy();
39
40
  const DEFAULT_REQUEST_STUBS = {
40
41
  "/@vite/client": clientStub,
41
42
  "@vite/client": clientStub
@@ -248,7 +249,7 @@ ${getStack()}`), 2e3);
248
249
  const { Object: Object2, Reflect: Reflect2, Symbol: Symbol2 } = this.getContextPrimitives();
249
250
  const modulePath = cleanUrl(moduleId);
250
251
  const href = pathToFileURL(modulePath).href;
251
- const meta = { url: href };
252
+ const meta = { url: href, env };
252
253
  const exports = Object2.create(null);
253
254
  Object2.defineProperty(exports, Symbol2.toStringTag, {
254
255
  value: "Module",
package/dist/server.cjs CHANGED
@@ -287,6 +287,16 @@ class ViteNodeServer {
287
287
  }
288
288
  return this.transformPromiseMap.get(id);
289
289
  }
290
+ async transformModule(id, transformMode) {
291
+ if (transformMode !== "web")
292
+ throw new Error('`transformModule` only supports `transformMode: "web"`.');
293
+ const normalizedId = utils.normalizeModuleId(id);
294
+ const mod = this.server.moduleGraph.getModuleById(normalizedId);
295
+ const result = (mod == null ? void 0 : mod.transformResult) || await this.server.transformRequest(normalizedId);
296
+ return {
297
+ code: result == null ? void 0 : result.code
298
+ };
299
+ }
290
300
  getTransformMode(id) {
291
301
  var _a, _b, _c, _d;
292
302
  const withoutQuery = id.split("?")[0];
package/dist/server.d.ts CHANGED
@@ -40,6 +40,9 @@ declare class ViteNodeServer {
40
40
  getSourceMap(source: string): EncodedSourceMap | null;
41
41
  fetchModule(id: string, transformMode?: 'web' | 'ssr'): Promise<FetchResult>;
42
42
  transformRequest(id: string, filepath?: string): Promise<TransformResult | null | undefined>;
43
+ transformModule(id: string, transformMode?: 'web' | 'ssr'): Promise<{
44
+ code: string | undefined;
45
+ }>;
43
46
  getTransformMode(id: string): "web" | "ssr";
44
47
  private _fetchModule;
45
48
  protected processTransformResult(filepath: string, result: TransformResult): Promise<TransformResult>;
package/dist/server.mjs CHANGED
@@ -278,6 +278,16 @@ class ViteNodeServer {
278
278
  }
279
279
  return this.transformPromiseMap.get(id);
280
280
  }
281
+ async transformModule(id, transformMode) {
282
+ if (transformMode !== "web")
283
+ throw new Error('`transformModule` only supports `transformMode: "web"`.');
284
+ const normalizedId = normalizeModuleId(id);
285
+ const mod = this.server.moduleGraph.getModuleById(normalizedId);
286
+ const result = (mod == null ? void 0 : mod.transformResult) || await this.server.transformRequest(normalizedId);
287
+ return {
288
+ code: result == null ? void 0 : result.code
289
+ };
290
+ }
281
291
  getTransformMode(id) {
282
292
  var _a, _b, _c, _d;
283
293
  const withoutQuery = id.split("?")[0];
package/dist/utils.cjs CHANGED
@@ -122,9 +122,35 @@ function traverseBetweenDirs(longerDir, shorterDir, cb) {
122
122
  longerDir = pathe.dirname(longerDir);
123
123
  }
124
124
  }
125
+ function createImportMetaEnvProxy() {
126
+ const booleanKeys = [
127
+ "DEV",
128
+ "PROD",
129
+ "SSR"
130
+ ];
131
+ return new Proxy(process.env, {
132
+ get(_, key) {
133
+ if (typeof key !== "string")
134
+ return void 0;
135
+ if (booleanKeys.includes(key))
136
+ return !!process.env[key];
137
+ return process.env[key];
138
+ },
139
+ set(_, key, value) {
140
+ if (typeof key !== "string")
141
+ return true;
142
+ if (booleanKeys.includes(key))
143
+ process.env[key] = value ? "1" : "";
144
+ else
145
+ process.env[key] = value;
146
+ return true;
147
+ }
148
+ });
149
+ }
125
150
 
126
151
  exports.VALID_ID_PREFIX = VALID_ID_PREFIX;
127
152
  exports.cleanUrl = cleanUrl;
153
+ exports.createImportMetaEnvProxy = createImportMetaEnvProxy;
128
154
  exports.getCachedData = getCachedData;
129
155
  exports.hashRE = hashRE;
130
156
  exports.isInternalRequest = isInternalRequest;
package/dist/utils.d.ts CHANGED
@@ -25,5 +25,6 @@ declare function isNodeBuiltin(id: string): boolean;
25
25
  declare function toArray<T>(array?: Nullable<Arrayable<T>>): Array<T>;
26
26
  declare function getCachedData<T>(cache: Map<string, T>, basedir: string, originalBasedir: string): NonNullable<T> | undefined;
27
27
  declare function setCacheData<T>(cache: Map<string, T>, data: T, basedir: string, originalBasedir: string): void;
28
+ declare function createImportMetaEnvProxy(): NodeJS.ProcessEnv;
28
29
 
29
- export { VALID_ID_PREFIX, cleanUrl, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath };
30
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath };
package/dist/utils.mjs CHANGED
@@ -118,5 +118,30 @@ function traverseBetweenDirs(longerDir, shorterDir, cb) {
118
118
  longerDir = dirname(longerDir);
119
119
  }
120
120
  }
121
+ function createImportMetaEnvProxy() {
122
+ const booleanKeys = [
123
+ "DEV",
124
+ "PROD",
125
+ "SSR"
126
+ ];
127
+ return new Proxy(process.env, {
128
+ get(_, key) {
129
+ if (typeof key !== "string")
130
+ return void 0;
131
+ if (booleanKeys.includes(key))
132
+ return !!process.env[key];
133
+ return process.env[key];
134
+ },
135
+ set(_, key, value) {
136
+ if (typeof key !== "string")
137
+ return true;
138
+ if (booleanKeys.includes(key))
139
+ process.env[key] = value ? "1" : "";
140
+ else
141
+ process.env[key] = value;
142
+ return true;
143
+ }
144
+ });
145
+ }
121
146
 
122
- export { VALID_ID_PREFIX, cleanUrl, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath };
147
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.34.0",
3
+ "version": "0.34.2",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",