@vmz/plugin 0.0.1 → 0.0.3
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/README.md +55 -1
- package/index.d.ts +110 -0
- package/index.js +69 -0
- package/package.json +23 -3
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
1
|
# @vmz/plugin
|
|
2
2
|
|
|
3
|
-
|
|
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,
|
|
48
|
+
graph node, or generated artifact, composition order becomes application semantics and no tool can explain the final
|
|
49
|
+
result.
|
|
50
|
+
|
|
51
|
+
A contribution says what capability is being added, which versioned schema it follows, what it reads, what it emits, and
|
|
52
|
+
where it may execute. That extra structure is what allows npm extensibility and strong compilation to coexist.
|
|
53
|
+
|
|
54
|
+
## The litmus test
|
|
55
|
+
|
|
56
|
+
If installing the plugin makes `vmz check`, SSR, resume, tests, or deployment less able to explain the application, the
|
|
57
|
+
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,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vmz/plugin — protocol helpers (no N-API).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
import { readFileSync } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { PLUGIN_PROTOCOL } from '@vmz/protocol';
|
|
10
|
+
|
|
11
|
+
export { PLUGIN_PROTOCOL };
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string | Buffer} content
|
|
15
|
+
* @returns {string}
|
|
16
|
+
*/
|
|
17
|
+
export function contentHash(content) {
|
|
18
|
+
return createHash('sha256').update(content).digest('hex');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve a path next to the calling module (`import.meta.url`).
|
|
23
|
+
* @param {string} importMetaUrl
|
|
24
|
+
* @param {string} relativePath
|
|
25
|
+
*/
|
|
26
|
+
export function pluginFileUrl(importMetaUrl, relativePath) {
|
|
27
|
+
return path.join(path.dirname(fileURLToPath(importMetaUrl)), relativePath);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Load a real `.vmz` (or other text) shipped beside `vmz.plugin.ts`.
|
|
32
|
+
* Do not embed SFC source as JS/TS string templates.
|
|
33
|
+
* @param {string} importMetaUrl `import.meta.url` of the plugin module
|
|
34
|
+
* @param {string} relativePath e.g. `components/Katex.vmz`
|
|
35
|
+
* @returns {{ content: string, contentHash: string, absPath: string }}
|
|
36
|
+
*/
|
|
37
|
+
export function loadPluginSource(importMetaUrl, relativePath) {
|
|
38
|
+
const absPath = pluginFileUrl(importMetaUrl, relativePath);
|
|
39
|
+
const content = readFileSync(absPath, 'utf8');
|
|
40
|
+
return { content, contentHash: contentHash(content), absPath };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {import('./index.js').DefinePluginInput} def
|
|
45
|
+
* @returns {import('./index.js').VmzPlugin}
|
|
46
|
+
*/
|
|
47
|
+
export function definePlugin(def) {
|
|
48
|
+
if (!def?.name || !def?.version || !Array.isArray(def.stages)) {
|
|
49
|
+
throw new Error('definePlugin requires name, version, stages[]');
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
manifest: {
|
|
53
|
+
name: def.name,
|
|
54
|
+
version: def.version,
|
|
55
|
+
protocol: def.protocol ?? PLUGIN_PROTOCOL,
|
|
56
|
+
stages: def.stages,
|
|
57
|
+
deterministic: def.deterministic ?? true,
|
|
58
|
+
},
|
|
59
|
+
contribute: def.contribute,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {import('./index.js').VmzUserConfig} config
|
|
65
|
+
* @returns {import('./index.js').VmzUserConfig}
|
|
66
|
+
*/
|
|
67
|
+
export function defineConfig(config) {
|
|
68
|
+
return config ?? {};
|
|
69
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vmz/plugin",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "VMZ plugin protocol types and definePlugin / defineConfig helpers (no N-API)",
|
|
5
6
|
"license": "MIT",
|
|
6
|
-
"
|
|
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.3"
|
|
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"
|