slicejs-web-framework 3.4.3 → 3.5.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/.opencode/opencode.json +14 -14
- package/Slice/Components/Structural/ContextManager/ContextManager.js +422 -422
- package/Slice/Components/Structural/ContextManager/ContextManagerDebugger.js +468 -468
- package/Slice/Components/Structural/Controller/Controller.js +1406 -1198
- package/Slice/Components/Structural/Debugger/Debugger.js +1503 -1503
- package/Slice/Components/Structural/EventManager/EventManager.js +651 -366
- package/Slice/Components/Structural/EventManager/EventManagerDebugger.js +368 -30
- package/Slice/Components/Structural/LeakInspector/LeakInspector.js +296 -0
- package/Slice/Components/Structural/Logger/Logger.js +225 -225
- package/Slice/Components/Structural/Router/Router.js +775 -775
- package/Slice/Components/Structural/StylesManager/StylesManager.js +82 -82
- package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +106 -106
- package/Slice/Slice.js +663 -627
- package/Slice/tests/build-singleton.test.js +244 -244
- package/Slice/tests/bundle-v2-runtime-contract.test.js +738 -738
- package/Slice/tests/context-patch-use.test.js +95 -95
- package/Slice/tests/event-emitters.test.js +79 -0
- package/Slice/tests/event-registry.test.js +141 -0
- package/Slice/tests/fixtures/real-runtime-loader.mjs +21 -21
- package/Slice/tests/leak-orphans.test.js +131 -0
- package/Slice/tests/public-env-typed-accessors.test.js +66 -66
- package/api/index.js +308 -281
- package/api/utils/publicEnvResolver.js +123 -123
- package/package.json +44 -44
- package/sliceConfig.schema.json +10 -1
- package/src/sliceConfig.json +5 -1
- package/types/index.d.ts +12 -0
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
-
|
|
3
|
-
const PUBLIC_PREFIX = 'SLICE_PUBLIC_';
|
|
4
|
-
const SUSPICIOUS_TERMS = ['SECRET', 'TOKEN', 'PASSWORD', 'PRIVATE', 'API_KEY', 'ACCESS_KEY', 'CREDENTIAL'];
|
|
5
|
-
|
|
6
|
-
function parseEnvFile(envFilePath) {
|
|
7
|
-
if (!envFilePath || !existsSync(envFilePath)) {
|
|
8
|
-
return {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
let fileContent;
|
|
12
|
-
try {
|
|
13
|
-
fileContent = readFileSync(envFilePath, 'utf8').replace(/^\uFEFF/, '');
|
|
14
|
-
} catch (error) {
|
|
15
|
-
console.error(`Error reading env file ${envFilePath}:`, error);
|
|
16
|
-
return {};
|
|
17
|
-
}
|
|
18
|
-
const parsed = {};
|
|
19
|
-
const lines = fileContent.split(/\r?\n/);
|
|
20
|
-
|
|
21
|
-
for (const rawLine of lines) {
|
|
22
|
-
const line = rawLine.trim();
|
|
23
|
-
|
|
24
|
-
if (!line || line.startsWith('#')) {
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const equalsIndex = line.indexOf('=');
|
|
29
|
-
if (equalsIndex === -1) {
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let key = line.slice(0, equalsIndex).trim();
|
|
34
|
-
if (!key) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (key.startsWith('export ')) {
|
|
39
|
-
key = key.slice('export '.length).trim();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
let value = line.slice(equalsIndex + 1).trim();
|
|
43
|
-
|
|
44
|
-
const quotedWithOptionalCommentMatch = value.match(/^(["'])(.*?)\1(?:\s+#.*)?$/);
|
|
45
|
-
|
|
46
|
-
if (quotedWithOptionalCommentMatch) {
|
|
47
|
-
value = quotedWithOptionalCommentMatch[2];
|
|
48
|
-
} else {
|
|
49
|
-
value = value.replace(/\s+#.*$/, '').trimEnd();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
parsed[key] = value;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return parsed;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function warnSuspiciousKey(key, logger, warnedKeys) {
|
|
59
|
-
const upperKey = key.toUpperCase();
|
|
60
|
-
const isSuspicious = SUSPICIOUS_TERMS.some((term) => upperKey.includes(term));
|
|
61
|
-
|
|
62
|
-
if (isSuspicious && !warnedKeys.has(key) && logger && typeof logger.warn === 'function') {
|
|
63
|
-
logger.warn(`[slice-env] Suspicious public environment key detected: ${key}`);
|
|
64
|
-
warnedKeys.add(key);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function buildPublicPayload({ envFromFile, processEnv, logger }) {
|
|
69
|
-
const env = {};
|
|
70
|
-
const warnedKeys = new Set();
|
|
71
|
-
|
|
72
|
-
for (const [key, value] of Object.entries(envFromFile)) {
|
|
73
|
-
if (key.startsWith(PUBLIC_PREFIX)) {
|
|
74
|
-
env[key] = String(value ?? '');
|
|
75
|
-
warnSuspiciousKey(key, logger, warnedKeys);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
for (const [key, value] of Object.entries(processEnv || {})) {
|
|
80
|
-
if (key.startsWith(PUBLIC_PREFIX)) {
|
|
81
|
-
env[key] = String(value ?? '');
|
|
82
|
-
warnSuspiciousKey(key, logger, warnedKeys);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return env;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function resolvePublicEnv({ mode, envFilePath, processEnv = process.env, logger = console }) {
|
|
90
|
-
const envFromFile = parseEnvFile(envFilePath);
|
|
91
|
-
const env = buildPublicPayload({
|
|
92
|
-
envFromFile,
|
|
93
|
-
processEnv,
|
|
94
|
-
logger,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
mode,
|
|
99
|
-
env,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function createPublicEnvProvider({ mode, envFilePath, processEnv = process.env, logger = console }) {
|
|
104
|
-
if (mode === 'production') {
|
|
105
|
-
let cachedPayload;
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
getPayload() {
|
|
109
|
-
if (!cachedPayload) {
|
|
110
|
-
cachedPayload = resolvePublicEnv({ mode, envFilePath, processEnv, logger });
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return cachedPayload;
|
|
114
|
-
},
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
getPayload() {
|
|
120
|
-
return resolvePublicEnv({ mode, envFilePath, processEnv, logger });
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
1
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
const PUBLIC_PREFIX = 'SLICE_PUBLIC_';
|
|
4
|
+
const SUSPICIOUS_TERMS = ['SECRET', 'TOKEN', 'PASSWORD', 'PRIVATE', 'API_KEY', 'ACCESS_KEY', 'CREDENTIAL'];
|
|
5
|
+
|
|
6
|
+
function parseEnvFile(envFilePath) {
|
|
7
|
+
if (!envFilePath || !existsSync(envFilePath)) {
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let fileContent;
|
|
12
|
+
try {
|
|
13
|
+
fileContent = readFileSync(envFilePath, 'utf8').replace(/^\uFEFF/, '');
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error(`Error reading env file ${envFilePath}:`, error);
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
const parsed = {};
|
|
19
|
+
const lines = fileContent.split(/\r?\n/);
|
|
20
|
+
|
|
21
|
+
for (const rawLine of lines) {
|
|
22
|
+
const line = rawLine.trim();
|
|
23
|
+
|
|
24
|
+
if (!line || line.startsWith('#')) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const equalsIndex = line.indexOf('=');
|
|
29
|
+
if (equalsIndex === -1) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
let key = line.slice(0, equalsIndex).trim();
|
|
34
|
+
if (!key) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (key.startsWith('export ')) {
|
|
39
|
+
key = key.slice('export '.length).trim();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let value = line.slice(equalsIndex + 1).trim();
|
|
43
|
+
|
|
44
|
+
const quotedWithOptionalCommentMatch = value.match(/^(["'])(.*?)\1(?:\s+#.*)?$/);
|
|
45
|
+
|
|
46
|
+
if (quotedWithOptionalCommentMatch) {
|
|
47
|
+
value = quotedWithOptionalCommentMatch[2];
|
|
48
|
+
} else {
|
|
49
|
+
value = value.replace(/\s+#.*$/, '').trimEnd();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
parsed[key] = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return parsed;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function warnSuspiciousKey(key, logger, warnedKeys) {
|
|
59
|
+
const upperKey = key.toUpperCase();
|
|
60
|
+
const isSuspicious = SUSPICIOUS_TERMS.some((term) => upperKey.includes(term));
|
|
61
|
+
|
|
62
|
+
if (isSuspicious && !warnedKeys.has(key) && logger && typeof logger.warn === 'function') {
|
|
63
|
+
logger.warn(`[slice-env] Suspicious public environment key detected: ${key}`);
|
|
64
|
+
warnedKeys.add(key);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function buildPublicPayload({ envFromFile, processEnv, logger }) {
|
|
69
|
+
const env = {};
|
|
70
|
+
const warnedKeys = new Set();
|
|
71
|
+
|
|
72
|
+
for (const [key, value] of Object.entries(envFromFile)) {
|
|
73
|
+
if (key.startsWith(PUBLIC_PREFIX)) {
|
|
74
|
+
env[key] = String(value ?? '');
|
|
75
|
+
warnSuspiciousKey(key, logger, warnedKeys);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
for (const [key, value] of Object.entries(processEnv || {})) {
|
|
80
|
+
if (key.startsWith(PUBLIC_PREFIX)) {
|
|
81
|
+
env[key] = String(value ?? '');
|
|
82
|
+
warnSuspiciousKey(key, logger, warnedKeys);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return env;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function resolvePublicEnv({ mode, envFilePath, processEnv = process.env, logger = console }) {
|
|
90
|
+
const envFromFile = parseEnvFile(envFilePath);
|
|
91
|
+
const env = buildPublicPayload({
|
|
92
|
+
envFromFile,
|
|
93
|
+
processEnv,
|
|
94
|
+
logger,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
mode,
|
|
99
|
+
env,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function createPublicEnvProvider({ mode, envFilePath, processEnv = process.env, logger = console }) {
|
|
104
|
+
if (mode === 'production') {
|
|
105
|
+
let cachedPayload;
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
getPayload() {
|
|
109
|
+
if (!cachedPayload) {
|
|
110
|
+
cachedPayload = resolvePublicEnv({ mode, envFilePath, processEnv, logger });
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return cachedPayload;
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
getPayload() {
|
|
120
|
+
return resolvePublicEnv({ mode, envFilePath, processEnv, logger });
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "slicejs-web-framework",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "",
|
|
5
|
-
"engines": {
|
|
6
|
-
"node": ">=20"
|
|
7
|
-
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"dev": "node ./node_modules/slicejs-cli/client.js dev",
|
|
10
|
-
"build": "node ./node_modules/slicejs-cli/client.js build",
|
|
11
|
-
"start": "node ./node_modules/slicejs-cli/client.js start",
|
|
12
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
|
-
"slice:init": "node ./node_modules/slicejs-cli/client.js init",
|
|
14
|
-
"slice:create": "node ./node_modules/slicejs-cli/client.js component create",
|
|
15
|
-
"slice:delete": "node ./node_modules/slicejs-cli/client.js component delete",
|
|
16
|
-
"slice:list": "node ./node_modules/slicejs-cli/client.js component list",
|
|
17
|
-
"slice:start": "node ./node_modules/slicejs-cli/client.js start",
|
|
18
|
-
"format": "prettier --write \"**/*.js\"",
|
|
19
|
-
"run": "node ./node_modules/slicejs-cli/client.js dev",
|
|
20
|
-
"slice:modify": "node ./node_modules/slicejs-cli/client.js modify"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [],
|
|
23
|
-
"author": "",
|
|
24
|
-
"license": "ISC",
|
|
25
|
-
"type": "module",
|
|
26
|
-
"exports": {
|
|
27
|
-
".": "./Slice/Slice.js",
|
|
28
|
-
"./api/framework/express.js": "./api/framework/express.js"
|
|
29
|
-
},
|
|
30
|
-
"types": "./types/index.d.ts",
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"express": "^4.19.2"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"prettier": "3.3.3"
|
|
36
|
-
},
|
|
37
|
-
"prettier": {
|
|
38
|
-
"trailingComma": "es5",
|
|
39
|
-
"tabWidth": 3,
|
|
40
|
-
"semi": true,
|
|
41
|
-
"singleQuote": true,
|
|
42
|
-
"printWidth": 120
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "slicejs-web-framework",
|
|
3
|
+
"version": "3.5.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=20"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "node ./node_modules/slicejs-cli/client.js dev",
|
|
10
|
+
"build": "node ./node_modules/slicejs-cli/client.js build",
|
|
11
|
+
"start": "node ./node_modules/slicejs-cli/client.js start",
|
|
12
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
13
|
+
"slice:init": "node ./node_modules/slicejs-cli/client.js init",
|
|
14
|
+
"slice:create": "node ./node_modules/slicejs-cli/client.js component create",
|
|
15
|
+
"slice:delete": "node ./node_modules/slicejs-cli/client.js component delete",
|
|
16
|
+
"slice:list": "node ./node_modules/slicejs-cli/client.js component list",
|
|
17
|
+
"slice:start": "node ./node_modules/slicejs-cli/client.js start",
|
|
18
|
+
"format": "prettier --write \"**/*.js\"",
|
|
19
|
+
"run": "node ./node_modules/slicejs-cli/client.js dev",
|
|
20
|
+
"slice:modify": "node ./node_modules/slicejs-cli/client.js modify"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [],
|
|
23
|
+
"author": "",
|
|
24
|
+
"license": "ISC",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./Slice/Slice.js",
|
|
28
|
+
"./api/framework/express.js": "./api/framework/express.js"
|
|
29
|
+
},
|
|
30
|
+
"types": "./types/index.d.ts",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"express": "^4.19.2"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"prettier": "3.3.3"
|
|
36
|
+
},
|
|
37
|
+
"prettier": {
|
|
38
|
+
"trailingComma": "es5",
|
|
39
|
+
"tabWidth": 3,
|
|
40
|
+
"semi": true,
|
|
41
|
+
"singleQuote": true,
|
|
42
|
+
"printWidth": 120
|
|
43
|
+
}
|
|
44
|
+
}
|
package/sliceConfig.schema.json
CHANGED
|
@@ -10,7 +10,16 @@
|
|
|
10
10
|
"additionalProperties": true,
|
|
11
11
|
"properties": {
|
|
12
12
|
"enabled": { "type": "boolean" },
|
|
13
|
-
"click": { "type": "string", "enum": ["right", "left"] }
|
|
13
|
+
"click": { "type": "string", "enum": ["right", "left"] },
|
|
14
|
+
"leakInspector": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"additionalProperties": true,
|
|
17
|
+
"description": "Dev-only memory-leak panel. Disabled in production regardless of this flag.",
|
|
18
|
+
"properties": {
|
|
19
|
+
"enabled": { "type": "boolean" },
|
|
20
|
+
"shortcut": { "type": "string" }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
14
23
|
}
|
|
15
24
|
},
|
|
16
25
|
"stylesManager": {
|
package/src/sliceConfig.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -44,6 +44,10 @@ export interface SliceControllerApi {
|
|
|
44
44
|
destroyComponent(components: HTMLElement | string | Array<HTMLElement | string>): number;
|
|
45
45
|
destroyByContainer(container: HTMLElement): number;
|
|
46
46
|
destroyByPattern(pattern: string | RegExp): number;
|
|
47
|
+
findOrphans(): Array<{ sliceId: string; name: string; reason: string; retainPath: string[] }>;
|
|
48
|
+
registerLeakExclusion(predicate: (component: HTMLElement) => boolean): void;
|
|
49
|
+
sampleComponentGrowth(): void;
|
|
50
|
+
isGrowthMonotonic(): boolean;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
export interface SliceStylesManagerApi {
|
|
@@ -88,6 +92,13 @@ export interface SliceEventManagerApi {
|
|
|
88
92
|
unsubscribe(eventName: string, subscriptionId: string): boolean;
|
|
89
93
|
emit(eventName: string, ...data: unknown[]): void;
|
|
90
94
|
bind(component: HTMLElement): SliceEventBindingApi | null;
|
|
95
|
+
register(namespace: string, catalog: Record<string, { description?: string; payload?: unknown }>): SliceEventManagerApi;
|
|
96
|
+
register(catalog: Record<string, { description?: string; payload?: unknown }>): SliceEventManagerApi;
|
|
97
|
+
loadGraph(graph: { events: Record<string, unknown>; dynamic?: unknown }): SliceEventManagerApi;
|
|
98
|
+
staticEmittersOf(eventName: string): Array<{ file: string; line: number; component: string | null }>;
|
|
99
|
+
staticListenersOf(eventName: string): Array<{ file: string; line: number; component: string | null }>;
|
|
100
|
+
isDeclared(eventName: string): boolean;
|
|
101
|
+
namespaceOf(eventName: string): string | null;
|
|
91
102
|
cleanupComponent(sliceId: string): number;
|
|
92
103
|
hasSubscribers(eventName: string): boolean;
|
|
93
104
|
subscriberCount(eventName: string): number;
|
|
@@ -178,6 +189,7 @@ export interface SliceApi {
|
|
|
178
189
|
debugger?: SliceDebuggerApi;
|
|
179
190
|
eventsDebugger?: SlicePanelDebuggerApi;
|
|
180
191
|
contextDebugger?: SlicePanelDebuggerApi;
|
|
192
|
+
leakInspector?: SlicePanelDebuggerApi;
|
|
181
193
|
loading?: SliceLoadingApi;
|
|
182
194
|
paths: SlicePaths;
|
|
183
195
|
_mode: SliceMode;
|