@interlace/eslint-devkit 2.2.0 → 2.3.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interlace/eslint-devkit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "ESLint plugin toolkit for building ESLint plugins in TypeScript — AST helpers, type utilities, rule-creation scaffolding, security benchmarks, and SARIF output.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
3
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
4
|
+
* MIT license that can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
interface FallbackOptions {
|
|
7
|
+
extensions?: string[];
|
|
8
|
+
conditionNames?: string[];
|
|
9
|
+
mainFields?: string[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resolve a non-relative specifier without `oxc-resolver`.
|
|
13
|
+
* Order matches oxc-resolver: tsconfig paths / baseUrl first, then node_modules.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveWithoutOxc(specifier: string, fromFile: string, tsconfigPath: string | null, options?: FallbackOptions): string | null;
|
|
16
|
+
export declare function clearFallbackCache(): void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.resolveWithoutOxc=resolveWithoutOxc;exports.clearFallbackCache=clearFallbackCache;const node_module_1=require("node:module");const fs_1=require("../node/fs");const path_1=require("../node/path");const DEFAULT_EXTENSIONS=[".ts",".tsx",".js",".jsx",".d.ts",".json"];const DEFAULT_CONDITIONS=["import","require","node","default","types"];function isFile(p){const s=(0,fs_1.statSync)(p);return!!s&&s.isFile()}function probe(p,extensions){if(isFile(p))return p;for(const ext of extensions)if(isFile(p+ext))return p+ext;for(const ext of extensions){const idx=(0,path_1.joinPath)(p,`index${ext}`);if(isFile(idx))return idx}return null}function parseJsonc(text){let out="";let i=0;while(i<text.length){const c=text[i];if(c==='"'){let j=i+1;while(j<text.length&&text[j]!=='"')j+=text[j]==="\\"?2:1;out+=text.slice(i,j+1);i=j+1}else if(c==="/"&&text[i+1]==="/"){while(i<text.length&&text[i]!=="\n")i++}else if(c==="/"&&text[i+1]==="*"){const end=text.indexOf("*/",i+2);i=end===-1?text.length:end+2}else{out+=c;i++}}try{return JSON.parse(out.replace(/,(\s*[}\]])/g,"$1"))}catch{return null}}const tsconfigCache=new Map;function loadPathsConfig(tsconfigPath,depth=0){const cached=tsconfigCache.get(tsconfigPath);if(cached)return cached;const dir=(0,path_1.getDirname)(tsconfigPath);const empty={baseUrl:null,paths:null,pathsDir:dir};const text=(0,fs_1.readFileSync)(tsconfigPath);const json=text===null?null:parseJsonc(text);if(!json)return empty;let result={...empty};const ext=json["extends"];if(typeof ext==="string"&&ext.startsWith(".")&&depth<8){const target=(0,path_1.resolvePath)(dir,ext.endsWith(".json")?ext:ext+".json");result={...loadPathsConfig(target,depth+1)}}const co=json["compilerOptions"]??{};if(typeof co["baseUrl"]==="string"){result.baseUrl=(0,path_1.resolvePath)(dir,co["baseUrl"])}if(co["paths"]&&typeof co["paths"]==="object"){result.paths=co["paths"];result.pathsDir=result.baseUrl??dir}tsconfigCache.set(tsconfigPath,result);return result}function resolveViaTsconfig(specifier,tsconfigPath,extensions){const cfg=loadPathsConfig(tsconfigPath);if(cfg.paths){for(const[pattern,targets]of Object.entries(cfg.paths)){const star=pattern.indexOf("*");let captured=null;if(star===-1){if(pattern===specifier)captured=""}else{const pre=pattern.slice(0,star);const post=pattern.slice(star+1);if(specifier.length>=pre.length+post.length&&specifier.startsWith(pre)&&specifier.endsWith(post)){captured=specifier.slice(pre.length,specifier.length-post.length)}}if(captured===null)continue;for(const target of targets){const hit=probe((0,path_1.resolvePath)(cfg.pathsDir,target.replace("*",captured)),extensions);if(hit)return hit}}}if(cfg.baseUrl){const hit=probe((0,path_1.resolvePath)(cfg.baseUrl,specifier),extensions);if(hit)return hit}return null}function splitPackage(spec){const parts=spec.split("/");const n=spec.startsWith("@")?2:1;if(parts.length<n||parts.slice(0,n).some(p=>!p))return null;return{name:parts.slice(0,n).join("/"),sub:parts.slice(n).join("/")}}function pickExport(target,conditions,star){if(typeof target==="string"){return star===null?target:target.replace("*",star)}if(Array.isArray(target)){for(const t of target){const r=pickExport(t,conditions,star);if(r)return r}return null}if(target&&typeof target==="object"){for(const[key,value]of Object.entries(target)){if(conditions.includes(key)){const r=pickExport(value,conditions,star);if(r)return r}}}return null}function matchSubpathMap(map,key,conditions){if(key in map)return pickExport(map[key],conditions,null);for(const[pattern,target]of Object.entries(map)){const star=pattern.indexOf("*");if(star===-1)continue;const pre=pattern.slice(0,star);const post=pattern.slice(star+1);if(key.startsWith(pre)&&key.endsWith(post)&&key.length>=pre.length+post.length){const rel=pickExport(target,conditions,key.slice(pre.length,key.length-post.length));if(rel)return rel}}return null}function resolveFromPackageDir(pkgDir,sub,opts){const pkgJsonText=(0,fs_1.readFileSync)((0,path_1.joinPath)(pkgDir,"package.json"));let pkg={};if(pkgJsonText){try{pkg=JSON.parse(pkgJsonText)}catch{return null}}const key=sub?`./${sub}`:".";const exportsField=pkg["exports"];if(exportsField!==void 0&&exportsField!==null){const isSubpathMap=typeof exportsField==="object"&&!Array.isArray(exportsField)&&Object.keys(exportsField).some(k=>k.startsWith("."));const map=isSubpathMap?exportsField:{".":exportsField};const rel=matchSubpathMap(map,key,opts.conditionNames);return rel?probe((0,path_1.resolvePath)(pkgDir,rel),[]):null}if(sub)return probe((0,path_1.joinPath)(pkgDir,sub),opts.extensions);for(const field of[...opts.mainFields,"types","typings"]){const v=pkg[field];if(typeof v==="string"){const hit=probe((0,path_1.resolvePath)(pkgDir,v),opts.extensions);if(hit)return hit}}return probe(pkgDir,opts.extensions)}const RELATIVE=/^\.\.?(\/|$)/;function resolveRelative(specifier,fromFile,extensions){const cut=specifier.search(/[?#]/);const bare=cut===-1?specifier:specifier.slice(0,cut);const hit=probe((0,path_1.resolvePath)((0,path_1.getDirname)(fromFile),bare),extensions);return hit===null||cut===-1?hit:hit+specifier.slice(cut)}function resolveViaNodeModules(specifier,fromFile,opts){try{return(0,node_module_1.createRequire)(fromFile).resolve(specifier)}catch{}const parts=splitPackage(specifier);if(!parts)return null;let dir=(0,path_1.getDirname)(fromFile);for(;;){const pkgDir=(0,path_1.joinPath)(dir,"node_modules",parts.name);if((0,fs_1.fileExistsSync)(pkgDir)){const hit=resolveFromPackageDir(pkgDir,parts.sub,opts);if(hit)return hit}const parent=(0,path_1.getDirname)(dir);if(parent===dir)return null;dir=parent}}function resolveViaImportsMap(specifier,fromFile,opts){const pkgPath=(0,fs_1.findFileUpward)("package.json",(0,path_1.getDirname)(fromFile));const text=pkgPath===null?null:(0,fs_1.readFileSync)(pkgPath);if(pkgPath===null||text===null)return null;let imports;try{imports=JSON.parse(text)["imports"]}catch{return null}if(!imports||typeof imports!=="object")return null;const rel=matchSubpathMap(imports,specifier,opts.conditionNames);if(rel===null)return null;return rel.startsWith(".")?probe((0,path_1.resolvePath)((0,path_1.getDirname)(pkgPath),rel),[]):resolveViaNodeModules(rel,pkgPath,opts)}function resolveWithoutOxc(specifier,fromFile,tsconfigPath,options={}){const opts={extensions:options.extensions??DEFAULT_EXTENSIONS,conditionNames:options.conditionNames??DEFAULT_CONDITIONS,mainFields:options.mainFields??["module","main"]};if((0,node_module_1.isBuiltin)(specifier))return null;if(specifier.startsWith("#")){return resolveViaImportsMap(specifier,fromFile,opts)}if(RELATIVE.test(specifier)){return resolveRelative(specifier,fromFile,opts.extensions)}if(specifier.startsWith("/"))return probe(specifier,opts.extensions);if(tsconfigPath){const hit=resolveViaTsconfig(specifier,tsconfigPath,opts.extensions);if(hit)return hit}return resolveViaNodeModules(specifier,fromFile,opts)}function clearFallbackCache(){tsconfigCache.clear()}
|
|
@@ -20,12 +20,9 @@ export interface ResolverOptions {
|
|
|
20
20
|
cssSupport?: boolean;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* failures and returns `null` (an unresolvable import is normal), and a
|
|
27
|
-
* missing peer must NOT disappear down that path — it would turn every
|
|
28
|
-
* import into a silent non-resolution instead of a fixable install error.
|
|
23
|
+
* @deprecated The resolver no longer throws this; it falls back to a
|
|
24
|
+
* dependency-free resolver when `oxc-resolver` is absent. Kept only so
|
|
25
|
+
* existing imports keep compiling.
|
|
29
26
|
*/
|
|
30
27
|
export declare class MissingResolverPeerError extends Error {
|
|
31
28
|
readonly name = "MissingResolverPeerError";
|
package/src/resolver/resolver.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.MissingResolverPeerError=void 0;exports.getResolverPerformanceMetrics=getResolverPerformanceMetrics;exports.resolveModule=resolveModule;exports.clearResolverCache=clearResolverCache;const fs_1=require("../node/fs");const path_1=require("../node/path");const resolver_adapter_1=require("./resolver-adapter");const oxcResolverCache=new Map;let factoryRef;class MissingResolverPeerError extends Error{name="MissingResolverPeerError"}exports.MissingResolverPeerError=MissingResolverPeerError;function loadResolverFactory(){if(factoryRef){return factoryRef}try{factoryRef=require("oxc-resolver").ResolverFactory}catch
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.MissingResolverPeerError=void 0;exports.getResolverPerformanceMetrics=getResolverPerformanceMetrics;exports.resolveModule=resolveModule;exports.clearResolverCache=clearResolverCache;const fs_1=require("../node/fs");const path_1=require("../node/path");const resolver_fallback_1=require("./resolver-fallback");const resolver_adapter_1=require("./resolver-adapter");const oxcResolverCache=new Map;let factoryRef;let factoryMissing=false;class MissingResolverPeerError extends Error{name="MissingResolverPeerError"}exports.MissingResolverPeerError=MissingResolverPeerError;function loadResolverFactory(){if(factoryRef){return factoryRef}if(factoryMissing){return null}try{factoryRef=require("oxc-resolver").ResolverFactory;return factoryRef}catch{factoryMissing=true;return null}}const tsconfigPathCache=new Map;function findTsconfigPath(fromFile){const startDir=(0,path_1.getDirname)(fromFile);const cached=tsconfigPathCache.get(startDir);if(cached!==void 0){return cached}const result=(0,fs_1.findFileUpward)("tsconfig.json",startDir);let dir=startDir;const root=(0,path_1.resolvePath)("/");while(dir!==root){tsconfigPathCache.set(dir,result);if(result&&(0,path_1.getDirname)(result)===dir)break;const parent=(0,path_1.getDirname)(dir);if(parent===dir)break;dir=parent}return result}function getOxcResolver(options,fromFile){const extensions=options.extensions||[".ts",".tsx",".js",".jsx",".d.ts",".json",".node"];const conditionNames=options.conditionNames||["import","require","node","default","types"];const mainFields=options.mainFields||["module","main"];const tsconfigPath=findTsconfigPath(fromFile);const key=`${extensions.join(",")}|${conditionNames.join(",")}|${mainFields.join(",")}|${tsconfigPath||""}`;const cached=oxcResolverCache.get(key);if(cached){return cached}const resolverOptions={extensions,conditionNames,mainFields,mainFiles:["index"],modules:["node_modules"]};if(tsconfigPath){resolverOptions["tsconfig"]={configFile:tsconfigPath,references:"auto"}}const ResolverFactory=loadResolverFactory();if(!ResolverFactory)return null;const resolver=new ResolverFactory(resolverOptions);oxcResolverCache.set(key,resolver);return resolver}function isCssImport(importPath){if(/\.(css|scss|sass|less|styl)$/i.test(importPath)){return true}if(importPath.startsWith("./")||importPath.startsWith("../")){return!/\.\w+$/.test(importPath)}return false}function resolveCssImport(importPath,fromFile){const fromDir=(0,path_1.getDirname)(fromFile);if(importPath.startsWith(".")){const resolved=(0,path_1.resolvePath)(fromDir,importPath);if((0,fs_1.fileExistsSync)(resolved)){const stats=(0,fs_1.statSync)(resolved);if(stats&&stats.isFile()){return resolved}}const cssExtensions=[".css",".scss",".sass",".less",".styl"];for(const ext of cssExtensions){const withExt=resolved+ext;if((0,fs_1.fileExistsSync)(withExt)){const stats=(0,fs_1.statSync)(withExt);if(stats&&stats.isFile()){return withExt}}}for(const ext of cssExtensions){const indexFile=(0,path_1.joinPath)(resolved,`index${ext}`);if((0,fs_1.fileExistsSync)(indexFile)){const stats=(0,fs_1.statSync)(indexFile);if(stats&&stats.isFile()){return indexFile}}}}return null}function getResolverPerformanceMetrics(){return[]}const NODENEXT_SOURCE_EXTENSIONS={".js":[".ts",".tsx"],".mjs":[".mts"],".cjs":[".cts"]};function resolveModule(importPath,fromFile,options={}){try{if(importPath.startsWith(".")&&!(options.cssSupport&&isCssImport(importPath))){const context2=(0,path_1.getDirname)(fromFile);const defaultExtensions=[".ts",".tsx",".js",".jsx",".d.ts",".json"];const extensions=options.extensions||defaultExtensions;const resolved=(0,path_1.resolvePath)(context2,importPath);const exactStats=(0,fs_1.statSync)(resolved);if(exactStats&&exactStats.isFile()){return resolved}for(const[outputExt,sourceExts]of Object.entries(NODENEXT_SOURCE_EXTENSIONS)){if(!resolved.endsWith(outputExt))continue;const stem=resolved.slice(0,-outputExt.length);for(const ext of sourceExts){if((0,fs_1.fileExistsSync)(stem+ext)){return stem+ext}}}for(const ext of extensions){if((0,fs_1.fileExistsSync)(resolved+ext)){return resolved+ext}}for(const ext of extensions){const indexFile=(0,path_1.joinPath)(resolved,`index${ext}`);if((0,fs_1.fileExistsSync)(indexFile)){return indexFile}}}if(options.resolverSettings){const externalResult=(0,resolver_adapter_1.resolveWithExternalResolvers)(importPath,fromFile,options.resolverSettings);if(externalResult){return externalResult}}if(options.cssSupport&&isCssImport(importPath)){const cssResult=resolveCssImport(importPath,fromFile);if(cssResult){return cssResult}}const resolver=getOxcResolver(options,fromFile);const context=(0,path_1.getDirname)(fromFile);if(!resolver){return(0,resolver_fallback_1.resolveWithoutOxc)(importPath,fromFile,findTsconfigPath(fromFile),options)}try{const result=resolver.sync(context,importPath);if(result&&result.path){return result.path}}catch{}return null}catch{return null}}function clearResolverCache(){for(const resolver of oxcResolverCache.values()){resolver.clearCache()}oxcResolverCache.clear();tsconfigPathCache.clear();(0,resolver_fallback_1.clearFallbackCache)()}
|