@jesscss/plugin-js 2.0.0-alpha.5 → 2.0.0-alpha.6
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/index.cjs +437 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +390 -426
- package/package.json +12 -8
- package/lib/index.js.map +0 -1
- package/lib/runtime-worker.js +0 -93
- package/lib/runtime-worker.js.map +0 -1
package/lib/index.cjs
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
+
});
|
|
5
|
+
//#region \0rolldown/runtime.js
|
|
6
|
+
var __create = Object.create;
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
+
key = keys[i];
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: ((k) => from[k]).bind(null, key),
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
//#endregion
|
|
27
|
+
let _jesscss_core = require("@jesscss/core");
|
|
28
|
+
let node_fs = require("node:fs");
|
|
29
|
+
node_fs = __toESM(node_fs);
|
|
30
|
+
let node_net = require("node:net");
|
|
31
|
+
node_net = __toESM(node_net);
|
|
32
|
+
let node_path = require("node:path");
|
|
33
|
+
node_path = __toESM(node_path);
|
|
34
|
+
let node_url = require("node:url");
|
|
35
|
+
let node_child_process = require("node:child_process");
|
|
36
|
+
//#region src/index.ts
|
|
37
|
+
const SCRIPT_EXTENSIONS = new Set([
|
|
38
|
+
".js",
|
|
39
|
+
".mjs",
|
|
40
|
+
".cjs",
|
|
41
|
+
".ts",
|
|
42
|
+
".mts",
|
|
43
|
+
".cts"
|
|
44
|
+
]);
|
|
45
|
+
const RUNTIME_MISSING_MESSAGE = [
|
|
46
|
+
"Deno runtime is required for @jesscss/plugin-js, but no usable Deno binary was found.",
|
|
47
|
+
"If using pnpm, approve build scripts for \"deno\" (pnpm approve-builds).",
|
|
48
|
+
"If using npm with ignored scripts, reinstall with lifecycle scripts enabled.",
|
|
49
|
+
"Or install native Deno and ensure \"deno\" is on PATH."
|
|
50
|
+
].join("\n");
|
|
51
|
+
const BOOT_TIMEOUT_MS = 8e3;
|
|
52
|
+
const REQUEST_TIMEOUT_MS = 1e4;
|
|
53
|
+
const IDLE_SHUTDOWN_MS = 5e3;
|
|
54
|
+
const isPathInside = (candidatePath, rootPath) => {
|
|
55
|
+
const rel = node_path.relative(rootPath, candidatePath);
|
|
56
|
+
return rel === "" || !rel.startsWith("..") && !node_path.isAbsolute(rel);
|
|
57
|
+
};
|
|
58
|
+
const canonicalPath = (p) => {
|
|
59
|
+
try {
|
|
60
|
+
return node_fs.realpathSync.native(p);
|
|
61
|
+
} catch {
|
|
62
|
+
return p;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const normalizePermissionPath = (value) => {
|
|
66
|
+
if (!value) return null;
|
|
67
|
+
if (value.startsWith("file://")) try {
|
|
68
|
+
return (0, node_url.fileURLToPath)(value);
|
|
69
|
+
} catch {
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
72
|
+
return value;
|
|
73
|
+
};
|
|
74
|
+
const isFnsPath = (importPath) => {
|
|
75
|
+
const normalized = importPath.replace(/\\/g, "/");
|
|
76
|
+
const isFnsPackagePath = /(^|\/)(@jesscss\/fns|packages\/fns)(\/|$)/.test(normalized);
|
|
77
|
+
return normalized === "@jesscss/fns" || normalized.startsWith("@jesscss/fns/") || normalized === "#less" || normalized.startsWith("#less/") || normalized === "#sass" || normalized.startsWith("#sass/") || isFnsPackagePath;
|
|
78
|
+
};
|
|
79
|
+
const isJsonValue = (value) => {
|
|
80
|
+
try {
|
|
81
|
+
JSON.stringify(value);
|
|
82
|
+
return true;
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var JsPlugin = class JsPlugin extends _jesscss_core.AbstractPlugin {
|
|
88
|
+
static cleanupRegistered = false;
|
|
89
|
+
static liveInstances = /* @__PURE__ */ new Set();
|
|
90
|
+
name = "js";
|
|
91
|
+
supportedExtensions = Array.from(SCRIPT_EXTENSIONS);
|
|
92
|
+
runtimeState = { status: "idle" };
|
|
93
|
+
brokerServer;
|
|
94
|
+
brokerSocketPath;
|
|
95
|
+
worker;
|
|
96
|
+
workerBuffer = "";
|
|
97
|
+
nextRequestId = 1;
|
|
98
|
+
pending = /* @__PURE__ */ new Map();
|
|
99
|
+
idleTimer;
|
|
100
|
+
constructor(opts = {}) {
|
|
101
|
+
super();
|
|
102
|
+
this.opts = opts;
|
|
103
|
+
JsPlugin.liveInstances.add(this);
|
|
104
|
+
JsPlugin.registerProcessCleanup();
|
|
105
|
+
}
|
|
106
|
+
prewarm() {
|
|
107
|
+
return this.ensureRuntime().catch(() => void 0);
|
|
108
|
+
}
|
|
109
|
+
static registerProcessCleanup() {
|
|
110
|
+
if (JsPlugin.cleanupRegistered) return;
|
|
111
|
+
JsPlugin.cleanupRegistered = true;
|
|
112
|
+
const cleanup = () => {
|
|
113
|
+
for (const instance of JsPlugin.liveInstances) try {
|
|
114
|
+
instance.dispose();
|
|
115
|
+
} catch {}
|
|
116
|
+
};
|
|
117
|
+
process.once("beforeExit", cleanup);
|
|
118
|
+
process.once("exit", cleanup);
|
|
119
|
+
}
|
|
120
|
+
clearIdleTimer() {
|
|
121
|
+
if (this.idleTimer) {
|
|
122
|
+
clearTimeout(this.idleTimer);
|
|
123
|
+
this.idleTimer = void 0;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
scheduleIdleShutdown() {
|
|
127
|
+
this.clearIdleTimer();
|
|
128
|
+
if (this.pending.size > 0 || this.runtimeState.status !== "ready") return;
|
|
129
|
+
this.idleTimer = setTimeout(() => {
|
|
130
|
+
this.shutdown();
|
|
131
|
+
this.runtimeState = { status: "idle" };
|
|
132
|
+
}, IDLE_SHUTDOWN_MS);
|
|
133
|
+
this.idleTimer.unref?.();
|
|
134
|
+
}
|
|
135
|
+
ensureRuntimeAvailable() {
|
|
136
|
+
if ((0, node_child_process.spawnSync)(this.opts.denoCommand ?? "deno", ["--version"], { stdio: "ignore" }).status !== 0) throw new Error(RUNTIME_MISSING_MESSAGE);
|
|
137
|
+
}
|
|
138
|
+
ensureRuntime() {
|
|
139
|
+
if (this.runtimeState.status === "ready") {
|
|
140
|
+
this.clearIdleTimer();
|
|
141
|
+
return Promise.resolve();
|
|
142
|
+
}
|
|
143
|
+
if (this.runtimeState.status === "initializing") return this.runtimeState.promise;
|
|
144
|
+
if (this.runtimeState.status === "failed") return Promise.reject(this.runtimeState.error);
|
|
145
|
+
const promise = this.startRuntime().then(() => {
|
|
146
|
+
this.runtimeState = { status: "ready" };
|
|
147
|
+
this.scheduleIdleShutdown();
|
|
148
|
+
}, (err) => {
|
|
149
|
+
this.runtimeState = {
|
|
150
|
+
status: "failed",
|
|
151
|
+
error: err
|
|
152
|
+
};
|
|
153
|
+
throw err;
|
|
154
|
+
});
|
|
155
|
+
this.runtimeState = {
|
|
156
|
+
status: "initializing",
|
|
157
|
+
promise
|
|
158
|
+
};
|
|
159
|
+
return promise;
|
|
160
|
+
}
|
|
161
|
+
createBrokerPath() {
|
|
162
|
+
if (process.platform === "win32") return `\\\\.\\pipe\\jess-deno-broker-${`${process.pid}-${Date.now()}-${Math.floor(Math.random() * 1e4)}`}`;
|
|
163
|
+
const rand = Math.floor(Math.random() * 1e4);
|
|
164
|
+
return `/tmp/jd-${process.pid}-${Date.now()}-${rand}.sock`;
|
|
165
|
+
}
|
|
166
|
+
isReadAllowed(value) {
|
|
167
|
+
const normalized = normalizePermissionPath(value);
|
|
168
|
+
if (!normalized) return false;
|
|
169
|
+
const requestedPath = canonicalPath(node_path.resolve(normalized));
|
|
170
|
+
const jsReadRoot = this.opts.jsReadRoot ? canonicalPath(node_path.resolve(this.opts.jsReadRoot)) : void 0;
|
|
171
|
+
if (jsReadRoot && isPathInside(requestedPath, jsReadRoot)) return true;
|
|
172
|
+
return requestedPath.includes(`${node_path.sep}node_modules${node_path.sep}`);
|
|
173
|
+
}
|
|
174
|
+
isNetAllowed(value) {
|
|
175
|
+
if (!this.opts.allowHttp) return false;
|
|
176
|
+
const allowHosts = this.opts.allowNetHosts ?? [];
|
|
177
|
+
if (allowHosts.length === 0) return true;
|
|
178
|
+
if (!value) return false;
|
|
179
|
+
const host = value.split(":")[0] ?? value;
|
|
180
|
+
return allowHosts.includes(host);
|
|
181
|
+
}
|
|
182
|
+
handleBrokerRequest(request) {
|
|
183
|
+
const deny = (reason) => ({
|
|
184
|
+
id: request.id,
|
|
185
|
+
result: "deny",
|
|
186
|
+
reason
|
|
187
|
+
});
|
|
188
|
+
switch (request.permission) {
|
|
189
|
+
case "read": return this.isReadAllowed(request.value) ? {
|
|
190
|
+
id: request.id,
|
|
191
|
+
result: "allow"
|
|
192
|
+
} : deny("Read access denied by Jess policy.");
|
|
193
|
+
case "net": return this.isNetAllowed(request.value) ? {
|
|
194
|
+
id: request.id,
|
|
195
|
+
result: "allow"
|
|
196
|
+
} : deny("Network access denied by Jess policy.");
|
|
197
|
+
case "env":
|
|
198
|
+
case "run":
|
|
199
|
+
case "ffi":
|
|
200
|
+
case "sys":
|
|
201
|
+
case "write": return deny(`${request.permission} permission denied by Jess policy.`);
|
|
202
|
+
default: return deny(`Permission "${request.permission}" denied by Jess policy.`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async startBroker() {
|
|
206
|
+
const socketPath = this.createBrokerPath();
|
|
207
|
+
if (process.platform !== "win32" && node_fs.existsSync(socketPath)) node_fs.unlinkSync(socketPath);
|
|
208
|
+
const server = node_net.createServer((socket) => {
|
|
209
|
+
let buf = "";
|
|
210
|
+
socket.setEncoding("utf8");
|
|
211
|
+
socket.on("data", (chunk) => {
|
|
212
|
+
buf += chunk;
|
|
213
|
+
let idx = buf.indexOf("\n");
|
|
214
|
+
while (idx >= 0) {
|
|
215
|
+
const line = buf.slice(0, idx).trim();
|
|
216
|
+
buf = buf.slice(idx + 1);
|
|
217
|
+
idx = buf.indexOf("\n");
|
|
218
|
+
if (!line) continue;
|
|
219
|
+
let req;
|
|
220
|
+
try {
|
|
221
|
+
req = JSON.parse(line);
|
|
222
|
+
} catch {
|
|
223
|
+
socket.write(JSON.stringify({
|
|
224
|
+
id: -1,
|
|
225
|
+
result: "deny",
|
|
226
|
+
reason: "Malformed permission request."
|
|
227
|
+
}) + "\n");
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const response = this.handleBrokerRequest(req);
|
|
231
|
+
socket.write(`${JSON.stringify(response)}\n`);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
await new Promise((resolve, reject) => {
|
|
236
|
+
server.once("error", reject);
|
|
237
|
+
server.listen(socketPath, () => resolve());
|
|
238
|
+
});
|
|
239
|
+
this.brokerServer = server;
|
|
240
|
+
this.brokerSocketPath = socketPath;
|
|
241
|
+
return socketPath;
|
|
242
|
+
}
|
|
243
|
+
startWorker(socketPath) {
|
|
244
|
+
const denoCommand = this.opts.denoCommand ?? "deno";
|
|
245
|
+
const moduleDir = node_path.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
246
|
+
const compiledWorkerPath = node_path.join(moduleDir, "runtime-worker.js");
|
|
247
|
+
const sourceWorkerPath = node_path.join(moduleDir, "runtime-worker.ts");
|
|
248
|
+
const child = (0, node_child_process.spawn)(denoCommand, [
|
|
249
|
+
"run",
|
|
250
|
+
"--no-prompt",
|
|
251
|
+
node_fs.existsSync(compiledWorkerPath) ? compiledWorkerPath : sourceWorkerPath
|
|
252
|
+
], {
|
|
253
|
+
stdio: [
|
|
254
|
+
"pipe",
|
|
255
|
+
"pipe",
|
|
256
|
+
"pipe"
|
|
257
|
+
],
|
|
258
|
+
env: {
|
|
259
|
+
...process.env,
|
|
260
|
+
DENO_PERMISSION_BROKER_PATH: socketPath
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
this.worker = child;
|
|
264
|
+
child.stdout.setEncoding("utf8");
|
|
265
|
+
child.stderr.setEncoding("utf8");
|
|
266
|
+
child.stdout.on("data", (chunk) => this.onWorkerStdout(chunk));
|
|
267
|
+
child.on("exit", () => {
|
|
268
|
+
const err = /* @__PURE__ */ new Error("Deno worker exited unexpectedly.");
|
|
269
|
+
this.rejectAllPending(err);
|
|
270
|
+
if (this.runtimeState.status !== "failed") this.runtimeState = {
|
|
271
|
+
status: "failed",
|
|
272
|
+
error: err
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
return new Promise((resolve, reject) => {
|
|
276
|
+
const timer = setTimeout(() => {
|
|
277
|
+
reject(/* @__PURE__ */ new Error("Timed out waiting for Deno worker startup."));
|
|
278
|
+
}, BOOT_TIMEOUT_MS);
|
|
279
|
+
const onData = (chunk) => {
|
|
280
|
+
this.workerBuffer += chunk;
|
|
281
|
+
let idx = this.workerBuffer.indexOf("\n");
|
|
282
|
+
while (idx >= 0) {
|
|
283
|
+
const line = this.workerBuffer.slice(0, idx).trim();
|
|
284
|
+
this.workerBuffer = this.workerBuffer.slice(idx + 1);
|
|
285
|
+
idx = this.workerBuffer.indexOf("\n");
|
|
286
|
+
if (!line) continue;
|
|
287
|
+
try {
|
|
288
|
+
if (JSON.parse(line).type === "ready") {
|
|
289
|
+
clearTimeout(timer);
|
|
290
|
+
child.stdout.off("data", onData);
|
|
291
|
+
resolve();
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
} catch {}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
child.stdout.on("data", onData);
|
|
298
|
+
child.once("error", (err) => {
|
|
299
|
+
clearTimeout(timer);
|
|
300
|
+
child.stdout.off("data", onData);
|
|
301
|
+
reject(err);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
async startRuntime() {
|
|
306
|
+
this.ensureRuntimeAvailable();
|
|
307
|
+
const socketPath = await this.startBroker();
|
|
308
|
+
try {
|
|
309
|
+
await this.startWorker(socketPath);
|
|
310
|
+
} catch (err) {
|
|
311
|
+
this.shutdown();
|
|
312
|
+
throw err instanceof Error ? err : new Error(String(err));
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
onWorkerStdout(chunk) {
|
|
316
|
+
this.workerBuffer += chunk;
|
|
317
|
+
let idx = this.workerBuffer.indexOf("\n");
|
|
318
|
+
while (idx >= 0) {
|
|
319
|
+
const line = this.workerBuffer.slice(0, idx).trim();
|
|
320
|
+
this.workerBuffer = this.workerBuffer.slice(idx + 1);
|
|
321
|
+
idx = this.workerBuffer.indexOf("\n");
|
|
322
|
+
if (!line) continue;
|
|
323
|
+
let parsed;
|
|
324
|
+
try {
|
|
325
|
+
parsed = JSON.parse(line);
|
|
326
|
+
} catch {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (!parsed || typeof parsed.id !== "number") continue;
|
|
330
|
+
const pending = this.pending.get(parsed.id);
|
|
331
|
+
if (!pending) continue;
|
|
332
|
+
this.pending.delete(parsed.id);
|
|
333
|
+
clearTimeout(pending.timeout);
|
|
334
|
+
pending.resolve(parsed);
|
|
335
|
+
if (this.pending.size === 0) this.scheduleIdleShutdown();
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
rejectAllPending(err) {
|
|
339
|
+
for (const pending of this.pending.values()) {
|
|
340
|
+
clearTimeout(pending.timeout);
|
|
341
|
+
pending.reject(err);
|
|
342
|
+
}
|
|
343
|
+
this.pending.clear();
|
|
344
|
+
}
|
|
345
|
+
async callWorker(request) {
|
|
346
|
+
await this.ensureRuntime();
|
|
347
|
+
this.clearIdleTimer();
|
|
348
|
+
if (!this.worker || !this.worker.stdin.writable) throw new Error("Deno worker is not available.");
|
|
349
|
+
const id = this.nextRequestId++;
|
|
350
|
+
const payload = {
|
|
351
|
+
...request,
|
|
352
|
+
id
|
|
353
|
+
};
|
|
354
|
+
return await new Promise((resolve, reject) => {
|
|
355
|
+
const timeout = setTimeout(() => {
|
|
356
|
+
this.pending.delete(id);
|
|
357
|
+
reject(/* @__PURE__ */ new Error("Timed out waiting for Deno worker response."));
|
|
358
|
+
}, REQUEST_TIMEOUT_MS);
|
|
359
|
+
this.pending.set(id, {
|
|
360
|
+
resolve,
|
|
361
|
+
reject,
|
|
362
|
+
timeout
|
|
363
|
+
});
|
|
364
|
+
this.worker.stdin.write(`${JSON.stringify(payload)}\n`);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
shutdown() {
|
|
368
|
+
this.clearIdleTimer();
|
|
369
|
+
if (this.worker && !this.worker.killed) this.worker.kill();
|
|
370
|
+
this.worker = void 0;
|
|
371
|
+
if (this.brokerServer) {
|
|
372
|
+
this.brokerServer.close();
|
|
373
|
+
this.brokerServer = void 0;
|
|
374
|
+
}
|
|
375
|
+
if (this.brokerSocketPath && process.platform !== "win32") try {
|
|
376
|
+
if (node_fs.existsSync(this.brokerSocketPath)) node_fs.unlinkSync(this.brokerSocketPath);
|
|
377
|
+
} catch {}
|
|
378
|
+
this.brokerSocketPath = void 0;
|
|
379
|
+
}
|
|
380
|
+
dispose() {
|
|
381
|
+
this.shutdown();
|
|
382
|
+
this.runtimeState = { status: "idle" };
|
|
383
|
+
}
|
|
384
|
+
assertAllowedPath(absoluteFilePath) {
|
|
385
|
+
const resolvedPath = node_path.resolve(absoluteFilePath);
|
|
386
|
+
const jsReadRoot = this.opts.jsReadRoot ? node_path.resolve(this.opts.jsReadRoot) : void 0;
|
|
387
|
+
if (!jsReadRoot) return;
|
|
388
|
+
if (isPathInside(resolvedPath, jsReadRoot)) return;
|
|
389
|
+
if (resolvedPath.includes(`${node_path.sep}node_modules${node_path.sep}`)) return;
|
|
390
|
+
throw new Error(`Script path "${resolvedPath}" is outside jsReadRoot "${jsReadRoot}"`);
|
|
391
|
+
}
|
|
392
|
+
async import(absoluteFilePath) {
|
|
393
|
+
const ext = node_path.extname(absoluteFilePath);
|
|
394
|
+
if (!SCRIPT_EXTENSIONS.has(ext)) throw new Error(`Plugin "${this.name}" cannot import "${absoluteFilePath}"`);
|
|
395
|
+
if (!isFnsPath(absoluteFilePath)) {
|
|
396
|
+
this.assertAllowedPath(absoluteFilePath);
|
|
397
|
+
await this.ensureRuntime();
|
|
398
|
+
const modulePath = node_path.resolve(absoluteFilePath);
|
|
399
|
+
const loadResult = await this.callWorker({
|
|
400
|
+
type: "load",
|
|
401
|
+
modulePath
|
|
402
|
+
});
|
|
403
|
+
if (!loadResult.ok) throw new Error(loadResult.error);
|
|
404
|
+
const moduleObject = {};
|
|
405
|
+
const exported = loadResult.exports ?? [];
|
|
406
|
+
for (const item of exported) if (item.kind === "function") moduleObject[item.name] = async (...args) => {
|
|
407
|
+
const invokeResult = await this.callWorker({
|
|
408
|
+
type: "invoke",
|
|
409
|
+
modulePath,
|
|
410
|
+
exportName: item.name,
|
|
411
|
+
args
|
|
412
|
+
});
|
|
413
|
+
if (!invokeResult.ok) throw new Error(invokeResult.error);
|
|
414
|
+
return invokeResult.value;
|
|
415
|
+
};
|
|
416
|
+
else moduleObject[item.name] = item.value;
|
|
417
|
+
return moduleObject;
|
|
418
|
+
}
|
|
419
|
+
const module = await import((0, node_url.pathToFileURL)(node_path.resolve(absoluteFilePath)).href);
|
|
420
|
+
const safeModule = {};
|
|
421
|
+
for (const [key, value] of Object.entries(module)) if (typeof value === "function" || isJsonValue(value)) safeModule[key] = value;
|
|
422
|
+
return safeModule;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
/**
|
|
426
|
+
* Global flag set when @jesscss/plugin-js is loaded.
|
|
427
|
+
* less-compat checks this before running @plugin scripts (scripts must be run when plugin-js/Deno is present).
|
|
428
|
+
*/
|
|
429
|
+
const JESS_PLUGIN_JS_GLOBAL = "__JESS_PLUGIN_JS_AVAILABLE__";
|
|
430
|
+
if (typeof globalThis !== "undefined") globalThis[JESS_PLUGIN_JS_GLOBAL] = true;
|
|
431
|
+
const jsPlugin = ((opts) => {
|
|
432
|
+
return new JsPlugin(opts);
|
|
433
|
+
});
|
|
434
|
+
//#endregion
|
|
435
|
+
exports.JESS_PLUGIN_JS_GLOBAL = JESS_PLUGIN_JS_GLOBAL;
|
|
436
|
+
exports.JsPlugin = JsPlugin;
|
|
437
|
+
exports.default = jsPlugin;
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface JsPluginOptions extends JavaScriptSandboxConfig {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class JsPlugin extends AbstractPlugin {
|
|
11
11
|
opts: JsPluginOptions;
|
|
12
|
+
private static cleanupRegistered;
|
|
13
|
+
private static liveInstances;
|
|
12
14
|
name: string;
|
|
13
15
|
supportedExtensions: string[];
|
|
14
16
|
private runtimeState;
|
|
@@ -18,8 +20,12 @@ export declare class JsPlugin extends AbstractPlugin {
|
|
|
18
20
|
private workerBuffer;
|
|
19
21
|
private nextRequestId;
|
|
20
22
|
private pending;
|
|
23
|
+
private idleTimer;
|
|
21
24
|
constructor(opts?: JsPluginOptions);
|
|
22
25
|
prewarm(): Promise<void | undefined>;
|
|
26
|
+
private static registerProcessCleanup;
|
|
27
|
+
private clearIdleTimer;
|
|
28
|
+
private scheduleIdleShutdown;
|
|
23
29
|
private ensureRuntimeAvailable;
|
|
24
30
|
private ensureRuntime;
|
|
25
31
|
private createBrokerPath;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACf,MAAM,eAAe,CAAC;AAOvB,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACf,MAAM,eAAe,CAAC;AAOvB,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,WAAW,eAAgB,SAAQ,uBAAuB;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAqGD,qBAAa,QAAS,SAAQ,cAAc;IAmBvB,IAAI,EAAE,eAAe;IAlBxC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAS;IACzC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAuB;IACnD,IAAI,SAAQ;IACZ,mBAAmB,WAAiC;IACpD,OAAO,CAAC,YAAY,CAAoC;IACxD,OAAO,CAAC,YAAY,CAAyB;IAC7C,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,MAAM,CAA6C;IAC3D,OAAO,CAAC,YAAY,CAAM;IAC1B,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,OAAO,CAIV;IAEL,OAAO,CAAC,SAAS,CAA6B;gBAE3B,IAAI,GAAE,eAAoB;IAM7C,OAAO;IAIP,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAkBrC,OAAO,CAAC,cAAc;IAOtB,OAAO,CAAC,oBAAoB;IAY5B,OAAO,CAAC,sBAAsB;IAU9B,OAAO,CAAC,aAAa;IAyBrB,OAAO,CAAC,gBAAgB;IAUxB,OAAO,CAAC,aAAa;IAarB,OAAO,CAAC,YAAY;IAepB,OAAO,CAAC,mBAAmB;YA0Bb,WAAW;IA4CzB,OAAO,CAAC,WAAW;YAmEL,YAAY;IAW1B,OAAO,CAAC,cAAc;IAiCtB,OAAO,CAAC,gBAAgB;YAQV,UAAU;IAsBxB,OAAO,CAAC,QAAQ;IAsBhB,OAAO;IAKP,OAAO,CAAC,iBAAiB;IAgBnB,MAAM,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CA8CrE;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,iCAAiC,CAAC;AAOpE,QAAA,MAAM,QAAQ,UAAY,eAAe,aAEtB,CAAC;AAEpB,eAAe,QAAQ,CAAC"}
|