vite-node 0.1.3 → 0.1.7

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/cli.mjs ADDED
@@ -0,0 +1,54 @@
1
+ /* eslint-disable no-console */
2
+ import minimist from 'minimist'
3
+ import { red, dim } from 'kolorist'
4
+ import { run } from './index.mjs'
5
+
6
+ const argv = minimist(process.argv.slice(2), {
7
+ 'alias': {
8
+ r: 'root',
9
+ c: 'config',
10
+ h: 'help',
11
+ w: 'watch',
12
+ s: 'silent',
13
+ },
14
+ '--': true,
15
+ 'string': ['root', 'config'],
16
+ 'boolean': ['help', 'vue', 'watch', 'silent'],
17
+ unknown(name) {
18
+ if (name[0] === '-') {
19
+ console.error(red(`Unknown argument: ${name}`))
20
+ help()
21
+ process.exit(1)
22
+ }
23
+ },
24
+ })
25
+
26
+ if (argv.help) {
27
+ help()
28
+ process.exit(0)
29
+ }
30
+
31
+ if (!argv._.length) {
32
+ console.error(red('No files specified.'))
33
+ help()
34
+ process.exit(1)
35
+ }
36
+
37
+ // forward argv
38
+ process.argv = [process.argv.slice(0, 2), ...argv['--']]
39
+
40
+ run(argv)
41
+
42
+ function help() {
43
+ console.log(`
44
+ Usage:
45
+ $ vite-node [options] [files]
46
+
47
+ Options:
48
+ -r, --root <path> ${dim('[string]')} use specified root directory
49
+ -c, --config <file> ${dim('[string]')} use specified config file
50
+ -w, --watch ${dim('[boolean]')} restart on file changes, similar to "nodemon"
51
+ -s, --silent ${dim('[boolean]')} do not emit errors and logs
52
+ --vue ${dim('[boolean]')} support for importing Vue component
53
+ `)
54
+ }
package/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { builtinModules, createRequire } from 'module'
3
3
  import { pathToFileURL } from 'url'
4
4
  import { dirname, resolve, relative } from 'path'
5
5
  import vm from 'vm'
6
- import { createServer } from 'vite'
6
+ import { createServer, mergeConfig } from 'vite'
7
7
  import createDebug from 'debug'
8
8
  import { red, dim, yellow, green, inverse, cyan } from 'kolorist'
9
9
 
@@ -12,7 +12,11 @@ const debugTransform = createDebug('vite-node:transform')
12
12
 
13
13
  let executing = false
14
14
 
15
- export async function startAndRun(argv) {
15
+ export async function run(argv) {
16
+ process.exitCode = 0
17
+ executing = true
18
+ let err
19
+
16
20
  function log(...args) {
17
21
  if (argv.silent)
18
22
  return
@@ -24,7 +28,7 @@ export async function startAndRun(argv) {
24
28
 
25
29
  const files = argv.files || argv._
26
30
 
27
- const server = await createServer({
31
+ const server = await createServer(mergeConfig(argv.defaultConfig || {}, {
28
32
  logLevel: 'error',
29
33
  clearScreen: false,
30
34
  configFile: argv.config,
@@ -42,10 +46,23 @@ export async function startAndRun(argv) {
42
46
  },
43
47
  }
44
48
  : {},
45
- })
49
+ }))
46
50
  await server.pluginContainer.buildStart({})
47
51
 
48
- await run(files, server, argv)
52
+ async function run() {
53
+ try {
54
+ await execute(files, server, argv)
55
+ }
56
+ catch (e) {
57
+ console.error(e)
58
+ err = e
59
+ if (!argv.watch)
60
+ process.exit(1)
61
+ }
62
+ finally {
63
+ executing = false
64
+ }
65
+ }
49
66
 
50
67
  if (argv.watch) {
51
68
  log(inverse(cyan(' vite node ')), cyan('watch mode enabled\n'))
@@ -57,29 +74,8 @@ export async function startAndRun(argv) {
57
74
  }
58
75
  })
59
76
  }
60
- }
61
-
62
- async function run(files, server, argv) {
63
- process.exitCode = 0
64
- executing = true
65
- let err
66
- try {
67
- await execute(files, server, argv)
68
- }
69
- catch (e) {
70
- console.error(e)
71
- err = e
72
- if (!argv.watch)
73
- process.exit(1)
74
- }
75
- finally {
76
- executing = false
77
- }
78
-
79
- function log(...args) {
80
- if (argv.silent)
81
- return
82
- console.log(...args)
77
+ else {
78
+ await run()
83
79
  }
84
80
 
85
81
  if (argv.watch) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.1.3",
3
+ "version": "0.1.7",
4
4
  "description": "Vite as Node runtime",
5
5
  "keywords": [
6
6
  "vite"
@@ -31,11 +31,10 @@
31
31
  "module": "./index.mjs",
32
32
  "types": "./index.d.ts",
33
33
  "bin": {
34
- "vite-node": "./bin/vite-node.mjs"
34
+ "vite-node": "./vite-node.mjs"
35
35
  },
36
36
  "files": [
37
- "index.mjs",
38
- "bin"
37
+ "*.mjs"
39
38
  ],
40
39
  "dependencies": {
41
40
  "debug": "^4.3.3",
@@ -62,7 +61,7 @@
62
61
  "scripts": {
63
62
  "lint": "eslint \"**/*.{ts,mjs}\"",
64
63
  "release": "bumpp --commit --push --tag && pnpm publish",
65
- "start": "DEBUG=vite-node:* node index.mjs",
64
+ "start": "DEBUG=vite-node:* node cli.mjs",
66
65
  "test": "node cli.mjs -c test/vite.config.ts --vue test/index.test.mjs"
67
66
  }
68
67
  }
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict'
3
3
 
4
- import '../cli.mjs'
4
+ import './cli.mjs'