From bec04b58a1e5e66cc740461d2476f903973149d3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 26 Jan 2023 10:51:23 -0500 Subject: [PATCH] DRY --- packages/kit/src/core/sync/ts.js | 6 ++++++ packages/kit/src/core/sync/write_tsconfig.js | 7 +------ packages/kit/src/core/sync/write_types/index.js | 8 +------- 3 files changed, 8 insertions(+), 13 deletions(-) create mode 100644 packages/kit/src/core/sync/ts.js diff --git a/packages/kit/src/core/sync/ts.js b/packages/kit/src/core/sync/ts.js new file mode 100644 index 000000000000..61c79e37f882 --- /dev/null +++ b/packages/kit/src/core/sync/ts.js @@ -0,0 +1,6 @@ +/** @type {import('typescript')} */ +// @ts-ignore +export let ts = undefined; +try { + ts = (await import('typescript')).default; +} catch {} diff --git a/packages/kit/src/core/sync/write_tsconfig.js b/packages/kit/src/core/sync/write_tsconfig.js index e26c2762ca0b..e94f85d0a60a 100644 --- a/packages/kit/src/core/sync/write_tsconfig.js +++ b/packages/kit/src/core/sync/write_tsconfig.js @@ -3,12 +3,7 @@ import path from 'path'; import colors from 'kleur'; import { posixify } from '../../utils/filesystem.js'; import { write_if_changed } from './utils.js'; - -/** @type {import('typescript') | undefined} */ -let ts = undefined; -try { - ts = (await import('typescript')).default; -} catch {} +import { ts } from './ts.js'; /** * @param {string} cwd diff --git a/packages/kit/src/core/sync/write_types/index.js b/packages/kit/src/core/sync/write_types/index.js index 83cb0e7e8b58..2d90123ddbb6 100644 --- a/packages/kit/src/core/sync/write_types/index.js +++ b/packages/kit/src/core/sync/write_types/index.js @@ -3,6 +3,7 @@ import path from 'path'; import MagicString from 'magic-string'; import { posixify, rimraf, walk } from '../../../utils/filesystem.js'; import { compact } from '../../../utils/array.js'; +import { ts } from '../ts.js'; /** * @typedef {{ @@ -20,13 +21,6 @@ import { compact } from '../../../utils/array.js'; * @typedef {Map} RoutesMap */ -/** @type {import('typescript')} */ -// @ts-ignore -let ts = undefined; -try { - ts = (await import('typescript')).default; -} catch {} - const cwd = process.cwd(); /**