Skip to content

Commit

Permalink
feat: remove support for down-leveling of TypeScript declarations fil…
Browse files Browse the repository at this point in the history
…es to ts3.9 to improve performance (#1474)

BREAKING CHANGE: This PR removes the TypeScript declaration file
down-leveling feature from the JSII compiler to address significant
performance issues. Our benchmarks show that >50% of the JSII compile
time is spent in the `downlevel-dts` dependency, causing JSII to be 2.7x
slower than standard TypeScript compilation. The down-leveling feature
was originally added to support TypeScript versions down to 3.9, but
analysis shows minimal usage - none of our AWS CDK codebase uses this
feature, and only about 12 non-fork repositories on GitHub would be
affected by its removal, additionally typescript 3.9 and earlier have
been EOL for quite a while on [definitively
typed](https://github.com/DefinitelyTyped/DefinitelyTyped?tab=readme-ov-file#support-window).

If you found this pr because removing this feature impacted your builds,
it is likely because you have [this
pattern](https://github.com/sandersn/downlevel-dts?tab=readme-ov-file#type-modifiers-on-importexport-names-45)
somewhere in your codebase. Simply refactor that pattern and rebuild.
Ensure you also are not seeing the below typesVersion in your app's
package.json
```json
  "typesVersions": {
    "<=3.9": {
      "*": [
        ".types-compat/ts3.9/*",
        ".types-compat/ts3.9/*/index.d.ts"
      ]
    }
  },
```


---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0

---------

Signed-off-by: github-actions <[email protected]>
Signed-off-by: Hogan Bobertz <[email protected]>
Co-authored-by: github-actions <[email protected]>
Co-authored-by: Momo Kornher <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2024
1 parent c0ecad6 commit 7be6ace
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 667 deletions.
4 changes: 0 additions & 4 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ project.addDeps(
'@jsii/spec',
'case',
'chalk@^4',
'downlevel-dts',
'fast-deep-equal',
'log4js',
'semver',
Expand Down
8 changes: 0 additions & 8 deletions fixtures/@scope/jsii-calc-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"typesVersions": {
"<=3.9": {
"*": [
".types-compat/ts3.9/*",
".types-compat/ts3.9/*/index.d.ts"
]
}
},
"exports": {
".": {
"types": "./lib/index.d.ts",
Expand Down
8 changes: 0 additions & 8 deletions fixtures/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"typesVersions": {
"<=3.9": {
"*": [
".types-compat/ts3.9/*",
".types-compat/ts3.9/*/index.d.ts"
]
}
},
"dependencies": {
"@fixtures/jsii-calc-bundled": "file:../@fixtures/jsii-calc-bundled",
"@scope/jsii-calc-base": "^0.0.0",
Expand Down
1 change: 0 additions & 1 deletion package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions src/ambient/downlevel-dts.d.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import * as ts from 'typescript';

import { Assembler } from './assembler';
import { findDependencyDirectory } from './common/find-utils';
import { emitDownleveledDeclarations, TYPES_COMPAT } from './downlevel-dts';
import { Emitter } from './emitter';
import { normalizeConfigPath } from './helpers';
import { JsiiDiagnostic } from './jsii-diagnostic';
import { ProjectInfo } from './project-info';
import { WARNINGSCODE_FILE_NAME } from './transforms/deprecation-warnings';
Expand Down Expand Up @@ -314,15 +312,6 @@ export class Compiler implements Emitter {
LOG.error('Compilation errors prevented the JSII assembly from being created');
}

if (!hasErrors) {
emitDownleveledDeclarations(
this.projectRoot,
this.options.projectInfo.packageJson,
// outDir might be absolute. Need to normalize it.
normalizeConfigPath(this.projectRoot, this.tsconfig.compilerOptions.outDir),
);
}

// Some extra validation on the config.
// Make sure that { "./.warnings.jsii.js": "./.warnings.jsii.js" } is in the set of
// exports, if they are specified.
Expand Down Expand Up @@ -365,9 +354,6 @@ export class Compiler implements Emitter {
}

const pi = this.options.projectInfo;
const configDir = path.dirname(this.configPath);
const absoluteTypesCompat = path.resolve(configDir, pi.tsc?.outDir ?? '.', TYPES_COMPAT);
const relativeTypesCompat = path.relative(configDir, absoluteTypesCompat);

return {
compilerOptions: {
Expand All @@ -381,7 +367,6 @@ export class Compiler implements Emitter {
include: [pi.tsc?.rootDir != null ? path.join(pi.tsc.rootDir, '**', '*.ts') : path.join('**', '*.ts')],
exclude: [
'node_modules',
relativeTypesCompat,
...(pi.excludeTypescript ?? []),
...(pi.tsc?.outDir != null &&
(pi.tsc?.rootDir == null || path.resolve(pi.tsc.outDir).startsWith(path.resolve(pi.tsc.rootDir) + path.sep))
Expand Down
221 changes: 0 additions & 221 deletions src/downlevel-dts.ts

This file was deleted.

Loading

0 comments on commit 7be6ace

Please sign in to comment.