Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: fix js2ts script #4844

Merged
merged 3 commits into from
Dec 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions private/js2ts/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -26,13 +27,30 @@ 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) {
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}`]]
}
yield [`${pkg}/*`, [`../${nickname}/*`]]
}
})(),
)
const references = uppyDeps.map((pkg) => ({
path: `../${pkg.slice('@uppy/'.length)}/tsconfig.build.json`,
}))

const depsNotYetConvertedToTS = references.filter(
(ref) => !existsSync(new URL(ref.path, packageRoot)),
Expand Down Expand Up @@ -93,6 +111,7 @@ await tsConfig.writeFile(
compilerOptions: {
emitDeclarationOnly: false,
noEmit: true,
paths,
},
include: ['./package.json', './src/**/*.*'],
references,
Expand All @@ -110,10 +129,11 @@ await writeFile(
{
extends: '../../../tsconfig.shared',
compilerOptions: {
noImplicitAny: false,
outDir: './lib',
rootDir: './src',
paths,
resolveJsonModule: false,
noImplicitAny: false,
rootDir: './src',
skipLibCheck: true,
},
include: ['./src/**/*.*'],
Expand Down
Loading