goaljs 0.1.0 → 0.1.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/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  A compiled JavaScript framework where **`var` is state** and **`let`/`const` are computed**. Pages are
4
4
  rendered on the server and the browser **resumes** them instead of hydrating: no component code runs at
5
- load, and each component's code (at most **1 KB gzipped**) loads on its first event. Components reach the
6
- server through **server functions**, with no `async` and no `fetch`. It is **secure by default**.
5
+ load, and each component's code, in a small chunk of its own, loads on its first event. Components
6
+ reach the server through **server functions**, with no `async` and no `fetch`. It is **secure by
7
+ default**.
7
8
 
8
9
  **Documentation: <https://goallabs.github.io/goal/>**
9
10
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "goaljs",
3
- "version": "0.1.0",
4
- "description": "goal.js: var is state, let/const are computed, SSR + resumable, 1 KB per component",
3
+ "version": "0.1.1",
4
+ "description": "goal.js: var is state, let/const are computed, server-rendered and resumable",
5
5
  "homepage": "https://goallabs.github.io/goal/",
6
6
  "repository": {
7
7
  "type": "git",
package/src/build.js CHANGED
@@ -17,7 +17,6 @@ import { desugar } from './syntax.js';
17
17
  import { loaderScript } from './server.js';
18
18
  import { createApp } from './app.js';
19
19
 
20
- export const BUDGET = 1024; // gzipped bytes per component chunk, and for the loader
21
20
 
22
21
  const SRC = dirname(fileURLToPath(import.meta.url));
23
22
  const RT = pathToFileURL(join(SRC, 'rt.js')).href;
@@ -61,12 +60,12 @@ const entriesPlugin = (entries) => {
61
60
  };
62
61
 
63
62
  /**
64
- * Compiles an app into dist/. Throws on a compile error, a duplicate route, or a chunk over budget.
63
+ * Compiles an app into dist/. Throws on a compile error or a duplicate route.
65
64
  * `dev` keeps chunks readable with source maps back to the .goal files; otherwise they are minified
66
65
  * and the source stays on the server. `publicPath` is where the site is served from.
67
66
  * @returns {Promise<{ version: string, chunks: { url: string, bytes: number, gzip: number }[], loader: number, routes: string[] }>}
68
67
  */
69
- export async function build(app, { out = join(app, 'dist'), budget = BUDGET, dev = false, publicPath = '/' } = {}) {
68
+ export async function build(app, { out = join(app, 'dist'), dev = false, publicPath = '/' } = {}) {
70
69
  const version = Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
71
70
  const chunks = [];
72
71
  const routes = [];
@@ -129,7 +128,7 @@ export async function build(app, { out = join(app, 'dist'), budget = BUDGET, dev
129
128
  const to = posix.relative(from, '_/keyed.js');
130
129
  return f.text.replaceAll(`"${KEYED}"`, JSON.stringify(to.startsWith('.') ? to : './' + to));
131
130
  };
132
- const files = (await bundle(true)).map((f) => ({ path: f.path, text: link(f) })); // the budget is for what production ships
131
+ const files = (await bundle(true)).map((f) => ({ path: f.path, text: link(f) })); // the sizes reported are what production ships
133
132
  for (const f of dev ? (await bundle(false)).map((f) => ({ path: f.path, text: link(f) })) : files) write(f.path, f.text);
134
133
  for (const f of files) {
135
134
  const rel = relative(resolve(out, 'client'), f.path).split(sep).join('/');
@@ -142,10 +141,7 @@ export async function build(app, { out = join(app, 'dist'), budget = BUDGET, dev
142
141
  `export default [${routeFiles.map((_, i) => `...r${i}`).join(', ')}];\n`,
143
142
  );
144
143
  if (existsSync(join(app, 'public'))) cpSync(join(app, 'public'), join(out, 'public'), { recursive: true });
145
- const loader = gzipSync(loaderScript()).length;
146
- const over = [...chunks, { url: 'the loader', gzip: loader }].filter((c) => c.gzip > budget);
147
- if (over.length) throw new Error(over.map((c) => `${c.url} is ${c.gzip} B gzipped, over the ${budget} B budget`).join('\n'));
148
- return { version, chunks, loader, routes: routes.map((r) => r.label) };
144
+ return { version, chunks, loader: gzipSync(loaderScript()).length, routes: routes.map((r) => r.label) };
149
145
  }
150
146
 
151
147
  /** Serves a built app. `dev` shows error details; `version` names the build to load. */
package/src/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // goal build [app] | goal start [app] [--port N] | goal dev [app] [--port N]
2
2
 
3
- import { build, serve, dev, BUDGET } from './build.js';
3
+ import { build, serve, dev } from './build.js';
4
4
 
5
5
  const USAGE = 'usage: goal build|start|dev [app folder] [--port 3000]';
6
6
 
@@ -13,7 +13,7 @@ export async function main(argv, log = console.log) {
13
13
  try {
14
14
  const r = await build(app);
15
15
  for (const route of r.routes) log(route);
16
- for (const c of r.chunks) log(`${c.url} ${c.bytes} B, ${c.gzip} B gzipped (budget ${BUDGET})`);
16
+ for (const c of r.chunks) log(`${c.url} ${c.bytes} B, ${c.gzip} B gzipped`);
17
17
  log(`loader ${r.loader} B gzipped, inline`);
18
18
  return 0;
19
19
  } catch (e) {
package/src/compiler.js CHANGED
@@ -965,7 +965,7 @@ function propKeys(fn) {
965
965
  return keys;
966
966
  }
967
967
 
968
- /** Removes imports and helper functions the component doesn't use, so they don't count toward its 1 KB. */
968
+ /** Removes imports and helper functions the component doesn't use, so they don't ship. */
969
969
  function prune(prog, keep) {
970
970
  for (let removed = true; removed; ) {
971
971
  removed = false;