chore: generate types with the TypeScript CLI instead of tooling - #291
Conversation
`tooling` is deprecated. Declarations are now emitted by `tsc` from the
JSDoc in `lib/` into `types/`, as in webpack-dev-middleware:
npm run build:types
# del-cli types && tsc -p tsconfig.types.json && prettier --write types
CI rebuilds them in the lint job and fails when the committed `types/`
are out of date.
`types.d.ts` stays the package's `types` entry and re-exports the
generated declarations in the same shape as before: every class as value
and type, the same helper types and `util.stringBufferUtils`. It is
type-checked by `lint:types-test`.
`@private` JSDoc tags are removed from `lib/` (no runtime change). `tsc`
emits them as `private` members, which makes TypeScript compare classes
nominally, so two installed copies of this package (even the same
version) would reject each other's instances. Without them the classes
stay structurally typed, as with the previous generated types.
The `inherit-types` and `format-file-header` checks are removed with
`tooling`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ThsbPWvW5vnYWEaFs2Q22F
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ThsbPWvW5vnYWEaFs2Q22F
One or more co-authors of this pull request were not found. You must specify co-authors in commit message trailer via: Supported
Alternatively, if the co-author should not be included, remove the Please update your commit message(s) by doing |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #291 +/- ##
=======================================
Coverage 98.29% 98.30%
=======================================
Files 25 25
Lines 2289 2295 +6
Branches 735 737 +2
=======================================
+ Hits 2250 2256 +6
Misses 37 37
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will regress 8 benchmarks
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. WalkthroughThe change adds declaration files for source classes and helpers, and updates the package declaration entry points. It configures a command to generate and format declarations, includes the generated directory in package files, and adds a CI check for declaration changes. It also removes several Merge Risk: 🟡 Moderate · up to Consumers using older Node type declarations may be unable to type-check the package. Address the generated Buffer types before merging unless that compatibility break is explicitly accepted. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
package.jsonESLint failed to execute (timeout). types.d.tsESLint skipped: the matched ESLint configuration already failed (timeout). types/CachedSource.d.tsESLint skipped: the matched ESLint configuration already failed (timeout).
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: ddbd1764-6fec-4598-864a-c69e04358754
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (40)
.github/workflows/test.ymllib/CachedSource.jslib/CompatSource.jslib/ConcatSource.jslib/OriginalSource.jslib/PrefixSource.jslib/RawSource.jslib/ReplaceSource.jslib/SizeOnlySource.jslib/SourceMapSource.jspackage.jsontest/ReplaceSource.jstsconfig.types.jsontsconfig.types.test.jsontypes.d.tstypes/CachedSource.d.tstypes/CompatSource.d.tstypes/ConcatSource.d.tstypes/OriginalSource.d.tstypes/PrefixSource.d.tstypes/RawSource.d.tstypes/ReplaceSource.d.tstypes/SizeOnlySource.d.tstypes/Source.d.tstypes/SourceMapSource.d.tstypes/helpers/createMappingsSerializer.d.tstypes/helpers/getFromStreamChunks.d.tstypes/helpers/getGeneratedSourceInfo.d.tstypes/helpers/getName.d.tstypes/helpers/getSource.d.tstypes/helpers/readMappings.d.tstypes/helpers/splitIntoLines.d.tstypes/helpers/splitIntoPotentialTokens.d.tstypes/helpers/streamAndGetSourceAndMap.d.tstypes/helpers/streamChunks.d.tstypes/helpers/streamChunksOfCombinedSourceMap.d.tstypes/helpers/streamChunksOfRawSource.d.tstypes/helpers/streamChunksOfSourceMap.d.tstypes/helpers/stringBufferUtils.d.tstypes/index.d.ts
💤 Files with no reviewable changes (10)
- lib/ReplaceSource.js
- lib/CompatSource.js
- lib/RawSource.js
- lib/OriginalSource.js
- lib/SizeOnlySource.js
- lib/ConcatSource.js
- test/ReplaceSource.js
- lib/PrefixSource.js
- lib/SourceMapSource.js
- lib/CachedSource.js
Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.
| _sourceMapAsBuffer: undefined | Buffer; | ||
| _hasOriginalSource: boolean; | ||
| _originalSourceAsString: string | undefined; | ||
| _originalSourceAsBuffer: Buffer<ArrayBufferLike> | undefined; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🌐 Web query:
Which @types/node version made Buffer generic (Buffer<TArrayBuffer>)?
💡 Result:
<source_evidence>
<source>
<title>node: Make `Buffer` generic to align with `Uint8Array`</title>
<location>GitHub pull request 70694 in DefinitelyTyped/DefinitelyTyped (link omitted to avoid creating a cross-reference)</location>
<excerpt># node: Make `Buffer` generic to align with `Uint8Array` ... - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [x] Add or edit tests to reflect the change. - [x] Follow the advice from the readme. - [x] Avoid common mistakes. - [x] Run `pnpm test `. If updating an existing definition: - [x] Provide a URL to documentation or source code which provides context for the suggested changes: https://github.com/microsoft/TypeScript/pull/59417 - [ ] If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the `package.json`. This reintroduces `"typesVersions"` to the node types in what is hopefully a fairly minimal way so as to allow `Buffer` to be generic over `ArrayBufferLike` in the same way that `Uint8Array` is in TypeScript 5.7. This also removes the `WithArrayBufferLike` helper type as it is no longer necessary. ... > "name": "node", > "kind": "edit", ... > "files ... > { > "path": "types/node/buffer.buffer.d.ts", > "kind": "definition" > }, ... > "path": "types/node/buffer.d.ts", > "kind": "definition"</excerpt>
</source>
<source>
<title>972af4c Upgrade `@vscode/test-electron` 2.3.8 → 3.0.0 (with TypeScript 5.9.3) (`#1979`)</title>
<location>https://github.com/databricks/databricks-vscode/commit/972af4cda4824333bfa8f0172ceba0d641b70a75</location>
<excerpt># 972af4c Upgrade `@vscode/test-electron` 2.3.8 → 3.0.0 (with TypeScript 5.9.3) (`#1979`) - SHA: 972af4cda4824333bfa8f0172ceba0d641b70a75 - Repository: databricks/databricks-vscode - Author: rugpanov - Date: 2026-07-07T12:07:36Z - +18 -35 in 2 files - Verified: yes --- Upgrade `@vscode/test-electron` 2.3.8 → 3.0.0 (with TypeScript 5.9.3) (`#1979`) ## Why Dependabot `#1974` bumped `@vscode/test-electron` to 3.0.0 but the one-line `package.json` change **breaks the build**. test-electron 3 ships a `.d.ts` (`out/util.d.ts`) that uses the generic `Buffer ` type, which `@types/node@22` only exposes to **TypeScript >= 5.7** (its `typesVersions` maps TS <=5.6 to a non-generic `Buffer` variant). The repo was pinned to `typescript@^5.3.3`, so tsc reported: ``` error TS2315: Type &`#39`;Buffer&`#39`; is not generic. ``` The bump also left `yarn.lock` out of sync. Rather than mask the mismatch with a repo-wide `skipLibCheck` (which would stop type-checking **all** `.d.ts` files and could hide real dependency type errors), this fixes the **root cause** by raising TypeScript to a version that type-checks test-electron 3&`#39`;s declarations natively. ## What - Bump `@vscode/test-electron` `^2.3.8` → `^3.0.0`. - Bump `typescript` `^5.3.3` → `^5.9.3` (>=5.7 for the generic `Buffer`; stays <6.1.0 so `@typescript-eslint@8`&`#39`;s peer range and `ts-node@10` remain satisfied — TS 6.0 breaks both, tracked separately in `#1975`). - Regenerate `yarn.lock` (also dedupes the previously-split direct `2.3.8` / transitive `2.5.2` test-electron resolutions onto `3.0.0`). Test-only devtooling — no product/user-facing change. test-electron 3&`#39`;s only declared behavioural change over v2 is requiring Node >=22, which the extension already mandates (`engines.node >=22.0`) and CI runs on. ## Verification - `yarn install --immutable` passes (no `YN0028`, no `YN0060`). - `yarn run build` (`tsc --build`) succeeds with **0 errors** under TS 5.9.3 — the generic-Buffer error is resolved natively, no `skipLibCheck`. - `eslint src --ext ts` clean (typescript-eslint@8 handles TS 5.9). - `ts-mocha --type-check` of the `sdk-extensions` integ suite type-checks. - `yarn run test:unit`: **268 passing, 0 failing**. (The pre-existing `ClusterLoader` unhandled-rejection console noise is unrelated and also present on main.) Supersedes `#1974`. This pull request and its description were written by Isaac. --- _This PR was created with GitHub MCP._ ## Changed Files | File | Status | + | - | | --- | --- | --- | --- | | packages/databricks-vscode/package.json | modified | 2 | 2 | | yarn.lock | modified | 16 | 33 |</excerpt>
</source>
<source>
<title>Result 3</title>
<location>https://cdn.jsdelivr.net/npm/@types/node@22.9.0/buffer.buffer.d.ts</location>
<excerpt>/** * Produces a Buffer backed by the same allocated memory as * the given {ArrayBuffer}/{SharedArrayBuffer}. * * `@param` arrayBuffer The ArrayBuffer with which to share memory. * `@deprecated` since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead. */ new (arrayBuffer: TArrayBuffer): Buffer; /** ... * A `TypeError` will be thrown if `size` is not a number. * `@since` v5.12.0 * `@param` size The desired length of the new `Buffer`. */ allocUnsafeSlow(size: number): Buffer; } interface Buffer extends Uint8Array { // see buffer.d.ts for implementation shared with all TypeScript versions /** * Returns a new `Buffer` that references the same memory as the original, but ... * offset and cropped by the `start` and `end` indices</excerpt>
</source>
<source>
<title>Update tests and definitions to support generic typed arrays</title>
<location>GitHub pull request 70390 in DefinitelyTyped/DefinitelyTyped (link omitted to avoid creating a cross-reference)</location>
<excerpt>This updates the tests for a number of packages to be compatible with an upcoming change to TypeScript which makes typed arrays like `Uint8Array` generic over the `ArrayBuffer` or `SharedArrayBuffer` they are created with. This also introduces a backwards compatible workaround for `Buffer`, which is a subclass of `Uint8Array`, so that a `Buffer` continues to be assignable to a `Uint8Array ` in both older and newer editions of TypeScript. Please fill in this template. - [x] Use a meaningful title for the pull request. Include the name of the package modified. - [x] Test the change in your own code. (Compile and run.) - [ ] Add or edit tests to reflect the change. - [x] Follow the advice from the readme. - [x] Avoid common mistakes. - [x] Run `pnpm test `. If changing an existing definition: - [x] Provide a URL to documentation or source code which provides context for the suggested changes: https://github.com/microsoft/TypeScript/pull/59417 - [ ] ~~If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the `package.json`.~~ ... > "name": "node", > "kind": "edit", > "files": [ > { > "path": "types/node/buffer.d.ts", > "kind": "definition" > }, ... > { > "path": "types/node/v16/buffer.d.ts", > "kind": "definition" > }, ... > { > "path": "types/node/v18/buffer.d.ts", > "kind": "definition" > }, ... > { > "path": "types/node/v20/buffer.d.ts", > "kind": "definition" > }, ... - Review by Renegade334: I believe that these need to go as well before the various typed array interfaces become generic: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d667ea73db0431a8d45829a7523f67e1d4bfdfd6/types/node/globals.d.ts#L205-L228 They were added a couple of months prior to lib.es2022.array being added to TS, in order to "jump the gun" on the new feature. ECMA features shouldn&`#39`;t be here anyway, so I think the simplest solution is just to get rid. This will cause new TS2550 errors for anyone using `.at()` without including lib.es2022.array, but the error text gives clear instructions on how to fix.</excerpt>
</source>
<source>
<title>types/node/buffer.buffer.d.ts at b4f65b920e76b97dc731ff8ebbcd2d6915998332 · DefinitelyTyped/DefinitelyTyped</title>
<location>https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b4f65b920e76b97dc731ff8ebbcd2d6915998332/types/node/buffer.buffer.d.ts</location>
<excerpt><ArrayBuffer ... /** * Produces a Buffer backed by the same allocated memory as * the given {ArrayBuffer}/{SharedArrayBuffer}. * * `@param` arrayBuffer The ArrayBuffer with which to share memory. * `@deprecated` since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead. */ new<TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: TArrayBuffer): Buffer<TArrayBuffer>; /** * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`. * Array entries outside that range will be truncated to fit into it. * * ```js * import { Buffer } from &`#39`;node:buffer&`#39`;; * * // Creates a new Buffer containing ... from([0x ... , 0 ... * ... another type appropriate for `Buffer.from()` * variants. * * It is important to remember that a backing `ArrayBuffer` can cover a range * of memory that extends beyond the bounds of a `TypedArray` view. A new * `Buffer` created using the `buffer` property of a `TypedArray` may extend * beyond the range of the `TypedArray`: * * ```js * import { Buffer } from &`#39`;node:buffer&`#39`;; * * const arrA = Uint8Array.from([0x63, 0x64, 0x65, 0x66]); // 4 elements * const arrB = new Uint8Array(arrA.buffer, 1, 2); // 2 elements * console.log(arrA.buffer === arrB.buffer); // true * * const buf = Buffer.from(arrB.buffer); * console.log(buf); * // Prints: <Buffer 63 64 65 66> * ``` * `@since` v5.10.0 ... `@param` arrayBuffer An ... ArrayBuffer`, `SharedArrayBuffer`, ... example the ... byteOffset Index of first byte to ... , byteOffset?: number ... length?: number ... <TArrayBuffer>>; /** * Creates a new `Buffer` containing `string`. The `encoding ... parameter identifies * ... character encoding to be used when converting ... string` into bytes. ... * * ```js ... * import { Buffer } from &`#39`;node:buffer&`#39`;; ... * const buf1 = Buffer.from(&`#39`;this ... Buffer.from(&`#39`; ... a small chunk ... * memory from a pool ... an indeterminate amount of time, it may be appropriate ... * to ... then copying out ... * ```js ... * import { ... * // Need to keep around a few small chunks of memory. * const store = []; * * socket.on(&`#39`;readable&`#39`;, () => { * let data; * while (null !== (data = readable.read())) { * // Allocate ... * const sb = ... .allocUnsafeSlow(10); * * // Copy the data into ... new allocation. ... * data.copy(sb, 0, 0, 10); * * store.push(sb); * } * }); * ``` * * A `TypeError` will be thrown if `size` is not a number. * `@since` v5.12.0 * `@param` size The desired length of the new `Buffer`. */ allocUnsafeSlow(size: number): Buffer<ArrayBuffer>; ... interface Buffer<TArrayBuffer extends ... ArrayBufferLike> extends Uint8Array ... TArrayBuffer> ... see buffer.d.ts for implementation shared with all TypeScript versions ... // Prints: cuffer ... * console.log(buf.toString()); ... * // Also prints: cuffer (!) * ``` * ... since v0.3.0 * `@deprecated` Use `subarray` instead. * `@param` [start=0] Where the new `Buffer` will start. * `@param` [end=buf.length] Where the new `Buffer` will end (not ... */ ... slice(start ... number, end ... * Returns a new `Buffer` ... original, but * offset ... the `start` ... `end` indices. * * Specifying `end` greater than `buf.length` will return the same result as * that of `end` equal to `buf.length`. * * This method is inherited from ... TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray). * * Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap. * * ```js * import { Buffer } from &`#39`;node:buffer&`#39`;; * * // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte * // from the original `Buffer`. * * const buf1 = Buffer.allocUnsafe(26); * * for (let i = 0; i < 26; i++) { * // 97 is the decimal ASCII value for &`#39`;a&`#39`;. * buf1[i] = i + 97; * } * * const buf2 = buf1.subarray(0, 3); * * console.log(buf2.…[truncated]</excerpt>
</source>
</source_evidence>
Citations:
- 1: GitHub pull request 70694 in DefinitelyTyped/DefinitelyTyped (link omitted to avoid creating a cross-reference)
- 2: https://github.com/databricks/databricks-vscode/commit/972af4cda4824333bfa8f0172ceba0d641b70a75
- 3: https://cdn.jsdelivr.net/npm/@types/node@22.9.0/buffer.buffer.d.ts
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- diff stat ---'
git diff --stat 6f9c00efc9df51c25030a9fd3cee4e98b9898412 4b743c9d6e59caed1a5ecf127f746feb9f151297 -- types lib package.json tsconfig.json jsconfig.json 2>/dev/null || true
printf '%s\n' '--- changed declaration context ---'
for f in types/SourceMapSource.d.ts types/CachedSource.d.ts; do
if git cat-file -e 4b743c9d6e59caed1a5ecf127f746feb9f151297:"$f" 2>/dev/null; then
echo "### $f"
git show 4b743c9d6e59caed1a5ecf127f746feb9f151297:"$f" | nl -ba | sed -n '35,105p'
fi
done
printf '%s\n' '--- source definitions and annotations ---'
for f in lib/SourceMapSource.js lib/CachedSource.js; do
if git cat-file -e 4b743c9d6e59caed1a5ecf127f746feb9f151297:"$f" 2>/dev/null; then
echo "### $f"
git show 4b743c9d6e59caed1a5ecf127f746feb9f151297:"$f" | nl -ba | sed -n '1,240p'
fi
done
printf '%s\n' '--- relevant package/config files ---'
for f in package.json tsconfig.json jsconfig.json; do
if git cat-file -e 4b743c9d6e59caed1a5ecf127f746feb9f151297:"$f" 2>/dev/null; then
echo "### $f"
git show 4b743c9d6e59caed1a5ecf127f746feb9f151297:"$f" | sed -n '1,240p'
fi
done
printf '%s\n' '--- repository references ---'
rg -n --glob '!node_modules' --glob '!dist' 'typescript|`@types/node`|skipLibCheck|declaration|SourceMapSource|CachedSource' . | head -240Repository: webpack/webpack-sources
Length of output: 41965
🏁 Script executed:
#!/bin/bash
set -eu
HEAD=4b743c9d6e59caed1a5ecf127f746feb9f151297
BASE=6f9c00efc9df51c25030a9fd3cee4e98b9898412
printf '%s\n' '--- package metadata and tsconfig ---'
for f in package.json tsconfig.json; do
echo "### $f"
git show "$HEAD:$f" | nl -ba | sed -n '1,180p'
done
printf '%s\n' '--- base/head declaration existence and cited declarations ---'
for f in types/SourceMapSource.d.ts types/CachedSource.d.ts; do
echo "### $f at base"
git cat-file -e "$BASE:$f" 2>/dev/null && git show "$BASE:$f" | nl -ba | sed -n '1,130p' || echo absent
echo "### $f at head"
git show "$HEAD:$f" | nl -ba | sed -n '1,130p'
done
printf '%s\n' '--- source method ranges ---'
for spec in 'lib/SourceMapSource.js:200,330' 'lib/CachedSource.js:100,180' 'lib/CachedSource.js:250,290'; do
f=${spec%%:*}; r=${spec##*:}
echo "### $f:$r"
git show "$HEAD:$f" | nl -ba | sed -n "${r}p"
done
printf '%s\n' '--- exact diff for relevant source and declarations ---'
git diff "$BASE" "$HEAD" -- lib/SourceMapSource.js lib/CachedSource.js types/SourceMapSource.d.ts types/CachedSource.d.ts | sed -n '1,320p'
printf '%s\n' '--- support/version references ---'
git grep -n -E 'engines|typescript|`@types/node`|skipLibCheck|TypeScript|types' "$HEAD" -- README.md CHANGELOG.md package.json tsconfig.json .github 2>/dev/null | head -240 || trueRepository: webpack/webpack-sources
Length of output: 32561
🏁 Script executed:
#!/bin/bash
set -eu
HEAD=4b743c9d6e59caed1a5ecf127f746feb9f151297
printf '%s\n' '--- CachedSource _cachedBuffers context ---'
git show "$HEAD:lib/CachedSource.js" | nl -ba | grep -C 8 '_cachedBuffers'
printf '%s\n' '--- all generated generic Buffer declarations in types ---'
git grep -n 'Buffer<ArrayBufferLike>' "$HEAD" -- typesRepository: webpack/webpack-sources
Length of output: 2889
Emit non-generic Buffer types for older @types/node versions.
The generated declarations expose Buffer<ArrayBufferLike> at four public members. Consumers with a non-generic Buffer declaration receive TS2315. Add explicit JSDoc types and regenerate the declarations.
Suggested fix
diff --git a/lib/SourceMapSource.js b/lib/SourceMapSource.js
--- a/lib/SourceMapSource.js
+++ b/lib/SourceMapSource.js
@@ -77,6 +77,9 @@ class SourceMapSource extends Source {
this._originalSourceAsString = originalSourceIsBuffer
? undefined
: originalSource;
+ /**
+ * `@type` {Buffer | undefined}
+ */
this._originalSourceAsBuffer = originalSourceIsBuffer
? originalSource
: undefined;
@@ -211,6 +214,9 @@ class SourceMapSource extends Source {
return this._innerSourceMapAsObject;
}
+ /**
+ * `@returns` {Buffer | undefined}
+ */
_innerSourceMapBuffer() {
if (this._innerSourceMapAsBuffer === undefined && this._hasInnerSourceMap) {
const value = Buffer.from(this._innerSourceMapString(), "utf8");
@@ -254,6 +260,9 @@ class SourceMapSource extends Source {
return this._sourceMapAsObject;
}
+ /**
+ * `@returns` {Buffer}
+ */
_sourceMapBuffer() {
if (this._sourceMapAsBuffer === undefined) {
const value = Buffer.from(this._sourceMapString(), "utf8");
diff --git a/lib/CachedSource.js b/lib/CachedSource.js
--- a/lib/CachedSource.js
+++ b/lib/CachedSource.js
@@ -131,6 +131,10 @@ class CachedSource extends Source {
*/
this._cachedSource = undefined;
+ /**
+ * `@type` {Buffer[] | undefined}
+ */
+ this._cachedBuffers = undefined;
// Split on `cachedData` once instead of re-evaluating the ternary for📍 Affects 2 files
types/SourceMapSource.d.ts#L54-L54(this comment)types/SourceMapSource.d.ts#L87-L87types/SourceMapSource.d.ts#L93-L93types/CachedSource.d.ts#L62-L62
Summary
toolingis deprecated. This PR generates the type declarations with the TypeScript CLI, following webpack-dev-middleware, and keeps the package's public type exports the same.How types are built
npm run build:typesrunsdel-cli types && tsc -p tsconfig.types.json && prettier --write types. It emits one.d.tsper file inlib/into a committedtypes/folder. The clean step makes sure declarations for deleted files don't linger.git status typesshows changes.toolingdependency and thelint:specialandfix:specialscripts.fixnow runsbuild:types.Public entry (
types.d.ts)types.d.tsstays the package'stypesentry. It's now a short hand-written file that re-exports the generated declarations in the same shape as before:util.stringBufferUtils.lint:types-testnow type-checks it.lib/index.jsexports a frozen object of lazy getters, so the generatedtypes/index.d.tsexposes the classes only as values.let s: Sourcewouldn't compile against it.typesattypes/index.d.tsoncelib/index.jsexports the classes as types too.types/is added tofiles.@privatetags removed fromlib/(JSDoc only, no runtime change)tscemits@privatemembers as TypeScriptprivatemembers, and a class withprivatemembers only accepts instances from the same declaration file. Two installed copies of webpack-sources (e.g. webpack's and a plugin's), even the same version, would then reject each other's instances. Reproduced:stripInternalhas no effect on declarations emitted from JavaScript, so with plaintscremoving the tags is the only way to keep duplicate copies compatible.@ts-expect-errorabovesource._sourceintest/ReplaceSource.jsbecame unused and is removed.Differences in the published types
_-prefixed class members (e.g.ReplaceSource._replacements) are now visible as ordinary members.Replacement.nameandReplacement.indexare nowstring | undefinedandnumber | undefinedinstead of optional, because a JavaScript class can't declare an optional field.Source,tscleaves the declaration out and it's inherited instead. The types are unchanged.inherit-typesandformat-file-headerchecks are removed along withtooling.Compatibility with 3.5.2
Source, all helper types andutilare identical in both directions._members. Code typed againstSourceis unaffected.skipLibCheckoff.Test plan
npm run lint(eslint,tsc, types test includingtypes.d.ts)npm run fmt:checkjest: 14 suites, 89,907 tests passnpm run build:typeson a clean tree produces no diffM types/RawSource.d.ts); fails after deleting alib/file (D types/helpers/getName.d.ts)No changeset is included. The package now ships a
types/folder and its internal members are visible in the published types, so a patch changeset may be worth adding.🤖 Generated with Claude Code
https://claude.ai/code/session_01ThsbPWvW5vnYWEaFs2Q22F
Generated by Claude Code
Summary by CodeRabbit