Skip to content

Commit dd6745e

Browse files
authored
Apply suggestion from @avivkeller
1 parent 919f5d5 commit dd6745e

1 file changed

Lines changed: 10 additions & 35 deletions

File tree

clone-webpack.mjs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,23 @@
1-
import fs from 'fs';
2-
import { execFileSync } from 'child_process';
1+
import { readFile, access } from 'node:fs/promises';
2+
import { execFileSync } from 'node:child_process';
33

4-
const webpackDir = './webpack';
5-
const headCommitFile = './HEAD_COMMIT';
4+
const WEBPACK_DIR = 'webpack';
5+
const REF = (await readFile('HEAD_COMMIT', 'utf-8')).trim();
66

7-
// Allow an env var override (used by CI)
8-
let ref = process.env.WEBPACK_REF;
9-
10-
if (!ref && fs.existsSync(headCommitFile)) {
11-
ref = fs.readFileSync(headCommitFile, 'utf-8').trim();
12-
}
13-
14-
if (!ref) {
15-
// Default fallback if running locally before any syncing has happened
16-
console.log(
17-
`Warning: WEBPACK_REF not set and ${headCommitFile} not found. Defaulting to 'main'.`
18-
);
19-
ref = 'main';
20-
}
21-
22-
console.log(`Cloning webpack repository at ref: ${ref}...`);
23-
24-
if (fs.existsSync(webpackDir)) {
25-
console.log(
26-
`Repository already exists at ${webpackDir}. Fetching latest updates...`
27-
);
7+
try {
8+
await access(WEBPACK_DIR);
289
execFileSync('git', ['fetch', '--all'], {
29-
cwd: webpackDir,
10+
cwd: WEBPACK_DIR,
3011
stdio: 'inherit',
3112
});
32-
} else {
33-
// Clone the repository
34-
console.log('Running git clone https://github.com/webpack/webpack.git...');
13+
} catch {
3514
execFileSync(
3615
'git',
37-
['clone', 'https://github.com/webpack/webpack.git', webpackDir],
16+
['clone', 'https://github.com/webpack/webpack.git', WEBPACK_DIR],
3817
{
3918
stdio: 'inherit',
4019
}
4120
);
4221
}
4322

44-
// Checkout the target commit
45-
console.log(`Checking out commit/branch: ${ref}...`);
46-
execFileSync('git', ['checkout', ref], { cwd: webpackDir, stdio: 'inherit' });
47-
48-
console.log('Successfully completed clone-webpack script.');
23+
execFileSync('git', ['checkout', REF], { cwd: WEBPACK_DIR, stdio: 'inherit' });

0 commit comments

Comments
 (0)