Skip to content

Commit e88156e

Browse files
committed
feat: Symlink duplicate npm versions
1 parent f510d19 commit e88156e

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

Diff for: image/setup/install_node.js

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
var versions = require('./versions.json');
2-
32
var { spawnSync, execSync } = require('child_process');
3+
var fs = require('fs');
44

55
var nvm = '. "$NVM_DIR/nvm.sh" && nvm';
66

77
process.env.PATH += ':/home/app/.nvm';
8-
98
console.log('\nInstalling node versions');
109

1110
function log({ output }) {
@@ -23,13 +22,19 @@ for (var i = 0; i < versions.length; i++) {
2322
});
2423
log(output);
2524

26-
var useOutput = spawnSync(nvm, ['use', version.node], {
27-
stdio: 'pipe',
28-
shell: true
29-
});
30-
log(useOutput);
31-
32-
if (version.npm !== 'default') {
25+
if (version.npm === (versions[i - 1] ? versions[i - 1].npm : '')) {
26+
console.log('symlinking duplicate npm version');
27+
const prevVersion = versions[i - 1];
28+
29+
// This is only correct when the version.node is 0.10.x since nvm stores
30+
// newer versions in a different location
31+
const targetPath = `/home/app/.nvm/v${version.node}/lib/node_modules/npm`;
32+
execSync(`rm -rf ${targetPath}`);
33+
fs.symlinkSync(
34+
`/home/app/.nvm/versions/node/v${prevVersion.node}/lib/node_modules/npm`,
35+
targetPath
36+
);
37+
} else if (version.npm !== 'default') {
3338
var npmOutput = execSync(`${nvm} use ${version.node} && npm install --global npm@${version.npm}`, {
3439
stdio: 'pipe'
3540
});

Diff for: image/setup/versions.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[
22
{
3-
"node": "0.10.48",
4-
"npm": "3.10.10"
3+
"node": "8.8.1",
4+
"npm": "default"
55
},
66
{
77
"node": "4.8.4",
88
"npm": "3.10.10"
99
},
1010
{
11-
"node": "8.11.2",
12-
"npm": "default"
11+
"node": "0.10.48",
12+
"npm": "3.10.10"
1313
}
14-
]
14+
]

0 commit comments

Comments
 (0)