eslint-plugin-fast-import 1.0.0-beta2
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/.prettierrc.json +6 -0
- package/.vscode/launch.json +39 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/module/computeAnalyzedInfo.d.ts +3 -0
- package/dist/module/computeAnalyzedInfo.js +297 -0
- package/dist/module/computeAnalyzedInfo.js.map +1 -0
- package/dist/module/computeBaseInfo.d.ts +24 -0
- package/dist/module/computeBaseInfo.js +564 -0
- package/dist/module/computeBaseInfo.js.map +1 -0
- package/dist/module/computeResolvedInfo.d.ts +7 -0
- package/dist/module/computeResolvedInfo.js +361 -0
- package/dist/module/computeResolvedInfo.js.map +1 -0
- package/dist/module/module.d.ts +20 -0
- package/dist/module/module.js +224 -0
- package/dist/module/module.js.map +1 -0
- package/dist/module/util.d.ts +44 -0
- package/dist/module/util.js +67 -0
- package/dist/module/util.js.map +1 -0
- package/dist/plugin.d.ts +19 -0
- package/dist/plugin.js +57 -0
- package/dist/plugin.js.map +1 -0
- package/dist/rules/circular/circular.d.ts +2 -0
- package/dist/rules/circular/circular.js +107 -0
- package/dist/rules/circular/circular.js.map +1 -0
- package/dist/rules/entryPoint/entryPoint.d.ts +1 -0
- package/dist/rules/entryPoint/entryPoint.js +38 -0
- package/dist/rules/entryPoint/entryPoint.js.map +1 -0
- package/dist/rules/externalBarrelReexports/externalBarrelReexports.d.ts +1 -0
- package/dist/rules/externalBarrelReexports/externalBarrelReexports.js +41 -0
- package/dist/rules/externalBarrelReexports/externalBarrelReexports.js.map +1 -0
- package/dist/rules/missing/missing.d.ts +1 -0
- package/dist/rules/missing/missing.js +59 -0
- package/dist/rules/missing/missing.js.map +1 -0
- package/dist/rules/testInProd/testInProd.d.ts +1 -0
- package/dist/rules/testInProd/testInProd.js +42 -0
- package/dist/rules/testInProd/testInProd.js.map +1 -0
- package/dist/rules/unused/unused.d.ts +3 -0
- package/dist/rules/unused/unused.js +77 -0
- package/dist/rules/unused/unused.js.map +1 -0
- package/dist/rules/util.d.ts +11 -0
- package/dist/rules/util.js +107 -0
- package/dist/rules/util.js.map +1 -0
- package/dist/settings/settings.d.ts +12 -0
- package/dist/settings/settings.js +123 -0
- package/dist/settings/settings.js.map +1 -0
- package/dist/settings/typescript.d.ts +3 -0
- package/dist/settings/typescript.js +39 -0
- package/dist/settings/typescript.js.map +1 -0
- package/dist/settings/user.d.ts +45 -0
- package/dist/settings/user.js +52 -0
- package/dist/settings/user.js.map +1 -0
- package/dist/settings/util.d.ts +2 -0
- package/dist/settings/util.js +33 -0
- package/dist/settings/util.js.map +1 -0
- package/dist/types/analyzed.d.ts +120 -0
- package/dist/types/analyzed.js +2 -0
- package/dist/types/analyzed.js.map +1 -0
- package/dist/types/base.d.ts +230 -0
- package/dist/types/base.js +2 -0
- package/dist/types/base.js.map +1 -0
- package/dist/types/context.d.ts +2 -0
- package/dist/types/context.js +2 -0
- package/dist/types/context.js.map +1 -0
- package/dist/types/resolved.d.ts +60 -0
- package/dist/types/resolved.js +2 -0
- package/dist/types/resolved.js.map +1 -0
- package/dist/util/code.d.ts +1 -0
- package/dist/util/code.js +6 -0
- package/dist/util/code.js.map +1 -0
- package/dist/util/error.d.ts +14 -0
- package/dist/util/error.js +19 -0
- package/dist/util/error.js.map +1 -0
- package/dist/util/files.d.ts +10 -0
- package/dist/util/files.js +122 -0
- package/dist/util/files.js.map +1 -0
- package/dist/util/logging.d.ts +5 -0
- package/dist/util/logging.js +19 -0
- package/dist/util/logging.js.map +1 -0
- package/eslint.config.mjs +85 -0
- package/jest.config.ts +10 -0
- package/package.json +49 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
import { getFiles, isFileIgnored } from '../util/files.js';
|
|
3
|
+
import { getSettings } from '../settings/settings.js';
|
|
4
|
+
import { getProjectInfo, initializeProject, updateCacheForFile, updateCacheFromFileSystem, } from '../module/module.js';
|
|
5
|
+
export const createRule = ESLintUtils.RuleCreator((name) => `https://github.com/nebrius/esm-utils/tree/main/src/rules/${name}/README.md`);
|
|
6
|
+
const updateListeners = new Set();
|
|
7
|
+
export function registerUpdateListener(cb) {
|
|
8
|
+
updateListeners.add(cb);
|
|
9
|
+
}
|
|
10
|
+
export function getESMInfo(context) {
|
|
11
|
+
const settings = getSettings(context);
|
|
12
|
+
initializeProject(settings);
|
|
13
|
+
// We have to call initializeProject first before we can check if this file
|
|
14
|
+
// is ignored, because initializeProject initializes the ignore cache
|
|
15
|
+
if (isFileIgnored(settings.rootDir, context.filename)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
// If we're not in one-shot mode, update the cache, and if there were changes
|
|
19
|
+
// call any esm change subscribers
|
|
20
|
+
if (settings.mode !== 'one-shot' &&
|
|
21
|
+
updateCacheForFile(context.filename, context.sourceCode.getText(), context.sourceCode.ast, settings)) {
|
|
22
|
+
for (const updateListener of updateListeners) {
|
|
23
|
+
updateListener();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const projectInfo = getProjectInfo();
|
|
27
|
+
// Initialize file watching if we're in editor mode
|
|
28
|
+
if (settings.mode === 'editor') {
|
|
29
|
+
void initializeFileWatching(settings);
|
|
30
|
+
}
|
|
31
|
+
// Format and return the ESM info
|
|
32
|
+
const fileInfo = projectInfo.files.get(context.filename);
|
|
33
|
+
if (!fileInfo) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
fileInfo,
|
|
38
|
+
projectInfo,
|
|
39
|
+
settings,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
let fileWatchingInitialized = false;
|
|
43
|
+
async function initializeFileWatching(settings) {
|
|
44
|
+
if (fileWatchingInitialized) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
fileWatchingInitialized = true;
|
|
48
|
+
async function getUpdatedAtTimes() {
|
|
49
|
+
const projectInfo = getProjectInfo();
|
|
50
|
+
const files = await getFiles(projectInfo.rootDir, settings.ignorePatterns);
|
|
51
|
+
return new Map(files.map(({ filePath, latestUpdatedAt }) => [filePath, latestUpdatedAt]));
|
|
52
|
+
}
|
|
53
|
+
let updatedAtTimes = await getUpdatedAtTimes();
|
|
54
|
+
async function refresh() {
|
|
55
|
+
try {
|
|
56
|
+
const start = Date.now();
|
|
57
|
+
const latestUpdatedTimes = await getUpdatedAtTimes();
|
|
58
|
+
// First, find files that were deleted, represented by entries that are in
|
|
59
|
+
// the previous list of modified times but are not in the new list
|
|
60
|
+
const deleted = [];
|
|
61
|
+
for (const [filePath] of updatedAtTimes) {
|
|
62
|
+
if (!latestUpdatedTimes.has(filePath)) {
|
|
63
|
+
deleted.push(filePath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Now, find files that were added, represented by entries that are in
|
|
67
|
+
// the new list of modified times but are not in the previous list
|
|
68
|
+
const added = [];
|
|
69
|
+
for (const [filePath, latestUpdatedAt] of latestUpdatedTimes) {
|
|
70
|
+
if (!updatedAtTimes.has(filePath)) {
|
|
71
|
+
added.push({ filePath, latestUpdatedAt });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Finally, find files that were modified, represented by entries that are
|
|
75
|
+
// in both the previous and new list of modified times but have different
|
|
76
|
+
// last modified at times
|
|
77
|
+
const modified = [];
|
|
78
|
+
for (const [filePath, latestUpdatedAt] of latestUpdatedTimes) {
|
|
79
|
+
if (updatedAtTimes.has(filePath) &&
|
|
80
|
+
updatedAtTimes.get(filePath) !== latestUpdatedAt) {
|
|
81
|
+
modified.push({ filePath, latestUpdatedAt });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Update the cache
|
|
85
|
+
if (updateCacheFromFileSystem({ added, deleted, modified }, settings, start)) {
|
|
86
|
+
for (const updateListener of updateListeners) {
|
|
87
|
+
updateListener();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Set up for the next refresh
|
|
91
|
+
updatedAtTimes = latestUpdatedTimes;
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
setTimeout(() => void refresh(), settings.editorUpdateRate);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
setTimeout(() => void refresh(), settings.editorUpdateRate);
|
|
98
|
+
}
|
|
99
|
+
export function isNonTestFile(filePath, rootDir) {
|
|
100
|
+
// We want to ignore folders named __test__ outside of this project, in case
|
|
101
|
+
// the entire project is itself a test (e.g. the unit tests for fast-import)
|
|
102
|
+
const relativeFilePath = filePath.replace(`${rootDir}/`, '');
|
|
103
|
+
return (!relativeFilePath.includes('.test.') &&
|
|
104
|
+
!relativeFilePath.includes('__test__') &&
|
|
105
|
+
!relativeFilePath.includes('__tests__'));
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/rules/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC,WAAW,CAC/C,CAAC,IAAI,EAAE,EAAE,CACP,4DAA4D,IAAI,YAAY,CAC/E,CAAC;AAEF,MAAM,eAAe,GAAG,IAAI,GAAG,EAAc,CAAC;AAC9C,MAAM,UAAU,sBAAsB,CAAC,EAAc;IACnD,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAAuB;IAChD,MAAM,QAAQ,GAAG,W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CAAC,KAAK,eAAe,EAChD,CAAC;oBACD,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;YAED,mBAAmB;YACnB,IACE,yBAAyB,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,EACxE,CAAC;gBACD,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;oBAC7C,cAAc,EAAE,CAAC;gBACnB,CAAC;YACH,CAAC;YAED,8BAA8B;YAC9B,cAAc,GAAG,kBAAkB,CAAC;QACtC,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,EAAE,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,EAAE,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,OAAe;IAC7D,4EAA4E;IAC5E,4EAA4E;IAC5E,MAAM,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,EAAE,EAAE,CAAC,CAAC;IAC7D,OAAO,CACL,CAAC,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACpC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,UAAU,CAAC;QACtC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,WAAW,CAAC,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RequiredDeep } from 'type-fest';
|
|
2
|
+
import type { GenericContext } from '../types/context.js';
|
|
3
|
+
import { type Settings } from './user.js';
|
|
4
|
+
export type IgnorePattern = {
|
|
5
|
+
dir: string;
|
|
6
|
+
contents: string;
|
|
7
|
+
};
|
|
8
|
+
export type ParsedSettings = Omit<RequiredDeep<Settings>, 'ignorePatterns'> & {
|
|
9
|
+
ignorePatterns: IgnorePattern[];
|
|
10
|
+
};
|
|
11
|
+
export declare function _resetSettings(): void;
|
|
12
|
+
export declare function getSettings(context: GenericContext): ParsedSettings;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { getTypeScriptSettings } from './typescript.js';
|
|
2
|
+
import { debug, error } from '../util/logging.js';
|
|
3
|
+
import { isAbsolute, join, resolve, sep } from 'node:path';
|
|
4
|
+
import { getUserSettings } from './user.js';
|
|
5
|
+
import { getEslintConfigDir } from './util.js';
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
function argsInclude(strs) {
|
|
8
|
+
for (const str of strs) {
|
|
9
|
+
if (process.argv.some((arg) => arg.includes(str))) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const DEFAULT_MODE = process.argv[0].includes('Visual Studio Code')
|
|
16
|
+
? 'editor'
|
|
17
|
+
: argsInclude(['--fix', '--fix-dry-run', '--fix-type'])
|
|
18
|
+
? 'fix'
|
|
19
|
+
: 'one-shot';
|
|
20
|
+
let settings = null;
|
|
21
|
+
// We need to reset settings between runs, since some tests try different settings
|
|
22
|
+
// eslint-disable-next-line fast-import/no-unused-exports
|
|
23
|
+
export function _resetSettings() {
|
|
24
|
+
settings = null;
|
|
25
|
+
}
|
|
26
|
+
export function getSettings(context) {
|
|
27
|
+
// Return the cached copy if we have it
|
|
28
|
+
if (settings) {
|
|
29
|
+
return settings;
|
|
30
|
+
}
|
|
31
|
+
const eslintConfigDir = getEslintConfigDir(context);
|
|
32
|
+
// Get TypeScript supplied settings
|
|
33
|
+
const typeScriptSettings = getTypeScriptSettings(context);
|
|
34
|
+
const userSettings = getUserSettings(context);
|
|
35
|
+
const mergedSettings = {
|
|
36
|
+
...typeScriptSettings,
|
|
37
|
+
...userSettings,
|
|
38
|
+
};
|
|
39
|
+
let { rootDir } = mergedSettings;
|
|
40
|
+
const { alias = {}, entryPoints = [] } = mergedSettings;
|
|
41
|
+
// If we don't have rootDir yet, default to setting it to the ESLint config
|
|
42
|
+
// file directory. If we do have it but it's a relative path, make it absolute
|
|
43
|
+
// by joining+resolving with the ESLint config file directory.
|
|
44
|
+
if (!rootDir || !isAbsolute(rootDir)) {
|
|
45
|
+
const eslintConfigDir = getEslintConfigDir(context);
|
|
46
|
+
if (!rootDir) {
|
|
47
|
+
rootDir = eslintConfigDir;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
rootDir = resolve(join(eslintConfigDir, rootDir));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Make sure we could find a rootDir
|
|
54
|
+
if (!rootDir) {
|
|
55
|
+
error(`Could not determine rootDir. Please add it to fast-import settings. See https://github.com/nebrius/fast-import for details`);
|
|
56
|
+
process.exit(-1);
|
|
57
|
+
}
|
|
58
|
+
// Clean up any aliases
|
|
59
|
+
const parsedAlias = {};
|
|
60
|
+
for (let [symbol, path] of Object.entries(alias)) {
|
|
61
|
+
if (symbol.endsWith('/')) {
|
|
62
|
+
symbol = symbol.slice(0, -1);
|
|
63
|
+
}
|
|
64
|
+
if (!isAbsolute(path)) {
|
|
65
|
+
path = resolve(join(getEslintConfigDir(context), path));
|
|
66
|
+
}
|
|
67
|
+
path = resolve(join(rootDir, path));
|
|
68
|
+
parsedAlias[symbol] = path;
|
|
69
|
+
}
|
|
70
|
+
// Clean up any entry points
|
|
71
|
+
const parsedEntryPoints = [];
|
|
72
|
+
for (let { symbol, file } of entryPoints) {
|
|
73
|
+
if (symbol.endsWith('/')) {
|
|
74
|
+
symbol = symbol.slice(0, -1);
|
|
75
|
+
}
|
|
76
|
+
if (isAbsolute(file)) {
|
|
77
|
+
error(`Invalid entry point file "${file}". Entry point files must be relative to rootDir, not absolute`);
|
|
78
|
+
process.exit(-1);
|
|
79
|
+
}
|
|
80
|
+
file = resolve(join(rootDir, file));
|
|
81
|
+
if (!existsSync(file)) {
|
|
82
|
+
error(`Entry point file "${file}" does not exist`);
|
|
83
|
+
process.exit(-1);
|
|
84
|
+
}
|
|
85
|
+
parsedEntryPoints.push({
|
|
86
|
+
file,
|
|
87
|
+
symbol,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
const mode = mergedSettings.mode !== 'auto' && mergedSettings.mode !== undefined
|
|
91
|
+
? mergedSettings.mode
|
|
92
|
+
: DEFAULT_MODE;
|
|
93
|
+
debug(`Running in ${mode} mode`);
|
|
94
|
+
debug(`Setting root dir to ${rootDir}`);
|
|
95
|
+
if (!Object.keys(parsedAlias).length) {
|
|
96
|
+
debug(`No aliases defined`);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
debug(`Aliases:`);
|
|
100
|
+
for (const [symbol, path] of Object.entries(parsedAlias)) {
|
|
101
|
+
debug(` ${symbol}: ${path}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
debug(`Entry points:`);
|
|
105
|
+
for (const { file, symbol } of parsedEntryPoints) {
|
|
106
|
+
debug(` ${file.replace(eslintConfigDir + sep, '')}: ${symbol}`);
|
|
107
|
+
}
|
|
108
|
+
const ignorePatterns = (mergedSettings.ignorePatterns ?? []).map((p) => ({
|
|
109
|
+
dir: eslintConfigDir,
|
|
110
|
+
contents: `${eslintConfigDir}/${p}`,
|
|
111
|
+
}));
|
|
112
|
+
// Apply defaults and save to the settings cache
|
|
113
|
+
settings = {
|
|
114
|
+
rootDir,
|
|
115
|
+
alias: parsedAlias,
|
|
116
|
+
entryPoints: parsedEntryPoints,
|
|
117
|
+
ignorePatterns,
|
|
118
|
+
editorUpdateRate: mergedSettings.editorUpdateRate ?? 5_000,
|
|
119
|
+
mode,
|
|
120
|
+
};
|
|
121
|
+
return settings;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=settings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings.js","s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KAAK,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,MAAM,EAAE,CAAC;QACrC,KAAK,CAAC,oBAAoB,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,UAAU,CAAC,CAAC;QAClB,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YACzD,KAAK,CAAC,KAAK,MAAM,KAAK,IAAI,EAAE,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,KAAK,CAAC,eAAe,CAAC,CAAC;IACvB,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,iBAAiB,EAAE,CAAC;QACjD,KAAK,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,eAAe,GAAG,GAAG,EAAE,EAAE,CAAC,KAAK,MAAM,EAAE,CAAC,CAAC;IACnE,CAAC;IAED,MAAM,cAAc,GAAG,CAAC,cAAc,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACvE,GAAG,EAAE,eAAe;QACpB,QAAQ,EAAE,GAAG,eAAe,IAAI,CAAC,EAAE;KACpC,CAAC,CAAC,CAAC;IAEJ,gDAAgD;IAChD,QAAQ,GAAG;QACT,OAAO;QACP,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,iBAAiB;QAC9B,cAAc;QACd,gBAAgB,EAAE,cAAc,CAAC,gBAAgB,IAAI,KAAK;QAC1D,IAAI;KACL,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { warn } from '../util/logging.js';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
export function getTypeScriptSettings(context) {
|
|
6
|
+
// Read in the file
|
|
7
|
+
const configPath = ts.findConfigFile(dirname(context.filename), ts.sys.fileExists.bind(ts.sys), 'tsconfig.json');
|
|
8
|
+
if (!configPath) {
|
|
9
|
+
return {};
|
|
10
|
+
}
|
|
11
|
+
const config = ts.readConfigFile(configPath, (file) => readFileSync(file, 'utf-8'));
|
|
12
|
+
// Handle errors in reading the file
|
|
13
|
+
if (config.error) {
|
|
14
|
+
// Technically there could be multiple errors in a chain, but we pretend as
|
|
15
|
+
// if there's only one, since users will have other, more detailed errors in
|
|
16
|
+
// their editor
|
|
17
|
+
const errorText = typeof config.error.messageText === 'string'
|
|
18
|
+
? config.error.messageText
|
|
19
|
+
: config.error.messageText.messageText;
|
|
20
|
+
warn(`Could not load TypeScript config, skipping settings analysis:\n ${errorText}`);
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
// I'm pretty sure this is impossible since we already checked error above,
|
|
24
|
+
// and the TS types for config are just too loose, but check just in case
|
|
25
|
+
if (!config.config) {
|
|
26
|
+
warn(`Could not load TypeScript config, skipping settings analysis:\n empty config`);
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
30
|
+
const rootDir = config.config?.compilerOptions?.rootDir;
|
|
31
|
+
const absoluteRootDir = rootDir
|
|
32
|
+
? join(dirname(configPath), rootDir)
|
|
33
|
+
: undefined;
|
|
34
|
+
// TODO: read in `paths` property and resolve here
|
|
35
|
+
// Fallback to the directory containing tsconfig.json if rootDir isn't
|
|
36
|
+
// supplied (like TypeScript itself does)
|
|
37
|
+
return { rootDir: absoluteRootDir ?? dirname(configPath) };
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=typescript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.js","sourceRoot":"","sources":["../../src/settings/typescript.ts"],"names":[],"mappings":"AAAA,OAAO,E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E,OAA6B,CAAC;IAC9E,MAAM,eAAe,GAAG,OAAO;QAC7B,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QACpC,CAAC,CAAC,SAAS,CAAC;IAEd,kDAAkD;IAElD,sEAAsE;IACtE,yCAAyC;IACzC,OAAO,EAAE,OAAO,EAAE,eAAe,IAAI,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { GenericContext } from '../types/context.js';
|
|
3
|
+
declare const settingsSchema: z.ZodObject<{
|
|
4
|
+
rootDir: z.ZodOptional<z.ZodString>;
|
|
5
|
+
alias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
6
|
+
entryPoints: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
7
|
+
file: z.ZodString;
|
|
8
|
+
symbol: z.ZodString;
|
|
9
|
+
}, "strict", z.ZodTypeAny, {
|
|
10
|
+
symbol: string;
|
|
11
|
+
file: string;
|
|
12
|
+
}, {
|
|
13
|
+
symbol: string;
|
|
14
|
+
file: string;
|
|
15
|
+
}>, "many">>;
|
|
16
|
+
ignorePatterns: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
17
|
+
mode: z.ZodOptional<z.ZodEnum<["auto", "one-shot", "fix", "editor"]>>;
|
|
18
|
+
editorUpdateRate: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
debugLogging: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
}, "strict", z.ZodTypeAny, {
|
|
21
|
+
rootDir?: string | undefined;
|
|
22
|
+
alias?: Record<string, string> | undefined;
|
|
23
|
+
entryPoints?: {
|
|
24
|
+
symbol: string;
|
|
25
|
+
file: string;
|
|
26
|
+
}[] | undefined;
|
|
27
|
+
ignorePatterns?: string[] | undefined;
|
|
28
|
+
mode?: "auto" | "one-shot" | "fix" | "editor" | undefined;
|
|
29
|
+
editorUpdateRate?: number | undefined;
|
|
30
|
+
debugLogging?: boolean | undefined;
|
|
31
|
+
}, {
|
|
32
|
+
rootDir?: string | undefined;
|
|
33
|
+
alias?: Record<string, string> | undefined;
|
|
34
|
+
entryPoints?: {
|
|
35
|
+
symbol: string;
|
|
36
|
+
file: string;
|
|
37
|
+
}[] | undefined;
|
|
38
|
+
ignorePatterns?: string[] | undefined;
|
|
39
|
+
mode?: "auto" | "one-shot" | "fix" | "editor" | undefined;
|
|
40
|
+
editorUpdateRate?: number | undefined;
|
|
41
|
+
debugLogging?: boolean | undefined;
|
|
42
|
+
}>;
|
|
43
|
+
export type Settings = Omit<z.infer<typeof settingsSchema>, 'debugLogging'>;
|
|
44
|
+
export declare function getUserSettings(context: GenericContext): Settings;
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { error, setVerbose } from '../util/logging.js';
|
|
3
|
+
const settingsSchema = z.strictObject({
|
|
4
|
+
rootDir: z.string().optional(),
|
|
5
|
+
alias: z.record(z.string(), z.string()).optional(),
|
|
6
|
+
entryPoints: z
|
|
7
|
+
.array(z.strictObject({
|
|
8
|
+
file: z.string(),
|
|
9
|
+
symbol: z.string(),
|
|
10
|
+
}))
|
|
11
|
+
.optional(),
|
|
12
|
+
ignorePatterns: z.array(z.string()).optional(),
|
|
13
|
+
mode: z.enum(['auto', 'one-shot', 'fix', 'editor']).optional(),
|
|
14
|
+
editorUpdateRate: z.number().optional(),
|
|
15
|
+
debugLogging: z.boolean().optional(),
|
|
16
|
+
});
|
|
17
|
+
export function getUserSettings(context) {
|
|
18
|
+
// Parse the raw settings, if supplied
|
|
19
|
+
const fastEsmSettings = context.settings['fast-import'];
|
|
20
|
+
const parseResult = settingsSchema.safeParse(fastEsmSettings);
|
|
21
|
+
// If there were errors, print a friendly-ish explanation of them
|
|
22
|
+
if (!parseResult.success) {
|
|
23
|
+
const issues = [];
|
|
24
|
+
for (const issue of parseResult.error.issues) {
|
|
25
|
+
let formattedIssue = issue.code.replace('_', ' ');
|
|
26
|
+
formattedIssue = ` ${formattedIssue[0].toUpperCase() + formattedIssue.slice(1)}`;
|
|
27
|
+
if (issue.path.length) {
|
|
28
|
+
formattedIssue += ` for property "${issue.path.join('.')}"\n`;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
formattedIssue += '\n';
|
|
32
|
+
}
|
|
33
|
+
for (const [key, value] of Object.entries(issue)) {
|
|
34
|
+
if (key !== 'code' && key !== 'path') {
|
|
35
|
+
formattedIssue += ` ${key}: ${String(value)}\n`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
issues.push(formattedIssue);
|
|
39
|
+
}
|
|
40
|
+
error('Invalid settings:\n' + issues.join('\n'));
|
|
41
|
+
process.exit(-1);
|
|
42
|
+
}
|
|
43
|
+
// Trim off the end `/` in case it was supplied with rootDir
|
|
44
|
+
if (parseResult.data.rootDir?.endsWith('/')) {
|
|
45
|
+
parseResult.data.rootDir = parseResult.data.rootDir.substring(0, parseResult.data.rootDir.length - 1);
|
|
46
|
+
}
|
|
47
|
+
// Set verbose logging, if enabled
|
|
48
|
+
setVerbose(!!parseResult.data.debugLogging);
|
|
49
|
+
// Get user supplied settings
|
|
50
|
+
return parseResult.data;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/settings/user.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,cAAc,GAAG,CAAC,CAAC,YAAY,CAAC;IACpC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,C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CAAC;gBACtB,cAAc,IAAI,kBAAkB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;YAChE,CAAC;iBAAM,CAAC;gBACN,cAAc,IAAI,IAAI,CAAC;YACzB,CAAC;YACD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;oBACrC,cAAc,IAAI,OAAO,GAAG,KAAK,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;gBACrD,CAAC;YACH,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC9B,CAAC;QACD,KAAK,CAAC,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACjD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;IAED,4DAA4D;IAC5D,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5C,WAAW,CAAC,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAC3D,CAAC,EACD,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CACpC,CAAC;IACJ,CAAC;IAED,kCAAkC;IAClC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAE5C,6BAA6B;IAC7B,OAAO,WAAW,CAAC,IAAI,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { dirname, join, resolve } from 'node:path';
|
|
2
|
+
import { readdirSync } from 'node:fs';
|
|
3
|
+
import { error } from '../util/logging.js';
|
|
4
|
+
let eslintConfigDir;
|
|
5
|
+
export function getEslintConfigDir(context) {
|
|
6
|
+
if (typeof eslintConfigDir !== 'undefined') {
|
|
7
|
+
return eslintConfigDir;
|
|
8
|
+
}
|
|
9
|
+
let currentDir = dirname(context.filename);
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
11
|
+
while (true) {
|
|
12
|
+
const dirContents = readdirSync(currentDir);
|
|
13
|
+
if (dirContents.includes('eslint.config.js') ||
|
|
14
|
+
dirContents.includes('eslint.config.mjs') ||
|
|
15
|
+
dirContents.includes('eslint.config.cjs') ||
|
|
16
|
+
dirContents.includes('eslint.config.ts') ||
|
|
17
|
+
dirContents.includes('eslint.config.mjs') ||
|
|
18
|
+
dirContents.includes('eslint.config.mts') ||
|
|
19
|
+
dirContents.includes('eslint.config.cts')) {
|
|
20
|
+
eslintConfigDir = currentDir;
|
|
21
|
+
return eslintConfigDir;
|
|
22
|
+
}
|
|
23
|
+
// Move up a level
|
|
24
|
+
const nextPath = resolve(join(currentDir, '..'));
|
|
25
|
+
if (currentDir === nextPath) {
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
currentDir = nextPath;
|
|
29
|
+
}
|
|
30
|
+
error('Could not find flat ESLint config file. This library is only designed to work with ESLint 9+');
|
|
31
|
+
process.exit(-1);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/settings/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,IAAI,eAAmC,CAAC;AACxC,MAAM,UAAU,kBAAkB,CAAC,OAAuB;IACxD,IAAI,OAAO,eAAe,KAAK,WAAW,EAAE,CAAC;QAC3C,OAAO,eAAe,CAAC;IACzB,CAAC;IACD,IAAI,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC3C,uEAAuE;IACvE,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;QAC5C,IACE,WAAW,CAAC,QAAQ,CAAC,kBAAkB,CAAC;YACxC,WAAW,CAAC,QAAQ,CAAC,mBAAmB,CAAC;YACzC,WAAW,CAAC,QAAQ,CAAC,mBAAmB,CAAC;YACzC,WAAW,CAAC,QAAQ,CAAC,kBAAkB,CAAC;YACxC,WAAW,CAAC,QAAQ,CAAC,mBAAmB,CAAC;YACzC,WAAW,CAAC,QAAQ,CAAC,mBAAmB,CAAC;YACzC,WAAW,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EACzC,CAAC;YACD,eAAe,GAAG,UAAU,CAAC;YAC7B,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,kBAAkB;QAClB,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;QACjD,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;YAC5B,MAAM;QACR,CAAC;QACD,UAAU,GAAG,QAAQ,CAAC;IACxB,CAAC;IAED,KAAK,CACH,8FAA8F,CAC/F,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import type { ResolvedBarrelImport, ResolvedBarrelReexport, ResolvedDynamicImport, ResolvedExport, ResolvedOtherFileDetails, ResolvedProjectInfo, ResolvedSingleImport, ResolvedSingleReexport } from './resolved.js';
|
|
2
|
+
export type AnalyzedImportBase = {
|
|
3
|
+
/**
|
|
4
|
+
* A rootModuleType of `undefined` indicates we couldn't resolve the root export
|
|
5
|
+
*/
|
|
6
|
+
rootModuleType: undefined;
|
|
7
|
+
} | {
|
|
8
|
+
rootModuleType: 'builtin';
|
|
9
|
+
} | {
|
|
10
|
+
rootModuleType: 'thirdParty';
|
|
11
|
+
} | {
|
|
12
|
+
rootModuleType: 'firstPartyOther';
|
|
13
|
+
/**
|
|
14
|
+
* The absolute path of the root file with the export that the import/reexport statement ultimately resolves to. In other
|
|
15
|
+
* words, if we have:
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* // foo.ts
|
|
19
|
+
* import { baz } from './bar'
|
|
20
|
+
*
|
|
21
|
+
* // bar.ts
|
|
22
|
+
* export { baz } from './baz'
|
|
23
|
+
*
|
|
24
|
+
* // baz.ts
|
|
25
|
+
* export const baz = 10;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* then `rootModulePath` in `foo.ts` is `/path/to/baz.ts`. Contrast this with `resolvedModulePath` which equals
|
|
29
|
+
* `/path/to/bar.ts`.
|
|
30
|
+
*/
|
|
31
|
+
rootModulePath: string;
|
|
32
|
+
} | {
|
|
33
|
+
rootModuleType: 'firstPartyCode';
|
|
34
|
+
/**
|
|
35
|
+
* The absolute path of the root file with the export that the import/reexport statement ultimately resolves to. In other
|
|
36
|
+
* words, if we have:
|
|
37
|
+
*
|
|
38
|
+
* ```
|
|
39
|
+
* // foo.ts
|
|
40
|
+
* import { baz } from './bar'
|
|
41
|
+
*
|
|
42
|
+
* // bar.ts
|
|
43
|
+
* export { baz } from './baz'
|
|
44
|
+
*
|
|
45
|
+
* // baz.ts
|
|
46
|
+
* export const baz = 10;
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* then `rootModulePath` in `foo.ts` is `/path/to/baz.ts`. Contrast this with `resolvedModulePath` which equals
|
|
50
|
+
* `/path/to/bar.ts`.
|
|
51
|
+
*/
|
|
52
|
+
rootModulePath: string;
|
|
53
|
+
/**
|
|
54
|
+
* The name of the original export
|
|
55
|
+
*/
|
|
56
|
+
rootExportName: string;
|
|
57
|
+
/**
|
|
58
|
+
* What is the actual root export type. Sometimes a named import can trace to a named barrel export, in which case
|
|
59
|
+
* we can't actually resolve this to an export since it resolves to potentially many exports across files.
|
|
60
|
+
*
|
|
61
|
+
* When this happens, we set this value to `namedBarrelReexport`, and `rootModulePath` and `rootName` point to the
|
|
62
|
+
* named reexport
|
|
63
|
+
*/
|
|
64
|
+
rootExportType: 'export' | 'namedBarrelReexport';
|
|
65
|
+
};
|
|
66
|
+
type AnalyzedExportBase = {
|
|
67
|
+
/**
|
|
68
|
+
* A list of files that imports this export, including indirect imports that are funneled through reexport statements
|
|
69
|
+
*/
|
|
70
|
+
importedByFiles: string[];
|
|
71
|
+
/**
|
|
72
|
+
* A list of files that barrel imports this export, including indirect imports that are funneled through reexport
|
|
73
|
+
* statements.
|
|
74
|
+
*
|
|
75
|
+
* Note: unlike `importedByFiles`, entries here do not actually guarantee this import is actually used
|
|
76
|
+
*/
|
|
77
|
+
barrelImportedByFiles: string[];
|
|
78
|
+
/**
|
|
79
|
+
* A list of files that reexport this export, including indirect reexports that themselves reexport a reexport
|
|
80
|
+
*/
|
|
81
|
+
reexportedByFiles: string[];
|
|
82
|
+
};
|
|
83
|
+
type AnalyzedReexportBase = {
|
|
84
|
+
/**
|
|
85
|
+
* A list of files that imports this reexport, including indirect imports that are funneled through other reexport
|
|
86
|
+
* statements
|
|
87
|
+
*/
|
|
88
|
+
importedByFiles: string[];
|
|
89
|
+
/**
|
|
90
|
+
* A list of files that barrel imports this export, including indirect imports that are funneled through reexport
|
|
91
|
+
* statements.
|
|
92
|
+
*
|
|
93
|
+
* Note: unlike `importedByFiles`, entries here do not actually guarantee this import is actually used
|
|
94
|
+
*/
|
|
95
|
+
barrelImportedByFiles: string[];
|
|
96
|
+
};
|
|
97
|
+
export type AnalyzedSingleImport = ResolvedSingleImport & AnalyzedImportBase;
|
|
98
|
+
export type AnalyzedBarrelImport = ResolvedBarrelImport;
|
|
99
|
+
export type AnalyzedDynamicImport = ResolvedDynamicImport;
|
|
100
|
+
export type AnalyzedImport = AnalyzedSingleImport | AnalyzedBarrelImport | AnalyzedDynamicImport;
|
|
101
|
+
export type AnalyzedExport = ResolvedExport & AnalyzedExportBase;
|
|
102
|
+
export type AnalyzedSingleReexport = ResolvedSingleReexport & AnalyzedImportBase & AnalyzedReexportBase;
|
|
103
|
+
export type AnalyzedBarrelReexport = ResolvedBarrelReexport & AnalyzedReexportBase;
|
|
104
|
+
export type AnalyzedReexport = AnalyzedSingleReexport | AnalyzedBarrelReexport;
|
|
105
|
+
export type AnalyzedOtherFileDetails = ResolvedOtherFileDetails;
|
|
106
|
+
export type AnalyzedCodeFileDetails = {
|
|
107
|
+
fileType: 'code';
|
|
108
|
+
lastUpdatedAt: number;
|
|
109
|
+
imports: AnalyzedImport[];
|
|
110
|
+
exports: AnalyzedExport[];
|
|
111
|
+
reexports: AnalyzedReexport[];
|
|
112
|
+
};
|
|
113
|
+
type AnalyzedFileDetails = AnalyzedOtherFileDetails | AnalyzedCodeFileDetails;
|
|
114
|
+
export type AnalyzedProjectInfo = Omit<ResolvedProjectInfo, 'files'> & {
|
|
115
|
+
/**
|
|
116
|
+
* Mapping of _absolute_ file paths to file details
|
|
117
|
+
*/
|
|
118
|
+
files: Map<string, AnalyzedFileDetails>;
|
|
119
|
+
};
|
|
120
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyzed.js","sourceRoot":"","sources":["../../src/types/analyzed.ts"],"names":[],"mappings":""}
|