@rsdoctor/utils 1.5.8 → 1.5.10

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.
Files changed (55) hide show
  1. package/dist/build/envinfo.d.cts +13 -0
  2. package/dist/build/file/cache.d.cts +5 -0
  3. package/dist/build/file/index.d.cts +3 -0
  4. package/dist/build/file/sharding.d.cts +21 -0
  5. package/dist/build/index.d.cts +5 -0
  6. package/dist/build/json.d.cts +3 -0
  7. package/dist/build/process.d.cts +2 -0
  8. package/dist/build/server.d.cts +14 -0
  9. package/dist/common/alerts.d.cts +2 -0
  10. package/dist/common/algorithm.d.cts +4 -0
  11. package/dist/common/bundle.d.cts +3 -0
  12. package/dist/common/crypto.d.cts +2 -0
  13. package/dist/common/data/index.d.cts +10 -0
  14. package/dist/common/decycle.d.cts +10 -0
  15. package/dist/common/fetch.d.cts +10 -0
  16. package/dist/common/file.d.cts +2 -0
  17. package/dist/common/global-config.d.cts +21 -0
  18. package/dist/common/graph/assets.d.cts +56 -0
  19. package/dist/common/graph/bundle-diff.d.cts +16 -0
  20. package/dist/common/graph/chunk.d.cts +7 -0
  21. package/dist/common/graph/dependency.d.cts +4 -0
  22. package/dist/common/graph/entrypoints.d.cts +2 -0
  23. package/dist/common/graph/index.d.cts +6 -0
  24. package/dist/common/graph/modules.d.cts +9 -0
  25. package/dist/common/index.d.cts +20 -0
  26. package/dist/common/loader.d.cts +22 -0
  27. package/dist/common/lodash.d.cts +10 -0
  28. package/dist/common/manifest.d.cts +4 -0
  29. package/dist/common/package.d.cts +7 -0
  30. package/dist/common/plugin.d.cts +5 -0
  31. package/dist/common/resolver.d.cts +6 -0
  32. package/dist/common/rspack.d.cts +17 -0
  33. package/dist/common/summary.d.cts +6 -0
  34. package/dist/common/time.d.cts +4 -0
  35. package/dist/common/url.d.cts +3 -0
  36. package/dist/common.cjs +7 -4
  37. package/dist/common.js +7 -4
  38. package/dist/error/error.d.cts +35 -0
  39. package/dist/error/index.d.cts +2 -0
  40. package/dist/error/transform.d.cts +3 -0
  41. package/dist/error/utils.d.cts +4 -0
  42. package/dist/logger.d.cts +9 -0
  43. package/dist/rule-utils/document/document.d.cts +16 -0
  44. package/dist/rule-utils/document/index.d.cts +3 -0
  45. package/dist/rule-utils/document/server.d.cts +4 -0
  46. package/dist/rule-utils/document/types.d.cts +31 -0
  47. package/dist/rule-utils/index.d.cts +2 -0
  48. package/dist/rule-utils/parser/asserts.d.cts +81 -0
  49. package/dist/rule-utils/parser/index.d.cts +4 -0
  50. package/dist/rule-utils/parser/parser.d.cts +118 -0
  51. package/dist/rule-utils/parser/types.d.cts +30 -0
  52. package/dist/rule-utils/parser/utils.d.cts +30 -0
  53. package/dist/ruleUtils.cjs +2 -2
  54. package/dist/ruleUtils.js +2 -2
  55. package/package.json +42 -17
@@ -0,0 +1,13 @@
1
+ export declare const getCPUInfo: () => Promise<string>;
2
+ export declare const getOSInfo: () => Promise<string>;
3
+ export declare const getMemoryInfo: () => Promise<string>;
4
+ export declare const getNodeVersion: () => Promise<string>;
5
+ export declare const getYarnVersion: () => Promise<string>;
6
+ export declare const getNpmVersion: () => Promise<string>;
7
+ export declare const getPnpmVersion: () => Promise<string>;
8
+ export declare function getNpmPackageVersion(pkg: string): Promise<string>;
9
+ export declare function getNpmPackageVersion(pkgs: string[]): Promise<string[]>;
10
+ export declare function getGlobalNpmPackageVersion(pkg: string): Promise<string>;
11
+ export declare function getGlobalNpmPackageVersion(pkgs: string[]): Promise<string[]>;
12
+ export declare function getGitBranch(): Promise<string>;
13
+ export declare function getGitRepo(): Promise<string>;
@@ -0,0 +1,5 @@
1
+ import { Common } from '@rsdoctor/types';
2
+ export declare function readFile(path: string): Promise<string>;
3
+ export declare function readFileSync(path: string): string;
4
+ export declare function readJSON<T extends Common.PlainObject>(path: string): Promise<T>;
5
+ export declare function readJSONSync<T extends Common.PlainObject>(path: string): T;
@@ -0,0 +1,3 @@
1
+ export * from './sharding';
2
+ export * as fse from 'fs-extra';
3
+ export * as cache from './cache';
@@ -0,0 +1,21 @@
1
+ export declare class FileSharding {
2
+ protected content: string;
3
+ protected limitBytes: number;
4
+ protected encoding: BufferEncoding;
5
+ constructor(content: string, limitBytes?: number, encoding?: BufferEncoding);
6
+ /**
7
+ * @param ext the extension name of the output file (must starts with ".")
8
+ */
9
+ createVirtualShardingFiles(ext?: string, index?: number): {
10
+ filename: string;
11
+ content: Buffer<ArrayBufferLike>;
12
+ }[];
13
+ /**
14
+ * @param folder absolute path of folder which used to save string sharding files.
15
+ * @param ext the extension name of the output file (must starts with ".")
16
+ */
17
+ writeStringToFolder(folder: string, ext?: string, index?: number): Promise<{
18
+ filename: string;
19
+ content: Buffer<ArrayBufferLike>;
20
+ }[]>;
21
+ }
@@ -0,0 +1,5 @@
1
+ export * as File from './file';
2
+ export * as Json from './json';
3
+ export * as Server from './server';
4
+ export * as EnvInfo from './envinfo';
5
+ export * as Process from './process';
@@ -0,0 +1,3 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ export declare function stringify<T, P = T extends undefined ? undefined : string>(json: T, replacer?: (this: any, key: string, value: any) => any, space?: string | number, cycle?: boolean): Promise<P>;
3
+ export declare const readPackageJson: (file: string, readFile?: SDK.GetPackageFile) => SDK.PackageBasicData | undefined;
@@ -0,0 +1,2 @@
1
+ export declare function getMemoryUsage(): NodeJS.MemoryUsage;
2
+ export declare function getMemoryUsageMessage(): string;
@@ -0,0 +1,14 @@
1
+ import connect from 'connect';
2
+ import http from 'http';
3
+ import { Thirdparty } from '@rsdoctor/types';
4
+ export declare const defaultPort: number;
5
+ export declare function getPort(expectPort: number): Promise<number>;
6
+ export declare const createGetPortSyncFunctionString: (expectPort: number) => string;
7
+ export declare function getPortSync(expectPort: number): number | never;
8
+ export declare function createApp(): connect.Server;
9
+ export declare function createServer(port: number): Promise<{
10
+ app: Thirdparty.connect.Server;
11
+ server: http.Server;
12
+ port: number;
13
+ close(): Promise<void> | never;
14
+ }>;
@@ -0,0 +1,2 @@
1
+ import { Rule, SDK } from '@rsdoctor/types';
2
+ export declare function getPackageRelationAlertDetails(modules: SDK.ModuleGraphData['modules'], dependencies: SDK.ModuleGraphData['dependencies'], root: string, packageDependencies: Rule.DependencyWithPackageData[], moduleCodeMap: SDK.ModuleCodeData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetPackageRelationAlertDetails>;
@@ -0,0 +1,4 @@
1
+ export declare function mergeIntervals(intervals: [number, number][]): [number, number][];
2
+ export declare function compressText(input: string): string;
3
+ export declare function decompressText(input: string): string;
4
+ export declare function random(min: number, max: number): number;
@@ -0,0 +1,3 @@
1
+ export declare function getBundleDiffPageQueryString(files: string[]): string;
2
+ export declare function getBundleDiffPageUrl(files: string[]): string;
3
+ export declare function parseFilesFromBundlePageUrlQuery(queryValue: string): string[];
@@ -0,0 +1,2 @@
1
+ export declare function encode(str: string): string;
2
+ export declare function decode(str: string): string;
@@ -0,0 +1,10 @@
1
+ import { SDK, Manifest } from '@rsdoctor/types';
2
+ /**
3
+ * this class will run at both browser and node environment.
4
+ */
5
+ export declare class APIDataLoader {
6
+ protected loader: Manifest.ManifestDataLoader;
7
+ constructor(loader: Manifest.ManifestDataLoader);
8
+ log(...args: unknown[]): void;
9
+ loadAPI<T extends SDK.ServerAPI.API, B extends SDK.ServerAPI.InferRequestBodyType<T> = SDK.ServerAPI.InferRequestBodyType<T>, R extends SDK.ServerAPI.InferResponseType<T> = SDK.ServerAPI.InferResponseType<T>>(...args: B extends void ? [api: T] : [api: T, body: B]): Promise<SDK.ServerAPI.InferResponseType<T>>;
10
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The following code is based on
3
+ * https://github.com/valery-barysok/json-cycle/blob/master/cycle.js
4
+ *
5
+ *
6
+ * MIT Licensed
7
+ * Author juliyvchirkov
8
+ * https://github.com/valery-barysok/json-cycle?tab=MIT-1-ov-file
9
+ */
10
+ export declare function decycle<T = any>(object: T): T;
@@ -0,0 +1,10 @@
1
+ export declare function getFetch(): typeof fetch;
2
+ export interface FetchOptions {
3
+ timeout?: number;
4
+ method?: string;
5
+ headers?: Record<string, string>;
6
+ body?: string;
7
+ signal?: AbortSignal;
8
+ }
9
+ export declare function fetchWithTimeout(url: string, options?: FetchOptions): Promise<Response>;
10
+ export declare function postJSON(url: string, body: unknown, timeout?: number): Promise<Response>;
@@ -0,0 +1,2 @@
1
+ export declare function isStyleExt(path: string): boolean;
2
+ export declare function isJsExt(path: string): boolean;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @description Writes the builder port information to mcp.json.
3
+ *
4
+ * The mcp.json file uses the following format:
5
+ * {
6
+ * portList: {
7
+ * builder1: portNumber,
8
+ * builder2: portNumber,
9
+ * },
10
+ * port: portNumber // The port of the last builder is used by default
11
+ * }
12
+ *
13
+ * @param {number} port - The port number to write.
14
+ * @param {string} [builderName] - The name of the builder.
15
+ */
16
+ export declare function writeMcpPort(port: number, builderName?: string): void;
17
+ /**
18
+ * @description Gets the path to the mcp.json file.
19
+ * @returns {string} The path to the mcp.json file.
20
+ */
21
+ export declare function getMcpConfigPath(): string;
@@ -0,0 +1,56 @@
1
+ import { Client, SDK } from '@rsdoctor/types';
2
+ export declare function formatAssetName(assetName: string, fileConfig?: string): string;
3
+ export declare function isAssetMatchExtension(asset: SDK.AssetData, ext: string): boolean;
4
+ export declare function isAssetMatchExtensions(asset: SDK.AssetData, exts: string[]): boolean;
5
+ export declare function filterAssetsByExtensions(assets: SDK.AssetData[], exts: string | string[]): SDK.AssetData[];
6
+ type FilterFunctionOrExtensions = string | string[] | ((asset: SDK.AssetData) => boolean);
7
+ interface GetAssetsOptions {
8
+ /**
9
+ * turn off it when you need not file content.
10
+ * @default true
11
+ */
12
+ withFileContent?: boolean;
13
+ /**
14
+ * filter with assets
15
+ */
16
+ filterOrExtensions?: FilterFunctionOrExtensions;
17
+ }
18
+ export declare function filterAssets(assets: SDK.AssetData[], filterOrExtensions?: FilterFunctionOrExtensions): SDK.AssetData[];
19
+ export declare function getAssetsSizeInfo(assets: SDK.AssetData[], chunks: SDK.ChunkData[], options?: GetAssetsOptions): {
20
+ count: number;
21
+ size: number;
22
+ files: {
23
+ path: string;
24
+ size: number;
25
+ gzipSize: number | undefined;
26
+ initial: boolean;
27
+ content: string | undefined;
28
+ }[];
29
+ };
30
+ export declare function isInitialAsset(asset: SDK.AssetData, chunks: SDK.ChunkData[]): boolean;
31
+ export declare function getInitialAssetsSizeInfo(assets: SDK.AssetData[], chunks: SDK.ChunkData[], options?: GetAssetsOptions): {
32
+ count: number;
33
+ size: number;
34
+ files: {
35
+ path: string;
36
+ size: number;
37
+ gzipSize: number | undefined;
38
+ initial: boolean;
39
+ content: string | undefined;
40
+ }[];
41
+ };
42
+ export declare function getAssetsDiffResult(baseline: SDK.ChunkGraphData, current: SDK.ChunkGraphData): Client.RsdoctorClientAssetsDiffResult;
43
+ /**
44
+ * @param bSize size of baseline
45
+ * @param cSize size of current
46
+ */
47
+ export declare function diffSize(bSize: number, cSize: number): {
48
+ percent: number;
49
+ state: Client.RsdoctorClientDiffState;
50
+ };
51
+ export declare function diffAssetsByExtensions(baseline: SDK.ChunkGraphData, current: SDK.ChunkGraphData, filterOrExtensions?: FilterFunctionOrExtensions, isInitial?: boolean): Client.RsdoctorClientAssetsDiffItem;
52
+ export declare function getAssetsSummary(assets: SDK.AssetData[], chunks: SDK.ChunkData[], options?: Omit<GetAssetsOptions, 'filterOrExtensions'>): Client.RsdoctorClientAssetsSummary;
53
+ export declare function getAssetDetails(assetPath: string, assets: SDK.AssetData[], chunks: SDK.ChunkData[], modules: SDK.ModuleData[], checkModules: (module: SDK.ModuleData) => boolean): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetAssetDetails>;
54
+ export declare function getAllBundleData(assets: SDK.AssetData[], chunks: SDK.ChunkData[], modules: SDK.ModuleData[], filtersModules?: (keyof SDK.ModuleData)[]): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetSummaryBundles>;
55
+ export declare function extname(filename: string): string;
56
+ export {};
@@ -0,0 +1,16 @@
1
+ import { Client, SDK } from '@rsdoctor/types';
2
+ /**
3
+ * Compute module diff between baseline and current.
4
+ * Modules are matched by their file path.
5
+ */
6
+ export declare function getModulesDiffResult(baseline: SDK.ModuleGraphData, current: SDK.ModuleGraphData): Client.RsdoctorClientModulesDiffResult;
7
+ /**
8
+ * Compute package diff between baseline and current.
9
+ * Packages are matched by name@version.
10
+ */
11
+ export declare function getPackagesDiffResult(baseline: SDK.PackageGraphData, current: SDK.PackageGraphData): Client.RsdoctorClientPackagesDiffResult;
12
+ /**
13
+ * Compute the full bundle diff result between baseline and current manifest data.
14
+ * Combines asset, module, and package diffs into a single result.
15
+ */
16
+ export declare function getBundleDiffResult(baseline: SDK.BuilderStoreData, current: SDK.BuilderStoreData): Client.RsdoctorClientBundleDiffResult;
@@ -0,0 +1,7 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ export declare function getChunkIdsByAsset(asset: SDK.AssetData): string[];
3
+ export declare function getChunksByModule(module: SDK.ModuleData, chunks: SDK.ChunkData[]): SDK.ChunkData[];
4
+ export declare function getChunkByChunkId(chunkId: string, chunks: SDK.ChunkData[]): SDK.ChunkData;
5
+ export declare function getChunksByChunkIds(chunkIds: string[], chunks: SDK.ChunkData[], filters?: (keyof SDK.ChunkData)[]): SDK.ChunkData[];
6
+ export declare function getChunksByAsset(asset: SDK.AssetData, chunks: SDK.ChunkData[], filters?: (keyof SDK.ChunkData)[]): SDK.ChunkData[];
7
+ export declare function getChunksByModuleId(id: number, modules: SDK.ModuleData[], chunks: SDK.ChunkData[]): SDK.ChunkData[];
@@ -0,0 +1,4 @@
1
+ import { Rule, SDK } from '@rsdoctor/types';
2
+ export declare function getDependencyByPackageData(dep: Rule.DependencyWithPackageData, dependencies: SDK.DependencyData[]): SDK.DependencyData | undefined;
3
+ export declare function getDependenciesByModule(module: SDK.ModuleData, dependencies: SDK.DependencyData[]): SDK.DependencyData[];
4
+ export declare function getDependencyByResolvedRequest(resolvedRequest: string, dependencies: SDK.DependencyData[]): SDK.DependencyData | undefined;
@@ -0,0 +1,2 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ export declare function getEntryPoints(entrypoints: SDK.EntryPointData[]): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetEntryPoints>;
@@ -0,0 +1,6 @@
1
+ export * from './assets';
2
+ export * from './bundle-diff';
3
+ export * from './chunk';
4
+ export * from './modules';
5
+ export * from './dependency';
6
+ export * from './entrypoints';
@@ -0,0 +1,9 @@
1
+ import { Rule, SDK } from '@rsdoctor/types';
2
+ export declare function getModulesByAsset(asset: SDK.AssetData, chunks: SDK.ChunkData[], modules: SDK.ModuleData[], filterModules?: (keyof SDK.ModuleData)[], checkModules?: (module: SDK.ModuleData) => boolean): SDK.ModuleData[];
3
+ export declare function getModuleIdsByChunk(chunk: SDK.ChunkData): number[];
4
+ export declare function getModuleIdsByModulesIds(moduleIds: number[], modules: SDK.ModuleData[]): SDK.ModuleData[];
5
+ export declare function getModulesByChunk(chunk: SDK.ChunkData, modules: SDK.ModuleData[], filterModules?: (keyof SDK.ModuleData)[]): SDK.ModuleData[];
6
+ export declare function getModulesByChunks(chunks: SDK.ChunkData[], modules: SDK.ModuleData[], filterModules?: (keyof SDK.ModuleData)[], checkModules?: (module: SDK.ModuleData) => boolean): SDK.ModuleData[];
7
+ export declare function getModuleByDependency(dep: SDK.DependencyData, modules: SDK.ModuleData[]): SDK.ModuleData | undefined;
8
+ export declare function filterModulesAndDependenciesByPackageDeps(deps: Rule.DependencyWithPackageData[], dependencies: SDK.DependencyData[], modules: SDK.ModuleData[]): Pick<SDK.ModuleGraphData, 'dependencies' | 'modules'>;
9
+ export declare function getModuleDetails(moduleId: number, modules: SDK.ModuleData[], dependencies: SDK.DependencyData[], sideEffectCodes?: SDK.SideEffectCodeData[]): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetModuleDetails>;
@@ -0,0 +1,20 @@
1
+ export * as Summary from './summary';
2
+ export * as Crypto from './crypto';
3
+ export * as Manifest from './manifest';
4
+ export * as Loader from './loader';
5
+ export * as Time from './time';
6
+ export * as Algorithm from './algorithm';
7
+ export * as Resolver from './resolver';
8
+ export * as Graph from './graph';
9
+ export * as Bundle from './bundle';
10
+ export * as Url from './url';
11
+ export * as Plugin from './plugin';
12
+ export * as Data from './data';
13
+ export * as Alerts from './alerts';
14
+ export * as Fetch from './fetch';
15
+ export * as Rspack from './rspack';
16
+ export * as Package from './package';
17
+ export * as Lodash from './lodash';
18
+ export * as GlobalConfig from './global-config';
19
+ export * as File from './file';
20
+ export * from './decycle';
@@ -0,0 +1,22 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ import { Plugin } from '@rsdoctor/types';
3
+ export declare function findLoaderTotalTiming(loaders: Pick<SDK.LoaderTransformData, 'startAt' | 'endAt'>[]): {
4
+ start: number;
5
+ end: number;
6
+ };
7
+ export declare function getLoadersCosts(filter: (loader: Pick<SDK.LoaderTransformData, 'loader' | 'startAt' | 'endAt' | 'pid'>) => boolean, loaders: Pick<SDK.LoaderTransformData, 'loader' | 'startAt' | 'endAt' | 'pid'>[]): number;
8
+ export declare function getLoaderCosts(loader: SDK.LoaderTransformData, loaders: SDK.LoaderTransformData[]): number;
9
+ export declare function getLoaderNames(loaders: SDK.LoaderData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderNames>;
10
+ export declare function getLoadersTransformData(loaders: SDK.LoaderData): SDK.LoaderTransformData[];
11
+ export declare function getLoaderChartData(loaders: SDK.LoaderData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderChartData>;
12
+ export declare function getLoaderFileTree(loaders: SDK.LoaderData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderFileTree>;
13
+ export declare function getLoaderFileDetails(path: string, loaders: SDK.LoaderData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderFileDetails>;
14
+ export declare function getLoaderFolderStatistics(folder: string, loaders: SDK.LoaderData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderFolderStatistics>;
15
+ export declare function getDirectoriesLoaders(loaders: SDK.LoaderData, root?: string): {
16
+ directory: string;
17
+ stats: SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderFolderStatistics>;
18
+ }[];
19
+ export declare function getLoaderFileFirstInput(file: string, loaders: SDK.LoaderData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderFileFirstInput>;
20
+ export declare function getLoaderFileInputAndOutput(file: string, loader: string, loaderIndex: number, loaders: SDK.LoaderData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetLoaderFileInputAndOutput>;
21
+ export declare const LoaderInternalPropertyName = "__l__";
22
+ export declare const isVue: (compiler: Plugin.BaseCompiler) => boolean;
@@ -0,0 +1,10 @@
1
+ export declare function isUndefined(value: unknown): value is undefined;
2
+ export declare function isNumber(value: unknown): value is number;
3
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
4
+ export declare function isEmpty(value: unknown): boolean;
5
+ export declare function last<T>(array: T[]): T | undefined;
6
+ export declare function compact<T>(array: (T | null | undefined)[]): T[];
7
+ export declare function isNil(value: unknown): value is null | undefined;
8
+ export declare const isPlainObject: (obj: unknown) => obj is Record<string, any>;
9
+ export declare const isString: (v: unknown) => v is string;
10
+ export declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: readonly K[]): Pick<T, K>;
@@ -0,0 +1,4 @@
1
+ import { Manifest } from '@rsdoctor/types';
2
+ export declare function isShardingData(data: unknown): data is string[];
3
+ export declare function fetchShardingData(shardingFiles: string[], fetchImplement: (url: string) => Promise<string>): Promise<any>;
4
+ export declare function fetchShardingFiles(data: Manifest.RsdoctorManifestWithShardingFiles['data'], fetchImplement: (url: string) => Promise<string>, filterKeys?: Array<keyof Manifest.RsdoctorManifestData>): Promise<Manifest.RsdoctorManifestData>;
@@ -0,0 +1,7 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ export declare const MODULE_PATH_PACKAGES: RegExp;
3
+ export declare const PACKAGE_PATH_NAME: RegExp;
4
+ /**
5
+ * Heuristics to extract package id, name, and path from a module path
6
+ */
7
+ export declare const getPackageMetaFromModulePath: (modulePath: string) => SDK.PackageJSONData;
@@ -0,0 +1,5 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ export declare function getPluginHooks(plugin: SDK.PluginData): string[];
3
+ export declare function getPluginTapNames(plugin: SDK.PluginData): string[];
4
+ export declare function getPluginSummary(plugin: SDK.PluginData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetPluginSummary>;
5
+ export declare function getPluginData(plugin: SDK.PluginData, selectedHooks?: string[], selectedTapNames?: string[]): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetPluginData>;
@@ -0,0 +1,6 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ export declare function isResolveSuccessData(data: SDK.PathResolverData): data is SDK.PathResolverSuccessData;
3
+ export declare function isResolveFailData(data: SDK.PathResolverData): data is SDK.PathResolverSuccessData;
4
+ export declare function getResolverCosts(resolver: SDK.PathResolverData, resolvers: SDK.ResolverData): number;
5
+ export declare function getResolverFileTree(resolver: SDK.ResolverData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetResolverFileTree>;
6
+ export declare function getResolverFileDetails(filepath: string, resolvers: SDK.ResolverData, modules: SDK.ModuleData[], moduleCodeMap: SDK.ModuleCodeData): SDK.ServerAPI.InferResponseType<SDK.ServerAPI.API.GetResolverFileDetails>;
@@ -0,0 +1,17 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ export declare const RspackLoaderInternalPropertyName = "__l__";
3
+ export declare enum RspackSummaryCostsDataName {
4
+ Bootstrap = "bootstrap->rspack:beforeCompile",
5
+ Compile = "rspack:beforeCompile->afterCompile",
6
+ Done = "rspack:afterCompile->done",
7
+ Minify = "rspack:minify(rspack:optimizeChunkAssets)"
8
+ }
9
+ /**
10
+ * Check if the compiler configuration supports source maps
11
+ * @param configs - Array of compiler configurations
12
+ * @returns Object containing compiler type and source map support status
13
+ */
14
+ export declare function checkSourceMapSupport(configs: SDK.WebpackConfigData[]): {
15
+ isRspack: boolean;
16
+ hasSourceMap: boolean;
17
+ };
@@ -0,0 +1,6 @@
1
+ export declare enum SummaryCostsDataName {
2
+ Bootstrap = "bootstrap->beforeCompile",
3
+ Compile = "beforeCompile->afterCompile",
4
+ Done = "afterCompile->done",
5
+ Minify = "minify(processAssets)"
6
+ }
@@ -0,0 +1,4 @@
1
+ export declare function toFixedDigits(num: number, digits?: number): number;
2
+ export declare function getUnit(num: number, type: 'm' | 'h'): string;
3
+ export declare function formatCosts(costs: number | string): string;
4
+ export declare function getCurrentTimestamp(start: number, startHRTime: [number, number]): number;
@@ -0,0 +1,3 @@
1
+ export declare function isUrl(uri: string): boolean;
2
+ export declare function isFilePath(uri: string): boolean;
3
+ export declare function isRemoteUrl(uri: unknown): boolean;
package/dist/common.cjs CHANGED
@@ -637,7 +637,7 @@ for(var __rspack_i in (()=>{
637
637
  return {
638
638
  ...data,
639
639
  loaders: data.loaders.map((el)=>{
640
- let { input, result, ...loaderWithoutCode } = el;
640
+ let { input: _input, result: _result, ...loaderWithoutCode } = el;
641
641
  return {
642
642
  ...loaderWithoutCode,
643
643
  loader: getLoadrName(el.loader),
@@ -907,9 +907,12 @@ for(var __rspack_i in (()=>{
907
907
  return (0, graph_chunk.Ip)(asset, chunks).some((e)=>!!e.initial);
908
908
  }
909
909
  function getInitialAssetsSizeInfo(assets, chunks, options = {}) {
910
- return options.filterOrExtensions && (assets = filterAssets(assets, options.filterOrExtensions)), getAssetsSizeInfo(assets, chunks, {
910
+ return getAssetsSizeInfo(assets, chunks, {
911
911
  ...options,
912
- filterOrExtensions: (asset)=>isInitialAsset(asset, chunks)
912
+ filterOrExtensions: (asset)=>{
913
+ var asset1, filterOrExtensions;
914
+ return asset1 = asset, (!(filterOrExtensions = options.filterOrExtensions) || ('function' == typeof filterOrExtensions ? filterOrExtensions(asset1) : 'string' == typeof filterOrExtensions ? isAssetMatchExtension(asset1, filterOrExtensions) : isAssetMatchExtensions(asset1, filterOrExtensions))) && isInitialAsset(asset, chunks);
915
+ }
913
916
  });
914
917
  }
915
918
  function getAssetsDiffResult(baseline, current) {
@@ -1440,7 +1443,7 @@ for(var __rspack_i in (()=>{
1440
1443
  case types_.SDK.ServerAPI.API.GetChunkGraphAI:
1441
1444
  return this.loader.loadData('chunkGraph').then((res)=>{
1442
1445
  let { assets = [] } = res || {};
1443
- return assets.map(({ content, ...rest })=>rest);
1446
+ return assets.map(({ content: _, ...rest })=>rest);
1444
1447
  });
1445
1448
  case types_.SDK.ServerAPI.API.GetChunkByIdAI:
1446
1449
  return Promise.all([
package/dist/common.js CHANGED
@@ -313,7 +313,7 @@ function getLoaderFileDetails(path, loaders) {
313
313
  return {
314
314
  ...data,
315
315
  loaders: data.loaders.map((el)=>{
316
- let { input, result, ...loaderWithoutCode } = el;
316
+ let { input: _input, result: _result, ...loaderWithoutCode } = el;
317
317
  return {
318
318
  ...loaderWithoutCode,
319
319
  loader: getLoadrName(el.loader),
@@ -610,9 +610,12 @@ function isInitialAsset(asset, chunks) {
610
610
  return getChunksByAsset(asset, chunks).some((e)=>!!e.initial);
611
611
  }
612
612
  function getInitialAssetsSizeInfo(assets, chunks, options = {}) {
613
- return options.filterOrExtensions && (assets = filterAssets(assets, options.filterOrExtensions)), getAssetsSizeInfo(assets, chunks, {
613
+ return getAssetsSizeInfo(assets, chunks, {
614
614
  ...options,
615
- filterOrExtensions: (asset)=>isInitialAsset(asset, chunks)
615
+ filterOrExtensions: (asset)=>{
616
+ var filterOrExtensions;
617
+ return (!(filterOrExtensions = options.filterOrExtensions) || ('function' == typeof filterOrExtensions ? filterOrExtensions(asset) : 'string' == typeof filterOrExtensions ? isAssetMatchExtension(asset, filterOrExtensions) : isAssetMatchExtensions(asset, filterOrExtensions))) && isInitialAsset(asset, chunks);
618
+ }
616
619
  });
617
620
  }
618
621
  function getAssetsDiffResult(baseline, current) {
@@ -1191,7 +1194,7 @@ class APIDataLoader {
1191
1194
  case SDK.ServerAPI.API.GetChunkGraphAI:
1192
1195
  return this.loader.loadData('chunkGraph').then((res)=>{
1193
1196
  let { assets = [] } = res || {};
1194
- return assets.map(({ content, ...rest })=>rest);
1197
+ return assets.map(({ content: _, ...rest })=>rest);
1195
1198
  });
1196
1199
  case SDK.ServerAPI.API.GetChunkByIdAI:
1197
1200
  return Promise.all([
@@ -0,0 +1,35 @@
1
+ import { Err, Rule } from '@rsdoctor/types';
2
+ export declare class DevToolError extends Error implements Err.DevToolErrorInstance {
3
+ static from(err: unknown, opt?: Err.DevToolErrorParams): DevToolError;
4
+ readonly id: number;
5
+ readonly code?: string;
6
+ readonly category?: string;
7
+ readonly title: string;
8
+ readonly detail?: any;
9
+ readonly fixData?: Err.FixData;
10
+ readonly hint?: string;
11
+ readonly referenceUrl?: string;
12
+ private _codeFrame?;
13
+ private _controller;
14
+ private readonly _level;
15
+ constructor(title: string, message: string, opts?: Err.DevToolErrorParams);
16
+ get level(): keyof typeof Err.ErrorLevel;
17
+ get path(): string | undefined;
18
+ set path(file: string | undefined);
19
+ get codeFrame(): Err.CodeFrameOption | undefined;
20
+ private printCodeFrame;
21
+ toString(): string;
22
+ toData(): Rule.RuleStoreDataItem;
23
+ toError(): Error;
24
+ /**
25
+ * for json stringify
26
+ */
27
+ toJSON(): {
28
+ message: string;
29
+ name: string;
30
+ stack: string | undefined;
31
+ };
32
+ setControllerOption(opt: Err.ControllerOption): void;
33
+ setCodeFrame(opt: Err.CodeFrameOption): void;
34
+ isSame(error: Err.DevToolErrorInstance): boolean;
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from './error';
2
+ export { printErrors } from './utils';
@@ -0,0 +1,3 @@
1
+ import { Err } from '@rsdoctor/types';
2
+ import { DevToolError } from './error';
3
+ export declare function transform(err: any, opt?: Err.DevToolErrorParams): DevToolError;
@@ -0,0 +1,4 @@
1
+ import { Err, Logger } from '@rsdoctor/types';
2
+ export declare function toLevel(level: keyof typeof Err.ErrorLevel): Err.ErrorLevel;
3
+ export declare function insertSpace(rawLines: string, line: number, width: number): string;
4
+ export declare function printErrors({ errors, warnings }: Err.DevToolErrorsData, logLevel?: Logger.LogLevelName): string;
@@ -0,0 +1,9 @@
1
+ import c from 'picocolors';
2
+ /**
3
+ * log debug message
4
+ */
5
+ export declare function debug(getMsg: () => string, prefix?: string): void;
6
+ declare const rsdoctorLogger: import("rslog").Logger;
7
+ declare function time(label: string): void;
8
+ declare function timeEnd(label: string): void;
9
+ export { time, timeEnd, c as chalk, rsdoctorLogger as logger };
@@ -0,0 +1,16 @@
1
+ import { Range, OffsetRange, Position, DocumentEditData } from './types';
2
+ /** Document Catalogue */
3
+ export declare class Document {
4
+ /** Actual document content. */
5
+ private _text;
6
+ /** Get the displacement of the file position in the text. */
7
+ positionAt: (offset: number) => Position | undefined;
8
+ /** Get the position of the displacement point in the file. */
9
+ offsetAt: (position: Position) => number | undefined;
10
+ constructor(content: string);
11
+ /** Generate location search */
12
+ private createFinder;
13
+ getText(range?: Range | OffsetRange): string;
14
+ /** Edit document data */
15
+ edit(data: DocumentEditData): string | undefined;
16
+ }
@@ -0,0 +1,3 @@
1
+ export * from './document';
2
+ export * from './types';
3
+ export * from './server';
@@ -0,0 +1,4 @@
1
+ import { Document } from './document';
2
+ /** Create Document */
3
+ export declare function getDocument(content: string): Document;
4
+ export declare function clearDocument(): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Location
3
+ * - line starting point is 1
4
+ * - column starting point is 0
5
+ */
6
+ export interface Position {
7
+ line: number;
8
+ column: number;
9
+ }
10
+ /** Location range */
11
+ export interface Range {
12
+ start: Position;
13
+ end: Position;
14
+ }
15
+ /** Offset range */
16
+ export interface OffsetRange {
17
+ start: number;
18
+ end: number;
19
+ }
20
+ /** Text repair data */
21
+ export interface DocumentEditData {
22
+ /** Modify the starting position of string in the original text */
23
+ start: number | Position;
24
+ /** Modify string in the key position of the original text */
25
+ end: number | Position;
26
+ /**
27
+ * Replaced new text
28
+ * - If empty, delete the original text
29
+ */
30
+ newText?: string;
31
+ }
@@ -0,0 +1,2 @@
1
+ export * from './document';
2
+ export * from './parser';
@@ -0,0 +1,81 @@
1
+ import { Node } from './types';
2
+ export declare const asserts: {
3
+ readonly isProgram: (node: unknown) => node is Node.Program;
4
+ readonly isEmptyStatement: (node: unknown) => node is Node.EmptyStatement;
5
+ readonly isBlockStatement: (node: unknown) => node is Node.BlockStatement;
6
+ readonly isStaticBlock: (node: unknown) => node is Node.StaticBlock;
7
+ readonly isExpressionStatement: (node: unknown) => node is Node.ExpressionStatement;
8
+ readonly isIfStatement: (node: unknown) => node is Node.IfStatement;
9
+ readonly isLabeledStatement: (node: unknown) => node is Node.LabeledStatement;
10
+ readonly isBreakStatement: (node: unknown) => node is Node.BreakStatement;
11
+ readonly isContinueStatement: (node: unknown) => node is Node.ContinueStatement;
12
+ readonly isWithStatement: (node: unknown) => node is Node.WithStatement;
13
+ readonly isSwitchStatement: (node: unknown) => node is Node.SwitchStatement;
14
+ readonly isReturnStatement: (node: unknown) => node is Node.ReturnStatement;
15
+ readonly isThrowStatement: (node: unknown) => node is Node.ThrowStatement;
16
+ readonly isTryStatement: (node: unknown) => node is Node.TryStatement;
17
+ readonly isWhileStatement: (node: unknown) => node is Node.WhileStatement;
18
+ readonly isDoWhileStatement: (node: unknown) => node is Node.DoWhileStatement;
19
+ readonly isForStatement: (node: unknown) => node is Node.ForStatement;
20
+ readonly isForInStatement: (node: unknown) => node is Node.ForInStatement;
21
+ readonly isForOfStatement: (node: unknown) => node is Node.ForOfStatement;
22
+ readonly isDebuggerStatement: (node: unknown) => node is Node.DebuggerStatement;
23
+ readonly isFunctionDeclaration: (node: unknown) => node is Node.FunctionDeclaration;
24
+ readonly isVariableDeclaration: (node: unknown) => node is Node.VariableDeclaration;
25
+ readonly isVariableDeclarator: (node: unknown) => node is Node.VariableDeclarator;
26
+ readonly isChainExpression: (node: unknown) => node is Node.ChainExpression;
27
+ readonly isThisExpression: (node: unknown) => node is Node.ThisExpression;
28
+ readonly isArrayExpression: (node: unknown) => node is Node.ArrayExpression;
29
+ readonly isObjectExpression: (node: unknown) => node is Node.ObjectExpression;
30
+ readonly isPrivateIdentifier: (node: unknown) => node is Node.PrivateIdentifier;
31
+ readonly isProperty: (node: unknown) => node is Node.Property;
32
+ readonly isPropertyDefinition: (node: unknown) => node is Node.PropertyDefinition;
33
+ readonly isFunctionExpression: (node: unknown) => node is Node.FunctionExpression;
34
+ readonly isSequenceExpression: (node: unknown) => node is Node.SequenceExpression;
35
+ readonly isUnaryExpression: (node: unknown) => node is Node.UnaryExpression;
36
+ readonly isBinaryExpression: (node: unknown) => node is Node.BinaryExpression;
37
+ readonly isAssignmentExpression: (node: unknown) => node is Node.AssignmentExpression;
38
+ readonly isUpdateExpression: (node: unknown) => node is Node.UpdateExpression;
39
+ readonly isLogicalExpression: (node: unknown) => node is Node.LogicalExpression;
40
+ readonly isConditionalExpression: (node: unknown) => node is Node.ConditionalExpression;
41
+ readonly isNewExpression: (node: unknown) => node is Node.NewExpression;
42
+ readonly isSwitchCase: (node: unknown) => node is Node.SwitchCase;
43
+ readonly isCatchClause: (node: unknown) => node is Node.CatchClause;
44
+ readonly isIdentifier: (node: unknown) => node is Node.Identifier;
45
+ readonly isLiteral: (node: unknown) => node is Node.Literal;
46
+ readonly isSuper: (node: unknown) => node is Node.Super;
47
+ readonly isSpreadElement: (node: unknown) => node is Node.SpreadElement;
48
+ readonly isArrowFunctionExpression: (node: unknown) => node is Node.ArrowFunctionExpression;
49
+ readonly isYieldExpression: (node: unknown) => node is Node.YieldExpression;
50
+ readonly isTemplateLiteral: (node: unknown) => node is Node.TemplateLiteral;
51
+ readonly isTaggedTemplateExpression: (node: unknown) => node is Node.TaggedTemplateExpression;
52
+ readonly isTemplateElement: (node: unknown) => node is Node.TemplateElement;
53
+ readonly isObjectPattern: (node: unknown) => node is Node.ObjectPattern;
54
+ readonly isArrayPattern: (node: unknown) => node is Node.ArrayPattern;
55
+ readonly isRestElement: (node: unknown) => node is Node.RestElement;
56
+ readonly isAssignmentPattern: (node: unknown) => node is Node.AssignmentPattern;
57
+ readonly isClassBody: (node: unknown) => node is Node.ClassBody;
58
+ readonly isClassDeclaration: (node: unknown) => node is Node.ClassDeclaration;
59
+ readonly isClassExpression: (node: unknown) => node is Node.ClassExpression;
60
+ readonly isMetaProperty: (node: unknown) => node is Node.MetaProperty;
61
+ readonly isImportDeclaration: (node: unknown) => node is Node.ImportDeclaration;
62
+ readonly isImportSpecifier: (node: unknown) => node is Node.ImportSpecifier;
63
+ readonly isImportExpression: (node: unknown) => node is Node.ImportExpression;
64
+ readonly isImportDefaultSpecifier: (node: unknown) => node is Node.ImportDefaultSpecifier;
65
+ readonly isImportNamespaceSpecifier: (node: unknown) => node is Node.ImportNamespaceSpecifier;
66
+ readonly isExportNamedDeclaration: (node: unknown) => node is Node.ExportNamedDeclaration;
67
+ readonly isExportSpecifier: (node: unknown) => node is Node.ExportSpecifier;
68
+ readonly isExportDefaultDeclaration: (node: unknown) => node is Node.ExportDefaultDeclaration;
69
+ readonly isExportAllDeclaration: (node: unknown) => node is Node.ExportAllDeclaration;
70
+ readonly isAwaitExpression: (node: unknown) => node is Node.AwaitExpression;
71
+ readonly isMethodDefinition: (node: unknown) => node is Node.MethodDefinition;
72
+ readonly isMemberExpression: (node: unknown) => node is Node.MemberExpression;
73
+ readonly isComment: (node: unknown) => node is Node.Comment;
74
+ readonly isDirective: (node: unknown) => node is Node.Directive;
75
+ readonly isSimpleCallExpression: (node: unknown) => node is Node.SimpleCallExpression;
76
+ readonly isAssignmentProperty: (node: unknown) => node is Node.AssignmentProperty;
77
+ readonly isSimpleLiteral: (node: unknown) => node is Node.SimpleLiteral;
78
+ readonly isRegExpLiteral: (node: unknown) => node is Node.RegExpLiteral;
79
+ readonly isBigIntLiteral: (node: unknown) => node is Node.BigIntLiteral;
80
+ readonly isExportStatement: (node: unknown) => node is Node.ExportStatement;
81
+ };
@@ -0,0 +1,4 @@
1
+ export * from './asserts';
2
+ export * from './parser';
3
+ export * from './utils';
4
+ export * from './types';
@@ -0,0 +1,118 @@
1
+ import { Parser as AcornParser, Options, Position } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import * as utils from './utils';
4
+ import type { Node } from './types';
5
+ export type { Options as ParseOptions } from 'acorn';
6
+ export interface ParseError extends Error {
7
+ loc?: Position;
8
+ pos: number;
9
+ raisedAt: number;
10
+ }
11
+ export declare const parser: {
12
+ /** AST iterator */
13
+ walk: typeof walk;
14
+ /**
15
+ * Compile code
16
+ * - Output root node is `Node.Program`
17
+ */
18
+ parse: (input: string, options: Options) => Node.Program;
19
+ /**
20
+ * Compile the next first expression
21
+ * - The output root node is `Node.ExpressionStatement`
22
+ */
23
+ parseExpressionAt: (input: string, pos: number, options: Options) => Node.ExpressionStatement;
24
+ /**
25
+ * add plugins for acorn
26
+ */
27
+ extend(...args: Parameters<typeof AcornParser.extend>): typeof AcornParser;
28
+ /** Set of assertions */
29
+ asserts: {
30
+ readonly isProgram: (node: unknown) => node is Node.Program;
31
+ readonly isEmptyStatement: (node: unknown) => node is Node.EmptyStatement;
32
+ readonly isBlockStatement: (node: unknown) => node is Node.BlockStatement;
33
+ readonly isStaticBlock: (node: unknown) => node is Node.StaticBlock;
34
+ readonly isExpressionStatement: (node: unknown) => node is Node.ExpressionStatement;
35
+ readonly isIfStatement: (node: unknown) => node is Node.IfStatement;
36
+ readonly isLabeledStatement: (node: unknown) => node is Node.LabeledStatement;
37
+ readonly isBreakStatement: (node: unknown) => node is Node.BreakStatement;
38
+ readonly isContinueStatement: (node: unknown) => node is Node.ContinueStatement;
39
+ readonly isWithStatement: (node: unknown) => node is Node.WithStatement;
40
+ readonly isSwitchStatement: (node: unknown) => node is Node.SwitchStatement;
41
+ readonly isReturnStatement: (node: unknown) => node is Node.ReturnStatement;
42
+ readonly isThrowStatement: (node: unknown) => node is Node.ThrowStatement;
43
+ readonly isTryStatement: (node: unknown) => node is Node.TryStatement;
44
+ readonly isWhileStatement: (node: unknown) => node is Node.WhileStatement;
45
+ readonly isDoWhileStatement: (node: unknown) => node is Node.DoWhileStatement;
46
+ readonly isForStatement: (node: unknown) => node is Node.ForStatement;
47
+ readonly isForInStatement: (node: unknown) => node is Node.ForInStatement;
48
+ readonly isForOfStatement: (node: unknown) => node is Node.ForOfStatement;
49
+ readonly isDebuggerStatement: (node: unknown) => node is Node.DebuggerStatement;
50
+ readonly isFunctionDeclaration: (node: unknown) => node is Node.FunctionDeclaration;
51
+ readonly isVariableDeclaration: (node: unknown) => node is Node.VariableDeclaration;
52
+ readonly isVariableDeclarator: (node: unknown) => node is Node.VariableDeclarator;
53
+ readonly isChainExpression: (node: unknown) => node is Node.ChainExpression;
54
+ readonly isThisExpression: (node: unknown) => node is Node.ThisExpression;
55
+ readonly isArrayExpression: (node: unknown) => node is Node.ArrayExpression;
56
+ readonly isObjectExpression: (node: unknown) => node is Node.ObjectExpression;
57
+ readonly isPrivateIdentifier: (node: unknown) => node is Node.PrivateIdentifier;
58
+ readonly isProperty: (node: unknown) => node is Node.Property;
59
+ readonly isPropertyDefinition: (node: unknown) => node is Node.PropertyDefinition;
60
+ readonly isFunctionExpression: (node: unknown) => node is Node.FunctionExpression;
61
+ readonly isSequenceExpression: (node: unknown) => node is Node.SequenceExpression;
62
+ readonly isUnaryExpression: (node: unknown) => node is Node.UnaryExpression;
63
+ readonly isBinaryExpression: (node: unknown) => node is Node.BinaryExpression;
64
+ readonly isAssignmentExpression: (node: unknown) => node is Node.AssignmentExpression;
65
+ readonly isUpdateExpression: (node: unknown) => node is Node.UpdateExpression;
66
+ readonly isLogicalExpression: (node: unknown) => node is Node.LogicalExpression;
67
+ readonly isConditionalExpression: (node: unknown) => node is Node.ConditionalExpression;
68
+ readonly isNewExpression: (node: unknown) => node is Node.NewExpression;
69
+ readonly isSwitchCase: (node: unknown) => node is Node.SwitchCase;
70
+ readonly isCatchClause: (node: unknown) => node is Node.CatchClause;
71
+ readonly isIdentifier: (node: unknown) => node is Node.Identifier;
72
+ readonly isLiteral: (node: unknown) => node is Node.Literal;
73
+ readonly isSuper: (node: unknown) => node is Node.Super;
74
+ readonly isSpreadElement: (node: unknown) => node is Node.SpreadElement;
75
+ readonly isArrowFunctionExpression: (node: unknown) => node is Node.ArrowFunctionExpression;
76
+ readonly isYieldExpression: (node: unknown) => node is Node.YieldExpression;
77
+ readonly isTemplateLiteral: (node: unknown) => node is Node.TemplateLiteral;
78
+ readonly isTaggedTemplateExpression: (node: unknown) => node is Node.TaggedTemplateExpression;
79
+ readonly isTemplateElement: (node: unknown) => node is Node.TemplateElement;
80
+ readonly isObjectPattern: (node: unknown) => node is Node.ObjectPattern;
81
+ readonly isArrayPattern: (node: unknown) => node is Node.ArrayPattern;
82
+ readonly isRestElement: (node: unknown) => node is Node.RestElement;
83
+ readonly isAssignmentPattern: (node: unknown) => node is Node.AssignmentPattern;
84
+ readonly isClassBody: (node: unknown) => node is Node.ClassBody;
85
+ readonly isClassDeclaration: (node: unknown) => node is Node.ClassDeclaration;
86
+ readonly isClassExpression: (node: unknown) => node is Node.ClassExpression;
87
+ readonly isMetaProperty: (node: unknown) => node is Node.MetaProperty;
88
+ readonly isImportDeclaration: (node: unknown) => node is Node.ImportDeclaration;
89
+ readonly isImportSpecifier: (node: unknown) => node is Node.ImportSpecifier;
90
+ readonly isImportExpression: (node: unknown) => node is Node.ImportExpression;
91
+ readonly isImportDefaultSpecifier: (node: unknown) => node is Node.ImportDefaultSpecifier;
92
+ readonly isImportNamespaceSpecifier: (node: unknown) => node is Node.ImportNamespaceSpecifier;
93
+ readonly isExportNamedDeclaration: (node: unknown) => node is Node.ExportNamedDeclaration;
94
+ readonly isExportSpecifier: (node: unknown) => node is Node.ExportSpecifier;
95
+ readonly isExportDefaultDeclaration: (node: unknown) => node is Node.ExportDefaultDeclaration;
96
+ readonly isExportAllDeclaration: (node: unknown) => node is Node.ExportAllDeclaration;
97
+ readonly isAwaitExpression: (node: unknown) => node is Node.AwaitExpression;
98
+ readonly isMethodDefinition: (node: unknown) => node is Node.MethodDefinition;
99
+ readonly isMemberExpression: (node: unknown) => node is Node.MemberExpression;
100
+ readonly isComment: (node: unknown) => node is Node.Comment;
101
+ readonly isDirective: (node: unknown) => node is Node.Directive;
102
+ readonly isSimpleCallExpression: (node: unknown) => node is Node.SimpleCallExpression;
103
+ readonly isAssignmentProperty: (node: unknown) => node is Node.AssignmentProperty;
104
+ readonly isSimpleLiteral: (node: unknown) => node is Node.SimpleLiteral;
105
+ readonly isRegExpLiteral: (node: unknown) => node is Node.RegExpLiteral;
106
+ readonly isBigIntLiteral: (node: unknown) => node is Node.BigIntLiteral;
107
+ readonly isExportStatement: (node: unknown) => node is Node.ExportStatement;
108
+ };
109
+ utils: typeof utils;
110
+ /**
111
+ * @internal
112
+ * parser for internal packages
113
+ */
114
+ internal: {
115
+ parse: (input: string, options: Options) => Node.Program;
116
+ parseExpressionAt: (input: string, pos: number, options: Options) => Node.ExpressionStatement;
117
+ };
118
+ };
@@ -0,0 +1,30 @@
1
+ import type * as Node from 'estree';
2
+ export type { Node };
3
+ export declare enum ECMAVersion {
4
+ ES5 = "ES5",
5
+ ES6 = "ES6",
6
+ ES7P = "ES7+"
7
+ }
8
+ /**
9
+ * estree supplement type
10
+ * Mainly to match the node type of acorn
11
+ * The main reason for not using the type of acorn directly is that the node type described by acorn itself is too simple
12
+ */
13
+ declare module 'estree' {
14
+ interface BaseNode {
15
+ start: number;
16
+ end: number;
17
+ loc?: SourceLocation | undefined;
18
+ }
19
+ interface Position {
20
+ offset: number;
21
+ }
22
+ /** all syntax nodes */
23
+ type SyntaxNode = Node.Comment | Node.Program | Node.Directive | Node.EmptyStatement | Node.BlockStatement | Node.StaticBlock | Node.ExpressionStatement | Node.IfStatement | Node.LabeledStatement | Node.BreakStatement | Node.ContinueStatement | Node.WithStatement | Node.SwitchStatement | Node.ReturnStatement | Node.ThrowStatement | Node.TryStatement | Node.WhileStatement | Node.DoWhileStatement | Node.ForStatement | Node.ForInStatement | Node.DebuggerStatement | Node.FunctionDeclaration | Node.VariableDeclaration | Node.VariableDeclarator | Node.ChainExpression | Node.ThisExpression | Node.ArrayExpression | Node.ObjectExpression | Node.PrivateIdentifier | Node.Property | Node.PropertyDefinition | Node.FunctionExpression | Node.SequenceExpression | Node.UnaryExpression | Node.BinaryExpression | Node.AssignmentExpression | Node.UpdateExpression | Node.LogicalExpression | Node.ConditionalExpression | Node.SimpleCallExpression | Node.NewExpression | Node.MemberExpression | Node.SwitchCase | Node.CatchClause | Node.Identifier | Node.SimpleLiteral | Node.RegExpLiteral | Node.BigIntLiteral | Node.ForOfStatement | Node.Super | Node.SpreadElement | Node.ArrowFunctionExpression | Node.YieldExpression | Node.TemplateLiteral | Node.TaggedTemplateExpression | Node.TemplateElement | Node.AssignmentProperty | Node.ObjectPattern | Node.ArrayPattern | Node.RestElement | Node.AssignmentPattern | Node.ClassBody | Node.MethodDefinition | Node.ClassDeclaration | Node.ClassExpression | Node.MetaProperty | Node.ImportDeclaration | Node.ImportSpecifier | Node.ImportExpression | Node.ImportDefaultSpecifier | Node.ImportNamespaceSpecifier | Node.ExportNamedDeclaration | Node.ExportSpecifier | Node.ExportDefaultDeclaration | Node.ExportAllDeclaration | Node.AwaitExpression;
24
+ /** all operators */
25
+ type SyntaxOperator = Node.UnaryOperator | Node.BinaryOperator | Node.LogicalOperator | Node.AssignmentOperator | Node.UpdateOperator;
26
+ /** Block-scoped statement */
27
+ type BlockScopeStatement = Node.StaticBlock | Node.BlockStatement | Node.ForInStatement | Node.ForOfStatement | Node.ForStatement | Node.CatchClause | Node.SwitchStatement;
28
+ /** Export statement */
29
+ type ExportStatement = Node.ExportAllDeclaration | Node.ExportDefaultDeclaration | Node.ExportNamedDeclaration;
30
+ }
@@ -0,0 +1,30 @@
1
+ import { ecmaVersion } from 'acorn';
2
+ import { Node, ECMAVersion } from './types';
3
+ /**
4
+ * Is the node semantics the same?
5
+ * @deprecated
6
+ * - Recursively compare whether the content of the node itself is the same
7
+ * - Ignore comments, positions, string symbols (single and double quotation marks)
8
+ * - String templates and string addition will be considered different
9
+ */
10
+ export declare function isSameSemantics(node1: Node.SyntaxNode, node2: Node.SyntaxNode): boolean;
11
+ /**
12
+ * Get all default reference statements
13
+ */
14
+ export declare function getDefaultImports(node: Node.Program): Node.ImportDeclaration[];
15
+ /** Get the literal in the text. */
16
+ export declare function getIdentifierInPattern(name: string, node: Node.Pattern): Node.Identifier | undefined;
17
+ /** Get the variable declaration statement identifier. */
18
+ export declare function getIdentifierInDeclaration(name: string, node: Node.SyntaxNode): Node.Identifier | undefined;
19
+ /** Get the reference declaration statement identifier. */
20
+ export declare function getIdentifierInImport(name: string, node: Node.SyntaxNode): Node.Identifier | undefined;
21
+ /** Get the export statement identifier. */
22
+ export declare function getIdentifierInExport(name: string, node: Node.SyntaxNode): Node.Identifier | undefined;
23
+ /** Determine that it can be resolved using the specified ECMA version */
24
+ export declare function canParse(code: string, ecmaVersion: ecmaVersion): boolean;
25
+ /** Determine whether it is all ES5 version code. */
26
+ export declare function isES5(code: string): boolean;
27
+ /** Determine whether it is all ES6 version code. */
28
+ export declare function isES6(code: string): boolean;
29
+ /** Detect ECMA version. */
30
+ export declare function detectECMAVersion(code: string): ECMAVersion;
@@ -81,7 +81,7 @@ class Document {
81
81
  positionAt;
82
82
  offsetAt;
83
83
  constructor(content){
84
- this._text, this._text = content, this.createFinder();
84
+ this._text = content, this.createFinder();
85
85
  }
86
86
  createFinder() {
87
87
  let find = new external_lines_and_columns_namespaceObject.LinesAndColumns(this._text);
@@ -272,7 +272,7 @@ function canParse(code, ecmaVersion) {
272
272
  ecmaVersion,
273
273
  sourceType: 'number' == typeof ecmaVersion && ecmaVersion <= 5 ? "script" : 'module'
274
274
  }), !0;
275
- } catch (err) {
275
+ } catch {
276
276
  return !1;
277
277
  }
278
278
  }
package/dist/ruleUtils.js CHANGED
@@ -22,7 +22,7 @@ class Document {
22
22
  positionAt;
23
23
  offsetAt;
24
24
  constructor(content){
25
- this._text, this._text = content, this.createFinder();
25
+ this._text = content, this.createFinder();
26
26
  }
27
27
  createFinder() {
28
28
  let find = new LinesAndColumns(this._text);
@@ -211,7 +211,7 @@ function canParse(code, ecmaVersion) {
211
211
  ecmaVersion,
212
212
  sourceType: 'number' == typeof ecmaVersion && ecmaVersion <= 5 ? "script" : 'module'
213
213
  }), !0;
214
- } catch (err) {
214
+ } catch {
215
215
  return !1;
216
216
  }
217
217
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/utils",
3
- "version": "1.5.8",
3
+ "version": "1.5.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -10,29 +10,54 @@
10
10
  "license": "MIT",
11
11
  "exports": {
12
12
  "./common": {
13
- "types": "./dist/common/index.d.ts",
14
- "import": "./dist/common.js",
15
- "default": "./dist/common.cjs"
13
+ "import": {
14
+ "types": "./dist/common/index.d.ts",
15
+ "default": "./dist/common.js"
16
+ },
17
+ "require": {
18
+ "types": "./dist/common/index.d.cts",
19
+ "default": "./dist/common.cjs"
20
+ }
16
21
  },
17
22
  "./build": {
18
- "types": "./dist/build/index.d.ts",
19
- "import": "./dist/build.js",
20
- "default": "./dist/build.cjs"
23
+ "import": {
24
+ "types": "./dist/build/index.d.ts",
25
+ "default": "./dist/build.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/build/index.d.cts",
29
+ "default": "./dist/build.cjs"
30
+ }
21
31
  },
22
32
  "./error": {
23
- "types": "./dist/error/index.d.ts",
24
- "import": "./dist/error.js",
25
- "default": "./dist/error.cjs"
33
+ "import": {
34
+ "types": "./dist/error/index.d.ts",
35
+ "default": "./dist/error.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/error/index.d.cts",
39
+ "default": "./dist/error.cjs"
40
+ }
26
41
  },
27
42
  "./ruleUtils": {
28
- "types": "./dist/rule-utils/index.d.ts",
29
- "import": "./dist/ruleUtils.js",
30
- "default": "./dist/ruleUtils.cjs"
43
+ "import": {
44
+ "types": "./dist/rule-utils/index.d.ts",
45
+ "default": "./dist/ruleUtils.js"
46
+ },
47
+ "require": {
48
+ "types": "./dist/rule-utils/index.d.cts",
49
+ "default": "./dist/ruleUtils.cjs"
50
+ }
31
51
  },
32
52
  "./logger": {
33
- "types": "./dist/logger.d.ts",
34
- "import": "./dist/logger.js",
35
- "default": "./dist/logger.cjs"
53
+ "import": {
54
+ "types": "./dist/logger.d.ts",
55
+ "default": "./dist/logger.js"
56
+ },
57
+ "require": {
58
+ "types": "./dist/logger.d.cts",
59
+ "default": "./dist/logger.cjs"
60
+ }
36
61
  }
37
62
  },
38
63
  "typesVersions": {
@@ -76,7 +101,7 @@
76
101
  "picocolors": "^1.1.1",
77
102
  "rslog": "^1.3.2",
78
103
  "strip-ansi": "^6.0.1",
79
- "@rsdoctor/types": "1.5.8"
104
+ "@rsdoctor/types": "1.5.10"
80
105
  },
81
106
  "devDependencies": {
82
107
  "@types/babel__code-frame": "7.27.0",