@vanillaes/esmtk 0.7.1 → 0.7.3
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/.vscode/launch.json +20 -8
- package/README.md +23 -7
- package/bin/commands/bundle.js +2 -2
- package/bin/commands/commonjs.js +2 -2
- package/bin/commands/index.js +1 -0
- package/bin/commands/minify.js +21 -4
- package/bin/commands/types.js +29 -0
- package/bin/esmtk.js +7 -1
- package/package.json +6 -2
- package/src/cp.js +1 -1
- package/src/rm.js +1 -1
package/.vscode/launch.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"version": "0.2.0",
|
|
3
3
|
"configurations": [
|
|
4
4
|
{
|
|
5
|
-
"name": "
|
|
5
|
+
"name": "Lint",
|
|
6
6
|
"type": "node",
|
|
7
7
|
"request": "launch",
|
|
8
8
|
"skipFiles": [
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
],
|
|
11
11
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
12
12
|
"cwd": "${workspaceFolder}",
|
|
13
|
-
"args": ["
|
|
13
|
+
"args": ["lint"],
|
|
14
14
|
"console": "integratedTerminal",
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
"name": "
|
|
17
|
+
"name": "Types",
|
|
18
18
|
"type": "node",
|
|
19
19
|
"request": "launch",
|
|
20
20
|
"skipFiles": [
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
],
|
|
23
23
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
24
24
|
"cwd": "${workspaceFolder}",
|
|
25
|
-
"args": ["
|
|
25
|
+
"args": ["types", "./test/index.js"],
|
|
26
26
|
"console": "integratedTerminal",
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
"name": "
|
|
29
|
+
"name": "CopyFileToFile",
|
|
30
30
|
"type": "node",
|
|
31
31
|
"request": "launch",
|
|
32
32
|
"skipFiles": [
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
],
|
|
35
35
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
36
36
|
"cwd": "${workspaceFolder}",
|
|
37
|
-
"args": ["cp", "
|
|
37
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cp2/test1.txt"],
|
|
38
38
|
"console": "integratedTerminal",
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
"name": "
|
|
41
|
+
"name": "CopyFileToFolder",
|
|
42
42
|
"type": "node",
|
|
43
43
|
"request": "launch",
|
|
44
44
|
"skipFiles": [
|
|
@@ -46,7 +46,19 @@
|
|
|
46
46
|
],
|
|
47
47
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
48
48
|
"cwd": "${workspaceFolder}",
|
|
49
|
-
"args": ["
|
|
49
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cp2"],
|
|
50
|
+
"console": "integratedTerminal",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "CopyFolderRecursively",
|
|
54
|
+
"type": "node",
|
|
55
|
+
"request": "launch",
|
|
56
|
+
"skipFiles": [
|
|
57
|
+
"<node_internals>/**"
|
|
58
|
+
],
|
|
59
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
60
|
+
"cwd": "${workspaceFolder}",
|
|
61
|
+
"args": ["cp", "-r", "./test/cp/", "./test/cp2"],
|
|
50
62
|
"console": "integratedTerminal",
|
|
51
63
|
},
|
|
52
64
|
{
|
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
|
|
|
@@ -25,9 +25,25 @@ Lint uses StandardJS to lint the source
|
|
|
25
25
|
esmtk lint
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
## Types
|
|
29
|
+
|
|
30
|
+
Type check the JSDoc typings (using Typescript)
|
|
31
|
+
|
|
32
|
+
### Arguments
|
|
33
|
+
|
|
34
|
+
`esmtk types index.js`
|
|
35
|
+
|
|
36
|
+
- `[entry]` - the entry-point for the source
|
|
37
|
+
|
|
38
|
+
### Usage
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
esmtk types index.js
|
|
42
|
+
```
|
|
43
|
+
|
|
28
44
|
## Bundle
|
|
29
45
|
|
|
30
|
-
Bundle
|
|
46
|
+
Bundle the source code to an ECMAScript module (using ESBuild)
|
|
31
47
|
|
|
32
48
|
### Arguments
|
|
33
49
|
|
|
@@ -44,7 +60,7 @@ esmtk bundle src/sample.js bundle.js
|
|
|
44
60
|
|
|
45
61
|
## Minify
|
|
46
62
|
|
|
47
|
-
Minify
|
|
63
|
+
Bundle and Minify the source code to an ECMAScript module (using ESBuild)
|
|
48
64
|
|
|
49
65
|
### Arguments
|
|
50
66
|
|
|
@@ -61,7 +77,7 @@ esmtk minify src/sample.js bundle.min.js
|
|
|
61
77
|
|
|
62
78
|
## CommonJS
|
|
63
79
|
|
|
64
|
-
|
|
80
|
+
Bundle the source code to a CommonJS module (using ESBuild)
|
|
65
81
|
|
|
66
82
|
### Arguments
|
|
67
83
|
|
package/bin/commands/bundle.js
CHANGED
|
@@ -11,14 +11,14 @@ export async function bundle (input, output) {
|
|
|
11
11
|
if (!npmExists) {
|
|
12
12
|
console.error('npm not found')
|
|
13
13
|
console.error('is node installed?')
|
|
14
|
-
|
|
14
|
+
process.exit(1)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const esbuildExists = await installed('esbuild')
|
|
18
18
|
if (!esbuildExists) {
|
|
19
19
|
console.error('esbuild not found')
|
|
20
20
|
console.error('esbuild can be installed with `npm i -g esbuild`')
|
|
21
|
-
|
|
21
|
+
process.exit(1)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
spawn('esbuild', ['--format=esm', '--bundle', input, `--outfile=${output}`], {
|
package/bin/commands/commonjs.js
CHANGED
|
@@ -11,14 +11,14 @@ export async function commonjs (input, output) {
|
|
|
11
11
|
if (!npmExists) {
|
|
12
12
|
console.error('npm not found')
|
|
13
13
|
console.error('is node installed?')
|
|
14
|
-
|
|
14
|
+
process.exit(1)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const esbuildExists = await installed('esbuild')
|
|
18
18
|
if (!esbuildExists) {
|
|
19
19
|
console.error('esbuild not found')
|
|
20
20
|
console.error('esbuild can be installed with `npm i -g esbuild`')
|
|
21
|
-
|
|
21
|
+
process.exit(1)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
spawn('esbuild', ['--format=cjs', '--bundle', input, `--outfile=${output}`], {
|
package/bin/commands/index.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
|
+
process.exit(1)
|
|
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
|
+
process.exit(1)
|
|
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 => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { installed, which } from '../../src/util.js'
|
|
2
|
+
import { spawn } from 'child_process'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type Check the JSDOC typings
|
|
6
|
+
* @param {string} entry the entry point
|
|
7
|
+
*/
|
|
8
|
+
export async function types (entry) {
|
|
9
|
+
const npmExists = await which('npm')
|
|
10
|
+
if (!npmExists) {
|
|
11
|
+
console.error('npm not found')
|
|
12
|
+
console.error('is node installed?')
|
|
13
|
+
process.exit(1)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const esbuildExists = await installed('typescript')
|
|
17
|
+
if (!esbuildExists) {
|
|
18
|
+
console.error('typescript not found')
|
|
19
|
+
console.error('typescript can be installed with `npm i -g typescript`')
|
|
20
|
+
process.exit(1)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
spawn('tsc', [entry, '-t', 'esnext', '--allowJS', '--checkJS', '--skipLibCheck', '--noEmit'], {
|
|
24
|
+
cwd: process.cwd(),
|
|
25
|
+
stdio: ['pipe', process.stdout, process.stderr]
|
|
26
|
+
}).on('error', err => {
|
|
27
|
+
console.error(err)
|
|
28
|
+
})
|
|
29
|
+
}
|
package/bin/esmtk.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { bundle, cp, commonjs, lint, minify, rm } from './commands/index.js'
|
|
2
|
+
import { bundle, cp, commonjs, lint, minify, rm, types } from './commands/index.js'
|
|
3
3
|
import { Command } from 'commander'
|
|
4
4
|
import { createRequire } from 'module'
|
|
5
5
|
const program = new Command()
|
|
@@ -16,6 +16,12 @@ program.command('lint')
|
|
|
16
16
|
lint(flags)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
+
program.command('types <entry>')
|
|
20
|
+
.description('Type check the JSDoc typings using Typescript')
|
|
21
|
+
.action((entry) => {
|
|
22
|
+
types(entry)
|
|
23
|
+
})
|
|
24
|
+
|
|
19
25
|
program.command('bundle <input> <output>')
|
|
20
26
|
.description('Bundle the source using ESBuild')
|
|
21
27
|
.action((input, output) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanillaes/esmtk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "ES Module Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"esm",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
25
25
|
"lint": "./bin/esmtk.js lint",
|
|
26
|
-
"
|
|
26
|
+
"types": "./bin/esmtk.js types src/index.js",
|
|
27
|
+
"preversion": "npm run lint && npm run types",
|
|
27
28
|
"postversion": "git push --follow-tags"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
@@ -32,5 +33,8 @@
|
|
|
32
33
|
},
|
|
33
34
|
"engines": {
|
|
34
35
|
"node": ">=17"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/node": "^25.3.5"
|
|
35
39
|
}
|
|
36
40
|
}
|
package/src/cp.js
CHANGED
|
@@ -51,7 +51,7 @@ export async function copyAsync (source, target, force = false) {
|
|
|
51
51
|
* Recursively copy a directory asynchronously
|
|
52
52
|
* @param {string} source The source directory
|
|
53
53
|
* @param {string} target The target directory
|
|
54
|
-
* @param {
|
|
54
|
+
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
55
55
|
*/
|
|
56
56
|
export async function copyRecursiveAsync (source, target, force = false) {
|
|
57
57
|
const sExists = await fileExists(source)
|
package/src/rm.js
CHANGED
|
@@ -27,7 +27,7 @@ export async function removeAsync (path, force = false) {
|
|
|
27
27
|
/**
|
|
28
28
|
* Recursively remove a file|directory asynchronously
|
|
29
29
|
* @param {string} path The file|directory to remove
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {boolean} force Ignore exceptions if the file|directory doesn't exist (default false)
|
|
31
31
|
*/
|
|
32
32
|
export async function removeRecursiveAsync (path, force = false) {
|
|
33
33
|
const exists = await fileExists(path)
|