@jesscss/plugin-js 2.0.0-alpha.1 → 2.0.0-alpha.10
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/README.md +47 -3
- package/lib/bridge.d.ts +46 -0
- package/lib/bridge.d.ts.map +1 -0
- package/lib/index.cjs +812 -0
- package/lib/index.d.ts +107 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +762 -426
- package/lib/runtime-worker.cjs +892 -0
- package/lib/runtime-worker.js +879 -81
- package/package.json +14 -8
- package/lib/index.js.map +0 -1
- package/lib/runtime-worker.js.map +0 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { AbstractPlugin } from '@jesscss/core';
|
|
2
|
+
/**
|
|
3
|
+
* A failure raised BY a `@plugin` script (its own `throw`, or a shim member it
|
|
4
|
+
* cannot use), as distinct from a value the engine simply could not compute.
|
|
5
|
+
* The distinction is what lets the compiler report a plugin fault loudly and
|
|
6
|
+
* attributably instead of preserving the call verbatim.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PluginFunctionError extends Error {
|
|
9
|
+
readonly functionName: string;
|
|
10
|
+
readonly pluginStack: string | undefined;
|
|
11
|
+
readonly originalName: string;
|
|
12
|
+
constructor(functionName: string, reason: string, pluginStack?: string, originalName?: string);
|
|
13
|
+
}
|
|
2
14
|
export type JavaScriptSandboxConfig = {
|
|
3
15
|
allowHttp?: boolean;
|
|
4
16
|
allowNetHosts?: string[];
|
|
@@ -6,20 +18,92 @@ export type JavaScriptSandboxConfig = {
|
|
|
6
18
|
};
|
|
7
19
|
export interface JsPluginOptions extends JavaScriptSandboxConfig {
|
|
8
20
|
denoCommand?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Runtime API exposed inside the Deno worker.
|
|
23
|
+
*
|
|
24
|
+
* Jess `@-use`/script imports run as plain ESM modules. Legacy Less
|
|
25
|
+
* `@plugin` loading can opt into the Less-compatible global shape.
|
|
26
|
+
*/
|
|
27
|
+
runtimeApi?: 'module' | 'less';
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns a copy of `env` with Node debugger/inspector-attach variables removed,
|
|
31
|
+
* so a spawned Deno subprocess starts regardless of the parent's debug env.
|
|
32
|
+
* The Deno permission sandbox is untouched; this only stops leaking the debugger
|
|
33
|
+
* into it.
|
|
34
|
+
*/
|
|
35
|
+
export declare const sanitizeSpawnEnv: (env?: NodeJS.ProcessEnv) => NodeJS.ProcessEnv;
|
|
36
|
+
/**
|
|
37
|
+
* One scope/built-in fact resolved on the HOST and handed to the sandbox so a
|
|
38
|
+
* synchronous Less-4 plugin body can read it. See {@link PluginCallCapabilities}.
|
|
39
|
+
*/
|
|
40
|
+
export type PluginCallFacts = {
|
|
41
|
+
vars: Record<string, {
|
|
42
|
+
value: unknown;
|
|
43
|
+
important?: boolean;
|
|
44
|
+
} | null>;
|
|
45
|
+
calls: Record<string, unknown>;
|
|
46
|
+
fileInfo: {
|
|
47
|
+
filename: string;
|
|
48
|
+
entryPath: string;
|
|
49
|
+
} | null;
|
|
50
|
+
};
|
|
51
|
+
export type PluginLogRecord = {
|
|
52
|
+
level: 'warn' | 'error' | 'info' | 'debug';
|
|
53
|
+
message: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The compiler-side capabilities a legacy `@plugin` function body needs. The
|
|
57
|
+
* dialect adapter supplies these bound to the LIVE evaluation frame of the call
|
|
58
|
+
* site; the sandbox reaches them only through the resolve-and-replay protocol,
|
|
59
|
+
* never as a live object.
|
|
60
|
+
*/
|
|
61
|
+
export interface PluginCallCapabilities {
|
|
62
|
+
/** Resolve `@name` at the call site. `null` means "no such variable". */
|
|
63
|
+
lookupVariable?(name: string): {
|
|
64
|
+
value: unknown;
|
|
65
|
+
important?: boolean;
|
|
66
|
+
} | null;
|
|
67
|
+
/** Evaluate a built-in function (`less.functions.functionRegistry.get(...)`). */
|
|
68
|
+
callFunction?(name: string, args: unknown[]): unknown;
|
|
69
|
+
/** The file/entry pair a plugin reads through `this.currentFileInfo`. */
|
|
70
|
+
currentFileInfo?: {
|
|
71
|
+
filename: string;
|
|
72
|
+
entryPath: string;
|
|
73
|
+
};
|
|
74
|
+
/** Records a diagnostic emitted by the plugin through `less.logger`. */
|
|
75
|
+
log?(record: PluginLogRecord): void;
|
|
76
|
+
/** Propagates `!important` picked up while resolving a variable. */
|
|
77
|
+
markImportant?(): void;
|
|
9
78
|
}
|
|
79
|
+
/** A `@plugin` function bound to the live call-site capabilities. */
|
|
80
|
+
export type ContextualPluginFunction = (args: readonly unknown[], capabilities: PluginCallCapabilities) => unknown | Promise<unknown>;
|
|
10
81
|
export declare class JsPlugin extends AbstractPlugin {
|
|
11
82
|
opts: JsPluginOptions;
|
|
83
|
+
private static cleanupRegistered;
|
|
84
|
+
private static liveInstances;
|
|
12
85
|
name: string;
|
|
13
86
|
supportedExtensions: string[];
|
|
14
87
|
private runtimeState;
|
|
88
|
+
private shuttingDown;
|
|
15
89
|
private brokerServer;
|
|
16
90
|
private brokerSocketPath;
|
|
17
91
|
private worker;
|
|
18
92
|
private workerBuffer;
|
|
19
93
|
private nextRequestId;
|
|
20
94
|
private pending;
|
|
95
|
+
private idleTimer;
|
|
96
|
+
/**
|
|
97
|
+
* Variable names each legacy plugin function has been observed to read,
|
|
98
|
+
* keyed by module+options+function. Prefetching them turns the steady-state
|
|
99
|
+
* call into a single round trip instead of one round trip per read.
|
|
100
|
+
*/
|
|
101
|
+
private readonly factMemo;
|
|
21
102
|
constructor(opts?: JsPluginOptions);
|
|
22
103
|
prewarm(): Promise<void | undefined>;
|
|
104
|
+
private static registerProcessCleanup;
|
|
105
|
+
private clearIdleTimer;
|
|
106
|
+
private scheduleIdleShutdown;
|
|
23
107
|
private ensureRuntimeAvailable;
|
|
24
108
|
private ensureRuntime;
|
|
25
109
|
private createBrokerPath;
|
|
@@ -36,6 +120,29 @@ export declare class JsPlugin extends AbstractPlugin {
|
|
|
36
120
|
dispose(): void;
|
|
37
121
|
private assertAllowedPath;
|
|
38
122
|
import(absoluteFilePath: string): Promise<Record<string, any>>;
|
|
123
|
+
/**
|
|
124
|
+
* Loads a legacy Less `@plugin` wrapper file in Deno Less-compat mode.
|
|
125
|
+
*
|
|
126
|
+
* @deprecated Less `@plugin` is deprecated. Prefer `@-from` for
|
|
127
|
+
* ESM-style script imports or `@-use` for Sass-module-style namespace imports.
|
|
128
|
+
*/
|
|
129
|
+
importLessPlugin(absoluteFilePath: string, options?: string | null): Promise<{
|
|
130
|
+
functions: Record<string, ContextualPluginFunction>;
|
|
131
|
+
}>;
|
|
132
|
+
/**
|
|
133
|
+
* Runs one legacy `@plugin` function, resolving the scope/built-in facts its
|
|
134
|
+
* body reads. The sandbox reports one unmet fact at a time; the host answers
|
|
135
|
+
* it from the LIVE call-site capabilities and replays. The names a function
|
|
136
|
+
* asked for are remembered per function, so steady-state calls ship the facts
|
|
137
|
+
* up front and complete in a single round trip.
|
|
138
|
+
*/
|
|
139
|
+
private invokePluginFunction;
|
|
140
|
+
private resolveVariableFact;
|
|
141
|
+
private resolveCallFact;
|
|
142
|
+
/** Context-facing executable-plugin capability used by the direct AST path. */
|
|
143
|
+
importPlugin(absoluteFilePath: string, options?: string | null): Promise<{
|
|
144
|
+
functions: Record<string, ContextualPluginFunction>;
|
|
145
|
+
}>;
|
|
39
146
|
}
|
|
40
147
|
/**
|
|
41
148
|
* Global flag set when @jesscss/plugin-js is loaded.
|
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;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACf,MAAM,eAAe,CAAC;AAQvB;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ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