Skip to content

Commit ed24f65

Browse files
authored
Fix Posthog by correctly copying .env in the build process (#4049)
1 parent f37e6f6 commit ed24f65

File tree

7 files changed

+57
-31
lines changed

7 files changed

+57
-31
lines changed

.changeset/thirty-cases-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"roo-cline": patch
3+
---
4+
5+
Fix Posthog by correctly copying .env in the build process

.github/workflows/marketplace-publish.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,22 @@ jobs:
4545
run: |
4646
current_package_version=$(node -p "require('./src/package.json').version")
4747
pnpm build
48-
package=$(unzip -l bin/roo-cline-${current_package_version}.vsix)
49-
echo "$package" | grep -q "extension/package.json" || exit 1
50-
echo "$package" | grep -q "extension/package.nls.json" || exit 1
51-
echo "$package" | grep -q "extension/dist/extension.js" || exit 1
52-
echo "$package" | grep -q "extension/webview-ui/audio/celebration.wav" || exit 1
53-
echo "$package" | grep -q "extension/webview-ui/build/assets/index.js" || exit 1
54-
echo "$package" | grep -q "extension/assets/codicons/codicon.ttf" || exit 1
55-
echo "$package" | grep -q "extension/assets/vscode-material-icons/icons/3d.svg" || exit 1
56-
echo "$package" | grep -q ".env" || exit 1
48+
49+
# Save VSIX contents to a temporary file to avoid broken pipe issues.
50+
unzip -l bin/roo-cline-${current_package_version}.vsix > /tmp/roo-code-vsix-contents.txt
51+
52+
# Check for required files.
53+
grep -q "extension/package.json" /tmp/roo-code-vsix-contents.txt || exit 1
54+
grep -q "extension/package.nls.json" /tmp/roo-code-vsix-contents.txt || exit 1
55+
grep -q "extension/dist/extension.js" /tmp/roo-code-vsix-contents.txt || exit 1
56+
grep -q "extension/webview-ui/audio/celebration.wav" /tmp/roo-code-vsix-contents.txt || exit 1
57+
grep -q "extension/webview-ui/build/assets/index.js" /tmp/roo-code-vsix-contents.txt || exit 1
58+
grep -q "extension/assets/codicons/codicon.ttf" /tmp/roo-code-vsix-contents.txt || exit 1
59+
grep -q "extension/assets/vscode-material-icons/icons/3d.svg" /tmp/roo-code-vsix-contents.txt || exit 1
60+
grep -q ".env" /tmp/roo-code-vsix-contents.txt || exit 1
61+
62+
# Clean up temporary file.
63+
rm /tmp/roo-code-vsix-contents.txt
5764
- name: Create and Push Git Tag
5865
run: |
5966
current_package_version=$(node -p "require('./src/package.json').version")

.prettierignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

.prettierrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"useTabs": true,
44
"printWidth": 120,
55
"semi": false,
6-
"bracketSameLine": true
6+
"bracketSameLine": true,
7+
"ignore": ["node_modules", "dist", "build", "out", ".next", ".venv", "pnpm-lock.yaml"]
78
}

apps/vscode-nightly/esbuild.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ async function main() {
6767
["../README.md", "README.md"],
6868
["../CHANGELOG.md", "CHANGELOG.md"],
6969
["../LICENSE", "LICENSE"],
70+
["../.env", ".env", { optional: true }],
7071
[".vscodeignore", ".vscodeignore"],
7172
["assets", "assets"],
7273
["integrations", "integrations"],

packages/build/src/esbuild.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ function rmDir(dirPath: string, maxRetries: number = 3): void {
2929
return
3030
} catch (error) {
3131
const isLastAttempt = attempt === maxRetries
32-
const isEnotemptyError = error instanceof Error && "code" in error && (error.code === 'ENOTEMPTY' || error.code === 'EBUSY')
32+
33+
const isEnotemptyError =
34+
error instanceof Error && "code" in error && (error.code === "ENOTEMPTY" || error.code === "EBUSY")
3335

3436
if (isLastAttempt || !isEnotemptyError) {
3537
throw error // Re-throw if it's the last attempt or not a locking error.
@@ -41,27 +43,42 @@ function rmDir(dirPath: string, maxRetries: number = 3): void {
4143

4244
// Synchronous sleep for simplicity in build scripts.
4345
const start = Date.now()
44-
while (Date.now() - start < delay) { /* Busy wait */ }
46+
47+
while (Date.now() - start < delay) {
48+
/* Busy wait */
49+
}
4550
}
4651
}
4752
}
4853

49-
export function copyPaths(copyPaths: [string, string][], srcDir: string, dstDir: string) {
50-
copyPaths.forEach(([srcRelPath, dstRelPath]) => {
51-
const stats = fs.lstatSync(path.join(srcDir, srcRelPath))
54+
type CopyPathOptions = {
55+
optional?: boolean
56+
}
5257

53-
if (stats.isDirectory()) {
54-
if (fs.existsSync(path.join(dstDir, dstRelPath))) {
55-
rmDir(path.join(dstDir, dstRelPath))
56-
}
58+
export function copyPaths(copyPaths: [string, string, CopyPathOptions?][], srcDir: string, dstDir: string) {
59+
copyPaths.forEach(([srcRelPath, dstRelPath, options = {}]) => {
60+
try {
61+
const stats = fs.lstatSync(path.join(srcDir, srcRelPath))
5762

58-
fs.mkdirSync(path.join(dstDir, dstRelPath), { recursive: true })
63+
if (stats.isDirectory()) {
64+
if (fs.existsSync(path.join(dstDir, dstRelPath))) {
65+
rmDir(path.join(dstDir, dstRelPath))
66+
}
5967

60-
const count = copyDir(path.join(srcDir, srcRelPath), path.join(dstDir, dstRelPath), 0)
61-
console.log(`[copyPaths] Copied ${count} files from ${srcRelPath} to ${dstRelPath}`)
62-
} else {
63-
fs.copyFileSync(path.join(srcDir, srcRelPath), path.join(dstDir, dstRelPath))
64-
console.log(`[copyPaths] Copied ${srcRelPath} to ${dstRelPath}`)
68+
fs.mkdirSync(path.join(dstDir, dstRelPath), { recursive: true })
69+
70+
const count = copyDir(path.join(srcDir, srcRelPath), path.join(dstDir, dstRelPath), 0)
71+
console.log(`[copyPaths] Copied ${count} files from ${srcRelPath} to ${dstRelPath}`)
72+
} else {
73+
fs.copyFileSync(path.join(srcDir, srcRelPath), path.join(dstDir, dstRelPath))
74+
console.log(`[copyPaths] Copied ${srcRelPath} to ${dstRelPath}`)
75+
}
76+
} catch (error) {
77+
if (options.optional) {
78+
console.warn(`[copyPaths] Optional file not found: ${srcRelPath}`)
79+
} else {
80+
throw error
81+
}
6582
}
6683
})
6784
}

src/esbuild.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ async function main() {
5252
["../README.md", "README.md"],
5353
["../CHANGELOG.md", "CHANGELOG.md"],
5454
["../LICENSE", "LICENSE"],
55+
["../.env", ".env", { optional: true }],
5556
["node_modules/vscode-material-icons/generated", "assets/vscode-material-icons"],
5657
["../webview-ui/audio", "webview-ui/audio"],
5758
],

0 commit comments

Comments
 (0)