|
10 | 10 | const fs = require('fs');
|
11 | 11 | const path = require('path');
|
12 | 12 | const shelljs = require('shelljs');
|
| 13 | +const tmp = require('tmp'); |
13 | 14 | const util = require('./util');
|
14 | 15 |
|
15 | 16 | const ORIG_DIR = process.cwd();
|
@@ -71,17 +72,28 @@ function publishYalcPackage(installTargetDir, installSource, flags) {
|
71 | 72 | // Update dependencies
|
72 | 73 | util._exec('yarn install --check-files');
|
73 | 74 |
|
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 | + } |
79 | 88 | }
|
80 |
| - } |
81 | 89 |
|
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); |
85 | 97 | }
|
86 | 98 |
|
87 | 99 | process.chdir(ORIG_DIR);
|
|
0 commit comments