提交 0425b36c 编写于 作者: J Johannes Rieken

patch and save source maps so that they get uploaded

上级 7f2ca9a8
...@@ -16,12 +16,10 @@ var buffer = require('gulp-buffer'); ...@@ -16,12 +16,10 @@ var buffer = require('gulp-buffer');
var json = require('gulp-json-editor'); var json = require('gulp-json-editor');
var webpack = require('webpack'); var webpack = require('webpack');
var webpackGulp = require('webpack-stream'); var webpackGulp = require('webpack-stream');
var sourcemaps = require("gulp-sourcemaps");
var fs = require("fs"); var fs = require("fs");
var path = require("path"); var path = require("path");
var vsce = require("vsce"); var vsce = require("vsce");
var File = require("vinyl"); var File = require("vinyl");
var util_1 = require("./util");
function fromLocal(extensionPath, sourceMappingURLBase) { function fromLocal(extensionPath, sourceMappingURLBase) {
var result = es.through(); var result = es.through();
vsce.listFiles({ cwd: extensionPath, packageManager: vsce.PackageManager.Yarn }).then(function (fileNames) { vsce.listFiles({ cwd: extensionPath, packageManager: vsce.PackageManager.Yarn }).then(function (fileNames) {
...@@ -55,13 +53,21 @@ function fromLocal(extensionPath, sourceMappingURLBase) { ...@@ -55,13 +53,21 @@ function fromLocal(extensionPath, sourceMappingURLBase) {
data.base = extensionPath; data.base = extensionPath;
this.emit('data', data); this.emit('data', data);
})) }))
.pipe(sourcemaps.init()) .pipe(es.through(function (data) {
.pipe(Boolean(sourceMappingURLBase) ? util_1.stripSourceMappingURL() : es.through()) // source map handling:
.pipe(sourcemaps.write('.', { // * rewrite sourceMappingURL
sourceMappingURLPrefix: sourceMappingURLBase && sourceMappingURLBase + "/dist", // * save to disk so that upload-task picks this up
addComment: !!sourceMappingURLBase, if (sourceMappingURLBase && /\.js\.map$/.test(data.path)) {
includeContent: !!sourceMappingURLBase, var contents = data.contents.toString('utf8');
sourceRoot: '../src', data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
return sourceMappingURLBase + "/extensions/" + path.basename(extensionPath) + "/out/" + g1;
}), 'utf8');
if (!fs.existsSync(path.dirname(data.path))) {
fs.mkdirSync(path.dirname(data.path));
}
fs.writeFileSync(data.path, data.contents);
}
this.emit('data', data);
})); }));
es.merge(webpackStream, patchFilesStream) es.merge(webpackStream, patchFilesStream)
// .pipe(es.through(function (data) { // .pipe(es.through(function (data) {
......
...@@ -16,12 +16,10 @@ const buffer = require('gulp-buffer'); ...@@ -16,12 +16,10 @@ const buffer = require('gulp-buffer');
const json = require('gulp-json-editor'); const json = require('gulp-json-editor');
const webpack = require('webpack'); const webpack = require('webpack');
const webpackGulp = require('webpack-stream'); const webpackGulp = require('webpack-stream');
import * as sourcemaps from 'gulp-sourcemaps';
import * as fs from 'fs'; import * as fs from 'fs';
import * as path from 'path'; import * as path from 'path';
import * as vsce from 'vsce'; import * as vsce from 'vsce';
import * as File from 'vinyl'; import * as File from 'vinyl';
import { stripSourceMappingURL } from './util';
export function fromLocal(extensionPath: string, sourceMappingURLBase?: string): Stream { export function fromLocal(extensionPath: string, sourceMappingURLBase?: string): Stream {
let result = es.through(); let result = es.through();
...@@ -61,14 +59,25 @@ export function fromLocal(extensionPath: string, sourceMappingURLBase?: string): ...@@ -61,14 +59,25 @@ export function fromLocal(extensionPath: string, sourceMappingURLBase?: string):
data.base = extensionPath; data.base = extensionPath;
this.emit('data', data); this.emit('data', data);
})) }))
.pipe(sourcemaps.init()) .pipe(es.through(function (data: File) {
.pipe(Boolean(sourceMappingURLBase) ? stripSourceMappingURL() : es.through()) // source map handling:
.pipe(sourcemaps.write('.', { // * rewrite sourceMappingURL
sourceMappingURLPrefix: sourceMappingURLBase && `${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/out`, // * save to disk so that upload-task picks this up
addComment: !!sourceMappingURLBase, if (sourceMappingURLBase && /\.js\.map$/.test(data.path)) {
includeContent: !!sourceMappingURLBase, const contents = (<Buffer>data.contents).toString('utf8');
sourceRoot: '../src', data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
})); return `${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/out/${g1}`;
}), 'utf8');
if (!fs.existsSync(path.dirname(data.path))) {
fs.mkdirSync(path.dirname(data.path));
}
fs.writeFileSync(data.path, data.contents);
}
this.emit('data', data);
}))
;
es.merge(webpackStream, patchFilesStream) es.merge(webpackStream, patchFilesStream)
// .pipe(es.through(function (data) { // .pipe(es.through(function (data) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册