@vanillaes/esmtk 0.12.0 → 0.14.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,19 @@
58
70
  ],
59
71
  "program": "${workspaceFolder}/bin/esmtk.js",
60
72
  "cwd": "${workspaceFolder}",
61
- "args": ["minify", "--sourcemap", "--platform=node", "./src/index.js", "./src/index.min.js"],
73
+ "args": ["minify", "--sourcemap", "--platform=node", "./src/index.js", "./dist/index.min.js"],
74
+ "console": "integratedTerminal",
75
+ },
76
+ {
77
+ "name": "CommonJS",
78
+ "type": "node",
79
+ "request": "launch",
80
+ "skipFiles": [
81
+ "<node_internals>/**"
82
+ ],
83
+ "program": "${workspaceFolder}/bin/esmtk.js",
84
+ "cwd": "${workspaceFolder}",
85
+ "args": ["commonjs", "--platform=node", "./src/index.js", "./dist/index.cjs"],
62
86
  "console": "integratedTerminal",
63
87
  },
64
88
  {
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
 
@@ -104,6 +105,7 @@ Bundle the source code to a CommonJS module (using ESBuild)
104
105
 
105
106
  - `[input]` - the input source file path
106
107
  - `[output]` - the output bundle file path
108
+ - `--platform=<platform>` - target a specific platform (ex 'node')
107
109
 
108
110
  ### Usage
109
111
 
@@ -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 => {
@@ -5,8 +5,9 @@ import { spawn } from 'child_process'
5
5
  * Bundle CJS (CommonJS) code
6
6
  * @param {string} input the input path
7
7
  * @param {string} output the output path
8
+ * @param {any} options commonjs options
8
9
  */
9
- export async function commonjs (input, output) {
10
+ export async function commonjs (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 commonjs (input, output) {
21
22
  process.exit(1)
22
23
  }
23
24
 
24
- spawn('esbuild', ['--format=cjs', '--bundle', input, `--outfile=${output}`], {
25
+ const args = []
26
+ args.push('--bundle')
27
+ args.push('--format=cjs')
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 => {
@@ -23,9 +23,9 @@ export async function minify (input, output, options) {
23
23
  }
24
24
 
25
25
  const args = []
26
+ args.push('--bundle')
26
27
  args.push('--format=esm')
27
28
  args.push('--minify')
28
- args.push('--bundle')
29
29
  if (options?.platform) {
30
30
  args.push(`--platform=${options?.platform}`)
31
31
  }
package/bin/esmtk.js CHANGED
@@ -31,14 +31,16 @@ 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>')
39
40
  .description('Transpile the source to CommonJS using ESBuild')
40
- .action((input, output) => {
41
- commonjs(input, output)
41
+ .option('--platform <platform>', 'Target a specific platform (ex node)')
42
+ .action((input, output, options) => {
43
+ commonjs(input, output, options)
42
44
  })
43
45
 
44
46
  program.command('minify <input> <output>')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "ES Module Toolkit",
5
5
  "keywords": [
6
6
  "esm",