Skip to content

Commit

Permalink
publish extension sourcemaps
Browse files Browse the repository at this point in the history
fixes #10994
  • Loading branch information
joaomoreno committed Sep 13, 2016
1 parent 037b234 commit 9da8d35
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 89 deletions.
20 changes: 6 additions & 14 deletions build/gulpfile.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ function log(prefix, message) {
gulpUtil.log(gulpUtil.colors.cyan('[' + prefix + ']'), message);
}

const root = path.dirname(__dirname);
const commit = util.getVersion(root);

exports.loaderConfig = function (emptyPaths) {
const result = {
paths: {
Expand Down Expand Up @@ -236,19 +233,16 @@ function uglifyWithCopyrights() {
const uglifyStream = uglify({ preserveComments });

return es.through(function (data) {
const _this = this;

onNewFile();

uglifyStream.once('data', function(data) {
_this.emit('data', data);
})
uglifyStream.once('data', data => this.emit('data', data));
uglifyStream.write(data);
},
function () { this.emit('end'); });
}

exports.minifyTask = function (src, addSourceMapsComment) {
exports.minifyTask = function (src, sourceMapBaseUrl) {
const sourceMappingURL = sourceMapBaseUrl && (f => `${ sourceMapBaseUrl }/${ f.relative }.map`);

return function() {
const jsFilter = filter('**/*.js', { restore: true });
const cssFilter = filter('**/*.css', { restore: true });
Expand All @@ -262,12 +256,10 @@ exports.minifyTask = function (src, addSourceMapsComment) {
.pipe(minifyCSS({ reduceIdents: false }))
.pipe(cssFilter.restore)
.pipe(sourcemaps.write('./', {
sourceMappingURL: function (file) {
return 'https://ticino.blob.core.windows.net/sourcemaps/' + commit + '/' + file.relative + '.map';
},
sourceMappingURL,
sourceRoot: null,
includeContent: true,
addComment: addSourceMapsComment
addComment: true
}))
.pipe(gulp.dest(src + '-min'));
};
Expand Down
3 changes: 1 addition & 2 deletions build/gulpfile.editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var buildfile = require('../src/buildfile');
var util = require('./lib/util');
var common = require('./gulpfile.common');
var es = require('event-stream');
var fs = require('fs');
var File = require('vinyl');

var root = path.dirname(__dirname);
Expand Down Expand Up @@ -78,7 +77,7 @@ gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common
}));

gulp.task('clean-minified-editor', util.rimraf('out-editor-min'));
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor', true));
gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor'));

gulp.task('clean-editor-distro', util.rimraf('out-monaco-editor-core'));
gulp.task('editor-distro', ['clean-editor-distro', 'minify-editor', 'optimize-editor'], function() {
Expand Down
113 changes: 56 additions & 57 deletions build/gulpfile.extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,63 @@
// Increase max listeners for event emitters
require('events').EventEmitter.defaultMaxListeners = 100;

var gulp = require('gulp');
var path = require('path');
var tsb = require('gulp-tsb');
var es = require('event-stream');
var filter = require('gulp-filter');
var rimraf = require('rimraf');
var util = require('./lib/util');
var watcher = require('./lib/watch');
var createReporter = require('./lib/reporter');
var glob = require('glob');
var sourcemaps = require('gulp-sourcemaps');
var nlsDev = require('vscode-nls-dev');

var extensionsPath = path.join(path.dirname(__dirname), 'extensions');

var compilations = glob.sync('**/tsconfig.json', {
const gulp = require('gulp');
const path = require('path');
const tsb = require('gulp-tsb');
const es = require('event-stream');
const filter = require('gulp-filter');
const rimraf = require('rimraf');
const util = require('./lib/util');
const watcher = require('./lib/watch');
const createReporter = require('./lib/reporter');
const glob = require('glob');
const sourcemaps = require('gulp-sourcemaps');
const nlsDev = require('vscode-nls-dev');
const root = path.dirname(__dirname);
const commit = util.getVersion(root);

const extensionsPath = path.join(path.dirname(__dirname), 'extensions');

const compilations = glob.sync('**/tsconfig.json', {
cwd: extensionsPath,
ignore: ['**/out/**', '**/node_modules/**']
});

var languages = ['chs', 'cht', 'jpn', 'kor', 'deu', 'fra', 'esn', 'rus', 'ita'];
const getBaseUrl = out => `https://ticino.blob.core.windows.net/sourcemaps/${ commit }/${ out }`;
const languages = ['chs', 'cht', 'jpn', 'kor', 'deu', 'fra', 'esn', 'rus', 'ita'];

var tasks = compilations.map(function(tsconfigFile) {
var absolutePath = path.join(extensionsPath, tsconfigFile);
var relativeDirname = path.dirname(tsconfigFile);
const tasks = compilations.map(function(tsconfigFile) {
const absolutePath = path.join(extensionsPath, tsconfigFile);
const relativeDirname = path.dirname(tsconfigFile);

var tsOptions = require(absolutePath).compilerOptions;
const tsOptions = require(absolutePath).compilerOptions;
tsOptions.verbose = false;
tsOptions.sourceMap = true;

var name = relativeDirname.replace(/\//g, '-');
const name = relativeDirname.replace(/\//g, '-');

// Tasks
var clean = 'clean-extension:' + name;
var compile = 'compile-extension:' + name;
var watch = 'watch-extension:' + name;
const clean = 'clean-extension:' + name;
const compile = 'compile-extension:' + name;
const watch = 'watch-extension:' + name;

// Build Tasks
var cleanBuild = 'clean-extension-build:' + name;
var compileBuild = 'compile-extension-build:' + name;
var watchBuild = 'watch-extension-build:' + name;
const cleanBuild = 'clean-extension-build:' + name;
const compileBuild = 'compile-extension-build:' + name;
const watchBuild = 'watch-extension-build:' + name;

var root = path.join('extensions', relativeDirname);
var srcBase = path.join(root, 'src');
var src = path.join(srcBase, '**');
var out = path.join(root, 'out');
var i18n = path.join(__dirname, '..', 'i18n');
const root = path.join('extensions', relativeDirname);
const srcBase = path.join(root, 'src');
const src = path.join(srcBase, '**');
const out = path.join(root, 'out');
const i18n = path.join(__dirname, '..', 'i18n');
const baseUrl = getBaseUrl(out);

function createPipeline(build) {
var reporter = createReporter();
const reporter = createReporter();

tsOptions.inlineSources = !!build;
var compilation = tsb.create(tsOptions, null, null, err => reporter(err.toString()));
const compilation = tsb.create(tsOptions, null, null, err => reporter(err.toString()));

return function () {
const input = es.through();
Expand All @@ -68,13 +72,12 @@ var tasks = compilations.map(function(tsconfigFile) {
.pipe(util.loadSourcemaps())
.pipe(compilation())
.pipe(build ? nlsDev.rewriteLocalizeCalls() : es.through())
.pipe(build ? util.stripSourceMappingURL() : es.through())
.pipe(sourcemaps.write('.', {
addComment: false,
sourceMappingURL: !build ? null : f => `${ baseUrl }/${ f.relative }.map`,
addComment: !!build,
includeContent: !!build,
sourceRoot: function(file) {
const levels = file.relative.split(path.sep).length;
return '../'.repeat(levels) + 'src';
}
sourceRoot: file => '../'.repeat(file.relative.split(path.sep).length) + 'src'
}))
.pipe(tsFilter.restore)
.pipe(build ? nlsDev.createAdditionalLanguageFiles(languages, i18n, out) : es.through())
Expand All @@ -86,11 +89,9 @@ var tasks = compilations.map(function(tsconfigFile) {

const srcOpts = { cwd: path.dirname(__dirname), base: srcBase };

gulp.task(clean, function (cb) {
rimraf(out, cb);
});
gulp.task(clean, cb => rimraf(out, cb));

gulp.task(compile, [clean], function () {
gulp.task(compile, [clean], () => {
const pipeline = createPipeline(false);
const input = gulp.src(src, srcOpts);

Expand All @@ -99,7 +100,7 @@ var tasks = compilations.map(function(tsconfigFile) {
.pipe(gulp.dest(out));
});

gulp.task(watch, [clean], function () {
gulp.task(watch, [clean], () => {
const pipeline = createPipeline(false);
const input = gulp.src(src, srcOpts);
const watchInput = watcher(src, srcOpts);
Expand All @@ -109,11 +110,9 @@ var tasks = compilations.map(function(tsconfigFile) {
.pipe(gulp.dest(out));
});

gulp.task(cleanBuild, function (cb) {
rimraf(out, cb);
});
gulp.task(cleanBuild, cb => rimraf(out, cb));

gulp.task(compileBuild, [clean], function () {
gulp.task(compileBuild, [clean], () => {
const pipeline = createPipeline(true);
const input = gulp.src(src, srcOpts);

Expand All @@ -122,13 +121,13 @@ var tasks = compilations.map(function(tsconfigFile) {
.pipe(gulp.dest(out));
});

gulp.task(watchBuild, [clean], function () {
gulp.task(watchBuild, [clean], () => {
const pipeline = createPipeline(true);
const input = gulp.src(src, srcOpts);
const watchInput = watcher(src, srcOpts);

return watchInput
.pipe(util.incremental(function () { return pipeline(true); }, input))
.pipe(util.incremental(() => pipeline(true), input))
.pipe(gulp.dest(out));
});

Expand All @@ -142,10 +141,10 @@ var tasks = compilations.map(function(tsconfigFile) {
};
});

gulp.task('clean-extensions', tasks.map(function (t) { return t.clean; }));
gulp.task('compile-extensions', tasks.map(function (t) { return t.compile; }));
gulp.task('watch-extensions', tasks.map(function (t) { return t.watch; }));
gulp.task('clean-extensions', tasks.map(t => t.clean));
gulp.task('compile-extensions', tasks.map(t => t.compile));
gulp.task('watch-extensions', tasks.map(t => t.watch));

gulp.task('clean-extensions-build', tasks.map(function (t) { return t.cleanBuild; }));
gulp.task('compile-extensions-build', tasks.map(function (t) { return t.compileBuild; }));
gulp.task('watch-extensions-build', tasks.map(function (t) { return t.watchBuild; }));
gulp.task('clean-extensions-build', tasks.map(t => t.cleanBuild));
gulp.task('compile-extensions-build', tasks.map(t => t.compileBuild));
gulp.task('watch-extensions-build', tasks.map(t => t.watchBuild));
17 changes: 13 additions & 4 deletions build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ gulp.task('optimize-vscode', ['clean-optimized-vscode', 'compile-build', 'compil
out: 'out-vscode'
}));

const baseUrl = `https://ticino.blob.core.windows.net/sourcemaps/${ commit }/core`;
gulp.task('clean-minified-vscode', util.rimraf('out-vscode-min'));
gulp.task('minify-vscode', ['clean-minified-vscode', 'optimize-vscode'], common.minifyTask('out-vscode', true));
gulp.task('minify-vscode', ['clean-minified-vscode', 'optimize-vscode'], common.minifyTask('out-vscode', baseUrl));

// Package
const darwinCreditsTemplate = product.darwinCredits && _.template(fs.readFileSync(path.join(root, product.darwinCredits), 'utf8'));
Expand Down Expand Up @@ -269,12 +270,20 @@ gulp.task('vscode-linux-arm-min', ['minify-vscode', 'clean-vscode-linux-arm'], p

// Sourcemaps

gulp.task('upload-vscode-sourcemaps', ['minify-vscode'], function () {
return gulp.src('out-vscode-min/**/*.map')
gulp.task('upload-vscode-sourcemaps', ['minify-vscode'], () => {
const vs = gulp.src('out-vscode-min/**/*.map', { base: 'out-vscode-min' })
.pipe(es.mapSync(f => {
f.path = `${ f.base }/core/${ f.relative }`;
return f;
}));

const extensions = gulp.src('extensions/**/out/**/*.map', { base: '.' });

return es.merge(vs, extensions)
.pipe(azure.upload({
account: process.env.AZURE_STORAGE_ACCOUNT,
key: process.env.AZURE_STORAGE_ACCESS_KEY,
container: 'sourcemaps',
prefix: commit + '/'
prefix: commit + '/core/'
}));
});
25 changes: 13 additions & 12 deletions build/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,6 @@ exports.toFileUri = filePath => {
return 'file://' + filePath.replace(/\\/g, '/');
};

exports.rebase = (base, append) => {
return es.mapSync(f => {
if (append) {
f.base = path.join(f.base, base);
} else {
f.base = base;
}

return f;
});
};

exports.skipDirectories = () => {
return es.mapSync(f => {
if (!f.isDirectory()) {
Expand Down Expand Up @@ -241,6 +229,19 @@ exports.loadSourcemaps = () => {
return es.duplex(input, output);
};

exports.stripSourceMappingURL = () => {
const input = es.through();

const output = input
.pipe(es.mapSync(f => {
const contents = f.contents.toString('utf8');
f.contents = new Buffer(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, ''), 'utf8');
return f;
}));

return es.duplex(input, output);
};

exports.rimraf = dir => {
let retries = 0;

Expand Down

0 comments on commit 9da8d35

Please sign in to comment.