main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

3
node_modules/eslint-config-next/core-web-vitals.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
module.exports = {
extends: [require.resolve('.'), 'plugin:@next/next/core-web-vitals'],
}

132
node_modules/eslint-config-next/index.js generated vendored Normal file
View File

@@ -0,0 +1,132 @@
/*
* @rushstack/eslint-patch is used to include plugins as dev
* dependencies instead of imposing them as peer dependencies
*
* https://www.npmjs.com/package/@rushstack/eslint-patch
*/
const keptPaths = []
const sortedPaths = []
const cwd = process.cwd().replace(/\\/g, '/')
const originalPaths = require.resolve.paths('eslint-plugin-import')
// eslint throws a conflict error when plugins resolve to different
// locations, since we want to lock our dependencies by default
// but also need to allow using user dependencies this updates
// our resolve paths to first check the cwd and iterate to
// eslint-config-next's dependencies if needed
for (let i = originalPaths.length - 1; i >= 0; i--) {
const currentPath = originalPaths[i]
if (currentPath.replace(/\\/g, '/').startsWith(cwd)) {
sortedPaths.push(currentPath)
} else {
keptPaths.unshift(currentPath)
}
}
// maintain order of node_modules outside of cwd
sortedPaths.push(...keptPaths)
const hookPropertyMap = new Map(
[
['eslint-plugin-import', 'eslint-plugin-import'],
['eslint-plugin-react', 'eslint-plugin-react'],
['eslint-plugin-jsx-a11y', 'eslint-plugin-jsx-a11y'],
].map(([request, replacement]) => [
request,
require.resolve(replacement, { paths: sortedPaths }),
])
)
const mod = require('module')
const resolveFilename = mod._resolveFilename
mod._resolveFilename = function (request, parent, isMain, options) {
const hookResolved = hookPropertyMap.get(request)
if (hookResolved) {
request = hookResolved
}
return resolveFilename.call(mod, request, parent, isMain, options)
}
require('@rushstack/eslint-patch/modern-module-resolution')
module.exports = {
extends: [
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:@next/next/recommended',
],
plugins: ['import', 'react', 'jsx-a11y'],
rules: {
'import/no-anonymous-default-export': 'warn',
'react/no-unknown-property': 'off',
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
'jsx-a11y/alt-text': [
'warn',
{
elements: ['img'],
img: ['Image'],
},
],
'jsx-a11y/aria-props': 'warn',
'jsx-a11y/aria-proptypes': 'warn',
'jsx-a11y/aria-unsupported-elements': 'warn',
'jsx-a11y/role-has-required-aria-props': 'warn',
'jsx-a11y/role-supports-aria-props': 'warn',
'react/jsx-no-target-blank': 'off',
},
parser: './parser.js',
parserOptions: {
requireConfigFile: false,
sourceType: 'module',
allowImportExportEverywhere: true,
babelOptions: {
presets: ['next/babel'],
caller: {
// Eslint supports top level await when a parser for it is included. We enable the parser by default for Babel.
supportsTopLevelAwait: true,
},
},
},
overrides: [
{
files: ['**/*.ts?(x)'],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
warnOnUnsupportedTypeScriptVersion: true,
},
},
],
settings: {
react: {
version: 'detect',
},
'import/parsers': {
[require.resolve('@typescript-eslint/parser')]: [
'.ts',
'.mts',
'.cts',
'.tsx',
'.d.ts',
],
},
'import/resolver': {
[require.resolve('eslint-import-resolver-node')]: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
},
[require.resolve('eslint-import-resolver-typescript')]: {
alwaysTryTypes: true,
},
},
},
env: {
browser: true,
node: true,
},
}

View File

@@ -0,0 +1,5 @@
Copyright 2021 Alex Gorbatchev <alex.gorbatchev@gmail.com>
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@@ -0,0 +1,234 @@
# eslint-import-resolver-typescript
[![GitHub Actions](https://github.com/import-js/eslint-import-resolver-typescript/workflows/CI/badge.svg)](https://github.com/import-js/eslint-import-resolver-typescript/actions/workflows/ci.yml)
[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fimport-js%2Feslint-import-resolver-typescript%2Fmaster%2Fpackage.json)](https://github.com/plantain-00/type-coverage)
[![npm](https://img.shields.io/npm/v/eslint-import-resolver-typescript.svg)](https://www.npmjs.com/package/eslint-import-resolver-typescript)
[![GitHub Release](https://img.shields.io/github/release/import-js/eslint-import-resolver-typescript)](https://github.com/import-js/eslint-import-resolver-typescript/releases)
[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/changesets/changesets)
This plugin adds [`TypeScript`][] support to [`eslint-plugin-import`][] (Or maybe you want to try [`eslint-plugin-i`][] for faster speed)
This means you can:
- `import`/`require` files with extension `.cts`/`.mts`/`.ts`/`.tsx`/`.d.cts`/`.d.mts`/`.d.ts`
- Use [`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) defined in `tsconfig.json`
- Prefer resolving `@types/*` definitions over plain `.js`/`.jsx`
- Multiple tsconfigs support just like normal
- `imports/exports` fields support in `package.json`
## TOC <!-- omit in toc -->
- [Notice](#notice)
- [Installation](#installation)
- [Configuration](#configuration)
- [Options from `enhanced-resolve`](#options-from-enhanced-resolve)
- [`conditionNames`](#conditionnames)
- [`extensions`](#extensions)
- [`extensionAlias`](#extensionalias)
- [`mainFields`](#mainfields)
- [Other options](#other-options)
- [Default options](#default-options)
- [Contributing](#contributing)
- [Sponsors](#sponsors)
- [Backers](#backers)
- [Changelog](#changelog)
- [License](#license)
## Notice
After version 2.0.0, `.d.ts` will take higher priority then normal `.js`/`.jsx` files on resolving `node_modules` packages in favor of `@types/*` definitions or its own definition.
If you're facing some problems on rules `import/default` or `import/named` from [`eslint-plugin-import`][], do not post any issue here, because they are just working exactly as [expected](https://github.com/import-js/eslint-import-resolver-typescript/issues/31#issuecomment-539751607) on our sides, take [import-js/eslint-plugin-import#1525](https://github.com/import-js/eslint-plugin-import/issues/1525) as reference or post a new issue to [`eslint-plugin-import`][] instead.
## Installation
```sh
# npm
npm i -D eslint-plugin-import eslint-import-resolver-typescript
# pnpm
pnpm i -D eslint-plugin-import eslint-import-resolver-typescript
# yarn
yarn add -D eslint-plugin-import eslint-import-resolver-typescript
```
**Important when using `eslint-plugin-i` and `npm`**: Use `npm i -D eslint-plugin-import@eslint-plugin-i@latest eslint-import-resolver-typescript`, or you will end up with both `eslint-plugin-import` and `eslint-plugin-i` in your node_modules.
## Configuration
Add the following to your `.eslintrc` config:
```jsonc
{
"plugins": ["import"],
"rules": {
// turn on errors for missing imports
"import/no-unresolved": "error"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true, // always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
// Choose from one of the "project" configs below or omit to use <root>/tsconfig.json by default
// use <root>/path/to/folder/tsconfig.json
"project": "path/to/folder",
// Multiple tsconfigs (Useful for monorepos)
// use a glob pattern
"project": "packages/*/tsconfig.json",
// use an array
"project": [
"packages/module-a/tsconfig.json",
"packages/module-b/tsconfig.json"
],
// use an array of glob patterns
"project": [
"packages/*/tsconfig.json",
"other-packages/*/tsconfig.json"
]
}
}
}
}
```
## Options from [`enhanced-resolve`][]
### `conditionNames`
Default:
```jsonc
[
"types",
"import",
// APF: https://angular.io/guide/angular-package-format
"esm2020",
"es2020",
"es2015",
"require",
"node",
"node-addons",
"browser",
"default"
]
```
### `extensions`
Default:
```jsonc
[
// `.mts`, `.cts`, `.d.mts`, `.d.cts`, `.mjs`, `.cjs` are not included because `.cjs` and `.mjs` must be used explicitly
".ts",
".tsx",
".d.ts",
".js",
".jsx",
".json",
".node"
]
```
### `extensionAlias`
Default:
```jsonc
{
".js": [
".ts",
// `.tsx` can also be compiled as `.js`
".tsx",
".d.ts",
".js"
],
".jsx": [".tsx", ".d.ts", ".jsx"],
".cjs": [".cts", ".d.cts", ".cjs"],
".mjs": [".mts", ".d.mts", ".mjs"]
}
```
### `mainFields`
Default:
```jsonc
[
"types",
"typings",
// APF: https://angular.io/guide/angular-package-format
"fesm2020",
"fesm2015",
"esm2020",
"es2020",
"module",
"jsnext:main",
"main"
]
```
### Other options
You can pass through other options of [`enhanced-resolve`][] directly
### Default options
You can reuse `defaultConditionNames`, `defaultExtensions`, `defaultExtensionAlias` and `defaultMainFields` by `require/import` them directly
## Contributing
- Make sure your change is covered by a test import.
- Make sure that `yarn test` passes without a failure.
- Make sure that `yarn lint` passes without conflicts.
- Make sure your code changes match our [type-coverage](https://github.com/plantain-00/type-coverage) settings: `yarn type-coverage`.
We have [GitHub Actions](https://github.com/import-js/eslint-import-resolver-typescript/actions) which will run the above commands on your PRs.
If either fails, we won't be able to merge your PR until it's fixed.
## Sponsors
| 1stG | RxTS | UnTS |
| ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/organizations.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/organizations.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/organizations.svg)](https://opencollective.com/unts) |
## Backers
| 1stG | RxTS | UnTS |
| -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| [![1stG Open Collective backers and sponsors](https://opencollective.com/1stG/individuals.svg)](https://opencollective.com/1stG) | [![RxTS Open Collective backers and sponsors](https://opencollective.com/rxts/individuals.svg)](https://opencollective.com/rxts) | [![UnTS Open Collective backers and sponsors](https://opencollective.com/unts/individuals.svg)](https://opencollective.com/unts) |
## Changelog
Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.md).
## License
[ISC][]
[`eslint-plugin-i`]: https://github.com/un-es/eslint-plugin-i
[`eslint-plugin-import`]: https://github.com/import-js/eslint-plugin-import
[`enhanced-resolve`]: https://github.com/webpack/enhanced-resolve
[`typescript`]: https://www.typescriptlang.org
[isc]: https://opensource.org/licenses/ISC

View File

@@ -0,0 +1,279 @@
'use strict';
var fs = require('node:fs');
var path = require('node:path');
var isNodeCoreModule = require('@nolyfill/is-core-module');
var debug = require('debug');
var enhancedResolve = require('enhanced-resolve');
var hash_js = require('eslint-module-utils/hash.js');
var fg = require('fast-glob');
var getTsconfig = require('get-tsconfig');
var isBunModule = require('is-bun-module');
var isGlob = require('is-glob');
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
const { globSync } = fg;
const IMPORTER_NAME = "eslint-import-resolver-typescript";
const log = debug(IMPORTER_NAME);
const defaultConditionNames = [
"types",
"import",
// APF: https://angular.io/guide/angular-package-format
"esm2020",
"es2020",
"es2015",
"require",
"node",
"node-addons",
"browser",
"default"
];
const defaultExtensions = [
".ts",
".tsx",
".d.ts",
".js",
".jsx",
".json",
".node"
];
const defaultExtensionAlias = {
".js": [
".ts",
// `.tsx` can also be compiled as `.js`
".tsx",
".d.ts",
".js"
],
".jsx": [".tsx", ".d.ts", ".jsx"],
".cjs": [".cts", ".d.cts", ".cjs"],
".mjs": [".mts", ".d.mts", ".mjs"]
};
const defaultMainFields = [
"types",
"typings",
// APF: https://angular.io/guide/angular-package-format
"fesm2020",
"fesm2015",
"esm2020",
"es2020",
"module",
"jsnext:main",
"main"
];
const interfaceVersion = 2;
const fileSystem = fs;
const JS_EXT_PATTERN = /\.(?:[cm]js|jsx?)$/;
const RELATIVE_PATH_PATTERN = /^\.{1,2}(?:\/.*)?$/;
let previousOptionsHash;
let optionsHash;
let cachedOptions;
let prevCwd;
let mappersCachedOptions;
let mappers;
let resolverCachedOptions;
let resolver;
const digestHashObject = (value) => hash_js.hashObject(value != null ? value : {}).digest("hex");
function resolve(source, file, options) {
var _a, _b, _c, _d, _e;
if (!cachedOptions || previousOptionsHash !== (optionsHash = digestHashObject(options))) {
previousOptionsHash = optionsHash;
cachedOptions = __spreadProps(__spreadValues({}, options), {
conditionNames: (_a = options == null ? void 0 : options.conditionNames) != null ? _a : defaultConditionNames,
extensions: (_b = options == null ? void 0 : options.extensions) != null ? _b : defaultExtensions,
extensionAlias: (_c = options == null ? void 0 : options.extensionAlias) != null ? _c : defaultExtensionAlias,
mainFields: (_d = options == null ? void 0 : options.mainFields) != null ? _d : defaultMainFields,
fileSystem: new enhancedResolve.CachedInputFileSystem(
fileSystem,
5 * 1e3
),
useSyncFileSystemCalls: true
});
}
if (!resolver || resolverCachedOptions !== cachedOptions) {
resolver = enhancedResolve.ResolverFactory.createResolver(cachedOptions);
resolverCachedOptions = cachedOptions;
}
log("looking for:", source);
source = removeQuerystring(source);
if (isNodeCoreModule(source) || isBunModule.isBunModule(source, (_e = process.versions.bun) != null ? _e : "latest")) {
log("matched core:", source);
return {
found: true,
path: null
};
}
initMappers(cachedOptions);
const mappedPath = getMappedPath(source, file, cachedOptions.extensions, true);
if (mappedPath) {
log("matched ts path:", mappedPath);
}
let foundNodePath;
try {
foundNodePath = resolver.resolveSync(
{},
path.dirname(path.resolve(file)),
mappedPath != null ? mappedPath : source
) || null;
} catch (e) {
foundNodePath = null;
}
if ((JS_EXT_PATTERN.test(foundNodePath) || cachedOptions.alwaysTryTypes && !foundNodePath) && !/^@types[/\\]/.test(source) && !path.isAbsolute(source) && !source.startsWith(".")) {
const definitelyTyped = resolve(
"@types" + path.sep + mangleScopedPackage(source),
file,
options
);
if (definitelyTyped.found) {
return definitelyTyped;
}
}
if (foundNodePath) {
log("matched node path:", foundNodePath);
return {
found: true,
path: foundNodePath
};
}
log("didn't find ", source);
return {
found: false
};
}
function removeQuerystring(id) {
const querystringIndex = id.lastIndexOf("?");
if (querystringIndex >= 0) {
return id.slice(0, querystringIndex);
}
return id;
}
const isFile = (path2) => {
var _a;
try {
return !!(path2 && ((_a = fs.statSync(path2, { throwIfNoEntry: false })) == null ? void 0 : _a.isFile()));
} catch (e) {
return false;
}
};
const isModule = (modulePath) => {
return !!modulePath && isFile(path.resolve(modulePath, "package.json"));
};
function getMappedPath(source, file, extensions = defaultExtensions, retry) {
const originalExtensions = extensions;
extensions = ["", ...extensions];
let paths = [];
if (RELATIVE_PATH_PATTERN.test(source)) {
const resolved = path.resolve(path.dirname(file), source);
if (isFile(resolved)) {
paths = [resolved];
}
} else {
paths = mappers.map(
(mapper) => mapper == null ? void 0 : mapper(source).map((item) => [
...extensions.map((ext) => `${item}${ext}`),
...originalExtensions.map((ext) => `${item}/index${ext}`)
])
).flat(2).filter((mappedPath) => {
if (mappedPath === void 0) {
return false;
}
try {
const stat = fs.statSync(mappedPath, { throwIfNoEntry: false });
if (stat === void 0)
return false;
if (stat.isFile())
return true;
if (stat.isDirectory()) {
return isModule(mappedPath);
}
} catch (e) {
return false;
}
return false;
});
}
if (retry && paths.length === 0) {
const isJs = JS_EXT_PATTERN.test(source);
if (isJs) {
const jsExt = path.extname(source);
const tsExt = jsExt.replace("js", "ts");
const basename = source.replace(JS_EXT_PATTERN, "");
const resolved = getMappedPath(basename + tsExt, file) || getMappedPath(
basename + ".d" + (tsExt === ".tsx" ? ".ts" : tsExt),
file
);
if (resolved) {
return resolved;
}
}
for (const ext of extensions) {
const resolved = (isJs ? null : getMappedPath(source + ext, file)) || getMappedPath(source + `/index${ext}`, file);
if (resolved) {
return resolved;
}
}
}
if (paths.length > 1) {
log("found multiple matching ts paths:", paths);
}
return paths[0];
}
function initMappers(options) {
if (mappers && mappersCachedOptions === options && prevCwd === process.cwd()) {
return;
}
prevCwd = process.cwd();
const configPaths = typeof options.project === "string" ? [options.project] : Array.isArray(options.project) ? options.project : [process.cwd()];
const ignore = ["!**/node_modules/**"];
const projectPaths = [
.../* @__PURE__ */ new Set([
...configPaths.filter((path2) => !isGlob(path2)),
...globSync([...configPaths.filter((path2) => isGlob(path2)), ...ignore])
])
];
mappers = projectPaths.map((projectPath) => {
let tsconfigResult;
if (isFile(projectPath)) {
const { dir, base } = path.parse(projectPath);
tsconfigResult = getTsconfig.getTsconfig(dir, base);
} else {
tsconfigResult = getTsconfig.getTsconfig(projectPath);
}
return tsconfigResult && getTsconfig.createPathsMatcher(tsconfigResult);
});
mappersCachedOptions = options;
}
function mangleScopedPackage(moduleName) {
if (moduleName.startsWith("@")) {
const replaceSlash = moduleName.replace(path.sep, "__");
if (replaceSlash !== moduleName) {
return replaceSlash.slice(1);
}
}
return moduleName;
}
exports.defaultConditionNames = defaultConditionNames;
exports.defaultExtensionAlias = defaultExtensionAlias;
exports.defaultExtensions = defaultExtensions;
exports.defaultMainFields = defaultMainFields;
exports.interfaceVersion = interfaceVersion;
exports.resolve = resolve;

View File

@@ -0,0 +1,20 @@
import type { ResolveOptions } from 'enhanced-resolve';
export declare const defaultConditionNames: string[];
export declare const defaultExtensions: string[];
export declare const defaultExtensionAlias: {
'.js': string[];
'.jsx': string[];
'.cjs': string[];
'.mjs': string[];
};
export declare const defaultMainFields: string[];
export declare const interfaceVersion = 2;
export interface TsResolverOptions extends Omit<ResolveOptions, 'fileSystem' | 'useSyncFileSystemCalls'> {
alwaysTryTypes?: boolean;
project?: string[] | string;
extensions?: string[];
}
export declare function resolve(source: string, file: string, options?: TsResolverOptions | null): {
found: boolean;
path?: string | null;
};

View File

@@ -0,0 +1,252 @@
import fs from 'node:fs';
import path from 'node:path';
import isNodeCoreModule from '@nolyfill/is-core-module';
import debug from 'debug';
import enhancedResolve from 'enhanced-resolve';
import { hashObject } from 'eslint-module-utils/hash.js';
import fg from 'fast-glob';
import { getTsconfig, createPathsMatcher } from 'get-tsconfig';
import { isBunModule } from 'is-bun-module';
import isGlob from 'is-glob';
const { globSync } = fg;
const IMPORTER_NAME = "eslint-import-resolver-typescript";
const log = debug(IMPORTER_NAME);
const defaultConditionNames = [
"types",
"import",
// APF: https://angular.io/guide/angular-package-format
"esm2020",
"es2020",
"es2015",
"require",
"node",
"node-addons",
"browser",
"default"
];
const defaultExtensions = [
".ts",
".tsx",
".d.ts",
".js",
".jsx",
".json",
".node"
];
const defaultExtensionAlias = {
".js": [
".ts",
// `.tsx` can also be compiled as `.js`
".tsx",
".d.ts",
".js"
],
".jsx": [".tsx", ".d.ts", ".jsx"],
".cjs": [".cts", ".d.cts", ".cjs"],
".mjs": [".mts", ".d.mts", ".mjs"]
};
const defaultMainFields = [
"types",
"typings",
// APF: https://angular.io/guide/angular-package-format
"fesm2020",
"fesm2015",
"esm2020",
"es2020",
"module",
"jsnext:main",
"main"
];
const interfaceVersion = 2;
const fileSystem = fs;
const JS_EXT_PATTERN = /\.(?:[cm]js|jsx?)$/;
const RELATIVE_PATH_PATTERN = /^\.{1,2}(?:\/.*)?$/;
let previousOptionsHash;
let optionsHash;
let cachedOptions;
let prevCwd;
let mappersCachedOptions;
let mappers;
let resolverCachedOptions;
let resolver;
const digestHashObject = (value) => hashObject(value ?? {}).digest("hex");
function resolve(source, file, options) {
if (!cachedOptions || previousOptionsHash !== (optionsHash = digestHashObject(options))) {
previousOptionsHash = optionsHash;
cachedOptions = {
...options,
conditionNames: options?.conditionNames ?? defaultConditionNames,
extensions: options?.extensions ?? defaultExtensions,
extensionAlias: options?.extensionAlias ?? defaultExtensionAlias,
mainFields: options?.mainFields ?? defaultMainFields,
fileSystem: new enhancedResolve.CachedInputFileSystem(
fileSystem,
5 * 1e3
),
useSyncFileSystemCalls: true
};
}
if (!resolver || resolverCachedOptions !== cachedOptions) {
resolver = enhancedResolve.ResolverFactory.createResolver(cachedOptions);
resolverCachedOptions = cachedOptions;
}
log("looking for:", source);
source = removeQuerystring(source);
if (isNodeCoreModule(source) || isBunModule(source, process.versions.bun ?? "latest")) {
log("matched core:", source);
return {
found: true,
path: null
};
}
initMappers(cachedOptions);
const mappedPath = getMappedPath(source, file, cachedOptions.extensions, true);
if (mappedPath) {
log("matched ts path:", mappedPath);
}
let foundNodePath;
try {
foundNodePath = resolver.resolveSync(
{},
path.dirname(path.resolve(file)),
mappedPath ?? source
) || null;
} catch {
foundNodePath = null;
}
if ((JS_EXT_PATTERN.test(foundNodePath) || cachedOptions.alwaysTryTypes && !foundNodePath) && !/^@types[/\\]/.test(source) && !path.isAbsolute(source) && !source.startsWith(".")) {
const definitelyTyped = resolve(
"@types" + path.sep + mangleScopedPackage(source),
file,
options
);
if (definitelyTyped.found) {
return definitelyTyped;
}
}
if (foundNodePath) {
log("matched node path:", foundNodePath);
return {
found: true,
path: foundNodePath
};
}
log("didn't find ", source);
return {
found: false
};
}
function removeQuerystring(id) {
const querystringIndex = id.lastIndexOf("?");
if (querystringIndex >= 0) {
return id.slice(0, querystringIndex);
}
return id;
}
const isFile = (path2) => {
try {
return !!(path2 && fs.statSync(path2, { throwIfNoEntry: false })?.isFile());
} catch {
return false;
}
};
const isModule = (modulePath) => {
return !!modulePath && isFile(path.resolve(modulePath, "package.json"));
};
function getMappedPath(source, file, extensions = defaultExtensions, retry) {
const originalExtensions = extensions;
extensions = ["", ...extensions];
let paths = [];
if (RELATIVE_PATH_PATTERN.test(source)) {
const resolved = path.resolve(path.dirname(file), source);
if (isFile(resolved)) {
paths = [resolved];
}
} else {
paths = mappers.map(
(mapper) => mapper?.(source).map((item) => [
...extensions.map((ext) => `${item}${ext}`),
...originalExtensions.map((ext) => `${item}/index${ext}`)
])
).flat(2).filter((mappedPath) => {
if (mappedPath === void 0) {
return false;
}
try {
const stat = fs.statSync(mappedPath, { throwIfNoEntry: false });
if (stat === void 0)
return false;
if (stat.isFile())
return true;
if (stat.isDirectory()) {
return isModule(mappedPath);
}
} catch {
return false;
}
return false;
});
}
if (retry && paths.length === 0) {
const isJs = JS_EXT_PATTERN.test(source);
if (isJs) {
const jsExt = path.extname(source);
const tsExt = jsExt.replace("js", "ts");
const basename = source.replace(JS_EXT_PATTERN, "");
const resolved = getMappedPath(basename + tsExt, file) || getMappedPath(
basename + ".d" + (tsExt === ".tsx" ? ".ts" : tsExt),
file
);
if (resolved) {
return resolved;
}
}
for (const ext of extensions) {
const resolved = (isJs ? null : getMappedPath(source + ext, file)) || getMappedPath(source + `/index${ext}`, file);
if (resolved) {
return resolved;
}
}
}
if (paths.length > 1) {
log("found multiple matching ts paths:", paths);
}
return paths[0];
}
function initMappers(options) {
if (mappers && mappersCachedOptions === options && prevCwd === process.cwd()) {
return;
}
prevCwd = process.cwd();
const configPaths = typeof options.project === "string" ? [options.project] : Array.isArray(options.project) ? options.project : [process.cwd()];
const ignore = ["!**/node_modules/**"];
const projectPaths = [
.../* @__PURE__ */ new Set([
...configPaths.filter((path2) => !isGlob(path2)),
...globSync([...configPaths.filter((path2) => isGlob(path2)), ...ignore])
])
];
mappers = projectPaths.map((projectPath) => {
let tsconfigResult;
if (isFile(projectPath)) {
const { dir, base } = path.parse(projectPath);
tsconfigResult = getTsconfig(dir, base);
} else {
tsconfigResult = getTsconfig(projectPath);
}
return tsconfigResult && createPathsMatcher(tsconfigResult);
});
mappersCachedOptions = options;
}
function mangleScopedPackage(moduleName) {
if (moduleName.startsWith("@")) {
const replaceSlash = moduleName.replace(path.sep, "__");
if (replaceSlash !== moduleName) {
return replaceSlash.slice(1);
}
}
return moduleName;
}
export { defaultConditionNames, defaultExtensionAlias, defaultExtensions, defaultMainFields, interfaceVersion, resolve };

View File

@@ -0,0 +1,254 @@
import fs from 'node:fs';
import path from 'node:path';
import isNodeCoreModule from '@nolyfill/is-core-module';
import debug from 'debug';
import enhancedResolve from 'enhanced-resolve';
import { hashObject } from 'eslint-module-utils/hash.js';
import fg from 'fast-glob';
import { createPathsMatcher, getTsconfig } from 'get-tsconfig';
import { isBunModule } from 'is-bun-module';
import isGlob from 'is-glob';
const { globSync } = fg;
const IMPORTER_NAME = 'eslint-import-resolver-typescript';
const log = debug(IMPORTER_NAME);
export const defaultConditionNames = [
'types',
'import',
'esm2020',
'es2020',
'es2015',
'require',
'node',
'node-addons',
'browser',
'default',
];
export const defaultExtensions = [
'.ts',
'.tsx',
'.d.ts',
'.js',
'.jsx',
'.json',
'.node',
];
export const defaultExtensionAlias = {
'.js': [
'.ts',
'.tsx',
'.d.ts',
'.js',
],
'.jsx': ['.tsx', '.d.ts', '.jsx'],
'.cjs': ['.cts', '.d.cts', '.cjs'],
'.mjs': ['.mts', '.d.mts', '.mjs'],
};
export const defaultMainFields = [
'types',
'typings',
'fesm2020',
'fesm2015',
'esm2020',
'es2020',
'module',
'jsnext:main',
'main',
];
export const interfaceVersion = 2;
const fileSystem = fs;
const JS_EXT_PATTERN = /\.(?:[cm]js|jsx?)$/;
const RELATIVE_PATH_PATTERN = /^\.{1,2}(?:\/.*)?$/;
let previousOptionsHash;
let optionsHash;
let cachedOptions;
let prevCwd;
let mappersCachedOptions;
let mappers;
let resolverCachedOptions;
let resolver;
const digestHashObject = (value) => hashObject(value ?? {}).digest('hex');
export function resolve(source, file, options) {
if (!cachedOptions ||
previousOptionsHash !== (optionsHash = digestHashObject(options))) {
previousOptionsHash = optionsHash;
cachedOptions = {
...options,
conditionNames: options?.conditionNames ?? defaultConditionNames,
extensions: options?.extensions ?? defaultExtensions,
extensionAlias: options?.extensionAlias ?? defaultExtensionAlias,
mainFields: options?.mainFields ?? defaultMainFields,
fileSystem: new enhancedResolve.CachedInputFileSystem(fileSystem, 5 * 1000),
useSyncFileSystemCalls: true,
};
}
if (!resolver || resolverCachedOptions !== cachedOptions) {
resolver = enhancedResolve.ResolverFactory.createResolver(cachedOptions);
resolverCachedOptions = cachedOptions;
}
log('looking for:', source);
source = removeQuerystring(source);
if (isNodeCoreModule(source) ||
isBunModule(source, (process.versions.bun ?? 'latest'))) {
log('matched core:', source);
return {
found: true,
path: null,
};
}
initMappers(cachedOptions);
const mappedPath = getMappedPath(source, file, cachedOptions.extensions, true);
if (mappedPath) {
log('matched ts path:', mappedPath);
}
let foundNodePath;
try {
foundNodePath =
resolver.resolveSync({}, path.dirname(path.resolve(file)), mappedPath ?? source) || null;
}
catch {
foundNodePath = null;
}
if ((JS_EXT_PATTERN.test(foundNodePath) ||
(cachedOptions.alwaysTryTypes && !foundNodePath)) &&
!/^@types[/\\]/.test(source) &&
!path.isAbsolute(source) &&
!source.startsWith('.')) {
const definitelyTyped = resolve('@types' + path.sep + mangleScopedPackage(source), file, options);
if (definitelyTyped.found) {
return definitelyTyped;
}
}
if (foundNodePath) {
log('matched node path:', foundNodePath);
return {
found: true,
path: foundNodePath,
};
}
log("didn't find ", source);
return {
found: false,
};
}
function removeQuerystring(id) {
const querystringIndex = id.lastIndexOf('?');
if (querystringIndex >= 0) {
return id.slice(0, querystringIndex);
}
return id;
}
const isFile = (path) => {
try {
return !!(path && fs.statSync(path, { throwIfNoEntry: false })?.isFile());
}
catch {
return false;
}
};
const isModule = (modulePath) => {
return !!modulePath && isFile(path.resolve(modulePath, 'package.json'));
};
function getMappedPath(source, file, extensions = defaultExtensions, retry) {
const originalExtensions = extensions;
extensions = ['', ...extensions];
let paths = [];
if (RELATIVE_PATH_PATTERN.test(source)) {
const resolved = path.resolve(path.dirname(file), source);
if (isFile(resolved)) {
paths = [resolved];
}
}
else {
paths = mappers
.map(mapper => mapper?.(source).map(item => [
...extensions.map(ext => `${item}${ext}`),
...originalExtensions.map(ext => `${item}/index${ext}`),
]))
.flat(2)
.filter(mappedPath => {
if (mappedPath === undefined) {
return false;
}
try {
const stat = fs.statSync(mappedPath, { throwIfNoEntry: false });
if (stat === undefined)
return false;
if (stat.isFile())
return true;
if (stat.isDirectory()) {
return isModule(mappedPath);
}
}
catch {
return false;
}
return false;
});
}
if (retry && paths.length === 0) {
const isJs = JS_EXT_PATTERN.test(source);
if (isJs) {
const jsExt = path.extname(source);
const tsExt = jsExt.replace('js', 'ts');
const basename = source.replace(JS_EXT_PATTERN, '');
const resolved = getMappedPath(basename + tsExt, file) ||
getMappedPath(basename + '.d' + (tsExt === '.tsx' ? '.ts' : tsExt), file);
if (resolved) {
return resolved;
}
}
for (const ext of extensions) {
const resolved = (isJs ? null : getMappedPath(source + ext, file)) ||
getMappedPath(source + `/index${ext}`, file);
if (resolved) {
return resolved;
}
}
}
if (paths.length > 1) {
log('found multiple matching ts paths:', paths);
}
return paths[0];
}
function initMappers(options) {
if (mappers &&
mappersCachedOptions === options &&
prevCwd === process.cwd()) {
return;
}
prevCwd = process.cwd();
const configPaths = typeof options.project === 'string'
? [options.project]
: Array.isArray(options.project)
? options.project
: [process.cwd()];
const ignore = ['!**/node_modules/**'];
const projectPaths = [
...new Set([
...configPaths.filter(path => !isGlob(path)),
...globSync([...configPaths.filter(path => isGlob(path)), ...ignore]),
]),
];
mappers = projectPaths.map(projectPath => {
let tsconfigResult;
if (isFile(projectPath)) {
const { dir, base } = path.parse(projectPath);
tsconfigResult = getTsconfig(dir, base);
}
else {
tsconfigResult = getTsconfig(projectPath);
}
return tsconfigResult && createPathsMatcher(tsconfigResult);
});
mappersCachedOptions = options;
}
function mangleScopedPackage(moduleName) {
if (moduleName.startsWith('@')) {
const replaceSlash = moduleName.replace(path.sep, '__');
if (replaceSlash !== moduleName) {
return replaceSlash.slice(1);
}
}
return moduleName;
}
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,126 @@
{
"name": "eslint-import-resolver-typescript",
"version": "3.6.3",
"type": "module",
"description": "This plugin adds `TypeScript` support to `eslint-plugin-import`",
"repository": "git+https://github.com/import-js/eslint-import-resolver-typescript",
"author": "Alex Gorbatchev <alex.gorbatchev@gmail.com>",
"contributors": [
"JounQin (https://www.1stG.me) <admin@1stg.me>"
],
"funding": "https://opencollective.com/unts/projects/eslint-import-resolver-ts",
"license": "ISC",
"packageManager": "yarn@4.0.2",
"engines": {
"node": "^14.18.0 || >=16.0.0"
},
"main": "lib/index.cjs",
"module": "lib/index.js",
"exports": {
".": {
"types": "./lib/index.d.ts",
"es2020": "./lib/index.es2020.mjs",
"fesm2020": "./lib/index.es2020.mjs",
"import": "./lib/index.js",
"require": "./lib/index.cjs"
},
"./package.json": "./package.json"
},
"es2020": "lib/index.es2020.mjs",
"fesm2020": "lib/index.es2020.mjs",
"types": "lib/index.d.ts",
"files": [
"lib",
"shim.d.ts",
"!**/*.tsbuildinfo"
],
"keywords": [
"typescript",
"eslint",
"import",
"resolver",
"plugin"
],
"scripts": {
"build": "run-p 'build:*'",
"build:r": "r -f cjs,es2020",
"build:ts": "tsc -b",
"lint": "run-p 'lint:*'",
"lint:es": "eslint src --cache -f friendly",
"lint:tsc": "tsc --noEmit",
"prepare": "simple-git-hooks",
"release": "changeset publish",
"test": "run-p 'test:*'",
"test:multipleEslintrcs": "eslint --ext ts,tsx tests/multipleEslintrcs",
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
"test:withJsExtension": "node tests/withJsExtension/test.js && eslint --ext ts,tsx tests/withJsExtension",
"test:withJsconfig": "eslint --ext js tests/withJsconfig",
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
"test:withPathsAndNestedBaseUrl": "eslint --ext ts,tsx tests/withPathsAndNestedBaseUrl",
"test:withQuerystring": "eslint --ext ts,tsx tests/withQuerystring",
"test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths",
"typecov": "type-coverage"
},
"peerDependencies": {
"eslint": "*",
"eslint-plugin-import": "*",
"eslint-plugin-import-x": "*"
},
"peerDependenciesMeta": {
"eslint-plugin-import": {
"optional": true
},
"eslint-plugin-import-x": {
"optional": true
}
},
"dependencies": {
"@nolyfill/is-core-module": "1.0.39",
"debug": "^4.3.5",
"enhanced-resolve": "^5.15.0",
"eslint-module-utils": "^2.8.1",
"fast-glob": "^3.3.2",
"get-tsconfig": "^4.7.5",
"is-bun-module": "^1.0.2",
"is-glob": "^4.0.3"
},
"devDependencies": {
"@1stg/lib-config": "^12.0.1",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.7",
"@commitlint/cli": "^17.8.1",
"@mozilla/glean": "^3.0.0",
"@pkgr/rollup": "^4.1.3",
"@types/debug": "^4.1.12",
"@types/is-glob": "^4.0.4",
"@types/node": "^18.19.42",
"@types/unist": "^2.0.10",
"dummy.js": "link:dummy.js",
"eslint": "^8.57.0",
"eslint-import-resolver-typescript": "link:.",
"eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
"lint-staged": "^13.3.0",
"npm-run-all2": "^5.0.2",
"prettier": "^2.8.8",
"react": "^18.2.0",
"simple-git-hooks": "^2.9.0",
"size-limit": "^11.0.0",
"size-limit-preset-node-lib": "^0.3.0",
"type-coverage": "^2.27.0",
"typescript": "^5.3.2"
},
"resolutions": {
"eslint-import-resolver-typescript": "link:.",
"prettier": "^2.8.8"
},
"typeCoverage": {
"atLeast": 100,
"cache": true,
"detail": true,
"ignoreAsAssertion": true,
"ignoreNonNullAssertion": true,
"ignoreCatch": true,
"strict": true,
"update": true
}
}

View File

@@ -0,0 +1,4 @@
declare module 'eslint-module-utils/hash.js' {
import type { Hash } from 'node:crypto'
export const hashObject: (object: object, hash?: Hash) => Hash
}

32
node_modules/eslint-config-next/package.json generated vendored Normal file
View File

@@ -0,0 +1,32 @@
{
"name": "eslint-config-next",
"version": "13.5.1",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
"repository": {
"url": "vercel/next.js",
"directory": "packages/eslint-config-next"
},
"homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config",
"dependencies": {
"@next/eslint-plugin-next": "13.5.1",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0",
"eslint-import-resolver-node": "^0.3.6",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.5.0 || 5.0.0-canary-7118f5dd7-20230705"
},
"peerDependencies": {
"eslint": "^7.23.0 || ^8.0.0",
"typescript": ">=3.3.1"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
}
}

9
node_modules/eslint-config-next/parser.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
const {
parse,
parseForESLint,
} = require('next/dist/compiled/babel/eslint-parser')
module.exports = {
parse,
parseForESLint,
}