Skip to content

Commit 5fb6b2a

Browse files
committed
Update to TS 5.3
1 parent 8c86774 commit 5fb6b2a

File tree

12 files changed

+80
-44
lines changed

12 files changed

+80
-44
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"devDependencies": {
1717
"@changesets/cli": "^2.26.1",
1818
"prettier": "^3.0.3",
19-
"typescript": "^5.2.2"
19+
"typescript": "5.3.2"
2020
},
2121
"engines": {
2222
"node": ">=18",

packages/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"tsc": "tsc -b",
3434
"local:install": "npm install -g .",
3535
"local:uninstall": "npm uninstall -g @arethetypeswrong/cli",
36-
"test": "tsc -b test && node --test test/dist",
36+
"test": "tsc -b test && node --test 'test/dist/**/*.test.js'",
3737
"prepack": "pnpm tsc"
3838
},
3939
"type": "module",
@@ -42,8 +42,8 @@
4242
"@types/marked-terminal": "^3.1.3",
4343
"@types/node": "^20.2.5",
4444
"@types/semver": "^7.5.3",
45-
"@types/ts-expose-internals": "npm:[email protected].2",
46-
"typescript": "^5.2.2"
45+
"ts-expose-internals": "5.3.2",
46+
"typescript": "5.3.2"
4747
},
4848
"dependencies": {
4949
"@arethetypeswrong/core": "0.13.0",

packages/cli/test/snapshots/[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$ attw [email protected] -f table-flipped
55
66
error while checking file:
7-
Expected double-quoted property name in JSON at position 450
7+
Expected double-quoted property name in JSON at position 450 (line 17 column 1)
88
99
1010
```

packages/core/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"scripts": {
2121
"tsc": "tsc",
22-
"test": "tsc -b test && node --test test/dist",
22+
"test": "tsc -b test && node --test 'test/dist/**/*.test.js'",
2323
"snapshot": "node scripts/createSnapshotFixture.js",
2424
"prepack": "pnpm tsc"
2525
},
@@ -50,14 +50,14 @@
5050
"@andrewbranch/untar.js": "^1.0.3",
5151
"fflate": "^0.7.4",
5252
"semver": "^7.5.4",
53-
"typescript": "^5.2.2",
53+
"typescript": "5.3.2",
5454
"validate-npm-package-name": "^5.0.0"
5555
},
5656
"devDependencies": {
5757
"@types/node": "^20.8.6",
5858
"@types/semver": "^7.5.0",
59-
"@types/ts-expose-internals": "npm:[email protected]",
60-
"@types/validate-npm-package-name": "^4.0.0"
59+
"@types/validate-npm-package-name": "^4.0.0",
60+
"ts-expose-internals": "5.3.2"
6161
},
6262
"engines": {
6363
"node": ">=18"

packages/core/src/checkPackage.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,17 @@ function getEntrypointResolution(
240240
}
241241
const moduleSpecifier = packageName + entrypoint.substring(1); // remove leading . before slash
242242
const importingFileName = resolutionKind === "node16-esm" ? "/index.mts" : "/index.ts";
243-
const resolutionMode = resolutionKind === "node16-esm" ? ts.ModuleKind.ESNext : ts.ModuleKind.CommonJS;
243+
const resolutionMode =
244+
resolutionKind === "node16-esm"
245+
? ts.ModuleKind.ESNext
246+
: resolutionKind === "node16-cjs"
247+
? ts.ModuleKind.CommonJS
248+
: undefined;
244249
const resolution = tryResolve();
245250
const implementationResolution = tryResolve(/*noDtsResolution*/ true);
246251
const files = resolution
247252
? host
248-
.createProgram([resolution.fileName])
253+
.createPrimaryProgram(resolution.fileName)
249254
.getSourceFiles()
250255
.map((f) => f.fileName)
251256
: undefined;

packages/core/src/internal/checks/exportDefaultDisagreement.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default defineCheck({
3838
implExports.has(ts.InternalSymbolName.ExportEquals)
3939
) {
4040
if (!implExports.has(ts.InternalSymbolName.Default)) {
41-
const checker = host.createProgram([implementationFileName], bindOptions).getTypeChecker();
41+
const checker = host.createAuxiliaryProgram([implementationFileName], bindOptions).getTypeChecker();
4242
if (
4343
!checker.getExportsAndPropertiesOfModule(implementationSourceFile.symbol).some((s) => s.name === "default")
4444
) {

packages/core/src/internal/checks/internalResolutionError.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export default defineCheck({
77
enumerateFiles: true,
88
dependencies: ({ resolutionOption, fileName }) => [resolutionOption, fileName],
99
execute: ([resolutionOption, fileName], context) => {
10+
if (!ts.hasTSFileExtension(fileName)) {
11+
return;
12+
}
1013
const host = context.hosts[resolutionOption];
1114
const sourceFile = host.getSourceFile(fileName);
1215
if (sourceFile?.imports) {
@@ -25,9 +28,12 @@ export default defineCheck({
2528
continue;
2629
}
2730
const resolutionMode = ts.getModeForUsageLocation(sourceFile, moduleSpecifier);
28-
const resolution = ts.getResolvedModule(sourceFile, moduleSpecifier.text, resolutionMode);
29-
31+
const resolution = host.getResolvedModule(sourceFile, moduleSpecifier.text, resolutionMode);
3032
if (!resolution) {
33+
throw new Error(`Expected resolution for '${moduleSpecifier.text}' in ${fileName}`);
34+
}
35+
36+
if (!resolution.resolvedModule) {
3137
problems.push({
3238
kind: "InternalResolutionError",
3339
resolutionOption,

packages/core/src/multiCompilerHost.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class CompilerHostWrapper {
4848
> = {};
4949
private traceCollector: TraceCollector = new TraceCollector();
5050
private sourceFileCache: Map<ts.Path, ts.SourceFile> = new Map();
51+
private resolvedModules: Exclude<ts.Program["resolvedModules"], undefined> = new Map();
5152
private languageVersion = ts.ScriptTarget.Latest;
5253

5354
constructor(fs: Package, moduleResolution: ts.ModuleResolutionKind, moduleKind: ts.ModuleKind) {
@@ -157,7 +158,27 @@ export class CompilerHostWrapper {
157158
return `${resolutionMode ?? 1}:${+!!noDtsResolution}:${+!!allowJs}:${moduleSpecifier}`;
158159
}
159160

160-
createProgram(rootNames: string[], extraOptions?: ts.CompilerOptions): ts.Program {
161+
createPrimaryProgram(rootName: string) {
162+
const program = ts.createProgram({
163+
rootNames: [rootName],
164+
options: this.compilerOptions,
165+
host: this.compilerHost,
166+
});
167+
168+
program.resolvedModules?.forEach((cache, path) => {
169+
let ownCache = this.resolvedModules.get(path);
170+
if (!ownCache) {
171+
this.resolvedModules.set(path, (ownCache = ts.createModeAwareCache()));
172+
}
173+
cache.forEach((resolution, key, mode) => {
174+
ownCache!.set(key, mode, resolution);
175+
});
176+
});
177+
178+
return program;
179+
}
180+
181+
createAuxiliaryProgram(rootNames: string[], extraOptions?: ts.CompilerOptions): ts.Program {
161182
if (
162183
extraOptions &&
163184
ts.changesAffectModuleResolution(
@@ -181,6 +202,10 @@ export class CompilerHostWrapper {
181202
});
182203
}
183204

205+
getResolvedModule(sourceFile: ts.SourceFile, moduleName: string, resolutionMode: ts.ResolutionMode) {
206+
return this.resolvedModules.get(sourceFile.path)?.get(moduleName, resolutionMode);
207+
}
208+
184209
private createCompilerHost(fs: Package, sourceFileCache: Map<ts.Path, ts.SourceFile>): ts.CompilerHost {
185210
return {
186211
fileExists: fs.fileExists.bind(fs),

packages/core/test/snapshots/[email protected]

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"File '/node_modules/moment.d.ts' does not exist.",
3131
"'package.json' has a 'typesVersions' field with version-specific path mappings.",
3232
"'package.json' has 'typings' field './moment.d.ts' that references '/node_modules/moment/moment.d.ts'.",
33-
"'package.json' has a 'typesVersions' entry '>=3.1' that matches compiler version '5.2.2', looking for a pattern to match module name 'moment.d.ts'.",
33+
"'package.json' has a 'typesVersions' entry '>=3.1' that matches compiler version '5.3.2', looking for a pattern to match module name 'moment.d.ts'.",
3434
"Module name 'moment.d.ts', matched pattern '*'.",
3535
"Trying substitution 'ts3.1-typings/*', candidate module location: 'ts3.1-typings/moment.d.ts'.",
3636
"File '/node_modules/moment/ts3.1-typings/moment.d.ts' exists - use it as a name resolution result.",
@@ -63,7 +63,7 @@
6363
"File '/node_modules/moment.d.ts' does not exist.",
6464
"'package.json' has a 'typesVersions' field with version-specific path mappings.",
6565
"'package.json' has 'typings' field './moment.d.ts' that references '/node_modules/moment/moment.d.ts'.",
66-
"'package.json' has a 'typesVersions' entry '>=3.1' that matches compiler version '5.2.2', looking for a pattern to match module name 'moment.d.ts'.",
66+
"'package.json' has a 'typesVersions' entry '>=3.1' that matches compiler version '5.3.2', looking for a pattern to match module name 'moment.d.ts'.",
6767
"Module name 'moment.d.ts', matched pattern '*'.",
6868
"Trying substitution 'ts3.1-typings/*', candidate module location: 'ts3.1-typings/moment.d.ts'.",
6969
"File '/node_modules/moment/ts3.1-typings/moment.d.ts' exists - use it as a name resolution result.",
@@ -92,7 +92,7 @@
9292
"Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration.",
9393
"File '/node_modules/moment/package.json' exists according to earlier cached lookups.",
9494
"'package.json' has 'typings' field './moment.d.ts' that references '/node_modules/moment/moment.d.ts'.",
95-
"'package.json' has a 'typesVersions' entry '>=3.1' that matches compiler version '5.2.2', looking for a pattern to match module name 'moment.d.ts'.",
95+
"'package.json' has a 'typesVersions' entry '>=3.1' that matches compiler version '5.3.2', looking for a pattern to match module name 'moment.d.ts'.",
9696
"Module name 'moment.d.ts', matched pattern '*'.",
9797
"Trying substitution 'ts3.1-typings/*', candidate module location: 'ts3.1-typings/moment.d.ts'.",
9898
"File '/node_modules/moment/ts3.1-typings/moment.d.ts' exists - use it as a name resolution result.",
@@ -125,7 +125,7 @@
125125
"File '/node_modules/moment.d.ts' does not exist.",
126126
"'package.json' has a 'typesVersions' field with version-specific path mappings.",
127127
"'package.json' has 'typings' field './moment.d.ts' that references '/node_modules/moment/moment.d.ts'.",
128-
"'package.json' has a 'typesVersions' entry '>=3.1' that matches compiler version '5.2.2', looking for a pattern to match module name 'moment.d.ts'.",
128+
"'package.json' has a 'typesVersions' entry '>=3.1' that matches compiler version '5.3.2', looking for a pattern to match module name 'moment.d.ts'.",
129129
"Module name 'moment.d.ts', matched pattern '*'.",
130130
"Trying substitution 'ts3.1-typings/*', candidate module location: 'ts3.1-typings/moment.d.ts'.",
131131
"File '/node_modules/moment/ts3.1-typings/moment.d.ts' exists - use it as a name resolution result.",

packages/core/test/snapshots/[email protected]

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"Found 'package.json' at '/node_modules/@types/react/package.json'.",
5050
"File '/node_modules/@types/react.d.ts' does not exist.",
5151
"'package.json' has a 'typesVersions' field with version-specific path mappings.",
52-
"'package.json' does not have a 'typesVersions' entry that matches version '5.2'.",
52+
"'package.json' does not have a 'typesVersions' entry that matches version '5.3'.",
5353
"'package.json' does not have a 'typings' field.",
5454
"'package.json' has 'types' field 'index.d.ts' that references '/node_modules/@types/react/index.d.ts'.",
5555
"File '/node_modules/@types/react/index.d.ts' exists - use it as a name resolution result.",
@@ -558,7 +558,7 @@
558558
"File name '/node_modules/react/package.json/index.js' has a '.js' extension - stripping it.",
559559
"File '/node_modules/@types/react/package.json' exists according to earlier cached lookups.",
560560
"'package.json' has a 'typesVersions' field with version-specific path mappings.",
561-
"'package.json' does not have a 'typesVersions' entry that matches version '5.2'.",
561+
"'package.json' does not have a 'typesVersions' entry that matches version '5.3'.",
562562
"File name '/node_modules/@types/react/package.json' has a '.json' extension - stripping it.",
563563
"File '/node_modules/@types/react/package.d.json.ts' does not exist.",
564564
"'package.json' does not have a 'typings' field.",
@@ -653,7 +653,7 @@
653653
"File name '/node_modules/react/package.json/index.js' has a '.js' extension - stripping it.",
654654
"File '/node_modules/@types/react/package.json' exists according to earlier cached lookups.",
655655
"'package.json' has a 'typesVersions' field with version-specific path mappings.",
656-
"'package.json' does not have a 'typesVersions' entry that matches version '5.2'.",
656+
"'package.json' does not have a 'typesVersions' entry that matches version '5.3'.",
657657
"File name '/node_modules/@types/react/package.json' has a '.json' extension - stripping it.",
658658
"File '/node_modules/@types/react/package.d.json.ts' does not exist.",
659659
"File '/node_modules/@types/react/package.json.d.ts' does not exist.",

0 commit comments

Comments
 (0)