@plugjs/plug 0.0.5 → 0.0.8

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 (61) 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.cjs +0 -1
  18. package/dist/plugs/esbuild.cjs.map +1 -1
  19. package/dist/plugs/esbuild.mjs +0 -1
  20. package/dist/plugs/esbuild.mjs.map +1 -1
  21. package/dist/plugs/tsc/options.cjs +1 -2
  22. package/dist/plugs/tsc/options.cjs.map +1 -1
  23. package/dist/plugs/tsc/options.mjs +1 -2
  24. package/dist/plugs/tsc/options.mjs.map +1 -1
  25. package/dist/plugs/tsc/runner.cjs +31 -17
  26. package/dist/plugs/tsc/runner.cjs.map +1 -1
  27. package/dist/plugs/tsc/runner.mjs +32 -18
  28. package/dist/plugs/tsc/runner.mjs.map +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 +4 -8
  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/walk.cjs +7 -4
  38. package/dist/utils/walk.cjs.map +1 -1
  39. package/dist/utils/walk.mjs +8 -5
  40. package/dist/utils/walk.mjs.map +1 -1
  41. package/package.json +4 -4
  42. package/src/files.ts +9 -12
  43. package/src/log/report.ts +22 -11
  44. package/src/paths.ts +2 -2
  45. package/src/plugs/copy.ts +6 -7
  46. package/src/plugs/esbuild.ts +0 -1
  47. package/src/plugs/tsc/options.ts +3 -3
  48. package/src/plugs/tsc/runner.ts +52 -28
  49. package/src/run.ts +4 -3
  50. package/src/utils/asyncfs.ts +9 -8
  51. package/src/utils/walk.ts +10 -5
  52. package/types/files.d.ts +1 -5
  53. package/types/plugs/esbuild.d.ts +0 -1
  54. package/types/plugs/tsc/options.d.ts +1 -1
  55. package/types/utils/asyncfs.d.ts +2 -5
  56. package/dist/plugs/esbuild/check-dependencies.cjs +0 -140
  57. package/dist/plugs/esbuild/check-dependencies.cjs.map +0 -6
  58. package/dist/plugs/esbuild/check-dependencies.mjs +0 -115
  59. package/dist/plugs/esbuild/check-dependencies.mjs.map +0 -6
  60. package/src/plugs/esbuild/check-dependencies.ts +0 -158
  61. package/types/plugs/esbuild/check-dependencies.d.ts +0 -12
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
  /* ========================================================================== *
@@ -72,12 +72,13 @@ export async function getCompilerOptions(
72
72
  file: AbsolutePath | undefined,
73
73
  overrides: ts.CompilerOptions,
74
74
  overridesFile: AbsolutePath,
75
+ overridesBasePath: AbsolutePath,
75
76
  ): Promise<CompilerOptionsAndDiagnostics>
76
77
 
77
78
  /** Load compiler options from a JSON file, and merge in the overrides */
78
79
  export async function getCompilerOptions(
79
80
  file?: AbsolutePath,
80
- ...override: [ ts.CompilerOptions, AbsolutePath ] | []
81
+ ...override: [ ts.CompilerOptions, AbsolutePath, AbsolutePath ] | []
81
82
  ): Promise<CompilerOptionsAndDiagnostics> {
82
83
  let result: CompilerOptionsAndDiagnostics = { options: ts.getDefaultCompilerOptions(), errors: [] }
83
84
 
@@ -86,8 +87,7 @@ export async function getCompilerOptions(
86
87
 
87
88
  // If we have overrides, merge them
88
89
  if (override.length) {
89
- const [ overrides, overridesFile ] = override
90
- const overridesDir = getAbsoluteParent(overridesFile)
90
+ const [ overrides, overridesFile, overridesDir ] = override
91
91
  const options = ts.convertCompilerOptionsFromJson(overrides, overridesDir, overridesFile)
92
92
  result = mergeResults(result, options)
93
93
  }
@@ -3,7 +3,7 @@ import ts from 'typescript' // TypeScript does NOT support ESM modules
3
3
  import { failure } from '../../assert.js'
4
4
  import { Files } from '../../files.js'
5
5
  import { $p, log } from '../../log.js'
6
- import { getCurrentWorkingDirectory, isFile } from '../../paths.js'
6
+ import { AbsolutePath, isFile } from '../../paths.js'
7
7
  import { Plug } from '../../pipe.js'
8
8
  import { Run } from '../../run.js'
9
9
  import { parseOptions, ParseOptions } from '../../utils/options.js'
@@ -31,47 +31,71 @@ export default class Tsc implements Plug<Files> {
31
31
  }
32
32
 
33
33
  async pipe(files: Files, run: Run): Promise<Files> {
34
- const tsconfig = this._tsconfig ?
35
- run.resolve(this._tsconfig) :
36
- isFile(files.directory, 'tsconfig.json')
34
+ const baseDir = run.resolve('.') // "this" directory, base of all relative paths
35
+ const report = run.report('TypeScript Report') // report used throughout
36
+ const overrides = { ...this._options } // clone our options
37
+
38
+ /*
39
+ * The "tsconfig" file is either specified, or (if existing) first checked
40
+ * alongside the sources, otherwise checked in the current directory.
41
+ */
42
+ const sourcesConfig = isFile(files.directory, 'tsconfig.json')
43
+ const tsconfig = this._tsconfig ? run.resolve(this._tsconfig) :
44
+ sourcesConfig || isFile(run.resolve('tsconfig.json'))
45
+
46
+ /* Root directory must always exist */
47
+ let rootDir: AbsolutePath
48
+ if (overrides.rootDir) {
49
+ rootDir = overrides.rootDir = run.resolve(overrides.rootDir)
50
+ } else {
51
+ rootDir = overrides.rootDir = files.directory
52
+ }
53
+
54
+ /* Output directory _also_ must always exist */
55
+ let outDir: AbsolutePath
56
+ if (overrides.outDir) {
57
+ outDir = overrides.outDir = run.resolve(overrides.outDir)
58
+ } else {
59
+ outDir = overrides.outDir = rootDir // default to the root directory
60
+ }
37
61
 
38
- const overrides: ts.CompilerOptions = {
39
- rootDir: files.directory, // by default, our "files" directory
40
- ...this._options, // any other options specified in the constructor
62
+ /* All other root paths */
63
+ if (overrides.rootDirs) {
64
+ overrides.rootDirs = overrides.rootDirs.map((dir) => run.resolve(dir))
41
65
  }
42
66
 
67
+ /* The baseURL is resolved, as well */
68
+ if (overrides.baseUrl) overrides.baseUrl = run.resolve(overrides.baseUrl)
69
+
70
+ /* We can now get our compiler options, and check any and all overrides */
43
71
  const { errors, options } = await getCompilerOptions(
44
72
  tsconfig, // resolved tsconfig.json from constructor, might be undefined
45
73
  overrides, // overrides from constructor, might be an empty object
46
- run.buildFile) // overrides are defined in the build file, sooo.....
47
-
48
- const report = run.report('TypeScript Report')
74
+ run.buildFile, // the build file where the overrides were specified,
75
+ baseDir) // base dir where to resolve overrides
49
76
 
50
- // Update report and fail on errors
51
- updateReport(report, errors, getCurrentWorkingDirectory())
77
+ /* Update report and fail on errors */
78
+ updateReport(report, errors, baseDir)
52
79
  if (report.errors) report.done(true)
53
80
 
54
- const { rootDir, outDir } = options
55
- const root = rootDir ? run.resolve(rootDir) : files.directory
56
- const out = outDir ? run.resolve(outDir) : root
57
-
58
- const host = new TypeScriptHost(root)
59
-
81
+ /* Prep for compilation */
60
82
  const paths = [ ...files.absolutePaths() ]
61
83
  for (const path of paths) log.trace(`Compiling "${$p(path)}"`)
62
84
 
63
- // Get our build file and create the master program
64
85
  log.info('Compiling', paths.length, 'files')
65
86
  log.debug('Compliation options', options)
66
87
 
88
+ /* Typescript host, create program and compile */
89
+ const host = new TypeScriptHost(rootDir)
67
90
  const program = ts.createProgram(paths, options, host, undefined, errors)
68
91
  const diagnostics = ts.getPreEmitDiagnostics(program)
69
92
 
70
- // Update report and fail on errors
71
- updateReport(report, diagnostics, root)
93
+ /* Update report and fail on errors */
94
+ updateReport(report, diagnostics, rootDir)
72
95
  if (report.errors) report.done(true)
73
96
 
74
- const builder = run.files(out)
97
+ /* Write out all files asynchronously */
98
+ const builder = run.files(outDir)
75
99
  const promises: Promise<void>[] = []
76
100
  const result = program.emit(undefined, (fileName, code) => {
77
101
  promises.push(builder.write(fileName, code).then((file) => {
@@ -82,17 +106,17 @@ export default class Tsc implements Plug<Files> {
82
106
  }))
83
107
  })
84
108
 
85
- // Update report and fail on errors
86
- updateReport(report, result.diagnostics, root)
87
- if (report.errors) report.done(true)
88
-
89
- // Await for all files to be written and check
109
+ /* Await for all files to be written and check */
90
110
  const settlements = await Promise.allSettled(promises)
91
111
  const failures = settlements
92
112
  .reduce((failures, s) => failures + s.status === 'rejected' ? 1 : 0, 0)
93
113
  if (failures) throw failure() // already logged above
94
114
 
95
- // All done, build our files and return it
115
+ /* Update report and fail on errors */
116
+ updateReport(report, result.diagnostics, rootDir)
117
+ if (report.errors) report.done(true)
118
+
119
+ /* All done, build our files and return it */
96
120
  const outputs = builder.build()
97
121
  log.info('TSC produced', outputs.length, 'files into', $p(outputs.directory))
98
122
  return outputs
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" />
2
- /// <reference types="node" />
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;
@@ -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';
@@ -5,4 +5,4 @@ export declare type CompilerOptionsAndDiagnostics = {
5
5
  errors: readonly ts.Diagnostic[];
6
6
  };
7
7
  export declare function getCompilerOptions(file?: AbsolutePath): Promise<CompilerOptionsAndDiagnostics>;
8
- export declare function getCompilerOptions(file: AbsolutePath | undefined, overrides: ts.CompilerOptions, overridesFile: AbsolutePath): Promise<CompilerOptionsAndDiagnostics>;
8
+ export declare function getCompilerOptions(file: AbsolutePath | undefined, overrides: ts.CompilerOptions, overridesFile: AbsolutePath, overridesBasePath: AbsolutePath): Promise<CompilerOptionsAndDiagnostics>;
@@ -1,10 +1,7 @@
1
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,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,OA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AI;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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