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

chore(workspace): automatically publish urql-core to JSR #3574

Merged
merged 9 commits into from
May 29, 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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
- name: Unit Tests
run: pnpm run test

- name: Check for slow types
run: pnpm jsr:dryrun

react-e2e:
name: React E2E
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main

jobs:
release:
name: Release
Expand Down
15 changes: 15 additions & 0 deletions exchanges/auth/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/exchange-auth",
"version": "2.1.6",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions exchanges/context/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/exchange-context",
"version": "0.2.1",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions exchanges/execute/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/exchange-execute",
"version": "2.2.2",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
17 changes: 17 additions & 0 deletions exchanges/graphcache/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@urql/exchange-graphcache",
"version": "7.0.2",
"exports": {
".": "./src/index.ts",
"./extras": "./src/extras/index.ts",
"./default-storage": "./src/default-storage/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions exchanges/persisted/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/exchange-persisted",
"version": "4.2.0",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions exchanges/populate/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/exchange-populate",
"version": "1.1.2",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions exchanges/refocus/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/exchange-refocus",
"version": "1.0.2",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions exchanges/request-policy/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/exchange-request-policy",
"version": "1.1.0",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions exchanges/retry/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/exchange-retry",
"version": "1.2.1",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"postinstall": "node ./scripts/prepare/postinstall.js",
"pack": "node ./scripts/actions/pack-all.mjs",
"changeset:version": "node ./scripts/changesets/version.mjs",
"changeset:publish": "changeset publish"
"changeset:publish": "changeset publish && pnpm jsr",
"jsr": "pnpm --filter @urql/core jsr",
"jsr:dryrun": "pnpm --filter @urql/core jsr --dry-run"
},
"eslintConfig": {
"root": true,
Expand Down Expand Up @@ -88,6 +90,7 @@
"husky-v4": "^4.3.8",
"invariant": "^2.2.4",
"jsdom": "^21.1.1",
"jsr": "^0.12.4",
"lint-staged": "^13.2.2",
"npm-packlist": "^7.0.4",
"npm-run-all": "^4.1.5",
Expand Down
16 changes: 16 additions & 0 deletions packages/core/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@urql/core",
"version": "5.0.2",
"exports": {
".": "./src/index.ts",
"./internal": "./src/internal/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
3 changes: 2 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"lint": "eslint --ext=js,jsx,ts,tsx .",
"build": "rollup -c ../../scripts/rollup/config.mjs",
"prepare": "node ../../scripts/prepare/index.js",
"prepublishOnly": "run-s clean build"
"prepublishOnly": "run-s clean build",
"jsr": "jsr publish"
},
"dependencies": {
"@0no-co/graphql.web": "^1.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class CombinedError extends Error {
this.response = input.response;
}

toString() {
toString(): string {
return this.message;
}
}
5 changes: 4 additions & 1 deletion packages/core/src/utils/formatDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ const formatNode = <
return node as FormattedNode<T>;
};

const formattedDocs = new Map<number, KeyedDocumentNode>();
const formattedDocs: Map<number, KeyedDocumentNode> = new Map<
number,
KeyedDocumentNode
>();

/** Formats a GraphQL document to add `__typename` fields and process client-side directives.
*
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ const SOURCE_NAME = 'gql';
const GRAPHQL_STRING_RE = /("{3}[\s\S]*"{3}|"(?:\\.|[^"])*")/g;
const REPLACE_CHAR_RE = /(?:#[^\n\r]+)?(?:[\r\n]+|$)/g;

const replaceOutsideStrings = (str: string, idx: number) =>
const replaceOutsideStrings = (str: string, idx: number): string =>
Copy link
Member

Choose a reason for hiding this comment

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

This, and annotations like Map below, seem a little concerning to me.
These are all internal functions and this seems to imply to me that JSR is enforcing a rule based on publishing raw TypeScript.

This may mean that we'd have to maintain a lot of changes across the code base for JSR and make a huge amount of changes. I think this would be reasonable if JSR/Deno would be the more popular platform over Node/npm, but it isn't.

We can implement an eslint rule for this (and there may even be an auto fixing one), but assuming declaration support is present in Deno, and we can publish prebuilts to JSR, wouldn't that be an easier way forward here?

If JSR doesn't allow this though, I think this seems a tad aggressive. Isolated declaration-like changes make sense to me, but changing all annotations to be statically analysable (except for functions where no assignment type is fine, but no return type isn't) seems a little aggressive 😅

Copy link
Collaborator Author

@JoviDeCroock JoviDeCroock May 27, 2024

Choose a reason for hiding this comment

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

I've shared that feedback with them, not much more I can do. We can ofcourse publish the bundled files instead that's true

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha! If we can't publish declarations yet, let's maybe publish this one package then figure out whether we want to do these changes for all packages.

Don't want to block this, but also want to make sure we don't have to make wide ranging changes across all packages of course 💙

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So to handle publishing JS we have to add a reference to the JS file

- Point the exports path to the js file
- Add a /// <reference path="my-script.d.ts" /> line at the top of the JS file to include the types

idx % 2 === 0 ? str.replace(REPLACE_CHAR_RE, '\n') : str;

/** Sanitizes a GraphQL document string by replacing comments and redundant newlines in it. */
const sanitizeDocument = (node: string): string =>
node.split(GRAPHQL_STRING_RE).map(replaceOutsideStrings).join('').trim();

const prints = new Map<DocumentNode | DefinitionNode, string>();
const docs = new Map<HashValue, KeyedDocumentNode>();
const prints: Map<DocumentNode | DefinitionNode, string> = new Map<
DocumentNode | DefinitionNode,
string
>();
const docs: Map<HashValue, KeyedDocumentNode> = new Map<
HashValue,
KeyedDocumentNode
>();

/** A cached printing function for GraphQL documents.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const makeResult = (
};
};

const deepMerge = (target: any, source: any) => {
const deepMerge = (target: any, source: any): any => {
if (typeof target === 'object' && target != null) {
if (
!target.constructor ||
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/variables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type FileMap = Map<string, File | Blob>;

const seen = new Set();
const cache = new WeakMap();
const seen: Set<any> = new Set();
const cache: WeakMap<any, any> = new WeakMap();

const stringify = (x: any): string => {
if (x === null || seen.has(x)) {
Expand Down
15 changes: 15 additions & 0 deletions packages/introspection/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/introspection",
"version": "1.0.3",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
16 changes: 16 additions & 0 deletions packages/next-urql/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "@urql/next",
"version": "1.1.1",
"exports": {
".": "./src/index.ts",
"./rsc": "./src/rsc.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions packages/preact-urql/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/preact",
"version": "4.0.5",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
13 changes: 13 additions & 0 deletions packages/react-urql/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "urql",
"version": "4.0.7",
"exports": "src/index.ts",
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions packages/storage-rn/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/storage-rn",
"version": "1.1.0",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
15 changes: 15 additions & 0 deletions packages/svelte-urql/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@urql/svelte",
"version": "4.1.1",
"exports": {
".": "./src/index.ts"
},
"exclude": [
"node_modules",
"cypress",
"**/*.test.*",
"**/*.spec.*",
"**/*.test.*.snap",
"**/*.spec.*.snap"
]
}
Loading