flexui-compiler 0.0.0-stage → 2.0.0-alpha.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/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # flexui-compiler
2
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.
3
+ npm wrapper for the FlexUI 2.0 compiler.
4
+
5
+ ```bash
6
+ npm install --save-dev flexui-compiler
7
+ npx flexui-compiler init
8
+ npx flexui-compiler build --minify
9
+
10
+ The installed command is `flexui`, so `npx flexui-compiler` and a local
11
+ `node_modules/.bin/flexui` both work.
12
+ ```
13
+
14
+ The compiler itself is a Go binary. This package resolves the right precompiled
15
+ binary for your platform, verifies its checksum and runs it. Nothing is compiled
16
+ on your machine and no install script is required.
17
+
18
+ ## Platform packages
19
+
20
+ | Platform | Package |
21
+ | --- | --- |
22
+ | Windows x64 | `flexui-cli-windows-x64` |
23
+ | Windows ARM64 | `flexui-cli-windows-arm64` |
24
+ | Linux x64 | `flexui-cli-linux-x64` |
25
+ | Linux ARM64 | `flexui-cli-linux-arm64` |
26
+ | macOS x64 | `flexui-cli-darwin-x64` |
27
+ | macOS ARM64 | `flexui-cli-darwin-arm64` |
28
+
29
+ If optional dependencies are disabled, install the platform package directly or
30
+ set `FLEXUI_BINARY` to a `flexui` executable.
31
+
32
+ ## TypeScript API
33
+
34
+ The wrapper is written in TypeScript. Sources live in `src/`, compiled output in
35
+ `dist/` (generated by `tsc`; `npm install` builds it through `prepare`).
36
+
37
+ ```ts
38
+ import { build, inspect, version } from "flexui-compiler";
39
+
40
+ await build({ minify: true, cwd: process.cwd(), output: "dist/flexui.css" });
41
+ const result = await inspect({ cwd: process.cwd() });
42
+ console.log(result.stdout);
43
+ ```
44
+
45
+ | Export | Purpose |
46
+ | --- | --- |
47
+ | `build(options)` | Compile the project and write the stylesheet. |
48
+ | `watch(options)` | Start watch mode. |
49
+ | `inspect(options)` | Print resolved rules. |
50
+ | `version(options)` | Read the compiler version. |
51
+ | `run(args, options)` | Run the compiler with arbitrary arguments, capturing output. |
52
+ | `runInherit(args, options)` | Run with inherited stdio; returns the exit code. |
53
+ | `resolveBinary()` | Path and verification state of the resolved binary. |
54
+ | `optArgs(options)` | Map options to compiler flags. |
55
+
56
+ `RunOptions` covers `cwd`, `root`, `config`, `input`, `output`, `content`,
57
+ `safelist`, `minify`, `verbose`, `noCache` and `env`. Failed builds reject with a
58
+ `FlexUIError` carrying `exitCode`, `stdout` and `stderr`.
59
+
60
+ ## Zero runtime dependencies
61
+
62
+ The published package has no `dependencies`. TypeScript and `@types/node` are
63
+ development-only.
package/checksums.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "win32-x64": { "file": "flexui.exe", "sha256": "791fedb89adbba9b19b8a917e2ede35dc436e6735dce345f7be603373051c1bf", "version": "2.0.0-alpha.2" },
3
+ "win32-arm64": { "file": "flexui.exe", "sha256": "ec2721b92a429269a449e4faa03488566b745a4ad723ae56fe5ebf690ee6f894", "version": "2.0.0-alpha.2" },
4
+ "linux-x64": { "file": "flexui", "sha256": "d3e176f3d77626f3a08beb208bb8d887c8925514b87a5db8cfc265b8ee28229d", "version": "2.0.0-alpha.2" },
5
+ "linux-arm64": { "file": "flexui", "sha256": "d2302194fc09518bd5012004a355022cde98a588b8c420eddd1f556fa0a41619", "version": "2.0.0-alpha.2" },
6
+ "darwin-x64": { "file": "flexui", "sha256": "f9db7865d99ba1775a7ffa9e70ab4ca6522860c3f7ea1e87bd18ed6441d85ef3", "version": "2.0.0-alpha.2" },
7
+ "darwin-arm64": { "file": "flexui", "sha256": "0a14623c5bbd09b21ebe2fe62751930ff1a5ec96c6fc11556a8aeb2aa55ab718", "version": "2.0.0-alpha.2" }
8
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Resolves the precompiled FlexUI compiler for the current platform.
3
+ *
4
+ * Resolution order:
5
+ * 1. `FLEXUI_BINARY` (explicit override used by CI and by release checks).
6
+ * 2. The optional platform package (`flexui-cli-<platform>-<arch>`), which
7
+ * npm installs as a normal dependency. No install script is involved, so
8
+ * it also works when lifecycle scripts are disabled.
9
+ * 3. A vendored copy inside this package (`binaries/<platform>-<arch>/`),
10
+ * produced by `scripts/build-binaries.sh` for offline use.
11
+ */
12
+ export interface PlatformInfo {
13
+ readonly pkg: string;
14
+ readonly binary: string;
15
+ }
16
+ export declare const PLATFORMS: Readonly<Record<string, PlatformInfo>>;
17
+ export interface ChecksumEntry {
18
+ readonly file: string;
19
+ readonly sha256: string;
20
+ readonly version: string;
21
+ }
22
+ export type Checksums = Record<string, ChecksumEntry>;
23
+ export interface ResolvedBinary {
24
+ readonly path: string;
25
+ readonly verified: boolean;
26
+ }
27
+ /** Returns the current platform key, for example `win32-x64`. */
28
+ export declare function platformKey(): string;
29
+ /** Reads the published checksum manifest, or an empty map when absent. */
30
+ export declare function readChecksums(): Checksums;
31
+ /** Locates the compiler binary or throws a message that says what to do. */
32
+ export declare function resolveBinary(): ResolvedBinary;
package/dist/binary.js ADDED
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /**
3
+ * Resolves the precompiled FlexUI compiler for the current platform.
4
+ *
5
+ * Resolution order:
6
+ * 1. `FLEXUI_BINARY` (explicit override used by CI and by release checks).
7
+ * 2. The optional platform package (`flexui-cli-<platform>-<arch>`), which
8
+ * npm installs as a normal dependency. No install script is involved, so
9
+ * it also works when lifecycle scripts are disabled.
10
+ * 3. A vendored copy inside this package (`binaries/<platform>-<arch>/`),
11
+ * produced by `scripts/build-binaries.sh` for offline use.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PLATFORMS = void 0;
15
+ exports.platformKey = platformKey;
16
+ exports.readChecksums = readChecksums;
17
+ exports.resolveBinary = resolveBinary;
18
+ const node_crypto_1 = require("node:crypto");
19
+ const node_fs_1 = require("node:fs");
20
+ const node_path_1 = require("node:path");
21
+ exports.PLATFORMS = {
22
+ "win32-x64": { pkg: "flexui-cli-windows-x64", binary: "flexui.exe" },
23
+ "win32-arm64": { pkg: "flexui-cli-windows-arm64", binary: "flexui.exe" },
24
+ "linux-x64": { pkg: "flexui-cli-linux-x64", binary: "flexui" },
25
+ "linux-arm64": { pkg: "flexui-cli-linux-arm64", binary: "flexui" },
26
+ "darwin-x64": { pkg: "flexui-cli-darwin-x64", binary: "flexui" },
27
+ "darwin-arm64": { pkg: "flexui-cli-darwin-arm64", binary: "flexui" },
28
+ };
29
+ /** Returns the current platform key, for example `win32-x64`. */
30
+ function platformKey() {
31
+ return `${process.platform}-${process.arch}`;
32
+ }
33
+ function checksumPath() {
34
+ return (0, node_path_1.join)(__dirname, "..", "checksums.json");
35
+ }
36
+ /** Reads the published checksum manifest, or an empty map when absent. */
37
+ function readChecksums() {
38
+ const file = checksumPath();
39
+ if (!(0, node_fs_1.existsSync)(file)) {
40
+ return {};
41
+ }
42
+ try {
43
+ return JSON.parse((0, node_fs_1.readFileSync)(file, "utf8"));
44
+ }
45
+ catch {
46
+ return {};
47
+ }
48
+ }
49
+ function verify(binaryPath, key) {
50
+ const expected = readChecksums()[key]?.sha256;
51
+ if (expected === undefined) {
52
+ // A locally built binary has no published checksum yet. Report it rather
53
+ // than failing, so development builds keep working.
54
+ return false;
55
+ }
56
+ const actual = (0, node_crypto_1.createHash)("sha256").update((0, node_fs_1.readFileSync)(binaryPath)).digest("hex");
57
+ if (actual !== expected) {
58
+ throw new Error([
59
+ `flexui: binary integrity check failed for ${binaryPath}`,
60
+ ` expected sha256 ${expected}`,
61
+ ` actual sha256 ${actual}`,
62
+ "Reinstall flexui to get an intact binary.",
63
+ ].join("\n"));
64
+ }
65
+ return true;
66
+ }
67
+ function candidatePaths(key) {
68
+ const info = exports.PLATFORMS[key];
69
+ if (info === undefined) {
70
+ return [];
71
+ }
72
+ const paths = [];
73
+ try {
74
+ const manifest = require.resolve(`${info.pkg}/package.json`);
75
+ paths.push((0, node_path_1.join)((0, node_path_1.dirname)(manifest), info.binary));
76
+ }
77
+ catch {
78
+ // The optional platform package is not installed for this platform.
79
+ }
80
+ paths.push((0, node_path_1.join)(__dirname, "..", "binaries", key, info.binary));
81
+ return paths;
82
+ }
83
+ /** Locates the compiler binary or throws a message that says what to do. */
84
+ function resolveBinary() {
85
+ const override = process.env["FLEXUI_BINARY"];
86
+ if (override !== undefined && override !== "") {
87
+ if (!(0, node_fs_1.existsSync)(override)) {
88
+ throw new Error(`flexui: FLEXUI_BINARY points at a missing file: ${override}`);
89
+ }
90
+ return { path: override, verified: false };
91
+ }
92
+ const key = platformKey();
93
+ const info = exports.PLATFORMS[key];
94
+ if (info === undefined) {
95
+ throw new Error([
96
+ `flexui: no precompiled compiler for ${key}.`,
97
+ `Supported platforms: ${Object.keys(exports.PLATFORMS).join(", ")}.`,
98
+ ].join("\n"));
99
+ }
100
+ const tried = [];
101
+ for (const candidate of candidatePaths(key)) {
102
+ tried.push(candidate);
103
+ if ((0, node_fs_1.existsSync)(candidate)) {
104
+ return { path: candidate, verified: verify(candidate, key) };
105
+ }
106
+ }
107
+ throw new Error([
108
+ `flexui: could not find the compiler binary for ${key}.`,
109
+ "Looked in:",
110
+ ...tried.map((candidate) => ` ${candidate}`),
111
+ `Install the platform package with: npm install ${info.pkg}`,
112
+ "or set FLEXUI_BINARY to a flexui binary.",
113
+ ].join("\n"));
114
+ }
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ /** Bin entry point for the `flexui` command (package `@flexui/cli`). */
3
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /** Bin entry point for the `flexui` command (package `@flexui/cli`). */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const index_1 = require("./index");
6
+ try {
7
+ process.exitCode = (0, index_1.runInherit)(process.argv.slice(2));
8
+ }
9
+ catch (error) {
10
+ console.error(error instanceof Error ? error.message : String(error));
11
+ process.exitCode = 1;
12
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Programmatic entry point for the FlexUI npm package.
3
+ *
4
+ * Every function here runs the native compiler; nothing duplicates compiler
5
+ * logic in TypeScript, so the CLI, the npm wrapper and any future bundler
6
+ * integration share one implementation.
7
+ */
8
+ export * from "./binary";
9
+ export interface RunOptions {
10
+ /** Working directory for the compiler process. */
11
+ cwd?: string;
12
+ /** Project directory passed as a positional argument. */
13
+ root?: string;
14
+ config?: string;
15
+ input?: string;
16
+ output?: string;
17
+ content?: string | readonly string[];
18
+ safelist?: string | readonly string[];
19
+ minify?: boolean;
20
+ verbose?: boolean;
21
+ noCache?: boolean;
22
+ env?: NodeJS.ProcessEnv;
23
+ }
24
+ export interface RunResult {
25
+ readonly code: number;
26
+ readonly stdout: string;
27
+ readonly stderr: string;
28
+ }
29
+ /** Raised when the compiler exits with a non-zero status. */
30
+ export declare class FlexUIError extends Error {
31
+ readonly exitCode: number;
32
+ readonly stdout: string;
33
+ readonly stderr: string;
34
+ constructor(message: string, exitCode: number, stdout: string, stderr: string);
35
+ }
36
+ /** Translates options into compiler flags. */
37
+ export declare function optArgs(options?: RunOptions): string[];
38
+ /**
39
+ * Runs the compiler with inherited stdio, so exit codes and signals behave
40
+ * exactly like a native binary. Used by the bin entry point.
41
+ */
42
+ export declare function runInherit(args: readonly string[], options?: RunOptions): number;
43
+ /** Runs the compiler and captures its output. */
44
+ export declare function run(args: readonly string[], options?: RunOptions): Promise<RunResult>;
45
+ /** Compiles the project and writes the stylesheet. */
46
+ export declare function build(options?: RunOptions): Promise<RunResult>;
47
+ /** Starts watch mode; resolves when the process exits. */
48
+ export declare function watch(options?: RunOptions): Promise<RunResult>;
49
+ /** Prints resolved rules without writing a file. */
50
+ export declare function inspect(options?: RunOptions): Promise<RunResult>;
51
+ /** Reads the compiler version. */
52
+ export declare function version(options?: RunOptions): Promise<RunResult>;
package/dist/index.js ADDED
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ /**
3
+ * Programmatic entry point for the FlexUI npm package.
4
+ *
5
+ * Every function here runs the native compiler; nothing duplicates compiler
6
+ * logic in TypeScript, so the CLI, the npm wrapper and any future bundler
7
+ * integration share one implementation.
8
+ */
9
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ var desc = Object.getOwnPropertyDescriptor(m, k);
12
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13
+ desc = { enumerable: true, get: function() { return m[k]; } };
14
+ }
15
+ Object.defineProperty(o, k2, desc);
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.FlexUIError = void 0;
25
+ exports.optArgs = optArgs;
26
+ exports.runInherit = runInherit;
27
+ exports.run = run;
28
+ exports.build = build;
29
+ exports.watch = watch;
30
+ exports.inspect = inspect;
31
+ exports.version = version;
32
+ const node_child_process_1 = require("node:child_process");
33
+ const binary_1 = require("./binary");
34
+ __exportStar(require("./binary"), exports);
35
+ /** Raised when the compiler exits with a non-zero status. */
36
+ class FlexUIError extends Error {
37
+ exitCode;
38
+ stdout;
39
+ stderr;
40
+ constructor(message, exitCode, stdout, stderr) {
41
+ super(message);
42
+ this.name = "FlexUIError";
43
+ this.exitCode = exitCode;
44
+ this.stdout = stdout;
45
+ this.stderr = stderr;
46
+ }
47
+ }
48
+ exports.FlexUIError = FlexUIError;
49
+ function asList(value) {
50
+ return Array.isArray(value) ? value.join(",") : String(value);
51
+ }
52
+ /** Translates options into compiler flags. */
53
+ function optArgs(options = {}) {
54
+ const args = [];
55
+ if (options.config !== undefined)
56
+ args.push("--config", options.config);
57
+ if (options.input !== undefined)
58
+ args.push("--input", options.input);
59
+ if (options.output !== undefined)
60
+ args.push("--output", options.output);
61
+ if (options.content !== undefined)
62
+ args.push("--content", asList(options.content));
63
+ if (options.safelist !== undefined)
64
+ args.push("--safelist", asList(options.safelist));
65
+ if (options.minify === true)
66
+ args.push("--minify");
67
+ if (options.verbose === true)
68
+ args.push("--verbose");
69
+ if (options.noCache === true)
70
+ args.push("--no-cache");
71
+ return args;
72
+ }
73
+ /**
74
+ * Runs the compiler with inherited stdio, so exit codes and signals behave
75
+ * exactly like a native binary. Used by the bin entry point.
76
+ */
77
+ function runInherit(args, options = {}) {
78
+ const binary = (0, binary_1.resolveBinary)();
79
+ const result = (0, node_child_process_1.spawnSync)(binary.path, [...args], {
80
+ stdio: "inherit",
81
+ cwd: options.cwd ?? process.cwd(),
82
+ env: options.env ?? process.env,
83
+ windowsHide: true,
84
+ });
85
+ if (result.error !== undefined) {
86
+ throw result.error;
87
+ }
88
+ return result.status ?? 1;
89
+ }
90
+ /** Runs the compiler and captures its output. */
91
+ function run(args, options = {}) {
92
+ const binary = (0, binary_1.resolveBinary)();
93
+ return new Promise((resolve, reject) => {
94
+ const child = (0, node_child_process_1.spawn)(binary.path, [...args], {
95
+ cwd: options.cwd ?? process.cwd(),
96
+ env: options.env ?? process.env,
97
+ windowsHide: true,
98
+ });
99
+ let stdout = "";
100
+ let stderr = "";
101
+ child.stdout?.setEncoding("utf8");
102
+ child.stderr?.setEncoding("utf8");
103
+ child.stdout?.on("data", (chunk) => {
104
+ stdout += chunk;
105
+ });
106
+ child.stderr?.on("data", (chunk) => {
107
+ stderr += chunk;
108
+ });
109
+ child.on("error", reject);
110
+ child.on("close", (code) => {
111
+ const exitCode = code ?? 1;
112
+ if (exitCode === 0) {
113
+ resolve({ code: exitCode, stdout, stderr });
114
+ return;
115
+ }
116
+ reject(new FlexUIError(stderr.trim() || `flexui exited with code ${exitCode}`, exitCode, stdout, stderr));
117
+ });
118
+ });
119
+ }
120
+ function command(name, options) {
121
+ const args = [name, ...optArgs(options)];
122
+ if (options.root !== undefined) {
123
+ args.push(options.root);
124
+ }
125
+ return args;
126
+ }
127
+ /** Compiles the project and writes the stylesheet. */
128
+ function build(options = {}) {
129
+ return run(command("build", options), options);
130
+ }
131
+ /** Starts watch mode; resolves when the process exits. */
132
+ function watch(options = {}) {
133
+ return run(command("watch", options), options);
134
+ }
135
+ /** Prints resolved rules without writing a file. */
136
+ function inspect(options = {}) {
137
+ return run(command("inspect", options), options);
138
+ }
139
+ /** Reads the compiler version. */
140
+ function version(options = {}) {
141
+ return run(["version"], options);
142
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "flexui-compiler",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.0-alpha.2",
4
+ "description": "FlexUI 2.0 - a utility-first CSS compiler written in Go, distributed as precompiled native binaries",
5
+ "license": "MIT",
6
+ "homepage": "https://github.com/Ahaduzzamankhan/flexui",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Ahaduzzamankhan/flexui.git"
10
+ },
11
+ "keywords": [
12
+ "css",
13
+ "utility-first",
14
+ "tailwind-alternative",
15
+ "compiler",
16
+ "go"
17
+ ],
18
+ "bin": {
19
+ "flexui": "dist/cli.js"
20
+ },
21
+ "main": "dist/index.js",
22
+ "types": "dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "require": "./dist/index.js",
27
+ "default": "./dist/index.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "checksums.json",
33
+ "README.md"
34
+ ],
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc -p tsconfig.json",
40
+ "typecheck": "tsc -p tsconfig.json --noEmit",
41
+ "prepare": "tsc -p tsconfig.json"
42
+ },
43
+ "optionalDependencies": {
44
+ "flexui-cli-windows-x64": "2.0.0-alpha.2",
45
+ "flexui-cli-windows-arm64": "2.0.0-alpha.2",
46
+ "flexui-cli-linux-x64": "2.0.0-alpha.2",
47
+ "flexui-cli-linux-arm64": "2.0.0-alpha.2",
48
+ "flexui-cli-darwin-x64": "2.0.0-alpha.2",
49
+ "flexui-cli-darwin-arm64": "2.0.0-alpha.2"
50
+ }
51
+ }