Repository navigation
Fix published type declarations for consumers with skipLibCheck off #2175
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
Open
lukasIO
wants to merge
1
commit into
main
Choose a base branch
from
claude/published-type-declarations-fix-124ebd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+130
−21
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "livekit-client": patch | ||
| --- | ||
|
|
||
| fix published type declarations for consumers with `skipLibCheck: false` or `exactOptionalPropertyTypes` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // Gate for the published declarations, as a consumer sees them. Packs the built package | ||
| // (run `pnpm build` first), installs the tarball into a temp project and type-checks every | ||
| // entry with `skipLibCheck` off and the strictest options a consumer may set. That catches: | ||
| // - a declaration that imports a package the consumer does not install (a devDependency, or a | ||
| // dependency whose types live in a devDependency `@types/*` package); | ||
| // - declarations that contradict each other under `exactOptionalPropertyTypes`. | ||
| // The temp project sits outside the repo: inside it, module resolution walks up to the repo's | ||
| // node_modules and finds the devDependencies, which hides the first case. | ||
| import { execFileSync } from 'node:child_process'; | ||
| import { mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); | ||
| const tsc = path.join(REPO, 'node_modules', '.bin', 'tsc'); | ||
| const tmp = mkdtempSync(path.join(os.tmpdir(), 'livekit-published-types-')); | ||
|
|
||
| const run = (cmd, args, cwd) => { | ||
| try { | ||
| return { ok: true, out: execFileSync(cmd, args, { cwd, encoding: 'utf8', stdio: 'pipe' }) }; | ||
| } catch (err) { | ||
| return { ok: false, out: `${err.stdout ?? ''}${err.stderr ?? ''}` }; | ||
| } | ||
| }; | ||
|
|
||
| const must = (result) => { | ||
| if (!result.ok) { | ||
| console.error(result.out); | ||
| process.exit(1); | ||
| } | ||
| }; | ||
|
|
||
| try { | ||
| must(run('pnpm', ['pack', '--pack-destination', tmp], REPO)); | ||
| const tarball = readdirSync(tmp).find((file) => file.endsWith('.tgz')); | ||
| writeFileSync( | ||
| path.join(tmp, 'package.json'), | ||
| JSON.stringify({ name: 'consumer', private: true, type: 'module' }), | ||
| ); | ||
| // npm, not pnpm: a flat node_modules with only what the package.json declares (and its peers). | ||
| must(run('npm', ['install', '--no-audit', '--no-fund', '--ignore-scripts', `./${tarball}`], tmp)); | ||
|
|
||
| writeFileSync( | ||
| path.join(tmp, 'probe.ts'), | ||
| `export * as full from 'livekit-client'; | ||
| export * as core from 'livekit-client/core'; | ||
| export * as e2eeWorker from 'livekit-client/e2ee-worker'; | ||
| export * as frameMetadataWorker from 'livekit-client/frame-metadata-worker'; | ||
| `, | ||
| ); | ||
| writeFileSync( | ||
| path.join(tmp, 'tsconfig.json'), | ||
| JSON.stringify({ | ||
| compilerOptions: { | ||
| noEmit: true, | ||
| strict: true, | ||
| exactOptionalPropertyTypes: true, | ||
| skipLibCheck: false, | ||
| module: 'ESNext', | ||
| moduleResolution: 'bundler', | ||
| target: 'ES2022', | ||
| lib: ['DOM', 'DOM.Iterable', 'ES2022'], | ||
| }, | ||
| files: ['probe.ts'], | ||
| }), | ||
| ); | ||
|
|
||
| const check = run(tsc, ['-p', path.join(tmp, 'tsconfig.json')], tmp); | ||
| const errors = check.out.split('\n').filter((line) => /error TS\d+/.test(line)); | ||
| if (!check.ok || errors.length > 0) { | ||
| console.error('published types: a consumer with skipLibCheck off gets errors:'); | ||
| for (const line of errors.length > 0 ? errors : [check.out]) console.error(` ${line.trim()}`); | ||
| process.exit(1); | ||
| } | ||
| console.log('published types: all entries type-check in a consumer with skipLibCheck off'); | ||
| } finally { | ||
| rmSync(tmp, { recursive: true, force: true }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // A copy of `Throws` from `@livekit/throws-transformer/throws`. The published declarations name | ||
| // this type, and the transformer is a devDependency, so a consumer could not resolve an import | ||
| // of it. The transformer matches the `__throws` brand, not the import path: keep the brand as is. | ||
|
|
||
| type Primitives = void | null | undefined | string | number | bigint | boolean | symbol; | ||
|
|
||
| /** | ||
| * Branded type that encodes possible thrown errors in the return type. The error types are | ||
| * phantom types for static analysis; the runtime value is just T. | ||
| */ | ||
| export type Throws<T, E extends Error> = | ||
| | (T & { | ||
| readonly __throws?: E; | ||
| }) | ||
| | Extract<T, Primitives>; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Is there some way these could pull from the npm package implementation still, but get resolved at build time into effectively the contents of this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I'm not particularly happy about just copying this either.
The potential viable options as I see them: