Skip to content

Commit 2c6fc71

Browse files
committed
refactor: switch to use exports rather than main
This will allow us to use conditional exports when we migrate to native ESM. It's also the more modern way of doing package exports as it's a lot more flexible than the top-level `main` property. Partially as a result of this change and partially because we'll be switching to TypeScript, I've also outlined some more strict requirements for Reliability Kit's usage with TypeScript, and the settings we recommend and support.
1 parent e655f36 commit 2c6fc71

File tree

58 files changed

+504
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+504
-169
lines changed

jsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"compilerOptions": {
33
"alwaysStrict": true,
44
"checkJs": true,
5+
"esModuleInterop": true,
56
"maxNodeModuleJsDepth": 0,
6-
"module": "commonjs",
7+
"module": "nodenext",
8+
"moduleResolution": "nodenext",
79
"noEmit": true,
810
"noImplicitOverride": true,
911
"noImplicitThis": true,
@@ -12,7 +14,7 @@
1214
"strictFunctionTypes": true,
1315
"strictNullChecks": true,
1416
"strictPropertyInitialization": true,
15-
"target": "es2022",
17+
"target": "es2024",
1618
"useUnknownInCatchVariables": true,
1719
"types": []
1820
},

package-lock.json

Lines changed: 29 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app-info/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ import appInfo from '@dotcom-reliability-kit/app-info';
3737
const appInfo = require('@dotcom-reliability-kit/app-info');
3838
```
3939

40+
> [!TIP]
41+
> If you're using this package with TypeScript, we recommend using the following settings in your `tsconfig.json` file to avoid type errors:
42+
>
43+
> ```json
44+
> {
45+
> "esModuleInterop": true,
46+
> "module": "nodenext",
47+
> "moduleResolution": "nodenext"
48+
> }
49+
> ```
50+
4051
The `appInfo` object has several properties which can be used to access application information.
4152
4253
### `appInfo.commitHash`

packages/app-info/docs/migration.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Emoji | Label | Meaning
1717
* [Migrating from v4 to v5](#migrating-from-v4-to-v5)
1818
* [Node.js 20 is no longer supported](#nodejs-20-is-no-longer-supported)
1919
* [Node.js 22.11 is no longer supported](#nodejs-2211-is-no-longer-supported)
20+
* [Stricter TypeScript requirements](#stricter-typescript-requirements)
2021

2122

2223
## Migrating from v1 to v2
@@ -49,3 +50,15 @@ Emoji | Label | Meaning
4950
### Node.js 22.11 is no longer supported
5051

5152
**:red_circle: Breaking:** this version drops support for Node.js v22.11 or lower. If your app is already using Node.js v22.12 then you may be able to migrate without code changes. This is so that we can publish native ESM modules without requiring complex changes in our consuming applications. [See #1479 for more information](https://github.com/Financial-Times/dotcom-reliability-kit/issues/1479).
53+
54+
### Stricter TypeScript requirements
55+
56+
**:orange_circle: Possibly Breaking:** this version outlines some requirements for use with TypeScript. Previously we made no recommendations about your TypeScript config and this package did not work in some scenarios. We are now explicitly documenting how we support TypeScript-based projects and we require the following settings to guarantee that this package will be free of type errors:
57+
58+
```json
59+
{
60+
"esModuleInterop": true,
61+
"module": "nodenext",
62+
"moduleResolution": "nodenext"
63+
}
64+
```

packages/app-info/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"engines": {
1717
"node": "^22.12 || ^24"
1818
},
19-
"main": "lib/index.js",
20-
"types": "types/index.d.ts"
19+
"exports": {
20+
".": {
21+
"types": "./types/index.d.ts",
22+
"default": "./lib/index.js"
23+
}
24+
}
2125
}

packages/client-metrics-web/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ import { MetricsClient } from '@dotcom-reliability-kit/client-metrics-web';
5757
const { MetricsClient } = require('@dotcom-reliability-kit/client-metrics-web');
5858
```
5959

60+
> [!TIP]
61+
> If you're using this package with TypeScript, we recommend using the following settings in your `tsconfig.json` file to avoid type errors:
62+
>
63+
> ```json
64+
> {
65+
> "esModuleInterop": true,
66+
> "module": "nodenext",
67+
> "moduleResolution": "nodenext"
68+
> }
69+
> ```
70+
6071
### `MetricsClient`
6172
6273
The `MetricsClient` class wraps an AWS CloudWatch RUM client with some FT-specific configurations and limitations. This class should only ever be constructed once or you'll end up sending duplicate metrics.

packages/client-metrics-web/docs/migration.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Emoji | Label | Meaning
1212
* [Migrating from v0 to v1](#migrating-from-v0-to-v1)
1313
* [Node.js 20 is no longer supported](#nodejs-20-is-no-longer-supported)
1414
* [Node.js 22.11 is no longer supported](#nodejs-2211-is-no-longer-supported)
15+
* [Stricter TypeScript requirements](#stricter-typescript-requirements)
1516

1617

1718
## Migrating from v0 to v1
@@ -23,3 +24,15 @@ Emoji | Label | Meaning
2324
### Node.js 22.11 is no longer supported
2425

2526
**:red_circle: Breaking:** this version drops support for Node.js v22.11 or lower. If your app is already using Node.js v22.12 then you may be able to migrate without code changes. This is so that we can publish native ESM modules without requiring complex changes in our consuming applications. [See #1479 for more information](https://github.com/Financial-Times/dotcom-reliability-kit/issues/1479).
27+
28+
### Stricter TypeScript requirements
29+
30+
**:orange_circle: Possibly Breaking:** this version outlines some requirements for use with TypeScript. Previously we made no recommendations about your TypeScript config and this package did not work in some scenarios. We are now explicitly documenting how we support TypeScript-based projects and we require the following settings to guarantee that this package will be free of type errors:
31+
32+
```json
33+
{
34+
"esModuleInterop": true,
35+
"module": "nodenext",
36+
"moduleResolution": "nodenext"
37+
}
38+
```

packages/client-metrics-web/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
"engines": {
1717
"node": "^22.12 || ^24"
1818
},
19-
"main": "lib/index.js",
20-
"types": "types/index.d.ts",
19+
"exports": {
20+
".": {
21+
"types": "./types/index.d.ts",
22+
"default": "./lib/index.js"
23+
}
24+
},
2125
"dependencies": {
2226
"aws-rum-web": "^1.25.0"
2327
}

packages/client-metrics-web/test/unit/lib/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
jest.mock('aws-rum-web');
33

44
const { AwsRum } = require('aws-rum-web');
5-
const { MetricsClient } = require('../../..');
5+
const { MetricsClient } = require('@dotcom-reliability-kit/client-metrics-web');
66

77
describe('@dotcom-reliability-kit/client-metrics-web', () => {
88
beforeEach(() => {

packages/crash-handler/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ import registerCrashHandler from '@dotcom-reliability-kit/crash-handler';
3131
const registerCrashHandler = require('@dotcom-reliability-kit/crash-handler');
3232
```
3333

34+
> [!TIP]
35+
> If you're using this package with TypeScript, we recommend using the following settings in your `tsconfig.json` file to avoid type errors:
36+
>
37+
> ```json
38+
> {
39+
> "esModuleInterop": true,
40+
> "module": "nodenext",
41+
> "moduleResolution": "nodenext"
42+
> }
43+
> ```
44+
3445
### `registerCrashHandler`
3546
3647
The `registerCrashHandler` function can be used to bind an event handler to the [Node.js `process.uncaughtException` event](https://nodejs.org/api/process.html#event-uncaughtexception). This ensures that your application logs a final message before crashing in the event on an unexpected error or promise rejection.

0 commit comments

Comments
 (0)