@vanillaes/esmtk 0.11.0 → 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.
@@ -49,6 +49,18 @@
49
49
  "args": ["typings", "./src/index.js"],
50
50
  "console": "integratedTerminal",
51
51
  },
52
+ {
53
+ "name": "Bundle",
54
+ "type": "node",
55
+ "request": "launch",
56
+ "skipFiles": [
57
+ "<node_internals>/**"
58
+ ],
59
+ "program": "${workspaceFolder}/bin/esmtk.js",
60
+ "cwd": "${workspaceFolder}",
61
+ "args": ["bundle", "--platform=node", "./src/index.js", "./dist/index.js"],
62
+ "console": "integratedTerminal",
63
+ },
52
64
  {
53
65
  "name": "Minify",
54
66
  "type": "node",
@@ -58,7 +70,7 @@
58
70
  ],
59
71
  "program": "${workspaceFolder}/bin/esmtk.js",
60
72
  "cwd": "${workspaceFolder}",
61
- "args": ["minify", "--sourcemap", "./src/index.js", "./src/index.min.js"],
73
+ "args": ["minify", "--sourcemap", "--platform=node", "./src/index.js", "./dist/index.min.js"],
62
74
  "console": "integratedTerminal",
63
75
  },
64
76
  {
package/README.md CHANGED
@@ -68,6 +68,7 @@ Bundle the source code to an ECMAScript module (using ESBuild)
68
68
 
69
69
  - `[input]` - the input source file path
70
70
  - `[output]` - the output bundle file path
71
+ - `--platform=<platform>` - target a specific platform (ex 'node')
71
72
 
72
73
  ### Usage
73
74
 
@@ -85,6 +86,7 @@ Bundle and Minify the source code to an ECMAScript module (using ESBuild)
85
86
 
86
87
  - `[input]` - the input source file path
87
88
  - `[output]` - the output bundle file path
89
+ - `--platform=<platform>` - target a specific platform (ex 'node')
88
90
  - `--sourcemap` - generate a source map for the minified bundle
89
91
 
90
92
  ### Usage
@@ -5,8 +5,9 @@ import { spawn } from 'child_process'
5
5
  * Bundle ESM (ECMAScript Module) code (with tree-shaking)
6
6
  * @param {string} input the input path
7
7
  * @param {string} output the output path
8
+ * @param {any} options bundle options
8
9
  */
9
- export async function bundle (input, output) {
10
+ export async function bundle (input, output, options) {
10
11
  const npmExists = await which('npm')
11
12
  if (!npmExists) {
12
13
  console.error('npm not found')
@@ -21,7 +22,16 @@ export async function bundle (input, output) {
21
22
  process.exit(1)
22
23
  }
23
24
 
24
- spawn('esbuild', ['--format=esm', '--bundle', input, `--outfile=${output}`], {
25
+ const args = []
26
+ args.push('--bundle')
27
+ args.push('--format=esm')
28
+ if (options?.platform) {
29
+ args.push(`--platform=${options?.platform}`)
30
+ }
31
+ args.push(input)
32
+ args.push(`--outfile=${output}`)
33
+
34
+ spawn('esbuild', args, {
25
35
  cwd: process.cwd(),
26
36
  stdio: ['pipe', process.stdout, process.stderr]
27
37
  }).on('error', err => {
@@ -1,5 +1,10 @@
1
1
  import { copyAsync, copyRecursiveAsync } from '../../src/cp.js'
2
2
 
3
+ /**
4
+ * POSIX cp Implemented in Node
5
+ * @param {string} path path of file(s)/directorie(s) to copy
6
+ * @param {any} options cp options
7
+ */
3
8
  export async function cp (source, target, options) {
4
9
  if (!options?.recursive) {
5
10
  await copyAsync(source, target, options?.force)
@@ -3,8 +3,17 @@ import { join } from 'path'
3
3
 
4
4
  const BIN_PATH = join(process.cwd(), 'node_modules', '.bin', 'standard')
5
5
 
6
- export async function lint (flags) {
7
- const child = spawn(BIN_PATH, flags, {
6
+ /**
7
+ * Lint the source code (using StandardJS)
8
+ * @param {any} options
9
+ */
10
+ export async function lint (options) {
11
+ const args = []
12
+ if (options?.fix) {
13
+ args.push('--fix')
14
+ }
15
+
16
+ const child = spawn(BIN_PATH, args, {
8
17
  cwd: process.cwd(),
9
18
  stdio: ['pipe', 'pipe', 'pipe']
10
19
  }).on('error', err => {
@@ -5,6 +5,7 @@ import { spawn } from 'child_process'
5
5
  * Bundle and minify ESM (ECMAScript Module) code (with tree-shaking)
6
6
  * @param {string} input the input path
7
7
  * @param {string} output the output path
8
+ * @param {any} options minify options
8
9
  */
9
10
  export async function minify (input, output, options) {
10
11
  const npmExists = await which('npm')
@@ -22,9 +23,12 @@ export async function minify (input, output, options) {
22
23
  }
23
24
 
24
25
  const args = []
26
+ args.push('--bundle')
25
27
  args.push('--format=esm')
26
28
  args.push('--minify')
27
- args.push('--bundle')
29
+ if (options?.platform) {
30
+ args.push(`--platform=${options?.platform}`)
31
+ }
28
32
  if (options?.sourcemap) {
29
33
  args.push('--sourcemap')
30
34
  }
@@ -1,5 +1,10 @@
1
1
  import { removeAsync, removeRecursiveAsync } from '../../src/rm.js'
2
2
 
3
+ /**
4
+ * POSIX rm Implemented in Node
5
+ * @param {string} path path of file(s)/directorie(s) to remove
6
+ * @param {any} options rm options
7
+ */
3
8
  export async function rm (path, options) {
4
9
  if (!options?.recursive) {
5
10
  await removeAsync(path, options?.force)
@@ -20,19 +20,22 @@ export async function types (entry, options) {
20
20
  process.exit(1)
21
21
  }
22
22
 
23
+ const args = []
24
+ args.push(entry)
25
+ args.push('-t')
26
+ args.push('esnext')
27
+ args.push('--allowJS')
28
+ args.push('--checkJS')
29
+ args.push('--noEmit')
30
+ args.push('--skipLibCheck')
23
31
  if (options?.strict) {
24
- spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--noEmit', '--strict'], {
25
- cwd: process.cwd(),
26
- stdio: ['pipe', process.stdout, process.stderr]
27
- }).on('error', err => {
28
- console.error(err)
29
- })
30
- } else {
31
- spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--noEmit'], {
32
- cwd: process.cwd(),
33
- stdio: ['pipe', process.stdout, process.stderr]
34
- }).on('error', err => {
35
- console.error(err)
36
- })
32
+ args.push('--strict')
37
33
  }
34
+
35
+ spawn('tsc', args, {
36
+ cwd: process.cwd(),
37
+ stdio: ['pipe', process.stdout, process.stderr]
38
+ }).on('error', err => {
39
+ console.error(err)
40
+ })
38
41
  }
package/bin/esmtk.js CHANGED
@@ -31,8 +31,9 @@ program.command('typings <entry>')
31
31
 
32
32
  program.command('bundle <input> <output>')
33
33
  .description('Bundle the source using ESBuild')
34
- .action((input, output) => {
35
- bundle(input, output)
34
+ .option('--platform <platform>', 'Target a specific platform (ex node)')
35
+ .action((input, output, options) => {
36
+ bundle(input, output, options)
36
37
  })
37
38
 
38
39
  program.command('commonjs <input> <output>')
@@ -43,6 +44,7 @@ program.command('commonjs <input> <output>')
43
44
 
44
45
  program.command('minify <input> <output>')
45
46
  .description('Minify the source using ESBuild')
47
+ .option('--platform <platform>', 'Target a specific platform (ex node)')
46
48
  .option('--sourcemap', 'Generate a source map')
47
49
  .action((input, output, options) => {
48
50
  minify(input, output, options)
@@ -51,8 +53,8 @@ program.command('minify <input> <output>')
51
53
  program.command('cp <source> <target>')
52
54
  .usage('[-rf] source target')
53
55
  .description('Copy files from the source to the target')
54
- .option('-f, --force', 'do not prompt before overwriting', false)
55
- .option('-r, --recursive', 'copy directories recursively', false)
56
+ .option('-f, --force', 'Do not prompt before overwriting', false)
57
+ .option('-r, --recursive', 'Copy directories recursively', false)
56
58
  .action((source, target, options) => {
57
59
  cp(source, target, options)
58
60
  })
@@ -60,8 +62,8 @@ program.command('cp <source> <target>')
60
62
  program.command('rm <path>')
61
63
  .usage('[-rf] file|directory')
62
64
  .description('Remove a file|directory')
63
- .option('-f, --force', 'do not prompt before overwriting', false)
64
- .option('-r, --recursive', 'remove directories recursively', false)
65
+ .option('-f, --force', 'Do not prompt before overwriting', false)
66
+ .option('-r, --recursive', 'Remove directories recursively', false)
65
67
  .action((path, options) => {
66
68
  rm(path, options)
67
69
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "0.11.0",
3
+ "version": "0.13.0",
4
4
  "description": "ES Module Toolkit",
5
5
  "keywords": [
6
6
  "esm",