@plugjs/plug 0.0.4 → 0.0.7

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 (62) hide show
  1. package/dist/files.cjs +5 -8
  2. package/dist/files.cjs.map +1 -1
  3. package/dist/files.mjs +5 -8
  4. package/dist/files.mjs.map +1 -1
  5. package/dist/log/report.cjs +16 -7
  6. package/dist/log/report.cjs.map +1 -1
  7. package/dist/log/report.mjs +17 -8
  8. package/dist/log/report.mjs.map +1 -1
  9. package/dist/paths.cjs +1 -1
  10. package/dist/paths.cjs.map +1 -1
  11. package/dist/paths.mjs +2 -2
  12. package/dist/paths.mjs.map +1 -1
  13. package/dist/plugs/copy.cjs +6 -12
  14. package/dist/plugs/copy.cjs.map +2 -2
  15. package/dist/plugs/copy.mjs +6 -6
  16. package/dist/plugs/copy.mjs.map +1 -1
  17. package/dist/plugs/esbuild/fix-extensions.cjs +1 -1
  18. package/dist/plugs/esbuild.cjs +0 -1
  19. package/dist/plugs/esbuild.cjs.map +1 -1
  20. package/dist/plugs/esbuild.mjs +0 -1
  21. package/dist/plugs/esbuild.mjs.map +1 -1
  22. package/dist/plugs/exec.cjs +2 -2
  23. package/dist/plugs/mocha/reporter.cjs +1 -1
  24. package/dist/plugs/mocha/runner.cjs +1 -1
  25. package/dist/plugs/tsc/compiler.cjs +1 -1
  26. package/dist/plugs/tsc/options.cjs +1 -1
  27. package/dist/plugs/tsc/report.cjs +1 -1
  28. package/dist/plugs/tsc/runner.cjs +1 -1
  29. package/dist/run.cjs +3 -2
  30. package/dist/run.cjs.map +1 -1
  31. package/dist/run.mjs +4 -3
  32. package/dist/run.mjs.map +1 -1
  33. package/dist/utils/asyncfs.cjs +5 -9
  34. package/dist/utils/asyncfs.cjs.map +2 -2
  35. package/dist/utils/asyncfs.mjs +3 -7
  36. package/dist/utils/asyncfs.mjs.map +2 -2
  37. package/dist/utils/match.cjs +1 -1
  38. package/dist/utils/walk.cjs +7 -4
  39. package/dist/utils/walk.cjs.map +1 -1
  40. package/dist/utils/walk.mjs +8 -5
  41. package/dist/utils/walk.mjs.map +1 -1
  42. package/extra/cli.mjs +29 -20
  43. package/extra/ts-loader.mjs +10 -3
  44. package/package.json +5 -5
  45. package/src/files.ts +9 -12
  46. package/src/log/report.ts +22 -11
  47. package/src/paths.ts +2 -2
  48. package/src/plugs/copy.ts +6 -7
  49. package/src/plugs/esbuild.ts +0 -1
  50. package/src/run.ts +4 -3
  51. package/src/utils/asyncfs.ts +9 -8
  52. package/src/utils/walk.ts +10 -5
  53. package/types/files.d.ts +1 -5
  54. package/types/log/options.d.ts +2 -2
  55. package/types/plugs/esbuild.d.ts +0 -1
  56. package/types/utils/asyncfs.d.ts +3 -6
  57. package/dist/plugs/esbuild/check-dependencies.cjs +0 -140
  58. package/dist/plugs/esbuild/check-dependencies.cjs.map +0 -6
  59. package/dist/plugs/esbuild/check-dependencies.mjs +0 -115
  60. package/dist/plugs/esbuild/check-dependencies.mjs.map +0 -6
  61. package/src/plugs/esbuild/check-dependencies.ts +0 -158
  62. package/types/plugs/esbuild/check-dependencies.d.ts +0 -12
package/src/log/report.ts CHANGED
@@ -3,7 +3,7 @@ import { AbsolutePath } from '../paths.js'
3
3
  import { readFile } from '../utils/asyncfs.js'
4
4
  import { $blu, $cyn, $gry, $red, $und, $wht, $ylw } from './colors.js'
5
5
  import { emitColor, emitPlain, LogEmitter } from './emit.js'
6
- import { ERROR, INFO, LogLevels, NOTICE, WARN } from './levels.js'
6
+ import { ERROR, LogLevels, NOTICE, WARN } from './levels.js'
7
7
  import { logOptions } from './options.js'
8
8
 
9
9
  /* ========================================================================== */
@@ -288,6 +288,9 @@ class ReportImpl implements Report {
288
288
  let lPad = 0
289
289
  let cPad = 0
290
290
 
291
+ /* Skip report all together if empty! */
292
+ if ((this._annotations.size === 0) && (this._records.size === 0)) return this
293
+
291
294
  /* This is GIANT: sort and convert our data for easy reporting */
292
295
  const entries = [ ...this._annotations.keys(), ...this._records.keys() ]
293
296
  // dedupe
@@ -334,12 +337,11 @@ class ReportImpl implements Report {
334
337
  cPad = cPad.toString().length
335
338
 
336
339
  /* Basic emit options */
337
- const options = { taskName: this._task, level: INFO }
340
+ const options = { taskName: this._task, level: NOTICE }
338
341
 
339
342
  this._emitter(options, [ '' ])
340
343
  this._emitter(options, [ $und($wht(this._title)) ])
341
344
 
342
-
343
345
  /* Iterate through all our [file,reports] tuple */
344
346
  for (let f = 0; f < entries.length; f ++) {
345
347
  const { file, records, annotation } = entries[f]
@@ -418,16 +420,25 @@ class ReportImpl implements Report {
418
420
  }
419
421
  }
420
422
 
421
- /* Our totals */
422
- const eLabel = this.errors === 1 ? 'error' : 'errors'
423
- const wLabel = this.warnings === 1 ? 'warning' : 'warnings'
424
- const eNumber = this.errors ? $red(this.errors) : 'no'
425
- const wNumber = this.warnings ? $ylw(this.warnings) : 'no'
426
-
427
- this._emitter(options, [ '' ])
428
- this._emitter(options, [ 'Found', eNumber, eLabel, 'and', wNumber, wLabel ])
423
+ /* Our totals (if any) */
429
424
  this._emitter(options, [ '' ])
430
425
 
426
+ const status: any[] = [ 'Found' ]
427
+ if (this.errors) {
428
+ status.push($red(this.errors), this.errors === 1 ? 'error' : 'errors' )
429
+ }
430
+
431
+ if (this.warnings) {
432
+ if (this.errors) status.push('and')
433
+ status.push($ylw(this.warnings), this.warnings === 1 ? 'warning' : 'warnings' )
434
+ }
435
+
436
+ if (this.errors || this.warnings) {
437
+ this._emitter(options, status)
438
+ this._emitter(options, [ '' ])
439
+ }
440
+
441
+ /* Done! */
431
442
  return this
432
443
  }
433
444
  }
package/src/paths.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { statSync } from 'node:fs'
2
2
  import { createRequire } from 'node:module'
3
- import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path'
3
+ import { dirname, extname, isAbsolute, join, normalize, relative, resolve, sep } from 'node:path'
4
4
  import { fileURLToPath, pathToFileURL } from 'node:url'
5
5
  import { assert } from './assert.js'
6
6
 
@@ -158,7 +158,7 @@ export function commonPath(path: AbsolutePath, ...paths: string[]): AbsolutePath
158
158
  // Here the first path will be split into its components
159
159
  // on win => [ 'C:', 'Windows', 'System32' ]
160
160
  // on unx => [ '', 'usr'
161
- const components = path.split(sep)
161
+ const components = normalize(path).split(sep)
162
162
 
163
163
  let length = components.length
164
164
  for (const current of paths) {
package/src/plugs/copy.ts CHANGED
@@ -1,11 +1,10 @@
1
- import fs from '../utils/asyncfs.js'
2
-
3
1
  import { assert } from '../assert.js'
4
2
  import { Files } from '../files.js'
5
3
  import { $p } from '../log.js'
6
4
  import { assertAbsolutePath, getAbsoluteParent, resolveAbsolutePath } from '../paths.js'
7
5
  import { install, Plug } from '../pipe.js'
8
6
  import { Run } from '../run.js'
7
+ import { chmod, copyFile, fsConstants, mkdir } from '../utils/asyncfs.js'
9
8
 
10
9
  /** Options for copying files */
11
10
  export interface CopyOptions {
@@ -30,7 +29,7 @@ export class Copy implements Plug<Files> {
30
29
  async pipe(files: Files, run: Run): Promise<Files> {
31
30
  /* Destructure our options with some defaults and compute write flags */
32
31
  const { mode, dirMode, overwrite, rename = (s): string => s } = this._options
33
- const flags = overwrite ? fs.constants.COPYFILE_EXCL : 0
32
+ const flags = overwrite ? fsConstants.COPYFILE_EXCL : 0
34
33
  const dmode = parseMode(dirMode)
35
34
  const fmode = parseMode(mode)
36
35
 
@@ -51,26 +50,26 @@ export class Copy implements Plug<Files> {
51
50
 
52
51
  /* Create the parent directory, recursively */
53
52
  const directory = getAbsoluteParent(target)
54
- const firstParent = await fs.mkdir(directory, { recursive: true })
53
+ const firstParent = await mkdir(directory, { recursive: true })
55
54
 
56
55
  /* Set the mode for all created directories */
57
56
  if (firstParent && (dmode !== undefined)) {
58
57
  assertAbsolutePath(firstParent)
59
58
  for (let dir = directory; ; dir = getAbsoluteParent(dir)) {
60
59
  run.log.trace(`Setting mode ${stringifyMode(dmode)} for directory`, $p(dir))
61
- await fs.chmod(dir, dmode)
60
+ await chmod(dir, dmode)
62
61
  if (dir === firstParent) break
63
62
  }
64
63
  }
65
64
 
66
65
  /* Actually _copy_ the file */
67
66
  run.log.trace(`Copying "${$p(absolute)}" to "${$p(target)}"`)
68
- await fs.copyFile(absolute, target, flags)
67
+ await copyFile(absolute, target, flags)
69
68
 
70
69
  /* Set the mode, if we need to */
71
70
  if (fmode !== undefined) {
72
71
  run.log.trace(`Setting mode ${stringifyMode(fmode)} for file`, $p(target))
73
- await fs.chmod(target, fmode)
72
+ await chmod(target, fmode)
74
73
  }
75
74
 
76
75
  /* Record this file */
@@ -129,7 +129,6 @@ declare module '../pipe.js' {
129
129
  * ========================================================================== */
130
130
 
131
131
  export * from './esbuild/bundle-locals.js'
132
- export * from './esbuild/check-dependencies.js'
133
132
  export * from './esbuild/fix-extensions.js'
134
133
 
135
134
  /* ========================================================================== *
package/src/run.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { join } from 'node:path'
1
+ import { join, normalize, sep } from 'node:path'
2
2
  import { assert } from './assert.js'
3
3
  import { Files, FilesBuilder } from './files.js'
4
4
  import { createReport, getLevelNumber, getLogger, Logger, LogLevelString, Report } from './log.js'
@@ -114,8 +114,9 @@ export class RunImpl implements Run {
114
114
  if (! path) return this.buildDir
115
115
 
116
116
  if (path.startsWith('@')) {
117
- const relative = path.substring(1)
118
- assert(! isAbsolutePath(relative), `Path component of "${path}" is absolute`)
117
+ const components = normalize(path.substring(1)).split(sep)
118
+ const relative = join(...components) // this will remove any leading slash
119
+ assert(! isAbsolutePath(relative), `Path "${path.substring(1)}" is absolute`)
119
120
  return resolveAbsolutePath(this.buildDir, relative)
120
121
  }
121
122
 
@@ -1,6 +1,12 @@
1
1
  import { constants } from 'node:fs'
2
2
  import fsp from 'node:fs/promises'
3
3
 
4
+ type FsPromises = typeof fsp
5
+
6
+ type FsWrappers = {
7
+ [ K in keyof FsPromises as FsPromises[K] extends ((...args: any[]) => any) ? K : never ]: FsPromises[K]
8
+ }
9
+
4
10
  /*
5
11
  * I have no idea why sometimes stacks don't have a trace when coming out of
6
12
  * the "node:fs/promises" api... There is a _stack_ property on the object
@@ -35,17 +41,12 @@ const fs = Object.entries(fsp as any).reduce((fs, [ key, val ]) => {
35
41
  Object.defineProperty(f, 'name', { value: key })
36
42
  /* Assign the wrapper to our exports */
37
43
  fs[key] = f
38
- } else {
39
- /* Not a function, no wrapping... */
40
- fs[key] = val
41
44
  }
42
45
 
43
46
  /* Return the "reduced" exports */
44
47
  return fs
45
- }, { constants } as any) as typeof fsp & { constants: typeof constants }
48
+ }, {} as any) as FsWrappers
46
49
 
47
- /* Export _our_ version of the "node:fs/promises" module */
48
- export default fs
49
50
 
50
51
  /* Export all the wrappers to "node:fs/promises" individually */
51
52
  export const access = fs.access
@@ -78,5 +79,5 @@ export const appendFile = fs.appendFile
78
79
  export const readFile = fs.readFile
79
80
  export const watch = fs.watch
80
81
 
81
- /* Export constants from "node:/fs" in addition */
82
- export { constants } from 'node:fs'
82
+ /* Export constants from "node:fs" */
83
+ export const fsConstants = constants
package/src/utils/walk.ts CHANGED
@@ -1,7 +1,8 @@
1
+ import { Dir } from 'node:fs'
1
2
  import { basename, join } from 'node:path'
2
3
  import { $p, log } from '../log.js'
3
4
  import { AbsolutePath, resolveAbsolutePath } from '../paths.js'
4
- import { readdir, stat } from './asyncfs.js'
5
+ import { opendir, stat } from './asyncfs.js'
5
6
  import { match, MatchOptions } from './match.js'
6
7
 
7
8
  /** Specific options for walking a directory */
@@ -101,14 +102,18 @@ async function* walker(args: WalkerArguments): AsyncGenerator<string, void, void
101
102
  const dir = resolveAbsolutePath(directory, relative)
102
103
  if (! onDirectory(dir)) return
103
104
  log.trace('Reading directory', $p(dir))
104
- const dirents = await readdir(dir, { withFileTypes: true }).catch((error) => {
105
+
106
+ let dirents: Dir
107
+ try {
108
+ dirents = await opendir(dir)
109
+ } catch (error: any) {
105
110
  if (error.code !== 'ENOENT') throw error
106
111
  log.warn('Directory', $p(dir), 'not found')
107
- return []
108
- })
112
+ return
113
+ }
109
114
 
110
115
  /* For each entry we determine the full path */
111
- for (const dirent of dirents) {
116
+ for await (const dirent of dirents) {
112
117
  const path = join(relative, dirent.name)
113
118
 
114
119
  /* If the entry is a file and matches, yield it */
package/types/files.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import { inspect } from 'node:util';
4
1
  import { AbsolutePath } from './paths.js';
5
2
  /** The {@link FilesBuilder} interface defines a builder for {@link Files}. */
6
3
  export interface FilesBuilder {
@@ -22,7 +19,7 @@ export interface FilesBuilder {
22
19
  /** Merge orther {@link Files} instance to the {@link Files} being built */
23
20
  merge(...files: Files[]): this;
24
21
  /** Write a file and add it to the {@link Files} instance being built */
25
- write(file: string, content: string | Buffer): Promise<AbsolutePath>;
22
+ write(file: string, content: string | Uint8Array): Promise<AbsolutePath>;
26
23
  /** Build and return a {@link Files} instance */
27
24
  build(): Files;
28
25
  }
@@ -48,7 +45,6 @@ export declare class Files {
48
45
  absolutePaths(): Generator<AbsolutePath>;
49
46
  /** Return an iterator over all _relative_ to _absolute_ mappings */
50
47
  pathMappings(): Generator<[relative: string, absolute: AbsolutePath]>;
51
- [inspect.custom](): any;
52
48
  /** Create a new {@link FilesBuilder} creating {@link Files} instances. */
53
49
  static builder(files: Files): FilesBuilder;
54
50
  static builder(directory: AbsolutePath): FilesBuilder;
@@ -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';
@@ -20,5 +20,4 @@ declare module '../pipe.js' {
20
20
  }
21
21
  }
22
22
  export * from './esbuild/bundle-locals.js';
23
- export * from './esbuild/check-dependencies.js';
24
23
  export * from './esbuild/fix-extensions.js';
@@ -1,10 +1,7 @@
1
- /// <reference types="node" resolution-mode="require"/>
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { constants } from 'node:fs';
3
4
  import fsp from 'node:fs/promises';
4
- declare const fs: typeof fsp & {
5
- constants: typeof constants;
6
- };
7
- export default fs;
8
5
  export declare const access: typeof fsp.access;
9
6
  export declare const copyFile: typeof fsp.copyFile;
10
7
  export declare const cp: typeof fsp.cp;
@@ -34,4 +31,4 @@ export declare const writeFile: typeof fsp.writeFile;
34
31
  export declare const appendFile: typeof fsp.appendFile;
35
32
  export declare const readFile: typeof fsp.readFile;
36
33
  export declare const watch: typeof fsp.watch;
37
- export { constants } from 'node:fs';
34
+ export declare const fsConstants: typeof constants;
@@ -1,140 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // plugs/esbuild/check-dependencies.ts
21
- var check_dependencies_exports = {};
22
- __export(check_dependencies_exports, {
23
- checkDependencies: () => checkDependencies
24
- });
25
- module.exports = __toCommonJS(check_dependencies_exports);
26
- var import_async = require("../../async.cjs");
27
- var import_log = require("../../log.cjs");
28
- var import_asyncfs = require("../../utils/asyncfs.cjs");
29
- var import_options = require("../../utils/options.cjs");
30
- function checkDependencies(...args) {
31
- const run = (0, import_async.currentRun)();
32
- const { params, options } = (0, import_options.parseOptions)(args, {
33
- ignored: [],
34
- allowDev: false,
35
- allowPeer: true,
36
- allowOptional: true,
37
- allowUnused: false
38
- });
39
- const allowDev = convertOption(options.allowDev);
40
- const allowPeer = convertOption(options.allowPeer);
41
- const allowOptional = convertOption(options.allowOptional);
42
- const allowUnused = convertOption(options.allowUnused);
43
- const dependencies = [];
44
- const devDependencies = [];
45
- const peerDependencies = [];
46
- const optionalDependencies = [];
47
- const ignored = new Set(options.ignored);
48
- const used = /* @__PURE__ */ new Set();
49
- return {
50
- name: "check-dependencies",
51
- setup(build) {
52
- build.initialOptions.bundle = true;
53
- let packageJson;
54
- build.onStart(async () => {
55
- if (!run)
56
- return { errors: [{ text: "Unable to find current Run" }] };
57
- const resolved = run.resolve(params[0] || "@package.json");
58
- packageJson = resolved;
59
- try {
60
- const data = await (0, import_asyncfs.readFile)(resolved, "utf-8");
61
- const json = JSON.parse(data);
62
- dependencies.push(...dependencyKeys(json.dependencies));
63
- devDependencies.push(...dependencyKeys(json.devDependencies));
64
- peerDependencies.push(...dependencyKeys(json.peerDependencies));
65
- optionalDependencies.push(...dependencyKeys(json.optionalDependencies));
66
- } catch (error) {
67
- return { errors: [{ text: `Unable to parse ${(0, import_log.$p)(resolved)}` }] };
68
- }
69
- });
70
- build.onResolve({ filter: /.*/ }, (args2) => {
71
- if (args2.importer.match(/\/node_modules\//))
72
- return;
73
- if (args2.path.startsWith("node:"))
74
- return;
75
- if (args2.path.startsWith("."))
76
- return;
77
- if (dependencies.includes(args2.path)) {
78
- used.add(args2.path);
79
- return { external: true };
80
- }
81
- const [result, label] = optionalDependencies.includes(args2.path) ? [allowOptional, "an optional"] : peerDependencies.includes(args2.path) ? [allowPeer, "a peer"] : devDependencies.includes(args2.path) ? [allowDev, "a dev"] : ["error", void 0];
82
- if (ignored.has(args2.path))
83
- return { external: true };
84
- if (result === "ignore")
85
- return { external: true };
86
- const text = label ? `Dependency "${args2.path}" is ${label} dependency` : `Dependency "${args2.path}" not specified in "package.json"`;
87
- return result === "warn" ? { external: true, warnings: [{ text }] } : { external: true, errors: [{ text }] };
88
- });
89
- build.onEnd((result) => {
90
- if (allowUnused === "ignore")
91
- return;
92
- const unused = new Set(dependencies);
93
- ignored.forEach((dep) => unused.delete(dep));
94
- used.forEach((dep) => unused.delete(dep));
95
- const messages = [...unused].map((dep) => `Unused dependency "${dep}"`).map((text) => ({
96
- id: "",
97
- pluginName: "check-dependencies",
98
- location: {
99
- file: packageJson,
100
- namespace: "file",
101
- line: 0,
102
- column: 0,
103
- length: 0,
104
- lineText: "",
105
- suggestion: ""
106
- },
107
- text,
108
- notes: [],
109
- detail: void 0
110
- }));
111
- if (allowUnused === "warn") {
112
- result.warnings.push(...messages);
113
- } else {
114
- result.errors.push(...messages);
115
- }
116
- });
117
- }
118
- };
119
- }
120
- function convertOption(option) {
121
- if (option === "warn")
122
- return "warn";
123
- if (option === "error")
124
- return "error";
125
- if (option)
126
- return "ignore";
127
- return "error";
128
- }
129
- function dependencyKeys(dependencies) {
130
- if (!dependencies)
131
- return [];
132
- if (typeof dependencies !== "object")
133
- return [];
134
- return Object.keys(dependencies).filter((key) => typeof key === "string");
135
- }
136
- // Annotate the CommonJS export names for ESM import in node:
137
- 0 && (module.exports = {
138
- checkDependencies
139
- });
140
- //# sourceMappingURL=check-dependencies.cjs.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/plugs/esbuild/check-dependencies.ts"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA2B;AAC3B,iBAAmB;AAEnB,qBAAyB;AACzB,qBAA2C;AAepC,SAAS,qBAAqB,MAAsD;AACzF,QAAM,UAAM,yBAAW;AAEvB,QAAM,EAAE,QAAQ,QAAQ,QAAI,6BAAa,MAAM;AAAA,IAC7C,SAAS,CAAC;AAAA,IACV,UAAU;AAAA,IACV,WAAW;AAAA,IACX,eAAe;AAAA,IACf,aAAa;AAAA,EACf,CAAC;AAED,QAAM,WAAW,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AAE;AAGN,YAAI,gBAAgB,QAAQ;AAC1B,iBAAO,SAAS,KAAK,GAAG,QAAQ;AAAA,QAClC,OAAO;AACL,iBAAO,OAAO,KAAK,GAAG,QAAQ;AAAA,QAChC;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,cAAc,QAAkE;AACvF,MAAI,WAAW;AAAQ,WAAO;AAC9B,MAAI,WAAW;AAAS,WAAO;AAC/B,MAAI;AAAQ,WAAO;AACnB,SAAO;AACT;AAGA,SAAS,eAAe,cAA6B;AACnD,MAAI,CAAE;AAAc,WAAO,CAAC;AAC5B,MAAI,OAAO,iBAAiB;AAAU,WAAO,CAAC;AAC9C,SAAO,OAAO,KAAK,YAAY,EAAE,OAAO,CAAC,QAAQ,OAAO,QAAQ,QAAQ;AAC1E;",
5
- "names": ["args"]
6
- }
@@ -1,115 +0,0 @@
1
- // plugs/esbuild/check-dependencies.ts
2
- import { currentRun } from "../../async.mjs";
3
- import { $p } from "../../log.mjs";
4
- import { readFile } from "../../utils/asyncfs.mjs";
5
- import { parseOptions } from "../../utils/options.mjs";
6
- function checkDependencies(...args) {
7
- const run = currentRun();
8
- const { params, options } = parseOptions(args, {
9
- ignored: [],
10
- allowDev: false,
11
- allowPeer: true,
12
- allowOptional: true,
13
- allowUnused: false
14
- });
15
- const allowDev = convertOption(options.allowDev);
16
- const allowPeer = convertOption(options.allowPeer);
17
- const allowOptional = convertOption(options.allowOptional);
18
- const allowUnused = convertOption(options.allowUnused);
19
- const dependencies = [];
20
- const devDependencies = [];
21
- const peerDependencies = [];
22
- const optionalDependencies = [];
23
- const ignored = new Set(options.ignored);
24
- const used = /* @__PURE__ */ new Set();
25
- return {
26
- name: "check-dependencies",
27
- setup(build) {
28
- build.initialOptions.bundle = true;
29
- let packageJson;
30
- build.onStart(async () => {
31
- if (!run)
32
- return { errors: [{ text: "Unable to find current Run" }] };
33
- const resolved = run.resolve(params[0] || "@package.json");
34
- packageJson = resolved;
35
- try {
36
- const data = await readFile(resolved, "utf-8");
37
- const json = JSON.parse(data);
38
- dependencies.push(...dependencyKeys(json.dependencies));
39
- devDependencies.push(...dependencyKeys(json.devDependencies));
40
- peerDependencies.push(...dependencyKeys(json.peerDependencies));
41
- optionalDependencies.push(...dependencyKeys(json.optionalDependencies));
42
- } catch (error) {
43
- return { errors: [{ text: `Unable to parse ${$p(resolved)}` }] };
44
- }
45
- });
46
- build.onResolve({ filter: /.*/ }, (args2) => {
47
- if (args2.importer.match(/\/node_modules\//))
48
- return;
49
- if (args2.path.startsWith("node:"))
50
- return;
51
- if (args2.path.startsWith("."))
52
- return;
53
- if (dependencies.includes(args2.path)) {
54
- used.add(args2.path);
55
- return { external: true };
56
- }
57
- const [result, label] = optionalDependencies.includes(args2.path) ? [allowOptional, "an optional"] : peerDependencies.includes(args2.path) ? [allowPeer, "a peer"] : devDependencies.includes(args2.path) ? [allowDev, "a dev"] : ["error", void 0];
58
- if (ignored.has(args2.path))
59
- return { external: true };
60
- if (result === "ignore")
61
- return { external: true };
62
- const text = label ? `Dependency "${args2.path}" is ${label} dependency` : `Dependency "${args2.path}" not specified in "package.json"`;
63
- return result === "warn" ? { external: true, warnings: [{ text }] } : { external: true, errors: [{ text }] };
64
- });
65
- build.onEnd((result) => {
66
- if (allowUnused === "ignore")
67
- return;
68
- const unused = new Set(dependencies);
69
- ignored.forEach((dep) => unused.delete(dep));
70
- used.forEach((dep) => unused.delete(dep));
71
- const messages = [...unused].map((dep) => `Unused dependency "${dep}"`).map((text) => ({
72
- id: "",
73
- pluginName: "check-dependencies",
74
- location: {
75
- file: packageJson,
76
- namespace: "file",
77
- line: 0,
78
- column: 0,
79
- length: 0,
80
- lineText: "",
81
- suggestion: ""
82
- },
83
- text,
84
- notes: [],
85
- detail: void 0
86
- }));
87
- if (allowUnused === "warn") {
88
- result.warnings.push(...messages);
89
- } else {
90
- result.errors.push(...messages);
91
- }
92
- });
93
- }
94
- };
95
- }
96
- function convertOption(option) {
97
- if (option === "warn")
98
- return "warn";
99
- if (option === "error")
100
- return "error";
101
- if (option)
102
- return "ignore";
103
- return "error";
104
- }
105
- function dependencyKeys(dependencies) {
106
- if (!dependencies)
107
- return [];
108
- if (typeof dependencies !== "object")
109
- return [];
110
- return Object.keys(dependencies).filter((key) => typeof key === "string");
111
- }
112
- export {
113
- checkDependencies
114
- };
115
- //# sourceMappingURL=check-dependencies.mjs.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/plugs/esbuild/check-dependencies.ts"],
4
- "mappings": ";AACA,SAAS,kBAAkB;AAC3B,SAAS,UAAU;AAEnB,SAAS,gBAAgB;AACzB,SAAuB,oBAAoB;AAepC,SAAS,qBAAqB,MAAsD;AACzF,QAAM,MAAM,WAAW;AAEvB,QAAM,EAAE,QAAQ,QAAQ,IAAI,aAAa,MAAM;AAAA,IAC7C,SAAS,CAAC;AAAA,IACV,UAAU;AAAA,IACV,WAAW;AAAA,IACX,eAAe;AAAA,IACf,aAAa;AAAA,EACf,CAAC;AAED,QAAM,WAAW,cAAc,QAAQ,QAAQ;AAC/C,QAAM,YAAY,cAAc,QAAQ,SAAS;AACjD,QAAM,gBAAgB,cAAc,QAAQ,aAAa;AACzD,QAAM,cAAc,cAAc,QAAQ,WAAW;AAErD,QAAM,eAAyB,CAAC;AAChC,QAAM,kBAA4B,CAAC;AACnC,QAAM,mBAA6B,CAAC;AACpC,QAAM,uBAAiC,CAAC;AACxC,QAAM,UAAU,IAAI,IAAI,QAAQ,OAAO;AACvC,QAAM,OAAO,oBAAI,IAAY;AAE7B,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,OAAa;AAEjB,YAAM,eAAe,SAAS;AAE9B,UAAI;AAEJ,YAAM,QAAQ,YAA2C;AACvD,YAAI,CAAE;AAAK,iBAAO,EAAE,QAAQ,CAAE,EAAE,MAAM,6BAA6B,CAAE,EAAE;AAEvE,cAAM,WAAW,IAAI,QAAQ,OAAO,MAAM,eAAe;AACzD,sBAAc;AA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