Path: blob/main/build/azure-pipelines/distro/mixin-npm.ts
3520 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import fs from 'fs';6import path from 'path';7const { dirs } = require('../../npm/dirs') as { dirs: string[] };89function log(...args: any[]): void {10console.log(`[${new Date().toLocaleTimeString('en', { hour12: false })}]`, '[distro]', ...args);11}1213function mixin(mixinPath: string) {14if (!fs.existsSync(`${mixinPath}/node_modules`)) {15log(`Skipping distro npm dependencies: ${mixinPath} (no node_modules)`);16return;17}1819log(`Mixing in distro npm dependencies: ${mixinPath}`);2021const distroPackageJson = JSON.parse(fs.readFileSync(`${mixinPath}/package.json`, 'utf8'));22const targetPath = path.relative('.build/distro/npm', mixinPath);2324for (const dependency of Object.keys(distroPackageJson.dependencies)) {25fs.rmSync(`./${targetPath}/node_modules/${dependency}`, { recursive: true, force: true });26fs.cpSync(`${mixinPath}/node_modules/${dependency}`, `./${targetPath}/node_modules/${dependency}`, { recursive: true, force: true, dereference: true });27}2829log(`Mixed in distro npm dependencies: ${mixinPath} ✔︎`);30}3132function main() {33log(`Mixing in distro npm dependencies...`);3435const mixinPaths = dirs.filter(d => /^.build\/distro\/npm/.test(d));3637for (const mixinPath of mixinPaths) {38mixin(mixinPath);39}40}4142main();434445