@@ -7,6 +7,8 @@ import { build } from "esbuild";
|
7 | 7 | |
8 | 8 | const modulePath = fileURLToPath(import.meta.url); |
9 | 9 | const repoRoot = path.resolve(path.dirname(modulePath), ".."); |
| 10 | +const pierreDiffsEmptySideEffectNamespace = "openclaw-diffs-empty-side-effect"; |
| 11 | +const pierreDiffsEmptySideEffectPath = "pierre-diffs-parse-decorations-side-effect"; |
10 | 12 | |
11 | 13 | const targets = { |
12 | 14 | curated: { |
@@ -20,6 +22,39 @@ const targets = {
|
20 | 22 | }, |
21 | 23 | }; |
22 | 24 | |
| 25 | +function toPosixPath(value) { |
| 26 | +return String(value ?? "").replaceAll("\\", "/"); |
| 27 | +} |
| 28 | + |
| 29 | +export function createPierreDiffsSideEffectImportPlugin() { |
| 30 | +return { |
| 31 | +name: "openclaw-diffs-pierre-side-effect-imports", |
| 32 | +setup(buildContext) { |
| 33 | +buildContext.onResolve({ filter: /^diff$/ }, (args) => { |
| 34 | +const importer = toPosixPath(args.importer); |
| 35 | +if (!importer.endsWith("/@pierre/diffs/dist/utils/parseDiffDecorations.js")) { |
| 36 | +return undefined; |
| 37 | +} |
| 38 | +return { |
| 39 | +path: pierreDiffsEmptySideEffectPath, |
| 40 | +namespace: pierreDiffsEmptySideEffectNamespace, |
| 41 | +sideEffects: true, |
| 42 | +}; |
| 43 | +}); |
| 44 | +buildContext.onLoad( |
| 45 | +{ |
| 46 | +filter: /^pierre-diffs-parse-decorations-side-effect$/, |
| 47 | +namespace: pierreDiffsEmptySideEffectNamespace, |
| 48 | +}, |
| 49 | +() => ({ |
| 50 | +contents: "export {};\n", |
| 51 | +loader: "js", |
| 52 | +}), |
| 53 | +); |
| 54 | +}, |
| 55 | +}; |
| 56 | +} |
| 57 | + |
23 | 58 | export async function buildDiffsViewerRuntime(targetName) { |
24 | 59 | const target = targets[targetName]; |
25 | 60 | if (!target) { |
@@ -44,18 +79,21 @@ export async function buildDiffsViewerRuntime(targetName) {
|
44 | 79 | legalComments: "none", |
45 | 80 | outfile: outputPath, |
46 | 81 | write: false, |
47 | | -plugins: target.shikiAlias |
48 | | - ? [ |
49 | | -{ |
50 | | -name: "openclaw-diffs-curated-shiki", |
51 | | -setup(buildContext) { |
52 | | -buildContext.onResolve({ filter: /^shiki$/ }, () => ({ |
53 | | -path: path.join(repoRoot, target.shikiAlias), |
54 | | -})); |
| 82 | +plugins: [ |
| 83 | +createPierreDiffsSideEffectImportPlugin(), |
| 84 | + ...(target.shikiAlias |
| 85 | + ? [ |
| 86 | +{ |
| 87 | +name: "openclaw-diffs-curated-shiki", |
| 88 | +setup(buildContext) { |
| 89 | +buildContext.onResolve({ filter: /^shiki$/ }, () => ({ |
| 90 | +path: path.join(repoRoot, target.shikiAlias), |
| 91 | +})); |
| 92 | +}, |
55 | 93 | }, |
56 | | -}, |
57 | | -] |
58 | | - : [], |
| 94 | +] |
| 95 | +: []), |
| 96 | +], |
59 | 97 | }); |
60 | 98 | |
61 | 99 | const outputFile = result.outputFiles?.[0]; |
|