@isograph/plugin-swc 0.0.0-main-f88ec435

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
+
3
+ exports[`Should load swc-plugin-isograph wasm plugin correctly > Should transform should_return_an_identity_for_non_called_iso_function correctly 1`] = `
4
+ "export const HomeRoute = (x)=>x;
5
+ "
6
+ `;
7
+
8
+ exports[`Should load swc-plugin-isograph wasm plugin correctly > Should transform should_transform_iso_fn_to_a_import_call correctly 1`] = `
9
+ "import _Query__HomeRoute from "../../__isograph/Query/HomeRoute/entrypoint.ts";
10
+ function test() {
11
+ const a = _Query__HomeRoute;
12
+ }
13
+ "
14
+ `;
15
+
16
+ exports[`Should load swc-plugin-isograph wasm plugin correctly > Should transform should_transform_iso_fn_to_a_require_call correctly 1`] = `
17
+ "const { fragmentReference } = useLazyReference(require("../../__isograph/Query/HomeRoute/entrypoint.ts").default, {});
18
+ "
19
+ `;
20
+
21
+ exports[`Should load swc-plugin-isograph wasm plugin correctly > Should transform should_transform_nested_calls_to_iso correctly 1`] = `
22
+ "export const HomeRoute = function HomeRouteComponent({ data }) {
23
+ const { fragmentReference, loadFragmentReference } = useImperativeReference(require("../../__isograph/Query/PetFavoritePhrase/entrypoint.ts").default);
24
+ return "Render";
25
+ };
26
+ "
27
+ `;
@@ -0,0 +1,89 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import url from 'node:url';
4
+ import { transform } from '@swc/core';
5
+ import { describe, expect, test } from 'vitest';
6
+
7
+ const pluginName = 'swc_isograph_plugin.wasm';
8
+
9
+ const transformCode = (code: string, options = {}, filename = '') => {
10
+ return transform(code, {
11
+ jsc: {
12
+ parser: {
13
+ syntax: 'ecmascript',
14
+ },
15
+ target: 'es2018',
16
+ experimental: {
17
+ plugins: [
18
+ [
19
+ path.join(
20
+ // @ts-ignore
21
+ path.dirname(url.fileURLToPath(import.meta.url)),
22
+ '..',
23
+ pluginName,
24
+ ),
25
+ options,
26
+ ],
27
+ ],
28
+ },
29
+ },
30
+ filename,
31
+ });
32
+ };
33
+
34
+ async function walkDir(
35
+ dir: URL,
36
+ callback: (
37
+ dir: string,
38
+ input: string,
39
+ config?: Record<string, unknown>,
40
+ filename?: string,
41
+ baseDir?: string,
42
+ ) => Promise<void>,
43
+ ) {
44
+ const dirs = await fs.readdir(dir);
45
+ const baseDir = url.fileURLToPath(dir);
46
+
47
+ for (const dir of dirs) {
48
+ const inputFilePath = path.join(baseDir, dir, 'input.js');
49
+ const configPath = path.join(baseDir, dir, 'isograph.config.json');
50
+
51
+ const isographConfig = await fs.readFile(configPath, 'utf-8').then(
52
+ (json) => {
53
+ return JSON.parse(json);
54
+ },
55
+ (_) => undefined,
56
+ );
57
+
58
+ const config = {
59
+ // must be an absolute path
60
+ root_dir: path.join(baseDir, dir),
61
+ config: isographConfig ?? {},
62
+ };
63
+
64
+ const filename = path.join(
65
+ baseDir,
66
+ dir,
67
+ `/src/components/Home/Header/File.ts`,
68
+ );
69
+
70
+ const input = await fs.readFile(inputFilePath, 'utf-8');
71
+ await callback(dir, input, config, filename, baseDir);
72
+ }
73
+ }
74
+
75
+ describe.skip('Should load swc-plugin-isograph wasm plugin correctly', async () => {
76
+ await walkDir(
77
+ new URL(
78
+ '../../../crates/swc_isograph_plugin/tests/fixtures/base',
79
+ // @ts-ignore
80
+ import.meta.url,
81
+ ),
82
+ async (dir, input, config, filename) => {
83
+ await test(`Should transform ${dir} correctly`, async () => {
84
+ const { code } = await transformCode(input, config, filename);
85
+ expect(code).toMatchSnapshot();
86
+ });
87
+ },
88
+ );
89
+ });
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@isograph/plugin-swc",
3
+ "version": "0.0.0-main-f88ec435",
4
+ "description": "SWC plugin for Isograph",
5
+ "homepage": "https://isograph.dev",
6
+ "main": "swc_isograph_plugin.wasm",
7
+ "author": "Isograph Labs",
8
+ "license": "MIT",
9
+ "scripts": {
10
+ "prepack": "cp ../../target/wasm32-wasip1/release/swc_isograph_plugin.wasm .",
11
+ "build": "cd ../../crates/swc_isograph_plugin && cargo build --release -p swc_isograph_plugin --target wasm32-wasip1 && cp ../../target/wasm32-wasip1/release/swc_isograph_plugin.wasm ../../libs/isograph-swc-plugin/",
12
+ "build:debug": "cd ../../crates/swc_isograph_plugin && cargo build -p swc_isograph_plugin --target wasm32-wasip1 && cp ../../target/wasm32-wasip1/debug/swc_isograph_plugin.wasm ../../libs/isograph-swc-plugin/",
13
+ "swc:test": "vitest run"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/isographlabs/isograph.git",
18
+ "directory": "libs/isograph-swc-plugin"
19
+ },
20
+ "keywords": [
21
+ "graphql",
22
+ "isograph",
23
+ "swc",
24
+ "swc-plugin"
25
+ ],
26
+ "preferUnplugged": true,
27
+ "dependencies": {
28
+ "@swc/counter": "^0.1.3"
29
+ }
30
+ }
Binary file