Skip to content

Commit

Permalink
feat!: bump globby, use synckit for sync fn
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jun 25, 2022
1 parent 1e1b5a6 commit 322cb29
Show file tree
Hide file tree
Showing 13 changed files with 3,135 additions and 3,181 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib
CHANGELOG.md
!/.*.cjs
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"root": true,
"extends": [
"plugin:prettier/recommended",
"plugin:mdx/recommended"
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
15 changes: 10 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
name: CI

on: [push, pull_request]
on:
- push
- pull_request

jobs:
default:
strategy:
matrix:
node:
- 12
- 14
- 16
os: [macOS-latest]
- 18
os:
- macOS-latest
- windows-latest
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: yarn
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
File renamed without changes.
36 changes: 19 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
{
"name": "eslint-import-resolver-typescript",
"version": "2.7.1",
"type": "module",
"description": "TypeScript .ts .tsx module resolver for `eslint-plugin-import`.",
"repository": "https://github.com/alexgorbatchev/eslint-import-resolver-typescript",
"author": "Alex Gorbatchev <alex.gorbatchev@gmail.com>",
"contributors": [
"JounQin <admin@1stg.me>"
],
"license": "ISC",
"packageManager": "yarn@1.22.19",
"engines": {
"node": ">=6"
"node": "^12.20 || ^14.18.0 || >=16.0.0"
},
"main": "lib/index.cjs",
"module": "lib/index.es2015.mjs",
"module": "lib/index.js",
"exports": {
".": {
"require": "./lib/index.cjs",
"import": "./lib/index.es2015.mjs",
"import": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"./package.json": "./package.json"
Expand All @@ -25,7 +27,7 @@
"types": "lib/index.d.ts",
"files": [
"lib",
"!*.tsbuildinfo"
"!**/*.tsbuildinfo"
],
"keywords": [
"typescript",
Expand Down Expand Up @@ -60,39 +62,39 @@
},
"dependencies": {
"debug": "^4.3.4",
"globby": "^11.1.0",
"globby": "^13.1.2",
"is-glob": "^4.0.3",
"resolve": "^1.22.0",
"resolve": "^1.22.1",
"synckit": "^0.7.1",
"tsconfig-paths": "^4.0.0"
},
"devDependencies": {
"@1stg/lib-config": "^5.4.0",
"@1stg/lib-config": "^6.2.3",
"@types/debug": "^4.1.7",
"@types/glob": "^7.2.0",
"@types/is-glob": "^4.0.2",
"@types/node": "^17.0.23",
"@types/resolve": "^1.20.1",
"@types/node": "^18.0.0",
"@types/resolve": "^1.20.2",
"@types/unist": "^2.0.6",
"dummy.js": "link:dummy.js",
"eslint-import-resolver-typescript": "link:.",
"react": "^18.0.0",
"standard-version": "^9.3.2",
"react": "^18.2.0",
"standard-version": "^9.5.0",
"type-coverage": "^2.21.1",
"typescript": "^4.6.3"
"typescript": "^4.7.4"
},
"resolutions": {
"eslint-import-resolver-typescript": "link:.",
"prettier": "^2.6.2"
"prettier": "^2.7.1"
},
"fes2015": "lib/index.es2015.mjs",
"typeCoverage": {
"atLeast": 99.28,
"atLeast": 100,
"cache": true,
"detail": true,
"ignoreAsAssertion": true,
"ignoreNonNullAssertion": true,
"ignoreCatch": true,
"ignoreFiles": [
"**/*.d.ts"
],
"strict": true,
"update": true
}
Expand Down
28 changes: 19 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import path from 'path'
import path from 'node:path'
import { fileURLToPath } from 'node:url'

import debug from 'debug'
import { sync as globSync } from 'globby'
import isGlob from 'is-glob'
import { isCore, sync, SyncOpts } from 'resolve'
import * as _resolve from 'resolve'
import { createSyncFn } from 'synckit'
import {
ConfigLoaderSuccessResult,
createMatchPath,
Expand All @@ -16,6 +17,15 @@ const IMPORTER_NAME = 'eslint-import-resolver-typescript'

const log = debug(IMPORTER_NAME)

const _dirname =
typeof __dirname === 'undefined'
? path.dirname(fileURLToPath(import.meta.url))
: __dirname

const globSync = createSyncFn<typeof import('globby').globby>(
path.resolve(_dirname, 'worker.mjs'),
)

/**
* .mts, .cts, .d.mts, .d.cts, .mjs, .cjs are not included because .cjs and .mjs must be used explicitly.
*/
Expand All @@ -31,7 +41,7 @@ const defaultExtensions = [

export const interfaceVersion = 2

export type TsResolverOptions = SyncOpts & {
export type TsResolverOptions = _resolve.SyncOpts & {
alwaysTryTypes?: boolean
/**
* @deprecated use `project` instead
Expand Down Expand Up @@ -62,7 +72,7 @@ export function resolve(
source = removeQuerystring(source)

// don't worry about core node modules
if (isCore(source)) {
if (_resolve.isCore(source)) {
log('matched core:', source)

return {
Expand Down Expand Up @@ -126,7 +136,7 @@ export function resolve(
}
}

function packageFilterDefault(pkg: Record<string, string>) {
function packageFilterDefault(pkg: _resolve.PackageJSON) {
pkg.main =
pkg.types || pkg.typings || pkg.module || pkg['jsnext:main'] || pkg.main
return pkg
Expand Down Expand Up @@ -162,13 +172,13 @@ function resolveExtension(id: string) {
* Like `sync` from `resolve` package, but considers that the module id
* could have a .js or .jsx extension.
*/
function tsResolve(id: string, opts: SyncOpts): string {
function tsResolve(id: string, opts: _resolve.SyncOpts): string {
try {
return sync(id, opts)
return _resolve.sync(id, opts)
} catch (error) {
const resolved = resolveExtension(id)
if (resolved) {
return sync(resolved.path, {
return _resolve.sync(resolved.path, {
...opts,
extensions: resolved.extensions ?? opts.extensions,
})
Expand Down
12 changes: 12 additions & 0 deletions src/worker.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Options } from 'globby'
import { runAsWorker } from 'synckit'

runAsWorker(
async (
patterns: string | readonly string[],
options: Options & { objectMode: true },
) => {
const { globby } = await import('globby')
return globby(patterns, options)
},
)
4 changes: 4 additions & 0 deletions tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "commonjs",
"private": true
}
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"extends": "./node_modules/@1stg/tsconfig/lib.json",
"extends": "@1stg/tsconfig/node16",
"compilerOptions": {
"baseUrl": ".",
"declarationMap": false,
"outDir": "lib"
},
"include": ["src"]
Expand Down
Loading

0 comments on commit 322cb29

Please sign in to comment.