Path: blob/main/build/azure-pipelines/upload-sourcemaps.ts
5221 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.ts';10import { getProductionDependencies } from '../lib/dependencies.ts';11import { ClientAssertionCredential } from '@azure/identity';12import Stream from 'stream';13import azure from 'gulp-azure-storage';1415const root = path.dirname(path.dirname(import.meta.dirname));16const commit = process.env['BUILD_SOURCEVERSION'];17const credential = new ClientAssertionCredential(process.env['AZURE_TENANT_ID']!, process.env['AZURE_CLIENT_ID']!, () => Promise.resolve(process.env['AZURE_ID_TOKEN']!));1819// optionally allow to pass in explicit base/maps to upload20const [, , base, maps] = process.argv;2122function src(base: string, maps = `${base}/**/*.map`) {23return vfs.src(maps, { base })24.pipe(es.mapSync((f: Vinyl) => {25f.path = `${f.base}/core/${f.relative}`;26return f;27}));28}2930function main(): Promise<void> {31const sources: Stream[] = [];3233// vscode client maps (default)34if (!base) {35const vs = src('out-vscode-min'); // client source-maps only36sources.push(vs);3738const productionDependencies = getProductionDependencies(root);39const productionDependenciesSrc = productionDependencies.map((d: string) => path.relative(root, d)).map((d: string) => `./${d}/**/*.map`);40const nodeModules = vfs.src(productionDependenciesSrc, { base: '.' })41.pipe(util.cleanNodeModules(path.join(root, 'build', '.moduleignore')))42.pipe(util.cleanNodeModules(path.join(root, 'build', `.moduleignore.${process.platform}`)));43sources.push(nodeModules);4445const extensionsOut = vfs.src(['.build/extensions/**/*.js.map', '!**/node_modules/**'], { base: '.build' });46sources.push(extensionsOut);47}4849// specific client base/maps50else {51sources.push(src(base, maps));52}5354return new Promise((c, e) => {55es.merge(...sources)56.pipe(es.through(function (data: Vinyl) {57console.log('Uploading Sourcemap', data.relative); // debug58this.emit('data', data);59}))60.pipe(azure.upload({61account: process.env.AZURE_STORAGE_ACCOUNT,62credential,63container: '$web',64prefix: `sourcemaps/${commit}/`65}))66.on('end', () => c())67.on('error', (err) => e(err));68});69}7071main().catch(err => {72console.error(err);73process.exit(1);74});75767778