@swiftuijs/twill-runtime 0.0.0-stage → 0.2.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 Saiya and twill contributors
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,4 +1,23 @@
1
- # Temporary Holding Version
1
+ # <img src="https://twill.evecalm.com/logo.png" alt="Twill hummingbird" align="right" width="40" height="40" /> Twill runtime
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.
4
- If no other versions are published within 30 days, this package and version will be deleted.
3
+ Optional, zero-dependency helpers for Twill, a TypeScript-based language with Swift-inspired syntax. Available in 0.2.0 for explicitly selected external cleanup helpers.
4
+
5
+ The compiler defaults to self-contained inline code. External mode shares dynamic synchronous `defer` draining across modules:
6
+
7
+ ```sh
8
+ pnpm add @swiftuijs/twill-runtime
9
+ ```
10
+
11
+ ```json
12
+ {
13
+ "runtime": "external"
14
+ }
15
+ ```
16
+
17
+ Put that option in `twill.config.json`, or use `twill({ runtime: 'external' })` in a build adapter. Install the runtime as a production dependency of applications and published libraries whose compiled code imports it. Inline-only output needs no runtime installation.
18
+
19
+ The compiler emits a hygienic named import from `@swiftuijs/twill-runtime/helpers/v1`. That subpath is a versioned compiler/helper ABI; applications normally use Twill syntax instead of calling helpers directly. ABI v1 preserves reverse cleanup order, runs every callback after failures and rethrows the last cleanup failure, including `undefined`. It is synchronous and ignores callback return values.
20
+
21
+ Single directly registered cleanup retains its native fast path. Explicit async or mixed cleanup stays inline to preserve scheduling. Guards, arrows, enum factories/matching and ordinary component output gain no runtime import. Only modules needing the helper import it; exports have no side effects, and bundlers can tree-shake unused helpers. There is no compiler, TypeScript engine, UI framework or Node-only API in the runtime.
22
+
23
+ Sharing reduces repeated uncompressed code but retains cleanup callback and array allocation. It is not a general speedup promise; gzip may already compress repeated inline code. See [performance](https://twill.evecalm.com/performance), [Twill documentation](https://twill.evecalm.com/) and [RFC 0032](https://github.com/swiftuijs/twill/blob/main/docs/rfcs/0032-optional-runtime-helpers.md). Twill's sibling UI project is [SwiftUI.js](https://swiftuijs.evecalm.com/).
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Compiler helper ABI v1. Synchronous cleanup uses native finally replacement
3
+ * semantics: every reached cleanup runs, and the last cleanup failure wins.
4
+ * Return values (including promises) are deliberately not awaited.
5
+ * @param {Array<() => unknown> | undefined} stack
6
+ * @returns {void}
7
+ */
8
+ export function runDefers(stack: Array<() => unknown> | undefined): void;
9
+ //# sourceMappingURL=v1.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1.d.ts","sourceRoot":"","sources":["../../src/helpers/v1.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,iCAHW,KAAK,CAAC,MAAM,OAAO,CAAC,GAAG,SAAS,GAC9B,IAAI,CAiBhB"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Compiler helper ABI v1. Synchronous cleanup uses native finally replacement
3
+ * semantics: every reached cleanup runs, and the last cleanup failure wins.
4
+ * Return values (including promises) are deliberately not awaited.
5
+ * @param {Array<() => unknown> | undefined} stack
6
+ * @returns {void}
7
+ */
8
+ export function runDefers(stack) {
9
+ let failed = false, failure;
10
+ while (stack?.length) {
11
+ const cleanup = stack.pop();
12
+ if (cleanup) {
13
+ try {
14
+ cleanup();
15
+ }
16
+ catch (error) {
17
+ failed = true;
18
+ failure = error;
19
+ }
20
+ }
21
+ }
22
+ if (failed)
23
+ throw failure;
24
+ }
25
+ //# sourceMappingURL=v1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v1.js","sourceRoot":"","sources":["../../src/helpers/v1.js"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,KAAK;IAC7B,IAAI,MAAM,GAAG,KAAK,EAChB,OAAO,CAAC;IACV,OAAO,KAAK,EAAE,MAAM,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,OAAO,EAAE,CAAC;YACZ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,GAAG,IAAI,CAAC;gBACd,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,MAAM;QAAE,MAAM,OAAO,CAAC;AAC5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,60 @@
1
1
  {
2
2
  "name": "@swiftuijs/twill-runtime",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Optional, zero-dependency runtime helpers for compiled Twill programs.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/swiftuijs/twill.git",
10
+ "directory": "packages/runtime"
11
+ },
12
+ "homepage": "https://twill.evecalm.com/",
13
+ "bugs": {
14
+ "url": "https://github.com/swiftuijs/twill/issues"
15
+ },
16
+ "sideEffects": false,
17
+ "files": [
18
+ "dist",
19
+ "src",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "exports": {
24
+ "./helpers/v1": {
25
+ "types": "./dist/helpers/v1.d.ts",
26
+ "import": "./dist/helpers/v1.js",
27
+ "default": "./dist/helpers/v1.js"
28
+ }
29
+ },
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
35
+ },
36
+ "devDependencies": {
37
+ "typescript": "5.9.3",
38
+ "@types/node": "^26.6.4",
39
+ "vitest": "^5.0.3",
40
+ "@vitest/coverage-v8": "^5.0.3"
41
+ },
42
+ "author": {
43
+ "name": "forth.ink",
44
+ "url": "https://forth.ink"
45
+ },
46
+ "keywords": [
47
+ "twill",
48
+ "runtime",
49
+ "typescript",
50
+ "defer",
51
+ "cleanup"
52
+ ],
53
+ "scripts": {
54
+ "build": "tsc -p tsconfig.build.json",
55
+ "typecheck": "tsc --noEmit -p tsconfig.json",
56
+ "test:unit": "vitest run",
57
+ "test:coverage": "vitest run --coverage",
58
+ "test:package": "node tests/consumer.mjs"
59
+ }
6
60
  }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Compiler helper ABI v1. Synchronous cleanup uses native finally replacement
3
+ * semantics: every reached cleanup runs, and the last cleanup failure wins.
4
+ * Return values (including promises) are deliberately not awaited.
5
+ * @param {Array<() => unknown> | undefined} stack
6
+ * @returns {void}
7
+ */
8
+ export function runDefers(stack) {
9
+ let failed = false,
10
+ failure;
11
+ while (stack?.length) {
12
+ const cleanup = stack.pop();
13
+ if (cleanup) {
14
+ try {
15
+ cleanup();
16
+ } catch (error) {
17
+ failed = true;
18
+ failure = error;
19
+ }
20
+ }
21
+ }
22
+ if (failed) throw failure;
23
+ }