slicejs-web-framework 4.0.1 → 4.1.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/Slice/Components/Structural/Router/Router.js +27 -0
- package/Slice/Components/Structural/Router/applyRouteMetadata.js +39 -0
- package/Slice/Components/Structural/StylesManager/ThemeManager/ThemeManager.js +15 -2
- package/Slice/Slice.js +31 -7
- package/api/framework/precompressedStatic.js +10 -1
- package/api/framework/seo.js +387 -0
- package/api/framework/server.js +432 -65
- package/api/index.js +17 -7
- package/package.json +53 -49
- package/.opencode/opencode.json +0 -15
- package/Slice/tests/build-bundled-component-without-category.test.js +0 -103
- package/Slice/tests/build-js-only-visual-components.test.js +0 -144
- package/Slice/tests/build-singleton.test.js +0 -244
- package/Slice/tests/bundle-v2-runtime-contract.test.js +0 -738
- package/Slice/tests/context-patch-use.test.js +0 -95
- package/Slice/tests/destroy-cascade.test.js +0 -215
- package/Slice/tests/event-emitters.test.js +0 -79
- package/Slice/tests/event-registry.test.js +0 -141
- package/Slice/tests/fixtures/real-runtime-loader.mjs +0 -21
- package/Slice/tests/leak-orphans.test.js +0 -131
- package/Slice/tests/props-allowed-values-validation.test.js +0 -119
- package/Slice/tests/public-env-runtime-accessors.test.js +0 -44
- package/Slice/tests/public-env-typed-accessors.test.js +0 -66
- package/Slice/tests/router-loading-finally.test.js +0 -68
- package/api/tests/dev-deps-optimizer.test.js +0 -137
- package/api/tests/dev-server-external.test.js +0 -56
- package/api/tests/precompressed-static.test.js +0 -119
- package/api/tests/public-env-resolver.test.js +0 -193
- package/tests/router-emit-ordering.test.js +0 -63
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { tmpdir } from 'node:os';
|
|
6
|
-
|
|
7
|
-
const resolverModulePath = new URL('../framework/publicEnvResolver.js', import.meta.url);
|
|
8
|
-
|
|
9
|
-
async function withTempEnvFile(contents, callback) {
|
|
10
|
-
const dir = await mkdtemp(path.join(tmpdir(), 'slice-public-env-'));
|
|
11
|
-
const envFilePath = path.join(dir, '.env');
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
await writeFile(envFilePath, contents, 'utf8');
|
|
15
|
-
await callback(envFilePath);
|
|
16
|
-
} finally {
|
|
17
|
-
await rm(dir, { recursive: true, force: true });
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
test('resolvePublicEnv filters only SLICE_PUBLIC_ keys', async () => {
|
|
22
|
-
const { resolvePublicEnv } = await import(resolverModulePath.href);
|
|
23
|
-
|
|
24
|
-
await withTempEnvFile(
|
|
25
|
-
['SLICE_PUBLIC_FROM_FILE=file-visible', 'PRIVATE_KEY=hidden-file-value', 'SLICE_API_URL=hidden-file-api-url'].join('\n'),
|
|
26
|
-
async (envFilePath) => {
|
|
27
|
-
const payload = resolvePublicEnv({
|
|
28
|
-
mode: 'development',
|
|
29
|
-
envFilePath,
|
|
30
|
-
processEnv: {
|
|
31
|
-
SLICE_PUBLIC_FROM_PROCESS: 'process-visible',
|
|
32
|
-
SECRET_TOKEN: 'hidden-process-token',
|
|
33
|
-
NODE_ENV: 'development',
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
assert.equal(payload.mode, 'development');
|
|
38
|
-
assert.deepEqual(payload.env, {
|
|
39
|
-
SLICE_PUBLIC_FROM_FILE: 'file-visible',
|
|
40
|
-
SLICE_PUBLIC_FROM_PROCESS: 'process-visible',
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('resolvePublicEnv uses process.env values over .env values', async () => {
|
|
47
|
-
const { resolvePublicEnv } = await import(resolverModulePath.href);
|
|
48
|
-
|
|
49
|
-
await withTempEnvFile('SLICE_PUBLIC_API_URL=https://from-file.example', async (envFilePath) => {
|
|
50
|
-
const payload = resolvePublicEnv({
|
|
51
|
-
mode: 'development',
|
|
52
|
-
envFilePath,
|
|
53
|
-
processEnv: {
|
|
54
|
-
SLICE_PUBLIC_API_URL: 'https://from-process.example',
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
assert.equal(payload.mode, 'development');
|
|
59
|
-
assert.equal(payload.env.SLICE_PUBLIC_API_URL, 'https://from-process.example');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('resolvePublicEnv warns about suspicious public key names without exposing values', async () => {
|
|
64
|
-
const { resolvePublicEnv } = await import(resolverModulePath.href);
|
|
65
|
-
const warnings = [];
|
|
66
|
-
const logger = {
|
|
67
|
-
warn: (...args) => warnings.push(args.map(String).join(' ')),
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
await withTempEnvFile('SLICE_PUBLIC_API_KEY=super-secret-value', async (envFilePath) => {
|
|
71
|
-
const payload = resolvePublicEnv({
|
|
72
|
-
mode: 'development',
|
|
73
|
-
envFilePath,
|
|
74
|
-
processEnv: {},
|
|
75
|
-
logger,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
assert.equal(payload.mode, 'development');
|
|
79
|
-
assert.equal(payload.env.SLICE_PUBLIC_API_KEY, 'super-secret-value');
|
|
80
|
-
assert.equal(warnings.length, 1);
|
|
81
|
-
assert.match(warnings[0], /SLICE_PUBLIC_API_KEY/);
|
|
82
|
-
assert.doesNotMatch(warnings[0], /super-secret-value/);
|
|
83
|
-
});
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('resolvePublicEnv warns once when suspicious key appears in .env and processEnv', async () => {
|
|
87
|
-
const { resolvePublicEnv } = await import(resolverModulePath.href);
|
|
88
|
-
const warnings = [];
|
|
89
|
-
const logger = {
|
|
90
|
-
warn: (...args) => warnings.push(args.map(String).join(' ')),
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
await withTempEnvFile('SLICE_PUBLIC_API_KEY=from-file-secret', async (envFilePath) => {
|
|
94
|
-
const payload = resolvePublicEnv({
|
|
95
|
-
mode: 'development',
|
|
96
|
-
envFilePath,
|
|
97
|
-
processEnv: {
|
|
98
|
-
SLICE_PUBLIC_API_KEY: 'from-process-secret',
|
|
99
|
-
},
|
|
100
|
-
logger,
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
assert.equal(payload.env.SLICE_PUBLIC_API_KEY, 'from-process-secret');
|
|
104
|
-
assert.equal(warnings.length, 1);
|
|
105
|
-
assert.match(warnings[0], /SLICE_PUBLIC_API_KEY/);
|
|
106
|
-
assert.doesNotMatch(warnings[0], /from-file-secret|from-process-secret/);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('resolvePublicEnv parses first key when .env starts with BOM', async () => {
|
|
111
|
-
const { resolvePublicEnv } = await import(resolverModulePath.href);
|
|
112
|
-
|
|
113
|
-
await withTempEnvFile('\uFEFFSLICE_PUBLIC_TITLE=Slice App', async (envFilePath) => {
|
|
114
|
-
const payload = resolvePublicEnv({
|
|
115
|
-
mode: 'development',
|
|
116
|
-
envFilePath,
|
|
117
|
-
processEnv: {},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
assert.equal(payload.env.SLICE_PUBLIC_TITLE, 'Slice App');
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test('resolvePublicEnv strips inline comments for unquoted values', async () => {
|
|
125
|
-
const { resolvePublicEnv } = await import(resolverModulePath.href);
|
|
126
|
-
|
|
127
|
-
await withTempEnvFile('SLICE_PUBLIC_ORIGIN=https://slice.dev # dev origin', async (envFilePath) => {
|
|
128
|
-
const payload = resolvePublicEnv({
|
|
129
|
-
mode: 'development',
|
|
130
|
-
envFilePath,
|
|
131
|
-
processEnv: {},
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
assert.equal(payload.env.SLICE_PUBLIC_ORIGIN, 'https://slice.dev');
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test('resolvePublicEnv strips trailing comments after quoted values', async () => {
|
|
139
|
-
const { resolvePublicEnv } = await import(resolverModulePath.href);
|
|
140
|
-
|
|
141
|
-
await withTempEnvFile('SLICE_PUBLIC_X="value" # comment', async (envFilePath) => {
|
|
142
|
-
const payload = resolvePublicEnv({
|
|
143
|
-
mode: 'development',
|
|
144
|
-
envFilePath,
|
|
145
|
-
processEnv: {},
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
assert.equal(payload.env.SLICE_PUBLIC_X, 'value');
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
test('createPublicEnvProvider caches in production and recomputes in development', async () => {
|
|
153
|
-
const { createPublicEnvProvider } = await import(resolverModulePath.href);
|
|
154
|
-
|
|
155
|
-
await withTempEnvFile('SLICE_PUBLIC_COUNTER=from-file', async (envFilePath) => {
|
|
156
|
-
let processValue = 'first-value';
|
|
157
|
-
const processEnv = {
|
|
158
|
-
get SLICE_PUBLIC_COUNTER() {
|
|
159
|
-
return processValue;
|
|
160
|
-
},
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const productionProvider = createPublicEnvProvider({
|
|
164
|
-
mode: 'production',
|
|
165
|
-
envFilePath,
|
|
166
|
-
processEnv,
|
|
167
|
-
});
|
|
168
|
-
assert.equal(typeof productionProvider.getPayload, 'function');
|
|
169
|
-
|
|
170
|
-
const firstProduction = productionProvider.getPayload();
|
|
171
|
-
processValue = 'second-value';
|
|
172
|
-
const secondProduction = productionProvider.getPayload();
|
|
173
|
-
|
|
174
|
-
assert.equal(firstProduction.mode, 'production');
|
|
175
|
-
assert.equal(firstProduction.env.SLICE_PUBLIC_COUNTER, 'first-value');
|
|
176
|
-
assert.equal(secondProduction.env.SLICE_PUBLIC_COUNTER, 'first-value');
|
|
177
|
-
|
|
178
|
-
const developmentProvider = createPublicEnvProvider({
|
|
179
|
-
mode: 'development',
|
|
180
|
-
envFilePath,
|
|
181
|
-
processEnv,
|
|
182
|
-
});
|
|
183
|
-
assert.equal(typeof developmentProvider.getPayload, 'function');
|
|
184
|
-
|
|
185
|
-
const firstDevelopment = developmentProvider.getPayload();
|
|
186
|
-
processValue = 'third-value';
|
|
187
|
-
const secondDevelopment = developmentProvider.getPayload();
|
|
188
|
-
|
|
189
|
-
assert.equal(firstDevelopment.mode, 'development');
|
|
190
|
-
assert.equal(firstDevelopment.env.SLICE_PUBLIC_COUNTER, 'second-value');
|
|
191
|
-
assert.equal(secondDevelopment.env.SLICE_PUBLIC_COUNTER, 'third-value');
|
|
192
|
-
});
|
|
193
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// Regression test for GOTCHAS §3: router:change must not be observable before
|
|
2
|
-
// slice.router.activeRoute is updated.
|
|
3
|
-
//
|
|
4
|
-
// Router is a plain class with no module-level DOM/global access and no imports,
|
|
5
|
-
// so onRouteChange() can be exercised directly on a stubbed instance. The fix
|
|
6
|
-
// makes onRouteChange() resolve only AFTER the debounced handleRoute() runs
|
|
7
|
-
// (which is where activeRoute is set), so a caller that awaits it — like
|
|
8
|
-
// _performNavigation — emits router:change with activeRoute already current.
|
|
9
|
-
//
|
|
10
|
-
// Run: node --test tests/router-emit-ordering.test.js
|
|
11
|
-
|
|
12
|
-
import { test, describe, before } from 'node:test';
|
|
13
|
-
import assert from 'node:assert/strict';
|
|
14
|
-
|
|
15
|
-
describe('Router.onRouteChange (§3 emit-after-activeRoute)', () => {
|
|
16
|
-
let Router;
|
|
17
|
-
|
|
18
|
-
before(async () => {
|
|
19
|
-
globalThis.window = globalThis.window || { location: { pathname: '/' } };
|
|
20
|
-
globalThis.slice = globalThis.slice || { logger: { error() {} }, router: {} };
|
|
21
|
-
({ default: Router } = await import('../Slice/Components/Structural/Router/Router.js'));
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const makeRouter = (handleRoute) => {
|
|
25
|
-
const r = Object.create(Router.prototype);
|
|
26
|
-
r.renderRoutesComponentsInPage = async () => false; // not the MultiRoute container path
|
|
27
|
-
r.matchRoute = () => ({ route: { component: 'X' }, params: {} });
|
|
28
|
-
r.handleRoute = handleRoute;
|
|
29
|
-
return r;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
test('awaiting onRouteChange() waits until handleRoute() has finished', async () => {
|
|
33
|
-
const order = [];
|
|
34
|
-
const r = makeRouter(async () => {
|
|
35
|
-
await new Promise((res) => setTimeout(res, 5)); // simulate async render
|
|
36
|
-
order.push('handleRoute-done'); // activeRoute is assigned here in the real code
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
await r.onRouteChange();
|
|
40
|
-
order.push('after-await');
|
|
41
|
-
|
|
42
|
-
// With the fix, handleRoute completes BEFORE the await returns. (Before the
|
|
43
|
-
// fix the awaited promise resolved the instant the timer was scheduled, so
|
|
44
|
-
// 'after-await' would land first — i.e. emit-before-activeRoute.)
|
|
45
|
-
assert.deepEqual(order, ['handleRoute-done', 'after-await']);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('a superseded (debounced) call still resolves — no hang', async () => {
|
|
49
|
-
let handled = 0;
|
|
50
|
-
const r = makeRouter(async () => { handled++; });
|
|
51
|
-
|
|
52
|
-
const p1 = r.onRouteChange(); // schedules timer T1
|
|
53
|
-
const p2 = r.onRouteChange(); // clears T1, resolves p1, schedules T2
|
|
54
|
-
|
|
55
|
-
await Promise.race([
|
|
56
|
-
Promise.all([p1, p2]),
|
|
57
|
-
new Promise((_, rej) => setTimeout(() => rej(new Error('onRouteChange hung')), 1000)),
|
|
58
|
-
]);
|
|
59
|
-
|
|
60
|
-
// Only the surviving timer runs its work.
|
|
61
|
-
assert.equal(handled, 1);
|
|
62
|
-
});
|
|
63
|
-
});
|