vite-node 0.12.8 → 0.13.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.
package/README.md CHANGED
@@ -27,6 +27,16 @@ Options:
27
27
  npx vite-node -h
28
28
  ```
29
29
 
30
+ ### Options via CLI
31
+
32
+ [All `ViteNodeServer` options](https://github.com/vitest-dev/vitest/blob/main/packages/vite-node/src/types.ts#L61-L78) are supported by the CLI. They may be defined through the dot syntax, as shown below:
33
+
34
+ ```bash
35
+ npx vite-node --options.deps.inline="module-name" --options.deps.external="/module-regexp/" index.ts
36
+ ```
37
+
38
+ Note that for options supporting RegExps, strings passed to the CLI must start _and_ end with a `/`;
39
+
30
40
  ## Programmatic Usage
31
41
 
32
42
  In Vite Node, the server and runner (client) are separated, so you can integrate them in different contexts (workers, cross-process, or remote) if needed. The demo below shows a simple example of having both (server and runner) running in the same context
package/dist/cli.cjs CHANGED
@@ -627,10 +627,29 @@ class CAC extends events.EventEmitter {
627
627
 
628
628
  const cac = (name = "") => new CAC(name);
629
629
 
630
- var version = "0.12.8";
630
+ var version = "0.13.0";
631
631
 
632
+ var __defProp = Object.defineProperty;
633
+ var __defProps = Object.defineProperties;
634
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
635
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
636
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
637
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
638
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
639
+ var __spreadValues = (a, b) => {
640
+ for (var prop in b || (b = {}))
641
+ if (__hasOwnProp.call(b, prop))
642
+ __defNormalProp(a, prop, b[prop]);
643
+ if (__getOwnPropSymbols)
644
+ for (var prop of __getOwnPropSymbols(b)) {
645
+ if (__propIsEnum.call(b, prop))
646
+ __defNormalProp(a, prop, b[prop]);
647
+ }
648
+ return a;
649
+ };
650
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
632
651
  const cli = cac("vite-node");
633
- cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').help();
652
+ cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
634
653
  cli.command("[...files]").action(run);
635
654
  cli.parse();
636
655
  async function run(files, options = {}) {
@@ -640,13 +659,14 @@ async function run(files, options = {}) {
640
659
  process.exit(1);
641
660
  }
642
661
  process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
662
+ const parsedServerOptions = options.options ? parseServerOptions(options.options) : void 0;
643
663
  const server$1 = await vite.createServer({
644
664
  logLevel: "error",
645
665
  configFile: options.config,
646
666
  root: options.root
647
667
  });
648
668
  await server$1.pluginContainer.buildStart({});
649
- const node = new server.ViteNodeServer(server$1);
669
+ const node = new server.ViteNodeServer(server$1, parsedServerOptions);
650
670
  const runner = new client.ViteNodeRunner({
651
671
  root: server$1.config.root,
652
672
  base: server$1.config.base,
@@ -672,3 +692,20 @@ async function run(files, options = {}) {
672
692
  await runner.executeFile(file);
673
693
  });
674
694
  }
695
+ function parseServerOptions(serverOptions) {
696
+ var _a, _b, _c, _d, _e, _f, _g, _h;
697
+ return __spreadProps(__spreadValues({}, serverOptions), {
698
+ deps: __spreadProps(__spreadValues({}, serverOptions.deps), {
699
+ inline: (_b = (_a = serverOptions.deps) == null ? void 0 : _a.inline) == null ? void 0 : _b.map((dep) => {
700
+ return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
701
+ }),
702
+ external: (_d = (_c = serverOptions.deps) == null ? void 0 : _c.external) == null ? void 0 : _d.map((dep) => {
703
+ return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
704
+ })
705
+ }),
706
+ transformMode: __spreadProps(__spreadValues({}, serverOptions.transformMode), {
707
+ ssr: (_f = (_e = serverOptions.transformMode) == null ? void 0 : _e.ssr) == null ? void 0 : _f.map((dep) => new RegExp(dep)),
708
+ web: (_h = (_g = serverOptions.transformMode) == null ? void 0 : _g.ssr) == null ? void 0 : _h.map((dep) => new RegExp(dep))
709
+ })
710
+ });
711
+ }
package/dist/cli.d.ts CHANGED
@@ -1,8 +1,16 @@
1
+ import { e as ViteNodeServerOptions } from './types-4b326db0.js';
2
+
1
3
  interface CliOptions {
2
4
  root?: string;
3
5
  config?: string;
4
6
  watch?: boolean;
7
+ options?: ViteNodeServerOptionsCLI;
5
8
  '--'?: string[];
6
9
  }
10
+ declare type Optional<T> = T | undefined;
11
+ declare type ComputeViteNodeServerOptionsCLI<T extends Record<string, any>> = {
12
+ [K in keyof T]: T[K] extends Optional<RegExp[]> ? string[] : T[K] extends Optional<(string | RegExp)[]> ? string[] : T[K] extends Optional<Record<string, any>> ? ComputeViteNodeServerOptionsCLI<T[K]> : T[K];
13
+ };
14
+ declare type ViteNodeServerOptionsCLI = ComputeViteNodeServerOptionsCLI<ViteNodeServerOptions>;
7
15
 
8
- export { CliOptions };
16
+ export { CliOptions, ViteNodeServerOptionsCLI };
package/dist/cli.js CHANGED
@@ -625,10 +625,29 @@ class CAC extends EventEmitter {
625
625
 
626
626
  const cac = (name = "") => new CAC(name);
627
627
 
628
- var version = "0.12.8";
628
+ var version = "0.13.0";
629
629
 
630
+ var __defProp = Object.defineProperty;
631
+ var __defProps = Object.defineProperties;
632
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
633
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
634
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
635
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
636
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
637
+ var __spreadValues = (a, b) => {
638
+ for (var prop in b || (b = {}))
639
+ if (__hasOwnProp.call(b, prop))
640
+ __defNormalProp(a, prop, b[prop]);
641
+ if (__getOwnPropSymbols)
642
+ for (var prop of __getOwnPropSymbols(b)) {
643
+ if (__propIsEnum.call(b, prop))
644
+ __defNormalProp(a, prop, b[prop]);
645
+ }
646
+ return a;
647
+ };
648
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
630
649
  const cli = cac("vite-node");
631
- cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').help();
650
+ cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
632
651
  cli.command("[...files]").action(run);
633
652
  cli.parse();
634
653
  async function run(files, options = {}) {
@@ -638,13 +657,14 @@ async function run(files, options = {}) {
638
657
  process.exit(1);
639
658
  }
640
659
  process.argv = [...process.argv.slice(0, 2), ...options["--"] || []];
660
+ const parsedServerOptions = options.options ? parseServerOptions(options.options) : void 0;
641
661
  const server = await createServer({
642
662
  logLevel: "error",
643
663
  configFile: options.config,
644
664
  root: options.root
645
665
  });
646
666
  await server.pluginContainer.buildStart({});
647
- const node = new ViteNodeServer(server);
667
+ const node = new ViteNodeServer(server, parsedServerOptions);
648
668
  const runner = new ViteNodeRunner({
649
669
  root: server.config.root,
650
670
  base: server.config.base,
@@ -670,3 +690,20 @@ async function run(files, options = {}) {
670
690
  await runner.executeFile(file);
671
691
  });
672
692
  }
693
+ function parseServerOptions(serverOptions) {
694
+ var _a, _b, _c, _d, _e, _f, _g, _h;
695
+ return __spreadProps(__spreadValues({}, serverOptions), {
696
+ deps: __spreadProps(__spreadValues({}, serverOptions.deps), {
697
+ inline: (_b = (_a = serverOptions.deps) == null ? void 0 : _a.inline) == null ? void 0 : _b.map((dep) => {
698
+ return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
699
+ }),
700
+ external: (_d = (_c = serverOptions.deps) == null ? void 0 : _c.external) == null ? void 0 : _d.map((dep) => {
701
+ return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
702
+ })
703
+ }),
704
+ transformMode: __spreadProps(__spreadValues({}, serverOptions.transformMode), {
705
+ ssr: (_f = (_e = serverOptions.transformMode) == null ? void 0 : _e.ssr) == null ? void 0 : _f.map((dep) => new RegExp(dep)),
706
+ web: (_h = (_g = serverOptions.transformMode) == null ? void 0 : _g.ssr) == null ? void 0 : _h.map((dep) => new RegExp(dep))
707
+ })
708
+ });
709
+ }
package/package.json CHANGED
@@ -1,53 +1,45 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "0.12.8",
4
+ "version": "0.13.0",
5
5
  "description": "Vite as Node.js runtime",
6
- "homepage": "https://github.com/vitest-dev/vitest/blob/main/packages/vite-node#readme",
7
- "bugs": {
8
- "url": "https://github.com/vitest-dev/vitest/issues"
9
- },
10
- "license": "MIT",
11
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
+ "license": "MIT",
8
+ "funding": "https://github.com/sponsors/antfu",
9
+ "homepage": "https://github.com/vitest-dev/vitest/blob/main/packages/vite-node#readme",
12
10
  "repository": {
13
11
  "type": "git",
14
12
  "url": "git+https://github.com/vitest-dev/vitest.git",
15
13
  "directory": "packages/vite-node"
16
14
  },
17
- "funding": "https://github.com/sponsors/antfu",
18
- "main": "./dist/index.js",
19
- "module": "./dist/index.js",
20
- "types": "./dist/index.d.ts",
15
+ "bugs": {
16
+ "url": "https://github.com/vitest-dev/vitest/issues"
17
+ },
21
18
  "exports": {
22
19
  ".": {
20
+ "types": "./dist/index.d.ts",
23
21
  "import": "./dist/index.js",
24
- "require": "./dist/index.cjs",
25
- "types": "./dist/index.d.ts"
22
+ "require": "./dist/index.cjs"
26
23
  },
27
24
  "./client": {
25
+ "types": "./dist/client.d.ts",
28
26
  "import": "./dist/client.js",
29
- "require": "./dist/client.cjs",
30
- "types": "./dist/client.d.ts"
27
+ "require": "./dist/client.cjs"
31
28
  },
32
29
  "./server": {
30
+ "types": "./dist/server.d.ts",
33
31
  "import": "./dist/server.js",
34
- "require": "./dist/server.cjs",
35
- "types": "./dist/server.d.ts"
32
+ "require": "./dist/server.cjs"
36
33
  },
37
34
  "./utils": {
35
+ "types": "./dist/utils.d.ts",
38
36
  "import": "./dist/utils.js",
39
- "require": "./dist/utils.cjs",
40
- "types": "./dist/utils.d.ts"
37
+ "require": "./dist/utils.cjs"
41
38
  }
42
39
  },
43
- "files": [
44
- "dist",
45
- "*.d.ts",
46
- "*.mjs"
47
- ],
48
- "bin": {
49
- "vite-node": "./vite-node.mjs"
50
- },
40
+ "main": "./dist/index.js",
41
+ "module": "./dist/index.js",
42
+ "types": "./dist/index.d.ts",
51
43
  "typesVersions": {
52
44
  "*": {
53
45
  "*": [
@@ -56,20 +48,28 @@
56
48
  ]
57
49
  }
58
50
  },
51
+ "bin": {
52
+ "vite-node": "./vite-node.mjs"
53
+ },
54
+ "files": [
55
+ "dist",
56
+ "*.d.ts",
57
+ "*.mjs"
58
+ ],
59
+ "engines": {
60
+ "node": ">=v14.16.0"
61
+ },
59
62
  "dependencies": {
60
63
  "debug": "^4.3.4",
61
64
  "kolorist": "^1.5.1",
62
65
  "mlly": "^0.5.2",
63
66
  "pathe": "^0.2.0",
64
- "vite": "^2.9.8"
67
+ "vite": "^2.9.9"
65
68
  },
66
69
  "devDependencies": {
67
70
  "@types/debug": "^4.1.7",
68
71
  "cac": "^6.7.12",
69
- "rollup": "^2.73.0"
70
- },
71
- "engines": {
72
- "node": ">=v14.16.0"
72
+ "rollup": "^2.74.1"
73
73
  },
74
74
  "scripts": {
75
75
  "build": "rimraf dist && rollup -c",
package/cli.d.ts DELETED
@@ -1,8 +0,0 @@
1
- interface CliOptions {
2
- files?: string[];
3
- _?: string[];
4
- root?: string;
5
- config?: string;
6
- }
7
-
8
- export { CliOptions };
package/client.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import { ViteNodeRunnerOptions, ModuleCache } from './types.js';
2
-
3
- declare const DEFAULT_REQUEST_STUBS: {
4
- '/@vite/client': {
5
- injectQuery: (id: string) => string;
6
- createHotContext(): {
7
- accept: () => void;
8
- prune: () => void;
9
- };
10
- updateStyle(): void;
11
- };
12
- };
13
- declare class ViteNodeRunner {
14
- options: ViteNodeRunnerOptions;
15
- root: string;
16
- moduleCache: Map<string, ModuleCache>;
17
- constructor(options: ViteNodeRunnerOptions);
18
- executeFile(file: string): Promise<any>;
19
- executeId(id: string): Promise<any>;
20
- cachedRequest(rawId: string, callstack: string[]): Promise<any>;
21
- directRequest(id: string, fsPath: string, callstack: string[]): Promise<any>;
22
- prepareContext(context: Record<string, any>): Record<string, any>;
23
- setCache(id: string, mod: Partial<ModuleCache>): void;
24
- shouldResolveId(dep: string): boolean;
25
- /**
26
- * Define if a module should be interop-ed
27
- * This function mostly for the ability to override by subclass
28
- */
29
- shouldInterop(path: string, mod: any): boolean;
30
- /**
31
- * Import a module and interop it
32
- */
33
- interopedImport(path: string): Promise<any>;
34
- hasNestedDefault(target: any): any;
35
- }
36
-
37
- export { DEFAULT_REQUEST_STUBS, ViteNodeRunner };
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions } from './types.js';
package/server.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import { ViteDevServer, TransformResult } from 'vite';
2
- import { DepsHandlingOptions, ViteNodeServerOptions, FetchResult, ViteNodeResolveId } from './types.js';
3
-
4
- declare function guessCJSversion(id: string): string | undefined;
5
- declare function shouldExternalize(id: string, options?: DepsHandlingOptions, cache?: Map<string, Promise<string | false>>): Promise<string | false>;
6
-
7
- declare class ViteNodeServer {
8
- server: ViteDevServer;
9
- options: ViteNodeServerOptions;
10
- private fetchPromiseMap;
11
- private transformPromiseMap;
12
- fetchCache: Map<string, {
13
- timestamp: number;
14
- result: FetchResult;
15
- }>;
16
- constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
17
- shouldExternalize(id: string): Promise<string | false>;
18
- resolveId(id: string, importer?: string): Promise<ViteNodeResolveId | null>;
19
- fetchModule(id: string): Promise<FetchResult>;
20
- transformRequest(id: string): Promise<TransformResult | null | undefined>;
21
- getTransformMode(id: string): "web" | "ssr";
22
- private _fetchModule;
23
- private _transformRequest;
24
- }
25
-
26
- export { ViteNodeServer, guessCJSversion, shouldExternalize };
package/types.d.ts DELETED
@@ -1,68 +0,0 @@
1
- interface DepsHandlingOptions {
2
- external?: (string | RegExp)[];
3
- inline?: (string | RegExp)[];
4
- /**
5
- * Try to guess the CJS version of a package when it's invalid ESM
6
- * @default true
7
- */
8
- fallbackCJS?: boolean;
9
- }
10
- interface StartOfSourceMap {
11
- file?: string;
12
- sourceRoot?: string;
13
- }
14
- interface RawSourceMap extends StartOfSourceMap {
15
- version: string;
16
- sources: string[];
17
- names: string[];
18
- sourcesContent?: string[];
19
- mappings: string;
20
- }
21
- interface FetchResult {
22
- code?: string;
23
- externalize?: string;
24
- map?: RawSourceMap;
25
- }
26
- declare type FetchFunction = (id: string) => Promise<FetchResult>;
27
- declare type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>;
28
- interface ModuleCache {
29
- promise?: Promise<any>;
30
- exports?: any;
31
- code?: string;
32
- }
33
- interface ViteNodeRunnerOptions {
34
- fetchModule: FetchFunction;
35
- resolveId: ResolveIdFunction;
36
- root: string;
37
- base?: string;
38
- moduleCache?: Map<string, ModuleCache>;
39
- interopDefault?: boolean;
40
- requestStubs?: Record<string, any>;
41
- }
42
- interface ViteNodeResolveId {
43
- external?: boolean | 'absolute' | 'relative';
44
- id: string;
45
- meta?: Record<string, any> | null;
46
- moduleSideEffects?: boolean | 'no-treeshake' | null;
47
- syntheticNamedExports?: boolean | string | null;
48
- }
49
- interface ViteNodeServerOptions {
50
- /**
51
- * Inject inline sourcemap to modules
52
- * @default 'inline'
53
- */
54
- sourcemap?: 'inline' | boolean;
55
- /**
56
- * Deps handling
57
- */
58
- deps?: DepsHandlingOptions;
59
- /**
60
- * Transform method for modules
61
- */
62
- transformMode?: {
63
- ssr?: RegExp[];
64
- web?: RegExp[];
65
- };
66
- }
67
-
68
- export { DepsHandlingOptions, FetchFunction, FetchResult, ModuleCache, RawSourceMap, ResolveIdFunction, StartOfSourceMap, ViteNodeResolveId, ViteNodeRunnerOptions, ViteNodeServerOptions };
package/utils.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { TransformResult } from 'vite';
2
-
3
- declare const isWindows: boolean;
4
- declare function slash(str: string): string;
5
- declare function normalizeId(id: string, base?: string): string;
6
- declare function isPrimitive(v: any): boolean;
7
- declare function toFilePath(id: string, root: string): string;
8
- declare function withInlineSourcemap(result: TransformResult): Promise<TransformResult>;
9
-
10
- export { isPrimitive, isWindows, normalizeId, slash, toFilePath, withInlineSourcemap };