@backtickjs/tspatch-plugin 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jean-François Bisson
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,38 @@
1
- # Temporary Holding Version
1
+ # @backtickjs/tspatch-plugin
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
+ Compiles `cs` client scripts when you build your server ahead of time. It's a [ts-patch](https://github.com/nonara/ts-patch) transformer: build with `tspc` and the output is plain JavaScript, which runs on `node`, Bun or a serverless platform with no loader. To compile a server's files as they load instead, with no build step, use [`@backtickjs/node-plugin`](https://github.com/backtickjs/backtick/tree/main/packages/node-plugin) or [`@backtickjs/bun-plugin`](https://github.com/backtickjs/backtick/tree/main/packages/bun-plugin). Backtick's own adapters are built with it.
4
+
5
+ ## Usage
6
+
7
+ Requires ts-patch 4 and TypeScript 6. Add the transformer to `tsconfig.json`, and name your framework's compile steps in the `package.json` beside it:
8
+
9
+ ```json
10
+ {
11
+ "compilerOptions": {
12
+ "plugins": [{ "transform": "@backtickjs/tspatch-plugin" }]
13
+ }
14
+ }
15
+ ```
16
+
17
+ ```json
18
+ {
19
+ "backtick": { "plugins": ["@backtickjs/solid-js/plugin"] },
20
+ "scripts": {
21
+ "build": "tspc -b --noCheck",
22
+ "typecheck": "backtick-tsc --noEmit"
23
+ }
24
+ }
25
+ ```
26
+
27
+ Build with `tspc` (from ts-patch) in place of `tsc`; plain `tsc` ignores the transformer and leaves scripts uncompiled. Backtick's adapters build with `--noCheck` and type-check separately with [`backtick-tsc`](https://github.com/backtickjs/backtick/tree/main/packages/tsc), which checks inside scripts. A script the compiler refuses is reported as a build error.
28
+
29
+ Source maps name a script's file as `<package name>/<path from the tsconfig directory>`, so they are the same on every machine.
30
+
31
+ ## Related
32
+
33
+ - [`@backtickjs/tsc`](https://github.com/backtickjs/backtick/tree/main/packages/tsc): type-checks scripts and writes their declarations
34
+ - [Documentation](https://backtickjs.com/docs)
35
+
36
+ ## License
37
+
38
+ MIT
@@ -0,0 +1,21 @@
1
+ import type { PluginConfig, TransformerExtras } from "ts-patch";
2
+ import type ts from "typescript";
3
+ /**
4
+ * Use it from a `tsconfig.json`:
5
+ *
6
+ * ```json
7
+ * {
8
+ * "compilerOptions": {
9
+ * "plugins": [{ "transform": "@backtickjs/tspatch-plugin" }]
10
+ * }
11
+ * }
12
+ * ```
13
+ *
14
+ * and compile with `tspc` (from `ts-patch`) instead of `tsc`. The framework's
15
+ * compile steps are the project's, named in its `package.json`:
16
+ *
17
+ * ```json
18
+ * "backtick": { "plugins": ["@backtickjs/solid-js/plugin"] }
19
+ * ```
20
+ */
21
+ export default function transformer(program: ts.Program, _config: PluginConfig, { ts, addDiagnostic }: TransformerExtras): ts.TransformerFactory<ts.SourceFile>;
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import { pluginsFrom, transform } from "@backtickjs/compiler";
5
+ /**
6
+ * Use it from a `tsconfig.json`:
7
+ *
8
+ * ```json
9
+ * {
10
+ * "compilerOptions": {
11
+ * "plugins": [{ "transform": "@backtickjs/tspatch-plugin" }]
12
+ * }
13
+ * }
14
+ * ```
15
+ *
16
+ * and compile with `tspc` (from `ts-patch`) instead of `tsc`. The framework's
17
+ * compile steps are the project's, named in its `package.json`:
18
+ *
19
+ * ```json
20
+ * "backtick": { "plugins": ["@backtickjs/solid-js/plugin"] }
21
+ * ```
22
+ */
23
+ export default function transformer(program, _config, { ts, addDiagnostic }) {
24
+ // A script's map names its file as its package does, `@scope/name/src/…`, as
25
+ // webpack's `webpack://<package name>/…` does: the same on every machine, and
26
+ // distinct from another package's in a bundle's map. The package is the one
27
+ // whose `tsconfig.json` this builds.
28
+ const root = path.posix.dirname(program.getCompilerOptions().configFilePath);
29
+ const packageJson = readFileSync(path.join(root, "package.json"), "utf8");
30
+ const { name } = JSON.parse(packageJson);
31
+ // Loaded as the project resolves them, at once, as a transformer is.
32
+ const plugins = pluginsFrom(packageJson, createRequire(path.resolve(root, "package.json")));
33
+ return transform(ts, (diagnostic) => {
34
+ addDiagnostic(diagnostic);
35
+ },
36
+ // TypeScript's file names use `/` on every platform.
37
+ {
38
+ sourceName: (fileName) => path.posix.join(name, path.posix.relative(root, fileName)),
39
+ plugins,
40
+ });
41
+ }
42
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAI9D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,OAAmB,EACnB,OAAqB,EACrB,EAAE,EAAE,EAAE,aAAa,EAAqB;IAExC,6EAA6E;IAC7E,8EAA8E;IAC9E,4EAA4E;IAC5E,qCAAqC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAC7B,OAAO,CAAC,kBAAkB,EAAE,CAAC,cAAwB,CACtD,CAAC;IACF,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;IAC1E,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAqB,CAAC;IAC7D,qEAAqE;IACrE,MAAM,OAAO,GAAG,WAAW,CACzB,WAAW,EACX,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAClD,CAAC;IACF,OAAO,SAAS,CACd,EAAE,EACF,CAAC,UAAU,EAAE,EAAE;QACb,aAAa,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;IACD,qDAAqD;IACrD;QACE,UAAU,EAAE,CAAC,QAAQ,EAAE,EAAE,CACvB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC5D,OAAO;KACR,CACF,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@backtickjs/tspatch-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Compiles Backtick client scripts when you build your server ahead of time with ts-patch's tspc",
5
+ "keywords": [
6
+ "backtick",
7
+ "react-native",
8
+ "server-driven-ui",
9
+ "server-components",
10
+ "ts-patch",
11
+ "tspc",
12
+ "typescript",
13
+ "transformer"
14
+ ],
15
+ "homepage": "https://backtickjs.com",
16
+ "bugs": {
17
+ "url": "https://github.com/backtickjs/backtick/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/backtickjs/backtick.git",
22
+ "directory": "packages/tspatch-plugin"
23
+ },
24
+ "license": "MIT",
25
+ "author": "Jean-François Bisson <jf@backtickjs.com>",
26
+ "type": "module",
27
+ "main": "./dist/index.js",
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "!dist/._cache",
37
+ "src"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "dependencies": {
43
+ "@backtickjs/compiler": "0.1.0"
44
+ },
45
+ "peerDependencies": {
46
+ "ts-patch": "^4.0.1",
47
+ "typescript": "^6.0.3"
48
+ },
49
+ "devDependencies": {
50
+ "prettier": "^3.6.2",
51
+ "ts-patch": "^4.0.1",
52
+ "typescript": "^6.0.3"
53
+ },
54
+ "scripts": {
55
+ "build": "tsc -b",
56
+ "dev": "tsc -b --watch",
57
+ "format": "prettier --write --ignore-unknown .",
58
+ "format:check": "prettier --check --ignore-unknown .",
59
+ "clean": "rm -rf node_modules dist .turbo"
60
+ }
6
61
  }
package/src/index.ts ADDED
@@ -0,0 +1,57 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import path from "node:path";
4
+ import { pluginsFrom, transform } from "@backtickjs/compiler";
5
+ import type { PluginConfig, TransformerExtras } from "ts-patch";
6
+ import type ts from "typescript";
7
+
8
+ /**
9
+ * Use it from a `tsconfig.json`:
10
+ *
11
+ * ```json
12
+ * {
13
+ * "compilerOptions": {
14
+ * "plugins": [{ "transform": "@backtickjs/tspatch-plugin" }]
15
+ * }
16
+ * }
17
+ * ```
18
+ *
19
+ * and compile with `tspc` (from `ts-patch`) instead of `tsc`. The framework's
20
+ * compile steps are the project's, named in its `package.json`:
21
+ *
22
+ * ```json
23
+ * "backtick": { "plugins": ["@backtickjs/solid-js/plugin"] }
24
+ * ```
25
+ */
26
+ export default function transformer(
27
+ program: ts.Program,
28
+ _config: PluginConfig,
29
+ { ts, addDiagnostic }: TransformerExtras,
30
+ ): ts.TransformerFactory<ts.SourceFile> {
31
+ // A script's map names its file as its package does, `@scope/name/src/…`, as
32
+ // webpack's `webpack://<package name>/…` does: the same on every machine, and
33
+ // distinct from another package's in a bundle's map. The package is the one
34
+ // whose `tsconfig.json` this builds.
35
+ const root = path.posix.dirname(
36
+ program.getCompilerOptions().configFilePath as string,
37
+ );
38
+ const packageJson = readFileSync(path.join(root, "package.json"), "utf8");
39
+ const { name } = JSON.parse(packageJson) as { name: string };
40
+ // Loaded as the project resolves them, at once, as a transformer is.
41
+ const plugins = pluginsFrom(
42
+ packageJson,
43
+ createRequire(path.resolve(root, "package.json")),
44
+ );
45
+ return transform(
46
+ ts,
47
+ (diagnostic) => {
48
+ addDiagnostic(diagnostic);
49
+ },
50
+ // TypeScript's file names use `/` on every platform.
51
+ {
52
+ sourceName: (fileName) =>
53
+ path.posix.join(name, path.posix.relative(root, fileName)),
54
+ plugins,
55
+ },
56
+ );
57
+ }