Skip to content

Commit 6d9dda5

Browse files
authored
chore: stop aliasing typescript in dependencies (#3623)
Aliasing `typescript` to `typescript-3.9` results in occasionally surprising hoisting behavior, in particular using `npm 18`. In particular, if two distinct versions of `typescript` are installed, aliasing allows both to be hoisted at the top-level, which results in ambiguity as to which of them gets to have the `node_modules/.bin/tsc` symlink. This PR stops aliasing `typescript` to `typescript-3.9` and does the necessary work to ensure builds continue to operate smoothly, menaing it replaced TypeScript configuration files for jest with plain ESM configuration files including typed JSDoc comments (for IDE supprot to continue working as before), as `jest` otherwise uses `ts-node` to transform the configuration files, and `ts-node` uses the "most local" `typescript` library to perform this parsing (and unfortunately, `[email protected]` does not support the `ES2020` target we are using). This also required allowing `jsii.tsc.types` to be specified in the `package.json` file of jsii projects, as otherwise the TypeScript compiler attempts to load `@types/*` packages that are not compatible with `[email protected]` (for example, `@synclair/typebox` requires `typescript@>=4.5`). This setting is anyway generally useful in complex monorepo situations. --- 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
1 parent 623c0c1 commit 6d9dda5

File tree

81 files changed

+155
-119
lines changed

Some content is hidden

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

81 files changed

+155
-119
lines changed

eslint-config.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
env:
3+
es2020: true
34
jest: true
45
node: true
56

@@ -10,9 +11,9 @@ plugins:
1011

1112
parser: '@typescript-eslint/parser'
1213
parserOptions:
13-
ecmaVersion: 2018
14+
ecmaVersion: 2020
1415
impliedStrict: true
15-
sourceType: module
16+
sourceType: script
1617
project: ./**/tsconfig.json
1718

1819
extends:

gh-pages/content/user-guides/lib-author/configuration/index.md

+4

jest.config.ts renamed to jest.config.mjs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Config } from '@jest/types';
1+
import jest from '@jest/types';
22
import { defaults } from 'jest-config';
33
import { cpus } from 'os';
44
import { env } from 'process';
@@ -10,8 +10,10 @@ import { env } from 'process';
1010
* be overridden (for example, the coverage threshold), then a new
1111
* `jest.config.ts` file should be created that imports from this one and
1212
* modifies just what needs to be modified, typically using `overriddenConfig`.
13+
*
14+
* @type {jest.Config.InitialOptions}
1315
*/
14-
const config: Config.InitialOptions = {
16+
const config = {
1517
...defaults,
1618

1719
collectCoverage: true,
@@ -41,32 +43,31 @@ const config: Config.InitialOptions = {
4143
* operation works deeply on objects, but overrides that are not objects (e.g:
4244
* arrays, strings, ...) simply replace the original value.
4345
*
44-
* @param overrides values to be used for overriding the orignal configuration.
46+
* @param {jest.Config.InitialOptions} overrides values to be used for overriding the orignal configuration.
47+
*
48+
* @return {jest.Config.InitialOptions}
4549
*/
46-
export function overriddenConfig(overrides: Config.InitialOptions) {
50+
export function overriddenConfig(overrides) {
4751
return merge(config, overrides);
4852

49-
function merge<T>(original: T, override: T): T {
53+
function merge(original, override) {
5054
if (typeof original === 'object') {
5155
// Arrays are objects, too!
5256
if (Array.isArray(override)) {
5357
return override;
5458
}
5559

56-
const result: any = {};
60+
const result = {};
5761
const allKeys = new Set([
5862
...Object.keys(original),
5963
...Object.keys(override),
6064
]);
6165

6266
// TypeScript appears to choke if we do the "as any" in the same
6367
// expression as the key access, so we delcare surrogate varibales...
64-
const originalAsAny = original as any;
65-
const overrideAsAny = override as any;
66-
6768
for (const key of Array.from(allKeys).sort()) {
68-
const originalValue: unknown = originalAsAny[key];
69-
const overrideValue: unknown = overrideAsAny[key];
69+
const originalValue = original[key];
70+
const overrideValue = override[key];
7071
if (originalValue == null) {
7172
result[key] = overrideValue;
7273
} else if (overrideValue == null) {

package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@
5050
],
5151
"nohoist": [
5252
"**/@fixtures/jsii-calc-bundled",
53-
"**/@fixtures/jsii-calc-bundled/**"
53+
"**/@fixtures/jsii-calc-bundled/**",
54+
"**/typescript"
5455
]
5556
},
5657
"resolutions": {
57-
"@types/prettier": "2.6.0"
58+
"minipass": "3.2.1"
59+
},
60+
"resolutions_info": {
61+
"minipass": "https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/60901"
5862
}
5963
}

packages/@jsii/benchmarks/lib/suite/aws-cdk-lib/build-with-jsii.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Compiler } from 'jsii/lib/compiler';
22
import { loadProjectInfo } from 'jsii/lib/project-info';
33
import * as path from 'node:path';
44
import * as process from 'node:process';
5-
import * as ts from 'typescript-3.9';
5+
import * as ts from 'typescript';
66

77
import type { Context } from '.';
88

packages/@jsii/benchmarks/lib/suite/aws-cdk-lib/build-with-tsc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from 'fs-extra';
22
import * as path from 'node:path';
33
import * as process from 'node:process';
4-
import * as ts from 'typescript-3.9';
4+
import * as ts from 'typescript';
55

66
import type { Context } from '.';
77

packages/@jsii/benchmarks/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"jsii": "^0.0.0",
1010
"npm": "^8.12.1",
1111
"tar": "^6.1.11",
12-
"typescript-3.9": "npm:typescript@~3.9.10",
12+
"typescript": "~3.9.10",
1313
"yargs": "^16.2.0"
1414
},
1515
"devDependencies": {

packages/@jsii/benchmarks/scripts/snapshot-package.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as glob from 'glob';
44
import * as os from 'os';
55
import * as path from 'path';
66
import * as tar from 'tar';
7-
import * as ts from 'typescript-3.9';
7+
import * as ts from 'typescript';
88

99
import { cdkTagv2_21_1, cdkv2_21_1 } from '../lib/constants';
1010

packages/@jsii/runtime/jest.config.ts renamed to packages/@jsii/check-node/jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { overriddenConfig } from '../../../jest.config';
1+
import { overriddenConfig } from '../../../jest.config.mjs';
22

33
export default overriddenConfig({
44
coveragePathIgnorePatterns: [

packages/@jsii/integ-test/jest.config.ts renamed to packages/@jsii/integ-test/jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { overriddenConfig } from '../../../jest.config';
1+
import { overriddenConfig } from '../../../jest.config.mjs';
22

33
export default overriddenConfig({
44
// We don't need coverage for the integration tests

packages/@jsii/kernel/jest.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import config from '../../../jest.config.mjs';
2+
3+
export default config;

packages/@jsii/kernel/jest.config.ts

-3
This file was deleted.

packages/@jsii/check-node/jest.config.ts renamed to packages/@jsii/runtime/jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { overriddenConfig } from '../../../jest.config';
1+
import { overriddenConfig } from '../../../jest.config.mjs';
22

33
export default overriddenConfig({
44
coveragePathIgnorePatterns: [

packages/@jsii/spec/jest.config.ts renamed to packages/@jsii/spec/jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { overriddenConfig } from '../../../jest.config';
1+
import { overriddenConfig } from '../../../jest.config.mjs';
22

33
export default overriddenConfig({
44
coverageThreshold: {

packages/@scope/jsii-calc-base-of-base/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
},
5959
"tsc": {
6060
"outDir": "./build",
61-
"rootDir": "."
61+
"rootDir": ".",
62+
"types": []
6263
},
6364
"versionFormat": "short",
6465
"metadata": {

packages/@scope/jsii-calc-base/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
"module": "scope.jsii_calc_base"
7373
}
7474
},
75+
"tsc": {
76+
"types": []
77+
},
7578
"versionFormat": "short"
7679
}
7780
}

packages/@scope/jsii-calc-lib/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@
7070
},
7171
"tsc": {
7272
"outDir": "build",
73-
"sourceMap": false
73+
"sourceMap": false,
74+
"types": []
7475
},
7576
"versionFormat": "short",
7677
"metadata": {

packages/codemaker/jest.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import config from '../../jest.config.mjs';
2+
3+
export default config;

packages/codemaker/jest.config.ts

-3
This file was deleted.

packages/jsii-calc/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
]
8282
}
8383
},
84+
"tsc": {
85+
"types": [
86+
"node"
87+
]
88+
},
8489
"metadata": {
8590
"jsii:boolean": true,
8691
"jsii:number": 1337,

packages/jsii-config/jest.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import config from '../../jest.config.mjs';
2+
3+
export default config;

packages/jsii-config/jest.config.ts

-3
This file was deleted.

packages/jsii-diff/jest.config.mjs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import config from '../../jest.config.mjs';
2+
3+
export default config;

packages/jsii-diff/jest.config.ts

-3
This file was deleted.

packages/jsii-pacmak/jest.config.ts renamed to packages/jsii-pacmak/jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { overriddenConfig } from '../../jest.config';
1+
import { overriddenConfig } from '../../jest.config.mjs';
22

33
export default overriddenConfig({
44
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/test'],

packages/jsii-reflect/jest.config.ts renamed to packages/jsii-reflect/jest.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { overriddenConfig } from '../../jest.config';
1+
import { overriddenConfig } from '../../jest.config.mjs';
22

33
export default overriddenConfig({
44
coverageThreshold: {

packages/jsii-rosetta/jest.config.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createRequire } from 'node:module';
2+
import { overriddenConfig } from '../../jest.config.mjs';
3+
4+
export default overriddenConfig({
5+
setupFiles: [createRequire(import.meta.url).resolve('./jestsetup.js')],
6+
});

packages/jsii-rosetta/jest.config.ts

-7
This file was deleted.

packages/jsii-rosetta/lib/fixtures.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fs from 'fs-extra';
22
import * as path from 'path';
3-
import { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript-3.9';
3+
import { createSourceFile, ScriptKind, ScriptTarget, SyntaxKind } from 'typescript';
44

55
import { TypeScriptSnippet, SnippetParameters, ApiLocation } from './snippet';
66

packages/jsii-rosetta/lib/jsii/jsii-types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { inferredTypeOfExpression, BuiltInType, builtInTypeName, mapElementType } from '../typescript/types';
44
import { hasAnyFlag, analyzeStructType, JsiiSymbol } from './jsii-utils';

packages/jsii-rosetta/lib/jsii/jsii-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as spec from '@jsii/spec';
22
import { symbolIdentifier } from 'jsii';
3-
import * as ts from 'typescript-3.9';
3+
import * as ts from 'typescript';
44

55
import { AstRenderer } from '../renderer';
66
import { typeContainsUndefined } from '../typescript/types';

packages/jsii-rosetta/lib/languages/csharp.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { determineJsiiType, JsiiType, ObjectLiteralStruct } from '../jsii/jsii-types';
44
import { JsiiSymbol, simpleName, namespaceName } from '../jsii/jsii-utils';

packages/jsii-rosetta/lib/languages/default.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { analyzeObjectLiteral, ObjectLiteralStruct } from '../jsii/jsii-types';
44
import { isNamedLikeStruct, isJsiiProtocolType } from '../jsii/jsii-utils';

packages/jsii-rosetta/lib/languages/go.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// import { JsiiSymbol, simpleName, namespaceName } from '../jsii/jsii-utils';
22
// import { jsiiTargetParameter } from '../jsii/packages';
33
import { AssertionError } from 'assert';
4-
import * as ts from 'typescript-3.9';
4+
import * as ts from 'typescript';
55

66
import { analyzeObjectLiteral, determineJsiiType, JsiiType, ObjectLiteralStruct } from '../jsii/jsii-types';
77
import { OTree } from '../o-tree';

packages/jsii-rosetta/lib/languages/java.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { determineJsiiType, JsiiType, analyzeObjectLiteral, ObjectLiteralStruct } from '../jsii/jsii-types';
44
import { JsiiSymbol, simpleName, namespaceName } from '../jsii/jsii-utils';

packages/jsii-rosetta/lib/languages/python.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { determineJsiiType, JsiiType, ObjectLiteralStruct } from '../jsii/jsii-types';
44
import {

packages/jsii-rosetta/lib/languages/record-references.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { lookupJsiiSymbol } from '../jsii/jsii-utils';
44
import { TargetLanguage } from '../languages/target-language';

packages/jsii-rosetta/lib/languages/visualize.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { OTree } from '../o-tree';
44
import { AstRenderer, AstHandler, nimpl, CommentSyntax } from '../renderer';

packages/jsii-rosetta/lib/markdown/replace-typescript-transform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export class ReplaceTypeScriptTransform extends ReplaceCodeTransform {
1111
public constructor(api: ApiLocation, strict: boolean, replacer: TypeScriptReplacer) {
1212
super((block, line) => {
1313
const languageParts = block.language ? block.language.split(' ') : [];
14-
if (languageParts[0] !== 'typescript-3.9' && languageParts[0] !== 'ts') {
14+
if (languageParts[0] !== 'typescript' && languageParts[0] !== 'ts') {
1515
return block;
1616
}
1717

packages/jsii-rosetta/lib/renderer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { TargetLanguage } from './languages';
44
import { NO_SYNTAX, OTree, UnknownSyntax, Span } from './o-tree';

packages/jsii-rosetta/lib/rosetta-reader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export class RosettaTabletReader {
259259

260260
const translated = this.translateSnippet(snippet, targetLang);
261261

262-
return translated ?? { language: 'typescript-3.9', source: example };
262+
return translated ?? { language: 'typescript', source: example };
263263
}
264264

265265
/**

packages/jsii-rosetta/lib/tablets/tablets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class TranslatedSnippet {
206206
public get originalSource(): Translation {
207207
return {
208208
source: this.snippet.translations[ORIGINAL_SNIPPET_KEY].source,
209-
language: 'typescript-3.9',
209+
language: 'typescript',
210210
didCompile: this.snippet.didCompile,
211211
};
212212
}

packages/jsii-rosetta/lib/translate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22
import { inspect } from 'util';
33

44
import { TARGET_LANGUAGES, TargetLanguage } from './languages';

packages/jsii-rosetta/lib/typescript/ast-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { AstRenderer } from '../renderer';
44

packages/jsii-rosetta/lib/typescript/imports.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { JsiiSymbol, parentSymbol, lookupJsiiSymbolFromNode } from '../jsii/jsii-utils';
44
import { AstRenderer } from '../renderer';

packages/jsii-rosetta/lib/typescript/syntax-kind-counter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
import { Spans } from './visible-spans';
44

packages/jsii-rosetta/lib/typescript/ts-compiler.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from 'typescript-3.9';
1+
import * as ts from 'typescript';
22

33
export class TypeScriptCompiler {
44
private readonly realHost = ts.createCompilerHost(STANDARD_COMPILER_OPTIONS, true);

0 commit comments

Comments
 (0)