@vetta-org/plugin-vite 0.2.2 → 0.2.4
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/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -23
- package/dist/index.js.map +1 -1
- package/dist/pack.d.ts +3 -2
- package/dist/pack.d.ts.map +1 -1
- package/dist/pack.js +3 -2
- package/dist/pack.js.map +1 -1
- package/dist/plugin-logger.d.ts +6 -0
- package/dist/plugin-logger.d.ts.map +1 -0
- package/dist/plugin-logger.js +37 -0
- package/dist/plugin-logger.js.map +1 -0
- package/package.json +2 -2
package/dist/cli.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"","sourcesContent":["#!/usr/bin/env node\n\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport { startVettaPluginDevServer } from \"./dev-server.js\";\nimport { createVettaPluginPackage } from \"./pack.js\";\n\ntype CliCommand = \"dev\" | \"pack\" | \"validate\";\n\ninterface CliOptions {\n\tcommand: CliCommand;\n\trootDir: string;\n}\n\nfunction parseCliOptions(argv: string[]): CliOptions {\n\tconst command = argv[0];\n\tif (command !== \"dev\" && command !== \"pack\" && command !== \"validate\") {\n\t\tthrow new Error(\"Usage: vetta-plugin <dev|validate|pack> [--root <plugin-directory>]\");\n\t}\n\tlet rootDir = process.cwd();\n\tfor (let index = 1; index < argv.length; index += 1) {\n\t\tconst argument = argv[index];\n\t\tif (argument !== \"--root\" || !argv[index + 1]) {\n\t\t\tthrow new Error(`Unknown or incomplete option: ${argument}`);\n\t\t}\n\t\trootDir = resolve(argv[index + 1]);\n\t\tindex += 1;\n\t}\n\treturn { command, rootDir };\n}\n\nfunction writeEvent(event: object): void {\n\tprocess.stdout.write(`${JSON.stringify(event)}\\n`);\n}\n\nasync function runDevServer(rootDir: string): Promise<void> {\n\tconst devServer = await startVettaPluginDevServer(rootDir, writeEvent);\n\tawait new Promise<void>((resolvePromise) => {\n\t\tlet closing = false;\n\t\tconst close = () => {\n\t\t\tif (closing) return;\n\t\t\tclosing = true;\n\t\t\tvoid devServer.close().finally(resolvePromise);\n\t\t};\n\t\tprocess.once(\"SIGINT\", close);\n\t\tprocess.once(\"SIGTERM\", close);\n\t});\n}\n\nasync function validateManifest(rootDir: string): Promise<void> {\n\tconst manifestPath = resolve(rootDir, \"plugin.json\");\n\tconst raw: unknown = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\tprocess.stdout.write(\n\t\t`${JSON.stringify({\n\t\t\tok: true,\n\t\t\tid: manifest.id,\n\t\t\tversion: manifest.version,\n\t\t\tpluginApiVersion: manifest.pluginApiVersion,\n\t\t})}\\n`,\n\t);\n}\n\nasync function packPlugin(rootDir: string): Promise<void> {\n\tconst raw: unknown = JSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\tconst result = await createVettaPluginPackage({ rootDir });\n\tprocess.stdout.write(\n\t\t`${JSON.stringify({\n\t\t\tok: true,\n\t\t\tid: manifest.id,\n\t\t\tversion: manifest.version,\n\t\t\tzipPath: result.outputPath,\n\t\t\tfiles: result.files.map((file) => file.archivePath),\n\t\t})}\\n`,\n\t);\n}\n\nasync function main(): Promise<void> {\n\ttry {\n\t\tconst options = parseCliOptions(process.argv.slice(2));\n\t\tif (options.command === \"dev\") {\n\t\t\tawait runDevServer(options.rootDir);\n\t\t\treturn;\n\t\t}\n\t\tif (options.command === \"validate\") {\n\t\t\tawait validateManifest(options.rootDir);\n\t\t\treturn;\n\t\t}\n\t\tawait packPlugin(options.rootDir);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tprocess.stderr.write(`${JSON.stringify({ ok: false, error: message })}\\n`);\n\t\tprocess.exitCode = 1;\n\t}\n}\n\nvoid main();\n"]}
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"","sourcesContent":["#!/usr/bin/env node\n\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport { startVettaPluginDevServer } from \"./dev-server.js\";\nimport { createVettaPluginPackage } from \"./pack.js\";\n\ntype CliCommand = \"dev\" | \"pack\" | \"validate\";\n\ninterface CliOptions {\n\tcommand: CliCommand;\n\trootDir: string;\n}\n\nfunction parseCliOptions(argv: string[]): CliOptions {\n\tconst command = argv[0];\n\tif (command !== \"dev\" && command !== \"pack\" && command !== \"validate\") {\n\t\tthrow new Error(\"Usage: vetta-plugin <dev|validate|pack> [--root <plugin-directory>]\");\n\t}\n\tlet rootDir = process.cwd();\n\tfor (let index = 1; index < argv.length; index += 1) {\n\t\tconst argument = argv[index];\n\t\tif (argument !== \"--root\" || !argv[index + 1]) {\n\t\t\tthrow new Error(`Unknown or incomplete option: ${argument}`);\n\t\t}\n\t\trootDir = resolve(argv[index + 1]);\n\t\tindex += 1;\n\t}\n\treturn { command, rootDir };\n}\n\nfunction writeEvent(event: object): void {\n\tprocess.stdout.write(`${JSON.stringify(event)}\\n`);\n}\n\nasync function runDevServer(rootDir: string): Promise<void> {\n\tconst devServer = await startVettaPluginDevServer(rootDir, writeEvent);\n\tawait new Promise<void>((resolvePromise) => {\n\t\tlet closing = false;\n\t\tconst close = () => {\n\t\t\tif (closing) return;\n\t\t\tclosing = true;\n\t\t\tvoid devServer.close().finally(resolvePromise);\n\t\t};\n\t\tprocess.once(\"SIGINT\", close);\n\t\tprocess.once(\"SIGTERM\", close);\n\t});\n}\n\nasync function validateManifest(rootDir: string): Promise<void> {\n\tconst manifestPath = resolve(rootDir, \"plugin.json\");\n\tconst raw: unknown = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\tprocess.stdout.write(\n\t\t`${JSON.stringify({\n\t\t\tok: true,\n\t\t\tid: manifest.id,\n\t\t\tversion: manifest.version,\n\t\t\tpluginApiVersion: manifest.pluginApiVersion,\n\t\t})}\\n`,\n\t);\n}\n\nasync function packPlugin(rootDir: string): Promise<void> {\n\tconst raw: unknown = JSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\tconst result = await createVettaPluginPackage({ rootDir });\n\tprocess.stdout.write(\n\t\t`${JSON.stringify({\n\t\t\tok: true,\n\t\t\tid: manifest.id,\n\t\t\tversion: manifest.version,\n\t\t\tpackagePath: result.outputPath,\n\t\t\t// Compatibility for workbench scripts built before .vettapkg became the public format.\n\t\t\tzipPath: result.outputPath,\n\t\t\tfiles: result.files.map((file) => file.archivePath),\n\t\t})}\\n`,\n\t);\n}\n\nasync function main(): Promise<void> {\n\ttry {\n\t\tconst options = parseCliOptions(process.argv.slice(2));\n\t\tif (options.command === \"dev\") {\n\t\t\tawait runDevServer(options.rootDir);\n\t\t\treturn;\n\t\t}\n\t\tif (options.command === \"validate\") {\n\t\t\tawait validateManifest(options.rootDir);\n\t\t\treturn;\n\t\t}\n\t\tawait packPlugin(options.rootDir);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tprocess.stderr.write(`${JSON.stringify({ ok: false, error: message })}\\n`);\n\t\tprocess.exitCode = 1;\n\t}\n}\n\nvoid main();\n"]}
|
package/dist/cli.js
CHANGED
|
@@ -56,6 +56,8 @@ async function packPlugin(rootDir) {
|
|
|
56
56
|
ok: true,
|
|
57
57
|
id: manifest.id,
|
|
58
58
|
version: manifest.version,
|
|
59
|
+
packagePath: result.outputPath,
|
|
60
|
+
// Compatibility for workbench scripts built before .vettapkg became the public format.
|
|
59
61
|
zipPath: result.outputPath,
|
|
60
62
|
files: result.files.map((file) => file.archivePath),
|
|
61
63
|
})}\n`);
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AASrD,SAAS,eAAe,CAAC,IAAc,EAAc;IACpD,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,MAAM,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;IACxF,CAAC;IACD,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC5B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,QAAQ,KAAK,QAAQ,IAAI,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QACnC,KAAK,IAAI,CAAC,CAAC;IACZ,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,OAA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AAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;QAC3E,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;AAAA,CACD;AAED,KAAK,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport { startVettaPluginDevServer } from \"./dev-server.js\";\nimport { createVettaPluginPackage } from \"./pack.js\";\n\ntype CliCommand = \"dev\" | \"pack\" | \"validate\";\n\ninterface CliOptions {\n\tcommand: CliCommand;\n\trootDir: string;\n}\n\nfunction parseCliOptions(argv: string[]): CliOptions {\n\tconst command = argv[0];\n\tif (command !== \"dev\" && command !== \"pack\" && command !== \"validate\") {\n\t\tthrow new Error(\"Usage: vetta-plugin <dev|validate|pack> [--root <plugin-directory>]\");\n\t}\n\tlet rootDir = process.cwd();\n\tfor (let index = 1; index < argv.length; index += 1) {\n\t\tconst argument = argv[index];\n\t\tif (argument !== \"--root\" || !argv[index + 1]) {\n\t\t\tthrow new Error(`Unknown or incomplete option: ${argument}`);\n\t\t}\n\t\trootDir = resolve(argv[index + 1]);\n\t\tindex += 1;\n\t}\n\treturn { command, rootDir };\n}\n\nfunction writeEvent(event: object): void {\n\tprocess.stdout.write(`${JSON.stringify(event)}\\n`);\n}\n\nasync function runDevServer(rootDir: string): Promise<void> {\n\tconst devServer = await startVettaPluginDevServer(rootDir, writeEvent);\n\tawait new Promise<void>((resolvePromise) => {\n\t\tlet closing = false;\n\t\tconst close = () => {\n\t\t\tif (closing) return;\n\t\t\tclosing = true;\n\t\t\tvoid devServer.close().finally(resolvePromise);\n\t\t};\n\t\tprocess.once(\"SIGINT\", close);\n\t\tprocess.once(\"SIGTERM\", close);\n\t});\n}\n\nasync function validateManifest(rootDir: string): Promise<void> {\n\tconst manifestPath = resolve(rootDir, \"plugin.json\");\n\tconst raw: unknown = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\tprocess.stdout.write(\n\t\t`${JSON.stringify({\n\t\t\tok: true,\n\t\t\tid: manifest.id,\n\t\t\tversion: manifest.version,\n\t\t\tpluginApiVersion: manifest.pluginApiVersion,\n\t\t})}\\n`,\n\t);\n}\n\nasync function packPlugin(rootDir: string): Promise<void> {\n\tconst raw: unknown = JSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\tconst result = await createVettaPluginPackage({ rootDir });\n\tprocess.stdout.write(\n\t\t`${JSON.stringify({\n\t\t\tok: true,\n\t\t\tid: manifest.id,\n\t\t\tversion: manifest.version,\n\t\t\tzipPath: result.outputPath,\n\t\t\tfiles: result.files.map((file) => file.archivePath),\n\t\t})}\\n`,\n\t);\n}\n\nasync function main(): Promise<void> {\n\ttry {\n\t\tconst options = parseCliOptions(process.argv.slice(2));\n\t\tif (options.command === \"dev\") {\n\t\t\tawait runDevServer(options.rootDir);\n\t\t\treturn;\n\t\t}\n\t\tif (options.command === \"validate\") {\n\t\t\tawait validateManifest(options.rootDir);\n\t\t\treturn;\n\t\t}\n\t\tawait packPlugin(options.rootDir);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tprocess.stderr.write(`${JSON.stringify({ ok: false, error: message })}\\n`);\n\t\tprocess.exitCode = 1;\n\t}\n}\n\nvoid main();\n"]}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5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AK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;QAC3E,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACtB,CAAC;AAAA,CACD;AAED,KAAK,IAAI,EAAE,CAAC","sourcesContent":["#!/usr/bin/env node\n\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport { startVettaPluginDevServer } from \"./dev-server.js\";\nimport { createVettaPluginPackage } from \"./pack.js\";\n\ntype CliCommand = \"dev\" | \"pack\" | \"validate\";\n\ninterface CliOptions {\n\tcommand: CliCommand;\n\trootDir: string;\n}\n\nfunction parseCliOptions(argv: string[]): CliOptions {\n\tconst command = argv[0];\n\tif (command !== \"dev\" && command !== \"pack\" && command !== \"validate\") {\n\t\tthrow new Error(\"Usage: vetta-plugin <dev|validate|pack> [--root <plugin-directory>]\");\n\t}\n\tlet rootDir = process.cwd();\n\tfor (let index = 1; index < argv.length; index += 1) {\n\t\tconst argument = argv[index];\n\t\tif (argument !== \"--root\" || !argv[index + 1]) {\n\t\t\tthrow new Error(`Unknown or incomplete option: ${argument}`);\n\t\t}\n\t\trootDir = resolve(argv[index + 1]);\n\t\tindex += 1;\n\t}\n\treturn { command, rootDir };\n}\n\nfunction writeEvent(event: object): void {\n\tprocess.stdout.write(`${JSON.stringify(event)}\\n`);\n}\n\nasync function runDevServer(rootDir: string): Promise<void> {\n\tconst devServer = await startVettaPluginDevServer(rootDir, writeEvent);\n\tawait new Promise<void>((resolvePromise) => {\n\t\tlet closing = false;\n\t\tconst close = () => {\n\t\t\tif (closing) return;\n\t\t\tclosing = true;\n\t\t\tvoid devServer.close().finally(resolvePromise);\n\t\t};\n\t\tprocess.once(\"SIGINT\", close);\n\t\tprocess.once(\"SIGTERM\", close);\n\t});\n}\n\nasync function validateManifest(rootDir: string): Promise<void> {\n\tconst manifestPath = resolve(rootDir, \"plugin.json\");\n\tconst raw: unknown = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\tprocess.stdout.write(\n\t\t`${JSON.stringify({\n\t\t\tok: true,\n\t\t\tid: manifest.id,\n\t\t\tversion: manifest.version,\n\t\t\tpluginApiVersion: manifest.pluginApiVersion,\n\t\t})}\\n`,\n\t);\n}\n\nasync function packPlugin(rootDir: string): Promise<void> {\n\tconst raw: unknown = JSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\tconst result = await createVettaPluginPackage({ rootDir });\n\tprocess.stdout.write(\n\t\t`${JSON.stringify({\n\t\t\tok: true,\n\t\t\tid: manifest.id,\n\t\t\tversion: manifest.version,\n\t\t\tpackagePath: result.outputPath,\n\t\t\t// Compatibility for workbench scripts built before .vettapkg became the public format.\n\t\t\tzipPath: result.outputPath,\n\t\t\tfiles: result.files.map((file) => file.archivePath),\n\t\t})}\\n`,\n\t);\n}\n\nasync function main(): Promise<void> {\n\ttry {\n\t\tconst options = parseCliOptions(process.argv.slice(2));\n\t\tif (options.command === \"dev\") {\n\t\t\tawait runDevServer(options.rootDir);\n\t\t\treturn;\n\t\t}\n\t\tif (options.command === \"validate\") {\n\t\t\tawait validateManifest(options.rootDir);\n\t\t\treturn;\n\t\t}\n\t\tawait packPlugin(options.rootDir);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tprocess.stderr.write(`${JSON.stringify({ ok: false, error: message })}\\n`);\n\t\tprocess.exitCode = 1;\n\t}\n}\n\nvoid main();\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface VettaPluginFederationOptions {
|
|
|
10
10
|
entry?: string;
|
|
11
11
|
manifestFileName?: string;
|
|
12
12
|
remoteEntryFileName?: string;
|
|
13
|
+
/** Share the host design-system primitives exposed by `@vetta-org/ui`. */
|
|
14
|
+
hostUi?: boolean;
|
|
13
15
|
/** Share the narrow host UI contract exposed by `@vetta-org/theme-ui/plugin-ui`. */
|
|
14
16
|
hostThemeUi?: boolean;
|
|
15
17
|
shared?: ModuleFederationOptions["shared"];
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AAQjD,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,WAAW,CAAC;AAQ3F,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,+BAA+B,EAAE,SAAS,GAAG,SAAS,CAAC;IAC9G,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,4BAA4B;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,oFAAoF;IACpF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;CAC9C;AAED,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,4BAA4B,GAAG,uBAAuB,CAmEhH;AAkID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,YAAY,EAAE,CAwB3F","sourcesContent":["import { federation, type ModuleFederationOptions } from \"@module-federation/vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n\tcreateVettaPluginDevPlugins,\n\tisVettaPluginDevServer,\n\tVETTA_PLUGIN_DEV_ENTRY_ID,\n} from \"./dev-vite-plugins.js\";\nimport { createPluginBuildWarningFilter } from \"./build-warning-filter.js\";\nimport { createHostThemeBridgePlugin } from \"./host-theme.js\";\nimport { type CreateVettaPluginPackageOptions, createVettaPluginPackage } from \"./pack.js\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\nimport { createPluginStyleScopePlugin } from \"./style-scope.js\";\n\nconst SHARED_REACT_COMMONJS_BRIDGE_ID = \"virtual:vetta-plugin-shared-react-commonjs\";\nconst RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;\nconst STATIC_REACT_REQUIRE_PATTERN = /\\brequire\\s*\\(\\s*([\"'])react\\1\\s*\\)/gu;\n\nexport interface VettaPluginPackageOptions extends Omit<CreateVettaPluginPackageOptions, \"rootDir\" | \"distDir\"> {\n\tenabled?: boolean;\n}\n\nexport interface VettaPluginFederationOptions {\n\tname: string;\n\texpose?: string;\n\tentry?: string;\n\tmanifestFileName?: string;\n\tremoteEntryFileName?: string;\n\t/** Share the narrow host UI contract exposed by `@vetta-org/theme-ui/plugin-ui`. */\n\thostThemeUi?: boolean;\n\tshared?: ModuleFederationOptions[\"shared\"];\n\tpackage?: boolean | VettaPluginPackageOptions;\n}\n\nexport function createVettaPluginFederationConfig(options: VettaPluginFederationOptions): ModuleFederationOptions {\n\tconst expose = options.expose ?? \"./plugin\";\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\treturn {\n\t\tname: options.name,\n\t\tfilename: options.remoteEntryFileName ?? \"remoteEntry.js\",\n\t\texposes: {\n\t\t\t[expose]: entry,\n\t\t},\n\t\tmanifest: {\n\t\t\tfileName: options.manifestFileName ?? \"mf-manifest.json\",\n\t\t},\n\t\tdts: false,\n\t\tshared: {\n\t\t\t\"@vetta-org/plugin-sdk\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\treact: {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t\"react-dom\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Match host plugin-shared-modules (tldraw remotes may require this subpath).\n\t\t\t\"react-dom/client\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Host design-system primitives; runtime provided by desktop-app share scope.\n\t\t\t\"@vetta-org/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// 这个包 0.1.0 之前叫 @vetta/ui。名字同时是 MF 的共享键,只留新名会让按旧名\n\t\t\t// 构建的既有插件在共享域里落空、退回自己打包的那一份(两份 React 组件实例)。\n\t\t\t\"@vetta/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t...(options.hostThemeUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.\n\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t// 旧名,理由同 @vetta/ui:名字就是共享键,市场上已按旧名构建的插件要继续命中宿主实例。\n\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...options.shared,\n\t\t},\n\t};\n}\n\nfunction createBuildDefaultsPlugin(entry: string): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-build-defaults\",\n\t\tapply: \"build\",\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\t// Plugin remotes run inside the host page. Absolute asset URLs like\n\t\t\t\t// `/icon.png` resolve against the host origin (desktop-app public/), not\n\t\t\t\t// the remote. Prefer inlining small assets; large ones still go under\n\t\t\t\t// assets/ and rely on MF publicPath, but never land on host public/.\n\t\t\t\tbuild: {\n\t\t\t\t\tassetsInlineLimit: 32 * 1024,\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\tinput: entry,\n\t\t\t\t\t\t// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).\n\t\t\t\t\t\texternal: [\n\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\",\n\t\t\t\t\t\t\t\"@vetta-org/ui\",\n\t\t\t\t\t\t\t// 旧名仍然外置:否则用旧名写的插件源码会把整个 UI 库打进产物。\n\t\t\t\t\t\t\t\"@vetta/ui\",\n\t\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\",\n\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\",\n\t\t\t\t\t\t],\n\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\tassetFileNames(assetInfo) {\n\t\t\t\t\t\t\t\treturn assetInfo.names.some((name) => name.endsWith(\".css\"))\n\t\t\t\t\t\t\t\t\t? \"style.css\"\n\t\t\t\t\t\t\t\t\t: \"assets/[name]-[hash][extname]\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tpaths: {\n\t\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\": \"vetta-host://plugin-sdk\",\n\t\t\t\t\t\t\t\t\"@vetta-org/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n// Module Federation exposes shared React through a virtual ESM module. Routing\n// static CommonJS requires through this namespace keeps Rollup's generated\n// bindings stable when dependencies such as use-sync-external-store are bundled.\nfunction createSharedReactCommonJsBridgePlugin(): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-shared-react-commonjs-bridge\",\n\t\tapply: \"build\",\n\t\tenforce: \"pre\",\n\t\ttransform(code) {\n\t\t\tif (!code.includes(\"require\") || !code.includes(\"react\")) return;\n\t\t\tconst transformed = code.replace(\n\t\t\t\tSTATIC_REACT_REQUIRE_PATTERN,\n\t\t\t\t`require(${JSON.stringify(SHARED_REACT_COMMONJS_BRIDGE_ID)})`,\n\t\t\t);\n\t\t\tif (transformed === code) return;\n\t\t\treturn { code: transformed, map: null };\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === SHARED_REACT_COMMONJS_BRIDGE_ID) return RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID) return;\n\t\t\treturn `import * as React from \"react\";\nexport * from \"react\";\nexport default React;\n`;\n\t\t},\n\t};\n}\n\nfunction createPackagePlugin(options: VettaPluginPackageOptions): Plugin {\n\tlet rootDir = \"\";\n\tlet distDir = \"\";\n\tlet buildFailed = false;\n\n\treturn {\n\t\tname: \"vetta-plugin-package\",\n\t\tapply: \"build\",\n\t\tbuildStart() {\n\t\t\tbuildFailed = false;\n\t\t},\n\t\tbuildEnd(error) {\n\t\t\tbuildFailed = error !== undefined;\n\t\t},\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t\tdistDir = config.build.outDir;\n\t\t},\n\t\tasync closeBundle() {\n\t\t\tif (options.enabled === false || buildFailed) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await createVettaPluginPackage({\n\t\t\t\t...options,\n\t\t\t\trootDir,\n\t\t\t\tdistDir,\n\t\t\t});\n\t\t\tconsole.log(`[vetta-plugin-vite] Wrote ${result.outputPath} with ${result.files.length} runtime files`);\n\t\t},\n\t};\n}\n\nfunction createPermissionContractPlugin(): Plugin {\n\tlet rootDir = \"\";\n\treturn {\n\t\tname: \"vetta-plugin-permission-contract\",\n\t\tapply: \"build\",\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync generateBundle(_outputOptions, bundle) {\n\t\t\tconst manifest = parsePluginManifest(\n\t\t\t\tJSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\")) as unknown,\n\t\t\t);\n\t\t\tassertPluginPermissionContract(\n\t\t\t\tmanifest,\n\t\t\t\tObject.values(bundle).flatMap((output) =>\n\t\t\t\t\toutput.type === \"chunk\" ? [{ fileName: output.fileName, code: output.code }] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function vettaPluginFederation(options: VettaPluginFederationOptions): PluginOption[] {\n\tconst packageOptions = typeof options.package === \"object\" ? options.package : {};\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\tconst devServer = isVettaPluginDevServer();\n\tconst plugins: PluginOption[] = [\n\t\tcreatePluginBuildWarningFilter(),\n\t\tcreateHostThemeBridgePlugin(),\n\t\t...(devServer ? createVettaPluginDevPlugins(entry) : []),\n\t\tcreateBuildDefaultsPlugin(entry),\n\t\tcreateSharedReactCommonJsBridgePlugin(),\n\t\t...federation({\n\t\t\t...createVettaPluginFederationConfig(options),\n\t\t\texposes: {\n\t\t\t\t[options.expose ?? \"./plugin\"]: devServer ? VETTA_PLUGIN_DEV_ENTRY_ID : entry,\n\t\t\t},\n\t\t}),\n\t\tcreatePluginStyleScopePlugin(),\n\t\tcreatePermissionContractPlugin(),\n\t];\n\t// 兼容旧宿主的 build-watch 流程:增量构建时不重复打 zip。\n\tif (options.package !== false && process.env.VETTA_PLUGIN_DEV_WATCH !== \"1\") {\n\t\tplugins.push(createPackagePlugin(packageOptions));\n\t}\n\treturn plugins;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAInF,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AAQjD,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,WAAW,CAAC;AAS3F,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CAAC,+BAA+B,EAAE,SAAS,GAAG,SAAS,CAAC;IAC9G,OAAO,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,4BAA4B;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,oFAAoF;IACpF,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,CAAC,EAAE,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;CAC9C;AAED,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,4BAA4B,GAAG,uBAAuB,CA0DhH;AAsID,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,4BAA4B,GAAG,YAAY,EAAE,CAyB3F","sourcesContent":["import { federation, type ModuleFederationOptions } from \"@module-federation/vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n\tcreateVettaPluginDevPlugins,\n\tisVettaPluginDevServer,\n\tVETTA_PLUGIN_DEV_ENTRY_ID,\n} from \"./dev-vite-plugins.js\";\nimport { createPluginBuildWarningFilter } from \"./build-warning-filter.js\";\nimport { createHostThemeBridgePlugin } from \"./host-theme.js\";\nimport { type CreateVettaPluginPackageOptions, createVettaPluginPackage } from \"./pack.js\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\nimport { createPluginStyleScopePlugin } from \"./style-scope.js\";\nimport { createPluginLoggerBindingPlugin } from \"./plugin-logger.js\";\n\nconst SHARED_REACT_COMMONJS_BRIDGE_ID = \"virtual:vetta-plugin-shared-react-commonjs\";\nconst RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;\nconst STATIC_REACT_REQUIRE_PATTERN = /\\brequire\\s*\\(\\s*([\"'])react\\1\\s*\\)/gu;\n\nexport interface VettaPluginPackageOptions extends Omit<CreateVettaPluginPackageOptions, \"rootDir\" | \"distDir\"> {\n\tenabled?: boolean;\n}\n\nexport interface VettaPluginFederationOptions {\n\tname: string;\n\texpose?: string;\n\tentry?: string;\n\tmanifestFileName?: string;\n\tremoteEntryFileName?: string;\n\t/** Share the host design-system primitives exposed by `@vetta-org/ui`. */\n\thostUi?: boolean;\n\t/** Share the narrow host UI contract exposed by `@vetta-org/theme-ui/plugin-ui`. */\n\thostThemeUi?: boolean;\n\tshared?: ModuleFederationOptions[\"shared\"];\n\tpackage?: boolean | VettaPluginPackageOptions;\n}\n\nexport function createVettaPluginFederationConfig(options: VettaPluginFederationOptions): ModuleFederationOptions {\n\tconst expose = options.expose ?? \"./plugin\";\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\treturn {\n\t\tname: options.name,\n\t\tfilename: options.remoteEntryFileName ?? \"remoteEntry.js\",\n\t\texposes: {\n\t\t\t[expose]: entry,\n\t\t},\n\t\tmanifest: {\n\t\t\tfileName: options.manifestFileName ?? \"mf-manifest.json\",\n\t\t},\n\t\tdts: false,\n\t\tshared: {\n\t\t\t\"@vetta-org/plugin-sdk\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\treact: {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t\"react-dom\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Match host plugin-shared-modules (tldraw remotes may require this subpath).\n\t\t\t\"react-dom/client\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t...(options.hostUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host design-system primitives; runtime provided by desktop-app share scope.\n\t\t\t\t\t\t\"@vetta-org/ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...(options.hostThemeUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.\n\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...options.shared,\n\t\t},\n\t};\n}\n\nfunction createBuildDefaultsPlugin(entry: string, options: Pick<VettaPluginFederationOptions, \"hostUi\">): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-build-defaults\",\n\t\tapply: \"build\",\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\t// Plugin remotes run inside the host page. Absolute asset URLs like\n\t\t\t\t// `/icon.png` resolve against the host origin (desktop-app public/), not\n\t\t\t\t// the remote. Prefer inlining small assets; large ones still go under\n\t\t\t\t// assets/ and rely on MF publicPath, but never land on host public/.\n\t\t\t\tbuild: {\n\t\t\t\t\tassetsInlineLimit: 32 * 1024,\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\tinput: entry,\n\t\t\t\t\t\t// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).\n\t\t\t\t\t\texternal: [\n\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\",\n\t\t\t\t\t\t\t...(options.hostUi\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\"@vetta-org/ui\",\n\t\t\t\t\t\t\t\t\t\t// 旧源码名仍映射到宿主;已构建的旧 remote 则由 Desktop share scope 兼容。\n\t\t\t\t\t\t\t\t\t\t\"@vetta/ui\",\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\",\n\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\",\n\t\t\t\t\t\t],\n\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\tassetFileNames(assetInfo) {\n\t\t\t\t\t\t\t\treturn assetInfo.names.some((name) => name.endsWith(\".css\"))\n\t\t\t\t\t\t\t\t\t? \"style.css\"\n\t\t\t\t\t\t\t\t\t: \"assets/[name]-[hash][extname]\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tpaths: {\n\t\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\": \"vetta-host://plugin-sdk\",\n\t\t\t\t\t\t\t\t\"@vetta-org/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n// Module Federation exposes shared React through a virtual ESM module. Routing\n// static CommonJS requires through this namespace keeps Rollup's generated\n// bindings stable when dependencies such as use-sync-external-store are bundled.\nfunction createSharedReactCommonJsBridgePlugin(): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-shared-react-commonjs-bridge\",\n\t\tapply: \"build\",\n\t\tenforce: \"pre\",\n\t\ttransform(code) {\n\t\t\tif (!code.includes(\"require\") || !code.includes(\"react\")) return;\n\t\t\tconst transformed = code.replace(\n\t\t\t\tSTATIC_REACT_REQUIRE_PATTERN,\n\t\t\t\t`require(${JSON.stringify(SHARED_REACT_COMMONJS_BRIDGE_ID)})`,\n\t\t\t);\n\t\t\tif (transformed === code) return;\n\t\t\treturn { code: transformed, map: null };\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === SHARED_REACT_COMMONJS_BRIDGE_ID) return RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID) return;\n\t\t\treturn `import * as React from \"react\";\nexport * from \"react\";\nexport default React;\n`;\n\t\t},\n\t};\n}\n\nfunction createPackagePlugin(options: VettaPluginPackageOptions): Plugin {\n\tlet rootDir = \"\";\n\tlet distDir = \"\";\n\tlet buildFailed = false;\n\n\treturn {\n\t\tname: \"vetta-plugin-package\",\n\t\tapply: \"build\",\n\t\tbuildStart() {\n\t\t\tbuildFailed = false;\n\t\t},\n\t\tbuildEnd(error) {\n\t\t\tbuildFailed = error !== undefined;\n\t\t},\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t\tdistDir = config.build.outDir;\n\t\t},\n\t\tasync closeBundle() {\n\t\t\tif (options.enabled === false || buildFailed) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await createVettaPluginPackage({\n\t\t\t\t...options,\n\t\t\t\trootDir,\n\t\t\t\tdistDir,\n\t\t\t});\n\t\t\tconsole.log(`[vetta-plugin-vite] Wrote ${result.outputPath} with ${result.files.length} runtime files`);\n\t\t},\n\t};\n}\n\nfunction createPermissionContractPlugin(): Plugin {\n\tlet rootDir = \"\";\n\treturn {\n\t\tname: \"vetta-plugin-permission-contract\",\n\t\tapply: \"build\",\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync generateBundle(_outputOptions, bundle) {\n\t\t\tconst manifest = parsePluginManifest(\n\t\t\t\tJSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\")) as unknown,\n\t\t\t);\n\t\t\tassertPluginPermissionContract(\n\t\t\t\tmanifest,\n\t\t\t\tObject.values(bundle).flatMap((output) =>\n\t\t\t\t\toutput.type === \"chunk\" ? [{ fileName: output.fileName, code: output.code }] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function vettaPluginFederation(options: VettaPluginFederationOptions): PluginOption[] {\n\tconst packageOptions = typeof options.package === \"object\" ? options.package : {};\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\tconst devServer = isVettaPluginDevServer();\n\tconst plugins: PluginOption[] = [\n\t\tcreatePluginBuildWarningFilter(),\n\t\tcreateHostThemeBridgePlugin(),\n\t\tcreatePluginLoggerBindingPlugin(),\n\t\t...(devServer ? createVettaPluginDevPlugins(entry) : []),\n\t\tcreateBuildDefaultsPlugin(entry, options),\n\t\tcreateSharedReactCommonJsBridgePlugin(),\n\t\t...federation({\n\t\t\t...createVettaPluginFederationConfig(options),\n\t\t\texposes: {\n\t\t\t\t[options.expose ?? \"./plugin\"]: devServer ? VETTA_PLUGIN_DEV_ENTRY_ID : entry,\n\t\t\t},\n\t\t}),\n\t\tcreatePluginStyleScopePlugin(),\n\t\tcreatePermissionContractPlugin(),\n\t];\n\t// 兼容旧宿主的 build-watch 流程:增量构建时不重复打 zip。\n\tif (options.package !== false && process.env.VETTA_PLUGIN_DEV_WATCH !== \"1\") {\n\t\tplugins.push(createPackagePlugin(packageOptions));\n\t}\n\treturn plugins;\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { createHostThemeBridgePlugin } from "./host-theme.js";
|
|
|
8
8
|
import { createVettaPluginPackage } from "./pack.js";
|
|
9
9
|
import { assertPluginPermissionContract } from "./permission-contract.js";
|
|
10
10
|
import { createPluginStyleScopePlugin } from "./style-scope.js";
|
|
11
|
+
import { createPluginLoggerBindingPlugin } from "./plugin-logger.js";
|
|
11
12
|
const SHARED_REACT_COMMONJS_BRIDGE_ID = "virtual:vetta-plugin-shared-react-commonjs";
|
|
12
13
|
const RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;
|
|
13
14
|
const STATIC_REACT_REQUIRE_PATTERN = /\brequire\s*\(\s*(["'])react\1\s*\)/gu;
|
|
@@ -46,29 +47,20 @@ export function createVettaPluginFederationConfig(options) {
|
|
|
46
47
|
import: false,
|
|
47
48
|
requiredVersion: "*",
|
|
48
49
|
},
|
|
49
|
-
|
|
50
|
-
"@vetta-org/ui": {
|
|
51
|
-
singleton: true,
|
|
52
|
-
import: false,
|
|
53
|
-
requiredVersion: "*",
|
|
54
|
-
},
|
|
55
|
-
// 这个包 0.1.0 之前叫 @vetta/ui。名字同时是 MF 的共享键,只留新名会让按旧名
|
|
56
|
-
// 构建的既有插件在共享域里落空、退回自己打包的那一份(两份 React 组件实例)。
|
|
57
|
-
"@vetta/ui": {
|
|
58
|
-
singleton: true,
|
|
59
|
-
import: false,
|
|
60
|
-
requiredVersion: "*",
|
|
61
|
-
},
|
|
62
|
-
...(options.hostThemeUi
|
|
50
|
+
...(options.hostUi
|
|
63
51
|
? {
|
|
64
|
-
// Host-
|
|
65
|
-
"@vetta-org/
|
|
52
|
+
// Host design-system primitives; runtime provided by desktop-app share scope.
|
|
53
|
+
"@vetta-org/ui": {
|
|
66
54
|
singleton: true,
|
|
67
55
|
import: false,
|
|
68
56
|
requiredVersion: "*",
|
|
69
57
|
},
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
}
|
|
59
|
+
: {}),
|
|
60
|
+
...(options.hostThemeUi
|
|
61
|
+
? {
|
|
62
|
+
// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.
|
|
63
|
+
"@vetta-org/theme-ui/plugin-ui": {
|
|
72
64
|
singleton: true,
|
|
73
65
|
import: false,
|
|
74
66
|
requiredVersion: "*",
|
|
@@ -79,7 +71,7 @@ export function createVettaPluginFederationConfig(options) {
|
|
|
79
71
|
},
|
|
80
72
|
};
|
|
81
73
|
}
|
|
82
|
-
function createBuildDefaultsPlugin(entry) {
|
|
74
|
+
function createBuildDefaultsPlugin(entry, options) {
|
|
83
75
|
return {
|
|
84
76
|
name: "vetta-plugin-build-defaults",
|
|
85
77
|
apply: "build",
|
|
@@ -96,9 +88,13 @@ function createBuildDefaultsPlugin(entry) {
|
|
|
96
88
|
// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).
|
|
97
89
|
external: [
|
|
98
90
|
"@vetta-org/plugin-sdk",
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
91
|
+
...(options.hostUi
|
|
92
|
+
? [
|
|
93
|
+
"@vetta-org/ui",
|
|
94
|
+
// 旧源码名仍映射到宿主;已构建的旧 remote 则由 Desktop share scope 兼容。
|
|
95
|
+
"@vetta/ui",
|
|
96
|
+
]
|
|
97
|
+
: []),
|
|
102
98
|
"@vetta-org/theme-ui/plugin-ui",
|
|
103
99
|
"@vetta/theme-ui/plugin-ui",
|
|
104
100
|
],
|
|
@@ -203,8 +199,9 @@ export function vettaPluginFederation(options) {
|
|
|
203
199
|
const plugins = [
|
|
204
200
|
createPluginBuildWarningFilter(),
|
|
205
201
|
createHostThemeBridgePlugin(),
|
|
202
|
+
createPluginLoggerBindingPlugin(),
|
|
206
203
|
...(devServer ? createVettaPluginDevPlugins(entry) : []),
|
|
207
|
-
createBuildDefaultsPlugin(entry),
|
|
204
|
+
createBuildDefaultsPlugin(entry, options),
|
|
208
205
|
createSharedReactCommonJsBridgePlugin(),
|
|
209
206
|
...federation({
|
|
210
207
|
...createVettaPluginFederationConfig(options),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAErE,OAAO,EACN,2BAA2B,EAC3B,sBAAsB,EACtB,yBAAyB,GACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAwC,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC3F,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,4BAA4B,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,+BAA+B,GAAG,4CAA4C,CAAC;AACrF,MAAM,wCAAwC,GAAG,KAAK,+BAA+B,EAAE,CAAC;AACxF,MAAM,4BAA4B,GAAG,uCAAuC,CAAC;AAkB7E,MAAM,UAAU,iCAAiC,CAAC,OAAqC,EAA2B;IACjH,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;IAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,iBAAiB,CAAC;IACjD,OA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AA2B,EAAE;QAC7B,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,yBAAyB,CAAC,KAAK,CAAC;QAChC,qCAAqC,EAAE;QACvC,GAAG,UAAU,CAAC;YACb,GAAG,iCAAiC,CAAC,OAAO,CAAC;YAC7C,OAAO,EAAE;gBACR,CAAC,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,KAAK;aAC7E;SACD,CAAC;QACF,4BAA4B,EAAE;QAC9B,8BAA8B,EAAE;KAChC,CAAC;IACF,6EAAuC;IACvC,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,GAAG,EAAE,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import { federation, type ModuleFederationOptions } from \"@module-federation/vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n\tcreateVettaPluginDevPlugins,\n\tisVettaPluginDevServer,\n\tVETTA_PLUGIN_DEV_ENTRY_ID,\n} from \"./dev-vite-plugins.js\";\nimport { createPluginBuildWarningFilter } from \"./build-warning-filter.js\";\nimport { createHostThemeBridgePlugin } from \"./host-theme.js\";\nimport { type CreateVettaPluginPackageOptions, createVettaPluginPackage } from \"./pack.js\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\nimport { createPluginStyleScopePlugin } from \"./style-scope.js\";\n\nconst SHARED_REACT_COMMONJS_BRIDGE_ID = \"virtual:vetta-plugin-shared-react-commonjs\";\nconst RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;\nconst STATIC_REACT_REQUIRE_PATTERN = /\\brequire\\s*\\(\\s*([\"'])react\\1\\s*\\)/gu;\n\nexport interface VettaPluginPackageOptions extends Omit<CreateVettaPluginPackageOptions, \"rootDir\" | \"distDir\"> {\n\tenabled?: boolean;\n}\n\nexport interface VettaPluginFederationOptions {\n\tname: string;\n\texpose?: string;\n\tentry?: string;\n\tmanifestFileName?: string;\n\tremoteEntryFileName?: string;\n\t/** Share the narrow host UI contract exposed by `@vetta-org/theme-ui/plugin-ui`. */\n\thostThemeUi?: boolean;\n\tshared?: ModuleFederationOptions[\"shared\"];\n\tpackage?: boolean | VettaPluginPackageOptions;\n}\n\nexport function createVettaPluginFederationConfig(options: VettaPluginFederationOptions): ModuleFederationOptions {\n\tconst expose = options.expose ?? \"./plugin\";\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\treturn {\n\t\tname: options.name,\n\t\tfilename: options.remoteEntryFileName ?? \"remoteEntry.js\",\n\t\texposes: {\n\t\t\t[expose]: entry,\n\t\t},\n\t\tmanifest: {\n\t\t\tfileName: options.manifestFileName ?? \"mf-manifest.json\",\n\t\t},\n\t\tdts: false,\n\t\tshared: {\n\t\t\t\"@vetta-org/plugin-sdk\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\treact: {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t\"react-dom\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Match host plugin-shared-modules (tldraw remotes may require this subpath).\n\t\t\t\"react-dom/client\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Host design-system primitives; runtime provided by desktop-app share scope.\n\t\t\t\"@vetta-org/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// 这个包 0.1.0 之前叫 @vetta/ui。名字同时是 MF 的共享键,只留新名会让按旧名\n\t\t\t// 构建的既有插件在共享域里落空、退回自己打包的那一份(两份 React 组件实例)。\n\t\t\t\"@vetta/ui\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t...(options.hostThemeUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.\n\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t// 旧名,理由同 @vetta/ui:名字就是共享键,市场上已按旧名构建的插件要继续命中宿主实例。\n\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...options.shared,\n\t\t},\n\t};\n}\n\nfunction createBuildDefaultsPlugin(entry: string): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-build-defaults\",\n\t\tapply: \"build\",\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\t// Plugin remotes run inside the host page. Absolute asset URLs like\n\t\t\t\t// `/icon.png` resolve against the host origin (desktop-app public/), not\n\t\t\t\t// the remote. Prefer inlining small assets; large ones still go under\n\t\t\t\t// assets/ and rely on MF publicPath, but never land on host public/.\n\t\t\t\tbuild: {\n\t\t\t\t\tassetsInlineLimit: 32 * 1024,\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\tinput: entry,\n\t\t\t\t\t\t// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).\n\t\t\t\t\t\texternal: [\n\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\",\n\t\t\t\t\t\t\t\"@vetta-org/ui\",\n\t\t\t\t\t\t\t// 旧名仍然外置:否则用旧名写的插件源码会把整个 UI 库打进产物。\n\t\t\t\t\t\t\t\"@vetta/ui\",\n\t\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\",\n\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\",\n\t\t\t\t\t\t],\n\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\tassetFileNames(assetInfo) {\n\t\t\t\t\t\t\t\treturn assetInfo.names.some((name) => name.endsWith(\".css\"))\n\t\t\t\t\t\t\t\t\t? \"style.css\"\n\t\t\t\t\t\t\t\t\t: \"assets/[name]-[hash][extname]\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tpaths: {\n\t\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\": \"vetta-host://plugin-sdk\",\n\t\t\t\t\t\t\t\t\"@vetta-org/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n// Module Federation exposes shared React through a virtual ESM module. Routing\n// static CommonJS requires through this namespace keeps Rollup's generated\n// bindings stable when dependencies such as use-sync-external-store are bundled.\nfunction createSharedReactCommonJsBridgePlugin(): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-shared-react-commonjs-bridge\",\n\t\tapply: \"build\",\n\t\tenforce: \"pre\",\n\t\ttransform(code) {\n\t\t\tif (!code.includes(\"require\") || !code.includes(\"react\")) return;\n\t\t\tconst transformed = code.replace(\n\t\t\t\tSTATIC_REACT_REQUIRE_PATTERN,\n\t\t\t\t`require(${JSON.stringify(SHARED_REACT_COMMONJS_BRIDGE_ID)})`,\n\t\t\t);\n\t\t\tif (transformed === code) return;\n\t\t\treturn { code: transformed, map: null };\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === SHARED_REACT_COMMONJS_BRIDGE_ID) return RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID) return;\n\t\t\treturn `import * as React from \"react\";\nexport * from \"react\";\nexport default React;\n`;\n\t\t},\n\t};\n}\n\nfunction createPackagePlugin(options: VettaPluginPackageOptions): Plugin {\n\tlet rootDir = \"\";\n\tlet distDir = \"\";\n\tlet buildFailed = false;\n\n\treturn {\n\t\tname: \"vetta-plugin-package\",\n\t\tapply: \"build\",\n\t\tbuildStart() {\n\t\t\tbuildFailed = false;\n\t\t},\n\t\tbuildEnd(error) {\n\t\t\tbuildFailed = error !== undefined;\n\t\t},\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t\tdistDir = config.build.outDir;\n\t\t},\n\t\tasync closeBundle() {\n\t\t\tif (options.enabled === false || buildFailed) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await createVettaPluginPackage({\n\t\t\t\t...options,\n\t\t\t\trootDir,\n\t\t\t\tdistDir,\n\t\t\t});\n\t\t\tconsole.log(`[vetta-plugin-vite] Wrote ${result.outputPath} with ${result.files.length} runtime files`);\n\t\t},\n\t};\n}\n\nfunction createPermissionContractPlugin(): Plugin {\n\tlet rootDir = \"\";\n\treturn {\n\t\tname: \"vetta-plugin-permission-contract\",\n\t\tapply: \"build\",\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync generateBundle(_outputOptions, bundle) {\n\t\t\tconst manifest = parsePluginManifest(\n\t\t\t\tJSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\")) as unknown,\n\t\t\t);\n\t\t\tassertPluginPermissionContract(\n\t\t\t\tmanifest,\n\t\t\t\tObject.values(bundle).flatMap((output) =>\n\t\t\t\t\toutput.type === \"chunk\" ? [{ fileName: output.fileName, code: output.code }] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function vettaPluginFederation(options: VettaPluginFederationOptions): PluginOption[] {\n\tconst packageOptions = typeof options.package === \"object\" ? options.package : {};\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\tconst devServer = isVettaPluginDevServer();\n\tconst plugins: PluginOption[] = [\n\t\tcreatePluginBuildWarningFilter(),\n\t\tcreateHostThemeBridgePlugin(),\n\t\t...(devServer ? createVettaPluginDevPlugins(entry) : []),\n\t\tcreateBuildDefaultsPlugin(entry),\n\t\tcreateSharedReactCommonJsBridgePlugin(),\n\t\t...federation({\n\t\t\t...createVettaPluginFederationConfig(options),\n\t\t\texposes: {\n\t\t\t\t[options.expose ?? \"./plugin\"]: devServer ? VETTA_PLUGIN_DEV_ENTRY_ID : entry,\n\t\t\t},\n\t\t}),\n\t\tcreatePluginStyleScopePlugin(),\n\t\tcreatePermissionContractPlugin(),\n\t];\n\t// 兼容旧宿主的 build-watch 流程:增量构建时不重复打 zip。\n\tif (options.package !== false && process.env.VETTA_PLUGIN_DEV_WATCH !== \"1\") {\n\t\tplugins.push(createPackagePlugin(packageOptions));\n\t}\n\treturn plugins;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,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AAO,KAAK,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,GAAG,EAAE,CAAC;QAC7E,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,OAAO,CAAC;AAAA,CACf","sourcesContent":["import { federation, type ModuleFederationOptions } from \"@module-federation/vite\";\nimport { readFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, PluginOption } from \"vite\";\nimport {\n\tcreateVettaPluginDevPlugins,\n\tisVettaPluginDevServer,\n\tVETTA_PLUGIN_DEV_ENTRY_ID,\n} from \"./dev-vite-plugins.js\";\nimport { createPluginBuildWarningFilter } from \"./build-warning-filter.js\";\nimport { createHostThemeBridgePlugin } from \"./host-theme.js\";\nimport { type CreateVettaPluginPackageOptions, createVettaPluginPackage } from \"./pack.js\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\nimport { createPluginStyleScopePlugin } from \"./style-scope.js\";\nimport { createPluginLoggerBindingPlugin } from \"./plugin-logger.js\";\n\nconst SHARED_REACT_COMMONJS_BRIDGE_ID = \"virtual:vetta-plugin-shared-react-commonjs\";\nconst RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID = `\\0${SHARED_REACT_COMMONJS_BRIDGE_ID}`;\nconst STATIC_REACT_REQUIRE_PATTERN = /\\brequire\\s*\\(\\s*([\"'])react\\1\\s*\\)/gu;\n\nexport interface VettaPluginPackageOptions extends Omit<CreateVettaPluginPackageOptions, \"rootDir\" | \"distDir\"> {\n\tenabled?: boolean;\n}\n\nexport interface VettaPluginFederationOptions {\n\tname: string;\n\texpose?: string;\n\tentry?: string;\n\tmanifestFileName?: string;\n\tremoteEntryFileName?: string;\n\t/** Share the host design-system primitives exposed by `@vetta-org/ui`. */\n\thostUi?: boolean;\n\t/** Share the narrow host UI contract exposed by `@vetta-org/theme-ui/plugin-ui`. */\n\thostThemeUi?: boolean;\n\tshared?: ModuleFederationOptions[\"shared\"];\n\tpackage?: boolean | VettaPluginPackageOptions;\n}\n\nexport function createVettaPluginFederationConfig(options: VettaPluginFederationOptions): ModuleFederationOptions {\n\tconst expose = options.expose ?? \"./plugin\";\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\treturn {\n\t\tname: options.name,\n\t\tfilename: options.remoteEntryFileName ?? \"remoteEntry.js\",\n\t\texposes: {\n\t\t\t[expose]: entry,\n\t\t},\n\t\tmanifest: {\n\t\t\tfileName: options.manifestFileName ?? \"mf-manifest.json\",\n\t\t},\n\t\tdts: false,\n\t\tshared: {\n\t\t\t\"@vetta-org/plugin-sdk\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\treact: {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t\"react-dom\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t// Match host plugin-shared-modules (tldraw remotes may require this subpath).\n\t\t\t\"react-dom/client\": {\n\t\t\t\tsingleton: true,\n\t\t\t\timport: false,\n\t\t\t\trequiredVersion: \"*\",\n\t\t\t},\n\t\t\t...(options.hostUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host design-system primitives; runtime provided by desktop-app share scope.\n\t\t\t\t\t\t\"@vetta-org/ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...(options.hostThemeUi\n\t\t\t\t? {\n\t\t\t\t\t\t// Host-built UI components (model selector, …); opt in to keep unrelated plugins decoupled.\n\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\": {\n\t\t\t\t\t\t\tsingleton: true,\n\t\t\t\t\t\t\timport: false,\n\t\t\t\t\t\t\trequiredVersion: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...options.shared,\n\t\t},\n\t};\n}\n\nfunction createBuildDefaultsPlugin(entry: string, options: Pick<VettaPluginFederationOptions, \"hostUi\">): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-build-defaults\",\n\t\tapply: \"build\",\n\t\tconfig() {\n\t\t\treturn {\n\t\t\t\t// Plugin remotes run inside the host page. Absolute asset URLs like\n\t\t\t\t// `/icon.png` resolve against the host origin (desktop-app public/), not\n\t\t\t\t// the remote. Prefer inlining small assets; large ones still go under\n\t\t\t\t// assets/ and rely on MF publicPath, but never land on host public/.\n\t\t\t\tbuild: {\n\t\t\t\t\tassetsInlineLimit: 32 * 1024,\n\t\t\t\t\trollupOptions: {\n\t\t\t\t\t\tinput: entry,\n\t\t\t\t\t\t// Host-provided singletons (see desktop-app plugin-shared-modules + vetta-host protocol).\n\t\t\t\t\t\texternal: [\n\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\",\n\t\t\t\t\t\t\t...(options.hostUi\n\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\"@vetta-org/ui\",\n\t\t\t\t\t\t\t\t\t\t// 旧源码名仍映射到宿主;已构建的旧 remote 则由 Desktop share scope 兼容。\n\t\t\t\t\t\t\t\t\t\t\"@vetta/ui\",\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t: []),\n\t\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\",\n\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\",\n\t\t\t\t\t\t],\n\t\t\t\t\t\toutput: {\n\t\t\t\t\t\t\tassetFileNames(assetInfo) {\n\t\t\t\t\t\t\t\treturn assetInfo.names.some((name) => name.endsWith(\".css\"))\n\t\t\t\t\t\t\t\t\t? \"style.css\"\n\t\t\t\t\t\t\t\t\t: \"assets/[name]-[hash][extname]\";\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tpaths: {\n\t\t\t\t\t\t\t\t\"@vetta-org/plugin-sdk\": \"vetta-host://plugin-sdk\",\n\t\t\t\t\t\t\t\t\"@vetta-org/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta/ui\": \"vetta-host://ui\",\n\t\t\t\t\t\t\t\t\"@vetta-org/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t\t\"@vetta/theme-ui/plugin-ui\": \"vetta-host://theme-ui-plugin\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n// Module Federation exposes shared React through a virtual ESM module. Routing\n// static CommonJS requires through this namespace keeps Rollup's generated\n// bindings stable when dependencies such as use-sync-external-store are bundled.\nfunction createSharedReactCommonJsBridgePlugin(): Plugin {\n\treturn {\n\t\tname: \"vetta-plugin-shared-react-commonjs-bridge\",\n\t\tapply: \"build\",\n\t\tenforce: \"pre\",\n\t\ttransform(code) {\n\t\t\tif (!code.includes(\"require\") || !code.includes(\"react\")) return;\n\t\t\tconst transformed = code.replace(\n\t\t\t\tSTATIC_REACT_REQUIRE_PATTERN,\n\t\t\t\t`require(${JSON.stringify(SHARED_REACT_COMMONJS_BRIDGE_ID)})`,\n\t\t\t);\n\t\t\tif (transformed === code) return;\n\t\t\treturn { code: transformed, map: null };\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === SHARED_REACT_COMMONJS_BRIDGE_ID) return RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID;\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_SHARED_REACT_COMMONJS_BRIDGE_ID) return;\n\t\t\treturn `import * as React from \"react\";\nexport * from \"react\";\nexport default React;\n`;\n\t\t},\n\t};\n}\n\nfunction createPackagePlugin(options: VettaPluginPackageOptions): Plugin {\n\tlet rootDir = \"\";\n\tlet distDir = \"\";\n\tlet buildFailed = false;\n\n\treturn {\n\t\tname: \"vetta-plugin-package\",\n\t\tapply: \"build\",\n\t\tbuildStart() {\n\t\t\tbuildFailed = false;\n\t\t},\n\t\tbuildEnd(error) {\n\t\t\tbuildFailed = error !== undefined;\n\t\t},\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t\tdistDir = config.build.outDir;\n\t\t},\n\t\tasync closeBundle() {\n\t\t\tif (options.enabled === false || buildFailed) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst result = await createVettaPluginPackage({\n\t\t\t\t...options,\n\t\t\t\trootDir,\n\t\t\t\tdistDir,\n\t\t\t});\n\t\t\tconsole.log(`[vetta-plugin-vite] Wrote ${result.outputPath} with ${result.files.length} runtime files`);\n\t\t},\n\t};\n}\n\nfunction createPermissionContractPlugin(): Plugin {\n\tlet rootDir = \"\";\n\treturn {\n\t\tname: \"vetta-plugin-permission-contract\",\n\t\tapply: \"build\",\n\t\tconfigResolved(config) {\n\t\t\trootDir = config.root;\n\t\t},\n\t\tasync generateBundle(_outputOptions, bundle) {\n\t\t\tconst manifest = parsePluginManifest(\n\t\t\t\tJSON.parse(await readFile(resolve(rootDir, \"plugin.json\"), \"utf8\")) as unknown,\n\t\t\t);\n\t\t\tassertPluginPermissionContract(\n\t\t\t\tmanifest,\n\t\t\t\tObject.values(bundle).flatMap((output) =>\n\t\t\t\t\toutput.type === \"chunk\" ? [{ fileName: output.fileName, code: output.code }] : [],\n\t\t\t\t),\n\t\t\t);\n\t\t},\n\t};\n}\n\nexport function vettaPluginFederation(options: VettaPluginFederationOptions): PluginOption[] {\n\tconst packageOptions = typeof options.package === \"object\" ? options.package : {};\n\tconst entry = options.entry ?? \"./src/index.tsx\";\n\tconst devServer = isVettaPluginDevServer();\n\tconst plugins: PluginOption[] = [\n\t\tcreatePluginBuildWarningFilter(),\n\t\tcreateHostThemeBridgePlugin(),\n\t\tcreatePluginLoggerBindingPlugin(),\n\t\t...(devServer ? createVettaPluginDevPlugins(entry) : []),\n\t\tcreateBuildDefaultsPlugin(entry, options),\n\t\tcreateSharedReactCommonJsBridgePlugin(),\n\t\t...federation({\n\t\t\t...createVettaPluginFederationConfig(options),\n\t\t\texposes: {\n\t\t\t\t[options.expose ?? \"./plugin\"]: devServer ? VETTA_PLUGIN_DEV_ENTRY_ID : entry,\n\t\t\t},\n\t\t}),\n\t\tcreatePluginStyleScopePlugin(),\n\t\tcreatePermissionContractPlugin(),\n\t];\n\t// 兼容旧宿主的 build-watch 流程:增量构建时不重复打 zip。\n\tif (options.package !== false && process.env.VETTA_PLUGIN_DEV_WATCH !== \"1\") {\n\t\tplugins.push(createPackagePlugin(packageOptions));\n\t}\n\treturn plugins;\n}\n"]}
|
package/dist/pack.d.ts
CHANGED
|
@@ -12,9 +12,10 @@ export interface CreateVettaPluginPackageOptions {
|
|
|
12
12
|
manifestPath?: string;
|
|
13
13
|
releaseDir?: string;
|
|
14
14
|
distDir?: string;
|
|
15
|
-
/** Also write the stable npm distribution artifact `release/vetta-plugin.
|
|
15
|
+
/** Also write the stable npm distribution artifact `release/vetta-plugin.vettapkg`. */
|
|
16
16
|
npmArchive?: boolean;
|
|
17
17
|
}
|
|
18
|
-
export declare const
|
|
18
|
+
export declare const VETTA_PLUGIN_PACKAGE_EXTENSION = ".vettapkg";
|
|
19
|
+
export declare const VETTA_NPM_PLUGIN_ARCHIVE_PATH = "release/vetta-plugin.vettapkg";
|
|
19
20
|
export declare function createVettaPluginPackage(options?: CreateVettaPluginPackageOptions): Promise<VettaPluginPackageResult>;
|
|
20
21
|
//# sourceMappingURL=pack.d.ts.map
|
package/dist/pack.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,sBAAsB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,+BAA+B;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kFAAkF;IAClF,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,6BAA6B,6BAA6B,CAAC;AAqSxE,wBAAsB,wBAAwB,CAC7C,OAAO,GAAE,+BAAoC,GAC3C,OAAO,CAAC,wBAAwB,CAAC,CAgDnC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, join, relative, resolve, sep } from \"node:path\";\nimport { listPluginManifestResources, parsePluginManifest, type PluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport { parseVettaNpmPluginPackage } from \"@vetta-org/plugin-sdk/npm-package\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\n\nexport interface VettaPluginPackageFile {\n\tfullPath: string;\n\tarchivePath: string;\n}\n\nexport interface VettaPluginPackageResult {\n\toutputPath: string;\n\tnpmOutputPath?: string;\n\tfiles: VettaPluginPackageFile[];\n}\n\nexport interface CreateVettaPluginPackageOptions {\n\trootDir?: string;\n\tmanifestPath?: string;\n\treleaseDir?: string;\n\tdistDir?: string;\n\t/** Also write the stable npm distribution artifact `release/vetta-plugin.zip`. */\n\tnpmArchive?: boolean;\n}\n\nexport const VETTA_NPM_PLUGIN_ARCHIVE_PATH = \"release/vetta-plugin.zip\";\n\nconst crcTable = new Uint32Array(256);\nfor (let i = 0; i < 256; i += 1) {\n\tlet value = i;\n\tfor (let bit = 0; bit < 8; bit += 1) {\n\t\tvalue = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;\n\t}\n\tcrcTable[i] = value >>> 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readString(record: Record<string, unknown>, key: string): string | undefined {\n\tconst value = record[key];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction validateAbilityDescriptor(value: unknown, pluginManifest: PluginManifest): void {\n\tif (!isRecord(value)) throw new Error(\"ability.json must contain an object.\");\n\tif (\n\t\tvalue.schemaVersion !== 1 ||\n\t\tvalue.type !== \"plugin\" ||\n\t\tvalue.slug !== pluginManifest.id ||\n\t\tvalue.version !== pluginManifest.version\n\t) {\n\t\tthrow new Error(\"ability.json identity must match plugin.json id and version.\");\n\t}\n}\n\nfunction parseJsonObject(buffer: Buffer, fileName: string): Record<string, unknown> {\n\tconst parsed = JSON.parse(buffer.toString(\"utf-8\")) as unknown;\n\tif (!isRecord(parsed)) {\n\t\tthrow new Error(`${fileName} must contain an object.`);\n\t}\n\treturn parsed;\n}\n\nfunction crc32(buffer: Buffer): number {\n\tlet value = 0xffffffff;\n\tfor (const byte of buffer) {\n\t\tvalue = crcTable[(value ^ byte) & 0xff] ^ (value >>> 8);\n\t}\n\treturn (value ^ 0xffffffff) >>> 0;\n}\n\nfunction writeUInt16(value: number): Buffer {\n\tconst buffer = Buffer.allocUnsafe(2);\n\tbuffer.writeUInt16LE(value, 0);\n\treturn buffer;\n}\n\nfunction writeUInt32(value: number): Buffer {\n\tconst buffer = Buffer.allocUnsafe(4);\n\tbuffer.writeUInt32LE(value >>> 0, 0);\n\treturn buffer;\n}\n\nfunction archivePathFromRoot(rootDir: string, fullPath: string): string {\n\tconst archivePath = relative(rootDir, fullPath).replace(/\\\\/g, \"/\");\n\tif (!archivePath || archivePath.startsWith(\"..\") || archivePath.includes(`${sep}..${sep}`)) {\n\t\tthrow new Error(`File is outside plugin root: ${fullPath}`);\n\t}\n\treturn archivePath;\n}\n\nasync function collectFiles(dir: string): Promise<VettaPluginPackageFile[]> {\n\tconst entries = await readdir(dir, { withFileTypes: true });\n\tconst files: VettaPluginPackageFile[] = [];\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry.name);\n\t\tif (entry.isDirectory()) {\n\t\t\tfiles.push(...(await collectFiles(fullPath)));\n\t\t} else if (entry.isFile()) {\n\t\t\tfiles.push({ fullPath, archivePath: \"\" });\n\t\t}\n\t}\n\treturn files;\n}\n\nasync function collectPath(path: string): Promise<VettaPluginPackageFile[]> {\n\tconst info = await stat(path);\n\tif (info.isDirectory()) {\n\t\treturn collectFiles(path);\n\t}\n\tif (info.isFile()) {\n\t\treturn [{ fullPath: path, archivePath: \"\" }];\n\t}\n\treturn [];\n}\n\nasync function createZip(files: VettaPluginPackageFile[]): Promise<Buffer> {\n\tconst localParts: Buffer[] = [];\n\tconst centralParts: Buffer[] = [];\n\tlet offset = 0;\n\n\tfor (const file of files) {\n\t\tconst data = await readFile(file.fullPath);\n\t\tconst name = Buffer.from(file.archivePath.replace(/\\\\/g, \"/\"));\n\t\tconst checksum = crc32(data);\n\t\tconst localHeader = Buffer.concat([\n\t\t\twriteUInt32(0x04034b50),\n\t\t\twriteUInt16(20),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt32(checksum),\n\t\t\twriteUInt32(data.length),\n\t\t\twriteUInt32(data.length),\n\t\t\twriteUInt16(name.length),\n\t\t\twriteUInt16(0),\n\t\t\tname,\n\t\t]);\n\t\tlocalParts.push(localHeader, data);\n\n\t\tcentralParts.push(\n\t\t\tBuffer.concat([\n\t\t\t\twriteUInt32(0x02014b50),\n\t\t\t\twriteUInt16(20),\n\t\t\t\twriteUInt16(20),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt32(checksum),\n\t\t\t\twriteUInt32(data.length),\n\t\t\t\twriteUInt32(data.length),\n\t\t\t\twriteUInt16(name.length),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt32(0),\n\t\t\t\twriteUInt32(offset),\n\t\t\t\tname,\n\t\t\t]),\n\t\t);\n\t\toffset += localHeader.length + data.length;\n\t}\n\n\tconst centralDirectory = Buffer.concat(centralParts);\n\tconst endOfCentralDirectory = Buffer.concat([\n\t\twriteUInt32(0x06054b50),\n\t\twriteUInt16(0),\n\t\twriteUInt16(0),\n\t\twriteUInt16(files.length),\n\t\twriteUInt16(files.length),\n\t\twriteUInt32(centralDirectory.length),\n\t\twriteUInt32(offset),\n\t\twriteUInt16(0),\n\t]);\n\n\treturn Buffer.concat([...localParts, centralDirectory, endOfCentralDirectory]);\n}\n\nfunction readManifestRemoteEntry(manifest: Record<string, unknown>): string | undefined {\n\tconst metaData = manifest.metaData;\n\tif (!isRecord(metaData)) {\n\t\treturn undefined;\n\t}\n\tconst remoteEntry = metaData.remoteEntry;\n\tif (!isRecord(remoteEntry)) {\n\t\treturn undefined;\n\t}\n\tconst name = readString(remoteEntry, \"name\");\n\tif (!name) {\n\t\treturn undefined;\n\t}\n\tconst path = readString(remoteEntry, \"path\") ?? \"\";\n\treturn path ? `${path.replace(/\\/$/, \"\")}/${name}` : name;\n}\n\nasync function collectRuntimeFiles(\n\trootDir: string,\n\tmanifestPath: string,\n\tdistDir: string,\n): Promise<VettaPluginPackageFile[]> {\n\tconst pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));\n\tconst packageFiles = new Map<string, VettaPluginPackageFile>();\n\tconst addFile = (fullPath: string) => {\n\t\tconst resolved = resolve(fullPath);\n\t\tconst archivePath = archivePathFromRoot(rootDir, resolved);\n\t\tpackageFiles.set(archivePath, { fullPath: resolved, archivePath });\n\t};\n\n\taddFile(manifestPath);\n\n\t// 插件详情跟随插件包发布;ability.json 缺省兼容,存在时必须与 plugin.json 身份一致。\n\tconst abilityDescriptorPath = resolve(rootDir, \"ability.json\");\n\tif (existsSync(abilityDescriptorPath)) {\n\t\tvalidateAbilityDescriptor(\n\t\t\tparseJsonObject(await readFile(abilityDescriptorPath), basename(abilityDescriptorPath)),\n\t\t\tpluginManifest,\n\t\t);\n\t\taddFile(abilityDescriptorPath);\n\t\t// 约定的展示资源目录;内联 blocks 可引用其中的图片,随包整体带上。\n\t\ttry {\n\t\t\tfor (const file of await collectFiles(resolve(rootDir, \"presentation\"))) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t} catch {\n\t\t\t// optional presentation/ directory\n\t\t}\n\t}\n\n\tconst runtimeEntryPath = resolve(rootDir, pluginManifest.entry);\n\taddFile(runtimeEntryPath);\n\n\tconst federationManifest = parseJsonObject(await readFile(runtimeEntryPath), basename(runtimeEntryPath));\n\tconst remoteEntry = readManifestRemoteEntry(federationManifest);\n\tif (remoteEntry) {\n\t\taddFile(resolve(dirname(runtimeEntryPath), remoteEntry));\n\t}\n\n\tconst assetsDir = join(distDir, \"assets\");\n\tfor (const file of await collectFiles(assetsDir)) {\n\t\taddFile(file.fullPath);\n\t}\n\n\t// Vite cssCodeSplit emits extra files like dist/style2.css for async chunks;\n\t// include all dist-root CSS so preload-helper can fetch them (not only styles[]).\n\ttry {\n\t\tfor (const file of await collectFiles(distDir)) {\n\t\t\tconst rel = relative(distDir, file.fullPath).replace(/\\\\/g, \"/\");\n\t\t\tif (rel.endsWith(\".css\") && !rel.includes(\"/\")) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// dist missing\n\t}\n\n\tfor (const resource of listPluginManifestResources(pluginManifest)) {\n\t\tif (resource.field === \"entry\") continue;\n\t\tconst resourcePath = resolve(rootDir, resource.path);\n\t\tif (resource.kind === \"file\") {\n\t\t\tif (!existsSync(resourcePath)) {\n\t\t\t\tthrow new Error(`plugin.json resource not found: ${resource.field} (${resource.path})`);\n\t\t\t}\n\t\t\taddFile(resourcePath);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const file of await collectPath(resourcePath)) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t}\n\n\t// Plugin-scoped MCP: include config file and conventional companion dirs when declared.\n\tconst mcpServers = pluginManifest.agent?.mcpServers;\n\tif (mcpServers !== undefined) {\n\t\ttry {\n\t\t\tfor (const file of await collectFiles(resolve(rootDir, \"mcp\"))) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t} catch {\n\t\t\t// optional mcp/ directory\n\t\t}\n\t}\n\n\t// Helper scripts (plugin workbench etc.): always pack scripts/ when present.\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"scripts\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// optional scripts/ directory\n\t}\n\n\t// Handbook / agent docs beside skills (not always listed in skillPaths).\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"agent/docs\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// optional agent/docs\n\t}\n\n\t// Plugin i18n catalogs (ADR-0033): bundle locales/<lang>.json so the host can\n\t// load them alongside the manifest. Optional — absent for single-language plugins.\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"locales\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// no locales/ directory — nothing to bundle\n\t}\n\n\treturn [...packageFiles.values()].sort((a, b) => a.archivePath.localeCompare(b.archivePath));\n}\n\nexport async function createVettaPluginPackage(\n\toptions: CreateVettaPluginPackageOptions = {},\n): Promise<VettaPluginPackageResult> {\n\tconst rootDir = resolve(options.rootDir ?? process.cwd());\n\tconst manifestPath = resolve(rootDir, options.manifestPath ?? \"plugin.json\");\n\tconst releaseDir = resolve(rootDir, options.releaseDir ?? \"release\");\n\tconst distDir = resolve(rootDir, options.distDir ?? \"dist\");\n\tconst pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));\n\tconst outputPath = join(releaseDir, `${pluginManifest.id}-${pluginManifest.version}.zip`);\n\tconst files = await collectRuntimeFiles(rootDir, manifestPath, distDir);\n\tassertPluginPermissionContract(\n\t\tpluginManifest,\n\t\tawait Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter((file) => /\\.(?:c|m)?js$/u.test(file.archivePath))\n\t\t\t\t.map(async (file) => ({ fileName: file.archivePath, code: await readFile(file.fullPath, \"utf8\") })),\n\t\t),\n\t);\n\tlet npmOutputPath: string | undefined;\n\tif (options.npmArchive === true) {\n\t\tconst packageManifest = parseVettaNpmPluginPackage(\n\t\t\tparseJsonObject(await readFile(resolve(rootDir, \"package.json\")), \"package.json\"),\n\t\t);\n\t\tif (packageManifest.version !== pluginManifest.version) {\n\t\t\tthrow new Error(\n\t\t\t\t`npm package version ${packageManifest.version} must match plugin version ${pluginManifest.version}.`,\n\t\t\t);\n\t\t}\n\t\tif (packageManifest.vetta.pluginId !== pluginManifest.id) {\n\t\t\tthrow new Error(\n\t\t\t\t`npm package plugin id ${packageManifest.vetta.pluginId} must match plugin id ${pluginManifest.id}.`,\n\t\t\t);\n\t\t}\n\t\tif (packageManifest.vetta.archive !== VETTA_NPM_PLUGIN_ARCHIVE_PATH) {\n\t\t\tthrow new Error(`npm package archive must be ${VETTA_NPM_PLUGIN_ARCHIVE_PATH}.`);\n\t\t}\n\t\tnpmOutputPath = resolve(rootDir, VETTA_NPM_PLUGIN_ARCHIVE_PATH);\n\t}\n\n\tawait mkdir(releaseDir, { recursive: true });\n\tawait rm(outputPath, { force: true });\n\tconst archive = await createZip(files);\n\tawait writeFile(outputPath, archive);\n\tif (npmOutputPath && npmOutputPath !== outputPath) {\n\t\tawait mkdir(dirname(npmOutputPath), { recursive: true });\n\t\tawait rm(npmOutputPath, { force: true });\n\t\tawait writeFile(npmOutputPath, archive);\n\t}\n\n\treturn { outputPath, npmOutputPath, files };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,sBAAsB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,wBAAwB;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,sBAAsB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,+BAA+B;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,8BAA8B,cAAc,CAAC;AAC1D,eAAO,MAAM,6BAA6B,kCAA0D,CAAC;AAqSrG,wBAAsB,wBAAwB,CAC7C,OAAO,GAAE,+BAAoC,GAC3C,OAAO,CAAC,wBAAwB,CAAC,CAmDnC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, join, relative, resolve, sep } from \"node:path\";\nimport { listPluginManifestResources, parsePluginManifest, type PluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport { parseVettaNpmPluginPackage } from \"@vetta-org/plugin-sdk/npm-package\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\n\nexport interface VettaPluginPackageFile {\n\tfullPath: string;\n\tarchivePath: string;\n}\n\nexport interface VettaPluginPackageResult {\n\toutputPath: string;\n\tnpmOutputPath?: string;\n\tfiles: VettaPluginPackageFile[];\n}\n\nexport interface CreateVettaPluginPackageOptions {\n\trootDir?: string;\n\tmanifestPath?: string;\n\treleaseDir?: string;\n\tdistDir?: string;\n\t/** Also write the stable npm distribution artifact `release/vetta-plugin.vettapkg`. */\n\tnpmArchive?: boolean;\n}\n\nexport const VETTA_PLUGIN_PACKAGE_EXTENSION = \".vettapkg\";\nexport const VETTA_NPM_PLUGIN_ARCHIVE_PATH = `release/vetta-plugin${VETTA_PLUGIN_PACKAGE_EXTENSION}`;\n\nconst crcTable = new Uint32Array(256);\nfor (let i = 0; i < 256; i += 1) {\n\tlet value = i;\n\tfor (let bit = 0; bit < 8; bit += 1) {\n\t\tvalue = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;\n\t}\n\tcrcTable[i] = value >>> 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readString(record: Record<string, unknown>, key: string): string | undefined {\n\tconst value = record[key];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction validateAbilityDescriptor(value: unknown, pluginManifest: PluginManifest): void {\n\tif (!isRecord(value)) throw new Error(\"ability.json must contain an object.\");\n\tif (\n\t\tvalue.schemaVersion !== 1 ||\n\t\tvalue.type !== \"plugin\" ||\n\t\tvalue.slug !== pluginManifest.id ||\n\t\tvalue.version !== pluginManifest.version\n\t) {\n\t\tthrow new Error(\"ability.json identity must match plugin.json id and version.\");\n\t}\n}\n\nfunction parseJsonObject(buffer: Buffer, fileName: string): Record<string, unknown> {\n\tconst parsed = JSON.parse(buffer.toString(\"utf-8\")) as unknown;\n\tif (!isRecord(parsed)) {\n\t\tthrow new Error(`${fileName} must contain an object.`);\n\t}\n\treturn parsed;\n}\n\nfunction crc32(buffer: Buffer): number {\n\tlet value = 0xffffffff;\n\tfor (const byte of buffer) {\n\t\tvalue = crcTable[(value ^ byte) & 0xff] ^ (value >>> 8);\n\t}\n\treturn (value ^ 0xffffffff) >>> 0;\n}\n\nfunction writeUInt16(value: number): Buffer {\n\tconst buffer = Buffer.allocUnsafe(2);\n\tbuffer.writeUInt16LE(value, 0);\n\treturn buffer;\n}\n\nfunction writeUInt32(value: number): Buffer {\n\tconst buffer = Buffer.allocUnsafe(4);\n\tbuffer.writeUInt32LE(value >>> 0, 0);\n\treturn buffer;\n}\n\nfunction archivePathFromRoot(rootDir: string, fullPath: string): string {\n\tconst archivePath = relative(rootDir, fullPath).replace(/\\\\/g, \"/\");\n\tif (!archivePath || archivePath.startsWith(\"..\") || archivePath.includes(`${sep}..${sep}`)) {\n\t\tthrow new Error(`File is outside plugin root: ${fullPath}`);\n\t}\n\treturn archivePath;\n}\n\nasync function collectFiles(dir: string): Promise<VettaPluginPackageFile[]> {\n\tconst entries = await readdir(dir, { withFileTypes: true });\n\tconst files: VettaPluginPackageFile[] = [];\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry.name);\n\t\tif (entry.isDirectory()) {\n\t\t\tfiles.push(...(await collectFiles(fullPath)));\n\t\t} else if (entry.isFile()) {\n\t\t\tfiles.push({ fullPath, archivePath: \"\" });\n\t\t}\n\t}\n\treturn files;\n}\n\nasync function collectPath(path: string): Promise<VettaPluginPackageFile[]> {\n\tconst info = await stat(path);\n\tif (info.isDirectory()) {\n\t\treturn collectFiles(path);\n\t}\n\tif (info.isFile()) {\n\t\treturn [{ fullPath: path, archivePath: \"\" }];\n\t}\n\treturn [];\n}\n\nasync function createZip(files: VettaPluginPackageFile[]): Promise<Buffer> {\n\tconst localParts: Buffer[] = [];\n\tconst centralParts: Buffer[] = [];\n\tlet offset = 0;\n\n\tfor (const file of files) {\n\t\tconst data = await readFile(file.fullPath);\n\t\tconst name = Buffer.from(file.archivePath.replace(/\\\\/g, \"/\"));\n\t\tconst checksum = crc32(data);\n\t\tconst localHeader = Buffer.concat([\n\t\t\twriteUInt32(0x04034b50),\n\t\t\twriteUInt16(20),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt32(checksum),\n\t\t\twriteUInt32(data.length),\n\t\t\twriteUInt32(data.length),\n\t\t\twriteUInt16(name.length),\n\t\t\twriteUInt16(0),\n\t\t\tname,\n\t\t]);\n\t\tlocalParts.push(localHeader, data);\n\n\t\tcentralParts.push(\n\t\t\tBuffer.concat([\n\t\t\t\twriteUInt32(0x02014b50),\n\t\t\t\twriteUInt16(20),\n\t\t\t\twriteUInt16(20),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt32(checksum),\n\t\t\t\twriteUInt32(data.length),\n\t\t\t\twriteUInt32(data.length),\n\t\t\t\twriteUInt16(name.length),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt32(0),\n\t\t\t\twriteUInt32(offset),\n\t\t\t\tname,\n\t\t\t]),\n\t\t);\n\t\toffset += localHeader.length + data.length;\n\t}\n\n\tconst centralDirectory = Buffer.concat(centralParts);\n\tconst endOfCentralDirectory = Buffer.concat([\n\t\twriteUInt32(0x06054b50),\n\t\twriteUInt16(0),\n\t\twriteUInt16(0),\n\t\twriteUInt16(files.length),\n\t\twriteUInt16(files.length),\n\t\twriteUInt32(centralDirectory.length),\n\t\twriteUInt32(offset),\n\t\twriteUInt16(0),\n\t]);\n\n\treturn Buffer.concat([...localParts, centralDirectory, endOfCentralDirectory]);\n}\n\nfunction readManifestRemoteEntry(manifest: Record<string, unknown>): string | undefined {\n\tconst metaData = manifest.metaData;\n\tif (!isRecord(metaData)) {\n\t\treturn undefined;\n\t}\n\tconst remoteEntry = metaData.remoteEntry;\n\tif (!isRecord(remoteEntry)) {\n\t\treturn undefined;\n\t}\n\tconst name = readString(remoteEntry, \"name\");\n\tif (!name) {\n\t\treturn undefined;\n\t}\n\tconst path = readString(remoteEntry, \"path\") ?? \"\";\n\treturn path ? `${path.replace(/\\/$/, \"\")}/${name}` : name;\n}\n\nasync function collectRuntimeFiles(\n\trootDir: string,\n\tmanifestPath: string,\n\tdistDir: string,\n): Promise<VettaPluginPackageFile[]> {\n\tconst pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));\n\tconst packageFiles = new Map<string, VettaPluginPackageFile>();\n\tconst addFile = (fullPath: string) => {\n\t\tconst resolved = resolve(fullPath);\n\t\tconst archivePath = archivePathFromRoot(rootDir, resolved);\n\t\tpackageFiles.set(archivePath, { fullPath: resolved, archivePath });\n\t};\n\n\taddFile(manifestPath);\n\n\t// 插件详情跟随插件包发布;ability.json 缺省兼容,存在时必须与 plugin.json 身份一致。\n\tconst abilityDescriptorPath = resolve(rootDir, \"ability.json\");\n\tif (existsSync(abilityDescriptorPath)) {\n\t\tvalidateAbilityDescriptor(\n\t\t\tparseJsonObject(await readFile(abilityDescriptorPath), basename(abilityDescriptorPath)),\n\t\t\tpluginManifest,\n\t\t);\n\t\taddFile(abilityDescriptorPath);\n\t\t// 约定的展示资源目录;内联 blocks 可引用其中的图片,随包整体带上。\n\t\ttry {\n\t\t\tfor (const file of await collectFiles(resolve(rootDir, \"presentation\"))) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t} catch {\n\t\t\t// optional presentation/ directory\n\t\t}\n\t}\n\n\tconst runtimeEntryPath = resolve(rootDir, pluginManifest.entry);\n\taddFile(runtimeEntryPath);\n\n\tconst federationManifest = parseJsonObject(await readFile(runtimeEntryPath), basename(runtimeEntryPath));\n\tconst remoteEntry = readManifestRemoteEntry(federationManifest);\n\tif (remoteEntry) {\n\t\taddFile(resolve(dirname(runtimeEntryPath), remoteEntry));\n\t}\n\n\tconst assetsDir = join(distDir, \"assets\");\n\tfor (const file of await collectFiles(assetsDir)) {\n\t\taddFile(file.fullPath);\n\t}\n\n\t// Vite cssCodeSplit emits extra files like dist/style2.css for async chunks;\n\t// include all dist-root CSS so preload-helper can fetch them (not only styles[]).\n\ttry {\n\t\tfor (const file of await collectFiles(distDir)) {\n\t\t\tconst rel = relative(distDir, file.fullPath).replace(/\\\\/g, \"/\");\n\t\t\tif (rel.endsWith(\".css\") && !rel.includes(\"/\")) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// dist missing\n\t}\n\n\tfor (const resource of listPluginManifestResources(pluginManifest)) {\n\t\tif (resource.field === \"entry\") continue;\n\t\tconst resourcePath = resolve(rootDir, resource.path);\n\t\tif (resource.kind === \"file\") {\n\t\t\tif (!existsSync(resourcePath)) {\n\t\t\t\tthrow new Error(`plugin.json resource not found: ${resource.field} (${resource.path})`);\n\t\t\t}\n\t\t\taddFile(resourcePath);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const file of await collectPath(resourcePath)) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t}\n\n\t// Plugin-scoped MCP: include config file and conventional companion dirs when declared.\n\tconst mcpServers = pluginManifest.agent?.mcpServers;\n\tif (mcpServers !== undefined) {\n\t\ttry {\n\t\t\tfor (const file of await collectFiles(resolve(rootDir, \"mcp\"))) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t} catch {\n\t\t\t// optional mcp/ directory\n\t\t}\n\t}\n\n\t// Helper scripts (plugin workbench etc.): always pack scripts/ when present.\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"scripts\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// optional scripts/ directory\n\t}\n\n\t// Handbook / agent docs beside skills (not always listed in skillPaths).\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"agent/docs\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// optional agent/docs\n\t}\n\n\t// Plugin i18n catalogs (ADR-0033): bundle locales/<lang>.json so the host can\n\t// load them alongside the manifest. Optional — absent for single-language plugins.\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"locales\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// no locales/ directory — nothing to bundle\n\t}\n\n\treturn [...packageFiles.values()].sort((a, b) => a.archivePath.localeCompare(b.archivePath));\n}\n\nexport async function createVettaPluginPackage(\n\toptions: CreateVettaPluginPackageOptions = {},\n): Promise<VettaPluginPackageResult> {\n\tconst rootDir = resolve(options.rootDir ?? process.cwd());\n\tconst manifestPath = resolve(rootDir, options.manifestPath ?? \"plugin.json\");\n\tconst releaseDir = resolve(rootDir, options.releaseDir ?? \"release\");\n\tconst distDir = resolve(rootDir, options.distDir ?? \"dist\");\n\tconst pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));\n\tconst outputPath = join(\n\t\treleaseDir,\n\t\t`${pluginManifest.id}-${pluginManifest.version}${VETTA_PLUGIN_PACKAGE_EXTENSION}`,\n\t);\n\tconst files = await collectRuntimeFiles(rootDir, manifestPath, distDir);\n\tassertPluginPermissionContract(\n\t\tpluginManifest,\n\t\tawait Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter((file) => /\\.(?:c|m)?js$/u.test(file.archivePath))\n\t\t\t\t.map(async (file) => ({ fileName: file.archivePath, code: await readFile(file.fullPath, \"utf8\") })),\n\t\t),\n\t);\n\tlet npmOutputPath: string | undefined;\n\tif (options.npmArchive === true) {\n\t\tconst packageManifest = parseVettaNpmPluginPackage(\n\t\t\tparseJsonObject(await readFile(resolve(rootDir, \"package.json\")), \"package.json\"),\n\t\t);\n\t\tif (packageManifest.version !== pluginManifest.version) {\n\t\t\tthrow new Error(\n\t\t\t\t`npm package version ${packageManifest.version} must match plugin version ${pluginManifest.version}.`,\n\t\t\t);\n\t\t}\n\t\tif (packageManifest.vetta.pluginId !== pluginManifest.id) {\n\t\t\tthrow new Error(\n\t\t\t\t`npm package plugin id ${packageManifest.vetta.pluginId} must match plugin id ${pluginManifest.id}.`,\n\t\t\t);\n\t\t}\n\t\tif (packageManifest.vetta.archive !== VETTA_NPM_PLUGIN_ARCHIVE_PATH) {\n\t\t\tthrow new Error(`npm package archive must be ${VETTA_NPM_PLUGIN_ARCHIVE_PATH}.`);\n\t\t}\n\t\tnpmOutputPath = resolve(rootDir, VETTA_NPM_PLUGIN_ARCHIVE_PATH);\n\t}\n\n\tawait mkdir(releaseDir, { recursive: true });\n\tawait rm(outputPath, { force: true });\n\tconst archive = await createZip(files);\n\tawait writeFile(outputPath, archive);\n\tif (npmOutputPath && npmOutputPath !== outputPath) {\n\t\tawait mkdir(dirname(npmOutputPath), { recursive: true });\n\t\tawait rm(npmOutputPath, { force: true });\n\t\tawait writeFile(npmOutputPath, archive);\n\t}\n\n\treturn { outputPath, npmOutputPath, files };\n}\n"]}
|
package/dist/pack.js
CHANGED
|
@@ -4,7 +4,8 @@ import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
|
4
4
|
import { listPluginManifestResources, parsePluginManifest } from "@vetta-org/plugin-sdk/manifest";
|
|
5
5
|
import { parseVettaNpmPluginPackage } from "@vetta-org/plugin-sdk/npm-package";
|
|
6
6
|
import { assertPluginPermissionContract } from "./permission-contract.js";
|
|
7
|
-
export const
|
|
7
|
+
export const VETTA_PLUGIN_PACKAGE_EXTENSION = ".vettapkg";
|
|
8
|
+
export const VETTA_NPM_PLUGIN_ARCHIVE_PATH = `release/vetta-plugin${VETTA_PLUGIN_PACKAGE_EXTENSION}`;
|
|
8
9
|
const crcTable = new Uint32Array(256);
|
|
9
10
|
for (let i = 0; i < 256; i += 1) {
|
|
10
11
|
let value = i;
|
|
@@ -270,7 +271,7 @@ export async function createVettaPluginPackage(options = {}) {
|
|
|
270
271
|
const releaseDir = resolve(rootDir, options.releaseDir ?? "release");
|
|
271
272
|
const distDir = resolve(rootDir, options.distDir ?? "dist");
|
|
272
273
|
const pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));
|
|
273
|
-
const outputPath = join(releaseDir, `${pluginManifest.id}-${pluginManifest.version}
|
|
274
|
+
const outputPath = join(releaseDir, `${pluginManifest.id}-${pluginManifest.version}${VETTA_PLUGIN_PACKAGE_EXTENSION}`);
|
|
274
275
|
const files = await collectRuntimeFiles(rootDir, manifestPath, distDir);
|
|
275
276
|
assertPluginPermissionContract(pluginManifest, await Promise.all(files
|
|
276
277
|
.filter((file) => /\.(?:c|m)?js$/u.test(file.archivePath))
|
package/dist/pack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pack.js","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAuB,MAAM,gCAAgC,CAAC;AACvH,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAsB1E,MAAM,CAAC,MAAM,6BAA6B,GAAG,0BAA0B,CAAC;AAExE,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC;AACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;IACjC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACrC,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,KAAK,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6BAA6B,EAAE,CAAC;YACrE,MAAM,IAAI,KAAK,CAAC,+BAA+B,6BAA6B,GAAG,CAAC,CAAC;QAClF,CAAC;QACD,aAAa,GAAG,OAAO,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,aAAa,IAAI,aAAa,KAAK,UAAU,EAAE,CAAC;QACnD,MAAM,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,MAAM,EAAE,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,MAAM,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;AAAA,CAC5C","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, join, relative, resolve, sep } from \"node:path\";\nimport { listPluginManifestResources, parsePluginManifest, type PluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport { parseVettaNpmPluginPackage } from \"@vetta-org/plugin-sdk/npm-package\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\n\nexport interface VettaPluginPackageFile {\n\tfullPath: string;\n\tarchivePath: string;\n}\n\nexport interface VettaPluginPackageResult {\n\toutputPath: string;\n\tnpmOutputPath?: string;\n\tfiles: VettaPluginPackageFile[];\n}\n\nexport interface CreateVettaPluginPackageOptions {\n\trootDir?: string;\n\tmanifestPath?: string;\n\treleaseDir?: string;\n\tdistDir?: string;\n\t/** Also write the stable npm distribution artifact `release/vetta-plugin.zip`. */\n\tnpmArchive?: boolean;\n}\n\nexport const VETTA_NPM_PLUGIN_ARCHIVE_PATH = \"release/vetta-plugin.zip\";\n\nconst crcTable = new Uint32Array(256);\nfor (let i = 0; i < 256; i += 1) {\n\tlet value = i;\n\tfor (let bit = 0; bit < 8; bit += 1) {\n\t\tvalue = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;\n\t}\n\tcrcTable[i] = value >>> 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readString(record: Record<string, unknown>, key: string): string | undefined {\n\tconst value = record[key];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction validateAbilityDescriptor(value: unknown, pluginManifest: PluginManifest): void {\n\tif (!isRecord(value)) throw new Error(\"ability.json must contain an object.\");\n\tif (\n\t\tvalue.schemaVersion !== 1 ||\n\t\tvalue.type !== \"plugin\" ||\n\t\tvalue.slug !== pluginManifest.id ||\n\t\tvalue.version !== pluginManifest.version\n\t) {\n\t\tthrow new Error(\"ability.json identity must match plugin.json id and version.\");\n\t}\n}\n\nfunction parseJsonObject(buffer: Buffer, fileName: string): Record<string, unknown> {\n\tconst parsed = JSON.parse(buffer.toString(\"utf-8\")) as unknown;\n\tif (!isRecord(parsed)) {\n\t\tthrow new Error(`${fileName} must contain an object.`);\n\t}\n\treturn parsed;\n}\n\nfunction crc32(buffer: Buffer): number {\n\tlet value = 0xffffffff;\n\tfor (const byte of buffer) {\n\t\tvalue = crcTable[(value ^ byte) & 0xff] ^ (value >>> 8);\n\t}\n\treturn (value ^ 0xffffffff) >>> 0;\n}\n\nfunction writeUInt16(value: number): Buffer {\n\tconst buffer = Buffer.allocUnsafe(2);\n\tbuffer.writeUInt16LE(value, 0);\n\treturn buffer;\n}\n\nfunction writeUInt32(value: number): Buffer {\n\tconst buffer = Buffer.allocUnsafe(4);\n\tbuffer.writeUInt32LE(value >>> 0, 0);\n\treturn buffer;\n}\n\nfunction archivePathFromRoot(rootDir: string, fullPath: string): string {\n\tconst archivePath = relative(rootDir, fullPath).replace(/\\\\/g, \"/\");\n\tif (!archivePath || archivePath.startsWith(\"..\") || archivePath.includes(`${sep}..${sep}`)) {\n\t\tthrow new Error(`File is outside plugin root: ${fullPath}`);\n\t}\n\treturn archivePath;\n}\n\nasync function collectFiles(dir: string): Promise<VettaPluginPackageFile[]> {\n\tconst entries = await readdir(dir, { withFileTypes: true });\n\tconst files: VettaPluginPackageFile[] = [];\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry.name);\n\t\tif (entry.isDirectory()) {\n\t\t\tfiles.push(...(await collectFiles(fullPath)));\n\t\t} else if (entry.isFile()) {\n\t\t\tfiles.push({ fullPath, archivePath: \"\" });\n\t\t}\n\t}\n\treturn files;\n}\n\nasync function collectPath(path: string): Promise<VettaPluginPackageFile[]> {\n\tconst info = await stat(path);\n\tif (info.isDirectory()) {\n\t\treturn collectFiles(path);\n\t}\n\tif (info.isFile()) {\n\t\treturn [{ fullPath: path, archivePath: \"\" }];\n\t}\n\treturn [];\n}\n\nasync function createZip(files: VettaPluginPackageFile[]): Promise<Buffer> {\n\tconst localParts: Buffer[] = [];\n\tconst centralParts: Buffer[] = [];\n\tlet offset = 0;\n\n\tfor (const file of files) {\n\t\tconst data = await readFile(file.fullPath);\n\t\tconst name = Buffer.from(file.archivePath.replace(/\\\\/g, \"/\"));\n\t\tconst checksum = crc32(data);\n\t\tconst localHeader = Buffer.concat([\n\t\t\twriteUInt32(0x04034b50),\n\t\t\twriteUInt16(20),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt32(checksum),\n\t\t\twriteUInt32(data.length),\n\t\t\twriteUInt32(data.length),\n\t\t\twriteUInt16(name.length),\n\t\t\twriteUInt16(0),\n\t\t\tname,\n\t\t]);\n\t\tlocalParts.push(localHeader, data);\n\n\t\tcentralParts.push(\n\t\t\tBuffer.concat([\n\t\t\t\twriteUInt32(0x02014b50),\n\t\t\t\twriteUInt16(20),\n\t\t\t\twriteUInt16(20),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt32(checksum),\n\t\t\t\twriteUInt32(data.length),\n\t\t\t\twriteUInt32(data.length),\n\t\t\t\twriteUInt16(name.length),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt32(0),\n\t\t\t\twriteUInt32(offset),\n\t\t\t\tname,\n\t\t\t]),\n\t\t);\n\t\toffset += localHeader.length + data.length;\n\t}\n\n\tconst centralDirectory = Buffer.concat(centralParts);\n\tconst endOfCentralDirectory = Buffer.concat([\n\t\twriteUInt32(0x06054b50),\n\t\twriteUInt16(0),\n\t\twriteUInt16(0),\n\t\twriteUInt16(files.length),\n\t\twriteUInt16(files.length),\n\t\twriteUInt32(centralDirectory.length),\n\t\twriteUInt32(offset),\n\t\twriteUInt16(0),\n\t]);\n\n\treturn Buffer.concat([...localParts, centralDirectory, endOfCentralDirectory]);\n}\n\nfunction readManifestRemoteEntry(manifest: Record<string, unknown>): string | undefined {\n\tconst metaData = manifest.metaData;\n\tif (!isRecord(metaData)) {\n\t\treturn undefined;\n\t}\n\tconst remoteEntry = metaData.remoteEntry;\n\tif (!isRecord(remoteEntry)) {\n\t\treturn undefined;\n\t}\n\tconst name = readString(remoteEntry, \"name\");\n\tif (!name) {\n\t\treturn undefined;\n\t}\n\tconst path = readString(remoteEntry, \"path\") ?? \"\";\n\treturn path ? `${path.replace(/\\/$/, \"\")}/${name}` : name;\n}\n\nasync function collectRuntimeFiles(\n\trootDir: string,\n\tmanifestPath: string,\n\tdistDir: string,\n): Promise<VettaPluginPackageFile[]> {\n\tconst pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));\n\tconst packageFiles = new Map<string, VettaPluginPackageFile>();\n\tconst addFile = (fullPath: string) => {\n\t\tconst resolved = resolve(fullPath);\n\t\tconst archivePath = archivePathFromRoot(rootDir, resolved);\n\t\tpackageFiles.set(archivePath, { fullPath: resolved, archivePath });\n\t};\n\n\taddFile(manifestPath);\n\n\t// 插件详情跟随插件包发布;ability.json 缺省兼容,存在时必须与 plugin.json 身份一致。\n\tconst abilityDescriptorPath = resolve(rootDir, \"ability.json\");\n\tif (existsSync(abilityDescriptorPath)) {\n\t\tvalidateAbilityDescriptor(\n\t\t\tparseJsonObject(await readFile(abilityDescriptorPath), basename(abilityDescriptorPath)),\n\t\t\tpluginManifest,\n\t\t);\n\t\taddFile(abilityDescriptorPath);\n\t\t// 约定的展示资源目录;内联 blocks 可引用其中的图片,随包整体带上。\n\t\ttry {\n\t\t\tfor (const file of await collectFiles(resolve(rootDir, \"presentation\"))) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t} catch {\n\t\t\t// optional presentation/ directory\n\t\t}\n\t}\n\n\tconst runtimeEntryPath = resolve(rootDir, pluginManifest.entry);\n\taddFile(runtimeEntryPath);\n\n\tconst federationManifest = parseJsonObject(await readFile(runtimeEntryPath), basename(runtimeEntryPath));\n\tconst remoteEntry = readManifestRemoteEntry(federationManifest);\n\tif (remoteEntry) {\n\t\taddFile(resolve(dirname(runtimeEntryPath), remoteEntry));\n\t}\n\n\tconst assetsDir = join(distDir, \"assets\");\n\tfor (const file of await collectFiles(assetsDir)) {\n\t\taddFile(file.fullPath);\n\t}\n\n\t// Vite cssCodeSplit emits extra files like dist/style2.css for async chunks;\n\t// include all dist-root CSS so preload-helper can fetch them (not only styles[]).\n\ttry {\n\t\tfor (const file of await collectFiles(distDir)) {\n\t\t\tconst rel = relative(distDir, file.fullPath).replace(/\\\\/g, \"/\");\n\t\t\tif (rel.endsWith(\".css\") && !rel.includes(\"/\")) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// dist missing\n\t}\n\n\tfor (const resource of listPluginManifestResources(pluginManifest)) {\n\t\tif (resource.field === \"entry\") continue;\n\t\tconst resourcePath = resolve(rootDir, resource.path);\n\t\tif (resource.kind === \"file\") {\n\t\t\tif (!existsSync(resourcePath)) {\n\t\t\t\tthrow new Error(`plugin.json resource not found: ${resource.field} (${resource.path})`);\n\t\t\t}\n\t\t\taddFile(resourcePath);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const file of await collectPath(resourcePath)) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t}\n\n\t// Plugin-scoped MCP: include config file and conventional companion dirs when declared.\n\tconst mcpServers = pluginManifest.agent?.mcpServers;\n\tif (mcpServers !== undefined) {\n\t\ttry {\n\t\t\tfor (const file of await collectFiles(resolve(rootDir, \"mcp\"))) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t} catch {\n\t\t\t// optional mcp/ directory\n\t\t}\n\t}\n\n\t// Helper scripts (plugin workbench etc.): always pack scripts/ when present.\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"scripts\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// optional scripts/ directory\n\t}\n\n\t// Handbook / agent docs beside skills (not always listed in skillPaths).\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"agent/docs\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// optional agent/docs\n\t}\n\n\t// Plugin i18n catalogs (ADR-0033): bundle locales/<lang>.json so the host can\n\t// load them alongside the manifest. Optional — absent for single-language plugins.\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"locales\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// no locales/ directory — nothing to bundle\n\t}\n\n\treturn [...packageFiles.values()].sort((a, b) => a.archivePath.localeCompare(b.archivePath));\n}\n\nexport async function createVettaPluginPackage(\n\toptions: CreateVettaPluginPackageOptions = {},\n): Promise<VettaPluginPackageResult> {\n\tconst rootDir = resolve(options.rootDir ?? process.cwd());\n\tconst manifestPath = resolve(rootDir, options.manifestPath ?? \"plugin.json\");\n\tconst releaseDir = resolve(rootDir, options.releaseDir ?? \"release\");\n\tconst distDir = resolve(rootDir, options.distDir ?? \"dist\");\n\tconst pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));\n\tconst outputPath = join(releaseDir, `${pluginManifest.id}-${pluginManifest.version}.zip`);\n\tconst files = await collectRuntimeFiles(rootDir, manifestPath, distDir);\n\tassertPluginPermissionContract(\n\t\tpluginManifest,\n\t\tawait Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter((file) => /\\.(?:c|m)?js$/u.test(file.archivePath))\n\t\t\t\t.map(async (file) => ({ fileName: file.archivePath, code: await readFile(file.fullPath, \"utf8\") })),\n\t\t),\n\t);\n\tlet npmOutputPath: string | undefined;\n\tif (options.npmArchive === true) {\n\t\tconst packageManifest = parseVettaNpmPluginPackage(\n\t\t\tparseJsonObject(await readFile(resolve(rootDir, \"package.json\")), \"package.json\"),\n\t\t);\n\t\tif (packageManifest.version !== pluginManifest.version) {\n\t\t\tthrow new Error(\n\t\t\t\t`npm package version ${packageManifest.version} must match plugin version ${pluginManifest.version}.`,\n\t\t\t);\n\t\t}\n\t\tif (packageManifest.vetta.pluginId !== pluginManifest.id) {\n\t\t\tthrow new Error(\n\t\t\t\t`npm package plugin id ${packageManifest.vetta.pluginId} must match plugin id ${pluginManifest.id}.`,\n\t\t\t);\n\t\t}\n\t\tif (packageManifest.vetta.archive !== VETTA_NPM_PLUGIN_ARCHIVE_PATH) {\n\t\t\tthrow new Error(`npm package archive must be ${VETTA_NPM_PLUGIN_ARCHIVE_PATH}.`);\n\t\t}\n\t\tnpmOutputPath = resolve(rootDir, VETTA_NPM_PLUGIN_ARCHIVE_PATH);\n\t}\n\n\tawait mkdir(releaseDir, { recursive: true });\n\tawait rm(outputPath, { force: true });\n\tconst archive = await createZip(files);\n\tawait writeFile(outputPath, archive);\n\tif (npmOutputPath && npmOutputPath !== outputPath) {\n\t\tawait mkdir(dirname(npmOutputPath), { recursive: true });\n\t\tawait rm(npmOutputPath, { force: true });\n\t\tawait writeFile(npmOutputPath, archive);\n\t}\n\n\treturn { outputPath, npmOutputPath, files };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pack.js","sourceRoot":"","sources":["../src/pack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAuB,MAAM,gCAAgC,CAAC;AACvH,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAC/E,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC;AAsB1E,MAAM,CAAC,MAAM,8BAA8B,GAAG,WAAW,CAAC;AAC1D,MAAM,CAAC,MAAM,6BAA6B,GAAG,uBAAuB,8BAA8B,EAAE,CAAC;AAErG,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC,GAAG,CAAC,CAAC;AACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;IACjC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE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d,yBAAyB,eAAe,CAAC,KAAK,CAAC,QAAQ,yBAAyB,cAAc,CAAC,EAAE,GAAG,CACpG,CAAC;QACH,CAAC;QACD,IAAI,eAAe,CAAC,KAAK,CAAC,OAAO,KAAK,6BAA6B,EAAE,CAAC;YACrE,MAAM,IAAI,KAAK,CAAC,+BAA+B,6BAA6B,GAAG,CAAC,CAAC;QAClF,CAAC;QACD,aAAa,GAAG,OAAO,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IACrC,IAAI,aAAa,IAAI,aAAa,KAAK,UAAU,EAAE,CAAC;QACnD,MAAM,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACzD,MAAM,EAAE,CAAC,aAAa,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,MAAM,SAAS,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;AAAA,CAC5C","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { mkdir, readdir, readFile, rm, stat, writeFile } from \"node:fs/promises\";\nimport { basename, dirname, join, relative, resolve, sep } from \"node:path\";\nimport { listPluginManifestResources, parsePluginManifest, type PluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport { parseVettaNpmPluginPackage } from \"@vetta-org/plugin-sdk/npm-package\";\nimport { assertPluginPermissionContract } from \"./permission-contract.js\";\n\nexport interface VettaPluginPackageFile {\n\tfullPath: string;\n\tarchivePath: string;\n}\n\nexport interface VettaPluginPackageResult {\n\toutputPath: string;\n\tnpmOutputPath?: string;\n\tfiles: VettaPluginPackageFile[];\n}\n\nexport interface CreateVettaPluginPackageOptions {\n\trootDir?: string;\n\tmanifestPath?: string;\n\treleaseDir?: string;\n\tdistDir?: string;\n\t/** Also write the stable npm distribution artifact `release/vetta-plugin.vettapkg`. */\n\tnpmArchive?: boolean;\n}\n\nexport const VETTA_PLUGIN_PACKAGE_EXTENSION = \".vettapkg\";\nexport const VETTA_NPM_PLUGIN_ARCHIVE_PATH = `release/vetta-plugin${VETTA_PLUGIN_PACKAGE_EXTENSION}`;\n\nconst crcTable = new Uint32Array(256);\nfor (let i = 0; i < 256; i += 1) {\n\tlet value = i;\n\tfor (let bit = 0; bit < 8; bit += 1) {\n\t\tvalue = value & 1 ? 0xedb88320 ^ (value >>> 1) : value >>> 1;\n\t}\n\tcrcTable[i] = value >>> 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction readString(record: Record<string, unknown>, key: string): string | undefined {\n\tconst value = record[key];\n\treturn typeof value === \"string\" ? value : undefined;\n}\n\nfunction validateAbilityDescriptor(value: unknown, pluginManifest: PluginManifest): void {\n\tif (!isRecord(value)) throw new Error(\"ability.json must contain an object.\");\n\tif (\n\t\tvalue.schemaVersion !== 1 ||\n\t\tvalue.type !== \"plugin\" ||\n\t\tvalue.slug !== pluginManifest.id ||\n\t\tvalue.version !== pluginManifest.version\n\t) {\n\t\tthrow new Error(\"ability.json identity must match plugin.json id and version.\");\n\t}\n}\n\nfunction parseJsonObject(buffer: Buffer, fileName: string): Record<string, unknown> {\n\tconst parsed = JSON.parse(buffer.toString(\"utf-8\")) as unknown;\n\tif (!isRecord(parsed)) {\n\t\tthrow new Error(`${fileName} must contain an object.`);\n\t}\n\treturn parsed;\n}\n\nfunction crc32(buffer: Buffer): number {\n\tlet value = 0xffffffff;\n\tfor (const byte of buffer) {\n\t\tvalue = crcTable[(value ^ byte) & 0xff] ^ (value >>> 8);\n\t}\n\treturn (value ^ 0xffffffff) >>> 0;\n}\n\nfunction writeUInt16(value: number): Buffer {\n\tconst buffer = Buffer.allocUnsafe(2);\n\tbuffer.writeUInt16LE(value, 0);\n\treturn buffer;\n}\n\nfunction writeUInt32(value: number): Buffer {\n\tconst buffer = Buffer.allocUnsafe(4);\n\tbuffer.writeUInt32LE(value >>> 0, 0);\n\treturn buffer;\n}\n\nfunction archivePathFromRoot(rootDir: string, fullPath: string): string {\n\tconst archivePath = relative(rootDir, fullPath).replace(/\\\\/g, \"/\");\n\tif (!archivePath || archivePath.startsWith(\"..\") || archivePath.includes(`${sep}..${sep}`)) {\n\t\tthrow new Error(`File is outside plugin root: ${fullPath}`);\n\t}\n\treturn archivePath;\n}\n\nasync function collectFiles(dir: string): Promise<VettaPluginPackageFile[]> {\n\tconst entries = await readdir(dir, { withFileTypes: true });\n\tconst files: VettaPluginPackageFile[] = [];\n\tfor (const entry of entries) {\n\t\tconst fullPath = join(dir, entry.name);\n\t\tif (entry.isDirectory()) {\n\t\t\tfiles.push(...(await collectFiles(fullPath)));\n\t\t} else if (entry.isFile()) {\n\t\t\tfiles.push({ fullPath, archivePath: \"\" });\n\t\t}\n\t}\n\treturn files;\n}\n\nasync function collectPath(path: string): Promise<VettaPluginPackageFile[]> {\n\tconst info = await stat(path);\n\tif (info.isDirectory()) {\n\t\treturn collectFiles(path);\n\t}\n\tif (info.isFile()) {\n\t\treturn [{ fullPath: path, archivePath: \"\" }];\n\t}\n\treturn [];\n}\n\nasync function createZip(files: VettaPluginPackageFile[]): Promise<Buffer> {\n\tconst localParts: Buffer[] = [];\n\tconst centralParts: Buffer[] = [];\n\tlet offset = 0;\n\n\tfor (const file of files) {\n\t\tconst data = await readFile(file.fullPath);\n\t\tconst name = Buffer.from(file.archivePath.replace(/\\\\/g, \"/\"));\n\t\tconst checksum = crc32(data);\n\t\tconst localHeader = Buffer.concat([\n\t\t\twriteUInt32(0x04034b50),\n\t\t\twriteUInt16(20),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt16(0),\n\t\t\twriteUInt32(checksum),\n\t\t\twriteUInt32(data.length),\n\t\t\twriteUInt32(data.length),\n\t\t\twriteUInt16(name.length),\n\t\t\twriteUInt16(0),\n\t\t\tname,\n\t\t]);\n\t\tlocalParts.push(localHeader, data);\n\n\t\tcentralParts.push(\n\t\t\tBuffer.concat([\n\t\t\t\twriteUInt32(0x02014b50),\n\t\t\t\twriteUInt16(20),\n\t\t\t\twriteUInt16(20),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt32(checksum),\n\t\t\t\twriteUInt32(data.length),\n\t\t\t\twriteUInt32(data.length),\n\t\t\t\twriteUInt16(name.length),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt16(0),\n\t\t\t\twriteUInt32(0),\n\t\t\t\twriteUInt32(offset),\n\t\t\t\tname,\n\t\t\t]),\n\t\t);\n\t\toffset += localHeader.length + data.length;\n\t}\n\n\tconst centralDirectory = Buffer.concat(centralParts);\n\tconst endOfCentralDirectory = Buffer.concat([\n\t\twriteUInt32(0x06054b50),\n\t\twriteUInt16(0),\n\t\twriteUInt16(0),\n\t\twriteUInt16(files.length),\n\t\twriteUInt16(files.length),\n\t\twriteUInt32(centralDirectory.length),\n\t\twriteUInt32(offset),\n\t\twriteUInt16(0),\n\t]);\n\n\treturn Buffer.concat([...localParts, centralDirectory, endOfCentralDirectory]);\n}\n\nfunction readManifestRemoteEntry(manifest: Record<string, unknown>): string | undefined {\n\tconst metaData = manifest.metaData;\n\tif (!isRecord(metaData)) {\n\t\treturn undefined;\n\t}\n\tconst remoteEntry = metaData.remoteEntry;\n\tif (!isRecord(remoteEntry)) {\n\t\treturn undefined;\n\t}\n\tconst name = readString(remoteEntry, \"name\");\n\tif (!name) {\n\t\treturn undefined;\n\t}\n\tconst path = readString(remoteEntry, \"path\") ?? \"\";\n\treturn path ? `${path.replace(/\\/$/, \"\")}/${name}` : name;\n}\n\nasync function collectRuntimeFiles(\n\trootDir: string,\n\tmanifestPath: string,\n\tdistDir: string,\n): Promise<VettaPluginPackageFile[]> {\n\tconst pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));\n\tconst packageFiles = new Map<string, VettaPluginPackageFile>();\n\tconst addFile = (fullPath: string) => {\n\t\tconst resolved = resolve(fullPath);\n\t\tconst archivePath = archivePathFromRoot(rootDir, resolved);\n\t\tpackageFiles.set(archivePath, { fullPath: resolved, archivePath });\n\t};\n\n\taddFile(manifestPath);\n\n\t// 插件详情跟随插件包发布;ability.json 缺省兼容,存在时必须与 plugin.json 身份一致。\n\tconst abilityDescriptorPath = resolve(rootDir, \"ability.json\");\n\tif (existsSync(abilityDescriptorPath)) {\n\t\tvalidateAbilityDescriptor(\n\t\t\tparseJsonObject(await readFile(abilityDescriptorPath), basename(abilityDescriptorPath)),\n\t\t\tpluginManifest,\n\t\t);\n\t\taddFile(abilityDescriptorPath);\n\t\t// 约定的展示资源目录;内联 blocks 可引用其中的图片,随包整体带上。\n\t\ttry {\n\t\t\tfor (const file of await collectFiles(resolve(rootDir, \"presentation\"))) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t} catch {\n\t\t\t// optional presentation/ directory\n\t\t}\n\t}\n\n\tconst runtimeEntryPath = resolve(rootDir, pluginManifest.entry);\n\taddFile(runtimeEntryPath);\n\n\tconst federationManifest = parseJsonObject(await readFile(runtimeEntryPath), basename(runtimeEntryPath));\n\tconst remoteEntry = readManifestRemoteEntry(federationManifest);\n\tif (remoteEntry) {\n\t\taddFile(resolve(dirname(runtimeEntryPath), remoteEntry));\n\t}\n\n\tconst assetsDir = join(distDir, \"assets\");\n\tfor (const file of await collectFiles(assetsDir)) {\n\t\taddFile(file.fullPath);\n\t}\n\n\t// Vite cssCodeSplit emits extra files like dist/style2.css for async chunks;\n\t// include all dist-root CSS so preload-helper can fetch them (not only styles[]).\n\ttry {\n\t\tfor (const file of await collectFiles(distDir)) {\n\t\t\tconst rel = relative(distDir, file.fullPath).replace(/\\\\/g, \"/\");\n\t\t\tif (rel.endsWith(\".css\") && !rel.includes(\"/\")) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// dist missing\n\t}\n\n\tfor (const resource of listPluginManifestResources(pluginManifest)) {\n\t\tif (resource.field === \"entry\") continue;\n\t\tconst resourcePath = resolve(rootDir, resource.path);\n\t\tif (resource.kind === \"file\") {\n\t\t\tif (!existsSync(resourcePath)) {\n\t\t\t\tthrow new Error(`plugin.json resource not found: ${resource.field} (${resource.path})`);\n\t\t\t}\n\t\t\taddFile(resourcePath);\n\t\t\tcontinue;\n\t\t}\n\t\tfor (const file of await collectPath(resourcePath)) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t}\n\n\t// Plugin-scoped MCP: include config file and conventional companion dirs when declared.\n\tconst mcpServers = pluginManifest.agent?.mcpServers;\n\tif (mcpServers !== undefined) {\n\t\ttry {\n\t\t\tfor (const file of await collectFiles(resolve(rootDir, \"mcp\"))) {\n\t\t\t\taddFile(file.fullPath);\n\t\t\t}\n\t\t} catch {\n\t\t\t// optional mcp/ directory\n\t\t}\n\t}\n\n\t// Helper scripts (plugin workbench etc.): always pack scripts/ when present.\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"scripts\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// optional scripts/ directory\n\t}\n\n\t// Handbook / agent docs beside skills (not always listed in skillPaths).\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"agent/docs\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// optional agent/docs\n\t}\n\n\t// Plugin i18n catalogs (ADR-0033): bundle locales/<lang>.json so the host can\n\t// load them alongside the manifest. Optional — absent for single-language plugins.\n\ttry {\n\t\tfor (const file of await collectFiles(resolve(rootDir, \"locales\"))) {\n\t\t\taddFile(file.fullPath);\n\t\t}\n\t} catch {\n\t\t// no locales/ directory — nothing to bundle\n\t}\n\n\treturn [...packageFiles.values()].sort((a, b) => a.archivePath.localeCompare(b.archivePath));\n}\n\nexport async function createVettaPluginPackage(\n\toptions: CreateVettaPluginPackageOptions = {},\n): Promise<VettaPluginPackageResult> {\n\tconst rootDir = resolve(options.rootDir ?? process.cwd());\n\tconst manifestPath = resolve(rootDir, options.manifestPath ?? \"plugin.json\");\n\tconst releaseDir = resolve(rootDir, options.releaseDir ?? \"release\");\n\tconst distDir = resolve(rootDir, options.distDir ?? \"dist\");\n\tconst pluginManifest = parsePluginManifest(parseJsonObject(await readFile(manifestPath), basename(manifestPath)));\n\tconst outputPath = join(\n\t\treleaseDir,\n\t\t`${pluginManifest.id}-${pluginManifest.version}${VETTA_PLUGIN_PACKAGE_EXTENSION}`,\n\t);\n\tconst files = await collectRuntimeFiles(rootDir, manifestPath, distDir);\n\tassertPluginPermissionContract(\n\t\tpluginManifest,\n\t\tawait Promise.all(\n\t\t\tfiles\n\t\t\t\t.filter((file) => /\\.(?:c|m)?js$/u.test(file.archivePath))\n\t\t\t\t.map(async (file) => ({ fileName: file.archivePath, code: await readFile(file.fullPath, \"utf8\") })),\n\t\t),\n\t);\n\tlet npmOutputPath: string | undefined;\n\tif (options.npmArchive === true) {\n\t\tconst packageManifest = parseVettaNpmPluginPackage(\n\t\t\tparseJsonObject(await readFile(resolve(rootDir, \"package.json\")), \"package.json\"),\n\t\t);\n\t\tif (packageManifest.version !== pluginManifest.version) {\n\t\t\tthrow new Error(\n\t\t\t\t`npm package version ${packageManifest.version} must match plugin version ${pluginManifest.version}.`,\n\t\t\t);\n\t\t}\n\t\tif (packageManifest.vetta.pluginId !== pluginManifest.id) {\n\t\t\tthrow new Error(\n\t\t\t\t`npm package plugin id ${packageManifest.vetta.pluginId} must match plugin id ${pluginManifest.id}.`,\n\t\t\t);\n\t\t}\n\t\tif (packageManifest.vetta.archive !== VETTA_NPM_PLUGIN_ARCHIVE_PATH) {\n\t\t\tthrow new Error(`npm package archive must be ${VETTA_NPM_PLUGIN_ARCHIVE_PATH}.`);\n\t\t}\n\t\tnpmOutputPath = resolve(rootDir, VETTA_NPM_PLUGIN_ARCHIVE_PATH);\n\t}\n\n\tawait mkdir(releaseDir, { recursive: true });\n\tawait rm(outputPath, { force: true });\n\tconst archive = await createZip(files);\n\tawait writeFile(outputPath, archive);\n\tif (npmOutputPath && npmOutputPath !== outputPath) {\n\t\tawait mkdir(dirname(npmOutputPath), { recursive: true });\n\t\tawait rm(npmOutputPath, { force: true });\n\t\tawait writeFile(npmOutputPath, archive);\n\t}\n\n\treturn { outputPath, npmOutputPath, files };\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export declare const PLUGIN_LOGGER_MODULE_ID = "@vetta-org/plugin-sdk/logger";
|
|
3
|
+
export declare const VETTA_PLUGIN_LOGGER_MODULE_ID = "virtual:vetta-plugin-logger";
|
|
4
|
+
/** Bind the public logger subpath to the current plugin's validated manifest identity. */
|
|
5
|
+
export declare function createPluginLoggerBindingPlugin(): Plugin;
|
|
6
|
+
//# sourceMappingURL=plugin-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-logger.d.ts","sourceRoot":"","sources":["../src/plugin-logger.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAEnD,eAAO,MAAM,uBAAuB,iCAAiC,CAAC;AACtE,eAAO,MAAM,6BAA6B,gCAAgC,CAAC;AAS3E,0FAA0F;AAC1F,wBAAgB,+BAA+B,IAAI,MAAM,CAqBxD","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, ResolvedConfig } from \"vite\";\n\nexport const PLUGIN_LOGGER_MODULE_ID = \"@vetta-org/plugin-sdk/logger\";\nexport const VETTA_PLUGIN_LOGGER_MODULE_ID = \"virtual:vetta-plugin-logger\";\nconst RESOLVED_PLUGIN_LOGGER_MODULE_ID = `\\0${VETTA_PLUGIN_LOGGER_MODULE_ID}`;\n\nfunction readPluginIdentity(config: ResolvedConfig): { id: string; version: string } {\n\tconst raw: unknown = JSON.parse(readFileSync(resolve(config.root, \"plugin.json\"), \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\treturn { id: manifest.id, version: manifest.version };\n}\n\n/** Bind the public logger subpath to the current plugin's validated manifest identity. */\nexport function createPluginLoggerBindingPlugin(): Plugin {\n\tlet identity: { id: string; version: string } | undefined;\n\treturn {\n\t\tname: \"vetta-plugin-logger-binding\",\n\t\tenforce: \"pre\",\n\t\tconfigResolved(config) {\n\t\t\tidentity = readPluginIdentity(config);\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === PLUGIN_LOGGER_MODULE_ID || id === VETTA_PLUGIN_LOGGER_MODULE_ID) {\n\t\t\t\treturn RESOLVED_PLUGIN_LOGGER_MODULE_ID;\n\t\t\t}\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_PLUGIN_LOGGER_MODULE_ID) return;\n\t\t\tif (!identity) throw new Error(\"Plugin logger identity is unavailable before Vite config resolution\");\n\t\t\treturn `import { __createPluginLogger } from \"@vetta-org/plugin-sdk\";\nexport const logger = __createPluginLogger(${JSON.stringify(identity)});\n`;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { parsePluginManifest } from "@vetta-org/plugin-sdk/manifest";
|
|
4
|
+
export const PLUGIN_LOGGER_MODULE_ID = "@vetta-org/plugin-sdk/logger";
|
|
5
|
+
export const VETTA_PLUGIN_LOGGER_MODULE_ID = "virtual:vetta-plugin-logger";
|
|
6
|
+
const RESOLVED_PLUGIN_LOGGER_MODULE_ID = `\0${VETTA_PLUGIN_LOGGER_MODULE_ID}`;
|
|
7
|
+
function readPluginIdentity(config) {
|
|
8
|
+
const raw = JSON.parse(readFileSync(resolve(config.root, "plugin.json"), "utf8"));
|
|
9
|
+
const manifest = parsePluginManifest(raw);
|
|
10
|
+
return { id: manifest.id, version: manifest.version };
|
|
11
|
+
}
|
|
12
|
+
/** Bind the public logger subpath to the current plugin's validated manifest identity. */
|
|
13
|
+
export function createPluginLoggerBindingPlugin() {
|
|
14
|
+
let identity;
|
|
15
|
+
return {
|
|
16
|
+
name: "vetta-plugin-logger-binding",
|
|
17
|
+
enforce: "pre",
|
|
18
|
+
configResolved(config) {
|
|
19
|
+
identity = readPluginIdentity(config);
|
|
20
|
+
},
|
|
21
|
+
resolveId(id) {
|
|
22
|
+
if (id === PLUGIN_LOGGER_MODULE_ID || id === VETTA_PLUGIN_LOGGER_MODULE_ID) {
|
|
23
|
+
return RESOLVED_PLUGIN_LOGGER_MODULE_ID;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
load(id) {
|
|
27
|
+
if (id !== RESOLVED_PLUGIN_LOGGER_MODULE_ID)
|
|
28
|
+
return;
|
|
29
|
+
if (!identity)
|
|
30
|
+
throw new Error("Plugin logger identity is unavailable before Vite config resolution");
|
|
31
|
+
return `import { __createPluginLogger } from "@vetta-org/plugin-sdk";
|
|
32
|
+
export const logger = __createPluginLogger(${JSON.stringify(identity)});
|
|
33
|
+
`;
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=plugin-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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E,CAAC,CAAC;YACtG,OAAO;6CACmC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;CACpE,CAAC;QAAA,CACC;KACD,CAAC;AAAA,CACF","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { parsePluginManifest } from \"@vetta-org/plugin-sdk/manifest\";\nimport type { Plugin, ResolvedConfig } from \"vite\";\n\nexport const PLUGIN_LOGGER_MODULE_ID = \"@vetta-org/plugin-sdk/logger\";\nexport const VETTA_PLUGIN_LOGGER_MODULE_ID = \"virtual:vetta-plugin-logger\";\nconst RESOLVED_PLUGIN_LOGGER_MODULE_ID = `\\0${VETTA_PLUGIN_LOGGER_MODULE_ID}`;\n\nfunction readPluginIdentity(config: ResolvedConfig): { id: string; version: string } {\n\tconst raw: unknown = JSON.parse(readFileSync(resolve(config.root, \"plugin.json\"), \"utf8\"));\n\tconst manifest = parsePluginManifest(raw);\n\treturn { id: manifest.id, version: manifest.version };\n}\n\n/** Bind the public logger subpath to the current plugin's validated manifest identity. */\nexport function createPluginLoggerBindingPlugin(): Plugin {\n\tlet identity: { id: string; version: string } | undefined;\n\treturn {\n\t\tname: \"vetta-plugin-logger-binding\",\n\t\tenforce: \"pre\",\n\t\tconfigResolved(config) {\n\t\t\tidentity = readPluginIdentity(config);\n\t\t},\n\t\tresolveId(id) {\n\t\t\tif (id === PLUGIN_LOGGER_MODULE_ID || id === VETTA_PLUGIN_LOGGER_MODULE_ID) {\n\t\t\t\treturn RESOLVED_PLUGIN_LOGGER_MODULE_ID;\n\t\t\t}\n\t\t},\n\t\tload(id) {\n\t\t\tif (id !== RESOLVED_PLUGIN_LOGGER_MODULE_ID) return;\n\t\t\tif (!identity) throw new Error(\"Plugin logger identity is unavailable before Vite config resolution\");\n\t\t\treturn `import { __createPluginLogger } from \"@vetta-org/plugin-sdk\";\nexport const logger = __createPluginLogger(${JSON.stringify(identity)});\n`;\n\t\t},\n\t};\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vetta-org/plugin-vite",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"postcss-selector-parser": "^7.1.4"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@vetta-org/plugin-sdk": ">=0.3.
|
|
37
|
+
"@vetta-org/plugin-sdk": ">=0.3.7 <0.4.0",
|
|
38
38
|
"vite": "^7.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|