@ohos-ports/vite-plugin-relay 2.1.0-beta.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Oscar Beaumont
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ <h1 align="center">Vite Plugin Relay</h1>
2
+
3
+ <div align="center">
4
+
5
+ [![NPM](https://img.shields.io/npm/v/vite-plugin-relay)](https://www.npmjs.com/package/vite-plugin-relay)
6
+ [![CI workflow](https://github.com/oscartbeaumont/vite-plugin-relay/actions/workflows/ci.yml/badge.svg)](https://github.com/oscartbeaumont/vite-plugin-relay/actions)
7
+
8
+ </div>
9
+
10
+ <div align="center">
11
+ Add relay support to your <a href="https://vitejs.dev">Vite</a> projects.
12
+ </div>
13
+
14
+ <br />
15
+
16
+ ❤️ Special thanks to:
17
+
18
+ - [@Brendonovich](https://github.com/Brendonovich) for general help
19
+ - [@kesne](https://github.com/kesne) for adding [pnpm](https://pnpm.io) support
20
+ - [@tobias-tengler](https://github.com/tobias-tengler) for adding Vite 3 support
21
+
22
+ I **do not** actively use this project anymore, however, it will still receive periodic updates.
23
+
24
+ ## Usage
25
+
26
+ Follow Relay's guide on [how to add Relay to your project](https://relay.dev/docs/getting-started/installation-and-setup/).
27
+
28
+ > ⚠️ Note: Install `babel-plugin-relay` (>= 13.0.1) as devDependencies as instructed, but skip its configuration. `vite-plugin-relay` will invoke the babel plugin for you!
29
+
30
+ Add `vite-plugin-relay` to your `devDependencies`:
31
+
32
+ ```bash
33
+ yarn add vite-plugin-relay -D
34
+ ```
35
+
36
+ Add `vite-plugin-relay` to your Vite configuration (`vite.config.ts` or `vite.config.js`):
37
+
38
+ ```typescript
39
+ import { defineConfig } from "vite";
40
+ import relay from "vite-plugin-relay";
41
+
42
+ export default defineConfig({
43
+ plugins: [..., relay],
44
+ });
45
+ ```
46
+
47
+ Configure `relay-compiler` to output artifacts with `export default` syntax, by setting `eagerEsModules` to `true`:
48
+
49
+ ```json
50
+ {
51
+ "relay": {
52
+ "src": "./src",
53
+ "schema": "./src/schema.graphql",
54
+ "language": "typescript",
55
+ "eagerEsModules": true,
56
+ "exclude": ["**/node_modules/**", "**/__mocks__/**", "**/__generated__/**"]
57
+ }
58
+ }
59
+ ```
60
+
61
+ Now your project is setup to use Relay with Vite!
62
+
63
+ ## How this plugin works
64
+
65
+ Under the hood we are invoking the official `babel-plugin-relay`. This ensures that our plugin and `babel-plugin-relay` do not get out of sync over time and also reduces the maintainance costs of this project.
66
+
67
+ Since v13 `babel-plugin-relay` automatically gets its configuration from either the `package.json`, `relay.config.js` or `relay.config.json`, so our plugin also doesn't have to expose a configuration API.
68
+
69
+ ## Common Issues
70
+
71
+ ### `Uncaught ReferenceError: global is not defined`
72
+
73
+ If you experience this error in your browser console when using the plugin add the following define to your `index.html` file before importing your Javascript:
74
+
75
+ ```html
76
+ <script>
77
+ let global = globalThis;
78
+ </script>
79
+ ```
80
+
81
+ ## Server Side Rendering
82
+
83
+ If you are planning to use this plugin with server side rendering you may need to define `window`. You could do this by putting the following snippet in your [`entry-server.js`](https://vitejs.dev/guide/ssr.html#source-structure) file.
84
+
85
+ ```js
86
+ if (typeof (window as any).global === 'undefined') {
87
+ (window as any).global = globalThis;
88
+ }
89
+ ```
90
+
91
+ ## Contributing
92
+
93
+ ```
94
+ git clone ...
95
+ pnpm i
96
+ # If you have never run Playwright run `npx playwright install` to setup your system.
97
+ cd examples/vite-3
98
+ pnpm dev
99
+
100
+ pnpm format # Do this before doing a commit
101
+ ```
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = function(target, all) {
7
+ for(var name in all)__defProp(target, name, {
8
+ get: all[name],
9
+ enumerable: true
10
+ });
11
+ };
12
+ var __copyProps = function(to, from, except, desc) {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
15
+ try {
16
+ var _loop = function() {
17
+ var key = _step.value;
18
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: function() {
20
+ return from[key];
21
+ },
22
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
23
+ });
24
+ };
25
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
26
+ } catch (err) {
27
+ _didIteratorError = true;
28
+ _iteratorError = err;
29
+ } finally{
30
+ try {
31
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
32
+ _iterator.return();
33
+ }
34
+ } finally{
35
+ if (_didIteratorError) {
36
+ throw _iteratorError;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ return to;
42
+ };
43
+ var __toCommonJS = function(mod) {
44
+ return __copyProps(__defProp({}, "__esModule", {
45
+ value: true
46
+ }), mod);
47
+ };
48
+ // src/plugin.ts
49
+ var plugin_exports = {};
50
+ __export(plugin_exports, {
51
+ default: function() {
52
+ return plugin_default;
53
+ }
54
+ });
55
+ module.exports = __toCommonJS(plugin_exports);
56
+ var import_core = require("@babel/core");
57
+ var plugin_default = {
58
+ name: "vite:relay",
59
+ transform: function transform(src, id) {
60
+ if (/.(t|j)sx?/.test(id) && src.includes("graphql`")) {
61
+ var out = (0, import_core.transformSync)(src, {
62
+ plugins: [
63
+ [
64
+ "babel-plugin-relay"
65
+ ]
66
+ ],
67
+ code: true,
68
+ filename: id,
69
+ sourceMaps: true
70
+ });
71
+ if (!(out === null || out === void 0 ? void 0 : out.code)) {
72
+ throw new Error("vite-plugin-relay: Failed to transform ".concat(id));
73
+ }
74
+ var code = out.code;
75
+ var map = out.map;
76
+ return {
77
+ code: code,
78
+ map: map
79
+ };
80
+ }
81
+ }
82
+ };
@@ -0,0 +1,5 @@
1
+ import { PluginOption } from '@ohos-ports/vite';
2
+
3
+ declare const _default: PluginOption;
4
+
5
+ export { _default as default };
@@ -0,0 +1,5 @@
1
+ import { PluginOption } from '@ohos-ports/vite';
2
+
3
+ declare const _default: PluginOption;
4
+
5
+ export { _default as default };
package/dist/plugin.js ADDED
@@ -0,0 +1,27 @@
1
+ // src/plugin.ts
2
+ import { transformSync } from "@babel/core";
3
+ var plugin_default = {
4
+ name: "vite:relay",
5
+ transform(src, id) {
6
+ if (/.(t|j)sx?/.test(id) && src.includes("graphql`")) {
7
+ const out = transformSync(src, {
8
+ plugins: [["babel-plugin-relay"]],
9
+ code: true,
10
+ filename: id,
11
+ sourceMaps: true
12
+ });
13
+ if (!out?.code) {
14
+ throw new Error(`vite-plugin-relay: Failed to transform ${id}`);
15
+ }
16
+ const code = out.code;
17
+ const map = out.map;
18
+ return {
19
+ code,
20
+ map
21
+ };
22
+ }
23
+ }
24
+ };
25
+ export {
26
+ plugin_default as default
27
+ };
package/package.json ADDED
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@ohos-ports/vite-plugin-relay",
3
+ "version": "2.1.0-beta.0",
4
+ "description": "A vite plugin for relay",
5
+ "author": {
6
+ "name": "Oscar Beaumont",
7
+ "email": "oscar@otbeaumont.me"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
13
+ "directory": "ports/vite-plugin-relay/2.1.0"
14
+ },
15
+ "keywords": [
16
+ "graphql",
17
+ "relay",
18
+ "typescript",
19
+ "graphql-relay",
20
+ "vite",
21
+ "vite-plugin",
22
+ "vite-plugin-relay"
23
+ ],
24
+ "type": "module",
25
+ "main": "dist/plugin.cjs",
26
+ "module": "dist/plugin.js",
27
+ "types": "dist/plugin.d.ts",
28
+ "exports": {
29
+ ".": {
30
+ "require": "./dist/plugin.cjs",
31
+ "import": "./dist/plugin.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsup src/plugin.ts --dts --clean --format cjs,esm --no-splitting --env.NODE_ENV production",
39
+ "dev": "tsup src/plugin.ts --dts --clean --format cjs,esm --no-splitting --watch",
40
+ "test": "pnpm -r --parallel --filter=!vite-plugin-relay exec pnpm test",
41
+ "lint": "prettier --check . && eslint src/** examples/latest/src/**",
42
+ "format": "prettier --write . && eslint src/** examples/latest/src/** --fix"
43
+ },
44
+ "peerDependencies": {
45
+ "babel-plugin-relay": ">=14.1.0",
46
+ "@ohos-ports/vite": "^8.3.0-beta.0"
47
+ },
48
+ "dependencies": {
49
+ "@babel/core": "^7.23.5"
50
+ },
51
+ "devDependencies": {
52
+ "@ohos-ports/swc-core": "^1.16.2-beta.0",
53
+ "@types/babel__core": "^7.20.5",
54
+ "@types/node": "^20.10.4",
55
+ "@typescript-eslint/eslint-plugin": "^6.13.2",
56
+ "@typescript-eslint/parser": "^6.13.2",
57
+ "eslint": "^8.55.0",
58
+ "eslint-config-prettier": "^9.1.0",
59
+ "husky": "^8.0.3",
60
+ "prettier": "^3.1.0",
61
+ "tsup": "^8.0.1",
62
+ "typescript": "^5.3.3",
63
+ "@ohos-ports/vite": "^8.3.0-beta.0"
64
+ },
65
+ "bugs": {
66
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
67
+ }
68
+ }