goaljs 0.5.0 → 0.7.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/README.md CHANGED
@@ -46,10 +46,12 @@ npx goal dev . # build the app in this folder, serve it on http://localho
46
46
  also cover [routes](https://goallabs.github.io/goal/routes),
47
47
  [components](https://goallabs.github.io/goal/components),
48
48
  [server functions](https://goallabs.github.io/goal/server-functions),
49
+ [types](https://goallabs.github.io/goal/types),
49
50
  [security](https://goallabs.github.io/goal/security),
50
51
  [how it works](https://goallabs.github.io/goal/how-it-works),
51
- [performance](https://goallabs.github.io/goal/performance), and working in
52
- [Vite](https://goallabs.github.io/goal/vite).
52
+ [performance](https://goallabs.github.io/goal/performance), working in
53
+ [Vite](https://goallabs.github.io/goal/vite), and [tools](https://goallabs.github.io/goal/tools):
54
+ `goal add` sets up Tailwind CSS, Prisma, Drizzle, ESLint, Prettier, Vitest, Playwright and Sentry.
53
55
 
54
56
  ## Working on goal.js
55
57
 
@@ -58,10 +60,12 @@ npm install
58
60
  npm run demo # builds examples/demo, serves it on http://localhost:3000, updates live on save
59
61
  npm test # the tests, with 100% coverage of src/ required
60
62
  npm run bench:virtual # a 100,000-row virtual list in headless Chrome: speed and memory
63
+ npm run test:recipes # sets up each goal add recipe in a new app, for real, and tests it
61
64
  ```
62
65
 
63
66
  The docs site is the `docs/` folder, published by GitHub Pages. `editors/vscode` is the VS Code
64
- extension.
67
+ extension. `recipes/` holds the `goal add` recipes: pull requests that add a tool or a version are
68
+ welcome (see [recipes/README.md](recipes/README.md)).
65
69
 
66
70
  ## License
67
71
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goaljs",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
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": {
@@ -14,7 +14,8 @@
14
14
  "test": "vitest run --coverage",
15
15
  "build:demo": "node bin/goal.js build examples/demo",
16
16
  "demo": "node bin/goal.js dev examples/demo",
17
- "bench:virtual": "node bench/virtual.mjs"
17
+ "bench:virtual": "node bench/virtual.mjs",
18
+ "test:recipes": "node test/recipes/run.mjs"
18
19
  },
19
20
  "keywords": [
20
21
  "framework",
@@ -28,7 +29,8 @@
28
29
  "type": "module",
29
30
  "files": [
30
31
  "bin",
31
- "src"
32
+ "src",
33
+ "recipes"
32
34
  ],
33
35
  "dependencies": {
34
36
  "@babel/generator": "^8.1.3",
@@ -62,6 +64,7 @@
62
64
  "./loader": "./src/loader.js",
63
65
  "./build": "./src/build.js",
64
66
  "./keyed": "./src/keyed.js",
65
- "./vite": "./src/vite.js"
67
+ "./vite": "./src/vite.js",
68
+ "./eslint": "./src/eslint.js"
66
69
  }
67
70
  }
@@ -0,0 +1,100 @@
1
+ # goal add recipes
2
+
3
+ `goal add <tool>` sets a tool up in a goal.js app. This folder holds one recipe per tool. A recipe is
4
+ plain data: which packages to install, and what the app needs around them. Tool maintainers and users
5
+ are welcome to send pull requests that update a recipe for a new version, or add a tool.
6
+
7
+ ## A recipe
8
+
9
+ `recipes/<tool>.js` exports the recipe as its default export:
10
+
11
+ ```js
12
+ export default {
13
+ name: 'tailwindcss', // goal add tailwindcss
14
+ aliases: ['tailwind'], // other names goal add takes (optional)
15
+ package: 'tailwindcss', // the package whose version picks the entry
16
+ about: 'Tailwind CSS: utility classes, compiled into public/style.css',
17
+ docs: 'https://tailwindcss.com/docs',
18
+ versions: [
19
+ // Newest first. goal add uses the first entry, unless the app already has the package
20
+ // (its version picks the entry) or the version is asked for: goal add tailwindcss@3.
21
+ {
22
+ range: '4',
23
+ devDependencies: { tailwindcss: '4.3.5', '@tailwindcss/postcss': '4.3.5', postcss: '8.5.33' },
24
+ files: { 'postcss.config.js': 'export default { ... };\n' },
25
+ prepend: { 'public/style.css': ['@import "tailwindcss" source("..");'] },
26
+ lines: { '.gitignore': ['node_modules', 'dist'] },
27
+ next: ['Link the stylesheet from your pages: <link rel="stylesheet" href="/style.css" />'],
28
+ test: { run: ['npx goal build .', 'node -e "..."'] },
29
+ },
30
+ { range: '3', ... },
31
+ ],
32
+ };
33
+ ```
34
+
35
+ Each entry can have:
36
+
37
+ | Key | What `goal add` does with it |
38
+ | --- | --- |
39
+ | `range` | The versions of `package` the entry is for: `4`, `4.x`, `>=0.45 <1`, `3 \|\| 4`. |
40
+ | `dependencies`, `devDependencies` | Installs each package the app doesn't have yet, at the exact version given: the one you tested. npm saves it as a `^` range. |
41
+ | `files` | Writes each file, unless the app has it. If the app's differs, it's kept, and the recipe's is printed. |
42
+ | `prepend`, `lines` | Adds each line the file doesn't have yet, at its start or its end, and makes the file if it isn't there. `KEY=value` lines compare by key, so a `.env` keeps its values. `dist` and `/dist/` count as the same line. |
43
+ | `scripts` | Adds each `package.json` script the app doesn't have. |
44
+ | `config` | Adds keys to `goal.config.js`'s exported object, with an import: `{ import: "import { onError } from './sentry.js';", keys: { onError: 'onError' } }`. Each value is code. |
45
+ | `run` | Commands to run once, in the app's folder, after all of the above, such as `npx prisma generate`. |
46
+ | `next` | What to tell the user to do next. The recipe's `docs` link is added. |
47
+ | `test` | For `npm run test:recipes` only: `files` to add to the test app, then `run`, commands that must all succeed. |
48
+
49
+ `goal add` also sets `"type": "module"` in `package.json`, so write config files as ES modules.
50
+
51
+ ## What a goal.js app is like
52
+
53
+ Keep these in mind when you write files for an app:
54
+
55
+ - `.goal` files hold routes and components. Server code (routes and server functions) can import `.js`
56
+ files and npm packages. Components can't use `async`, `await` or `fetch`.
57
+ - `goal build` copies the app's `.js` and `.json` files into `dist/server/` and runs the server from
58
+ there, with the app's folder as the working directory. Other files, such as `.ts`, aren't copied,
59
+ so server code imports only `.js`, `.json` and packages.
60
+ - `goal dev` loads the server code again after every change. A database client belongs on
61
+ `globalThis` (`globalThis.prisma ??= new PrismaClient()`), so each change doesn't open another one.
62
+ - `goal dev`, `goal start` and the Vite plugin read the app's `.env` into `process.env`. Commands like
63
+ `prisma` or `drizzle-kit` don't, so their config loads it (`process.loadEnvFile()`).
64
+ - With a `postcss.config.js`, every stylesheet in `public/` goes through PostCSS.
65
+ - `goal.config.js` can have `onError(error, request)`, called for each error a route or server
66
+ function throws.
67
+ - The page has a strict Content-Security-Policy: no inline scripts or styles.
68
+
69
+ ## Updating a recipe for a new version
70
+
71
+ - **The setup didn't change:** raise the versions in the entry, and widen its `range` if it's narrow.
72
+ - **The setup changed** (a new config format, a new package): add an entry for the new range at the
73
+ top of `versions`. Keep the old entry, and narrow its `range`, so apps on the old version still get
74
+ a setup that works.
75
+ - **A new tool:** add `recipes/<tool>.js`, and a row for it in `docs/tools.md`.
76
+
77
+ ## Testing it
78
+
79
+ ```bash
80
+ npm install
81
+ npm test # checks every recipe's shape, among the other tests
82
+ npm run test:recipes -- tailwindcss # sets each tailwindcss entry up for real, and runs its test
83
+ npm run test:recipes -- prisma --keep # keeps the test apps, to look at
84
+ npm run test:recipes # all of them
85
+ ```
86
+
87
+ `npm run test:recipes` copies [test/recipes/app](../test/recipes/app), a small app with a route, a
88
+ component and a stylesheet, into a new folder for each entry. It runs `npm init -y`, installs this
89
+ checkout of goal.js, runs `goal add <tool>@<version>` with npm for real, and then runs the entry's
90
+ `test`. A test should show that the tool works with goal.js, not only that it installed. For example,
91
+ Tailwind CSS's test checks that a class from a `.goal` file is in the built stylesheet. Prisma's test
92
+ writes a row from `db.js`, then reads it back from the `dist/server` copy.
93
+
94
+ ## Your pull request
95
+
96
+ - The versions are exact and are the ones you tested.
97
+ - `npm test` passes, and so does `npm run test:recipes -- <tool>`.
98
+ - If the tool is new, or what `goal add` does for it changed, `docs/tools.md` says so.
99
+
100
+ A pull request that changes a recipe runs both in CI (`.github/workflows/recipes.yml`).
@@ -0,0 +1,59 @@
1
+ // goal add drizzle: Drizzle ORM with SQLite (better-sqlite3), the tables in JavaScript.
2
+
3
+ export default {
4
+ name: 'drizzle',
5
+ aliases: ['drizzle-orm'],
6
+ package: 'drizzle-orm',
7
+ about: 'Drizzle ORM with SQLite: tables in JavaScript, and a client for server code',
8
+ docs: 'https://orm.drizzle.team/docs/overview',
9
+ versions: [
10
+ {
11
+ range: '>=0.45 <1',
12
+ dependencies: { 'drizzle-orm': '0.45.4', 'better-sqlite3': '13.2.0' },
13
+ devDependencies: { 'drizzle-kit': '0.31.11' },
14
+ files: {
15
+ 'drizzle.config.js': `import { existsSync } from 'node:fs';
16
+ import { defineConfig } from 'drizzle-kit';
17
+
18
+ if (existsSync('.env')) process.loadEnvFile(); // goal.js reads .env for the app; drizzle-kit doesn't
19
+
20
+ export default defineConfig({
21
+ dialect: 'sqlite',
22
+ schema: './db/schema.js',
23
+ out: './drizzle',
24
+ dbCredentials: { url: process.env.DB_FILE_NAME },
25
+ });
26
+ `,
27
+ 'db/schema.js': `import { sqliteTable, integer, text } from 'drizzle-orm/sqlite-core';
28
+
29
+ export const notes = sqliteTable('notes', {
30
+ id: integer().primaryKey({ autoIncrement: true }),
31
+ text: text().notNull(),
32
+ createdAt: integer({ mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
33
+ });
34
+ `,
35
+ 'db/index.js': `import { drizzle } from 'drizzle-orm/better-sqlite3';
36
+ import * as schema from './schema.js';
37
+
38
+ // One connection per process: goal dev loads the server code again after each change.
39
+ export const db = (globalThis.drizzle ??= drizzle(process.env.DB_FILE_NAME, { schema }));
40
+ `,
41
+ },
42
+ lines: { '.env': ['DB_FILE_NAME=sqlite.db'], '.gitignore': ['node_modules', 'dist', '.env', 'sqlite.db*'] },
43
+ scripts: { 'db:push': 'drizzle-kit push' },
44
+ run: ['npx drizzle-kit push'],
45
+ next: [
46
+ "Use it from server code: import { db } from './db/index.js' and import { notes } from './db/schema.js', then: return db.select().from(notes)",
47
+ 'After changing db/schema.js: npm run db:push (or npx drizzle-kit generate and migrate)',
48
+ 'DB_FILE_NAME is in .env; in production, set it in the environment',
49
+ ],
50
+ test: {
51
+ run: [
52
+ `node --input-type=module --env-file=.env -e "import { db } from './db/index.js'; import { notes } from './db/schema.js'; await db.insert(notes).values({ text: 'hi' }); process.exit((await db.select().from(notes)).length === 1 ? 0 : 1)"`,
53
+ 'npx goal build .',
54
+ `node --input-type=module --env-file=.env -e "import { db } from './dist/server/db/index.js'; import { notes } from './dist/server/db/schema.js'; process.exit((await db.select().from(notes)).length === 1 ? 0 : 1)"`,
55
+ ],
56
+ },
57
+ },
58
+ ],
59
+ };
@@ -0,0 +1,38 @@
1
+ // goal add eslint: ESLint for the app's .js and .goal files. goaljs/eslint (src/eslint.js) lets it
2
+ // read .goal files and reports each problem where it is in the file.
3
+
4
+ export default {
5
+ name: 'eslint',
6
+ package: 'eslint',
7
+ about: 'ESLint for .js and .goal files',
8
+ docs: 'https://eslint.org/docs/latest/',
9
+ versions: [
10
+ {
11
+ range: '10',
12
+ devDependencies: { eslint: '10.15.0', '@eslint/js': '10.0.1', globals: '17.14.0' },
13
+ files: {
14
+ 'eslint.config.js': `import js from '@eslint/js';
15
+ import globals from 'globals';
16
+ import goal from 'goaljs/eslint';
17
+
18
+ export default [
19
+ { ignores: ['dist/'] },
20
+ js.configs.recommended,
21
+ ...goal.configs.recommended,
22
+ { languageOptions: { globals: globals.node } },
23
+ { files: ['**/*.goal/*.jsx'], languageOptions: { globals: globals.browser } }, // event handlers run in the page
24
+ ];
25
+ `,
26
+ },
27
+ scripts: { lint: 'eslint .' },
28
+ next: ['npm run lint checks the .js and .goal files; add rules to eslint.config.js', 'Your editor\'s ESLint extension shows the problems in .goal files too once it lints them (VS Code: "eslint.validate": ["javascript", "goal"])'],
29
+ test: {
30
+ files: { 'Unused.goal': "import { Counter } from './Counter.goal';\nexport function Unused() {\n const x = 1;\n return <Counter start={1} />;\n}\n" },
31
+ run: [
32
+ `node -e "const { execSync } = require('child_process'); let out = ''; try { execSync('npx eslint .', { encoding: 'utf8' }); } catch (e) { out = e.stdout; } process.exit(/Unused\\.goal\\s+3:9\\s+error\\s+'x' is assigned a value but never used/.test(out) ? 0 : 1)"`,
33
+ 'npx eslint --ignore-pattern Unused.goal .',
34
+ ],
35
+ },
36
+ },
37
+ ],
38
+ };
@@ -0,0 +1,48 @@
1
+ // goal add playwright: Playwright browser tests against the app as goal build and goal start serve it,
2
+ // with its security headers and Content-Security-Policy.
3
+
4
+ export default {
5
+ name: 'playwright',
6
+ aliases: ['@playwright/test'],
7
+ package: '@playwright/test',
8
+ about: 'Playwright: browser tests against the built app',
9
+ docs: 'https://playwright.dev/docs/intro',
10
+ versions: [
11
+ {
12
+ range: '1',
13
+ devDependencies: { '@playwright/test': '1.65.1' },
14
+ files: {
15
+ 'playwright.config.js': `import { defineConfig, devices } from '@playwright/test';
16
+
17
+ export default defineConfig({
18
+ testDir: 'e2e',
19
+ use: { baseURL: 'http://localhost:4173' },
20
+ projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
21
+ // The app as production serves it
22
+ webServer: {
23
+ command: 'npx goal build . && npx goal start . --port 4173',
24
+ url: 'http://localhost:4173',
25
+ reuseExistingServer: !process.env.CI,
26
+ },
27
+ });
28
+ `,
29
+ 'e2e/home.spec.js': `import { test, expect } from '@playwright/test';
30
+
31
+ test('the home page loads with no errors', async ({ page }) => {
32
+ const errors = [];
33
+ page.on('pageerror', (e) => errors.push(e.message));
34
+ page.on('console', (m) => m.type() === 'error' && errors.push(m.text())); // a blocked inline script shows here
35
+ const res = await page.goto('/');
36
+ expect(res.status()).toBeLessThan(400);
37
+ expect(errors).toEqual([]);
38
+ });
39
+ `,
40
+ },
41
+ lines: { '.gitignore': ['node_modules', 'dist', 'test-results', 'playwright-report'] },
42
+ scripts: { 'test:e2e': 'playwright test' },
43
+ run: ['npx playwright install chromium'],
44
+ next: ['npm run test:e2e builds the app, starts it on port 4173 and runs the tests in e2e/ in Chromium', 'More browsers: add projects to playwright.config.js and npx playwright install'],
45
+ test: { run: ['npx playwright test --reporter=line'] },
46
+ },
47
+ ],
48
+ };
@@ -0,0 +1,32 @@
1
+ // goal add postcss: PostCSS, which goal build and goal dev run the stylesheets in public/ through
2
+ // (see src/css.js), with autoprefixer to start with.
3
+
4
+ export default {
5
+ name: 'postcss',
6
+ aliases: ['autoprefixer'],
7
+ package: 'postcss',
8
+ about: 'PostCSS: the stylesheets in public/ through plugins, autoprefixer first',
9
+ docs: 'https://postcss.org',
10
+ versions: [
11
+ {
12
+ range: '8',
13
+ devDependencies: { postcss: '8.5.33', autoprefixer: '10.7.0' },
14
+ files: {
15
+ 'postcss.config.js': `export default {
16
+ plugins: {
17
+ autoprefixer: {},
18
+ },
19
+ };
20
+ `,
21
+ },
22
+ lines: { '.gitignore': ['node_modules', 'dist'] },
23
+ next: [
24
+ 'goal dev and goal build run every stylesheet in public/ through the plugins in postcss.config.js',
25
+ 'Add a plugin: npm install --save-dev <plugin>, then name it in postcss.config.js',
26
+ ],
27
+ test: {
28
+ run: ['npx goal build .', `node -e "process.exit(require('fs').readFileSync('dist/public/style.css', 'utf8').includes('-webkit-user-select') ? 0 : 1)"`],
29
+ },
30
+ },
31
+ ],
32
+ };
@@ -0,0 +1,19 @@
1
+ // goal add prettier: Prettier for the app's .js, .css, .json and .md files. It leaves .goal files
2
+ // alone: it doesn't know their routes and {if}.
3
+
4
+ export default {
5
+ name: 'prettier',
6
+ package: 'prettier',
7
+ about: 'Prettier: formats .js, .css, .json and .md files',
8
+ docs: 'https://prettier.io/docs/',
9
+ versions: [
10
+ {
11
+ range: '3',
12
+ devDependencies: { prettier: '3.10.1' },
13
+ files: { '.prettierrc.json': '{}\n', '.prettierignore': 'dist\n' },
14
+ scripts: { format: 'prettier --write .', 'format:check': 'prettier --check .' },
15
+ next: ['npm run format formats the .js, .css, .json and .md files; .goal files are left as they are', 'Set options, like "singleQuote": true, in .prettierrc.json'],
16
+ test: { run: ['npx prettier --write .', 'npx prettier --check .'] },
17
+ },
18
+ ],
19
+ };
@@ -0,0 +1,67 @@
1
+ // goal add prisma: Prisma ORM with SQLite. The client is generated into node_modules and imported as
2
+ // @prisma/client, so the server code finds it from the app's folder and from dist/server alike.
3
+
4
+ export default {
5
+ name: 'prisma',
6
+ aliases: ['@prisma/client'],
7
+ package: 'prisma',
8
+ about: 'Prisma ORM with SQLite: a schema, and a client for server code',
9
+ docs: 'https://www.prisma.io/docs/orm',
10
+ versions: [
11
+ {
12
+ range: '7',
13
+ dependencies: { '@prisma/client': '7.10.1', '@prisma/adapter-better-sqlite3': '7.10.1' },
14
+ devDependencies: { prisma: '7.10.1' },
15
+ files: {
16
+ 'prisma/schema.prisma': `generator client {
17
+ provider = "prisma-client-js"
18
+ }
19
+
20
+ datasource db {
21
+ provider = "sqlite"
22
+ }
23
+
24
+ model Note {
25
+ id Int @id @default(autoincrement())
26
+ text String
27
+ createdAt DateTime @default(now())
28
+ }
29
+ `,
30
+ // Prisma 7 looks for prisma7.config.* before prisma.config.*
31
+ 'prisma7.config.js': `import { existsSync } from 'node:fs';
32
+ import { defineConfig } from 'prisma/config';
33
+
34
+ if (existsSync('.env')) process.loadEnvFile(); // goal.js reads .env for the app; the prisma command doesn't
35
+
36
+ export default defineConfig({
37
+ schema: 'prisma/schema.prisma',
38
+ datasource: { url: process.env.DATABASE_URL },
39
+ });
40
+ `,
41
+ 'db.js': `import { PrismaClient } from '@prisma/client';
42
+ import { PrismaBetterSqlite3 } from '@prisma/adapter-better-sqlite3';
43
+
44
+ // One client per process: goal dev loads the server code again after each change.
45
+ export const db = (globalThis.prisma ??= new PrismaClient({
46
+ adapter: new PrismaBetterSqlite3({ url: process.env.DATABASE_URL }),
47
+ }));
48
+ `,
49
+ },
50
+ lines: { '.env': ['DATABASE_URL="file:./dev.db"'], '.gitignore': ['node_modules', 'dist', '.env', 'dev.db*'] },
51
+ scripts: { postinstall: 'prisma generate', 'db:push': 'prisma db push' },
52
+ run: ['npx prisma generate', 'npx prisma db push'],
53
+ next: [
54
+ "Use it from server code: import { db } from './db.js', then in a route or server function: return db.note.findMany()",
55
+ 'After changing prisma/schema.prisma: npm run db:push (or npx prisma migrate dev), and restart goal dev',
56
+ 'DATABASE_URL is in .env; in production, set it in the environment',
57
+ ],
58
+ test: {
59
+ run: [
60
+ `node --input-type=module --env-file=.env -e "import { db } from './db.js'; await db.note.create({ data: { text: 'hi' } }); process.exit((await db.note.count()) === 1 ? 0 : 1)"`,
61
+ 'npx goal build .',
62
+ `node --input-type=module --env-file=.env -e "import { db } from './dist/server/db.js'; process.exit((await db.note.count()) === 1 ? 0 : 1)"`,
63
+ ],
64
+ },
65
+ },
66
+ ],
67
+ };
@@ -0,0 +1,57 @@
1
+ // goal add sentry: errors that routes and server functions throw, reported to Sentry from
2
+ // goal.config.js's onError (see src/app.js).
3
+
4
+ export default {
5
+ name: 'sentry',
6
+ aliases: ['@sentry/node'],
7
+ package: '@sentry/node',
8
+ about: 'Sentry: errors from routes and server functions',
9
+ docs: 'https://docs.sentry.io/platforms/javascript/guides/node/',
10
+ versions: [
11
+ {
12
+ range: '11',
13
+ dependencies: { '@sentry/node': '11.18.0' },
14
+ files: {
15
+ 'sentry.js': `// Errors that routes and server functions throw, reported to Sentry: goal.config.js passes them to
16
+ // onError. Without SENTRY_DSN, in .env or the environment, nothing is sent.
17
+ import * as Sentry from '@sentry/node';
18
+
19
+ Sentry.init({ dsn: process.env.SENTRY_DSN });
20
+
21
+ export function onError(error, request) {
22
+ Sentry.captureException(error, { extra: { method: request?.method, path: request?.path } });
23
+ }
24
+ `,
25
+ },
26
+ config: { import: "import { onError } from './sentry.js';", keys: { onError: 'onError' } },
27
+ lines: { '.env': ['SENTRY_DSN='], '.gitignore': ['node_modules', 'dist', '.env'] },
28
+ next: ["Put your Sentry project's DSN in .env as SENTRY_DSN, and in the environment in production; until then nothing is sent"],
29
+ test: {
30
+ files: {
31
+ 'Boom.goal': 'route GET /boom {\n throw new Error("boom from a route");\n}\n',
32
+ 'check-sentry.mjs': `// A stand-in for Sentry, and the app with SENTRY_DSN pointing at it: a route's error must reach it.
33
+ import { createServer } from 'node:http';
34
+ import { spawn } from 'node:child_process';
35
+
36
+ const got = [];
37
+ const sentry = createServer((req, res) => {
38
+ let body = '';
39
+ req.on('data', (c) => (body += c));
40
+ req.on('end', () => (got.push(body), res.end('{}')));
41
+ });
42
+ await new Promise((ok) => sentry.listen(0, ok));
43
+ const env = { ...process.env, SENTRY_DSN: \`http://public@localhost:\${sentry.address().port}/1\` };
44
+ const app = spawn(process.execPath, ['node_modules/goaljs/bin/goal.js', 'start', '.', '--port', '4179'], { env, stdio: 'ignore' });
45
+ let res;
46
+ for (let i = 0; i < 100 && !res; i++) res = await fetch('http://localhost:4179/boom').catch(() => new Promise((ok) => setTimeout(ok, 100)));
47
+ for (let i = 0; i < 50 && !got.some((b) => b.includes('boom from a route')); i++) await new Promise((ok) => setTimeout(ok, 100));
48
+ app.kill();
49
+ sentry.close();
50
+ process.exit(res.status === 500 && got.some((b) => b.includes('boom from a route')) ? 0 : 1);
51
+ `,
52
+ },
53
+ run: ['npx goal build .', 'node check-sentry.mjs'],
54
+ },
55
+ },
56
+ ],
57
+ };
@@ -0,0 +1,60 @@
1
+ // goal add tailwindcss: Tailwind CSS, compiled by goal build and goal dev through PostCSS (see
2
+ // src/css.js), with the classes the app's .goal files use.
3
+
4
+ const ignore = { '.gitignore': ['node_modules', 'dist'] };
5
+ const link = 'Link the stylesheet from your pages: <link rel="stylesheet" href="/style.css" />';
6
+ const check = (file) => `node -e "process.exit(require('fs').readFileSync('${file}', 'utf8').includes('.text-3xl') ? 0 : 1)"`;
7
+
8
+ export default {
9
+ name: 'tailwindcss',
10
+ aliases: ['tailwind'],
11
+ package: 'tailwindcss',
12
+ about: 'Tailwind CSS: utility classes, compiled into public/style.css',
13
+ docs: 'https://tailwindcss.com/docs',
14
+ versions: [
15
+ {
16
+ range: '4',
17
+ devDependencies: { tailwindcss: '4.3.5', '@tailwindcss/postcss': '4.3.5', postcss: '8.5.33' },
18
+ files: {
19
+ 'postcss.config.js': `export default {
20
+ plugins: {
21
+ '@tailwindcss/postcss': {},
22
+ },
23
+ };
24
+ `,
25
+ },
26
+ // source(".."): the classes are looked for in the app's folder, wherever goal runs from
27
+ prepend: { 'public/style.css': ['@import "tailwindcss" source("..");'] },
28
+ lines: ignore,
29
+ next: [link, 'Use its classes in markup, like <h1 class="text-3xl font-bold">: goal dev and goal build put the ones your .goal files use in /style.css'],
30
+ test: { run: ['npx goal build .', check('dist/public/style.css')] },
31
+ },
32
+ {
33
+ range: '3',
34
+ devDependencies: { tailwindcss: '3.4.19', postcss: '8.5.33', autoprefixer: '10.7.0' },
35
+ files: {
36
+ 'tailwind.config.js': `/** @type {import('tailwindcss').Config} */
37
+ export default {
38
+ // The app's .goal files, from this file's folder
39
+ content: { relative: true, files: ['./**/*.goal', '!./node_modules/**', '!./dist/**'] },
40
+ theme: { extend: {} },
41
+ plugins: [],
42
+ };
43
+ `,
44
+ 'postcss.config.js': `import { fileURLToPath } from 'node:url';
45
+
46
+ export default {
47
+ plugins: {
48
+ tailwindcss: { config: fileURLToPath(new URL('./tailwind.config.js', import.meta.url)) },
49
+ autoprefixer: {},
50
+ },
51
+ };
52
+ `,
53
+ },
54
+ prepend: { 'public/style.css': ['@tailwind base;', '@tailwind components;', '@tailwind utilities;'] },
55
+ lines: ignore,
56
+ next: [link, 'Use its classes in markup, like <h1 class="text-3xl font-bold">: goal dev and goal build put the ones your .goal files use in /style.css'],
57
+ test: { run: ['npx goal build .', check('dist/public/style.css')] },
58
+ },
59
+ ],
60
+ };
@@ -0,0 +1,43 @@
1
+ // goal add vitest: Vitest, with goal.js's Vite plugin, so tests import components and server
2
+ // functions from .goal files as server code does.
3
+
4
+ export default {
5
+ name: 'vitest',
6
+ package: 'vitest',
7
+ about: 'Vitest: tests that import .goal files',
8
+ docs: 'https://vitest.dev/guide/',
9
+ versions: [
10
+ {
11
+ range: '5',
12
+ devDependencies: { vitest: '5.1.2' },
13
+ files: {
14
+ 'vitest.config.js': `import { defineConfig } from 'vitest/config';
15
+ import { goal } from 'goaljs/vite';
16
+
17
+ export default defineConfig({
18
+ plugins: [goal()], // tests import .goal files
19
+ test: { include: ['**/*.test.js'], exclude: ['node_modules/**', 'dist/**'] },
20
+ });
21
+ `,
22
+ },
23
+ scripts: { test: 'vitest' },
24
+ next: [
25
+ "Write tests as *.test.js. They import from .goal files: import { Counter } from './Counter.goal'",
26
+ 'A component renders to HTML: expect(String(Counter({ start: 1 }))).toContain(\'1\'); a server function is a plain async function',
27
+ 'npm test runs them and watches; npx vitest run runs them once',
28
+ ],
29
+ test: {
30
+ files: {
31
+ 'tests/counter.test.js': `import { test, expect } from 'vitest';
32
+ import { Counter } from '../Counter.goal';
33
+
34
+ test('Counter renders its start', () => {
35
+ expect(String(Counter({ start: 41 }))).toContain('41');
36
+ });
37
+ `,
38
+ },
39
+ run: ['npx vitest run'],
40
+ },
41
+ },
42
+ ],
43
+ };