clarusjs 0.0.0-stage → 0.1.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.
@@ -0,0 +1,80 @@
1
+ // The clarusjs Vite plugin: a thin adapter around the compiler.
2
+ // Server environment gets render(), client environment gets attach(). Dev requests go through the fetch handler.
3
+ import { isAbsolute, relative } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ import { isRunnableDevEnvironment } from 'vite';
6
+ import { compile, ClarusError } from '../compiler/index.js';
7
+ import { sendResponse, toRequest } from './node.js';
8
+ // From src/ (workspace, tests) our siblings are .ts files; from the published dist/ they are .js.
9
+ const ext = import.meta.url.endsWith('.ts') ? '.ts' : '.js';
10
+ const here = (path) => fileURLToPath(new URL(path + ext, import.meta.url));
11
+ const ENTRY = 'virtual:clarusjs/server-entry';
12
+ /** Dev URL of a component's client module: root-relative, or Vite's /@fs/ form for files outside the root. */
13
+ export function clientUrlFor(root, file) {
14
+ const rel = relative(root, file);
15
+ return rel.startsWith('..') || isAbsolute(rel) ? `/@fs${file}?import` : `/${rel}?import`;
16
+ }
17
+ export default function clarusjs() {
18
+ let root = process.cwd();
19
+ return {
20
+ name: 'clarusjs',
21
+ config: () => ({
22
+ appType: 'custom',
23
+ resolve: {
24
+ alias: [
25
+ { find: 'clarusjs/runtime/server', replacement: here('../runtime/server') },
26
+ { find: 'clarusjs/runtime', replacement: here('../runtime/index') },
27
+ ],
28
+ },
29
+ }),
30
+ configResolved(config) { root = config.root; },
31
+ resolveId(id) {
32
+ if (id === '/cl-loader.js')
33
+ return here('../runtime/loader');
34
+ if (id === ENTRY)
35
+ return '\0' + ENTRY;
36
+ },
37
+ load(id) {
38
+ if (id !== '\0' + ENTRY)
39
+ return;
40
+ return `import { createHandler } from ${JSON.stringify(here('../server/handler'))}\n` +
41
+ `export default createHandler(import.meta.glob('/src/pages/**/*.clarus'))\n`;
42
+ },
43
+ transform: {
44
+ filter: { id: /\.clarus(\?|$)/ },
45
+ handler(code, id) {
46
+ const file = id.replace(/\?.*$/, '');
47
+ const target = this.environment.config.consumer === 'server' ? 'server' : 'client';
48
+ // ponytail: ?import makes Vite's dev transform middleware serve .clarus as JS for the loader's dynamic import; build output uses hashed chunk URLs from the client manifest (stage 3)
49
+ const clientUrl = clientUrlFor(root, file);
50
+ try {
51
+ return { code: compile(code, { file, target, clientUrl }).code, map: null };
52
+ }
53
+ catch (err) {
54
+ if (err instanceof ClarusError)
55
+ this.error(err.message);
56
+ throw err;
57
+ }
58
+ },
59
+ },
60
+ configureServer(server) {
61
+ return () => {
62
+ server.middlewares.use(async (req, res, next) => {
63
+ try {
64
+ const env = server.environments.ssr;
65
+ if (!isRunnableDevEnvironment(env))
66
+ return next();
67
+ const app = await env.runner.import(ENTRY);
68
+ const response = await app.default.fetch(toRequest(req));
69
+ if (response.status === 404)
70
+ return next();
71
+ await sendResponse(res, response);
72
+ }
73
+ catch (err) {
74
+ next(err);
75
+ }
76
+ });
77
+ };
78
+ },
79
+ };
80
+ }
package/package.json CHANGED
@@ -1,6 +1,81 @@
1
1
  {
2
2
  "name": "clarusjs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Clear, compiled views: templates compiled to server HTML, with JavaScript only for interactive islands. SSR, SSG and CSR from one component model, built on Vite.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "clarusjs",
8
+ "framework",
9
+ "compiler",
10
+ "templates",
11
+ "ssr",
12
+ "ssg",
13
+ "islands",
14
+ "partial-hydration",
15
+ "signals",
16
+ "vite",
17
+ "vite-plugin",
18
+ "html-first",
19
+ "typescript"
20
+ ],
21
+ "homepage": "https://github.com/forinda/clarusjs#readme",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/forinda/clarusjs.git",
25
+ "directory": "packages/clarusjs"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/forinda/clarusjs/issues"
29
+ },
30
+ "type": "module",
31
+ "exports": {
32
+ "./compiler": {
33
+ "types": "./dist/compiler/index.d.ts",
34
+ "default": "./dist/compiler/index.js"
35
+ },
36
+ "./runtime": {
37
+ "types": "./dist/runtime/index.d.ts",
38
+ "default": "./dist/runtime/index.js"
39
+ },
40
+ "./runtime/server": {
41
+ "types": "./dist/runtime/server.d.ts",
42
+ "default": "./dist/runtime/server.js"
43
+ },
44
+ "./server": {
45
+ "types": "./dist/server/handler.d.ts",
46
+ "default": "./dist/server/handler.js"
47
+ },
48
+ "./vite": {
49
+ "types": "./dist/vite/plugin.d.ts",
50
+ "default": "./dist/vite/plugin.js"
51
+ }
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "LICENSE"
56
+ ],
57
+ "engines": {
58
+ "node": "^22.12.0 || ^24.0.0 || >=26.0.0"
59
+ },
60
+ "dependencies": {
61
+ "acorn": "^8.19.0"
62
+ },
63
+ "peerDependencies": {
64
+ "vite": "^8.0.0"
65
+ },
66
+ "devDependencies": {
67
+ "@types/node": "^26.6.6",
68
+ "happy-dom": "^21.0.4",
69
+ "typescript": "^7.0.2",
70
+ "vite": "^8.3.8",
71
+ "vitest": "^5.1.1"
72
+ },
73
+ "publishConfig": {
74
+ "access": "public"
75
+ },
76
+ "scripts": {
77
+ "build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json",
78
+ "test": "vitest run",
79
+ "typecheck": "tsc --noEmit"
80
+ }
6
81
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.