@plugjs/plug 0.0.2 → 0.0.5
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/dist/async.cjs +4 -2
- package/dist/async.cjs.map +1 -1
- package/dist/async.mjs +4 -2
- package/dist/async.mjs.map +1 -1
- package/dist/build.cjs +36 -16
- package/dist/build.cjs.map +2 -2
- package/dist/build.mjs +37 -17
- package/dist/build.mjs.map +2 -2
- package/dist/files.cjs +16 -2
- package/dist/files.cjs.map +1 -1
- package/dist/files.mjs +17 -3
- package/dist/files.mjs.map +1 -1
- package/dist/fork.cjs +7 -7
- package/dist/fork.cjs.map +1 -1
- package/dist/fork.mjs +7 -7
- package/dist/fork.mjs.map +1 -1
- package/dist/helpers.cjs +1 -18
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.mjs +1 -17
- package/dist/helpers.mjs.map +1 -1
- package/dist/log/report.cjs +2 -1
- package/dist/log/report.cjs.map +1 -1
- package/dist/log/report.mjs +2 -1
- package/dist/log/report.mjs.map +1 -1
- package/dist/log.cjs +4 -1
- package/dist/log.cjs.map +1 -1
- package/dist/log.mjs +4 -1
- package/dist/log.mjs.map +1 -1
- package/dist/paths.cjs.map +1 -1
- package/dist/paths.mjs.map +1 -1
- package/dist/plugs/copy.cjs +2 -2
- package/dist/plugs/copy.cjs.map +1 -1
- package/dist/plugs/copy.mjs +1 -1
- package/dist/plugs/copy.mjs.map +1 -1
- package/dist/plugs/coverage/analysis.cjs +8 -3
- package/dist/plugs/coverage/analysis.cjs.map +2 -2
- package/dist/plugs/coverage/analysis.mjs +8 -3
- package/dist/plugs/coverage/analysis.mjs.map +2 -2
- package/dist/plugs/coverage/report.cjs +2 -1
- package/dist/plugs/coverage/report.cjs.map +1 -1
- package/dist/plugs/coverage/report.mjs +2 -1
- package/dist/plugs/coverage/report.mjs.map +1 -1
- package/dist/plugs/debug.cjs +6 -6
- package/dist/plugs/debug.cjs.map +1 -1
- package/dist/plugs/debug.mjs +7 -7
- package/dist/plugs/debug.mjs.map +1 -1
- package/dist/plugs/esbuild/fix-extensions.cjs +5 -4
- package/dist/plugs/esbuild/fix-extensions.cjs.map +1 -1
- package/dist/plugs/esbuild/fix-extensions.mjs +4 -3
- package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
- package/dist/plugs/esbuild.cjs +34 -4
- package/dist/plugs/esbuild.cjs.map +2 -2
- package/dist/plugs/esbuild.mjs +35 -5
- package/dist/plugs/esbuild.mjs.map +2 -2
- package/dist/plugs/exec.cjs +2 -2
- package/dist/plugs/filter.cjs +2 -3
- package/dist/plugs/filter.cjs.map +1 -1
- package/dist/plugs/filter.mjs +2 -3
- package/dist/plugs/filter.mjs.map +1 -1
- package/dist/plugs/mocha/reporter.cjs +2 -2
- package/dist/plugs/mocha/reporter.cjs.map +1 -1
- package/dist/plugs/mocha/reporter.mjs +1 -1
- package/dist/plugs/mocha/reporter.mjs.map +1 -1
- package/dist/plugs/mocha/runner.cjs +1 -1
- package/dist/plugs/rmf.cjs +53 -0
- package/dist/plugs/rmf.cjs.map +6 -0
- package/dist/plugs/rmf.mjs +28 -0
- package/dist/plugs/rmf.mjs.map +6 -0
- package/dist/plugs/tsc/compiler.cjs +1 -1
- package/dist/plugs/tsc/options.cjs +1 -1
- package/dist/plugs/tsc/report.cjs +1 -1
- package/dist/plugs/tsc/runner.cjs +1 -1
- package/dist/plugs.cjs +1 -0
- package/dist/plugs.cjs.map +1 -1
- package/dist/plugs.mjs +1 -0
- package/dist/plugs.mjs.map +1 -1
- package/dist/run.cjs +3 -3
- package/dist/run.cjs.map +1 -1
- package/dist/run.mjs +3 -3
- package/dist/run.mjs.map +1 -1
- package/dist/utils/asyncfs.cjs +1 -1
- package/dist/utils/match.cjs +1 -1
- package/extra/cli.mjs +29 -20
- package/extra/ts-loader.mjs +10 -3
- package/package.json +4 -4
- package/src/files.ts +36 -4
- package/src/fork.ts +8 -8
- package/src/helpers.ts +4 -33
- package/src/paths.ts +1 -0
- package/src/plugs/copy.ts +1 -1
- package/src/plugs/debug.ts +7 -7
- package/src/plugs/esbuild.ts +69 -10
- package/src/plugs/filter.ts +2 -3
- package/src/plugs/rmf.ts +42 -0
- package/src/plugs.ts +1 -0
- package/src/run.ts +5 -5
- package/types/files.d.ts +14 -3
- package/types/helpers.d.ts +3 -13
- package/types/log/options.d.ts +2 -2
- package/types/plugs/rmf.d.ts +15 -0
- package/types/plugs.d.ts +1 -0
- package/types/run.d.ts +2 -2
- package/types/utils/asyncfs.d.ts +1 -1
package/src/plugs/filter.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Files } from '../files.js'
|
|
2
|
-
import { log } from '../log.js'
|
|
3
2
|
import { resolveRelativeChildPath } from '../paths.js'
|
|
4
3
|
import { install, Plug } from '../pipe.js'
|
|
5
4
|
import { Run } from '../run.js'
|
|
@@ -31,12 +30,12 @@ export class Filter implements Plug<Files> {
|
|
|
31
30
|
|
|
32
31
|
for (const file of files.absolutePaths()) {
|
|
33
32
|
const relative = resolveRelativeChildPath(builder.directory, file)
|
|
34
|
-
if (relative && matcher(relative)) builder.
|
|
33
|
+
if (relative && matcher(relative)) builder.unchecked(relative)
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
const result = builder.build()
|
|
38
37
|
const discarded = files.length - result.length
|
|
39
|
-
log.debug('Filtered', result.length, 'files (discarded', discarded, 'files)')
|
|
38
|
+
run.log.debug('Filtered', result.length, 'files (discarded', discarded, 'files)')
|
|
40
39
|
|
|
41
40
|
return result
|
|
42
41
|
}
|
package/src/plugs/rmf.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Files } from '../files.js'
|
|
2
|
+
import { $gry, $p } from '../log.js'
|
|
3
|
+
import { install, Plug } from '../pipe.js'
|
|
4
|
+
import { Run } from '../run.js'
|
|
5
|
+
import { rm } from '../utils/asyncfs.js'
|
|
6
|
+
|
|
7
|
+
/** Remove some files using globs. */
|
|
8
|
+
export class Rmf implements Plug<undefined> {
|
|
9
|
+
private readonly _dryRun: boolean
|
|
10
|
+
|
|
11
|
+
constructor(dryRun?: boolean) {
|
|
12
|
+
this._dryRun = !! dryRun
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async pipe(files: Files, run: Run): Promise<undefined> {
|
|
16
|
+
if (this._dryRun) {
|
|
17
|
+
for (const file of files.absolutePaths()) {
|
|
18
|
+
run.log.notice('Not removing file', $p(file), $gry('(dry-run)'))
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
for (const file of files.absolutePaths()) {
|
|
22
|
+
run.log.notice('Removing file', $p(file))
|
|
23
|
+
await rm(file)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return undefined
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/* ========================================================================== *
|
|
32
|
+
* INSTALLATION *
|
|
33
|
+
* ========================================================================== */
|
|
34
|
+
|
|
35
|
+
install('rmf', Rmf)
|
|
36
|
+
|
|
37
|
+
declare module '../pipe.js' {
|
|
38
|
+
export interface Pipe {
|
|
39
|
+
/** Remove all {@link Files} piped in. */
|
|
40
|
+
rmf: PipeExtension<typeof Rmf>
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/plugs.ts
CHANGED
package/src/run.ts
CHANGED
|
@@ -51,8 +51,8 @@ export interface Run {
|
|
|
51
51
|
* Resolve a path in the context of this {@link Run}.
|
|
52
52
|
*
|
|
53
53
|
* If the path starts with `@...` it is considered to be relative to the
|
|
54
|
-
*
|
|
55
|
-
*
|
|
54
|
+
* _directory containing the build file where the task was defined_, otherwise
|
|
55
|
+
* it will be relative to the {@link process.cwd | current working directory}.
|
|
56
56
|
*/
|
|
57
57
|
resolve(...paths: string[]): AbsolutePath
|
|
58
58
|
|
|
@@ -116,12 +116,12 @@ export class RunImpl implements Run {
|
|
|
116
116
|
if (path.startsWith('@')) {
|
|
117
117
|
const relative = path.substring(1)
|
|
118
118
|
assert(! isAbsolutePath(relative), `Path component of "${path}" is absolute`)
|
|
119
|
-
return resolveAbsolutePath(
|
|
119
|
+
return resolveAbsolutePath(this.buildDir, relative)
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
if (isAbsolutePath(path)) return path
|
|
123
123
|
|
|
124
|
-
return resolveAbsolutePath(
|
|
124
|
+
return resolveAbsolutePath(getCurrentWorkingDirectory(), path)
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
files(files: Files): FilesBuilder
|
|
@@ -142,7 +142,7 @@ export class RunImpl implements Run {
|
|
|
142
142
|
const promise = Promise.resolve().then(async () => {
|
|
143
143
|
const builder = this.files(directory || '.')
|
|
144
144
|
for await (const file of walk(builder.directory, [ glob, ...params ], options)) {
|
|
145
|
-
builder.
|
|
145
|
+
builder.unchecked(file)
|
|
146
146
|
}
|
|
147
147
|
return builder.build()
|
|
148
148
|
})
|
package/types/files.d.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
/// <reference types="node"
|
|
2
|
-
/// <reference types="node"
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
3
|
import { inspect } from 'node:util';
|
|
4
4
|
import { AbsolutePath } from './paths.js';
|
|
5
5
|
/** The {@link FilesBuilder} interface defines a builder for {@link Files}. */
|
|
6
6
|
export interface FilesBuilder {
|
|
7
7
|
/** The (resolved) directory the {@link Files} will be associated with */
|
|
8
8
|
readonly directory: AbsolutePath;
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Push files into the {@link Files} instance being built **checking for
|
|
11
|
+
* their existance on disk**.
|
|
12
|
+
*
|
|
13
|
+
* This _will_ be slow, use {@link FilesBuilder.unchecked} when absolutely
|
|
14
|
+
* sure the file already exist.
|
|
15
|
+
*/
|
|
10
16
|
add(...files: string[]): this;
|
|
17
|
+
/**
|
|
18
|
+
* Push files into the {@link Files} instance being built without checking
|
|
19
|
+
* they exist on disk _(use with care!)_.
|
|
20
|
+
*/
|
|
21
|
+
unchecked(...files: string[]): this;
|
|
11
22
|
/** Merge orther {@link Files} instance to the {@link Files} being built */
|
|
12
23
|
merge(...files: Files[]): this;
|
|
13
24
|
/** Write a file and add it to the {@link Files} instance being built */
|
package/types/helpers.d.ts
CHANGED
|
@@ -18,15 +18,15 @@ export declare function setLogLevel(level: LogLevelString): void;
|
|
|
18
18
|
* Resolve a path into an {@link AbsolutePath}.
|
|
19
19
|
*
|
|
20
20
|
* If the path starts with `@...` it is considered to be relative to the
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* _directory containing the build file where the task was defined_, otherwise
|
|
22
|
+
* it will be relative to the {@link process.cwd | current working directory}.
|
|
23
23
|
*/
|
|
24
24
|
export declare function resolve(...paths: string[]): AbsolutePath;
|
|
25
25
|
/**
|
|
26
26
|
* Create a new {@link Files} instance.
|
|
27
27
|
*/
|
|
28
28
|
export declare function files(files: Files): FilesBuilder;
|
|
29
|
-
export declare function files(...paths: string[]): FilesBuilder;
|
|
29
|
+
export declare function files(directory: string, ...paths: string[]): FilesBuilder;
|
|
30
30
|
/**
|
|
31
31
|
* Merge multiple {@link Files} instance.
|
|
32
32
|
*/
|
|
@@ -37,13 +37,3 @@ export declare function merge(args: (Files | Promise<Files>)[]): Promise<Files>
|
|
|
37
37
|
export declare function find(glob: string, ...args: ParseOptions<FindOptions>): Pipe & Promise<Files>;
|
|
38
38
|
/** Create a {@link Pipe} from a {@link Files} instance. */
|
|
39
39
|
export declare function pipe(files: Files | Promise<Files>): Pipe & Promise<Files>;
|
|
40
|
-
/** Await for the settlement of all the promises, then return their results. */
|
|
41
|
-
export declare function parallel<P extends readonly any[]>(promises: P): Promise<ParallelResult<P>>;
|
|
42
|
-
declare type ParallelResult<T extends readonly any[]> = T extends readonly [infer First, ...infer Rest] ? [
|
|
43
|
-
Awaited<First>,
|
|
44
|
-
...ParallelResult<Rest>
|
|
45
|
-
] : T extends readonly [infer Only] ? [
|
|
46
|
-
Awaited<Only>
|
|
47
|
-
] : T extends readonly [] ? [
|
|
48
|
-
] : never;
|
|
49
|
-
export {};
|
package/types/log/options.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="node"
|
|
2
|
-
/// <reference types="node"
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
3
|
import { Writable } from 'node:stream';
|
|
4
4
|
import { InspectOptions } from 'node:util';
|
|
5
5
|
import { LogLevel } from './levels.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Files } from '../files.js';
|
|
2
|
+
import { Plug } from '../pipe.js';
|
|
3
|
+
import { Run } from '../run.js';
|
|
4
|
+
/** Remove some files using globs. */
|
|
5
|
+
export declare class Rmf implements Plug<undefined> {
|
|
6
|
+
private readonly _dryRun;
|
|
7
|
+
constructor(dryRun?: boolean);
|
|
8
|
+
pipe(files: Files, run: Run): Promise<undefined>;
|
|
9
|
+
}
|
|
10
|
+
declare module '../pipe.js' {
|
|
11
|
+
interface Pipe {
|
|
12
|
+
/** Remove all {@link Files} piped in. */
|
|
13
|
+
rmf: PipeExtension<typeof Rmf>;
|
|
14
|
+
}
|
|
15
|
+
}
|
package/types/plugs.d.ts
CHANGED
package/types/run.d.ts
CHANGED
|
@@ -43,8 +43,8 @@ export interface Run {
|
|
|
43
43
|
* Resolve a path in the context of this {@link Run}.
|
|
44
44
|
*
|
|
45
45
|
* If the path starts with `@...` it is considered to be relative to the
|
|
46
|
-
*
|
|
47
|
-
*
|
|
46
|
+
* _directory containing the build file where the task was defined_, otherwise
|
|
47
|
+
* it will be relative to the {@link process.cwd | current working directory}.
|
|
48
48
|
*/
|
|
49
49
|
resolve(...paths: string[]): AbsolutePath;
|
|
50
50
|
/** Create a {@link FilesBuilder} cloning an existing {@link Files}. */
|
package/types/utils/asyncfs.d.ts
CHANGED