@vanillaes/esmtk 0.21.0 → 0.22.1
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 +35 -23
- package/README.md +4 -0
- package/bin/commands/test.js +7 -3
- package/bin/esmtk.js +3 -2
- package/package.json +1 -1
- package/src/__test__/cp.json +68 -0
- package/src/cp.spec.js +106 -0
- package/src/index.js +1 -1
- package/src/rm.spec.js +1 -0
package/.vscode/launch.json
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"console": "integratedTerminal",
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
"name": "Test
|
|
41
|
+
"name": "Test --ignore",
|
|
42
42
|
"type": "node",
|
|
43
43
|
"request": "launch",
|
|
44
44
|
"skipFiles": [
|
|
@@ -49,6 +49,18 @@
|
|
|
49
49
|
"args": ["test", "--ignore", "node_modules/**,src/util.spec.js"],
|
|
50
50
|
"console": "integratedTerminal",
|
|
51
51
|
},
|
|
52
|
+
{
|
|
53
|
+
"name": "Test --root",
|
|
54
|
+
"type": "node",
|
|
55
|
+
"request": "launch",
|
|
56
|
+
"skipFiles": [
|
|
57
|
+
"<node_internals>/**"
|
|
58
|
+
],
|
|
59
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
60
|
+
"cwd": "${workspaceFolder}",
|
|
61
|
+
"args": ["test", "--root", "src/"],
|
|
62
|
+
"console": "integratedTerminal",
|
|
63
|
+
},
|
|
52
64
|
{
|
|
53
65
|
"name": "Lint",
|
|
54
66
|
"type": "node",
|
|
@@ -134,19 +146,7 @@
|
|
|
134
146
|
"console": "integratedTerminal",
|
|
135
147
|
},
|
|
136
148
|
{
|
|
137
|
-
"name": "
|
|
138
|
-
"type": "node",
|
|
139
|
-
"request": "launch",
|
|
140
|
-
"skipFiles": [
|
|
141
|
-
"<node_internals>/**"
|
|
142
|
-
],
|
|
143
|
-
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
144
|
-
"cwd": "${workspaceFolder}",
|
|
145
|
-
"args": ["cp", "./test/cp/test1.txt", "./test/cp2/test1.txt"],
|
|
146
|
-
"console": "integratedTerminal",
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
"name": "CopyGlobToFolder",
|
|
149
|
+
"name": "CopyFileToFile - Error source doesn't exist",
|
|
150
150
|
"type": "node",
|
|
151
151
|
"request": "launch",
|
|
152
152
|
"skipFiles": [
|
|
@@ -154,11 +154,11 @@
|
|
|
154
154
|
],
|
|
155
155
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
156
156
|
"cwd": "${workspaceFolder}",
|
|
157
|
-
"args": ["cp", "./test/cp
|
|
157
|
+
"args": ["cp", "./test/cp/testx.txt", "./test/cp2/"],
|
|
158
158
|
"console": "integratedTerminal",
|
|
159
159
|
},
|
|
160
160
|
{
|
|
161
|
-
"name": "CopyFileToFile - Error source
|
|
161
|
+
"name": "CopyFileToFile - Error source is a directory",
|
|
162
162
|
"type": "node",
|
|
163
163
|
"request": "launch",
|
|
164
164
|
"skipFiles": [
|
|
@@ -166,11 +166,11 @@
|
|
|
166
166
|
],
|
|
167
167
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
168
168
|
"cwd": "${workspaceFolder}",
|
|
169
|
-
"args": ["cp", "./test/cp/
|
|
169
|
+
"args": ["cp", "./test/cp/", "./test/cp2/test1.txt"],
|
|
170
170
|
"console": "integratedTerminal",
|
|
171
171
|
},
|
|
172
172
|
{
|
|
173
|
-
"name": "CopyFileToFile - Error
|
|
173
|
+
"name": "CopyFileToFile - Error target directory doesn't exist",
|
|
174
174
|
"type": "node",
|
|
175
175
|
"request": "launch",
|
|
176
176
|
"skipFiles": [
|
|
@@ -178,11 +178,11 @@
|
|
|
178
178
|
],
|
|
179
179
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
180
180
|
"cwd": "${workspaceFolder}",
|
|
181
|
-
"args": ["cp", "./test/cp/", "./test/
|
|
181
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cpx/"],
|
|
182
182
|
"console": "integratedTerminal",
|
|
183
183
|
},
|
|
184
184
|
{
|
|
185
|
-
"name": "
|
|
185
|
+
"name": "CopyFileToDirectory",
|
|
186
186
|
"type": "node",
|
|
187
187
|
"request": "launch",
|
|
188
188
|
"skipFiles": [
|
|
@@ -190,11 +190,11 @@
|
|
|
190
190
|
],
|
|
191
191
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
192
192
|
"cwd": "${workspaceFolder}",
|
|
193
|
-
"args": ["cp", "./test/cp/test1.txt", "./test/
|
|
193
|
+
"args": ["cp", "./test/cp/test1.txt", "./test/cp2/test1.txt"],
|
|
194
194
|
"console": "integratedTerminal",
|
|
195
195
|
},
|
|
196
196
|
{
|
|
197
|
-
"name": "
|
|
197
|
+
"name": "CopyGlobToDirectory",
|
|
198
198
|
"type": "node",
|
|
199
199
|
"request": "launch",
|
|
200
200
|
"skipFiles": [
|
|
@@ -202,7 +202,7 @@
|
|
|
202
202
|
],
|
|
203
203
|
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
204
204
|
"cwd": "${workspaceFolder}",
|
|
205
|
-
"args": ["cp", "
|
|
205
|
+
"args": ["cp", "./test/cp/*.js", "./test/cp2/"],
|
|
206
206
|
"console": "integratedTerminal",
|
|
207
207
|
},
|
|
208
208
|
{
|
|
@@ -265,6 +265,18 @@
|
|
|
265
265
|
"args": ["cp", "./test/cp/test1.txt", "./test/cp/test2.txt", "./test/cp/*.js", "./test/cp2/"],
|
|
266
266
|
"console": "integratedTerminal",
|
|
267
267
|
},
|
|
268
|
+
{
|
|
269
|
+
"name": "CopyDirectoryRecursively",
|
|
270
|
+
"type": "node",
|
|
271
|
+
"request": "launch",
|
|
272
|
+
"skipFiles": [
|
|
273
|
+
"<node_internals>/**"
|
|
274
|
+
],
|
|
275
|
+
"program": "${workspaceFolder}/bin/esmtk.js",
|
|
276
|
+
"cwd": "${workspaceFolder}",
|
|
277
|
+
"args": ["cp", "-r", "./test/cp/", "./test/cp2"],
|
|
278
|
+
"console": "integratedTerminal",
|
|
279
|
+
},
|
|
268
280
|
{
|
|
269
281
|
"name": "RemoveFile",
|
|
270
282
|
"type": "node",
|
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ Run tests (using Tape-ES)
|
|
|
51
51
|
|
|
52
52
|
- `[glob]` - the glob used to locate test files (default: `**/*.spec.js`)
|
|
53
53
|
- `-i` | `--ignore` - the ignore matcher pattern (default `**/node_modules/**`)
|
|
54
|
+
- `-r` | `--root` - the root path to run the tests from (default `process.cwd()`)
|
|
54
55
|
- `--watch` - watch for changes to the tests
|
|
55
56
|
|
|
56
57
|
### Usage
|
|
@@ -65,6 +66,9 @@ npx @vanillaes/esmtk test **/*.test.js
|
|
|
65
66
|
# run the tests (ignore tests)
|
|
66
67
|
npx @vanillaes/esmtk test **/*.test.js --ignore **/node_modules/**,src/rm.spec.js
|
|
67
68
|
|
|
69
|
+
# run the tests (ignore tests)
|
|
70
|
+
npx @vanillaes/esmtk test **/*.test.js --root src/
|
|
71
|
+
|
|
68
72
|
# run the tests (watch for changes)
|
|
69
73
|
npx @vanillaes/esmtk test --watch
|
|
70
74
|
```
|
package/bin/commands/test.js
CHANGED
|
@@ -9,13 +9,17 @@ export async function test (glob, options) {
|
|
|
9
9
|
const args = []
|
|
10
10
|
args.push('./node_modules/.bin/tape-es')
|
|
11
11
|
args.push(glob)
|
|
12
|
-
if (options?.watch) {
|
|
13
|
-
args.push('--watch')
|
|
14
|
-
}
|
|
15
12
|
if (options?.ignore) {
|
|
16
13
|
args.push('--ignore')
|
|
17
14
|
args.push(options.ignore)
|
|
18
15
|
}
|
|
16
|
+
if (options?.root) {
|
|
17
|
+
args.push('--root')
|
|
18
|
+
args.push(options.root)
|
|
19
|
+
}
|
|
20
|
+
if (options?.watch) {
|
|
21
|
+
args.push('--watch')
|
|
22
|
+
}
|
|
19
23
|
|
|
20
24
|
spawn('node', args, {
|
|
21
25
|
cwd: process.cwd(),
|
package/bin/esmtk.js
CHANGED
|
@@ -16,8 +16,9 @@ program.command('init')
|
|
|
16
16
|
|
|
17
17
|
program.command('test')
|
|
18
18
|
.description('Run tests using Tape-ES')
|
|
19
|
-
.argument('[glob]', 'The glob pattern used to find test files', '**/*.spec.js')
|
|
20
|
-
.option('-i, --ignore <ignore>', 'the ignore matcher pattern')
|
|
19
|
+
.argument('[glob]', 'The glob pattern used to find test files (default: `**/*.spec.js`)', '**/*.spec.js')
|
|
20
|
+
.option('-i, --ignore <ignore>', 'the ignore matcher pattern (default `**/node_modules/**`)')
|
|
21
|
+
.option('-r, --root <root>', 'the root path to run the tests from (default `process.cwd()`)')
|
|
21
22
|
.option('--watch', 'Watch the files for changes')
|
|
22
23
|
.action((glob, options) => {
|
|
23
24
|
test(glob, options)
|
package/package.json
CHANGED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"copyAsync": {
|
|
3
|
+
"cp1": {
|
|
4
|
+
"test1.txt": "test 1 text",
|
|
5
|
+
"test2.txt": "test 2 text"
|
|
6
|
+
},
|
|
7
|
+
"cp2": {}
|
|
8
|
+
},
|
|
9
|
+
"copyAsyncExpect": {
|
|
10
|
+
"cp1": {
|
|
11
|
+
"test1.txt": "test 1 text",
|
|
12
|
+
"test2.txt": "test 2 text"
|
|
13
|
+
},
|
|
14
|
+
"cp2": {
|
|
15
|
+
"test1.txt": "test 1 text"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"copyMultipleAsync": {
|
|
19
|
+
"cp1": {
|
|
20
|
+
"test1.txt": "test 1 text",
|
|
21
|
+
"test2.txt": "test 2 text",
|
|
22
|
+
"test1.js": "test 1 javascript",
|
|
23
|
+
"test2.js": "test 2 javascript"
|
|
24
|
+
},
|
|
25
|
+
"cp2": {}
|
|
26
|
+
},
|
|
27
|
+
"copyMultipleAsyncExpect": {
|
|
28
|
+
"cp1": {
|
|
29
|
+
"test1.txt": "test 1 text",
|
|
30
|
+
"test2.txt": "test 2 text",
|
|
31
|
+
"test1.js": "test 1 javascript",
|
|
32
|
+
"test2.js": "test 2 javascript"
|
|
33
|
+
},
|
|
34
|
+
"cp2": {
|
|
35
|
+
"test1.txt": "test 1 text",
|
|
36
|
+
"test1.js": "test 1 javascript"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"copyRecursiveAsync": {
|
|
40
|
+
"cp1": {
|
|
41
|
+
"test1.txt": "test 1 text",
|
|
42
|
+
"test1.js": "test 1 javascript",
|
|
43
|
+
"sub": {
|
|
44
|
+
"test2.txt": "test 2 text",
|
|
45
|
+
"test2.js": "test 2 javascript"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"cp2": {}
|
|
49
|
+
},
|
|
50
|
+
"copyRecursiveAsyncExpect": {
|
|
51
|
+
"cp1": {
|
|
52
|
+
"test1.txt": "test 1 text",
|
|
53
|
+
"test1.js": "test 1 javascript",
|
|
54
|
+
"sub": {
|
|
55
|
+
"test2.txt": "test 2 text",
|
|
56
|
+
"test2.js": "test 2 javascript"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"cp2": {
|
|
60
|
+
"test1.txt": "test 1 text",
|
|
61
|
+
"test1.js": "test 1 javascript",
|
|
62
|
+
"sub": {
|
|
63
|
+
"test2.txt": "test 2 text",
|
|
64
|
+
"test2.js": "test 2 javascript"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/src/cp.spec.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { filesλobjects, setup, teardown, test } from './__test__/test.js'
|
|
2
|
+
import { copyAsync, copyMultipleAsync, copyRecursiveAsync } from '@vanillaes/esmtk'
|
|
3
|
+
import { rmSync } from 'node:fs'
|
|
4
|
+
|
|
5
|
+
import { createRequire } from 'module'
|
|
6
|
+
const require = createRequire(import.meta.url)
|
|
7
|
+
const files = require('./__test__/cp.json')
|
|
8
|
+
const processExit = process.exit
|
|
9
|
+
|
|
10
|
+
setup(async (t) => {
|
|
11
|
+
process.exit = function () {
|
|
12
|
+
throw new Error('process.exit(1)')
|
|
13
|
+
}
|
|
14
|
+
process.chdir(process.cwd())
|
|
15
|
+
rmSync('test', { recursive: true, force: true })
|
|
16
|
+
|
|
17
|
+
t.end()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test('copyAsync - copy file-to-file', files.copyAsync, async (t) => {
|
|
21
|
+
await copyAsync('cp1/test1.txt', 'cp2/test1.txt')
|
|
22
|
+
|
|
23
|
+
const actual = filesλobjects()
|
|
24
|
+
const expect = files.copyAsyncExpect
|
|
25
|
+
|
|
26
|
+
t.deepEqual(actual, expect)
|
|
27
|
+
t.end()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('copyAsync - copy file-to-file - ERROR: no such file or directory (source)', files.copyAsync, async (t) => {
|
|
31
|
+
try {
|
|
32
|
+
await copyAsync('cp1/test1.ts', 'cp2/test1.ts')
|
|
33
|
+
t.fail('Expected error was not thrown')
|
|
34
|
+
} catch (err) {
|
|
35
|
+
t.ok(err, 'Error was thrown as expected')
|
|
36
|
+
}
|
|
37
|
+
t.end()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('copyAsync - copy file-to-file - ERROR: source is a directory', files.copyAsync, async (t) => {
|
|
41
|
+
try {
|
|
42
|
+
await copyAsync('cp1/', 'cp2/test1.txt')
|
|
43
|
+
t.fail('Expected error was not thrown')
|
|
44
|
+
} catch (err) {
|
|
45
|
+
t.ok(err, 'Error was thrown as expected')
|
|
46
|
+
}
|
|
47
|
+
t.end()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test('copyAsync - copy file-to-directory', files.copyAsync, async (t) => {
|
|
51
|
+
await copyAsync('cp1/test1.txt', 'cp2/')
|
|
52
|
+
|
|
53
|
+
const actual = filesλobjects()
|
|
54
|
+
const expect = files.copyAsyncExpect
|
|
55
|
+
|
|
56
|
+
t.deepEqual(actual, expect)
|
|
57
|
+
t.end()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
test('copyAsync - copy file-to-directory - ERROR: no such file or directory (target)', files.copyAsync, async (t) => {
|
|
61
|
+
try {
|
|
62
|
+
await copyAsync('cp1/test1.txt', 'cpx/')
|
|
63
|
+
t.fail('Expected error was not thrown')
|
|
64
|
+
} catch (err) {
|
|
65
|
+
t.ok(err, 'Error was thrown as expected')
|
|
66
|
+
}
|
|
67
|
+
t.end()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('copyMultipleAsync - copy multiple files', files.copyMultipleAsync, async (t) => {
|
|
71
|
+
await copyMultipleAsync(['cp1/test1.txt', 'cp1/test1.js'], 'cp2/')
|
|
72
|
+
|
|
73
|
+
const actual = filesλobjects()
|
|
74
|
+
const expect = files.copyMultipleAsyncExpect
|
|
75
|
+
|
|
76
|
+
t.deepEqual(actual, expect)
|
|
77
|
+
t.end()
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('copyMultipleAsync - copy multiple files - ERROR: no such file or directory (target)', files.copyMultipleAsync, async (t) => {
|
|
81
|
+
try {
|
|
82
|
+
await copyMultipleAsync(['cp1/test1.txt', 'cp1/test1.js'], 'cpx/')
|
|
83
|
+
t.fail('Expected error was not thrown')
|
|
84
|
+
} catch (err) {
|
|
85
|
+
t.ok(err, 'Error was thrown as expected')
|
|
86
|
+
}
|
|
87
|
+
t.end()
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
test('copyRecursiveAsync - ', files.copyRecursiveAsync, async (t) => {
|
|
91
|
+
await copyRecursiveAsync('cp1/', 'cp2/')
|
|
92
|
+
|
|
93
|
+
const actual = filesλobjects()
|
|
94
|
+
const expect = files.copyRecursiveAsyncExpect
|
|
95
|
+
|
|
96
|
+
t.deepEqual(actual, expect)
|
|
97
|
+
t.end()
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
teardown(async (t) => {
|
|
101
|
+
process.exit = processExit
|
|
102
|
+
process.chdir(process.cwd())
|
|
103
|
+
rmSync('test', { recursive: true, force: true })
|
|
104
|
+
|
|
105
|
+
t.end()
|
|
106
|
+
})
|
package/src/index.js
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.spec.js
CHANGED
|
@@ -30,6 +30,7 @@ test('removeAsync - remove a file', files.removeAsync, async (t) => {
|
|
|
30
30
|
test('removeAsync - ERROR: no such file or directory', files.removeAsync, async (t) => {
|
|
31
31
|
try {
|
|
32
32
|
await removeAsync('test1.ts')
|
|
33
|
+
t.fail('Expected error was not thrown')
|
|
33
34
|
} catch (err) {
|
|
34
35
|
t.ok(err, 'Error was thrown as expected')
|
|
35
36
|
}
|