From 8130b88e8f79580ea72efe15b29effef2592a8f3 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 30 Dec 2023 23:47:36 +0100 Subject: [PATCH 1/2] meta: fix `js2ts` script --- packages/@uppy/core/tsconfig.build.json | 5 +++++ packages/@uppy/core/tsconfig.json | 7 ++++++- packages/@uppy/locales/tsconfig.build.json | 3 +++ packages/@uppy/locales/tsconfig.json | 3 +++ private/js2ts/index.mjs | 12 +++++++----- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/@uppy/core/tsconfig.build.json b/packages/@uppy/core/tsconfig.build.json index fbe7f66948..db8238509c 100644 --- a/packages/@uppy/core/tsconfig.build.json +++ b/packages/@uppy/core/tsconfig.build.json @@ -5,6 +5,11 @@ "rootDir": "./src", "resolveJsonModule": false, "noImplicitAny": false, + "paths": { + "@uppy/store-default": ["../store-default/src/index.js"], + "@uppy/store-default/lib/*": ["../store-default/src/*"], + "@uppy/utils/lib/*": ["../utils/src/*"] + }, "skipLibCheck": true }, "include": ["./src/**/*.*"], diff --git a/packages/@uppy/core/tsconfig.json b/packages/@uppy/core/tsconfig.json index 2362543d82..a23d8f86ee 100644 --- a/packages/@uppy/core/tsconfig.json +++ b/packages/@uppy/core/tsconfig.json @@ -2,7 +2,12 @@ "extends": "../../../tsconfig.shared", "compilerOptions": { "emitDeclarationOnly": false, - "noEmit": true + "noEmit": true, + "paths": { + "@uppy/store-default": ["../store-default/src/index.js"], + "@uppy/store-default/lib/*": ["../store-default/src/*"], + "@uppy/utils/lib/*": ["../utils/src/*"] + } }, "include": ["./package.json", "./src/**/*.*"], "references": [ diff --git a/packages/@uppy/locales/tsconfig.build.json b/packages/@uppy/locales/tsconfig.build.json index 0f80e6dad1..b76d049caf 100644 --- a/packages/@uppy/locales/tsconfig.build.json +++ b/packages/@uppy/locales/tsconfig.build.json @@ -3,6 +3,9 @@ "compilerOptions": { "outDir": "./lib", "rootDir": "./src", + "paths": { + "@uppy/utils/lib/*": ["../utils/src/*"] + }, "skipLibCheck": true }, "include": ["./src/**/*.*"], diff --git a/packages/@uppy/locales/tsconfig.json b/packages/@uppy/locales/tsconfig.json index 284d675390..f8a97e4278 100644 --- a/packages/@uppy/locales/tsconfig.json +++ b/packages/@uppy/locales/tsconfig.json @@ -2,6 +2,9 @@ "extends": "../../../tsconfig.shared", "compilerOptions": { "emitDeclarationOnly": false, + "paths": { + "@uppy/utils/lib/*": ["../utils/src/*"] + }, "noEmit": true }, "include": ["./package.json", "./src/**/*.*"], diff --git a/private/js2ts/index.mjs b/private/js2ts/index.mjs index 79921ce7e2..522a802678 100755 --- a/private/js2ts/index.mjs +++ b/private/js2ts/index.mjs @@ -32,6 +32,7 @@ const uppyDeps = Object.keys(packageJSON.dependencies || {}) .concat(Object.keys(packageJSON.devDependencies || {})) .filter((pkg) => pkg.startsWith('@uppy/')) +// We want TS to check the source files so it doesn't use outdated (or missing) types: const paths = Object.fromEntries( (function* generatePaths() { const require = createRequire(packageRoot) @@ -39,12 +40,13 @@ const paths = Object.fromEntries( const nickname = pkg.slice('@uppy/'.length) // eslint-disable-next-line import/no-dynamic-require const pkgJson = require(`../${nickname}/package.json`) - if (pkgJson.exports?.['.']) { - yield [pkg, [`../${nickname}/${pkgJson.exports['.']}`]] - } else if (pkgJson.main) { - yield [pkg, [`../${nickname}/${pkgJson.main}`]] + if (pkgJson.main) { + yield [ + pkg, + [`../${nickname}/${pkgJson.main.replace(/^(\.\/)?lib\//, 'src/')}`], + ] } - yield [`${pkg}/*`, [`../${nickname}/*`]] + yield [`${pkg}/lib/*`, [`../${nickname}/src/*`]] } })(), ) From f36aaae3873ed8c99a03562e62eb60838d4fa73a Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 31 Dec 2023 00:31:16 +0100 Subject: [PATCH 2/2] fixup! meta: fix `js2ts` script --- .github/workflows/ci.yml | 2 ++ private/js2ts/index.mjs | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 461fbe8054..1d05c5b8f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -101,6 +101,7 @@ jobs: corepack yarn run build:lib corepack yarn run build:companion corepack yarn run build:locale-pack + find packages/@uppy -name 'tsconfig.json' -delete - name: Run type tests run: corepack yarn run test:type - name: Drop manual tyoes @@ -108,6 +109,7 @@ jobs: # We don't want to remove that file to not break users. # However, we want to validate the types based on the types inferred from source. run: | + git checkout -- packages/@uppy node --input-type=module <<'EOF' import { existsSync } from 'node:fs'; import { opendir, readFile, writeFile } from 'node:fs/promises'; diff --git a/private/js2ts/index.mjs b/private/js2ts/index.mjs index 522a802678..d2098d0f08 100755 --- a/private/js2ts/index.mjs +++ b/private/js2ts/index.mjs @@ -27,10 +27,12 @@ if (packageJSON.type !== 'module') { throw new Error('Cannot convert non-ESM package to TS') } -const uppyDeps = Object.keys(packageJSON.dependencies || {}) - .concat(Object.keys(packageJSON.peerDependencies || {})) - .concat(Object.keys(packageJSON.devDependencies || {})) - .filter((pkg) => pkg.startsWith('@uppy/')) +const uppyDeps = new Set( + Object.keys(packageJSON.dependencies || {}) + .concat(Object.keys(packageJSON.peerDependencies || {})) + .concat(Object.keys(packageJSON.devDependencies || {})) + .filter((pkg) => pkg.startsWith('@uppy/')), +) // We want TS to check the source files so it doesn't use outdated (or missing) types: const paths = Object.fromEntries( @@ -50,7 +52,7 @@ const paths = Object.fromEntries( } })(), ) -const references = uppyDeps.map((pkg) => ({ +const references = Array.from(uppyDeps, (pkg) => ({ path: `../${pkg.slice('@uppy/'.length)}/tsconfig.build.json`, }))