Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(build): Turn on isolatedModules TS option #4497

Merged
merged 3 commits into from
Feb 4, 2022

Conversation

lobsterkatie
Copy link
Member

This applies the TypeScript isolatedModules setting to all packages in the repo, which is necessary in order for us to use any compiler other than tsc. (All other compilers handle each file separately, without understanding the relationships between them the way tsc does, so we need TS to warn us if we're doing anything which would make that a problem).

It also makes two code changes necessary in order to be compatible with the isolatedModules flag, specifically:

  • All re-exported types and interfaces (anything that will get stripped away when compiling from TS to JS) are now exported using export type. This lets non-tsc compilers know that the exported types are eligible for stripping, in spite of the fact that said compilers can't follow the export path backwards to see the types' implementation.

  • Usages of the Severity enum from @sentry/types were replaced with string literals, which was necessary here because non-tsc compilers can't trace usages of a const enum back to their underlying values to do the substitution. They therefore leave those usages alone, while at the same time stripping the enum definitions the way tsc would. This leads to usages of something which no longer exists, which is obviously a problem. Using the string literals prevents that.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2022

size-limit report

Path Base Size (ad37109) Current Size Change
@sentry/browser - CDN Bundle (gzipped) 19.68 KB 19.68 KB +0.01% 🔺
@sentry/browser - CDN Bundle (minified) 62.89 KB 62.87 KB -0.05% 🔽
@sentry/browser - Webpack 22.21 KB 22.21 KB -0.02% 🔽
@sentry/browser - Webpack - gzip = false 76.02 KB 76.04 KB +0.03% 🔺
@sentry/react - Webpack 22.24 KB 22.24 KB -0.02% 🔽
@sentry/nextjs Client - Webpack 46.24 KB 46.27 KB +0.08% 🔺
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.22 KB 28.23 KB +0.04% 🔺

@lobsterkatie lobsterkatie merged commit 4e89e5c into kmclb-new-bundling-process Feb 4, 2022
@lobsterkatie lobsterkatie deleted the kmclb-use-isolated-modules branch February 4, 2022 02:30
lobsterkatie added a commit that referenced this pull request Apr 14, 2022
Note: This and #4896 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

Our original v7 plan called for deprecating and then removing the `Severity` enum which lives in `@sentry/types`, because enums transpile to a two-way lookup function with a fairly hefty footprint (see this SO answer[1] from one of the maintainers of TS). We therefore added a new `SeverityLevel` type, which is the union of all of `Severity`'s underlying values, and directed people to use that instead. Though we subsequently decided not to remove `Severity` (at least in v7), we agreed that we should stop using it internally. This implements that change.

Key Changes:

- `Severity` and `severityFromString` have been redeprecated.
- The original plan to have `SeverityLevel` live in `@sentry/utils` has been reverted, and it now lives only in `@sentry/types`. 
- The internal `SeverityLevels` array on which we were basing `SeverityLevel` has been removed. While we lose the elegance of the derived type, we gain the ability to truly only export types from `@sentry/types`.
- Wherever we accept a `Severity` value, we now also accept a `SeverityLevel`.
- All internal uses of `Severity` values have been replaced with the equivalent string constants.
- A new `severityLevelFromString` function has been introduced, and is now used in place of `SeverityFromString`.
- The tests for `severityFromString` have been cleaned up and replaced with equivalent tests for `SeverityLevelFromString`.

[1] https://stackoverflow.com/a/28818850
lobsterkatie added a commit that referenced this pull request Apr 14, 2022
Note: This and #4926 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

This applies [the TypeScript `isolatedModules` setting[1] to all packages in the repo, which is necessary in order for us to use any compiler other than `tsc`. (All other compilers handle each file separately, without understanding the relationships between them the way `tsc` does, so we need TS to warn us if we're doing anything which would make that a problem).

It also makes the second of two code changes necessary in order to be compatible with the `isolatedModules` flag: all re-exported types and interfaces (anything that will get stripped away when compiling from TS to JS) are now exported using `export type`. This lets non-`tsc` compilers know that the exported types are eligible for stripping, in spite of the fact that said compilers can't follow the export path backwards to see the types' implementation.

(The other code change, eliminating our usage of the `Severity` enum, was split off into the PR linked above.)

[1] https://www.typescriptlang.org/tsconfig#isolatedModules
Lms24 pushed a commit that referenced this pull request Apr 26, 2022
Note: This and #4896 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

Our original v7 plan called for deprecating and then removing the `Severity` enum which lives in `@sentry/types`, because enums transpile to a two-way lookup function with a fairly hefty footprint (see this SO answer[1] from one of the maintainers of TS). We therefore added a new `SeverityLevel` type, which is the union of all of `Severity`'s underlying values, and directed people to use that instead. Though we subsequently decided not to remove `Severity` (at least in v7), we agreed that we should stop using it internally. This implements that change.

Key Changes:

- `Severity` and `severityFromString` have been redeprecated.
- The original plan to have `SeverityLevel` live in `@sentry/utils` has been reverted, and it now lives only in `@sentry/types`. 
- The internal `SeverityLevels` array on which we were basing `SeverityLevel` has been removed. While we lose the elegance of the derived type, we gain the ability to truly only export types from `@sentry/types`.
- Wherever we accept a `Severity` value, we now also accept a `SeverityLevel`.
- All internal uses of `Severity` values have been replaced with the equivalent string constants.
- A new `severityLevelFromString` function has been introduced, and is now used in place of `SeverityFromString`.
- The tests for `severityFromString` have been cleaned up and replaced with equivalent tests for `SeverityLevelFromString`.

[1] https://stackoverflow.com/a/28818850
Lms24 pushed a commit that referenced this pull request Apr 26, 2022
Note: This and #4926 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

This applies [the TypeScript `isolatedModules` setting[1] to all packages in the repo, which is necessary in order for us to use any compiler other than `tsc`. (All other compilers handle each file separately, without understanding the relationships between them the way `tsc` does, so we need TS to warn us if we're doing anything which would make that a problem).

It also makes the second of two code changes necessary in order to be compatible with the `isolatedModules` flag: all re-exported types and interfaces (anything that will get stripped away when compiling from TS to JS) are now exported using `export type`. This lets non-`tsc` compilers know that the exported types are eligible for stripping, in spite of the fact that said compilers can't follow the export path backwards to see the types' implementation.

(The other code change, eliminating our usage of the `Severity` enum, was split off into the PR linked above.)

[1] https://www.typescriptlang.org/tsconfig#isolatedModules
lobsterkatie added a commit that referenced this pull request Apr 26, 2022
Note: This and #4896 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

Our original v7 plan called for deprecating and then removing the `Severity` enum which lives in `@sentry/types`, because enums transpile to a two-way lookup function with a fairly hefty footprint (see this SO answer[1] from one of the maintainers of TS). We therefore added a new `SeverityLevel` type, which is the union of all of `Severity`'s underlying values, and directed people to use that instead. Though we subsequently decided not to remove `Severity` (at least in v7), we agreed that we should stop using it internally. This implements that change.

Key Changes:

- `Severity` and `severityFromString` have been redeprecated.
- The original plan to have `SeverityLevel` live in `@sentry/utils` has been reverted, and it now lives only in `@sentry/types`. 
- The internal `SeverityLevels` array on which we were basing `SeverityLevel` has been removed. While we lose the elegance of the derived type, we gain the ability to truly only export types from `@sentry/types`.
- Wherever we accept a `Severity` value, we now also accept a `SeverityLevel`.
- All internal uses of `Severity` values have been replaced with the equivalent string constants.
- A new `severityLevelFromString` function has been introduced, and is now used in place of `SeverityFromString`.
- The tests for `severityFromString` have been cleaned up and replaced with equivalent tests for `SeverityLevelFromString`.

[1] https://stackoverflow.com/a/28818850
lobsterkatie added a commit that referenced this pull request Apr 26, 2022
Note: This and #4926 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

This applies [the TypeScript `isolatedModules` setting[1] to all packages in the repo, which is necessary in order for us to use any compiler other than `tsc`. (All other compilers handle each file separately, without understanding the relationships between them the way `tsc` does, so we need TS to warn us if we're doing anything which would make that a problem).

It also makes the second of two code changes necessary in order to be compatible with the `isolatedModules` flag: all re-exported types and interfaces (anything that will get stripped away when compiling from TS to JS) are now exported using `export type`. This lets non-`tsc` compilers know that the exported types are eligible for stripping, in spite of the fact that said compilers can't follow the export path backwards to see the types' implementation.

(The other code change, eliminating our usage of the `Severity` enum, was split off into the PR linked above.)

[1] https://www.typescriptlang.org/tsconfig#isolatedModules
lobsterkatie added a commit that referenced this pull request Apr 26, 2022
Note: This and #4896 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

Our original v7 plan called for deprecating and then removing the `Severity` enum which lives in `@sentry/types`, because enums transpile to a two-way lookup function with a fairly hefty footprint (see this SO answer[1] from one of the maintainers of TS). We therefore added a new `SeverityLevel` type, which is the union of all of `Severity`'s underlying values, and directed people to use that instead. Though we subsequently decided not to remove `Severity` (at least in v7), we agreed that we should stop using it internally. This implements that change.

Key Changes:

- `Severity` and `severityFromString` have been redeprecated.
- The original plan to have `SeverityLevel` live in `@sentry/utils` has been reverted, and it now lives only in `@sentry/types`. 
- The internal `SeverityLevels` array on which we were basing `SeverityLevel` has been removed. While we lose the elegance of the derived type, we gain the ability to truly only export types from `@sentry/types`.
- Wherever we accept a `Severity` value, we now also accept a `SeverityLevel`.
- All internal uses of `Severity` values have been replaced with the equivalent string constants.
- A new `severityLevelFromString` function has been introduced, and is now used in place of `SeverityFromString`.
- The tests for `severityFromString` have been cleaned up and replaced with equivalent tests for `SeverityLevelFromString`.

[1] https://stackoverflow.com/a/28818850
lobsterkatie added a commit that referenced this pull request Apr 26, 2022
Note: This and #4926 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

This applies [the TypeScript `isolatedModules` setting[1] to all packages in the repo, which is necessary in order for us to use any compiler other than `tsc`. (All other compilers handle each file separately, without understanding the relationships between them the way `tsc` does, so we need TS to warn us if we're doing anything which would make that a problem).

It also makes the second of two code changes necessary in order to be compatible with the `isolatedModules` flag: all re-exported types and interfaces (anything that will get stripped away when compiling from TS to JS) are now exported using `export type`. This lets non-`tsc` compilers know that the exported types are eligible for stripping, in spite of the fact that said compilers can't follow the export path backwards to see the types' implementation.

(The other code change, eliminating our usage of the `Severity` enum, was split off into the PR linked above.)

[1] https://www.typescriptlang.org/tsconfig#isolatedModules
AbhiPrasad pushed a commit that referenced this pull request May 30, 2022
Note: This and #4896 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

Our original v7 plan called for deprecating and then removing the `Severity` enum which lives in `@sentry/types`, because enums transpile to a two-way lookup function with a fairly hefty footprint (see this SO answer[1] from one of the maintainers of TS). We therefore added a new `SeverityLevel` type, which is the union of all of `Severity`'s underlying values, and directed people to use that instead. Though we subsequently decided not to remove `Severity` (at least in v7), we agreed that we should stop using it internally. This implements that change.

Key Changes:

- `Severity` and `severityFromString` have been redeprecated.
- The original plan to have `SeverityLevel` live in `@sentry/utils` has been reverted, and it now lives only in `@sentry/types`. 
- The internal `SeverityLevels` array on which we were basing `SeverityLevel` has been removed. While we lose the elegance of the derived type, we gain the ability to truly only export types from `@sentry/types`.
- Wherever we accept a `Severity` value, we now also accept a `SeverityLevel`.
- All internal uses of `Severity` values have been replaced with the equivalent string constants.
- A new `severityLevelFromString` function has been introduced, and is now used in place of `SeverityFromString`.
- The tests for `severityFromString` have been cleaned up and replaced with equivalent tests for `SeverityLevelFromString`.

[1] https://stackoverflow.com/a/28818850
AbhiPrasad pushed a commit that referenced this pull request May 30, 2022
Note: This and #4926 are together a (slightly updated) repeat of #4497, to get it onto the main v7 branch.

This applies [the TypeScript `isolatedModules` setting[1] to all packages in the repo, which is necessary in order for us to use any compiler other than `tsc`. (All other compilers handle each file separately, without understanding the relationships between them the way `tsc` does, so we need TS to warn us if we're doing anything which would make that a problem).

It also makes the second of two code changes necessary in order to be compatible with the `isolatedModules` flag: all re-exported types and interfaces (anything that will get stripped away when compiling from TS to JS) are now exported using `export type`. This lets non-`tsc` compilers know that the exported types are eligible for stripping, in spite of the fact that said compilers can't follow the export path backwards to see the types' implementation.

(The other code change, eliminating our usage of the `Severity` enum, was split off into the PR linked above.)

[1] https://www.typescriptlang.org/tsconfig#isolatedModules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants