tldraw/scripts/api-check.ts
Mime Čuvalo 3adae06d9c
security: enforce use of our fetch function and its default referrerpolicy (#3884)
followup to https://github.com/tldraw/tldraw/pull/3881 to enforce this
in the codebase

Describe what your pull request does. If appropriate, add GIFs or images
showing the before and after.

### Change Type

<!--  Please select a 'Scope' label ️ -->

- [x] `sdk` — Changes the tldraw SDK
- [x] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff

<!--  Please select a 'Type' label ️ -->

- [ ] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [x] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
2024-06-11 13:59:25 +00:00

65 lines
1.8 KiB
TypeScript
Executable file

import { writeFileSync } from 'fs'
import { join, resolve } from 'path'
import { exec } from './lib/exec'
import { readFileIfExists } from './lib/file'
import { nicelog } from './lib/nicelog'
import { getAllWorkspacePackages } from './lib/workspace'
const packagesOurTypesCanDependOn = [
'@types/lodash.throttle',
'@types/lodash.uniq',
'@types/react',
'@types/react-dom',
'eventemitter3',
// todo: external types shouldn't depend on this
'@types/ws',
]
main()
async function main() {
const tsconfig: any = {
compilerOptions: {
lib: ['es2015', 'dom'],
strict: true,
rootDir: '.',
paths: {},
esModuleInterop: true,
},
files: [],
}
const tempDir = (await exec('mktemp', ['-d'])).trim()
nicelog(`Working in ${tempDir}`)
const packages = (await getAllWorkspacePackages()).filter(
({ packageJson }) => !packageJson.private
)
nicelog(
'Checking packages:',
packages.map(({ packageJson }) => packageJson.name)
)
for (const { name, relativePath } of packages) {
const unprefixedName = name.replace('@tldraw/', '')
const dtsFile = await readFileIfExists(join(relativePath, 'api', 'public.d.ts'))
if (!dtsFile) {
nicelog(`No public.d.ts for ${name}, skipping`)
continue
}
writeFileSync(join(tempDir, `${unprefixedName}.d.ts`), dtsFile, 'utf8')
tsconfig.compilerOptions.paths[name] = [`./${unprefixedName}.d.ts`]
tsconfig.files.push(`./${unprefixedName}.d.ts`)
}
nicelog('Checking with tsconfig:', tsconfig)
writeFileSync(`${tempDir}/tsconfig.json`, JSON.stringify(tsconfig, null, '\t'), 'utf8')
writeFileSync(`${tempDir}/package.json`, JSON.stringify({ dependencies: {} }, null, '\t'), 'utf8')
await exec('npm', ['install', ...packagesOurTypesCanDependOn], { pwd: tempDir })
await exec(resolve('./node_modules/.bin/tsc'), [], { pwd: tempDir })
await exec('rm', ['-rf', tempDir])
}