Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@r1-runtime/vite-plugin

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@r1-runtime/vite-plugin - npm Package Compare versions

Comparing version
0.3.3
to
0.3.4
+1
-1
dist/index.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAS9C,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,MAAM,CAsgB9D"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAS9C,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,MAAM,CA0hB9D"}
import { spawn as v } from "child_process";
import { existsSync as p, readFileSync as u } from "fs";
import { dirname as P, resolve as o } from "path";
import { existsSync as m, readFileSync as g } from "fs";
import { dirname as P, resolve as e } from "path";
import { fileURLToPath as j } from "url";
import * as _ from "esbuild";
const w = P(j(import.meta.url));
function O(h = {}) {
const n = P(j(import.meta.url));
function O(q = {}) {
const {
rustSrc: y = "src-tauri",
wasmOut: x = "public/wasm"
} = h;
wasmOut: h = "public/wasm"
} = q;
let r;
const q = () => {
const s = o((r == null ? void 0 : r.root) || process.cwd(), y, "Cargo.toml");
if (p(s)) {
const n = u(s, "utf8"), e = n.match(/\[lib\][^]*?name\s*=\s*"([^"]+)"/);
if (e) return e[1].replace(/-/g, "_");
const a = n.match(/\[package\][^]*?name\s*=\s*"([^"]+)"/);
const x = () => {
const o = e((r == null ? void 0 : r.root) || process.cwd(), y, "Cargo.toml");
if (m(o)) {
const l = g(o, "utf8"), s = l.match(/\[lib\][^]*?name\s*=\s*"([^"]+)"/);
if (s) return s[1].replace(/-/g, "_");
const a = l.match(/\[package\][^]*?name\s*=\s*"([^"]+)"/);
if (a) return a[1].replace(/-/g, "_");
const l = n.match(/name\s*=\s*"([^"]+)"/);
if (l) return l[1].replace(/-/g, "_");
const c = l.match(/name\s*=\s*"([^"]+)"/);
if (c) return c[1].replace(/-/g, "_");
}
return "app";
}, m = "/r1/env.js", b = "\0" + m;
}, u = "/r1/env.js", b = "\0" + u;
return {
name: "vite-plugin-r1",
enforce: "pre",
configResolved(s) {
r = s;
configResolved(o) {
r = o;
},

@@ -45,7 +45,7 @@ config() {

},
resolveId(s) {
return s === m ? b : null;
resolveId(o) {
return o === u ? b : null;
},
load(s) {
return s === b ? `
load(o) {
return o === b ? `
const delegate = (name) => (...args) => {

@@ -83,4 +83,4 @@ if (globalThis.__R1_WASI__ && globalThis.__R1_WASI__[name]) {

async buildStart() {
const s = o(r.root, y, "Cargo.toml");
p(s) && (console.log(`[R1] Found Rust source at ${y}. Building WASM...`), await new Promise((n, e) => {
const o = e(r.root, y, "Cargo.toml");
m(o) && (console.log(`[R1] Found Rust source at ${y}. Building WASM...`), await new Promise((l, s) => {
const a = v("wasm-pack", [

@@ -92,22 +92,22 @@ "build",

"--out-dir",
o(r.root, x)
e(r.root, h)
], { stdio: "inherit", shell: !0 });
a.on("error", (l) => {
l.code === "ENOENT" ? (console.warn("[R1] wasm-pack not found. Please install it: https://rustwasm.github.io/wasm-pack/installer/"), n()) : e(l);
}), a.on("close", (l) => {
l === 0 || console.warn(`[R1] wasm-pack failed with code ${l}. Skipping WASM build.`), n();
a.on("error", (c) => {
c.code === "ENOENT" ? (console.warn("[R1] wasm-pack not found. Please install it: https://rustwasm.github.io/wasm-pack/installer/"), l()) : s(c);
}), a.on("close", (c) => {
c === 0 || console.warn(`[R1] wasm-pack failed with code ${c}. Skipping WASM build.`), l();
});
}));
},
transform(s, n) {
if (n.includes(x) && n.endsWith(".js") && s.includes('from "env"')) {
console.log(`[R1 Plugin] Patching "env" imports in ${n}`);
const a = `${m}`;
transform(o, l) {
if (l.includes(h) && l.endsWith(".js") && o.includes('from "env"')) {
console.log(`[R1 Plugin] Patching "env" imports in ${l}`);
const a = `${u}`;
return {
code: s.replace(/from\s+(['"])env\1/g, `from $1${a}$1`),
code: o.replace(/from\s+(['"])env\1/g, `from $1${a}$1`),
map: null
};
}
if (!n.match(/\.(js|ts|jsx|tsx)$/) || n.includes("node_modules")) return null;
const e = {
if (!l.match(/\.(js|ts|jsx|tsx)$/) || l.includes("node_modules")) return null;
const s = {
"@tauri-apps/api/core": "@r1-runtime/apis/core",

@@ -132,8 +132,8 @@ "@tauri-apps/api/tauri": "@r1-runtime/apis/core",

};
if (s.includes("@tauri-apps/api") || s.includes("@tauri-apps/plugin-store") || s.includes("@tauri-apps/plugin-sql")) {
let a = s;
const l = Object.keys(e).sort((t, g) => g.length - t.length);
for (const t of l) {
const g = e[t], c = new RegExp(`(['"])${t.replace(/\//g, "\\/")}\\1`, "g");
a = a.replace(c, `$1${g}$1`);
if (o.includes("@tauri-apps/api") || o.includes("@tauri-apps/plugin-store") || o.includes("@tauri-apps/plugin-sql")) {
let a = o;
const c = Object.keys(s).sort((t, f) => f.length - t.length);
for (const t of c) {
const f = s[t], d = new RegExp(`(['"])${t.replace(/\//g, "\\/")}\\1`, "g");
a = a.replace(d, `$1${f}$1`);
}

@@ -147,5 +147,5 @@ return {

},
async transformIndexHtml(s) {
return h.manualBoot ? s : {
html: s,
async transformIndexHtml(o) {
return q.manualBoot ? o : {
html: o,
tags: [

@@ -161,7 +161,7 @@ {

async generateBundle() {
const s = h.swSrc || o(w, "../../sw/src/index.ts");
if (p(s)) {
console.log(`[R1] Bundling Service Worker from ${s}...`);
const o = q.swSrc || e(n, "../../sw/src/index.ts");
if (m(o)) {
console.log(`[R1] Bundling Service Worker from ${o}...`);
const i = await _.build({
entryPoints: [s],
entryPoints: [o],
bundle: !0,

@@ -179,26 +179,38 @@ write: !1,

}
const e = [
o(r.root, "node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
o(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
o(r.root, "node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js"),
o(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js")
].find((i) => p(i));
e ? (console.log("[R1] Emitting SQLite OPFS Proxy from:", e), this.emitFile({
const s = [
e(r.root, "node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
e(r.root, "node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js"),
e(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
e(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js"),
// Inside @r1-runtime/kernel's own node_modules (npm install path)
e(n, "../../kernel/node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
e(n, "../../kernel/node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js"),
// Hoisted to the vite-plugin's parent node_modules
e(n, "../../../@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
e(n, "../../../@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js")
].find((i) => m(i));
s ? (console.log("[R1] Emitting SQLite OPFS Proxy from:", s), this.emitFile({
type: "asset",
fileName: "sqlite3-opfs-async-proxy.js",
source: u(e, "utf-8")
source: g(s, "utf-8")
})) : console.warn("[R1] sqlite3-opfs-async-proxy.js not found — OPFS persistence will not work. Run: npm install @sqlite.org/sqlite-wasm in packages/kernel");
const l = [
o(r.root, "node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
o(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
o(r.root, "node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm"),
o(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm")
].find((i) => p(i));
l ? (console.log("[R1] Emitting SQLite WASM from:", l), this.emitFile({
const c = [
e(r.root, "node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
e(r.root, "node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm"),
e(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
e(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm"),
// Inside @r1-runtime/kernel's own node_modules (npm install path)
e(n, "../../kernel/node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
e(n, "../../kernel/node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm"),
// Hoisted to the vite-plugin's parent node_modules
e(n, "../../../@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
e(n, "../../../@sqlite.org/sqlite-wasm/sqlite3.wasm")
].find((i) => m(i));
c ? (console.log("[R1] Emitting SQLite WASM from:", c), this.emitFile({
type: "asset",
fileName: "sqlite3.wasm",
source: u(l)
source: g(c)
})) : console.error("[R1] sqlite3.wasm NOT FOUND. SQLite will fail to load.");
const t = o(w, "../../kernel/src/kernel.worker.ts");
if (p(t)) {
const t = e(n, "../../kernel/src/kernel.worker.ts");
if (m(t)) {
console.log(`[R1] Bundling Kernel Worker from ${t}...`);

@@ -219,3 +231,3 @@ const i = await _.build({

}
const c = `
const d = `
import { R1Runtime } from '@r1-runtime/core';

@@ -225,3 +237,3 @@ console.log('[R1] Booting Runtime...');

r1.boot({
wasmPath: '/wasm/${q()}.js'
wasmPath: '/wasm/${x()}.js'
}).then(() => {

@@ -233,5 +245,5 @@ console.log('[R1] Boot complete.');

console.log("[R1] Bundling R1 Boot script...");
const d = await _.build({
const p = await _.build({
stdin: {
contents: c,
contents: d,
resolveDir: process.cwd(),

@@ -249,22 +261,22 @@ loader: "ts"

fileName: "r1-boot.js",
source: d.outputFiles[0].text
source: p.outputFiles[0].text
});
},
configureServer(s) {
s.middlewares.stack.unshift({
configureServer(o) {
o.middlewares.stack.unshift({
route: "",
handle: (n, e, a) => {
const t = (n.url || "").split("?")[0].split("#")[0];
if (!(t.endsWith("/r1-sw.js") || t.endsWith("/sw.js") || t.endsWith("/r1-boot.js") || t.endsWith(m) || t.endsWith("/sqlite3.wasm") || t.endsWith("/sqlite3-opfs-async-proxy.js") || t.startsWith("/wasm/") && t.endsWith(".js")))
handle: (l, s, a) => {
const t = (l.url || "").split("?")[0].split("#")[0];
if (!(t.endsWith("/r1-sw.js") || t.endsWith("/sw.js") || t.endsWith("/r1-boot.js") || t.endsWith(u) || t.endsWith("/sqlite3.wasm") || t.endsWith("/sqlite3-opfs-async-proxy.js") || t.startsWith("/wasm/") && t.endsWith(".js")))
return a();
e.setHeader("Cross-Origin-Resource-Policy", "cross-origin"), e.setHeader("Cross-Origin-Embedder-Policy", "credentialless"), (async () => {
s.setHeader("Cross-Origin-Resource-Policy", "cross-origin"), s.setHeader("Cross-Origin-Embedder-Policy", "credentialless"), (async () => {
try {
console.log(`[R1 Plugin] Intercepting: ${t}`);
let c = "";
let d = "";
if (t.endsWith("/r1-sw.js") || t.endsWith("/sw.js")) {
const d = t.endsWith("/r1-sw.js") ? h.swSrc || o(w, "../../sw/src/index.ts") : o(w, "../../kernel/src/kernel.worker.ts");
if (!p(d))
return console.warn(`[R1 Plugin] Source not found: ${d}`), e.statusCode = 404, e.end(`console.error("[R1 Plugin] Source not found for ${t}");`);
c = (await _.build({
entryPoints: [d],
const p = t.endsWith("/r1-sw.js") ? q.swSrc || e(n, "../../sw/src/index.ts") : e(n, "../../kernel/src/kernel.worker.ts");
if (!m(p))
return console.warn(`[R1 Plugin] Source not found: ${p}`), s.statusCode = 404, s.end(`console.error("[R1 Plugin] Source not found for ${t}");`);
d = (await _.build({
entryPoints: [p],
bundle: !0,

@@ -289,3 +301,3 @@ write: !1,

r1.boot({
wasmPath: '/wasm/${q()}.js'
wasmPath: '/wasm/${x()}.js'
}).then(() => {

@@ -299,6 +311,6 @@ window.dispatchEvent(new Event('r1:ready'));

`;
c = (await _.build({
d = (await _.build({
stdin: {
contents: i,
resolveDir: o(w, ".."),
resolveDir: e(n, ".."),
loader: "ts"

@@ -314,4 +326,4 @@ },

})).outputFiles[0].text;
} else if (t.endsWith(m))
c = `
} else if (t.endsWith(u))
d = `
const delegate = (name) => (...args) => {

@@ -346,11 +358,11 @@ if (globalThis.__R1_WASI__ && globalThis.__R1_WASI__[name]) {

else if (t.startsWith("/wasm/") && t.endsWith(".js")) {
const d = o(r.root, x, t.replace("/wasm/", ""));
if (p(d)) {
let i = u(d, "utf8");
const p = e(r.root, h, t.replace("/wasm/", ""));
if (m(p)) {
let i = g(p, "utf8");
if (i.includes('from "env"')) {
console.log(`[R1 Plugin] Middleware patching "env" in ${t}`);
const R = `${`${n.socket.remotePort === 443 ? "https" : "http"}://${n.headers.host}`}${m}`;
const R = `${`${l.socket.remotePort === 443 ? "https" : "http"}://${l.headers.host}`}${u}`;
i = i.replace(/from\s+(['"])env\1/g, `from $1${R}$1`);
}
c = i;
d = i;
} else

@@ -360,20 +372,28 @@ return a();

const i = [
o(r.root, "node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
o(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
o(r.root, "node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm"),
o(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm")
].find((f) => p(f));
return i ? (e.setHeader("Content-Type", "application/wasm"), e.setHeader("Cross-Origin-Resource-Policy", "cross-origin"), e.end(u(i))) : a();
e(r.root, "node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
e(r.root, "node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm"),
e(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
e(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm"),
e(n, "../../kernel/node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
e(n, "../../kernel/node_modules/@sqlite.org/sqlite-wasm/sqlite3.wasm"),
e(n, "../../../@sqlite.org/sqlite-wasm/dist/sqlite3.wasm"),
e(n, "../../../@sqlite.org/sqlite-wasm/sqlite3.wasm")
].find((w) => m(w));
return i ? (s.setHeader("Content-Type", "application/wasm"), s.setHeader("Cross-Origin-Resource-Policy", "cross-origin"), s.end(g(i))) : a();
} else if (t.endsWith("/sqlite3-opfs-async-proxy.js")) {
const i = [
o(r.root, "node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
o(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
o(r.root, "node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js"),
o(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js")
].find((f) => p(f));
return i ? (e.setHeader("Content-Type", "application/javascript"), e.setHeader("Cross-Origin-Resource-Policy", "cross-origin"), e.end(u(i, "utf-8"))) : a();
e(r.root, "node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
e(r.root, "node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js"),
e(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
e(r.root, "../../node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js"),
e(n, "../../kernel/node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
e(n, "../../kernel/node_modules/@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js"),
e(n, "../../../@sqlite.org/sqlite-wasm/dist/sqlite3-opfs-async-proxy.js"),
e(n, "../../../@sqlite.org/sqlite-wasm/sqlite3-opfs-async-proxy.js")
].find((w) => m(w));
return i ? (s.setHeader("Content-Type", "application/javascript"), s.setHeader("Cross-Origin-Resource-Policy", "cross-origin"), s.end(g(i, "utf-8"))) : a();
}
e.setHeader("Content-Type", "application/javascript"), e.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"), e.setHeader("Cross-Origin-Opener-Policy", "same-origin"), e.setHeader("Cross-Origin-Embedder-Policy", "credentialless"), e.setHeader("Cross-Origin-Resource-Policy", "cross-origin"), e.setHeader("Access-Control-Allow-Origin", "*"), r.command === "serve" && console.log(`[R1 Plugin] Serving ${t} with CORP/COOP/COEP headers`), t.endsWith("/r1-sw.js") && e.setHeader("Service-Worker-Allowed", "/"), e.end(c);
} catch (c) {
console.error(`[R1 Plugin] Error serving ${t}:`, c), e.headersSent || (e.statusCode = 500, e.setHeader("Content-Type", "application/javascript"), e.end(`console.error("[R1 Plugin] Failed to build ${t}: ${String(c).replace(/"/g, "'")}");`));
s.setHeader("Content-Type", "application/javascript"), s.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"), s.setHeader("Cross-Origin-Opener-Policy", "same-origin"), s.setHeader("Cross-Origin-Embedder-Policy", "credentialless"), s.setHeader("Cross-Origin-Resource-Policy", "cross-origin"), s.setHeader("Access-Control-Allow-Origin", "*"), r.command === "serve" && console.log(`[R1 Plugin] Serving ${t} with CORP/COOP/COEP headers`), t.endsWith("/r1-sw.js") && s.setHeader("Service-Worker-Allowed", "/"), s.end(d);
} catch (d) {
console.error(`[R1 Plugin] Error serving ${t}:`, d), s.headersSent || (s.statusCode = 500, s.setHeader("Content-Type", "application/javascript"), s.end(`console.error("[R1 Plugin] Failed to build ${t}: ${String(d).replace(/"/g, "'")}");`));
}

@@ -380,0 +400,0 @@ })();

{
"name": "@r1-runtime/vite-plugin",
"version": "0.3.3",
"version": "0.3.4",
"description": "Official Vite plugin for R1 — automates Rust→WASM compilation and Tauri import patching.",

@@ -5,0 +5,0 @@ "type": "module",