Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/generate-types-with-typescript.md
Original file line number Diff line number Diff line change
@@ -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.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@ package.json
package-lock.json
test/**/*.*
!test/*.js

# Generated files
types.d.ts
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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/**", "types/**"]),
{
extends: [config],
},
Expand Down
4 changes: 2 additions & 2 deletions lib/PackageMapPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
*/

Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 {{
Expand Down
6 changes: 5 additions & 1 deletion lib/util/graceful-fs-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
Loading
Loading