From 51145d91ee0da12c64b4e9b5834b029b60adcf0c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 30 Dec 2023 12:13:38 +0100 Subject: [PATCH 1/3] meta: fix `js2ts` script --- private/js2ts/index.mjs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/private/js2ts/index.mjs b/private/js2ts/index.mjs index 92f10c63e1..07bd3010e9 100755 --- a/private/js2ts/index.mjs +++ b/private/js2ts/index.mjs @@ -6,6 +6,7 @@ */ import { opendir, readFile, open, writeFile, rm } from 'node:fs/promises' +import { createRequire } from 'node:module' import { argv } from 'node:process' import { basename, extname, join } from 'node:path' import { existsSync } from 'node:fs' @@ -26,13 +27,29 @@ if (packageJSON.type !== 'module') { throw new Error('Cannot convert non-ESM package to TS') } -const references = Object.keys(packageJSON.dependencies || {}) +const uppyDeps = Object.keys(packageJSON.dependencies || {}) .concat(Object.keys(packageJSON.peerDependencies || {})) .concat(Object.keys(packageJSON.devDependencies || {})) .filter((pkg) => pkg.startsWith('@uppy/')) - .map((pkg) => ({ - path: `../${pkg.slice('@uppy/'.length)}/tsconfig.build.json`, - })) + +const paths = Object.fromEntries( + (function* generatePaths() { + const require = createRequire(packageRoot) + for (const pkg of uppyDeps) { + // eslint-disable-next-line import/no-dynamic-require + const pkgJson = require(`../../${pkg}/package.json`) + if (pkgJson.main || pkgJson.exports?.['.']) { + // If the package does have a main export (e.g. `import '@uppy/utils'` + // should flag an error because @uppy/utils does not have a main export). + yield [pkg, [`../${pkg.slice('@uppy/'.length)}/lib/index.js`]] + } + yield [`${pkg}/*`, [`../${pkg.slice('@uppy/'.length)}/*`]] + } + })(), +) +const references = uppyDeps.map((pkg) => ({ + path: `../${pkg.slice('@uppy/'.length)}/tsconfig.build.json`, +})) const depsNotYetConvertedToTS = references.filter( (ref) => !existsSync(new URL(ref.path, packageRoot)), @@ -93,6 +110,7 @@ await tsConfig.writeFile( compilerOptions: { emitDeclarationOnly: false, noEmit: true, + paths, }, include: ['./package.json', './src/**/*.*'], references, @@ -110,10 +128,11 @@ await writeFile( { extends: '../../../tsconfig.shared', compilerOptions: { + noImplicitAny: false, outDir: './lib', - rootDir: './src', + paths, resolveJsonModule: false, - noImplicitAny: false, + rootDir: './src', skipLibCheck: true, }, include: ['./src/**/*.*'], From 8e5b5c81c6364c210021e8a666f9d91f8577c444 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 30 Dec 2023 12:36:53 +0100 Subject: [PATCH 2/3] fixup! meta: fix `js2ts` script --- private/js2ts/index.mjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/private/js2ts/index.mjs b/private/js2ts/index.mjs index 07bd3010e9..536c1d5dac 100755 --- a/private/js2ts/index.mjs +++ b/private/js2ts/index.mjs @@ -38,10 +38,13 @@ const paths = Object.fromEntries( for (const pkg of uppyDeps) { // eslint-disable-next-line import/no-dynamic-require const pkgJson = require(`../../${pkg}/package.json`) - if (pkgJson.main || pkgJson.exports?.['.']) { - // If the package does have a main export (e.g. `import '@uppy/utils'` - // should flag an error because @uppy/utils does not have a main export). - yield [pkg, [`../${pkg.slice('@uppy/'.length)}/lib/index.js`]] + if (pkgJson.main) { + yield [pkg, [`../${pkg.slice('@uppy/'.length)}/${pkgJson.main}`]] + } else if (pkgJson.exports?.['.']) { + yield [ + pkg, + [`../${pkg.slice('@uppy/'.length)}/${pkgJson.exports['.']}`], + ] } yield [`${pkg}/*`, [`../${pkg.slice('@uppy/'.length)}/*`]] } From 6ce4d9a55fee99a9e514d166d7a4ad5aebbe3c3c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 30 Dec 2023 12:40:55 +0100 Subject: [PATCH 3/3] fixup! meta: fix `js2ts` script --- private/js2ts/index.mjs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/private/js2ts/index.mjs b/private/js2ts/index.mjs index 536c1d5dac..79921ce7e2 100755 --- a/private/js2ts/index.mjs +++ b/private/js2ts/index.mjs @@ -36,17 +36,15 @@ const paths = Object.fromEntries( (function* generatePaths() { const require = createRequire(packageRoot) for (const pkg of uppyDeps) { + const nickname = pkg.slice('@uppy/'.length) // eslint-disable-next-line import/no-dynamic-require - const pkgJson = require(`../../${pkg}/package.json`) - if (pkgJson.main) { - yield [pkg, [`../${pkg.slice('@uppy/'.length)}/${pkgJson.main}`]] - } else if (pkgJson.exports?.['.']) { - yield [ - pkg, - [`../${pkg.slice('@uppy/'.length)}/${pkgJson.exports['.']}`], - ] + const pkgJson = require(`../${nickname}/package.json`) + if (pkgJson.exports?.['.']) { + yield [pkg, [`../${nickname}/${pkgJson.exports['.']}`]] + } else if (pkgJson.main) { + yield [pkg, [`../${nickname}/${pkgJson.main}`]] } - yield [`${pkg}/*`, [`../${pkg.slice('@uppy/'.length)}/*`]] + yield [`${pkg}/*`, [`../${nickname}/*`]] } })(), )