Path: blob/main/build/azure-pipelines/upload-sourcemaps.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 path from 'path';6import es from 'event-stream';7import Vinyl from 'vinyl';8import vfs from 'vinyl-fs';9import * as util from '../lib/util';10import { getProductionDependencies } from '../lib/dependencies';11import { ClientAssertionCredential } from '@azure/identity';12const azure = require('gulp-azure-storage');1314const root = path.dirname(path.dirname(__dirname));15const commit = process.env['BUILD_SOURCEVERSION'];16const credential = new ClientAssertionCredential(process.env['AZURE_TENANT_ID']!, process.env['AZURE_CLIENT_ID']!, () => Promise.resolve(process.env['AZURE_ID_TOKEN']!));1718// optionally allow to pass in explicit base/maps to upload19const [, , base, maps] = process.argv;2021function src(base: string, maps = `${base}/**/*.map`) {22return vfs.src(maps, { base })23.pipe(es.mapSync((f: Vinyl) => {24f.path = `${f.base}/core/${f.relative}`;25return f;26}));27}2829function main(): Promise<void> {30const sources: any[] = [];3132// vscode client maps (default)33if (!base) {34const vs = src('out-vscode-min'); // client source-maps only35sources.push(vs);3637const productionDependencies = getProductionDependencies(root);38const productionDependenciesSrc = productionDependencies.map((d: string) => path.relative(root, d)).map((d: string) => `./${d}/**/*.map`);39const nodeModules = vfs.src(productionDependenciesSrc, { base: '.' })40.pipe(util.cleanNodeModules(path.join(root, 'build', '.moduleignore')))41.pipe(util.cleanNodeModules(path.join(root, 'build', `.moduleignore.${process.platform}`)));42sources.push(nodeModules);4344const extensionsOut = vfs.src(['.build/extensions/**/*.js.map', '!**/node_modules/**'], { base: '.build' });45sources.push(extensionsOut);46}4748// specific client base/maps49else {50sources.push(src(base, maps));51}5253return new Promise((c, e) => {54es.merge(...sources)55.pipe(es.through(function (data: Vinyl) {56console.log('Uploading Sourcemap', data.relative); // debug57this.emit('data', data);58}))59.pipe(azure.upload({60account: process.env.AZURE_STORAGE_ACCOUNT,61credential,62container: '$web',63prefix: `sourcemaps/${commit}/`64}))65.on('end', () => c())66.on('error', (err: any) => e(err));67});68}6970main().catch(err => {71console.error(err);72process.exit(1);73});74757677