Skip to content

refactor using globals and fix misc type errors - #1727

Merged
KATT merged 8 commits into
nextfrom
sachinraja/refactor-globals
Apr 4, 2022
Merged

KATT merged 8 commits into
nextfrom
sachinraja/refactor-globals

Conversation

@sachinraja

@sachinraja sachinraja commented Apr 3, 2022 •

Copy link
Copy Markdown
Member

closes #1597
closes #1588

Refactor globals:

  • use URL and URLSearchParams global instead of importing from url

Type errors:

This could have been two separate PRs but both are needed for Deno support.

Need to add examples.

@vercel

vercel Bot commented Apr 3, 2022 •

Copy link
Copy Markdown

Comment thread packages/server/src/assertNotBrowser.ts Resolved

@KATT KATT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!!

const error = new TRPCError({
code: 'PARSE_ERROR',
cause,
cause: getCauseFromUnknown(cause),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

"include": ["src", "test"],
"compilerOptions": {
"lib": ["ES2020"],
"lib": ["ES2020", "DOM"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm. How come is this needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the tests and the window object in assertNotBrowser:

typeof window !== 'undefined' &&
!('Deno' in window) &&

I can suppress the errors in assertNotBrowser and create a separate tsconfig for the tests if you like that better

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, didn't know window was a global in deno. All good then.

Is there a way to do a "deno build" as part of ci to ensure it all works?

@sachinraja sachinraja Apr 3, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering it relies on a CDN to work with Deno, probably not, unless we do a publish. We could do a separate build for Deno but that would definitely complicate things (although I'm open to looking into it if you want to go in that direction).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use github as a cdn and have a dynamic deno script that is created and run in CI?

Not asking you to do this, just spitballing if it would work

E.g. create a file creates:

import trpc from `https://raw.githubusercontent.com/trpc/trpc/{{CURRENT_COMMIT_HASH}}/packages/server/src/index.ts`


// [..] start deno server with a little router

Then it could ping itself or something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sachinraja sachinraja Apr 3, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would still be other issues, Deno can work with relative file imports anyway. One thing is that in Deno, all imports must have file extensions (.ts). TypeScript doesn't support this though (Deno has forked TS to allow it), so it will break for us if we try to add extensions.

@sachinraja

sachinraja commented Apr 3, 2022 •

Copy link
Copy Markdown
Member Author

Adding a cloudflare workers example needs #1596 because subscriptions currently use the node builtin events.

@KATT KATT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

@KATT
KATT merged commit 2a65105 into next Apr 4, 2022
@KATT
KATT deleted the sachinraja/refactor-globals branch April 4, 2022 14:18
@KATT KATT added this to the v10 milestone Apr 4, 2022
@github-actions

github-actions Bot commented Oct 6, 2022

Copy link
Copy Markdown
Contributor

This pull request has been locked because it had no new activity for 30 days. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 6, 2022

This branch was successfully deployed

3 active deployments
Preview – www — 646b5935 Deployed Apr 3, 2022 by vercel[bot]
Preview – next-prisma-starter — 646b5935 Deployed Apr 3, 2022 by vercel[bot]
Preview – todomvc — 646b5935 Deployed Apr 3, 2022 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Decouple @trpc/server from node Type error in @trpc/server with TS 4.6

2 participants