@tishlang/tish-format 1.0.12

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/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@tishlang/tish-format",
3
+ "version": "1.0.12",
4
+ "description": "Tish code formatter",
5
+ "license": "PIF",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/tishlang/tish.git"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "bin": {
14
+ "tish-format": "./bin/tish-format"
15
+ },
16
+ "scripts": {
17
+ "postinstall": "node scripts/install-bin.js"
18
+ },
19
+ "files": [
20
+ "bin",
21
+ "scripts/install-bin.js",
22
+ "platform",
23
+ "README.md",
24
+ "LICENSE",
25
+ "Cargo.toml",
26
+ "crates",
27
+ "justfile"
28
+ ],
29
+ "engines": {
30
+ "node": ">=22"
31
+ },
32
+ "keywords": [
33
+ "tish",
34
+ "format",
35
+ "formatter"
36
+ ]
37
+ }
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Copy platform/<os>-<arch>/tish-format to bin/tish-format so the npm bin is the native binary.
6
+ * If not found, attempts to build it from source using cargo.
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const { execSync } = require('child_process');
12
+
13
+ const platformKey = `${process.platform}-${process.arch}`;
14
+ const binaryName = process.platform === 'win32' ? 'tish-fmt.exe' : 'tish-fmt';
15
+ const crateName = 'tishlang_fmt';
16
+
17
+ const root = path.join(__dirname, '..');
18
+ const src = path.join(root, 'platform', platformKey, binaryName);
19
+ const dest = path.join(root, 'bin', 'tish-format');
20
+
21
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
22
+
23
+ if (!fs.existsSync(src)) {
24
+ if (process.env.TISH_NPM_PACK_REQUIRE === '1') {
25
+ console.error(`[tish-format] No prebuilt binary for this platform: ${platformKey}`);
26
+ console.error(`[tish-format] Expected: ${src}`);
27
+ process.exit(1);
28
+ }
29
+
30
+ console.warn(`[tish-format] No prebuilt binary for ${platformKey} found at: ${src}`);
31
+ console.warn(`[tish-format] Attempting to build from source via cargo...`);
32
+ try {
33
+ execSync(`cargo build --release -p ${crateName} --target-dir target`, { stdio: 'inherit', cwd: root });
34
+ const builtSrc = path.join(root, 'target', 'release', binaryName);
35
+ if (!fs.existsSync(builtSrc)) {
36
+ throw new Error(`Expected built binary at ${builtSrc}`);
37
+ }
38
+ fs.copyFileSync(builtSrc, dest);
39
+ console.log(`[tish-format] Successfully built from source.`);
40
+ } catch (err) {
41
+ console.error(`[tish-format] Failed to build from source.`);
42
+ console.error(`[tish-format] Make sure Rust and Cargo are installed (https://rustup.rs/).`);
43
+ console.error(err);
44
+ process.exit(1);
45
+ }
46
+ } else {
47
+ fs.copyFileSync(src, dest);
48
+ }
49
+
50
+ try {
51
+ fs.chmodSync(dest, 0o755);
52
+ } catch (_) {
53
+ /* Windows may ignore chmod */
54
+ }