@goodpuppies/workman 0.0.0-stage → 0.9.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Good Puppies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # Workman
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
+ Workman 0.9.0: the compiler, language server, REPL, test runner, TypeScript 7.1 content mapper and Vite/Bun integrations.
4
+
5
+ Install optional dependencies to obtain the platform binary, which embeds the Deno runtime; no separate Deno installation is needed. Node is required for the CLI and mapper launcher; Bun can use the integration directly.
6
+
7
+ This build does not yet support programs that import packages (bare, npm:, jsr: or remote specifiers), or building executables with --executable; use the Deno/JSR installation for those.
@@ -0,0 +1,33 @@
1
+ const path = require("node:path");
2
+ const fs = require("node:fs");
3
+ const manifest = require("../package.json");
4
+
5
+ exports.resolveBinary = function () {
6
+ const key = `${process.platform}-${process.arch}`;
7
+ const names = {
8
+ "linux-x64": "linux-x64",
9
+ "linux-arm64": "linux-arm64",
10
+ "darwin-x64": "darwin-x64",
11
+ "darwin-arm64": "darwin-arm64",
12
+ "win32-x64": "win32-x64",
13
+ "win32-arm64": "win32-arm64",
14
+ };
15
+ const suffix = names[key];
16
+ if (!suffix) throw new Error(`Workman has no prebuilt binary for ${key}`);
17
+ const name = `${manifest.name}-${suffix}`;
18
+ let metadata;
19
+ try {
20
+ metadata = require.resolve(`${name}/package.json`);
21
+ } catch {
22
+ throw new Error(
23
+ `Missing ${name}@${manifest.version}. Install optional dependencies; Linux binaries require glibc.`,
24
+ );
25
+ }
26
+ const platform = JSON.parse(fs.readFileSync(metadata, "utf8"));
27
+ if (platform.version !== manifest.version) {
28
+ throw new Error(
29
+ `Workman binary version mismatch: expected ${manifest.version}, found ${platform.version}`,
30
+ );
31
+ }
32
+ return path.join(path.dirname(metadata), "bin", process.platform === "win32" ? "wm.exe" : "wm");
33
+ };
package/bin/wm.cjs ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require("node:child_process");
3
+ try {
4
+ const binary = require("./resolve.cjs").resolveBinary();
5
+ const child = spawn(binary, process.argv.slice(2), { stdio: "inherit" });
6
+ for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, () => child.kill(signal));
7
+ child.on("error", (error) => {
8
+ console.error(error.message);
9
+ process.exitCode = 1;
10
+ });
11
+ child.on("exit", (code, signal) => {
12
+ process.exitCode = code ?? (signal === "SIGINT" ? 130 : 1);
13
+ });
14
+ } catch (error) {
15
+ console.error(error.message);
16
+ process.exitCode = 1;
17
+ }
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@goodpuppies/workman",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.9.0",
4
+ "type": "module",
5
+ "description": "Workman language tools and experimental TypeScript content mapper",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/goodpuppies/workman.git"
10
+ },
11
+ "bin": {
12
+ "wm": "./bin/wm.cjs"
13
+ },
14
+ "exports": {
15
+ "./vite": {
16
+ "types": "./src/integrations/vite.d.mts",
17
+ "import": "./src/integrations/vite.mjs"
18
+ },
19
+ "./interop": {
20
+ "types": "./src/integrations/interop.d.mts",
21
+ "import": "./src/integrations/interop.mjs"
22
+ },
23
+ "./bun": {
24
+ "types": "./src/integrations/bun.d.mts",
25
+ "import": "./src/integrations/bun.mjs"
26
+ }
27
+ },
28
+ "files": [
29
+ "bin",
30
+ "src/integrations",
31
+ "README.md",
32
+ "LICENSE"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "engines": {
38
+ "node": ">=20"
39
+ },
40
+ "typescript": {
41
+ "contentMapper": {
42
+ "exec": [
43
+ "node",
44
+ "./bin/wm.cjs",
45
+ "content-mapper"
46
+ ],
47
+ "compilerOptions": [],
48
+ "dynamicConfig": true
49
+ }
50
+ },
51
+ "optionalDependencies": {
52
+ "@goodpuppies/workman-linux-x64": "0.9.0",
53
+ "@goodpuppies/workman-linux-arm64": "0.9.0",
54
+ "@goodpuppies/workman-darwin-x64": "0.9.0",
55
+ "@goodpuppies/workman-darwin-arm64": "0.9.0",
56
+ "@goodpuppies/workman-win32-x64": "0.9.0",
57
+ "@goodpuppies/workman-win32-arm64": "0.9.0"
58
+ }
59
+ }
@@ -0,0 +1,17 @@
1
+ export interface WorkmanOptions {
2
+ compilerPath?: string;
3
+ }
4
+ /** Bun runtime/bundler plugin; register at startup before importing WM. */
5
+ export function workman(options?: WorkmanOptions): {
6
+ name: string;
7
+ setup(build: {
8
+ onLoad(
9
+ options: { filter: RegExp },
10
+ callback: (args: { path: string }) => Promise<{
11
+ contents: string;
12
+ loader: "js";
13
+ resolveDir: string;
14
+ }>,
15
+ ): void;
16
+ }): void;
17
+ };
@@ -0,0 +1,19 @@
1
+ import { dirname } from "node:path";
2
+ import { compileWorkman } from "./compile.mjs";
3
+
4
+ /** Use with Bun.plugin() in a preload, or in Bun.build({ plugins: [...] }). */
5
+ export function workman(options = {}) {
6
+ return {
7
+ name: "workman",
8
+ setup(build) {
9
+ build.onLoad({ filter: /\.wm$/ }, async ({ path }) => {
10
+ const result = await compileWorkman(path, options);
11
+ return {
12
+ contents: result.code,
13
+ loader: "js",
14
+ resolveDir: dirname(path),
15
+ };
16
+ });
17
+ },
18
+ };
19
+ }
@@ -0,0 +1,22 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { createRequire } from "node:module";
4
+ const run = promisify(execFile);
5
+ const { resolveBinary } = createRequire(import.meta.url)("../../bin/resolve.cjs");
6
+
7
+ export async function compileWorkman(path, options = {}) {
8
+ try {
9
+ const { stdout } = await run(options.compilerPath ?? resolveBinary(), [
10
+ "compile-library-json",
11
+ path,
12
+ ], {
13
+ maxBuffer: 64 * 1024 * 1024,
14
+ timeout: 60_000,
15
+ });
16
+ return JSON.parse(stdout);
17
+ } catch (error) {
18
+ throw new Error(`Workman compilation failed for ${path}\n${error.stderr || error.message}`, {
19
+ cause: error,
20
+ });
21
+ }
22
+ }
@@ -0,0 +1,52 @@
1
+ declare const optionBrand: unique symbol;
2
+
3
+ /**
4
+ * A Workman `Option`. Opaque: construct it with `Some`/`None`/`fromNullable` and read it with
5
+ * `isSome`, `getOr`, `match`, or `toNullable`. Nested Options and `Some(undefined)` stay distinct.
6
+ */
7
+ export interface Option<out T> {
8
+ readonly [optionBrand]: T;
9
+ }
10
+
11
+ declare const jsErrorBrand: unique symbol;
12
+
13
+ /** A Workman `Js.Error`: a failure caught at a safe JS FFI boundary. Opaque. */
14
+ export interface JsError {
15
+ readonly [jsErrorBrand]: true;
16
+ }
17
+
18
+ declare const unprojectableBrand: unique symbol;
19
+
20
+ /**
21
+ * The type of a Workman export that has no TypeScript form yet; `Reason` says why. Nothing
22
+ * can be done with it, so TypeScript reports the reason where the export is used.
23
+ */
24
+ export interface Unprojectable<Reason extends string> {
25
+ readonly [unprojectableBrand]: Reason;
26
+ }
27
+
28
+ /** A Workman `Result`, as a discriminated union. */
29
+ export type Result<T, E> =
30
+ | { readonly ok: true; readonly value: T }
31
+ | { readonly ok: false; readonly error: E };
32
+
33
+ /** A Workman `Task`: eager, and an ordinary WM `Err` resolves rather than rejects. */
34
+ export type Task<T, E> = Promise<Result<T, E>>;
35
+
36
+ export const None: Option<never>;
37
+ export function Some<T>(value: T): Option<T>;
38
+ export function isSome<T>(option: Option<T>): boolean;
39
+ export function isNone<T>(option: Option<T>): boolean;
40
+ export function getOr<T>(option: Option<T>, fallback: T): T;
41
+ export function match<T, R>(
42
+ option: Option<T>,
43
+ cases: { readonly some: (value: T) => R; readonly none: () => R },
44
+ ): R;
45
+ /** `null` and `undefined` become `None`; any other value, `Some(value)`. */
46
+ export function fromNullable<T>(value: T | null | undefined): Option<T>;
47
+ /** `None` becomes `undefined`. Loses the distinction for `Option<undefined>` and nested Options. */
48
+ export function toNullable<T>(option: Option<T>): T | undefined;
49
+ export function Ok<T>(value: T): Result<T, never>;
50
+ export function Err<E>(error: E): Result<never, E>;
51
+ /** The message of a `Js.Error`, or `undefined` for `Js.Unknown` (a thrown non-Error value). */
52
+ export function jsErrorMessage(error: JsError): string | undefined;
@@ -0,0 +1,61 @@
1
+ // TypeScript/JavaScript helpers for values crossing the Workman library boundary.
2
+ //
3
+ // Option values are opaque WM values. Nullary basis constructors are shared through
4
+ // globalThis, so a None built here is the same object every compiled WM library matches.
5
+
6
+ const NONE_ID = -1;
7
+ const SOME_ID = -2;
8
+
9
+ /** The shared None, as the WM runtime prelude registers it. Keep in sync with emit_prelude.ts. */
10
+ export const None = (globalThis[Symbol.for(`workman.basis.ctor.${NONE_ID}`)] ??= Object.freeze({
11
+ ctor: NONE_ID,
12
+ name: "None",
13
+ }));
14
+
15
+ export function Some(value) {
16
+ return { ctor: SOME_ID, name: "Some", a0: value };
17
+ }
18
+
19
+ function checked(option) {
20
+ if (option === None || option?.ctor === SOME_ID) return option;
21
+ throw new TypeError("Expected a Workman Option");
22
+ }
23
+
24
+ export function isSome(option) {
25
+ return checked(option) !== None;
26
+ }
27
+
28
+ export function isNone(option) {
29
+ return checked(option) === None;
30
+ }
31
+
32
+ export function getOr(option, fallback) {
33
+ return checked(option) === None ? fallback : option.a0;
34
+ }
35
+
36
+ export function match(option, cases) {
37
+ return checked(option) === None ? cases.none() : cases.some(option.a0);
38
+ }
39
+
40
+ export function fromNullable(value) {
41
+ return value == null ? None : Some(value);
42
+ }
43
+
44
+ export function toNullable(option) {
45
+ return checked(option) === None ? undefined : option.a0;
46
+ }
47
+
48
+ export function Ok(value) {
49
+ return { ok: true, value };
50
+ }
51
+
52
+ export function Err(error) {
53
+ return { ok: false, error };
54
+ }
55
+
56
+ const JS_ERROR_ID = -7;
57
+
58
+ /** The message of a WM Js.Error, or undefined for Js.Unknown (a thrown non-Error value). */
59
+ export function jsErrorMessage(error) {
60
+ return error?.ctor === JS_ERROR_ID ? error.a0 : undefined;
61
+ }
@@ -0,0 +1,12 @@
1
+ export interface WorkmanOptions {
2
+ compilerPath?: string;
3
+ }
4
+ /** Vite plugin. Compiles WM library entries and watches their transitive WM dependencies. */
5
+ export function workman(options?: WorkmanOptions): {
6
+ name: string;
7
+ enforce: "pre";
8
+ load(
9
+ this: { addWatchFile(path: string): void },
10
+ id: string,
11
+ ): Promise<{ code: string; map: null } | null>;
12
+ };
@@ -0,0 +1,28 @@
1
+ import { compileWorkman } from "./compile.mjs";
2
+
3
+ export function workman(options = {}) {
4
+ const dependencies = new Map();
5
+ return {
6
+ name: "workman",
7
+ enforce: "pre",
8
+ async load(id) {
9
+ // Leave Vite's explicit asset/text queries to Vite.
10
+ if (!id.endsWith(".wm")) return null;
11
+ const result = await compileWorkman(id, options);
12
+ dependencies.set(id, new Set(result.dependencies));
13
+ for (const path of result.dependencies) this.addWatchFile(path);
14
+ return { code: result.code, map: null };
15
+ },
16
+ hotUpdate(context) {
17
+ const modules = new Set(context.modules);
18
+ for (const [entry, paths] of dependencies) {
19
+ if (!paths.has(context.file)) continue;
20
+ for (const module of this.environment.moduleGraph.getModulesByFile(entry) ?? []) {
21
+ this.environment.moduleGraph.invalidateModule(module, new Set(), context.timestamp, true);
22
+ modules.add(module);
23
+ }
24
+ }
25
+ return [...modules];
26
+ },
27
+ };
28
+ }