From a6d00faf6f95c568a8d58097852fabd0e3f2b69a Mon Sep 17 00:00:00 2001 From: Rahul Kumar Rai Date: Mon, 30 Mar 2026 19:09:03 +0530 Subject: [PATCH 1/5] feat(dx): add clone-webpack script and unify CI checkout logic --- .github/workflows/ci.yml | 14 +++--------- .github/workflows/sync.yml | 14 +++++------- clone-webpack.mjs | 45 ++++++++++++++++++++++++++++++++++++++ package.json | 1 + 4 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 clone-webpack.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ed7075..57aff09 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,17 +34,6 @@ jobs: - name: Checkout code uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - - name: Read HEAD_COMMIT - id: webpack-ref - run: echo "ref=$(cat HEAD_COMMIT)" >> "$GITHUB_OUTPUT" - - - name: Checkout webpack - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - with: - repository: webpack/webpack - ref: ${{ steps.webpack-ref.outputs.ref }} - path: webpack - - name: Setup Node.js uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 with: @@ -54,6 +43,9 @@ jobs: - name: Install dependencies run: npm ci + - name: Clone webpack + run: npm run clone-webpack + - name: Regenerate docs run: npm run generate-docs diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 29eaef8..9ef766b 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -38,14 +38,6 @@ jobs: echo "New webpack commit detected, syncing." fi - - name: Checkout webpack - if: steps.check.outputs.changed == 'true' - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - with: - repository: webpack/webpack - ref: ${{ steps.latest.outputs.latest }} - path: webpack - - name: Setup Node.js if: steps.check.outputs.changed == 'true' uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 @@ -57,6 +49,12 @@ jobs: if: steps.check.outputs.changed == 'true' run: npm ci + - name: Clone webpack + if: steps.check.outputs.changed == 'true' + env: + WEBPACK_REF: ${{ steps.latest.outputs.latest }} + run: npm run clone-webpack + - name: Update HEAD_COMMIT if: steps.check.outputs.changed == 'true' run: echo "${{ steps.latest.outputs.latest }}" > HEAD_COMMIT diff --git a/clone-webpack.mjs b/clone-webpack.mjs new file mode 100644 index 0000000..7d08fb9 --- /dev/null +++ b/clone-webpack.mjs @@ -0,0 +1,45 @@ +import fs from 'fs'; +import { execSync } from 'child_process'; + +const webpackDir = './webpack'; +const headCommitFile = './HEAD_COMMIT'; + +// Allow an env var override (used by CI) +let ref = process.env.WEBPACK_REF; + +if (!ref && fs.existsSync(headCommitFile)) { + ref = fs.readFileSync(headCommitFile, 'utf-8').trim(); +} + +if (!ref) { + // Default fallback if running locally before any syncing has happened + console.log( + `Warning: WEBPACK_REF not set and ${headCommitFile} not found. Defaulting to 'main'.` + ); + ref = 'main'; +} + +console.log(`Cloning webpack repository at ref: ${ref}...`); + +// Clean up existing directory if it exists +if (fs.existsSync(webpackDir)) { + console.log(`Removing existing ${webpackDir} directory...`); + fs.rmSync(webpackDir, { recursive: true, force: true }); +} + +try { + // Clone the repository + console.log('Running git clone https://github.com/webpack/webpack.git...'); + execSync(`git clone https://github.com/webpack/webpack.git ${webpackDir}`, { + stdio: 'inherit', + }); + + // Checkout the target commit + console.log(`Checking out commit/branch: ${ref}...`); + execSync(`git checkout ${ref}`, { cwd: webpackDir, stdio: 'inherit' }); + + console.log('✨ Successfully completed clone-webpack script.'); +} catch (error) { + console.error('Error during git clone or checkout:', error.message); + process.exit(1); +} diff --git a/package.json b/package.json index 029a5c9..b8562d8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "scripts": { + "clone-webpack": "node clone-webpack.mjs", "generate-docs": "node generate-md.mjs", "build-html": "doc-kit generate -t web --config-file ./doc-kit.config.mjs", "build": "npm run generate-docs && npm run build-html", From 328782069d6be8386a828477f8ac421bfd614488 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Rai Date: Mon, 30 Mar 2026 19:50:43 +0530 Subject: [PATCH 2/5] refactor(dx): optimize cloning logic and unify versioning --- .github/workflows/sync.yml | 10 ++++------ README.md | 1 + clone-webpack.mjs | 23 ++++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 9ef766b..40ff5da 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -49,16 +49,14 @@ jobs: if: steps.check.outputs.changed == 'true' run: npm ci - - name: Clone webpack - if: steps.check.outputs.changed == 'true' - env: - WEBPACK_REF: ${{ steps.latest.outputs.latest }} - run: npm run clone-webpack - - name: Update HEAD_COMMIT if: steps.check.outputs.changed == 'true' run: echo "${{ steps.latest.outputs.latest }}" > HEAD_COMMIT + - name: Clone webpack + if: steps.check.outputs.changed == 'true' + run: npm run clone-webpack + - name: Regenerate docs if: steps.check.outputs.changed == 'true' run: npm run generate-docs diff --git a/README.md b/README.md index 24dfb85..1a3a112 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ This ensures documentation stays in sync with upstream webpack without manual in | Script | Description | | ----------------------- | ------------------------------------ | +| `npm run clone-webpack` | Clone webpack repo at pinned commit | | `npm run generate-docs` | Generate Markdown from webpack types | | `npm run build-html` | Convert Markdown to HTML | | `npm run build` | Generate docs + build HTML | diff --git a/clone-webpack.mjs b/clone-webpack.mjs index 7d08fb9..3954311 100644 --- a/clone-webpack.mjs +++ b/clone-webpack.mjs @@ -21,18 +21,19 @@ if (!ref) { console.log(`Cloning webpack repository at ref: ${ref}...`); -// Clean up existing directory if it exists -if (fs.existsSync(webpackDir)) { - console.log(`Removing existing ${webpackDir} directory...`); - fs.rmSync(webpackDir, { recursive: true, force: true }); -} - try { - // Clone the repository - console.log('Running git clone https://github.com/webpack/webpack.git...'); - execSync(`git clone https://github.com/webpack/webpack.git ${webpackDir}`, { - stdio: 'inherit', - }); + if (fs.existsSync(webpackDir)) { + console.log( + `Repository already exists at ${webpackDir}. Fetching latest updates...` + ); + execSync('git fetch --all', { cwd: webpackDir, stdio: 'inherit' }); + } else { + // Clone the repository + console.log('Running git clone https://github.com/webpack/webpack.git...'); + execSync(`git clone https://github.com/webpack/webpack.git ${webpackDir}`, { + stdio: 'inherit', + }); + } // Checkout the target commit console.log(`Checking out commit/branch: ${ref}...`); From 79835ec206101227eeb4b7586a46bcadc50c1ad7 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Rai Date: Mon, 30 Mar 2026 20:23:54 +0530 Subject: [PATCH 3/5] used safer variable of child_process, to pass the arguments as an array --- clone-webpack.mjs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/clone-webpack.mjs b/clone-webpack.mjs index 3954311..c816161 100644 --- a/clone-webpack.mjs +++ b/clone-webpack.mjs @@ -1,5 +1,5 @@ import fs from 'fs'; -import { execSync } from 'child_process'; +import { execFileSync } from 'child_process'; const webpackDir = './webpack'; const headCommitFile = './HEAD_COMMIT'; @@ -26,20 +26,27 @@ try { console.log( `Repository already exists at ${webpackDir}. Fetching latest updates...` ); - execSync('git fetch --all', { cwd: webpackDir, stdio: 'inherit' }); + execFileSync('git', ['fetch', '--all'], { + cwd: webpackDir, + stdio: 'inherit', + }); } else { // Clone the repository console.log('Running git clone https://github.com/webpack/webpack.git...'); - execSync(`git clone https://github.com/webpack/webpack.git ${webpackDir}`, { - stdio: 'inherit', - }); + execFileSync( + 'git', + ['clone', 'https://github.com/webpack/webpack.git', webpackDir], + { + stdio: 'inherit', + } + ); } // Checkout the target commit console.log(`Checking out commit/branch: ${ref}...`); - execSync(`git checkout ${ref}`, { cwd: webpackDir, stdio: 'inherit' }); + execFileSync('git', ['checkout', ref], { cwd: webpackDir, stdio: 'inherit' }); - console.log('✨ Successfully completed clone-webpack script.'); + console.log('Successfully completed clone-webpack script.'); } catch (error) { console.error('Error during git clone or checkout:', error.message); process.exit(1); From 919f5d53f74425822124f9c970d88380383f5dce Mon Sep 17 00:00:00 2001 From: Rahul Kumar Rai Date: Mon, 30 Mar 2026 20:36:21 +0530 Subject: [PATCH 4/5] remove error handle as per suggestation --- clone-webpack.mjs | 51 +++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/clone-webpack.mjs b/clone-webpack.mjs index c816161..c109a37 100644 --- a/clone-webpack.mjs +++ b/clone-webpack.mjs @@ -21,33 +21,28 @@ if (!ref) { console.log(`Cloning webpack repository at ref: ${ref}...`); -try { - if (fs.existsSync(webpackDir)) { - console.log( - `Repository already exists at ${webpackDir}. Fetching latest updates...` - ); - execFileSync('git', ['fetch', '--all'], { - cwd: webpackDir, +if (fs.existsSync(webpackDir)) { + console.log( + `Repository already exists at ${webpackDir}. Fetching latest updates...` + ); + execFileSync('git', ['fetch', '--all'], { + cwd: webpackDir, + stdio: 'inherit', + }); +} else { + // Clone the repository + console.log('Running git clone https://github.com/webpack/webpack.git...'); + execFileSync( + 'git', + ['clone', 'https://github.com/webpack/webpack.git', webpackDir], + { stdio: 'inherit', - }); - } else { - // Clone the repository - console.log('Running git clone https://github.com/webpack/webpack.git...'); - execFileSync( - 'git', - ['clone', 'https://github.com/webpack/webpack.git', webpackDir], - { - stdio: 'inherit', - } - ); - } - - // Checkout the target commit - console.log(`Checking out commit/branch: ${ref}...`); - execFileSync('git', ['checkout', ref], { cwd: webpackDir, stdio: 'inherit' }); - - console.log('Successfully completed clone-webpack script.'); -} catch (error) { - console.error('Error during git clone or checkout:', error.message); - process.exit(1); + } + ); } + +// Checkout the target commit +console.log(`Checking out commit/branch: ${ref}...`); +execFileSync('git', ['checkout', ref], { cwd: webpackDir, stdio: 'inherit' }); + +console.log('Successfully completed clone-webpack script.'); From dd6745e7b61340863c7a120e625ed66c868d71a2 Mon Sep 17 00:00:00 2001 From: Aviv Keller Date: Mon, 30 Mar 2026 11:49:06 -0400 Subject: [PATCH 5/5] Apply suggestion from @avivkeller --- clone-webpack.mjs | 45 ++++++++++----------------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/clone-webpack.mjs b/clone-webpack.mjs index c109a37..578a460 100644 --- a/clone-webpack.mjs +++ b/clone-webpack.mjs @@ -1,48 +1,23 @@ -import fs from 'fs'; -import { execFileSync } from 'child_process'; +import { readFile, access } from 'node:fs/promises'; +import { execFileSync } from 'node:child_process'; -const webpackDir = './webpack'; -const headCommitFile = './HEAD_COMMIT'; +const WEBPACK_DIR = 'webpack'; +const REF = (await readFile('HEAD_COMMIT', 'utf-8')).trim(); -// Allow an env var override (used by CI) -let ref = process.env.WEBPACK_REF; - -if (!ref && fs.existsSync(headCommitFile)) { - ref = fs.readFileSync(headCommitFile, 'utf-8').trim(); -} - -if (!ref) { - // Default fallback if running locally before any syncing has happened - console.log( - `Warning: WEBPACK_REF not set and ${headCommitFile} not found. Defaulting to 'main'.` - ); - ref = 'main'; -} - -console.log(`Cloning webpack repository at ref: ${ref}...`); - -if (fs.existsSync(webpackDir)) { - console.log( - `Repository already exists at ${webpackDir}. Fetching latest updates...` - ); +try { + await access(WEBPACK_DIR); execFileSync('git', ['fetch', '--all'], { - cwd: webpackDir, + cwd: WEBPACK_DIR, stdio: 'inherit', }); -} else { - // Clone the repository - console.log('Running git clone https://github.com/webpack/webpack.git...'); +} catch { execFileSync( 'git', - ['clone', 'https://github.com/webpack/webpack.git', webpackDir], + ['clone', 'https://github.com/webpack/webpack.git', WEBPACK_DIR], { stdio: 'inherit', } ); } -// Checkout the target commit -console.log(`Checking out commit/branch: ${ref}...`); -execFileSync('git', ['checkout', ref], { cwd: webpackDir, stdio: 'inherit' }); - -console.log('Successfully completed clone-webpack script.'); +execFileSync('git', ['checkout', REF], { cwd: WEBPACK_DIR, stdio: 'inherit' });