redweb 0.16.1 → 0.16.2
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/CHANGELOG.md +7 -0
- package/README.md +9 -7
- package/docs/CLI.md +9 -3
- package/docs/DEVELOPMENT.md +1 -1
- package/docs/GETTING_STARTED.md +23 -3
- package/docs/MIGRATION.md +1 -1
- package/docs/RELEASE_TRUST.md +4 -4
- package/docs/RUNTIME_DIAGNOSTICS.md +1 -1
- package/docs/SOCKET_CONTRACTS.md +2 -2
- package/docs/generated.json +220 -220
- package/docs/releases/0.16.2.json +2286 -0
- package/package.json +1 -1
- package/recipes/foundation/README.md +7 -0
- package/recipes/foundation/app.test.cjs +15 -0
- package/recipes/foundation/app.tsx +12 -0
- package/src/cli/ProjectInitializer.js +1 -1
- package/src/cli/arguments.js +21 -9
- package/src/cli/run.js +12 -3
- package/src/cli/templates.js +37 -24
- package/src/docs/Documentation.js +14 -4
package/package.json
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Neutral application foundation
|
|
2
|
+
|
|
3
|
+
The default initializer creates a working TypeScript/TSX application without choosing a product domain. Replace `HomePage` with your pages, then add socket routes and application services as needed.
|
|
4
|
+
|
|
5
|
+
Use `--with auth,multiplayer` when the project needs those dependency sets. `auth` adds Express, Zod, their TypeScript declarations, and the Node version required by Redweb's native-SQLite authentication path. `multiplayer` adds Redweb Client and Zod. Capabilities adjust the manifest without copying dashboard, chat, counter, or match-example source. Use an explicit `--template` only when you want a complete example walkthrough.
|
|
6
|
+
|
|
7
|
+
Run `npm test` for the real HTTP and lifecycle checks. Pass `--bare` only when you intentionally do not want the test directory, test scripts, or test-only coverage dependency; the runnable source, assets, build scripts, and development setup stay the same.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const { listen } = require('./network.cjs');
|
|
4
|
+
|
|
5
|
+
test('neutral application foundation serves real HTML and CSS', { timeout: 10000 }, async t => {
|
|
6
|
+
const origin = await listen(t);
|
|
7
|
+
const response = await fetch(origin);
|
|
8
|
+
assert.equal(response.status, 200);
|
|
9
|
+
const document = await response.text();
|
|
10
|
+
assert.match(document, /<h1>Redweb is ready\.<\/h1>/);
|
|
11
|
+
const css = document.match(/<link rel="stylesheet" href="([^"]+)"/)[1];
|
|
12
|
+
const stylesheet = await fetch(`${origin}${css}`);
|
|
13
|
+
assert.equal(stylesheet.status, 200);
|
|
14
|
+
assert.match(await stylesheet.text(), /\.home/);
|
|
15
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineApp, page } from 'redweb';
|
|
2
|
+
|
|
3
|
+
@page('/', { live: false, css: 'app.css' })
|
|
4
|
+
export class HomePage {
|
|
5
|
+
render() {
|
|
6
|
+
return <main class="home"><h1>Redweb is ready.</h1><p>Replace this page with your application.</p></main>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const app = defineApp({ pages: [HomePage], port: Number(process.env.PORT ?? 8181), templateRoot: __dirname });
|
|
11
|
+
|
|
12
|
+
if (require.main === module) app.run();
|
|
@@ -11,7 +11,7 @@ class ProjectInitializer {
|
|
|
11
11
|
|
|
12
12
|
initialize(target, options = {}) {
|
|
13
13
|
const root = path.resolve(target);
|
|
14
|
-
const templateFiles = projectFiles(this.version, options.template);
|
|
14
|
+
const templateFiles = projectFiles(this.version, options.template ?? null, undefined, options);
|
|
15
15
|
const files = options.existing ? templateFiles.filter(file => file.path === 'tsconfig.json') : templateFiles;
|
|
16
16
|
return new FilePlan(root, files).write({ dryRun: options.dryRun });
|
|
17
17
|
}
|
package/src/cli/arguments.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const { TEMPLATES } = require('./templates');
|
|
3
|
+
const { CAPABILITIES, TEMPLATES } = require('./templates');
|
|
4
4
|
const { KINDS } = require('./ProjectAddition');
|
|
5
5
|
|
|
6
6
|
const USAGE = [
|
|
7
|
-
`Usage: redweb init [directory] [--template ${TEMPLATES.join('|')}] [--existing] [--dry-run] [--json]`,
|
|
7
|
+
`Usage: redweb init [directory] [--with ${CAPABILITIES.join(',')}] [--template ${TEMPLATES.join('|')}] [--bare] [--existing] [--dry-run] [--json]`,
|
|
8
8
|
' redweb doctor [directory] [--port number] [--json]',
|
|
9
9
|
` redweb add <${KINDS.join('|')}> <name> [directory] [--config file] [--source-dir dir] [--test-dir dir] [--dry-run] [--json]`,
|
|
10
10
|
' redweb --help | --version',
|
|
11
11
|
'',
|
|
12
|
-
'--existing creates only a missing tsconfig.json; no starter or package changes.',
|
|
12
|
+
'--existing creates only a missing tsconfig.json; no starter or package changes.',
|
|
13
|
+
'--with adds neutral capability dependencies without generating example-domain code.',
|
|
14
|
+
'--bare omits generated tests; templates remain explicit examples.',
|
|
13
15
|
'--dry-run reports planned files without writing anything.',
|
|
14
16
|
'doctor inspects configuration without executing application code or repairing files.',
|
|
15
17
|
].join('\n') + '\n';
|
|
@@ -18,7 +20,7 @@ function parseArguments(args) {
|
|
|
18
20
|
const [command = '--help', ...rest] = args;
|
|
19
21
|
if (['--help', '-h', '--version'].includes(command) && !rest.length) return { command };
|
|
20
22
|
if (!['init', 'doctor', 'add'].includes(command)) throw new Error('Unknown command. Run redweb --help.');
|
|
21
|
-
const result = { command, target: '.', existing: false, dryRun: false, json: false, port: null };
|
|
23
|
+
const result = { command, target: '.', existing: false, dryRun: false, json: false, port: null };
|
|
22
24
|
if (command === 'add') {
|
|
23
25
|
result.kind = rest.shift();
|
|
24
26
|
result.name = rest.shift();
|
|
@@ -37,25 +39,35 @@ function parseArguments(args) {
|
|
|
37
39
|
if (seen.has(value)) throw new Error(`Duplicate option: ${value}`);
|
|
38
40
|
seen.add(value);
|
|
39
41
|
if (value === '--json') result.json = true;
|
|
40
|
-
else if (value === '--existing' && command === 'init') result.existing = true;
|
|
42
|
+
else if (value === '--existing' && command === 'init') result.existing = true;
|
|
43
|
+
else if (value === '--bare' && command === 'init') result.bare = true;
|
|
41
44
|
else if (value === '--dry-run' && ['init', 'add'].includes(command)) result.dryRun = true;
|
|
42
45
|
else if (command === 'add' && ['--config', '--source-dir', '--test-dir'].includes(value)) {
|
|
43
46
|
const argument = rest[++i];
|
|
44
47
|
if (!argument || argument.startsWith('-')) throw new Error(`${value} requires a path.`);
|
|
45
48
|
result[{ '--config': 'configFile', '--source-dir': 'sourceDir', '--test-dir': 'testDir' }[value]] = argument;
|
|
46
49
|
}
|
|
47
|
-
else if (value === '--template' && command === 'init') {
|
|
50
|
+
else if (value === '--template' && command === 'init') {
|
|
48
51
|
const template = rest[++i];
|
|
49
52
|
if (!TEMPLATES.includes(template)) throw new Error(`--template must be one of: ${TEMPLATES.join(', ')}.`);
|
|
50
|
-
result.template = template;
|
|
51
|
-
}
|
|
53
|
+
result.template = template;
|
|
54
|
+
}
|
|
55
|
+
else if (value === '--with' && command === 'init') {
|
|
56
|
+
const raw = rest[++i];
|
|
57
|
+
if (!raw || raw.startsWith('-')) throw new Error('--with requires a comma-separated capability list.');
|
|
58
|
+
const capabilities = raw.split(',');
|
|
59
|
+
if (capabilities.some(capability => !CAPABILITIES.includes(capability)) || new Set(capabilities).size !== capabilities.length) {
|
|
60
|
+
throw new Error(`--with must contain unique capabilities from: ${CAPABILITIES.join(', ')}.`);
|
|
61
|
+
}
|
|
62
|
+
result.with = capabilities;
|
|
63
|
+
}
|
|
52
64
|
else if (value === '--port' && command === 'doctor') {
|
|
53
65
|
const port = rest[++i];
|
|
54
66
|
if (!/^\d+$/.test(port) || Number(port) > 65535) throw new Error('--port must be an integer from 0 through 65535.');
|
|
55
67
|
result.port = Number(port);
|
|
56
68
|
} else throw new Error(`Unknown option for ${command}: ${value}`);
|
|
57
69
|
}
|
|
58
|
-
if (result.existing && result.template) throw new Error('--existing
|
|
70
|
+
if (result.existing && (result.template || result.with || result.bare)) throw new Error('--existing cannot be combined with --template, --with, or --bare.');
|
|
59
71
|
return result;
|
|
60
72
|
}
|
|
61
73
|
|
package/src/cli/run.js
CHANGED
|
@@ -36,9 +36,18 @@ async function run(args, cwd, version) {
|
|
|
36
36
|
return { exitCode: 0, stdout: `${output}\n`, stderr: '' };
|
|
37
37
|
}
|
|
38
38
|
const result = new ProjectInitializer(version).initialize(root, options);
|
|
39
|
-
const report = {
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const report = {
|
|
40
|
+
schemaVersion: 1,
|
|
41
|
+
operation: 'init',
|
|
42
|
+
dryRun: options.dryRun,
|
|
43
|
+
foundation: options.template ?? 'default',
|
|
44
|
+
capabilities: options.with ?? [],
|
|
45
|
+
tests: !options.bare,
|
|
46
|
+
...result,
|
|
47
|
+
};
|
|
48
|
+
const output = options.json ? JSON.stringify(report) : [
|
|
49
|
+
`${options.dryRun ? 'Planned initialization' : 'Initialization complete'} in ${result.root}`,
|
|
50
|
+
`Foundation: ${options.template ? `example template "${options.template}"` : 'neutral default'}; capabilities: ${options.with?.join(', ') || 'base'}; tests: ${options.bare ? 'omitted' : 'included'}.`,
|
|
42
51
|
`Created: ${result.created.join(', ')}`,
|
|
43
52
|
`Kept existing: ${result.skipped.join(', ')}`,
|
|
44
53
|
`Planned: ${result.planned.join(', ')}`,
|
package/src/cli/templates.js
CHANGED
|
@@ -3,11 +3,18 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
const json = value => `${JSON.stringify(value, null, 2)}\n`;
|
|
7
|
-
const TEMPLATES = Object.freeze(['realtime', 'chat', 'site', 'socket', 'dashboard', 'http-ws']);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const json = value => `${JSON.stringify(value, null, 2)}\n`;
|
|
7
|
+
const TEMPLATES = Object.freeze(['realtime', 'chat', 'site', 'socket', 'dashboard', 'http-ws']);
|
|
8
|
+
const CAPABILITIES = Object.freeze(['auth', 'multiplayer']);
|
|
9
|
+
|
|
10
|
+
function projectFiles(version, template = null, root = path.resolve(__dirname, '../..'), options = {}) {
|
|
11
|
+
if (template !== null && !TEMPLATES.includes(template)) throw new Error('Unknown starter template.');
|
|
12
|
+
if (options.with !== undefined && !Array.isArray(options.with)) throw new TypeError('Initializer capabilities must be an array.');
|
|
13
|
+
const capabilities = new Set(options.with || []);
|
|
14
|
+
if ([...capabilities].some(capability => !CAPABILITIES.includes(capability))) throw new Error('Unknown initializer capability.');
|
|
15
|
+
const selected = template ?? 'foundation';
|
|
16
|
+
const authenticated = template === 'dashboard' || capabilities.has('auth');
|
|
17
|
+
const multiplayer = capabilities.has('multiplayer');
|
|
11
18
|
const { devDependencies, dependencies, overrides } = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
|
|
12
19
|
const read = relative => fs.readFileSync(path.join(root, 'recipes', relative), 'utf8');
|
|
13
20
|
const manifest = {
|
|
@@ -16,18 +23,22 @@ function projectFiles(version, template = 'realtime', root = path.resolve(__dirn
|
|
|
16
23
|
build: 'tsc && node scripts/copy-assets.cjs',
|
|
17
24
|
start: 'node dist/app.js',
|
|
18
25
|
dev: 'nodemon',
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
...(!options.bare ? {
|
|
27
|
+
test: 'npm run build && node --test test/app.test.cjs test/lifecycle.test.cjs',
|
|
28
|
+
'test:coverage': 'npm run build && c8 --all --src=dist --include=dist/** --reporter=text --reporter=json node --test test/app.test.cjs test/lifecycle.test.cjs',
|
|
29
|
+
} : {}),
|
|
21
30
|
},
|
|
22
31
|
dependencies: {
|
|
23
32
|
redweb: `^${version}`,
|
|
24
|
-
...(['chat', 'socket', 'dashboard'].includes(template) ? { zod: devDependencies.zod } : {}),
|
|
25
|
-
...(
|
|
33
|
+
...(['chat', 'socket', 'dashboard'].includes(template) || authenticated || multiplayer ? { zod: devDependencies.zod } : {}),
|
|
34
|
+
...(authenticated ? { express: dependencies.express } : {}),
|
|
35
|
+
...(multiplayer ? { 'redweb-client': dependencies['redweb-client'] } : {}),
|
|
26
36
|
},
|
|
27
37
|
overrides,
|
|
28
38
|
devDependencies: {
|
|
29
|
-
typescript: devDependencies.typescript, nodemon: devDependencies.nodemon, ws: dependencies.ws,
|
|
30
|
-
...(
|
|
39
|
+
typescript: devDependencies.typescript, nodemon: devDependencies.nodemon, ws: dependencies.ws,
|
|
40
|
+
...(!options.bare ? { c8: devDependencies.c8 } : {}),
|
|
41
|
+
...(authenticated ? {
|
|
31
42
|
'@types/node': devDependencies['redweb-dashboard-types'].replace('npm:@types/node@', ''),
|
|
32
43
|
'@types/express': dependencies['@types/express'],
|
|
33
44
|
} : {}),
|
|
@@ -40,10 +51,10 @@ function projectFiles(version, template = 'realtime', root = path.resolve(__dirn
|
|
|
40
51
|
delay: 200,
|
|
41
52
|
},
|
|
42
53
|
};
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
manifest.scripts['add-user'] = 'npm run build && node dist/admin.js';
|
|
46
|
-
manifest.scripts['test:coverage'] += ' test/rate-window.test.cjs';
|
|
54
|
+
if (authenticated) manifest.engines = { node: '>=22.13.0' };
|
|
55
|
+
if (template === 'dashboard') {
|
|
56
|
+
manifest.scripts['add-user'] = 'npm run build && node dist/admin.js';
|
|
57
|
+
if (!options.bare) manifest.scripts['test:coverage'] += ' test/rate-window.test.cjs';
|
|
47
58
|
}
|
|
48
59
|
const files = [
|
|
49
60
|
{ path: 'package.json', content: json(manifest) },
|
|
@@ -52,13 +63,15 @@ function projectFiles(version, template = 'realtime', root = path.resolve(__dirn
|
|
|
52
63
|
compilerOptions: { rootDir: 'src', outDir: 'dist', sourceMap: true },
|
|
53
64
|
include: ['src/**/*.ts', 'src/**/*.tsx'],
|
|
54
65
|
}) },
|
|
55
|
-
{ path: 'src/app.tsx', content: read(`${
|
|
56
|
-
{ path: 'src/app.css', content: read(`${
|
|
57
|
-
{ path: 'scripts/copy-assets.cjs', content: read('shared/copy-assets.cjs') },
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
{ path: 'src/app.tsx', content: read(`${selected}/app.tsx`) },
|
|
67
|
+
{ path: 'src/app.css', content: read(`${selected === 'dashboard' ? selected : 'shared'}/app.css`) },
|
|
68
|
+
{ path: 'scripts/copy-assets.cjs', content: read('shared/copy-assets.cjs') },
|
|
69
|
+
...(!options.bare ? [
|
|
70
|
+
{ path: 'test/network.cjs', content: read('shared/network.cjs') },
|
|
71
|
+
{ path: 'test/app.test.cjs', content: read(`${selected}/app.test.cjs`) },
|
|
72
|
+
{ path: 'test/lifecycle.test.cjs', content: read('shared/lifecycle.test.cjs') },
|
|
73
|
+
] : []),
|
|
74
|
+
{ path: 'README.md', content: `${read('shared/README.md')}\n${read(`${selected}/README.md`)}` },
|
|
62
75
|
{ path: '.gitignore', content: 'node_modules/\ndist/\ncoverage/\n.env\ndata/\n*.sqlite\n*.sqlite-wal\n*.sqlite-shm\n' },
|
|
63
76
|
];
|
|
64
77
|
if (template === 'chat') {
|
|
@@ -75,7 +88,7 @@ function projectFiles(version, template = 'realtime', root = path.resolve(__dirn
|
|
|
75
88
|
}
|
|
76
89
|
if (template === 'dashboard') {
|
|
77
90
|
files.push({ path: '.npmrc', content: 'engine-strict=true\n' });
|
|
78
|
-
files.push({ path: 'test/rate-window.test.cjs', content: read('dashboard/rate-window.test.cjs') });
|
|
91
|
+
if (!options.bare) files.push({ path: 'test/rate-window.test.cjs', content: read('dashboard/rate-window.test.cjs') });
|
|
79
92
|
for (const name of ['store.ts', 'auth.ts', 'cards.tsx', 'admin.ts']) {
|
|
80
93
|
files.push({ path: `src/${name}`, content: read(`dashboard/${name}`) });
|
|
81
94
|
}
|
|
@@ -83,4 +96,4 @@ function projectFiles(version, template = 'realtime', root = path.resolve(__dirn
|
|
|
83
96
|
return Object.freeze(files.map(Object.freeze));
|
|
84
97
|
}
|
|
85
98
|
|
|
86
|
-
module.exports = { projectFiles, TEMPLATES };
|
|
99
|
+
module.exports = { projectFiles, CAPABILITIES, TEMPLATES };
|
|
@@ -77,8 +77,8 @@ class Documentation {
|
|
|
77
77
|
: `> Documentation for Redweb ${this.channel}. Install that exact version when following these examples.`;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
setup(template) {
|
|
81
|
-
if (!TEMPLATES.includes(template)) throw new Error('Unknown starter template.');
|
|
80
|
+
setup(template) {
|
|
81
|
+
if (!TEMPLATES.includes(template)) throw new Error('Unknown starter template.');
|
|
82
82
|
const acceptance = `${template === 'dashboard' ? 'npm run add-user -- alice\n' : ''}npm test\nnpm run dev`;
|
|
83
83
|
return this.channel === 'unreleased'
|
|
84
84
|
? [
|
|
@@ -86,8 +86,18 @@ class Documentation {
|
|
|
86
86
|
fence(`npx --yes --package TARBALL redweb init my-${template} --template ${template}\ncd my-${template}\nnpm install --save-exact TARBALL\n${acceptance}`, 'sh'),
|
|
87
87
|
'This prerelease Redweb artifact is development-only until its release checks finish. For released applications, use an available versioned release guide.',
|
|
88
88
|
].join('\n\n')
|
|
89
|
-
: fence(`npx --yes redweb@${this.channel} init my-${template} --template ${template}\ncd my-${template}\nnpm install --save-exact redweb@${this.channel}\n${acceptance}`, 'sh');
|
|
90
|
-
}
|
|
89
|
+
: fence(`npx --yes redweb@${this.channel} init my-${template} --template ${template}\ncd my-${template}\nnpm install --save-exact redweb@${this.channel}\n${acceptance}`, 'sh');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
foundationSetup() {
|
|
93
|
+
return this.channel === 'unreleased'
|
|
94
|
+
? [
|
|
95
|
+
'Replace `TARBALL` with the absolute path to the matching Redweb tarball produced by `npm pack` (quoted if it contains spaces):',
|
|
96
|
+
fence('npx --yes --package TARBALL redweb init my-app\ncd my-app\nnpm install --save-exact TARBALL\nnpm test\nnpm run dev', 'sh'),
|
|
97
|
+
'This prerelease Redweb artifact is development-only until its release checks finish.',
|
|
98
|
+
].join('\n\n')
|
|
99
|
+
: fence(`npx --yes redweb@${this.channel} init my-app\ncd my-app\nnpm install --save-exact redweb@${this.channel}\nnpm test\nnpm run dev`, 'sh');
|
|
100
|
+
}
|
|
91
101
|
|
|
92
102
|
recipe(template) {
|
|
93
103
|
const files = projectFiles(this.manifest.version, template, this.root).map(file => ({ ...file, content: normalize(file.content) }));
|