@yannosay/sinth 4.1.0 → 5.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/CHANGELOG.md +89 -0
- package/DOCS.md +1359 -0
- package/README.md +83 -74
- package/bin/sinth.js +2 -1
- package/dist/cli/args.d.ts +11 -0
- package/dist/cli/args.js +74 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +437 -0
- package/dist/cli/templates.d.ts +10 -0
- package/dist/cli/templates.js +193 -0
- package/dist/cli/ui.d.ts +28 -0
- package/dist/cli/ui.js +61 -0
- package/dist/cli/update-check.d.ts +2 -0
- package/dist/cli/update-check.js +124 -0
- package/dist/compiler/ast.d.ts +315 -0
- package/dist/compiler/ast.js +4 -0
- package/dist/compiler/codegen.d.ts +143 -0
- package/dist/compiler/codegen.js +1326 -0
- package/dist/compiler/diagnostics.d.ts +36 -0
- package/dist/compiler/diagnostics.js +142 -0
- package/dist/compiler/elements.d.ts +14 -0
- package/dist/compiler/elements.js +78 -0
- package/dist/compiler/globals.d.ts +2 -0
- package/dist/compiler/globals.js +27 -0
- package/dist/compiler/html.d.ts +37 -0
- package/dist/compiler/html.js +152 -0
- package/dist/compiler/lexer.d.ts +42 -0
- package/dist/compiler/lexer.js +404 -0
- package/dist/compiler/parser.d.ts +95 -0
- package/dist/compiler/parser.js +1374 -0
- package/dist/compiler/prerender.d.ts +72 -0
- package/dist/compiler/prerender.js +910 -0
- package/dist/compiler/script-analysis.d.ts +6 -0
- package/dist/compiler/script-analysis.js +106 -0
- package/dist/compiler/style.d.ts +39 -0
- package/dist/compiler/style.js +463 -0
- package/dist/deploy/cloudflare.d.ts +9 -0
- package/dist/deploy/cloudflare.js +111 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +23 -0
- package/dist/project/build.d.ts +31 -0
- package/dist/project/build.js +425 -0
- package/dist/project/config.d.ts +33 -0
- package/dist/project/config.js +142 -0
- package/dist/project/project.d.ts +74 -0
- package/dist/project/project.js +555 -0
- package/dist/runtime/index.d.ts +68 -0
- package/dist/runtime/index.js +912 -0
- package/dist/server/client.d.ts +1 -0
- package/dist/server/client.js +112 -0
- package/dist/server/dev.d.ts +8 -0
- package/dist/server/dev.js +244 -0
- package/dist/server/preview.d.ts +6 -0
- package/dist/server/preview.js +106 -0
- package/dist/server/static.d.ts +10 -0
- package/dist/server/static.js +136 -0
- package/lib/ui/index.sinth +436 -0
- package/package.json +33 -15
- package/schema/sinth.config.schema.json +54 -0
- package/dist/browser/compile.js +0 -63
- package/dist/cli.js +0 -509
- package/dist/core/builtins.js +0 -117
- package/dist/core/cli-compiler.js +0 -705
- package/dist/core/compiler.js +0 -1489
- package/dist/core/expr.js +0 -129
- package/dist/core/head-builder.js +0 -130
- package/dist/core/lexer.js +0 -410
- package/dist/core/parser.js +0 -1646
- package/dist/core/runtime/custom-element.js +0 -81
- package/dist/core/runtime/functions.js +0 -99
- package/dist/core/runtime/helpers.js +0 -347
- package/dist/core/runtime/render.js +0 -136
- package/dist/core/style-processor.js +0 -317
- package/dist/core/types.js +0 -93
- package/dist/resolver.js +0 -175
- package/dist/server.js +0 -174
- package/dist/update-check.js +0 -109
- package/dist/utils.js +0 -80
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DEFAULT_CONFIG = void 0;
|
|
37
|
+
exports.loadConfig = loadConfig;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const diagnostics_1 = require("../compiler/diagnostics");
|
|
41
|
+
exports.DEFAULT_CONFIG = {
|
|
42
|
+
outDir: "dist",
|
|
43
|
+
pagesDir: "pages",
|
|
44
|
+
publicDir: "public",
|
|
45
|
+
staticDirs: ["assets"],
|
|
46
|
+
libraryPaths: ["libraries"],
|
|
47
|
+
base: "/",
|
|
48
|
+
minify: false,
|
|
49
|
+
sourcemap: false,
|
|
50
|
+
port: 3000,
|
|
51
|
+
host: "127.0.0.1",
|
|
52
|
+
previewPort: 4000,
|
|
53
|
+
target: ["es2020", "chrome90", "firefox90", "safari15", "edge90"],
|
|
54
|
+
security: { headers: true, csp: true },
|
|
55
|
+
cloudflare: {},
|
|
56
|
+
};
|
|
57
|
+
const KNOWN_KEYS = new Set([
|
|
58
|
+
"outDir", "pagesDir", "publicDir", "staticDirs", "libraryPaths", "site", "base", "minify", "sourcemap", "port", "host",
|
|
59
|
+
"previewPort", "target", "security", "cloudflare", "development", "production", "$schema",
|
|
60
|
+
"sharedRuntime", "inlineJS", "inlineCSS",
|
|
61
|
+
]);
|
|
62
|
+
const LEGACY_KEYS = new Set(["sharedRuntime", "inlineJS", "inlineCSS"]);
|
|
63
|
+
function validate(raw, file, warnings) {
|
|
64
|
+
for (const key of Object.keys(raw)) {
|
|
65
|
+
if (!KNOWN_KEYS.has(key))
|
|
66
|
+
warnings.push(`Unknown option '${key}' in ${path.basename(file)} (ignored)`);
|
|
67
|
+
else if (LEGACY_KEYS.has(key))
|
|
68
|
+
warnings.push(`Option '${key}' is no longer needed in Sinth 5: code splitting and asset bundling are automatic`);
|
|
69
|
+
}
|
|
70
|
+
const check = (key, type, ok) => {
|
|
71
|
+
if (key in raw && !ok(raw[key]))
|
|
72
|
+
throw new diagnostics_1.SinthError("E0900", `Option '${key}' in ${path.basename(file)} must be ${type}`, { file, line: 1, col: 1 });
|
|
73
|
+
};
|
|
74
|
+
const str = (v) => typeof v === "string";
|
|
75
|
+
const strArr = (v) => Array.isArray(v) && v.every(x => typeof x === "string");
|
|
76
|
+
for (const k of ["outDir", "pagesDir", "publicDir", "site", "base", "host"])
|
|
77
|
+
check(k, "a string", str);
|
|
78
|
+
for (const k of ["staticDirs", "libraryPaths", "target"])
|
|
79
|
+
check(k, "an array of strings", strArr);
|
|
80
|
+
for (const k of ["minify", "sourcemap"])
|
|
81
|
+
check(k, "true or false", v => typeof v === "boolean");
|
|
82
|
+
for (const k of ["port", "previewPort"])
|
|
83
|
+
check(k, "a port number (1-65535)", v => Number.isInteger(v) && v > 0 && v < 65536);
|
|
84
|
+
check("site", "an absolute URL like https://example.com", v => typeof v === "string" && /^https?:\/\/[^\s]+$/.test(v));
|
|
85
|
+
}
|
|
86
|
+
function loadConfig(root, mode) {
|
|
87
|
+
const warnings = [];
|
|
88
|
+
const file = path.join(root, "sinth.config.json");
|
|
89
|
+
let raw = {};
|
|
90
|
+
if (fs.existsSync(file)) {
|
|
91
|
+
const text = fs.readFileSync(file, "utf-8");
|
|
92
|
+
try {
|
|
93
|
+
raw = JSON.parse(text);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
const m = err.message.match(/position (\d+)/);
|
|
97
|
+
const pos = m ? Number(m[1]) : 0;
|
|
98
|
+
const line = text.slice(0, pos).split("\n").length;
|
|
99
|
+
throw new diagnostics_1.SinthError("E0901", `Invalid JSON in sinth.config.json: ${err.message}`, { file, line, col: 1 });
|
|
100
|
+
}
|
|
101
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw))
|
|
102
|
+
throw new diagnostics_1.SinthError("E0901", "sinth.config.json must contain a JSON object", { file, line: 1, col: 1 });
|
|
103
|
+
validate(raw, file, warnings);
|
|
104
|
+
const env = raw[mode];
|
|
105
|
+
if (env)
|
|
106
|
+
validate(env, file, warnings);
|
|
107
|
+
}
|
|
108
|
+
const envOverrides = raw[mode] ?? {};
|
|
109
|
+
const merged = {
|
|
110
|
+
...exports.DEFAULT_CONFIG,
|
|
111
|
+
...stripNested(raw),
|
|
112
|
+
...stripNested(envOverrides),
|
|
113
|
+
security: { ...exports.DEFAULT_CONFIG.security, ...(raw.security ?? {}), ...(envOverrides.security ?? {}) },
|
|
114
|
+
cloudflare: { ...(raw.cloudflare ?? {}) },
|
|
115
|
+
};
|
|
116
|
+
if (mode === "production" && raw.minify === undefined && envOverrides.minify === undefined)
|
|
117
|
+
merged.minify = true;
|
|
118
|
+
if (mode === "development" && raw.sourcemap === undefined && envOverrides.sourcemap === undefined)
|
|
119
|
+
merged.sourcemap = true;
|
|
120
|
+
merged.staticDirs = merged.staticDirs.map(d => d.replace(/^\.\//, ""));
|
|
121
|
+
merged.libraryPaths = merged.libraryPaths.map(d => path.resolve(root, d));
|
|
122
|
+
merged.outDir = path.resolve(root, merged.outDir);
|
|
123
|
+
merged.pagesDir = path.resolve(root, merged.pagesDir);
|
|
124
|
+
merged.publicDir = path.resolve(root, merged.publicDir);
|
|
125
|
+
if (!merged.base.startsWith("/"))
|
|
126
|
+
merged.base = "/" + merged.base;
|
|
127
|
+
if (!merged.base.endsWith("/"))
|
|
128
|
+
merged.base += "/";
|
|
129
|
+
if (merged.outDir === path.resolve(root))
|
|
130
|
+
throw new diagnostics_1.SinthError("E0902", "outDir cannot be the project root", { file, line: 1, col: 1 });
|
|
131
|
+
return { config: merged, file: fs.existsSync(file) ? file : undefined, warnings };
|
|
132
|
+
}
|
|
133
|
+
function stripNested(raw) {
|
|
134
|
+
const out = {};
|
|
135
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
136
|
+
if (k === "development" || k === "production" || k === "security" || k === "cloudflare" || k === "$schema" || LEGACY_KEYS.has(k))
|
|
137
|
+
continue;
|
|
138
|
+
if (v !== undefined)
|
|
139
|
+
out[k] = v;
|
|
140
|
+
}
|
|
141
|
+
return out;
|
|
142
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SinthFile } from "../compiler/ast";
|
|
2
|
+
import { ModuleOutput, ResolvedImport } from "../compiler/codegen";
|
|
3
|
+
import { Diagnostic } from "../compiler/diagnostics";
|
|
4
|
+
import { MetaValue } from "../compiler/html";
|
|
5
|
+
import { ScssCompiler } from "../compiler/style";
|
|
6
|
+
import { SinthConfig } from "./config";
|
|
7
|
+
export declare const PACKAGE_ROOT: string;
|
|
8
|
+
export declare const RUNTIME_PATH: string;
|
|
9
|
+
export declare const LIB_ROOT: string;
|
|
10
|
+
export interface PageInfo {
|
|
11
|
+
file: string;
|
|
12
|
+
route: string;
|
|
13
|
+
outFile: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PageInstance {
|
|
16
|
+
page: PageInfo;
|
|
17
|
+
prerendered: string;
|
|
18
|
+
meta: MetaValue[];
|
|
19
|
+
params?: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
export interface CompiledPage {
|
|
22
|
+
page: PageInfo;
|
|
23
|
+
module: ModuleOutput;
|
|
24
|
+
graph: string[];
|
|
25
|
+
interactive: boolean;
|
|
26
|
+
/** One entry per generated HTML file. Static routes have exactly one; dynamic routes one per `paths` item. */
|
|
27
|
+
instances: PageInstance[];
|
|
28
|
+
styleImports: string[];
|
|
29
|
+
externalStyles: string[];
|
|
30
|
+
externalScripts: {
|
|
31
|
+
src: string;
|
|
32
|
+
attrs: Record<string, string | boolean>;
|
|
33
|
+
}[];
|
|
34
|
+
fonts: string[];
|
|
35
|
+
warnings: Diagnostic[];
|
|
36
|
+
}
|
|
37
|
+
export declare class Project {
|
|
38
|
+
readonly root: string;
|
|
39
|
+
readonly config: SinthConfig;
|
|
40
|
+
readonly dev: boolean;
|
|
41
|
+
private readonly parsed;
|
|
42
|
+
private compiled;
|
|
43
|
+
private readonly resolved;
|
|
44
|
+
private scssCompiler;
|
|
45
|
+
constructor(root: string, config: SinthConfig, dev: boolean);
|
|
46
|
+
invalidate(): void;
|
|
47
|
+
getFile(file: string): SinthFile;
|
|
48
|
+
/**
|
|
49
|
+
* A file is a page when it lives in the pages folder (or, without one, in the project root),
|
|
50
|
+
* is not hidden behind a leading underscore, and is not a pure component module. The Sinth 4
|
|
51
|
+
* `page` keyword still forces a page anywhere.
|
|
52
|
+
*/
|
|
53
|
+
private isPageFile;
|
|
54
|
+
scss(): ScssCompiler | undefined;
|
|
55
|
+
findPages(): PageInfo[];
|
|
56
|
+
private pagesBase;
|
|
57
|
+
pageInfo(file: string, base?: string): PageInfo;
|
|
58
|
+
private resolveFile;
|
|
59
|
+
private resolveBare;
|
|
60
|
+
resolveImports(file: SinthFile): ResolvedImport[];
|
|
61
|
+
private notFound;
|
|
62
|
+
private resolveImport;
|
|
63
|
+
private sinthImport;
|
|
64
|
+
persistPrefix(file: string): string;
|
|
65
|
+
compile(file: string, stack?: string[]): ModuleOutput;
|
|
66
|
+
private hasScss;
|
|
67
|
+
moduleGraph(entry: string): string[];
|
|
68
|
+
compilePage(page: PageInfo): CompiledPage;
|
|
69
|
+
private expandParams;
|
|
70
|
+
private needsRuntime;
|
|
71
|
+
resolveAsset(value: string, fromFile: string): string;
|
|
72
|
+
}
|
|
73
|
+
export declare function routeParams(rel: string): string[];
|
|
74
|
+
export declare function fontHref(spec: string): string;
|