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 #4846

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ 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
# For backward compatiblity reasons, Uppy plugins ship a manual crafted d.ts file.
# 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';
Expand Down
5 changes: 5 additions & 0 deletions packages/@uppy/core/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"rootDir": "./src",
"resolveJsonModule": false,
"noImplicitAny": false,
"paths": {
Murderlon marked this conversation as resolved.
Show resolved Hide resolved
"@uppy/store-default": ["../store-default/src/index.js"],
"@uppy/store-default/lib/*": ["../store-default/src/*"],
"@uppy/utils/lib/*": ["../utils/src/*"]
},
"skipLibCheck": true
},
"include": ["./src/**/*.*"],
Expand Down
7 changes: 6 additions & 1 deletion packages/@uppy/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/locales/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"compilerOptions": {
"outDir": "./lib",
"rootDir": "./src",
"paths": {
"@uppy/utils/lib/*": ["../utils/src/*"]
},
"skipLibCheck": true
},
"include": ["./src/**/*.*"],
Expand Down
3 changes: 3 additions & 0 deletions packages/@uppy/locales/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"extends": "../../../tsconfig.shared",
"compilerOptions": {
"emitDeclarationOnly": false,
"paths": {
"@uppy/utils/lib/*": ["../utils/src/*"]
},
"noEmit": true
},
"include": ["./package.json", "./src/**/*.*"],
Expand Down
24 changes: 14 additions & 10 deletions private/js2ts/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,32 @@ 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(
(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}`]]
if (pkgJson.main) {
yield [
pkg,
[`../${nickname}/${pkgJson.main.replace(/^(\.\/)?lib\//, 'src/')}`],
]
}
yield [`${pkg}/*`, [`../${nickname}/*`]]
yield [`${pkg}/lib/*`, [`../${nickname}/src/*`]]
}
})(),
)
const references = uppyDeps.map((pkg) => ({
const references = Array.from(uppyDeps, (pkg) => ({
path: `../${pkg.slice('@uppy/'.length)}/tsconfig.build.json`,
}))

Expand Down
Loading