@mearie/vite 0.0.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,20 @@
1
+ MIT License
2
+
3
+ Copyright 2025 Bae Junehyeon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,146 @@
1
+ # @mearie/vite
2
+
3
+ Vite plugin for Mearie GraphQL code generation.
4
+
5
+ ## Features
6
+
7
+ - ✅ **Zero Configuration** - No additional plugins required
8
+ - 🔍 Automatically extracts GraphQL operations from your source code
9
+ - 📦 Supports multiple file types: `.js`, `.jsx`, `.ts`, `.tsx`, `.vue`, `.svelte`, `.astro`, `.graphql`, `.gql`
10
+ - 🔥 Hot Module Replacement (HMR) support for schema changes
11
+ - ⚡ Fast - Uses native Node.js WASM support (no bundler plugins needed)
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pnpm add -D @mearie/vite
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ### Basic Setup
22
+
23
+ ```typescript
24
+ // vite.config.ts
25
+ import { defineConfig } from 'vite';
26
+ import { mearie } from '@mearie/vite';
27
+
28
+ export default defineConfig({
29
+ plugins: [
30
+ mearie({
31
+ schema: 'schema.graphql',
32
+ output: 'src/generated/mearie.ts',
33
+ watch: true,
34
+ }),
35
+ ],
36
+ });
37
+ ```
38
+
39
+ ### GraphQL in Your Code
40
+
41
+ The plugin supports multiple ways to define GraphQL operations:
42
+
43
+ #### 1. Using `gql` tagged template
44
+
45
+ ```typescript
46
+ import { gql } from 'mearie';
47
+
48
+ const query = gql\`
49
+ query GetUser($id: ID!) {
50
+ user(id: $id) {
51
+ id
52
+ name
53
+ }
54
+ }
55
+ \`;
56
+ ```
57
+
58
+ #### 2. Using `/* GraphQL */` comment
59
+
60
+ ```typescript
61
+ const query = /* GraphQL */ \`
62
+ query GetUser($id: ID!) {
63
+ user(id: $id) {
64
+ id
65
+ name
66
+ }
67
+ }
68
+ \`;
69
+ ```
70
+
71
+ #### 3. In `.graphql` or `.gql` files
72
+
73
+ ```graphql
74
+ query GetUser($id: ID!) {
75
+ user(id: $id) {
76
+ id
77
+ name
78
+ }
79
+ }
80
+ ```
81
+
82
+ ## Options
83
+
84
+ ### `schema`
85
+
86
+ - Type: `string`
87
+ - Optional
88
+
89
+ Path to your GraphQL schema file.
90
+
91
+ ### `output`
92
+
93
+ - Type: `string`
94
+ - Default: `'src/generated/mearie.ts'`
95
+
96
+ Output path for generated TypeScript files.
97
+
98
+ ### `watch`
99
+
100
+ - Type: `boolean`
101
+ - Default: `true`
102
+
103
+ Whether to watch for schema changes and trigger HMR.
104
+
105
+ ## Testing
106
+
107
+ ### Run Unit Tests
108
+
109
+ ```bash
110
+ pnpm test
111
+ ```
112
+
113
+ ### Run Example Project
114
+
115
+ ```bash
116
+ cd examples/basic
117
+ pnpm install
118
+ pnpm dev
119
+ ```
120
+
121
+ ### Manual Testing
122
+
123
+ 1. Create a Vite project
124
+ 2. Add `@mearie/vite` as a dev dependency
125
+ 3. Configure the plugin in `vite.config.ts`
126
+ 4. Add GraphQL operations to your source code
127
+ 5. Run `pnpm dev` or `pnpm build`
128
+ 6. Check the generated TypeScript file at the specified output path
129
+
130
+ ## Development
131
+
132
+ ### Build
133
+
134
+ ```bash
135
+ pnpm build
136
+ ```
137
+
138
+ ### Watch Mode
139
+
140
+ ```bash
141
+ pnpm test:watch
142
+ ```
143
+
144
+ ## License
145
+
146
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,119 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ let node_path = require("node:path");
25
+ node_path = __toESM(node_path);
26
+ let __mearie_config = require("@mearie/config");
27
+ __mearie_config = __toESM(__mearie_config);
28
+ let __mearie_codegen = require("@mearie/codegen");
29
+ __mearie_codegen = __toESM(__mearie_codegen);
30
+ let __mearie_core = require("@mearie/core");
31
+ __mearie_core = __toESM(__mearie_core);
32
+
33
+ //#region src/plugin.ts
34
+ /**
35
+ * Vite plugin for Mearie GraphQL code generation.
36
+ * @param options - Plugin options.
37
+ * @returns Vite plugin.
38
+ */
39
+ const mearie = (options = {}) => {
40
+ let viteConfig;
41
+ let mearieConfig;
42
+ let context = null;
43
+ let generateTimer = null;
44
+ const ensureInitialized = async () => {
45
+ if (context) return;
46
+ mearieConfig = (0, __mearie_config.mergeConfig)(await (0, __mearie_config.loadConfig)({
47
+ cwd: viteConfig.root,
48
+ filename: options.config
49
+ }), options);
50
+ const { schemas, documents, exclude } = mearieConfig;
51
+ context = new __mearie_codegen.CodegenContext();
52
+ const schemaFiles = await (0, __mearie_codegen.findFiles)(viteConfig.root, {
53
+ include: schemas,
54
+ exclude
55
+ });
56
+ const documentFiles = await (0, __mearie_codegen.findFiles)(viteConfig.root, {
57
+ include: documents,
58
+ exclude
59
+ });
60
+ await Promise.all([...schemaFiles.map((file) => context.addSchema(file)), ...documentFiles.map((file) => context.addDocument(file))]);
61
+ };
62
+ const scheduleGenerate = () => {
63
+ if (generateTimer) clearTimeout(generateTimer);
64
+ generateTimer = setTimeout(() => {
65
+ (async () => {
66
+ try {
67
+ await context?.generate();
68
+ } catch (error) {
69
+ (0, __mearie_core.report)(__mearie_core.logger, error);
70
+ }
71
+ })();
72
+ }, 100);
73
+ };
74
+ return {
75
+ name: "mearie",
76
+ enforce: "pre",
77
+ async configResolved(resolvedConfig) {
78
+ viteConfig = resolvedConfig;
79
+ try {
80
+ await ensureInitialized();
81
+ await context?.generate();
82
+ } catch (error) {
83
+ (0, __mearie_core.report)(__mearie_core.logger, error);
84
+ if (viteConfig.command === "build") throw error;
85
+ }
86
+ },
87
+ async hotUpdate({ file, type }) {
88
+ if (!context || !mearieConfig) return;
89
+ const { schemas, documents, exclude } = mearieConfig;
90
+ const relativePath = node_path.default.relative(viteConfig.root, file);
91
+ const schemaMatcher = (0, __mearie_codegen.createMatcher)({
92
+ include: schemas,
93
+ exclude
94
+ });
95
+ const documentMatcher = (0, __mearie_codegen.createMatcher)({
96
+ include: documents,
97
+ exclude
98
+ });
99
+ const matchesSchema = schemaMatcher(relativePath);
100
+ const matchesDocument = documentMatcher(relativePath);
101
+ if (!matchesSchema && !matchesDocument) return;
102
+ try {
103
+ if (type === "delete") {
104
+ if (matchesSchema) context.removeSchema(file);
105
+ if (matchesDocument) context.removeDocument(file);
106
+ } else {
107
+ if (matchesSchema) await context.addSchema(file);
108
+ if (matchesDocument) await context.addDocument(file);
109
+ }
110
+ scheduleGenerate();
111
+ } catch (error) {
112
+ (0, __mearie_core.report)(__mearie_core.logger, error);
113
+ }
114
+ }
115
+ };
116
+ };
117
+
118
+ //#endregion
119
+ exports.mearie = mearie;
@@ -0,0 +1,26 @@
1
+ import { Plugin } from "vite";
2
+ import { MearieConfig } from "@mearie/config";
3
+
4
+ //#region src/types.d.ts
5
+
6
+ /**
7
+ * Options for the Mearie Vite plugin.
8
+ * All options are optional and will override values from mearie.config.ts.
9
+ */
10
+ type MearieOptions = Partial<MearieConfig> & {
11
+ /**
12
+ * Path to the Mearie configuration file.
13
+ * @default "mearie.config.{ts,js,mjs,cjs}"
14
+ */
15
+ config?: string;
16
+ };
17
+ //#endregion
18
+ //#region src/plugin.d.ts
19
+ /**
20
+ * Vite plugin for Mearie GraphQL code generation.
21
+ * @param options - Plugin options.
22
+ * @returns Vite plugin.
23
+ */
24
+ declare const mearie: (options?: MearieOptions) => Plugin;
25
+ //#endregion
26
+ export { type MearieOptions, mearie };
@@ -0,0 +1,26 @@
1
+ import { MearieConfig } from "@mearie/config";
2
+ import { Plugin } from "vite";
3
+
4
+ //#region src/types.d.ts
5
+
6
+ /**
7
+ * Options for the Mearie Vite plugin.
8
+ * All options are optional and will override values from mearie.config.ts.
9
+ */
10
+ type MearieOptions = Partial<MearieConfig> & {
11
+ /**
12
+ * Path to the Mearie configuration file.
13
+ * @default "mearie.config.{ts,js,mjs,cjs}"
14
+ */
15
+ config?: string;
16
+ };
17
+ //#endregion
18
+ //#region src/plugin.d.ts
19
+ /**
20
+ * Vite plugin for Mearie GraphQL code generation.
21
+ * @param options - Plugin options.
22
+ * @returns Vite plugin.
23
+ */
24
+ declare const mearie: (options?: MearieOptions) => Plugin;
25
+ //#endregion
26
+ export { type MearieOptions, mearie };
package/dist/index.js ADDED
@@ -0,0 +1,92 @@
1
+ import path from "node:path";
2
+ import { loadConfig, mergeConfig } from "@mearie/config";
3
+ import { CodegenContext, createMatcher, findFiles } from "@mearie/codegen";
4
+ import { logger, report } from "@mearie/core";
5
+
6
+ //#region src/plugin.ts
7
+ /**
8
+ * Vite plugin for Mearie GraphQL code generation.
9
+ * @param options - Plugin options.
10
+ * @returns Vite plugin.
11
+ */
12
+ const mearie = (options = {}) => {
13
+ let viteConfig;
14
+ let mearieConfig;
15
+ let context = null;
16
+ let generateTimer = null;
17
+ const ensureInitialized = async () => {
18
+ if (context) return;
19
+ mearieConfig = mergeConfig(await loadConfig({
20
+ cwd: viteConfig.root,
21
+ filename: options.config
22
+ }), options);
23
+ const { schemas, documents, exclude } = mearieConfig;
24
+ context = new CodegenContext();
25
+ const schemaFiles = await findFiles(viteConfig.root, {
26
+ include: schemas,
27
+ exclude
28
+ });
29
+ const documentFiles = await findFiles(viteConfig.root, {
30
+ include: documents,
31
+ exclude
32
+ });
33
+ await Promise.all([...schemaFiles.map((file) => context.addSchema(file)), ...documentFiles.map((file) => context.addDocument(file))]);
34
+ };
35
+ const scheduleGenerate = () => {
36
+ if (generateTimer) clearTimeout(generateTimer);
37
+ generateTimer = setTimeout(() => {
38
+ (async () => {
39
+ try {
40
+ await context?.generate();
41
+ } catch (error) {
42
+ report(logger, error);
43
+ }
44
+ })();
45
+ }, 100);
46
+ };
47
+ return {
48
+ name: "mearie",
49
+ enforce: "pre",
50
+ async configResolved(resolvedConfig) {
51
+ viteConfig = resolvedConfig;
52
+ try {
53
+ await ensureInitialized();
54
+ await context?.generate();
55
+ } catch (error) {
56
+ report(logger, error);
57
+ if (viteConfig.command === "build") throw error;
58
+ }
59
+ },
60
+ async hotUpdate({ file, type }) {
61
+ if (!context || !mearieConfig) return;
62
+ const { schemas, documents, exclude } = mearieConfig;
63
+ const relativePath = path.relative(viteConfig.root, file);
64
+ const schemaMatcher = createMatcher({
65
+ include: schemas,
66
+ exclude
67
+ });
68
+ const documentMatcher = createMatcher({
69
+ include: documents,
70
+ exclude
71
+ });
72
+ const matchesSchema = schemaMatcher(relativePath);
73
+ const matchesDocument = documentMatcher(relativePath);
74
+ if (!matchesSchema && !matchesDocument) return;
75
+ try {
76
+ if (type === "delete") {
77
+ if (matchesSchema) context.removeSchema(file);
78
+ if (matchesDocument) context.removeDocument(file);
79
+ } else {
80
+ if (matchesSchema) await context.addSchema(file);
81
+ if (matchesDocument) await context.addDocument(file);
82
+ }
83
+ scheduleGenerate();
84
+ } catch (error) {
85
+ report(logger, error);
86
+ }
87
+ }
88
+ };
89
+ };
90
+
91
+ //#endregion
92
+ export { mearie };
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@mearie/vite",
3
+ "version": "0.0.0",
4
+ "description": "Vite plugin for Mearie",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./src/index.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "dependencies": {
12
+ "@mearie/codegen": "0.0.0",
13
+ "@mearie/config": "0.0.0",
14
+ "@mearie/core": "0.0.0"
15
+ },
16
+ "devDependencies": {
17
+ "tsdown": "^0.15.7",
18
+ "tsx": "^4.20.6",
19
+ "vite": "^7.1.10",
20
+ "vitest": "^3.2.4"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "scripts": {
26
+ "build": "tsdown",
27
+ "test": "vitest run",
28
+ "test:all": "pnpm test && pnpm test:examples",
29
+ "test:examples": "tsx scripts/test-examples.ts",
30
+ "test:watch": "vitest"
31
+ },
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.js",
36
+ "require": "./dist/index.cjs"
37
+ }
38
+ }
39
+ }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Vite plugin for Mearie GraphQL code generation.
3
+ *
4
+ * This plugin extracts GraphQL operations from your source files and
5
+ * generates TypeScript types and runtime code using `@mearie/native`.
6
+ */
7
+
8
+ export { mearie } from './plugin.ts';
9
+ export type { MearieOptions } from './types.ts';