Skip to content

Commit

Permalink
meta: fix js2ts script (#4846)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Jan 3, 2024
1 parent 353c7cb commit 2c05594
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
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": {
"@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

0 comments on commit 2c05594

Please sign in to comment.