@mearie/vite 0.0.1-next.3 → 0.0.1-next.5
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/dist/index.cjs +49 -23
- package/dist/index.js +46 -20
- package/package.json +16 -20
package/dist/index.cjs
CHANGED
|
@@ -23,50 +23,55 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
let node_path = require("node:path");
|
|
25
25
|
node_path = __toESM(node_path);
|
|
26
|
+
let node_fs_promises = require("node:fs/promises");
|
|
27
|
+
node_fs_promises = __toESM(node_fs_promises);
|
|
26
28
|
let __mearie_config = require("@mearie/config");
|
|
27
29
|
__mearie_config = __toESM(__mearie_config);
|
|
28
30
|
let __mearie_codegen = require("@mearie/codegen");
|
|
29
31
|
__mearie_codegen = __toESM(__mearie_codegen);
|
|
30
|
-
let __mearie_core = require("@mearie/core");
|
|
31
|
-
__mearie_core = __toESM(__mearie_core);
|
|
32
32
|
|
|
33
33
|
//#region src/plugin.ts
|
|
34
|
+
const VIRTUAL_MODULE_ID = "$mearie";
|
|
35
|
+
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
34
36
|
/**
|
|
35
37
|
* Vite plugin for Mearie GraphQL code generation.
|
|
36
38
|
* @param options - Plugin options.
|
|
37
39
|
* @returns Vite plugin.
|
|
38
40
|
*/
|
|
39
41
|
const mearie = (options = {}) => {
|
|
40
|
-
let
|
|
42
|
+
let projectRoot;
|
|
41
43
|
let mearieConfig;
|
|
42
|
-
let context
|
|
44
|
+
let context;
|
|
43
45
|
let generateTimer = null;
|
|
44
46
|
const ensureInitialized = async () => {
|
|
45
47
|
if (context) return;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
context
|
|
52
|
-
const schemaFiles = await (0, __mearie_codegen.findFiles)(
|
|
48
|
+
const { config, cwd } = await (0, __mearie_config.loadConfig)({ filename: options.config });
|
|
49
|
+
projectRoot = cwd;
|
|
50
|
+
mearieConfig = (0, __mearie_config.mergeConfig)(config, options);
|
|
51
|
+
const { schema, document, exclude, scalars } = mearieConfig;
|
|
52
|
+
context = new __mearie_codegen.CodegenContext(projectRoot);
|
|
53
|
+
context.setConfig({ scalars });
|
|
54
|
+
const schemaFiles = await (0, __mearie_codegen.findFiles)(projectRoot, {
|
|
53
55
|
include: schema,
|
|
54
56
|
exclude
|
|
55
57
|
});
|
|
56
|
-
const documentFiles = await (0, __mearie_codegen.findFiles)(
|
|
58
|
+
const documentFiles = await (0, __mearie_codegen.findFiles)(projectRoot, {
|
|
57
59
|
include: document,
|
|
58
60
|
exclude
|
|
59
61
|
});
|
|
60
62
|
await Promise.all([...schemaFiles.map((file) => context.addSchema(file)), ...documentFiles.map((file) => context.addDocument(file))]);
|
|
61
63
|
};
|
|
62
|
-
const scheduleGenerate = () => {
|
|
64
|
+
const scheduleGenerate = (server) => {
|
|
63
65
|
if (generateTimer) clearTimeout(generateTimer);
|
|
64
66
|
generateTimer = setTimeout(() => {
|
|
65
67
|
(async () => {
|
|
66
68
|
try {
|
|
69
|
+
await ensureInitialized();
|
|
67
70
|
await context?.generate();
|
|
71
|
+
const virtualModule = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
72
|
+
if (virtualModule) await server.reloadModule(virtualModule);
|
|
68
73
|
} catch (error) {
|
|
69
|
-
(0,
|
|
74
|
+
(0, __mearie_codegen.report)(__mearie_codegen.logger, error);
|
|
70
75
|
}
|
|
71
76
|
})();
|
|
72
77
|
}, 100);
|
|
@@ -74,20 +79,28 @@ const mearie = (options = {}) => {
|
|
|
74
79
|
return {
|
|
75
80
|
name: "mearie",
|
|
76
81
|
enforce: "pre",
|
|
77
|
-
async configResolved(
|
|
78
|
-
viteConfig = resolvedConfig;
|
|
82
|
+
async configResolved(config) {
|
|
79
83
|
try {
|
|
80
84
|
await ensureInitialized();
|
|
81
85
|
await context?.generate();
|
|
82
86
|
} catch (error) {
|
|
83
|
-
(0,
|
|
84
|
-
if (
|
|
87
|
+
(0, __mearie_codegen.report)(__mearie_codegen.logger, error);
|
|
88
|
+
if (config.command === "build") throw error;
|
|
85
89
|
}
|
|
86
90
|
},
|
|
87
|
-
async
|
|
88
|
-
|
|
91
|
+
async configureServer(server) {
|
|
92
|
+
await ensureInitialized();
|
|
93
|
+
const { schema, exclude } = mearieConfig;
|
|
94
|
+
const schemaFiles = await (0, __mearie_codegen.findFiles)(projectRoot, {
|
|
95
|
+
include: schema,
|
|
96
|
+
exclude
|
|
97
|
+
});
|
|
98
|
+
for (const file of schemaFiles) server.watcher.add(file);
|
|
99
|
+
},
|
|
100
|
+
async hotUpdate({ file, type, server }) {
|
|
101
|
+
await ensureInitialized();
|
|
89
102
|
const { schema, document, exclude } = mearieConfig;
|
|
90
|
-
const relativePath = node_path.default.relative(
|
|
103
|
+
const relativePath = node_path.default.relative(projectRoot, file);
|
|
91
104
|
const schemaMatcher = (0, __mearie_codegen.createMatcher)({
|
|
92
105
|
include: schema,
|
|
93
106
|
exclude
|
|
@@ -107,9 +120,22 @@ const mearie = (options = {}) => {
|
|
|
107
120
|
if (matchesSchema) await context.addSchema(file);
|
|
108
121
|
if (matchesDocument) await context.addDocument(file);
|
|
109
122
|
}
|
|
110
|
-
scheduleGenerate();
|
|
123
|
+
scheduleGenerate(server);
|
|
111
124
|
} catch (error) {
|
|
112
|
-
(0,
|
|
125
|
+
(0, __mearie_codegen.report)(__mearie_codegen.logger, error);
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
resolveId(id) {
|
|
129
|
+
if (id === VIRTUAL_MODULE_ID) return RESOLVED_VIRTUAL_MODULE_ID;
|
|
130
|
+
},
|
|
131
|
+
async load(id) {
|
|
132
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
133
|
+
const jsPath = node_path.default.join(projectRoot, ".mearie", "graphql.js");
|
|
134
|
+
try {
|
|
135
|
+
return await (0, node_fs_promises.readFile)(jsPath, "utf8");
|
|
136
|
+
} catch {
|
|
137
|
+
return "export function graphql() { throw new Error(\"Mearie: graphql file not generated yet\"); }";
|
|
138
|
+
}
|
|
113
139
|
}
|
|
114
140
|
}
|
|
115
141
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,48 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
2
3
|
import { loadConfig, mergeConfig } from "@mearie/config";
|
|
3
|
-
import { CodegenContext, createMatcher, findFiles } from "@mearie/codegen";
|
|
4
|
-
import { logger, report } from "@mearie/core";
|
|
4
|
+
import { CodegenContext, createMatcher, findFiles, logger, report } from "@mearie/codegen";
|
|
5
5
|
|
|
6
6
|
//#region src/plugin.ts
|
|
7
|
+
const VIRTUAL_MODULE_ID = "$mearie";
|
|
8
|
+
const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
|
|
7
9
|
/**
|
|
8
10
|
* Vite plugin for Mearie GraphQL code generation.
|
|
9
11
|
* @param options - Plugin options.
|
|
10
12
|
* @returns Vite plugin.
|
|
11
13
|
*/
|
|
12
14
|
const mearie = (options = {}) => {
|
|
13
|
-
let
|
|
15
|
+
let projectRoot;
|
|
14
16
|
let mearieConfig;
|
|
15
|
-
let context
|
|
17
|
+
let context;
|
|
16
18
|
let generateTimer = null;
|
|
17
19
|
const ensureInitialized = async () => {
|
|
18
20
|
if (context) return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
context
|
|
25
|
-
const schemaFiles = await findFiles(
|
|
21
|
+
const { config, cwd } = await loadConfig({ filename: options.config });
|
|
22
|
+
projectRoot = cwd;
|
|
23
|
+
mearieConfig = mergeConfig(config, options);
|
|
24
|
+
const { schema, document, exclude, scalars } = mearieConfig;
|
|
25
|
+
context = new CodegenContext(projectRoot);
|
|
26
|
+
context.setConfig({ scalars });
|
|
27
|
+
const schemaFiles = await findFiles(projectRoot, {
|
|
26
28
|
include: schema,
|
|
27
29
|
exclude
|
|
28
30
|
});
|
|
29
|
-
const documentFiles = await findFiles(
|
|
31
|
+
const documentFiles = await findFiles(projectRoot, {
|
|
30
32
|
include: document,
|
|
31
33
|
exclude
|
|
32
34
|
});
|
|
33
35
|
await Promise.all([...schemaFiles.map((file) => context.addSchema(file)), ...documentFiles.map((file) => context.addDocument(file))]);
|
|
34
36
|
};
|
|
35
|
-
const scheduleGenerate = () => {
|
|
37
|
+
const scheduleGenerate = (server) => {
|
|
36
38
|
if (generateTimer) clearTimeout(generateTimer);
|
|
37
39
|
generateTimer = setTimeout(() => {
|
|
38
40
|
(async () => {
|
|
39
41
|
try {
|
|
42
|
+
await ensureInitialized();
|
|
40
43
|
await context?.generate();
|
|
44
|
+
const virtualModule = server.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
45
|
+
if (virtualModule) await server.reloadModule(virtualModule);
|
|
41
46
|
} catch (error) {
|
|
42
47
|
report(logger, error);
|
|
43
48
|
}
|
|
@@ -47,20 +52,28 @@ const mearie = (options = {}) => {
|
|
|
47
52
|
return {
|
|
48
53
|
name: "mearie",
|
|
49
54
|
enforce: "pre",
|
|
50
|
-
async configResolved(
|
|
51
|
-
viteConfig = resolvedConfig;
|
|
55
|
+
async configResolved(config) {
|
|
52
56
|
try {
|
|
53
57
|
await ensureInitialized();
|
|
54
58
|
await context?.generate();
|
|
55
59
|
} catch (error) {
|
|
56
60
|
report(logger, error);
|
|
57
|
-
if (
|
|
61
|
+
if (config.command === "build") throw error;
|
|
58
62
|
}
|
|
59
63
|
},
|
|
60
|
-
async
|
|
61
|
-
|
|
64
|
+
async configureServer(server) {
|
|
65
|
+
await ensureInitialized();
|
|
66
|
+
const { schema, exclude } = mearieConfig;
|
|
67
|
+
const schemaFiles = await findFiles(projectRoot, {
|
|
68
|
+
include: schema,
|
|
69
|
+
exclude
|
|
70
|
+
});
|
|
71
|
+
for (const file of schemaFiles) server.watcher.add(file);
|
|
72
|
+
},
|
|
73
|
+
async hotUpdate({ file, type, server }) {
|
|
74
|
+
await ensureInitialized();
|
|
62
75
|
const { schema, document, exclude } = mearieConfig;
|
|
63
|
-
const relativePath = path.relative(
|
|
76
|
+
const relativePath = path.relative(projectRoot, file);
|
|
64
77
|
const schemaMatcher = createMatcher({
|
|
65
78
|
include: schema,
|
|
66
79
|
exclude
|
|
@@ -80,10 +93,23 @@ const mearie = (options = {}) => {
|
|
|
80
93
|
if (matchesSchema) await context.addSchema(file);
|
|
81
94
|
if (matchesDocument) await context.addDocument(file);
|
|
82
95
|
}
|
|
83
|
-
scheduleGenerate();
|
|
96
|
+
scheduleGenerate(server);
|
|
84
97
|
} catch (error) {
|
|
85
98
|
report(logger, error);
|
|
86
99
|
}
|
|
100
|
+
},
|
|
101
|
+
resolveId(id) {
|
|
102
|
+
if (id === VIRTUAL_MODULE_ID) return RESOLVED_VIRTUAL_MODULE_ID;
|
|
103
|
+
},
|
|
104
|
+
async load(id) {
|
|
105
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
106
|
+
const jsPath = path.join(projectRoot, ".mearie", "graphql.js");
|
|
107
|
+
try {
|
|
108
|
+
return await readFile(jsPath, "utf8");
|
|
109
|
+
} catch {
|
|
110
|
+
return "export function graphql() { throw new Error(\"Mearie: graphql file not generated yet\"); }";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
87
113
|
}
|
|
88
114
|
};
|
|
89
115
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearie/vite",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.5",
|
|
4
4
|
"description": "Type-safe, zero-overhead GraphQL client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -26,22 +26,28 @@
|
|
|
26
26
|
"author": "Bae Junehyeon <finn@penxle.io>",
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"type": "module",
|
|
29
|
-
"
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
30
37
|
"files": [
|
|
31
38
|
"dist",
|
|
32
39
|
"package.json",
|
|
33
40
|
"README.md"
|
|
34
41
|
],
|
|
35
42
|
"dependencies": {
|
|
36
|
-
"@mearie/codegen": "0.0.1-next.
|
|
37
|
-
"@mearie/config": "0.0.1-next.
|
|
38
|
-
"@mearie/core": "0.0.1-next.3"
|
|
43
|
+
"@mearie/codegen": "0.0.1-next.5",
|
|
44
|
+
"@mearie/config": "0.0.1-next.5"
|
|
39
45
|
},
|
|
40
46
|
"devDependencies": {
|
|
41
|
-
"tsdown": "^0.15.
|
|
47
|
+
"tsdown": "^0.15.12",
|
|
42
48
|
"tsx": "^4.20.6",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
49
|
+
"typescript": "^5.9.3",
|
|
50
|
+
"vite": "^7.1.12"
|
|
45
51
|
},
|
|
46
52
|
"engines": {
|
|
47
53
|
"bun": ">=1.2.0",
|
|
@@ -53,19 +59,9 @@
|
|
|
53
59
|
},
|
|
54
60
|
"scripts": {
|
|
55
61
|
"build": "tsdown",
|
|
56
|
-
"
|
|
57
|
-
"test:all": "pnpm test && pnpm test:examples",
|
|
58
|
-
"test:examples": "tsx scripts/test-examples.ts",
|
|
59
|
-
"test:watch": "vitest"
|
|
60
|
-
},
|
|
61
|
-
"exports": {
|
|
62
|
-
".": {
|
|
63
|
-
"types": "./dist/index.d.ts",
|
|
64
|
-
"import": "./dist/index.js",
|
|
65
|
-
"require": "./dist/index.cjs"
|
|
66
|
-
},
|
|
67
|
-
"./package.json": "./package.json"
|
|
62
|
+
"typecheck": "tsc"
|
|
68
63
|
},
|
|
64
|
+
"main": "./dist/index.cjs",
|
|
69
65
|
"module": "./dist/index.js",
|
|
70
66
|
"types": "./dist/index.d.ts"
|
|
71
67
|
}
|