From d6e2ecf2200dc1a17a5b38b3076e82b82744d669 Mon Sep 17 00:00:00 2001 From: Samuel Hinshaw Date: Mon, 29 Jul 2024 21:36:35 -0700 Subject: [PATCH 1/4] support typescript 5.5 --- dash/extract-meta.js | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/dash/extract-meta.js b/dash/extract-meta.js index c9a3fb11ed..6e55dcb793 100755 --- a/dash/extract-meta.js +++ b/dash/extract-meta.js @@ -37,24 +37,7 @@ if (!src.length) { } if (fs.existsSync('tsconfig.json')) { - tsconfig = JSON.parse(fs.readFileSync('tsconfig.json')).compilerOptions; - // Map moduleResolution to the appropriate enum. - switch (tsconfig.moduleResolution) { - case 'node': - tsconfig.moduleResolution = ts.ModuleResolutionKind.NodeJs; - break; - case 'node16': - tsconfig.moduleResolution = ts.ModuleResolutionKind.Node16; - break; - case 'nodenext': - tsconfig.moduleResolution = ts.ModuleResolutionKind.NodeNext; - break; - case 'classic': - tsconfig.moduleResolution = ts.ModuleResolutionKind.Classic; - break; - default: - break; - } + tsconfig = ts.getParsedCommandLineOfConfigFile('tsconfig.json', {}, ts.sys); } let failedBuild = false; From 9547dc92efc66be87242ed73f914d18bc9ed66c6 Mon Sep 17 00:00:00 2001 From: Samuel Hinshaw Date: Mon, 29 Jul 2024 22:12:41 -0700 Subject: [PATCH 2/4] extend esmoduleinterop inline --- dash/extract-meta.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dash/extract-meta.js b/dash/extract-meta.js index 6e55dcb793..91e01a407b 100755 --- a/dash/extract-meta.js +++ b/dash/extract-meta.js @@ -37,7 +37,7 @@ if (!src.length) { } if (fs.existsSync('tsconfig.json')) { - tsconfig = ts.getParsedCommandLineOfConfigFile('tsconfig.json', {}, ts.sys); + tsconfig = ts.getParsedCommandLineOfConfigFile('tsconfig.json', { esModuleInterop: true }, ts.sys); } let failedBuild = false; @@ -187,7 +187,7 @@ function gatherComponents(sources, components = {}) { return components; } - const program = ts.createProgram(filepaths, {...tsconfig, esModuleInterop: true}); + const program = ts.createProgram(filepaths, tsconfig); const checker = program.getTypeChecker(); const coerceValue = t => { From 0f8f7d8ee4a69faa06a4d3b1c507d147dbdede4f Mon Sep 17 00:00:00 2001 From: Samuel Hinshaw Date: Mon, 29 Jul 2024 22:14:46 -0700 Subject: [PATCH 3/4] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c938ea994b..4fa8115d08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## Added - [#2881](https://github.com/plotly/dash/pull/2881) Add outputs_list to window.dash_clientside.callback_context. Fixes [#2877](https://github.com/plotly/dash/issues/2877). +- [#2936](https://github.com/plotly/dash/pull/2936) Adds support for TypeScript 5.5+. ## Fixed From 5390e4b8cdb34358bcb24efd7ec64e65d653e364 Mon Sep 17 00:00:00 2001 From: Samuel Hinshaw Date: Thu, 22 Aug 2024 10:33:55 -0700 Subject: [PATCH 4/4] Just get the compiler options --- dash/extract-meta.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dash/extract-meta.js b/dash/extract-meta.js index 91e01a407b..5675caab1a 100755 --- a/dash/extract-meta.js +++ b/dash/extract-meta.js @@ -21,8 +21,6 @@ const reservedPatterns = args[1] ? args[1].split('|').map(part => new RegExp(part)) : []; -let tsconfig = {}; - function help() { console.error('usage: '); console.error( @@ -36,8 +34,15 @@ if (!src.length) { process.exit(1); } -if (fs.existsSync('tsconfig.json')) { - tsconfig = ts.getParsedCommandLineOfConfigFile('tsconfig.json', { esModuleInterop: true }, ts.sys); +function getTsConfigCompilerOptions() { + // Since extract-meta can be run on JavaScript sources, if trying to get the + // config doesn't work, we can fall back gracefully. + try { + const tsconfig = ts.getParsedCommandLineOfConfigFile('tsconfig.json', { esModuleInterop: true }, ts.sys); + return tsconfig?.options ?? {}; + } catch { + return {}; + } } let failedBuild = false; @@ -187,7 +192,7 @@ function gatherComponents(sources, components = {}) { return components; } - const program = ts.createProgram(filepaths, tsconfig); + const program = ts.createProgram(filepaths, getTsConfigCompilerOptions()); const checker = program.getTypeChecker(); const coerceValue = t => {