slicejs-cli 3.5.1 → 3.6.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.
Files changed (74) hide show
  1. package/README.md +34 -15
  2. package/client.js +67 -20
  3. package/commands/doctor/doctor.js +69 -3
  4. package/commands/getComponent/getComponent.js +33 -25
  5. package/commands/init/init.js +106 -28
  6. package/commands/utils/PackageManager.js +148 -0
  7. package/commands/utils/VersionChecker.js +6 -4
  8. package/commands/utils/sliceScripts.js +21 -0
  9. package/commands/utils/updateManager.js +54 -35
  10. package/package.json +12 -1
  11. package/post.js +8 -16
  12. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -29
  13. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -25
  14. package/.github/pull_request_template.md +0 -22
  15. package/.github/workflows/ci.yml +0 -43
  16. package/AGENTS.md +0 -247
  17. package/CODE_OF_CONDUCT.md +0 -126
  18. package/ECOSYSTEM.md +0 -9
  19. package/docs/superpowers/specs/2026-05-10-pwa-generate-design.md +0 -182
  20. package/playwright.config.js +0 -51
  21. package/tests/build-command-integration.test.js +0 -87
  22. package/tests/build-production-e2e.test.js +0 -140
  23. package/tests/builder-edge-cases.test.js +0 -322
  24. package/tests/bundle-generate-e2e.test.js +0 -115
  25. package/tests/bundle-generator.test.js +0 -691
  26. package/tests/bundle-v2-register-output.test.js +0 -470
  27. package/tests/bundling-dependency-edges.test.js +0 -127
  28. package/tests/bundling-imports-unit.test.js +0 -267
  29. package/tests/client-launcher-contract.test.js +0 -211
  30. package/tests/client-update-flow-contract.test.js +0 -272
  31. package/tests/commands-component-crud.test.js +0 -102
  32. package/tests/commands-doctor.test.js +0 -80
  33. package/tests/commands-version-checker.test.js +0 -37
  34. package/tests/component-registry-parse.test.js +0 -34
  35. package/tests/dependency-analyzer.test.js +0 -24
  36. package/tests/e2e/bundles.spec.js +0 -91
  37. package/tests/e2e/dependency-scenarios.spec.js +0 -56
  38. package/tests/e2e/fixtures/components/Service/FetchManager/FetchManager.js +0 -136
  39. package/tests/e2e/fixtures/components/Service/IndexedDbManager/IndexedDbManager.js +0 -149
  40. package/tests/e2e/fixtures/components/Service/LocalStorageManager/LocalStorageManager.js +0 -45
  41. package/tests/e2e/fixtures/components/Visual/Button/Button.css +0 -106
  42. package/tests/e2e/fixtures/components/Visual/Button/Button.html +0 -5
  43. package/tests/e2e/fixtures/components/Visual/Button/Button.js +0 -158
  44. package/tests/e2e/fixtures/components/Visual/Link/Link.js +0 -33
  45. package/tests/e2e/fixtures/components/Visual/Loading/Loading.css +0 -56
  46. package/tests/e2e/fixtures/components/Visual/Loading/Loading.html +0 -83
  47. package/tests/e2e/fixtures/components/Visual/Loading/Loading.js +0 -164
  48. package/tests/e2e/fixtures/components/Visual/MultiRoute/MultiRoute.js +0 -167
  49. package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.css +0 -116
  50. package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.html +0 -44
  51. package/tests/e2e/fixtures/components/Visual/Navbar/Navbar.js +0 -180
  52. package/tests/e2e/fixtures/components/Visual/NotFound/NotFound.js +0 -20
  53. package/tests/e2e/fixtures/components/Visual/Route/Route.js +0 -181
  54. package/tests/e2e/fixtures/components/registry.json +0 -12
  55. package/tests/e2e/fixtures/vendor-components.mjs +0 -65
  56. package/tests/e2e/navigation.spec.js +0 -44
  57. package/tests/e2e/render.spec.js +0 -34
  58. package/tests/e2e/serve.mjs +0 -264
  59. package/tests/e2e/shared-deps.spec.js +0 -61
  60. package/tests/e2e/unminified.spec.js +0 -33
  61. package/tests/e2e-serve.test.js +0 -148
  62. package/tests/fixtures/components.js +0 -8
  63. package/tests/fixtures/sliceConfig.json +0 -74
  64. package/tests/getcomponent.test.js +0 -407
  65. package/tests/helpers/setup.js +0 -102
  66. package/tests/init-command-contract.test.js +0 -46
  67. package/tests/local-cli-delegation.test.js +0 -81
  68. package/tests/path-helper.test.js +0 -206
  69. package/tests/perf-budget.test.js +0 -86
  70. package/tests/postinstall-command.test.js +0 -72
  71. package/tests/types-breakage.test.js +0 -491
  72. package/tests/types-generator-errors.test.js +0 -361
  73. package/tests/types-generator.test.js +0 -346
  74. package/tests/update-manager-notifications.test.js +0 -88
package/AGENTS.md DELETED
@@ -1,247 +0,0 @@
1
- # Slice.js CLI — Agent Context
2
-
3
- ## Project Structure
4
-
5
- ```
6
- slicejs-cli/
7
- ├── client.js # CLI entry point (commander)
8
- ├── commands/
9
- │ ├── init/init.js # slice init
10
- │ ├── startServer/startServer.js # slice dev / slice start
11
- │ ├── build/build.js # slice build
12
- │ ├── getComponent/getComponent.js # slice get / browse / sync
13
- │ ├── createComponent/ # slice component create
14
- │ ├── listComponents/ # slice component list
15
- │ ├── deleteComponent/ # slice component delete
16
- │ ├── doctor/doctor.js # slice doctor
17
- │ ├── types/types.js # slice types generate
18
- │ ├── bundle/bundle.js # bundling logic
19
- │ ├── utils/
20
- │ │ ├── PathHelper.js # Path resolution (critical)
21
- │ │ ├── bundling/BundleGenerator.js
22
- │ │ ├── updateManager.js
23
- │ │ ├── VersionChecker.js
24
- │ │ └── LocalCliDelegation.js
25
- │ └── Print.js # Wrapper for console.log/error
26
- ├── tests/
27
- │ ├── helpers/setup.js # Shared test helper (createTestProject, withTestProject)
28
- │ ├── fixtures/ # Minimal fixture files for tests
29
- │ ├── bundle-generator.test.js
30
- │ ├── bundle-v2-register-output.test.js
31
- │ ├── client-launcher-contract.test.js
32
- │ ├── client-update-flow-contract.test.js
33
- │ ├── component-registry-parse.test.js
34
- │ ├── dependency-analyzer.test.js
35
- │ ├── init-command-contract.test.js
36
- │ ├── local-cli-delegation.test.js
37
- │ ├── path-helper.test.js
38
- │ ├── postinstall-command.test.js
39
- │ ├── types-generator.test.js
40
- │ └── update-manager-notifications.test.js
41
- ├── package.json # type: "module" — ES modules only
42
- └── AGENTS.md # This file
43
- ```
44
-
45
- ## Testing System
46
-
47
- ### Runner
48
- - Uses Node.js built-in test runner: `node --test`
49
- - Run: `npm test`
50
- - Watch mode: `node --test --watch`
51
-
52
- ### Shared Test Helper (`tests/helpers/setup.js`)
53
- Three exported functions:
54
-
55
- ```js
56
- import { createTestProject, cleanupTestProject, withTestProject } from './helpers/setup.js';
57
- ```
58
-
59
- **`createTestProject(options)`** — Creates a temp directory with full Slice.js project scaffold.
60
- - Copies real framework files from `../slice.js/` (sibling directory in monorepo)
61
- - Falls back to `tests/fixtures/` minimal scaffold if framework not available
62
- - Options:
63
- - `visualComponents: ['Button']` — creates stub component files + rewrites `components.js` to include only those
64
- - `frameworkDir` — custom framework source path
65
- - Returns the temp directory path
66
- - Temp dir path: `{os.tmpdir()}/slice-test-{PID}-{N}-{random}/`
67
-
68
- **`cleanupTestProject(dir)`** — Removes the temp directory recursively.
69
-
70
- **`withTestProject(fn, options)`** — Convenience wrapper that:
71
- 1. Calls `createTestProject(options)`
72
- 2. Saves and sets `process.env.INIT_CWD = dir`
73
- 3. Runs `fn(dir)`
74
- 4. Restores `process.env.INIT_CWD` to original value
75
- 5. Calls `cleanupTestProject(dir)` in `finally`
76
-
77
- ### Patterns
78
-
79
- **For tests that need INIT_CWD pointing to the project:**
80
- ```js
81
- test('my test', async () => {
82
- await withTestProject(async (tmpDir) => {
83
- // process.env.INIT_CWD is already set to tmpDir
84
- const result = someFunction(import.meta.url);
85
- assert.ok(result);
86
- });
87
- });
88
- ```
89
-
90
- **For tests that pass projectRoot explicitly:**
91
- ```js
92
- test('my test', async () => {
93
- const tmpRoot = await createTestProject({ visualComponents: ['Button'] });
94
- try {
95
- const result = await someFunction({ projectRoot: tmpRoot });
96
- assert.equal(result, 1);
97
- } finally {
98
- await cleanupTestProject(tmpRoot);
99
- }
100
- });
101
- ```
102
-
103
- **For tests with shared project setup across a describe block:**
104
- ```js
105
- let tmpRoot;
106
- before(async () => {
107
- tmpRoot = await createTestProject();
108
- process.env.INIT_CWD = tmpRoot;
109
- });
110
- after(async () => {
111
- delete process.env.INIT_CWD;
112
- await cleanupTestProject(tmpRoot);
113
- });
114
- ```
115
-
116
- ### Test types
117
-
118
- 1. **Contract tests** (`*-contract.test.js`) — Static analysis of `client.js` source code via `@babel/parser` + AST or regex. Verify command registration, option flags, and function calls. No runtime execution.
119
- 2. **Unit tests** — Test individual functions/modules in isolation. Use temp dirs for filesystem-dependent code.
120
- 3. **Snapshot/Integration tests** — Verify output files, generated declarations, bundle configs.
121
-
122
- ### Rules
123
- - No external mocking libraries (sinon, jest, etc.). Use monkey-patching + try/finally restore.
124
- - All temp dirs MUST be cleaned up in `finally` blocks.
125
- - `process.env.INIT_CWD` must be saved before modification and restored in `finally`.
126
- - Dynamic `import()` is used where module caching matters, but PathHelper reads env vars at call time so cached modules work correctly.
127
-
128
- ## PathHelper Rules (`commands/utils/PathHelper.js`)
129
-
130
- ### Project Root Resolution
131
- `getProjectRoot(moduleUrl)` resolves in this order:
132
- 1. `process.env.INIT_CWD` — set by npm or by `withTestProject` during tests
133
- 2. `process.cwd()` — current working directory
134
- 3. `candidates(moduleUrl)` — heuristic: walk up `../../` and `../../../../` from module location, check for `src/` or `api/`
135
-
136
- ### Functions
137
-
138
- | Function | Returns | Notes |
139
- |---|---|---|
140
- | `getProjectRoot(moduleUrl)` | Resolved project root path | |
141
- | `getSrcPath(moduleUrl, ...seg)` | `<root>/src/[...seg]` | |
142
- | `getApiPath(moduleUrl, ...seg)` | `<root>/api/[...seg]` | |
143
- | `getDistPath(moduleUrl, ...seg)` | `<root>/dist/[...seg]` | |
144
- | `getPath(moduleUrl, ...seg)` | `<root>/[...seg]` | General purpose |
145
- | `getConfigPath(moduleUrl, root?)` | `src/sliceConfig.json` | Optional explicit root param |
146
- | `getComponentsJsPath(moduleUrl, root?)` | `src/Components/components.js` | Optional explicit root param |
147
- | `joinRoot(root, ...seg)` | `<root>/[...seg]` | No moduleUrl needed, pure path join |
148
-
149
- ### Critical Rules
150
-
151
- 1. **`import.meta.url` must be passed** as first argument to all PathHelper functions (except `joinRoot`).
152
- 2. **Explicit root parameter** (`getConfigPath`, `getComponentsJsPath`) is used by `types/types.js` when generating types for a non-cwd project. This keeps functions testable without global state.
153
- 3. **`INIT_CWD` is the primary mechanism** for project root resolution. It's set by npm lifecycle scripts and by `withTestProject`.
154
- 4. **`candidates()` fallback** only works when the CLI is installed inside a project that has `src/` or `api/`. This is intentionally limited.
155
-
156
- ## Code Quality Standards
157
-
158
- ### ES Modules Only
159
- - `"type": "module"` in `package.json`
160
- - Use `import`/`export` everywhere
161
- - NO `require()`, NO `__dirname` at module scope (use `path.dirname(fileURLToPath(import.meta.url))` inline where needed)
162
-
163
- ### No eval()
164
- - `eval()` has been fully replaced with `JSON.parse()` for reading `components.js` files
165
- - Components are written via `JSON.stringify()`, so content is always valid JSON
166
- - Use `JSON.parse()` or the AST-based `ComponentRegistry` for component registry parsing
167
-
168
- ### Error Messages
169
- - Bare error messages (just the error message without context) must NOT be used
170
- - Always wrap errors with context: `Print.error('Context:', error.message)`
171
- - Use `Print.error()` / `Print.success()` / `Print.info()` / `Print.warning()` instead of raw `console.log`/`console.error`
172
- - EXCEPTION: Formatted help/command listing output can use `console.log` directly (avoids `ℹ️ Info:` prefix pollution)
173
-
174
- ### Empty Catch Blocks
175
- - Silent catches are acceptable ONLY for:
176
- - Non-critical operations (update checks, optional config reads)
177
- - Graceful degradation paths
178
- - All silent catches MUST have a comment explaining why: `catch { /* intentional: non-critical */ }`
179
-
180
- ### Port Resolution (startServer)
181
- Priority order:
182
- 1. `--port` CLI flag (if provided by user)
183
- 2. `config.server.port` from `sliceConfig.json`
184
- 3. Hardcoded `3000` fallback
185
-
186
- Commander `.option()` defaults must NOT override config values. Pass `undefined` when flag is not provided:
187
- ```js
188
- port: options.port ? parseInt(options.port) : undefined
189
- ```
190
-
191
- ### Dependency Injection for Testability
192
- - Functions that need a project root accept it as a parameter (`projectRoot`, `root`)
193
- - PathHelper functions that accept an explicit root param enable testing without INIT_CWD gymnastics
194
- - Avoid reading `process.env.INIT_CWD` or `process.cwd()` directly inside business logic; use PathHelper
195
-
196
- ## CLI Architecture (client.js)
197
-
198
- ### Command Registration Pattern
199
- ```js
200
- sliceClient
201
- .command("mycommand")
202
- .description("...")
203
- .option("-x, --flag <value>", "...")
204
- .action(async (options) => {
205
- // 1. Handle --yes / non-interactive flags before prompts
206
- // 2. Prompt for missing required values
207
- // 3. Delegate to command implementation
208
- await runWithVersionCheck(async () => {
209
- await myCommandImplementation(options);
210
- });
211
- });
212
- ```
213
-
214
- ### `runWithVersionCheck(commandFunction)`
215
- - Wraps every command action
216
- - Responsibilities:
217
- 1. Fire-and-forget update notification (`notifyAvailableUpdates().catch(() => {})`)
218
- 2. Execute the command
219
- 3. Background version check (`checkForUpdates(false)` after 100ms delay)
220
- - Does NOT block or prompt the user (pre-flight checks were removed)
221
- - Errors are caught and logged via `Print.error()`
222
-
223
- ### Init Command (`slice init`)
224
- - Default project name: `my-slice-app`
225
- - `-y`/`--yes [name]` flag skips interactive prompts
226
- - Creates project directory, `chdir`s into it, sets `INIT_CWD`
227
- - Calls `initializeProject()` from `commands/init/init.js`
228
- - Name normalization: trim → lowercase → spaces to hyphens → strip non-alphanumeric → collapse hyphens → trim hyphens
229
-
230
- ### Local CLI Delegation
231
- - `maybeDelegateToLocalCli()` runs at module level before command parsing
232
- - If a local `node_modules/slicejs-cli/` exists, spawns it instead of running the global CLI
233
- - Controlled by `SLICE_NO_LOCAL_DELEGATION` env var
234
-
235
- ## Visual Component Registry
236
- - Components downloaded from GitHub: `https://raw.githubusercontent.com/VKneider/slice.js_visual_library/master/src/Components/{category}/{Name}/{file}`
237
- - Registry URL: same base + `src/Components/components.js`
238
- - Starter visual components on init: Button, Link, Loading, MultiRoute, Navbar, NotFound, Route
239
- - Components are registered by writing to `src/Components/components.js`
240
-
241
- ### File Download Rules (in `getAvailableComponents`)
242
- - **Routing/navigation components** (`Route`, `MultiRoute`, `Link`): only `.js` file
243
- - **Other Visual components** (Button, Loading, Navbar, etc.): `.js`, `.html`, `.css`
244
- - **Service components** (FetchManager, etc.): only `.js` file
245
- - File list is determined by hardcoded rules, NOT by checking the remote server
246
- - If `.js` download fails → component install fails (fatal)
247
- - If `.html`/`.css` fails → component install succeeds with warning
@@ -1,126 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our
6
- community a harassment-free experience for everyone, regardless of age, body
7
- size, visible or invisible disability, ethnicity, sex characteristics, gender
8
- identity and expression, level of experience, education, socio-economic status,
9
- nationality, personal appearance, race, caste, color, religion, or sexual
10
- identity and orientation.
11
-
12
- We pledge to act and interact in ways that contribute to an open, welcoming,
13
- diverse, inclusive, and healthy community.
14
-
15
- ## Our Standards
16
-
17
- Examples of behavior that contributes to a positive environment for our
18
- community include:
19
-
20
- * Demonstrating empathy and kindness toward other people
21
- * Being respectful of differing opinions, viewpoints, and experiences
22
- * Giving and gracefully accepting constructive feedback
23
- * Accepting responsibility and apologizing to those affected by our mistakes,
24
- and learning from the experience
25
- * Focusing on what is best not just for us as individuals, but for the
26
- overall community
27
-
28
- Examples of unacceptable behavior include:
29
-
30
- * The use of sexualized language or imagery, and sexual attention or
31
- advances of any kind
32
- * Trolling, insulting or derogatory comments, and personal or political attacks
33
- * Public or private harassment
34
- * Publishing others' private information, such as a physical or email
35
- address, without their explicit permission
36
- * Other conduct which could reasonably be considered inappropriate in a
37
- professional setting
38
-
39
- ## Enforcement Responsibilities
40
-
41
- Community leaders are responsible for clarifying and enforcing our standards of
42
- acceptable behavior and will take appropriate and fair corrective action in
43
- response to any behavior that they deem inappropriate, threatening, offensive,
44
- or harmful.
45
-
46
- Community leaders have the right and responsibility to remove, edit, or reject
47
- comments, commits, code, wiki edits, issues, and other contributions that are
48
- not aligned to this Code of Conduct, and will communicate reasons for moderation
49
- decisions when appropriate.
50
-
51
- ## Scope
52
-
53
- This Code of Conduct applies within all community spaces, and also applies when
54
- an individual is officially representing the community in public spaces.
55
- Examples of representing our community include using an official e-mail address,
56
- posting via an official social media account, or acting as an appointed
57
- representative at an online or offline event.
58
-
59
- ## Enforcement
60
-
61
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
- reported to Victor Kneider at vkneider.dev@gmail.com or via LinkedIn
63
- (https://www.linkedin.com/in/vkneider/). All complaints will be reviewed and investigated
64
- promptly and fairly.
65
-
66
- All community leaders are obligated to respect the privacy and security of the
67
- reporter of any incident.
68
-
69
- ## Enforcement Guidelines
70
-
71
- Community leaders will follow these Community Impact Guidelines in determining
72
- the consequences for any action they deem in violation of this Code of Conduct:
73
-
74
- ### 1. Correction
75
-
76
- **Community Impact**: Use of inappropriate language or other behavior deemed
77
- unprofessional or unwelcome in the community.
78
-
79
- **Consequence**: A private, written warning from community leaders, providing
80
- clarity around the nature of the violation and an explanation of why the
81
- behavior was inappropriate. A public apology may be requested.
82
-
83
- ### 2. Warning
84
-
85
- **Community Impact**: A violation through a single incident or series of
86
- actions.
87
-
88
- **Consequence**: A warning with consequences for continued behavior. No
89
- interaction with the people involved, including unsolicited interaction with
90
- those enforcing the Code of Conduct, for a specified period of time. This
91
- includes avoiding interactions in community spaces as well as external channels
92
- like social media. Violating these terms may lead to a temporary or permanent
93
- ban.
94
-
95
- ### 3. Temporary Ban
96
-
97
- **Community Impact**: A serious violation of community standards, including
98
- sustained inappropriate behavior.
99
-
100
- **Consequence**: A temporary ban from any sort of interaction or public
101
- communication with the community for a specified period of time. No public or
102
- private interaction with the people involved, including unsolicited interaction
103
- with those enforcing the Code of Conduct, is allowed during this period.
104
- Violating these terms may lead to a permanent ban.
105
-
106
- ### 4. Permanent Ban
107
-
108
- **Community Impact**: Demonstrating a pattern of violation of community
109
- standards, including sustained inappropriate behavior, harassment of an
110
- individual, or aggression toward or disparagement of classes of individuals.
111
-
112
- **Consequence**: A permanent ban from any sort of public interaction within
113
- the community.
114
-
115
- ## Attribution
116
-
117
- This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org),
118
- version 2.1, available at
119
- https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
120
-
121
- Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
- enforcement ladder](https://github.com/mozilla/diversity).
123
-
124
- For answers to common questions about this code of conduct, see the FAQ at
125
- https://www.contributor-covenant.org/faq. Translations are available at
126
- https://www.contributor-covenant.org/translations.
package/ECOSYSTEM.md DELETED
@@ -1,9 +0,0 @@
1
- # Slice.js Ecosystem
2
-
3
- | Repository | Description | URL |
4
- |---|---|---|
5
- | slice.js | Core web framework | https://github.com/VKneider/slice.js |
6
- | slice-cli | CLI tool for project management | https://github.com/VKneider/slicejs-cli |
7
- | slice.js_visual_library | Official visual components and docs | https://github.com/VKneider/slice.js_visual_library |
8
- | sliceDocs | Framework documentation site | https://github.com/VKneider/slicejs_docs |
9
- | PortfolioVK2 | Portfolio and demo app | https://github.com/VKneider/portfolio |
@@ -1,182 +0,0 @@
1
- # Design of `slice generate-pwa` (V1)
2
-
3
- ## Objective
4
-
5
- Add a dedicated CLI command, `slice generate-pwa`, that converts a Slice build into an offline-capable PWA, with configurable cache strategy and explicit backend domain exclusion to prevent accidental REST API caching.
6
-
7
- The command must be post-bundle, operate on `dist/`, and maintain a simple V1 experience.
8
-
9
- ## V1 Scope
10
-
11
- - New `slice generate-pwa` command.
12
- - Automatically run `build` before the PWA process.
13
- - Generate `manifest.json` in `dist/`.
14
- - Generate `sw.js` in `dist/`.
15
- - Register Service Worker in the entry HTML of `dist`.
16
- - Support strategies: `hybrid` (default), `offline-first`, `network-first`.
17
- - Persist and read configuration from `src/sliceConfig.json` in:
18
- - `pwa.cache.excludeDomains`.
19
- - Apply effective exclusion of `localhost` and `127.0.0.1` in development.
20
-
21
- ## Out of V1 Scope
22
-
23
- - Exclusion by paths or headers (`excludePaths`, `excludeHeaders`).
24
- - Advanced interactive UI for creating PWA icons.
25
- - Support for push notifications, background sync, or advanced runtime caching by API type.
26
- - Formal plugin system; left prepared for future evolution.
27
-
28
- ## Command UX
29
-
30
- ### Syntax
31
-
32
- ```bash
33
- slice generate-pwa
34
- slice generate-pwa --strategy hybrid
35
- slice generate-pwa --strategy offline-first
36
- slice generate-pwa --strategy network-first
37
- slice generate-pwa --name "My App" --short-name "MyApp"
38
- ```
39
-
40
- ### V1 Flags
41
-
42
- - `--strategy <hybrid|offline-first|network-first>` (default: `hybrid`)
43
- - `--name <string>`
44
- - `--short-name <string>`
45
-
46
- ### Execution flow
47
-
48
- 1. Run production build.
49
- 2. Read and normalize PWA configuration from `src/sliceConfig.json`.
50
- 3. Generate asset manifest for precache from `dist/`.
51
- 4. Generate `dist/manifest.json`.
52
- 5. Generate `dist/sw.js` with the selected strategy.
53
- 6. Inject (or ensure) SW registration in entry HTML of `dist`.
54
- 7. Print final summary:
55
- - strategy used,
56
- - number of precached assets,
57
- - effective excluded domains.
58
-
59
- ## Configuration in `sliceConfig.json`
60
-
61
- V1 minimal section:
62
-
63
- ```json
64
- {
65
- "pwa": {
66
- "cache": {
67
- "excludeDomains": []
68
- }
69
- }
70
- }
71
- ```
72
-
73
- Rules:
74
-
75
- - If `pwa` does not exist, the command creates the section without breaking existing configuration.
76
- - `excludeDomains` accepts exact hosts (e.g., `api.mydomain.com`).
77
- - In development execution, `localhost` and `127.0.0.1` are effectively added (not necessarily persisted).
78
-
79
- ## Proposed Architecture
80
-
81
- ### CLI Integration
82
-
83
- - Add command in `client.js`:
84
- - `generate-pwa`
85
- - `--strategy` option
86
- - name options for manifest
87
-
88
- ### New Modules
89
-
90
- - `commands/pwa/generatePwa.js`
91
- - Orchestrator of the complete flow.
92
- - `commands/pwa/ConfigResolver.js`
93
- - Reads/creates/normalizes `pwa.cache.excludeDomains`.
94
- - `commands/pwa/AssetManifestBuilder.js`
95
- - Iterates `dist/` and builds precache list.
96
- - `commands/pwa/ManifestGenerator.js`
97
- - Generates `manifest.json` with defaults and flag overrides.
98
- - `commands/pwa/ServiceWorkerGenerator.js`
99
- - Generates `sw.js` with selected strategy and exclusions.
100
-
101
- ## Cache Design
102
-
103
- ### Global Rules
104
-
105
- - Intercept only `GET` requests.
106
- - If the host is in `excludeDomains`, do a direct `fetch` (no cache).
107
- - Cache versioning by build id (timestamp or build hash).
108
- - On new SW activation, automatically clean old caches.
109
-
110
- ### Strategies
111
-
112
- - `hybrid` (default):
113
- - static assets -> `cache-first`.
114
- - HTML navigation -> `network-first` with offline fallback.
115
- - `offline-first`:
116
- - navigation + static -> `cache-first`.
117
- - background update when online.
118
- - `network-first`:
119
- - navigation -> `network-first`.
120
- - precached static assets as fallback.
121
-
122
- ## REST API and Security Handling
123
-
124
- To prevent unwanted backend caching:
125
-
126
- - Domain exclusion via `excludeDomains` (main V1 rule).
127
- - Limit runtime cache to frontend assets and navigation per strategy.
128
- - Do not cache methods other than `GET`.
129
-
130
- Result: client assets are accelerated offline, but the backend stays out of the cache via explicit configuration.
131
-
132
- ## Error handling
133
-
134
- - If build fails, abort `generate-pwa` with a clear message.
135
- - If `dist/` does not exist after build, abort with diagnostics.
136
- - If `sliceConfig.json` is invalid, show error with repair suggestion.
137
- - If SW registration cannot be injected into HTML, report warning and target path.
138
-
139
- ## Testing
140
-
141
- ### Unit tests
142
-
143
- - `ConfigResolver`:
144
- - creates `pwa.cache.excludeDomains` section when it does not exist,
145
- - respects existing config.
146
- - `AssetManifestBuilder`:
147
- - includes expected assets,
148
- - excludes unsuitable files.
149
- - `ServiceWorkerGenerator`:
150
- - generates correct logic per strategy,
151
- - respects `excludeDomains`.
152
-
153
- ### Integration
154
-
155
- - `slice generate-pwa` runs build and creates `dist/manifest.json` + `dist/sw.js`.
156
- - SW registration present in output HTML.
157
- - domain exclusions applied in generated code.
158
-
159
- ### Minimal E2E manual
160
-
161
- - Build + generate-pwa.
162
- - Open app, validate installability (manifest).
163
- - Turn off network, validate offline navigation in `hybrid`.
164
- - Verify that requests to excluded domain are not served from SW cache.
165
-
166
- ## Evolution Plan (post V1)
167
-
168
- - `excludePaths` and `excludeHeaders`.
169
- - Assisted PWA icon and shortcut support.
170
- - Per-route strategy (e.g., `/api/*` network-only).
171
- - Extract reusable postbundle pipeline for other features.
172
-
173
- ## Acceptance Criteria
174
-
175
- - Functional `slice generate-pwa` command exists.
176
- - Runs build before generating PWA artifacts.
177
- - Generates `manifest.json` and `sw.js` in `dist/`.
178
- - Registers SW in main output HTML.
179
- - `hybrid` is default with HTML `network-first` and offline fallback.
180
- - Reads/writes `pwa.cache.excludeDomains` in `src/sliceConfig.json`.
181
- - Excludes configured domains from runtime cache.
182
- - Shows a readable final summary to the user.
@@ -1,51 +0,0 @@
1
- import { defineConfig, devices } from '@playwright/test';
2
-
3
- const PORT = process.env.E2E_PORT ? Number(process.env.E2E_PORT) : 3210;
4
- const UNMIN_PORT = PORT + 4;
5
- const BASE_URL = `http://127.0.0.1:${PORT}`;
6
- const UNMIN_URL = `http://127.0.0.1:${UNMIN_PORT}`;
7
-
8
- export default defineConfig({
9
- testDir: './tests/e2e',
10
- testMatch: '**/*.spec.js',
11
- fullyParallel: false,
12
- workers: 1,
13
- timeout: 30_000,
14
- expect: { timeout: 10_000 },
15
- reporter: process.env.CI ? [['list'], ['html', { open: 'never' }]] : [['list']],
16
- use: {
17
- trace: 'retain-on-failure',
18
- },
19
- projects: [
20
- {
21
- name: 'chromium',
22
- testIgnore: '**/unminified.spec.js',
23
- use: { ...devices['Desktop Chrome'], baseURL: BASE_URL },
24
- },
25
- {
26
- name: 'chromium-unminified',
27
- testMatch: '**/unminified.spec.js',
28
- use: { ...devices['Desktop Chrome'], baseURL: UNMIN_URL },
29
- },
30
- ],
31
- webServer: [
32
- {
33
- command: 'node tests/e2e/serve.mjs',
34
- url: `${BASE_URL}/slice-env.json`,
35
- env: { E2E_PORT: String(PORT) },
36
- timeout: 120_000,
37
- reuseExistingServer: !process.env.CI,
38
- stdout: 'pipe',
39
- stderr: 'pipe',
40
- },
41
- {
42
- command: 'node tests/e2e/serve.mjs',
43
- url: `${UNMIN_URL}/slice-env.json`,
44
- env: { E2E_PORT: String(UNMIN_PORT), E2E_MINIFY: 'false' },
45
- timeout: 120_000,
46
- reuseExistingServer: !process.env.CI,
47
- stdout: 'pipe',
48
- stderr: 'pipe',
49
- },
50
- ],
51
- });