@typestyles/build-runner 0.0.0-unstable.247bf362710f

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/dist/index.cjs ADDED
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ runTypestylesBuild: () => runTypestylesBuild
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_esbuild = require("esbuild");
27
+ var import_node_fs = require("fs");
28
+ var import_node_path = require("path");
29
+ var import_node_child_process = require("child_process");
30
+ function toImportPath(modulePath) {
31
+ const normalized = modulePath.replace(/\\/g, "/");
32
+ if (normalized.startsWith(".") || normalized.startsWith("/")) {
33
+ return normalized;
34
+ }
35
+ return `./${normalized}`;
36
+ }
37
+ async function runTypestylesBuild({
38
+ root,
39
+ modules
40
+ }) {
41
+ if (!modules.length) return "";
42
+ const importLines = modules.map((mod) => `import ${JSON.stringify(toImportPath(mod))};`).join("\n");
43
+ const bundleResult = await (0, import_esbuild.build)({
44
+ write: false,
45
+ bundle: true,
46
+ platform: "node",
47
+ format: "cjs",
48
+ target: "node18",
49
+ external: ["typestyles"],
50
+ stdin: {
51
+ contents: importLines,
52
+ resolveDir: root,
53
+ sourcefile: "typestyles-extract-entry.ts",
54
+ loader: "ts"
55
+ }
56
+ });
57
+ const bundledCode = bundleResult.outputFiles?.[0]?.text;
58
+ if (!bundledCode) {
59
+ throw new Error("[typestyles] Failed to produce extraction bundle.");
60
+ }
61
+ const scriptPath = (0, import_node_path.resolve)(root, `.typestyles-extract-${process.pid}.cjs`);
62
+ const script = `${bundledCode}
63
+ process.stdout.write(require('typestyles').getRegisteredCss());
64
+ `;
65
+ try {
66
+ (0, import_node_fs.writeFileSync)(scriptPath, script, "utf8");
67
+ const result = (0, import_node_child_process.spawnSync)(process.execPath, [scriptPath], {
68
+ cwd: root,
69
+ encoding: "utf8",
70
+ stdio: ["ignore", "pipe", "pipe"]
71
+ });
72
+ if (result.error) {
73
+ throw new Error(`[typestyles] Extraction failed: ${result.error.message}.`);
74
+ }
75
+ if (result.status !== 0) {
76
+ throw new Error(
77
+ `[typestyles] Extraction script failed:
78
+ ${result.stderr || result.stdout || "unknown error"}`
79
+ );
80
+ }
81
+ return result.stdout ?? "";
82
+ } finally {
83
+ if ((0, import_node_fs.existsSync)(scriptPath)) {
84
+ try {
85
+ (0, import_node_fs.unlinkSync)(scriptPath);
86
+ } catch {
87
+ }
88
+ }
89
+ }
90
+ }
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ runTypestylesBuild
94
+ });
@@ -0,0 +1,19 @@
1
+ interface RunTypestylesBuildOptions {
2
+ /**
3
+ * Project root used to resolve extraction entry modules.
4
+ */
5
+ root: string;
6
+ /**
7
+ * Module paths (relative to root) that register typestyles styles.
8
+ */
9
+ modules: string[];
10
+ }
11
+ /**
12
+ * Bundle + execute style registration modules and return collected CSS.
13
+ *
14
+ * This is shared by integrations (Vite, Rollup, Rolldown, etc.) so app code
15
+ * does not need an external TS runtime loader like tsx.
16
+ */
17
+ declare function runTypestylesBuild({ root, modules, }: RunTypestylesBuildOptions): Promise<string>;
18
+
19
+ export { type RunTypestylesBuildOptions, runTypestylesBuild };
@@ -0,0 +1,19 @@
1
+ interface RunTypestylesBuildOptions {
2
+ /**
3
+ * Project root used to resolve extraction entry modules.
4
+ */
5
+ root: string;
6
+ /**
7
+ * Module paths (relative to root) that register typestyles styles.
8
+ */
9
+ modules: string[];
10
+ }
11
+ /**
12
+ * Bundle + execute style registration modules and return collected CSS.
13
+ *
14
+ * This is shared by integrations (Vite, Rollup, Rolldown, etc.) so app code
15
+ * does not need an external TS runtime loader like tsx.
16
+ */
17
+ declare function runTypestylesBuild({ root, modules, }: RunTypestylesBuildOptions): Promise<string>;
18
+
19
+ export { type RunTypestylesBuildOptions, runTypestylesBuild };
package/dist/index.js ADDED
@@ -0,0 +1,69 @@
1
+ // src/index.ts
2
+ import { build as esbuildBuild } from "esbuild";
3
+ import { existsSync, unlinkSync, writeFileSync } from "fs";
4
+ import { resolve } from "path";
5
+ import { spawnSync } from "child_process";
6
+ function toImportPath(modulePath) {
7
+ const normalized = modulePath.replace(/\\/g, "/");
8
+ if (normalized.startsWith(".") || normalized.startsWith("/")) {
9
+ return normalized;
10
+ }
11
+ return `./${normalized}`;
12
+ }
13
+ async function runTypestylesBuild({
14
+ root,
15
+ modules
16
+ }) {
17
+ if (!modules.length) return "";
18
+ const importLines = modules.map((mod) => `import ${JSON.stringify(toImportPath(mod))};`).join("\n");
19
+ const bundleResult = await esbuildBuild({
20
+ write: false,
21
+ bundle: true,
22
+ platform: "node",
23
+ format: "cjs",
24
+ target: "node18",
25
+ external: ["typestyles"],
26
+ stdin: {
27
+ contents: importLines,
28
+ resolveDir: root,
29
+ sourcefile: "typestyles-extract-entry.ts",
30
+ loader: "ts"
31
+ }
32
+ });
33
+ const bundledCode = bundleResult.outputFiles?.[0]?.text;
34
+ if (!bundledCode) {
35
+ throw new Error("[typestyles] Failed to produce extraction bundle.");
36
+ }
37
+ const scriptPath = resolve(root, `.typestyles-extract-${process.pid}.cjs`);
38
+ const script = `${bundledCode}
39
+ process.stdout.write(require('typestyles').getRegisteredCss());
40
+ `;
41
+ try {
42
+ writeFileSync(scriptPath, script, "utf8");
43
+ const result = spawnSync(process.execPath, [scriptPath], {
44
+ cwd: root,
45
+ encoding: "utf8",
46
+ stdio: ["ignore", "pipe", "pipe"]
47
+ });
48
+ if (result.error) {
49
+ throw new Error(`[typestyles] Extraction failed: ${result.error.message}.`);
50
+ }
51
+ if (result.status !== 0) {
52
+ throw new Error(
53
+ `[typestyles] Extraction script failed:
54
+ ${result.stderr || result.stdout || "unknown error"}`
55
+ );
56
+ }
57
+ return result.stdout ?? "";
58
+ } finally {
59
+ if (existsSync(scriptPath)) {
60
+ try {
61
+ unlinkSync(scriptPath);
62
+ } catch {
63
+ }
64
+ }
65
+ }
66
+ }
67
+ export {
68
+ runTypestylesBuild
69
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@typestyles/build-runner",
3
+ "version": "0.0.0-unstable.247bf362710f",
4
+ "description": "Shared module execution utilities for typestyles build integrations",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "dependencies": {
25
+ "esbuild": "^0.27.3"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^25.2.1",
29
+ "tsup": "^8.0.0",
30
+ "typescript": "^5.4.0"
31
+ },
32
+ "license": "Apache-2.0",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "https://github.com/dbanksdesign/typestyles",
36
+ "directory": "packages/build-runner"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
40
+ "typecheck": "tsc --noEmit"
41
+ }
42
+ }