From 8a236aee8d96979c4c3f27526ab3d52e37c4ee07 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 18 Sep 2026 18:01:20 +0000 Subject: [PATCH 1/4] refactor: generate types with typescript instead of webpack/tooling `webpack/tooling` bundled every reachable type into a single hand-rolled `types.d.ts`, which meant a second type system to keep in sync with the JSDoc it was derived from. TypeScript emits the same information itself, so `tsc` now generates the declarations straight from `lib/`. The declarations live in `types/`; `types.d.ts` stays the entry point and re-exports them, so the `types` field and any direct reference to `enhanced-resolve/types.d.ts` keep resolving. `scripts/generate-types.js` writes them and, with `--check`, fails on a stale checkout by emitting into a temporary directory and comparing, so CI reports drift without leaving a dirty working tree. Per-file emit only exports what the entry point re-exports, so the four plugin classes needed `@typedef` aliases in `lib/index.js` to stay usable as types rather than only as constructors. `test/types/surface.ts`, run by `lint:types-api`, now pins the whole public surface: every previously exported name is used there in the position it has to support, so a typedef that stops being re-exported fails the build instead of silently disappearing from the package. Two shapes follow the sources more closely than the old generator did. The object form of `Plugin` no longer declares `this: Resolver` on `apply` - it is invoked as `plugin.apply(resolver)`, so `this` is the plugin, not the resolver - and the entries of `ResolveContext.stack` declare `name: string | undefined` rather than an optional `name`. Class fields the old generator dropped, such as the cache backends on `CachedInputFileSystem`, are now part of the declarations. Dropping the dependency removes 32 transitive packages from the lockfile. It also drops the `inherit-types` check, which copied JSDoc from base methods onto overrides; the sources already carry the results. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_016aGHrb1YaEvaGwNELGEHjF --- .changeset/generate-types-with-typescript.md | 5 + .prettierignore | 2 +- eslint.config.mjs | 10 +- lib/index.js | 4 + package-lock.json | 386 +-- package.json | 9 +- scripts/generate-types.js | 127 + test/types/surface.ts | 109 + tsconfig.types.api.json | 11 + tsconfig.types.json | 9 +- types.d.ts | 2108 +---------------- types/AliasFieldPlugin.d.ts | 33 + types/AliasPlugin.d.ts | 28 + types/AliasUtils.d.ts | 115 + types/AppendPlugin.d.ts | 23 + types/CachedInputFileSystem.d.ts | 141 ++ types/CloneBasenamePlugin.d.ts | 21 + types/ConditionalPlugin.d.ts | 27 + types/DescriptionFilePlugin.d.ts | 25 + types/DescriptionFileUtils.d.ts | 70 + types/DirectoryExistsPlugin.d.ts | 20 + types/ExportsFieldPlugin.d.ts | 32 + types/ExtensionAliasPlugin.d.ts | 27 + types/FileExistsPlugin.d.ts | 20 + types/ImportsFieldPlugin.d.ts | 32 + types/JoinRequestPartPlugin.d.ts | 21 + types/JoinRequestPlugin.d.ts | 21 + types/LogInfoPlugin.d.ts | 18 + types/MainFieldPlugin.d.ts | 31 + .../ModulesInHierachicDirectoriesPlugin.d.ts | 2 + ...odulesInHierarchicalDirectoriesPlugin.d.ts | 22 + types/ModulesInRootPlugin.d.ts | 23 + types/ModulesUtils.d.ts | 15 + types/NextPlugin.d.ts | 20 + types/PackageMapPlugin.d.ts | 64 + types/ParsePlugin.d.ts | 23 + types/PnpPlugin.d.ts | 33 + types/Resolver.d.ts | 1208 ++++++++++ types/ResolverFactory.d.ts | 330 +++ types/RestrictionsPlugin.d.ts | 43 + types/ResultPlugin.d.ts | 18 + types/RootsPlugin.d.ts | 26 + types/SelfReferencePlugin.d.ts | 27 + types/SymlinkPlugin.d.ts | 21 + types/SyncAsyncFileSystemDecorator.d.ts | 46 + types/TryNextPlugin.d.ts | 22 + types/TsconfigPathsPlugin.d.ts | 147 ++ types/UnsafeCachePlugin.d.ts | 31 + types/UseFilePlugin.d.ts | 23 + types/createInnerContext.d.ts | 6 + types/forEachBail.d.ts | 7 + types/getInnerRequest.d.ts | 7 + types/getPaths.d.ts | 31 + types/index.d.ts | 64 + types/util/entrypoints.d.ts | 53 + types/util/fileURLToPath.d.ts | 9 + types/util/fs.d.ts | 30 + types/util/graceful-fs-browser.d.ts | 5 + types/util/identifier.d.ts | 5 + types/util/memoize.d.ts | 15 + types/util/module-browser.d.ts | 1 + types/util/packageMap.d.ts | 109 + types/util/path-browser.d.ts | 45 + types/util/path.d.ts | 125 + types/util/pathToFileURL.d.ts | 9 + types/util/process-browser.d.ts | 3 + types/util/strip-json-comments.d.ts | 21 + types/util/url-browser.d.ts | 1 + 68 files changed, 3681 insertions(+), 2494 deletions(-) create mode 100644 .changeset/generate-types-with-typescript.md create mode 100644 scripts/generate-types.js create mode 100644 test/types/surface.ts create mode 100644 tsconfig.types.api.json create mode 100644 types/AliasFieldPlugin.d.ts create mode 100644 types/AliasPlugin.d.ts create mode 100644 types/AliasUtils.d.ts create mode 100644 types/AppendPlugin.d.ts create mode 100644 types/CachedInputFileSystem.d.ts create mode 100644 types/CloneBasenamePlugin.d.ts create mode 100644 types/ConditionalPlugin.d.ts create mode 100644 types/DescriptionFilePlugin.d.ts create mode 100644 types/DescriptionFileUtils.d.ts create mode 100644 types/DirectoryExistsPlugin.d.ts create mode 100644 types/ExportsFieldPlugin.d.ts create mode 100644 types/ExtensionAliasPlugin.d.ts create mode 100644 types/FileExistsPlugin.d.ts create mode 100644 types/ImportsFieldPlugin.d.ts create mode 100644 types/JoinRequestPartPlugin.d.ts create mode 100644 types/JoinRequestPlugin.d.ts create mode 100644 types/LogInfoPlugin.d.ts create mode 100644 types/MainFieldPlugin.d.ts create mode 100644 types/ModulesInHierachicDirectoriesPlugin.d.ts create mode 100644 types/ModulesInHierarchicalDirectoriesPlugin.d.ts create mode 100644 types/ModulesInRootPlugin.d.ts create mode 100644 types/ModulesUtils.d.ts create mode 100644 types/NextPlugin.d.ts create mode 100644 types/PackageMapPlugin.d.ts create mode 100644 types/ParsePlugin.d.ts create mode 100644 types/PnpPlugin.d.ts create mode 100644 types/Resolver.d.ts create mode 100644 types/ResolverFactory.d.ts create mode 100644 types/RestrictionsPlugin.d.ts create mode 100644 types/ResultPlugin.d.ts create mode 100644 types/RootsPlugin.d.ts create mode 100644 types/SelfReferencePlugin.d.ts create mode 100644 types/SymlinkPlugin.d.ts create mode 100644 types/SyncAsyncFileSystemDecorator.d.ts create mode 100644 types/TryNextPlugin.d.ts create mode 100644 types/TsconfigPathsPlugin.d.ts create mode 100644 types/UnsafeCachePlugin.d.ts create mode 100644 types/UseFilePlugin.d.ts create mode 100644 types/createInnerContext.d.ts create mode 100644 types/forEachBail.d.ts create mode 100644 types/getInnerRequest.d.ts create mode 100644 types/getPaths.d.ts create mode 100644 types/index.d.ts create mode 100644 types/util/entrypoints.d.ts create mode 100644 types/util/fileURLToPath.d.ts create mode 100644 types/util/fs.d.ts create mode 100644 types/util/graceful-fs-browser.d.ts create mode 100644 types/util/identifier.d.ts create mode 100644 types/util/memoize.d.ts create mode 100644 types/util/module-browser.d.ts create mode 100644 types/util/packageMap.d.ts create mode 100644 types/util/path-browser.d.ts create mode 100644 types/util/path.d.ts create mode 100644 types/util/pathToFileURL.d.ts create mode 100644 types/util/process-browser.d.ts create mode 100644 types/util/strip-json-comments.d.ts create mode 100644 types/util/url-browser.d.ts diff --git a/.changeset/generate-types-with-typescript.md b/.changeset/generate-types-with-typescript.md new file mode 100644 index 00000000..7514934c --- /dev/null +++ b/.changeset/generate-types-with-typescript.md @@ -0,0 +1,5 @@ +--- +"enhanced-resolve": minor +--- + +Generate the published type declarations with TypeScript instead of `webpack/tooling`, which is no longer a dependency. Every name the package exported before is still exported, and `types.d.ts` is still the entry point, but the declarations themselves now live in `types/` and are emitted by `tsc` from the JSDoc in `lib/`. Two shapes follow the sources more closely than the previous generator did: the object form of `Plugin` no longer declares `this: Resolver` on `apply` (it is called as `plugin.apply(resolver)`, so `this` is the plugin), and the entries of `ResolveContext.stack` declare `name: string | undefined` rather than an optional `name`. Class fields that the old generator dropped, such as the cache backends on `CachedInputFileSystem`, are now part of the declarations. diff --git a/.prettierignore b/.prettierignore index d69fb976..783e854b 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,4 +4,4 @@ test/**/*.* !test/*.js # Generated files -types.d.ts +types/ diff --git a/eslint.config.mjs b/eslint.config.mjs index bff426fa..02ac9b4e 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -2,7 +2,7 @@ import { defineConfig, globalIgnores } from "eslint/config"; import config from "eslint-config-webpack"; export default defineConfig([ - globalIgnores(["benchmark/**/fixture/**"]), + globalIgnores(["benchmark/**/fixture/**", "test/types/**", "types/**"]), { extends: [config], }, @@ -46,6 +46,14 @@ export default defineConfig([ "no-console": "off", }, }, + { + // Repo-local development scripts run on the contributor's Node.js, not on + // the `engines.node` range the published library supports. + files: ["scripts/*.js"], + rules: { + "n/no-unsupported-features/node-builtins": "off", + }, + }, { // The test suite relies on `node:test` and modern `node:assert` helpers, // which are newer than the `engines.node` range the published library diff --git a/lib/index.js b/lib/index.js index 256d4f7f..b7f7a0c1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -7,7 +7,10 @@ const memoize = require("./util/memoize"); +/** @typedef {import("./CachedInputFileSystem")} CachedInputFileSystem */ /** @typedef {import("./CachedInputFileSystem").BaseFileSystem} BaseFileSystem */ +/** @typedef {import("./CloneBasenamePlugin")} CloneBasenamePlugin */ +/** @typedef {import("./LogInfoPlugin")} LogInfoPlugin */ /** @typedef {import("./PnpPlugin").PnpApiImpl} PnpApi */ /** @typedef {import("./Resolver")} Resolver */ /** @typedef {import("./Resolver").Context} Context */ @@ -18,6 +21,7 @@ const memoize = require("./util/memoize"); /** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */ /** @typedef {import("./ResolverFactory").Plugin} Plugin */ /** @typedef {import("./ResolverFactory").UserResolveOptions} ResolveOptions */ +/** @typedef {import("./TsconfigPathsPlugin")} TsconfigPathsPlugin */ /** * @typedef {{ diff --git a/package-lock.json b/package-lock.json index 2374f329..7d47afe7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "enhanced-resolve", - "version": "5.24.5", + "version": "5.25.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "enhanced-resolve", - "version": "5.24.5", + "version": "5.25.1", "license": "MIT", "dependencies": { "graceful-fs": "^4.2.4", @@ -26,7 +26,6 @@ "memfs": "^4.56.11", "prettier": "^3.7.4", "tinybench": "^6.0.0", - "tooling": "https://codeload.github.com/webpack/tooling/tar.gz/refs/tags/v1.26.4", "typescript": "^6.0.2", "webpack": "^5.107.2" }, @@ -34,24 +33,6 @@ "node": ">=10.13.0" } }, - "node_modules/@apidevtools/json-schema-ref-parser": { - "version": "11.9.3", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.9.3.tgz", - "integrity": "sha512-60vepv88RwcJtSHrD6MjIL6Ta3SOYbgfnkHb+ppAVK+o9mXprRtulx7VlRl3lN3bbvysAfCS7WMVfhUYemB0IQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@jsdevtools/ono": "^7.1.3", - "@types/json-schema": "^7.0.15", - "js-yaml": "^4.1.0" - }, - "engines": { - "node": ">= 16" - }, - "funding": { - "url": "https://github.com/sponsors/philsturgeon" - } - }, "node_modules/@babel/code-frame": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", @@ -1619,13 +1600,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@jsdevtools/ono": { - "version": "7.1.3", - "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", - "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==", - "dev": true, - "license": "MIT" - }, "node_modules/@jsonjoy.com/base64": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@jsonjoy.com/base64/-/base64-1.1.2.tgz", @@ -2224,13 +2198,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/lodash": { - "version": "4.17.24", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.24.tgz", - "integrity": "sha512-gIW7lQLZbue7lRSWEFql49QJJWThrTFFeIMJdp3eH4tKoxm1OvEPg02rm4wCCSHS0cL3/Fizimb35b7k8atwsQ==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/mdast": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz", @@ -2722,13 +2689,6 @@ "dev": true, "license": "Apache-2.0" }, - "node_modules/@yarnpkg/lockfile": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@yarnpkg/lockfile/-/lockfile-1.1.0.tgz", - "integrity": "sha512-GpSwvyXOcOOlV70vbnzjj4fW5xW/FdUF6nQEt1ENy7m4ZCczi1+/buVUPAqmGfqznsORNFzUMjctTIp8a9tuCQ==", - "dev": true, - "license": "BSD-2-Clause" - }, "node_modules/acorn": { "version": "8.18.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.18.0.tgz", @@ -3350,77 +3310,6 @@ "node": ">=0.8.0" } }, - "node_modules/cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", - "dev": true, - "license": "ISC", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, - "node_modules/cliui/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/cliui/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/cliui/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "license": "MIT", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/cliui/node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -3488,13 +3377,6 @@ "node": ">= 12.0.0" } }, - "node_modules/commondir": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", - "dev": true, - "license": "MIT" - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -3956,13 +3838,6 @@ "dev": true, "license": "ISC" }, - "node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true, - "license": "MIT" - }, "node_modules/enhanced-resolve": { "version": "5.24.5", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.24.5.tgz", @@ -5279,13 +5154,6 @@ "node": ">=0.4.x" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true, - "license": "ISC" - }, "node_modules/function-bind": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", @@ -5360,16 +5228,6 @@ "node": ">=6.9.0" } }, - "node_modules/get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", - "dev": true, - "license": "ISC", - "engines": { - "node": "6.* || 8.* || >= 10.*" - } - }, "node_modules/get-intrinsic": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", @@ -5457,28 +5315,6 @@ "dev": true, "license": "ISC" }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me", - "dev": true, - "license": "ISC", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -5816,25 +5652,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", - "dev": true, - "license": "ISC", - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true, - "license": "ISC" - }, "node_modules/ini": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/ini/-/ini-6.0.0.tgz", @@ -6414,30 +6231,6 @@ "dev": true, "license": "MIT" }, - "node_modules/json-schema-to-typescript": { - "version": "15.0.4", - "resolved": "https://registry.npmjs.org/json-schema-to-typescript/-/json-schema-to-typescript-15.0.4.tgz", - "integrity": "sha512-Su9oK8DR4xCmDsLlyvadkXzX6+GGXJpbhwoLtOGArAG61dvbW4YQmSEno2y66ahpIdmLMg6YUf/QHLgiwvkrHQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@apidevtools/json-schema-ref-parser": "^11.5.5", - "@types/json-schema": "^7.0.15", - "@types/lodash": "^4.17.7", - "is-glob": "^4.0.3", - "js-yaml": "^4.1.0", - "lodash": "^4.17.21", - "minimist": "^1.2.8", - "prettier": "^3.2.5", - "tinyglobby": "^0.2.9" - }, - "bin": { - "json2ts": "dist/src/cli.js" - }, - "engines": { - "node": ">=16.0.0" - } - }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -6621,13 +6414,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lodash": { - "version": "4.18.1", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.18.1.tgz", - "integrity": "sha512-dMInicTPVE8d1e5otfwmmjlxkZoUpiVLwyeTdUsi/Caj/gfzzblBcCE5sRHV/AsjuCmxWrte2TNGSYuCeCq+0Q==", - "dev": true, - "license": "MIT" - }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -7938,16 +7724,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, - "license": "ISC", - "dependencies": { - "wrappy": "1" - } - }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -8064,16 +7840,6 @@ "node": "^12.20.0 || ^14.13.1 || >=16.0.0" } }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -8276,16 +8042,6 @@ "regjsparser": "bin/parser" } }, - "node_modules/require-directory": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", @@ -8880,29 +8636,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/strip-ansi/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -9094,50 +8827,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/tooling": { - "version": "1.26.4", - "resolved": "https://codeload.github.com/webpack/tooling/tar.gz/refs/tags/v1.26.4", - "integrity": "sha512-SpwV8A0E7t6nfWSy4tPYfmbVLjJtZu7d39tTyZ5ZUmqJ19C0dLFZHVgnUewQR6uJVkPSDyFj9PSkBiHJw7tuzw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@yarnpkg/lockfile": "^1.1.0", - "ajv": "^8.1.0", - "commondir": "^1.0.1", - "glob": "^7.1.6", - "json-schema-to-typescript": "^15.0.4", - "terser": "^5.32.0", - "yargs": "^16.1.1" - }, - "peerDependencies": { - "prettier": "*", - "typescript": "*" - } - }, - "node_modules/tooling/node_modules/ajv": { - "version": "8.20.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", - "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", - "dev": true, - "license": "MIT", - "dependencies": { - "fast-deep-equal": "^3.1.3", - "fast-uri": "^3.0.1", - "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" - } - }, - "node_modules/tooling/node_modules/json-schema-traverse": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true, - "license": "MIT" - }, "node_modules/tree-dump": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/tree-dump/-/tree-dump-1.1.0.tgz", @@ -9689,13 +9378,6 @@ "node": ">=0.10.0" } }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true, - "license": "ISC" - }, "node_modules/xdg-basedir": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-5.1.0.tgz", @@ -9709,16 +9391,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=10" - } - }, "node_modules/yallist": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", @@ -9742,60 +9414,6 @@ "url": "https://github.com/sponsors/eemeli" } }, - "node_modules/yargs": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", - "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", - "dev": true, - "license": "MIT", - "dependencies": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.0", - "y18n": "^5.0.5", - "yargs-parser": "^20.2.2" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/yargs-parser": { - "version": "20.2.9", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", - "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=10" - } - }, - "node_modules/yargs/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/yargs/node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, - "license": "MIT", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/yocto-queue": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.2.2.tgz", diff --git a/package.json b/package.json index 2c72af1c..aaec2448 100644 --- a/package.json +++ b/package.json @@ -20,23 +20,25 @@ "types": "types.d.ts", "files": [ "lib", + "types", "types.d.ts", "LICENSE" ], "scripts": { "prepare": "husky", - "lint": "npm run lint:code && npm run lint:types && npm run lint:types-test && npm run lint:special && npm run fmt:check && npm run lint:spellcheck", + "lint": "npm run lint:code && npm run lint:types && npm run lint:types-test && npm run lint:types-api && npm run lint:special && npm run fmt:check && npm run lint:spellcheck", "lint:code": "eslint --cache .", - "lint:special": "node node_modules/tooling/inherit-types && node node_modules/tooling/generate-types", + "lint:special": "node scripts/generate-types.js --check", "lint:types": "tsc", "lint:types-test": "tsc -p tsconfig.types.test.json", + "lint:types-api": "tsc -p tsconfig.types.api.json", "lint:spellcheck": "cspell --cache --no-must-find-files --quiet \"**/*.*\"", "fmt": "npm run fmt:base -- --log-level warn --write", "fmt:check": "npm run fmt:base -- --check", "fmt:base": "node_modules/prettier/bin/prettier.cjs --cache --ignore-unknown .", "fix": "npm run fix:code && npm run fix:special", "fix:code": "npm run lint:code -- --fix", - "fix:special": "node node_modules/tooling/inherit-types --write && node node_modules/tooling/generate-types --write", + "fix:special": "node scripts/generate-types.js", "type-report": "rimraf coverage && npm run cover:types && npm run cover:report && open-cli coverage/lcov-report/index.html", "pretest": "npm run lint", "test": "npm run test:only", @@ -75,7 +77,6 @@ "memfs": "^4.56.11", "prettier": "^3.7.4", "tinybench": "^6.0.0", - "tooling": "https://codeload.github.com/webpack/tooling/tar.gz/refs/tags/v1.26.4", "typescript": "^6.0.2", "webpack": "^5.107.2" }, diff --git a/scripts/generate-types.js b/scripts/generate-types.js new file mode 100644 index 00000000..1c09c37a --- /dev/null +++ b/scripts/generate-types.js @@ -0,0 +1,127 @@ +"use strict"; + +// Generates the published type declarations from the JSDoc in `lib/`. +// +// This used to be done by `webpack/tooling`, which bundled every reachable +// type into a single hand-rolled `types.d.ts`. TypeScript can emit the same +// information itself, so the declarations are now whatever `tsc` derives from +// the sources - there is no second type system to keep in sync, and a type +// that is wrong in the emitted output is wrong in the JSDoc it came from. +// +// node scripts/generate-types.js write `types/` +// node scripts/generate-types.js --check fail if `types/` is stale +// +// The check mode emits into a temporary directory and compares, so CI reports +// a stale checkout without leaving a dirty working tree behind. + +const { spawnSync } = require("child_process"); +const { + existsSync, + mkdtempSync, + readFileSync, + readdirSync, + rmSync, + statSync, +} = require("fs"); +const { tmpdir } = require("os"); +const path = require("path"); + +const root = path.join(__dirname, ".."); +const outDir = path.join(root, "types"); + +/** + * @param {string} dir directory to emit the declarations into + * @returns {void} + */ +const emit = (dir) => { + const tsc = path.join( + root, + "node_modules", + ".bin", + process.platform === "win32" ? "tsc.cmd" : "tsc", + ); + const { status } = spawnSync( + tsc, + ["-p", "tsconfig.types.json", "--declarationDir", dir], + { cwd: root, stdio: "inherit", shell: process.platform === "win32" }, + ); + + if (status !== 0) { + throw new Error(`tsc exited with ${status === null ? "a signal" : status}`); + } +}; + +/** + * @param {string} dir directory to walk + * @param {string=} prefix path of `dir` relative to the walk root + * @returns {Map} declaration path relative to `dir`, to content + */ +const readDeclarations = (dir, prefix = "") => { + /** @type {Map} */ + const declarations = new Map(); + + for (const entry of readdirSync(dir).sort()) { + const absolute = path.join(dir, entry); + const relative = prefix ? `${prefix}/${entry}` : entry; + + if (statSync(absolute).isDirectory()) { + for (const [file, content] of readDeclarations(absolute, relative)) { + declarations.set(file, content); + } + } else if (entry.endsWith(".d.ts")) { + declarations.set(relative, readFileSync(absolute, "utf8")); + } + } + + return declarations; +}; + +/** + * @returns {void} + */ +const write = () => { + rmSync(outDir, { recursive: true, force: true }); + emit(outDir); +}; + +/** + * @returns {void} + */ +const check = () => { + const temporary = mkdtempSync(path.join(tmpdir(), "enhanced-resolve-types-")); + + try { + emit(temporary); + + const expected = readDeclarations(temporary); + const actual = existsSync(outDir) ? readDeclarations(outDir) : new Map(); + /** @type {string[]} */ + const stale = []; + + for (const [file, content] of expected) { + if (actual.get(file) !== content) stale.push(`types/${file}`); + } + + for (const file of actual.keys()) { + if (!expected.has(file)) { + stale.push(`types/${file} (no longer generated)`); + } + } + + if (stale.length > 0) { + throw new Error( + `The following generated files need to be updated:\n${stale + .map((file) => ` ${file}`) + .join("\n")}\nRun \`npm run fix:special\` to update them.`, + ); + } + } finally { + rmSync(temporary, { recursive: true, force: true }); + } +}; + +if (process.argv.includes("--check")) { + check(); +} else { + write(); +} diff --git a/test/types/surface.ts b/test/types/surface.ts new file mode 100644 index 00000000..291f8a21 --- /dev/null +++ b/test/types/surface.ts @@ -0,0 +1,109 @@ +/* + * Compile-time guard on the published type surface. + * + * `types/` is generated from the JSDoc in `lib/`, so a typedef that stops being + * re-exported from `lib/index.js` silently disappears from the package's types + * without any other check noticing. Every name below was exported before the + * declarations were generated by TypeScript itself, and each is used both the + * way consumers use it and in the position (type or value) it has to support. + * + * Checked by `npm run lint:types-api`. This file is never executed. + */ + +import resolve = require("enhanced-resolve"); +import { + BaseFileSystem, + Context, + FileSystem, + Plugin, + PnpApi, + ResolveCallback, + ResolveContext, + ResolveFunction, + ResolveFunctionAsync, + ResolveFunctionPromise, + ResolveOptions, + ResolveOptionsOptionalFS, + ResolveRequest, + Resolver, + SyncFileSystem, +} from "enhanced-resolve"; + +// Exported types must be usable in a type position. +declare const baseFileSystem: BaseFileSystem; +declare const context: Context; +declare const fileSystem: FileSystem; +declare const plugin: Plugin; +declare const pnpApi: PnpApi; +declare const resolveCallback: ResolveCallback; +declare const resolveContext: ResolveContext; +declare const resolveFunction: ResolveFunction; +declare const resolveFunctionAsync: ResolveFunctionAsync; +declare const resolveFunctionPromise: ResolveFunctionPromise; +declare const resolveOptions: ResolveOptions; +declare const resolveOptionsOptionalFS: ResolveOptionsOptionalFS; +declare const resolveRequest: ResolveRequest; +declare const resolver: Resolver; +declare const syncFileSystem: SyncFileSystem; + +// The exported classes must be usable as a type and as a constructor. +declare const cachedInputFileSystem: resolve.CachedInputFileSystem; +declare const cloneBasenamePlugin: resolve.CloneBasenamePlugin; +declare const logInfoPlugin: resolve.LogInfoPlugin; +declare const tsconfigPathsPlugin: resolve.TsconfigPathsPlugin; + +new resolve.CachedInputFileSystem(baseFileSystem, 4000); +new resolve.CloneBasenamePlugin("described-resolve", "resolve"); +new resolve.LogInfoPlugin("resolve"); +new resolve.TsconfigPathsPlugin({}); + +// The module itself is callable, in each documented argument shape. +resolve("/parent", "./specifier", resolveCallback); +resolve(context, "/parent", "./specifier", resolveCallback); +resolve("/parent", "./specifier", resolveContext, resolveCallback); +resolve(context, "/parent", "./specifier", resolveContext, resolveCallback); + +const sync: string | false = resolve.sync("/parent", "./specifier"); +const promise: Promise = resolve.promise( + "/parent", + "./specifier", +); + +const created: ResolveFunctionAsync = resolve.create({}); +const createdSync: ResolveFunction = resolve.create.sync({}); +const createdPromise: ResolveFunctionPromise = resolve.create.promise({}); + +const factoryResolver: Resolver = resolve.ResolverFactory.createResolver({ + fileSystem, +}); + +resolve.forEachBail( + [1, 2, 3], + (item, callback) => callback(), + (err, result) => {}, +); + +export { + baseFileSystem, + cachedInputFileSystem, + cloneBasenamePlugin, + context, + created, + createdPromise, + createdSync, + factoryResolver, + logInfoPlugin, + plugin, + pnpApi, + promise, + resolveFunction, + resolveFunctionAsync, + resolveFunctionPromise, + resolveOptions, + resolveOptionsOptionalFS, + resolveRequest, + resolver, + sync, + syncFileSystem, + tsconfigPathsPlugin, +}; diff --git a/tsconfig.types.api.json b/tsconfig.types.api.json new file mode 100644 index 00000000..ed0111ed --- /dev/null +++ b/tsconfig.types.api.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig", + "compilerOptions": { + "allowJs": false, + "checkJs": false, + "paths": { + "enhanced-resolve": ["./types.d.ts"] + } + }, + "include": ["test/types/*.ts"] +} diff --git a/tsconfig.types.json b/tsconfig.types.json index 1c66acf6..7d0dc8c4 100644 --- a/tsconfig.types.json +++ b/tsconfig.types.json @@ -1,3 +1,10 @@ { - "extends": "./tsconfig" + "extends": "./tsconfig", + "compilerOptions": { + "noEmit": false, + "declaration": true, + "emitDeclarationOnly": true, + "rootDir": "lib", + "declarationDir": "types" + } } diff --git a/types.d.ts b/types.d.ts index 8701a271..c8ec3d3b 100644 --- a/types.d.ts +++ b/types.d.ts @@ -1,2107 +1,9 @@ /* - * This file was automatically generated. - * DO NOT MODIFY BY HAND. - * Run `yarn fix:special` to update + * The type declarations are generated from the JSDoc in `lib/` and live in + * `types/`. This file re-exports the entry point so that the `types` field and + * any direct reference to `enhanced-resolve/types.d.ts` keep resolving. */ -import { Buffer } from "buffer"; -import { AsyncSeriesBailHook, AsyncSeriesHook, SyncHook } from "tapable"; -import { URL as URL_Import } from "url"; +import resolve = require("./types/index"); -declare interface Abortable { - /** - * When provided the corresponding `AbortController` can be used to cancel an asynchronous action. - */ - signal?: AbortSignal; -} -type Alias = string | false | string[]; -declare interface AliasOption { - alias: Alias; - name: string; - onlyModule?: boolean; -} -type BaseFileSystem = FileSystem & SyncFileSystem; -declare interface BaseResolveRequest { - /** - * path - */ - path: string | false; - - /** - * content - */ - context?: Context; - - /** - * description file path - */ - descriptionFilePath?: string; - - /** - * description file root - */ - descriptionFileRoot?: string; - - /** - * description file data - */ - descriptionFileData?: JsonObject; - - /** - * tsconfig paths map - */ - tsconfigPathsMap?: null | TsconfigPathsMap; - - /** - * relative path - */ - relativePath?: string; - - /** - * true when need to ignore symlinks, otherwise false - */ - ignoreSymlinks?: boolean; - - /** - * true when full specified, otherwise false - */ - fullySpecified?: boolean; - - /** - * package id the request was resolved to in the package map, to be propagated to resolutions made from the resulting file (`@experimental`, see the `packageMap` option) - */ - packageId?: string; - - /** - * inner request for internal usage - */ - __innerRequest?: string; - - /** - * inner request for internal usage - */ - __innerRequest_request?: string; - - /** - * inner relative path for internal usage - */ - __innerRequest_relativePath?: string; - - /** - * internal: shared marker `RestrictionsPlugin` flips when it filters out an existing target, letting `ExportsFieldPlugin` fall back instead of erroring - */ - __restrictionsMarker?: { blocked: boolean }; -} -declare interface BasenameCacheEntry { - /** - * cached dirname function - */ - fn: (maybePath: string, suffix?: string) => string; - - /** - * the underlying cache map - */ - cache: Map>; -} -type BufferEncoding = - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex"; -type BufferEncodingOption = "buffer" | { encoding: "buffer" }; -declare interface Cache { - [index: string]: undefined | ResolveRequest | ResolveRequest[]; -} -declare class CachedInputFileSystem { - constructor(fileSystem: BaseFileSystem, duration: number); - fileSystem: BaseFileSystem; - lstat?: LStat; - lstatSync?: LStatSync; - stat: Stat; - statSync: StatSync; - readdir: Readdir; - readdirSync: ReaddirSync; - readFile: ReadFile; - readFileSync: ReadFileSync; - readJson?: ( - pathOrFileDescription: PathOrFileDescriptor, - callback: ( - err: null | Error | NodeJS.ErrnoException, - result?: JsonObject, - ) => void, - ) => void; - readJsonSync?: (pathOrFileDescription: PathOrFileDescriptor) => JsonObject; - readlink: Readlink; - readlinkSync: ReadlinkSync; - realpath?: RealPath; - realpathSync?: RealPathSync; - purge( - what?: - | string - | number - | URL_url - | Buffer - | (string | number | URL_url | Buffer)[] - | Set, - options?: { exact?: boolean }, - ): void; -} -declare class CloneBasenamePlugin { - constructor( - source: - | string - | AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >, - target: - | string - | AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >, - ); - source: - | string - | AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >; - target: - | string - | AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >; - apply(resolver: Resolver): void; -} -declare interface CompiledAliasOption { - /** - * original alias name - */ - name: string; - - /** - * name + "/" — precomputed to avoid per-resolve concat - */ - nameWithSlash: string; - - /** - * alias target(s) - */ - alias: Alias; - - /** - * normalized onlyModule flag - */ - onlyModule: boolean; - - /** - * absolute form of `name` (with slash ending), null when not absolute - */ - absolutePath: null | string; - - /** - * substring before the single "*" in `name`, null when no wildcard - */ - wildcardPrefix: null | string; - - /** - * substring after the single "*" in `name`, null when no wildcard - */ - wildcardSuffix: null | string; - - /** - * first character code of `name` — used as a cheap screen on the hot path. `-1` indicates "matches any first char" (empty wildcard prefix). - */ - firstCharCode: number; - - /** - * true when `alias` is an array — precomputed so the hot path skips `Array.isArray` - */ - arrayAlias: boolean; -} -declare interface CompiledAliasOptions { - /** - * declaration-ordered list - */ - all: CompiledAliasOption[]; - - /** - * bucketed by first char code - */ - byFirstChar: Map; - - /** - * true when an empty-prefix wildcard is present - */ - hasAnyFirstChar: boolean; - - /** - * true when the bucket fast-path should be used at resolve time - */ - useBuckets: boolean; -} -type Context = KnownContext & Record; -declare interface Dirent { - /** - * true when is file, otherwise false - */ - isFile: () => boolean; - - /** - * true when is directory, otherwise false - */ - isDirectory: () => boolean; - - /** - * true when is block device, otherwise false - */ - isBlockDevice: () => boolean; - - /** - * true when is character device, otherwise false - */ - isCharacterDevice: () => boolean; - - /** - * true when is symbolic link, otherwise false - */ - isSymbolicLink: () => boolean; - - /** - * true when is FIFO, otherwise false - */ - isFIFO: () => boolean; - - /** - * true when is socket, otherwise false - */ - isSocket: () => boolean; - - /** - * name - */ - name: T; - - /** - * path - */ - parentPath: string; - - /** - * path - */ - path?: string; -} -declare interface DirnameCacheEntry { - /** - * cached dirname function - */ - fn: (maybePath: string) => string; - - /** - * the underlying cache map - */ - cache: Map; -} -type EncodingOption = - | undefined - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex" - | ObjectEncodingOptions; -type ErrorWithDetail = Error & { details?: string }; -declare interface ExtensionAliasOption { - alias: string | string[]; - extension: string; -} -declare interface ExtensionAliasOptions { - [index: string]: string | string[]; -} -declare interface FileSystem { - /** - * read file method - */ - readFile: ReadFile; - - /** - * readdir method - */ - readdir: Readdir; - - /** - * read json method - */ - readJson?: ( - pathOrFileDescription: PathOrFileDescriptor, - callback: ( - err: null | Error | NodeJS.ErrnoException, - result?: JsonObject, - ) => void, - ) => void; - - /** - * read link method - */ - readlink: Readlink; - - /** - * lstat method - */ - lstat?: LStat; - - /** - * stat method - */ - stat: Stat; - - /** - * realpath method - */ - realpath?: RealPath; -} -type IBigIntStats = IStatsBase & { - atimeNs: bigint; - mtimeNs: bigint; - ctimeNs: bigint; - birthtimeNs: bigint; -}; -declare interface IStats { - /** - * is file - */ - isFile: () => boolean; - - /** - * is directory - */ - isDirectory: () => boolean; - - /** - * is block device - */ - isBlockDevice: () => boolean; - - /** - * is character device - */ - isCharacterDevice: () => boolean; - - /** - * is symbolic link - */ - isSymbolicLink: () => boolean; - - /** - * is FIFO - */ - isFIFO: () => boolean; - - /** - * is socket - */ - isSocket: () => boolean; - - /** - * dev - */ - dev: number; - - /** - * ino - */ - ino: number; - - /** - * mode - */ - mode: number; - - /** - * nlink - */ - nlink: number; - - /** - * uid - */ - uid: number; - - /** - * gid - */ - gid: number; - - /** - * rdev - */ - rdev: number; - - /** - * size - */ - size: number; - - /** - * blksize - */ - blksize: number; - - /** - * blocks - */ - blocks: number; - - /** - * atime ms - */ - atimeMs: number; - - /** - * mtime ms - */ - mtimeMs: number; - - /** - * ctime ms - */ - ctimeMs: number; - - /** - * birthtime ms - */ - birthtimeMs: number; - - /** - * atime - */ - atime: Date; - - /** - * mtime - */ - mtime: Date; - - /** - * ctime - */ - ctime: Date; - - /** - * birthtime - */ - birthtime: Date; -} -declare interface IStatsBase { - /** - * is file - */ - isFile: () => boolean; - - /** - * is directory - */ - isDirectory: () => boolean; - - /** - * is block device - */ - isBlockDevice: () => boolean; - - /** - * is character device - */ - isCharacterDevice: () => boolean; - - /** - * is symbolic link - */ - isSymbolicLink: () => boolean; - - /** - * is FIFO - */ - isFIFO: () => boolean; - - /** - * is socket - */ - isSocket: () => boolean; - - /** - * dev - */ - dev: T; - - /** - * ino - */ - ino: T; - - /** - * mode - */ - mode: T; - - /** - * nlink - */ - nlink: T; - - /** - * uid - */ - uid: T; - - /** - * gid - */ - gid: T; - - /** - * rdev - */ - rdev: T; - - /** - * size - */ - size: T; - - /** - * blksize - */ - blksize: T; - - /** - * blocks - */ - blocks: T; - - /** - * atime ms - */ - atimeMs: T; - - /** - * mtime ms - */ - mtimeMs: T; - - /** - * ctime ms - */ - ctimeMs: T; - - /** - * birthtime ms - */ - birthtimeMs: T; - - /** - * atime - */ - atime: Date; - - /** - * mtime - */ - mtime: Date; - - /** - * ctime - */ - ctime: Date; - - /** - * birthtime - */ - birthtime: Date; -} -declare interface Iterator { - ( - item: T, - callback: (err?: null | Error, result?: null | Z) => void, - i: number, - ): void; -} -declare interface JoinCacheEntry { - /** - * cached join function - */ - fn: (rootPath: string, request: string) => string; - - /** - * the underlying cache map - */ - cache: Map>; -} -declare interface JsonObject { - [index: string]: - undefined | null | string | number | boolean | JsonObject | JsonValue[]; -} -type JsonValue = null | string | number | boolean | JsonObject | JsonValue[]; -declare interface KnownContext { - /** - * environments - */ - environments?: string[]; - - /** - * package id of the importing file in the package map, propagated from a previous result to disambiguate package entries that share a location (`@experimental`, see the `packageMap` option) - */ - packageId?: string; -} -declare interface KnownHooks { - /** - * resolve step hook - */ - resolveStep: SyncHook< - [ - AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >, - ResolveRequest, - ] - >; - - /** - * no resolve hook - */ - noResolve: SyncHook<[ResolveRequest, Error]>; - - /** - * resolve hook - */ - resolve: AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >; - - /** - * result hook - */ - result: AsyncSeriesHook<[ResolveRequest, ResolveContext]>; -} -declare interface LStat { - ( - path: PathLike, - callback: (err: null | NodeJS.ErrnoException, result?: IStats) => void, - ): void; - ( - path: PathLike, - options: undefined | (StatOptions & { bigint?: false }), - callback: (err: null | NodeJS.ErrnoException, result?: IStats) => void, - ): void; - ( - path: PathLike, - options: StatOptions & { bigint: true }, - callback: ( - err: null | NodeJS.ErrnoException, - result?: IBigIntStats, - ) => void, - ): void; - ( - path: PathLike, - options: undefined | StatOptions, - callback: ( - err: null | NodeJS.ErrnoException, - result?: IStats | IBigIntStats, - ) => void, - ): void; -} -declare interface LStatSync { - (path: PathLike, options?: undefined): IStats; - ( - path: PathLike, - options?: StatSyncOptions & { bigint?: false; throwIfNoEntry: false }, - ): undefined | IStats; - ( - path: PathLike, - options: StatSyncOptions & { bigint: true; throwIfNoEntry: false }, - ): undefined | IBigIntStats; - (path: PathLike, options?: StatSyncOptions & { bigint?: false }): IStats; - (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats; - ( - path: PathLike, - options: StatSyncOptions & { bigint: boolean; throwIfNoEntry?: false }, - ): IStats | IBigIntStats; - ( - path: PathLike, - options?: StatSyncOptions, - ): undefined | IStats | IBigIntStats; -} -declare class LogInfoPlugin { - constructor( - source: - | string - | AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >, - ); - source: - | string - | AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >; - apply(resolver: Resolver): void; -} -declare interface ObjectEncodingOptions { - /** - * encoding - */ - encoding?: - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex"; -} -declare interface PackageMapDependencies { - [index: string]: string; -} -declare interface PackageMapOptions { - /** - * absolute path of the configuration file, read lazily when `packages` is not given - */ - configFile: null | string; - - /** - * an already-parsed `packages` object, used instead of reading `configFile` - */ - packages: null | PackageMapPackages; -} -declare interface PackageMapPackage { - /** - * an absolute or relative `file:` URL, resolved against the configuration file - */ - url: string; - - /** - * bare specifier to package id - */ - dependencies?: PackageMapDependencies; -} -declare interface PackageMapPackages { - [index: string]: PackageMapPackage; -} -declare interface ParsedIdentifier { - /** - * request - */ - request: string; - - /** - * query - */ - query: string; - - /** - * fragment - */ - fragment: string; - - /** - * is directory - */ - directory: boolean; - - /** - * is module - */ - module: boolean; - - /** - * is file - */ - file: boolean; - - /** - * is internal - */ - internal: boolean; -} -declare interface PathCacheFunctions { - /** - * cached join - */ - join: JoinCacheEntry; - - /** - * cached dirname - */ - dirname: DirnameCacheEntry; - - /** - * cached basename - */ - basename: BasenameCacheEntry; -} -type PathLike = string | URL_url | Buffer; -type PathOrFileDescriptor = string | number | URL_url | Buffer; -type Plugin = - | undefined - | null - | false - | "" - | 0 - | { apply: (this: Resolver, resolver: Resolver) => void } - | ((this: Resolver, resolver: Resolver) => void); -declare interface PnpApi { - /** - * resolve to unqualified - */ - resolveToUnqualified: ( - packageName: string, - issuer: string, - options: { considerBuiltins: boolean }, - ) => null | string; -} -declare interface ReadFile { - ( - path: PathOrFileDescriptor, - options: - undefined | null | ({ encoding?: null; flag?: string } & Abortable), - callback: (err: null | NodeJS.ErrnoException, result?: Buffer) => void, - ): void; - ( - path: PathOrFileDescriptor, - options: - | ({ encoding: BufferEncoding; flag?: string } & Abortable) - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex", - callback: (err: null | NodeJS.ErrnoException, result?: string) => void, - ): void; - ( - path: PathOrFileDescriptor, - options: - | undefined - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex" - | (ObjectEncodingOptions & { flag?: string } & Abortable), - callback: ( - err: null | NodeJS.ErrnoException, - result?: string | Buffer, - ) => void, - ): void; - ( - path: PathOrFileDescriptor, - callback: (err: null | NodeJS.ErrnoException, result?: Buffer) => void, - ): void; -} -declare interface ReadFileSync { - ( - path: PathOrFileDescriptor, - options?: null | { encoding?: null; flag?: string }, - ): Buffer; - ( - path: PathOrFileDescriptor, - options: - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex" - | { encoding: BufferEncoding; flag?: string }, - ): string; - ( - path: PathOrFileDescriptor, - options?: - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex" - | (ObjectEncodingOptions & { flag?: string }), - ): string | Buffer; -} -declare interface Readdir { - ( - path: PathLike, - options: - | undefined - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex" - | { - encoding: - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex"; - withFileTypes?: false; - recursive?: boolean; - }, - callback: (err: null | NodeJS.ErrnoException, files?: string[]) => void, - ): void; - ( - path: PathLike, - options: - | { encoding: "buffer"; withFileTypes?: false; recursive?: boolean } - | "buffer", - callback: (err: null | NodeJS.ErrnoException, files?: Buffer[]) => void, - ): void; - ( - path: PathLike, - options: - | undefined - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex" - | (ObjectEncodingOptions & { - withFileTypes?: false; - recursive?: boolean; - }), - callback: ( - err: null | NodeJS.ErrnoException, - files?: string[] | Buffer[], - ) => void, - ): void; - ( - path: PathLike, - callback: (err: null | NodeJS.ErrnoException, files?: string[]) => void, - ): void; - ( - path: PathLike, - options: ObjectEncodingOptions & { - withFileTypes: true; - recursive?: boolean; - }, - callback: ( - err: null | NodeJS.ErrnoException, - files?: Dirent[], - ) => void, - ): void; - ( - path: PathLike, - options: { encoding: "buffer"; withFileTypes: true; recursive?: boolean }, - callback: ( - err: null | NodeJS.ErrnoException, - files: Dirent[], - ) => void, - ): void; -} -declare interface ReaddirSync { - ( - path: PathLike, - options?: - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex" - | { - encoding: - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex"; - withFileTypes?: false; - recursive?: boolean; - }, - ): string[]; - ( - path: PathLike, - options: - | "buffer" - | { encoding: "buffer"; withFileTypes?: false; recursive?: boolean }, - ): Buffer[]; - ( - path: PathLike, - options?: - | null - | "ascii" - | "utf8" - | "utf-8" - | "utf16le" - | "utf-16le" - | "ucs2" - | "ucs-2" - | "base64" - | "base64url" - | "latin1" - | "binary" - | "hex" - | (ObjectEncodingOptions & { - withFileTypes?: false; - recursive?: boolean; - }), - ): string[] | Buffer[]; - ( - path: PathLike, - options: ObjectEncodingOptions & { - withFileTypes: true; - recursive?: boolean; - }, - ): Dirent[]; - ( - path: PathLike, - options: { encoding: "buffer"; withFileTypes: true; recursive?: boolean }, - ): Dirent[]; -} -declare interface Readlink { - ( - path: PathLike, - options: EncodingOption, - callback: (err: null | NodeJS.ErrnoException, result?: string) => void, - ): void; - ( - path: PathLike, - options: BufferEncodingOption, - callback: (err: null | NodeJS.ErrnoException, result?: Buffer) => void, - ): void; - ( - path: PathLike, - options: EncodingOption, - callback: ( - err: null | NodeJS.ErrnoException, - result?: string | Buffer, - ) => void, - ): void; - ( - path: PathLike, - callback: (err: null | NodeJS.ErrnoException, result?: string) => void, - ): void; -} -declare interface ReadlinkSync { - (path: PathLike, options?: EncodingOption): string; - (path: PathLike, options: BufferEncodingOption): Buffer; - (path: PathLike, options?: EncodingOption): string | Buffer; -} -declare interface RealPath { - ( - path: PathLike, - options: EncodingOption, - callback: (err: null | NodeJS.ErrnoException, result?: string) => void, - ): void; - ( - path: PathLike, - options: BufferEncodingOption, - callback: (err: null | NodeJS.ErrnoException, result?: Buffer) => void, - ): void; - ( - path: PathLike, - options: EncodingOption, - callback: ( - err: null | NodeJS.ErrnoException, - result?: string | Buffer, - ) => void, - ): void; - ( - path: PathLike, - callback: (err: null | NodeJS.ErrnoException, result?: string) => void, - ): void; -} -declare interface RealPathSync { - (path: PathLike, options?: EncodingOption): string; - (path: PathLike, options: BufferEncodingOption): Buffer; - (path: PathLike, options?: EncodingOption): string | Buffer; -} -declare interface ResolveContext { - /** - * directories that was found on file system - */ - contextDependencies?: WriteOnlySet; - - /** - * files that was found on file system - */ - fileDependencies?: WriteOnlySet; - - /** - * dependencies that was not found on file system - */ - missingDependencies?: WriteOnlySet; - - /** - * tip of the resolver call stack (a singly-linked list with Set-like API). For instance, `resolve → parsedResolve → describedResolve`. Accepts a legacy `Set` for back-compat with older callers; it is normalized internally without a hot-path branch. - */ - stack?: StackEntry | Set; - - /** - * log function - */ - log?: (str: string) => void; - - /** - * yield result, if provided plugins can return several results - */ - yield?: (request: ResolveRequest) => void; -} -declare interface ResolveFunction { - ( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - resolveContext?: ResolveContext, - ): string | false; - ( - parent: string | URL_url, - specifier: string | URL_url, - resolveContext?: ResolveContext, - ): string | false; -} -declare interface ResolveFunctionAsync { - ( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - resolveContext: ResolveContext, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, - ): void; - ( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, - ): void; - ( - parent: string | URL_url, - specifier: string | URL_url, - resolveContext: ResolveContext, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, - ): void; - ( - parent: string | URL_url, - specifier: string | URL_url, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, - ): void; -} -declare interface ResolveFunctionPromise { - ( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - resolveContext?: ResolveContext, - ): Promise; - ( - parent: string | URL_url, - specifier: string | URL_url, - resolveContext?: ResolveContext, - ): Promise; -} -type ResolveOptionsOptionalFS = Omit< - ResolveOptionsResolverFactoryObject_2, - "fileSystem" -> & - Partial>; -declare interface ResolveOptionsResolverFactoryObject_1 { - /** - * alias - */ - alias: AliasOption[]; - - /** - * fallback - */ - fallback: AliasOption[]; - - /** - * alias fields - */ - aliasFields: Set; - - /** - * extension alias - */ - extensionAlias: ExtensionAliasOption[]; - - /** - * apply extension alias to exports field targets - */ - extensionAliasForExports: boolean; - - /** - * cache predicate - */ - cachePredicate: (predicate: ResolveRequest) => boolean; - - /** - * cache with context - */ - cacheWithContext: boolean; - - /** - * A list of exports field condition names. - */ - conditionNames: Set; - - /** - * description files - */ - descriptionFiles: string[]; - - /** - * enforce extension - */ - enforceExtension: boolean; - - /** - * exports fields - */ - exportsFields: Set; - - /** - * imports fields - */ - importsFields: Set; - - /** - * extensions - */ - extensions: Set; - - /** - * fileSystem - */ - fileSystem: FileSystem; - - /** - * unsafe cache - */ - unsafeCache: false | Cache; - - /** - * symlinks - */ - symlinks: boolean; - - /** - * resolver - */ - resolver?: Resolver; - - /** - * modules - */ - modules: (string | string[])[]; - - /** - * main fields - */ - mainFields: { name: string[]; forceRelative: boolean }[]; - - /** - * main files - */ - mainFiles: Set; - - /** - * plugins - */ - plugins: Plugin[]; - - /** - * package map - */ - packageMap: null | PackageMapOptions; - - /** - * pnp API - */ - pnpApi: null | PnpApi; - - /** - * roots - */ - roots: Set; - - /** - * fully specified - */ - fullySpecified: boolean; - - /** - * resolve to context - */ - resolveToContext: boolean; - - /** - * restrictions - */ - restrictions: Set; - - /** - * prefer relative - */ - preferRelative: boolean; - - /** - * prefer absolute - */ - preferAbsolute: boolean; - - /** - * tsconfig file path or config object - */ - tsconfig: string | boolean | TsconfigOptions; -} -declare interface ResolveOptionsResolverFactoryObject_2 { - /** - * A list of module alias configurations or an object which maps key to value - */ - alias?: UserAliasOptions | UserAliasOptionEntry[]; - - /** - * A list of module alias configurations or an object which maps key to value, applied only after modules option - */ - fallback?: UserAliasOptions | UserAliasOptionEntry[]; - - /** - * An object which maps extension to extension aliases - */ - extensionAlias?: ExtensionAliasOptions; - - /** - * Also apply `extensionAlias` to paths resolved through the package.json `exports` field. Off by default (Node.js-aligned); when enabled, matches TypeScript's behavior for packages that ship TS sources alongside compiled JS. - */ - extensionAliasForExports?: boolean; - - /** - * A list of alias fields in description files - */ - aliasFields?: (string | string[])[]; - - /** - * A function which decides whether a request should be cached or not. An object is passed with at least `path` and `request` properties. - */ - cachePredicate?: (predicate: ResolveRequest) => boolean; - - /** - * Whether or not the unsafeCache should include request context as part of the cache key. - */ - cacheWithContext?: boolean; - - /** - * A list of description files to read from - */ - descriptionFiles?: string[]; - - /** - * A list of exports field condition names. - */ - conditionNames?: string[]; - - /** - * Enforce that a extension from extensions must be used - */ - enforceExtension?: boolean; - - /** - * A list of exports fields in description files - */ - exportsFields?: (string | string[])[]; - - /** - * A list of imports fields in description files - */ - importsFields?: (string | string[])[]; - - /** - * A list of extensions which should be tried for files - */ - extensions?: string[]; - - /** - * The file system which should be used - */ - fileSystem: FileSystem; - - /** - * Use this cache object to unsafely cache the successful requests - */ - unsafeCache?: boolean | Cache; - - /** - * Resolve symlinks to their symlinked location - */ - symlinks?: boolean; - - /** - * A prepared Resolver to which the plugins are attached - */ - resolver?: Resolver; - - /** - * A list of directories to resolve modules from, can be absolute path, folder name, or a `file:` URL - */ - modules?: string | URL_url | (string | URL_url)[]; - - /** - * A list of main fields in description files - */ - mainFields?: ( - string | string[] | { name: string | string[]; forceRelative: boolean } - )[]; - - /** - * A list of main files in directories - */ - mainFiles?: string[]; - - /** - * A list of additional resolve plugins which should be applied - */ - plugins?: Plugin[]; - - /** - * A Node.js package map file path (or `file:` `URL` instance), or an object with the already-parsed `packages`. When set, bare specifiers resolve through the map instead of `node_modules` (`@experimental`) - */ - packageMap?: string | URL_url | UserPackageMapOptions; - - /** - * A PnP API that should be used - null is "never", undefined is "auto" - */ - pnpApi?: null | PnpApi; - - /** - * A list of root paths, each an absolute path or a `file:` URL - */ - roots?: (string | URL_url)[]; - - /** - * The request is already fully specified and no extensions or directories are resolved for it - */ - fullySpecified?: boolean; - - /** - * Resolve to a context instead of a file - */ - resolveToContext?: boolean; - - /** - * A list of resolve restrictions, each an absolute path, a `file:` URL, or a RegExp - */ - restrictions?: (string | RegExp | URL_url)[]; - - /** - * Use only the sync constraints of the file system calls - */ - useSyncFileSystemCalls?: boolean; - - /** - * Prefer to resolve module requests as relative requests before falling back to modules - */ - preferRelative?: boolean; - - /** - * Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots - */ - preferAbsolute?: boolean; - - /** - * TypeScript config file path (or `file:` URL) or config object with configFile and references - */ - tsconfig?: string | boolean | URL_url | UserTsconfigOptions; -} -type ResolveRequest = BaseResolveRequest & Partial; -declare abstract class Resolver { - fileSystem: FileSystem; - options: ResolveOptionsResolverFactoryObject_1; - pathCache: PathCacheFunctions; - hooks: KnownHooks; - ensureHook( - name: - | string - | AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >, - ): AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >; - getHook( - name: - | string - | AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >, - ): AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >; - resolveSync( - parent: string | URL_url, - specifier: string | URL_url, - resolveContext?: ResolveContext, - ): string | false; - resolveSync( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - resolveContext?: ResolveContext, - ): string | false; - resolvePromise( - parent: string | URL_url, - specifier: string | URL_url, - resolveContext?: ResolveContext, - ): Promise; - resolvePromise( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - resolveContext?: ResolveContext, - ): Promise; - resolve( - parent: string | URL_url, - specifier: string | URL_url, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, - ): void; - resolve( - parent: string | URL_url, - specifier: string | URL_url, - resolveContext: ResolveContext, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, - ): void; - resolve( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, - ): void; - resolve( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - resolveContext: ResolveContext, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, - ): void; - doResolve( - hook: AsyncSeriesBailHook< - [ResolveRequest, ResolveContext], - null | ResolveRequest - >, - request: ResolveRequest, - message: null | string, - resolveContext: ResolveContext, - callback: (err?: null | Error, result?: ResolveRequest) => void, - ): void; - parse(identifier: string): ParsedIdentifier; - isModule(path: string): boolean; - isPrivate(path: string): boolean; - isDirectory(path: string): boolean; - normalize(path: string): string; - join(path: string, request: string): string; - dirname(path: string): string; - basename(path: string, suffix?: string): string; -} - -/** - * Singly-linked stack entry that also exposes a Set-like API - * (`has`, `size`, iteration). Each `doResolve` call prepends a new - * `StackEntry` that points at the previous tip via `.parent`, so pushing - * is O(1) in time and memory. Recursion detection walks the linked list - * (O(n)) but the stack is typically shallow, so this is cheaper overall - * than cloning a `Set` per call. - */ -declare abstract class StackEntry { - name?: string; - path: string | false; - request: string; - query: string; - fragment: string; - directory: boolean; - module: boolean; - parent?: StackEntry; - - /** - * Strings seeded by callers that still pass `stack: new Set([...])`. - * Propagated through the chain so deeper `doResolve` calls still see - * them during recursion checks. `undefined` in the common case so - * there is no extra work on the hot path. - */ - preSeeded?: Set; - - /** - * Walk the linked list looking for an entry with the same request shape. - * Set-compatible: callers that used `stack.has(entry)` keep working. - * NOTE: kept monomorphic on purpose. An earlier draft accepted a string - * query too (so pre-5.21 plugins keeping their own `Set` of - * seen entries could probe the live stack with the formatted form), - * but adding the second shape regressed `doResolve`'s heap profile by - * ~1 MiB / 200 resolves on stack-churn — V8 keeps a polymorphic - * call-site state for `parent.has(stackEntry)` once `has` has two - * argument shapes. Plugins that need string membership can reach for - * `[...stack].find(e => e.includes(formattedString))` via the - * `String`-method proxies on `StackEntry` instead. - */ - has(query: StackEntry): boolean; - - /** - * Number of entries on the stack (oldest-to-newest length). - */ - get size(): number; - - /** - * Human-readable form used in recursion error messages, logs, and the - * iterator above. Not memoized: caching would require an extra slot on - * every `StackEntry`, which costs heap even on resolves that never look - * at the formatted form. - */ - toString(): string; - - /** - * Iterate entries from oldest (root) to newest (tip), matching how a - * `Set` that was populated in insertion order would iterate. Pre-seeded - * legacy `Set` entries come first so error-message output stays - * ordered oldest-to-newest. - * Yields each entry as its formatted `toString()` form. Plugins written - * against the pre-5.21 `Set` shape — e.g. - * `[...resolveContext.stack].find(a => a.includes("module:"))` — keep - * working unchanged because each yielded value is a plain string with - * all of `String.prototype` available natively. Resolves that never - * iterate the stack pay nothing; iteration costs one `toString()` - * allocation per stack frame. - */ - [Symbol.iterator](): IterableIterator; -} -declare interface Stat { - ( - path: PathLike, - callback: (err: null | NodeJS.ErrnoException, result?: IStats) => void, - ): void; - ( - path: PathLike, - options: undefined | (StatOptions & { bigint?: false }), - callback: (err: null | NodeJS.ErrnoException, result?: IStats) => void, - ): void; - ( - path: PathLike, - options: StatOptions & { bigint: true }, - callback: ( - err: null | NodeJS.ErrnoException, - result?: IBigIntStats, - ) => void, - ): void; - ( - path: PathLike, - options: undefined | StatOptions, - callback: ( - err: null | NodeJS.ErrnoException, - result?: IStats | IBigIntStats, - ) => void, - ): void; -} -declare interface StatOptions { - /** - * need bigint values - */ - bigint?: boolean; -} -declare interface StatSync { - (path: PathLike, options?: undefined): IStats; - ( - path: PathLike, - options?: StatSyncOptions & { bigint?: false; throwIfNoEntry: false }, - ): undefined | IStats; - ( - path: PathLike, - options: StatSyncOptions & { bigint: true; throwIfNoEntry: false }, - ): undefined | IBigIntStats; - (path: PathLike, options?: StatSyncOptions & { bigint?: false }): IStats; - (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats; - ( - path: PathLike, - options: StatSyncOptions & { bigint: boolean; throwIfNoEntry?: false }, - ): IStats | IBigIntStats; - ( - path: PathLike, - options?: StatSyncOptions, - ): undefined | IStats | IBigIntStats; -} -declare interface StatSyncOptions { - /** - * need bigint values - */ - bigint?: boolean; - - /** - * throw if no entry - */ - throwIfNoEntry?: boolean; -} -declare interface SyncFileSystem { - /** - * read file sync method - */ - readFileSync: ReadFileSync; - - /** - * read dir sync method - */ - readdirSync: ReaddirSync; - - /** - * read json sync method - */ - readJsonSync?: (pathOrFileDescription: PathOrFileDescriptor) => JsonObject; - - /** - * read link sync method - */ - readlinkSync: ReadlinkSync; - - /** - * lstat sync method - */ - lstatSync?: LStatSync; - - /** - * stat sync method - */ - statSync: StatSync; - - /** - * real path sync method - */ - realpathSync?: RealPathSync; -} -declare interface TsconfigOptions { - /** - * A relative path to the tsconfig file based on cwd, or an absolute path of tsconfig file - */ - configFile?: string; - - /** - * References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths - */ - references?: string[] | "auto"; - - /** - * Override baseUrl from tsconfig.json. If provided, this value will be used instead of the baseUrl in the tsconfig file - */ - baseUrl?: string; -} -declare interface TsconfigPathsData { - /** - * tsconfig file data - */ - alias: CompiledAliasOptions; - - /** - * tsconfig file data - */ - modules: string[]; -} -declare interface TsconfigPathsMap { - /** - * main tsconfig paths data - */ - main: TsconfigPathsData; - - /** - * main tsconfig base URL (absolute path) - */ - mainContext: string; - - /** - * referenced tsconfig paths data mapped by baseUrl - */ - refs: { [index: string]: TsconfigPathsData }; - - /** - * all contexts (main + refs) for quick lookup - */ - allContexts: { [index: string]: TsconfigPathsData }; - - /** - * precomputed `Object.keys(allContexts)` — read-only; used on the `_selectPathsDataForContext` hot path - */ - contextList: string[]; - - /** - * file dependencies - */ - fileDependencies: Set; -} -declare class TsconfigPathsPlugin { - constructor(configFileOrOptions: string | true | TsconfigOptions); - isAutoConfigFile: boolean; - configFile: string; - references: "auto" | TsconfigReference[]; - baseUrl?: string; - apply(resolver: Resolver): void; -} -declare interface TsconfigReference { - /** - * Path to the referenced project - */ - path: string; -} -declare interface URL_url extends URL_Import {} -declare interface UserAliasOptionEntry { - alias: UserAliasOptionNewRequest; - name: string; - onlyModule?: boolean; -} -type UserAliasOptionNewRequest = - string | false | URL_url | (string | URL_url)[]; -declare interface UserAliasOptions { - [index: string]: UserAliasOptionNewRequest; -} -declare interface UserPackageMapOptions { - /** - * A path, or `file:` `URL` instance, pointing at the package map file. Required together with `packages`, whose relative `url` values are resolved against it - */ - configFile?: string | URL_url; - - /** - * An already-parsed `packages` object, used instead of reading `configFile` from disk - */ - packages?: PackageMapPackages; -} -declare interface UserTsconfigOptions { - /** - * A path, or `file:` URL, pointing at the tsconfig file - */ - configFile?: string | URL_url; - - /** - * References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths or `file:` URLs - */ - references?: (string | URL_url)[] | "auto"; - - /** - * Override baseUrl from tsconfig.json with a path or `file:` URL - */ - baseUrl?: string | URL_url; -} -declare interface WriteOnlySet { - add: (item: T) => void; -} -declare function exports( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - resolveContext: ResolveContext, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, -): void; -declare function exports( - context: Context, - parent: string | URL_url, - specifier: string | URL_url, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, -): void; -declare function exports( - parent: string | URL_url, - specifier: string | URL_url, - resolveContext: ResolveContext, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, -): void; -declare function exports( - parent: string | URL_url, - specifier: string | URL_url, - callback: ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void, -): void; -declare namespace exports { - export const sync: ResolveFunction; - export const promise: ResolveFunctionPromise; - export function create( - options: ResolveOptionsOptionalFS, - ): ResolveFunctionAsync; - export namespace create { - export const sync: (options: ResolveOptionsOptionalFS) => ResolveFunction; - export const promise: ( - options: ResolveOptionsOptionalFS, - ) => ResolveFunctionPromise; - } - export namespace ResolverFactory { - export let createResolver: ( - options: ResolveOptionsResolverFactoryObject_2, - ) => Resolver; - } - export const forEachBail: ( - array: T[], - iterator: Iterator, - callback: (err?: null | Error, result?: null | Z, i?: number) => void, - ) => void; - export type ResolveCallback = ( - err: null | ErrorWithDetail, - res?: string | false, - req?: ResolveRequest, - ) => void; - export { - CachedInputFileSystem, - CloneBasenamePlugin, - LogInfoPlugin, - TsconfigPathsPlugin, - ResolveOptionsOptionalFS, - BaseFileSystem, - PnpApi, - Resolver, - Context, - FileSystem, - ResolveContext, - ResolveRequest, - SyncFileSystem, - Plugin, - ResolveOptionsResolverFactoryObject_2 as ResolveOptions, - ResolveFunctionAsync, - ResolveFunction, - ResolveFunctionPromise, - }; -} - -export = exports; +export = resolve; diff --git a/types/AliasFieldPlugin.d.ts b/types/AliasFieldPlugin.d.ts new file mode 100644 index 00000000..8f0d47fb --- /dev/null +++ b/types/AliasFieldPlugin.d.ts @@ -0,0 +1,33 @@ +export = AliasFieldPlugin; +declare class AliasFieldPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | string[]} field field + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, field: string | string[], target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + field: string | string[]; + target: string | import("./Resolver").ResolveStepHook; + /** @type {WeakMap} */ + _fieldDataCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace AliasFieldPlugin { + export { Resolver, JsonPrimitive, ResolveRequest, ResolveStepHook }; +} +/** @typedef {import("./Resolver")} Resolver */ +/** @typedef {import("./Resolver").JsonPrimitive} JsonPrimitive */ +/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */ +/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */ +declare const NO_FIELD_OBJECT: unique symbol; +type Resolver = import("./Resolver"); +type JsonPrimitive = import("./Resolver").JsonPrimitive; +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/AliasPlugin.d.ts b/types/AliasPlugin.d.ts new file mode 100644 index 00000000..fa7108e2 --- /dev/null +++ b/types/AliasPlugin.d.ts @@ -0,0 +1,28 @@ +export = AliasPlugin; +declare class AliasPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {AliasOption | AliasOption[]} options options + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, options: AliasOption | AliasOption[], target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + options: AliasOption[]; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace AliasPlugin { + export { Resolver, ResolveStepHook, Alias, AliasOption }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type Alias = string | string[] | false; +type AliasOption = { + alias: Alias; + name: string; + onlyModule?: boolean; +}; diff --git a/types/AliasUtils.d.ts b/types/AliasUtils.d.ts new file mode 100644 index 00000000..da24ec76 --- /dev/null +++ b/types/AliasUtils.d.ts @@ -0,0 +1,115 @@ +export type InnerCallback = (err?: null | Error, result?: null | ResolveRequest) => void; +export type Resolver = import("./Resolver"); +export type ResolveRequest = import("./Resolver").ResolveRequest; +export type ResolveContext = import("./Resolver").ResolveContext; +export type ResolveStepHook = import("./Resolver").ResolveStepHook; +export type ResolveCallback = import("./Resolver").ResolveCallback; +export type Alias = string | string[] | false; +export type AliasOption = { + alias: Alias; + name: string; + onlyModule?: boolean; +}; +export type CompiledAliasOption = { + /** + * original alias name + */ + name: string; + /** + * name + "/" — precomputed to avoid per-resolve concat + */ + nameWithSlash: string; + /** + * alias target(s) + */ + alias: Alias; + /** + * normalized onlyModule flag + */ + onlyModule: boolean; + /** + * absolute form of `name` (with slash ending), null when not absolute + */ + absolutePath: string | null; + /** + * substring before the single "*" in `name`, null when no wildcard + */ + wildcardPrefix: string | null; + /** + * substring after the single "*" in `name`, null when no wildcard + */ + wildcardSuffix: string | null; + /** + * first character code of `name` — used as a cheap screen on the hot path. `-1` indicates "matches any first char" (empty wildcard prefix). + */ + firstCharCode: number; + /** + * true when `alias` is an array — precomputed so the hot path skips `Array.isArray` + */ + arrayAlias: boolean; +}; +/** + * Bucketed view of compiled options used by `aliasResolveHandler` to avoid + * walking the full option list on every resolve. The `all` array preserves + * the legacy linear order (declaration order) for the fallback path. The + * `byFirstChar` map buckets options by the first char code of their `name` + * — each bucket preserves declaration order among its members. The + * `hasAnyFirstChar` flag is true when at least one option matches any + * first char (`firstCharCode === -1`), in which case resolve-time scans + * fall back to `all` to keep declaration-order semantics across buckets. + * The `useBuckets` flag is true only when bucketing would actually help — + * i.e. there are at least 2 distinct first chars AND no empty-prefix + * wildcard. When false, the resolve hot path skips the `Map.get` and + * iterates `all` directly with the per-option first-char-code screen + * (matching the pre-bucketing behavior). This avoids paying for `Map.get` + * on degenerate single-bucket lists like a long chain of aliases that + * all share one first char — the bucket lookup adds overhead without + * narrowing the candidate set, which showed up as a transient-memory + * regression on `pathological-deep-stack`. + */ +export type CompiledAliasOptions = { + /** + * declaration-ordered list + */ + all: CompiledAliasOption[]; + /** + * bucketed by first char code + */ + byFirstChar: Map; + /** + * true when an empty-prefix wildcard is present + */ + hasAnyFirstChar: boolean; + /** + * true when the bucket fast-path should be used at resolve time + */ + useBuckets: boolean; +}; +/** @typedef {(err?: null | Error, result?: null | ResolveRequest) => void} InnerCallback */ +/** + * @param {Resolver} resolver resolver + * @param {CompiledAliasOptions} options compiled options + * @param {ResolveStepHook} target target + * @param {ResolveRequest} request request + * @param {ResolveContext} resolveContext resolve context + * @param {InnerCallback} callback callback + * @returns {void} + */ +export function aliasResolveHandler(resolver: Resolver, options: CompiledAliasOptions, target: ResolveStepHook, request: ResolveRequest, resolveContext: ResolveContext, callback: InnerCallback): void; +/** + * Precompute per-option strings used on every resolve so the hot path in + * `aliasResolveHandler` does no string concatenation / split work per entry. + * Called once per plugin apply — the returned structure is stable for the + * lifetime of the resolver. + * + * Beyond the per-option precompute step, this also partitions the list into + * a `byFirstChar` map so that, when no "empty-prefix" wildcards are + * present, the resolve-time scan only walks options whose `name` starts + * with the same char as the current request. For large alias lists (300+ + * entries) this turns an O(N) screen into O(K) where K is the bucket size + * for the request's first char. + * @param {Resolver} resolver resolver + * @param {AliasOption[]} options options + * @returns {CompiledAliasOptions} compiled options + */ +export function compileAliasOptions(resolver: Resolver, options: AliasOption[]): CompiledAliasOptions; diff --git a/types/AppendPlugin.d.ts b/types/AppendPlugin.d.ts new file mode 100644 index 00000000..e3513560 --- /dev/null +++ b/types/AppendPlugin.d.ts @@ -0,0 +1,23 @@ +export = AppendPlugin; +declare class AppendPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string} appending appending + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, appending: string, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + appending: string; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace AppendPlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/CachedInputFileSystem.d.ts b/types/CachedInputFileSystem.d.ts new file mode 100644 index 00000000..7ceb207f --- /dev/null +++ b/types/CachedInputFileSystem.d.ts @@ -0,0 +1,141 @@ +export = CachedInputFileSystem; +declare class CachedInputFileSystem { + /** + * @param {BaseFileSystem} fileSystem file system + * @param {number} duration duration in ms files are cached + */ + constructor(fileSystem: BaseFileSystem, duration: number); + fileSystem: BaseFileSystem; + _lstatBackend: OperationMergerBackend | CacheBackend; + lstat: import("./Resolver").LStat | undefined; + lstatSync: import("./Resolver").LStatSync | undefined; + _statBackend: OperationMergerBackend | CacheBackend; + stat: import("./Resolver").Stat; + statSync: import("./Resolver").StatSync; + _readdirBackend: OperationMergerBackend | CacheBackend; + readdir: import("./Resolver").Readdir; + readdirSync: import("./Resolver").ReaddirSync; + _readFileBackend: OperationMergerBackend | CacheBackend; + readFile: import("./Resolver").ReadFile; + readFileSync: import("./Resolver").ReadFileSync; + _readJsonBackend: OperationMergerBackend | CacheBackend; + readJson: import("./Resolver").ReadJson | undefined; + readJsonSync: import("./Resolver").ReadJsonSync | undefined; + _readlinkBackend: OperationMergerBackend | CacheBackend; + readlink: import("./Resolver").Readlink; + readlinkSync: import("./Resolver").ReadlinkSync; + _realpathBackend: OperationMergerBackend | CacheBackend; + realpath: import("./Resolver").RealPath | undefined; + realpathSync: import("./Resolver").RealPathSync | undefined; + /** + * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge + * @param {{ exact?: boolean }=} options options; `exact: true` removes only cache entries whose key matches `what` exactly instead of any entry whose key starts with `what` + */ + purge(what?: (string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set) | undefined, options?: { + exact?: boolean; + } | undefined): void; +} +declare namespace CachedInputFileSystem { + export { FileSystem, PathLike, PathOrFileDescriptor, SyncFileSystem, BaseFileSystem, FileSystemCallback, EXPECTED_FUNCTION, EXPECTED_ANY, Provide }; +} +declare class OperationMergerBackend { + /** + * @param {EXPECTED_FUNCTION | undefined} provider async method in filesystem + * @param {EXPECTED_FUNCTION | undefined} syncProvider sync method in filesystem + * @param {BaseFileSystem} providerContext call context for the provider methods + */ + constructor(provider: EXPECTED_FUNCTION | undefined, syncProvider: EXPECTED_FUNCTION | undefined, providerContext: BaseFileSystem); + _provider: Function | undefined; + _syncProvider: Function | undefined; + _providerContext: BaseFileSystem; + _activeAsyncOperations: Map; + provide: ((path: PathLike | PathOrFileDescriptor, options: object | FileSystemCallback | undefined, callback?: FileSystemCallback | undefined) => EXPECTED_ANY) | null; + provideSync: ((path: PathLike | PathOrFileDescriptor, options?: object | undefined) => EXPECTED_ANY) | null; + purge(): void; + purgeParent(): void; +} +/** + * @callback Provide + * @param {PathLike | PathOrFileDescriptor} path path + * @param {EXPECTED_ANY} options options + * @param {FileSystemCallback} callback callback + * @returns {void} + */ +declare class CacheBackend { + /** + * @param {number} duration max cache duration of items + * @param {EXPECTED_FUNCTION | undefined} provider async method + * @param {EXPECTED_FUNCTION | undefined} syncProvider sync method + * @param {BaseFileSystem} providerContext call context for the provider methods + */ + constructor(duration: number, provider: EXPECTED_FUNCTION | undefined, syncProvider: EXPECTED_FUNCTION | undefined, providerContext: BaseFileSystem); + _duration: number; + _provider: Function | undefined; + _syncProvider: Function | undefined; + _providerContext: BaseFileSystem; + /** @type {Map[]>} */ + _activeAsyncOperations: Map[]>; + /** @type {Map }>} */ + _data: Map; + }>; + /** @type {Set[]} */ + _levels: Set[]; + _currentLevel: number; + _tickInterval: number; + /** @type {STORAGE_MODE_IDLE | STORAGE_MODE_SYNC | STORAGE_MODE_ASYNC} */ + _mode: 0 | 1 | 2; + /** @type {NodeJS.Timeout | undefined} */ + _timeout: NodeJS.Timeout | undefined; + /** @type {number | undefined} */ + _nextDecay: number | undefined; + /** + * @param {PathLike | PathOrFileDescriptor} path path + * @param {EXPECTED_ANY} options options + * @param {FileSystemCallback} callback callback + * @returns {void} + */ + provide(path: PathLike | PathOrFileDescriptor, options: EXPECTED_ANY, callback: FileSystemCallback): void; + /** + * @param {PathLike | PathOrFileDescriptor} path path + * @param {EXPECTED_ANY} options options + * @returns {EXPECTED_ANY} result + */ + provideSync(path: PathLike | PathOrFileDescriptor, options: EXPECTED_ANY): EXPECTED_ANY; + /** + * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge + * @param {{ exact?: boolean }=} options options; `exact: true` removes only entries whose key matches `what` exactly instead of any entry whose key starts with `what` + */ + purge(what?: (string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set) | undefined, options?: { + exact?: boolean; + } | undefined): void; + /** + * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge + */ + purgeParent(what?: (string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set) | undefined): void; + /** + * @param {string} path path + * @param {Error | null} err error + * @param {EXPECTED_ANY} result result + */ + _storeResult(path: string, err: Error | null, result: EXPECTED_ANY): void; + _decayLevel(): void; + _runDecays(): void; + _enterAsyncMode(): void; + _enterSyncModeWhenIdle(): void; + _enterIdleMode(): void; +} +type FileSystem = import("./Resolver").FileSystem; +type PathLike = import("./Resolver").PathLike; +type PathOrFileDescriptor = import("./Resolver").PathOrFileDescriptor; +type SyncFileSystem = import("./Resolver").SyncFileSystem; +type BaseFileSystem = FileSystem & SyncFileSystem; +/** + * + */ +type FileSystemCallback = import("./Resolver").FileSystemCallback; +type EXPECTED_FUNCTION = Function; +type EXPECTED_ANY = any; +type Provide = (path: PathLike | PathOrFileDescriptor, options: EXPECTED_ANY, callback: FileSystemCallback) => void; diff --git a/types/CloneBasenamePlugin.d.ts b/types/CloneBasenamePlugin.d.ts new file mode 100644 index 00000000..75801a04 --- /dev/null +++ b/types/CloneBasenamePlugin.d.ts @@ -0,0 +1,21 @@ +export = CloneBasenamePlugin; +declare class CloneBasenamePlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace CloneBasenamePlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/ConditionalPlugin.d.ts b/types/ConditionalPlugin.d.ts new file mode 100644 index 00000000..aeee7b47 --- /dev/null +++ b/types/ConditionalPlugin.d.ts @@ -0,0 +1,27 @@ +export = ConditionalPlugin; +declare class ConditionalPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {Partial} test compare object + * @param {string | null} message log message + * @param {boolean} allowAlternatives when false, do not continue with the current step when "test" matches + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, test: Partial, message: string | null, allowAlternatives: boolean, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + test: Partial; + message: string | null; + allowAlternatives: boolean; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace ConditionalPlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/DescriptionFilePlugin.d.ts b/types/DescriptionFilePlugin.d.ts new file mode 100644 index 00000000..0d784323 --- /dev/null +++ b/types/DescriptionFilePlugin.d.ts @@ -0,0 +1,25 @@ +export = DescriptionFilePlugin; +declare class DescriptionFilePlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string[]} filenames filenames + * @param {boolean} pathIsFile pathIsFile + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, filenames: string[], pathIsFile: boolean, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + filenames: string[]; + pathIsFile: boolean; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace DescriptionFilePlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/DescriptionFileUtils.d.ts b/types/DescriptionFileUtils.d.ts new file mode 100644 index 00000000..1732e2d7 --- /dev/null +++ b/types/DescriptionFileUtils.d.ts @@ -0,0 +1,70 @@ +export type Resolver = import("./Resolver"); +export type JsonObject = import("./Resolver").JsonObject; +export type JsonValue = import("./Resolver").JsonValue; +export type ResolveContext = import("./Resolver").ResolveContext; +export type ResolveRequest = import("./Resolver").ResolveRequest; +export type DescriptionFileInfo = { + /** + * content + */ + content?: JsonObject | undefined; + /** + * path + */ + path: string; + /** + * directory + */ + directory: string; +}; +export type ErrorFirstCallback = (error?: (Error | null) | undefined, result?: DescriptionFileInfo | undefined) => any; +export type Result = { + /** + * path to description file + */ + path: string; + /** + * directory of description file + */ + directory: string; + /** + * content of description file + */ + content: JsonObject; +}; +/** + * Walk up one directory. Called once per package-root candidate and once per + * `described-resolve` (to find the enclosing description file), so it's on + * the resolver's hot path. + * + * Previous implementation called `lastIndexOf("/")` and `lastIndexOf("\\")` + * separately and then picked the larger. For any non-trivial directory + * string on POSIX, `lastIndexOf("\\")` scans the full string just to return + * -1. A single reverse char-code scan does the same work in one pass. + * + * Any single-character directory is treated as a root — `directory.length + * <= 1` collapses the `"/"`, `"\\"` and `""` branches into one compare. + * Without the `"\\"` case, `cdUp("\\")` (reached from a UNC root or a DOS + * device path like `\\?\…`) would return itself via `slice(0, i || 1)` + * and trap `loadDescriptionFile` in an infinite loop. Once single-char + * roots are filtered up front, the reverse scan always produces a + * strictly shorter string. + * @param {string} directory directory + * @returns {string | null} parent directory or null + */ +export function cdUp(directory: string): string | null; +/** + * @param {JsonObject} content content + * @param {string | string[]} field field + * @returns {JsonValue | undefined} field data + */ +export function getField(content: JsonObject, field: string | string[]): JsonValue | undefined; +/** + * @param {Resolver} resolver resolver + * @param {string} directory directory + * @param {string[]} filenames filenames + * @param {DescriptionFileInfo | undefined} oldInfo oldInfo + * @param {ResolveContext} resolveContext resolveContext + * @param {ErrorFirstCallback} callback callback + */ +export function loadDescriptionFile(resolver: Resolver, directory: string, filenames: string[], oldInfo: DescriptionFileInfo | undefined, resolveContext: ResolveContext, callback: ErrorFirstCallback): void; diff --git a/types/DirectoryExistsPlugin.d.ts b/types/DirectoryExistsPlugin.d.ts new file mode 100644 index 00000000..929ff5fa --- /dev/null +++ b/types/DirectoryExistsPlugin.d.ts @@ -0,0 +1,20 @@ +export = DirectoryExistsPlugin; +declare class DirectoryExistsPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace DirectoryExistsPlugin { + export { Resolver, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/ExportsFieldPlugin.d.ts b/types/ExportsFieldPlugin.d.ts new file mode 100644 index 00000000..70270f46 --- /dev/null +++ b/types/ExportsFieldPlugin.d.ts @@ -0,0 +1,32 @@ +export = ExportsFieldPlugin; +declare class ExportsFieldPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {Set} conditionNames condition names + * @param {string | string[]} fieldNamePath name path + * @param {string | ResolveStepHook} target target + * @param {boolean=} restrictions whether `restrictions` are configured (enables exports-target fallback when a target is filtered out) + */ + constructor(source: string | ResolveStepHook, conditionNames: Set, fieldNamePath: string | string[], target: string | ResolveStepHook, restrictions?: boolean | undefined); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + conditionNames: Set; + fieldName: string | string[]; + restrictions: boolean; + /** @type {WeakMap} */ + _fieldProcessorCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace ExportsFieldPlugin { + export { Resolver, JsonObject, ResolveRequest, ResolveStepHook, ExportsField, FieldProcessor }; +} +type Resolver = import("./Resolver"); +type JsonObject = import("./Resolver").JsonObject; +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type ExportsField = import("./util/entrypoints").ExportsField; +type FieldProcessor = import("./util/entrypoints").FieldProcessor; diff --git a/types/ExtensionAliasPlugin.d.ts b/types/ExtensionAliasPlugin.d.ts new file mode 100644 index 00000000..268a843d --- /dev/null +++ b/types/ExtensionAliasPlugin.d.ts @@ -0,0 +1,27 @@ +export = ExtensionAliasPlugin; +declare class ExtensionAliasPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {ExtensionAliasOption} options options + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, options: ExtensionAliasOption, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + options: ExtensionAliasOption; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace ExtensionAliasPlugin { + export { Resolver, ResolveRequest, ResolveStepHook, ExtensionAliasOption }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type ExtensionAliasOption = { + alias: string | string[]; + extension: string; +}; diff --git a/types/FileExistsPlugin.d.ts b/types/FileExistsPlugin.d.ts new file mode 100644 index 00000000..909bd504 --- /dev/null +++ b/types/FileExistsPlugin.d.ts @@ -0,0 +1,20 @@ +export = FileExistsPlugin; +declare class FileExistsPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace FileExistsPlugin { + export { Resolver, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/ImportsFieldPlugin.d.ts b/types/ImportsFieldPlugin.d.ts new file mode 100644 index 00000000..b6743f4b --- /dev/null +++ b/types/ImportsFieldPlugin.d.ts @@ -0,0 +1,32 @@ +export = ImportsFieldPlugin; +declare class ImportsFieldPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {Set} conditionNames condition names + * @param {string | string[]} fieldNamePath name path + * @param {string | ResolveStepHook} targetFile target file + * @param {string | ResolveStepHook} targetPackage target package + */ + constructor(source: string | ResolveStepHook, conditionNames: Set, fieldNamePath: string | string[], targetFile: string | ResolveStepHook, targetPackage: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + targetFile: string | import("./Resolver").ResolveStepHook; + targetPackage: string | import("./Resolver").ResolveStepHook; + conditionNames: Set; + fieldName: string | string[]; + /** @type {WeakMap} */ + _fieldProcessorCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace ImportsFieldPlugin { + export { Resolver, JsonObject, ResolveRequest, ResolveStepHook, FieldProcessor, ImportsField }; +} +type Resolver = import("./Resolver"); +type JsonObject = import("./Resolver").JsonObject; +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type FieldProcessor = import("./util/entrypoints").FieldProcessor; +type ImportsField = import("./util/entrypoints").ImportsField; diff --git a/types/JoinRequestPartPlugin.d.ts b/types/JoinRequestPartPlugin.d.ts new file mode 100644 index 00000000..f4dc883e --- /dev/null +++ b/types/JoinRequestPartPlugin.d.ts @@ -0,0 +1,21 @@ +export = JoinRequestPartPlugin; +declare class JoinRequestPartPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace JoinRequestPartPlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/JoinRequestPlugin.d.ts b/types/JoinRequestPlugin.d.ts new file mode 100644 index 00000000..f583e8ef --- /dev/null +++ b/types/JoinRequestPlugin.d.ts @@ -0,0 +1,21 @@ +export = JoinRequestPlugin; +declare class JoinRequestPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace JoinRequestPlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/LogInfoPlugin.d.ts b/types/LogInfoPlugin.d.ts new file mode 100644 index 00000000..67e5623b --- /dev/null +++ b/types/LogInfoPlugin.d.ts @@ -0,0 +1,18 @@ +export = LogInfoPlugin; +declare class LogInfoPlugin { + /** + * @param {string | ResolveStepHook} source source + */ + constructor(source: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace LogInfoPlugin { + export { Resolver, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/MainFieldPlugin.d.ts b/types/MainFieldPlugin.d.ts new file mode 100644 index 00000000..c65a1787 --- /dev/null +++ b/types/MainFieldPlugin.d.ts @@ -0,0 +1,31 @@ +export = MainFieldPlugin; +declare class MainFieldPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {MainFieldOptions} options options + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, options: MainFieldOptions, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + options: MainFieldOptions; + target: string | import("./Resolver").ResolveStepHook; + /** @type {WeakMap} */ + _mainModuleCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace MainFieldPlugin { + export { Resolver, JsonObject, ResolveRequest, ResolveStepHook, MainFieldOptions }; +} +declare const NO_MAIN: unique symbol; +type Resolver = import("./Resolver"); +type JsonObject = import("./Resolver").JsonObject; +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type MainFieldOptions = { + name: string | string[]; + forceRelative: boolean; +}; diff --git a/types/ModulesInHierachicDirectoriesPlugin.d.ts b/types/ModulesInHierachicDirectoriesPlugin.d.ts new file mode 100644 index 00000000..2c309498 --- /dev/null +++ b/types/ModulesInHierachicDirectoriesPlugin.d.ts @@ -0,0 +1,2 @@ +declare const _exports: typeof import("./ModulesInHierarchicalDirectoriesPlugin"); +export = _exports; diff --git a/types/ModulesInHierarchicalDirectoriesPlugin.d.ts b/types/ModulesInHierarchicalDirectoriesPlugin.d.ts new file mode 100644 index 00000000..83fb453e --- /dev/null +++ b/types/ModulesInHierarchicalDirectoriesPlugin.d.ts @@ -0,0 +1,22 @@ +export = ModulesInHierarchicalDirectoriesPlugin; +declare class ModulesInHierarchicalDirectoriesPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | string[]} directories directories + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, directories: string | string[], target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + directories: string[]; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace ModulesInHierarchicalDirectoriesPlugin { + export { Resolver, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/ModulesInRootPlugin.d.ts b/types/ModulesInRootPlugin.d.ts new file mode 100644 index 00000000..f78d7228 --- /dev/null +++ b/types/ModulesInRootPlugin.d.ts @@ -0,0 +1,23 @@ +export = ModulesInRootPlugin; +declare class ModulesInRootPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string} path path + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, path: string, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + path: string; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace ModulesInRootPlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/ModulesUtils.d.ts b/types/ModulesUtils.d.ts new file mode 100644 index 00000000..ac7d10d4 --- /dev/null +++ b/types/ModulesUtils.d.ts @@ -0,0 +1,15 @@ +export type Resolver = import("./Resolver"); +export type ResolveRequest = import("./Resolver").ResolveRequest; +export type ResolveStepHook = import("./Resolver").ResolveStepHook; +export type ResolveContext = import("./Resolver").ResolveContext; +export type InnerCallback = (err?: null | Error, result?: null | ResolveRequest) => void; +/** + * @param {Resolver} resolver resolver + * @param {string[]} directories directories + * @param {ResolveStepHook} target target + * @param {ResolveRequest} request request + * @param {ResolveContext} resolveContext resolve context + * @param {InnerCallback} callback callback + * @returns {void} + */ +export function modulesResolveHandler(resolver: Resolver, directories: string[], target: ResolveStepHook, request: ResolveRequest, resolveContext: ResolveContext, callback: InnerCallback): void; diff --git a/types/NextPlugin.d.ts b/types/NextPlugin.d.ts new file mode 100644 index 00000000..32e10c74 --- /dev/null +++ b/types/NextPlugin.d.ts @@ -0,0 +1,20 @@ +export = NextPlugin; +declare class NextPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace NextPlugin { + export { Resolver, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/PackageMapPlugin.d.ts b/types/PackageMapPlugin.d.ts new file mode 100644 index 00000000..23392183 --- /dev/null +++ b/types/PackageMapPlugin.d.ts @@ -0,0 +1,64 @@ +export = PackageMapPlugin; +declare class PackageMapPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {PackageMapOptions} options package map options + * @param {boolean} symlinks whether the resolver resolves symlinks + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, options: PackageMapOptions, symlinks: boolean, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + options: PackageMapOptions; + symlinks: boolean; + target: string | import("./Resolver").ResolveStepHook; + /** @type {PackageMap | undefined} */ + _packageMap: PackageMap | undefined; + /** @type {PackageMapCallback[] | undefined} */ + _pending: PackageMapCallback[] | undefined; + /** + * Read and parse the configuration file once, queueing every request that + * arrives while the read is in flight so a cold start does not re-read the + * same file for each of them. + * @param {Resolver} resolver the resolver + * @param {ResolveContext} resolveContext resolve context + * @param {PackageMapCallback} callback callback + * @returns {void} + */ + _getPackageMap(resolver: Resolver, resolveContext: ResolveContext, callback: PackageMapCallback): void; + /** + * Hand back the configuration file path package locations resolve against: + * its real path when the resolver follows symlinks, and the path as given + * otherwise. A configuration file whose real path cannot be read (it may not + * exist, or the file system may not implement it) is used as-is, so the + * read below reports the problem. + * @param {Resolver} resolver the resolver + * @param {(configFile: string) => void} callback callback + * @returns {void} + */ + _resolveConfigFile(resolver: Resolver, callback: (configFile: string) => void): void; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace PackageMapPlugin { + export { Resolver, ResolveContext, ResolveRequest, ResolveStepHook, PackageMap, PackageMapPackages, PackageMapOptions, PackageMapCallback }; +} +type Resolver = import("./Resolver"); +type ResolveContext = import("./Resolver").ResolveContext; +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type PackageMap = import("./util/packageMap").PackageMap; +type PackageMapPackages = import("./util/packageMap").PackageMapPackages; +type PackageMapOptions = { + /** + * absolute path of the configuration file, read lazily when `packages` is not given + */ + configFile: string | null; + /** + * an already-parsed `packages` object, used instead of reading `configFile` + */ + packages: PackageMapPackages | null; +}; +type PackageMapCallback = (err: Error | null, packageMap?: PackageMap) => void; diff --git a/types/ParsePlugin.d.ts b/types/ParsePlugin.d.ts new file mode 100644 index 00000000..28b58a5a --- /dev/null +++ b/types/ParsePlugin.d.ts @@ -0,0 +1,23 @@ +export = ParsePlugin; +declare class ParsePlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {Partial} requestOptions request options + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, requestOptions: Partial, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + requestOptions: Partial; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace ParsePlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/PnpPlugin.d.ts b/types/PnpPlugin.d.ts new file mode 100644 index 00000000..e9c97707 --- /dev/null +++ b/types/PnpPlugin.d.ts @@ -0,0 +1,33 @@ +export = PnpPlugin; +declare class PnpPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {PnpApiImpl} pnpApi pnpApi + * @param {string | ResolveStepHook} target target + * @param {string | ResolveStepHook} alternateTarget alternateTarget + */ + constructor(source: string | ResolveStepHook, pnpApi: PnpApiImpl, target: string | ResolveStepHook, alternateTarget: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + pnpApi: PnpApiImpl; + target: string | import("./Resolver").ResolveStepHook; + alternateTarget: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace PnpPlugin { + export { Resolver, ResolveStepHook, ResolveRequest, PnpApiImpl }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type ResolveRequest = import("./Resolver").ResolveRequest; +type PnpApiImpl = { + /** + * resolve to unqualified + */ + resolveToUnqualified: (packageName: string, issuer: string, options: { + considerBuiltins: boolean; + }) => string | null; +}; diff --git a/types/Resolver.d.ts b/types/Resolver.d.ts new file mode 100644 index 00000000..81704c08 --- /dev/null +++ b/types/Resolver.d.ts @@ -0,0 +1,1208 @@ +export = Resolver; +declare class Resolver { + /** + * @param {ResolveStepHook} hook hook + * @param {ResolveRequest} request request + * @param {StackEntry=} parent previous tip of the stack + * @param {Set=} preSeeded entries pre-seeded via the legacy `Set` API + * @returns {StackEntry} stack entry + */ + static createStackEntry(hook: ResolveStepHook, request: ResolveRequest, parent?: StackEntry | undefined, preSeeded?: Set | undefined): StackEntry; + /** + * @param {FileSystem} fileSystem a filesystem + * @param {ResolveOptions} options options + */ + constructor(fileSystem: FileSystem, options: ResolveOptions); + /** @type {FileSystem} */ + fileSystem: FileSystem; + /** @type {ResolveOptions} */ + options: ResolveOptions; + /** @type {PathCacheFunctions} */ + pathCache: PathCacheFunctions; + /** @type {KnownHooks} */ + hooks: KnownHooks; + /** + * @param {string | ResolveStepHook} name hook name or hook itself + * @returns {ResolveStepHook} the hook + */ + ensureHook(name: string | ResolveStepHook): ResolveStepHook; + /** + * @param {string | ResolveStepHook} name hook name or hook itself + * @returns {ResolveStepHook} the hook + */ + getHook(name: string | ResolveStepHook): ResolveStepHook; + /** + * @overload + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext=} resolveContext resolve context + * @returns {string | false} result + */ + resolveSync(parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext | undefined): string | false; + /** + * @overload + * @param {Context} context context information object + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext=} resolveContext resolve context + * @returns {string | false} result + */ + resolveSync(context: Context, parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext | undefined): string | false; + /** + * @overload + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext=} resolveContext resolve context + * @returns {Promise} result + */ + resolvePromise(parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext | undefined): Promise; + /** + * @overload + * @param {Context} context context information object + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext=} resolveContext resolve context + * @returns {Promise} result + */ + resolvePromise(context: Context, parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext | undefined): Promise; + /** + * @overload + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveCallback} callback callback function + * @returns {void} + */ + resolve(parent: string | URL, specifier: string | URL, callback: ResolveCallback): void; + /** + * @overload + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext} resolveContext resolve context + * @param {ResolveCallback} callback callback function + * @returns {void} + */ + resolve(parent: string | URL, specifier: string | URL, resolveContext: ResolveContext, callback: ResolveCallback): void; + /** + * @overload + * @param {Context} context context information object + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveCallback} callback callback function + * @returns {void} + */ + resolve(context: Context, parent: string | URL, specifier: string | URL, callback: ResolveCallback): void; + /** + * @overload + * @param {Context} context context information object + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext} resolveContext resolve context + * @param {ResolveCallback} callback callback function + * @returns {void} + */ + resolve(context: Context, parent: string | URL, specifier: string | URL, resolveContext: ResolveContext, callback: ResolveCallback): void; + /** + * @param {ResolveStepHook} hook hook + * @param {ResolveRequest} request request + * @param {null | string} message string + * @param {ResolveContext} resolveContext resolver context + * @param {(err?: null | Error, result?: ResolveRequest) => void} callback callback + * @returns {void} + */ + doResolve(hook: ResolveStepHook, request: ResolveRequest, message: null | string, resolveContext: ResolveContext, callback: (err?: null | Error, result?: ResolveRequest) => void): void; + /** + * @param {string} identifier identifier + * @returns {ParsedIdentifier} parsed identifier + */ + parse(identifier: string): ParsedIdentifier; + /** + * @param {string} path path + * @returns {boolean} true, if the path is a module + */ + isModule(path: string): boolean; + /** + * @param {string} path path + * @returns {boolean} true, if the path is private + */ + isPrivate(path: string): boolean; + /** + * @param {string} path a path + * @returns {boolean} true, if the path is a directory path + */ + isDirectory(path: string): boolean; + /** + * @param {string} path path + * @returns {string} normalized path + */ + normalize(path: string): string; + /** + * @param {string} path path + * @param {string} request request + * @returns {string} joined path + */ + join(path: string, request: string): string; + /** + * @param {string} path path + * @returns {string} parent directory + */ + dirname(path: string): string; + /** + * @param {string} path the path to evaluate + * @param {string=} suffix an extension to remove from the result + * @returns {string} the last portion of a path + */ + basename(path: string, suffix?: string | undefined): string; +} +declare namespace Resolver { + export { ResolveContext, ResolveStepHook, KnownHooks, EnsuredHooks, AliasOption, CachedJoin, CachedDirname, CachedBasename, JoinCacheEntry, DirnameCacheEntry, BasenameCacheEntry, PathCacheFunctions, ResolveOptions, KnownContext, Context, ErrorWithDetail, ResolveCallback, PossibleFileSystemError, FileSystemCallback, PathLike, PathOrFileDescriptor, ObjectEncodingOptions, EncodingOption, StringCallback, BufferCallback, StringOrBufferCallback, StatsCallback, BigIntStatsCallback, StatsOrBigIntStatsCallback, ReadJsonCallback, IStatsBase, IStats, IBigIntStats, Dirent, StatOptions, StatSyncOptions, ReadFile, BufferEncodingOption, ReadFileSync, Readdir, ReaddirSync, ReadJson, ReadJsonSync, Readlink, ReadlinkSync, LStat, LStatSync, Stat, StatSync, RealPath, RealPathSync, FileSystem, SyncFileSystem, ParsedIdentifier, JsonPrimitive, JsonArray, JsonValue, JsonObject, TsconfigPathsMap, TsconfigPathsData, BaseResolveRequest, ResolveRequest, WriteOnlySet, ResolveContextYield }; +} +/** @typedef {import("./ResolverFactory").ResolveOptions} ResolveOptions */ +/** + * @typedef {object} KnownContext + * @property {string[]=} environments environments + * @property {string=} packageId package id of the importing file in the package map, propagated from a previous result to disambiguate package entries that share a location (`@experimental`, see the `packageMap` option) + */ +/** @typedef {KnownContext & Record} Context */ +/** @typedef {Error & { details?: string }} ErrorWithDetail */ +/** @typedef {(err: ErrorWithDetail | null, res?: string | false, req?: ResolveRequest) => void} ResolveCallback */ +/** + * @typedef {object} PossibleFileSystemError + * @property {string=} code code + * @property {number=} errno number + * @property {string=} path path + * @property {string=} syscall syscall + */ +/** + * @template T + * @callback FileSystemCallback + * @param {PossibleFileSystemError & Error | null} err + * @param {T=} result + */ +/** + * @typedef {string | Buffer | URL} PathLike + */ +/** + * @typedef {PathLike | number} PathOrFileDescriptor + */ +/** + * @typedef {object} ObjectEncodingOptions + * @property {BufferEncoding | null | undefined=} encoding encoding + */ +/** + * @typedef {ObjectEncodingOptions | BufferEncoding | undefined | null} EncodingOption + */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: string) => void} StringCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: Buffer) => void} BufferCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: (string | Buffer)) => void} StringOrBufferCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: IStats) => void} StatsCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: IBigIntStats) => void} BigIntStatsCallback */ +/** @typedef {(err: NodeJS.ErrnoException | null, result?: (IStats | IBigIntStats)) => void} StatsOrBigIntStatsCallback */ +/** @typedef {(err: NodeJS.ErrnoException | Error | null, result?: JsonObject) => void} ReadJsonCallback */ +/** + * @template T + * @typedef {object} IStatsBase + * @property {() => boolean} isFile is file + * @property {() => boolean} isDirectory is directory + * @property {() => boolean} isBlockDevice is block device + * @property {() => boolean} isCharacterDevice is character device + * @property {() => boolean} isSymbolicLink is symbolic link + * @property {() => boolean} isFIFO is FIFO + * @property {() => boolean} isSocket is socket + * @property {T} dev dev + * @property {T} ino ino + * @property {T} mode mode + * @property {T} nlink nlink + * @property {T} uid uid + * @property {T} gid gid + * @property {T} rdev rdev + * @property {T} size size + * @property {T} blksize blksize + * @property {T} blocks blocks + * @property {T} atimeMs atime ms + * @property {T} mtimeMs mtime ms + * @property {T} ctimeMs ctime ms + * @property {T} birthtimeMs birthtime ms + * @property {Date} atime atime + * @property {Date} mtime mtime + * @property {Date} ctime ctime + * @property {Date} birthtime birthtime + */ +/** + * @typedef {IStatsBase} IStats + */ +/** + * @typedef {IStatsBase & { atimeNs: bigint, mtimeNs: bigint, ctimeNs: bigint, birthtimeNs: bigint }} IBigIntStats + */ +/** + * @template {string | Buffer} [T=string] + * @typedef {object} Dirent + * @property {() => boolean} isFile true when is file, otherwise false + * @property {() => boolean} isDirectory true when is directory, otherwise false + * @property {() => boolean} isBlockDevice true when is block device, otherwise false + * @property {() => boolean} isCharacterDevice true when is character device, otherwise false + * @property {() => boolean} isSymbolicLink true when is symbolic link, otherwise false + * @property {() => boolean} isFIFO true when is FIFO, otherwise false + * @property {() => boolean} isSocket true when is socket, otherwise false + * @property {T} name name + * @property {string} parentPath path + * @property {string=} path path + */ +/** + * @typedef {object} StatOptions + * @property {(boolean | undefined)=} bigint need bigint values + */ +/** + * @typedef {object} StatSyncOptions + * @property {(boolean | undefined)=} bigint need bigint values + * @property {(boolean | undefined)=} throwIfNoEntry throw if no entry + */ +/** + * @typedef {{ + * (path: PathOrFileDescriptor, options: ({ encoding?: null | undefined, flag?: string | undefined } & import("events").Abortable) | undefined | null, callback: BufferCallback): void, + * (path: PathOrFileDescriptor, options: ({ encoding: BufferEncoding, flag?: string | undefined } & import("events").Abortable) | BufferEncoding, callback: StringCallback): void, + * (path: PathOrFileDescriptor, options: (ObjectEncodingOptions & { flag?: string | undefined } & import("events").Abortable) | BufferEncoding | undefined | null, callback: StringOrBufferCallback): void, + * (path: PathOrFileDescriptor, callback: BufferCallback): void, + * }} ReadFile + */ +/** + * @typedef {"buffer" | { encoding: "buffer" }} BufferEncodingOption + */ +/** + * @typedef {{ + * (path: PathOrFileDescriptor, options?: { encoding?: null | undefined, flag?: string | undefined } | null): Buffer, + * (path: PathOrFileDescriptor, options: { encoding: BufferEncoding, flag?: string | undefined } | BufferEncoding): string, + * (path: PathOrFileDescriptor, options?: (ObjectEncodingOptions & { flag?: string | undefined }) | BufferEncoding | null): string | Buffer, + * }} ReadFileSync + */ +/** + * @typedef {{ + * (path: PathLike, options: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void, + * (path: PathLike, options: { encoding: "buffer", withFileTypes?: false | undefined, recursive?: boolean | undefined } | "buffer", callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void): void, + * (path: PathLike, options: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[] | Buffer[]) => void): void, + * (path: PathLike, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void, + * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files?: Dirent[]) => void): void, + * (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }, callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void): void, + * }} Readdir + */ +/** + * @typedef {{ + * (path: PathLike, options?: { encoding: BufferEncoding | null, withFileTypes?: false | undefined, recursive?: boolean | undefined } | BufferEncoding | null): string[], + * (path: PathLike, options: { encoding: "buffer", withFileTypes?: false | undefined, recursive?: boolean | undefined } | "buffer"): Buffer[], + * (path: PathLike, options?: (ObjectEncodingOptions & { withFileTypes?: false | undefined, recursive?: boolean | undefined }) | BufferEncoding | null): string[] | Buffer[], + * (path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true, recursive?: boolean | undefined }): Dirent[], + * (path: PathLike, options: { encoding: "buffer", withFileTypes: true, recursive?: boolean | undefined }): Dirent[], + * }} ReaddirSync + */ +/** + * @typedef {(pathOrFileDescription: PathOrFileDescriptor, callback: ReadJsonCallback) => void} ReadJson + */ +/** + * @typedef {(pathOrFileDescription: PathOrFileDescriptor) => JsonObject} ReadJsonSync + */ +/** + * @typedef {{ + * (path: PathLike, options: EncodingOption, callback: StringCallback): void, + * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void, + * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void, + * (path: PathLike, callback: StringCallback): void, + * }} Readlink + */ +/** + * @typedef {{ + * (path: PathLike, options?: EncodingOption): string, + * (path: PathLike, options: BufferEncodingOption): Buffer, + * (path: PathLike, options?: EncodingOption): string | Buffer, + * }} ReadlinkSync + */ +/** + * @typedef {{ + * (path: PathLike, callback: StatsCallback): void, + * (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void, + * (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void, + * (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void, + * }} LStat + */ +/** + * @typedef {{ + * (path: PathLike, options?: undefined): IStats, + * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined, + * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined, + * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats, + * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats, + * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats, + * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined, + * }} LStatSync + */ +/** + * @typedef {{ + * (path: PathLike, callback: StatsCallback): void, + * (path: PathLike, options: (StatOptions & { bigint?: false | undefined }) | undefined, callback: StatsCallback): void, + * (path: PathLike, options: StatOptions & { bigint: true }, callback: BigIntStatsCallback): void, + * (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void, + * }} Stat + */ +/** + * @typedef {{ + * (path: PathLike, options?: undefined): IStats, + * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined, throwIfNoEntry: false }): IStats | undefined, + * (path: PathLike, options: StatSyncOptions & { bigint: true, throwIfNoEntry: false }): IBigIntStats | undefined, + * (path: PathLike, options?: StatSyncOptions & { bigint?: false | undefined }): IStats, + * (path: PathLike, options: StatSyncOptions & { bigint: true }): IBigIntStats, + * (path: PathLike, options: StatSyncOptions & { bigint: boolean, throwIfNoEntry?: false | undefined }): IStats | IBigIntStats, + * (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined, + * }} StatSync + */ +/** + * @typedef {{ + * (path: PathLike, options: EncodingOption, callback: StringCallback): void, + * (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void, + * (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void, + * (path: PathLike, callback: StringCallback): void, + * }} RealPath + */ +/** + * @typedef {{ + * (path: PathLike, options?: EncodingOption): string, + * (path: PathLike, options: BufferEncodingOption): Buffer, + * (path: PathLike, options?: EncodingOption): string | Buffer, + * }} RealPathSync + */ +/** + * @typedef {object} FileSystem + * @property {ReadFile} readFile read file method + * @property {Readdir} readdir readdir method + * @property {ReadJson=} readJson read json method + * @property {Readlink} readlink read link method + * @property {LStat=} lstat lstat method + * @property {Stat} stat stat method + * @property {RealPath=} realpath realpath method + */ +/** + * @typedef {object} SyncFileSystem + * @property {ReadFileSync} readFileSync read file sync method + * @property {ReaddirSync} readdirSync read dir sync method + * @property {ReadJsonSync=} readJsonSync read json sync method + * @property {ReadlinkSync} readlinkSync read link sync method + * @property {LStatSync=} lstatSync lstat sync method + * @property {StatSync} statSync stat sync method + * @property {RealPathSync=} realpathSync real path sync method + */ +/** + * @typedef {object} ParsedIdentifier + * @property {string} request request + * @property {string} query query + * @property {string} fragment fragment + * @property {boolean} directory is directory + * @property {boolean} module is module + * @property {boolean} file is file + * @property {boolean} internal is internal + */ +/** @typedef {string | number | boolean | null} JsonPrimitive */ +/** @typedef {JsonValue[]} JsonArray */ +/** @typedef {JsonPrimitive | JsonObject | JsonArray} JsonValue */ +/** @typedef {{ [Key in string]?: JsonValue | undefined }} JsonObject */ +/** + * @typedef {object} TsconfigPathsMap + * @property {TsconfigPathsData} main main tsconfig paths data + * @property {string} mainContext main tsconfig base URL (absolute path) + * @property {{ [baseUrl: string]: TsconfigPathsData }} refs referenced tsconfig paths data mapped by baseUrl + * @property {{ [context: string]: TsconfigPathsData }} allContexts all contexts (main + refs) for quick lookup + * @property {string[]} contextList precomputed `Object.keys(allContexts)` — read-only; used on the `_selectPathsDataForContext` hot path + * @property {Set} fileDependencies file dependencies + */ +/** + * @typedef {object} TsconfigPathsData + * @property {import("./AliasUtils").CompiledAliasOptions} alias tsconfig file data + * @property {string[]} modules tsconfig file data + */ +/** + * @typedef {object} BaseResolveRequest + * @property {string | false} path path + * @property {Context=} context content + * @property {string=} descriptionFilePath description file path + * @property {string=} descriptionFileRoot description file root + * @property {JsonObject=} descriptionFileData description file data + * @property {TsconfigPathsMap | null | undefined=} tsconfigPathsMap tsconfig paths map + * @property {string=} relativePath relative path + * @property {boolean=} ignoreSymlinks true when need to ignore symlinks, otherwise false + * @property {boolean=} fullySpecified true when full specified, otherwise false + * @property {string=} packageId package id the request was resolved to in the package map, to be propagated to resolutions made from the resulting file (`@experimental`, see the `packageMap` option) + * @property {string=} __innerRequest inner request for internal usage + * @property {string=} __innerRequest_request inner request for internal usage + * @property {string=} __innerRequest_relativePath inner relative path for internal usage + * @property {{ blocked: boolean }=} __restrictionsMarker internal: shared marker `RestrictionsPlugin` flips when it filters out an existing target, letting `ExportsFieldPlugin` fall back instead of erroring + */ +/** @typedef {BaseResolveRequest & Partial} ResolveRequest */ +/** + * @template T + * @typedef {{ add: (item: T) => void }} WriteOnlySet + */ +/** @typedef {(request: ResolveRequest) => void} ResolveContextYield */ +/** + * Singly-linked stack entry that also exposes a Set-like API + * (`has`, `size`, iteration). Each `doResolve` call prepends a new + * `StackEntry` that points at the previous tip via `.parent`, so pushing + * is O(1) in time and memory. Recursion detection walks the linked list + * (O(n)) but the stack is typically shallow, so this is cheaper overall + * than cloning a `Set` per call. + */ +declare class StackEntry { + /** + * @param {ResolveStepHook} hook hook + * @param {ResolveRequest} request request + * @param {StackEntry=} parent previous tip + * @param {Set=} preSeeded entries pre-seeded via the legacy `Set` API + */ + constructor(hook: ResolveStepHook, request: ResolveRequest, parent?: StackEntry | undefined, preSeeded?: Set | undefined); + name: string | undefined; + path: string | false; + request: string; + query: string; + fragment: string; + directory: boolean; + module: boolean; + /** @type {StackEntry | undefined} */ + parent: StackEntry | undefined; + /** + * Strings seeded by callers that still pass `stack: new Set([...])`. + * Propagated through the chain so deeper `doResolve` calls still see + * them during recursion checks. `undefined` in the common case so + * there is no extra work on the hot path. + * @type {Set | undefined} + */ + preSeeded: Set | undefined; + /** + * Walk the linked list looking for an entry with the same request shape. + * Set-compatible: callers that used `stack.has(entry)` keep working. + * + * NOTE: kept monomorphic on purpose. An earlier draft accepted a string + * query too (so pre-5.21 plugins keeping their own `Set` of + * seen entries could probe the live stack with the formatted form), + * but adding the second shape regressed `doResolve`'s heap profile by + * ~1 MiB / 200 resolves on stack-churn — V8 keeps a polymorphic + * call-site state for `parent.has(stackEntry)` once `has` has two + * argument shapes. Plugins that need string membership can reach for + * `[...stack].find(e => e.includes(formattedString))` via the + * `String`-method proxies on `StackEntry` instead. + * @param {StackEntry} query entry to look for + * @returns {boolean} whether the stack already contains an equivalent entry + */ + has(query: StackEntry): boolean; + /** + * Number of entries on the stack (oldest-to-newest length). + * @returns {number} size + */ + get size(): number; + /** + * Human-readable form used in recursion error messages, logs, and the + * iterator above. Not memoized: caching would require an extra slot on + * every `StackEntry`, which costs heap even on resolves that never look + * at the formatted form. + * @returns {string} formatted entry + */ + toString(): string; + /** + * Iterate entries from oldest (root) to newest (tip), matching how a + * `Set` that was populated in insertion order would iterate. Pre-seeded + * legacy `Set` entries come first so error-message output stays + * ordered oldest-to-newest. + * + * Yields each entry as its formatted `toString()` form. Plugins written + * against the pre-5.21 `Set` shape — e.g. + * `[...resolveContext.stack].find(a => a.includes("module:"))` — keep + * working unchanged because each yielded value is a plain string with + * all of `String.prototype` available natively. Resolves that never + * iterate the stack pay nothing; iteration costs one `toString()` + * allocation per stack frame. + * @returns {IterableIterator} iterator + */ + [Symbol.iterator](): IterableIterator; +} +/** + * Resolve context + */ +type ResolveContext = { + /** + * directories that was found on file system + */ + contextDependencies?: WriteOnlySet | undefined; + /** + * files that was found on file system + */ + fileDependencies?: WriteOnlySet | undefined; + /** + * dependencies that was not found on file system + */ + missingDependencies?: WriteOnlySet | undefined; + /** + * tip of the resolver call stack (a singly-linked list with Set-like API). For instance, `resolve → parsedResolve → describedResolve`. Accepts a legacy `Set` for back-compat with older callers; it is normalized internally without a hot-path branch. + */ + stack?: (StackEntry | Set) | undefined; + /** + * log function + */ + log?: ((str: string) => void) | undefined; + /** + * yield result, if provided plugins can return several results + */ + yield?: ResolveContextYield | undefined; +}; +type ResolveStepHook = AsyncSeriesBailHook<[ResolveRequest, ResolveContext], ResolveRequest | null>; +type KnownHooks = { + /** + * resolve step hook + */ + resolveStep: SyncHook<[ResolveStepHook, ResolveRequest], void>; + /** + * no resolve hook + */ + noResolve: SyncHook<[ResolveRequest, Error]>; + /** + * resolve hook + */ + resolve: ResolveStepHook; + /** + * result hook + */ + result: AsyncSeriesHook<[ResolveRequest, ResolveContext]>; +}; +type EnsuredHooks = { + [key: string]: ResolveStepHook; +}; +type AliasOption = import("./AliasUtils").AliasOption; +type CachedJoin = import("./util/path").CachedJoin; +type CachedDirname = import("./util/path").CachedDirname; +type CachedBasename = import("./util/path").CachedBasename; +type JoinCacheEntry = { + /** + * cached join function + */ + fn: CachedJoin["fn"]; + /** + * the underlying cache map + */ + cache: CachedJoin["cache"]; +}; +type DirnameCacheEntry = { + /** + * cached dirname function + */ + fn: CachedDirname["fn"]; + /** + * the underlying cache map + */ + cache: CachedDirname["cache"]; +}; +type BasenameCacheEntry = { + /** + * cached dirname function + */ + fn: CachedBasename["fn"]; + /** + * the underlying cache map + */ + cache: CachedBasename["cache"]; +}; +type PathCacheFunctions = { + /** + * cached join + */ + join: JoinCacheEntry; + /** + * cached dirname + */ + dirname: DirnameCacheEntry; + /** + * cached basename + */ + basename: BasenameCacheEntry; +}; +type ResolveOptions = import("./ResolverFactory").ResolveOptions; +type KnownContext = { + /** + * environments + */ + environments?: string[] | undefined; + /** + * package id of the importing file in the package map, propagated from a previous result to disambiguate package entries that share a location (`@experimental`, see the `packageMap` option) + */ + packageId?: string | undefined; +}; +type Context = KnownContext & Record; +type ErrorWithDetail = Error & { + details?: string; +}; +type ResolveCallback = (err: ErrorWithDetail | null, res?: string | false, req?: ResolveRequest) => void; +type PossibleFileSystemError = { + /** + * code + */ + code?: string | undefined; + /** + * number + */ + errno?: number | undefined; + /** + * path + */ + path?: string | undefined; + /** + * syscall + */ + syscall?: string | undefined; +}; +type FileSystemCallback = (err: (PossibleFileSystemError & Error) | null, result?: T | undefined) => any; +type PathLike = string | Buffer | URL; +type PathOrFileDescriptor = PathLike | number; +type ObjectEncodingOptions = { + /** + * encoding + */ + encoding?: (BufferEncoding | null | undefined) | undefined; +}; +type EncodingOption = ObjectEncodingOptions | BufferEncoding | undefined | null; +type StringCallback = (err: NodeJS.ErrnoException | null, result?: string) => void; +type BufferCallback = (err: NodeJS.ErrnoException | null, result?: Buffer) => void; +type StringOrBufferCallback = (err: NodeJS.ErrnoException | null, result?: (string | Buffer)) => void; +type StatsCallback = (err: NodeJS.ErrnoException | null, result?: IStats) => void; +type BigIntStatsCallback = (err: NodeJS.ErrnoException | null, result?: IBigIntStats) => void; +type StatsOrBigIntStatsCallback = (err: NodeJS.ErrnoException | null, result?: (IStats | IBigIntStats)) => void; +type ReadJsonCallback = (err: NodeJS.ErrnoException | Error | null, result?: JsonObject) => void; +type IStatsBase = { + /** + * is file + */ + isFile: () => boolean; + /** + * is directory + */ + isDirectory: () => boolean; + /** + * is block device + */ + isBlockDevice: () => boolean; + /** + * is character device + */ + isCharacterDevice: () => boolean; + /** + * is symbolic link + */ + isSymbolicLink: () => boolean; + /** + * is FIFO + */ + isFIFO: () => boolean; + /** + * is socket + */ + isSocket: () => boolean; + /** + * dev + */ + dev: T; + /** + * ino + */ + ino: T; + /** + * mode + */ + mode: T; + /** + * nlink + */ + nlink: T; + /** + * uid + */ + uid: T; + /** + * gid + */ + gid: T; + /** + * rdev + */ + rdev: T; + /** + * size + */ + size: T; + /** + * blksize + */ + blksize: T; + /** + * blocks + */ + blocks: T; + /** + * atime ms + */ + atimeMs: T; + /** + * mtime ms + */ + mtimeMs: T; + /** + * ctime ms + */ + ctimeMs: T; + /** + * birthtime ms + */ + birthtimeMs: T; + /** + * atime + */ + atime: Date; + /** + * mtime + */ + mtime: Date; + /** + * ctime + */ + ctime: Date; + /** + * birthtime + */ + birthtime: Date; +}; +type IStats = IStatsBase; +type IBigIntStats = IStatsBase & { + atimeNs: bigint; + mtimeNs: bigint; + ctimeNs: bigint; + birthtimeNs: bigint; +}; +type Dirent = { + /** + * true when is file, otherwise false + */ + isFile: () => boolean; + /** + * true when is directory, otherwise false + */ + isDirectory: () => boolean; + /** + * true when is block device, otherwise false + */ + isBlockDevice: () => boolean; + /** + * true when is character device, otherwise false + */ + isCharacterDevice: () => boolean; + /** + * true when is symbolic link, otherwise false + */ + isSymbolicLink: () => boolean; + /** + * true when is FIFO, otherwise false + */ + isFIFO: () => boolean; + /** + * true when is socket, otherwise false + */ + isSocket: () => boolean; + /** + * name + */ + name: T; + /** + * path + */ + parentPath: string; + /** + * path + */ + path?: string | undefined; +}; +type StatOptions = { + /** + * need bigint values + */ + bigint?: (boolean | undefined) | undefined; +}; +type StatSyncOptions = { + /** + * need bigint values + */ + bigint?: (boolean | undefined) | undefined; + /** + * throw if no entry + */ + throwIfNoEntry?: (boolean | undefined) | undefined; +}; +type ReadFile = { + (path: PathOrFileDescriptor, options: ({ + encoding?: null | undefined; + flag?: string | undefined; + } & import("events").Abortable) | undefined | null, callback: BufferCallback): void; + (path: PathOrFileDescriptor, options: ({ + encoding: BufferEncoding; + flag?: string | undefined; + } & import("events").Abortable) | BufferEncoding, callback: StringCallback): void; + (path: PathOrFileDescriptor, options: (ObjectEncodingOptions & { + flag?: string | undefined; + } & import("events").Abortable) | BufferEncoding | undefined | null, callback: StringOrBufferCallback): void; + (path: PathOrFileDescriptor, callback: BufferCallback): void; +}; +type BufferEncodingOption = "buffer" | { + encoding: "buffer"; +}; +type ReadFileSync = { + (path: PathOrFileDescriptor, options?: { + encoding?: null | undefined; + flag?: string | undefined; + } | null): Buffer; + (path: PathOrFileDescriptor, options: { + encoding: BufferEncoding; + flag?: string | undefined; + } | BufferEncoding): string; + (path: PathOrFileDescriptor, options?: (ObjectEncodingOptions & { + flag?: string | undefined; + }) | BufferEncoding | null): string | Buffer; +}; +type Readdir = { + (path: PathLike, options: { + encoding: BufferEncoding | null; + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void; + (path: PathLike, options: { + encoding: "buffer"; + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + } | "buffer", callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void): void; + (path: PathLike, options: (ObjectEncodingOptions & { + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + }) | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[] | Buffer[]) => void): void; + (path: PathLike, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void; + (path: PathLike, options: ObjectEncodingOptions & { + withFileTypes: true; + recursive?: boolean | undefined; + }, callback: (err: NodeJS.ErrnoException | null, files?: Dirent[]) => void): void; + (path: PathLike, options: { + encoding: "buffer"; + withFileTypes: true; + recursive?: boolean | undefined; + }, callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void): void; +}; +type ReaddirSync = { + (path: PathLike, options?: { + encoding: BufferEncoding | null; + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + } | BufferEncoding | null): string[]; + (path: PathLike, options: { + encoding: "buffer"; + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + } | "buffer"): Buffer[]; + (path: PathLike, options?: (ObjectEncodingOptions & { + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + }) | BufferEncoding | null): string[] | Buffer[]; + (path: PathLike, options: ObjectEncodingOptions & { + withFileTypes: true; + recursive?: boolean | undefined; + }): Dirent[]; + (path: PathLike, options: { + encoding: "buffer"; + withFileTypes: true; + recursive?: boolean | undefined; + }): Dirent[]; +}; +type ReadJson = (pathOrFileDescription: PathOrFileDescriptor, callback: ReadJsonCallback) => void; +type ReadJsonSync = (pathOrFileDescription: PathOrFileDescriptor) => JsonObject; +type Readlink = { + (path: PathLike, options: EncodingOption, callback: StringCallback): void; + (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void; + (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void; + (path: PathLike, callback: StringCallback): void; +}; +type ReadlinkSync = { + (path: PathLike, options?: EncodingOption): string; + (path: PathLike, options: BufferEncodingOption): Buffer; + (path: PathLike, options?: EncodingOption): string | Buffer; +}; +type LStat = { + (path: PathLike, callback: StatsCallback): void; + (path: PathLike, options: (StatOptions & { + bigint?: false | undefined; + }) | undefined, callback: StatsCallback): void; + (path: PathLike, options: StatOptions & { + bigint: true; + }, callback: BigIntStatsCallback): void; + (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void; +}; +type LStatSync = { + (path: PathLike, options?: undefined): IStats; + (path: PathLike, options?: StatSyncOptions & { + bigint?: false | undefined; + throwIfNoEntry: false; + }): IStats | undefined; + (path: PathLike, options: StatSyncOptions & { + bigint: true; + throwIfNoEntry: false; + }): IBigIntStats | undefined; + (path: PathLike, options?: StatSyncOptions & { + bigint?: false | undefined; + }): IStats; + (path: PathLike, options: StatSyncOptions & { + bigint: true; + }): IBigIntStats; + (path: PathLike, options: StatSyncOptions & { + bigint: boolean; + throwIfNoEntry?: false | undefined; + }): IStats | IBigIntStats; + (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined; +}; +type Stat = { + (path: PathLike, callback: StatsCallback): void; + (path: PathLike, options: (StatOptions & { + bigint?: false | undefined; + }) | undefined, callback: StatsCallback): void; + (path: PathLike, options: StatOptions & { + bigint: true; + }, callback: BigIntStatsCallback): void; + (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void; +}; +type StatSync = { + (path: PathLike, options?: undefined): IStats; + (path: PathLike, options?: StatSyncOptions & { + bigint?: false | undefined; + throwIfNoEntry: false; + }): IStats | undefined; + (path: PathLike, options: StatSyncOptions & { + bigint: true; + throwIfNoEntry: false; + }): IBigIntStats | undefined; + (path: PathLike, options?: StatSyncOptions & { + bigint?: false | undefined; + }): IStats; + (path: PathLike, options: StatSyncOptions & { + bigint: true; + }): IBigIntStats; + (path: PathLike, options: StatSyncOptions & { + bigint: boolean; + throwIfNoEntry?: false | undefined; + }): IStats | IBigIntStats; + (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined; +}; +type RealPath = { + (path: PathLike, options: EncodingOption, callback: StringCallback): void; + (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void; + (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void; + (path: PathLike, callback: StringCallback): void; +}; +type RealPathSync = { + (path: PathLike, options?: EncodingOption): string; + (path: PathLike, options: BufferEncodingOption): Buffer; + (path: PathLike, options?: EncodingOption): string | Buffer; +}; +type FileSystem = { + /** + * read file method + */ + readFile: ReadFile; + /** + * readdir method + */ + readdir: Readdir; + /** + * read json method + */ + readJson?: ReadJson | undefined; + /** + * read link method + */ + readlink: Readlink; + /** + * lstat method + */ + lstat?: LStat | undefined; + /** + * stat method + */ + stat: Stat; + /** + * realpath method + */ + realpath?: RealPath | undefined; +}; +type SyncFileSystem = { + /** + * read file sync method + */ + readFileSync: ReadFileSync; + /** + * read dir sync method + */ + readdirSync: ReaddirSync; + /** + * read json sync method + */ + readJsonSync?: ReadJsonSync | undefined; + /** + * read link sync method + */ + readlinkSync: ReadlinkSync; + /** + * lstat sync method + */ + lstatSync?: LStatSync | undefined; + /** + * stat sync method + */ + statSync: StatSync; + /** + * real path sync method + */ + realpathSync?: RealPathSync | undefined; +}; +type ParsedIdentifier = { + /** + * request + */ + request: string; + /** + * query + */ + query: string; + /** + * fragment + */ + fragment: string; + /** + * is directory + */ + directory: boolean; + /** + * is module + */ + module: boolean; + /** + * is file + */ + file: boolean; + /** + * is internal + */ + internal: boolean; +}; +type JsonPrimitive = string | number | boolean | null; +type JsonArray = JsonValue[]; +type JsonValue = JsonPrimitive | JsonObject | JsonArray; +type JsonObject = { [Key in string]?: JsonValue | undefined; }; +type TsconfigPathsMap = { + /** + * main tsconfig paths data + */ + main: TsconfigPathsData; + /** + * main tsconfig base URL (absolute path) + */ + mainContext: string; + /** + * referenced tsconfig paths data mapped by baseUrl + */ + refs: { + [baseUrl: string]: TsconfigPathsData; + }; + /** + * all contexts (main + refs) for quick lookup + */ + allContexts: { + [context: string]: TsconfigPathsData; + }; + /** + * precomputed `Object.keys(allContexts)` — read-only; used on the `_selectPathsDataForContext` hot path + */ + contextList: string[]; + /** + * file dependencies + */ + fileDependencies: Set; +}; +type TsconfigPathsData = { + /** + * tsconfig file data + */ + alias: import("./AliasUtils").CompiledAliasOptions; + /** + * tsconfig file data + */ + modules: string[]; +}; +type BaseResolveRequest = { + /** + * path + */ + path: string | false; + /** + * content + */ + context?: Context | undefined; + /** + * description file path + */ + descriptionFilePath?: string | undefined; + /** + * description file root + */ + descriptionFileRoot?: string | undefined; + /** + * description file data + */ + descriptionFileData?: JsonObject | undefined; + /** + * tsconfig paths map + */ + tsconfigPathsMap?: (TsconfigPathsMap | null | undefined) | undefined; + /** + * relative path + */ + relativePath?: string | undefined; + /** + * true when need to ignore symlinks, otherwise false + */ + ignoreSymlinks?: boolean | undefined; + /** + * true when full specified, otherwise false + */ + fullySpecified?: boolean | undefined; + /** + * package id the request was resolved to in the package map, to be propagated to resolutions made from the resulting file (`@experimental`, see the `packageMap` option) + */ + packageId?: string | undefined; + /** + * inner request for internal usage + */ + __innerRequest?: string | undefined; + /** + * inner request for internal usage + */ + __innerRequest_request?: string | undefined; + /** + * inner relative path for internal usage + */ + __innerRequest_relativePath?: string | undefined; + /** + * internal: shared marker `RestrictionsPlugin` flips when it filters out an existing target, letting `ExportsFieldPlugin` fall back instead of erroring + */ + __restrictionsMarker?: { + blocked: boolean; + } | undefined; +}; +type ResolveRequest = BaseResolveRequest & Partial; +type WriteOnlySet = { + add: (item: T) => void; +}; +type ResolveContextYield = (request: ResolveRequest) => void; +import { AsyncSeriesBailHook } from "tapable"; +import { SyncHook } from "tapable"; +import { AsyncSeriesHook } from "tapable"; diff --git a/types/ResolverFactory.d.ts b/types/ResolverFactory.d.ts new file mode 100644 index 00000000..1dfae85c --- /dev/null +++ b/types/ResolverFactory.d.ts @@ -0,0 +1,330 @@ +export function createResolver(options: UserResolveOptions): Resolver; +export type AliasOptionEntry = import("./AliasPlugin").AliasOption; +export type ExtensionAliasOption = import("./ExtensionAliasPlugin").ExtensionAliasOption; +export type PackageMapOptions = import("./PackageMapPlugin").PackageMapOptions; +export type PackageMapPackages = import("./util/packageMap").PackageMapPackages; +export type PnpApi = import("./PnpPlugin").PnpApiImpl; +export type EnsuredHooks = import("./Resolver").EnsuredHooks; +export type FileSystem = import("./Resolver").FileSystem; +export type KnownHooks = import("./Resolver").KnownHooks; +export type ResolveRequest = import("./Resolver").ResolveRequest; +export type SyncFileSystem = import("./Resolver").SyncFileSystem; +export type Cache = import("./UnsafeCachePlugin").Cache; +export type AliasOptionNewRequest = string | string[] | false; +export type AliasOptions = { + [k: string]: AliasOptionNewRequest; +}; +export type UserAliasOptionNewRequest = string | URL | (string | URL)[] | false; +export type UserAliasOptions = { + [k: string]: UserAliasOptionNewRequest; +}; +export type UserAliasOptionEntry = { + alias: UserAliasOptionNewRequest; + name: string; + onlyModule?: boolean; +}; +export type ExtensionAliasOptions = { + [k: string]: string | string[]; +}; +export type Falsy = false | 0 | "" | null | undefined; +export type Plugin = { + apply: (resolver: Resolver) => void; +} | ((this: Resolver, resolver: Resolver) => void) | Falsy; +export type TsconfigOptions = { + /** + * A relative path to the tsconfig file based on cwd, or an absolute path of tsconfig file + */ + configFile?: string | undefined; + /** + * References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths + */ + references?: (string[] | "auto") | undefined; + /** + * Override baseUrl from tsconfig.json. If provided, this value will be used instead of the baseUrl in the tsconfig file + */ + baseUrl?: string | undefined; +}; +export type UserTsconfigOptions = { + /** + * A path, or `file:` URL, pointing at the tsconfig file + */ + configFile?: (string | URL) | undefined; + /** + * References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths or `file:` URLs + */ + references?: ((string | URL)[] | "auto") | undefined; + /** + * Override baseUrl from tsconfig.json with a path or `file:` URL + */ + baseUrl?: (string | URL) | undefined; +}; +/** + * A Node.js package map (https://nodejs.org/api/packages.html#package-maps), + * either as the path of the configuration file or as its already-parsed + * contents. + */ +export type UserPackageMapOptions = { + /** + * A path, or `file:` `URL` instance, pointing at the package map file. Required together with `packages`, whose relative `url` values are resolved against it + */ + configFile?: (string | URL) | undefined; + /** + * An already-parsed `packages` object, used instead of reading `configFile` from disk + */ + packages?: PackageMapPackages | undefined; +}; +export type UserResolveOptions = { + /** + * A list of module alias configurations or an object which maps key to value + */ + alias?: (UserAliasOptions | UserAliasOptionEntry[]) | undefined; + /** + * A list of module alias configurations or an object which maps key to value, applied only after modules option + */ + fallback?: (UserAliasOptions | UserAliasOptionEntry[]) | undefined; + /** + * An object which maps extension to extension aliases + */ + extensionAlias?: ExtensionAliasOptions | undefined; + /** + * Also apply `extensionAlias` to paths resolved through the package.json `exports` field. Off by default (Node.js-aligned); when enabled, matches TypeScript's behavior for packages that ship TS sources alongside compiled JS. + */ + extensionAliasForExports?: boolean | undefined; + /** + * A list of alias fields in description files + */ + aliasFields?: (string | string[])[] | undefined; + /** + * A function which decides whether a request should be cached or not. An object is passed with at least `path` and `request` properties. + */ + cachePredicate?: ((predicate: ResolveRequest) => boolean) | undefined; + /** + * Whether or not the unsafeCache should include request context as part of the cache key. + */ + cacheWithContext?: boolean | undefined; + /** + * A list of description files to read from + */ + descriptionFiles?: string[] | undefined; + /** + * A list of exports field condition names. + */ + conditionNames?: string[] | undefined; + /** + * Enforce that a extension from extensions must be used + */ + enforceExtension?: boolean | undefined; + /** + * A list of exports fields in description files + */ + exportsFields?: (string | string[])[] | undefined; + /** + * A list of imports fields in description files + */ + importsFields?: (string | string[])[] | undefined; + /** + * A list of extensions which should be tried for files + */ + extensions?: string[] | undefined; + /** + * The file system which should be used + */ + fileSystem: FileSystem; + /** + * Use this cache object to unsafely cache the successful requests + */ + unsafeCache?: (Cache | boolean) | undefined; + /** + * Resolve symlinks to their symlinked location + */ + symlinks?: boolean | undefined; + /** + * A prepared Resolver to which the plugins are attached + */ + resolver?: Resolver | undefined; + /** + * A list of directories to resolve modules from, can be absolute path, folder name, or a `file:` URL + */ + modules?: ((string | URL)[] | string | URL) | undefined; + /** + * A list of main fields in description files + */ + mainFields?: (string | string[] | { + name: string | string[]; + forceRelative: boolean; + })[] | undefined; + /** + * A list of main files in directories + */ + mainFiles?: string[] | undefined; + /** + * A list of additional resolve plugins which should be applied + */ + plugins?: Plugin[] | undefined; + /** + * A Node.js package map file path (or `file:` `URL` instance), or an object with the already-parsed `packages`. When set, bare specifiers resolve through the map instead of `node_modules` (`@experimental`) + */ + packageMap?: (string | URL | UserPackageMapOptions) | undefined; + /** + * A PnP API that should be used - null is "never", undefined is "auto" + */ + pnpApi?: (PnpApi | null) | undefined; + /** + * A list of root paths, each an absolute path or a `file:` URL + */ + roots?: (string | URL)[] | undefined; + /** + * The request is already fully specified and no extensions or directories are resolved for it + */ + fullySpecified?: boolean | undefined; + /** + * Resolve to a context instead of a file + */ + resolveToContext?: boolean | undefined; + /** + * A list of resolve restrictions, each an absolute path, a `file:` URL, or a RegExp + */ + restrictions?: (string | URL | RegExp)[] | undefined; + /** + * Use only the sync constraints of the file system calls + */ + useSyncFileSystemCalls?: boolean | undefined; + /** + * Prefer to resolve module requests as relative requests before falling back to modules + */ + preferRelative?: boolean | undefined; + /** + * Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots + */ + preferAbsolute?: boolean | undefined; + /** + * TypeScript config file path (or `file:` URL) or config object with configFile and references + */ + tsconfig?: (string | URL | boolean | UserTsconfigOptions) | undefined; +}; +export type ResolveOptions = { + /** + * alias + */ + alias: AliasOptionEntry[]; + /** + * fallback + */ + fallback: AliasOptionEntry[]; + /** + * alias fields + */ + aliasFields: Set; + /** + * extension alias + */ + extensionAlias: ExtensionAliasOption[]; + /** + * apply extension alias to exports field targets + */ + extensionAliasForExports: boolean; + /** + * cache predicate + */ + cachePredicate: (predicate: ResolveRequest) => boolean; + /** + * cache with context + */ + cacheWithContext: boolean; + /** + * A list of exports field condition names. + */ + conditionNames: Set; + /** + * description files + */ + descriptionFiles: string[]; + /** + * enforce extension + */ + enforceExtension: boolean; + /** + * exports fields + */ + exportsFields: Set; + /** + * imports fields + */ + importsFields: Set; + /** + * extensions + */ + extensions: Set; + /** + * fileSystem + */ + fileSystem: FileSystem; + /** + * unsafe cache + */ + unsafeCache: Cache | false; + /** + * symlinks + */ + symlinks: boolean; + /** + * resolver + */ + resolver?: Resolver | undefined; + /** + * modules + */ + modules: (string | string[])[]; + /** + * main fields + */ + mainFields: { + name: string[]; + forceRelative: boolean; + }[]; + /** + * main files + */ + mainFiles: Set; + /** + * plugins + */ + plugins: Plugin[]; + /** + * package map + */ + packageMap: PackageMapOptions | null; + /** + * pnp API + */ + pnpApi: PnpApi | null; + /** + * roots + */ + roots: Set; + /** + * fully specified + */ + fullySpecified: boolean; + /** + * resolve to context + */ + resolveToContext: boolean; + /** + * restrictions + */ + restrictions: Set; + /** + * prefer relative + */ + preferRelative: boolean; + /** + * prefer absolute + */ + preferAbsolute: boolean; + /** + * tsconfig file path or config object + */ + tsconfig: string | boolean | TsconfigOptions; +}; +import Resolver = require("./Resolver"); diff --git a/types/RestrictionsPlugin.d.ts b/types/RestrictionsPlugin.d.ts new file mode 100644 index 00000000..050a7089 --- /dev/null +++ b/types/RestrictionsPlugin.d.ts @@ -0,0 +1,43 @@ +export = RestrictionsPlugin; +declare class RestrictionsPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {Set} restrictions restrictions + */ + constructor(source: string | ResolveStepHook, restrictions: Set); + source: string | import("./Resolver").ResolveStepHook; + restrictions: Set; + /** @type {Restriction[]} */ + _restrictions: Restriction[]; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace RestrictionsPlugin { + export { Resolver, ResolveStepHook, PathRestriction, RegExpRestriction, Restriction }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type PathRestriction = { + /** + * type of the restriction + */ + type: "path"; + /** + * normalized path the request has to be inside of + */ + rule: string; +}; +type RegExpRestriction = { + /** + * type of the restriction + */ + type: "regexp"; + /** + * pattern the request has to match + */ + rule: RegExp; +}; +type Restriction = PathRestriction | RegExpRestriction; diff --git a/types/ResultPlugin.d.ts b/types/ResultPlugin.d.ts new file mode 100644 index 00000000..c738c650 --- /dev/null +++ b/types/ResultPlugin.d.ts @@ -0,0 +1,18 @@ +export = ResultPlugin; +declare class ResultPlugin { + /** + * @param {ResolveStepHook} source source + */ + constructor(source: ResolveStepHook); + source: import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace ResultPlugin { + export { Resolver, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/RootsPlugin.d.ts b/types/RootsPlugin.d.ts new file mode 100644 index 00000000..465a7f83 --- /dev/null +++ b/types/RootsPlugin.d.ts @@ -0,0 +1,26 @@ +export = RootsPlugin; +/** @typedef {import("./Resolver")} Resolver */ +/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */ +/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */ +declare class RootsPlugin { + /** + * @param {string | ResolveStepHook} source source hook + * @param {Set} roots roots + * @param {string | ResolveStepHook} target target hook + */ + constructor(source: string | ResolveStepHook, roots: Set, target: string | ResolveStepHook); + roots: string[]; + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace RootsPlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/SelfReferencePlugin.d.ts b/types/SelfReferencePlugin.d.ts new file mode 100644 index 00000000..aaa53439 --- /dev/null +++ b/types/SelfReferencePlugin.d.ts @@ -0,0 +1,27 @@ +export = SelfReferencePlugin; +declare class SelfReferencePlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | string[]} fieldNamePath name path + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, fieldNamePath: string | string[], target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + fieldName: string | string[]; + /** @type {WeakMap} */ + _nameCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace SelfReferencePlugin { + export { Resolver, JsonObject, ResolveRequest, ResolveStepHook }; +} +declare const NO_SELF_REF: unique symbol; +type Resolver = import("./Resolver"); +type JsonObject = import("./Resolver").JsonObject; +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/SymlinkPlugin.d.ts b/types/SymlinkPlugin.d.ts new file mode 100644 index 00000000..8f747081 --- /dev/null +++ b/types/SymlinkPlugin.d.ts @@ -0,0 +1,21 @@ +export = SymlinkPlugin; +declare class SymlinkPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace SymlinkPlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/SyncAsyncFileSystemDecorator.d.ts b/types/SyncAsyncFileSystemDecorator.d.ts new file mode 100644 index 00000000..eafb0211 --- /dev/null +++ b/types/SyncAsyncFileSystemDecorator.d.ts @@ -0,0 +1,46 @@ +export = SyncAsyncFileSystemDecorator; +/** @typedef {import("./Resolver").FileSystem} FileSystem */ +/** @typedef {import("./Resolver").StringCallback} StringCallback */ +/** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */ +/** @typedef {Function} SyncOrAsyncFunction */ +/** @typedef {any} ResultOfSyncOrAsyncFunction */ +/** + * @param {SyncFileSystem} fs file system implementation + * @constructor + */ +declare function SyncAsyncFileSystemDecorator(fs: SyncFileSystem): void; +declare class SyncAsyncFileSystemDecorator { + /** @typedef {import("./Resolver").FileSystem} FileSystem */ + /** @typedef {import("./Resolver").StringCallback} StringCallback */ + /** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */ + /** @typedef {Function} SyncOrAsyncFunction */ + /** @typedef {any} ResultOfSyncOrAsyncFunction */ + /** + * @param {SyncFileSystem} fs file system implementation + * @constructor + */ + constructor(fs: SyncFileSystem); + fs: import("./Resolver").SyncFileSystem; + lstat: import("./Resolver").LStat | undefined; + lstatSync: import("./Resolver").LStatSync | undefined; + stat: import("./Resolver").Stat; + statSync: import("./Resolver").StatSync; + readdir: import("./Resolver").Readdir; + readdirSync: import("./Resolver").ReaddirSync; + readFile: import("./Resolver").ReadFile; + readFileSync: import("./Resolver").ReadFileSync; + readlink: import("./Resolver").Readlink; + readlinkSync: import("./Resolver").ReadlinkSync; + readJson: import("./Resolver").ReadJson | undefined; + readJsonSync: import("./Resolver").ReadJsonSync | undefined; + realpath: import("./Resolver").RealPath | undefined; + realpathSync: import("./Resolver").RealPathSync | undefined; +} +declare namespace SyncAsyncFileSystemDecorator { + export { FileSystem, StringCallback, SyncFileSystem, SyncOrAsyncFunction, ResultOfSyncOrAsyncFunction }; +} +type FileSystem = import("./Resolver").FileSystem; +type StringCallback = import("./Resolver").StringCallback; +type SyncFileSystem = import("./Resolver").SyncFileSystem; +type SyncOrAsyncFunction = Function; +type ResultOfSyncOrAsyncFunction = any; diff --git a/types/TryNextPlugin.d.ts b/types/TryNextPlugin.d.ts new file mode 100644 index 00000000..2ca7595f --- /dev/null +++ b/types/TryNextPlugin.d.ts @@ -0,0 +1,22 @@ +export = TryNextPlugin; +declare class TryNextPlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string} message message + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, message: string, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + message: string; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace TryNextPlugin { + export { Resolver, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/TsconfigPathsPlugin.d.ts b/types/TsconfigPathsPlugin.d.ts new file mode 100644 index 00000000..598ed33b --- /dev/null +++ b/types/TsconfigPathsPlugin.d.ts @@ -0,0 +1,147 @@ +export = TsconfigPathsPlugin; +declare class TsconfigPathsPlugin { + /** + * @param {true | string | TsconfigOptions} configFileOrOptions tsconfig file path or options object + */ + constructor(configFileOrOptions: true | string | TsconfigOptions); + /** @type {boolean} */ + isAutoConfigFile: boolean; + /** @type {string} */ + configFile: string; + /** @type {TsconfigReference[] | "auto"} */ + references: TsconfigReference[] | "auto"; + /** @type {string | undefined} */ + baseUrl: string | undefined; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; + /** + * Get TsconfigPathsMap for the request (with caching) + * @param {Resolver} resolver the resolver + * @param {ResolveRequest} request the request + * @param {ResolveContext} resolveContext the resolve context + * @param {(err: Error | null, result?: TsconfigPathsMap | null) => void} callback the callback + * @returns {void} + */ + _getTsconfigPathsMap(resolver: Resolver, request: ResolveRequest, resolveContext: ResolveContext, callback: (err: Error | null, result?: TsconfigPathsMap | null) => void): void; + /** + * Walk up from startDir to the filesystem root looking for tsconfig.json. + * Like TypeScript's own `findConfigFile` / `forEachAncestorDirectory`. + * @param {Resolver} resolver the resolver + * @param {string} startDir the directory to start searching from + * @param {(err: Error | null, result?: TsconfigPathsMap | null) => void} callback the callback + * @returns {void} + */ + _findTsconfigUpward(resolver: Resolver, startDir: string, callback: (err: Error | null, result?: TsconfigPathsMap | null) => void): void; + /** + * Load tsconfig.json and build complete TsconfigPathsMap + * Includes main project paths and all referenced projects + * @param {Resolver} resolver the resolver + * @param {string} absTsconfigPath absolute path to tsconfig.json + * @param {(err: Error | null, result?: TsconfigPathsMap) => void} callback the callback + * @returns {void} + */ + _loadTsconfigPathsMap(resolver: Resolver, absTsconfigPath: string, callback: (err: Error | null, result?: TsconfigPathsMap) => void): void; + /** + * Select the correct TsconfigPathsData based on request.path (context-aware) + * Matches the behavior of tsconfig-paths-webpack-plugin + * @param {string | false} requestPath the request path + * @param {TsconfigPathsMap} tsconfigPathsMap the tsconfig paths map + * @returns {TsconfigPathsData | null} the selected paths data + */ + _selectPathsDataForContext(requestPath: string | false, tsconfigPathsMap: TsconfigPathsMap): TsconfigPathsData | null; + /** + * Load tsconfig from extends path + * @param {Resolver} resolver the resolver + * @param {string} configFilePath current config file path + * @param {string} extendedConfigValue extends value + * @param {Set} fileDependencies the file dependencies + * @param {Set} visitedConfigPaths config paths being loaded (for circular extends detection) + * @param {(err: Error | null, result?: Tsconfig) => void} callback callback + * @returns {void} + */ + _loadTsconfigFromExtends(resolver: Resolver, configFilePath: string, extendedConfigValue: string, fileDependencies: Set, visitedConfigPaths: Set, callback: (err: Error | null, result?: Tsconfig) => void): void; + /** + * Walk up from startDir looking for `/` (a + * `node_modules/...` sub-path), matching Node.js module resolution so a + * package hoisted to a parent workspace's node_modules is found. + * @param {Resolver} resolver the resolver + * @param {string} startDir directory to start searching from + * @param {string} subPath node_modules-relative sub-path to look for + * @param {(found: string | null) => void} callback receives the found path or null + * @returns {void} + */ + _findExtendsInNodeModules(resolver: Resolver, startDir: string, subPath: string, callback: (found: string | null) => void): void; + /** + * Load referenced tsconfig projects and store in referenceMatchMap + * Simple implementation matching tsconfig-paths-webpack-plugin: + * Just load each reference and store independently + * @param {Resolver} resolver the resolver + * @param {string} context the context + * @param {TsconfigReference[]} references array of references + * @param {Set} fileDependencies the file dependencies + * @param {{ [baseUrl: string]: TsconfigPathsData }} referenceMatchMap the map to populate + * @param {(err: Error | null) => void} callback callback + * @param {Set=} visitedRefPaths visited reference config paths (for circular reference detection) + * @returns {void} + */ + _loadTsconfigReferences(resolver: Resolver, context: string, references: TsconfigReference[], fileDependencies: Set, referenceMatchMap: { + [baseUrl: string]: TsconfigPathsData; + }, callback: (err: Error | null) => void, visitedRefPaths?: Set | undefined): void; + /** + * Load tsconfig.json with extends support + * @param {Resolver} resolver the resolver + * @param {string} configFilePath absolute path to tsconfig.json + * @param {Set} fileDependencies the file dependencies + * @param {Set | undefined} visitedConfigPaths config paths being loaded (for circular extends detection) + * @param {(err: Error | null, result?: Tsconfig) => void} callback callback + * @returns {void} + */ + _loadTsconfig(resolver: Resolver, configFilePath: string, fileDependencies: Set, visitedConfigPaths: Set | undefined, callback: (err: Error | null, result?: Tsconfig) => void): void; +} +declare namespace TsconfigPathsPlugin { + export { Resolver, ResolveStepHook, AliasOption, ResolveRequest, ResolveContext, FileSystem, TsconfigPathsData, TsconfigPathsMap, TsconfigOptions, TsconfigCompilerOptions, TsconfigReference, Tsconfig }; +} +type Resolver = import("./Resolver"); +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type AliasOption = import("./AliasUtils").AliasOption; +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveContext = import("./Resolver").ResolveContext; +type FileSystem = import("./Resolver").FileSystem; +type TsconfigPathsData = import("./Resolver").TsconfigPathsData; +type TsconfigPathsMap = import("./Resolver").TsconfigPathsMap; +type TsconfigOptions = import("./ResolverFactory").TsconfigOptions; +type TsconfigCompilerOptions = { + /** + * Base URL for resolving paths + */ + baseUrl?: string | undefined; + /** + * TypeScript paths mapping + */ + paths?: { + [key: string]: string[]; + } | undefined; +}; +type TsconfigReference = { + /** + * Path to the referenced project + */ + path: string; +}; +type Tsconfig = { + /** + * Compiler options + */ + compilerOptions?: TsconfigCompilerOptions | undefined; + /** + * Extended configuration paths + */ + extends?: (string | string[]) | undefined; + /** + * Project references + */ + references?: TsconfigReference[] | undefined; +}; diff --git a/types/UnsafeCachePlugin.d.ts b/types/UnsafeCachePlugin.d.ts new file mode 100644 index 00000000..5a0a47f6 --- /dev/null +++ b/types/UnsafeCachePlugin.d.ts @@ -0,0 +1,31 @@ +export = UnsafeCachePlugin; +declare class UnsafeCachePlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {(request: ResolveRequest) => boolean} filterPredicate filterPredicate + * @param {Cache} cache cache + * @param {boolean} withContext withContext + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, filterPredicate: (request: ResolveRequest) => boolean, cache: Cache, withContext: boolean, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + filterPredicate: (request: ResolveRequest) => boolean; + withContext: boolean; + cache: Cache; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace UnsafeCachePlugin { + export { Resolver, ResolveRequest, ResolveStepHook, ResolveContextYield, Cache }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; +type ResolveContextYield = import("./Resolver").ResolveContextYield; +type Cache = { + [k: string]: undefined | ResolveRequest | ResolveRequest[]; +}; diff --git a/types/UseFilePlugin.d.ts b/types/UseFilePlugin.d.ts new file mode 100644 index 00000000..ce9a25b4 --- /dev/null +++ b/types/UseFilePlugin.d.ts @@ -0,0 +1,23 @@ +export = UseFilePlugin; +declare class UseFilePlugin { + /** + * @param {string | ResolveStepHook} source source + * @param {string} filename filename + * @param {string | ResolveStepHook} target target + */ + constructor(source: string | ResolveStepHook, filename: string, target: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + filename: string; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; +} +declare namespace UseFilePlugin { + export { Resolver, ResolveRequest, ResolveStepHook }; +} +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; +type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/createInnerContext.d.ts b/types/createInnerContext.d.ts new file mode 100644 index 00000000..dc91f848 --- /dev/null +++ b/types/createInnerContext.d.ts @@ -0,0 +1,6 @@ +declare namespace _exports { + export { ResolveContext }; +} +declare function _exports(parent: ResolveContext, stack: ResolveContext["stack"], message: null | string): ResolveContext; +export = _exports; +type ResolveContext = import("./Resolver").ResolveContext; diff --git a/types/forEachBail.d.ts b/types/forEachBail.d.ts new file mode 100644 index 00000000..4ed4625c --- /dev/null +++ b/types/forEachBail.d.ts @@ -0,0 +1,7 @@ +declare namespace _exports { + export { ResolveRequest, Iterator }; +} +declare function _exports(array: T[], iterator: Iterator, callback: (err?: null | Error, result?: null | Z, i?: number) => void): void; +export = _exports; +type ResolveRequest = import("./Resolver").ResolveRequest; +type Iterator = (item: T, callback: (err?: null | Error, result?: null | Z) => void, i: number) => void; diff --git a/types/getInnerRequest.d.ts b/types/getInnerRequest.d.ts new file mode 100644 index 00000000..a6e1899a --- /dev/null +++ b/types/getInnerRequest.d.ts @@ -0,0 +1,7 @@ +declare namespace _exports { + export { Resolver, ResolveRequest }; +} +declare function _exports(resolver: Resolver, request: ResolveRequest): string; +export = _exports; +type Resolver = import("./Resolver"); +type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/getPaths.d.ts b/types/getPaths.d.ts new file mode 100644 index 00000000..8107d24d --- /dev/null +++ b/types/getPaths.d.ts @@ -0,0 +1,31 @@ +export = getPaths; +/** @typedef {import("./Resolver").FileSystem} FileSystem */ +/** @typedef {{ paths: string[], segments: string[] }} GetPathsResult */ +/** + * Walk `path` from tip to root, returning every ancestor directory (plus the + * input itself) in `paths`, and each corresponding segment name in `segments`. + * + * The return value may be shared across callers via `getPathsCached` — treat + * it as read-only. Callers that need to mutate (currently only + * `SymlinkPlugin`) should `slice()` the arrays locally before writing. + * @param {string} path path + * @returns {GetPathsResult} paths and segments + */ +declare function getPaths(path: string): GetPathsResult; +declare namespace getPaths { + export { getPathsCached, FileSystem, GetPathsResult }; +} +/** + * Memoized `getPaths`. The returned object is shared across callers — do + * not mutate the `paths` or `segments` arrays in-place; `slice()` first if + * you need a mutable copy. + * @param {FileSystem} fileSystem filesystem used as the cache namespace + * @param {string} path path + * @returns {GetPathsResult} paths and segments + */ +declare function getPathsCached(fileSystem: FileSystem, path: string): GetPathsResult; +type FileSystem = import("./Resolver").FileSystem; +type GetPathsResult = { + paths: string[]; + segments: string[]; +}; diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 00000000..1c84698d --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,64 @@ +declare namespace _exports { + export { ResolveOptionsOptionalFS, CachedInputFileSystem, BaseFileSystem, CloneBasenamePlugin, LogInfoPlugin, PnpApi, Resolver, Context, FileSystem, ResolveCallback, ResolveContext, ResolveRequest, SyncFileSystem, Plugin, ResolveOptions, TsconfigPathsPlugin, ResolveFunctionAsync, ResolveFunction, ResolveFunctionPromise }; +} +declare const _exports: ResolveFunctionAsync & { + readonly sync: ResolveFunction; + readonly promise: ResolveFunctionPromise; + create: typeof create & { + readonly sync: typeof createSync; + readonly promise: typeof createPromise; + }; + readonly ResolverFactory: typeof import("./ResolverFactory"); + readonly CachedInputFileSystem: typeof import("./CachedInputFileSystem"); + readonly CloneBasenamePlugin: typeof import("./CloneBasenamePlugin"); + readonly LogInfoPlugin: typeof import("./LogInfoPlugin"); + readonly TsconfigPathsPlugin: typeof import("./TsconfigPathsPlugin"); + readonly forEachBail: (array: T[], iterator: import("./forEachBail").Iterator, callback: (err?: null | Error, result?: null | Z, i?: number) => void) => void; +}; +export = _exports; +type ResolveOptionsOptionalFS = Omit & Partial>; +type CachedInputFileSystem = import("./CachedInputFileSystem"); +type BaseFileSystem = import("./CachedInputFileSystem").BaseFileSystem; +type CloneBasenamePlugin = import("./CloneBasenamePlugin"); +type LogInfoPlugin = import("./LogInfoPlugin"); +type PnpApi = import("./PnpPlugin").PnpApiImpl; +type Resolver = import("./Resolver"); +type Context = import("./Resolver").Context; +type FileSystem = import("./Resolver").FileSystem; +type ResolveCallback = import("./Resolver").ResolveCallback; +type ResolveContext = import("./Resolver").ResolveContext; +type ResolveRequest = import("./Resolver").ResolveRequest; +type SyncFileSystem = import("./Resolver").SyncFileSystem; +type Plugin = import("./ResolverFactory").Plugin; +type ResolveOptions = import("./ResolverFactory").UserResolveOptions; +type TsconfigPathsPlugin = import("./TsconfigPathsPlugin"); +type ResolveFunctionAsync = { + (context: Context, parent: string | URL, specifier: string | URL, resolveContext: ResolveContext, callback: ResolveCallback): void; + (context: Context, parent: string | URL, specifier: string | URL, callback: ResolveCallback): void; + (parent: string | URL, specifier: string | URL, resolveContext: ResolveContext, callback: ResolveCallback): void; + (parent: string | URL, specifier: string | URL, callback: ResolveCallback): void; +}; +type ResolveFunction = { + (context: Context, parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext): string | false; + (parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext): string | false; +}; +type ResolveFunctionPromise = { + (context: Context, parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext): Promise; + (parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext): Promise; +}; +/** @typedef {Omit & Partial>} ResolveOptionsOptionalFS */ +/** + * @param {ResolveOptionsOptionalFS} options Resolver options + * @returns {ResolveFunctionAsync} Resolver function + */ +declare function create(options: ResolveOptionsOptionalFS): ResolveFunctionAsync; +/** + * @param {ResolveOptionsOptionalFS} options Resolver options + * @returns {ResolveFunction} Resolver function + */ +declare function createSync(options: ResolveOptionsOptionalFS): ResolveFunction; +/** + * @param {ResolveOptionsOptionalFS} options Resolver options + * @returns {ResolveFunctionPromise} Resolver function + */ +declare function createPromise(options: ResolveOptionsOptionalFS): ResolveFunctionPromise; diff --git a/types/util/entrypoints.d.ts b/types/util/entrypoints.d.ts new file mode 100644 index 00000000..3a28a065 --- /dev/null +++ b/types/util/entrypoints.d.ts @@ -0,0 +1,53 @@ +export function processExportsField(exportsField: ExportsField): FieldProcessor; +export function processImportsField(importsField: ImportsField): FieldProcessor; +export type DirectMapping = string | (string | ConditionalMapping)[]; +export type ConditionalMapping = { + [k: string]: MappingValue; +}; +export type MappingValue = ConditionalMapping | DirectMapping | null; +export type ExportsField = Record | ConditionalMapping | DirectMapping; +export type ImportsField = Record; +/** + * Processing exports/imports field + */ +export type FieldProcessor = (request: string, conditionNames: Set) => [string[], string | null]; +export type RecordMapping = Record; +/** + * Per-key precomputed info used by `findMatch`. Equivalent to what the + * previous implementation recomputed inline on every resolve. + */ +export type FieldKeyInfo = { + /** + * the original key + */ + key: string; + /** + * position of the single "*" in the key, or -1 when absent + */ + patternIndex: number; + /** + * substring before "*" (empty when patternIndex === -1) + */ + wildcardPrefix: string; + /** + * substring after "*" (empty when patternIndex === -1) + */ + wildcardSuffix: string; + /** + * true when key is a legacy `./foo/`-style folder key with no "*" + */ + isLegacySubpath: boolean; + /** + * true when key contains "*" + */ + isPattern: boolean; + /** + * true when key ends with "/" + */ + isSubpathMapping: boolean; + /** + * true when key has at most one "*" + */ + isValidPattern: boolean; +}; +export type MatchTuple = [MappingValue, string, boolean, boolean, string] | null; diff --git a/types/util/fileURLToPath.d.ts b/types/util/fileURLToPath.d.ts new file mode 100644 index 00000000..04e6b3fc --- /dev/null +++ b/types/util/fileURLToPath.d.ts @@ -0,0 +1,9 @@ +export = fileURLToPath; +/** + * @param {string | URL} path a `file:` URL string or `URL` instance + * @param {{ windows?: boolean }=} options force the platform branch + * @returns {string} the filesystem path + */ +declare function fileURLToPath(path: string | URL, options?: { + windows?: boolean; +} | undefined): string; diff --git a/types/util/fs.d.ts b/types/util/fs.d.ts new file mode 100644 index 00000000..31c516ea --- /dev/null +++ b/types/util/fs.d.ts @@ -0,0 +1,30 @@ +export type FileSystem = import("../Resolver").FileSystem; +export type JsonObject = import("../Resolver").JsonObject; +export type ReadJsonOptions = { + /** + * Whether to strip JSONC comments + */ + stripComments?: boolean | undefined; +}; +/** + * Decode a file's raw contents to text without assuming a Node runtime. A + * `Buffer` (Node) uses its fast native `toString`; any other binary input + * (`Uint8Array` from a browser/Deno/Bun file system) goes through + * `TextDecoder`, and strings are returned as-is. + * @param {string | Buffer | Uint8Array} data raw file contents + * @returns {string} decoded text + */ +export function decodeText(data: string | Buffer | Uint8Array): string; +/** + * Read and parse JSON file (supports JSONC with comments). + * Callback-based so a synchronous `fileSystem` stays synchronous all the + * way through — Promise wrapping would defer resolution by a Promise tick + * and break `resolveSync` when `tsconfig` is used together with + * `useSyncFileSystemCalls: true`. + * @param {FileSystem} fileSystem the file system + * @param {string} jsonFilePath absolute path to JSON file + * @param {ReadJsonOptions} options Options + * @param {(err: NodeJS.ErrnoException | Error | null, content?: JsonObject) => void} callback callback + * @returns {void} + */ +export function readJson(fileSystem: FileSystem, jsonFilePath: string, options: ReadJsonOptions, callback: (err: NodeJS.ErrnoException | Error | null, content?: JsonObject) => void): void; diff --git a/types/util/graceful-fs-browser.d.ts b/types/util/graceful-fs-browser.d.ts new file mode 100644 index 00000000..066af568 --- /dev/null +++ b/types/util/graceful-fs-browser.d.ts @@ -0,0 +1,5 @@ +/** + * @returns {never} always throws + */ +declare function unavailable(): never; +export { unavailable as lstat, unavailable as lstatSync, unavailable as readFile, unavailable as readFileSync, unavailable as readdir, unavailable as readdirSync, unavailable as readlink, unavailable as readlinkSync, unavailable as realpath, unavailable as realpathSync, unavailable as stat, unavailable as statSync }; diff --git a/types/util/identifier.d.ts b/types/util/identifier.d.ts new file mode 100644 index 00000000..f0265975 --- /dev/null +++ b/types/util/identifier.d.ts @@ -0,0 +1,5 @@ +/** + * @param {string} identifier identifier + * @returns {[string, string, string] | null} parsed identifier + */ +export function parseIdentifier(identifier: string): [string, string, string] | null; diff --git a/types/util/memoize.d.ts b/types/util/memoize.d.ts new file mode 100644 index 00000000..3441c81e --- /dev/null +++ b/types/util/memoize.d.ts @@ -0,0 +1,15 @@ +export = memoize; +/** + * @template T + * @typedef {() => T} FunctionReturning + */ +/** + * @template T + * @param {FunctionReturning} fn memorized function + * @returns {FunctionReturning} new function + */ +declare function memoize(fn: FunctionReturning): FunctionReturning; +declare namespace memoize { + export { FunctionReturning }; +} +type FunctionReturning = () => T; diff --git a/types/util/module-browser.d.ts b/types/util/module-browser.d.ts new file mode 100644 index 00000000..cb0ff5c3 --- /dev/null +++ b/types/util/module-browser.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/types/util/packageMap.d.ts b/types/util/packageMap.d.ts new file mode 100644 index 00000000..805c1e50 --- /dev/null +++ b/types/util/packageMap.d.ts @@ -0,0 +1,109 @@ +export type JsonObject = import("../Resolver").JsonObject; +export type PackageMapDependencies = { + [specifier: string]: string; +}; +/** + * A single entry of the configuration file's `packages` object. + */ +export type PackageMapPackage = { + /** + * an absolute or relative `file:` URL, resolved against the configuration file + */ + url: string; + /** + * bare specifier to package id + */ + dependencies?: PackageMapDependencies | undefined; +}; +export type PackageMapPackages = { + [id: string]: PackageMapPackage; +}; +/** + * The parsed contents of a package map configuration file. + */ +export type PackageMapJson = { + /** + * package entries by package id + */ + packages: PackageMapPackages; +}; +export type PackageMapEntry = { + /** + * the package id this entry is keyed by + */ + id: string; + /** + * absolute filesystem path the entry's `url` points at + */ + path: string; + /** + * bare specifier to package id + */ + dependencies: Map; +}; +export type PackageMap = { + /** + * entries by package id + */ + packages: Map; + /** + * package ids by location, longest path first + */ + locations: { + path: string; + ids: string[]; + }[]; +}; +/** @typedef {import("../Resolver").JsonObject} JsonObject */ +/** @typedef {{ [specifier: string]: string }} PackageMapDependencies */ +/** + * A single entry of the configuration file's `packages` object. + * @typedef {object} PackageMapPackage + * @property {string} url an absolute or relative `file:` URL, resolved against the configuration file + * @property {PackageMapDependencies=} dependencies bare specifier to package id + */ +/** @typedef {{ [id: string]: PackageMapPackage }} PackageMapPackages */ +/** + * The parsed contents of a package map configuration file. + * @typedef {object} PackageMapJson + * @property {PackageMapPackages} packages package entries by package id + */ +/** + * @typedef {object} PackageMapEntry + * @property {string} id the package id this entry is keyed by + * @property {string} path absolute filesystem path the entry's `url` points at + * @property {Map} dependencies bare specifier to package id + */ +/** + * @typedef {object} PackageMap + * @property {Map} packages entries by package id + * @property {{ path: string, ids: string[] }[]} locations package ids by location, longest path first + */ +/** + * @param {string} message message + * @param {string} code error code + * @returns {Error & { code: string }} the error + */ +export function createError(message: string, code: string): Error & { + code: string; +}; +/** + * Find the package ids whose location contains `filePath`. More than one id is + * returned when several package entries share the same `url`, which the caller + * has to disambiguate with an explicit package id. + * @param {PackageMap} packageMap the package map + * @param {string} filePath an absolute filesystem path + * @returns {string[]} the matching package ids, empty when the path is outside every package + */ +export function findPackageIds(packageMap: PackageMap, filePath: string): string[]; +/** + * Parse and validate a package map configuration file. + * + * Dangling dependency targets are rejected here rather than at resolution + * time: the map is static, so a broken table is a configuration error that is + * better surfaced once and in full. + * @param {JsonObject} data the parsed configuration file contents + * @param {string} configFilePath absolute path of the configuration file, used as the base for relative urls + * @returns {PackageMap} the parsed package map + */ +export function parsePackageMap(data: JsonObject, configFilePath: string): PackageMap; diff --git a/types/util/path-browser.d.ts b/types/util/path-browser.d.ts new file mode 100644 index 00000000..fe8556d8 --- /dev/null +++ b/types/util/path-browser.d.ts @@ -0,0 +1,45 @@ +/** + * Posix `basename` — the browser is treated as a posix platform, matching how + * Node picks the posix variant for `path.basename` on non-Windows systems. + * @param {string} path path + * @param {string=} suffix optional suffix to strip + * @returns {string} basename + */ +export function basename(path: string, suffix?: string | undefined): string; +/** + * @param {string} path path + * @returns {string} normalized posix path + */ +declare function posixNormalize(path: string): string; +/** + * @param {string} path path + * @returns {string} posix dirname + */ +declare function posixDirname(path: string): string; +/** + * Normalizes drive paths (`C:\…`), UNC paths (`\\server\share\…`), DOS device + * paths (`\\.\…`, `\\?\…`) and relative/normal segments like Node's + * `path.win32.normalize`, including the CVE-2024-36139 colon-segment guard. + * + * Scope note: reserved Windows device names (`CON`, `COM1`, `LPT1`, …) are not + * special-cased, so e.g. `\\.\COM1:` differs from Node. Such names cannot occur + * in a browser (the only place this shim is used) and the resolver never routes + * them to `win32.normalize`, so this does not affect resolution. + * @param {string} path path + * @returns {string} normalized win32 path + */ +declare function win32Normalize(path: string): string; +/** + * @param {string} path path + * @returns {string} win32 dirname + */ +declare function win32Dirname(path: string): string; +export declare namespace posix { + export { posixNormalize as normalize }; + export { posixDirname as dirname }; +} +export declare namespace win32 { + export { win32Normalize as normalize }; + export { win32Dirname as dirname }; +} +export {}; diff --git a/types/util/path.d.ts b/types/util/path.d.ts new file mode 100644 index 00000000..91d4ee55 --- /dev/null +++ b/types/util/path.d.ts @@ -0,0 +1,125 @@ +export type CachedJoin = { + fn: (rootPath: string, request: string) => string; + cache: Map>; +}; +export type CachedDirname = { + fn: (maybePath: string) => string; + cache: Map; +}; +export type CachedBasename = { + fn: (maybePath: string, suffix?: string) => string; + cache: Map>; +}; +export type PathType = number; +/** + * @enum {number} + */ +export const PathType: Readonly<{ + Empty: 0; + Normal: 1; + Relative: 2; + AbsoluteWin: 3; + AbsolutePosix: 4; + Internal: 5; +}>; +/** @typedef {{ fn: (maybePath: string, suffix?: string) => string, cache: Map> }} CachedBasename */ +/** + * @returns {CachedBasename} cached basename + */ +export function createCachedBasename(): CachedBasename; +/** @typedef {{ fn: (maybePath: string) => string, cache: Map }} CachedDirname */ +/** + * @returns {CachedDirname} cached dirname + */ +export function createCachedDirname(): CachedDirname; +/** @typedef {{ fn: (rootPath: string, request: string) => string, cache: Map> }} CachedJoin */ +/** + * @returns {CachedJoin} cached join + */ +export function createCachedJoin(): CachedJoin; +export const deprecatedInvalidSegmentRegEx: RegExp; +/** + * @param {string} maybePath a path + * @returns {string} the directory name + */ +export function dirname(maybePath: string): string; +/** + * @param {string} maybePath a path + * @returns {PathType} type of path + */ +export function getType(maybePath: string): PathType; +export const invalidSegmentRegEx: RegExp; +/** + * Whether a string names a `file:` URL rather than a path. The scheme has to + * open the string and be followed by a slash, as Node's own URL parser needs, + * so a path segment spelled `file:` stays a path and `file:x.js` — which Node + * reads as `/x.js` — stays the relative request it looks like. + * @param {string} maybePath a path or a `file:` URL string + * @returns {boolean} true when the string is a `file:` URL + */ +export function isFileURL(maybePath: string): boolean; +/** + * Whether childPath is parentPath itself or a path under it, the answer node's + * `relative(parentPath, childPath)` gives: not escaping upward and not + * absolute. A trailing separator on the parent is not part of the boundary, so + * `/a/b/` contains exactly what `/a/b` contains. + * @param {string} parentPath parent directory path + * @param {string} childPath child path to check + * @returns {boolean} true if childPath is parentPath or is under it + */ +export function isInside(parentPath: string, childPath: string): boolean; +/** + * Whether `request` is a relative request — i.e. matches `^\.\.?(?:\/|$)`. + * + * This is called on every `doResolve` via `UnsafeCachePlugin` and + * `getInnerRequest`, so the char-code form is meaningfully faster than the + * equivalent regex test: no regex state machine, no string object churn. + * @param {string} request request string + * @returns {boolean} true if request is relative + */ +export function isRelativeRequest(request: string): boolean; +/** + * Check if childPath is a subdirectory of parentPath. Compares like `isInside`, + * except that a path is not a subpath of itself. + * + * Called from `TsconfigPathsPlugin._selectPathsDataForContext` inside a loop + * over every tsconfig-paths context on every resolve, so it's worth keeping + * cheap: a native `startsWith` plus a separator char check answers it, and the + * character loop only runs for a Windows path that the prefix test missed. + * @param {string} parentPath parent directory path + * @param {string} childPath child path to check + * @returns {boolean} true if childPath is under parentPath + */ +export function isSubPath(parentPath: string, childPath: string): boolean; +/** + * Whether this is a Windows path, in which `/` and `\` are interchangeable and + * paths compare case-insensitively, as opposed to a posix path, in which `\` is + * an ordinary filename character. Decided by the root — a drive letter or a + * leading `\` — which is where `path.win32` and `path.posix` disagree about + * `parse(maybePath).root`, and never by the host platform, since Windows paths + * are resolved on posix hosts and in browsers too. A path starting with `//` + * stays posix: `path.win32` reads it as a UNC root, but here it cannot be told + * apart from a posix path, where `\` has to keep being a filename character. + * @param {string} maybePath a path + * @returns {boolean} true, when the path is a Windows path + */ +export function isWindowsPath(maybePath: string): boolean; +/** + * @param {string} rootPath the root path + * @param {string | undefined} request the request path + * @returns {string} the joined path + */ +export function join(rootPath: string, request: string | undefined): string; +/** + * @param {string} maybePath a path + * @returns {string} the normalized path + */ +export function normalize(maybePath: string): string; +/** + * Convert a `file:` URL — a `URL` instance or a `file:/` string, the form + * `import.meta.resolve` returns — to the path it names. Anything else is + * returned unchanged, so a path passes through. + * @param {string | URL} maybeURL a path, a `file:` URL string or a `file:` `URL` instance + * @returns {string} a filesystem path + */ +export function toPath(maybeURL: string | URL): string; diff --git a/types/util/pathToFileURL.d.ts b/types/util/pathToFileURL.d.ts new file mode 100644 index 00000000..7780e0c4 --- /dev/null +++ b/types/util/pathToFileURL.d.ts @@ -0,0 +1,9 @@ +export = pathToFileURL; +/** + * @param {string} filepath an absolute filesystem path + * @param {{ windows?: boolean }=} options force the platform branch + * @returns {URL} the `file:` URL + */ +declare function pathToFileURL(filepath: string, options?: { + windows?: boolean; +} | undefined): URL; diff --git a/types/util/process-browser.d.ts b/types/util/process-browser.d.ts new file mode 100644 index 00000000..11b331b1 --- /dev/null +++ b/types/util/process-browser.d.ts @@ -0,0 +1,3 @@ +export let versions: Record; +/** @param {Function} fn function */ +export function nextTick(fn: Function, ...args: any[]): void; diff --git a/types/util/strip-json-comments.d.ts b/types/util/strip-json-comments.d.ts new file mode 100644 index 00000000..6d294f8a --- /dev/null +++ b/types/util/strip-json-comments.d.ts @@ -0,0 +1,21 @@ +export = stripJsonComments; +/** + * Strip comments from JSON string + * @param {string} jsonString JSON string with potential comments + * @param {StripJsonCommentsOptions} options Options + * @returns {string} JSON string without comments + */ +declare function stripJsonComments(jsonString: string, { whitespace, trailingCommas }?: StripJsonCommentsOptions): string; +declare namespace stripJsonComments { + export { StripJsonCommentsOptions }; +} +type StripJsonCommentsOptions = { + /** + * Replace comments with whitespace + */ + whitespace?: boolean | undefined; + /** + * Strip trailing commas + */ + trailingCommas?: boolean | undefined; +}; diff --git a/types/util/url-browser.d.ts b/types/util/url-browser.d.ts new file mode 100644 index 00000000..9af30a4e --- /dev/null +++ b/types/util/url-browser.d.ts @@ -0,0 +1 @@ +export let fileURLToPath: typeof import("./fileURLToPath"); From d1d96e288b15e2dba8e0d7167039201022a859a5 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Fri, 18 Sep 2026 19:18:37 +0000 Subject: [PATCH 2/4] ci: verify the generated types in the lint job The declarations in `types/` are generated from the JSDoc in `lib/`, so a checkout whose types were never regenerated ships declarations that do not describe the code. Nothing caught that in CI. The lint job now regenerates them and diffs, which is how `webpack-dev-middleware` and `schema-utils` check theirs: - name: Build types run: npm run build:types - name: Check types run: git status types --porcelain # non-empty => fail `build:types` replaces the bespoke `--check` mode that compared against a temporary directory; git already answers that question, and the script is smaller for it. It removes `types/` before emitting, because `tsc` overwrites the declarations it still emits but never deletes the ones it no longer does - and a leftover file is invisible to a `git status` check, being tracked, unchanged, and still published after its source is gone. `types/` is no longer in `.prettierignore`: `build:types` formats it, so `fmt:check` covers it like any other source. `lint:special` is gone from the `lint` chain, since the CI steps above are what check this now. Verified: regenerating on a clean tree leaves it clean; a JSDoc change without regeneration is reported; a deleted source file removes its declaration rather than leaving it behind. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_016aGHrb1YaEvaGwNELGEHjF --- .github/workflows/test.yml | 15 + .prettierignore | 3 - package.json | 7 +- scripts/build-types.js | 45 + scripts/generate-types.js | 127 -- types/AliasFieldPlugin.d.ts | 46 +- types/AliasPlugin.d.ts | 40 +- types/AliasUtils.d.ts | 129 +- types/AppendPlugin.d.ts | 34 +- types/CachedInputFileSystem.d.ts | 311 ++- types/CloneBasenamePlugin.d.ts | 29 +- types/ConditionalPlugin.d.ts | 44 +- types/DescriptionFilePlugin.d.ts | 39 +- types/DescriptionFileUtils.d.ts | 67 +- types/DirectoryExistsPlugin.d.ts | 29 +- types/ExportsFieldPlugin.d.ts | 55 +- types/ExtensionAliasPlugin.d.ts | 38 +- types/FileExistsPlugin.d.ts | 29 +- types/ImportsFieldPlugin.d.ts | 55 +- types/JoinRequestPartPlugin.d.ts | 29 +- types/JoinRequestPlugin.d.ts | 29 +- types/LogInfoPlugin.d.ts | 22 +- types/MainFieldPlugin.d.ts | 48 +- ...odulesInHierarchicalDirectoriesPlugin.d.ts | 34 +- types/ModulesInRootPlugin.d.ts | 34 +- types/ModulesUtils.d.ts | 14 +- types/NextPlugin.d.ts | 29 +- types/PackageMapPlugin.d.ts | 121 +- types/ParsePlugin.d.ts | 34 +- types/PnpPlugin.d.ts | 55 +- types/Resolver.d.ts | 1975 ++++++++++------- types/ResolverFactory.d.ts | 594 ++--- types/RestrictionsPlugin.d.ts | 71 +- types/ResultPlugin.d.ts | 22 +- types/RootsPlugin.d.ts | 34 +- types/SelfReferencePlugin.d.ts | 38 +- types/SymlinkPlugin.d.ts | 29 +- types/SyncAsyncFileSystemDecorator.d.ts | 58 +- types/TryNextPlugin.d.ts | 34 +- types/TsconfigPathsPlugin.d.ts | 311 +-- types/UnsafeCachePlugin.d.ts | 52 +- types/UseFilePlugin.d.ts | 34 +- types/createInnerContext.d.ts | 8 +- types/forEachBail.d.ts | 14 +- types/getInnerRequest.d.ts | 2 +- types/getPaths.d.ts | 11 +- types/index.d.ts | 115 +- types/util/entrypoints.d.ts | 77 +- types/util/fileURLToPath.d.ts | 11 +- types/util/fs.d.ts | 18 +- types/util/graceful-fs-browser.d.ts | 15 +- types/util/identifier.d.ts | 4 +- types/util/memoize.d.ts | 2 +- types/util/packageMap.d.ts | 91 +- types/util/path-browser.d.ts | 8 +- types/util/path.d.ts | 24 +- types/util/pathToFileURL.d.ts | 11 +- types/util/strip-json-comments.d.ts | 23 +- 58 files changed, 3017 insertions(+), 2260 deletions(-) create mode 100644 scripts/build-types.js delete mode 100644 scripts/generate-types.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9a531d6e..11bec040 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -36,6 +36,21 @@ jobs: - run: npm ci - run: npm run lint + + - name: Build types + run: npm run build:types + + # `types/` is generated from the JSDoc in `lib/`, so a checkout whose + # declarations were never regenerated ships types that do not describe + # the code. Regenerating above and diffing here is what catches that. + - name: Check types + run: | + if [ -n "$(git status types --porcelain)" ]; then + git status types --porcelain + echo "::error::Generated types are out of date - run 'npm run build:types' and commit the result" + exit 1 + fi + echo "All types are up to date" test: strategy: fail-fast: false diff --git a/.prettierignore b/.prettierignore index 783e854b..793d7065 100644 --- a/.prettierignore +++ b/.prettierignore @@ -2,6 +2,3 @@ package.json package-lock.json test/**/*.* !test/*.js - -# Generated files -types/ diff --git a/package.json b/package.json index aaec2448..6b986b5d 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,8 @@ ], "scripts": { "prepare": "husky", - "lint": "npm run lint:code && npm run lint:types && npm run lint:types-test && npm run lint:types-api && npm run lint:special && npm run fmt:check && npm run lint:spellcheck", + "lint": "npm run lint:code && npm run lint:types && npm run lint:types-test && npm run lint:types-api && npm run fmt:check && npm run lint:spellcheck", "lint:code": "eslint --cache .", - "lint:special": "node scripts/generate-types.js --check", "lint:types": "tsc", "lint:types-test": "tsc -p tsconfig.types.test.json", "lint:types-api": "tsc -p tsconfig.types.api.json", @@ -36,9 +35,9 @@ "fmt": "npm run fmt:base -- --log-level warn --write", "fmt:check": "npm run fmt:base -- --check", "fmt:base": "node_modules/prettier/bin/prettier.cjs --cache --ignore-unknown .", - "fix": "npm run fix:code && npm run fix:special", + "fix": "npm run fix:code && npm run build:types", "fix:code": "npm run lint:code -- --fix", - "fix:special": "node scripts/generate-types.js", + "build:types": "node scripts/build-types.js", "type-report": "rimraf coverage && npm run cover:types && npm run cover:report && open-cli coverage/lcov-report/index.html", "pretest": "npm run lint", "test": "npm run test:only", diff --git a/scripts/build-types.js b/scripts/build-types.js new file mode 100644 index 00000000..54d3a01d --- /dev/null +++ b/scripts/build-types.js @@ -0,0 +1,45 @@ +"use strict"; + +// Generates the published type declarations in `types/` from the JSDoc in +// `lib/`, then formats them. CI regenerates and checks `git status types`, so +// a stale checkout fails the `lint` job - see `.github/workflows/test.yml`. +// +// The output directory is removed first. `tsc` overwrites the declarations it +// still emits but never deletes the ones it no longer does, and a leftover +// file is invisible to a `git status` check: it is tracked, unchanged, and +// would keep shipping after its source was gone. + +const { spawnSync } = require("child_process"); +const { rmSync } = require("fs"); +const path = require("path"); + +const root = path.join(__dirname, ".."); + +/** + * @param {string} command binary to run, relative to `node_modules/.bin` + * @param {string[]} args arguments + * @returns {void} + */ +const run = (command, args) => { + const binary = path.join( + root, + "node_modules", + ".bin", + process.platform === "win32" ? `${command}.cmd` : command, + ); + const { status } = spawnSync(binary, args, { + cwd: root, + stdio: "inherit", + shell: process.platform === "win32", + }); + + if (status !== 0) { + throw new Error( + `${command} exited with ${status === null ? "a signal" : status}`, + ); + } +}; + +rmSync(path.join(root, "types"), { recursive: true, force: true }); +run("tsc", ["-p", "tsconfig.types.json"]); +run("prettier", ["--log-level", "warn", "--write", "types/**/*.d.ts"]); diff --git a/scripts/generate-types.js b/scripts/generate-types.js deleted file mode 100644 index 1c09c37a..00000000 --- a/scripts/generate-types.js +++ /dev/null @@ -1,127 +0,0 @@ -"use strict"; - -// Generates the published type declarations from the JSDoc in `lib/`. -// -// This used to be done by `webpack/tooling`, which bundled every reachable -// type into a single hand-rolled `types.d.ts`. TypeScript can emit the same -// information itself, so the declarations are now whatever `tsc` derives from -// the sources - there is no second type system to keep in sync, and a type -// that is wrong in the emitted output is wrong in the JSDoc it came from. -// -// node scripts/generate-types.js write `types/` -// node scripts/generate-types.js --check fail if `types/` is stale -// -// The check mode emits into a temporary directory and compares, so CI reports -// a stale checkout without leaving a dirty working tree behind. - -const { spawnSync } = require("child_process"); -const { - existsSync, - mkdtempSync, - readFileSync, - readdirSync, - rmSync, - statSync, -} = require("fs"); -const { tmpdir } = require("os"); -const path = require("path"); - -const root = path.join(__dirname, ".."); -const outDir = path.join(root, "types"); - -/** - * @param {string} dir directory to emit the declarations into - * @returns {void} - */ -const emit = (dir) => { - const tsc = path.join( - root, - "node_modules", - ".bin", - process.platform === "win32" ? "tsc.cmd" : "tsc", - ); - const { status } = spawnSync( - tsc, - ["-p", "tsconfig.types.json", "--declarationDir", dir], - { cwd: root, stdio: "inherit", shell: process.platform === "win32" }, - ); - - if (status !== 0) { - throw new Error(`tsc exited with ${status === null ? "a signal" : status}`); - } -}; - -/** - * @param {string} dir directory to walk - * @param {string=} prefix path of `dir` relative to the walk root - * @returns {Map} declaration path relative to `dir`, to content - */ -const readDeclarations = (dir, prefix = "") => { - /** @type {Map} */ - const declarations = new Map(); - - for (const entry of readdirSync(dir).sort()) { - const absolute = path.join(dir, entry); - const relative = prefix ? `${prefix}/${entry}` : entry; - - if (statSync(absolute).isDirectory()) { - for (const [file, content] of readDeclarations(absolute, relative)) { - declarations.set(file, content); - } - } else if (entry.endsWith(".d.ts")) { - declarations.set(relative, readFileSync(absolute, "utf8")); - } - } - - return declarations; -}; - -/** - * @returns {void} - */ -const write = () => { - rmSync(outDir, { recursive: true, force: true }); - emit(outDir); -}; - -/** - * @returns {void} - */ -const check = () => { - const temporary = mkdtempSync(path.join(tmpdir(), "enhanced-resolve-types-")); - - try { - emit(temporary); - - const expected = readDeclarations(temporary); - const actual = existsSync(outDir) ? readDeclarations(outDir) : new Map(); - /** @type {string[]} */ - const stale = []; - - for (const [file, content] of expected) { - if (actual.get(file) !== content) stale.push(`types/${file}`); - } - - for (const file of actual.keys()) { - if (!expected.has(file)) { - stale.push(`types/${file} (no longer generated)`); - } - } - - if (stale.length > 0) { - throw new Error( - `The following generated files need to be updated:\n${stale - .map((file) => ` ${file}`) - .join("\n")}\nRun \`npm run fix:special\` to update them.`, - ); - } - } finally { - rmSync(temporary, { recursive: true, force: true }); - } -}; - -if (process.argv.includes("--check")) { - check(); -} else { - write(); -} diff --git a/types/AliasFieldPlugin.d.ts b/types/AliasFieldPlugin.d.ts index 8f0d47fb..f6ce2047 100644 --- a/types/AliasFieldPlugin.d.ts +++ b/types/AliasFieldPlugin.d.ts @@ -1,26 +1,34 @@ export = AliasFieldPlugin; declare class AliasFieldPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | string[]} field field - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, field: string | string[], target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - field: string | string[]; - target: string | import("./Resolver").ResolveStepHook; - /** @type {WeakMap} */ - _fieldDataCache: WeakMap; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | string[]} field field + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + field: string | string[], + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + field: string | string[]; + target: string | import("./Resolver").ResolveStepHook; + /** @type {WeakMap} */ + _fieldDataCache: WeakMap< + import("./Resolver").JsonObject, + | { + [k: string]: JsonPrimitive; + } + | typeof NO_FIELD_OBJECT + >; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace AliasFieldPlugin { - export { Resolver, JsonPrimitive, ResolveRequest, ResolveStepHook }; + export { Resolver, JsonPrimitive, ResolveRequest, ResolveStepHook }; } /** @typedef {import("./Resolver")} Resolver */ /** @typedef {import("./Resolver").JsonPrimitive} JsonPrimitive */ diff --git a/types/AliasPlugin.d.ts b/types/AliasPlugin.d.ts index fa7108e2..2aa17661 100644 --- a/types/AliasPlugin.d.ts +++ b/types/AliasPlugin.d.ts @@ -1,28 +1,32 @@ export = AliasPlugin; declare class AliasPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {AliasOption | AliasOption[]} options options - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, options: AliasOption | AliasOption[], target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - options: AliasOption[]; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {AliasOption | AliasOption[]} options options + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + options: AliasOption | AliasOption[], + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + options: AliasOption[]; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace AliasPlugin { - export { Resolver, ResolveStepHook, Alias, AliasOption }; + export { Resolver, ResolveStepHook, Alias, AliasOption }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; type Alias = string | string[] | false; type AliasOption = { - alias: Alias; - name: string; - onlyModule?: boolean; + alias: Alias; + name: string; + onlyModule?: boolean; }; diff --git a/types/AliasUtils.d.ts b/types/AliasUtils.d.ts index da24ec76..2bf58f31 100644 --- a/types/AliasUtils.d.ts +++ b/types/AliasUtils.d.ts @@ -1,4 +1,7 @@ -export type InnerCallback = (err?: null | Error, result?: null | ResolveRequest) => void; +export type InnerCallback = ( + err?: null | Error, + result?: null | ResolveRequest, +) => void; export type Resolver = import("./Resolver"); export type ResolveRequest = import("./Resolver").ResolveRequest; export type ResolveContext = import("./Resolver").ResolveContext; @@ -6,47 +9,47 @@ export type ResolveStepHook = import("./Resolver").ResolveStepHook; export type ResolveCallback = import("./Resolver").ResolveCallback; export type Alias = string | string[] | false; export type AliasOption = { - alias: Alias; - name: string; - onlyModule?: boolean; + alias: Alias; + name: string; + onlyModule?: boolean; }; export type CompiledAliasOption = { - /** - * original alias name - */ - name: string; - /** - * name + "/" — precomputed to avoid per-resolve concat - */ - nameWithSlash: string; - /** - * alias target(s) - */ - alias: Alias; - /** - * normalized onlyModule flag - */ - onlyModule: boolean; - /** - * absolute form of `name` (with slash ending), null when not absolute - */ - absolutePath: string | null; - /** - * substring before the single "*" in `name`, null when no wildcard - */ - wildcardPrefix: string | null; - /** - * substring after the single "*" in `name`, null when no wildcard - */ - wildcardSuffix: string | null; - /** - * first character code of `name` — used as a cheap screen on the hot path. `-1` indicates "matches any first char" (empty wildcard prefix). - */ - firstCharCode: number; - /** - * true when `alias` is an array — precomputed so the hot path skips `Array.isArray` - */ - arrayAlias: boolean; + /** + * original alias name + */ + name: string; + /** + * name + "/" — precomputed to avoid per-resolve concat + */ + nameWithSlash: string; + /** + * alias target(s) + */ + alias: Alias; + /** + * normalized onlyModule flag + */ + onlyModule: boolean; + /** + * absolute form of `name` (with slash ending), null when not absolute + */ + absolutePath: string | null; + /** + * substring before the single "*" in `name`, null when no wildcard + */ + wildcardPrefix: string | null; + /** + * substring after the single "*" in `name`, null when no wildcard + */ + wildcardSuffix: string | null; + /** + * first character code of `name` — used as a cheap screen on the hot path. `-1` indicates "matches any first char" (empty wildcard prefix). + */ + firstCharCode: number; + /** + * true when `alias` is an array — precomputed so the hot path skips `Array.isArray` + */ + arrayAlias: boolean; }; /** * Bucketed view of compiled options used by `aliasResolveHandler` to avoid @@ -68,22 +71,22 @@ export type CompiledAliasOption = { * regression on `pathological-deep-stack`. */ export type CompiledAliasOptions = { - /** - * declaration-ordered list - */ - all: CompiledAliasOption[]; - /** - * bucketed by first char code - */ - byFirstChar: Map; - /** - * true when an empty-prefix wildcard is present - */ - hasAnyFirstChar: boolean; - /** - * true when the bucket fast-path should be used at resolve time - */ - useBuckets: boolean; + /** + * declaration-ordered list + */ + all: CompiledAliasOption[]; + /** + * bucketed by first char code + */ + byFirstChar: Map; + /** + * true when an empty-prefix wildcard is present + */ + hasAnyFirstChar: boolean; + /** + * true when the bucket fast-path should be used at resolve time + */ + useBuckets: boolean; }; /** @typedef {(err?: null | Error, result?: null | ResolveRequest) => void} InnerCallback */ /** @@ -95,7 +98,14 @@ export type CompiledAliasOptions = { * @param {InnerCallback} callback callback * @returns {void} */ -export function aliasResolveHandler(resolver: Resolver, options: CompiledAliasOptions, target: ResolveStepHook, request: ResolveRequest, resolveContext: ResolveContext, callback: InnerCallback): void; +export function aliasResolveHandler( + resolver: Resolver, + options: CompiledAliasOptions, + target: ResolveStepHook, + request: ResolveRequest, + resolveContext: ResolveContext, + callback: InnerCallback, +): void; /** * Precompute per-option strings used on every resolve so the hot path in * `aliasResolveHandler` does no string concatenation / split work per entry. @@ -112,4 +122,7 @@ export function aliasResolveHandler(resolver: Resolver, options: CompiledAliasOp * @param {AliasOption[]} options options * @returns {CompiledAliasOptions} compiled options */ -export function compileAliasOptions(resolver: Resolver, options: AliasOption[]): CompiledAliasOptions; +export function compileAliasOptions( + resolver: Resolver, + options: AliasOption[], +): CompiledAliasOptions; diff --git a/types/AppendPlugin.d.ts b/types/AppendPlugin.d.ts index e3513560..97fcf625 100644 --- a/types/AppendPlugin.d.ts +++ b/types/AppendPlugin.d.ts @@ -1,22 +1,26 @@ export = AppendPlugin; declare class AppendPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string} appending appending - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, appending: string, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - appending: string; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string} appending appending + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + appending: string, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + appending: string; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace AppendPlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/CachedInputFileSystem.d.ts b/types/CachedInputFileSystem.d.ts index 7ceb207f..65f50c02 100644 --- a/types/CachedInputFileSystem.d.ts +++ b/types/CachedInputFileSystem.d.ts @@ -1,58 +1,97 @@ export = CachedInputFileSystem; declare class CachedInputFileSystem { - /** - * @param {BaseFileSystem} fileSystem file system - * @param {number} duration duration in ms files are cached - */ - constructor(fileSystem: BaseFileSystem, duration: number); - fileSystem: BaseFileSystem; - _lstatBackend: OperationMergerBackend | CacheBackend; - lstat: import("./Resolver").LStat | undefined; - lstatSync: import("./Resolver").LStatSync | undefined; - _statBackend: OperationMergerBackend | CacheBackend; - stat: import("./Resolver").Stat; - statSync: import("./Resolver").StatSync; - _readdirBackend: OperationMergerBackend | CacheBackend; - readdir: import("./Resolver").Readdir; - readdirSync: import("./Resolver").ReaddirSync; - _readFileBackend: OperationMergerBackend | CacheBackend; - readFile: import("./Resolver").ReadFile; - readFileSync: import("./Resolver").ReadFileSync; - _readJsonBackend: OperationMergerBackend | CacheBackend; - readJson: import("./Resolver").ReadJson | undefined; - readJsonSync: import("./Resolver").ReadJsonSync | undefined; - _readlinkBackend: OperationMergerBackend | CacheBackend; - readlink: import("./Resolver").Readlink; - readlinkSync: import("./Resolver").ReadlinkSync; - _realpathBackend: OperationMergerBackend | CacheBackend; - realpath: import("./Resolver").RealPath | undefined; - realpathSync: import("./Resolver").RealPathSync | undefined; - /** - * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge - * @param {{ exact?: boolean }=} options options; `exact: true` removes only cache entries whose key matches `what` exactly instead of any entry whose key starts with `what` - */ - purge(what?: (string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set) | undefined, options?: { - exact?: boolean; - } | undefined): void; + /** + * @param {BaseFileSystem} fileSystem file system + * @param {number} duration duration in ms files are cached + */ + constructor(fileSystem: BaseFileSystem, duration: number); + fileSystem: BaseFileSystem; + _lstatBackend: OperationMergerBackend | CacheBackend; + lstat: import("./Resolver").LStat | undefined; + lstatSync: import("./Resolver").LStatSync | undefined; + _statBackend: OperationMergerBackend | CacheBackend; + stat: import("./Resolver").Stat; + statSync: import("./Resolver").StatSync; + _readdirBackend: OperationMergerBackend | CacheBackend; + readdir: import("./Resolver").Readdir; + readdirSync: import("./Resolver").ReaddirSync; + _readFileBackend: OperationMergerBackend | CacheBackend; + readFile: import("./Resolver").ReadFile; + readFileSync: import("./Resolver").ReadFileSync; + _readJsonBackend: OperationMergerBackend | CacheBackend; + readJson: import("./Resolver").ReadJson | undefined; + readJsonSync: import("./Resolver").ReadJsonSync | undefined; + _readlinkBackend: OperationMergerBackend | CacheBackend; + readlink: import("./Resolver").Readlink; + readlinkSync: import("./Resolver").ReadlinkSync; + _realpathBackend: OperationMergerBackend | CacheBackend; + realpath: import("./Resolver").RealPath | undefined; + realpathSync: import("./Resolver").RealPathSync | undefined; + /** + * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge + * @param {{ exact?: boolean }=} options options; `exact: true` removes only cache entries whose key matches `what` exactly instead of any entry whose key starts with `what` + */ + purge( + what?: + | ( + | string + | Buffer + | URL + | number + | (string | URL | Buffer | number)[] + | Set + ) + | undefined, + options?: + | { + exact?: boolean; + } + | undefined, + ): void; } declare namespace CachedInputFileSystem { - export { FileSystem, PathLike, PathOrFileDescriptor, SyncFileSystem, BaseFileSystem, FileSystemCallback, EXPECTED_FUNCTION, EXPECTED_ANY, Provide }; + export { + FileSystem, + PathLike, + PathOrFileDescriptor, + SyncFileSystem, + BaseFileSystem, + FileSystemCallback, + EXPECTED_FUNCTION, + EXPECTED_ANY, + Provide, + }; } declare class OperationMergerBackend { - /** - * @param {EXPECTED_FUNCTION | undefined} provider async method in filesystem - * @param {EXPECTED_FUNCTION | undefined} syncProvider sync method in filesystem - * @param {BaseFileSystem} providerContext call context for the provider methods - */ - constructor(provider: EXPECTED_FUNCTION | undefined, syncProvider: EXPECTED_FUNCTION | undefined, providerContext: BaseFileSystem); - _provider: Function | undefined; - _syncProvider: Function | undefined; - _providerContext: BaseFileSystem; - _activeAsyncOperations: Map; - provide: ((path: PathLike | PathOrFileDescriptor, options: object | FileSystemCallback | undefined, callback?: FileSystemCallback | undefined) => EXPECTED_ANY) | null; - provideSync: ((path: PathLike | PathOrFileDescriptor, options?: object | undefined) => EXPECTED_ANY) | null; - purge(): void; - purgeParent(): void; + /** + * @param {EXPECTED_FUNCTION | undefined} provider async method in filesystem + * @param {EXPECTED_FUNCTION | undefined} syncProvider sync method in filesystem + * @param {BaseFileSystem} providerContext call context for the provider methods + */ + constructor( + provider: EXPECTED_FUNCTION | undefined, + syncProvider: EXPECTED_FUNCTION | undefined, + providerContext: BaseFileSystem, + ); + _provider: Function | undefined; + _syncProvider: Function | undefined; + _providerContext: BaseFileSystem; + _activeAsyncOperations: Map; + provide: + | (( + path: PathLike | PathOrFileDescriptor, + options: object | FileSystemCallback | undefined, + callback?: FileSystemCallback | undefined, + ) => EXPECTED_ANY) + | null; + provideSync: + | (( + path: PathLike | PathOrFileDescriptor, + options?: object | undefined, + ) => EXPECTED_ANY) + | null; + purge(): void; + purgeParent(): void; } /** * @callback Provide @@ -62,70 +101,110 @@ declare class OperationMergerBackend { * @returns {void} */ declare class CacheBackend { - /** - * @param {number} duration max cache duration of items - * @param {EXPECTED_FUNCTION | undefined} provider async method - * @param {EXPECTED_FUNCTION | undefined} syncProvider sync method - * @param {BaseFileSystem} providerContext call context for the provider methods - */ - constructor(duration: number, provider: EXPECTED_FUNCTION | undefined, syncProvider: EXPECTED_FUNCTION | undefined, providerContext: BaseFileSystem); - _duration: number; - _provider: Function | undefined; - _syncProvider: Function | undefined; - _providerContext: BaseFileSystem; - /** @type {Map[]>} */ - _activeAsyncOperations: Map[]>; - /** @type {Map }>} */ - _data: Map; - }>; - /** @type {Set[]} */ - _levels: Set[]; - _currentLevel: number; - _tickInterval: number; - /** @type {STORAGE_MODE_IDLE | STORAGE_MODE_SYNC | STORAGE_MODE_ASYNC} */ - _mode: 0 | 1 | 2; - /** @type {NodeJS.Timeout | undefined} */ - _timeout: NodeJS.Timeout | undefined; - /** @type {number | undefined} */ - _nextDecay: number | undefined; - /** - * @param {PathLike | PathOrFileDescriptor} path path - * @param {EXPECTED_ANY} options options - * @param {FileSystemCallback} callback callback - * @returns {void} - */ - provide(path: PathLike | PathOrFileDescriptor, options: EXPECTED_ANY, callback: FileSystemCallback): void; - /** - * @param {PathLike | PathOrFileDescriptor} path path - * @param {EXPECTED_ANY} options options - * @returns {EXPECTED_ANY} result - */ - provideSync(path: PathLike | PathOrFileDescriptor, options: EXPECTED_ANY): EXPECTED_ANY; - /** - * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge - * @param {{ exact?: boolean }=} options options; `exact: true` removes only entries whose key matches `what` exactly instead of any entry whose key starts with `what` - */ - purge(what?: (string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set) | undefined, options?: { - exact?: boolean; - } | undefined): void; - /** - * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge - */ - purgeParent(what?: (string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set) | undefined): void; - /** - * @param {string} path path - * @param {Error | null} err error - * @param {EXPECTED_ANY} result result - */ - _storeResult(path: string, err: Error | null, result: EXPECTED_ANY): void; - _decayLevel(): void; - _runDecays(): void; - _enterAsyncMode(): void; - _enterSyncModeWhenIdle(): void; - _enterIdleMode(): void; + /** + * @param {number} duration max cache duration of items + * @param {EXPECTED_FUNCTION | undefined} provider async method + * @param {EXPECTED_FUNCTION | undefined} syncProvider sync method + * @param {BaseFileSystem} providerContext call context for the provider methods + */ + constructor( + duration: number, + provider: EXPECTED_FUNCTION | undefined, + syncProvider: EXPECTED_FUNCTION | undefined, + providerContext: BaseFileSystem, + ); + _duration: number; + _provider: Function | undefined; + _syncProvider: Function | undefined; + _providerContext: BaseFileSystem; + /** @type {Map[]>} */ + _activeAsyncOperations: Map[]>; + /** @type {Map }>} */ + _data: Map< + string, + { + err: Error | null; + result?: EXPECTED_ANY; + level: Set; + } + >; + /** @type {Set[]} */ + _levels: Set[]; + _currentLevel: number; + _tickInterval: number; + /** @type {STORAGE_MODE_IDLE | STORAGE_MODE_SYNC | STORAGE_MODE_ASYNC} */ + _mode: 0 | 1 | 2; + /** @type {NodeJS.Timeout | undefined} */ + _timeout: NodeJS.Timeout | undefined; + /** @type {number | undefined} */ + _nextDecay: number | undefined; + /** + * @param {PathLike | PathOrFileDescriptor} path path + * @param {EXPECTED_ANY} options options + * @param {FileSystemCallback} callback callback + * @returns {void} + */ + provide( + path: PathLike | PathOrFileDescriptor, + options: EXPECTED_ANY, + callback: FileSystemCallback, + ): void; + /** + * @param {PathLike | PathOrFileDescriptor} path path + * @param {EXPECTED_ANY} options options + * @returns {EXPECTED_ANY} result + */ + provideSync( + path: PathLike | PathOrFileDescriptor, + options: EXPECTED_ANY, + ): EXPECTED_ANY; + /** + * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge + * @param {{ exact?: boolean }=} options options; `exact: true` removes only entries whose key matches `what` exactly instead of any entry whose key starts with `what` + */ + purge( + what?: + | ( + | string + | Buffer + | URL + | number + | (string | URL | Buffer | number)[] + | Set + ) + | undefined, + options?: + | { + exact?: boolean; + } + | undefined, + ): void; + /** + * @param {(string | Buffer | URL | number | (string | URL | Buffer | number)[] | Set)=} what what to purge + */ + purgeParent( + what?: + | ( + | string + | Buffer + | URL + | number + | (string | URL | Buffer | number)[] + | Set + ) + | undefined, + ): void; + /** + * @param {string} path path + * @param {Error | null} err error + * @param {EXPECTED_ANY} result result + */ + _storeResult(path: string, err: Error | null, result: EXPECTED_ANY): void; + _decayLevel(): void; + _runDecays(): void; + _enterAsyncMode(): void; + _enterSyncModeWhenIdle(): void; + _enterIdleMode(): void; } type FileSystem = import("./Resolver").FileSystem; type PathLike = import("./Resolver").PathLike; @@ -138,4 +217,8 @@ type BaseFileSystem = FileSystem & SyncFileSystem; type FileSystemCallback = import("./Resolver").FileSystemCallback; type EXPECTED_FUNCTION = Function; type EXPECTED_ANY = any; -type Provide = (path: PathLike | PathOrFileDescriptor, options: EXPECTED_ANY, callback: FileSystemCallback) => void; +type Provide = ( + path: PathLike | PathOrFileDescriptor, + options: EXPECTED_ANY, + callback: FileSystemCallback, +) => void; diff --git a/types/CloneBasenamePlugin.d.ts b/types/CloneBasenamePlugin.d.ts index 75801a04..a0b852d9 100644 --- a/types/CloneBasenamePlugin.d.ts +++ b/types/CloneBasenamePlugin.d.ts @@ -1,20 +1,23 @@ export = CloneBasenamePlugin; declare class CloneBasenamePlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace CloneBasenamePlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/ConditionalPlugin.d.ts b/types/ConditionalPlugin.d.ts index aeee7b47..a3c70e10 100644 --- a/types/ConditionalPlugin.d.ts +++ b/types/ConditionalPlugin.d.ts @@ -1,26 +1,32 @@ export = ConditionalPlugin; declare class ConditionalPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {Partial} test compare object - * @param {string | null} message log message - * @param {boolean} allowAlternatives when false, do not continue with the current step when "test" matches - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, test: Partial, message: string | null, allowAlternatives: boolean, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - test: Partial; - message: string | null; - allowAlternatives: boolean; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {Partial} test compare object + * @param {string | null} message log message + * @param {boolean} allowAlternatives when false, do not continue with the current step when "test" matches + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + test: Partial, + message: string | null, + allowAlternatives: boolean, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + test: Partial; + message: string | null; + allowAlternatives: boolean; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace ConditionalPlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/DescriptionFilePlugin.d.ts b/types/DescriptionFilePlugin.d.ts index 0d784323..c063cd7e 100644 --- a/types/DescriptionFilePlugin.d.ts +++ b/types/DescriptionFilePlugin.d.ts @@ -1,24 +1,29 @@ export = DescriptionFilePlugin; declare class DescriptionFilePlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string[]} filenames filenames - * @param {boolean} pathIsFile pathIsFile - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, filenames: string[], pathIsFile: boolean, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - filenames: string[]; - pathIsFile: boolean; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string[]} filenames filenames + * @param {boolean} pathIsFile pathIsFile + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + filenames: string[], + pathIsFile: boolean, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + filenames: string[]; + pathIsFile: boolean; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace DescriptionFilePlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/DescriptionFileUtils.d.ts b/types/DescriptionFileUtils.d.ts index 1732e2d7..29385645 100644 --- a/types/DescriptionFileUtils.d.ts +++ b/types/DescriptionFileUtils.d.ts @@ -4,33 +4,36 @@ export type JsonValue = import("./Resolver").JsonValue; export type ResolveContext = import("./Resolver").ResolveContext; export type ResolveRequest = import("./Resolver").ResolveRequest; export type DescriptionFileInfo = { - /** - * content - */ - content?: JsonObject | undefined; - /** - * path - */ - path: string; - /** - * directory - */ - directory: string; + /** + * content + */ + content?: JsonObject | undefined; + /** + * path + */ + path: string; + /** + * directory + */ + directory: string; }; -export type ErrorFirstCallback = (error?: (Error | null) | undefined, result?: DescriptionFileInfo | undefined) => any; +export type ErrorFirstCallback = ( + error?: (Error | null) | undefined, + result?: DescriptionFileInfo | undefined, +) => any; export type Result = { - /** - * path to description file - */ - path: string; - /** - * directory of description file - */ - directory: string; - /** - * content of description file - */ - content: JsonObject; + /** + * path to description file + */ + path: string; + /** + * directory of description file + */ + directory: string; + /** + * content of description file + */ + content: JsonObject; }; /** * Walk up one directory. Called once per package-root candidate and once per @@ -58,7 +61,10 @@ export function cdUp(directory: string): string | null; * @param {string | string[]} field field * @returns {JsonValue | undefined} field data */ -export function getField(content: JsonObject, field: string | string[]): JsonValue | undefined; +export function getField( + content: JsonObject, + field: string | string[], +): JsonValue | undefined; /** * @param {Resolver} resolver resolver * @param {string} directory directory @@ -67,4 +73,11 @@ export function getField(content: JsonObject, field: string | string[]): JsonVal * @param {ResolveContext} resolveContext resolveContext * @param {ErrorFirstCallback} callback callback */ -export function loadDescriptionFile(resolver: Resolver, directory: string, filenames: string[], oldInfo: DescriptionFileInfo | undefined, resolveContext: ResolveContext, callback: ErrorFirstCallback): void; +export function loadDescriptionFile( + resolver: Resolver, + directory: string, + filenames: string[], + oldInfo: DescriptionFileInfo | undefined, + resolveContext: ResolveContext, + callback: ErrorFirstCallback, +): void; diff --git a/types/DirectoryExistsPlugin.d.ts b/types/DirectoryExistsPlugin.d.ts index 929ff5fa..025b53ef 100644 --- a/types/DirectoryExistsPlugin.d.ts +++ b/types/DirectoryExistsPlugin.d.ts @@ -1,20 +1,23 @@ export = DirectoryExistsPlugin; declare class DirectoryExistsPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace DirectoryExistsPlugin { - export { Resolver, ResolveStepHook }; + export { Resolver, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/ExportsFieldPlugin.d.ts b/types/ExportsFieldPlugin.d.ts index 70270f46..84b5375d 100644 --- a/types/ExportsFieldPlugin.d.ts +++ b/types/ExportsFieldPlugin.d.ts @@ -1,28 +1,41 @@ export = ExportsFieldPlugin; declare class ExportsFieldPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {Set} conditionNames condition names - * @param {string | string[]} fieldNamePath name path - * @param {string | ResolveStepHook} target target - * @param {boolean=} restrictions whether `restrictions` are configured (enables exports-target fallback when a target is filtered out) - */ - constructor(source: string | ResolveStepHook, conditionNames: Set, fieldNamePath: string | string[], target: string | ResolveStepHook, restrictions?: boolean | undefined); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - conditionNames: Set; - fieldName: string | string[]; - restrictions: boolean; - /** @type {WeakMap} */ - _fieldProcessorCache: WeakMap; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {Set} conditionNames condition names + * @param {string | string[]} fieldNamePath name path + * @param {string | ResolveStepHook} target target + * @param {boolean=} restrictions whether `restrictions` are configured (enables exports-target fallback when a target is filtered out) + */ + constructor( + source: string | ResolveStepHook, + conditionNames: Set, + fieldNamePath: string | string[], + target: string | ResolveStepHook, + restrictions?: boolean | undefined, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + conditionNames: Set; + fieldName: string | string[]; + restrictions: boolean; + /** @type {WeakMap} */ + _fieldProcessorCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace ExportsFieldPlugin { - export { Resolver, JsonObject, ResolveRequest, ResolveStepHook, ExportsField, FieldProcessor }; + export { + Resolver, + JsonObject, + ResolveRequest, + ResolveStepHook, + ExportsField, + FieldProcessor, + }; } type Resolver = import("./Resolver"); type JsonObject = import("./Resolver").JsonObject; diff --git a/types/ExtensionAliasPlugin.d.ts b/types/ExtensionAliasPlugin.d.ts index 268a843d..39b35495 100644 --- a/types/ExtensionAliasPlugin.d.ts +++ b/types/ExtensionAliasPlugin.d.ts @@ -1,27 +1,31 @@ export = ExtensionAliasPlugin; declare class ExtensionAliasPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {ExtensionAliasOption} options options - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, options: ExtensionAliasOption, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - options: ExtensionAliasOption; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {ExtensionAliasOption} options options + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + options: ExtensionAliasOption, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + options: ExtensionAliasOption; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace ExtensionAliasPlugin { - export { Resolver, ResolveRequest, ResolveStepHook, ExtensionAliasOption }; + export { Resolver, ResolveRequest, ResolveStepHook, ExtensionAliasOption }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; type ResolveStepHook = import("./Resolver").ResolveStepHook; type ExtensionAliasOption = { - alias: string | string[]; - extension: string; + alias: string | string[]; + extension: string; }; diff --git a/types/FileExistsPlugin.d.ts b/types/FileExistsPlugin.d.ts index 909bd504..d4f7aeea 100644 --- a/types/FileExistsPlugin.d.ts +++ b/types/FileExistsPlugin.d.ts @@ -1,20 +1,23 @@ export = FileExistsPlugin; declare class FileExistsPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace FileExistsPlugin { - export { Resolver, ResolveStepHook }; + export { Resolver, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/ImportsFieldPlugin.d.ts b/types/ImportsFieldPlugin.d.ts index b6743f4b..197d04b2 100644 --- a/types/ImportsFieldPlugin.d.ts +++ b/types/ImportsFieldPlugin.d.ts @@ -1,28 +1,41 @@ export = ImportsFieldPlugin; declare class ImportsFieldPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {Set} conditionNames condition names - * @param {string | string[]} fieldNamePath name path - * @param {string | ResolveStepHook} targetFile target file - * @param {string | ResolveStepHook} targetPackage target package - */ - constructor(source: string | ResolveStepHook, conditionNames: Set, fieldNamePath: string | string[], targetFile: string | ResolveStepHook, targetPackage: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - targetFile: string | import("./Resolver").ResolveStepHook; - targetPackage: string | import("./Resolver").ResolveStepHook; - conditionNames: Set; - fieldName: string | string[]; - /** @type {WeakMap} */ - _fieldProcessorCache: WeakMap; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {Set} conditionNames condition names + * @param {string | string[]} fieldNamePath name path + * @param {string | ResolveStepHook} targetFile target file + * @param {string | ResolveStepHook} targetPackage target package + */ + constructor( + source: string | ResolveStepHook, + conditionNames: Set, + fieldNamePath: string | string[], + targetFile: string | ResolveStepHook, + targetPackage: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + targetFile: string | import("./Resolver").ResolveStepHook; + targetPackage: string | import("./Resolver").ResolveStepHook; + conditionNames: Set; + fieldName: string | string[]; + /** @type {WeakMap} */ + _fieldProcessorCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace ImportsFieldPlugin { - export { Resolver, JsonObject, ResolveRequest, ResolveStepHook, FieldProcessor, ImportsField }; + export { + Resolver, + JsonObject, + ResolveRequest, + ResolveStepHook, + FieldProcessor, + ImportsField, + }; } type Resolver = import("./Resolver"); type JsonObject = import("./Resolver").JsonObject; diff --git a/types/JoinRequestPartPlugin.d.ts b/types/JoinRequestPartPlugin.d.ts index f4dc883e..27834033 100644 --- a/types/JoinRequestPartPlugin.d.ts +++ b/types/JoinRequestPartPlugin.d.ts @@ -1,20 +1,23 @@ export = JoinRequestPartPlugin; declare class JoinRequestPartPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace JoinRequestPartPlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/JoinRequestPlugin.d.ts b/types/JoinRequestPlugin.d.ts index f583e8ef..b9fe5269 100644 --- a/types/JoinRequestPlugin.d.ts +++ b/types/JoinRequestPlugin.d.ts @@ -1,20 +1,23 @@ export = JoinRequestPlugin; declare class JoinRequestPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace JoinRequestPlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/LogInfoPlugin.d.ts b/types/LogInfoPlugin.d.ts index 67e5623b..9fe3d72a 100644 --- a/types/LogInfoPlugin.d.ts +++ b/types/LogInfoPlugin.d.ts @@ -1,18 +1,18 @@ export = LogInfoPlugin; declare class LogInfoPlugin { - /** - * @param {string | ResolveStepHook} source source - */ - constructor(source: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + */ + constructor(source: string | ResolveStepHook); + source: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace LogInfoPlugin { - export { Resolver, ResolveStepHook }; + export { Resolver, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/MainFieldPlugin.d.ts b/types/MainFieldPlugin.d.ts index c65a1787..1b311263 100644 --- a/types/MainFieldPlugin.d.ts +++ b/types/MainFieldPlugin.d.ts @@ -1,24 +1,34 @@ export = MainFieldPlugin; declare class MainFieldPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {MainFieldOptions} options options - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, options: MainFieldOptions, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - options: MainFieldOptions; - target: string | import("./Resolver").ResolveStepHook; - /** @type {WeakMap} */ - _mainModuleCache: WeakMap; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {MainFieldOptions} options options + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + options: MainFieldOptions, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + options: MainFieldOptions; + target: string | import("./Resolver").ResolveStepHook; + /** @type {WeakMap} */ + _mainModuleCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace MainFieldPlugin { - export { Resolver, JsonObject, ResolveRequest, ResolveStepHook, MainFieldOptions }; + export { + Resolver, + JsonObject, + ResolveRequest, + ResolveStepHook, + MainFieldOptions, + }; } declare const NO_MAIN: unique symbol; type Resolver = import("./Resolver"); @@ -26,6 +36,6 @@ type JsonObject = import("./Resolver").JsonObject; type ResolveRequest = import("./Resolver").ResolveRequest; type ResolveStepHook = import("./Resolver").ResolveStepHook; type MainFieldOptions = { - name: string | string[]; - forceRelative: boolean; + name: string | string[]; + forceRelative: boolean; }; diff --git a/types/ModulesInHierarchicalDirectoriesPlugin.d.ts b/types/ModulesInHierarchicalDirectoriesPlugin.d.ts index 83fb453e..af501cee 100644 --- a/types/ModulesInHierarchicalDirectoriesPlugin.d.ts +++ b/types/ModulesInHierarchicalDirectoriesPlugin.d.ts @@ -1,22 +1,26 @@ export = ModulesInHierarchicalDirectoriesPlugin; declare class ModulesInHierarchicalDirectoriesPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | string[]} directories directories - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, directories: string | string[], target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - directories: string[]; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | string[]} directories directories + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + directories: string | string[], + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + directories: string[]; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace ModulesInHierarchicalDirectoriesPlugin { - export { Resolver, ResolveStepHook }; + export { Resolver, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/ModulesInRootPlugin.d.ts b/types/ModulesInRootPlugin.d.ts index f78d7228..87a61fd3 100644 --- a/types/ModulesInRootPlugin.d.ts +++ b/types/ModulesInRootPlugin.d.ts @@ -1,22 +1,26 @@ export = ModulesInRootPlugin; declare class ModulesInRootPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string} path path - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, path: string, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - path: string; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string} path path + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + path: string, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + path: string; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace ModulesInRootPlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/ModulesUtils.d.ts b/types/ModulesUtils.d.ts index ac7d10d4..9a55bf73 100644 --- a/types/ModulesUtils.d.ts +++ b/types/ModulesUtils.d.ts @@ -2,7 +2,10 @@ export type Resolver = import("./Resolver"); export type ResolveRequest = import("./Resolver").ResolveRequest; export type ResolveStepHook = import("./Resolver").ResolveStepHook; export type ResolveContext = import("./Resolver").ResolveContext; -export type InnerCallback = (err?: null | Error, result?: null | ResolveRequest) => void; +export type InnerCallback = ( + err?: null | Error, + result?: null | ResolveRequest, +) => void; /** * @param {Resolver} resolver resolver * @param {string[]} directories directories @@ -12,4 +15,11 @@ export type InnerCallback = (err?: null | Error, result?: null | ResolveRequest) * @param {InnerCallback} callback callback * @returns {void} */ -export function modulesResolveHandler(resolver: Resolver, directories: string[], target: ResolveStepHook, request: ResolveRequest, resolveContext: ResolveContext, callback: InnerCallback): void; +export function modulesResolveHandler( + resolver: Resolver, + directories: string[], + target: ResolveStepHook, + request: ResolveRequest, + resolveContext: ResolveContext, + callback: InnerCallback, +): void; diff --git a/types/NextPlugin.d.ts b/types/NextPlugin.d.ts index 32e10c74..6a93aacc 100644 --- a/types/NextPlugin.d.ts +++ b/types/NextPlugin.d.ts @@ -1,20 +1,23 @@ export = NextPlugin; declare class NextPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace NextPlugin { - export { Resolver, ResolveStepHook }; + export { Resolver, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/PackageMapPlugin.d.ts b/types/PackageMapPlugin.d.ts index 23392183..5d7a7a23 100644 --- a/types/PackageMapPlugin.d.ts +++ b/types/PackageMapPlugin.d.ts @@ -1,49 +1,70 @@ export = PackageMapPlugin; declare class PackageMapPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {PackageMapOptions} options package map options - * @param {boolean} symlinks whether the resolver resolves symlinks - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, options: PackageMapOptions, symlinks: boolean, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - options: PackageMapOptions; - symlinks: boolean; - target: string | import("./Resolver").ResolveStepHook; - /** @type {PackageMap | undefined} */ - _packageMap: PackageMap | undefined; - /** @type {PackageMapCallback[] | undefined} */ - _pending: PackageMapCallback[] | undefined; - /** - * Read and parse the configuration file once, queueing every request that - * arrives while the read is in flight so a cold start does not re-read the - * same file for each of them. - * @param {Resolver} resolver the resolver - * @param {ResolveContext} resolveContext resolve context - * @param {PackageMapCallback} callback callback - * @returns {void} - */ - _getPackageMap(resolver: Resolver, resolveContext: ResolveContext, callback: PackageMapCallback): void; - /** - * Hand back the configuration file path package locations resolve against: - * its real path when the resolver follows symlinks, and the path as given - * otherwise. A configuration file whose real path cannot be read (it may not - * exist, or the file system may not implement it) is used as-is, so the - * read below reports the problem. - * @param {Resolver} resolver the resolver - * @param {(configFile: string) => void} callback callback - * @returns {void} - */ - _resolveConfigFile(resolver: Resolver, callback: (configFile: string) => void): void; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {PackageMapOptions} options package map options + * @param {boolean} symlinks whether the resolver resolves symlinks + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + options: PackageMapOptions, + symlinks: boolean, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + options: PackageMapOptions; + symlinks: boolean; + target: string | import("./Resolver").ResolveStepHook; + /** @type {PackageMap | undefined} */ + _packageMap: PackageMap | undefined; + /** @type {PackageMapCallback[] | undefined} */ + _pending: PackageMapCallback[] | undefined; + /** + * Read and parse the configuration file once, queueing every request that + * arrives while the read is in flight so a cold start does not re-read the + * same file for each of them. + * @param {Resolver} resolver the resolver + * @param {ResolveContext} resolveContext resolve context + * @param {PackageMapCallback} callback callback + * @returns {void} + */ + _getPackageMap( + resolver: Resolver, + resolveContext: ResolveContext, + callback: PackageMapCallback, + ): void; + /** + * Hand back the configuration file path package locations resolve against: + * its real path when the resolver follows symlinks, and the path as given + * otherwise. A configuration file whose real path cannot be read (it may not + * exist, or the file system may not implement it) is used as-is, so the + * read below reports the problem. + * @param {Resolver} resolver the resolver + * @param {(configFile: string) => void} callback callback + * @returns {void} + */ + _resolveConfigFile( + resolver: Resolver, + callback: (configFile: string) => void, + ): void; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace PackageMapPlugin { - export { Resolver, ResolveContext, ResolveRequest, ResolveStepHook, PackageMap, PackageMapPackages, PackageMapOptions, PackageMapCallback }; + export { + Resolver, + ResolveContext, + ResolveRequest, + ResolveStepHook, + PackageMap, + PackageMapPackages, + PackageMapOptions, + PackageMapCallback, + }; } type Resolver = import("./Resolver"); type ResolveContext = import("./Resolver").ResolveContext; @@ -52,13 +73,13 @@ type ResolveStepHook = import("./Resolver").ResolveStepHook; type PackageMap = import("./util/packageMap").PackageMap; type PackageMapPackages = import("./util/packageMap").PackageMapPackages; type PackageMapOptions = { - /** - * absolute path of the configuration file, read lazily when `packages` is not given - */ - configFile: string | null; - /** - * an already-parsed `packages` object, used instead of reading `configFile` - */ - packages: PackageMapPackages | null; + /** + * absolute path of the configuration file, read lazily when `packages` is not given + */ + configFile: string | null; + /** + * an already-parsed `packages` object, used instead of reading `configFile` + */ + packages: PackageMapPackages | null; }; type PackageMapCallback = (err: Error | null, packageMap?: PackageMap) => void; diff --git a/types/ParsePlugin.d.ts b/types/ParsePlugin.d.ts index 28b58a5a..39975049 100644 --- a/types/ParsePlugin.d.ts +++ b/types/ParsePlugin.d.ts @@ -1,22 +1,26 @@ export = ParsePlugin; declare class ParsePlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {Partial} requestOptions request options - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, requestOptions: Partial, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - requestOptions: Partial; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {Partial} requestOptions request options + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + requestOptions: Partial, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + requestOptions: Partial; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace ParsePlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/PnpPlugin.d.ts b/types/PnpPlugin.d.ts index e9c97707..18e1109c 100644 --- a/types/PnpPlugin.d.ts +++ b/types/PnpPlugin.d.ts @@ -1,33 +1,42 @@ export = PnpPlugin; declare class PnpPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {PnpApiImpl} pnpApi pnpApi - * @param {string | ResolveStepHook} target target - * @param {string | ResolveStepHook} alternateTarget alternateTarget - */ - constructor(source: string | ResolveStepHook, pnpApi: PnpApiImpl, target: string | ResolveStepHook, alternateTarget: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - pnpApi: PnpApiImpl; - target: string | import("./Resolver").ResolveStepHook; - alternateTarget: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {PnpApiImpl} pnpApi pnpApi + * @param {string | ResolveStepHook} target target + * @param {string | ResolveStepHook} alternateTarget alternateTarget + */ + constructor( + source: string | ResolveStepHook, + pnpApi: PnpApiImpl, + target: string | ResolveStepHook, + alternateTarget: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + pnpApi: PnpApiImpl; + target: string | import("./Resolver").ResolveStepHook; + alternateTarget: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace PnpPlugin { - export { Resolver, ResolveStepHook, ResolveRequest, PnpApiImpl }; + export { Resolver, ResolveStepHook, ResolveRequest, PnpApiImpl }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; type ResolveRequest = import("./Resolver").ResolveRequest; type PnpApiImpl = { - /** - * resolve to unqualified - */ - resolveToUnqualified: (packageName: string, issuer: string, options: { - considerBuiltins: boolean; - }) => string | null; + /** + * resolve to unqualified + */ + resolveToUnqualified: ( + packageName: string, + issuer: string, + options: { + considerBuiltins: boolean; + }, + ) => string | null; }; diff --git a/types/Resolver.d.ts b/types/Resolver.d.ts index 81704c08..6b88cd8c 100644 --- a/types/Resolver.d.ts +++ b/types/Resolver.d.ts @@ -1,160 +1,274 @@ export = Resolver; declare class Resolver { - /** - * @param {ResolveStepHook} hook hook - * @param {ResolveRequest} request request - * @param {StackEntry=} parent previous tip of the stack - * @param {Set=} preSeeded entries pre-seeded via the legacy `Set` API - * @returns {StackEntry} stack entry - */ - static createStackEntry(hook: ResolveStepHook, request: ResolveRequest, parent?: StackEntry | undefined, preSeeded?: Set | undefined): StackEntry; - /** - * @param {FileSystem} fileSystem a filesystem - * @param {ResolveOptions} options options - */ - constructor(fileSystem: FileSystem, options: ResolveOptions); - /** @type {FileSystem} */ - fileSystem: FileSystem; - /** @type {ResolveOptions} */ - options: ResolveOptions; - /** @type {PathCacheFunctions} */ - pathCache: PathCacheFunctions; - /** @type {KnownHooks} */ - hooks: KnownHooks; - /** - * @param {string | ResolveStepHook} name hook name or hook itself - * @returns {ResolveStepHook} the hook - */ - ensureHook(name: string | ResolveStepHook): ResolveStepHook; - /** - * @param {string | ResolveStepHook} name hook name or hook itself - * @returns {ResolveStepHook} the hook - */ - getHook(name: string | ResolveStepHook): ResolveStepHook; - /** - * @overload - * @param {string | URL} parent context path or a `file:` URL - * @param {string | URL} specifier request string or a `file:` URL - * @param {ResolveContext=} resolveContext resolve context - * @returns {string | false} result - */ - resolveSync(parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext | undefined): string | false; - /** - * @overload - * @param {Context} context context information object - * @param {string | URL} parent context path or a `file:` URL - * @param {string | URL} specifier request string or a `file:` URL - * @param {ResolveContext=} resolveContext resolve context - * @returns {string | false} result - */ - resolveSync(context: Context, parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext | undefined): string | false; - /** - * @overload - * @param {string | URL} parent context path or a `file:` URL - * @param {string | URL} specifier request string or a `file:` URL - * @param {ResolveContext=} resolveContext resolve context - * @returns {Promise} result - */ - resolvePromise(parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext | undefined): Promise; - /** - * @overload - * @param {Context} context context information object - * @param {string | URL} parent context path or a `file:` URL - * @param {string | URL} specifier request string or a `file:` URL - * @param {ResolveContext=} resolveContext resolve context - * @returns {Promise} result - */ - resolvePromise(context: Context, parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext | undefined): Promise; - /** - * @overload - * @param {string | URL} parent context path or a `file:` URL - * @param {string | URL} specifier request string or a `file:` URL - * @param {ResolveCallback} callback callback function - * @returns {void} - */ - resolve(parent: string | URL, specifier: string | URL, callback: ResolveCallback): void; - /** - * @overload - * @param {string | URL} parent context path or a `file:` URL - * @param {string | URL} specifier request string or a `file:` URL - * @param {ResolveContext} resolveContext resolve context - * @param {ResolveCallback} callback callback function - * @returns {void} - */ - resolve(parent: string | URL, specifier: string | URL, resolveContext: ResolveContext, callback: ResolveCallback): void; - /** - * @overload - * @param {Context} context context information object - * @param {string | URL} parent context path or a `file:` URL - * @param {string | URL} specifier request string or a `file:` URL - * @param {ResolveCallback} callback callback function - * @returns {void} - */ - resolve(context: Context, parent: string | URL, specifier: string | URL, callback: ResolveCallback): void; - /** - * @overload - * @param {Context} context context information object - * @param {string | URL} parent context path or a `file:` URL - * @param {string | URL} specifier request string or a `file:` URL - * @param {ResolveContext} resolveContext resolve context - * @param {ResolveCallback} callback callback function - * @returns {void} - */ - resolve(context: Context, parent: string | URL, specifier: string | URL, resolveContext: ResolveContext, callback: ResolveCallback): void; - /** - * @param {ResolveStepHook} hook hook - * @param {ResolveRequest} request request - * @param {null | string} message string - * @param {ResolveContext} resolveContext resolver context - * @param {(err?: null | Error, result?: ResolveRequest) => void} callback callback - * @returns {void} - */ - doResolve(hook: ResolveStepHook, request: ResolveRequest, message: null | string, resolveContext: ResolveContext, callback: (err?: null | Error, result?: ResolveRequest) => void): void; - /** - * @param {string} identifier identifier - * @returns {ParsedIdentifier} parsed identifier - */ - parse(identifier: string): ParsedIdentifier; - /** - * @param {string} path path - * @returns {boolean} true, if the path is a module - */ - isModule(path: string): boolean; - /** - * @param {string} path path - * @returns {boolean} true, if the path is private - */ - isPrivate(path: string): boolean; - /** - * @param {string} path a path - * @returns {boolean} true, if the path is a directory path - */ - isDirectory(path: string): boolean; - /** - * @param {string} path path - * @returns {string} normalized path - */ - normalize(path: string): string; - /** - * @param {string} path path - * @param {string} request request - * @returns {string} joined path - */ - join(path: string, request: string): string; - /** - * @param {string} path path - * @returns {string} parent directory - */ - dirname(path: string): string; - /** - * @param {string} path the path to evaluate - * @param {string=} suffix an extension to remove from the result - * @returns {string} the last portion of a path - */ - basename(path: string, suffix?: string | undefined): string; + /** + * @param {ResolveStepHook} hook hook + * @param {ResolveRequest} request request + * @param {StackEntry=} parent previous tip of the stack + * @param {Set=} preSeeded entries pre-seeded via the legacy `Set` API + * @returns {StackEntry} stack entry + */ + static createStackEntry( + hook: ResolveStepHook, + request: ResolveRequest, + parent?: StackEntry | undefined, + preSeeded?: Set | undefined, + ): StackEntry; + /** + * @param {FileSystem} fileSystem a filesystem + * @param {ResolveOptions} options options + */ + constructor(fileSystem: FileSystem, options: ResolveOptions); + /** @type {FileSystem} */ + fileSystem: FileSystem; + /** @type {ResolveOptions} */ + options: ResolveOptions; + /** @type {PathCacheFunctions} */ + pathCache: PathCacheFunctions; + /** @type {KnownHooks} */ + hooks: KnownHooks; + /** + * @param {string | ResolveStepHook} name hook name or hook itself + * @returns {ResolveStepHook} the hook + */ + ensureHook(name: string | ResolveStepHook): ResolveStepHook; + /** + * @param {string | ResolveStepHook} name hook name or hook itself + * @returns {ResolveStepHook} the hook + */ + getHook(name: string | ResolveStepHook): ResolveStepHook; + /** + * @overload + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext=} resolveContext resolve context + * @returns {string | false} result + */ + resolveSync( + parent: string | URL, + specifier: string | URL, + resolveContext?: ResolveContext | undefined, + ): string | false; + /** + * @overload + * @param {Context} context context information object + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext=} resolveContext resolve context + * @returns {string | false} result + */ + resolveSync( + context: Context, + parent: string | URL, + specifier: string | URL, + resolveContext?: ResolveContext | undefined, + ): string | false; + /** + * @overload + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext=} resolveContext resolve context + * @returns {Promise} result + */ + resolvePromise( + parent: string | URL, + specifier: string | URL, + resolveContext?: ResolveContext | undefined, + ): Promise; + /** + * @overload + * @param {Context} context context information object + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext=} resolveContext resolve context + * @returns {Promise} result + */ + resolvePromise( + context: Context, + parent: string | URL, + specifier: string | URL, + resolveContext?: ResolveContext | undefined, + ): Promise; + /** + * @overload + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveCallback} callback callback function + * @returns {void} + */ + resolve( + parent: string | URL, + specifier: string | URL, + callback: ResolveCallback, + ): void; + /** + * @overload + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext} resolveContext resolve context + * @param {ResolveCallback} callback callback function + * @returns {void} + */ + resolve( + parent: string | URL, + specifier: string | URL, + resolveContext: ResolveContext, + callback: ResolveCallback, + ): void; + /** + * @overload + * @param {Context} context context information object + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveCallback} callback callback function + * @returns {void} + */ + resolve( + context: Context, + parent: string | URL, + specifier: string | URL, + callback: ResolveCallback, + ): void; + /** + * @overload + * @param {Context} context context information object + * @param {string | URL} parent context path or a `file:` URL + * @param {string | URL} specifier request string or a `file:` URL + * @param {ResolveContext} resolveContext resolve context + * @param {ResolveCallback} callback callback function + * @returns {void} + */ + resolve( + context: Context, + parent: string | URL, + specifier: string | URL, + resolveContext: ResolveContext, + callback: ResolveCallback, + ): void; + /** + * @param {ResolveStepHook} hook hook + * @param {ResolveRequest} request request + * @param {null | string} message string + * @param {ResolveContext} resolveContext resolver context + * @param {(err?: null | Error, result?: ResolveRequest) => void} callback callback + * @returns {void} + */ + doResolve( + hook: ResolveStepHook, + request: ResolveRequest, + message: null | string, + resolveContext: ResolveContext, + callback: (err?: null | Error, result?: ResolveRequest) => void, + ): void; + /** + * @param {string} identifier identifier + * @returns {ParsedIdentifier} parsed identifier + */ + parse(identifier: string): ParsedIdentifier; + /** + * @param {string} path path + * @returns {boolean} true, if the path is a module + */ + isModule(path: string): boolean; + /** + * @param {string} path path + * @returns {boolean} true, if the path is private + */ + isPrivate(path: string): boolean; + /** + * @param {string} path a path + * @returns {boolean} true, if the path is a directory path + */ + isDirectory(path: string): boolean; + /** + * @param {string} path path + * @returns {string} normalized path + */ + normalize(path: string): string; + /** + * @param {string} path path + * @param {string} request request + * @returns {string} joined path + */ + join(path: string, request: string): string; + /** + * @param {string} path path + * @returns {string} parent directory + */ + dirname(path: string): string; + /** + * @param {string} path the path to evaluate + * @param {string=} suffix an extension to remove from the result + * @returns {string} the last portion of a path + */ + basename(path: string, suffix?: string | undefined): string; } declare namespace Resolver { - export { ResolveContext, ResolveStepHook, KnownHooks, EnsuredHooks, AliasOption, CachedJoin, CachedDirname, CachedBasename, JoinCacheEntry, DirnameCacheEntry, BasenameCacheEntry, PathCacheFunctions, ResolveOptions, KnownContext, Context, ErrorWithDetail, ResolveCallback, PossibleFileSystemError, FileSystemCallback, PathLike, PathOrFileDescriptor, ObjectEncodingOptions, EncodingOption, StringCallback, BufferCallback, StringOrBufferCallback, StatsCallback, BigIntStatsCallback, StatsOrBigIntStatsCallback, ReadJsonCallback, IStatsBase, IStats, IBigIntStats, Dirent, StatOptions, StatSyncOptions, ReadFile, BufferEncodingOption, ReadFileSync, Readdir, ReaddirSync, ReadJson, ReadJsonSync, Readlink, ReadlinkSync, LStat, LStatSync, Stat, StatSync, RealPath, RealPathSync, FileSystem, SyncFileSystem, ParsedIdentifier, JsonPrimitive, JsonArray, JsonValue, JsonObject, TsconfigPathsMap, TsconfigPathsData, BaseResolveRequest, ResolveRequest, WriteOnlySet, ResolveContextYield }; + export { + ResolveContext, + ResolveStepHook, + KnownHooks, + EnsuredHooks, + AliasOption, + CachedJoin, + CachedDirname, + CachedBasename, + JoinCacheEntry, + DirnameCacheEntry, + BasenameCacheEntry, + PathCacheFunctions, + ResolveOptions, + KnownContext, + Context, + ErrorWithDetail, + ResolveCallback, + PossibleFileSystemError, + FileSystemCallback, + PathLike, + PathOrFileDescriptor, + ObjectEncodingOptions, + EncodingOption, + StringCallback, + BufferCallback, + StringOrBufferCallback, + StatsCallback, + BigIntStatsCallback, + StatsOrBigIntStatsCallback, + ReadJsonCallback, + IStatsBase, + IStats, + IBigIntStats, + Dirent, + StatOptions, + StatSyncOptions, + ReadFile, + BufferEncodingOption, + ReadFileSync, + Readdir, + ReaddirSync, + ReadJson, + ReadJsonSync, + Readlink, + ReadlinkSync, + LStat, + LStatSync, + Stat, + StatSync, + RealPath, + RealPathSync, + FileSystem, + SyncFileSystem, + ParsedIdentifier, + JsonPrimitive, + JsonArray, + JsonValue, + JsonObject, + TsconfigPathsMap, + TsconfigPathsData, + BaseResolveRequest, + ResolveRequest, + WriteOnlySet, + ResolveContextYield, + }; } /** @typedef {import("./ResolverFactory").ResolveOptions} ResolveOptions */ /** @@ -447,760 +561,983 @@ declare namespace Resolver { * than cloning a `Set` per call. */ declare class StackEntry { - /** - * @param {ResolveStepHook} hook hook - * @param {ResolveRequest} request request - * @param {StackEntry=} parent previous tip - * @param {Set=} preSeeded entries pre-seeded via the legacy `Set` API - */ - constructor(hook: ResolveStepHook, request: ResolveRequest, parent?: StackEntry | undefined, preSeeded?: Set | undefined); - name: string | undefined; - path: string | false; - request: string; - query: string; - fragment: string; - directory: boolean; - module: boolean; - /** @type {StackEntry | undefined} */ - parent: StackEntry | undefined; - /** - * Strings seeded by callers that still pass `stack: new Set([...])`. - * Propagated through the chain so deeper `doResolve` calls still see - * them during recursion checks. `undefined` in the common case so - * there is no extra work on the hot path. - * @type {Set | undefined} - */ - preSeeded: Set | undefined; - /** - * Walk the linked list looking for an entry with the same request shape. - * Set-compatible: callers that used `stack.has(entry)` keep working. - * - * NOTE: kept monomorphic on purpose. An earlier draft accepted a string - * query too (so pre-5.21 plugins keeping their own `Set` of - * seen entries could probe the live stack with the formatted form), - * but adding the second shape regressed `doResolve`'s heap profile by - * ~1 MiB / 200 resolves on stack-churn — V8 keeps a polymorphic - * call-site state for `parent.has(stackEntry)` once `has` has two - * argument shapes. Plugins that need string membership can reach for - * `[...stack].find(e => e.includes(formattedString))` via the - * `String`-method proxies on `StackEntry` instead. - * @param {StackEntry} query entry to look for - * @returns {boolean} whether the stack already contains an equivalent entry - */ - has(query: StackEntry): boolean; - /** - * Number of entries on the stack (oldest-to-newest length). - * @returns {number} size - */ - get size(): number; - /** - * Human-readable form used in recursion error messages, logs, and the - * iterator above. Not memoized: caching would require an extra slot on - * every `StackEntry`, which costs heap even on resolves that never look - * at the formatted form. - * @returns {string} formatted entry - */ - toString(): string; - /** - * Iterate entries from oldest (root) to newest (tip), matching how a - * `Set` that was populated in insertion order would iterate. Pre-seeded - * legacy `Set` entries come first so error-message output stays - * ordered oldest-to-newest. - * - * Yields each entry as its formatted `toString()` form. Plugins written - * against the pre-5.21 `Set` shape — e.g. - * `[...resolveContext.stack].find(a => a.includes("module:"))` — keep - * working unchanged because each yielded value is a plain string with - * all of `String.prototype` available natively. Resolves that never - * iterate the stack pay nothing; iteration costs one `toString()` - * allocation per stack frame. - * @returns {IterableIterator} iterator - */ - [Symbol.iterator](): IterableIterator; + /** + * @param {ResolveStepHook} hook hook + * @param {ResolveRequest} request request + * @param {StackEntry=} parent previous tip + * @param {Set=} preSeeded entries pre-seeded via the legacy `Set` API + */ + constructor( + hook: ResolveStepHook, + request: ResolveRequest, + parent?: StackEntry | undefined, + preSeeded?: Set | undefined, + ); + name: string | undefined; + path: string | false; + request: string; + query: string; + fragment: string; + directory: boolean; + module: boolean; + /** @type {StackEntry | undefined} */ + parent: StackEntry | undefined; + /** + * Strings seeded by callers that still pass `stack: new Set([...])`. + * Propagated through the chain so deeper `doResolve` calls still see + * them during recursion checks. `undefined` in the common case so + * there is no extra work on the hot path. + * @type {Set | undefined} + */ + preSeeded: Set | undefined; + /** + * Walk the linked list looking for an entry with the same request shape. + * Set-compatible: callers that used `stack.has(entry)` keep working. + * + * NOTE: kept monomorphic on purpose. An earlier draft accepted a string + * query too (so pre-5.21 plugins keeping their own `Set` of + * seen entries could probe the live stack with the formatted form), + * but adding the second shape regressed `doResolve`'s heap profile by + * ~1 MiB / 200 resolves on stack-churn — V8 keeps a polymorphic + * call-site state for `parent.has(stackEntry)` once `has` has two + * argument shapes. Plugins that need string membership can reach for + * `[...stack].find(e => e.includes(formattedString))` via the + * `String`-method proxies on `StackEntry` instead. + * @param {StackEntry} query entry to look for + * @returns {boolean} whether the stack already contains an equivalent entry + */ + has(query: StackEntry): boolean; + /** + * Number of entries on the stack (oldest-to-newest length). + * @returns {number} size + */ + get size(): number; + /** + * Human-readable form used in recursion error messages, logs, and the + * iterator above. Not memoized: caching would require an extra slot on + * every `StackEntry`, which costs heap even on resolves that never look + * at the formatted form. + * @returns {string} formatted entry + */ + toString(): string; + /** + * Iterate entries from oldest (root) to newest (tip), matching how a + * `Set` that was populated in insertion order would iterate. Pre-seeded + * legacy `Set` entries come first so error-message output stays + * ordered oldest-to-newest. + * + * Yields each entry as its formatted `toString()` form. Plugins written + * against the pre-5.21 `Set` shape — e.g. + * `[...resolveContext.stack].find(a => a.includes("module:"))` — keep + * working unchanged because each yielded value is a plain string with + * all of `String.prototype` available natively. Resolves that never + * iterate the stack pay nothing; iteration costs one `toString()` + * allocation per stack frame. + * @returns {IterableIterator} iterator + */ + [Symbol.iterator](): IterableIterator; } /** * Resolve context */ type ResolveContext = { - /** - * directories that was found on file system - */ - contextDependencies?: WriteOnlySet | undefined; - /** - * files that was found on file system - */ - fileDependencies?: WriteOnlySet | undefined; - /** - * dependencies that was not found on file system - */ - missingDependencies?: WriteOnlySet | undefined; - /** - * tip of the resolver call stack (a singly-linked list with Set-like API). For instance, `resolve → parsedResolve → describedResolve`. Accepts a legacy `Set` for back-compat with older callers; it is normalized internally without a hot-path branch. - */ - stack?: (StackEntry | Set) | undefined; - /** - * log function - */ - log?: ((str: string) => void) | undefined; - /** - * yield result, if provided plugins can return several results - */ - yield?: ResolveContextYield | undefined; + /** + * directories that was found on file system + */ + contextDependencies?: WriteOnlySet | undefined; + /** + * files that was found on file system + */ + fileDependencies?: WriteOnlySet | undefined; + /** + * dependencies that was not found on file system + */ + missingDependencies?: WriteOnlySet | undefined; + /** + * tip of the resolver call stack (a singly-linked list with Set-like API). For instance, `resolve → parsedResolve → describedResolve`. Accepts a legacy `Set` for back-compat with older callers; it is normalized internally without a hot-path branch. + */ + stack?: (StackEntry | Set) | undefined; + /** + * log function + */ + log?: ((str: string) => void) | undefined; + /** + * yield result, if provided plugins can return several results + */ + yield?: ResolveContextYield | undefined; }; -type ResolveStepHook = AsyncSeriesBailHook<[ResolveRequest, ResolveContext], ResolveRequest | null>; +type ResolveStepHook = AsyncSeriesBailHook< + [ResolveRequest, ResolveContext], + ResolveRequest | null +>; type KnownHooks = { - /** - * resolve step hook - */ - resolveStep: SyncHook<[ResolveStepHook, ResolveRequest], void>; - /** - * no resolve hook - */ - noResolve: SyncHook<[ResolveRequest, Error]>; - /** - * resolve hook - */ - resolve: ResolveStepHook; - /** - * result hook - */ - result: AsyncSeriesHook<[ResolveRequest, ResolveContext]>; + /** + * resolve step hook + */ + resolveStep: SyncHook<[ResolveStepHook, ResolveRequest], void>; + /** + * no resolve hook + */ + noResolve: SyncHook<[ResolveRequest, Error]>; + /** + * resolve hook + */ + resolve: ResolveStepHook; + /** + * result hook + */ + result: AsyncSeriesHook<[ResolveRequest, ResolveContext]>; }; type EnsuredHooks = { - [key: string]: ResolveStepHook; + [key: string]: ResolveStepHook; }; type AliasOption = import("./AliasUtils").AliasOption; type CachedJoin = import("./util/path").CachedJoin; type CachedDirname = import("./util/path").CachedDirname; type CachedBasename = import("./util/path").CachedBasename; type JoinCacheEntry = { - /** - * cached join function - */ - fn: CachedJoin["fn"]; - /** - * the underlying cache map - */ - cache: CachedJoin["cache"]; + /** + * cached join function + */ + fn: CachedJoin["fn"]; + /** + * the underlying cache map + */ + cache: CachedJoin["cache"]; }; type DirnameCacheEntry = { - /** - * cached dirname function - */ - fn: CachedDirname["fn"]; - /** - * the underlying cache map - */ - cache: CachedDirname["cache"]; + /** + * cached dirname function + */ + fn: CachedDirname["fn"]; + /** + * the underlying cache map + */ + cache: CachedDirname["cache"]; }; type BasenameCacheEntry = { - /** - * cached dirname function - */ - fn: CachedBasename["fn"]; - /** - * the underlying cache map - */ - cache: CachedBasename["cache"]; + /** + * cached dirname function + */ + fn: CachedBasename["fn"]; + /** + * the underlying cache map + */ + cache: CachedBasename["cache"]; }; type PathCacheFunctions = { - /** - * cached join - */ - join: JoinCacheEntry; - /** - * cached dirname - */ - dirname: DirnameCacheEntry; - /** - * cached basename - */ - basename: BasenameCacheEntry; + /** + * cached join + */ + join: JoinCacheEntry; + /** + * cached dirname + */ + dirname: DirnameCacheEntry; + /** + * cached basename + */ + basename: BasenameCacheEntry; }; type ResolveOptions = import("./ResolverFactory").ResolveOptions; type KnownContext = { - /** - * environments - */ - environments?: string[] | undefined; - /** - * package id of the importing file in the package map, propagated from a previous result to disambiguate package entries that share a location (`@experimental`, see the `packageMap` option) - */ - packageId?: string | undefined; + /** + * environments + */ + environments?: string[] | undefined; + /** + * package id of the importing file in the package map, propagated from a previous result to disambiguate package entries that share a location (`@experimental`, see the `packageMap` option) + */ + packageId?: string | undefined; }; type Context = KnownContext & Record; type ErrorWithDetail = Error & { - details?: string; + details?: string; }; -type ResolveCallback = (err: ErrorWithDetail | null, res?: string | false, req?: ResolveRequest) => void; +type ResolveCallback = ( + err: ErrorWithDetail | null, + res?: string | false, + req?: ResolveRequest, +) => void; type PossibleFileSystemError = { - /** - * code - */ - code?: string | undefined; - /** - * number - */ - errno?: number | undefined; - /** - * path - */ - path?: string | undefined; - /** - * syscall - */ - syscall?: string | undefined; + /** + * code + */ + code?: string | undefined; + /** + * number + */ + errno?: number | undefined; + /** + * path + */ + path?: string | undefined; + /** + * syscall + */ + syscall?: string | undefined; }; -type FileSystemCallback = (err: (PossibleFileSystemError & Error) | null, result?: T | undefined) => any; +type FileSystemCallback = ( + err: (PossibleFileSystemError & Error) | null, + result?: T | undefined, +) => any; type PathLike = string | Buffer | URL; type PathOrFileDescriptor = PathLike | number; type ObjectEncodingOptions = { - /** - * encoding - */ - encoding?: (BufferEncoding | null | undefined) | undefined; + /** + * encoding + */ + encoding?: (BufferEncoding | null | undefined) | undefined; }; type EncodingOption = ObjectEncodingOptions | BufferEncoding | undefined | null; -type StringCallback = (err: NodeJS.ErrnoException | null, result?: string) => void; -type BufferCallback = (err: NodeJS.ErrnoException | null, result?: Buffer) => void; -type StringOrBufferCallback = (err: NodeJS.ErrnoException | null, result?: (string | Buffer)) => void; -type StatsCallback = (err: NodeJS.ErrnoException | null, result?: IStats) => void; -type BigIntStatsCallback = (err: NodeJS.ErrnoException | null, result?: IBigIntStats) => void; -type StatsOrBigIntStatsCallback = (err: NodeJS.ErrnoException | null, result?: (IStats | IBigIntStats)) => void; -type ReadJsonCallback = (err: NodeJS.ErrnoException | Error | null, result?: JsonObject) => void; +type StringCallback = ( + err: NodeJS.ErrnoException | null, + result?: string, +) => void; +type BufferCallback = ( + err: NodeJS.ErrnoException | null, + result?: Buffer, +) => void; +type StringOrBufferCallback = ( + err: NodeJS.ErrnoException | null, + result?: string | Buffer, +) => void; +type StatsCallback = ( + err: NodeJS.ErrnoException | null, + result?: IStats, +) => void; +type BigIntStatsCallback = ( + err: NodeJS.ErrnoException | null, + result?: IBigIntStats, +) => void; +type StatsOrBigIntStatsCallback = ( + err: NodeJS.ErrnoException | null, + result?: IStats | IBigIntStats, +) => void; +type ReadJsonCallback = ( + err: NodeJS.ErrnoException | Error | null, + result?: JsonObject, +) => void; type IStatsBase = { - /** - * is file - */ - isFile: () => boolean; - /** - * is directory - */ - isDirectory: () => boolean; - /** - * is block device - */ - isBlockDevice: () => boolean; - /** - * is character device - */ - isCharacterDevice: () => boolean; - /** - * is symbolic link - */ - isSymbolicLink: () => boolean; - /** - * is FIFO - */ - isFIFO: () => boolean; - /** - * is socket - */ - isSocket: () => boolean; - /** - * dev - */ - dev: T; - /** - * ino - */ - ino: T; - /** - * mode - */ - mode: T; - /** - * nlink - */ - nlink: T; - /** - * uid - */ - uid: T; - /** - * gid - */ - gid: T; - /** - * rdev - */ - rdev: T; - /** - * size - */ - size: T; - /** - * blksize - */ - blksize: T; - /** - * blocks - */ - blocks: T; - /** - * atime ms - */ - atimeMs: T; - /** - * mtime ms - */ - mtimeMs: T; - /** - * ctime ms - */ - ctimeMs: T; - /** - * birthtime ms - */ - birthtimeMs: T; - /** - * atime - */ - atime: Date; - /** - * mtime - */ - mtime: Date; - /** - * ctime - */ - ctime: Date; - /** - * birthtime - */ - birthtime: Date; + /** + * is file + */ + isFile: () => boolean; + /** + * is directory + */ + isDirectory: () => boolean; + /** + * is block device + */ + isBlockDevice: () => boolean; + /** + * is character device + */ + isCharacterDevice: () => boolean; + /** + * is symbolic link + */ + isSymbolicLink: () => boolean; + /** + * is FIFO + */ + isFIFO: () => boolean; + /** + * is socket + */ + isSocket: () => boolean; + /** + * dev + */ + dev: T; + /** + * ino + */ + ino: T; + /** + * mode + */ + mode: T; + /** + * nlink + */ + nlink: T; + /** + * uid + */ + uid: T; + /** + * gid + */ + gid: T; + /** + * rdev + */ + rdev: T; + /** + * size + */ + size: T; + /** + * blksize + */ + blksize: T; + /** + * blocks + */ + blocks: T; + /** + * atime ms + */ + atimeMs: T; + /** + * mtime ms + */ + mtimeMs: T; + /** + * ctime ms + */ + ctimeMs: T; + /** + * birthtime ms + */ + birthtimeMs: T; + /** + * atime + */ + atime: Date; + /** + * mtime + */ + mtime: Date; + /** + * ctime + */ + ctime: Date; + /** + * birthtime + */ + birthtime: Date; }; type IStats = IStatsBase; type IBigIntStats = IStatsBase & { - atimeNs: bigint; - mtimeNs: bigint; - ctimeNs: bigint; - birthtimeNs: bigint; + atimeNs: bigint; + mtimeNs: bigint; + ctimeNs: bigint; + birthtimeNs: bigint; }; type Dirent = { - /** - * true when is file, otherwise false - */ - isFile: () => boolean; - /** - * true when is directory, otherwise false - */ - isDirectory: () => boolean; - /** - * true when is block device, otherwise false - */ - isBlockDevice: () => boolean; - /** - * true when is character device, otherwise false - */ - isCharacterDevice: () => boolean; - /** - * true when is symbolic link, otherwise false - */ - isSymbolicLink: () => boolean; - /** - * true when is FIFO, otherwise false - */ - isFIFO: () => boolean; - /** - * true when is socket, otherwise false - */ - isSocket: () => boolean; - /** - * name - */ - name: T; - /** - * path - */ - parentPath: string; - /** - * path - */ - path?: string | undefined; + /** + * true when is file, otherwise false + */ + isFile: () => boolean; + /** + * true when is directory, otherwise false + */ + isDirectory: () => boolean; + /** + * true when is block device, otherwise false + */ + isBlockDevice: () => boolean; + /** + * true when is character device, otherwise false + */ + isCharacterDevice: () => boolean; + /** + * true when is symbolic link, otherwise false + */ + isSymbolicLink: () => boolean; + /** + * true when is FIFO, otherwise false + */ + isFIFO: () => boolean; + /** + * true when is socket, otherwise false + */ + isSocket: () => boolean; + /** + * name + */ + name: T; + /** + * path + */ + parentPath: string; + /** + * path + */ + path?: string | undefined; }; type StatOptions = { - /** - * need bigint values - */ - bigint?: (boolean | undefined) | undefined; + /** + * need bigint values + */ + bigint?: (boolean | undefined) | undefined; }; type StatSyncOptions = { - /** - * need bigint values - */ - bigint?: (boolean | undefined) | undefined; - /** - * throw if no entry - */ - throwIfNoEntry?: (boolean | undefined) | undefined; + /** + * need bigint values + */ + bigint?: (boolean | undefined) | undefined; + /** + * throw if no entry + */ + throwIfNoEntry?: (boolean | undefined) | undefined; }; type ReadFile = { - (path: PathOrFileDescriptor, options: ({ - encoding?: null | undefined; - flag?: string | undefined; - } & import("events").Abortable) | undefined | null, callback: BufferCallback): void; - (path: PathOrFileDescriptor, options: ({ - encoding: BufferEncoding; - flag?: string | undefined; - } & import("events").Abortable) | BufferEncoding, callback: StringCallback): void; - (path: PathOrFileDescriptor, options: (ObjectEncodingOptions & { - flag?: string | undefined; - } & import("events").Abortable) | BufferEncoding | undefined | null, callback: StringOrBufferCallback): void; - (path: PathOrFileDescriptor, callback: BufferCallback): void; -}; -type BufferEncodingOption = "buffer" | { - encoding: "buffer"; + ( + path: PathOrFileDescriptor, + options: + | ({ + encoding?: null | undefined; + flag?: string | undefined; + } & import("events").Abortable) + | undefined + | null, + callback: BufferCallback, + ): void; + ( + path: PathOrFileDescriptor, + options: + | ({ + encoding: BufferEncoding; + flag?: string | undefined; + } & import("events").Abortable) + | BufferEncoding, + callback: StringCallback, + ): void; + ( + path: PathOrFileDescriptor, + options: + | (ObjectEncodingOptions & { + flag?: string | undefined; + } & import("events").Abortable) + | BufferEncoding + | undefined + | null, + callback: StringOrBufferCallback, + ): void; + (path: PathOrFileDescriptor, callback: BufferCallback): void; }; +type BufferEncodingOption = + | "buffer" + | { + encoding: "buffer"; + }; type ReadFileSync = { - (path: PathOrFileDescriptor, options?: { - encoding?: null | undefined; - flag?: string | undefined; - } | null): Buffer; - (path: PathOrFileDescriptor, options: { - encoding: BufferEncoding; - flag?: string | undefined; - } | BufferEncoding): string; - (path: PathOrFileDescriptor, options?: (ObjectEncodingOptions & { - flag?: string | undefined; - }) | BufferEncoding | null): string | Buffer; + ( + path: PathOrFileDescriptor, + options?: { + encoding?: null | undefined; + flag?: string | undefined; + } | null, + ): Buffer; + ( + path: PathOrFileDescriptor, + options: + | { + encoding: BufferEncoding; + flag?: string | undefined; + } + | BufferEncoding, + ): string; + ( + path: PathOrFileDescriptor, + options?: + | (ObjectEncodingOptions & { + flag?: string | undefined; + }) + | BufferEncoding + | null, + ): string | Buffer; }; type Readdir = { - (path: PathLike, options: { - encoding: BufferEncoding | null; - withFileTypes?: false | undefined; - recursive?: boolean | undefined; - } | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void; - (path: PathLike, options: { - encoding: "buffer"; - withFileTypes?: false | undefined; - recursive?: boolean | undefined; - } | "buffer", callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void): void; - (path: PathLike, options: (ObjectEncodingOptions & { - withFileTypes?: false | undefined; - recursive?: boolean | undefined; - }) | BufferEncoding | undefined | null, callback: (err: NodeJS.ErrnoException | null, files?: string[] | Buffer[]) => void): void; - (path: PathLike, callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void): void; - (path: PathLike, options: ObjectEncodingOptions & { - withFileTypes: true; - recursive?: boolean | undefined; - }, callback: (err: NodeJS.ErrnoException | null, files?: Dirent[]) => void): void; - (path: PathLike, options: { - encoding: "buffer"; - withFileTypes: true; - recursive?: boolean | undefined; - }, callback: (err: NodeJS.ErrnoException | null, files: Dirent[]) => void): void; + ( + path: PathLike, + options: + | { + encoding: BufferEncoding | null; + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + } + | BufferEncoding + | undefined + | null, + callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void, + ): void; + ( + path: PathLike, + options: + | { + encoding: "buffer"; + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + } + | "buffer", + callback: (err: NodeJS.ErrnoException | null, files?: Buffer[]) => void, + ): void; + ( + path: PathLike, + options: + | (ObjectEncodingOptions & { + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + }) + | BufferEncoding + | undefined + | null, + callback: ( + err: NodeJS.ErrnoException | null, + files?: string[] | Buffer[], + ) => void, + ): void; + ( + path: PathLike, + callback: (err: NodeJS.ErrnoException | null, files?: string[]) => void, + ): void; + ( + path: PathLike, + options: ObjectEncodingOptions & { + withFileTypes: true; + recursive?: boolean | undefined; + }, + callback: ( + err: NodeJS.ErrnoException | null, + files?: Dirent[], + ) => void, + ): void; + ( + path: PathLike, + options: { + encoding: "buffer"; + withFileTypes: true; + recursive?: boolean | undefined; + }, + callback: ( + err: NodeJS.ErrnoException | null, + files: Dirent[], + ) => void, + ): void; }; type ReaddirSync = { - (path: PathLike, options?: { - encoding: BufferEncoding | null; - withFileTypes?: false | undefined; - recursive?: boolean | undefined; - } | BufferEncoding | null): string[]; - (path: PathLike, options: { - encoding: "buffer"; - withFileTypes?: false | undefined; - recursive?: boolean | undefined; - } | "buffer"): Buffer[]; - (path: PathLike, options?: (ObjectEncodingOptions & { - withFileTypes?: false | undefined; - recursive?: boolean | undefined; - }) | BufferEncoding | null): string[] | Buffer[]; - (path: PathLike, options: ObjectEncodingOptions & { - withFileTypes: true; - recursive?: boolean | undefined; - }): Dirent[]; - (path: PathLike, options: { - encoding: "buffer"; - withFileTypes: true; - recursive?: boolean | undefined; - }): Dirent[]; + ( + path: PathLike, + options?: + | { + encoding: BufferEncoding | null; + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + } + | BufferEncoding + | null, + ): string[]; + ( + path: PathLike, + options: + | { + encoding: "buffer"; + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + } + | "buffer", + ): Buffer[]; + ( + path: PathLike, + options?: + | (ObjectEncodingOptions & { + withFileTypes?: false | undefined; + recursive?: boolean | undefined; + }) + | BufferEncoding + | null, + ): string[] | Buffer[]; + ( + path: PathLike, + options: ObjectEncodingOptions & { + withFileTypes: true; + recursive?: boolean | undefined; + }, + ): Dirent[]; + ( + path: PathLike, + options: { + encoding: "buffer"; + withFileTypes: true; + recursive?: boolean | undefined; + }, + ): Dirent[]; }; -type ReadJson = (pathOrFileDescription: PathOrFileDescriptor, callback: ReadJsonCallback) => void; +type ReadJson = ( + pathOrFileDescription: PathOrFileDescriptor, + callback: ReadJsonCallback, +) => void; type ReadJsonSync = (pathOrFileDescription: PathOrFileDescriptor) => JsonObject; type Readlink = { - (path: PathLike, options: EncodingOption, callback: StringCallback): void; - (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void; - (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void; - (path: PathLike, callback: StringCallback): void; + (path: PathLike, options: EncodingOption, callback: StringCallback): void; + ( + path: PathLike, + options: BufferEncodingOption, + callback: BufferCallback, + ): void; + ( + path: PathLike, + options: EncodingOption, + callback: StringOrBufferCallback, + ): void; + (path: PathLike, callback: StringCallback): void; }; type ReadlinkSync = { - (path: PathLike, options?: EncodingOption): string; - (path: PathLike, options: BufferEncodingOption): Buffer; - (path: PathLike, options?: EncodingOption): string | Buffer; + (path: PathLike, options?: EncodingOption): string; + (path: PathLike, options: BufferEncodingOption): Buffer; + (path: PathLike, options?: EncodingOption): string | Buffer; }; type LStat = { - (path: PathLike, callback: StatsCallback): void; - (path: PathLike, options: (StatOptions & { - bigint?: false | undefined; - }) | undefined, callback: StatsCallback): void; - (path: PathLike, options: StatOptions & { - bigint: true; - }, callback: BigIntStatsCallback): void; - (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void; + (path: PathLike, callback: StatsCallback): void; + ( + path: PathLike, + options: + | (StatOptions & { + bigint?: false | undefined; + }) + | undefined, + callback: StatsCallback, + ): void; + ( + path: PathLike, + options: StatOptions & { + bigint: true; + }, + callback: BigIntStatsCallback, + ): void; + ( + path: PathLike, + options: StatOptions | undefined, + callback: StatsOrBigIntStatsCallback, + ): void; }; type LStatSync = { - (path: PathLike, options?: undefined): IStats; - (path: PathLike, options?: StatSyncOptions & { - bigint?: false | undefined; - throwIfNoEntry: false; - }): IStats | undefined; - (path: PathLike, options: StatSyncOptions & { - bigint: true; - throwIfNoEntry: false; - }): IBigIntStats | undefined; - (path: PathLike, options?: StatSyncOptions & { - bigint?: false | undefined; - }): IStats; - (path: PathLike, options: StatSyncOptions & { - bigint: true; - }): IBigIntStats; - (path: PathLike, options: StatSyncOptions & { - bigint: boolean; - throwIfNoEntry?: false | undefined; - }): IStats | IBigIntStats; - (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined; + (path: PathLike, options?: undefined): IStats; + ( + path: PathLike, + options?: StatSyncOptions & { + bigint?: false | undefined; + throwIfNoEntry: false; + }, + ): IStats | undefined; + ( + path: PathLike, + options: StatSyncOptions & { + bigint: true; + throwIfNoEntry: false; + }, + ): IBigIntStats | undefined; + ( + path: PathLike, + options?: StatSyncOptions & { + bigint?: false | undefined; + }, + ): IStats; + ( + path: PathLike, + options: StatSyncOptions & { + bigint: true; + }, + ): IBigIntStats; + ( + path: PathLike, + options: StatSyncOptions & { + bigint: boolean; + throwIfNoEntry?: false | undefined; + }, + ): IStats | IBigIntStats; + ( + path: PathLike, + options?: StatSyncOptions, + ): IStats | IBigIntStats | undefined; }; type Stat = { - (path: PathLike, callback: StatsCallback): void; - (path: PathLike, options: (StatOptions & { - bigint?: false | undefined; - }) | undefined, callback: StatsCallback): void; - (path: PathLike, options: StatOptions & { - bigint: true; - }, callback: BigIntStatsCallback): void; - (path: PathLike, options: StatOptions | undefined, callback: StatsOrBigIntStatsCallback): void; + (path: PathLike, callback: StatsCallback): void; + ( + path: PathLike, + options: + | (StatOptions & { + bigint?: false | undefined; + }) + | undefined, + callback: StatsCallback, + ): void; + ( + path: PathLike, + options: StatOptions & { + bigint: true; + }, + callback: BigIntStatsCallback, + ): void; + ( + path: PathLike, + options: StatOptions | undefined, + callback: StatsOrBigIntStatsCallback, + ): void; }; type StatSync = { - (path: PathLike, options?: undefined): IStats; - (path: PathLike, options?: StatSyncOptions & { - bigint?: false | undefined; - throwIfNoEntry: false; - }): IStats | undefined; - (path: PathLike, options: StatSyncOptions & { - bigint: true; - throwIfNoEntry: false; - }): IBigIntStats | undefined; - (path: PathLike, options?: StatSyncOptions & { - bigint?: false | undefined; - }): IStats; - (path: PathLike, options: StatSyncOptions & { - bigint: true; - }): IBigIntStats; - (path: PathLike, options: StatSyncOptions & { - bigint: boolean; - throwIfNoEntry?: false | undefined; - }): IStats | IBigIntStats; - (path: PathLike, options?: StatSyncOptions): IStats | IBigIntStats | undefined; + (path: PathLike, options?: undefined): IStats; + ( + path: PathLike, + options?: StatSyncOptions & { + bigint?: false | undefined; + throwIfNoEntry: false; + }, + ): IStats | undefined; + ( + path: PathLike, + options: StatSyncOptions & { + bigint: true; + throwIfNoEntry: false; + }, + ): IBigIntStats | undefined; + ( + path: PathLike, + options?: StatSyncOptions & { + bigint?: false | undefined; + }, + ): IStats; + ( + path: PathLike, + options: StatSyncOptions & { + bigint: true; + }, + ): IBigIntStats; + ( + path: PathLike, + options: StatSyncOptions & { + bigint: boolean; + throwIfNoEntry?: false | undefined; + }, + ): IStats | IBigIntStats; + ( + path: PathLike, + options?: StatSyncOptions, + ): IStats | IBigIntStats | undefined; }; type RealPath = { - (path: PathLike, options: EncodingOption, callback: StringCallback): void; - (path: PathLike, options: BufferEncodingOption, callback: BufferCallback): void; - (path: PathLike, options: EncodingOption, callback: StringOrBufferCallback): void; - (path: PathLike, callback: StringCallback): void; + (path: PathLike, options: EncodingOption, callback: StringCallback): void; + ( + path: PathLike, + options: BufferEncodingOption, + callback: BufferCallback, + ): void; + ( + path: PathLike, + options: EncodingOption, + callback: StringOrBufferCallback, + ): void; + (path: PathLike, callback: StringCallback): void; }; type RealPathSync = { - (path: PathLike, options?: EncodingOption): string; - (path: PathLike, options: BufferEncodingOption): Buffer; - (path: PathLike, options?: EncodingOption): string | Buffer; + (path: PathLike, options?: EncodingOption): string; + (path: PathLike, options: BufferEncodingOption): Buffer; + (path: PathLike, options?: EncodingOption): string | Buffer; }; type FileSystem = { - /** - * read file method - */ - readFile: ReadFile; - /** - * readdir method - */ - readdir: Readdir; - /** - * read json method - */ - readJson?: ReadJson | undefined; - /** - * read link method - */ - readlink: Readlink; - /** - * lstat method - */ - lstat?: LStat | undefined; - /** - * stat method - */ - stat: Stat; - /** - * realpath method - */ - realpath?: RealPath | undefined; + /** + * read file method + */ + readFile: ReadFile; + /** + * readdir method + */ + readdir: Readdir; + /** + * read json method + */ + readJson?: ReadJson | undefined; + /** + * read link method + */ + readlink: Readlink; + /** + * lstat method + */ + lstat?: LStat | undefined; + /** + * stat method + */ + stat: Stat; + /** + * realpath method + */ + realpath?: RealPath | undefined; }; type SyncFileSystem = { - /** - * read file sync method - */ - readFileSync: ReadFileSync; - /** - * read dir sync method - */ - readdirSync: ReaddirSync; - /** - * read json sync method - */ - readJsonSync?: ReadJsonSync | undefined; - /** - * read link sync method - */ - readlinkSync: ReadlinkSync; - /** - * lstat sync method - */ - lstatSync?: LStatSync | undefined; - /** - * stat sync method - */ - statSync: StatSync; - /** - * real path sync method - */ - realpathSync?: RealPathSync | undefined; + /** + * read file sync method + */ + readFileSync: ReadFileSync; + /** + * read dir sync method + */ + readdirSync: ReaddirSync; + /** + * read json sync method + */ + readJsonSync?: ReadJsonSync | undefined; + /** + * read link sync method + */ + readlinkSync: ReadlinkSync; + /** + * lstat sync method + */ + lstatSync?: LStatSync | undefined; + /** + * stat sync method + */ + statSync: StatSync; + /** + * real path sync method + */ + realpathSync?: RealPathSync | undefined; }; type ParsedIdentifier = { - /** - * request - */ - request: string; - /** - * query - */ - query: string; - /** - * fragment - */ - fragment: string; - /** - * is directory - */ - directory: boolean; - /** - * is module - */ - module: boolean; - /** - * is file - */ - file: boolean; - /** - * is internal - */ - internal: boolean; + /** + * request + */ + request: string; + /** + * query + */ + query: string; + /** + * fragment + */ + fragment: string; + /** + * is directory + */ + directory: boolean; + /** + * is module + */ + module: boolean; + /** + * is file + */ + file: boolean; + /** + * is internal + */ + internal: boolean; }; type JsonPrimitive = string | number | boolean | null; type JsonArray = JsonValue[]; type JsonValue = JsonPrimitive | JsonObject | JsonArray; -type JsonObject = { [Key in string]?: JsonValue | undefined; }; +type JsonObject = { [Key in string]?: JsonValue | undefined }; type TsconfigPathsMap = { - /** - * main tsconfig paths data - */ - main: TsconfigPathsData; - /** - * main tsconfig base URL (absolute path) - */ - mainContext: string; - /** - * referenced tsconfig paths data mapped by baseUrl - */ - refs: { - [baseUrl: string]: TsconfigPathsData; - }; - /** - * all contexts (main + refs) for quick lookup - */ - allContexts: { - [context: string]: TsconfigPathsData; - }; - /** - * precomputed `Object.keys(allContexts)` — read-only; used on the `_selectPathsDataForContext` hot path - */ - contextList: string[]; - /** - * file dependencies - */ - fileDependencies: Set; + /** + * main tsconfig paths data + */ + main: TsconfigPathsData; + /** + * main tsconfig base URL (absolute path) + */ + mainContext: string; + /** + * referenced tsconfig paths data mapped by baseUrl + */ + refs: { + [baseUrl: string]: TsconfigPathsData; + }; + /** + * all contexts (main + refs) for quick lookup + */ + allContexts: { + [context: string]: TsconfigPathsData; + }; + /** + * precomputed `Object.keys(allContexts)` — read-only; used on the `_selectPathsDataForContext` hot path + */ + contextList: string[]; + /** + * file dependencies + */ + fileDependencies: Set; }; type TsconfigPathsData = { - /** - * tsconfig file data - */ - alias: import("./AliasUtils").CompiledAliasOptions; - /** - * tsconfig file data - */ - modules: string[]; + /** + * tsconfig file data + */ + alias: import("./AliasUtils").CompiledAliasOptions; + /** + * tsconfig file data + */ + modules: string[]; }; type BaseResolveRequest = { - /** - * path - */ - path: string | false; - /** - * content - */ - context?: Context | undefined; - /** - * description file path - */ - descriptionFilePath?: string | undefined; - /** - * description file root - */ - descriptionFileRoot?: string | undefined; - /** - * description file data - */ - descriptionFileData?: JsonObject | undefined; - /** - * tsconfig paths map - */ - tsconfigPathsMap?: (TsconfigPathsMap | null | undefined) | undefined; - /** - * relative path - */ - relativePath?: string | undefined; - /** - * true when need to ignore symlinks, otherwise false - */ - ignoreSymlinks?: boolean | undefined; - /** - * true when full specified, otherwise false - */ - fullySpecified?: boolean | undefined; - /** - * package id the request was resolved to in the package map, to be propagated to resolutions made from the resulting file (`@experimental`, see the `packageMap` option) - */ - packageId?: string | undefined; - /** - * inner request for internal usage - */ - __innerRequest?: string | undefined; - /** - * inner request for internal usage - */ - __innerRequest_request?: string | undefined; - /** - * inner relative path for internal usage - */ - __innerRequest_relativePath?: string | undefined; - /** - * internal: shared marker `RestrictionsPlugin` flips when it filters out an existing target, letting `ExportsFieldPlugin` fall back instead of erroring - */ - __restrictionsMarker?: { - blocked: boolean; - } | undefined; + /** + * path + */ + path: string | false; + /** + * content + */ + context?: Context | undefined; + /** + * description file path + */ + descriptionFilePath?: string | undefined; + /** + * description file root + */ + descriptionFileRoot?: string | undefined; + /** + * description file data + */ + descriptionFileData?: JsonObject | undefined; + /** + * tsconfig paths map + */ + tsconfigPathsMap?: (TsconfigPathsMap | null | undefined) | undefined; + /** + * relative path + */ + relativePath?: string | undefined; + /** + * true when need to ignore symlinks, otherwise false + */ + ignoreSymlinks?: boolean | undefined; + /** + * true when full specified, otherwise false + */ + fullySpecified?: boolean | undefined; + /** + * package id the request was resolved to in the package map, to be propagated to resolutions made from the resulting file (`@experimental`, see the `packageMap` option) + */ + packageId?: string | undefined; + /** + * inner request for internal usage + */ + __innerRequest?: string | undefined; + /** + * inner request for internal usage + */ + __innerRequest_request?: string | undefined; + /** + * inner relative path for internal usage + */ + __innerRequest_relativePath?: string | undefined; + /** + * internal: shared marker `RestrictionsPlugin` flips when it filters out an existing target, letting `ExportsFieldPlugin` fall back instead of erroring + */ + __restrictionsMarker?: + | { + blocked: boolean; + } + | undefined; }; type ResolveRequest = BaseResolveRequest & Partial; type WriteOnlySet = { - add: (item: T) => void; + add: (item: T) => void; }; type ResolveContextYield = (request: ResolveRequest) => void; import { AsyncSeriesBailHook } from "tapable"; diff --git a/types/ResolverFactory.d.ts b/types/ResolverFactory.d.ts index 1dfae85c..bad1977f 100644 --- a/types/ResolverFactory.d.ts +++ b/types/ResolverFactory.d.ts @@ -1,6 +1,7 @@ export function createResolver(options: UserResolveOptions): Resolver; export type AliasOptionEntry = import("./AliasPlugin").AliasOption; -export type ExtensionAliasOption = import("./ExtensionAliasPlugin").ExtensionAliasOption; +export type ExtensionAliasOption = + import("./ExtensionAliasPlugin").ExtensionAliasOption; export type PackageMapOptions = import("./PackageMapPlugin").PackageMapOptions; export type PackageMapPackages = import("./util/packageMap").PackageMapPackages; export type PnpApi = import("./PnpPlugin").PnpApiImpl; @@ -12,51 +13,54 @@ export type SyncFileSystem = import("./Resolver").SyncFileSystem; export type Cache = import("./UnsafeCachePlugin").Cache; export type AliasOptionNewRequest = string | string[] | false; export type AliasOptions = { - [k: string]: AliasOptionNewRequest; + [k: string]: AliasOptionNewRequest; }; export type UserAliasOptionNewRequest = string | URL | (string | URL)[] | false; export type UserAliasOptions = { - [k: string]: UserAliasOptionNewRequest; + [k: string]: UserAliasOptionNewRequest; }; export type UserAliasOptionEntry = { - alias: UserAliasOptionNewRequest; - name: string; - onlyModule?: boolean; + alias: UserAliasOptionNewRequest; + name: string; + onlyModule?: boolean; }; export type ExtensionAliasOptions = { - [k: string]: string | string[]; + [k: string]: string | string[]; }; export type Falsy = false | 0 | "" | null | undefined; -export type Plugin = { - apply: (resolver: Resolver) => void; -} | ((this: Resolver, resolver: Resolver) => void) | Falsy; +export type Plugin = + | { + apply: (resolver: Resolver) => void; + } + | ((this: Resolver, resolver: Resolver) => void) + | Falsy; export type TsconfigOptions = { - /** - * A relative path to the tsconfig file based on cwd, or an absolute path of tsconfig file - */ - configFile?: string | undefined; - /** - * References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths - */ - references?: (string[] | "auto") | undefined; - /** - * Override baseUrl from tsconfig.json. If provided, this value will be used instead of the baseUrl in the tsconfig file - */ - baseUrl?: string | undefined; + /** + * A relative path to the tsconfig file based on cwd, or an absolute path of tsconfig file + */ + configFile?: string | undefined; + /** + * References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths + */ + references?: (string[] | "auto") | undefined; + /** + * Override baseUrl from tsconfig.json. If provided, this value will be used instead of the baseUrl in the tsconfig file + */ + baseUrl?: string | undefined; }; export type UserTsconfigOptions = { - /** - * A path, or `file:` URL, pointing at the tsconfig file - */ - configFile?: (string | URL) | undefined; - /** - * References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths or `file:` URLs - */ - references?: ((string | URL)[] | "auto") | undefined; - /** - * Override baseUrl from tsconfig.json with a path or `file:` URL - */ - baseUrl?: (string | URL) | undefined; + /** + * A path, or `file:` URL, pointing at the tsconfig file + */ + configFile?: (string | URL) | undefined; + /** + * References to other tsconfig files. 'auto' inherits from TypeScript config, or an array of relative/absolute paths or `file:` URLs + */ + references?: ((string | URL)[] | "auto") | undefined; + /** + * Override baseUrl from tsconfig.json with a path or `file:` URL + */ + baseUrl?: (string | URL) | undefined; }; /** * A Node.js package map (https://nodejs.org/api/packages.html#package-maps), @@ -64,267 +68,273 @@ export type UserTsconfigOptions = { * contents. */ export type UserPackageMapOptions = { - /** - * A path, or `file:` `URL` instance, pointing at the package map file. Required together with `packages`, whose relative `url` values are resolved against it - */ - configFile?: (string | URL) | undefined; - /** - * An already-parsed `packages` object, used instead of reading `configFile` from disk - */ - packages?: PackageMapPackages | undefined; + /** + * A path, or `file:` `URL` instance, pointing at the package map file. Required together with `packages`, whose relative `url` values are resolved against it + */ + configFile?: (string | URL) | undefined; + /** + * An already-parsed `packages` object, used instead of reading `configFile` from disk + */ + packages?: PackageMapPackages | undefined; }; export type UserResolveOptions = { - /** - * A list of module alias configurations or an object which maps key to value - */ - alias?: (UserAliasOptions | UserAliasOptionEntry[]) | undefined; - /** - * A list of module alias configurations or an object which maps key to value, applied only after modules option - */ - fallback?: (UserAliasOptions | UserAliasOptionEntry[]) | undefined; - /** - * An object which maps extension to extension aliases - */ - extensionAlias?: ExtensionAliasOptions | undefined; - /** - * Also apply `extensionAlias` to paths resolved through the package.json `exports` field. Off by default (Node.js-aligned); when enabled, matches TypeScript's behavior for packages that ship TS sources alongside compiled JS. - */ - extensionAliasForExports?: boolean | undefined; - /** - * A list of alias fields in description files - */ - aliasFields?: (string | string[])[] | undefined; - /** - * A function which decides whether a request should be cached or not. An object is passed with at least `path` and `request` properties. - */ - cachePredicate?: ((predicate: ResolveRequest) => boolean) | undefined; - /** - * Whether or not the unsafeCache should include request context as part of the cache key. - */ - cacheWithContext?: boolean | undefined; - /** - * A list of description files to read from - */ - descriptionFiles?: string[] | undefined; - /** - * A list of exports field condition names. - */ - conditionNames?: string[] | undefined; - /** - * Enforce that a extension from extensions must be used - */ - enforceExtension?: boolean | undefined; - /** - * A list of exports fields in description files - */ - exportsFields?: (string | string[])[] | undefined; - /** - * A list of imports fields in description files - */ - importsFields?: (string | string[])[] | undefined; - /** - * A list of extensions which should be tried for files - */ - extensions?: string[] | undefined; - /** - * The file system which should be used - */ - fileSystem: FileSystem; - /** - * Use this cache object to unsafely cache the successful requests - */ - unsafeCache?: (Cache | boolean) | undefined; - /** - * Resolve symlinks to their symlinked location - */ - symlinks?: boolean | undefined; - /** - * A prepared Resolver to which the plugins are attached - */ - resolver?: Resolver | undefined; - /** - * A list of directories to resolve modules from, can be absolute path, folder name, or a `file:` URL - */ - modules?: ((string | URL)[] | string | URL) | undefined; - /** - * A list of main fields in description files - */ - mainFields?: (string | string[] | { - name: string | string[]; - forceRelative: boolean; - })[] | undefined; - /** - * A list of main files in directories - */ - mainFiles?: string[] | undefined; - /** - * A list of additional resolve plugins which should be applied - */ - plugins?: Plugin[] | undefined; - /** - * A Node.js package map file path (or `file:` `URL` instance), or an object with the already-parsed `packages`. When set, bare specifiers resolve through the map instead of `node_modules` (`@experimental`) - */ - packageMap?: (string | URL | UserPackageMapOptions) | undefined; - /** - * A PnP API that should be used - null is "never", undefined is "auto" - */ - pnpApi?: (PnpApi | null) | undefined; - /** - * A list of root paths, each an absolute path or a `file:` URL - */ - roots?: (string | URL)[] | undefined; - /** - * The request is already fully specified and no extensions or directories are resolved for it - */ - fullySpecified?: boolean | undefined; - /** - * Resolve to a context instead of a file - */ - resolveToContext?: boolean | undefined; - /** - * A list of resolve restrictions, each an absolute path, a `file:` URL, or a RegExp - */ - restrictions?: (string | URL | RegExp)[] | undefined; - /** - * Use only the sync constraints of the file system calls - */ - useSyncFileSystemCalls?: boolean | undefined; - /** - * Prefer to resolve module requests as relative requests before falling back to modules - */ - preferRelative?: boolean | undefined; - /** - * Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots - */ - preferAbsolute?: boolean | undefined; - /** - * TypeScript config file path (or `file:` URL) or config object with configFile and references - */ - tsconfig?: (string | URL | boolean | UserTsconfigOptions) | undefined; + /** + * A list of module alias configurations or an object which maps key to value + */ + alias?: (UserAliasOptions | UserAliasOptionEntry[]) | undefined; + /** + * A list of module alias configurations or an object which maps key to value, applied only after modules option + */ + fallback?: (UserAliasOptions | UserAliasOptionEntry[]) | undefined; + /** + * An object which maps extension to extension aliases + */ + extensionAlias?: ExtensionAliasOptions | undefined; + /** + * Also apply `extensionAlias` to paths resolved through the package.json `exports` field. Off by default (Node.js-aligned); when enabled, matches TypeScript's behavior for packages that ship TS sources alongside compiled JS. + */ + extensionAliasForExports?: boolean | undefined; + /** + * A list of alias fields in description files + */ + aliasFields?: (string | string[])[] | undefined; + /** + * A function which decides whether a request should be cached or not. An object is passed with at least `path` and `request` properties. + */ + cachePredicate?: ((predicate: ResolveRequest) => boolean) | undefined; + /** + * Whether or not the unsafeCache should include request context as part of the cache key. + */ + cacheWithContext?: boolean | undefined; + /** + * A list of description files to read from + */ + descriptionFiles?: string[] | undefined; + /** + * A list of exports field condition names. + */ + conditionNames?: string[] | undefined; + /** + * Enforce that a extension from extensions must be used + */ + enforceExtension?: boolean | undefined; + /** + * A list of exports fields in description files + */ + exportsFields?: (string | string[])[] | undefined; + /** + * A list of imports fields in description files + */ + importsFields?: (string | string[])[] | undefined; + /** + * A list of extensions which should be tried for files + */ + extensions?: string[] | undefined; + /** + * The file system which should be used + */ + fileSystem: FileSystem; + /** + * Use this cache object to unsafely cache the successful requests + */ + unsafeCache?: (Cache | boolean) | undefined; + /** + * Resolve symlinks to their symlinked location + */ + symlinks?: boolean | undefined; + /** + * A prepared Resolver to which the plugins are attached + */ + resolver?: Resolver | undefined; + /** + * A list of directories to resolve modules from, can be absolute path, folder name, or a `file:` URL + */ + modules?: ((string | URL)[] | string | URL) | undefined; + /** + * A list of main fields in description files + */ + mainFields?: + | ( + | string + | string[] + | { + name: string | string[]; + forceRelative: boolean; + } + )[] + | undefined; + /** + * A list of main files in directories + */ + mainFiles?: string[] | undefined; + /** + * A list of additional resolve plugins which should be applied + */ + plugins?: Plugin[] | undefined; + /** + * A Node.js package map file path (or `file:` `URL` instance), or an object with the already-parsed `packages`. When set, bare specifiers resolve through the map instead of `node_modules` (`@experimental`) + */ + packageMap?: (string | URL | UserPackageMapOptions) | undefined; + /** + * A PnP API that should be used - null is "never", undefined is "auto" + */ + pnpApi?: (PnpApi | null) | undefined; + /** + * A list of root paths, each an absolute path or a `file:` URL + */ + roots?: (string | URL)[] | undefined; + /** + * The request is already fully specified and no extensions or directories are resolved for it + */ + fullySpecified?: boolean | undefined; + /** + * Resolve to a context instead of a file + */ + resolveToContext?: boolean | undefined; + /** + * A list of resolve restrictions, each an absolute path, a `file:` URL, or a RegExp + */ + restrictions?: (string | URL | RegExp)[] | undefined; + /** + * Use only the sync constraints of the file system calls + */ + useSyncFileSystemCalls?: boolean | undefined; + /** + * Prefer to resolve module requests as relative requests before falling back to modules + */ + preferRelative?: boolean | undefined; + /** + * Prefer to resolve server-relative urls as absolute paths before falling back to resolve in roots + */ + preferAbsolute?: boolean | undefined; + /** + * TypeScript config file path (or `file:` URL) or config object with configFile and references + */ + tsconfig?: (string | URL | boolean | UserTsconfigOptions) | undefined; }; export type ResolveOptions = { - /** - * alias - */ - alias: AliasOptionEntry[]; - /** - * fallback - */ - fallback: AliasOptionEntry[]; - /** - * alias fields - */ - aliasFields: Set; - /** - * extension alias - */ - extensionAlias: ExtensionAliasOption[]; - /** - * apply extension alias to exports field targets - */ - extensionAliasForExports: boolean; - /** - * cache predicate - */ - cachePredicate: (predicate: ResolveRequest) => boolean; - /** - * cache with context - */ - cacheWithContext: boolean; - /** - * A list of exports field condition names. - */ - conditionNames: Set; - /** - * description files - */ - descriptionFiles: string[]; - /** - * enforce extension - */ - enforceExtension: boolean; - /** - * exports fields - */ - exportsFields: Set; - /** - * imports fields - */ - importsFields: Set; - /** - * extensions - */ - extensions: Set; - /** - * fileSystem - */ - fileSystem: FileSystem; - /** - * unsafe cache - */ - unsafeCache: Cache | false; - /** - * symlinks - */ - symlinks: boolean; - /** - * resolver - */ - resolver?: Resolver | undefined; - /** - * modules - */ - modules: (string | string[])[]; - /** - * main fields - */ - mainFields: { - name: string[]; - forceRelative: boolean; - }[]; - /** - * main files - */ - mainFiles: Set; - /** - * plugins - */ - plugins: Plugin[]; - /** - * package map - */ - packageMap: PackageMapOptions | null; - /** - * pnp API - */ - pnpApi: PnpApi | null; - /** - * roots - */ - roots: Set; - /** - * fully specified - */ - fullySpecified: boolean; - /** - * resolve to context - */ - resolveToContext: boolean; - /** - * restrictions - */ - restrictions: Set; - /** - * prefer relative - */ - preferRelative: boolean; - /** - * prefer absolute - */ - preferAbsolute: boolean; - /** - * tsconfig file path or config object - */ - tsconfig: string | boolean | TsconfigOptions; + /** + * alias + */ + alias: AliasOptionEntry[]; + /** + * fallback + */ + fallback: AliasOptionEntry[]; + /** + * alias fields + */ + aliasFields: Set; + /** + * extension alias + */ + extensionAlias: ExtensionAliasOption[]; + /** + * apply extension alias to exports field targets + */ + extensionAliasForExports: boolean; + /** + * cache predicate + */ + cachePredicate: (predicate: ResolveRequest) => boolean; + /** + * cache with context + */ + cacheWithContext: boolean; + /** + * A list of exports field condition names. + */ + conditionNames: Set; + /** + * description files + */ + descriptionFiles: string[]; + /** + * enforce extension + */ + enforceExtension: boolean; + /** + * exports fields + */ + exportsFields: Set; + /** + * imports fields + */ + importsFields: Set; + /** + * extensions + */ + extensions: Set; + /** + * fileSystem + */ + fileSystem: FileSystem; + /** + * unsafe cache + */ + unsafeCache: Cache | false; + /** + * symlinks + */ + symlinks: boolean; + /** + * resolver + */ + resolver?: Resolver | undefined; + /** + * modules + */ + modules: (string | string[])[]; + /** + * main fields + */ + mainFields: { + name: string[]; + forceRelative: boolean; + }[]; + /** + * main files + */ + mainFiles: Set; + /** + * plugins + */ + plugins: Plugin[]; + /** + * package map + */ + packageMap: PackageMapOptions | null; + /** + * pnp API + */ + pnpApi: PnpApi | null; + /** + * roots + */ + roots: Set; + /** + * fully specified + */ + fullySpecified: boolean; + /** + * resolve to context + */ + resolveToContext: boolean; + /** + * restrictions + */ + restrictions: Set; + /** + * prefer relative + */ + preferRelative: boolean; + /** + * prefer absolute + */ + preferAbsolute: boolean; + /** + * tsconfig file path or config object + */ + tsconfig: string | boolean | TsconfigOptions; }; import Resolver = require("./Resolver"); diff --git a/types/RestrictionsPlugin.d.ts b/types/RestrictionsPlugin.d.ts index 050a7089..ceb2fb60 100644 --- a/types/RestrictionsPlugin.d.ts +++ b/types/RestrictionsPlugin.d.ts @@ -1,43 +1,52 @@ export = RestrictionsPlugin; declare class RestrictionsPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {Set} restrictions restrictions - */ - constructor(source: string | ResolveStepHook, restrictions: Set); - source: string | import("./Resolver").ResolveStepHook; - restrictions: Set; - /** @type {Restriction[]} */ - _restrictions: Restriction[]; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {Set} restrictions restrictions + */ + constructor( + source: string | ResolveStepHook, + restrictions: Set, + ); + source: string | import("./Resolver").ResolveStepHook; + restrictions: Set; + /** @type {Restriction[]} */ + _restrictions: Restriction[]; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace RestrictionsPlugin { - export { Resolver, ResolveStepHook, PathRestriction, RegExpRestriction, Restriction }; + export { + Resolver, + ResolveStepHook, + PathRestriction, + RegExpRestriction, + Restriction, + }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; type PathRestriction = { - /** - * type of the restriction - */ - type: "path"; - /** - * normalized path the request has to be inside of - */ - rule: string; + /** + * type of the restriction + */ + type: "path"; + /** + * normalized path the request has to be inside of + */ + rule: string; }; type RegExpRestriction = { - /** - * type of the restriction - */ - type: "regexp"; - /** - * pattern the request has to match - */ - rule: RegExp; + /** + * type of the restriction + */ + type: "regexp"; + /** + * pattern the request has to match + */ + rule: RegExp; }; type Restriction = PathRestriction | RegExpRestriction; diff --git a/types/ResultPlugin.d.ts b/types/ResultPlugin.d.ts index c738c650..94fe0b2f 100644 --- a/types/ResultPlugin.d.ts +++ b/types/ResultPlugin.d.ts @@ -1,18 +1,18 @@ export = ResultPlugin; declare class ResultPlugin { - /** - * @param {ResolveStepHook} source source - */ - constructor(source: ResolveStepHook); - source: import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {ResolveStepHook} source source + */ + constructor(source: ResolveStepHook); + source: import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace ResultPlugin { - export { Resolver, ResolveStepHook }; + export { Resolver, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/RootsPlugin.d.ts b/types/RootsPlugin.d.ts index 465a7f83..72625d25 100644 --- a/types/RootsPlugin.d.ts +++ b/types/RootsPlugin.d.ts @@ -3,23 +3,27 @@ export = RootsPlugin; /** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */ /** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */ declare class RootsPlugin { - /** - * @param {string | ResolveStepHook} source source hook - * @param {Set} roots roots - * @param {string | ResolveStepHook} target target hook - */ - constructor(source: string | ResolveStepHook, roots: Set, target: string | ResolveStepHook); - roots: string[]; - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source hook + * @param {Set} roots roots + * @param {string | ResolveStepHook} target target hook + */ + constructor( + source: string | ResolveStepHook, + roots: Set, + target: string | ResolveStepHook, + ); + roots: string[]; + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace RootsPlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/SelfReferencePlugin.d.ts b/types/SelfReferencePlugin.d.ts index aaa53439..642e7d9c 100644 --- a/types/SelfReferencePlugin.d.ts +++ b/types/SelfReferencePlugin.d.ts @@ -1,24 +1,28 @@ export = SelfReferencePlugin; declare class SelfReferencePlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | string[]} fieldNamePath name path - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, fieldNamePath: string | string[], target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - fieldName: string | string[]; - /** @type {WeakMap} */ - _nameCache: WeakMap; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | string[]} fieldNamePath name path + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + fieldNamePath: string | string[], + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + fieldName: string | string[]; + /** @type {WeakMap} */ + _nameCache: WeakMap; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace SelfReferencePlugin { - export { Resolver, JsonObject, ResolveRequest, ResolveStepHook }; + export { Resolver, JsonObject, ResolveRequest, ResolveStepHook }; } declare const NO_SELF_REF: unique symbol; type Resolver = import("./Resolver"); diff --git a/types/SymlinkPlugin.d.ts b/types/SymlinkPlugin.d.ts index 8f747081..09750b71 100644 --- a/types/SymlinkPlugin.d.ts +++ b/types/SymlinkPlugin.d.ts @@ -1,20 +1,23 @@ export = SymlinkPlugin; declare class SymlinkPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace SymlinkPlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/SyncAsyncFileSystemDecorator.d.ts b/types/SyncAsyncFileSystemDecorator.d.ts index eafb0211..716926b8 100644 --- a/types/SyncAsyncFileSystemDecorator.d.ts +++ b/types/SyncAsyncFileSystemDecorator.d.ts @@ -10,34 +10,40 @@ export = SyncAsyncFileSystemDecorator; */ declare function SyncAsyncFileSystemDecorator(fs: SyncFileSystem): void; declare class SyncAsyncFileSystemDecorator { - /** @typedef {import("./Resolver").FileSystem} FileSystem */ - /** @typedef {import("./Resolver").StringCallback} StringCallback */ - /** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */ - /** @typedef {Function} SyncOrAsyncFunction */ - /** @typedef {any} ResultOfSyncOrAsyncFunction */ - /** - * @param {SyncFileSystem} fs file system implementation - * @constructor - */ - constructor(fs: SyncFileSystem); - fs: import("./Resolver").SyncFileSystem; - lstat: import("./Resolver").LStat | undefined; - lstatSync: import("./Resolver").LStatSync | undefined; - stat: import("./Resolver").Stat; - statSync: import("./Resolver").StatSync; - readdir: import("./Resolver").Readdir; - readdirSync: import("./Resolver").ReaddirSync; - readFile: import("./Resolver").ReadFile; - readFileSync: import("./Resolver").ReadFileSync; - readlink: import("./Resolver").Readlink; - readlinkSync: import("./Resolver").ReadlinkSync; - readJson: import("./Resolver").ReadJson | undefined; - readJsonSync: import("./Resolver").ReadJsonSync | undefined; - realpath: import("./Resolver").RealPath | undefined; - realpathSync: import("./Resolver").RealPathSync | undefined; + /** @typedef {import("./Resolver").FileSystem} FileSystem */ + /** @typedef {import("./Resolver").StringCallback} StringCallback */ + /** @typedef {import("./Resolver").SyncFileSystem} SyncFileSystem */ + /** @typedef {Function} SyncOrAsyncFunction */ + /** @typedef {any} ResultOfSyncOrAsyncFunction */ + /** + * @param {SyncFileSystem} fs file system implementation + * @constructor + */ + constructor(fs: SyncFileSystem); + fs: import("./Resolver").SyncFileSystem; + lstat: import("./Resolver").LStat | undefined; + lstatSync: import("./Resolver").LStatSync | undefined; + stat: import("./Resolver").Stat; + statSync: import("./Resolver").StatSync; + readdir: import("./Resolver").Readdir; + readdirSync: import("./Resolver").ReaddirSync; + readFile: import("./Resolver").ReadFile; + readFileSync: import("./Resolver").ReadFileSync; + readlink: import("./Resolver").Readlink; + readlinkSync: import("./Resolver").ReadlinkSync; + readJson: import("./Resolver").ReadJson | undefined; + readJsonSync: import("./Resolver").ReadJsonSync | undefined; + realpath: import("./Resolver").RealPath | undefined; + realpathSync: import("./Resolver").RealPathSync | undefined; } declare namespace SyncAsyncFileSystemDecorator { - export { FileSystem, StringCallback, SyncFileSystem, SyncOrAsyncFunction, ResultOfSyncOrAsyncFunction }; + export { + FileSystem, + StringCallback, + SyncFileSystem, + SyncOrAsyncFunction, + ResultOfSyncOrAsyncFunction, + }; } type FileSystem = import("./Resolver").FileSystem; type StringCallback = import("./Resolver").StringCallback; diff --git a/types/TryNextPlugin.d.ts b/types/TryNextPlugin.d.ts index 2ca7595f..c3ade874 100644 --- a/types/TryNextPlugin.d.ts +++ b/types/TryNextPlugin.d.ts @@ -1,22 +1,26 @@ export = TryNextPlugin; declare class TryNextPlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string} message message - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, message: string, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - message: string; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string} message message + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + message: string, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + message: string; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace TryNextPlugin { - export { Resolver, ResolveStepHook }; + export { Resolver, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; diff --git a/types/TsconfigPathsPlugin.d.ts b/types/TsconfigPathsPlugin.d.ts index 598ed33b..8c65d39d 100644 --- a/types/TsconfigPathsPlugin.d.ts +++ b/types/TsconfigPathsPlugin.d.ts @@ -1,108 +1,163 @@ export = TsconfigPathsPlugin; declare class TsconfigPathsPlugin { - /** - * @param {true | string | TsconfigOptions} configFileOrOptions tsconfig file path or options object - */ - constructor(configFileOrOptions: true | string | TsconfigOptions); - /** @type {boolean} */ - isAutoConfigFile: boolean; - /** @type {string} */ - configFile: string; - /** @type {TsconfigReference[] | "auto"} */ - references: TsconfigReference[] | "auto"; - /** @type {string | undefined} */ - baseUrl: string | undefined; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; - /** - * Get TsconfigPathsMap for the request (with caching) - * @param {Resolver} resolver the resolver - * @param {ResolveRequest} request the request - * @param {ResolveContext} resolveContext the resolve context - * @param {(err: Error | null, result?: TsconfigPathsMap | null) => void} callback the callback - * @returns {void} - */ - _getTsconfigPathsMap(resolver: Resolver, request: ResolveRequest, resolveContext: ResolveContext, callback: (err: Error | null, result?: TsconfigPathsMap | null) => void): void; - /** - * Walk up from startDir to the filesystem root looking for tsconfig.json. - * Like TypeScript's own `findConfigFile` / `forEachAncestorDirectory`. - * @param {Resolver} resolver the resolver - * @param {string} startDir the directory to start searching from - * @param {(err: Error | null, result?: TsconfigPathsMap | null) => void} callback the callback - * @returns {void} - */ - _findTsconfigUpward(resolver: Resolver, startDir: string, callback: (err: Error | null, result?: TsconfigPathsMap | null) => void): void; - /** - * Load tsconfig.json and build complete TsconfigPathsMap - * Includes main project paths and all referenced projects - * @param {Resolver} resolver the resolver - * @param {string} absTsconfigPath absolute path to tsconfig.json - * @param {(err: Error | null, result?: TsconfigPathsMap) => void} callback the callback - * @returns {void} - */ - _loadTsconfigPathsMap(resolver: Resolver, absTsconfigPath: string, callback: (err: Error | null, result?: TsconfigPathsMap) => void): void; - /** - * Select the correct TsconfigPathsData based on request.path (context-aware) - * Matches the behavior of tsconfig-paths-webpack-plugin - * @param {string | false} requestPath the request path - * @param {TsconfigPathsMap} tsconfigPathsMap the tsconfig paths map - * @returns {TsconfigPathsData | null} the selected paths data - */ - _selectPathsDataForContext(requestPath: string | false, tsconfigPathsMap: TsconfigPathsMap): TsconfigPathsData | null; - /** - * Load tsconfig from extends path - * @param {Resolver} resolver the resolver - * @param {string} configFilePath current config file path - * @param {string} extendedConfigValue extends value - * @param {Set} fileDependencies the file dependencies - * @param {Set} visitedConfigPaths config paths being loaded (for circular extends detection) - * @param {(err: Error | null, result?: Tsconfig) => void} callback callback - * @returns {void} - */ - _loadTsconfigFromExtends(resolver: Resolver, configFilePath: string, extendedConfigValue: string, fileDependencies: Set, visitedConfigPaths: Set, callback: (err: Error | null, result?: Tsconfig) => void): void; - /** - * Walk up from startDir looking for `/` (a - * `node_modules/...` sub-path), matching Node.js module resolution so a - * package hoisted to a parent workspace's node_modules is found. - * @param {Resolver} resolver the resolver - * @param {string} startDir directory to start searching from - * @param {string} subPath node_modules-relative sub-path to look for - * @param {(found: string | null) => void} callback receives the found path or null - * @returns {void} - */ - _findExtendsInNodeModules(resolver: Resolver, startDir: string, subPath: string, callback: (found: string | null) => void): void; - /** - * Load referenced tsconfig projects and store in referenceMatchMap - * Simple implementation matching tsconfig-paths-webpack-plugin: - * Just load each reference and store independently - * @param {Resolver} resolver the resolver - * @param {string} context the context - * @param {TsconfigReference[]} references array of references - * @param {Set} fileDependencies the file dependencies - * @param {{ [baseUrl: string]: TsconfigPathsData }} referenceMatchMap the map to populate - * @param {(err: Error | null) => void} callback callback - * @param {Set=} visitedRefPaths visited reference config paths (for circular reference detection) - * @returns {void} - */ - _loadTsconfigReferences(resolver: Resolver, context: string, references: TsconfigReference[], fileDependencies: Set, referenceMatchMap: { - [baseUrl: string]: TsconfigPathsData; - }, callback: (err: Error | null) => void, visitedRefPaths?: Set | undefined): void; - /** - * Load tsconfig.json with extends support - * @param {Resolver} resolver the resolver - * @param {string} configFilePath absolute path to tsconfig.json - * @param {Set} fileDependencies the file dependencies - * @param {Set | undefined} visitedConfigPaths config paths being loaded (for circular extends detection) - * @param {(err: Error | null, result?: Tsconfig) => void} callback callback - * @returns {void} - */ - _loadTsconfig(resolver: Resolver, configFilePath: string, fileDependencies: Set, visitedConfigPaths: Set | undefined, callback: (err: Error | null, result?: Tsconfig) => void): void; + /** + * @param {true | string | TsconfigOptions} configFileOrOptions tsconfig file path or options object + */ + constructor(configFileOrOptions: true | string | TsconfigOptions); + /** @type {boolean} */ + isAutoConfigFile: boolean; + /** @type {string} */ + configFile: string; + /** @type {TsconfigReference[] | "auto"} */ + references: TsconfigReference[] | "auto"; + /** @type {string | undefined} */ + baseUrl: string | undefined; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; + /** + * Get TsconfigPathsMap for the request (with caching) + * @param {Resolver} resolver the resolver + * @param {ResolveRequest} request the request + * @param {ResolveContext} resolveContext the resolve context + * @param {(err: Error | null, result?: TsconfigPathsMap | null) => void} callback the callback + * @returns {void} + */ + _getTsconfigPathsMap( + resolver: Resolver, + request: ResolveRequest, + resolveContext: ResolveContext, + callback: (err: Error | null, result?: TsconfigPathsMap | null) => void, + ): void; + /** + * Walk up from startDir to the filesystem root looking for tsconfig.json. + * Like TypeScript's own `findConfigFile` / `forEachAncestorDirectory`. + * @param {Resolver} resolver the resolver + * @param {string} startDir the directory to start searching from + * @param {(err: Error | null, result?: TsconfigPathsMap | null) => void} callback the callback + * @returns {void} + */ + _findTsconfigUpward( + resolver: Resolver, + startDir: string, + callback: (err: Error | null, result?: TsconfigPathsMap | null) => void, + ): void; + /** + * Load tsconfig.json and build complete TsconfigPathsMap + * Includes main project paths and all referenced projects + * @param {Resolver} resolver the resolver + * @param {string} absTsconfigPath absolute path to tsconfig.json + * @param {(err: Error | null, result?: TsconfigPathsMap) => void} callback the callback + * @returns {void} + */ + _loadTsconfigPathsMap( + resolver: Resolver, + absTsconfigPath: string, + callback: (err: Error | null, result?: TsconfigPathsMap) => void, + ): void; + /** + * Select the correct TsconfigPathsData based on request.path (context-aware) + * Matches the behavior of tsconfig-paths-webpack-plugin + * @param {string | false} requestPath the request path + * @param {TsconfigPathsMap} tsconfigPathsMap the tsconfig paths map + * @returns {TsconfigPathsData | null} the selected paths data + */ + _selectPathsDataForContext( + requestPath: string | false, + tsconfigPathsMap: TsconfigPathsMap, + ): TsconfigPathsData | null; + /** + * Load tsconfig from extends path + * @param {Resolver} resolver the resolver + * @param {string} configFilePath current config file path + * @param {string} extendedConfigValue extends value + * @param {Set} fileDependencies the file dependencies + * @param {Set} visitedConfigPaths config paths being loaded (for circular extends detection) + * @param {(err: Error | null, result?: Tsconfig) => void} callback callback + * @returns {void} + */ + _loadTsconfigFromExtends( + resolver: Resolver, + configFilePath: string, + extendedConfigValue: string, + fileDependencies: Set, + visitedConfigPaths: Set, + callback: (err: Error | null, result?: Tsconfig) => void, + ): void; + /** + * Walk up from startDir looking for `/` (a + * `node_modules/...` sub-path), matching Node.js module resolution so a + * package hoisted to a parent workspace's node_modules is found. + * @param {Resolver} resolver the resolver + * @param {string} startDir directory to start searching from + * @param {string} subPath node_modules-relative sub-path to look for + * @param {(found: string | null) => void} callback receives the found path or null + * @returns {void} + */ + _findExtendsInNodeModules( + resolver: Resolver, + startDir: string, + subPath: string, + callback: (found: string | null) => void, + ): void; + /** + * Load referenced tsconfig projects and store in referenceMatchMap + * Simple implementation matching tsconfig-paths-webpack-plugin: + * Just load each reference and store independently + * @param {Resolver} resolver the resolver + * @param {string} context the context + * @param {TsconfigReference[]} references array of references + * @param {Set} fileDependencies the file dependencies + * @param {{ [baseUrl: string]: TsconfigPathsData }} referenceMatchMap the map to populate + * @param {(err: Error | null) => void} callback callback + * @param {Set=} visitedRefPaths visited reference config paths (for circular reference detection) + * @returns {void} + */ + _loadTsconfigReferences( + resolver: Resolver, + context: string, + references: TsconfigReference[], + fileDependencies: Set, + referenceMatchMap: { + [baseUrl: string]: TsconfigPathsData; + }, + callback: (err: Error | null) => void, + visitedRefPaths?: Set | undefined, + ): void; + /** + * Load tsconfig.json with extends support + * @param {Resolver} resolver the resolver + * @param {string} configFilePath absolute path to tsconfig.json + * @param {Set} fileDependencies the file dependencies + * @param {Set | undefined} visitedConfigPaths config paths being loaded (for circular extends detection) + * @param {(err: Error | null, result?: Tsconfig) => void} callback callback + * @returns {void} + */ + _loadTsconfig( + resolver: Resolver, + configFilePath: string, + fileDependencies: Set, + visitedConfigPaths: Set | undefined, + callback: (err: Error | null, result?: Tsconfig) => void, + ): void; } declare namespace TsconfigPathsPlugin { - export { Resolver, ResolveStepHook, AliasOption, ResolveRequest, ResolveContext, FileSystem, TsconfigPathsData, TsconfigPathsMap, TsconfigOptions, TsconfigCompilerOptions, TsconfigReference, Tsconfig }; + export { + Resolver, + ResolveStepHook, + AliasOption, + ResolveRequest, + ResolveContext, + FileSystem, + TsconfigPathsData, + TsconfigPathsMap, + TsconfigOptions, + TsconfigCompilerOptions, + TsconfigReference, + Tsconfig, + }; } type Resolver = import("./Resolver"); type ResolveStepHook = import("./Resolver").ResolveStepHook; @@ -114,34 +169,36 @@ type TsconfigPathsData = import("./Resolver").TsconfigPathsData; type TsconfigPathsMap = import("./Resolver").TsconfigPathsMap; type TsconfigOptions = import("./ResolverFactory").TsconfigOptions; type TsconfigCompilerOptions = { - /** - * Base URL for resolving paths - */ - baseUrl?: string | undefined; - /** - * TypeScript paths mapping - */ - paths?: { - [key: string]: string[]; - } | undefined; + /** + * Base URL for resolving paths + */ + baseUrl?: string | undefined; + /** + * TypeScript paths mapping + */ + paths?: + | { + [key: string]: string[]; + } + | undefined; }; type TsconfigReference = { - /** - * Path to the referenced project - */ - path: string; + /** + * Path to the referenced project + */ + path: string; }; type Tsconfig = { - /** - * Compiler options - */ - compilerOptions?: TsconfigCompilerOptions | undefined; - /** - * Extended configuration paths - */ - extends?: (string | string[]) | undefined; - /** - * Project references - */ - references?: TsconfigReference[] | undefined; + /** + * Compiler options + */ + compilerOptions?: TsconfigCompilerOptions | undefined; + /** + * Extended configuration paths + */ + extends?: (string | string[]) | undefined; + /** + * Project references + */ + references?: TsconfigReference[] | undefined; }; diff --git a/types/UnsafeCachePlugin.d.ts b/types/UnsafeCachePlugin.d.ts index 5a0a47f6..efb46b72 100644 --- a/types/UnsafeCachePlugin.d.ts +++ b/types/UnsafeCachePlugin.d.ts @@ -1,31 +1,43 @@ export = UnsafeCachePlugin; declare class UnsafeCachePlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {(request: ResolveRequest) => boolean} filterPredicate filterPredicate - * @param {Cache} cache cache - * @param {boolean} withContext withContext - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, filterPredicate: (request: ResolveRequest) => boolean, cache: Cache, withContext: boolean, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - filterPredicate: (request: ResolveRequest) => boolean; - withContext: boolean; - cache: Cache; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {(request: ResolveRequest) => boolean} filterPredicate filterPredicate + * @param {Cache} cache cache + * @param {boolean} withContext withContext + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + filterPredicate: (request: ResolveRequest) => boolean, + cache: Cache, + withContext: boolean, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + filterPredicate: (request: ResolveRequest) => boolean; + withContext: boolean; + cache: Cache; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace UnsafeCachePlugin { - export { Resolver, ResolveRequest, ResolveStepHook, ResolveContextYield, Cache }; + export { + Resolver, + ResolveRequest, + ResolveStepHook, + ResolveContextYield, + Cache, + }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; type ResolveStepHook = import("./Resolver").ResolveStepHook; type ResolveContextYield = import("./Resolver").ResolveContextYield; type Cache = { - [k: string]: undefined | ResolveRequest | ResolveRequest[]; + [k: string]: undefined | ResolveRequest | ResolveRequest[]; }; diff --git a/types/UseFilePlugin.d.ts b/types/UseFilePlugin.d.ts index ce9a25b4..58fb9403 100644 --- a/types/UseFilePlugin.d.ts +++ b/types/UseFilePlugin.d.ts @@ -1,22 +1,26 @@ export = UseFilePlugin; declare class UseFilePlugin { - /** - * @param {string | ResolveStepHook} source source - * @param {string} filename filename - * @param {string | ResolveStepHook} target target - */ - constructor(source: string | ResolveStepHook, filename: string, target: string | ResolveStepHook); - source: string | import("./Resolver").ResolveStepHook; - filename: string; - target: string | import("./Resolver").ResolveStepHook; - /** - * @param {Resolver} resolver the resolver - * @returns {void} - */ - apply(resolver: Resolver): void; + /** + * @param {string | ResolveStepHook} source source + * @param {string} filename filename + * @param {string | ResolveStepHook} target target + */ + constructor( + source: string | ResolveStepHook, + filename: string, + target: string | ResolveStepHook, + ); + source: string | import("./Resolver").ResolveStepHook; + filename: string; + target: string | import("./Resolver").ResolveStepHook; + /** + * @param {Resolver} resolver the resolver + * @returns {void} + */ + apply(resolver: Resolver): void; } declare namespace UseFilePlugin { - export { Resolver, ResolveRequest, ResolveStepHook }; + export { Resolver, ResolveRequest, ResolveStepHook }; } type Resolver = import("./Resolver"); type ResolveRequest = import("./Resolver").ResolveRequest; diff --git a/types/createInnerContext.d.ts b/types/createInnerContext.d.ts index dc91f848..25c4bf42 100644 --- a/types/createInnerContext.d.ts +++ b/types/createInnerContext.d.ts @@ -1,6 +1,10 @@ declare namespace _exports { - export { ResolveContext }; + export { ResolveContext }; } -declare function _exports(parent: ResolveContext, stack: ResolveContext["stack"], message: null | string): ResolveContext; +declare function _exports( + parent: ResolveContext, + stack: ResolveContext["stack"], + message: null | string, +): ResolveContext; export = _exports; type ResolveContext = import("./Resolver").ResolveContext; diff --git a/types/forEachBail.d.ts b/types/forEachBail.d.ts index 4ed4625c..472cae06 100644 --- a/types/forEachBail.d.ts +++ b/types/forEachBail.d.ts @@ -1,7 +1,15 @@ declare namespace _exports { - export { ResolveRequest, Iterator }; + export { ResolveRequest, Iterator }; } -declare function _exports(array: T[], iterator: Iterator, callback: (err?: null | Error, result?: null | Z, i?: number) => void): void; +declare function _exports( + array: T[], + iterator: Iterator, + callback: (err?: null | Error, result?: null | Z, i?: number) => void, +): void; export = _exports; type ResolveRequest = import("./Resolver").ResolveRequest; -type Iterator = (item: T, callback: (err?: null | Error, result?: null | Z) => void, i: number) => void; +type Iterator = ( + item: T, + callback: (err?: null | Error, result?: null | Z) => void, + i: number, +) => void; diff --git a/types/getInnerRequest.d.ts b/types/getInnerRequest.d.ts index a6e1899a..1271b98b 100644 --- a/types/getInnerRequest.d.ts +++ b/types/getInnerRequest.d.ts @@ -1,5 +1,5 @@ declare namespace _exports { - export { Resolver, ResolveRequest }; + export { Resolver, ResolveRequest }; } declare function _exports(resolver: Resolver, request: ResolveRequest): string; export = _exports; diff --git a/types/getPaths.d.ts b/types/getPaths.d.ts index 8107d24d..f7fe471a 100644 --- a/types/getPaths.d.ts +++ b/types/getPaths.d.ts @@ -13,7 +13,7 @@ export = getPaths; */ declare function getPaths(path: string): GetPathsResult; declare namespace getPaths { - export { getPathsCached, FileSystem, GetPathsResult }; + export { getPathsCached, FileSystem, GetPathsResult }; } /** * Memoized `getPaths`. The returned object is shared across callers — do @@ -23,9 +23,12 @@ declare namespace getPaths { * @param {string} path path * @returns {GetPathsResult} paths and segments */ -declare function getPathsCached(fileSystem: FileSystem, path: string): GetPathsResult; +declare function getPathsCached( + fileSystem: FileSystem, + path: string, +): GetPathsResult; type FileSystem = import("./Resolver").FileSystem; type GetPathsResult = { - paths: string[]; - segments: string[]; + paths: string[]; + segments: string[]; }; diff --git a/types/index.d.ts b/types/index.d.ts index 1c84698d..7b7e2fab 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,22 +1,47 @@ declare namespace _exports { - export { ResolveOptionsOptionalFS, CachedInputFileSystem, BaseFileSystem, CloneBasenamePlugin, LogInfoPlugin, PnpApi, Resolver, Context, FileSystem, ResolveCallback, ResolveContext, ResolveRequest, SyncFileSystem, Plugin, ResolveOptions, TsconfigPathsPlugin, ResolveFunctionAsync, ResolveFunction, ResolveFunctionPromise }; + export { + ResolveOptionsOptionalFS, + CachedInputFileSystem, + BaseFileSystem, + CloneBasenamePlugin, + LogInfoPlugin, + PnpApi, + Resolver, + Context, + FileSystem, + ResolveCallback, + ResolveContext, + ResolveRequest, + SyncFileSystem, + Plugin, + ResolveOptions, + TsconfigPathsPlugin, + ResolveFunctionAsync, + ResolveFunction, + ResolveFunctionPromise, + }; } declare const _exports: ResolveFunctionAsync & { - readonly sync: ResolveFunction; - readonly promise: ResolveFunctionPromise; - create: typeof create & { - readonly sync: typeof createSync; - readonly promise: typeof createPromise; - }; - readonly ResolverFactory: typeof import("./ResolverFactory"); - readonly CachedInputFileSystem: typeof import("./CachedInputFileSystem"); - readonly CloneBasenamePlugin: typeof import("./CloneBasenamePlugin"); - readonly LogInfoPlugin: typeof import("./LogInfoPlugin"); - readonly TsconfigPathsPlugin: typeof import("./TsconfigPathsPlugin"); - readonly forEachBail: (array: T[], iterator: import("./forEachBail").Iterator, callback: (err?: null | Error, result?: null | Z, i?: number) => void) => void; + readonly sync: ResolveFunction; + readonly promise: ResolveFunctionPromise; + create: typeof create & { + readonly sync: typeof createSync; + readonly promise: typeof createPromise; + }; + readonly ResolverFactory: typeof import("./ResolverFactory"); + readonly CachedInputFileSystem: typeof import("./CachedInputFileSystem"); + readonly CloneBasenamePlugin: typeof import("./CloneBasenamePlugin"); + readonly LogInfoPlugin: typeof import("./LogInfoPlugin"); + readonly TsconfigPathsPlugin: typeof import("./TsconfigPathsPlugin"); + readonly forEachBail: ( + array: T[], + iterator: import("./forEachBail").Iterator, + callback: (err?: null | Error, result?: null | Z, i?: number) => void, + ) => void; }; export = _exports; -type ResolveOptionsOptionalFS = Omit & Partial>; +type ResolveOptionsOptionalFS = Omit & + Partial>; type CachedInputFileSystem = import("./CachedInputFileSystem"); type BaseFileSystem = import("./CachedInputFileSystem").BaseFileSystem; type CloneBasenamePlugin = import("./CloneBasenamePlugin"); @@ -33,25 +58,65 @@ type Plugin = import("./ResolverFactory").Plugin; type ResolveOptions = import("./ResolverFactory").UserResolveOptions; type TsconfigPathsPlugin = import("./TsconfigPathsPlugin"); type ResolveFunctionAsync = { - (context: Context, parent: string | URL, specifier: string | URL, resolveContext: ResolveContext, callback: ResolveCallback): void; - (context: Context, parent: string | URL, specifier: string | URL, callback: ResolveCallback): void; - (parent: string | URL, specifier: string | URL, resolveContext: ResolveContext, callback: ResolveCallback): void; - (parent: string | URL, specifier: string | URL, callback: ResolveCallback): void; + ( + context: Context, + parent: string | URL, + specifier: string | URL, + resolveContext: ResolveContext, + callback: ResolveCallback, + ): void; + ( + context: Context, + parent: string | URL, + specifier: string | URL, + callback: ResolveCallback, + ): void; + ( + parent: string | URL, + specifier: string | URL, + resolveContext: ResolveContext, + callback: ResolveCallback, + ): void; + ( + parent: string | URL, + specifier: string | URL, + callback: ResolveCallback, + ): void; }; type ResolveFunction = { - (context: Context, parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext): string | false; - (parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext): string | false; + ( + context: Context, + parent: string | URL, + specifier: string | URL, + resolveContext?: ResolveContext, + ): string | false; + ( + parent: string | URL, + specifier: string | URL, + resolveContext?: ResolveContext, + ): string | false; }; type ResolveFunctionPromise = { - (context: Context, parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext): Promise; - (parent: string | URL, specifier: string | URL, resolveContext?: ResolveContext): Promise; + ( + context: Context, + parent: string | URL, + specifier: string | URL, + resolveContext?: ResolveContext, + ): Promise; + ( + parent: string | URL, + specifier: string | URL, + resolveContext?: ResolveContext, + ): Promise; }; /** @typedef {Omit & Partial>} ResolveOptionsOptionalFS */ /** * @param {ResolveOptionsOptionalFS} options Resolver options * @returns {ResolveFunctionAsync} Resolver function */ -declare function create(options: ResolveOptionsOptionalFS): ResolveFunctionAsync; +declare function create( + options: ResolveOptionsOptionalFS, +): ResolveFunctionAsync; /** * @param {ResolveOptionsOptionalFS} options Resolver options * @returns {ResolveFunction} Resolver function @@ -61,4 +126,6 @@ declare function createSync(options: ResolveOptionsOptionalFS): ResolveFunction; * @param {ResolveOptionsOptionalFS} options Resolver options * @returns {ResolveFunctionPromise} Resolver function */ -declare function createPromise(options: ResolveOptionsOptionalFS): ResolveFunctionPromise; +declare function createPromise( + options: ResolveOptionsOptionalFS, +): ResolveFunctionPromise; diff --git a/types/util/entrypoints.d.ts b/types/util/entrypoints.d.ts index 3a28a065..15091184 100644 --- a/types/util/entrypoints.d.ts +++ b/types/util/entrypoints.d.ts @@ -2,52 +2,57 @@ export function processExportsField(exportsField: ExportsField): FieldProcessor; export function processImportsField(importsField: ImportsField): FieldProcessor; export type DirectMapping = string | (string | ConditionalMapping)[]; export type ConditionalMapping = { - [k: string]: MappingValue; + [k: string]: MappingValue; }; export type MappingValue = ConditionalMapping | DirectMapping | null; -export type ExportsField = Record | ConditionalMapping | DirectMapping; +export type ExportsField = + Record | ConditionalMapping | DirectMapping; export type ImportsField = Record; /** * Processing exports/imports field */ -export type FieldProcessor = (request: string, conditionNames: Set) => [string[], string | null]; +export type FieldProcessor = ( + request: string, + conditionNames: Set, +) => [string[], string | null]; export type RecordMapping = Record; /** * Per-key precomputed info used by `findMatch`. Equivalent to what the * previous implementation recomputed inline on every resolve. */ export type FieldKeyInfo = { - /** - * the original key - */ - key: string; - /** - * position of the single "*" in the key, or -1 when absent - */ - patternIndex: number; - /** - * substring before "*" (empty when patternIndex === -1) - */ - wildcardPrefix: string; - /** - * substring after "*" (empty when patternIndex === -1) - */ - wildcardSuffix: string; - /** - * true when key is a legacy `./foo/`-style folder key with no "*" - */ - isLegacySubpath: boolean; - /** - * true when key contains "*" - */ - isPattern: boolean; - /** - * true when key ends with "/" - */ - isSubpathMapping: boolean; - /** - * true when key has at most one "*" - */ - isValidPattern: boolean; + /** + * the original key + */ + key: string; + /** + * position of the single "*" in the key, or -1 when absent + */ + patternIndex: number; + /** + * substring before "*" (empty when patternIndex === -1) + */ + wildcardPrefix: string; + /** + * substring after "*" (empty when patternIndex === -1) + */ + wildcardSuffix: string; + /** + * true when key is a legacy `./foo/`-style folder key with no "*" + */ + isLegacySubpath: boolean; + /** + * true when key contains "*" + */ + isPattern: boolean; + /** + * true when key ends with "/" + */ + isSubpathMapping: boolean; + /** + * true when key has at most one "*" + */ + isValidPattern: boolean; }; -export type MatchTuple = [MappingValue, string, boolean, boolean, string] | null; +export type MatchTuple = + [MappingValue, string, boolean, boolean, string] | null; diff --git a/types/util/fileURLToPath.d.ts b/types/util/fileURLToPath.d.ts index 04e6b3fc..a217605c 100644 --- a/types/util/fileURLToPath.d.ts +++ b/types/util/fileURLToPath.d.ts @@ -4,6 +4,11 @@ export = fileURLToPath; * @param {{ windows?: boolean }=} options force the platform branch * @returns {string} the filesystem path */ -declare function fileURLToPath(path: string | URL, options?: { - windows?: boolean; -} | undefined): string; +declare function fileURLToPath( + path: string | URL, + options?: + | { + windows?: boolean; + } + | undefined, +): string; diff --git a/types/util/fs.d.ts b/types/util/fs.d.ts index 31c516ea..b191ce2a 100644 --- a/types/util/fs.d.ts +++ b/types/util/fs.d.ts @@ -1,10 +1,10 @@ export type FileSystem = import("../Resolver").FileSystem; export type JsonObject = import("../Resolver").JsonObject; export type ReadJsonOptions = { - /** - * Whether to strip JSONC comments - */ - stripComments?: boolean | undefined; + /** + * Whether to strip JSONC comments + */ + stripComments?: boolean | undefined; }; /** * Decode a file's raw contents to text without assuming a Node runtime. A @@ -27,4 +27,12 @@ export function decodeText(data: string | Buffer | Uint8Array): string; * @param {(err: NodeJS.ErrnoException | Error | null, content?: JsonObject) => void} callback callback * @returns {void} */ -export function readJson(fileSystem: FileSystem, jsonFilePath: string, options: ReadJsonOptions, callback: (err: NodeJS.ErrnoException | Error | null, content?: JsonObject) => void): void; +export function readJson( + fileSystem: FileSystem, + jsonFilePath: string, + options: ReadJsonOptions, + callback: ( + err: NodeJS.ErrnoException | Error | null, + content?: JsonObject, + ) => void, +): void; diff --git a/types/util/graceful-fs-browser.d.ts b/types/util/graceful-fs-browser.d.ts index 066af568..13331336 100644 --- a/types/util/graceful-fs-browser.d.ts +++ b/types/util/graceful-fs-browser.d.ts @@ -2,4 +2,17 @@ * @returns {never} always throws */ declare function unavailable(): never; -export { unavailable as lstat, unavailable as lstatSync, unavailable as readFile, unavailable as readFileSync, unavailable as readdir, unavailable as readdirSync, unavailable as readlink, unavailable as readlinkSync, unavailable as realpath, unavailable as realpathSync, unavailable as stat, unavailable as statSync }; +export { + unavailable as lstat, + unavailable as lstatSync, + unavailable as readFile, + unavailable as readFileSync, + unavailable as readdir, + unavailable as readdirSync, + unavailable as readlink, + unavailable as readlinkSync, + unavailable as realpath, + unavailable as realpathSync, + unavailable as stat, + unavailable as statSync, +}; diff --git a/types/util/identifier.d.ts b/types/util/identifier.d.ts index f0265975..99644890 100644 --- a/types/util/identifier.d.ts +++ b/types/util/identifier.d.ts @@ -2,4 +2,6 @@ * @param {string} identifier identifier * @returns {[string, string, string] | null} parsed identifier */ -export function parseIdentifier(identifier: string): [string, string, string] | null; +export function parseIdentifier( + identifier: string, +): [string, string, string] | null; diff --git a/types/util/memoize.d.ts b/types/util/memoize.d.ts index 3441c81e..4ada2d11 100644 --- a/types/util/memoize.d.ts +++ b/types/util/memoize.d.ts @@ -10,6 +10,6 @@ export = memoize; */ declare function memoize(fn: FunctionReturning): FunctionReturning; declare namespace memoize { - export { FunctionReturning }; + export { FunctionReturning }; } type FunctionReturning = () => T; diff --git a/types/util/packageMap.d.ts b/types/util/packageMap.d.ts index 805c1e50..deca530c 100644 --- a/types/util/packageMap.d.ts +++ b/types/util/packageMap.d.ts @@ -1,58 +1,58 @@ export type JsonObject = import("../Resolver").JsonObject; export type PackageMapDependencies = { - [specifier: string]: string; + [specifier: string]: string; }; /** * A single entry of the configuration file's `packages` object. */ export type PackageMapPackage = { - /** - * an absolute or relative `file:` URL, resolved against the configuration file - */ - url: string; - /** - * bare specifier to package id - */ - dependencies?: PackageMapDependencies | undefined; + /** + * an absolute or relative `file:` URL, resolved against the configuration file + */ + url: string; + /** + * bare specifier to package id + */ + dependencies?: PackageMapDependencies | undefined; }; export type PackageMapPackages = { - [id: string]: PackageMapPackage; + [id: string]: PackageMapPackage; }; /** * The parsed contents of a package map configuration file. */ export type PackageMapJson = { - /** - * package entries by package id - */ - packages: PackageMapPackages; + /** + * package entries by package id + */ + packages: PackageMapPackages; }; export type PackageMapEntry = { - /** - * the package id this entry is keyed by - */ - id: string; - /** - * absolute filesystem path the entry's `url` points at - */ - path: string; - /** - * bare specifier to package id - */ - dependencies: Map; + /** + * the package id this entry is keyed by + */ + id: string; + /** + * absolute filesystem path the entry's `url` points at + */ + path: string; + /** + * bare specifier to package id + */ + dependencies: Map; }; export type PackageMap = { - /** - * entries by package id - */ - packages: Map; - /** - * package ids by location, longest path first - */ - locations: { - path: string; - ids: string[]; - }[]; + /** + * entries by package id + */ + packages: Map; + /** + * package ids by location, longest path first + */ + locations: { + path: string; + ids: string[]; + }[]; }; /** @typedef {import("../Resolver").JsonObject} JsonObject */ /** @typedef {{ [specifier: string]: string }} PackageMapDependencies */ @@ -84,8 +84,11 @@ export type PackageMap = { * @param {string} code error code * @returns {Error & { code: string }} the error */ -export function createError(message: string, code: string): Error & { - code: string; +export function createError( + message: string, + code: string, +): Error & { + code: string; }; /** * Find the package ids whose location contains `filePath`. More than one id is @@ -95,7 +98,10 @@ export function createError(message: string, code: string): Error & { * @param {string} filePath an absolute filesystem path * @returns {string[]} the matching package ids, empty when the path is outside every package */ -export function findPackageIds(packageMap: PackageMap, filePath: string): string[]; +export function findPackageIds( + packageMap: PackageMap, + filePath: string, +): string[]; /** * Parse and validate a package map configuration file. * @@ -106,4 +112,7 @@ export function findPackageIds(packageMap: PackageMap, filePath: string): string * @param {string} configFilePath absolute path of the configuration file, used as the base for relative urls * @returns {PackageMap} the parsed package map */ -export function parsePackageMap(data: JsonObject, configFilePath: string): PackageMap; +export function parsePackageMap( + data: JsonObject, + configFilePath: string, +): PackageMap; diff --git a/types/util/path-browser.d.ts b/types/util/path-browser.d.ts index fe8556d8..05a5d220 100644 --- a/types/util/path-browser.d.ts +++ b/types/util/path-browser.d.ts @@ -35,11 +35,11 @@ declare function win32Normalize(path: string): string; */ declare function win32Dirname(path: string): string; export declare namespace posix { - export { posixNormalize as normalize }; - export { posixDirname as dirname }; + export { posixNormalize as normalize }; + export { posixDirname as dirname }; } export declare namespace win32 { - export { win32Normalize as normalize }; - export { win32Dirname as dirname }; + export { win32Normalize as normalize }; + export { win32Dirname as dirname }; } export {}; diff --git a/types/util/path.d.ts b/types/util/path.d.ts index 91d4ee55..572770b9 100644 --- a/types/util/path.d.ts +++ b/types/util/path.d.ts @@ -1,26 +1,26 @@ export type CachedJoin = { - fn: (rootPath: string, request: string) => string; - cache: Map>; + fn: (rootPath: string, request: string) => string; + cache: Map>; }; export type CachedDirname = { - fn: (maybePath: string) => string; - cache: Map; + fn: (maybePath: string) => string; + cache: Map; }; export type CachedBasename = { - fn: (maybePath: string, suffix?: string) => string; - cache: Map>; + fn: (maybePath: string, suffix?: string) => string; + cache: Map>; }; export type PathType = number; /** * @enum {number} */ export const PathType: Readonly<{ - Empty: 0; - Normal: 1; - Relative: 2; - AbsoluteWin: 3; - AbsolutePosix: 4; - Internal: 5; + Empty: 0; + Normal: 1; + Relative: 2; + AbsoluteWin: 3; + AbsolutePosix: 4; + Internal: 5; }>; /** @typedef {{ fn: (maybePath: string, suffix?: string) => string, cache: Map> }} CachedBasename */ /** diff --git a/types/util/pathToFileURL.d.ts b/types/util/pathToFileURL.d.ts index 7780e0c4..a12d55e3 100644 --- a/types/util/pathToFileURL.d.ts +++ b/types/util/pathToFileURL.d.ts @@ -4,6 +4,11 @@ export = pathToFileURL; * @param {{ windows?: boolean }=} options force the platform branch * @returns {URL} the `file:` URL */ -declare function pathToFileURL(filepath: string, options?: { - windows?: boolean; -} | undefined): URL; +declare function pathToFileURL( + filepath: string, + options?: + | { + windows?: boolean; + } + | undefined, +): URL; diff --git a/types/util/strip-json-comments.d.ts b/types/util/strip-json-comments.d.ts index 6d294f8a..cef87e3f 100644 --- a/types/util/strip-json-comments.d.ts +++ b/types/util/strip-json-comments.d.ts @@ -5,17 +5,20 @@ export = stripJsonComments; * @param {StripJsonCommentsOptions} options Options * @returns {string} JSON string without comments */ -declare function stripJsonComments(jsonString: string, { whitespace, trailingCommas }?: StripJsonCommentsOptions): string; +declare function stripJsonComments( + jsonString: string, + { whitespace, trailingCommas }?: StripJsonCommentsOptions, +): string; declare namespace stripJsonComments { - export { StripJsonCommentsOptions }; + export { StripJsonCommentsOptions }; } type StripJsonCommentsOptions = { - /** - * Replace comments with whitespace - */ - whitespace?: boolean | undefined; - /** - * Strip trailing commas - */ - trailingCommas?: boolean | undefined; + /** + * Replace comments with whitespace + */ + whitespace?: boolean | undefined; + /** + * Strip trailing commas + */ + trailingCommas?: boolean | undefined; }; From cfe266bd409f4ae16fd4713d2b05384fe20cdaf4 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Sat, 19 Sep 2026 14:20:51 +0000 Subject: [PATCH 3/4] fix: address the review findings on the generated types Three findings from the review on #675, each verified against the sources before changing anything: `scripts/build-types.js` ran the `node_modules/.bin` shims, which are `.cmd` files on Windows and so needed `shell: true`. A shell receives the command line verbatim, so a checkout under a path containing a space would not start - `C:\Users\Jane Doe\...` splits at the space. It now runs each tool's JavaScript entry point under `process.execPath`, with no shell and nothing to quote. The browser stub for `graceful-fs` declared `unavailable()` with no parameters, so the declaration this package now ships rejected the calls its own callers make: `readFile(path, callback)` did not compile for anyone importing the subpath. It takes a rest parameter now. Every alias still throws; only the declared arity changed. `PackageMapOptions.configFile` was `string | null`, but the only code that constructs `PackageMapPlugin` is `normalizePackageMap`, which throws unless a config file is given - the property is never null in practice, which is why reading it needed a cast. Narrowing it to `string` makes the declaration honest and removes the cast. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_016aGHrb1YaEvaGwNELGEHjF --- lib/PackageMapPlugin.js | 4 ++-- lib/util/graceful-fs-browser.js | 6 +++++- scripts/build-types.js | 33 ++++++++++++++++------------- types/PackageMapPlugin.d.ts | 2 +- types/util/graceful-fs-browser.d.ts | 6 +++++- 5 files changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/PackageMapPlugin.js b/lib/PackageMapPlugin.js index 12592510..39377b33 100644 --- a/lib/PackageMapPlugin.js +++ b/lib/PackageMapPlugin.js @@ -20,7 +20,7 @@ const { /** * @typedef {object} PackageMapOptions - * @property {string | null} configFile absolute path of the configuration file, read lazily when `packages` is not given + * @property {string} configFile absolute path of the configuration file, read lazily when `packages` is not given * @property {PackageMapPackages | null} packages an already-parsed `packages` object, used instead of reading `configFile` */ @@ -159,7 +159,7 @@ module.exports = class PackageMapPlugin { * @returns {void} */ _resolveConfigFile(resolver, callback) { - const { configFile } = /** @type {{ configFile: string }} */ (this.options); + const { configFile } = this.options; const { realpath } = resolver.fileSystem; if (!this.symlinks || !realpath) return callback(configFile); diff --git a/lib/util/graceful-fs-browser.js b/lib/util/graceful-fs-browser.js index 1dda4f00..63210c8f 100644 --- a/lib/util/graceful-fs-browser.js +++ b/lib/util/graceful-fs-browser.js @@ -16,9 +16,13 @@ const message = "Pass a `fileSystem` to `create()` or `ResolverFactory.createResolver()`."; /** + * Takes the arguments its callers pass - `readFile(path, callback)` and the + * rest - so the declaration describes a call that actually compiles, even + * though every one of them throws. + * @param {...unknown} _args arguments, ignored * @returns {never} always throws */ -const unavailable = () => { +const unavailable = (..._args) => { throw new Error(message); }; diff --git a/scripts/build-types.js b/scripts/build-types.js index 54d3a01d..879f38ce 100644 --- a/scripts/build-types.js +++ b/scripts/build-types.js @@ -16,30 +16,33 @@ const path = require("path"); const root = path.join(__dirname, ".."); /** - * @param {string} command binary to run, relative to `node_modules/.bin` + * Runs a tool's JavaScript entry point under this Node.js, rather than its + * `node_modules/.bin` shim. The shims are `.cmd` files on Windows, which need + * a shell to run - and a shell gets the command line verbatim, so a checkout + * under a path containing a space would not start. + * @param {string} entry module path of the tool's entry point * @param {string[]} args arguments * @returns {void} */ -const run = (command, args) => { - const binary = path.join( - root, - "node_modules", - ".bin", - process.platform === "win32" ? `${command}.cmd` : command, +const run = (entry, args) => { + const { status } = spawnSync( + process.execPath, + [require.resolve(entry), ...args], + { cwd: root, stdio: "inherit" }, ); - const { status } = spawnSync(binary, args, { - cwd: root, - stdio: "inherit", - shell: process.platform === "win32", - }); if (status !== 0) { throw new Error( - `${command} exited with ${status === null ? "a signal" : status}`, + `${entry} exited with ${status === null ? "a signal" : status}`, ); } }; rmSync(path.join(root, "types"), { recursive: true, force: true }); -run("tsc", ["-p", "tsconfig.types.json"]); -run("prettier", ["--log-level", "warn", "--write", "types/**/*.d.ts"]); +run("typescript/bin/tsc", ["-p", "tsconfig.types.json"]); +run("prettier/bin/prettier.cjs", [ + "--log-level", + "warn", + "--write", + "types/**/*.d.ts", +]); diff --git a/types/PackageMapPlugin.d.ts b/types/PackageMapPlugin.d.ts index 5d7a7a23..76a3777d 100644 --- a/types/PackageMapPlugin.d.ts +++ b/types/PackageMapPlugin.d.ts @@ -76,7 +76,7 @@ type PackageMapOptions = { /** * absolute path of the configuration file, read lazily when `packages` is not given */ - configFile: string | null; + configFile: string; /** * an already-parsed `packages` object, used instead of reading `configFile` */ diff --git a/types/util/graceful-fs-browser.d.ts b/types/util/graceful-fs-browser.d.ts index 13331336..a8ee8eb8 100644 --- a/types/util/graceful-fs-browser.d.ts +++ b/types/util/graceful-fs-browser.d.ts @@ -1,7 +1,11 @@ /** + * Takes the arguments its callers pass - `readFile(path, callback)` and the + * rest - so the declaration describes a call that actually compiles, even + * though every one of them throws. + * @param {...unknown} _args arguments, ignored * @returns {never} always throws */ -declare function unavailable(): never; +declare function unavailable(..._args: unknown[]): never; export { unavailable as lstat, unavailable as lstatSync, From cf0ffcb5feef8aee41cb564c0fc1db24baa9e70b Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Sun, 20 Sep 2026 22:49:43 +0000 Subject: [PATCH 4/4] refactor: generate the types straight from package.json `scripts/build-types.js` existed to run `tsc` and `prettier` and to clear `types/` first. npm already puts both binaries on PATH and handles the Windows shims, so the script bought nothing that a script field cannot do, and the clearing is one `node -e` away: "build:types": "node -e \"require('fs').rmSync('types', { recursive: true, force: true })\" && tsc -p tsconfig.types.json && prettier --log-level warn --write \"types/**/*.d.ts\"" That also settles the Windows quoting the review raised, further up the stack than the previous fix: npm invokes the tools, so there is no `spawnSync` of ours to get wrong. `test/types/surface.ts` and `lint:types-api` are gone too. They guarded against an export silently disappearing, but the `@typedef` re-exports in `lib/index.js` are already that guard: they are what TypeScript emits the export list from, `types/` is generated and committed, and CI regenerates and diffs it. Dropping a typedef therefore changes a committed file and fails the `Check types` step - a second copy of the API in a test file was restating what the sources already say. Verified rather than assumed: `lib/index.js` declares 19 typedefs, `types/index.d.ts` exports exactly those 19, and they are exactly the 19 names `webpack/tooling` exported at 332d999 - nothing lost, nothing added. Deleting the `ResolveRequest` typedef drops it from the declarations entirely and shows up as a modified `types/index.d.ts`. A consumer installed from `npm pack` imports all 19, including the four plugin classes in type position, and compiles. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_016aGHrb1YaEvaGwNELGEHjF --- eslint.config.mjs | 10 +--- package.json | 5 +- scripts/build-types.js | 48 ------------------ test/types/surface.ts | 109 ---------------------------------------- tsconfig.types.api.json | 11 ---- 5 files changed, 3 insertions(+), 180 deletions(-) delete mode 100644 scripts/build-types.js delete mode 100644 test/types/surface.ts delete mode 100644 tsconfig.types.api.json diff --git a/eslint.config.mjs b/eslint.config.mjs index 02ac9b4e..d4a3e6c4 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -2,7 +2,7 @@ import { defineConfig, globalIgnores } from "eslint/config"; import config from "eslint-config-webpack"; export default defineConfig([ - globalIgnores(["benchmark/**/fixture/**", "test/types/**", "types/**"]), + globalIgnores(["benchmark/**/fixture/**", "types/**"]), { extends: [config], }, @@ -46,14 +46,6 @@ export default defineConfig([ "no-console": "off", }, }, - { - // Repo-local development scripts run on the contributor's Node.js, not on - // the `engines.node` range the published library supports. - files: ["scripts/*.js"], - rules: { - "n/no-unsupported-features/node-builtins": "off", - }, - }, { // The test suite relies on `node:test` and modern `node:assert` helpers, // which are newer than the `engines.node` range the published library diff --git a/package.json b/package.json index 6b986b5d..e48c91af 100644 --- a/package.json +++ b/package.json @@ -26,18 +26,17 @@ ], "scripts": { "prepare": "husky", - "lint": "npm run lint:code && npm run lint:types && npm run lint:types-test && npm run lint:types-api && npm run fmt:check && npm run lint:spellcheck", + "lint": "npm run lint:code && npm run lint:types && npm run lint:types-test && npm run fmt:check && npm run lint:spellcheck", "lint:code": "eslint --cache .", "lint:types": "tsc", "lint:types-test": "tsc -p tsconfig.types.test.json", - "lint:types-api": "tsc -p tsconfig.types.api.json", "lint:spellcheck": "cspell --cache --no-must-find-files --quiet \"**/*.*\"", "fmt": "npm run fmt:base -- --log-level warn --write", "fmt:check": "npm run fmt:base -- --check", "fmt:base": "node_modules/prettier/bin/prettier.cjs --cache --ignore-unknown .", "fix": "npm run fix:code && npm run build:types", "fix:code": "npm run lint:code -- --fix", - "build:types": "node scripts/build-types.js", + "build:types": "node -e \"require('fs').rmSync('types', { recursive: true, force: true })\" && tsc -p tsconfig.types.json && prettier --log-level warn --write \"types/**/*.d.ts\"", "type-report": "rimraf coverage && npm run cover:types && npm run cover:report && open-cli coverage/lcov-report/index.html", "pretest": "npm run lint", "test": "npm run test:only", diff --git a/scripts/build-types.js b/scripts/build-types.js deleted file mode 100644 index 879f38ce..00000000 --- a/scripts/build-types.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; - -// Generates the published type declarations in `types/` from the JSDoc in -// `lib/`, then formats them. CI regenerates and checks `git status types`, so -// a stale checkout fails the `lint` job - see `.github/workflows/test.yml`. -// -// The output directory is removed first. `tsc` overwrites the declarations it -// still emits but never deletes the ones it no longer does, and a leftover -// file is invisible to a `git status` check: it is tracked, unchanged, and -// would keep shipping after its source was gone. - -const { spawnSync } = require("child_process"); -const { rmSync } = require("fs"); -const path = require("path"); - -const root = path.join(__dirname, ".."); - -/** - * Runs a tool's JavaScript entry point under this Node.js, rather than its - * `node_modules/.bin` shim. The shims are `.cmd` files on Windows, which need - * a shell to run - and a shell gets the command line verbatim, so a checkout - * under a path containing a space would not start. - * @param {string} entry module path of the tool's entry point - * @param {string[]} args arguments - * @returns {void} - */ -const run = (entry, args) => { - const { status } = spawnSync( - process.execPath, - [require.resolve(entry), ...args], - { cwd: root, stdio: "inherit" }, - ); - - if (status !== 0) { - throw new Error( - `${entry} exited with ${status === null ? "a signal" : status}`, - ); - } -}; - -rmSync(path.join(root, "types"), { recursive: true, force: true }); -run("typescript/bin/tsc", ["-p", "tsconfig.types.json"]); -run("prettier/bin/prettier.cjs", [ - "--log-level", - "warn", - "--write", - "types/**/*.d.ts", -]); diff --git a/test/types/surface.ts b/test/types/surface.ts deleted file mode 100644 index 291f8a21..00000000 --- a/test/types/surface.ts +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Compile-time guard on the published type surface. - * - * `types/` is generated from the JSDoc in `lib/`, so a typedef that stops being - * re-exported from `lib/index.js` silently disappears from the package's types - * without any other check noticing. Every name below was exported before the - * declarations were generated by TypeScript itself, and each is used both the - * way consumers use it and in the position (type or value) it has to support. - * - * Checked by `npm run lint:types-api`. This file is never executed. - */ - -import resolve = require("enhanced-resolve"); -import { - BaseFileSystem, - Context, - FileSystem, - Plugin, - PnpApi, - ResolveCallback, - ResolveContext, - ResolveFunction, - ResolveFunctionAsync, - ResolveFunctionPromise, - ResolveOptions, - ResolveOptionsOptionalFS, - ResolveRequest, - Resolver, - SyncFileSystem, -} from "enhanced-resolve"; - -// Exported types must be usable in a type position. -declare const baseFileSystem: BaseFileSystem; -declare const context: Context; -declare const fileSystem: FileSystem; -declare const plugin: Plugin; -declare const pnpApi: PnpApi; -declare const resolveCallback: ResolveCallback; -declare const resolveContext: ResolveContext; -declare const resolveFunction: ResolveFunction; -declare const resolveFunctionAsync: ResolveFunctionAsync; -declare const resolveFunctionPromise: ResolveFunctionPromise; -declare const resolveOptions: ResolveOptions; -declare const resolveOptionsOptionalFS: ResolveOptionsOptionalFS; -declare const resolveRequest: ResolveRequest; -declare const resolver: Resolver; -declare const syncFileSystem: SyncFileSystem; - -// The exported classes must be usable as a type and as a constructor. -declare const cachedInputFileSystem: resolve.CachedInputFileSystem; -declare const cloneBasenamePlugin: resolve.CloneBasenamePlugin; -declare const logInfoPlugin: resolve.LogInfoPlugin; -declare const tsconfigPathsPlugin: resolve.TsconfigPathsPlugin; - -new resolve.CachedInputFileSystem(baseFileSystem, 4000); -new resolve.CloneBasenamePlugin("described-resolve", "resolve"); -new resolve.LogInfoPlugin("resolve"); -new resolve.TsconfigPathsPlugin({}); - -// The module itself is callable, in each documented argument shape. -resolve("/parent", "./specifier", resolveCallback); -resolve(context, "/parent", "./specifier", resolveCallback); -resolve("/parent", "./specifier", resolveContext, resolveCallback); -resolve(context, "/parent", "./specifier", resolveContext, resolveCallback); - -const sync: string | false = resolve.sync("/parent", "./specifier"); -const promise: Promise = resolve.promise( - "/parent", - "./specifier", -); - -const created: ResolveFunctionAsync = resolve.create({}); -const createdSync: ResolveFunction = resolve.create.sync({}); -const createdPromise: ResolveFunctionPromise = resolve.create.promise({}); - -const factoryResolver: Resolver = resolve.ResolverFactory.createResolver({ - fileSystem, -}); - -resolve.forEachBail( - [1, 2, 3], - (item, callback) => callback(), - (err, result) => {}, -); - -export { - baseFileSystem, - cachedInputFileSystem, - cloneBasenamePlugin, - context, - created, - createdPromise, - createdSync, - factoryResolver, - logInfoPlugin, - plugin, - pnpApi, - promise, - resolveFunction, - resolveFunctionAsync, - resolveFunctionPromise, - resolveOptions, - resolveOptionsOptionalFS, - resolveRequest, - resolver, - sync, - syncFileSystem, - tsconfigPathsPlugin, -}; diff --git a/tsconfig.types.api.json b/tsconfig.types.api.json deleted file mode 100644 index ed0111ed..00000000 --- a/tsconfig.types.api.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "./tsconfig", - "compilerOptions": { - "allowJs": false, - "checkJs": false, - "paths": { - "enhanced-resolve": ["./types.d.ts"] - } - }, - "include": ["test/types/*.ts"] -}