feat: add JSDoc types and TypeScript declaration generation#464
Conversation
Annotate the source with JSDoc, add a `tsconfig.json`, and emit TypeScript declarations to `types/`. The package now exposes types via the `exports`/`types` fields, mirroring how `sass-loader` ships them.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #464 +/- ##
==========================================
+ Coverage 95.28% 96.21% +0.93%
==========================================
Files 2 2
Lines 996 1269 +273
==========================================
+ Hits 949 1221 +272
- Misses 47 48 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds first-class TypeScript support for stylus-loader by annotating the JS source with JSDoc, introducing a tsconfig.json for declaration emit, and shipping the generated .d.ts files via exports/types in package.json.
Changes:
- Added JSDoc typedefs throughout
src/(and some helpers) and generated declaration outputs intotypes/. - Introduced
tsconfig.jsonand newbuild:types/lint:typesscripts to emit and typecheck declarations. - Updated package metadata (
exports,types,files) and lockfile to include the new typing toolchain.
Reviewed changes
Copilot reviewed 12 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
types/utils.d.ts |
New generated declaration file for utility types and exported helper APIs. |
types/index.d.ts |
New generated declaration file for the loader entry point and re-exported types. |
tsconfig.json |
TypeScript config for allowJs + checkJs and emitting declarations to types/. |
src/utils.js |
Added JSDoc types and casts to satisfy TS checking while keeping runtime behavior. |
src/index.js |
Added JSDoc types for the loader and some casts for strict checking. |
package.json |
Exposes types in exports/types, includes types/ in published files, adds TS scripts/dev deps. |
package-lock.json |
Updates lockfile for newly added dev tooling and dependency graph changes. |
test/loader.test.js |
Adds JSDoc typedefs to satisfy TS checking for inline stylus plugins. |
test/helpers/testLoader.cjs |
Adds JSDoc for TS checking. |
test/helpers/readAssets.js |
Adds JSDoc for TS checking. |
test/helpers/normalizeErrors.js |
Adds JSDoc for TS checking. |
test/helpers/getCodeFromStylus.js |
Adds JSDoc/typedefs for TS checking. |
test/helpers/getCodeFromBundle.js |
Adds JSDoc for TS checking. |
bench/index.js |
Adds JSDoc for TS checking. |
bench/fixtures/imports/testLoader.js |
Adds JSDoc for TS checking. |
.changeset/add-jsdoc-types.md |
Changeset entry documenting the new typings feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "prebuild": "npm run clean", | ||
| "build:esm": "babel src -d dist/esm --env-name esm --copy-files --no-copy-ignored", | ||
| "build:cjs": "babel src -d dist/cjs --env-name cjs --copy-files --no-copy-ignored && node -e \"const fs=require('fs');fs.writeFileSync('dist/cjs/package.json','{\\\"type\\\":\\\"commonjs\\\"}\\n');fs.appendFileSync('dist/cjs/index.js','module.exports = exports.default;\\nmodule.exports.default = exports.default;\\n')\"", | ||
| "build:types": "tsc && prettier \"types/**/*.ts\" --write", |
| "prebuild": "npm run clean", | ||
| "build:esm": "babel src -d dist/esm --env-name esm --copy-files --no-copy-ignored", | ||
| "build:cjs": "babel src -d dist/cjs --env-name cjs --copy-files --no-copy-ignored && node -e \"const fs=require('fs');fs.writeFileSync('dist/cjs/package.json','{\\\"type\\\":\\\"commonjs\\\"}\\n');fs.appendFileSync('dist/cjs/index.js','module.exports = exports.default;\\nmodule.exports.default = exports.default;\\n')\"", | ||
| "build:types": "tsc && prettier \"types/**/*.ts\" --write", |
|
|
||
| /** | ||
| * @typedef {object} StylusResolveUrlOptions | ||
| * @property {boolean=} nocheck true when no need to check on disk, otherwise false |
| /** | ||
| * Resolve relative url()'s inside imported files. | ||
| * | ||
| * @see https://stylus-lang.com/docs/js.html#stylusresolveroptions | ||
| * | ||
| * @type {boolean|Object} | ||
| * @type {boolean | { nocheck?: boolean }} | ||
| * @default { nocheck: true } |
| * @param {LoaderContext} loaderContext loader context | ||
| * @param {string} code code | ||
| * @param {StylusOptions} options stylus options | ||
| * @returns {Promise<Evaluator>} custom evaluator class |
Annotate the source with JSDoc, add a
tsconfig.json, and emit TypeScript declarations totypes/. The package now exposes types via theexports/typesfields, mirroring howsass-loaderships them.Summary
What kind of change does this PR introduce?
Did you add tests for your changes?
Does this PR introduce a breaking change?
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Use of AI