@plugjs/plug 0.0.6 → 0.0.9

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 (59) hide show
  1. package/dist/build.cjs.map +1 -1
  2. package/dist/build.mjs.map +1 -1
  3. package/dist/files.cjs +5 -8
  4. package/dist/files.cjs.map +1 -1
  5. package/dist/files.mjs +5 -8
  6. package/dist/files.mjs.map +1 -1
  7. package/dist/paths.cjs +1 -1
  8. package/dist/paths.cjs.map +1 -1
  9. package/dist/paths.mjs +2 -2
  10. package/dist/paths.mjs.map +1 -1
  11. package/dist/plugs/copy.cjs +6 -12
  12. package/dist/plugs/copy.cjs.map +2 -2
  13. package/dist/plugs/copy.mjs +6 -6
  14. package/dist/plugs/copy.mjs.map +1 -1
  15. package/dist/plugs/esbuild.cjs +0 -1
  16. package/dist/plugs/esbuild.cjs.map +1 -1
  17. package/dist/plugs/esbuild.mjs +0 -1
  18. package/dist/plugs/esbuild.mjs.map +1 -1
  19. package/dist/plugs/tsc/options.cjs +1 -2
  20. package/dist/plugs/tsc/options.cjs.map +1 -1
  21. package/dist/plugs/tsc/options.mjs +1 -2
  22. package/dist/plugs/tsc/options.mjs.map +1 -1
  23. package/dist/plugs/tsc/runner.cjs +31 -17
  24. package/dist/plugs/tsc/runner.cjs.map +1 -1
  25. package/dist/plugs/tsc/runner.mjs +32 -18
  26. package/dist/plugs/tsc/runner.mjs.map +1 -1
  27. package/dist/run.cjs +3 -2
  28. package/dist/run.cjs.map +1 -1
  29. package/dist/run.mjs +4 -3
  30. package/dist/run.mjs.map +1 -1
  31. package/dist/utils/asyncfs.cjs +4 -8
  32. package/dist/utils/asyncfs.cjs.map +2 -2
  33. package/dist/utils/asyncfs.mjs +3 -7
  34. package/dist/utils/asyncfs.mjs.map +2 -2
  35. package/dist/utils/walk.cjs +7 -4
  36. package/dist/utils/walk.cjs.map +1 -1
  37. package/dist/utils/walk.mjs +8 -5
  38. package/dist/utils/walk.mjs.map +1 -1
  39. package/package.json +4 -4
  40. package/src/files.ts +9 -12
  41. package/src/paths.ts +2 -2
  42. package/src/plugs/copy.ts +6 -7
  43. package/src/plugs/esbuild.ts +0 -1
  44. package/src/plugs/tsc/options.ts +3 -3
  45. package/src/plugs/tsc/runner.ts +52 -28
  46. package/src/run.ts +4 -3
  47. package/src/utils/asyncfs.ts +9 -8
  48. package/src/utils/walk.ts +10 -5
  49. package/types/build.d.ts +1 -1
  50. package/types/files.d.ts +1 -5
  51. package/types/plugs/esbuild.d.ts +0 -1
  52. package/types/plugs/tsc/options.d.ts +1 -1
  53. package/types/utils/asyncfs.d.ts +2 -5
  54. package/dist/plugs/esbuild/check-dependencies.cjs +0 -140
  55. package/dist/plugs/esbuild/check-dependencies.cjs.map +0 -6
  56. package/dist/plugs/esbuild/check-dependencies.mjs +0 -115
  57. package/dist/plugs/esbuild/check-dependencies.mjs.map +0 -6
  58. package/src/plugs/esbuild/check-dependencies.ts +0 -158
  59. package/types/plugs/esbuild/check-dependencies.d.ts +0 -12
@@ -1,158 +0,0 @@
1
- import { Message, OnStartResult, Plugin } from 'esbuild'
2
- import { currentRun } from '../../async.js'
3
- import { $p } from '../../log.js'
4
- import { AbsolutePath } from '../../paths.js'
5
- import { readFile } from '../../utils/asyncfs.js'
6
- import { ParseOptions, parseOptions } from '../../utils/options.js'
7
-
8
- export interface CheckDependenciesOptions {
9
- allowDev?: boolean | 'warn' | 'error',
10
- allowPeer?: boolean | 'warn' | 'error',
11
- allowOptional?: boolean | 'warn' | 'error',
12
- allowUnused?: boolean | 'warn' | 'error',
13
- ignored?: string[]
14
- }
15
-
16
- export function checkDependencies(): Plugin
17
- export function checkDependencies(packageJson: string): Plugin
18
- export function checkDependencies(options: CheckDependenciesOptions): Plugin
19
- export function checkDependencies(packageJson: string, options: CheckDependenciesOptions): Plugin
20
-
21
- export function checkDependencies(...args: ParseOptions<CheckDependenciesOptions>): Plugin {
22
- const run = currentRun() // outside of "onStart", goes into esbuild domain
23
-
24
- const { params, options } = parseOptions(args, {
25
- ignored: [] as string[],
26
- allowDev: false,
27
- allowPeer: true,
28
- allowOptional: true,
29
- allowUnused: false,
30
- })
31
-
32
- const allowDev = convertOption(options.allowDev)
33
- const allowPeer = convertOption(options.allowPeer)
34
- const allowOptional = convertOption(options.allowOptional)
35
- const allowUnused = convertOption(options.allowUnused)
36
-
37
- const dependencies: string[] = []
38
- const devDependencies: string[] = []
39
- const peerDependencies: string[] = []
40
- const optionalDependencies: string[] = []
41
- const ignored = new Set(options.ignored)
42
- const used = new Set<string>()
43
-
44
- return {
45
- name: 'check-dependencies',
46
- setup(build): void {
47
- /* When using this, we fake esbuild's "bundle" functionality */
48
- build.initialOptions.bundle = true
49
-
50
- let packageJson: AbsolutePath
51
-
52
- build.onStart(async (): Promise<OnStartResult | void> => {
53
- if (! run) return { errors: [ { text: 'Unable to find current Run' } ] }
54
-
55
- const resolved = run.resolve(params[0] || '@package.json')
56
- packageJson = resolved
57
-
58
- try {
59
- const data = await readFile(resolved, 'utf-8')
60
- const json = JSON.parse(data)
61
- dependencies.push(...dependencyKeys(json.dependencies))
62
- devDependencies.push(...dependencyKeys(json.devDependencies))
63
- peerDependencies.push(...dependencyKeys(json.peerDependencies))
64
- optionalDependencies.push(...dependencyKeys(json.optionalDependencies))
65
- } catch (error) {
66
- return { errors: [ { text: `Unable to parse ${$p(resolved)}` } ] }
67
- }
68
- })
69
-
70
- /* Intercept resolution */
71
- build.onResolve({ filter: /.*/ }, (args) => {
72
- if (args.importer.match(/\/node_modules\//)) return // only our sources
73
- if (args.path.startsWith('node:')) return // node imports
74
- if (args.path.startsWith('.')) return // local imports
75
-
76
- // Normal dependencies get the green light immediately
77
- if (dependencies.includes(args.path)) {
78
- used.add(args.path)
79
- return { external: true }
80
- }
81
-
82
- // In order, here, we first check "optional" and "peers" (which should)
83
- // also have a corresponding entry in "dev" for things to work, then
84
- // "dev" is definitely checked last
85
- const [ result, label ] =
86
- optionalDependencies.includes(args.path) ? [ allowOptional, 'an optional' ] as const :
87
- peerDependencies.includes(args.path) ? [ allowPeer, 'a peer' ] as const :
88
- devDependencies.includes(args.path) ? [ allowDev, 'a dev' ] as const :
89
- [ 'error', undefined ] as const
90
-
91
- // If we're told to ignore, then... IGNORE!
92
- if (ignored.has(args.path)) return { external: true }
93
- if (result === 'ignore') return { external: true }
94
-
95
- // Prep the message
96
- const text = label ?
97
- `Dependency "${args.path}" is ${label} dependency` :
98
- `Dependency "${args.path}" not specified in "package.json"`
99
-
100
- // Return the proper error or warning
101
- return result === 'warn' ?
102
- { external: true, warnings: [ { text } ] } :
103
- { external: true, errors: [ { text } ] }
104
- })
105
-
106
- /* Check for unused */
107
- build.onEnd((result) => {
108
- if (allowUnused === 'ignore') return
109
-
110
- // Figure out every unused dependency
111
- const unused = new Set(dependencies)
112
- ignored.forEach((dep) => unused.delete(dep))
113
- used.forEach((dep) => unused.delete(dep))
114
-
115
- // Convert the dependency name into a "message"
116
- const messages = [ ...unused ]
117
- .map((dep) => `Unused dependency "${dep}"`)
118
- .map((text): Message => ({
119
- id: '',
120
- pluginName: 'check-dependencies',
121
- location: {
122
- file: packageJson,
123
- namespace: 'file',
124
- line: 0,
125
- column: 0,
126
- length: 0,
127
- lineText: '',
128
- suggestion: '',
129
- },
130
- text,
131
- notes: [],
132
- detail: undefined,
133
- }))
134
-
135
- // Inject our messages either as warnings or errors
136
- if (allowUnused === 'warn') {
137
- result.warnings.push(...messages)
138
- } else {
139
- result.errors.push(...messages)
140
- }
141
- })
142
- },
143
- }
144
- }
145
-
146
- function convertOption(option?: boolean | 'warn' | 'error'): 'ignore' | 'warn' | 'error' {
147
- if (option === 'warn') return 'warn'
148
- if (option === 'error') return 'error'
149
- if (option) return 'ignore'
150
- return 'error'
151
- }
152
-
153
-
154
- function dependencyKeys(dependencies: any): string[] {
155
- if (! dependencies) return []
156
- if (typeof dependencies !== 'object') return []
157
- return Object.keys(dependencies).filter((key) => typeof key === 'string')
158
- }
@@ -1,12 +0,0 @@
1
- import { Plugin } from 'esbuild';
2
- export interface CheckDependenciesOptions {
3
- allowDev?: boolean | 'warn' | 'error';
4
- allowPeer?: boolean | 'warn' | 'error';
5
- allowOptional?: boolean | 'warn' | 'error';
6
- allowUnused?: boolean | 'warn' | 'error';
7
- ignored?: string[];
8
- }
9
- export declare function checkDependencies(): Plugin;
10
- export declare function checkDependencies(packageJson: string): Plugin;
11
- export declare function checkDependencies(options: CheckDependenciesOptions): Plugin;
12
- export declare function checkDependencies(packageJson: string, options: CheckDependenciesOptions): Plugin;