@plugjs/plug 0.0.1 → 0.0.4

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 (92) 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 +11 -9
  14. package/dist/fork.cjs.map +1 -1
  15. package/dist/fork.mjs +11 -9
  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 +1 -1
  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 +4 -3
  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/filter.cjs +2 -3
  56. package/dist/plugs/filter.cjs.map +1 -1
  57. package/dist/plugs/filter.mjs +2 -3
  58. package/dist/plugs/filter.mjs.map +1 -1
  59. package/dist/plugs/mocha/reporter.cjs +1 -1
  60. package/dist/plugs/mocha/reporter.cjs.map +1 -1
  61. package/dist/plugs/mocha/reporter.mjs +1 -1
  62. package/dist/plugs/mocha/reporter.mjs.map +1 -1
  63. package/dist/plugs/rmf.cjs +53 -0
  64. package/dist/plugs/rmf.cjs.map +6 -0
  65. package/dist/plugs/rmf.mjs +28 -0
  66. package/dist/plugs/rmf.mjs.map +6 -0
  67. package/dist/plugs.cjs +1 -0
  68. package/dist/plugs.cjs.map +1 -1
  69. package/dist/plugs.mjs +1 -0
  70. package/dist/plugs.mjs.map +1 -1
  71. package/dist/run.cjs +3 -3
  72. package/dist/run.cjs.map +1 -1
  73. package/dist/run.mjs +3 -3
  74. package/dist/run.mjs.map +1 -1
  75. package/extra/cli.mjs +4 -2
  76. package/package.json +2 -2
  77. package/src/files.ts +36 -4
  78. package/src/fork.ts +14 -11
  79. package/src/helpers.ts +4 -33
  80. package/src/paths.ts +1 -0
  81. package/src/plugs/copy.ts +1 -1
  82. package/src/plugs/debug.ts +7 -7
  83. package/src/plugs/esbuild.ts +69 -10
  84. package/src/plugs/filter.ts +2 -3
  85. package/src/plugs/rmf.ts +42 -0
  86. package/src/plugs.ts +1 -0
  87. package/src/run.ts +5 -5
  88. package/types/files.d.ts +12 -1
  89. package/types/helpers.d.ts +3 -13
  90. package/types/plugs/rmf.d.ts +15 -0
  91. package/types/plugs.d.ts +1 -0
  92. package/types/run.d.ts +2 -2
package/extra/cli.mjs CHANGED
@@ -8,7 +8,9 @@ async function main() {
8
8
  const { buildFile, tasks, listOnly } = parseCommandLine();
9
9
  if (tasks.length === 0)
10
10
  tasks.push("default");
11
- const build = (await import(buildFile)).default;
11
+ let build = await import(buildFile);
12
+ while (build && !isBuild(build))
13
+ build = build.default;
12
14
  if (!isBuild(build)) {
13
15
  console.log("Build file did not export a proper build");
14
16
  console.log();
@@ -209,4 +211,4 @@ export {
209
211
  isBuildFailure,
210
212
  parseCommandLine
211
213
  };
212
- //# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsiY2xpLm10cyJdLAogICJtYXBwaW5ncyI6ICI7QUFJQSxPQUFPLFlBQVk7QUFFbkIsT0FBTyxtQkFBbUI7QUFDMUIsT0FBTyxTQUFTO0FBQ2hCLE9BQU8sV0FBVztBQUNsQixPQUFPLFVBQVU7QUFXakIsZUFBZSxPQUFzQjtBQUNuQyxRQUFNLEVBQUUsV0FBVyxPQUFPLFNBQVMsSUFBSSxpQkFBaUI7QUFDeEQsTUFBSSxNQUFNLFdBQVc7QUFBRyxVQUFNLEtBQUssU0FBUztBQUU1QyxRQUFNLFNBQVMsTUFBTSxPQUFPLFlBQVk7QUFFeEMsTUFBSSxDQUFFLFFBQVEsS0FBSyxHQUFHO0FBQ3BCLFlBQVEsSUFBSSwwQ0FBMEM7QUFDdEQsWUFBUSxJQUFJO0FBQ1osWUFBUSxJQUFJLDJEQUEyRDtBQUN2RSxZQUFRLElBQUkseUNBQXlDO0FBQ3JELFlBQVEsSUFBSTtBQ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BQVMsT0FBTyxNQUF1QjtBQUNyQyxNQUFJO0FBQ0YsV0FBTyxJQUFJLFNBQVMsSUFBSSxFQUFFLE9BQU87QUFBQSxFQUNuQyxTQUFTLE9BQVA7QUFDQSxXQUFPO0FBQUEsRUFDVDtBQUNGOyIsCiAgIm5hbWVzIjogW10KfQo=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plugjs/plug",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -32,7 +32,7 @@
32
32
  "@babel/types": "^7.18.10",
33
33
  "@plugjs/cov8-html": "^0.0.1",
34
34
  "diff": "^5.1.0",
35
- "esbuild": "^0.15.4",
35
+ "esbuild": "^0.15.5",
36
36
  "eslint": "^8.22.0",
37
37
  "mocha": "^10.0.0",
38
38
  "picomatch": "^2.3.1",
package/src/files.ts CHANGED
@@ -1,17 +1,34 @@
1
1
  import { inspect } from 'node:util'
2
- import { AbsolutePath, assertRelativeChildPath, getAbsoluteParent, resolveAbsolutePath } from './paths.js'
2
+ import { assert } from './assert.js'
3
+ import { AbsolutePath, assertRelativeChildPath, getAbsoluteParent, isFile, resolveAbsolutePath } from './paths.js'
3
4
  import { mkdir, writeFile } from './utils/asyncfs.js'
4
5
 
5
6
  /** The {@link FilesBuilder} interface defines a builder for {@link Files}. */
6
7
  export interface FilesBuilder {
7
8
  /** The (resolved) directory the {@link Files} will be associated with */
8
9
  readonly directory: AbsolutePath
9
- /** Push files into the {@link Files} instance being built */
10
+
11
+ /**
12
+ * Push files into the {@link Files} instance being built **checking for
13
+ * their existance on disk**.
14
+ *
15
+ * This _will_ be slow, use {@link FilesBuilder.unchecked} when absolutely
16
+ * sure the file already exist.
17
+ */
10
18
  add(...files: string[]): this
19
+
20
+ /**
21
+ * Push files into the {@link Files} instance being built without checking
22
+ * they exist on disk _(use with care!)_.
23
+ */
24
+ unchecked(...files: string[]): this
25
+
11
26
  /** Merge orther {@link Files} instance to the {@link Files} being built */
12
27
  merge(...files: Files[]): this
28
+
13
29
  /** Write a file and add it to the {@link Files} instance being built */
14
30
  write(file: string, content: string | Buffer): Promise<AbsolutePath>
31
+
15
32
  /** Build and return a {@link Files} instance */
16
33
  build(): Files
17
34
  }
@@ -83,6 +100,21 @@ export class Files {
83
100
  add(...files: string[]): FilesBuilder {
84
101
  if (built) throw new Error('FileBuilder "build()" already called')
85
102
 
103
+ if (typeof files === 'string') files = [ files ]
104
+ for (const file of files) {
105
+ const relative = assertRelativeChildPath(instance.directory, file)
106
+ const resolved = resolveAbsolutePath(instance.directory, file)
107
+
108
+ assert(isFile(resolved), `File "${resolved}" does not exist`)
109
+ set.add(relative)
110
+ }
111
+
112
+ return this
113
+ },
114
+
115
+ unchecked(...files: string[]): FilesBuilder {
116
+ if (built) throw new Error('FileBuilder "build()" already called')
117
+
86
118
  if (typeof files === 'string') files = [ files ]
87
119
  for (const file of files) {
88
120
  const relative = assertRelativeChildPath(instance.directory, file)
@@ -97,7 +129,7 @@ export class Files {
97
129
 
98
130
  for (const files of args) {
99
131
  for (const file of files.absolutePaths()) {
100
- this.add(file)
132
+ this.unchecked(file)
101
133
  }
102
134
  }
103
135
 
@@ -111,7 +143,7 @@ export class Files {
111
143
 
112
144
  await mkdir(directory, { recursive: true })
113
145
  await writeFile(absolute, content)
114
- this.add(absolute)
146
+ this.unchecked(absolute)
115
147
 
116
148
  return absolute
117
149
  },
package/src/fork.ts CHANGED
@@ -128,7 +128,7 @@ export abstract class ForkingPlug implements Plug<Files | undefined> {
128
128
 
129
129
  child.on('error', (error) => {
130
130
  run.log.error('Child process error', error)
131
- return done ? reject(failure()) : void 0
131
+ return done || reject(failure())
132
132
  })
133
133
 
134
134
  child.on('message', (message: ForkResult) => {
@@ -139,21 +139,21 @@ export abstract class ForkingPlug implements Plug<Files | undefined> {
139
139
  child.on('exit', (code, signal) => {
140
140
  if (signal) {
141
141
  run.log.error(`Child process exited with signal ${signal}`, $gry(`(pid=${child.pid})`))
142
- return done ? reject(failure()) : void 0
142
+ return done || reject(failure())
143
143
  } else if (code !== 0) {
144
144
  run.log.error(`Child process exited with code ${code}`, $gry(`(pid=${child.pid})`))
145
- return done ? reject(failure()) : void 0
145
+ return done || reject(failure())
146
146
  } else if (! result) {
147
147
  run.log.error('Child process exited with no result', $gry(`(pid=${child.pid})`))
148
- return done ? reject(failure()) : void 0
148
+ return done || reject(failure())
149
149
  } else if (result.failed) {
150
150
  // definitely logged on the child side
151
- return done ? reject(failure()) : void 0
151
+ return done || reject(failure())
152
152
  }
153
153
 
154
154
  /* We definitely have a successful result! */
155
- return resolve(message.filesDir && message.filesList ?
156
- run.files(message.filesDir).add(...message.filesList).build() :
155
+ return done || resolve(message.filesDir && message.filesList ?
156
+ run.files(message.filesDir).unchecked(...message.filesList).build() :
157
157
  undefined)
158
158
  })
159
159
 
@@ -223,14 +223,17 @@ if ((process.argv[1] === requireFilename(__fileurl)) && (process.send)) {
223
223
  assert(isFile(scriptFile), `Script file ${$p(scriptFile)} not found`)
224
224
  const script = await import(scriptFile)
225
225
 
226
+ /* Figure out the constructor, in the "default" chain */
227
+ let Ctor = script
228
+ while (Ctor && (typeof Ctor !== 'function')) Ctor = Ctor.default
229
+
226
230
  /* Check that we have a proper constructor */
227
- assert(typeof script.default === 'function',
231
+ assert(typeof Ctor === 'function',
228
232
  `Script ${$p(scriptFile)} does not export a default constructor`)
229
233
 
230
234
  /* Create the Plug instance and our Files instance */
231
- const Ctor = script.default as new (...args: any[]) => Plug<Files | undefined>
232
- const plug = new Ctor(...constructorArgs)
233
- const files = run.files(filesDir).add(...filesList).build()
235
+ const plug = new Ctor(...constructorArgs) as Plug<Files | undefined>
236
+ const files = run.files(filesDir).unchecked(...filesList).build()
234
237
 
235
238
  /* Run and return the result */
236
239
  return plug.pipe(files, run)
package/src/helpers.ts CHANGED
@@ -27,7 +27,7 @@ export async function rmrf(directory: string): Promise<void> {
27
27
  return
28
28
  }
29
29
 
30
- log.info('Removing', $p(dir))
30
+ log.notice('Removing directory', $p(dir), 'recursively')
31
31
  await rm(dir, { recursive: true })
32
32
  }
33
33
 
@@ -46,8 +46,8 @@ export function setLogLevel(level: LogLevelString): void {
46
46
  * Resolve a path into an {@link AbsolutePath}.
47
47
  *
48
48
  * If the path starts with `@...` it is considered to be relative to the
49
- * {@link process.cwd | current working directory}, otherwise it will be
50
- * resolved against the build file where the task was originally defined in.
49
+ * _directory containing the build file where the task was defined_, otherwise
50
+ * it will be relative to the {@link process.cwd | current working directory}.
51
51
  */
52
52
  export function resolve(...paths: string[]): AbsolutePath {
53
53
  const run = currentRun()
@@ -60,7 +60,7 @@ export function resolve(...paths: string[]): AbsolutePath {
60
60
  * Create a new {@link Files} instance.
61
61
  */
62
62
  export function files(files: Files): FilesBuilder
63
- export function files(...paths: string[]): FilesBuilder
63
+ export function files(directory: string, ...paths: string[]): FilesBuilder
64
64
  export function files(first: Files | string | undefined, ...paths: string[]): FilesBuilder {
65
65
  const run = currentRun()
66
66
  assert(run, 'Unable to create files builder outside a running task')
@@ -114,32 +114,3 @@ export function pipe(files: Files | Promise<Files>): Pipe & Promise<Files> {
114
114
  assert(run, 'Unable to create pipes outside a running task')
115
115
  return run.pipe(files)
116
116
  }
117
-
118
- /** Await for the settlement of all the promises, then return their results. */
119
- export async function parallel<P extends readonly any[]>(promises: P): Promise<ParallelResult<P>> {
120
- const settlements = await Promise.allSettled(promises)
121
- const results: any[] = []
122
-
123
- let errors = 0
124
- for (const settlement of settlements) {
125
- if (settlement.status === 'fulfilled') {
126
- results.push(settlement.value)
127
- continue
128
- }
129
-
130
- log.error(settlement.reason)
131
- errors ++
132
- }
133
-
134
- assert(! errors, `Parallel execution failed for ${errors} tasks`)
135
- return results as ParallelResult<P>
136
- }
137
-
138
- type ParallelResult<T extends readonly any[]> =
139
- T extends readonly [ infer First, ...infer Rest ] ?
140
- [ Awaited<First>, ...ParallelResult<Rest> ] :
141
- T extends readonly [ infer Only ] ?
142
- [ Awaited<Only> ] :
143
- T extends readonly [] ?
144
- [] :
145
- never
package/src/paths.ts CHANGED
@@ -75,6 +75,7 @@ export function getCurrentWorkingDirectory(): AbsolutePath {
75
75
  return cwd
76
76
  }
77
77
 
78
+
78
79
  /* ========================================================================== *
79
80
  * MODULE RESOLUTION FUNCTIONS *
80
81
  * ========================================================================== */
package/src/plugs/copy.ts CHANGED
@@ -74,7 +74,7 @@ export class Copy implements Plug<Files> {
74
74
  }
75
75
 
76
76
  /* Record this file */
77
- builder.add(relative)
77
+ builder.unchecked(relative)
78
78
  }
79
79
 
80
80
  const result = builder.build()
@@ -1,5 +1,5 @@
1
1
  import { Files } from '../files.js'
2
- import { $gry, $p, $und, log } from '../log.js'
2
+ import { $gry, $p, $und } from '../log.js'
3
3
  import { install, Plug } from '../pipe.js'
4
4
  import { Run } from '../run.js'
5
5
 
@@ -8,14 +8,14 @@ export class Debug implements Plug<Files> {
8
8
  constructor() {}
9
9
 
10
10
  async pipe(files: Files, run: Run): Promise<Files> {
11
- log.notice('Debugging', files.length, 'files')
12
- log.notice('- base dir:', $p(run.resolve('@')))
13
- log.notice('- build file dir:', $p(run.resolve('.')))
14
- log.notice('- files dir:', $p(files.directory))
11
+ run.log.notice('Debugging', files.length, 'files')
12
+ run.log.notice('- base dir:', $p(run.resolve('@')))
13
+ run.log.notice('- build file dir:', $p(run.resolve('.')))
14
+ run.log.notice('- files dir:', $p(files.directory))
15
15
  if (files.length) {
16
16
  const [ path, ...paths ] = files
17
- log.notice('- relative paths:', $und($gry(path)))
18
- for (const p of paths) log.notice('- :', $und($gry(p)))
17
+ run.log.notice('- relative paths:', $und($gry(path)))
18
+ for (const p of paths) run.log.notice('- :', $und($gry(p)))
19
19
  }
20
20
  return files
21
21
  }
@@ -1,10 +1,12 @@
1
- import { build, BuildFailure, BuildOptions, BuildResult, Message, Metafile } from 'esbuild'
1
+ import { build, BuildFailure, BuildOptions, BuildResult, Format, Message, Metafile } from 'esbuild'
2
+ import { basename } from 'node:path'
2
3
  import { assert } from '../assert.js'
3
4
  import { Files, FilesBuilder } from '../files.js'
4
- import { $p, ERROR, ReportLevel, ReportRecord, WARN } from '../log.js'
5
- import { AbsolutePath, resolveAbsolutePath } from '../paths.js'
5
+ import { $p, ERROR, Logger, ReportLevel, ReportRecord, WARN } from '../log.js'
6
+ import { AbsolutePath, getAbsoluteParent, resolveAbsolutePath } from '../paths.js'
6
7
  import { install, Plug } from '../pipe.js'
7
8
  import { Run } from '../run.js'
9
+ import { readFile } from '../utils/asyncfs.js'
8
10
 
9
11
  export type ESBuildOptions = Omit<BuildOptions, 'absWorkingDir' | 'entryPoints' | 'watch'>
10
12
 
@@ -20,20 +22,23 @@ export class ESBuild implements Plug<Files> {
20
22
  const absWorkingDir = files.directory
21
23
 
22
24
  const options: BuildOptions = {
23
- /* Defaults */
25
+ /* Default our platform/target to NodeJS, current major version */
24
26
  platform: 'node',
25
- target: `node${process.versions['node']}`,
26
- format: 'cjs',
27
- outbase: absWorkingDir,
27
+ target: `node${process.versions['node'].split('.')[0]}`,
28
28
 
29
- logLevel: 'silent',
29
+ /* The default format (if not specified in options) is from package.json */
30
+ format: this._options.format || await _moduleFormat(files.directory, run.log),
31
+
32
+ /* Output bese directory */
33
+ outbase: absWorkingDir,
30
34
 
31
- /* Our options */
35
+ /* Merge in the caller's options */
32
36
  ...this._options,
33
37
 
34
38
  /* Always override */
35
39
  absWorkingDir,
36
40
  entryPoints,
41
+ logLevel: 'silent',
37
42
  watch: false,
38
43
  }
39
44
 
@@ -81,7 +86,7 @@ export class ESBuild implements Plug<Files> {
81
86
  assert(esbuild, 'ESBuild did not produce any result')
82
87
 
83
88
  for (const file in esbuild.metafile.outputs) {
84
- builder.add(resolveAbsolutePath(absWorkingDir, file))
89
+ builder.unchecked(resolveAbsolutePath(absWorkingDir, file))
85
90
  }
86
91
 
87
92
  const result = builder.build()
@@ -126,3 +131,57 @@ declare module '../pipe.js' {
126
131
  export * from './esbuild/bundle-locals.js'
127
132
  export * from './esbuild/check-dependencies.js'
128
133
  export * from './esbuild/fix-extensions.js'
134
+
135
+ /* ========================================================================== *
136
+ * DEFAULT MODULE FORMAT FROM PACKAGE.JSON *
137
+ * ========================================================================== */
138
+
139
+ /** Cache for directory to module format as discovered in "package.json" */
140
+ const _moduleFormatCache = new Map<AbsolutePath, Format>()
141
+
142
+ /**
143
+ * Figures out the _default_ module type for a directory, looking into the
144
+ * `package.json`'s `type` field (either `commonjs` or `module`)
145
+ */
146
+ async function _moduleFormat(directory: AbsolutePath, log: Logger): Promise<Format> {
147
+ /* Before doing anything else, check our cache */
148
+ const type = _moduleFormatCache.get(directory)
149
+ if (type) return type
150
+
151
+ /* Try to read the "package.json" file from this directory */
152
+ const file = resolveAbsolutePath(directory, 'package.json')
153
+
154
+ try {
155
+ const json = await readFile(file, 'utf-8')
156
+ const data = JSON.parse(json)
157
+
158
+ /* Be liberal in what you accept? Default to CommonJS if none found */
159
+ const type = data.type === 'module' ? 'esm' : 'cjs'
160
+ log.debug(`File "${file}" defines module type as "${data.type}" (${type})`)
161
+ _moduleFormatCache.set(directory, type)
162
+ return type
163
+ } catch (cause: any) {
164
+ /* We _accept_ a couple of errors, file not found, or file is directory */
165
+ if ((cause.code !== 'ENOENT') && (cause.code !== 'EISDIR')) throw cause
166
+ }
167
+
168
+ /*
169
+ * We couldn't find "package.json" in this directory, go up if we can!
170
+ *
171
+ * That said, if we are at a directory called "node_modules" we stop here,
172
+ * as we don't want to inherit the default type from an _importing_ package,
173
+ * into the _imported_ one...
174
+ */
175
+ const name = basename(directory)
176
+ const parent = getAbsoluteParent(directory)
177
+
178
+ if ((name === 'node_modules') || (parent === directory)) {
179
+ _moduleFormatCache.set(directory, 'cjs') // default
180
+ return 'cjs'
181
+ } else {
182
+ /* We also cache back, on the way up */
183
+ const type = await _moduleFormat(parent, log)
184
+ _moduleFormatCache.set(directory, type)
185
+ return type
186
+ }
187
+ }
@@ -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
@@ -6,8 +6,19 @@ import { AbsolutePath } from './paths.js';
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 {};
@@ -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}. */