Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dist/bundleAssets.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare function bundleAssets(): Promise<void>;
8 changes: 4 additions & 4 deletions dist/snippetFormatter.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/snippetFormatter.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dist/talonFormatter.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/talonFormatter.js.map

Large diffs are not rendered by default.

Binary file added dist/tree-sitter-query.wasm
Binary file not shown.
Binary file added dist/tree-sitter-talon.wasm
Binary file not shown.
18 changes: 9 additions & 9 deletions dist/treeSitterFormatter.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/treeSitterFormatter.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion oxlint.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const disabledRules = [
"unicorn/no-null",
"unicorn/prefer-at",
"unicorn/prefer-spread",
"unicorn/prefer-ternary",
"unicorn/switch-case-braces",
];

Expand Down Expand Up @@ -142,10 +143,16 @@ export default defineConfig({

overrides: [
{
files: ["src/node/**/*.ts", "src/test/**/*.ts", "src/build.ts"],
files: [
"src/node/**/*.ts",
"src/test/**/*.ts",
"src/build.ts",
"src/bundleAssets.ts",
],
rules: {
"import/no-nodejs-modules": "off",
"no-restricted-imports": "off",
"node/no-top-level-await": "off",
},
},
],
Expand Down
81 changes: 75 additions & 6 deletions package-lock.json

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

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@cursorless/talon-tools",
"version": "0.15.0",
"version": "0.16.0",
"description": "Linting and formatting tools for Talon and Cursorless",
"author": "Cursorless Dev",
"license": "MIT",
"type": "module",
"files": [
"dist",
"!dist/test",
"!dist/build.*"
"!dist/build.*",
"!dist/bundleAssets.*"
],
"types": "./dist/lib.d.ts",
"exports": {
Expand Down Expand Up @@ -48,16 +49,18 @@
"test:subset": "tsx src/test/runAllTests.ts --subset"
},
"dependencies": {
"@cursorless/tree-sitter-wasms": "^0.13.0",
"editorconfig": "^4.0.1",
"fast-glob": "^3.3.3",
"get-stdin": "^10.0.0",
"web-tree-sitter": "^0.27.2"
},
"devDependencies": {
"@cursorless/tree-sitter-wasms": "^0.14.0",
"@types/fs-extra": "^11.0.4",
"@types/mocha": "^10.0.10",
"@types/node": "^26.6.6",
"esbuild": "^0.28.2",
"fs-extra": "^11.4.1",
"mocha": "^12.0.3",
"oxfmt": "^0.78.0",
"oxlint-tsgolint": "^7.0.2007",
Expand Down
3 changes: 2 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { exit } from "node:process";
import esbuild from "esbuild";
import type { BuildOptions } from "esbuild";
import { bundleAssets } from "./bundleAssets.js";

async function build(): Promise<void> {
console.log("Running esbuild...");
Expand Down Expand Up @@ -35,8 +36,8 @@ async function build(): Promise<void> {
}

try {
// oxlint-disable-next-line node/no-top-level-await
await build();
await bundleAssets();
} catch (error) {
console.error(error);
exit(1);
Expand Down
45 changes: 45 additions & 0 deletions src/bundleAssets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { lstat, mkdir } from "node:fs/promises";
import path from "node:path";
import { copy } from "fs-extra";

const projectRoot = path.join(import.meta.dirname, "..");
const sourceRoot = path.join(
projectRoot,
"node_modules/@cursorless/tree-sitter-wasms/out",
);
const destinationRoot = path.join(projectRoot, "dist");

async function copyAsset(source: string, destination?: string): Promise<void> {
const fullSource = path.join(sourceRoot, source);
const fullDestination = path.join(destinationRoot, destination ?? source);

console.log(` ${source}`);

// oxlint-disable-next-line typescript/explicit-function-return-type
const stat = await (async () => {
try {
return await lstat(fullSource);
} catch (error) {
const message =
error instanceof Error ? error.message : String(error);
throw new Error(`Missing asset ${fullSource}: ${message}`, {
cause: error,
});
}
})();

if (stat.isDirectory()) {
await mkdir(fullDestination, { recursive: true });
} else {
await mkdir(path.dirname(fullDestination), { recursive: true });
}

await copy(fullSource, fullDestination);
}

export async function bundleAssets(): Promise<void> {
console.log("Bundling assets:");

await copyAsset("tree-sitter-talon.wasm");
await copyAsset("tree-sitter-query.wasm");
}
17 changes: 4 additions & 13 deletions src/node/parseText.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { Language, Parser } from "web-tree-sitter";
import type { SyntaxNode } from "../types.js";

type ParserName = "tree-sitter-talon" | "tree-sitter-query";

let initPromise: Promise<void> | undefined;
const languageCache = new Map<ParserName, Promise<Language>>();
// oxlint-disable-next-line unicorn/prefer-import-meta-properties
const moduleDir = path.dirname(fileURLToPath(import.meta.url));

function initTreeSitter() {
initPromise ??= Parser.init();
Expand All @@ -31,16 +28,10 @@ function loadLanguage(parserName: ParserName) {
function getWasmFilePath(parserName: ParserName) {
const fileName = `${parserName}.wasm`;
const wasmFilePath = [
path.join(
moduleDir,
"../../node_modules/@cursorless/tree-sitter-wasms/out",
fileName,
),
path.join(
moduleDir,
"../node_modules/@cursorless/tree-sitter-wasms/out",
fileName,
),
// Used by production build
path.join(import.meta.dirname, fileName),
// Used by development/test build
path.join(import.meta.dirname, "../../dist", fileName),
].find((candidate) => fs.existsSync(candidate));

if (wasmFilePath == null) {
Expand Down
Loading