Skip to content

Commit 2512b85

Browse files
authored
chore: reinstall esbuild (#2652)
1 parent 3e273cf commit 2512b85

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

.github/workflows/deploy-local-preview-dev.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: find .next -depth -mindepth 1 -not -path ".next/standalone*" -exec rm -rf {} \;
4141
- name: Remove esbuild dependency
4242
working-directory: packages/fern-docs/bundle
43-
run: rm -rf .next/standalone/node_modules/.pnpm/[email protected]
43+
run: rm -rf .next/standalone/node_modules/.pnpm/[email protected] && rm -rf .next/standalone/node_modules/.pnpm/@[email protected]
4444
- name: Synthesize local preview bundle
4545
run: pnpm --filter=@fern-platform/cdk run deploy-app:dev2
4646

packages/cdk/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.js
2+
!install-esbuild.js
23
*.d.ts
34
node_modules
45

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const fs = require('fs').promises;
2+
const path = require('path');
3+
const os = require('os');
4+
const { exec } = require('child_process');
5+
const util = require('util');
6+
const execAsync = util.promisify(exec);
7+
8+
const SKIP_DIRS = ['node_modules', '.git', 'dist', 'build'];
9+
10+
async function processFiles(dir, platform, arch) {
11+
const entries = await fs.readdir(dir, { withFileTypes: true });
12+
13+
for (const entry of entries) {
14+
const fullPath = path.join(dir, entry.name);
15+
16+
if (entry.isDirectory() && !SKIP_DIRS.includes(entry.name)) {
17+
await processFiles(fullPath, platform, arch);
18+
} else if (entry.isFile() && entry.name.endsWith('.json')) {
19+
let content = await fs.readFile(fullPath, 'utf8');
20+
21+
if (content.includes('linux-x64')) {
22+
const replacement = `${platform}-${arch}`;
23+
content = content.replace(/linux-x64/g, replacement);
24+
await fs.writeFile(fullPath, content, 'utf8');
25+
}
26+
}
27+
}
28+
}
29+
30+
const targetDir = path.join(__dirname, './standalone');
31+
32+
function checkOS() {
33+
const platform = os.platform();
34+
const arch = os.arch();
35+
return { platform, arch };
36+
}
37+
38+
async function copyModules(destPath) {
39+
const isWindows = os.platform() === 'win32';
40+
41+
try {
42+
if (isWindows) {
43+
await execAsync(`copy node_modules/.pnpm/[email protected] ${destPath}\\ && copy node_modules/.pnpm/@esbuild+* ${destPath}\\`);
44+
} else {
45+
await execAsync(`cp -r node_modules/.pnpm/[email protected] node_modules/.pnpm/@esbuild+* ${destPath}/`);
46+
}
47+
} catch (error) {
48+
console.error('Error copying modules:', error.message);
49+
throw error;
50+
}
51+
}
52+
53+
async function checkImport() {
54+
try {
55+
const pnpmDir = path.resolve('node_modules/.pnpm');
56+
const entries = await fs.readdir(pnpmDir);
57+
58+
const esbuildPackage = entries.find(entry => entry.startsWith('@esbuild+'));
59+
if (!esbuildPackage) return null;
60+
61+
const match = esbuildPackage.match(/@esbuild\+(.+)@0\.25\.0/);
62+
return match ? match[1] : null;
63+
} catch (error) {
64+
console.error('Error checking imports:', error.message);
65+
return null;
66+
}
67+
}
68+
69+
async function main() {
70+
try {
71+
const { platform, arch } = checkOS();
72+
console.log(`Replacing 'linux-x64' with '${platform}-${arch}' in .json files in ${targetDir}`);
73+
await processFiles(targetDir, platform, arch);
74+
75+
const importName = await checkImport();
76+
if (importName) {
77+
console.log(`Found esbuild import: ${importName}`);
78+
79+
const destPath = path.resolve('./standalone/node_modules/.pnpm');
80+
await copyModules(destPath);
81+
console.log(`Modules copied to ${destPath}`);
82+
}
83+
} catch (error) {
84+
console.error('Error in main process:', error.message);
85+
process.exit(1);
86+
}
87+
}
88+
89+
void main();

0 commit comments

Comments
 (0)