@playableintelligence/template-vite 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2026 PlayableIntelligence. All rights reserved.
2
+
3
+ This software is proprietary and confidential. The published npm package
4
+ contains only compiled, minified output; the original source code is not
5
+ distributed. No license is granted to use, copy, modify, distribute, or
6
+ create derivative works from this software except as expressly permitted in
7
+ writing by PlayableIntelligence.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @playableintelligence/template-vite
2
+
3
+ unplugin-based bundler plugin (Vite-first) for asset-swappable game templates. On every build it extracts `hotswappable()` slots and emits the JSON Schema, fails the build on bad authoring, and serves the schema as a virtual module.
4
+
5
+ ```bash
6
+ npm i -D @playableintelligence/template-vite
7
+ ```
8
+
9
+ ```ts
10
+ // vite.config.ts
11
+ import templateSchema from "@playableintelligence/template-vite";
12
+
13
+ export default {
14
+ plugins: [templateSchema({ src: "src/**/*.ts", out: "schema.json", template: "my-template" })],
15
+ };
16
+ ```
17
+
18
+ ```ts
19
+ import schema from "virtual:workflow/schema";
20
+ ```
21
+
22
+ One core, many bundlers — also exports `rollup`, `webpack`, `esbuild`, and `rspack` factories.
23
+
24
+ Pairs with `@playableintelligence/template-sdk` + `-cli`. Proprietary — see [LICENSE](./LICENSE).
package/dist/index.cjs ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";var g=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var y=(t,e)=>{for(var n in e)g(t,n,{get:e[n],enumerable:!0})},I=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of x(e))!k.call(t,s)&&s!==n&&g(t,s,{get:()=>e[s],enumerable:!(r=S(e,s))||r.enumerable});return t};var R=t=>I(g({},"__esModule",{value:!0}),t);var b={};y(b,{RESOLVED_VIRTUAL_MODULE_ID:()=>c,VIRTUAL_MODULE_ID:()=>i,buildSchema:()=>l,default:()=>E,esbuild:()=>A,formatDiagnostics:()=>p,rollup:()=>v,rspack:()=>_,unplugin:()=>o,validateInputs:()=>u,vite:()=>h,webpack:()=>U});module.exports=R(b);var f=require("fs"),m=require("path"),D=require("unplugin");var a=require("@playableintelligence/template-cli"),w=require("@playableintelligence/template-sdk"),i="virtual:workflow/schema",c=`\0${i}`,O=["src/**/*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}"];function L(t){return t===void 0?O:Array.isArray(t)?t:[t]}function l(t={}){let e=(0,a.extract)({entries:L(t.src),cwd:t.cwd,packageSpecifiers:t.packageSpecifiers}),n=e.diagnostics.filter(d=>d.severity==="error"),r=e.diagnostics.filter(d=>d.severity==="warning");return{schema:(0,a.toJsonSchema)(e.descriptors,{template:t.template}),descriptors:e.descriptors,errors:n,warnings:r}}function u(t,e){let n=(0,w.createRuntime)(e);for(let r of t)n.resolve({name:r.name,input:r.input,variable:r.variable,default:r.default,...r.description!==void 0?{description:r.description}:{},...r.constraints?{constraints:r.constraints}:{}});return n.diagnostics()}function p(t){return t.map(e=>` ${e.severity} [${e.code}] ${e.loc.file}:${e.loc.line}:${e.loc.column} \u2014 ${e.message}`).join(`
2
+ `)}var $=(t={})=>{let e,n=()=>{let r=l(t);if(e=r,r.errors.length>0)throw new Error(`[workflow] extraction failed with ${r.errors.length} error(s):
3
+ ${p(r.errors)}`);for(let s of r.warnings)console.warn(`[workflow] warning [${s.code}] ${s.loc.file}:${s.loc.line} \u2014 ${s.message}`);if(t.out){let s=(0,m.resolve)(t.cwd??process.cwd(),t.out);(0,f.mkdirSync)((0,m.dirname)(s),{recursive:!0}),(0,f.writeFileSync)(s,`${JSON.stringify(r.schema,null,2)}
4
+ `,"utf8")}if(t.inputs)for(let s of u(r.descriptors,t.inputs))console.warn(`[workflow] ${s.code}: ${s.message}`);return r};return{name:"unplugin-workflow",buildStart(){n()},resolveId(r){return r===i?c:null},load(r){if(r!==c)return null;let s=(e??n()).schema;return`export default ${JSON.stringify(s)};`}}},o=(0,D.createUnplugin)($),h=o.vite,v=o.rollup,U=o.webpack,_=o.rspack,A=o.esbuild,E=h;0&&(module.exports={RESOLVED_VIRTUAL_MODULE_ID,VIRTUAL_MODULE_ID,buildSchema,esbuild,formatDiagnostics,rollup,rspack,unplugin,validateInputs,vite,webpack});
@@ -0,0 +1,58 @@
1
+ import * as _rollup from 'rollup';
2
+ import * as _vite from 'vite';
3
+ import * as _unplugin from 'unplugin';
4
+ import { AssetDescriptor, Diagnostic } from '@playableintelligence/template-cli';
5
+ import { AssetInputs, RuntimeDiagnostic } from '@playableintelligence/template-sdk';
6
+
7
+ /**
8
+ * Core logic for the workflow bundler plugin (M06).
9
+ *
10
+ * Thin wrapper over the CLI's `extract` + `toJsonSchema` (no second extraction
11
+ * or schema code path — ADR 0006). Input validation reuses the SDK runtime so it
12
+ * can never drift from real resolution semantics.
13
+ */
14
+
15
+ /** Virtual module specifier the app imports to read its own schema. */
16
+ declare const VIRTUAL_MODULE_ID = "virtual:workflow/schema";
17
+ /** Resolved (null-prefixed) id, per bundler virtual-module convention. */
18
+ declare const RESOLVED_VIRTUAL_MODULE_ID = "\0virtual:workflow/schema";
19
+ interface WorkflowPluginOptions {
20
+ /** Source globs to scan. Default: `src/**` over TS/JS flavors. */
21
+ src?: string | string[];
22
+ /** Output path for `schema.json` (relative to `cwd`). When omitted, nothing is written. */
23
+ out?: string;
24
+ /** Template name recorded as `x-gc-template`. */
25
+ template?: string;
26
+ /** Working directory for glob resolution. Defaults to `process.cwd()`. */
27
+ cwd?: string;
28
+ /** Sample provided inputs to validate against the schema in dev. */
29
+ inputs?: AssetInputs;
30
+ /** Package specifiers whose `hotswappable` export is the extraction target. */
31
+ packageSpecifiers?: string[];
32
+ }
33
+ interface BuildSchemaResult {
34
+ schema: Record<string, unknown>;
35
+ descriptors: AssetDescriptor[];
36
+ errors: Diagnostic[];
37
+ warnings: Diagnostic[];
38
+ }
39
+ /** Extract slots and emit the JSON Schema. Reports diagnostics; never throws on bad input. */
40
+ declare function buildSchema(options?: WorkflowPluginOptions): BuildSchemaResult;
41
+ /**
42
+ * Validate provided inputs against extracted slots by replaying them through the
43
+ * SDK runtime — yielding the same `unknown-variable` / `unsatisfied-required-constraint`
44
+ * diagnostics the game would see at runtime.
45
+ */
46
+ declare function validateInputs(descriptors: AssetDescriptor[], inputs: AssetInputs): RuntimeDiagnostic[];
47
+ /** Format extraction diagnostics for terminal / overlay output. */
48
+ declare function formatDiagnostics(diagnostics: Diagnostic[]): string;
49
+
50
+ /** The shared unplugin instance (exposes `.vite`, `.rollup`, `.raw`, …). */
51
+ declare const unplugin: _unplugin.UnpluginInstance<WorkflowPluginOptions | undefined, boolean>;
52
+ declare const vite: (options?: WorkflowPluginOptions | undefined) => _vite.Plugin<any> | _vite.Plugin<any>[];
53
+ declare const rollup: (options?: WorkflowPluginOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
54
+ declare const webpack: (options?: WorkflowPluginOptions | undefined) => WebpackPluginInstance;
55
+ declare const rspack: (options?: WorkflowPluginOptions | undefined) => RspackPluginInstance;
56
+ declare const esbuild: (options?: WorkflowPluginOptions | undefined) => _unplugin.EsbuildPlugin;
57
+
58
+ export { type BuildSchemaResult, RESOLVED_VIRTUAL_MODULE_ID, VIRTUAL_MODULE_ID, type WorkflowPluginOptions, buildSchema, vite as default, esbuild, formatDiagnostics, rollup, rspack, unplugin, validateInputs, vite, webpack };
@@ -0,0 +1,58 @@
1
+ import * as _rollup from 'rollup';
2
+ import * as _vite from 'vite';
3
+ import * as _unplugin from 'unplugin';
4
+ import { AssetDescriptor, Diagnostic } from '@playableintelligence/template-cli';
5
+ import { AssetInputs, RuntimeDiagnostic } from '@playableintelligence/template-sdk';
6
+
7
+ /**
8
+ * Core logic for the workflow bundler plugin (M06).
9
+ *
10
+ * Thin wrapper over the CLI's `extract` + `toJsonSchema` (no second extraction
11
+ * or schema code path — ADR 0006). Input validation reuses the SDK runtime so it
12
+ * can never drift from real resolution semantics.
13
+ */
14
+
15
+ /** Virtual module specifier the app imports to read its own schema. */
16
+ declare const VIRTUAL_MODULE_ID = "virtual:workflow/schema";
17
+ /** Resolved (null-prefixed) id, per bundler virtual-module convention. */
18
+ declare const RESOLVED_VIRTUAL_MODULE_ID = "\0virtual:workflow/schema";
19
+ interface WorkflowPluginOptions {
20
+ /** Source globs to scan. Default: `src/**` over TS/JS flavors. */
21
+ src?: string | string[];
22
+ /** Output path for `schema.json` (relative to `cwd`). When omitted, nothing is written. */
23
+ out?: string;
24
+ /** Template name recorded as `x-gc-template`. */
25
+ template?: string;
26
+ /** Working directory for glob resolution. Defaults to `process.cwd()`. */
27
+ cwd?: string;
28
+ /** Sample provided inputs to validate against the schema in dev. */
29
+ inputs?: AssetInputs;
30
+ /** Package specifiers whose `hotswappable` export is the extraction target. */
31
+ packageSpecifiers?: string[];
32
+ }
33
+ interface BuildSchemaResult {
34
+ schema: Record<string, unknown>;
35
+ descriptors: AssetDescriptor[];
36
+ errors: Diagnostic[];
37
+ warnings: Diagnostic[];
38
+ }
39
+ /** Extract slots and emit the JSON Schema. Reports diagnostics; never throws on bad input. */
40
+ declare function buildSchema(options?: WorkflowPluginOptions): BuildSchemaResult;
41
+ /**
42
+ * Validate provided inputs against extracted slots by replaying them through the
43
+ * SDK runtime — yielding the same `unknown-variable` / `unsatisfied-required-constraint`
44
+ * diagnostics the game would see at runtime.
45
+ */
46
+ declare function validateInputs(descriptors: AssetDescriptor[], inputs: AssetInputs): RuntimeDiagnostic[];
47
+ /** Format extraction diagnostics for terminal / overlay output. */
48
+ declare function formatDiagnostics(diagnostics: Diagnostic[]): string;
49
+
50
+ /** The shared unplugin instance (exposes `.vite`, `.rollup`, `.raw`, …). */
51
+ declare const unplugin: _unplugin.UnpluginInstance<WorkflowPluginOptions | undefined, boolean>;
52
+ declare const vite: (options?: WorkflowPluginOptions | undefined) => _vite.Plugin<any> | _vite.Plugin<any>[];
53
+ declare const rollup: (options?: WorkflowPluginOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
54
+ declare const webpack: (options?: WorkflowPluginOptions | undefined) => WebpackPluginInstance;
55
+ declare const rspack: (options?: WorkflowPluginOptions | undefined) => RspackPluginInstance;
56
+ declare const esbuild: (options?: WorkflowPluginOptions | undefined) => _unplugin.EsbuildPlugin;
57
+
58
+ export { type BuildSchemaResult, RESOLVED_VIRTUAL_MODULE_ID, VIRTUAL_MODULE_ID, type WorkflowPluginOptions, buildSchema, vite as default, esbuild, formatDiagnostics, rollup, rspack, unplugin, validateInputs, vite, webpack };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import{mkdirSync as D,writeFileSync as h}from"fs";import{dirname as S,resolve as x}from"path";import{createUnplugin as k}from"unplugin";import{extract as f,toJsonSchema as m}from"@playableintelligence/template-cli";import{createRuntime as d}from"@playableintelligence/template-sdk";var i="virtual:workflow/schema",c=`\0${i}`,g=["src/**/*.{ts,tsx,js,jsx,mts,cts,mjs,cjs}"];function w(e){return e===void 0?g:Array.isArray(e)?e:[e]}function l(e={}){let r=f({entries:w(e.src),cwd:e.cwd,packageSpecifiers:e.packageSpecifiers}),n=r.diagnostics.filter(a=>a.severity==="error"),t=r.diagnostics.filter(a=>a.severity==="warning");return{schema:m(r.descriptors,{template:e.template}),descriptors:r.descriptors,errors:n,warnings:t}}function u(e,r){let n=d(r);for(let t of e)n.resolve({name:t.name,input:t.input,variable:t.variable,default:t.default,...t.description!==void 0?{description:t.description}:{},...t.constraints?{constraints:t.constraints}:{}});return n.diagnostics()}function p(e){return e.map(r=>` ${r.severity} [${r.code}] ${r.loc.file}:${r.loc.line}:${r.loc.column} \u2014 ${r.message}`).join(`
2
+ `)}var y=(e={})=>{let r,n=()=>{let t=l(e);if(r=t,t.errors.length>0)throw new Error(`[workflow] extraction failed with ${t.errors.length} error(s):
3
+ ${p(t.errors)}`);for(let s of t.warnings)console.warn(`[workflow] warning [${s.code}] ${s.loc.file}:${s.loc.line} \u2014 ${s.message}`);if(e.out){let s=x(e.cwd??process.cwd(),e.out);D(S(s),{recursive:!0}),h(s,`${JSON.stringify(t.schema,null,2)}
4
+ `,"utf8")}if(e.inputs)for(let s of u(t.descriptors,e.inputs))console.warn(`[workflow] ${s.code}: ${s.message}`);return t};return{name:"unplugin-workflow",buildStart(){n()},resolveId(t){return t===i?c:null},load(t){if(t!==c)return null;let s=(r??n()).schema;return`export default ${JSON.stringify(s)};`}}},o=k(y),I=o.vite,A=o.rollup,E=o.webpack,b=o.rspack,V=o.esbuild,P=I;export{c as RESOLVED_VIRTUAL_MODULE_ID,i as VIRTUAL_MODULE_ID,l as buildSchema,P as default,V as esbuild,p as formatDiagnostics,A as rollup,b as rspack,o as unplugin,u as validateInputs,I as vite,E as webpack};
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@playableintelligence/template-vite",
3
+ "version": "0.1.0",
4
+ "description": "unplugin-based bundler plugin (Vite-first) that emits the template JSON Schema at build time, fails fast on diagnostics, exposes a virtual schema module, and validates inputs in dev.",
5
+ "license": "UNLICENSED",
6
+ "author": "PlayableIntelligence",
7
+ "keywords": [
8
+ "playableintelligence",
9
+ "game-template",
10
+ "vite-plugin",
11
+ "unplugin",
12
+ "json-schema"
13
+ ],
14
+ "type": "module",
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/index.d.cts",
26
+ "default": "./dist/index.cjs"
27
+ }
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "engines": {
34
+ "node": ">=18"
35
+ },
36
+ "scripts": {
37
+ "build": "tsup",
38
+ "prepublishOnly": "tsup",
39
+ "publish:dry": "bun publish --dry-run",
40
+ "publish:pkg": "bun publish"
41
+ },
42
+ "dependencies": {
43
+ "@playableintelligence/template-cli": "0.0.0",
44
+ "@playableintelligence/template-sdk": "0.0.0",
45
+ "unplugin": "^2.1.0"
46
+ },
47
+ "devDependencies": {
48
+ "tsup": "^8.3.5",
49
+ "vite": "^6.0.0"
50
+ },
51
+ "peerDependencies": {
52
+ "vite": ">=5"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "vite": {
56
+ "optional": true
57
+ }
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ }
62
+ }