Skip to content

Commit 35644f2

Browse files
Merge pull request #32 from DeDuckProject/fix/replace-esbuild-with-sucrase
fix: replace esbuild runtime usage with sucrase (pure JS, fully bundl…
2 parents 0f88b1e + e54dceb commit 35644f2

File tree

9 files changed

+47424
-184
lines changed

9 files changed

+47424
-184
lines changed

packages/action/dist/check.js

Lines changed: 23692 additions & 128 deletions
Large diffs are not rendered by default.

packages/action/dist/check.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/action/dist/index.js

Lines changed: 23579 additions & 19 deletions
Large diffs are not rendered by default.

packages/action/dist/index.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/action/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"main": "./dist/index.js",
77
"scripts": {
8-
"build": "pnpm --filter @git-glimpse/core build && esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.js --external:@playwright/test --external:playwright-core --external:playwright --external:esbuild --sourcemap && esbuild src/check.ts --bundle --platform=node --format=cjs --outfile=dist/check.js --external:@playwright/test --external:playwright-core --external:playwright --external:esbuild --sourcemap",
8+
"build": "pnpm --filter @git-glimpse/core build && esbuild src/index.ts --bundle --platform=node --format=cjs --outfile=dist/index.js --external:@playwright/test --external:playwright-core --external:playwright --sourcemap && esbuild src/check.ts --bundle --platform=node --format=cjs --outfile=dist/check.js --external:@playwright/test --external:playwright-core --external:playwright --sourcemap",
99
"typecheck": "tsc --noEmit"
1010
},
1111
"dependencies": {

packages/core/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
"types": "./dist/index.d.ts"
1313
}
1414
},
15-
"files": ["dist"],
15+
"files": [
16+
"dist"
17+
],
1618
"scripts": {
1719
"build": "tsc -p tsconfig.json",
1820
"typecheck": "tsc --noEmit"
1921
},
2022
"dependencies": {
2123
"@anthropic-ai/sdk": "^0.24.3",
22-
"@playwright/test": "^1.44.0",
2324
"@octokit/rest": "^20.1.1",
24-
"esbuild": "^0.21.5",
25+
"@playwright/test": "^1.44.0",
2526
"minimatch": "^10.0.1",
27+
"sucrase": "^3.35.1",
2628
"zod": "^3.23.4"
2729
},
2830
"devDependencies": {
2931
"@actions/artifact": "^2.1.11",
32+
"@types/node": "^20.12.0",
3033
"typescript": "^5.4.5",
31-
"vitest": "^1.6.0",
32-
"@types/node": "^20.12.0"
34+
"vitest": "^1.6.0"
3335
}
3436
}

packages/core/src/config/loader.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { pathToFileURL } from 'node:url';
2-
import { existsSync, writeFileSync, unlinkSync } from 'node:fs';
3-
import { resolve, extname } from 'node:path';
2+
import { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs';
3+
import { resolve, dirname, extname } from 'node:path';
44
import { tmpdir } from 'node:os';
55
import { GitGlimpseConfigSchema, type GitGlimpseConfig } from './schema.js';
66
import { DEFAULT_RECORDING, DEFAULT_LLM, DEFAULT_TRIGGER } from './defaults.js';
@@ -11,19 +11,15 @@ async function importConfigFile(filePath: string): Promise<unknown> {
1111
return mod.default ?? mod;
1212
}
1313

14-
// Transpile .ts config via esbuild before importing
15-
const { build } = await import('esbuild');
16-
const result = await build({
17-
entryPoints: [filePath],
18-
bundle: true,
19-
platform: 'node',
20-
format: 'esm',
21-
write: false,
22-
});
14+
// Transpile .ts config via sucrase (pure JS, fully bundleable, no native deps)
15+
const { transform } = await import('sucrase');
16+
const source = readFileSync(filePath, 'utf-8');
17+
const { code } = transform(source, { transforms: ['typescript'] });
2318

24-
const tmpFile = resolve(tmpdir(), `git-glimpse-config-${Date.now()}.mjs`);
19+
// Write next to the original so relative imports in the config resolve correctly
20+
const tmpFile = resolve(dirname(filePath), `.git-glimpse-config-${Date.now()}.mjs`);
2521
try {
26-
writeFileSync(tmpFile, result.outputFiles[0].text);
22+
writeFileSync(tmpFile, code);
2723
const mod = await import(pathToFileURL(tmpFile).href);
2824
return mod.default ?? mod;
2925
} finally {

packages/core/src/recorder/playwright-runner.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,10 @@ async function executeScript(script: string, page: Page, _baseUrl: string): Prom
136136
const { writeFileSync, unlinkSync } = await import('node:fs');
137137
const { tmpdir } = await import('node:os');
138138
const { pathToFileURL } = await import('node:url');
139-
const { transformSync } = await import('esbuild');
139+
const { transform } = await import('sucrase');
140140

141-
// Transpile TypeScript → ESM JavaScript via esbuild
142-
const { code } = transformSync(script, {
143-
loader: 'ts',
144-
format: 'esm',
145-
target: 'node20',
146-
});
141+
// Transpile TypeScript → ESM JavaScript via sucrase (pure JS, no native deps)
142+
const { code } = transform(script, { transforms: ['typescript'] });
147143

148144
const tmpPath = join(tmpdir(), `git-glimpse-script-${Date.now()}.mjs`);
149145
writeFileSync(tmpPath, code, 'utf-8');

pnpm-lock.yaml

Lines changed: 125 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)