@jti/typst 1.0.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/CHANGELOG.adoc ADDED
@@ -0,0 +1,20 @@
1
+ // vim: tw=0 ai et ts=2 sw=2
2
+ = Changelog
3
+ Ewan Edwards <eedwards@journaltech.com>
4
+ :keepacl: https://keepachangelog.com/en/1.1.0/[Keep a Changelog^]
5
+ :semantic: https://semver.org/spec/v2.0.0.html[Semantic Versioning^]
6
+ :org: https://github.com/jtidocs
7
+ :repo: jti-typst
8
+ :unreleased: {org}/{repo}/compare/v1.0.0\...HEAD[Unreleased]
9
+ :1-0-0: {org}/{repo}/releases/tag/1.0.0[1.0.0]
10
+
11
+ All notable changes to this project are documented in this file.
12
+
13
+ The format is based on {keepacl}, and this project adheres to {semantic}.
14
+
15
+
16
+ == {unreleased}
17
+
18
+ == {1-0-0} - 2026-03-29
19
+
20
+ - Initial release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Journal Technologies, Inc.
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.adoc ADDED
@@ -0,0 +1,3 @@
1
+ = jti-typst
2
+
3
+ A Node.js package that installs a Typst binary suitable for the host platform.
package/install.js ADDED
@@ -0,0 +1,167 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Installs a platform/arch appropriate binary for typst/typst.
4
+
5
+ 'use strict'
6
+
7
+ const fs = require('fs')
8
+ const path = require('path')
9
+ const { pipeline } = require('stream/promises')
10
+ const tar = require('tar')
11
+ const https = require('https')
12
+ const http = require('http')
13
+ const lzma = require('lzma-native')
14
+
15
+ // Debugging helper.
16
+ const DEBUG = true
17
+ const debug = function (...msgs) {
18
+ if (DEBUG) {
19
+ for (let m of msgs) {
20
+ console.log(m)
21
+ }
22
+ }
23
+ }
24
+
25
+ // Main configuration.
26
+ const cwd = process.env.INIT_CWD
27
+ ? process.env.INIT_CWD
28
+ : process.cwd()
29
+ const { platform, arch } = process
30
+ const typstVersion = '0.14.2'
31
+ const targetFolder = path.join(__dirname, 'bin')
32
+
33
+ // Returns the release-specific platform string based on platform
34
+ const mapPlatform = (map = {}) => {
35
+ if (!(platform in map)) return null
36
+ return map[platform]
37
+ }
38
+
39
+ // Returns the release-specific arch string based on arch
40
+ const mapArch = (map = {}) => {
41
+ if (!(arch in map)) return null
42
+ return map[arch]
43
+ }
44
+
45
+ const extractTarXz = async (source, outputDir = 'bin') => {
46
+ // Create output directory if it doesn't exist
47
+ if (!fs.existsSync(outputDir)) {
48
+ fs.mkdirSync(outputDir, { recursive: true })
49
+ debug(`Created output dir: ${outputDir}`)
50
+ }
51
+
52
+ let readStream
53
+
54
+ // Handle HTTP/HTTPS URL
55
+ const client = source.startsWith('https://') ? https : http
56
+ readStream = await new Promise((resolve, reject) => {
57
+ const handleResponse = (response) => {
58
+ if (response.statusCode === 302 || response.statusCode === 301) {
59
+ // Handle redirects
60
+ const redirectUrl = response.headers.location
61
+ const redirectClient = redirectUrl.startsWith('https://') ? https : http
62
+ redirectClient.get(redirectUrl, handleResponse).on('error', reject)
63
+ } else if (response.statusCode === 200) {
64
+ resolve(response)
65
+ } else {
66
+ reject(new Error(`Failed to fetch: ${response.statusCode}`))
67
+ }
68
+ }
69
+
70
+ client.get(source, handleResponse).on('error', reject);
71
+ })
72
+
73
+ // Decompress xz and extract tar in one pipeline
74
+ debug(`Have HTTP response for release`)
75
+ await pipeline(
76
+ readStream,
77
+ lzma.createDecompressor(),
78
+ tar.extract({
79
+ cwd: outputDir,
80
+ strip: 0
81
+ })
82
+ )
83
+ debug('Fetched, decompressed, and wrote release contents')
84
+ debug(fs.readdirSync(outputDir))
85
+ }
86
+
87
+ const getRelease = async (url, outputDir) => {
88
+ console.log(`Installing ${url} into ${outputDir}`)
89
+
90
+ // Fetch an unpack the release archive
91
+ await extractTarXz(url, outputDir)
92
+
93
+ // Typst archives include an encapsulating folder.
94
+ // So:
95
+ // 1. Move the `typst` executable to the target folder.
96
+ // 2. Remove the encapsulating folder.
97
+ try {
98
+ // determine the path to the encapsulating folder
99
+ let [dirname] = path.basename(url).split('.tar.xz')
100
+ let dir = path.join(outputDir, dirname)
101
+ debug(`Encapsulating folder: ${dir}`)
102
+
103
+ // Find the Typst binary
104
+ let found = false
105
+ const files = fs.readdirSync(dir)
106
+ for (let file of files) {
107
+ debug(`Evaluating file: ${file}`)
108
+ if (file.startsWith('typst')) {
109
+ found = true
110
+ debug(`Found binary! Moving...`)
111
+ // Move the binary out of the encapsulating folder
112
+ fs.renameSync(path.join(dir, file), path.join(outputDir, file))
113
+ debug('Moved!')
114
+ break
115
+ }
116
+ }
117
+
118
+ // Remove the encapsulating folder
119
+ if (found) {
120
+ debug(`Removing encapsulating folder...`)
121
+ fs.rmSync(dir, { recursive: true })
122
+ debug(`Removed...`)
123
+ }
124
+ else {
125
+ debug("Did not find Typst binary!")
126
+ }
127
+ }
128
+ catch (err) {
129
+ console.log(`Could not process downloaded asset:`, err)
130
+ }
131
+ debug(`All done!`)
132
+ }
133
+
134
+ const typst = async () => {
135
+ // Set up the download URL for the appropriate platform/arch.
136
+ const p = mapPlatform({
137
+ 'darwin': 'apple-darwin',
138
+ 'linux': 'unknown-linux-musl',
139
+ 'win32': 'pc-windows-msvc'
140
+ })
141
+
142
+ const a = mapArch({
143
+ 'x64': 'x86_64',
144
+ 'arm64': 'aarch64',
145
+ })
146
+
147
+ if (!p || !a) {
148
+ console.log(`Cannot handle a Typst release for ${p}/${a}.`)
149
+ return
150
+ }
151
+
152
+ const ext = (p === 'pc-windows-msvc') ? 'zip' : 'tar.xz'
153
+ if (ext !== 'tar.xz' && ext !== 'zip') {
154
+ console.log(`Don't know how to handle a .${ext} file!`)
155
+ return
156
+ }
157
+
158
+ const url = `https://github.com/typst/typst/releases/download/`
159
+ + `v${typstVersion}/typst-${a}-${p}.${ext}`
160
+
161
+ await getRelease(url, targetFolder)
162
+ debug(`Really all done!`)
163
+ process.exit(0)
164
+ }
165
+
166
+ console.log(`Installing typst...`)
167
+ typst()
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@jti/typst",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "author": "Ewan Edwards <eedwards@journaltech.com>",
6
+ "description": "This package installs typst/typst in the `bin` folder.",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/jtidocs/jti-typst.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/jtidocs/jti-typst/issues"
13
+ },
14
+ "homepage": "https://github.com/jtidocs/jti-typst#readme",
15
+ "main": "install.js",
16
+ "scripts": {
17
+ "test": "echo \"Error: no test specified\" && exit 1",
18
+ "postinstall": "node install.js"
19
+ },
20
+ "bin": {
21
+ "typst": "run.js"
22
+ },
23
+ "keywords": [
24
+ "antora",
25
+ "documentation",
26
+ "link",
27
+ "check",
28
+ "vale",
29
+ "tools"
30
+ ],
31
+ "dependencies": {
32
+ "tar": "7.4.3",
33
+ "lzma-native": "8.0.6",
34
+ "@jti/utils": "1.0.3"
35
+ }
36
+ }
package/run.js ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+ const path = require('path');
3
+ const { execFileSync } = require('child_process');
4
+
5
+ const binFile = process.platform === 'win32' ? 'typst.exe' : 'typst'
6
+ const binPath = path.join(__dirname, `bin/${binFile}`);
7
+
8
+ try {
9
+ execFileSync(binPath, process.argv.slice(2), {
10
+ stdio: 'inherit',
11
+ windowsHide: true,
12
+ })
13
+ }
14
+ catch (err) {
15
+ // Vale emits its own errors.
16
+ // But we still need to show that errors occurred.
17
+ process.exit(1)
18
+ }