bennyp
bennyp
DDeno
Created by bennyp on 4/30/2025 in #help
Decorators with esbuild-deno-loader
I want to compile class method decorators (ecmascript stage 3) with esbuild per the bundling docs, but I get "Unexpected token @logged" at runtime
❯ dist/bin/design-tokens-language-server
error: Uncaught SyntaxError: Invalid or unexpected token
@logged("hi")
^
at <anonymous> (file:///tmp/deno-compile-design-tokens-language-server/dist/main.js:42625:3)
❯ dist/bin/design-tokens-language-server
error: Uncaught SyntaxError: Invalid or unexpected token
@logged("hi")
^
at <anonymous> (file:///tmp/deno-compile-design-tokens-language-server/dist/main.js:42625:3)
build script:
import * as esbuild from "esbuild";
import { denoPlugins } from "@luca/esbuild-deno-loader";

import { expandGlob } from "jsr:@std/fs";

const decoder = new TextDecoder();

await esbuild.build({
plugins: [...denoPlugins()],
entryPoints: ["src/main.ts"],
outfile: "./dist/main.js",
bundle: true,
format: "esm",
});

await esbuild.stop();

const includes = await Array.fromAsync(
expandGlob("dist/*.wasm"),
(file) => `--include=${file.path}`,
);

async function compile() {
const args = [
"compile",
"--allow-all",
"--no-lock",
"--no-check",
"--no-remote",
"--no-config",
"--import-map=import-map-bundle.json",
...includes,
`--output=dist/bin/design-tokens-language-server`,
"dist/main.js",
"--stdio",
].filter((x) => typeof x === "string");
const { code, stdout, stderr } = await new Deno.Command(Deno.execPath(), {
stdout: "piped",
args,
}).output();
if (code === 0) {
console.log(`Built ${arch ?? "native"}`);
} else {
console.log(`deno ${args.join(" ")}\n`);
console.log(decoder.decode(stdout));
console.log(decoder.decode(stderr));
throw new Error(`Could not build ${arch ?? "native"}`);
}
}

await compile();
import * as esbuild from "esbuild";
import { denoPlugins } from "@luca/esbuild-deno-loader";

import { expandGlob } from "jsr:@std/fs";

const decoder = new TextDecoder();

await esbuild.build({
plugins: [...denoPlugins()],
entryPoints: ["src/main.ts"],
outfile: "./dist/main.js",
bundle: true,
format: "esm",
});

await esbuild.stop();

const includes = await Array.fromAsync(
expandGlob("dist/*.wasm"),
(file) => `--include=${file.path}`,
);

async function compile() {
const args = [
"compile",
"--allow-all",
"--no-lock",
"--no-check",
"--no-remote",
"--no-config",
"--import-map=import-map-bundle.json",
...includes,
`--output=dist/bin/design-tokens-language-server`,
"dist/main.js",
"--stdio",
].filter((x) => typeof x === "string");
const { code, stdout, stderr } = await new Deno.Command(Deno.execPath(), {
stdout: "piped",
args,
}).output();
if (code === 0) {
console.log(`Built ${arch ?? "native"}`);
} else {
console.log(`deno ${args.join(" ")}\n`);
console.log(decoder.decode(stdout));
console.log(decoder.decode(stderr));
throw new Error(`Could not build ${arch ?? "native"}`);
}
}

await compile();
1 replies
DDeno
Created by bennyp on 4/29/2025 in #help
Mocking the FileSystem
Hello! I'd like to mock the filesystem for some BDD tests - in other words, create some fake files before a test and tear them down afterwards. I need these mocks to specifically affect require.resolve calls. Do you have an example of this I could crib from?
1 replies
DDeno
Created by bennyp on 4/20/2025 in #help
Using scopes in deno.json to mock modules for tests
Hello, I have something like this in my deno.json
"imports": {
"#css": "./src/css/documents.ts",
"@std/assert": "jsr:@std/assert@1",
"@std/collections": "jsr:@std/collections@^1.0.10",
"@std/expect": "jsr:@std/expect@^1.0.15",
"@std/io": "jsr:@std/io@^0.225.2",
"@std/testing": "jsr:@std/testing@^1.0.11",
},
"scopes": {
"./src/lsp/methods/textDocument/completion.test.ts": {
"#css": "./test/css-mock.ts"
}
}
"imports": {
"#css": "./src/css/documents.ts",
"@std/assert": "jsr:@std/assert@1",
"@std/collections": "jsr:@std/collections@^1.0.10",
"@std/expect": "jsr:@std/expect@^1.0.15",
"@std/io": "jsr:@std/io@^0.225.2",
"@std/testing": "jsr:@std/testing@^1.0.11",
},
"scopes": {
"./src/lsp/methods/textDocument/completion.test.ts": {
"#css": "./test/css-mock.ts"
}
}
completion.test.ts imports completion.ts which imports #css. I expect that when I run deno test -A, my mock module would be loaded, not the real one instead the real one is loaded. Please advise how I can mock modules for testing.
2 replies
DDeno
Created by bennyp on 4/17/2025 in #help
deno compile --include whatev.wasm
I'd like to include a wasm file as data, but when I try to --include it I get
error: Relative import path "env" not prefixed with / or ./ or ../ and not in import map from "file:///var/home/bennyp/Developer/design-tokens-language-server/src/server/css/tree-sitter/tree-sitter-css.wasm"
error: Relative import path "env" not prefixed with / or ./ or ../ and not in import map from "file:///var/home/bennyp/Developer/design-tokens-language-server/src/server/css/tree-sitter/tree-sitter-css.wasm"
I'm aware that the docs say to add wasm imports to the import map, but that's not what I'm getting at: I just want to include a tree sitter grammar as data so that web-tree-sitter can load it up.
2 replies
DDeno
Created by bennyp on 4/16/2025 in #help
Writing the whole buffer to stdout
No description
3 replies
DDeno
Created by bennyp on 4/3/2025 in #help
Bundling node-tree-sitter
Hello there! I'm working on a language server written in Deno TS. I'd like to bundle it with node-tree-sitter, and I'm using esbuild as the docs recommend., but node-tree-sitter doesn't bundle nicely. https://github.com/bennypowers/design-tokens-language-server/issues/1#issuecomment-2776935304 If you have some ideas how I might work around this, I'd appreciate your input. Maybe with a dynamic import and --include?
3 replies