knip 6.32.3 → 6.34.0
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.
- package/dist/DependencyDeputy.d.ts +1 -2
- package/dist/DependencyDeputy.js +1 -2
- package/dist/ProjectPrincipal.d.ts +6 -3
- package/dist/ProjectPrincipal.js +29 -6
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +2 -0
- package/dist/config.js +1 -0
- package/dist/graph/analyze.js +4 -4
- package/dist/graph/build.js +1 -2
- package/dist/graph-explorer/explorer.d.ts +1 -0
- package/dist/graph-explorer/explorer.js +2 -0
- package/dist/graph-explorer/operations/is-enumerated.d.ts +2 -0
- package/dist/graph-explorer/operations/is-enumerated.js +33 -0
- package/dist/manifest/helpers.d.ts +2 -3
- package/dist/manifest/helpers.js +6 -42
- package/dist/manifest/index.d.ts +1 -2
- package/dist/manifest/index.js +2 -2
- package/dist/plugins/dotenv/index.js +1 -8
- package/dist/plugins/eslint/helpers.d.ts +2 -1
- package/dist/plugins/eslint/helpers.js +1 -0
- package/dist/plugins/eslint/resolveFromAST.d.ts +1 -0
- package/dist/plugins/eslint/resolveFromAST.js +5 -2
- package/dist/plugins/eslint/types.d.ts +1 -1
- package/dist/plugins/moonrepo/index.js +3 -3
- package/dist/plugins/node/index.js +5 -0
- package/dist/plugins/node/visitors/fsPromisesGlob.d.ts +2 -0
- package/dist/plugins/node/visitors/fsPromisesGlob.js +89 -0
- package/dist/plugins/nuxt/index.js +38 -13
- package/dist/plugins/nuxt/types.d.ts +5 -1
- package/dist/plugins/oxlint/index.js +6 -2
- package/dist/plugins/oxlint/types.d.ts +2 -0
- package/dist/plugins/typescript/index.js +22 -5
- package/dist/plugins/vitest/index.js +18 -11
- package/dist/plugins/vitest/types.d.ts +1 -1
- package/dist/plugins/vitest/visitors/mock.d.ts +2 -0
- package/dist/plugins/vitest/visitors/mock.js +50 -0
- package/dist/plugins/webpack/index.js +15 -14
- package/dist/run.js +1 -1
- package/dist/types/config.d.ts +2 -0
- package/dist/types/module-graph.d.ts +2 -0
- package/dist/types/tsconfig-json.d.ts +6 -0
- package/dist/typescript/get-imports-and-exports.js +7 -1
- package/dist/typescript/glob-imports.js +8 -3
- package/dist/typescript/visitors/calls.js +2 -2
- package/dist/typescript/visitors/members.js +56 -8
- package/dist/typescript/visitors/walk.d.ts +4 -1
- package/dist/typescript/visitors/walk.js +78 -14
- package/dist/util/cli-arguments.d.ts +1 -0
- package/dist/util/cli-arguments.js +9 -0
- package/dist/util/create-options.d.ts +2 -1
- package/dist/util/create-options.js +3 -1
- package/dist/util/load-config.js +6 -1
- package/dist/util/resolve.d.ts +1 -0
- package/dist/util/resolve.js +11 -0
- package/dist/util/scripts.d.ts +1 -0
- package/dist/util/scripts.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +16 -12
|
@@ -22,9 +22,8 @@ export declare class DependencyDeputy {
|
|
|
22
22
|
installedBinaries: Map<string, InstalledBinaries>;
|
|
23
23
|
hasTypesIncluded: Map<string, Set<string>>;
|
|
24
24
|
constructor({ isProduction, isStrict, isReportDependencies }: MainOptions);
|
|
25
|
-
addWorkspace({ name,
|
|
25
|
+
addWorkspace({ name, dir, manifestPath, manifestStr, manifest, ignoreDependencies: id, ignoreBinaries: ib, ignoreUnresolved: iu, }: {
|
|
26
26
|
name: string;
|
|
27
|
-
cwd: string;
|
|
28
27
|
dir: string;
|
|
29
28
|
manifestPath: string;
|
|
30
29
|
manifestStr: string;
|
package/dist/DependencyDeputy.js
CHANGED
|
@@ -26,7 +26,7 @@ export class DependencyDeputy {
|
|
|
26
26
|
this.installedBinaries = new Map();
|
|
27
27
|
this.hasTypesIncluded = new Map();
|
|
28
28
|
}
|
|
29
|
-
addWorkspace({ name,
|
|
29
|
+
addWorkspace({ name, dir, manifestPath, manifestStr, manifest, ignoreDependencies: id, ignoreBinaries: ib, ignoreUnresolved: iu, }) {
|
|
30
30
|
const dependencies = Object.keys(manifest.dependencies ?? {});
|
|
31
31
|
const peerDependencies = Object.keys(manifest.peerDependencies ?? {});
|
|
32
32
|
const optionalDependencies = Object.keys(manifest.optionalDependencies ?? {});
|
|
@@ -45,7 +45,6 @@ export class DependencyDeputy {
|
|
|
45
45
|
const { hostDependencies, installedBinaries, hasTypesIncluded } = getDependencyMetaData({
|
|
46
46
|
packageNames,
|
|
47
47
|
dir,
|
|
48
|
-
cwd,
|
|
49
48
|
});
|
|
50
49
|
this.setHostDependencies(name, hostDependencies);
|
|
51
50
|
this.installedBinaries.set(name, installedBinaries);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ParseResult } from 'oxc-parser';
|
|
2
2
|
import { CacheConsultant } from './CacheConsultant.ts';
|
|
3
|
-
import type { AsyncCompilers, SyncCompilers } from './compilers/types.ts';
|
|
3
|
+
import type { AsyncCompilers, Compilers, SyncCompilers } from './compilers/types.ts';
|
|
4
4
|
import type { GetImportsAndExportsOptions, IgnoreExportsUsedInFile, PluginVisitorContext, PluginVisitorObject } from './types/config.ts';
|
|
5
5
|
import type { FileNode, ModuleGraph } from './types/module-graph.ts';
|
|
6
6
|
import type { Paths } from './types/project.ts';
|
|
@@ -19,6 +19,8 @@ export declare class ProjectPrincipal {
|
|
|
19
19
|
private _localRefsVisitor;
|
|
20
20
|
syncCompilers: SyncCompilers;
|
|
21
21
|
asyncCompilers: AsyncCompilers;
|
|
22
|
+
private scopedSyncCompilers;
|
|
23
|
+
private scopedAsyncCompilers;
|
|
22
24
|
private paths;
|
|
23
25
|
private rootDirs;
|
|
24
26
|
private tsConfigFile;
|
|
@@ -26,14 +28,15 @@ export declare class ProjectPrincipal {
|
|
|
26
28
|
cache: CacheConsultant<FileNode>;
|
|
27
29
|
toSourceFilePath: ToSourceFilePath;
|
|
28
30
|
private findWorkspacePackageTarget;
|
|
31
|
+
private findWorkspaceNameByFilePath;
|
|
29
32
|
fileManager: SourceFileManager;
|
|
30
33
|
private resolveModule;
|
|
31
34
|
resolveGlobPattern: ResolveGlobPattern;
|
|
32
35
|
resolvedFiles: Set<string>;
|
|
33
36
|
deletedFiles: Set<string>;
|
|
34
37
|
private onPathAdded;
|
|
35
|
-
constructor(options: MainOptions, toSourceFilePath: ToSourceFilePath, findWorkspacePackageTarget
|
|
36
|
-
addCompilers(
|
|
38
|
+
constructor(options: MainOptions, toSourceFilePath: ToSourceFilePath, findWorkspacePackageTarget: WorkspacePackageTargetHandler | undefined, findWorkspaceNameByFilePath: (filePath: string) => string | undefined);
|
|
39
|
+
addCompilers(workspaceName: string, compilers: Compilers): void;
|
|
37
40
|
addPaths(paths: Paths, basePath: string, scope: string): void;
|
|
38
41
|
addRootDirs(rootDirs: string[] | undefined, scope: string): void;
|
|
39
42
|
init(): void;
|
package/dist/ProjectPrincipal.js
CHANGED
|
@@ -21,6 +21,7 @@ export class ProjectPrincipal {
|
|
|
21
21
|
sourceText: '',
|
|
22
22
|
addScript: () => { },
|
|
23
23
|
addImport: () => { },
|
|
24
|
+
markImportExpressionHandled: () => { },
|
|
24
25
|
addImportGlob: () => { },
|
|
25
26
|
markExportRegistered: () => { },
|
|
26
27
|
};
|
|
@@ -29,6 +30,8 @@ export class ProjectPrincipal {
|
|
|
29
30
|
_localRefsVisitor;
|
|
30
31
|
syncCompilers = new Map();
|
|
31
32
|
asyncCompilers = new Map();
|
|
33
|
+
scopedSyncCompilers = new Map();
|
|
34
|
+
scopedAsyncCompilers = new Map();
|
|
32
35
|
paths = new Map();
|
|
33
36
|
rootDirs = new Map();
|
|
34
37
|
tsConfigFile;
|
|
@@ -36,16 +39,18 @@ export class ProjectPrincipal {
|
|
|
36
39
|
cache;
|
|
37
40
|
toSourceFilePath;
|
|
38
41
|
findWorkspacePackageTarget;
|
|
42
|
+
findWorkspaceNameByFilePath;
|
|
39
43
|
fileManager;
|
|
40
44
|
resolveModule = () => undefined;
|
|
41
45
|
resolveGlobPattern = pattern => [pattern];
|
|
42
46
|
resolvedFiles = new Set();
|
|
43
47
|
deletedFiles = new Set();
|
|
44
48
|
onPathAdded;
|
|
45
|
-
constructor(options, toSourceFilePath, findWorkspacePackageTarget) {
|
|
49
|
+
constructor(options, toSourceFilePath, findWorkspacePackageTarget, findWorkspaceNameByFilePath) {
|
|
46
50
|
this.cache = new CacheConsultant('root', options);
|
|
47
51
|
this.toSourceFilePath = toSourceFilePath;
|
|
48
52
|
this.findWorkspacePackageTarget = findWorkspacePackageTarget;
|
|
53
|
+
this.findWorkspaceNameByFilePath = findWorkspaceNameByFilePath;
|
|
49
54
|
this.tsConfigFile = options.tsConfigFile ? toAbsolute(options.tsConfigFile, options.cwd) : undefined;
|
|
50
55
|
this.pluginVisitorObjects.push(createBunShellVisitor(this.pluginCtx));
|
|
51
56
|
this.fileManager = new SourceFileManager({
|
|
@@ -53,16 +58,34 @@ export class ProjectPrincipal {
|
|
|
53
58
|
});
|
|
54
59
|
this.walkAndAnalyze = timerify(this.walkAndAnalyze.bind(this), 'walkAndAnalyze');
|
|
55
60
|
}
|
|
56
|
-
addCompilers(compilers) {
|
|
61
|
+
addCompilers(workspaceName, compilers) {
|
|
57
62
|
for (const [ext, compiler] of compilers[0]) {
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
const workspaceCompilers = this.scopedSyncCompilers.get(ext);
|
|
64
|
+
if (workspaceCompilers) {
|
|
65
|
+
workspaceCompilers.set(workspaceName, compiler);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const workspaceCompilers = new Map([[workspaceName, compiler]]);
|
|
69
|
+
this.scopedSyncCompilers.set(ext, workspaceCompilers);
|
|
70
|
+
this.syncCompilers.set(ext, (source, filePath) => {
|
|
71
|
+
const owner = this.findWorkspaceNameByFilePath(filePath);
|
|
72
|
+
return ((owner ? workspaceCompilers.get(owner) : undefined) ?? compiler)(source, filePath);
|
|
73
|
+
});
|
|
60
74
|
this.extensions.add(ext);
|
|
61
75
|
}
|
|
62
76
|
}
|
|
63
77
|
for (const [ext, compiler] of compilers[1]) {
|
|
64
|
-
|
|
65
|
-
|
|
78
|
+
const workspaceCompilers = this.scopedAsyncCompilers.get(ext);
|
|
79
|
+
if (workspaceCompilers) {
|
|
80
|
+
workspaceCompilers.set(workspaceName, compiler);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const workspaceCompilers = new Map([[workspaceName, compiler]]);
|
|
84
|
+
this.scopedAsyncCompilers.set(ext, workspaceCompilers);
|
|
85
|
+
this.asyncCompilers.set(ext, (source, filePath) => {
|
|
86
|
+
const owner = this.findWorkspaceNameByFilePath(filePath);
|
|
87
|
+
return ((owner ? workspaceCompilers.get(owner) : undefined) ?? compiler)(source, filePath);
|
|
88
|
+
});
|
|
66
89
|
this.extensions.add(ext);
|
|
67
90
|
}
|
|
68
91
|
}
|
package/dist/cli.js
CHANGED
|
@@ -51,7 +51,7 @@ const main = async () => {
|
|
|
51
51
|
isShowProgress: options.isShowProgress,
|
|
52
52
|
isTreatConfigHintsAsErrors: options.isTreatConfigHintsAsErrors,
|
|
53
53
|
isTreatTagHintsAsErrors: options.isTreatTagHintsAsErrors,
|
|
54
|
-
maxShowIssues:
|
|
54
|
+
maxShowIssues: options.maxShowIssues,
|
|
55
55
|
options: args['reporter-options'] ?? '',
|
|
56
56
|
preprocessorOptions: args['preprocessor-options'] ?? '',
|
|
57
57
|
selectedWorkspaces,
|
|
@@ -75,7 +75,7 @@ const main = async () => {
|
|
|
75
75
|
perfObserver.reset();
|
|
76
76
|
}
|
|
77
77
|
if (!args['no-exit-code'] &&
|
|
78
|
-
(totalErrorCount >
|
|
78
|
+
(totalErrorCount > options.maxIssues ||
|
|
79
79
|
(!options.isDisableConfigHints && options.isTreatConfigHintsAsErrors && configurationHints.length > 0) ||
|
|
80
80
|
(!options.isDisableTagHints && options.isTreatTagHintsAsErrors && tagHints.size > 0))) {
|
|
81
81
|
process.exitCode = 1;
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const defineConfig = (config) => config;
|
package/dist/graph/analyze.js
CHANGED
|
@@ -106,7 +106,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
|
|
|
106
106
|
exportedItem.members.length > 0 &&
|
|
107
107
|
exportedItem.type !== 'enum';
|
|
108
108
|
if ((isEnumMembers || isNsMembers) && exportedItem.members.length > 0) {
|
|
109
|
-
if (
|
|
109
|
+
if (explorer.isEnumerated(filePath, identifier))
|
|
110
110
|
continue;
|
|
111
111
|
if (!options.includedIssueTypes.nsTypes && importsForExport.refs.has(identifier))
|
|
112
112
|
continue;
|
|
@@ -191,7 +191,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
if (file.imports
|
|
194
|
+
if (file.imports.external) {
|
|
195
195
|
for (const extImport of file.imports.external) {
|
|
196
196
|
const packageName = getPackageNameFromModuleSpecifier(extImport.specifier);
|
|
197
197
|
const isHandled = packageName &&
|
|
@@ -200,7 +200,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
|
|
|
200
200
|
isTypeOnly: extImport.isTypeOnly,
|
|
201
201
|
isResolved: extImport.filePath !== undefined,
|
|
202
202
|
});
|
|
203
|
-
if (!isHandled)
|
|
203
|
+
if (!isHandled && !(extImport.jsDocTags?.size && shouldIgnoreTags(extImport.jsDocTags)))
|
|
204
204
|
collector.addIssue({
|
|
205
205
|
type: 'unlisted',
|
|
206
206
|
filePath,
|
|
@@ -214,7 +214,7 @@ export const analyze = async ({ analyzedFiles, counselor, chief, collector, depu
|
|
|
214
214
|
});
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
if (file.imports
|
|
217
|
+
if (file.imports.unresolved) {
|
|
218
218
|
for (const unresolvedImport of file.imports.unresolved) {
|
|
219
219
|
const { specifier, pos, line, col } = unresolvedImport;
|
|
220
220
|
collector.addIssue({
|
package/dist/graph/build.js
CHANGED
|
@@ -41,7 +41,6 @@ export async function build({ chief, collector, counselor, deputy, principal, is
|
|
|
41
41
|
continue;
|
|
42
42
|
deputy.addWorkspace({
|
|
43
43
|
name,
|
|
44
|
-
cwd: options.cwd,
|
|
45
44
|
dir,
|
|
46
45
|
manifestPath,
|
|
47
46
|
manifestStr,
|
|
@@ -91,7 +90,7 @@ export async function build({ chief, collector, counselor, deputy, principal, is
|
|
|
91
90
|
compilers[0].set(ext, compiler);
|
|
92
91
|
};
|
|
93
92
|
await worker.registerCompilers(registerCompiler);
|
|
94
|
-
principal.addCompilers(compilers);
|
|
93
|
+
principal.addCompilers(name, compilers);
|
|
95
94
|
const extensions = getCompilerExtensions(compilers);
|
|
96
95
|
const extensionGlobStr = `.{${[...DEFAULT_EXTENSIONS, ...extensions].map(ext => ext.slice(1)).join(',')}}`;
|
|
97
96
|
const config = chief.getConfigForWorkspace(name, extensions);
|
|
@@ -5,6 +5,7 @@ export declare const createGraphExplorer: (graph: ModuleGraph, entryPaths: Set<s
|
|
|
5
5
|
treatStarAtEntryAsReferenced?: boolean;
|
|
6
6
|
}) => readonly [false, string | undefined];
|
|
7
7
|
hasStrictlyNsReferences: (filePath: string, identifier: string) => [boolean, (string | undefined)?];
|
|
8
|
+
isEnumerated: (filePath: string, identifier: string) => boolean;
|
|
8
9
|
buildExportsTree: (options: {
|
|
9
10
|
filePath?: string;
|
|
10
11
|
identifier?: string;
|
|
@@ -6,12 +6,14 @@ import { getContention } from './operations/get-contention.js';
|
|
|
6
6
|
import { getDependencyUsage } from './operations/get-dependency-usage.js';
|
|
7
7
|
import { getUsage } from './operations/get-usage.js';
|
|
8
8
|
import { hasStrictlyNsReferences } from './operations/has-strictly-ns-references.js';
|
|
9
|
+
import { isEnumerated } from './operations/is-enumerated.js';
|
|
9
10
|
import { isReferenced } from './operations/is-referenced.js';
|
|
10
11
|
import { resolveDefinition } from './operations/resolve-definition.js';
|
|
11
12
|
export const createGraphExplorer = (graph, entryPaths) => {
|
|
12
13
|
return {
|
|
13
14
|
isReferenced: (filePath, identifier, options) => isReferenced(graph, entryPaths, filePath, identifier, options),
|
|
14
15
|
hasStrictlyNsReferences: (filePath, identifier) => hasStrictlyNsReferences(graph, filePath, graph.get(filePath)?.importedBy, identifier),
|
|
16
|
+
isEnumerated: (filePath, identifier) => isEnumerated(graph, filePath, graph.get(filePath)?.importedBy, identifier),
|
|
15
17
|
buildExportsTree: (options) => buildExportsTree(graph, entryPaths, options),
|
|
16
18
|
getDependencyUsage: (pattern) => getDependencyUsage(graph, pattern),
|
|
17
19
|
resolveDefinition: (filePath, identifier) => resolveDefinition(graph, filePath, identifier),
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getAliasReExportMap, getPassThroughReExportSources, getStarReExportSources } from '../visitors.js';
|
|
2
|
+
export const isEnumerated = (graph, filePath, importsForExport, identifier) => {
|
|
3
|
+
const seen = new Set();
|
|
4
|
+
const walkDown = (path, importMaps, id) => {
|
|
5
|
+
if (!importMaps || seen.has(path))
|
|
6
|
+
return false;
|
|
7
|
+
seen.add(path);
|
|
8
|
+
if (importMaps.enumerated?.has(id))
|
|
9
|
+
return true;
|
|
10
|
+
const follow = (sources, nextId) => {
|
|
11
|
+
for (const source of sources) {
|
|
12
|
+
if (walkDown(source, graph.get(source)?.importedBy, nextId))
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
};
|
|
17
|
+
const directSources = getPassThroughReExportSources(importMaps, id);
|
|
18
|
+
if (directSources && follow(directSources, id))
|
|
19
|
+
return true;
|
|
20
|
+
const starSources = getStarReExportSources(importMaps);
|
|
21
|
+
if (starSources && follow(starSources, id))
|
|
22
|
+
return true;
|
|
23
|
+
const aliasMap = getAliasReExportMap(importMaps, id);
|
|
24
|
+
if (aliasMap) {
|
|
25
|
+
for (const [alias, sources] of aliasMap) {
|
|
26
|
+
if (follow(sources, alias))
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
32
|
+
return walkDown(filePath, importsForExport, identifier);
|
|
33
|
+
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type { Scripts } from '../types/package-json.ts';
|
|
1
|
+
import type { PackageJson, Scripts } from '../types/package-json.ts';
|
|
2
2
|
type LoadPackageManifestOptions = {
|
|
3
3
|
dir: string;
|
|
4
4
|
packageName: string;
|
|
5
|
-
cwd: string;
|
|
6
5
|
};
|
|
7
|
-
export declare const loadPackageManifest: ({ dir, packageName
|
|
6
|
+
export declare const loadPackageManifest: ({ dir, packageName }: LoadPackageManifestOptions) => PackageJson | undefined;
|
|
8
7
|
export declare const getFilteredScripts: (scripts: Scripts) => Scripts[];
|
|
9
8
|
export {};
|
package/dist/manifest/helpers.js
CHANGED
|
@@ -1,49 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, join } from '../util/path.js';
|
|
1
|
+
import { resolvePackageManifestPath } from '../util/resolve.js';
|
|
3
2
|
import { _require } from '../util/require.js';
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
7
|
-
return
|
|
8
|
-
let current = dirname(startDir);
|
|
9
|
-
let result;
|
|
10
|
-
while (current !== dirname(current)) {
|
|
11
|
-
if (existsSync(join(current, 'pnpm-workspace.yaml'))) {
|
|
12
|
-
result = current;
|
|
13
|
-
break;
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
const pkg = JSON.parse(readFileSync(join(current, 'package.json'), 'utf8'));
|
|
17
|
-
if (pkg.workspaces) {
|
|
18
|
-
result = current;
|
|
19
|
-
break;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
catch { }
|
|
23
|
-
current = dirname(current);
|
|
24
|
-
}
|
|
25
|
-
monorepoRootCache.set(startDir, result);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
export const loadPackageManifest = ({ dir, packageName, cwd }) => {
|
|
3
|
+
export const loadPackageManifest = ({ dir, packageName }) => {
|
|
4
|
+
const manifestPath = resolvePackageManifestPath(packageName, dir);
|
|
5
|
+
if (!manifestPath)
|
|
6
|
+
return;
|
|
29
7
|
try {
|
|
30
|
-
return _require(
|
|
8
|
+
return _require(manifestPath);
|
|
31
9
|
}
|
|
32
10
|
catch { }
|
|
33
|
-
if (dir !== cwd) {
|
|
34
|
-
try {
|
|
35
|
-
return _require(join(cwd, 'node_modules', packageName, 'package.json'));
|
|
36
|
-
}
|
|
37
|
-
catch { }
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const root = findMonorepoRootAbove(cwd);
|
|
41
|
-
if (root) {
|
|
42
|
-
try {
|
|
43
|
-
return _require(join(root, 'node_modules', packageName, 'package.json'));
|
|
44
|
-
}
|
|
45
|
-
catch { }
|
|
46
|
-
}
|
|
47
11
|
};
|
|
48
12
|
export const getFilteredScripts = (scripts) => {
|
|
49
13
|
if (!scripts)
|
package/dist/manifest/index.d.ts
CHANGED
|
@@ -2,9 +2,8 @@ import type { HostDependencies, InstalledBinaries } from '../types/workspace.ts'
|
|
|
2
2
|
type Options = {
|
|
3
3
|
packageNames: string[];
|
|
4
4
|
dir: string;
|
|
5
|
-
cwd: string;
|
|
6
5
|
};
|
|
7
|
-
declare const getMetaDataFromPackageJson: ({
|
|
6
|
+
declare const getMetaDataFromPackageJson: ({ dir, packageNames }: Options) => {
|
|
8
7
|
hostDependencies: HostDependencies;
|
|
9
8
|
installedBinaries: InstalledBinaries;
|
|
10
9
|
hasTypesIncluded: Set<string>;
|
package/dist/manifest/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isDefinitelyTyped } from '../util/modules.js';
|
|
2
2
|
import { timerify } from '../util/Performance.js';
|
|
3
3
|
import { loadPackageManifest } from './helpers.js';
|
|
4
|
-
const getMetaDataFromPackageJson = ({
|
|
4
|
+
const getMetaDataFromPackageJson = ({ dir, packageNames }) => {
|
|
5
5
|
const hostDependencies = new Map();
|
|
6
6
|
const installedBinaries = new Map();
|
|
7
7
|
const hasTypesIncluded = new Set();
|
|
@@ -13,7 +13,7 @@ const getMetaDataFromPackageJson = ({ cwd, dir, packageNames }) => {
|
|
|
13
13
|
installedBinaries.set(key, new Set([value]));
|
|
14
14
|
};
|
|
15
15
|
for (const packageName of packageNames) {
|
|
16
|
-
const manifest = loadPackageManifest({
|
|
16
|
+
const manifest = loadPackageManifest({ dir, packageName });
|
|
17
17
|
if (manifest) {
|
|
18
18
|
const defaultBinaryName = packageName.replace(/^@[^/]+\//, '');
|
|
19
19
|
const binaries = typeof manifest.bin === 'string' ? [defaultBinaryName] : Object.keys(manifest.bin ?? {});
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { argsFrom } from '../../binaries/util.js';
|
|
2
2
|
const title = 'dotenv';
|
|
3
3
|
const args = {
|
|
4
|
-
fromArgs: (parsed, args) =>
|
|
5
|
-
if (parsed._[0])
|
|
6
|
-
return argsFrom(args, parsed._[0]);
|
|
7
|
-
if (!parsed['--'] || parsed['--'].length === 0)
|
|
8
|
-
return [];
|
|
9
|
-
const script = parsed['--'].map(arg => (arg.includes(' ') ? `"${arg}"` : arg)).join(' ');
|
|
10
|
-
return [script];
|
|
11
|
-
},
|
|
4
|
+
fromArgs: (parsed, args) => (parsed._[0] ? argsFrom(args, parsed._[0]) : (parsed['--'] ?? [])),
|
|
12
5
|
};
|
|
13
6
|
const plugin = {
|
|
14
7
|
title,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { PluginOptions } from '../../types/config.ts';
|
|
2
2
|
import { type ConfigInput, type Input } from '../../util/input.ts';
|
|
3
|
-
import type { ESLintConfig, ESLintConfigDeprecated, OverrideConfigDeprecated } from './types.ts';
|
|
3
|
+
import type { ESLintConfig, ESLintConfigDeprecated, OverrideConfigDeprecated, Settings } from './types.ts';
|
|
4
4
|
export declare const isFlatConfig: (fileName: string) => boolean;
|
|
5
5
|
export declare const getInputs: (config: ESLintConfigDeprecated | OverrideConfigDeprecated | ESLintConfig, options: PluginOptions) => (Input | ConfigInput)[];
|
|
6
|
+
export declare const getInputsFromSettings: (settings?: Settings) => Input[];
|
|
6
7
|
export declare const resolveFormatters: (formatters: string | string[]) => Set<Input>;
|
|
@@ -80,6 +80,7 @@ const getDependenciesFromSettings = (settings = {}) => {
|
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
|
+
export const getInputsFromSettings = (settings) => compact(getDependenciesFromSettings(settings)).map(id => toDeferResolve(id, { optional: true }));
|
|
83
84
|
const builtinFormatters = new Set(['html', 'json-with-metadata', 'json', 'stylish']);
|
|
84
85
|
export const resolveFormatters = (formatters) => {
|
|
85
86
|
const inputs = new Set();
|
|
@@ -3,7 +3,7 @@ import { toDeferResolve } from '../../util/input.js';
|
|
|
3
3
|
import { findProperty, getPropertyKey } from '../../typescript/ast-helpers.js';
|
|
4
4
|
import { getStringValue } from '../../typescript/ast-nodes.js';
|
|
5
5
|
import { isInternal } from '../../util/path.js';
|
|
6
|
-
export const
|
|
6
|
+
export const getInputsFromSettingsAST = (program) => {
|
|
7
7
|
const inputs = [];
|
|
8
8
|
const addResolver = (key, resolver) => {
|
|
9
9
|
if (!resolver || resolver === 'node' || isInternal(resolver))
|
|
@@ -35,6 +35,9 @@ export const getInputsFromFlatConfigAST = (program) => {
|
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
37
|
visitor.visit(program);
|
|
38
|
-
inputs.push(toDeferResolve('eslint-import-resolver-typescript', { optional: true }));
|
|
39
38
|
return inputs;
|
|
40
39
|
};
|
|
40
|
+
export const getInputsFromFlatConfigAST = (program) => [
|
|
41
|
+
...getInputsFromSettingsAST(program),
|
|
42
|
+
toDeferResolve('eslint-import-resolver-typescript', { optional: true }),
|
|
43
|
+
];
|
|
@@ -6,7 +6,7 @@ type ParserOptions = {
|
|
|
6
6
|
presets: string[];
|
|
7
7
|
};
|
|
8
8
|
};
|
|
9
|
-
type Settings = Record<string, Record<string, unknown> | string>;
|
|
9
|
+
export type Settings = Record<string, Record<string, unknown> | string>;
|
|
10
10
|
type Rules = Record<string, string | number>;
|
|
11
11
|
type BaseConfig = {
|
|
12
12
|
extends?: string | string[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { hasDependency } from '../../util/plugin.js';
|
|
2
|
+
import { toShellCommand } from '../../util/scripts.js';
|
|
2
3
|
const title = 'moonrepo';
|
|
3
4
|
const enablers = ['@moonrepo/cli'];
|
|
4
5
|
const isEnabled = ({ dependencies }) => hasDependency(dependencies, enablers);
|
|
@@ -6,12 +7,11 @@ const isRootOnly = true;
|
|
|
6
7
|
const config = ['moon.yml', '.moon/tasks.yml', '.moon/tasks/*.yml'];
|
|
7
8
|
const resolveConfig = async (config, options) => {
|
|
8
9
|
const tasks = config.tasks ? Object.values(config.tasks) : [];
|
|
10
|
+
const expand = (value) => value.replace('$workspaceRoot', options.rootCwd).replace('$projectRoot', options.cwd);
|
|
9
11
|
const inputs = tasks
|
|
10
12
|
.map(task => task.command)
|
|
11
13
|
.filter(command => command)
|
|
12
|
-
.map(command => (Array.isArray(command) ? command.
|
|
13
|
-
.map(command => command.replace('$workspaceRoot', options.rootCwd))
|
|
14
|
-
.map(command => command.replace('$projectRoot', options.cwd))
|
|
14
|
+
.map(command => (Array.isArray(command) ? toShellCommand(command.map(expand)) : expand(command)))
|
|
15
15
|
.flatMap(command => options.getInputsFromScripts(command));
|
|
16
16
|
return [...inputs];
|
|
17
17
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { toEntry, toProductionEntry } from '../../util/input.js';
|
|
2
2
|
import { getScriptCommands } from '../../util/scripts.js';
|
|
3
|
+
import { createFsPromisesGlobVisitor } from './visitors/fsPromisesGlob.js';
|
|
3
4
|
const title = 'Node.js';
|
|
4
5
|
const isEnabled = () => true;
|
|
5
6
|
const patterns = [
|
|
@@ -21,6 +22,9 @@ const hasNodeTest = (scripts) => {
|
|
|
21
22
|
return result;
|
|
22
23
|
};
|
|
23
24
|
const entry = ['server.js'];
|
|
25
|
+
const registerVisitors = ({ ctx, registerVisitor }) => {
|
|
26
|
+
registerVisitor(createFsPromisesGlobVisitor(ctx));
|
|
27
|
+
};
|
|
24
28
|
const resolve = options => {
|
|
25
29
|
const entries = entry.map(id => toProductionEntry(id));
|
|
26
30
|
if (hasNodeTest(options.manifest.scripts) || hasNodeTest(options.rootManifest?.scripts)) {
|
|
@@ -53,5 +57,6 @@ const plugin = {
|
|
|
53
57
|
entry,
|
|
54
58
|
resolve,
|
|
55
59
|
args,
|
|
60
|
+
registerVisitors,
|
|
56
61
|
};
|
|
57
62
|
export default plugin;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { findProperty, getPropertyKey } from '../../../typescript/ast-helpers.js';
|
|
2
|
+
import { getStringValue, isStringLiteral } from '../../../typescript/ast-nodes.js';
|
|
3
|
+
const FS_PROMISES = new Set(['node:fs/promises', 'fs/promises']);
|
|
4
|
+
export function createFsPromisesGlobVisitor(ctx) {
|
|
5
|
+
const globNames = new Set();
|
|
6
|
+
const namespaceNames = new Set();
|
|
7
|
+
return {
|
|
8
|
+
Program() {
|
|
9
|
+
globNames.clear();
|
|
10
|
+
namespaceNames.clear();
|
|
11
|
+
},
|
|
12
|
+
ImportDeclaration(node) {
|
|
13
|
+
if (!FS_PROMISES.has(node.source.value))
|
|
14
|
+
return;
|
|
15
|
+
for (const specifier of node.specifiers ?? []) {
|
|
16
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
17
|
+
namespaceNames.add(specifier.local.name);
|
|
18
|
+
}
|
|
19
|
+
else if (specifier.type === 'ImportSpecifier' &&
|
|
20
|
+
specifier.imported.type === 'Identifier' &&
|
|
21
|
+
specifier.imported.name === 'glob') {
|
|
22
|
+
globNames.add(specifier.local.name);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
VariableDeclarator(node) {
|
|
27
|
+
if (node.init?.type !== 'CallExpression' ||
|
|
28
|
+
node.init.callee.type !== 'Identifier' ||
|
|
29
|
+
node.init.callee.name !== 'require' ||
|
|
30
|
+
!isStringLiteral(node.init.arguments[0]) ||
|
|
31
|
+
!FS_PROMISES.has(getStringValue(node.init.arguments[0])))
|
|
32
|
+
return;
|
|
33
|
+
if (node.id.type === 'Identifier') {
|
|
34
|
+
namespaceNames.add(node.id.name);
|
|
35
|
+
}
|
|
36
|
+
else if (node.id.type === 'ObjectPattern') {
|
|
37
|
+
for (const property of node.id.properties) {
|
|
38
|
+
if (property.type === 'Property' &&
|
|
39
|
+
getPropertyKey(property) === 'glob' &&
|
|
40
|
+
property.value.type === 'Identifier') {
|
|
41
|
+
globNames.add(property.value.name);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
CallExpression(node) {
|
|
47
|
+
let isGlobCall = node.callee.type === 'Identifier' && globNames.has(node.callee.name);
|
|
48
|
+
if (!isGlobCall &&
|
|
49
|
+
node.callee.type === 'MemberExpression' &&
|
|
50
|
+
!node.callee.computed &&
|
|
51
|
+
node.callee.object.type === 'Identifier' &&
|
|
52
|
+
namespaceNames.has(node.callee.object.name) &&
|
|
53
|
+
node.callee.property.type === 'Identifier' &&
|
|
54
|
+
node.callee.property.name === 'glob') {
|
|
55
|
+
isGlobCall = true;
|
|
56
|
+
}
|
|
57
|
+
if (!isGlobCall)
|
|
58
|
+
return;
|
|
59
|
+
const arg = node.arguments[0];
|
|
60
|
+
if (!arg)
|
|
61
|
+
return;
|
|
62
|
+
let patterns;
|
|
63
|
+
if (isStringLiteral(arg)) {
|
|
64
|
+
patterns = [getStringValue(arg)];
|
|
65
|
+
}
|
|
66
|
+
else if (arg.type === 'ArrayExpression') {
|
|
67
|
+
patterns = [];
|
|
68
|
+
for (const element of arg.elements) {
|
|
69
|
+
if (!element || !isStringLiteral(element))
|
|
70
|
+
return;
|
|
71
|
+
patterns.push(getStringValue(element));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (!patterns?.length || patterns.some(pattern => pattern.startsWith('!')))
|
|
75
|
+
return;
|
|
76
|
+
const options = node.arguments[1];
|
|
77
|
+
if (options && options.type !== 'ObjectExpression')
|
|
78
|
+
return;
|
|
79
|
+
if (options &&
|
|
80
|
+
(options.properties.length > 1 ||
|
|
81
|
+
options.properties.some(property => property.type !== 'Property' || property.computed || getPropertyKey(property) !== 'cwd')))
|
|
82
|
+
return;
|
|
83
|
+
const cwdNode = findProperty(options, 'cwd');
|
|
84
|
+
if (cwdNode && !isStringLiteral(cwdNode))
|
|
85
|
+
return;
|
|
86
|
+
ctx.addImportGlob(patterns, { cwd: cwdNode ? getStringValue(cwdNode) : '.' });
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|