@vanillaes/esmtk 0.7.0 → 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 +7 -7
- package/bin/commands/bundle.js +21 -4
- package/bin/commands/commonjs.js +21 -4
- package/bin/commands/lint.js +1 -1
- package/bin/commands/minify.js +21 -4
- package/package.json +1 -2
- package/src/util.js +32 -0
package/README.md
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
<h1 align="center">
|
|
1
|
+
<h1 align="center">ECMAScript Module Toolkit</h1>
|
|
2
2
|
|
|
3
|
-
ESMTK, essential tools
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
64
|
+
Bundle the source code to a CommonJS module (using ESBuild)
|
|
65
65
|
|
|
66
66
|
### Arguments
|
|
67
67
|
|
package/bin/commands/bundle.js
CHANGED
|
@@ -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 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 bundle (input, output) {
|
|
7
|
-
|
|
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', '--bundle', input, `--outfile=${output}`], {
|
|
8
25
|
cwd: process.cwd(),
|
|
9
26
|
stdio: ['pipe', process.stdout, process.stderr]
|
|
10
27
|
}).on('error', err => {
|
package/bin/commands/commonjs.js
CHANGED
|
@@ -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 CJS (CommonJS) code
|
|
6
|
+
* @param {string} input the input path
|
|
7
|
+
* @param {string} output the output path
|
|
8
|
+
*/
|
|
6
9
|
export async function commonjs (input, output) {
|
|
7
|
-
|
|
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=cjs', '--bundle', input, `--outfile=${output}`], {
|
|
8
25
|
cwd: process.cwd(),
|
|
9
26
|
stdio: ['pipe', process.stdout, process.stderr]
|
|
10
27
|
}).on('error', err => {
|
package/bin/commands/lint.js
CHANGED
package/bin/commands/minify.js
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "ES Module Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esm",
|
|
@@ -28,7 +28,6 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"commander": "^14.0.3",
|
|
31
|
-
"esbuild": "^0.27.3",
|
|
32
31
|
"standard": "^17.1.2"
|
|
33
32
|
},
|
|
34
33
|
"engines": {
|
package/src/util.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { exec } from 'child_process'
|
|
2
|
+
import { promisify } from 'node:util'
|
|
3
|
+
|
|
4
|
+
const execAsync = promisify(exec)
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check to see if a NPM package is installed globally
|
|
8
|
+
* @param {string} pkg the name of the package
|
|
9
|
+
* @returns {boolean} true if the package is installed, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
export async function installed (pkg) {
|
|
12
|
+
try {
|
|
13
|
+
await execAsync(`npm list -g --depth=0 ${pkg}`)
|
|
14
|
+
return true
|
|
15
|
+
} catch (e) {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Check to see if an application is installed globally
|
|
22
|
+
* @param {string} program the name of the application
|
|
23
|
+
* @returns {boolean} true if the application is installed, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
export async function which (program) {
|
|
26
|
+
try {
|
|
27
|
+
await execAsync(`which ${program}`)
|
|
28
|
+
return true
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
}
|