Skip to content

Commit 8df5b99

Browse files
feat(publish_yalc_package): Build packages in temp directory before publishing
1 parent 38cf7b2 commit 8df5b99

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

publish_yalc_package.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
const fs = require('fs');
1111
const path = require('path');
1212
const shelljs = require('shelljs');
13+
const tmp = require('tmp');
1314
const util = require('./util');
1415

1516
const ORIG_DIR = process.cwd();
@@ -71,17 +72,28 @@ function publishYalcPackage(installTargetDir, installSource, flags) {
7172
// Update dependencies
7273
util._exec('yarn install --check-files');
7374

74-
if (!flags.noBuild) {
75-
// Build package
76-
const pkgJson = JSON.parse(fs.readFileSync('package.json'));
77-
if (pkgJson.scripts && pkgJson.scripts.build) {
78-
util._exec('npm run build');
75+
const TEMP = tmp.dirSync();
76+
const TEMP_DIR = TEMP.name;
77+
const BUILD_TEMP_DIR = path.resolve(TEMP_DIR, path.basename(installTargetDir));
78+
try {
79+
shelljs.mv(installTargetDir, TEMP_DIR);
80+
process.chdir(BUILD_TEMP_DIR);
81+
82+
if (!flags.noBuild) {
83+
// Build package
84+
const pkgJson = JSON.parse(fs.readFileSync('package.json'));
85+
if (pkgJson.scripts && pkgJson.scripts.build) {
86+
util._exec('npm run build');
87+
}
7988
}
80-
}
8189

82-
if (!flags.noPublish) {
83-
// Publish to local yalc registry
84-
util._exec('yalc publish');
90+
if (!flags.noPublish) {
91+
// Publish to local yalc registry
92+
util._exec('yalc publish');
93+
}
94+
} finally {
95+
shelljs.mv(BUILD_TEMP_DIR, installTargetDir);
96+
shelljs.rm('-rf', TEMP_DIR);
8597
}
8698

8799
process.chdir(ORIG_DIR);

0 commit comments

Comments
 (0)