diff --git a/.config/.prettierignore b/.config/.prettierignore index b939d452b..9245daa3e 100644 --- a/.config/.prettierignore +++ b/.config/.prettierignore @@ -12,3 +12,6 @@ ../example/docs/ **/tmp **/.vs + +# Remove once Prettier has support +../src/test/converter2/behavior/resolutionMode.ts diff --git a/.gitignore b/.gitignore index 5f78983dd..f8b415d1d 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ yarn-error.log /src/test/renderer/*/doc /src/test/renderer/testProject/json.json **/node_modules/ +!src/test/converter2/behavior/node_modules/ /coverage/ /dist/ /docs diff --git a/example/package-lock.json b/example/package-lock.json index caee83b65..216c4bec6 100644 --- a/example/package-lock.json +++ b/example/package-lock.json @@ -17,7 +17,7 @@ "react-dom": "^17.0.2" }, "devDependencies": { - "typescript": "^5.1.3" + "typescript": "^5.3.2" } }, "node_modules/@types/lodash": { @@ -122,9 +122,9 @@ } }, "node_modules/typescript": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz", - "integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -226,9 +226,9 @@ } }, "typescript": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz", - "integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "dev": true } } diff --git a/example/package.json b/example/package.json index 0e39ed0ed..d12880461 100644 --- a/example/package.json +++ b/example/package.json @@ -19,6 +19,6 @@ "react-dom": "^17.0.2" }, "devDependencies": { - "typescript": "^5.1.3" + "typescript": "^5.3.2" } } diff --git a/package-lock.json b/package-lock.json index a96f00d3c..7e5fa830a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,13 +32,13 @@ "prettier": "3.0.3", "puppeteer": "^13.5.2", "ts-node": "^10.9.1", - "typescript": "5.2.2" + "typescript": "5.3.2" }, "engines": { "node": ">= 16" }, "peerDependencies": { - "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x" + "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -3228,9 +3228,9 @@ } }, "node_modules/typescript": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", - "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.2.tgz", + "integrity": "sha512-6l+RyNy7oAHDfxC4FzSJcz9vnjTKxrLpDG5M2Vu4SHRVNg6xzqZp6LYSR9zjqQTu8DU/f5xwxUdADOkbrIX2gQ==", "dev": true, "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index 7b8ad3eb6..f0bdf81f2 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "shiki": "^0.14.1" }, "peerDependencies": { - "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x" + "typescript": "4.6.x || 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x || 5.2.x || 5.3.x" }, "devDependencies": { "@types/lunr": "^2.3.5", @@ -47,7 +47,7 @@ "prettier": "3.0.3", "puppeteer": "^13.5.2", "ts-node": "^10.9.1", - "typescript": "5.2.2" + "typescript": "5.3.2" }, "files": [ "/bin", diff --git a/src/test/behavior.c2.test.ts b/src/test/behavior.c2.test.ts index 27ad9c4ec..1deeda6c5 100644 --- a/src/test/behavior.c2.test.ts +++ b/src/test/behavior.c2.test.ts @@ -970,4 +970,10 @@ describe("Behavior Tests", () => { "asConstEnum", ]); }); + + it("Respects resolution-mode when resolving types", () => { + app.options.setValue("excludeExternals", false); + const MergedType = query(convert("resolutionMode"), "MergedType"); + equal(MergedType.children?.map((child) => child.name), ["cjs", "esm"]); + }); }); diff --git a/src/test/converter2/behavior/node_modules/dual/cjs.d.ts b/src/test/converter2/behavior/node_modules/dual/cjs.d.ts new file mode 100644 index 000000000..33a97f5b8 --- /dev/null +++ b/src/test/converter2/behavior/node_modules/dual/cjs.d.ts @@ -0,0 +1 @@ +export type TypeFromRequire = { cjs: true } diff --git a/src/test/converter2/behavior/node_modules/dual/esm.d.ts b/src/test/converter2/behavior/node_modules/dual/esm.d.ts new file mode 100644 index 000000000..9eed09119 --- /dev/null +++ b/src/test/converter2/behavior/node_modules/dual/esm.d.ts @@ -0,0 +1 @@ +export type TypeFromImport = { esm: true } diff --git a/src/test/converter2/behavior/node_modules/dual/package.json b/src/test/converter2/behavior/node_modules/dual/package.json new file mode 100644 index 000000000..215e40301 --- /dev/null +++ b/src/test/converter2/behavior/node_modules/dual/package.json @@ -0,0 +1,13 @@ +{ + "name": "dual", + "exports": { + ".": { + "import": { + "types": "./esm.d.ts" + }, + "require": { + "types": "./cjs.d.ts" + } + } + } +} diff --git a/src/test/converter2/behavior/resolutionMode.ts b/src/test/converter2/behavior/resolutionMode.ts new file mode 100644 index 000000000..e4e1db574 --- /dev/null +++ b/src/test/converter2/behavior/resolutionMode.ts @@ -0,0 +1,11 @@ +// Resolve `pkg` as if we were importing with a `require()` +import type { TypeFromRequire } from "dual" with { + "resolution-mode": "require" +}; + +// Resolve `pkg` as if we were importing with an `import` +import type { TypeFromImport } from "dual" with { + "resolution-mode": "import" +}; + +export interface MergedType extends TypeFromRequire, TypeFromImport {} diff --git a/src/test/converter2/issues/gh2036.ts b/src/test/converter2/issues/gh2036.ts index c23220a93..617b91437 100644 --- a/src/test/converter2/issues/gh2036.ts +++ b/src/test/converter2/issues/gh2036.ts @@ -1,10 +1,10 @@ -declare const SingleSimpleCtor: { +export declare const SingleSimpleCtor: { new (a: string, b: string): Array; }; -declare const MultipleSimpleCtors: { +export declare const MultipleSimpleCtors: { new (a: string, b: string): Array; new (a: string, b: number): Array; }; -const AnotherCtor = null! as new (a: string) => Object; +export const AnotherCtor = null! as new (a: string) => Object; diff --git a/src/test/converter2/tsconfig.json b/src/test/converter2/tsconfig.json index 65b24c4a5..61e0d66ca 100644 --- a/src/test/converter2/tsconfig.json +++ b/src/test/converter2/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "strict": true, - "module": "CommonJS", + "module": "Node16", "checkJs": true, "outDir": "dist", "target": "ESNext", diff --git a/src/test/programs.ts b/src/test/programs.ts index e3f9ea3a6..63055f0ea 100644 --- a/src/test/programs.ts +++ b/src/test/programs.ts @@ -125,7 +125,8 @@ export function getConverter2Program() { ); const errors = ts.getPreEmitDiagnostics(converter2Program); - equal(errors, []); + app.logger.diagnostics(errors); + equal(errors.length, 0); } return converter2Program;