@vanillaes/esmtk 1.1.1 → 1.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/README.md CHANGED
@@ -112,7 +112,9 @@ Type check the JSDoc typings (using Typescript)
112
112
  `esmtk type [...options] [entry]`
113
113
 
114
114
  - `[entry]` - the entry-point for the source
115
+ - `--module [module]` - module resolution type (default `esnext`)
115
116
  - `--strict` - enable 'strict mode' type checks
117
+ - `--types [types]` - specify type package names to include (ex `node` for `@types/node`)
116
118
 
117
119
  ### Usage
118
120
 
@@ -12,14 +12,16 @@ export async function bundle (input, output, options) {
12
12
  if (!npmExists) {
13
13
  console.error('npm not found')
14
14
  console.error('is node installed?')
15
- process.exit(1)
15
+ process.exitCode = 1
16
+ return
16
17
  }
17
18
 
18
19
  const esbuildExists = await installed('esbuild')
19
20
  if (!esbuildExists) {
20
21
  console.error('esbuild not found')
21
22
  console.error('esbuild can be installed with `npm i -g esbuild`')
22
- process.exit(1)
23
+ process.exitCode = 1
24
+ return
23
25
  }
24
26
 
25
27
  const args = []
@@ -34,7 +36,8 @@ export async function bundle (input, output, options) {
34
36
  spawn('esbuild', args, {
35
37
  cwd: process.cwd(),
36
38
  stdio: ['pipe', process.stdout, process.stderr]
37
- }).on('error', err => {
38
- console.error(err)
39
+ }).on('error', error => {
40
+ console.error(error)
41
+ process.exitCode = 1
39
42
  })
40
43
  }
@@ -10,7 +10,8 @@ export async function clean (cwd, options) {
10
10
  const exists = await fileExists(cwd)
11
11
  if (!exists) {
12
12
  console.error(`clean: ${cwd} No such file or directory`)
13
- process.exit(1)
13
+ process.exitCode = 1
14
+ return
14
15
  }
15
16
 
16
17
  if (options?.bundle) {
@@ -12,14 +12,16 @@ export async function commonjs (input, output, options) {
12
12
  if (!npmExists) {
13
13
  console.error('npm not found')
14
14
  console.error('is node installed?')
15
- process.exit(1)
15
+ process.exitCode = 1
16
+ return
16
17
  }
17
18
 
18
19
  const esbuildExists = await installed('esbuild')
19
20
  if (!esbuildExists) {
20
21
  console.error('esbuild not found')
21
22
  console.error('esbuild can be installed with `npm i -g esbuild`')
22
- process.exit(1)
23
+ process.exitCode = 1
24
+ return
23
25
  }
24
26
 
25
27
  const args = []
@@ -34,7 +36,8 @@ export async function commonjs (input, output, options) {
34
36
  spawn('esbuild', args, {
35
37
  cwd: process.cwd(),
36
38
  stdio: ['pipe', process.stdout, process.stderr]
37
- }).on('error', err => {
38
- console.error(err)
39
+ }).on('error', error => {
40
+ console.error(error)
41
+ process.exitCode = 1
39
42
  })
40
43
  }
@@ -9,6 +9,8 @@ import { expand } from '../../src/index.js'
9
9
  export async function cp (paths, options) {
10
10
  if (paths.length < 2) {
11
11
  console.error('cp: Not enough arguments')
12
+ process.exitCode = 1
13
+ return
12
14
  }
13
15
 
14
16
  if (paths.length === 2) {
@@ -17,22 +17,37 @@ export async function init (options) {
17
17
  if (!npmExists) {
18
18
  console.error('npm not found')
19
19
  console.error('is node installed?')
20
- process.exit(1)
20
+ process.exitCode = 1
21
+ return
21
22
  }
22
23
 
23
24
  const gitExists = await which('git')
24
25
  if (!gitExists) {
25
26
  console.error('git not found')
26
27
  console.error('is git installed?')
27
- process.exit(1)
28
+ process.exitCode = 1
29
+ return
28
30
  }
29
31
 
30
32
  // defaults
31
33
  const DIR = process.cwd()
32
34
  const DIRNAME = basename(process.cwd())
33
- const REPOSITORY = await getGitRepository()
34
- const USERNAME = gitExists ? await fetchGitUser() : ''
35
- const EMAIL = gitExists ? await fetchGitEmail() : ''
35
+ let REPOSITORY
36
+ let USERNAME
37
+ let EMAIL
38
+ try {
39
+ REPOSITORY = await fetchGitRepository()
40
+ USERNAME = gitExists ? await fetchGitUser() : ''
41
+ EMAIL = gitExists ? await fetchGitEmail() : ''
42
+ } catch (error) {
43
+ if (error instanceof Error) {
44
+ console.log(error.message)
45
+ } else {
46
+ console.error(`Unexpected error: ${error}`)
47
+ }
48
+ process.exitCode = 1
49
+ return
50
+ }
36
51
 
37
52
  const program = createInterface({ input: stdin, output: stdout })
38
53
 
@@ -116,8 +131,7 @@ async function ask (program, prompt, defaultValue) {
116
131
  async function fetchGitUser () {
117
132
  const { stdout, stderr } = await execAsync('git config --get user.name')
118
133
  if (stderr) {
119
- console.error(`exec error: ${stderr}`)
120
- process.exit(1)
134
+ throw new Error(`exec error: ${stderr}`)
121
135
  }
122
136
  console.log(`${stdout}`.trim())
123
137
  return `${stdout}`.trim()
@@ -130,18 +144,17 @@ async function fetchGitUser () {
130
144
  async function fetchGitEmail () {
131
145
  const { stdout, stderr } = await execAsync('git config --get user.email')
132
146
  if (stderr) {
133
- console.error(`exec error: ${stderr}`)
134
- process.exit(1)
147
+ throw new Error(`exec error: ${stderr}`)
135
148
  }
136
149
  console.log(`${stdout}`.trim())
137
150
  return `${stdout}`.trim()
138
151
  }
139
152
 
140
153
  /**
141
- * Get the repository name from .git/config
154
+ * Fetch the repository name from .git/config
142
155
  * @returns {Promise<string>} the repository name
143
156
  */
144
- async function getGitRepository () {
157
+ async function fetchGitRepository () {
145
158
  const config = join(process.cwd(), '.git', 'config')
146
159
  const exists = await fileExists(config)
147
160
  if (!exists) {
@@ -16,8 +16,9 @@ export async function lint (options) {
16
16
  const child = spawn(BIN_PATH, args, {
17
17
  cwd: process.cwd(),
18
18
  stdio: ['pipe', 'pipe', 'pipe']
19
- }).on('error', err => {
20
- console.error(`${err}`)
19
+ }).on('error', error => {
20
+ console.error(`${error}`)
21
+ process.exitCode = 1
21
22
  })
22
23
 
23
24
  child.stdout.on('data', (data) => {
@@ -30,5 +31,6 @@ export async function lint (options) {
30
31
  } else {
31
32
  process.stderr.write(`${data}`)
32
33
  }
34
+ process.exitCode = 1
33
35
  })
34
36
  }
@@ -12,14 +12,16 @@ export async function minify (input, output, options) {
12
12
  if (!npmExists) {
13
13
  console.error('npm not found')
14
14
  console.error('is node installed?')
15
- process.exit(1)
15
+ process.exitCode = 1
16
+ return
16
17
  }
17
18
 
18
19
  const esbuildExists = await installed('esbuild')
19
20
  if (!esbuildExists) {
20
21
  console.error('esbuild not found')
21
22
  console.error('esbuild can be installed with `npm i -g esbuild`')
22
- process.exit(1)
23
+ process.exitCode = 1
24
+ return
23
25
  }
24
26
 
25
27
  const args = []
@@ -38,7 +40,8 @@ export async function minify (input, output, options) {
38
40
  spawn('esbuild', args, {
39
41
  cwd: process.cwd(),
40
42
  stdio: ['pipe', process.stdout, process.stderr]
41
- }).on('error', err => {
42
- console.error(err)
43
+ }).on('error', error => {
44
+ console.error(error)
45
+ process.exitCode = 1
43
46
  })
44
47
  }
@@ -17,7 +17,7 @@ export async function preview (options) {
17
17
  let files = await match('**/*', options.cwd, ignore)
18
18
  if (files.length === 0) {
19
19
  console.log('preview: no files found')
20
- process.exit(0)
20
+ return
21
21
  }
22
22
  files = files
23
23
  .filter(path => statSync(path).isFile())
@@ -21,10 +21,20 @@ export async function test (glob, options) {
21
21
  args.push('--watch')
22
22
  }
23
23
 
24
- spawn('node', args, {
24
+ const child = spawn('node', args, {
25
25
  cwd: process.cwd(),
26
- stdio: ['pipe', process.stdout, process.stderr]
27
- }).on('error', err => {
28
- console.error(err)
26
+ stdio: ['pipe', 'pipe', 'pipe']
27
+ }).on('error', error => {
28
+ console.error(error)
29
+ process.exitCode = 1
30
+ })
31
+
32
+ child.stdout.on('data', (data) => {
33
+ process.stdout.write(`${data}`)
34
+ })
35
+
36
+ child.stderr.on('data', (data) => {
37
+ process.stderr.write(`${data}`)
38
+ process.exitCode = 1
29
39
  })
30
40
  }
@@ -11,14 +11,16 @@ export async function type (entry, options) {
11
11
  if (!npmExists) {
12
12
  console.error('npm not found')
13
13
  console.error('is node installed?')
14
- process.exit(1)
14
+ process.exitCode = 1
15
+ return
15
16
  }
16
17
 
17
18
  const esbuildExists = await installed('typescript')
18
19
  if (!esbuildExists) {
19
20
  console.error('typescript not found')
20
21
  console.error('typescript can be installed with `npm i -g typescript`')
21
- process.exit(1)
22
+ process.exitCode = 1
23
+ return
22
24
  }
23
25
 
24
26
  const args = []
@@ -36,11 +38,16 @@ export async function type (entry, options) {
36
38
  if (options?.strict) {
37
39
  args.push('--strict')
38
40
  }
41
+ if (options?.types) {
42
+ args.push('--types')
43
+ args.push(options.types)
44
+ }
39
45
 
40
46
  spawn('tsc', args, {
41
47
  cwd: process.cwd(),
42
48
  stdio: ['pipe', process.stdout, process.stderr]
43
- }).on('error', err => {
44
- console.error(err)
49
+ }).on('error', error => {
50
+ console.error(error)
51
+ process.exitCode = 1
45
52
  })
46
53
  }
@@ -10,20 +10,23 @@ export async function typings (entry) {
10
10
  if (!npmExists) {
11
11
  console.error('npm not found')
12
12
  console.error('is node installed?')
13
- process.exit(1)
13
+ process.exitCode = 1
14
+ return
14
15
  }
15
16
 
16
17
  const esbuildExists = await installed('typescript')
17
18
  if (!esbuildExists) {
18
19
  console.error('typescript not found')
19
20
  console.error('typescript can be installed with `npm i -g typescript`')
20
- process.exit(1)
21
+ process.exitCode = 1
22
+ return
21
23
  }
22
24
 
23
25
  spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--declaration', '--emitDeclarationOnly', '--noEmitOnError'], {
24
26
  cwd: process.cwd(),
25
27
  stdio: ['pipe', process.stdout, process.stderr]
26
- }).on('error', err => {
27
- console.error(err)
28
+ }).on('error', error => {
29
+ console.error(error)
30
+ process.exitCode = 1
28
31
  })
29
32
  }
package/bin/esmtk.js CHANGED
@@ -37,6 +37,7 @@ program.command('type <entry>')
37
37
  .description('Type check the JSDoc typings using Typescript')
38
38
  .option('--module <module>', 'Module resolution type (default esnext)', 'esnext')
39
39
  .option('--strict', 'Enable \'strict mode\'')
40
+ .option('--types <types>', 'specify type package names to include (ex `node` for `@types/node`)')
40
41
  .action((entry, options) => {
41
42
  type(entry, options)
42
43
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "ES Module Toolkit",
5
5
  "keywords": [
6
6
  "ecmascript",
@@ -54,12 +54,12 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@vanillaes/lint-es": "^1.0.0",
57
- "@vanillaes/tape-es": "^4.0.3",
58
57
  "commander": "^14.0.3"
59
58
  },
60
59
  "devDependencies": {
61
60
  "@types/json5": "^0.0.30",
62
- "@types/node": "^25.5.0"
61
+ "@types/node": "^25.5.0",
62
+ "@vanillaes/tape-es": "^4.0.4"
63
63
  },
64
64
  "lint": {
65
65
  "ignore": [
package/src/cp.js CHANGED
@@ -12,16 +12,19 @@ export async function copyAsync (source, target, force = false) {
12
12
  const sExists = await fileExists(source)
13
13
  if (!sExists) {
14
14
  console.error(`cp: ${source} No such file or directory`)
15
- process.exit(1)
15
+ process.exitCode = 1
16
+ return
16
17
  }
17
18
  const sStats = await stat(source)
18
19
  if (sStats.isSymbolicLink()) {
19
20
  console.error(`cp: ${source} is a sybolic link (not copied)`)
20
- process.exit(1)
21
+ process.exitCode = 1
22
+ return
21
23
  }
22
24
  if (!sStats.isFile()) {
23
25
  console.error(`cp: ${source} is a directory (not copied)`)
24
- process.exit(1)
26
+ process.exitCode = 1
27
+ return
25
28
  }
26
29
 
27
30
  const tExists = await fileExists(target)
@@ -30,12 +33,14 @@ export async function copyAsync (source, target, force = false) {
30
33
  if (tIsDir) {
31
34
  if (!tExists) {
32
35
  console.error(`cp: ${target} No such file or directory`)
33
- process.exit(1)
36
+ process.exitCode = 1
37
+ return
34
38
  }
35
39
  const tStats = await stat(target)
36
40
  if (tStats.isSymbolicLink()) {
37
41
  console.error(`cp: ${target} is a sybolic link (not copied)`)
38
- process.exit(1)
42
+ process.exitCode = 1
43
+ return
39
44
  }
40
45
 
41
46
  // append source file name to target directory
@@ -46,8 +51,9 @@ export async function copyAsync (source, target, force = false) {
46
51
 
47
52
  try {
48
53
  await cp(source, target, { force: true })
49
- } catch (err) {
50
- console.error(`cp: error ${err.message}`)
54
+ } catch (error) {
55
+ console.error(`cp: error ${error.message}`)
56
+ process.exitCode = 1
51
57
  }
52
58
  }
53
59
 
@@ -61,12 +67,14 @@ export async function copyMultipleAsync (sources, target, force = false) {
61
67
  const tExists = await fileExists(target)
62
68
  if (!tExists) {
63
69
  console.error(`cp: ${target} No such file or directory`)
64
- process.exit(1)
70
+ process.exitCode = 1
71
+ return
65
72
  }
66
73
  const tStats = await stat(target)
67
74
  if (tStats.isSymbolicLink()) {
68
75
  console.error(`cp: ${target} is a sybolic link (not copied)`)
69
- process.exit(1)
76
+ process.exitCode = 1
77
+ return
70
78
  }
71
79
 
72
80
  try {
@@ -74,8 +82,9 @@ export async function copyMultipleAsync (sources, target, force = false) {
74
82
  for (const source of sources) {
75
83
  await cp(source, `${target}${sep}${basename(source)}`, { force: true })
76
84
  }
77
- } catch (err) {
78
- console.error(`cp": error ${err.message}`)
85
+ } catch (error) {
86
+ console.error(`cp": error ${error.message}`)
87
+ process.exitCode = 1
79
88
  }
80
89
  }
81
90
 
@@ -89,32 +98,38 @@ export async function copyRecursiveAsync (source, target, force = false) {
89
98
  const sExists = await fileExists(source)
90
99
  if (!sExists) {
91
100
  console.error(`cp: ${source} No such file or directory`)
92
- process.exit(1)
101
+ process.exitCode = 1
102
+ return
93
103
  }
94
104
  const sStats = await stat(source)
95
105
  if (sStats.isSymbolicLink()) {
96
106
  console.error(`cp: ${source} is a sybolic link (not copied)`)
97
- process.exit(1)
107
+ process.exitCode = 1
108
+ return
98
109
  }
99
110
 
100
111
  const tExists = await fileExists(target)
101
112
  if (!tExists) {
102
113
  console.error(`cp: ${target} No such file or directory`)
103
- process.exit(1)
114
+ process.exitCode = 1
115
+ return
104
116
  }
105
117
  const tStats = await stat(target)
106
118
  if (tStats.isSymbolicLink()) {
107
119
  console.error(`cp: ${target} is a sybolic link (not copied)`)
108
- process.exit(1)
120
+ process.exitCode = 1
121
+ return
109
122
  }
110
123
  if (!tStats.isDirectory()) {
111
124
  console.error(`cp: target ${target} Not a directory`)
112
- process.exit(1)
125
+ process.exitCode = 1
126
+ return
113
127
  }
114
128
 
115
129
  try {
116
130
  await cp(source, target, { force: true, recursive: true })
117
- } catch (err) {
118
- console.error(`cp": error ${err.message}`)
131
+ } catch (error) {
132
+ console.error(`cp": error ${error.message}`)
133
+ process.exitCode = 1
119
134
  }
120
135
  }
package/src/rm.js CHANGED
@@ -10,22 +10,25 @@ export async function removeAsync (path, force = false) {
10
10
  const exists = await fileExists(path)
11
11
  if (!exists) {
12
12
  console.error(`rm: ${path} No such file or directory`)
13
- process.exit(1)
13
+ process.exitCode = 1
14
+ return
14
15
  }
15
16
  const stats = await stat(path)
16
17
  if (stats.isSymbolicLink()) {
17
18
  console.error(`rm: ${path} is a sybolic link`)
18
- process.exit(1)
19
+ process.exitCode = 1
20
+ return
19
21
  }
20
22
  if (!stats.isFile()) {
21
23
  console.error(`rm: ${path} is a directory`)
22
- process.exit(1)
24
+ process.exitCode = 1
25
+ return
23
26
  }
24
27
 
25
28
  try {
26
29
  await rm(path, { force: true })
27
- } catch (err) {
28
- console.error(`rm: error ${err.message}`)
30
+ } catch (error) {
31
+ console.error(`rm: error ${error.message}`)
29
32
  }
30
33
  }
31
34
 
@@ -39,8 +42,8 @@ export async function removeMultipleAsync (files, force = false) {
39
42
  for (const file of files) {
40
43
  await rm(file, { force: true })
41
44
  }
42
- } catch (err) {
43
- console.error(`cp": error ${err.message}`)
45
+ } catch (error) {
46
+ console.error(`cp": error ${error.message}`)
44
47
  }
45
48
  }
46
49
 
@@ -53,17 +56,19 @@ export async function removeRecursiveAsync (path, force = false) {
53
56
  const exists = await fileExists(path)
54
57
  if (!exists) {
55
58
  console.error(`rm: ${path} No such file or directory`)
56
- process.exit(1)
59
+ process.exitCode = 1
60
+ return
57
61
  }
58
62
  const stats = await stat(path)
59
63
  if (stats.isSymbolicLink()) {
60
64
  console.error(`rm: ${path} is a sybolic link`)
61
- process.exit(1)
65
+ process.exitCode = 1
66
+ return
62
67
  }
63
68
 
64
69
  try {
65
70
  await rm(path, { force: true, recursive: true })
66
- } catch (err) {
67
- console.error(`rm": error ${err.message}`)
71
+ } catch (error) {
72
+ console.error(`rm": error ${error.message}`)
68
73
  }
69
74
  }
package/src/util.js CHANGED
@@ -15,14 +15,16 @@ export async function expand (source) {
15
15
  const paths = await match(source)
16
16
  if (paths.length === 0) {
17
17
  console.error(`${source} no matches found`)
18
- process.exit(1)
18
+ process.exitCode = 1
19
+ return
19
20
  }
20
21
  return paths
21
22
  } else {
22
23
  const exists = await fileExists(source)
23
24
  if (!exists) {
24
25
  console.error(`${source} No such file or directory`)
25
- process.exit(1)
26
+ process.exitCode = 1
27
+ return
26
28
  }
27
29
  return [source]
28
30
  }
@@ -51,7 +53,7 @@ export async function installed (pkg) {
51
53
  try {
52
54
  await execAsync(`npm list -g --depth=0 ${pkg}`)
53
55
  return true
54
- } catch (e) {
56
+ } catch (error) {
55
57
  return false
56
58
  }
57
59
  }
@@ -80,7 +82,7 @@ export async function which (program) {
80
82
  try {
81
83
  await execAsync(`which ${program}`)
82
84
  return true
83
- } catch (e) {
85
+ } catch (error) {
84
86
  return false
85
87
  }
86
88
  }