@vmz/plugin 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. package/README.md +51 -1
  2. package/index.d.ts +110 -0
  3. package/index.js +70 -0
  4. package/package.json +23 -3
package/README.md CHANGED
@@ -1,3 +1,53 @@
1
1
  # @vmz/plugin
2
2
 
3
- Placeholder package (0.0.1). Reserved for the VMZ project.
3
+ ## Build extensions without dissolving the application boundary
4
+
5
+ `@vmz/plugin` is the foundation for authors who want to extend VMZ with a domain capability: a renderer, a content
6
+ processor, a language integration, an editor, a design-oriented utility, or another contribution that belongs in a
7
+ full-stack application workflow.
8
+
9
+ ## The promise to plugin authors
10
+
11
+ VMZ should be hospitable to npm and JavaScript ecosystem packages. You should be able to package, version, distribute,
12
+ and compose useful functionality with normal Node tooling. A plugin can contribute declared capabilities and source
13
+ assets without forcing every project to adopt a bespoke compiler fork.
14
+
15
+ ## The promise to application authors
16
+
17
+ An extension must not make the application opaque. A VMZ plugin is not an unrestricted `transform(code)` escape hatch
18
+ and not an invitation to mutate the compiler's program graph in place. Contributions are versioned and declared so VMZ
19
+ can continue to reason about ownership, execution placement, SSR, resume, testing, diagnostics, and deployment.
20
+
21
+ This is the tradeoff: plugin authors gain a stable way to participate in VMZ, while users retain a coherent application
22
+ model after installing the plugin. If an integration requires arbitrary runtime injection or hidden semantic rewrites,
23
+ it belongs outside the core VMZ plugin contract.
24
+
25
+ | A plugin should contribute... | A plugin should not become... |
26
+ |----------------------------------------------------|----------------------------------------------------------|
27
+ | A declared capability with known inputs and output | A hidden second application runtime |
28
+ | Versioned integration behavior | An unrestricted semantic rewrite |
29
+ | Assets or adapters VMZ can place and test | A way around server, lifecycle, or deployment boundaries |
30
+
31
+ ## Who should use it
32
+
33
+ Use this package when you are creating a native VMZ integration, not when you simply need a conventional JavaScript
34
+ library in application code. The latter should remain a normal dependency unless it needs to participate in VMZ's
35
+ compiler-visible boundaries.
36
+
37
+ ## What a strong plugin can unlock 🚀
38
+
39
+ - A content engine can contribute deterministic rendered output and diagnostics.
40
+ - An editor can declare browser-only delivery while preserving an SSR-readable host.
41
+ - A design tool can expose compile-time tokens without becoming a global runtime store.
42
+ - A deployment adapter can contribute a target without rewriting application semantics.
43
+ - A testing integration can add evidence while preserving VMZ's test model.
44
+
45
+ ## Why contribution beats mutation
46
+
47
+ Mutation is convenient for the first plugin and expensive for the fiftieth. If every plugin can rewrite any source, graph node, or generated artifact, composition order becomes application semantics and no tool can explain the final result.
48
+
49
+ A contribution says what capability is being added, which versioned schema it follows, what it reads, what it emits, and where it may execute. That extra structure is what allows npm extensibility and strong compilation to coexist.
50
+
51
+ ## The litmus test
52
+
53
+ If installing the plugin makes `vmz check`, SSR, resume, tests, or deployment less able to explain the application, the integration is using the wrong boundary. A native plugin should leave VMZ more capable, not less coherent.
package/index.d.ts ADDED
@@ -0,0 +1,110 @@
1
+ /** VMZ plugin protocol helpers — types + identity `define*` (no N-API). */
2
+
3
+ export { PLUGIN_PROTOCOL } from '@vmz/protocol';
4
+
5
+ export function contentHash(content: string | Buffer): string;
6
+
7
+ /** Resolve a path next to the calling module (`import.meta.url`). */
8
+ export function pluginFileUrl(importMetaUrl: string, relativePath: string): string;
9
+
10
+ /**
11
+ * Load a real source file shipped with the plugin (typically `components/*.vmz`).
12
+ * Do not embed `.vmz` SFC text inside `vmz.plugin.ts`.
13
+ */
14
+ export function loadPluginSource(
15
+ importMetaUrl: string,
16
+ relativePath: string,
17
+ ): {
18
+ content: string;
19
+ contentHash: string;
20
+ absPath: string;
21
+ };
22
+
23
+ export type PluginStage = 'workspace_resolve' | 'source_adapter' | 'analyzer' | 'target';
24
+
25
+ export interface PluginManifest {
26
+ name: string;
27
+ version: string;
28
+ protocol?: string;
29
+ stages: PluginStage[];
30
+ deterministic?: boolean;
31
+ }
32
+
33
+ export interface ResolvedPackage {
34
+ name: string;
35
+ root: string;
36
+ version?: string;
37
+ }
38
+
39
+ export interface PluginContext {
40
+ project: string;
41
+ outDir: string;
42
+ stage: PluginStage | string;
43
+ protocol: string;
44
+ packages: ResolvedPackage[];
45
+ /** Default engines from `vmz.config`. */
46
+ engines?: VmzEngines;
47
+ }
48
+
49
+ export interface ContributionItem {
50
+ id: string;
51
+ kind: string;
52
+ path?: string;
53
+ content?: string;
54
+ contentHash?: string;
55
+ content_hash?: string;
56
+ materialize?: boolean;
57
+ severity?: string;
58
+ message?: string;
59
+ code?: string;
60
+ targetId?: string;
61
+ target_id?: string;
62
+ targetKind?: string;
63
+ target_kind?: string;
64
+ type?: string;
65
+ manifest?: unknown;
66
+ manifestJson?: string;
67
+ manifest_json?: string;
68
+ detail?: string;
69
+ /** Engine registration (host-recognized analyzer/source sidecar). */
70
+ engine?: string;
71
+ engineKind?: 'code' | 'math' | 'markdown' | string;
72
+ }
73
+
74
+ export interface ContributionBatchInput {
75
+ stage: PluginStage | string;
76
+ cacheKey?: string;
77
+ deterministic?: boolean;
78
+ items: ContributionItem[];
79
+ }
80
+
81
+ export interface VmzPlugin {
82
+ manifest: PluginManifest;
83
+ contribute?: (
84
+ ctx: PluginContext,
85
+ ) => Promise<ContributionBatchInput[] | ContributionBatchInput> | ContributionBatchInput[] | ContributionBatchInput;
86
+ }
87
+
88
+ export interface VmzEngines {
89
+ /** Default for `<Code>` when `engine` prop omitted. */
90
+ code?: string;
91
+ /** Default for `<Math>` when `engine` prop omitted. */
92
+ math?: string;
93
+ /** Default for `<Markdown>` when `engine` prop omitted; also used by `vmz document`. */
94
+ markdown?: string;
95
+ }
96
+
97
+ export interface VmzUserConfig {
98
+ plugins?: Array<string | VmzPlugin | Promise<VmzPlugin>>;
99
+ engines?: VmzEngines;
100
+ }
101
+
102
+ export type DefinePluginInput = PluginManifest & {
103
+ contribute?: VmzPlugin['contribute'];
104
+ };
105
+
106
+ /** Identity helper for IDE inference. */
107
+ export function definePlugin(def: DefinePluginInput): VmzPlugin;
108
+
109
+ /** Identity helper for `vmz.config.ts` inference. */
110
+ export function defineConfig(config: VmzUserConfig): VmzUserConfig;
package/index.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @vmz/plugin — protocol helpers (no N-API).
3
+ * Design: 规划设计/vmz/14-Node-NAPI与插件宿主.md
4
+ */
5
+
6
+ import { createHash } from 'node:crypto';
7
+ import { readFileSync } from 'node:fs';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ import { PLUGIN_PROTOCOL } from '@vmz/protocol';
11
+
12
+ export { PLUGIN_PROTOCOL };
13
+
14
+ /**
15
+ * @param {string | Buffer} content
16
+ * @returns {string}
17
+ */
18
+ export function contentHash(content) {
19
+ return createHash('sha256').update(content).digest('hex');
20
+ }
21
+
22
+ /**
23
+ * Resolve a path next to the calling module (`import.meta.url`).
24
+ * @param {string} importMetaUrl
25
+ * @param {string} relativePath
26
+ */
27
+ export function pluginFileUrl(importMetaUrl, relativePath) {
28
+ return path.join(path.dirname(fileURLToPath(importMetaUrl)), relativePath);
29
+ }
30
+
31
+ /**
32
+ * Load a real `.vmz` (or other text) shipped beside `vmz.plugin.ts`.
33
+ * Do not embed SFC source as JS/TS string templates.
34
+ * @param {string} importMetaUrl `import.meta.url` of the plugin module
35
+ * @param {string} relativePath e.g. `components/Katex.vmz`
36
+ * @returns {{ content: string, contentHash: string, absPath: string }}
37
+ */
38
+ export function loadPluginSource(importMetaUrl, relativePath) {
39
+ const absPath = pluginFileUrl(importMetaUrl, relativePath);
40
+ const content = readFileSync(absPath, 'utf8');
41
+ return { content, contentHash: contentHash(content), absPath };
42
+ }
43
+
44
+ /**
45
+ * @param {import('./index.js').DefinePluginInput} def
46
+ * @returns {import('./index.js').VmzPlugin}
47
+ */
48
+ export function definePlugin(def) {
49
+ if (!def?.name || !def?.version || !Array.isArray(def.stages)) {
50
+ throw new Error('definePlugin requires name, version, stages[]');
51
+ }
52
+ return {
53
+ manifest: {
54
+ name: def.name,
55
+ version: def.version,
56
+ protocol: def.protocol ?? PLUGIN_PROTOCOL,
57
+ stages: def.stages,
58
+ deterministic: def.deterministic ?? true,
59
+ },
60
+ contribute: def.contribute,
61
+ };
62
+ }
63
+
64
+ /**
65
+ * @param {import('./index.js').VmzUserConfig} config
66
+ * @returns {import('./index.js').VmzUserConfig}
67
+ */
68
+ export function defineConfig(config) {
69
+ return config ?? {};
70
+ }
package/package.json CHANGED
@@ -1,12 +1,32 @@
1
1
  {
2
2
  "name": "@vmz/plugin",
3
- "version": "0.0.1",
4
- "description": "VMZ placeholder 鈥?not for production use.",
3
+ "version": "0.0.2",
4
+ "type": "module",
5
+ "description": "VMZ plugin protocol types and definePlugin / defineConfig helpers (no N-API)",
5
6
  "license": "MIT",
6
- "private": false,
7
+ "main": "./index.js",
8
+ "types": "./index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./index.d.ts",
12
+ "default": "./index.js"
13
+ }
14
+ },
7
15
  "files": [
16
+ "index.js",
17
+ "index.d.ts",
8
18
  "README.md"
9
19
  ],
20
+ "dependencies": {
21
+ "@vmz/protocol": "0.0.2"
22
+ },
23
+ "keywords": [
24
+ "vmz",
25
+ "plugin"
26
+ ],
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
10
30
  "repository": {
11
31
  "type": "git",
12
32
  "url": "git+https://github.com/doki-land/vmz-framework.git"