Skip to content

Commit afb4edb

Browse files
committed
feat: replace tsconfig-paths + typescript with get-tsconfig
feat!: bump `semver`, remove unnecessary dependencies
1 parent 6d34c88 commit afb4edb

28 files changed

+222
-106
lines changed

.changeset/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/config/schema.json",
3+
"commit": false,
4+
"linked": [],
5+
"access": "public",
6+
"baseBranch": "fork-release",
7+
"updateInternalDependencies": "patch",
8+
"ignore": []
9+
}

.github/FUNDING.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
# These are supported funding model platforms
2-
3-
github: [ljharb]
4-
patreon: # Replace with a single Patreon username
5-
open_collective: eslint-plugin-import # Replace with a single Open Collective username
6-
ko_fi: # Replace with a single Ko-fi username
7-
tidelift: npm/eslint-plugin-import
8-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9-
liberapay: # Replace with a single Liberapay username
10-
issuehunt: # Replace with a single IssueHunt username
11-
otechie: # Replace with a single Otechie username
12-
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
1+
github:
2+
- JounQin
3+
- 1stG
4+
- rx-ts
5+
- un-ts
6+
patreon: 1stG
7+
open_collective: unts
8+
custom:
9+
- https://opencollective.com/1stG
10+
- https://opencollective.com/rxts
11+
- https://afdian.net/@JounQin

.github/workflows/node-4+.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ jobs:
1717
with:
1818
versionsAsRoot: true
1919
type: majors
20-
preset: '>= 6' # preset: '>=4' # see https://github.com/import-js/eslint-plugin-import/issues/2053
20+
# preset: '>= 6' # preset: '>=4' # see https://github.com/import-js/eslint-plugin-import/issues/2053
21+
# target Node.js 12 now, see https://github.com/un-es/eslint-plugin-i/issues/10 & https://github.com/un-es/eslint-plugin-i/pull/11
22+
preset: '>= 12'
2123

2224
latest:
2325
needs: [matrix]
@@ -31,11 +33,6 @@ jobs:
3133
eslint:
3234
- 8
3335
- 7
34-
- 6
35-
- 5
36-
- 4
37-
- 3
38-
- 2
3936
include:
4037
- node-version: 'lts/*'
4138
eslint: 7

.github/workflows/rebase-upstream.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Rebase
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
- cron: '0 0 * * *'
7+
8+
jobs:
9+
rebase:
10+
name: Rebase and Push
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Repo
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
ref: fork-release
18+
19+
- name: Set Git Info
20+
run: |
21+
git config --global user.email [email protected]
22+
git config --global user.name JounQin
23+
git remote add upstream https://github.com/import-js/eslint-plugin-import.git
24+
25+
- name: Rebase and Push
26+
run: |
27+
git fetch upstream main:main
28+
git rebase upstream/main
29+
git push -f

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- fork-release
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Repo
14+
uses: actions/checkout@v3
15+
with:
16+
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
17+
fetch-depth: 0
18+
19+
- name: Setup Node.js 16
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 16
23+
24+
- name: Install Dependencies
25+
run: npm install
26+
27+
- name: Publish to npm
28+
uses: changesets/action@v1
29+
with:
30+
publish: npx @changesets/cli publish
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
34+
35+
- name: Sync to cnpm
36+
run: npx cnpm sync eslint-plugin-i

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# eslint-plugin-i
2+
3+
A fork of [`eslint-plugin-import`] using [`get-tsconfig`] to replace [`tsconfig-paths`](https://github.com/dividab/tsconfig-paths) and heavy [`typescript`](https://github.com/microsoft/TypeScript) under the hood.
4+
5+
It will rebase and try to release in order to sync with the upstream every day, see [.github/workflows/rebase-upstream.yml](.github/workflows/rebase-upstream.yml) for details.
6+
7+
And also you can take https://github.com/import-js/eslint-plugin-import/pull/2447 and https://github.com/import-js/eslint-plugin-import/pull/2504 to understand why this forked project exists.
8+
9+
Issues related to `get-tsconfig` should be posted here or [`get-tsconfig`] instead, and other issues should be posted to [`eslint-plugin-import`] instead.
10+
11+
[`eslint-plugin-import`]: https://github.com/import-js/eslint-plugin-import
12+
[`get-tsconfig`]: https://github.com/privatenumber/get-tsconfig
13+
14+
## Installation
15+
16+
```bash
17+
$ npm install -D eslint-plugin-import@npm:eslint-plugin-i@latest
18+
```
19+
20+
---
21+
122
# eslint-plugin-import
223

324
[![github actions][actions-image]][actions-url]

package.json

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
2-
"name": "eslint-plugin-import",
2+
"name": "eslint-plugin-i",
33
"version": "2.29.0",
4-
"description": "Import with sanity.",
4+
"description": "A fork of `eslint-plugin-import` using `get-tsconfig` to replace `tsconfig-paths` and heavy `typescript` under the hood.",
5+
"funding": "https://opencollective.com/unts",
56
"engines": {
6-
"node": ">=4"
7+
"node": ">=12"
78
},
89
"main": "lib/index.js",
910
"directories": {
@@ -24,7 +25,7 @@
2425
"copy-metafiles": "node --require babel-register ./scripts/copyMetafiles",
2526
"watch": "npm run tests-only -- -- --watch",
2627
"pretest": "linklocal",
27-
"posttest": "eslint . && npm run update:eslint-docs -- --check && markdownlint \"**/*.md\"",
28+
"posttest": "eslint . && markdownlint \"**/*.md\"",
2829
"mocha": "cross-env BABEL_ENV=test nyc mocha",
2930
"tests-only": "npm run mocha tests/src",
3031
"test": "npm run tests-only",
@@ -37,7 +38,7 @@
3738
},
3839
"repository": {
3940
"type": "git",
40-
"url": "https://github.com/import-js/eslint-plugin-import"
41+
"url": "https://github.com/un-es/eslint-plugin-i"
4142
},
4243
"keywords": [
4344
"eslint",
@@ -50,11 +51,10 @@
5051
"export"
5152
],
5253
"author": "Ben Mosher <[email protected]>",
54+
"contributors": [
55+
"JounQin (https://www.1stG.me) <[email protected]>"
56+
],
5357
"license": "MIT",
54-
"bugs": {
55-
"url": "https://github.com/import-js/eslint-plugin-import/issues"
56-
},
57-
"homepage": "https://github.com/import-js/eslint-plugin-import",
5858
"devDependencies": {
5959
"@angular-eslint/template-parser": "^13.5.0",
6060
"@eslint/import-test-order-redirect-scoped": "file:./tests/files/order-redirect-scoped",
@@ -86,6 +86,7 @@
8686
"glob": "^7.2.3",
8787
"in-publish": "^2.0.1",
8888
"jackspeak": "=2.1.1",
89+
"is-core-module": "^2.12.1",
8990
"linklocal": "^2.8.2",
9091
"lodash.isarray": "^4.0.0",
9192
"markdownlint-cli": "^0.35.0",
@@ -100,25 +101,17 @@
100101
"typescript-eslint-parser": "^15 || ^20 || ^22"
101102
},
102103
"peerDependencies": {
103-
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8"
104+
"eslint": "^7.2.0 || ^8"
104105
},
105106
"dependencies": {
106-
"array-includes": "^3.1.7",
107-
"array.prototype.findlastindex": "^1.2.3",
108-
"array.prototype.flat": "^1.3.2",
109-
"array.prototype.flatmap": "^1.3.2",
110107
"debug": "^3.2.7",
111108
"doctrine": "^2.1.0",
112109
"eslint-import-resolver-node": "^0.3.9",
113110
"eslint-module-utils": "^2.8.0",
114-
"hasown": "^2.0.0",
115-
"is-core-module": "^2.13.1",
111+
"get-tsconfig": "^4.6.2",
116112
"is-glob": "^4.0.3",
117113
"minimatch": "^3.1.2",
118-
"object.fromentries": "^2.0.7",
119-
"object.groupby": "^1.0.1",
120-
"object.values": "^1.1.7",
121-
"semver": "^6.3.1",
122-
"tsconfig-paths": "^3.14.2"
114+
"resolve": "^1.22.3",
115+
"semver": "^7.5.3"
123116
}
124117
}

resolvers/webpack/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ const fs = require('fs');
99
const isCore = require('is-core-module');
1010
const resolve = require('resolve/sync');
1111
const semver = require('semver');
12-
const hasOwn = require('hasown');
1312
const isRegex = require('is-regex');
1413

1514
const log = require('debug')('eslint-plugin-import:resolver:webpack');
1615

16+
const hasOwn = Function.bind.bind(Function.prototype.call)(Object.prototype.hasOwnProperty);
17+
1718
exports.interfaceVersion = 2;
1819

1920
/**

src/ExportMap.js

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import { dirname } from 'path';
2+
import { resolve as pathResolve } from 'path';
33

44
import doctrine from 'doctrine';
55

@@ -15,11 +15,9 @@ import isIgnored, { hasValidExtension } from 'eslint-module-utils/ignore';
1515
import { hashObject } from 'eslint-module-utils/hash';
1616
import * as unambiguous from 'eslint-module-utils/unambiguous';
1717

18-
import { tsConfigLoader } from 'tsconfig-paths/lib/tsconfig-loader';
18+
import { getTsconfig } from 'get-tsconfig';
1919

20-
import includes from 'array-includes';
21-
22-
let ts;
20+
const includes = Function.bind.bind(Function.prototype.call)(Array.prototype.includes);
2321

2422
const log = debug('eslint-plugin-import:ExportMap');
2523

@@ -548,41 +546,34 @@ ExportMap.parse = function (path, content, context) {
548546

549547
const source = makeSourceCode(content, ast);
550548

551-
function readTsConfig(context) {
552-
const tsconfigInfo = tsConfigLoader({
553-
cwd: context.parserOptions && context.parserOptions.tsconfigRootDir || process.cwd(),
554-
getEnv: (key) => process.env[key],
555-
});
556-
try {
557-
if (tsconfigInfo.tsConfigPath !== undefined) {
558-
// Projects not using TypeScript won't have `typescript` installed.
559-
if (!ts) { ts = require('typescript'); } // eslint-disable-line import/no-extraneous-dependencies
560-
561-
const configFile = ts.readConfigFile(tsconfigInfo.tsConfigPath, ts.sys.readFile);
562-
return ts.parseJsonConfigFileContent(
563-
configFile.config,
564-
ts.sys,
565-
dirname(tsconfigInfo.tsConfigPath),
566-
);
567-
}
568-
} catch (e) {
569-
// Catch any errors
570-
}
571-
572-
return null;
573-
}
574-
575549
function isEsModuleInterop() {
550+
const parserOptions = context.parserOptions || {};
551+
let tsconfigRootDir = parserOptions.tsconfigRootDir;
552+
const project = parserOptions.project;
576553
const cacheKey = hashObject({
577-
tsconfigRootDir: context.parserOptions && context.parserOptions.tsconfigRootDir,
554+
tsconfigRootDir,
555+
project,
578556
}).digest('hex');
579557
let tsConfig = tsconfigCache.get(cacheKey);
580558
if (typeof tsConfig === 'undefined') {
581-
tsConfig = readTsConfig(context);
559+
tsconfigRootDir = tsconfigRootDir || process.cwd();
560+
let tsconfigResult;
561+
if (project) {
562+
const projects = Array.isArray(project) ? project : [project];
563+
for (const project of projects) {
564+
tsconfigResult = getTsconfig(pathResolve(tsconfigRootDir, project));
565+
if (tsconfigResult) {
566+
break;
567+
}
568+
}
569+
} else {
570+
tsconfigResult = getTsconfig(tsconfigRootDir);
571+
}
572+
tsConfig = tsconfigResult && tsconfigResult.config || null;
582573
tsconfigCache.set(cacheKey, tsConfig);
583574
}
584575

585-
return tsConfig && tsConfig.options ? tsConfig.options.esModuleInterop : false;
576+
return tsConfig && tsConfig.compilerOptions ? tsConfig.compilerOptions.esModuleInterop : false;
586577
}
587578

588579
ast.body.forEach(function (n) {

src/core/importType.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { isAbsolute as nodeIsAbsolute, relative, resolve as nodeResolve } from 'path';
2-
import isCoreModule from 'is-core-module';
32

43
import resolve from 'eslint-module-utils/resolve';
54
import { getContextPackagePath } from './packagePath';
5+
import { Module } from 'module';
6+
7+
const isCoreModule = (pkg) => Module.builtinModules.includes(
8+
pkg.startsWith('node:')
9+
? pkg.slice(5)
10+
: pkg,
11+
);
612

713
function baseModule(name) {
814
if (isScoped(name)) {

src/rules/export.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import ExportMap, { recursivePatternCapture } from '../ExportMap';
22
import docsUrl from '../docsUrl';
3-
import includes from 'array-includes';
4-
import flatMap from 'array.prototype.flatmap';
3+
4+
const includes = Function.bind.bind(Function.prototype.call)(Array.prototype.includes);
5+
const flatMap = Function.bind.bind(Function.prototype.call)(Array.prototype.flatMap);
56

67
/*
78
Notes on TypeScript namespaces aka TSModuleDeclaration:

src/rules/exports-last.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
import findLastIndex from 'array.prototype.findlastindex';
2-
31
import docsUrl from '../docsUrl';
42

3+
const findLastIndex = (array, predicate) => {
4+
let i = array.length - 1;
5+
while (i >= 0) {
6+
if (predicate(array[i])) {
7+
return i;
8+
}
9+
i--;
10+
}
11+
return -1;
12+
};
13+
514
function isNonExportStatement({ type }) {
615
return type !== 'ExportDefaultDeclaration'
716
&& type !== 'ExportNamedDeclaration'

src/rules/group-exports.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import docsUrl from '../docsUrl';
2-
import values from 'object.values';
3-
import flat from 'array.prototype.flat';
2+
3+
const { values } = Object;
4+
const flat = Function.bind.bind(Function.prototype.call)(Array.prototype.flat);
45

56
const meta = {
67
type: 'suggestion',

0 commit comments

Comments
 (0)