Skip to content

Commit

Permalink
feat: replace tsconfig-paths + typescript with get-tsconfig
Browse files Browse the repository at this point in the history
feat!: bump `semver`, remove unnecessary dependencies
  • Loading branch information
JounQin committed Dec 18, 2023
1 parent ee5fade commit e1b204b
Show file tree
Hide file tree
Showing 28 changed files with 227 additions and 112 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
9 changes: 9 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "https://unpkg.com/@changesets/config/schema.json",
"commit": false,
"linked": [],
"access": "public",
"baseBranch": "fork-release",
"updateInternalDependencies": "patch",
"ignore": []
}
23 changes: 11 additions & 12 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# These are supported funding model platforms

github: [ljharb]
patreon: # Replace with a single Patreon username
open_collective: eslint-plugin-import # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: npm/eslint-plugin-import
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
github:
- JounQin
- 1stG
- rx-ts
- un-ts
patreon: 1stG
open_collective: unts
custom:
- https://opencollective.com/1stG
- https://opencollective.com/rxts
- https://afdian.net/@JounQin
9 changes: 3 additions & 6 deletions .github/workflows/node-4+.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
with:
versionsAsRoot: true
type: majors
preset: '>= 6' # preset: '>=4' # see https://github.com/import-js/eslint-plugin-import/issues/2053
# preset: '>= 6' # preset: '>=4' # see https://github.com/import-js/eslint-plugin-import/issues/2053
# 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
preset: '>= 12'

latest:
needs: [matrix]
Expand All @@ -31,11 +33,6 @@ jobs:
eslint:
- 8
- 7
- 6
- 5
- 4
- 3
- 2
include:
- node-version: 'lts/*'
eslint: 7
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/rebase-upstream.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Rebase

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
rebase:
name: Rebase and Push
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: fork-release

- name: Set Git Info
run: |
git config --global user.email [email protected]
git config --global user.name JounQin
git remote add upstream https://github.com/import-js/eslint-plugin-import.git
- name: Rebase and Push
run: |
git fetch upstream main:main
git rebase upstream/main
git push -f
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Release

on:
push:
branches:
- fork-release

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install Dependencies
run: npm install

- name: Publish to npm
uses: changesets/action@v1
with:
publish: npx @changesets/cli publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Sync to cnpm
run: npx cnpm sync eslint-plugin-i
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# eslint-plugin-i

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.

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.

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.

Issues related to `get-tsconfig` should be posted here or [`get-tsconfig`] instead, and other issues should be posted to [`eslint-plugin-import`] instead.

[`eslint-plugin-import`]: https://github.com/import-js/eslint-plugin-import
[`get-tsconfig`]: https://github.com/privatenumber/get-tsconfig

## Installation

```bash
$ npm install -D eslint-plugin-import@npm:eslint-plugin-i@latest
```

---

# eslint-plugin-import

[![github actions][actions-image]][actions-url]
Expand Down
38 changes: 15 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "eslint-plugin-import",
"name": "eslint-plugin-i",
"version": "2.29.1",
"description": "Import with sanity.",
"description": "A fork of `eslint-plugin-import` using `get-tsconfig` to replace `tsconfig-paths` and heavy `typescript` under the hood.",
"funding": "https://opencollective.com/unts",
"engines": {
"node": ">=4"
"node": ">=12"
},
"main": "lib/index.js",
"directories": {
Expand All @@ -24,7 +25,7 @@
"copy-metafiles": "node --require babel-register ./scripts/copyMetafiles",
"watch": "npm run tests-only -- -- --watch",
"pretest": "linklocal",
"posttest": "eslint . && npm run update:eslint-docs -- --check && markdownlint \"**/*.md\"",
"posttest": "eslint . && markdownlint \"**/*.md\"",
"mocha": "cross-env BABEL_ENV=test nyc mocha",
"tests-only": "npm run mocha tests/src",
"test": "npm run tests-only",
Expand All @@ -37,7 +38,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/import-js/eslint-plugin-import"
"url": "https://github.com/un-es/eslint-plugin-i"
},
"keywords": [
"eslint",
Expand All @@ -50,11 +51,10 @@
"export"
],
"author": "Ben Mosher <[email protected]>",
"contributors": [
"JounQin (https://www.1stG.me) <[email protected]>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/import-js/eslint-plugin-import/issues"
},
"homepage": "https://github.com/import-js/eslint-plugin-import",
"devDependencies": {
"@angular-eslint/template-parser": "^13.5.0",
"@eslint/import-test-order-redirect-scoped": "file:./tests/files/order-redirect-scoped",
Expand Down Expand Up @@ -86,6 +86,7 @@
"glob": "^7.2.3",
"in-publish": "^2.0.1",
"jackspeak": "=2.1.1",
"is-core-module": "^2.12.1",
"linklocal": "^2.8.2",
"lodash.isarray": "^4.0.0",
"markdownlint-cli": "^0.38.0",
Expand All @@ -100,25 +101,16 @@
"typescript-eslint-parser": "^15 || ^20 || ^22"
},
"peerDependencies": {
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8"
"eslint": "^7.2.0 || ^8"
},
"dependencies": {
"array-includes": "^3.1.7",
"array.prototype.findlastindex": "^1.2.3",
"array.prototype.flat": "^1.3.2",
"array.prototype.flatmap": "^1.3.2",
"debug": "^3.2.7",
"doctrine": "^2.1.0",
"debug": "^4.3.4",
"doctrine": "^3.0.0",
"eslint-import-resolver-node": "^0.3.9",
"eslint-module-utils": "^2.8.0",
"hasown": "^2.0.0",
"is-core-module": "^2.13.1",
"get-tsconfig": "^4.7.2",
"is-glob": "^4.0.3",
"minimatch": "^3.1.2",
"object.fromentries": "^2.0.7",
"object.groupby": "^1.0.1",
"object.values": "^1.1.7",
"semver": "^6.3.1",
"tsconfig-paths": "^3.15.0"
"semver": "^7.5.4"
}
}
3 changes: 2 additions & 1 deletion resolvers/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ const fs = require('fs');
const isCore = require('is-core-module');
const resolve = require('resolve/sync');
const semver = require('semver');
const hasOwn = require('hasown');
const isRegex = require('is-regex');

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

const hasOwn = Function.bind.bind(Function.prototype.call)(Object.prototype.hasOwnProperty);

exports.interfaceVersion = 2;

/**
Expand Down
55 changes: 23 additions & 32 deletions src/ExportMap.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import { dirname } from 'path';
import { resolve as pathResolve } from 'path';

import doctrine from 'doctrine';

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

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

import includes from 'array-includes';

let ts;
const includes = Function.bind.bind(Function.prototype.call)(Array.prototype.includes);

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

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

const source = makeSourceCode(content, ast);

function readTsConfig(context) {
const tsconfigInfo = tsConfigLoader({
cwd: context.parserOptions && context.parserOptions.tsconfigRootDir || process.cwd(),
getEnv: (key) => process.env[key],
});
try {
if (tsconfigInfo.tsConfigPath !== undefined) {
// Projects not using TypeScript won't have `typescript` installed.
if (!ts) { ts = require('typescript'); } // eslint-disable-line import/no-extraneous-dependencies

const configFile = ts.readConfigFile(tsconfigInfo.tsConfigPath, ts.sys.readFile);
return ts.parseJsonConfigFileContent(
configFile.config,
ts.sys,
dirname(tsconfigInfo.tsConfigPath),
);
}
} catch (e) {
// Catch any errors
}

return null;
}

function isEsModuleInterop() {
const parserOptions = context.parserOptions || {};
let tsconfigRootDir = parserOptions.tsconfigRootDir;
const project = parserOptions.project;
const cacheKey = hashObject({
tsconfigRootDir: context.parserOptions && context.parserOptions.tsconfigRootDir,
tsconfigRootDir,
project,
}).digest('hex');
let tsConfig = tsconfigCache.get(cacheKey);
if (typeof tsConfig === 'undefined') {
tsConfig = readTsConfig(context);
tsconfigRootDir = tsconfigRootDir || process.cwd();
let tsconfigResult;
if (project) {
const projects = Array.isArray(project) ? project : [project];
for (const project of projects) {
tsconfigResult = getTsconfig(pathResolve(tsconfigRootDir, project));
if (tsconfigResult) {
break;
}
}
} else {
tsconfigResult = getTsconfig(tsconfigRootDir);
}
tsConfig = tsconfigResult && tsconfigResult.config || null;
tsconfigCache.set(cacheKey, tsConfig);
}

return tsConfig && tsConfig.options ? tsConfig.options.esModuleInterop : false;
return tsConfig && tsConfig.compilerOptions ? tsConfig.compilerOptions.esModuleInterop : false;
}

ast.body.forEach(function (n) {
Expand Down
8 changes: 7 additions & 1 deletion src/core/importType.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { isAbsolute as nodeIsAbsolute, relative, resolve as nodeResolve } from 'path';
import isCoreModule from 'is-core-module';

import resolve from 'eslint-module-utils/resolve';
import { getContextPackagePath } from './packagePath';
import { Module } from 'module';

const isCoreModule = (pkg) => Module.builtinModules.includes(
pkg.startsWith('node:')
? pkg.slice(5)
: pkg,
);

function baseModule(name) {
if (isScoped(name)) {
Expand Down
5 changes: 3 additions & 2 deletions src/rules/export.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import ExportMap, { recursivePatternCapture } from '../ExportMap';
import docsUrl from '../docsUrl';
import includes from 'array-includes';
import flatMap from 'array.prototype.flatmap';

const includes = Function.bind.bind(Function.prototype.call)(Array.prototype.includes);
const flatMap = Function.bind.bind(Function.prototype.call)(Array.prototype.flatMap);

/*
Notes on TypeScript namespaces aka TSModuleDeclaration:
Expand Down
13 changes: 11 additions & 2 deletions src/rules/exports-last.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import findLastIndex from 'array.prototype.findlastindex';

import docsUrl from '../docsUrl';

const findLastIndex = (array, predicate) => {
let i = array.length - 1;
while (i >= 0) {
if (predicate(array[i])) {
return i;
}
i--;
}
return -1;
};

function isNonExportStatement({ type }) {
return type !== 'ExportDefaultDeclaration'
&& type !== 'ExportNamedDeclaration'
Expand Down
5 changes: 3 additions & 2 deletions src/rules/group-exports.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import docsUrl from '../docsUrl';
import values from 'object.values';
import flat from 'array.prototype.flat';

const { values } = Object;
const flat = Function.bind.bind(Function.prototype.call)(Array.prototype.flat);

const meta = {
type: 'suggestion',
Expand Down
Loading

0 comments on commit e1b204b

Please sign in to comment.