@venizia/dev-configs 0.5.0-0 → 0.5.0-10
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/README.md +18 -13
- package/dist/checks/purity/manifest.js +11 -3
- package/dist/checks/purity/manifest.js.map +1 -1
- package/dist/checks/purity/probe.js +19 -2
- package/dist/checks/purity/probe.js.map +1 -1
- package/dist/checks/split-report.js +2 -1
- package/dist/checks/split-report.js.map +1 -1
- package/dist/checks/test-controls.d.ts +9 -1
- package/dist/checks/test-controls.js +9 -3
- package/dist/checks/test-controls.js.map +1 -1
- package/dist/checks/test-dead-code.d.ts +9 -1
- package/dist/checks/test-dead-code.js +13 -2
- package/dist/checks/test-dead-code.js.map +1 -1
- package/dist/checks/test-mutate.d.ts +9 -1
- package/dist/checks/test-mutate.js +12 -6
- package/dist/checks/test-mutate.js.map +1 -1
- package/dist/cli/check.js +42 -38
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/clean.js +3 -2
- package/dist/cli/clean.js.map +1 -1
- package/dist/cli/codemod/any-aliases.d.ts +1 -1
- package/dist/cli/codemod/any-aliases.js +14 -13
- package/dist/cli/codemod/any-aliases.js.map +1 -1
- package/dist/cli/codemod/async-style.d.ts +1 -1
- package/dist/cli/codemod/async-style.js +18 -17
- package/dist/cli/codemod/async-style.js.map +1 -1
- package/dist/cli/codemod/binding-keys.d.ts +32 -1
- package/dist/cli/codemod/binding-keys.js +251 -68
- package/dist/cli/codemod/binding-keys.js.map +1 -1
- package/dist/cli/codemod/class-renames.d.ts +39 -0
- package/dist/cli/codemod/class-renames.js +297 -0
- package/dist/cli/codemod/class-renames.js.map +1 -0
- package/dist/cli/codemod/connector-imports.d.ts +1 -1
- package/dist/cli/codemod/connector-imports.js +13 -12
- package/dist/cli/codemod/connector-imports.js.map +1 -1
- package/dist/cli/codemod/const-class-sets.d.ts +55 -0
- package/dist/cli/codemod/const-class-sets.js +219 -0
- package/dist/cli/codemod/const-class-sets.js.map +1 -0
- package/dist/cli/codemod/const-classes.d.ts +21 -3
- package/dist/cli/codemod/const-classes.js +151 -36
- package/dist/cli/codemod/const-classes.js.map +1 -1
- package/dist/cli/codemod/drop-redundant-casts.d.ts +6 -1
- package/dist/cli/codemod/drop-redundant-casts.js +27 -19
- package/dist/cli/codemod/drop-redundant-casts.js.map +1 -1
- package/dist/cli/codemod/env-get.d.ts +3 -3
- package/dist/cli/codemod/env-get.js +19 -18
- package/dist/cli/codemod/env-get.js.map +1 -1
- package/dist/cli/codemod/files.d.ts +4 -2
- package/dist/cli/codemod/files.js +7 -8
- package/dist/cli/codemod/files.js.map +1 -1
- package/dist/cli/codemod/function-to-arrow.d.ts +76 -0
- package/dist/cli/codemod/function-to-arrow.js +357 -0
- package/dist/cli/codemod/function-to-arrow.js.map +1 -0
- package/dist/cli/codemod/index.js +25 -4
- package/dist/cli/codemod/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/index.d.ts +1 -1
- package/dist/cli/codemod/namespace-functions/index.js +14 -13
- package/dist/cli/codemod/namespace-functions/index.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js +3 -3
- package/dist/cli/codemod/namespace-functions/mappings/dev-configs.js.map +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/helpers.js +1 -1
- package/dist/cli/codemod/namespace-functions/mappings/helpers.js.map +1 -1
- package/dist/cli/codemod/typed-route-context.d.ts +58 -0
- package/dist/cli/codemod/typed-route-context.js +918 -0
- package/dist/cli/codemod/typed-route-context.js.map +1 -0
- package/dist/cli/index.js +5 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/common/cli-output.d.ts +16 -0
- package/dist/common/cli-output.js +49 -0
- package/dist/common/cli-output.js.map +1 -0
- package/dist/compilers/bun.js +1 -1
- package/dist/compilers/bun.js.map +1 -1
- package/dist/linters/eslint.js +1 -1
- package/dist/linters/eslint.js.map +1 -1
- package/dist/linters/house/browser-api-patterns.d.ts +43 -0
- package/dist/linters/house/browser-api-patterns.js +87 -0
- package/dist/linters/house/browser-api-patterns.js.map +1 -0
- package/dist/linters/house/common.d.ts +17 -2
- package/dist/linters/house/common.js +18 -2
- package/dist/linters/house/common.js.map +1 -1
- package/dist/linters/house/configs.js +25 -0
- package/dist/linters/house/configs.js.map +1 -1
- package/dist/linters/house/const-class-values.rule.d.ts +2 -2
- package/dist/linters/house/const-class-values.rule.js +14 -5
- package/dist/linters/house/const-class-values.rule.js.map +1 -1
- package/dist/linters/house/effect-cleanup-consistency.rule.d.ts +2 -2
- package/dist/linters/house/effect-cleanup-consistency.rule.js +1 -1
- package/dist/linters/house/effect-cleanup-consistency.rule.js.map +1 -1
- package/dist/linters/house/framework-api-patterns.d.ts +54 -0
- package/dist/linters/house/framework-api-patterns.js +62 -0
- package/dist/linters/house/framework-api-patterns.js.map +1 -0
- package/dist/linters/house/framework-exports.d.ts +62 -0
- package/dist/linters/house/framework-exports.js +325 -0
- package/dist/linters/house/framework-exports.js.map +1 -0
- package/dist/linters/house/import-support.d.ts +56 -0
- package/dist/linters/house/import-support.js +179 -0
- package/dist/linters/house/import-support.js.map +1 -0
- package/dist/linters/house/index.d.ts +12 -0
- package/dist/linters/house/index.js +15 -1
- package/dist/linters/house/index.js.map +1 -1
- package/dist/linters/house/max-params-own.rule.d.ts +2 -2
- package/dist/linters/house/max-params-own.rule.js +1 -1
- package/dist/linters/house/max-params-own.rule.js.map +1 -1
- package/dist/linters/house/no-async-hook-callback.rule.d.ts +2 -2
- package/dist/linters/house/no-async-hook-callback.rule.js +1 -1
- package/dist/linters/house/no-async-hook-callback.rule.js.map +1 -1
- package/dist/linters/house/no-await-new-chain.rule.d.ts +2 -2
- package/dist/linters/house/no-await-new-chain.rule.js +1 -1
- package/dist/linters/house/no-await-new-chain.rule.js.map +1 -1
- package/dist/linters/house/no-await-promise-chain.rule.d.ts +2 -2
- package/dist/linters/house/no-await-promise-chain.rule.js +5 -5
- package/dist/linters/house/no-await-promise-chain.rule.js.map +1 -1
- package/dist/linters/house/no-inline-await.rule.d.ts +2 -2
- package/dist/linters/house/no-inline-await.rule.js +1 -1
- package/dist/linters/house/no-inline-await.rule.js.map +1 -1
- package/dist/linters/house/no-leaked-render.rule.d.ts +2 -2
- package/dist/linters/house/no-leaked-render.rule.js +1 -1
- package/dist/linters/house/no-leaked-render.rule.js.map +1 -1
- package/dist/linters/house/no-new-error.rule.d.ts +2 -2
- package/dist/linters/house/no-new-error.rule.js +2 -2
- package/dist/linters/house/no-new-error.rule.js.map +1 -1
- package/dist/linters/house/no-parent-import.rule.d.ts +45 -0
- package/dist/linters/house/no-parent-import.rule.js +176 -0
- package/dist/linters/house/no-parent-import.rule.js.map +1 -0
- package/dist/linters/house/no-return-await.rule.d.ts +2 -2
- package/dist/linters/house/no-return-await.rule.js +1 -1
- package/dist/linters/house/no-return-await.rule.js.map +1 -1
- package/dist/linters/house/no-shadow-framework-type.rule.d.ts +24 -0
- package/dist/linters/house/no-shadow-framework-type.rule.js +100 -0
- package/dist/linters/house/no-shadow-framework-type.rule.js.map +1 -0
- package/dist/linters/house/no-silent-catch.rule.d.ts +2 -2
- package/dist/linters/house/no-silent-catch.rule.js +3 -3
- package/dist/linters/house/no-silent-catch.rule.js.map +1 -1
- package/dist/linters/house/no-unbraced-case.rule.d.ts +2 -2
- package/dist/linters/house/no-unbraced-case.rule.js +1 -1
- package/dist/linters/house/no-unbraced-case.rule.js.map +1 -1
- package/dist/linters/house/plugin.d.ts +1 -1
- package/dist/linters/house/plugin.js +18 -2
- package/dist/linters/house/plugin.js.map +1 -1
- package/dist/linters/house/prefer-framework-api.rule.d.ts +83 -0
- package/dist/linters/house/prefer-framework-api.rule.js +562 -0
- package/dist/linters/house/prefer-framework-api.rule.js.map +1 -0
- package/dist/linters/house/prefer-http-method.rule.d.ts +22 -0
- package/dist/linters/house/prefer-http-method.rule.js +182 -0
- package/dist/linters/house/prefer-http-method.rule.js.map +1 -0
- package/dist/linters/house/prefer-promise-sleep.rule.d.ts +26 -0
- package/dist/linters/house/prefer-promise-sleep.rule.js +155 -0
- package/dist/linters/house/prefer-promise-sleep.rule.js.map +1 -0
- package/dist/linters/house/prefer-tnullable.rule.d.ts +25 -0
- package/dist/linters/house/prefer-tnullable.rule.js +124 -0
- package/dist/linters/house/prefer-tnullable.rule.js.map +1 -0
- package/dist/linters/house/typed-route-context.rule.d.ts +19 -0
- package/dist/linters/house/typed-route-context.rule.js +334 -0
- package/dist/linters/house/typed-route-context.rule.js.map +1 -0
- package/dist/linters/house/zod-schema-convention.rule.d.ts +82 -0
- package/dist/linters/house/zod-schema-convention.rule.js +477 -0
- package/dist/linters/house/zod-schema-convention.rule.js.map +1 -0
- package/dist/linters/oxlint.js +11 -1
- package/dist/linters/oxlint.js.map +1 -1
- package/dist/linters/react-eslint.js.map +1 -1
- package/dist/linters/rules/naming-convention.rule.d.ts +4 -1
- package/dist/linters/rules/naming-convention.rule.js +30 -1
- package/dist/linters/rules/naming-convention.rule.js.map +1 -1
- package/dist/linters/rules/no-restricted-properties.rule.js +1 -1
- package/dist/linters/rules/no-restricted-properties.rule.js.map +1 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/{rejection.helper.d.ts → rejection.utility.d.ts} +4 -4
- package/dist/testing/{rejection.helper.js → rejection.utility.js} +7 -7
- package/dist/testing/rejection.utility.js.map +1 -0
- package/dist/testing/{spawn.helper.d.ts → spawn.utility.d.ts} +2 -2
- package/dist/testing/{spawn.helper.js → spawn.utility.js} +6 -6
- package/dist/testing/spawn.utility.js.map +1 -0
- package/package.json +7 -7
- package/dist/testing/rejection.helper.js.map +0 -1
- package/dist/testing/spawn.helper.js.map +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type ts from 'typescript';
|
|
2
|
+
/** The nearest package.json at or above a folder: where it is, and what it says. */
|
|
3
|
+
export interface IPackageManifest {
|
|
4
|
+
directory: string;
|
|
5
|
+
name: string | undefined;
|
|
6
|
+
dependencies: ReadonlyArray<string>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The type names the installed `@venizia/*` packages export, read from their published `.d.ts` files: the names a project
|
|
10
|
+
* must import, not write again. Only interfaces and type aliases count (a class or a const is not a type your own
|
|
11
|
+
* `interface Logger` copies). A declaration scan only (the TypeScript parser, no program, no type check), memoized per
|
|
12
|
+
* package for the life of the process: after an upgrade an ESLint server must be restarted to read the new names.
|
|
13
|
+
*
|
|
14
|
+
* It never stops a lint run. TypeScript is looked up from the linted package, the working directory and dev-configs' own
|
|
15
|
+
* install, and only a copy that has the parser API is used (the native TypeScript 7 has none); a package.json or a `.d.ts`
|
|
16
|
+
* that cannot be read is skipped. Whatever is missing, the answer is fewer names, never an exception.
|
|
17
|
+
*/
|
|
18
|
+
export declare class FrameworkExports {
|
|
19
|
+
static readonly SCOPE = "@venizia/";
|
|
20
|
+
private static readonly manifests;
|
|
21
|
+
private static readonly packages;
|
|
22
|
+
private static readonly typescripts;
|
|
23
|
+
/** `value` as the TypeScript module when it has the parser API this scan uses. */
|
|
24
|
+
private static isParser;
|
|
25
|
+
/** The text of a file, or `undefined` when it cannot be read. */
|
|
26
|
+
private static readText;
|
|
27
|
+
/** A JSON file, or `undefined` when it cannot be read or does not parse. */
|
|
28
|
+
private static readJson;
|
|
29
|
+
/**
|
|
30
|
+
* TypeScript for the linted package: from its own folder, the working directory, or this package's install, the first that
|
|
31
|
+
* has the parser API. `undefined` when none does (the rule then reports nothing).
|
|
32
|
+
*/
|
|
33
|
+
static loadTypeScript(opts: {
|
|
34
|
+
directory: string;
|
|
35
|
+
}): typeof ts | undefined;
|
|
36
|
+
/** The nearest package.json at or above `directory`. */
|
|
37
|
+
static manifestFor(opts: {
|
|
38
|
+
directory: string;
|
|
39
|
+
}): IPackageManifest | undefined;
|
|
40
|
+
/** The folder of the installed package `name`, looked up from `directory` upwards. */
|
|
41
|
+
private static locate;
|
|
42
|
+
/** Every `.d.ts` path an `exports` value names, with the subpath it is reached by. */
|
|
43
|
+
private static entriesOf;
|
|
44
|
+
/** The declaration file a relative specifier points at (`./x.js` is `./x.d.ts`). */
|
|
45
|
+
private static resolveRelative;
|
|
46
|
+
/**
|
|
47
|
+
* The names `file` exports, each with what it is, following `export *` into relative files and into other `@venizia/*`
|
|
48
|
+
* packages (an umbrella package re-exports its siblings). A name re-exported by `export { X } from` takes the type it has
|
|
49
|
+
* where it is declared; `export type { X }` is a type whatever the target says.
|
|
50
|
+
*/
|
|
51
|
+
private static namesOf;
|
|
52
|
+
/** Type name to the specifier that exports it (`@venizia/ignis-helpers/common`), for one installed package. */
|
|
53
|
+
private static readPackage;
|
|
54
|
+
/**
|
|
55
|
+
* The type names the `@venizia/*` packages that `directory`'s project depends on export, each with the specifier to import
|
|
56
|
+
* it from. The project's own package is left out: it may declare what it exports.
|
|
57
|
+
*/
|
|
58
|
+
static of(opts: {
|
|
59
|
+
directory: string;
|
|
60
|
+
}): Map<string, string>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=framework-exports.d.ts.map
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FrameworkExports = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_module_1 = require("node:module");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const common_1 = require("./common");
|
|
8
|
+
/**
|
|
9
|
+
* The type names the installed `@venizia/*` packages export, read from their published `.d.ts` files: the names a project
|
|
10
|
+
* must import, not write again. Only interfaces and type aliases count (a class or a const is not a type your own
|
|
11
|
+
* `interface Logger` copies). A declaration scan only (the TypeScript parser, no program, no type check), memoized per
|
|
12
|
+
* package for the life of the process: after an upgrade an ESLint server must be restarted to read the new names.
|
|
13
|
+
*
|
|
14
|
+
* It never stops a lint run. TypeScript is looked up from the linted package, the working directory and dev-configs' own
|
|
15
|
+
* install, and only a copy that has the parser API is used (the native TypeScript 7 has none); a package.json or a `.d.ts`
|
|
16
|
+
* that cannot be read is skipped. Whatever is missing, the answer is fewer names, never an exception.
|
|
17
|
+
*/
|
|
18
|
+
class FrameworkExports {
|
|
19
|
+
static { this.SCOPE = '@venizia/'; }
|
|
20
|
+
static { this.manifests = new Map(); }
|
|
21
|
+
static { this.packages = new Map(); }
|
|
22
|
+
static { this.typescripts = new Map(); }
|
|
23
|
+
/** `value` as the TypeScript module when it has the parser API this scan uses. */
|
|
24
|
+
static isParser(value) {
|
|
25
|
+
return (typeof value === 'object' &&
|
|
26
|
+
value !== null &&
|
|
27
|
+
typeof Reflect.get(value, 'createSourceFile') === 'function' &&
|
|
28
|
+
typeof common_1.AstNode.readField({ node: Reflect.get(value, 'ScriptTarget'), key: 'Latest' }) ===
|
|
29
|
+
'number');
|
|
30
|
+
}
|
|
31
|
+
/** The text of a file, or `undefined` when it cannot be read. */
|
|
32
|
+
static readText(opts) {
|
|
33
|
+
try {
|
|
34
|
+
return (0, node_fs_1.readFileSync)(opts.file, 'utf8');
|
|
35
|
+
// eslint-disable-next-line @venizia/no-silent-catch -- an unreadable file only means fewer names
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** A JSON file, or `undefined` when it cannot be read or does not parse. */
|
|
42
|
+
static readJson(opts) {
|
|
43
|
+
const text = FrameworkExports.readText(opts);
|
|
44
|
+
if (text === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
return JSON.parse(text);
|
|
49
|
+
// eslint-disable-next-line @venizia/no-silent-catch -- a package.json that does not parse only means fewer names
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* TypeScript for the linted package: from its own folder, the working directory, or this package's install, the first that
|
|
57
|
+
* has the parser API. `undefined` when none does (the rule then reports nothing).
|
|
58
|
+
*/
|
|
59
|
+
static loadTypeScript(opts) {
|
|
60
|
+
const { directory } = opts;
|
|
61
|
+
const cached = FrameworkExports.typescripts.get(directory);
|
|
62
|
+
if (cached !== undefined) {
|
|
63
|
+
return cached ?? undefined;
|
|
64
|
+
}
|
|
65
|
+
const starts = [
|
|
66
|
+
directory,
|
|
67
|
+
process.cwd(),
|
|
68
|
+
typeof __dirname === 'string' ? __dirname : undefined,
|
|
69
|
+
];
|
|
70
|
+
for (const start of starts) {
|
|
71
|
+
if (start === undefined) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const loaded = (0, node_module_1.createRequire)((0, node_path_1.join)(start, 'noop.js'))('typescript');
|
|
76
|
+
if (FrameworkExports.isParser(loaded)) {
|
|
77
|
+
FrameworkExports.typescripts.set(directory, loaded);
|
|
78
|
+
return loaded;
|
|
79
|
+
}
|
|
80
|
+
// eslint-disable-next-line @venizia/no-silent-catch -- not installed at this start: the next one is tried
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
FrameworkExports.typescripts.set(directory, null);
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
/** The nearest package.json at or above `directory`. */
|
|
90
|
+
static manifestFor(opts) {
|
|
91
|
+
const { directory } = opts;
|
|
92
|
+
const cached = FrameworkExports.manifests.get(directory);
|
|
93
|
+
if (cached !== undefined) {
|
|
94
|
+
return cached ?? undefined;
|
|
95
|
+
}
|
|
96
|
+
const file = (0, node_path_1.join)(directory, 'package.json');
|
|
97
|
+
let found;
|
|
98
|
+
if ((0, node_fs_1.existsSync)(file)) {
|
|
99
|
+
const parsed = FrameworkExports.readJson({ file });
|
|
100
|
+
const name = common_1.AstNode.readField({ node: parsed, key: 'name' });
|
|
101
|
+
const names = ['dependencies', 'peerDependencies'].flatMap((key) => {
|
|
102
|
+
const group = common_1.AstNode.readField({ node: parsed, key });
|
|
103
|
+
return typeof group === 'object' && group !== null ? Object.keys(group) : [];
|
|
104
|
+
});
|
|
105
|
+
found = {
|
|
106
|
+
directory,
|
|
107
|
+
name: typeof name === 'string' ? name : undefined,
|
|
108
|
+
dependencies: names.filter((entry) => entry.startsWith(FrameworkExports.SCOPE)),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const parent = (0, node_path_1.dirname)(directory);
|
|
113
|
+
found =
|
|
114
|
+
parent === directory ? undefined : FrameworkExports.manifestFor({ directory: parent });
|
|
115
|
+
}
|
|
116
|
+
FrameworkExports.manifests.set(directory, found ?? null);
|
|
117
|
+
return found;
|
|
118
|
+
}
|
|
119
|
+
/** The folder of the installed package `name`, looked up from `directory` upwards. */
|
|
120
|
+
static locate(opts) {
|
|
121
|
+
const candidate = (0, node_path_1.join)(opts.directory, 'node_modules', opts.name);
|
|
122
|
+
if ((0, node_fs_1.existsSync)((0, node_path_1.join)(candidate, 'package.json'))) {
|
|
123
|
+
return candidate;
|
|
124
|
+
}
|
|
125
|
+
const parent = (0, node_path_1.dirname)(opts.directory);
|
|
126
|
+
return parent === opts.directory
|
|
127
|
+
? undefined
|
|
128
|
+
: FrameworkExports.locate({ name: opts.name, directory: parent });
|
|
129
|
+
}
|
|
130
|
+
/** Every `.d.ts` path an `exports` value names, with the subpath it is reached by. */
|
|
131
|
+
static entriesOf(opts) {
|
|
132
|
+
const { manifest } = opts;
|
|
133
|
+
const exported = common_1.AstNode.readField({ node: manifest, key: 'exports' });
|
|
134
|
+
const declarations = (value) => {
|
|
135
|
+
if (typeof value === 'string') {
|
|
136
|
+
return /\.d\.[cm]?ts$/.test(value) ? [value] : [];
|
|
137
|
+
}
|
|
138
|
+
return typeof value === 'object' && value !== null
|
|
139
|
+
? Object.values(value).flatMap((entry) => declarations(entry))
|
|
140
|
+
: [];
|
|
141
|
+
};
|
|
142
|
+
if (typeof exported === 'object' && exported !== null) {
|
|
143
|
+
return Object.entries(exported).flatMap(([key, value]) => declarations(value).map((file) => ({ subpath: key === '.' ? '' : key.slice(1), file })));
|
|
144
|
+
}
|
|
145
|
+
const legacy = common_1.AstNode.readField({ node: manifest, key: 'types' });
|
|
146
|
+
return typeof legacy === 'string' ? [{ subpath: '', file: legacy }] : [];
|
|
147
|
+
}
|
|
148
|
+
/** The declaration file a relative specifier points at (`./x.js` is `./x.d.ts`). */
|
|
149
|
+
static resolveRelative(opts) {
|
|
150
|
+
const base = (0, node_path_1.resolve)((0, node_path_1.dirname)(opts.from), opts.specifier.replace(/\.(?:[cm]?js|[cm]?ts)$/, ''));
|
|
151
|
+
return [`${base}.d.ts`, `${base}.d.mts`, (0, node_path_1.join)(base, 'index.d.ts')].find((file) => (0, node_fs_1.existsSync)(file));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The names `file` exports, each with what it is, following `export *` into relative files and into other `@venizia/*`
|
|
155
|
+
* packages (an umbrella package re-exports its siblings). A name re-exported by `export { X } from` takes the type it has
|
|
156
|
+
* where it is declared; `export type { X }` is a type whatever the target says.
|
|
157
|
+
*/
|
|
158
|
+
static namesOf(opts) {
|
|
159
|
+
const { typescript, file, seen } = opts;
|
|
160
|
+
const names = new Map();
|
|
161
|
+
const text = FrameworkExports.readText({ file });
|
|
162
|
+
if (seen.has(file) || text === undefined) {
|
|
163
|
+
return names;
|
|
164
|
+
}
|
|
165
|
+
seen.add(file);
|
|
166
|
+
const source = typescript.createSourceFile(file, text, typescript.ScriptTarget.Latest, false);
|
|
167
|
+
const typeOf = (node) => typescript.isInterfaceDeclaration(node) || typescript.isTypeAliasDeclaration(node)
|
|
168
|
+
? 'type'
|
|
169
|
+
: 'value';
|
|
170
|
+
const isExported = (node) => typescript.canHaveModifiers(node) &&
|
|
171
|
+
(typescript.getModifiers(node) ?? []).some((modifier) => modifier.kind === typescript.SyntaxKind.ExportKeyword);
|
|
172
|
+
// What the file declares, exported or not: `declare class X {}` then `export { X }` is a value.
|
|
173
|
+
const locals = new Map();
|
|
174
|
+
for (const statement of source.statements) {
|
|
175
|
+
if (typescript.isVariableStatement(statement)) {
|
|
176
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
177
|
+
if (typescript.isIdentifier(declaration.name)) {
|
|
178
|
+
locals.set(declaration.name.text, 'value');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else if ((typescript.isInterfaceDeclaration(statement) ||
|
|
183
|
+
typescript.isTypeAliasDeclaration(statement) ||
|
|
184
|
+
typescript.isClassDeclaration(statement) ||
|
|
185
|
+
typescript.isFunctionDeclaration(statement) ||
|
|
186
|
+
typescript.isEnumDeclaration(statement) ||
|
|
187
|
+
typescript.isModuleDeclaration(statement)) &&
|
|
188
|
+
statement.name &&
|
|
189
|
+
typescript.isIdentifier(statement.name)) {
|
|
190
|
+
// An interface merged with a class or a namespace of the same name has a value too.
|
|
191
|
+
locals.set(statement.name.text, locals.get(statement.name.text) === 'value' ? 'value' : typeOf(statement));
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
for (const statement of source.statements) {
|
|
195
|
+
if (typescript.isExportDeclaration(statement)) {
|
|
196
|
+
const clause = statement.exportClause;
|
|
197
|
+
const specifier = statement.moduleSpecifier && typescript.isStringLiteral(statement.moduleSpecifier)
|
|
198
|
+
? statement.moduleSpecifier.text
|
|
199
|
+
: undefined;
|
|
200
|
+
if (clause && typescript.isNamedExports(clause)) {
|
|
201
|
+
const remote = specifier?.startsWith('.') === true
|
|
202
|
+
? FrameworkExports.resolveRelative({ from: file, specifier })
|
|
203
|
+
: undefined;
|
|
204
|
+
const there = remote
|
|
205
|
+
? FrameworkExports.namesOf({ typescript, file: remote, seen: new Set(seen) })
|
|
206
|
+
: undefined;
|
|
207
|
+
for (const element of clause.elements) {
|
|
208
|
+
const original = (element.propertyName ?? element.name).text;
|
|
209
|
+
const declared = statement.isTypeOnly || element.isTypeOnly
|
|
210
|
+
? 'type'
|
|
211
|
+
: specifier === undefined
|
|
212
|
+
? locals.get(original)
|
|
213
|
+
: there?.get(original);
|
|
214
|
+
if (declared !== undefined) {
|
|
215
|
+
names.set(element.name.text, declared);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if (!clause && specifier?.startsWith('.') === true) {
|
|
220
|
+
const target = FrameworkExports.resolveRelative({ from: file, specifier });
|
|
221
|
+
if (target) {
|
|
222
|
+
for (const [name, declared] of FrameworkExports.namesOf({
|
|
223
|
+
typescript,
|
|
224
|
+
file: target,
|
|
225
|
+
seen,
|
|
226
|
+
})) {
|
|
227
|
+
names.set(name, declared);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else if (!clause && specifier?.startsWith(FrameworkExports.SCOPE) === true) {
|
|
232
|
+
const sibling = FrameworkExports.locate({ name: specifier, directory: (0, node_path_1.dirname)(file) });
|
|
233
|
+
if (sibling) {
|
|
234
|
+
for (const name of FrameworkExports.readPackage({ directory: sibling }).keys()) {
|
|
235
|
+
names.set(name, 'type');
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (!isExported(statement)) {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
if (typescript.isVariableStatement(statement)) {
|
|
245
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
246
|
+
if (typescript.isIdentifier(declaration.name)) {
|
|
247
|
+
names.set(declaration.name.text, 'value');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
else if ((typescript.isInterfaceDeclaration(statement) ||
|
|
252
|
+
typescript.isTypeAliasDeclaration(statement) ||
|
|
253
|
+
typescript.isClassDeclaration(statement) ||
|
|
254
|
+
typescript.isFunctionDeclaration(statement) ||
|
|
255
|
+
typescript.isEnumDeclaration(statement) ||
|
|
256
|
+
typescript.isModuleDeclaration(statement)) &&
|
|
257
|
+
statement.name &&
|
|
258
|
+
typescript.isIdentifier(statement.name)) {
|
|
259
|
+
names.set(statement.name.text, locals.get(statement.name.text) ?? typeOf(statement));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return names;
|
|
263
|
+
}
|
|
264
|
+
/** Type name to the specifier that exports it (`@venizia/ignis-helpers/common`), for one installed package. */
|
|
265
|
+
static readPackage(opts) {
|
|
266
|
+
const { directory } = opts;
|
|
267
|
+
const cached = FrameworkExports.packages.get(directory);
|
|
268
|
+
if (cached) {
|
|
269
|
+
return cached;
|
|
270
|
+
}
|
|
271
|
+
const exported = new Map();
|
|
272
|
+
FrameworkExports.packages.set(directory, exported);
|
|
273
|
+
const typescript = FrameworkExports.loadTypeScript({ directory });
|
|
274
|
+
const manifest = FrameworkExports.readJson({ file: (0, node_path_1.join)(directory, 'package.json') });
|
|
275
|
+
const name = common_1.AstNode.readField({ node: manifest, key: 'name' });
|
|
276
|
+
if (!typescript || typeof name !== 'string') {
|
|
277
|
+
return exported;
|
|
278
|
+
}
|
|
279
|
+
// A name reachable from several entries is imported from the narrowest one: `/common` over the root that re-exports it.
|
|
280
|
+
const sizes = new Map();
|
|
281
|
+
for (const { subpath, file } of FrameworkExports.entriesOf({ manifest })) {
|
|
282
|
+
const path = (0, node_path_1.resolve)(directory, file);
|
|
283
|
+
if (!(0, node_fs_1.existsSync)(path)) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const declared = FrameworkExports.namesOf({ typescript, file: path, seen: new Set() });
|
|
287
|
+
const types = [...declared].filter(([, type]) => type === 'type').map(([entry]) => entry);
|
|
288
|
+
for (const entry of types) {
|
|
289
|
+
if (types.length < (sizes.get(entry) ?? Number.POSITIVE_INFINITY)) {
|
|
290
|
+
sizes.set(entry, types.length);
|
|
291
|
+
exported.set(entry, `${name}${subpath}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return exported;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The type names the `@venizia/*` packages that `directory`'s project depends on export, each with the specifier to import
|
|
299
|
+
* it from. The project's own package is left out: it may declare what it exports.
|
|
300
|
+
*/
|
|
301
|
+
static of(opts) {
|
|
302
|
+
const manifest = FrameworkExports.manifestFor({ directory: opts.directory });
|
|
303
|
+
const all = new Map();
|
|
304
|
+
if (!manifest) {
|
|
305
|
+
return all;
|
|
306
|
+
}
|
|
307
|
+
for (const dependency of manifest.dependencies) {
|
|
308
|
+
const installed = FrameworkExports.locate({
|
|
309
|
+
name: dependency,
|
|
310
|
+
directory: manifest.directory,
|
|
311
|
+
});
|
|
312
|
+
if (!installed || dependency === manifest.name) {
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
for (const [name, specifier] of FrameworkExports.readPackage({ directory: installed })) {
|
|
316
|
+
if (!all.has(name)) {
|
|
317
|
+
all.set(name, specifier);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return all;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
exports.FrameworkExports = FrameworkExports;
|
|
325
|
+
//# sourceMappingURL=framework-exports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-exports.js","sourceRoot":"","sources":["../../../src/linters/house/framework-exports.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,6CAA4C;AAC5C,yCAAmD;AAEnD,qCAAmC;AAYnC;;;;;;;;;GASG;AACH,MAAa,gBAAgB;aACX,UAAK,GAAG,WAAW,CAAC;aAEZ,cAAS,GAAG,IAAI,GAAG,EAAmC,CAAC;aACvD,aAAQ,GAAG,IAAI,GAAG,EAA+B,CAAC;aAClD,gBAAW,GAAG,IAAI,GAAG,EAA4B,CAAC;IAE1E,kFAAkF;IAC1E,MAAM,CAAC,QAAQ,CAAC,KAAc;QACpC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;YACzB,KAAK,KAAK,IAAI;YACd,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,kBAAkB,CAAC,KA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,GAAG,IAAI,GAAG,EAAkB,CAAC;QAEtC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,GAAG,CAAC;QACb,CAAC;QAED,KAAK,MAAM,UAAU,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;YAC/C,MAAM,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC;gBACxC,IAAI,EAAE,UAAU;gBAChB,SAAS,EAAE,QAAQ,CAAC,SAAS;aAC9B,CAAC,CAAC;YAEH,IAAI,CAAC,SAAS,IAAI,UAAU,KAAK,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAC/C,SAAS;YACX,CAAC;YAED,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,gBAAgB,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;gBACvF,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;oBACnB,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;;AApYH,4CAqYC","sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { createRequire } from 'node:module';\nimport { dirname, join, resolve } from 'node:path';\nimport type ts from 'typescript';\nimport { AstNode } from './common';\n\n/** The nearest package.json at or above a folder: where it is, and what it says. */\nexport interface IPackageManifest {\n directory: string;\n name: string | undefined;\n dependencies: ReadonlyArray<string>;\n}\n\n/** Whether a declared name is a type (an interface or a type alias) or something with a runtime value (a class, a function, a const, an enum, a namespace). */\ntype TDeclarationType = 'type' | 'value';\n\n/**\n * The type names the installed `@venizia/*` packages export, read from their published `.d.ts` files: the names a project\n * must import, not write again. Only interfaces and type aliases count (a class or a const is not a type your own\n * `interface Logger` copies). A declaration scan only (the TypeScript parser, no program, no type check), memoized per\n * package for the life of the process: after an upgrade an ESLint server must be restarted to read the new names.\n *\n * It never stops a lint run. TypeScript is looked up from the linted package, the working directory and dev-configs' own\n * install, and only a copy that has the parser API is used (the native TypeScript 7 has none); a package.json or a `.d.ts`\n * that cannot be read is skipped. Whatever is missing, the answer is fewer names, never an exception.\n */\nexport class FrameworkExports {\n static readonly SCOPE = '@venizia/';\n\n private static readonly manifests = new Map<string, IPackageManifest | null>();\n private static readonly packages = new Map<string, Map<string, string>>();\n private static readonly typescripts = new Map<string, typeof ts | null>();\n\n /** `value` as the TypeScript module when it has the parser API this scan uses. */\n private static isParser(value: unknown): value is typeof ts {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof Reflect.get(value, 'createSourceFile') === 'function' &&\n typeof AstNode.readField({ node: Reflect.get(value, 'ScriptTarget'), key: 'Latest' }) ===\n 'number'\n );\n }\n\n /** The text of a file, or `undefined` when it cannot be read. */\n private static readText(opts: { file: string }): string | undefined {\n try {\n return readFileSync(opts.file, 'utf8');\n // eslint-disable-next-line @venizia/no-silent-catch -- an unreadable file only means fewer names\n } catch {\n return undefined;\n }\n }\n\n /** A JSON file, or `undefined` when it cannot be read or does not parse. */\n private static readJson(opts: { file: string }): unknown {\n const text = FrameworkExports.readText(opts);\n\n if (text === undefined) {\n return undefined;\n }\n\n try {\n return JSON.parse(text);\n // eslint-disable-next-line @venizia/no-silent-catch -- a package.json that does not parse only means fewer names\n } catch {\n return undefined;\n }\n }\n\n /**\n * TypeScript for the linted package: from its own folder, the working directory, or this package's install, the first that\n * has the parser API. `undefined` when none does (the rule then reports nothing).\n */\n static loadTypeScript(opts: { directory: string }): typeof ts | undefined {\n const { directory } = opts;\n const cached = FrameworkExports.typescripts.get(directory);\n\n if (cached !== undefined) {\n return cached ?? undefined;\n }\n\n const starts = [\n directory,\n process.cwd(),\n typeof __dirname === 'string' ? __dirname : undefined,\n ];\n\n for (const start of starts) {\n if (start === undefined) {\n continue;\n }\n\n try {\n const loaded: unknown = createRequire(join(start, 'noop.js'))('typescript');\n\n if (FrameworkExports.isParser(loaded)) {\n FrameworkExports.typescripts.set(directory, loaded);\n\n return loaded;\n }\n // eslint-disable-next-line @venizia/no-silent-catch -- not installed at this start: the next one is tried\n } catch {\n continue;\n }\n }\n\n FrameworkExports.typescripts.set(directory, null);\n\n return undefined;\n }\n\n /** The nearest package.json at or above `directory`. */\n static manifestFor(opts: { directory: string }): IPackageManifest | undefined {\n const { directory } = opts;\n const cached = FrameworkExports.manifests.get(directory);\n\n if (cached !== undefined) {\n return cached ?? undefined;\n }\n\n const file = join(directory, 'package.json');\n let found: IPackageManifest | undefined;\n\n if (existsSync(file)) {\n const parsed = FrameworkExports.readJson({ file });\n const name = AstNode.readField({ node: parsed, key: 'name' });\n const names = ['dependencies', 'peerDependencies'].flatMap((key) => {\n const group = AstNode.readField({ node: parsed, key });\n\n return typeof group === 'object' && group !== null ? Object.keys(group) : [];\n });\n\n found = {\n directory,\n name: typeof name === 'string' ? name : undefined,\n dependencies: names.filter((entry) => entry.startsWith(FrameworkExports.SCOPE)),\n };\n } else {\n const parent = dirname(directory);\n found =\n parent === directory ? undefined : FrameworkExports.manifestFor({ directory: parent });\n }\n\n FrameworkExports.manifests.set(directory, found ?? null);\n\n return found;\n }\n\n /** The folder of the installed package `name`, looked up from `directory` upwards. */\n private static locate(opts: { name: string; directory: string }): string | undefined {\n const candidate = join(opts.directory, 'node_modules', opts.name);\n\n if (existsSync(join(candidate, 'package.json'))) {\n return candidate;\n }\n\n const parent = dirname(opts.directory);\n\n return parent === opts.directory\n ? undefined\n : FrameworkExports.locate({ name: opts.name, directory: parent });\n }\n\n /** Every `.d.ts` path an `exports` value names, with the subpath it is reached by. */\n private static entriesOf(opts: { manifest: unknown }): Array<{ subpath: string; file: string }> {\n const { manifest } = opts;\n const exported = AstNode.readField({ node: manifest, key: 'exports' });\n\n const declarations = (value: unknown): Array<string> => {\n if (typeof value === 'string') {\n return /\\.d\\.[cm]?ts$/.test(value) ? [value] : [];\n }\n\n return typeof value === 'object' && value !== null\n ? Object.values(value).flatMap((entry) => declarations(entry))\n : [];\n };\n\n if (typeof exported === 'object' && exported !== null) {\n return Object.entries(exported).flatMap(([key, value]) =>\n declarations(value).map((file) => ({ subpath: key === '.' ? '' : key.slice(1), file })),\n );\n }\n\n const legacy = AstNode.readField({ node: manifest, key: 'types' });\n\n return typeof legacy === 'string' ? [{ subpath: '', file: legacy }] : [];\n }\n\n /** The declaration file a relative specifier points at (`./x.js` is `./x.d.ts`). */\n private static resolveRelative(opts: { from: string; specifier: string }): string | undefined {\n const base = resolve(dirname(opts.from), opts.specifier.replace(/\\.(?:[cm]?js|[cm]?ts)$/, ''));\n\n return [`${base}.d.ts`, `${base}.d.mts`, join(base, 'index.d.ts')].find((file) =>\n existsSync(file),\n );\n }\n\n /**\n * The names `file` exports, each with what it is, following `export *` into relative files and into other `@venizia/*`\n * packages (an umbrella package re-exports its siblings). A name re-exported by `export { X } from` takes the type it has\n * where it is declared; `export type { X }` is a type whatever the target says.\n */\n private static namesOf(opts: {\n typescript: typeof ts;\n file: string;\n seen: Set<string>;\n }): Map<string, TDeclarationType> {\n const { typescript, file, seen } = opts;\n const names = new Map<string, TDeclarationType>();\n const text = FrameworkExports.readText({ file });\n\n if (seen.has(file) || text === undefined) {\n return names;\n }\n\n seen.add(file);\n\n const source = typescript.createSourceFile(file, text, typescript.ScriptTarget.Latest, false);\n const typeOf = (node: ts.Statement): TDeclarationType =>\n typescript.isInterfaceDeclaration(node) || typescript.isTypeAliasDeclaration(node)\n ? 'type'\n : 'value';\n const isExported = (node: ts.Node) =>\n typescript.canHaveModifiers(node) &&\n (typescript.getModifiers(node) ?? []).some(\n (modifier) => modifier.kind === typescript.SyntaxKind.ExportKeyword,\n );\n\n // What the file declares, exported or not: `declare class X {}` then `export { X }` is a value.\n const locals = new Map<string, TDeclarationType>();\n\n for (const statement of source.statements) {\n if (typescript.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n if (typescript.isIdentifier(declaration.name)) {\n locals.set(declaration.name.text, 'value');\n }\n }\n } else if (\n (typescript.isInterfaceDeclaration(statement) ||\n typescript.isTypeAliasDeclaration(statement) ||\n typescript.isClassDeclaration(statement) ||\n typescript.isFunctionDeclaration(statement) ||\n typescript.isEnumDeclaration(statement) ||\n typescript.isModuleDeclaration(statement)) &&\n statement.name &&\n typescript.isIdentifier(statement.name)\n ) {\n // An interface merged with a class or a namespace of the same name has a value too.\n locals.set(\n statement.name.text,\n locals.get(statement.name.text) === 'value' ? 'value' : typeOf(statement),\n );\n }\n }\n\n for (const statement of source.statements) {\n if (typescript.isExportDeclaration(statement)) {\n const clause = statement.exportClause;\n const specifier =\n statement.moduleSpecifier && typescript.isStringLiteral(statement.moduleSpecifier)\n ? statement.moduleSpecifier.text\n : undefined;\n\n if (clause && typescript.isNamedExports(clause)) {\n const remote =\n specifier?.startsWith('.') === true\n ? FrameworkExports.resolveRelative({ from: file, specifier })\n : undefined;\n const there = remote\n ? FrameworkExports.namesOf({ typescript, file: remote, seen: new Set(seen) })\n : undefined;\n\n for (const element of clause.elements) {\n const original = (element.propertyName ?? element.name).text;\n const declared: TDeclarationType | undefined =\n statement.isTypeOnly || element.isTypeOnly\n ? 'type'\n : specifier === undefined\n ? locals.get(original)\n : there?.get(original);\n\n if (declared !== undefined) {\n names.set(element.name.text, declared);\n }\n }\n } else if (!clause && specifier?.startsWith('.') === true) {\n const target = FrameworkExports.resolveRelative({ from: file, specifier });\n\n if (target) {\n for (const [name, declared] of FrameworkExports.namesOf({\n typescript,\n file: target,\n seen,\n })) {\n names.set(name, declared);\n }\n }\n } else if (!clause && specifier?.startsWith(FrameworkExports.SCOPE) === true) {\n const sibling = FrameworkExports.locate({ name: specifier, directory: dirname(file) });\n\n if (sibling) {\n for (const name of FrameworkExports.readPackage({ directory: sibling }).keys()) {\n names.set(name, 'type');\n }\n }\n }\n\n continue;\n }\n\n if (!isExported(statement)) {\n continue;\n }\n\n if (typescript.isVariableStatement(statement)) {\n for (const declaration of statement.declarationList.declarations) {\n if (typescript.isIdentifier(declaration.name)) {\n names.set(declaration.name.text, 'value');\n }\n }\n } else if (\n (typescript.isInterfaceDeclaration(statement) ||\n typescript.isTypeAliasDeclaration(statement) ||\n typescript.isClassDeclaration(statement) ||\n typescript.isFunctionDeclaration(statement) ||\n typescript.isEnumDeclaration(statement) ||\n typescript.isModuleDeclaration(statement)) &&\n statement.name &&\n typescript.isIdentifier(statement.name)\n ) {\n names.set(statement.name.text, locals.get(statement.name.text) ?? typeOf(statement));\n }\n }\n\n return names;\n }\n\n /** Type name to the specifier that exports it (`@venizia/ignis-helpers/common`), for one installed package. */\n private static readPackage(opts: { directory: string }): Map<string, string> {\n const { directory } = opts;\n const cached = FrameworkExports.packages.get(directory);\n\n if (cached) {\n return cached;\n }\n\n const exported = new Map<string, string>();\n FrameworkExports.packages.set(directory, exported);\n\n const typescript = FrameworkExports.loadTypeScript({ directory });\n const manifest = FrameworkExports.readJson({ file: join(directory, 'package.json') });\n const name = AstNode.readField({ node: manifest, key: 'name' });\n\n if (!typescript || typeof name !== 'string') {\n return exported;\n }\n\n // A name reachable from several entries is imported from the narrowest one: `/common` over the root that re-exports it.\n const sizes = new Map<string, number>();\n\n for (const { subpath, file } of FrameworkExports.entriesOf({ manifest })) {\n const path = resolve(directory, file);\n\n if (!existsSync(path)) {\n continue;\n }\n\n const declared = FrameworkExports.namesOf({ typescript, file: path, seen: new Set() });\n const types = [...declared].filter(([, type]) => type === 'type').map(([entry]) => entry);\n\n for (const entry of types) {\n if (types.length < (sizes.get(entry) ?? Number.POSITIVE_INFINITY)) {\n sizes.set(entry, types.length);\n exported.set(entry, `${name}${subpath}`);\n }\n }\n }\n\n return exported;\n }\n\n /**\n * The type names the `@venizia/*` packages that `directory`'s project depends on export, each with the specifier to import\n * it from. The project's own package is left out: it may declare what it exports.\n */\n static of(opts: { directory: string }): Map<string, string> {\n const manifest = FrameworkExports.manifestFor({ directory: opts.directory });\n const all = new Map<string, string>();\n\n if (!manifest) {\n return all;\n }\n\n for (const dependency of manifest.dependencies) {\n const installed = FrameworkExports.locate({\n name: dependency,\n directory: manifest.directory,\n });\n\n if (!installed || dependency === manifest.name) {\n continue;\n }\n\n for (const [name, specifier] of FrameworkExports.readPackage({ directory: installed })) {\n if (!all.has(name)) {\n all.set(name, specifier);\n }\n }\n }\n\n return all;\n }\n}\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
/** Adds the import a rule's autofix needs, once, and not at all when the name is already in scope. */
|
|
3
|
+
export declare class ImportSupport {
|
|
4
|
+
/** The top-level declaration types that bring a name into the file. */
|
|
5
|
+
private static readonly DECLARATIONS;
|
|
6
|
+
/** The name a top-level statement declares, whether or not it is exported. */
|
|
7
|
+
private static declaredName;
|
|
8
|
+
/** Whether the file imports `name`. */
|
|
9
|
+
static isImported(opts: {
|
|
10
|
+
context: Rule.RuleContext;
|
|
11
|
+
name: string;
|
|
12
|
+
}): boolean;
|
|
13
|
+
/** Whether the file declares `name` itself at the top level (a copy or a stand-in, not an import). */
|
|
14
|
+
static isDeclared(opts: {
|
|
15
|
+
context: Rule.RuleContext;
|
|
16
|
+
name: string;
|
|
17
|
+
}): boolean;
|
|
18
|
+
/** The name the file binds the import `name` to (`TNullable as N` answers `N`), or `undefined` when it does not import it. */
|
|
19
|
+
static importedAs(opts: {
|
|
20
|
+
context: Rule.RuleContext;
|
|
21
|
+
name: string;
|
|
22
|
+
asValue?: boolean;
|
|
23
|
+
}): string | undefined;
|
|
24
|
+
/** Whether `name` is imported (under its own name or an alias) or declared at the top level of the file. */
|
|
25
|
+
static isInScope(opts: {
|
|
26
|
+
context: Rule.RuleContext;
|
|
27
|
+
name: string;
|
|
28
|
+
}): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether an import can be added to this file: it is an ES module (it has an import or an export) and not a declaration
|
|
31
|
+
* file. An import added to a script, or to an ambient `.d.ts`, would turn it into a module and change what it declares.
|
|
32
|
+
*/
|
|
33
|
+
static canAdd(opts: {
|
|
34
|
+
context: Rule.RuleContext;
|
|
35
|
+
}): boolean;
|
|
36
|
+
/** The statement the new import goes before when the file has no import: the first one after the leading directives (`'use client'`). */
|
|
37
|
+
private static firstAfterDirectives;
|
|
38
|
+
/**
|
|
39
|
+
* The fixes that import `name` from `source`: after the last import, or before the first statement that is not a
|
|
40
|
+
* directive. None when the name is already in scope; `undefined` when an import cannot be added to this file.
|
|
41
|
+
*/
|
|
42
|
+
static ensure(opts: {
|
|
43
|
+
context: Rule.RuleContext;
|
|
44
|
+
fixer: Rule.RuleFixer;
|
|
45
|
+
name: string;
|
|
46
|
+
source: string;
|
|
47
|
+
isType: boolean;
|
|
48
|
+
}): Array<Rule.Fix> | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* The fix that adds `name` to an import the file already has from `source`, when that import is a plain named list: a
|
|
51
|
+
* second `import { ... } from 'same-module'` line is what `no-duplicate-imports` reports. A type goes into an
|
|
52
|
+
* `import type` list as it is, and into a value list as `type Name`; a value only goes into a value list.
|
|
53
|
+
*/
|
|
54
|
+
private static mergeInto;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=import-support.d.ts.map
|