slicejs-cli 3.5.0 → 3.5.1
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/.github/workflows/ci.yml +43 -0
- package/commands/createComponent/createComponent.js +6 -2
- package/commands/deleteComponent/deleteComponent.js +4 -0
- package/commands/doctor/doctor.js +9 -0
- package/commands/utils/bundling/BundleGenerator.js +271 -38
- package/package.json +4 -1
- package/playwright.config.js +51 -0
- package/tests/build-command-integration.test.js +87 -0
- package/tests/build-production-e2e.test.js +140 -0
- package/tests/builder-edge-cases.test.js +322 -0
- package/tests/bundle-generate-e2e.test.js +115 -0
- package/tests/bundling-dependency-edges.test.js +127 -0
- package/tests/bundling-imports-unit.test.js +267 -0
- package/tests/commands-component-crud.test.js +102 -0
- package/tests/commands-doctor.test.js +80 -0
- package/tests/commands-version-checker.test.js +37 -0
- package/tests/component-registry-parse.test.js +1 -1
- package/tests/e2e/bundles.spec.js +91 -0
- package/tests/e2e/dependency-scenarios.spec.js +56 -0
- package/tests/e2e/fixtures/components/Service/FetchManager/FetchManager.js +136 -0
- package/tests/e2e/fixtures/components/Service/IndexedDbManager/IndexedDbManager.js +149 -0
- package/tests/e2e/fixtures/components/Service/LocalStorageManager/LocalStorageManager.js +45 -0
- package/tests/e2e/fixtures/components/Visual/Button/Button.css +106 -0
- package/tests/e2e/fixtures/components/Visual/Button/Button.html +5 -0
- package/tests/e2e/fixtures/components/Visual/Button/Button.js +158 -0
- package/tests/e2e/fixtures/components/Visual/Link/Link.js +33 -0
- package/tests/e2e/fixtures/components/Visual/Loading/Loading.css +56 -0
- package/tests/e2e/fixtures/components/Visual/Loading/Loading.html +83 -0
- package/tests/e2e/fixtures/components/Visual/Loading/Loading.js +164 -0
- package/tests/e2e/fixtures/components/Visual/MultiRoute/MultiRoute.js +167 -0
- package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.css +116 -0
- package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.html +44 -0
- package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.js +180 -0
- package/tests/e2e/fixtures/components/Visual/NotFound/NotFound.js +20 -0
- package/tests/e2e/fixtures/components/Visual/Route/Route.js +181 -0
- package/tests/e2e/fixtures/components/registry.json +12 -0
- package/tests/e2e/fixtures/vendor-components.mjs +65 -0
- package/tests/e2e/navigation.spec.js +44 -0
- package/tests/e2e/render.spec.js +34 -0
- package/tests/e2e/serve.mjs +264 -0
- package/tests/e2e/shared-deps.spec.js +61 -0
- package/tests/e2e/unminified.spec.js +33 -0
- package/tests/e2e-serve.test.js +148 -0
- package/tests/helpers/setup.js +6 -1
- package/tests/perf-budget.test.js +86 -0
- package/tests/types-generator.test.js +2 -0
package/tests/helpers/setup.js
CHANGED
|
@@ -4,7 +4,12 @@ import os from 'os'
|
|
|
4
4
|
import { fileURLToPath } from 'url'
|
|
5
5
|
|
|
6
6
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
7
|
-
|
|
7
|
+
// Prefer the sibling framework dev repo when present (local monorepo checkout);
|
|
8
|
+
// otherwise fall back to the installed framework package (e.g. CI, where only
|
|
9
|
+
// this repo is checked out). Both ship the same src/ + api/ starter structure.
|
|
10
|
+
const SIBLING_FW = path.resolve(__dirname, '../../../slice.js')
|
|
11
|
+
const PACKAGE_FW = path.resolve(__dirname, '../../node_modules/slicejs-web-framework')
|
|
12
|
+
const FW_DIR = fs.pathExistsSync(SIBLING_FW) ? SIBLING_FW : PACKAGE_FW
|
|
8
13
|
const FIXTURES_DIR = path.resolve(__dirname, '../fixtures')
|
|
9
14
|
|
|
10
15
|
let counter = 0
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { test } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import fs from 'fs-extra';
|
|
6
|
+
import { createTestProject, cleanupTestProject } from './helpers/setup.js';
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const FIXTURES = path.resolve(__dirname, 'e2e/fixtures/components');
|
|
10
|
+
const FW_PKG = path.resolve(__dirname, '../node_modules/slicejs-web-framework');
|
|
11
|
+
|
|
12
|
+
// Performance budgets for the realistic starter app (App Shell + the vendored
|
|
13
|
+
// starter components). Bundle byte sizes are fully deterministic, so a surprise
|
|
14
|
+
// failure here means a change degraded the output — review it, and only bump a
|
|
15
|
+
// budget when the growth is intentional. (Actuals shown for reference.)
|
|
16
|
+
const BUDGET = {
|
|
17
|
+
bundleCount: 5, // actual: 4
|
|
18
|
+
totalBundleBytes: 165_000, // actual: ~133.6 KB
|
|
19
|
+
criticalBytes: 51_200, // actual: ~40.8 KB (bundler's own critical cap is 50 KB)
|
|
20
|
+
frameworkBytes: 85_000, // actual: ~67.4 KB (tracks the slicejs-web-framework package)
|
|
21
|
+
buildMs: 30_000, // actual: ~1 s — generous ceiling to catch pathological slowdowns
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
async function assembleAndBuild() {
|
|
25
|
+
process.env.NODE_ENV = 'production';
|
|
26
|
+
const app = await createTestProject();
|
|
27
|
+
|
|
28
|
+
await fs.ensureDir(path.join(app, 'node_modules'));
|
|
29
|
+
await fs
|
|
30
|
+
.ensureSymlink(FW_PKG, path.join(app, 'node_modules', 'slicejs-web-framework'), 'dir')
|
|
31
|
+
.catch(() => fs.copy(FW_PKG, path.join(app, 'node_modules', 'slicejs-web-framework')));
|
|
32
|
+
|
|
33
|
+
await fs.copy(path.join(FIXTURES, 'Visual'), path.join(app, 'src', 'Components', 'Visual'));
|
|
34
|
+
await fs.copy(path.join(FIXTURES, 'Service'), path.join(app, 'src', 'Components', 'Service'));
|
|
35
|
+
|
|
36
|
+
process.env.INIT_CWD = app;
|
|
37
|
+
(await import('../commands/listComponents/listComponents.js')).default();
|
|
38
|
+
|
|
39
|
+
const build = (await import('../commands/build/build.js')).default;
|
|
40
|
+
const start = Date.now();
|
|
41
|
+
const ok = await build({ minify: true, obfuscate: true });
|
|
42
|
+
const buildMs = Date.now() - start;
|
|
43
|
+
assert.equal(ok, true, 'build should succeed');
|
|
44
|
+
return { app, buildMs };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test('production build stays within performance budgets', async () => {
|
|
48
|
+
const { app, buildMs } = await assembleAndBuild();
|
|
49
|
+
try {
|
|
50
|
+
const bundlesDir = path.join(app, 'dist', 'bundles');
|
|
51
|
+
const files = (await fs.readdir(bundlesDir)).filter(
|
|
52
|
+
(f) => f.startsWith('slice-bundle.') && f.endsWith('.js')
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const sizes = {};
|
|
56
|
+
let totalBundleBytes = 0;
|
|
57
|
+
for (const f of files) {
|
|
58
|
+
sizes[f] = (await fs.stat(path.join(bundlesDir, f))).size;
|
|
59
|
+
totalBundleBytes += sizes[f];
|
|
60
|
+
}
|
|
61
|
+
const cfg = await fs.readJson(path.join(bundlesDir, 'bundle.config.json'));
|
|
62
|
+
const criticalBytes = sizes['slice-bundle.critical.js'] || 0;
|
|
63
|
+
const frameworkBytes = sizes['slice-bundle.framework.js'] || 0;
|
|
64
|
+
|
|
65
|
+
// Always print the metrics so trends are visible even on a passing run.
|
|
66
|
+
console.log(
|
|
67
|
+
`\n [perf] bundles=${files.length} total=${Math.round(totalBundleBytes / 1024)}KB ` +
|
|
68
|
+
`critical=${Math.round(criticalBytes / 1024)}KB framework=${Math.round(frameworkBytes / 1024)}KB ` +
|
|
69
|
+
`requestReduction=${100 - Math.round((files.length / cfg.stats.totalComponents) * 100)}% build=${buildMs}ms`
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
assert.ok(files.length <= BUDGET.bundleCount, `bundle count ${files.length} exceeds budget ${BUDGET.bundleCount}`);
|
|
73
|
+
assert.ok(
|
|
74
|
+
totalBundleBytes <= BUDGET.totalBundleBytes,
|
|
75
|
+
`total bundle bytes ${totalBundleBytes} exceeds budget ${BUDGET.totalBundleBytes}`
|
|
76
|
+
);
|
|
77
|
+
assert.ok(criticalBytes <= BUDGET.criticalBytes, `critical bundle ${criticalBytes} exceeds budget ${BUDGET.criticalBytes}`);
|
|
78
|
+
assert.ok(frameworkBytes <= BUDGET.frameworkBytes, `framework bundle ${frameworkBytes} exceeds budget ${BUDGET.frameworkBytes}`);
|
|
79
|
+
assert.ok(buildMs <= BUDGET.buildMs, `build took ${buildMs}ms, over budget ${BUDGET.buildMs}ms`);
|
|
80
|
+
|
|
81
|
+
// Sanity: the realistic app actually bundled its full component set.
|
|
82
|
+
assert.ok(cfg.stats.totalComponents >= 20, `unexpectedly few components bundled: ${cfg.stats.totalComponents}`);
|
|
83
|
+
} finally {
|
|
84
|
+
await cleanupTestProject(app);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
@@ -160,7 +160,9 @@ test('generateTypesFile creates declaration file from local components', async (
|
|
|
160
160
|
const serviceDir = path.join(srcDir, 'Components', 'Service', 'FetchManager');
|
|
161
161
|
const outputFile = path.join(srcDir, 'slice-build.generated.d.ts');
|
|
162
162
|
|
|
163
|
+
fs.mkdirSync(visualDir, { recursive: true });
|
|
163
164
|
fs.mkdirSync(noStaticDir, { recursive: true });
|
|
165
|
+
fs.mkdirSync(serviceDir, { recursive: true });
|
|
164
166
|
|
|
165
167
|
fs.writeFileSync(
|
|
166
168
|
path.join(visualDir, 'Button.js'),
|