@gjsify/rolldown-native 0.49.0 → 0.51.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/lib/esm/plugins.js +2 -1
- package/package.json +9 -9
package/lib/esm/plugins.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{loadNativeRolldown as e}from"./index.js";function getGLib(){let e=globalThis.imports?.gi;if(!e||!e.GLib)throw Error(`@gjsify/rolldown-native: GLib not available (not running under GJS?)`);return e.GLib}const enc=e=>getGLib().Bytes.new(new TextEncoder().encode(e)),dec=e=>new TextDecoder().decode(e.get_data()??new Uint8Array),t=[`load`,`transform`,`resolveId`,`renderChunk`,`banner`,`footer`,`intro`,`outro`,`buildStart`,`buildEnd`,`generateBundle`,`writeBundle`,`closeBundle`];function pluginMeta(e){let n=t.filter(t=>typeof e[t]==`function`),r={name:e.name,hooks:n};return e.idFilter&&(r.idFilter=e.idFilter),r}const n=new Set;function isResolveMiss(e){return e.startsWith(`NotFound(`)}
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{loadNativeRolldown as e}from"./index.js";function getGLib(){let e=globalThis.imports?.gi;if(!e||!e.GLib)throw Error(`@gjsify/rolldown-native: GLib not available (not running under GJS?)`);return e.GLib}const enc=e=>getGLib().Bytes.new(new TextEncoder().encode(e)),dec=e=>new TextDecoder().decode(e.get_data()??new Uint8Array),t=[`load`,`transform`,`resolveId`,`renderChunk`,`banner`,`footer`,`intro`,`outro`,`buildStart`,`buildEnd`,`generateBundle`,`writeBundle`,`closeBundle`];function pluginMeta(e){let n=t.filter(t=>typeof e[t]==`function`),r={name:e.name,hooks:n};return e.idFilter&&(r.idFilter=e.idFilter),r}const n=new Set;function isResolveMiss(e){return e.startsWith(`NotFound(`)}var HookErrorLog=class{entries=[];record(e,t){this.entries.push({...e,message:t})}format(){if(this.entries.length===0)return``;let e=this.entries.slice(0,8),t=e.map(({plugin:e,hook:t,message:n})=>` [plugin ${e}] ${t}: ${n}`),n=this.entries.length-e.length;return n>0&&t.push(` … and ${n} more`),`${this.entries.length===1?`1 plugin hook failed during this build:`:`${this.entries.length} plugin hooks failed during this build:`}\n${t.join(`
|
|
2
|
+
`)}`}};function bundleWithPlugins(t,r){let i=e();if(!i)return Promise.reject(Error(`@gjsify/rolldown-native: prebuild not available`));let a=new i.BundlerSession;n.add(a);let o=new HookErrorLog,s=new Map;a.connect(`context_response`,(e,t,n)=>{let r=s.get(t);if(!r)return;s.delete(t);let i;try{i=JSON.parse(dec(n))}catch(e){r.reject(e instanceof Error?e:Error(String(e)));return}i.error&&isResolveMiss(i.error)?r.resolve(null):i.error?r.reject(Error(i.error)):i.id?r.resolve({id:i.id,external:i.external??!1}):r.resolve(null)});function makeContext(e){return{resolve(t,n,r){return new Promise((i,o)=>{let c=a.context_resolve(e,enc(JSON.stringify({specifier:t,importer:n,skipSelf:r?.skipSelf??!0,isEntry:r?.isEntry??!1})));if(c===0){o(Error(`@gjsify/rolldown-native: ctx.resolve('${t}') failed — parent req_id ${e} unknown`));return}s.set(c,{resolve:i,reject:o})})},warn(e){a.context_warn(enc(e))},error(e){throw Error(e)}}}a.connect(`hook_requested`,(e,t,n,r,i)=>{dispatchHook(t,n,r,i)});async function dispatchHook(e,t,n,i){let o={plugin:r[n]?.name??`#${n}`,hook:e},s;try{s=JSON.parse(dec(i))}catch(e){respondError(t,e,o);return}let c=r[n];if(!c){respondError(t,Error(`@gjsify/rolldown-native: unknown plugin index ${n}`),o);return}let l=makeContext(t);try{if(e===`transform`&&c.transform){let e=s,n=a.take_request_payload(t);if(n===null)throw Error(`@gjsify/rolldown-native: transform request for ${e.id} missing payload bytes`);let r=dec(n);respondTransform(t,await c.transform.call(l,r,e.id,e.moduleType),o);return}respondOk(t,await runHook(c,e,s,l))}catch(e){respondError(t,e,o)}}function respondOk(e,t){let n=t==null?{kind:`skip`}:{kind:`ok`,value:t};a.respond(e,enc(JSON.stringify(n)))}function respondTransform(e,t,n){if(t==null){a.respond(e,enc(JSON.stringify({kind:`skip`})));return}let r,i;if(typeof t==`string`)r=t;else if(typeof t==`object`){let e=t;r=e.code,i=e.moduleType}if(typeof r!=`string`){a.respond(e,enc(JSON.stringify({kind:`skip`})));return}let o=getGLib().Bytes.new(new TextEncoder().encode(r));if(!a.set_response_payload(e,o)){respondError(e,Error(`@gjsify/rolldown-native: failed to stash transform response payload for reqId ${e}`),n);return}a.respond(e,enc(JSON.stringify({kind:`ok`,value:i===void 0?{hasCodeBytes:!0}:{hasCodeBytes:!0,moduleType:i}})))}function respondError(e,t,n){let r=t instanceof Error?t:Error(String(t));o.record(n,r.message),a.respond(e,enc(JSON.stringify({kind:`error`,message:r.message,stack:r.stack})))}let closeSession=()=>{n.delete(a);let e=a;try{e.close?.()}catch{}};return new Promise((e,n)=>{a.connect(`completed`,(t,r)=>{try{e(JSON.parse(dec(r)))}catch(e){n(e instanceof Error?e:Error(String(e)))}}),a.connect(`error_occurred`,(e,t)=>{let r=o.format();n(Error(r?`${t}\n${r}`:t))});try{a.start(enc(JSON.stringify({options:t,plugins:r.map(pluginMeta)})))}catch(e){n(e instanceof Error?e:Error(String(e)))}}).finally(closeSession)}async function runHook(e,t,n,r){switch(t){case`load`:return e.load?normalizeLoadResult(await e.load.call(r,n.id)):null;case`transform`:return null;case`resolveId`:{if(!e.resolveId)return null;let t=n;return normalizeResolveIdResult(await e.resolveId.call(r,t.specifier,t.importer,{isEntry:t.isEntry}))}case`renderChunk`:{if(!e.renderChunk)return null;let t=n;return normalizeRenderChunkResult(await e.renderChunk.call(r,t.code,{fileName:t.fileName,name:t.name,isEntry:t.isEntry}))}case`banner`:case`footer`:case`intro`:case`outro`:{let i=e[t];if(!i)return null;let a=n;return normalizeAddonResult(await i.call(r,{fileName:a.fileName,name:a.name,isEntry:a.isEntry}))}case`buildStart`:case`buildEnd`:case`generateBundle`:case`writeBundle`:case`closeBundle`:{let n=e[t];return n&&await n.call(r),null}default:throw Error(`@gjsify/rolldown-native: unknown hook '${t}'`)}}function normalizeLoadResult(e){return e==null?null:typeof e==`string`?{code:e}:{code:e.code,moduleType:e.moduleType}}function normalizeResolveIdResult(e){return e==null?null:typeof e==`string`?{id:e}:{id:e.id,external:e.external}}function normalizeRenderChunkResult(e){return e==null?null:typeof e==`string`?{code:e}:{code:e.code}}function normalizeAddonResult(e){return e==null?null:typeof e==`string`?e:e.text}export{bundleWithPlugins,isResolveMiss};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/rolldown-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Phase D-2 POC: Vala/GObject + Rust cdylib bridge to rolldown for GJS. Wraps `rolldown::Bundler::generate()` (async, tokio) in a per-call current-thread runtime so JS sees a sync `bundle()` call. JSON-encoded BundlerOptions in, JSON-encoded BundleOutput out — the boundary stays small even though rolldown's option surface is enormous. POC scope: no JS plugins (Phase B), no watch/HMR, no incremental builds. Companion to `@gjsify/lightningcss-native`; together they remove the last two Rust-crate runtime blockers from the gjsify build pipeline (Phase D-3 unblock).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/esm/index.js",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"native"
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@girs/gjs": "
|
|
57
|
-
"@girs/glib-2.0": "
|
|
58
|
-
"@girs/gobject-2.0": "
|
|
56
|
+
"@girs/gjs": "5.0.0",
|
|
57
|
+
"@girs/glib-2.0": "5.0.0",
|
|
58
|
+
"@girs/gobject-2.0": "5.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@gjsify/cli": "^0.
|
|
61
|
+
"@gjsify/cli": "^0.51.0",
|
|
62
62
|
"@types/node": "^25.9.2",
|
|
63
63
|
"typescript": "^6.0.3"
|
|
64
64
|
},
|
|
@@ -74,9 +74,9 @@
|
|
|
74
74
|
},
|
|
75
75
|
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/rolldown-native#readme",
|
|
76
76
|
"optionalDependencies": {
|
|
77
|
-
"@gjsify/rolldown-native-darwin-arm64": "0.
|
|
78
|
-
"@gjsify/rolldown-native-darwin-x64": "0.
|
|
79
|
-
"@gjsify/rolldown-native-linux-arm64": "0.
|
|
80
|
-
"@gjsify/rolldown-native-linux-x64": "0.
|
|
77
|
+
"@gjsify/rolldown-native-darwin-arm64": "0.51.0",
|
|
78
|
+
"@gjsify/rolldown-native-darwin-x64": "0.51.0",
|
|
79
|
+
"@gjsify/rolldown-native-linux-arm64": "0.51.0",
|
|
80
|
+
"@gjsify/rolldown-native-linux-x64": "0.51.0"
|
|
81
81
|
}
|
|
82
82
|
}
|