Skip to content

Commit b514c2a

Browse files
committed
fix: add type declarations for the logger
This is the final package we need to add manual type declarations for, it's also the most complex but I decided to just replicate the existing generated types. Because we no longer need a build step I'm removing all of the build-related tooling and updating the documentation accordingly. Resolves #946
1 parent 36490d1 commit b514c2a

17 files changed

+159
-266
lines changed

.circleci/config.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@ jobs:
126126
name: Set npm auth token
127127
command: echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" >
128128
${HOME}/.npmrc
129-
- run:
130-
name: Build packages
131-
command: npm run build
132129
- run:
133130
name: NPM publish
134131
command: ./scripts/circleci-publish.sh
@@ -141,9 +138,6 @@ jobs:
141138
name: Set npm auth token
142139
command: echo "//registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}" >
143140
${HOME}/.npmrc
144-
- run:
145-
name: Build packages
146-
command: npm run build
147141
- run:
148142
name: NPM publish
149143
command: ./scripts/circleci-publish.sh --tag=prerelease

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.husky/_
2-
packages/logger/**/*.d.*
32
coverage
43
node_modules/
54
resources/logos/dist

docs/contributing.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ We're glad you want to contribute to Reliability Kit!
2626
* [Pull request scope](#pull-request-scope)
2727
* [Merging pull requests](#merging-pull-requests)
2828
* [Releasing](#releasing)
29-
* [Generated files](#generated-files)
3029
* [Hard-coding the release version](#hard-coding-the-release-version)
3130
* [Correcting releases](#correcting-releases)
3231
* [Issue management](#issue-management)
@@ -174,7 +173,7 @@ The linters are also run on pull requests and linting errors will block merging,
174173

175174
### Type safety
176175

177-
We do not write TypeScript in this project, but we _do_ write [thorough JSDoc](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html) and test against it which gives us all the benefits of TypeScript ([more info](./design.md#languages)).
176+
We do not write TypeScript code, but we _do_ write [thorough JSDoc](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html) and publish type declarations, then test against it which gives us all the benefits of TypeScript ([more info](./design.md#languages)).
178177

179178
We do not compile the code in our packages, but we do check that all variables are set to the correct types. If there are any type errors then you should see these in your editor if you're using VS Code. Otherwise type checking can be manually run as part of linting:
180179

@@ -269,16 +268,6 @@ If the PR is left alone, it will continue to be updated with new releases as mor
269268

270269
Before approving and merging the release PR, make sure you review it. You need to check the package versions that it updates to make sure you’re only releasing the things you expect.
271270

272-
### Generated files
273-
274-
Before publishing npm packages we do generate TypeScript type declaration files (`.d.ts`) so that TypeScript-based projects which use Reliability Kit will get correct type hinting.
275-
276-
If a release has caused issues with Type hinting or TypeScript-based projects compiling, then you can inspect the generated files by running the build command locally and viewing the `.d.ts` files in your editor:
277-
278-
```
279-
npm run build
280-
```
281-
282271
### Hard-coding the release version
283272

284273
Sometimes it's necessary to hard-code a release version, for example if commits have been pushed to `main` which don't match our [commit format](#commit-type-prefixes). A more common reason to do this is when you want to publish a prerelease package to experiment before marking it as stable (e.g. publishing a `v0.1.0` before `v1.0.0`).

docs/design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The combination of the above allows us to work on and publish the packages in th
2727

2828
In terms of TypeScript, the key benefits are having type safety and type hinting in your editor. We can achieve both of these without writing TypeScript. Using [JavaScript with JSDoc comments to document types](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html), VSCode (used by the majority of our engineers) offers the same level of type hinting as it does with TypeScript. It's also possible to run the TypeScript type checker against JavaScript code to verify that everything is type safe (e.g. using `tsc --checkJS`).
2929

30-
In order to be useful for TypeScript projects, we do still need to publish our modules with TypeScript type declaration files (`.d.ts`). We made this an automated step during publishing and when authoring modules you should still write JavaScript and JSDoc.
30+
In order to be useful for TypeScript projects, we do still need to publish our modules with TypeScript type declaration files (`.d.ts`).
3131

3232
### CommonJS
3333

jsconfig.build.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@
2020
"create-package": "./scripts/create-package.js",
2121
"lint": "npm run lint:eslint && npm run lint:tsc",
2222
"lint:eslint": "eslint .",
23-
"lint:tsc": "npm run clean && tsc --project ./jsconfig.json",
24-
"clean": "npm run clean:types",
25-
"clean:types": "./scripts/clean-generated-types.sh",
26-
"build": "npm run clean && npm run build:types",
27-
"build:types": "tsc --project ./jsconfig.build.json",
23+
"lint:tsc": "tsc --project ./jsconfig.json",
2824
"test": "npm run test:jest && npm run test:modules",
2925
"test:jest": "jest --silent",
30-
"test:modules": "npm run build && npm run test --workspaces --if-present",
26+
"test:modules": "npm run test --workspaces --if-present",
3127
"prepare": "husky",
3228
"postinstall": "npm run build:logos"
3329
},

packages/logger/.npmignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
!*.d.ts
2-
!*.d.ts.map
31
CHANGELOG.md
42
docs
53
test

packages/logger/lib/index.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,8 @@ const Logger = require('./logger');
22
const legacyMask = require('./transforms/legacy-mask');
33

44
/**
5-
* @typedef {object} Transforms
6-
* @property {legacyMask} legacyMask
7-
* The legacy mask logger.
8-
*/
9-
10-
/**
11-
* @typedef {object} DefaultLogger
12-
* @property {typeof Logger} Logger
13-
* The Logger class.
14-
* @property {Transforms} transforms
15-
* Built-in log transforms.
5+
* @typedef {import('@dotcom-reliability-kit/logger').DefaultLogger} DefaultLogger
6+
* @typedef {import('@dotcom-reliability-kit/logger').Transforms} Transforms
167
*/
178

189
/** @type {Transforms} */

0 commit comments

Comments
 (0)