@vanillaes/esmtk 0.24.5 → 0.24.6
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/bin/commands/bundle.js +1 -1
- package/bin/commands/clean.js +7 -1
- package/bin/commands/commonjs.js +1 -1
- package/bin/commands/cp.js +4 -4
- package/bin/commands/init.js +22 -4
- package/bin/commands/lint.js +1 -1
- package/bin/commands/minify.js +1 -1
- package/bin/commands/preview.js +7 -7
- package/bin/commands/rm.js +4 -4
- package/bin/commands/test.js +1 -1
- package/bin/commands/types.js +3 -0
- package/package.json +6 -1
- package/src/cp.d.ts +0 -3
- package/src/cp.js +0 -3
- package/src/index.d.ts +1 -1
- package/src/rm.d.ts +0 -1
- package/src/rm.js +0 -1
- package/src/util.d.ts +2 -3
- package/src/util.js +1 -2
package/bin/commands/bundle.js
CHANGED
|
@@ -5,7 +5,7 @@ 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 {
|
|
8
|
+
* @param {object} options 'bundle' options
|
|
9
9
|
*/
|
|
10
10
|
export async function bundle (input, output, options) {
|
|
11
11
|
const npmExists = await which('npm')
|
package/bin/commands/clean.js
CHANGED
|
@@ -4,7 +4,7 @@ import { fileExists, match } from '../../src/util.js'
|
|
|
4
4
|
/**
|
|
5
5
|
* Clean build artifcats using sensible defaults
|
|
6
6
|
* @param {string} root the root directory
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {object} options 'clean' options
|
|
8
8
|
*/
|
|
9
9
|
export async function clean (root, options) {
|
|
10
10
|
const exists = await fileExists(root)
|
|
@@ -30,6 +30,12 @@ export async function clean (root, options) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Run one category of build artifacts
|
|
35
|
+
* @param {string} root the root directory (default process.cwd())
|
|
36
|
+
* @param {string} glob the pattern of files to match
|
|
37
|
+
* @param {object} options 'clean' options
|
|
38
|
+
*/
|
|
33
39
|
async function cleanOne (root, glob, options) {
|
|
34
40
|
const files = await match(glob, root, 'node_modules/**')
|
|
35
41
|
await removeMultipleAsync(files, options?.force)
|
package/bin/commands/commonjs.js
CHANGED
|
@@ -5,7 +5,7 @@ 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 {
|
|
8
|
+
* @param {object} options 'commonjs' options
|
|
9
9
|
*/
|
|
10
10
|
export async function commonjs (input, output, options) {
|
|
11
11
|
const npmExists = await which('npm')
|
package/bin/commands/cp.js
CHANGED
|
@@ -4,7 +4,7 @@ import { expand } from '../../src/index.js'
|
|
|
4
4
|
/**
|
|
5
5
|
* POSIX cp Implemented in Node
|
|
6
6
|
* @param {string[]} paths Variadic of source/destination paths
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {object} options 'cp' options
|
|
8
8
|
*/
|
|
9
9
|
export async function cp (paths, options) {
|
|
10
10
|
if (paths.length < 2) {
|
|
@@ -30,9 +30,9 @@ export async function cp (paths, options) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (paths.length > 2) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
sources =
|
|
33
|
+
const sourcePatterns = paths.slice(0, -1)
|
|
34
|
+
const sourceFiles = await await Promise.all(sourcePatterns.map(source => expand(source)))
|
|
35
|
+
const sources = sourceFiles.flat()
|
|
36
36
|
const target = paths.slice(-1)[0]
|
|
37
37
|
|
|
38
38
|
await copyMultipleAsync(sources, target, options?.force)
|
package/bin/commands/init.js
CHANGED
|
@@ -10,7 +10,7 @@ const execAsync = promisify(exec)
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Create a package.json file for ECMAScript Development
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {object} options 'init' options
|
|
14
14
|
*/
|
|
15
15
|
export async function init (options) {
|
|
16
16
|
const npmExists = await which('npm')
|
|
@@ -46,10 +46,9 @@ export async function init (options) {
|
|
|
46
46
|
pkg.name = await ask(program, 'package name', DIRNAME)
|
|
47
47
|
pkg.version = await ask(program, 'version', '0.0.0')
|
|
48
48
|
pkg.description = await ask(program, 'description')
|
|
49
|
-
|
|
49
|
+
const keywords = await ask(program, 'keywords')
|
|
50
50
|
if (keywords) {
|
|
51
|
-
keywords = keywords.split(' ')
|
|
52
|
-
pkg.keywords = keywords
|
|
51
|
+
pkg.keywords = keywords.split(' ')
|
|
53
52
|
}
|
|
54
53
|
pkg.repository = await ask(program, 'git repository', REPOSITORY)
|
|
55
54
|
const user = await ask(program, 'author', USERNAME)
|
|
@@ -97,12 +96,23 @@ export async function init (options) {
|
|
|
97
96
|
program.close()
|
|
98
97
|
}
|
|
99
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Ask a question on the command-line
|
|
101
|
+
* @param {object} program reference to the CLI
|
|
102
|
+
* @param {string} prompt the question to ask the User
|
|
103
|
+
* @param {string} [defaultValue] the default value for the question
|
|
104
|
+
* @returns {Promise<string>} the answer to the question | the default value
|
|
105
|
+
*/
|
|
100
106
|
async function ask (program, prompt, defaultValue) {
|
|
101
107
|
const suffix = defaultValue ? `(${defaultValue}) ` : ''
|
|
102
108
|
const answer = await program.question(`${prompt}: ${suffix}`)
|
|
103
109
|
return answer || defaultValue
|
|
104
110
|
}
|
|
105
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Fetch the user.name from .gitconfig
|
|
114
|
+
* @returns {Promise<string>} the user.name
|
|
115
|
+
*/
|
|
106
116
|
async function fetchGitUser () {
|
|
107
117
|
const { stdout, stderr } = await execAsync('git config --get user.name')
|
|
108
118
|
if (stderr) {
|
|
@@ -113,6 +123,10 @@ async function fetchGitUser () {
|
|
|
113
123
|
return `${stdout}`.trim()
|
|
114
124
|
}
|
|
115
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Fetch the user.email from .gitconfig
|
|
128
|
+
* @returns {Promise<string>} the user.email
|
|
129
|
+
*/
|
|
116
130
|
async function fetchGitEmail () {
|
|
117
131
|
const { stdout, stderr } = await execAsync('git config --get user.email')
|
|
118
132
|
if (stderr) {
|
|
@@ -123,6 +137,10 @@ async function fetchGitEmail () {
|
|
|
123
137
|
return `${stdout}`.trim()
|
|
124
138
|
}
|
|
125
139
|
|
|
140
|
+
/**
|
|
141
|
+
* Get the repository name from .git/config
|
|
142
|
+
* @returns {Promise<string>} the repository name
|
|
143
|
+
*/
|
|
126
144
|
async function getGitRepository () {
|
|
127
145
|
const config = join(process.cwd(), '.git', 'config')
|
|
128
146
|
const exists = await fileExists(config)
|
package/bin/commands/lint.js
CHANGED
package/bin/commands/minify.js
CHANGED
|
@@ -5,7 +5,7 @@ import { spawn } from 'child_process'
|
|
|
5
5
|
* Bundle and minify 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 {
|
|
8
|
+
* @param {object} options 'minify' options
|
|
9
9
|
*/
|
|
10
10
|
export async function minify (input, output, options) {
|
|
11
11
|
const npmExists = await which('npm')
|
package/bin/commands/preview.js
CHANGED
|
@@ -8,7 +8,7 @@ const require = createRequire(import.meta.url)
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Preview the package contents included during 'npm publish'
|
|
11
|
-
* @param {
|
|
11
|
+
* @param {object} options 'preview' options
|
|
12
12
|
*/
|
|
13
13
|
export async function preview (options) {
|
|
14
14
|
let ignore = await readNPMIgnore(options.root)
|
|
@@ -35,8 +35,8 @@ export async function preview (options) {
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Read .npmignore
|
|
38
|
-
* @param {
|
|
39
|
-
* @returns a comma-deliminated list of ignore globs
|
|
38
|
+
* @param {string} root the root path
|
|
39
|
+
* @returns {Promise<string>} a comma-deliminated list of ignore globs
|
|
40
40
|
*/
|
|
41
41
|
async function readNPMIgnore (root) {
|
|
42
42
|
const path = join(root, '.npmignore')
|
|
@@ -50,8 +50,8 @@ async function readNPMIgnore (root) {
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* File list comparator
|
|
53
|
-
* @param {
|
|
54
|
-
* @param {
|
|
53
|
+
* @param {string} a file path a
|
|
54
|
+
* @param {string} b file path b
|
|
55
55
|
* @returns {number} 1 | -1
|
|
56
56
|
*/
|
|
57
57
|
function fileCompare (a, b) {
|
|
@@ -68,8 +68,8 @@ function fileCompare (a, b) {
|
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Format a file path to include file size
|
|
71
|
-
* @param {
|
|
72
|
-
* @returns file size followed by file path
|
|
71
|
+
* @param {string} path the file path
|
|
72
|
+
* @returns {string} file size followed by file path
|
|
73
73
|
*/
|
|
74
74
|
function formatFile (path) {
|
|
75
75
|
const size = statSync(path).size
|
package/bin/commands/rm.js
CHANGED
|
@@ -4,7 +4,7 @@ import { expand } from '../../src/util.js'
|
|
|
4
4
|
/**
|
|
5
5
|
* POSIX rm Implemented in Node
|
|
6
6
|
* @param {string[]} paths Variadic of file paths
|
|
7
|
-
* @param {
|
|
7
|
+
* @param {object} options 'rm' options
|
|
8
8
|
*/
|
|
9
9
|
export async function rm (paths, options) {
|
|
10
10
|
if (paths.length === 1) {
|
|
@@ -26,9 +26,9 @@ export async function rm (paths, options) {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
if (paths.length > 1) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const files = await await Promise.all(paths.map(path => expand(path)))
|
|
30
|
+
const flatFiles = files.flat()
|
|
31
31
|
|
|
32
|
-
await removeMultipleAsync(
|
|
32
|
+
await removeMultipleAsync(flatFiles, options?.force)
|
|
33
33
|
}
|
|
34
34
|
}
|
package/bin/commands/test.js
CHANGED
|
@@ -3,7 +3,7 @@ import { spawn } from 'child_process'
|
|
|
3
3
|
/**
|
|
4
4
|
* Test runnner using Tape-ES
|
|
5
5
|
* @param {string} glob the glob to match test files
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {object} options 'test' options
|
|
7
7
|
*/
|
|
8
8
|
export async function test (glob, options) {
|
|
9
9
|
const args = []
|
package/bin/commands/types.js
CHANGED
|
@@ -4,6 +4,7 @@ import { spawn } from 'child_process'
|
|
|
4
4
|
/**
|
|
5
5
|
* Type Check the JSDOC typings
|
|
6
6
|
* @param {string} entry the entry point
|
|
7
|
+
* @param {object} options 'types' options
|
|
7
8
|
*/
|
|
8
9
|
export async function types (entry, options) {
|
|
9
10
|
const npmExists = await which('npm')
|
|
@@ -26,6 +27,8 @@ export async function types (entry, options) {
|
|
|
26
27
|
args.push('esnext')
|
|
27
28
|
args.push('--allowJS')
|
|
28
29
|
args.push('--checkJS')
|
|
30
|
+
args.push('--module')
|
|
31
|
+
args.push('esnext')
|
|
29
32
|
args.push('--noEmit')
|
|
30
33
|
args.push('--skipLibCheck')
|
|
31
34
|
if (options?.strict) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanillaes/esmtk",
|
|
3
|
-
"version": "0.24.
|
|
3
|
+
"version": "0.24.6",
|
|
4
4
|
"description": "ES Module Toolkit",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecmascript",
|
|
@@ -59,5 +59,10 @@
|
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/json5": "^0.0.30",
|
|
61
61
|
"@types/node": "^25.5.0"
|
|
62
|
+
},
|
|
63
|
+
"lint": {
|
|
64
|
+
"ignore": [
|
|
65
|
+
"**/__tests__/**"
|
|
66
|
+
]
|
|
62
67
|
}
|
|
63
68
|
}
|
package/src/cp.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copy a single file asynchronously
|
|
3
|
-
*
|
|
4
3
|
* @param {string} source The source file
|
|
5
4
|
* @param {string} target The target file
|
|
6
5
|
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
@@ -8,7 +7,6 @@
|
|
|
8
7
|
export function copyAsync(source: string, target: string, force?: boolean): Promise<void>;
|
|
9
8
|
/**
|
|
10
9
|
* Copy a multiple files/globs asynchronously
|
|
11
|
-
*
|
|
12
10
|
* @param {string[]} sources The source files/globs
|
|
13
11
|
* @param {string} target The target file
|
|
14
12
|
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
@@ -16,7 +14,6 @@ export function copyAsync(source: string, target: string, force?: boolean): Prom
|
|
|
16
14
|
export function copyMultipleAsync(sources: string[], target: string, force?: boolean): Promise<void>;
|
|
17
15
|
/**
|
|
18
16
|
* Recursively copy a directory asynchronously
|
|
19
|
-
*
|
|
20
17
|
* @param {string} source The source directory
|
|
21
18
|
* @param {string} target The target directory
|
|
22
19
|
* @param {boolean} force If the file already exists, overwrite it (default false)
|
package/src/cp.js
CHANGED
|
@@ -4,7 +4,6 @@ import { cp, stat } from 'node:fs/promises'
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Copy a single file asynchronously
|
|
7
|
-
*
|
|
8
7
|
* @param {string} source The source file
|
|
9
8
|
* @param {string} target The target file
|
|
10
9
|
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
@@ -54,7 +53,6 @@ export async function copyAsync (source, target, force = false) {
|
|
|
54
53
|
|
|
55
54
|
/**
|
|
56
55
|
* Copy a multiple files/globs asynchronously
|
|
57
|
-
*
|
|
58
56
|
* @param {string[]} sources The source files/globs
|
|
59
57
|
* @param {string} target The target file
|
|
60
58
|
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
@@ -83,7 +81,6 @@ export async function copyMultipleAsync (sources, target, force = false) {
|
|
|
83
81
|
|
|
84
82
|
/**
|
|
85
83
|
* Recursively copy a directory asynchronously
|
|
86
|
-
*
|
|
87
84
|
* @param {string} source The source directory
|
|
88
85
|
* @param {string} target The target directory
|
|
89
86
|
* @param {boolean} force If the file already exists, overwrite it (default false)
|
package/src/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { copyAsync, copyRecursiveAsync } from "./cp.js";
|
|
1
|
+
export { copyAsync, copyMultipleAsync, copyRecursiveAsync } from "./cp.js";
|
|
2
2
|
export { removeAsync, removeMultipleAsync, removeRecursiveAsync } from "./rm.js";
|
|
3
3
|
export { expand, fileExists, installed, match, which } from "./util.js";
|
package/src/rm.d.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
export function removeAsync(path: string, force?: boolean): Promise<void>;
|
|
7
7
|
/**
|
|
8
8
|
* Remove a multiple files/globs asynchronously
|
|
9
|
-
*
|
|
10
9
|
* @param {string[]} files The files/globs to delete
|
|
11
10
|
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
12
11
|
*/
|
package/src/rm.js
CHANGED
|
@@ -31,7 +31,6 @@ export async function removeAsync (path, force = false) {
|
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Remove a multiple files/globs asynchronously
|
|
34
|
-
*
|
|
35
34
|
* @param {string[]} files The files/globs to delete
|
|
36
35
|
* @param {boolean} force If the file already exists, overwrite it (default false)
|
|
37
36
|
*/
|
package/src/util.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Expand file/glob into a list of paths
|
|
3
|
-
*
|
|
4
|
-
* @param {*} source the source file/glob
|
|
3
|
+
* @param {string} source the source file/glob
|
|
5
4
|
* @returns {Promise<string[]>} an array of paths
|
|
6
5
|
*/
|
|
7
|
-
export function expand(source:
|
|
6
|
+
export function expand(source: string): Promise<string[]>;
|
|
8
7
|
/**
|
|
9
8
|
* Check if a file/folder exists
|
|
10
9
|
* @param {string} path the path to the file/folder
|
package/src/util.js
CHANGED
|
@@ -6,8 +6,7 @@ const execAsync = promisify(exec)
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Expand file/glob into a list of paths
|
|
9
|
-
*
|
|
10
|
-
* @param {*} source the source file/glob
|
|
9
|
+
* @param {string} source the source file/glob
|
|
11
10
|
* @returns {Promise<string[]>} an array of paths
|
|
12
11
|
*/
|
|
13
12
|
export async function expand (source) {
|