Skip to content

Commit

Permalink
publish 0.10.0-6 using optionalDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jcbhmr committed Dec 18, 2023
1 parent e693baf commit ff3f343
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 48 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typst",
"version": "0.10.0-5",
"version": "0.10.0-6",
"description": "A new markup-based typesetting system that is powerful and easy to learn.",
"keywords": [
"typesetting",
Expand Down Expand Up @@ -28,11 +28,13 @@
"scripts": {
"pretest": "tsc",
"test": "node --test",
"prepare": "bash tools/prepare.sh",
"build": "tsc",
"format": "prettier -w .",
"lint": "tsc --noEmit",
"postversion": "node tools/postversion.js",
"generate-dist-packages": "node tools/generate-dist-packages.js"
"generate-dist-packages": "node tools/generate-dist-packages.js",
"prepublishOnly": "bash tools/prepublishOnly.sh"
},
"dependencies": {
"execa": "^8.0.1"
Expand All @@ -44,10 +46,10 @@
"vitest": "^1.0.4"
},
"optionalDependencies": {
"@typst-community/typst-win32-x64": "0.10.0-5",
"@typst-community/typst-darwin-x64": "0.10.0-5",
"@typst-community/typst-darwin-arm64": "0.10.0-5",
"@typst-community/typst-linux-arm64": "0.10.0-5",
"@typst-community/typst-linux-x64": "0.10.0-5"
"@typst-community/typst-win32-x64": "0.10.0-6",
"@typst-community/typst-darwin-x64": "0.10.0-6",
"@typst-community/typst-darwin-arm64": "0.10.0-6",
"@typst-community/typst-linux-arm64": "0.10.0-6",
"@typst-community/typst-linux-x64": "0.10.0-6"
}
}
2 changes: 1 addition & 1 deletion packages/typst-community+typst-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typst-community/typst-darwin-arm64",
"version": "0.10.0-5",
"version": "0.10.0-6",
"exports": "./.typst/bin/typst",
"os": [
"darwin"
Expand Down
2 changes: 1 addition & 1 deletion packages/typst-community+typst-darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typst-community/typst-darwin-x64",
"version": "0.10.0-5",
"version": "0.10.0-6",
"exports": "./.typst/bin/typst",
"os": [
"darwin"
Expand Down
2 changes: 1 addition & 1 deletion packages/typst-community+typst-linux-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typst-community/typst-linux-arm64",
"version": "0.10.0-5",
"version": "0.10.0-6",
"exports": "./.typst/bin/typst",
"os": [
"linux"
Expand Down
2 changes: 1 addition & 1 deletion packages/typst-community+typst-linux-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typst-community/typst-linux-x64",
"version": "0.10.0-5",
"version": "0.10.0-6",
"exports": "./.typst/bin/typst",
"os": [
"linux"
Expand Down
2 changes: 1 addition & 1 deletion packages/typst-community+typst-win32-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typst-community/typst-win32-x64",
"version": "0.10.0-5",
"version": "0.10.0-6",
"exports": "./.typst/bin/typst",
"os": [
"win32"
Expand Down
9 changes: 9 additions & 0 deletions src/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { $ } from "execa";
import getTypstPath from "./lib/getTypstPath.js";

export default async function help(options: { signal?: AbortSignal } = {}) {
const { stdout } = await $({
signal: options.signal,
})`${getTypstPath()} --help`;
return stdout;
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export { default as compile, type TypstCompileOptions } from "./compile.js";
export { default as fonts, type TypstFontsOptions } from "./fonts.js";
export { default as query, type TypstQueryOptions } from "./query.js";
export { default as watch, type TypstWatchOptions } from "./watch.js";
export { default as help } from "./help.js";
export { default as version } from "./version.js";
30 changes: 20 additions & 10 deletions src/lib/getTypstPath.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { createRequire } from "node:module";
import { fileURLToPath, pathToFileURL } from "node:url";
const require = createRequire(new URL(import.meta.url));
import.meta.resolve ??= (s) => require.resolve(s);
import.meta.resolve ??= (s) => pathToFileURL(require.resolve(s)).href;

const getTypstPath = {
"win32,x64": () => import.meta.resolve("@typst-community/typst-win32-x64"),
"darwin-x64": () => import.meta.resolve("@typst-community/typst-darwin-x64"),
"darwin-arm64": () =>
import.meta.resolve("@typst-community/typst-darwin-arm64"),
"linux-arm64": () =>
import.meta.resolve("@typst-community/typst-linux-arm64"),
"linux-x64": () => import.meta.resolve("@typst-community/typst-linux-x64"),
}[[process.platform, process.arch].toString()]!;
const getTypstPath =
{
"win32,x64": () =>
fileURLToPath(import.meta.resolve("@typst-community/typst-win32-x64")),
"darwin,x64": () =>
fileURLToPath(import.meta.resolve("@typst-community/typst-darwin-x64")),
"darwin,arm64": () =>
fileURLToPath(import.meta.resolve("@typst-community/typst-darwin-arm64")),
"linux,arm64": () =>
fileURLToPath(import.meta.resolve("@typst-community/typst-linux-arm64")),
"linux,x64": () =>
fileURLToPath(import.meta.resolve("@typst-community/typst-linux-x64")),
}[[process.platform, process.arch].toString()] ??
(() => {
throw new ReferenceError(
`@typst-community/typst-[os]-[arch] not found for ${process.platform}-${process.arch}`,
);
});
export default getTypstPath;
5 changes: 2 additions & 3 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export interface TypstQueryOptions {

export default async function query(
inputRaw: PathLike,
selectorRaw: PathLike,
selector: string,
options: TypstQueryOptions = {},
) {
const inputPath = pathOrFileURLToPath(inputRaw);
const selectorPath = pathOrFileURLToPath(selectorRaw);
const opts = [];
if (options.root != null)
opts.push("--root", pathOrFileURLToPath(options.root));
Expand All @@ -35,7 +34,7 @@ export default async function query(
opts.push("--cert", pathOrFileURLToPath(options.cert));
const { stdout } = await $({
signal: options.signal,
})`${getTypstPath()} query ${opts} ${inputPath} ${selectorPath}`;
})`${getTypstPath()} query ${opts} ${inputPath} ${selector}`;
const json = JSON.parse(stdout);
return json;
}
10 changes: 10 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { $ } from "execa";
import getTypstPath from "./lib/getTypstPath.js";

export default async function version(options: { signal?: AbortSignal } = {}) {
const { stdout } = await $({
signal: options.signal,
})`${getTypstPath()} --version`;
const version = stdout.match(/\d+\.\d+\.\d+/)[0];
return version;
}
4 changes: 2 additions & 2 deletions test/fonts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from "node:test";
import assert from "node:assert/strict";
import * as typst from "../dist/index.js";

test("compile example.typ", async () => {
test("fonts", async () => {
const r = await typst.fonts();
console.log(r);
console.log(`${r.length} fonts`);
});
8 changes: 8 additions & 0 deletions test/help.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import test from "node:test";
import assert from "node:assert/strict";
import * as typst from "../dist/index.js";

test("help", async () => {
const r = await typst.help();
console.log(`${r.length} chars`);
});
4 changes: 2 additions & 2 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import assert from "node:assert/strict";
import { $ } from "execa";
import { fileURLToPath } from "node:url";

test("main.js --help", async () => {
test("main.js --version", async () => {
const mainPath = fileURLToPath(new URL("../dist/main.js", import.meta.url));
await $({ stdio: "inherit" })`${process.execPath} ${mainPath} --help`;
await $({ stdio: "inherit" })`${process.execPath} ${mainPath} --version`;
});
7 changes: 5 additions & 2 deletions test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import test from "node:test";
import assert from "node:assert/strict";
import * as typst from "../dist/index.js";

test("compile example.typ", async () => {
const r = await typst.query(new URL("./example.typ"), "<note>");
test("query example.typ <note>", async () => {
const r = await typst.query(
new URL("./example.typ", import.meta.url),
"<note>",
);
console.log(r);
});
8 changes: 8 additions & 0 deletions test/version.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import test from "node:test";
import assert from "node:assert/strict";
import * as typst from "../dist/index.js";

test("version", async () => {
const r = await typst.version();
console.log(`got typst v${r}`);
});
10 changes: 5 additions & 5 deletions tools/postversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ let text = await readFile(packageFile, "utf8");
let package_ = JSON.parse(text);

const tuples = [
"@typst-community/typst-win32-x64",
"@typst-community/typst-darwin-x64",
"@typst-community/typst-darwin-arm64",
"@typst-community/typst-linux-arm64",
"@typst-community/typst-linux-x64",
"win32-x64",
"darwin-x64",
"darwin-arm64",
"linux-arm64",
"linux-x64",
];

for (const tuple of tuples) {
Expand Down
4 changes: 4 additions & 0 deletions tools/prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -ex
tuple=$(node -p '`${process.platform}-${process.arch}`')
npm link "./packages/typst-community+typst-$tuple"
7 changes: 7 additions & 0 deletions tools/prepublishOnly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -ex
for tuple in win32-x64 darwin-x64 darwin-arm64 linux-arm64 linux-x64; do
pushd "./packages/typst-community+typst-$tuple"
npm publish
popd
done

0 comments on commit ff3f343

Please sign in to comment.