@vanillaes/esmtk 0.13.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.
@@ -73,6 +73,18 @@
73
73
  "args": ["minify", "--sourcemap", "--platform=node", "./src/index.js", "./dist/index.min.js"],
74
74
  "console": "integratedTerminal",
75
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"],
86
+ "console": "integratedTerminal",
87
+ },
76
88
  {
77
89
  "name": "CopyFileToFile",
78
90
  "type": "node",
package/README.md CHANGED
@@ -105,6 +105,7 @@ Bundle the source code to a CommonJS module (using ESBuild)
105
105
 
106
106
  - `[input]` - the input source file path
107
107
  - `[output]` - the output bundle file path
108
+ - `--platform=<platform>` - target a specific platform (ex 'node')
108
109
 
109
110
  ### Usage
110
111
 
@@ -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 => {
package/bin/esmtk.js CHANGED
@@ -38,8 +38,9 @@ program.command('bundle <input> <output>')
38
38
 
39
39
  program.command('commonjs <input> <output>')
40
40
  .description('Transpile the source to CommonJS using ESBuild')
41
- .action((input, output) => {
42
- commonjs(input, output)
41
+ .option('--platform <platform>', 'Target a specific platform (ex node)')
42
+ .action((input, output, options) => {
43
+ commonjs(input, output, options)
43
44
  })
44
45
 
45
46
  program.command('minify <input> <output>')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "ES Module Toolkit",
5
5
  "keywords": [
6
6
  "esm",