Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/distro/mixin-npm.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import fs from 'fs';
7
import path from 'path';
8
const { dirs } = require('../../npm/dirs') as { dirs: string[] };
9
10
function log(...args: any[]): void {
11
console.log(`[${new Date().toLocaleTimeString('en', { hour12: false })}]`, '[distro]', ...args);
12
}
13
14
function mixin(mixinPath: string) {
15
if (!fs.existsSync(`${mixinPath}/node_modules`)) {
16
log(`Skipping distro npm dependencies: ${mixinPath} (no node_modules)`);
17
return;
18
}
19
20
log(`Mixing in distro npm dependencies: ${mixinPath}`);
21
22
const distroPackageJson = JSON.parse(fs.readFileSync(`${mixinPath}/package.json`, 'utf8'));
23
const targetPath = path.relative('.build/distro/npm', mixinPath);
24
25
for (const dependency of Object.keys(distroPackageJson.dependencies)) {
26
fs.rmSync(`./${targetPath}/node_modules/${dependency}`, { recursive: true, force: true });
27
fs.cpSync(`${mixinPath}/node_modules/${dependency}`, `./${targetPath}/node_modules/${dependency}`, { recursive: true, force: true, dereference: true });
28
}
29
30
log(`Mixed in distro npm dependencies: ${mixinPath} ✔︎`);
31
}
32
33
function main() {
34
log(`Mixing in distro npm dependencies...`);
35
36
const mixinPaths = dirs.filter(d => /^.build\/distro\/npm/.test(d));
37
38
for (const mixinPath of mixinPaths) {
39
mixin(mixinPath);
40
}
41
}
42
43
main();
44
45