Skip to content
Open
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: 0 additions & 1 deletion apps/lsp/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ runBuild({
outfile: '../vscode/out/lsp/lsp.js',
assets: [
{ from: [nodeSqlLiteWasm], to: '../vscode/out/lsp/' },
{ from: ['./src/run.js'], to: '../vscode/out/lsp' },
{ from: ['../../packages/editor-server/src/resources/**'], to: '../vscode/out/lsp/resources/' },
{ from: ['../../packages/quarto-core/src/resources/**'], to: '../vscode/out/lsp/resources/' }
],
Expand Down
3 changes: 1 addition & 2 deletions apps/lsp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
"@types/node": "^22.15.0",
"@types/picomatch": "^2.3.0",
"build": "*",
"esbuild": "^0.16.7",
"eslint": "^7.32.0",
"eslint-config-custom-server": "*",
"tsconfig": "*",
"tsx": "^3.12.1",
"tsx": "^4.23.15",
"typescript": "^5.9.3"
}
}
3 changes: 1 addition & 2 deletions apps/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1578,11 +1578,10 @@
"@vscode/test-electron": "^2.5.2",
"@vscode/vsce": "^2.15.0",
"build": "*",
"esbuild": "^0.16.7",
"eslint": "^8.28.0",
"mocha": "^9.2.1",
"plist": "^3.0.6",
"tsx": "^3.12.1",
"tsx": "^4.23.15",
"typescript": "^5.9.3",
"vsce": "^2.15.0",
"vscode-languageserver": "^8.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/_annotated-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"@quarto/_tidyverse-errors": "*"
},
"devDependencies": {
"tsx": "^4.7.1"
"tsx": "^4.23.15"
}
}
2 changes: 1 addition & 1 deletion packages/_json-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@quarto/_annotated-json": "*"
},
"devDependencies": {
"tsx": "^4.7.1"
"tsx": "^4.23.15"
}
}
2 changes: 1 addition & 1 deletion packages/_mapped-string/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"@quarto/_tidyverse-errors": "*"
},
"devDependencies": {
"tsx": "^4.7.1"
"tsx": "^4.23.15"
}
}
2 changes: 1 addition & 1 deletion packages/_tidyverse-errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"ansi-colors": "^4.1.3"
},
"devDependencies": {
"tsx": "^4.7.1"
"tsx": "^4.23.15"
}
}
2 changes: 1 addition & 1 deletion packages/annotated-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"devDependencies": {
"tsconfig": "*",
"tsx": "^4.7.1",
"tsx": "^4.23.15",
"typescript": "^5.9.3"
},
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"main": "./src/index.ts",
"types": "./src/index.ts",
"devDependencies": {
"esbuild": "^0.16.7",
"esbuild-plugin-copy": "^2.0.1",
"tsconfig": "*"
},
"dependencies": {}
"dependencies": {
"esbuild": "^0.28.2"
}
}
80 changes: 62 additions & 18 deletions packages/build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
* Copyright (C) 2022-2026 by Posit Software, PBC
*/

import { build, Format, Platform, PluginBuild } from 'esbuild';
import { AssetPair, copy } from 'esbuild-plugin-copy';
import { rm } from 'node:fs/promises';
import { build, BuildOptions as EsbuildOptions, context, Format, Platform, PluginBuild } from 'esbuild';
import { copyFile, glob, mkdir, rm, stat } from 'node:fs/promises';
import { dirname, join, relative } from 'node:path';

// Copy files matching the `from` globs (relative to cwd) into the `to` directory,
// keeping each file's path relative to the non-glob prefix of its pattern
export interface AssetPair {
from: string[];
to: string;
}

export interface BuildOptions {
entryPoints: string[];
Expand All @@ -17,6 +24,7 @@ export interface BuildOptions {
minify?: boolean; // false
format?: Format; // cjs
platform?: Platform; // node
target?: string; // node22
external?: string[]; // []
dev?: boolean; // false
sourcemap?: boolean | 'linked' | 'inline' | 'external' | 'both'; // false
Expand All @@ -33,31 +41,26 @@ export async function runBuild(options: BuildOptions) {
minify = false,
format = 'cjs',
platform = 'node',
// The Node bundled with the oldest VS Code we support (engines.vscode ^1.101)
target = 'node22',
external,
dev = false,
sourcemap = dev,
legalComments = 'eof'
} = options;

await build({
const esbuildOptions: EsbuildOptions = {
entryPoints,
outfile,
outdir,
bundle,
minify,
format,
platform,
target,
external,
sourcemap,
legalComments,
watch: dev ? {
onRebuild(error) {
if (error)
console.error('[watch] build failed:', error);
else
console.log('[watch] build finished');
},
} : false,
plugins: [
...(outdir ? [{
name: 'clear-outdir',
Expand All @@ -69,14 +72,55 @@ export async function runBuild(options: BuildOptions) {
});
},
}] : []),
...(assets ? [copy({
resolveFrom: 'cwd',
assets,
})] : []),
...(assets ? [{
name: 'copy-assets',
setup(build: PluginBuild) {
build.onEnd(async () => {
await copyAssets(assets);
});
},
}] : []),
...(dev ? [{
name: 'watch-logger',
setup(build: PluginBuild) {
build.onEnd(result => {
if (result.errors.length > 0)
console.error('[watch] build failed');
else
console.log('[watch] build finished');
});
},
}] : []),
],
});
};

if (dev) {
console.log("[watch] build finished, watching for changes...");
const ctx = await context(esbuildOptions);
await ctx.watch();
console.log("[watch] watching for changes...");
} else {
await build(esbuildOptions);
}
}

async function copyAssets(assets: AssetPair[]) {
for (const { from, to } of assets) {
for (const pattern of from) {
const base = globBase(pattern);
for await (const file of glob(pattern)) {
if (!(await stat(file)).isFile()) {
continue;
}
const dest = join(to, relative(base, file));
await mkdir(dirname(dest), { recursive: true });
await copyFile(file, dest);
}
}
}
}

function globBase(pattern: string) {
const segments = pattern.split('/');
const firstGlob = segments.findIndex(segment => /[*?[\]{}]/.test(segment));
return firstGlob === -1 ? dirname(pattern) : segments.slice(0, firstGlob).join('/');
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@types/markdown-it": "^12.2.3",
"@types/markdown-it-attrs": "^4.1.0",
"@types/wcwidth": "^1.0.0",
"tsx": "^4.7.1"
"tsx": "^4.23.15"
},
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
Expand Down
2 changes: 1 addition & 1 deletion packages/json-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"build": "*",
"tsconfig": "*",
"tsx": "^4.7.1",
"tsx": "^4.23.15",
"typescript": "^5.9.3"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/mapped-string/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"devDependencies": {
"tsconfig": "*",
"tsx": "^4.7.1",
"tsx": "^4.23.15",
"typescript": "^5.9.3"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/tidyverse-errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"tsconfig": "*",
"tsx": "^4.7.1",
"tsx": "^4.23.15",
"typescript": "^5.9.3"
},
"scripts": {
Expand Down
Loading
Loading