@vanillaes/esmtk 0.7.1 → 0.7.2

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
@@ -1,17 +1,17 @@
1
- <h1 align="center">ES Module Toolkit</h1>
1
+ <h1 align="center">ECMAScript Module Toolkit</h1>
2
2
 
3
- ESMTK, essential tools and libs for ES module development
3
+ ESMTK, essential tools for ECMAScript module development
4
4
 
5
5
  <div align="center">
6
6
  <a href="https://github.com/vanillaes/esmtk/releases"><img src="https://badgen.net/github/tag/vanillaes/esmtk" alt="GitHub Release"></a>
7
- <a href="https://www.npmjs.com/package/esmtk"><img src="https://badgen.net/npm/v/esmtk" alt="NPM Releases"></a>
7
+ <a href="https://www.npmjs.com/package/@vanillaes/esmtk"><img src="https://badgen.net/npm/v/@vanillaes/esmtk" alt="NPM Releases"></a>
8
8
  <a href="https://github.com/vanillaes/esmtk/actions"><img src="https://github.com/vanillaes/esmtk/workflows/Latest/badge.svg" alt="Latest Status"></a>
9
9
  <a href="https://github.com/vanillaes/esmtk/actions"><img src="https://github.com/vanillaes/esmtk/workflows/Release/badge.svg" alt="Release Status"></a>
10
10
  </div>
11
11
 
12
12
  ## Lint
13
13
 
14
- Lint uses StandardJS to lint the source
14
+ Lint the source code (using StandardJS)
15
15
 
16
16
  ### Arguments
17
17
 
@@ -27,7 +27,7 @@ esmtk lint
27
27
 
28
28
  ## Bundle
29
29
 
30
- Bundle uses ESBuild to compile an ES module (and its deps) into a bundle
30
+ Bundle the source code to an ECMAScript module (using ESBuild)
31
31
 
32
32
  ### Arguments
33
33
 
@@ -44,7 +44,7 @@ esmtk bundle src/sample.js bundle.js
44
44
 
45
45
  ## Minify
46
46
 
47
- Minify uses ESBuild to compile an ES module (and its deps) into a minified bundle
47
+ Bundle and Minify the source code to an ECMAScript module (using ESBuild)
48
48
 
49
49
  ### Arguments
50
50
 
@@ -61,7 +61,7 @@ esmtk minify src/sample.js bundle.min.js
61
61
 
62
62
  ## CommonJS
63
63
 
64
- CommonJS uses ESBuild to compile an ES module (and its deps) into a CommonJS bundle
64
+ Bundle the source code to a CommonJS module (using ESBuild)
65
65
 
66
66
  ### Arguments
67
67
 
@@ -1,10 +1,27 @@
1
+ import { installed, which } from '../../src/util.js'
1
2
  import { spawn } from 'child_process'
2
- import { join } from 'path'
3
-
4
- const BIN_PATH = join(process.cwd(), 'node_modules', '.bin', 'esbuild')
5
3
 
4
+ /**
5
+ * Bundle and minify ESM (ECMAScript Module) code (with tree-shaking)
6
+ * @param {string} input the input path
7
+ * @param {string} output the output path
8
+ */
6
9
  export async function minify (input, output) {
7
- spawn(BIN_PATH, ['--format=esm', '--minify', '--bundle', input, `--outfile=${output}`], {
10
+ const npmExists = await which('npm')
11
+ if (!npmExists) {
12
+ console.error('npm not found')
13
+ console.error('is node installed?')
14
+ return
15
+ }
16
+
17
+ const esbuildExists = await installed('esbuild')
18
+ if (!esbuildExists) {
19
+ console.error('esbuild not found')
20
+ console.error('esbuild can be installed with `npm i -g esbuild`')
21
+ return
22
+ }
23
+
24
+ spawn('esbuild', ['--format=esm', '--minify', '--bundle', input, `--outfile=${output}`], {
8
25
  cwd: process.cwd(),
9
26
  stdio: ['pipe', process.stdout, process.stderr]
10
27
  }).on('error', err => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vanillaes/esmtk",
3
- "version": "0.7.1",
3
+ "version": "0.7.2",
4
4
  "description": "ES Module Toolkit",
5
5
  "keywords": [
6
6
  "esm",