Skip to content

Commit 6fb5297

Browse files
feat: Add SWC plugin for optimizing client-preset (#8759)
* feat: add swc plugin for optimizing client-preset * Slight optimization * refactor: change directory location * fix: tests * ci: a small change to trigger CI * ci: build, test and publish swc plugin * ci: change cwd for cargo build and test * ci: change cwd * ci: fix the gh action version with sha * ci: ignore bob in the wasm package * chore: run prettier * chore: run prettier * chore: update examples * chore: change plugin name * tests: fix snapshots diff --------- Co-authored-by: YassinEldeeb <[email protected]>
1 parent 915afbb commit 6fb5297

File tree

35 files changed

+2651
-41
lines changed

35 files changed

+2651
-41
lines changed

.github/workflows/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
env:
1212
NODE_OPTIONS: '--max_old_space_size=4096'
13+
CARGO_TERM_COLOR: always
1314

1415
jobs:
1516
lint:
@@ -135,3 +136,22 @@ jobs:
135136
run: yarn test
136137
env:
137138
CI: true
139+
test-rust-swc-plugin:
140+
name: Build and Unit Test SWC Plugin
141+
runs-on: ubuntu-latest
142+
steps:
143+
- uses: actions/checkout@v2
144+
- uses: actions-rs/toolchain@v1
145+
with:
146+
toolchain: stable
147+
target: wasm32-wasi
148+
override: true
149+
- uses: marcopolo/cargo@a527bf4d534717ff4424a84446c5d710f8833139
150+
with:
151+
working-directory: ./packages/presets/swc-plugin
152+
command: build
153+
args: --target wasm32-wasi
154+
- uses: marcopolo/cargo@a527bf4d534717ff4424a84446c5d710f8833139
155+
with:
156+
working-directory: ./packages/presets/swc-plugin
157+
command: test

.github/workflows/release.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ jobs:
1414
githubToken: ${{ secrets.GITHUB_TOKEN }}
1515
npmToken: ${{ secrets.NPM_TOKEN }}
1616

17+
publish-rust-swc-plugin:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v3
21+
# Setup .npmrc file to publish to npm
22+
- uses: actions/setup-node@v3
23+
with:
24+
node-version: '18.x'
25+
registry-url: 'https://registry.npmjs.org'
26+
- name: Publish SWC plugin
27+
working-directory: ./packages/presets/swc-plugin
28+
run: npm publish
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31+
1732
algolia:
1833
uses: the-guild-org/shared-config/.github/workflows/algolia-publish.yml@main
1934
secrets:

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ website/src/pages/plugins/index.mdx
2020
website/src/pages/plugins/presets/near-operation-file-preset.mdx
2121

2222
website/algolia-lockfile.json
23+
2324
temp/
2425
website/out
2526
website/.next
2627

2728
# added because it blocks CI and when I try to format it locally nothing happens :)
2829
website/src/components/live-demo/LiveDemo.tsx
30+
31+
# This should be added bc our rust test setup for the SWC plugin does a string diff, and it fails
32+
# bc it compares imports with double quotes against the formatted perttier single quotes
33+
packages/presets/swc-plugin/tests/fixtures

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["rust-lang.rust-analyzer", "tamasfe.even-better-toml"]
3+
}

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
},
2323
"typescript.tsdk": "node_modules/typescript/lib",
2424
"editor.formatOnSave": true,
25-
"editor.defaultFormatter": "esbenp.prettier-vscode"
25+
"editor.defaultFormatter": "esbenp.prettier-vscode",
26+
"[rust]": {
27+
"editor.defaultFormatter": "rust-lang.rust-analyzer",
28+
"editor.formatOnSave": true
29+
}
2630
}

dev-test/gql-tag-operations-masking-star-wars/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query HeroDetailsWithFragment($episode: Episode) {\n hero(episode: $episode) {\n ...HeroDetails\n }\n }\n':

dev-test/gql-tag-operations-masking/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n fragment TweetFragment on Tweet {\n id\n body\n ...TweetAuthorFragment\n }\n':

dev-test/gql-tag-operations/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query Foo {\n Tweets {\n id\n }\n }\n': types.FooDocument,

dev-test/gql-tag-operations/graphql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query Foo {\n Tweets {\n id\n }\n }\n': types.FooDocument,

examples/persisted-documents/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query HelloQuery {\n hello\n }\n': types.HelloQueryDocument,

examples/react/apollo-client/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n':

examples/react/babel-optimized/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n':

examples/react/graphql-request/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n':

examples/react/nextjs-swr/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n':

examples/react/tanstack-react-query/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n':

examples/react/urql/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n':

examples/typescript-esm/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n':

examples/typescript-graphql-request/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n':

examples/vue/apollo-composable/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n ':

examples/vue/urql/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n ':

examples/vue/villus/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n ':

examples/yoga-tests/src/gql/gql.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
1010
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
1111
* 3. It does not support dead code elimination, so it will add unused operations.
1212
*
13-
* Therefore it is highly recommended to use the babel-plugin for production.
13+
* Therefore it is highly recommended to use the babel or swc plugin for production.
1414
*/
1515
const documents = {
1616
'\n query HelloQuery {\n hello\n }\n ': types.HelloQueryDocument,

packages/plugins/typescript/gql-tag-operations/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function getDocumentRegistryChunk(sourcesWithOperations: Array<SourceWithOperati
109109
lines.add(` * 1. It is not tree-shakeable, so it will include all operations in the project.\n`);
110110
lines.add(` * 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.\n`);
111111
lines.add(` * 3. It does not support dead code elimination, so it will add unused operations.\n *\n`);
112-
lines.add(` * Therefore it is highly recommended to use the babel-plugin for production.\n */\n`);
112+
lines.add(` * Therefore it is highly recommended to use the babel or swc plugin for production.\n */\n`);
113113
lines.add(`const documents = {\n`);
114114

115115
for (const { operations, ...rest } of sourcesWithOperations) {

packages/presets/client/tests/client-preset.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export * from "./gql";`);
4646
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
4747
* 3. It does not support dead code elimination, so it will add unused operations.
4848
*
49-
* Therefore it is highly recommended to use the babel-plugin for production.
49+
* Therefore it is highly recommended to use the babel or swc plugin for production.
5050
*/
5151
const documents = {
5252
"\\n query A {\\n a\\n }\\n": types.ADocument,
@@ -133,7 +133,7 @@ export * from "./gql";`);
133133
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
134134
* 3. It does not support dead code elimination, so it will add unused operations.
135135
*
136-
* Therefore it is highly recommended to use the babel-plugin for production.
136+
* Therefore it is highly recommended to use the babel or swc plugin for production.
137137
*/
138138
const documents = {
139139
"\\n query a {\\n a\\n }\\n": types.ADocument,
@@ -212,7 +212,7 @@ export * from "./gql";`);
212212
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
213213
* 3. It does not support dead code elimination, so it will add unused operations.
214214
*
215-
* Therefore it is highly recommended to use the babel-plugin for production.
215+
* Therefore it is highly recommended to use the babel or swc plugin for production.
216216
*/
217217
const documents = {
218218
"\\n query a {\\n a\\n }\\n": types.ADocument,
@@ -292,7 +292,7 @@ export * from "./gql";`);
292292
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
293293
* 3. It does not support dead code elimination, so it will add unused operations.
294294
*
295-
* Therefore it is highly recommended to use the babel-plugin for production.
295+
* Therefore it is highly recommended to use the babel or swc plugin for production.
296296
*/
297297
const documents = {
298298
"\\n query A {\\n a\\n }\\n": types.ADocument,
@@ -420,7 +420,7 @@ export * from "./gql";`);
420420
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
421421
* 3. It does not support dead code elimination, so it will add unused operations.
422422
*
423-
* Therefore it is highly recommended to use the babel-plugin for production.
423+
* Therefore it is highly recommended to use the babel or swc plugin for production.
424424
*/
425425
const documents = {
426426
"\\n query A {\\n a\\n }\\n": types.ADocument,
@@ -541,7 +541,7 @@ export * from "./gql";`);
541541
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
542542
* 3. It does not support dead code elimination, so it will add unused operations.
543543
*
544-
* Therefore it is highly recommended to use the babel-plugin for production.
544+
* Therefore it is highly recommended to use the babel or swc plugin for production.
545545
*/
546546
const documents = {
547547
"\\n query a {\\n a\\n }\\n": types.ADocument,
@@ -652,7 +652,7 @@ export * from "./gql";`);
652652
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
653653
* 3. It does not support dead code elimination, so it will add unused operations.
654654
*
655-
* Therefore it is highly recommended to use the babel-plugin for production.
655+
* Therefore it is highly recommended to use the babel or swc plugin for production.
656656
*/
657657
const documents = {
658658
"\\n query A {\\n a\\n }\\n": types.ADocument,
@@ -952,7 +952,7 @@ export * from "./gql.js";`);
952952
* 2. It is not minifiable, so the string of a GraphQL query will be multiple times inside the bundle.
953953
* 3. It does not support dead code elimination, so it will add unused operations.
954954
*
955-
* Therefore it is highly recommended to use the babel-plugin for production.
955+
* Therefore it is highly recommended to use the babel or swc plugin for production.
956956
*/
957957
const documents = {
958958
"\\n query A {\\n a\\n }\\n": types.ADocument,

0 commit comments

Comments
 (0)