Skip to content

Commit 3f05332

Browse files
committed
refactor(ci): simplify prepare skip using shell env var
(cherry picked from commit 3367129)
1 parent d38428c commit 3f05332

4 files changed

Lines changed: 4 additions & 32 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ remote-client/build
6767
# Temporary backup during publish
6868
.publish-backup
6969

70-
# NPM publish flag file
71-
.npm-publish-in-progress
72-
7370
# Build artifacts
7471
*.tgz
7572

.gitlab-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ release:
6060
- export NEW_VERSION=$(echo "$CI_COMMIT_TAG" | sed 's/^cli-release-v//')
6161
# 更新版本号
6262
- npm version "$NEW_VERSION" --no-git-tag-version --force
63-
# 发布到 npm(prepublishOnly 钩子会自动执行 prepare-publish.js 和 bundle:prod
63+
# 发布到 npm(设置 SKIP_PREPARE=1 让 prepare 钩子也跳过
6464
- echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
65+
- export SKIP_PREPARE=1
6566
- npm publish
6667
after_script:
6768
- rm -f .npmrc || true

scripts/prepare-publish.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const rootDir = path.dirname(__dirname);
1414

1515
function preparePublish() {
1616
const readmePath = path.join(rootDir, 'README.md');
17-
const publishFlagFile = path.join(rootDir, '.npm-publish-in-progress');
1817

1918
console.log(chalk.cyan('\n📦 Preparing publication package...\n'));
2019

@@ -26,14 +25,6 @@ function preparePublish() {
2625

2726
console.log(chalk.green('✅ README.md check passed'));
2827
console.log(chalk.dim(' (No README replacement needed)\n'));
29-
30-
// Create a flag file to signal that we're in publish mode
31-
// This prevents the prepare hook from running redundant builds
32-
try {
33-
fs.writeFileSync(publishFlagFile, Date.now().toString());
34-
} catch (err) {
35-
console.warn(chalk.yellow('⚠️ Failed to create publish flag file:', err.message));
36-
}
3728
}
3829

3930
preparePublish();

scripts/prepare.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
#!/usr/bin/env node
22

33
import { execSync } from 'child_process';
4-
import { existsSync, unlinkSync } from 'fs';
5-
import { join, dirname } from 'path';
6-
import { fileURLToPath } from 'url';
7-
8-
const __dirname = dirname(fileURLToPath(import.meta.url));
9-
const root = join(__dirname, '..');
10-
const publishFlagFile = join(root, '.npm-publish-in-progress');
114

125
const buildEnv = process.env.BUILD_ENV;
136

147
// Skip build during npm publish (prepublishOnly will handle it)
15-
if (process.env.SKIP_PREPARE === '1' || existsSync(publishFlagFile)) {
8+
if (process.env.SKIP_PREPARE === '1') {
169
console.log('⏭️ Skipping prepare build (handled by prepublishOnly or explicitly disabled)');
17-
18-
// Clean up the flag file if it exists (prepare is the last hook in publish flow)
19-
if (existsSync(publishFlagFile)) {
20-
try {
21-
unlinkSync(publishFlagFile);
22-
} catch (err) {
23-
// Ignore errors in cleanup
24-
}
25-
}
26-
2710
process.exit(0);
2811
}
2912

@@ -34,4 +17,4 @@ if (buildEnv === 'development') {
3417
} else {
3518
console.log('Running production bundle...');
3619
execSync('npm run bundle:prod', { stdio: 'inherit' });
37-
}
20+
}

0 commit comments

Comments
 (0)