@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.
Files changed (103) hide show
  1. package/dist/async.cjs +4 -2
  2. package/dist/async.cjs.map +1 -1
  3. package/dist/async.mjs +4 -2
  4. package/dist/async.mjs.map +1 -1
  5. package/dist/build.cjs +36 -16
  6. package/dist/build.cjs.map +2 -2
  7. package/dist/build.mjs +37 -17
  8. package/dist/build.mjs.map +2 -2
  9. package/dist/files.cjs +16 -2
  10. package/dist/files.cjs.map +1 -1
  11. package/dist/files.mjs +17 -3
  12. package/dist/files.mjs.map +1 -1
  13. package/dist/fork.cjs +7 -7
  14. package/dist/fork.cjs.map +1 -1
  15. package/dist/fork.mjs +7 -7
  16. package/dist/fork.mjs.map +1 -1
  17. package/dist/helpers.cjs +1 -18
  18. package/dist/helpers.cjs.map +1 -1
  19. package/dist/helpers.mjs +1 -17
  20. package/dist/helpers.mjs.map +1 -1
  21. package/dist/log/report.cjs +2 -1
  22. package/dist/log/report.cjs.map +1 -1
  23. package/dist/log/report.mjs +2 -1
  24. package/dist/log/report.mjs.map +1 -1
  25. package/dist/log.cjs +4 -1
  26. package/dist/log.cjs.map +1 -1
  27. package/dist/log.mjs +4 -1
  28. package/dist/log.mjs.map +1 -1
  29. package/dist/paths.cjs.map +1 -1
  30. package/dist/paths.mjs.map +1 -1
  31. package/dist/plugs/copy.cjs +2 -2
  32. package/dist/plugs/copy.cjs.map +1 -1
  33. package/dist/plugs/copy.mjs +1 -1
  34. package/dist/plugs/copy.mjs.map +1 -1
  35. package/dist/plugs/coverage/analysis.cjs +8 -3
  36. package/dist/plugs/coverage/analysis.cjs.map +2 -2
  37. package/dist/plugs/coverage/analysis.mjs +8 -3
  38. package/dist/plugs/coverage/analysis.mjs.map +2 -2
  39. package/dist/plugs/coverage/report.cjs +2 -1
  40. package/dist/plugs/coverage/report.cjs.map +1 -1
  41. package/dist/plugs/coverage/report.mjs +2 -1
  42. package/dist/plugs/coverage/report.mjs.map +1 -1
  43. package/dist/plugs/debug.cjs +6 -6
  44. package/dist/plugs/debug.cjs.map +1 -1
  45. package/dist/plugs/debug.mjs +7 -7
  46. package/dist/plugs/debug.mjs.map +1 -1
  47. package/dist/plugs/esbuild/fix-extensions.cjs +5 -4
  48. package/dist/plugs/esbuild/fix-extensions.cjs.map +1 -1
  49. package/dist/plugs/esbuild/fix-extensions.mjs +4 -3
  50. package/dist/plugs/esbuild/fix-extensions.mjs.map +1 -1
  51. package/dist/plugs/esbuild.cjs +34 -4
  52. package/dist/plugs/esbuild.cjs.map +2 -2
  53. package/dist/plugs/esbuild.mjs +35 -5
  54. package/dist/plugs/esbuild.mjs.map +2 -2
  55. package/dist/plugs/exec.cjs +2 -2
  56. package/dist/plugs/filter.cjs +2 -3
  57. package/dist/plugs/filter.cjs.map +1 -1
  58. package/dist/plugs/filter.mjs +2 -3
  59. package/dist/plugs/filter.mjs.map +1 -1
  60. package/dist/plugs/mocha/reporter.cjs +2 -2
  61. package/dist/plugs/mocha/reporter.cjs.map +1 -1
  62. package/dist/plugs/mocha/reporter.mjs +1 -1
  63. package/dist/plugs/mocha/reporter.mjs.map +1 -1
  64. package/dist/plugs/mocha/runner.cjs +1 -1
  65. package/dist/plugs/rmf.cjs +53 -0
  66. package/dist/plugs/rmf.cjs.map +6 -0
  67. package/dist/plugs/rmf.mjs +28 -0
  68. package/dist/plugs/rmf.mjs.map +6 -0
  69. package/dist/plugs/tsc/compiler.cjs +1 -1
  70. package/dist/plugs/tsc/options.cjs +1 -1
  71. package/dist/plugs/tsc/report.cjs +1 -1
  72. package/dist/plugs/tsc/runner.cjs +1 -1
  73. package/dist/plugs.cjs +1 -0
  74. package/dist/plugs.cjs.map +1 -1
  75. package/dist/plugs.mjs +1 -0
  76. package/dist/plugs.mjs.map +1 -1
  77. package/dist/run.cjs +3 -3
  78. package/dist/run.cjs.map +1 -1
  79. package/dist/run.mjs +3 -3
  80. package/dist/run.mjs.map +1 -1
  81. package/dist/utils/asyncfs.cjs +1 -1
  82. package/dist/utils/match.cjs +1 -1
  83. package/extra/cli.mjs +29 -20
  84. package/extra/ts-loader.mjs +10 -3
  85. package/package.json +4 -4
  86. package/src/files.ts +36 -4
  87. package/src/fork.ts +8 -8
  88. package/src/helpers.ts +4 -33
  89. package/src/paths.ts +1 -0
  90. package/src/plugs/copy.ts +1 -1
  91. package/src/plugs/debug.ts +7 -7
  92. package/src/plugs/esbuild.ts +69 -10
  93. package/src/plugs/filter.ts +2 -3
  94. package/src/plugs/rmf.ts +42 -0
  95. package/src/plugs.ts +1 -0
  96. package/src/run.ts +5 -5
  97. package/types/files.d.ts +14 -3
  98. package/types/helpers.d.ts +3 -13
  99. package/types/log/options.d.ts +2 -2
  100. package/types/plugs/rmf.d.ts +15 -0
  101. package/types/plugs.d.ts +1 -0
  102. package/types/run.d.ts +2 -2
  103. package/types/utils/asyncfs.d.ts +1 -1
@@ -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.add(relative)
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
  }
@@ -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
@@ -31,3 +31,4 @@ export * from './plugs/debug.js'
31
31
  export * from './plugs/esbuild.js'
32
32
  export * from './plugs/exec.js'
33
33
  export * from './plugs/filter.js'
34
+ export * from './plugs/rmf.js'
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
- * {@link process.cwd | current working directory}, otherwise it will be
55
- * resolved against the build file where the task was originally defined in.
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(getCurrentWorkingDirectory(), relative)
119
+ return resolveAbsolutePath(this.buildDir, relative)
120
120
  }
121
121
 
122
122
  if (isAbsolutePath(path)) return path
123
123
 
124
- return resolveAbsolutePath(this.buildDir, path)
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.add(file)
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" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
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
- /** Push files into the {@link Files} instance being built */
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 */
@@ -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
- * {@link process.cwd | current working directory}, otherwise it will be
22
- * resolved against the build file where the task was originally defined in.
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 {};
@@ -1,5 +1,5 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
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
@@ -14,3 +14,4 @@ export * from './plugs/debug.js';
14
14
  export * from './plugs/esbuild.js';
15
15
  export * from './plugs/exec.js';
16
16
  export * from './plugs/filter.js';
17
+ export * from './plugs/rmf.js';
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
- * {@link process.cwd | current working directory}, otherwise it will be
47
- * resolved against the build file where the task was originally defined in.
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}. */
@@ -1,4 +1,4 @@
1
- /// <reference types="node" resolution-mode="require"/>
1
+ /// <reference types="node" />
2
2
  import { constants } from 'node:fs';
3
3
  import fsp from 'node:fs/promises';
4
4
  declare const fs: typeof fsp & {