mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 13:46:13 +00:00
Merge pull request #56261 from Microsoft/joh/extpack
Use webpack for emmet and git extension
This commit is contained in:
commit
5399233b88
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@ npm-debug.log
|
|||
Thumbs.db
|
||||
node_modules/
|
||||
.build/
|
||||
extensions/**/dist/
|
||||
out/
|
||||
out-build/
|
||||
out-editor/
|
||||
|
|
|
@ -89,7 +89,7 @@ const tasks = compilations.map(function (tsconfigFile) {
|
|||
.pipe(tsFilter)
|
||||
.pipe(util.loadSourcemaps())
|
||||
.pipe(compilation())
|
||||
.pipe(build ? nlsDev.rewriteLocalizeCalls() : es.through())
|
||||
.pipe(build ? nlsDev.rewriteLocalizeCalls({ keepFilenames: true }) : es.through())
|
||||
.pipe(build ? util.stripSourceMappingURL() : es.through())
|
||||
.pipe(sourcemaps.write('.', {
|
||||
sourceMappingURL: !build ? null : f => `${baseUrl}/${f.relative}.map`,
|
||||
|
|
|
@ -113,9 +113,9 @@ gulp.task('optimize-index-js', ['optimize-vscode'], () => {
|
|||
fs.writeFileSync(fullpath, newContents);
|
||||
});
|
||||
|
||||
const baseUrl = `https://ticino.blob.core.windows.net/sourcemaps/${commit}/core`;
|
||||
const sourceMappingURLBase = `https://ticino.blob.core.windows.net/sourcemaps/${commit}`;
|
||||
gulp.task('clean-minified-vscode', util.rimraf('out-vscode-min'));
|
||||
gulp.task('minify-vscode', ['clean-minified-vscode', 'optimize-index-js'], common.minifyTask('out-vscode', baseUrl));
|
||||
gulp.task('minify-vscode', ['clean-minified-vscode', 'optimize-index-js'], common.minifyTask('out-vscode', `${sourceMappingURLBase}/core`));
|
||||
|
||||
// Package
|
||||
|
||||
|
@ -240,7 +240,7 @@ function packageTask(platform, arch, opts) {
|
|||
.filter(({ name }) => builtInExtensions.every(b => b.name !== name));
|
||||
|
||||
const localExtensions = es.merge(...localExtensionDescriptions.map(extension => {
|
||||
return ext.fromLocal(extension.path)
|
||||
return ext.fromLocal(extension.path, sourceMappingURLBase)
|
||||
.pipe(rename(p => p.dirname = `extensions/${extension.name}/${p.dirname}`));
|
||||
}));
|
||||
|
||||
|
@ -451,16 +451,22 @@ gulp.task('vscode-translations-import', function () {
|
|||
|
||||
// Sourcemaps
|
||||
|
||||
gulp.task('upload-vscode-sourcemaps', ['minify-vscode'], () => {
|
||||
gulp.task('upload-vscode-sourcemaps', ['vscode-darwin-min', '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: '.' });
|
||||
const extensionsOut = gulp.src('extensions/**/out/**/*.map', { base: '.' });
|
||||
const extensionsDist = gulp.src('extensions/**/dist/**/*.map', { base: '.' });
|
||||
|
||||
return es.merge(vs, extensions)
|
||||
return es.merge(vs, extensionsOut, extensionsDist)
|
||||
.pipe(es.through(function (data) {
|
||||
// debug
|
||||
console.log('Uploading Sourcemap', data.relative);
|
||||
this.emit('data', data);
|
||||
}))
|
||||
.pipe(azure.upload({
|
||||
account: process.env.AZURE_STORAGE_ACCOUNT,
|
||||
key: process.env.AZURE_STORAGE_ACCESS_KEY,
|
||||
|
|
|
@ -3,6 +3,14 @@
|
|||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
var __assign = (this && this.__assign) || Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var es = require("event-stream");
|
||||
var assign = require("object-assign");
|
||||
|
@ -14,14 +22,15 @@ var rename = require('gulp-rename');
|
|||
var util = require('gulp-util');
|
||||
var buffer = require('gulp-buffer');
|
||||
var json = require('gulp-json-editor');
|
||||
var webpack = require('webpack');
|
||||
var webpackGulp = require('webpack-stream');
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var vsce = require("vsce");
|
||||
var File = require("vinyl");
|
||||
function fromLocal(extensionPath) {
|
||||
function fromLocal(extensionPath, sourceMappingURLBase) {
|
||||
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) {
|
||||
var files = fileNames
|
||||
.map(function (fileName) { return path.join(extensionPath, fileName); })
|
||||
.map(function (filePath) { return new File({
|
||||
|
@ -30,9 +39,58 @@ function fromLocal(extensionPath) {
|
|||
base: extensionPath,
|
||||
contents: fs.createReadStream(filePath)
|
||||
}); });
|
||||
es.readArray(files).pipe(result);
|
||||
})
|
||||
.catch(function (err) { return result.emit('error', err); });
|
||||
var filesStream = es.readArray(files);
|
||||
// check for a webpack configuration file, then invoke webpack
|
||||
// and merge its output with the files stream. also rewrite the package.json
|
||||
// file to a new entry point
|
||||
if (fs.existsSync(path.join(extensionPath, 'extension.webpack.config.js'))) {
|
||||
var packageJsonFilter = filter('package.json', { restore: true });
|
||||
var patchFilesStream = filesStream
|
||||
.pipe(packageJsonFilter)
|
||||
.pipe(buffer())
|
||||
.pipe(json(function (data) {
|
||||
// hardcoded entry point directory!
|
||||
data.main = data.main.replace('/out/', /dist/);
|
||||
return data;
|
||||
}))
|
||||
.pipe(packageJsonFilter.restore);
|
||||
var webpackConfig = __assign({}, require(path.join(extensionPath, 'extension.webpack.config.js')), { mode: 'production', stats: 'errors-only' });
|
||||
var webpackStream = webpackGulp(webpackConfig, webpack)
|
||||
.pipe(es.through(function (data) {
|
||||
data.stat = data.stat || {};
|
||||
data.base = extensionPath;
|
||||
this.emit('data', data);
|
||||
}))
|
||||
.pipe(es.through(function (data) {
|
||||
// source map handling:
|
||||
// * rewrite sourceMappingURL
|
||||
// * save to disk so that upload-task picks this up
|
||||
if (sourceMappingURLBase) {
|
||||
var contents = data.contents.toString('utf8');
|
||||
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
|
||||
return "\n//# sourceMappingURL=" + sourceMappingURLBase + "/extensions/" + path.basename(extensionPath) + "/dist/" + g1;
|
||||
}), 'utf8');
|
||||
if (/\.js\.map$/.test(data.path)) {
|
||||
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)
|
||||
// .pipe(es.through(function (data) {
|
||||
// // debug
|
||||
// console.log('out', data.path, data.contents.length);
|
||||
// this.emit('data', data);
|
||||
// }))
|
||||
.pipe(result);
|
||||
}
|
||||
else {
|
||||
filesStream.pipe(result);
|
||||
}
|
||||
}).catch(function (err) { return result.emit('error', err); });
|
||||
return result;
|
||||
}
|
||||
exports.fromLocal = fromLocal;
|
||||
|
|
|
@ -14,16 +14,17 @@ const rename = require('gulp-rename');
|
|||
const util = require('gulp-util');
|
||||
const buffer = require('gulp-buffer');
|
||||
const json = require('gulp-json-editor');
|
||||
const webpack = require('webpack');
|
||||
const webpackGulp = require('webpack-stream');
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as vsce from 'vsce';
|
||||
import * as File from 'vinyl';
|
||||
|
||||
export function fromLocal(extensionPath: string): Stream {
|
||||
const result = es.through();
|
||||
export function fromLocal(extensionPath: string, sourceMappingURLBase?: string): Stream {
|
||||
let result = es.through();
|
||||
|
||||
vsce.listFiles({ cwd: extensionPath, packageManager: vsce.PackageManager.Yarn })
|
||||
.then(fileNames => {
|
||||
vsce.listFiles({ cwd: extensionPath, packageManager: vsce.PackageManager.Yarn }).then(fileNames => {
|
||||
const files = fileNames
|
||||
.map(fileName => path.join(extensionPath, fileName))
|
||||
.map(filePath => new File({
|
||||
|
@ -33,9 +34,68 @@ export function fromLocal(extensionPath: string): Stream {
|
|||
contents: fs.createReadStream(filePath) as any
|
||||
}));
|
||||
|
||||
es.readArray(files).pipe(result);
|
||||
})
|
||||
.catch(err => result.emit('error', err));
|
||||
const filesStream = es.readArray(files);
|
||||
|
||||
// check for a webpack configuration file, then invoke webpack
|
||||
// and merge its output with the files stream. also rewrite the package.json
|
||||
// file to a new entry point
|
||||
if (fs.existsSync(path.join(extensionPath, 'extension.webpack.config.js'))) {
|
||||
const packageJsonFilter = filter('package.json', { restore: true });
|
||||
|
||||
const patchFilesStream = filesStream
|
||||
.pipe(packageJsonFilter)
|
||||
.pipe(buffer())
|
||||
.pipe(json(data => {
|
||||
// hardcoded entry point directory!
|
||||
data.main = data.main.replace('/out/', /dist/);
|
||||
return data;
|
||||
}))
|
||||
.pipe(packageJsonFilter.restore);
|
||||
|
||||
const webpackConfig = {
|
||||
...require(path.join(extensionPath, 'extension.webpack.config.js')),
|
||||
...{ mode: 'production', stats: 'errors-only' }
|
||||
};
|
||||
const webpackStream = webpackGulp(webpackConfig, webpack)
|
||||
.pipe(es.through(function (data) {
|
||||
data.stat = data.stat || {};
|
||||
data.base = extensionPath;
|
||||
this.emit('data', data);
|
||||
}))
|
||||
.pipe(es.through(function (data: File) {
|
||||
// source map handling:
|
||||
// * rewrite sourceMappingURL
|
||||
// * save to disk so that upload-task picks this up
|
||||
if (sourceMappingURLBase) {
|
||||
const contents = (<Buffer>data.contents).toString('utf8');
|
||||
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
|
||||
return `\n//# sourceMappingURL=${sourceMappingURLBase}/extensions/${path.basename(extensionPath)}/dist/${g1}`;
|
||||
}), 'utf8');
|
||||
|
||||
if (/\.js\.map$/.test(data.path)) {
|
||||
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)
|
||||
// .pipe(es.through(function (data) {
|
||||
// // debug
|
||||
// console.log('out', data.path, data.contents.length);
|
||||
// this.emit('data', data);
|
||||
// }))
|
||||
.pipe(result);
|
||||
|
||||
} else {
|
||||
filesStream.pipe(result);
|
||||
}
|
||||
|
||||
}).catch(err => result.emit('error', err));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
test/**
|
||||
src/**
|
||||
out/**
|
||||
tsconfig.json
|
24
extensions/emmet/extension.webpack.config.js
Normal file
24
extensions/emmet/extension.webpack.config.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const sharedConfig = require('../shared.webpack.config');
|
||||
|
||||
const myConfig = {
|
||||
entry: {
|
||||
extension: './src/extension.ts',
|
||||
},
|
||||
externals: {
|
||||
'vscode': 'commonjs vscode', // ignored because it doesn't exist
|
||||
'@emmetio/css-parser': 'commonjs @emmetio/css-parser',
|
||||
'@emmetio/html-matcher': 'commonjs @emmetio/html-matcher',
|
||||
'@emmetio/math-expression': 'commonjs @emmetio/math-expression',
|
||||
'image-size': 'commonjs image-size',
|
||||
'vscode-emmet-helper': 'commonjs vscode-emmet-helper',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = { ...sharedConfig(__dirname), ...myConfig };
|
|
@ -1,5 +1,5 @@
|
|||
src/**
|
||||
test/**
|
||||
out/test/**
|
||||
out/**
|
||||
tsconfig.json
|
||||
build/**
|
37
extensions/git/extension.webpack.config.js
Normal file
37
extensions/git/extension.webpack.config.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const sharedConfig = require('../shared.webpack.config');
|
||||
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
||||
|
||||
const myConfig = {
|
||||
node: {
|
||||
__dirname: false // leave the __dirname-behaviour intact
|
||||
},
|
||||
entry: {
|
||||
main: './out/main.js',
|
||||
['askpass-main']: './out/askpass-main.js'
|
||||
},
|
||||
plugins: [
|
||||
new CopyWebpackPlugin([
|
||||
{ from: './out/*.sh', to: '[name].sh' },
|
||||
{ from: './out/nls.*.json', to: '[name].json' }
|
||||
])
|
||||
],
|
||||
externals: {
|
||||
'vscode': 'commonjs vscode', // ignored because it doesn't exist
|
||||
"byline": 'commonjs byline',
|
||||
"file-type": 'commonjs file-type',
|
||||
"iconv-lite": 'commonjs iconv-lite',
|
||||
"jschardet": 'commonjs jschardet',
|
||||
"vscode-extension-telemetry": 'commonjs vscode-extension-telemetry',
|
||||
"vscode-nls": 'commonjs vscode-nls',
|
||||
"which": 'commonjs which',
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = { ...sharedConfig(__dirname, false), ...myConfig };
|
|
@ -77,7 +77,7 @@ export async function activate(context: ExtensionContext): Promise<API> {
|
|||
commands.registerCommand('git.showOutput', () => outputChannel.show());
|
||||
disposables.push(outputChannel);
|
||||
|
||||
const { name, version, aiKey } = require(context.asAbsolutePath('./package.json')) as { name: string, version: string, aiKey: string };
|
||||
const { name, version, aiKey } = require('../package.json') as { name: string, version: string, aiKey: string };
|
||||
const telemetryReporter = new TelemetryReporter(name, version, aiKey);
|
||||
deactivateTasks.push(() => telemetryReporter.dispose());
|
||||
|
||||
|
|
59
extensions/shared.webpack.config.js
Normal file
59
extensions/shared.webpack.config.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
/**
|
||||
* Function that must be invoked with __dirname and that
|
||||
* returns a good default configuation for extensions that
|
||||
* want to do webpack
|
||||
*/
|
||||
module.exports = function (extensionDir, useTsLoader = true) {
|
||||
let config = {
|
||||
context: extensionDir,
|
||||
mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production')
|
||||
target: 'node', // extensions run in a node context
|
||||
resolve: {
|
||||
mainFields: ['main'], // prefer the main-entry of package.json files
|
||||
extensions: [".js"]
|
||||
},
|
||||
module: {
|
||||
rules: []
|
||||
},
|
||||
output: {
|
||||
// all output goes into `dist`.
|
||||
// packaging depends on that and this must always be like it
|
||||
filename: '[name].js',
|
||||
path: path.join(extensionDir, 'dist'),
|
||||
libraryTarget: "commonjs",
|
||||
},
|
||||
// yes, really source maps
|
||||
devtool: 'source-map'
|
||||
};
|
||||
|
||||
if (useTsLoader) {
|
||||
config.resolve.extensions = [".ts", ".js"]; // support ts-files and js-files
|
||||
config.module.rules = [{
|
||||
// configure TypeScript loader:
|
||||
// * only transpile because we have a separate compilation pipeline
|
||||
// * enable sources maps for end-to-end source maps
|
||||
test: /\.ts$/,
|
||||
exclude: /node_modules/,
|
||||
use: [{
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
transpileOnly: true,
|
||||
compilerOptions: {
|
||||
"sourceMap": true,
|
||||
}
|
||||
}
|
||||
}]
|
||||
}];
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
|
@ -62,6 +62,7 @@
|
|||
"asar": "^0.14.0",
|
||||
"chromium-pickle-js": "^0.2.0",
|
||||
"clean-css": "3.4.6",
|
||||
"copy-webpack-plugin": "^4.5.2",
|
||||
"coveralls": "^2.11.11",
|
||||
"cson-parser": "^1.3.3",
|
||||
"debounce": "^1.0.0",
|
||||
|
@ -115,6 +116,7 @@
|
|||
"rimraf": "^2.2.8",
|
||||
"sinon": "^1.17.2",
|
||||
"source-map": "^0.4.4",
|
||||
"ts-loader": "^4.4.2",
|
||||
"tslint": "^5.9.1",
|
||||
"typescript": "2.9.2",
|
||||
"typescript-formatter": "7.1.0",
|
||||
|
@ -123,7 +125,10 @@
|
|||
"vinyl": "^0.4.5",
|
||||
"vinyl-fs": "^2.4.3",
|
||||
"vsce": "1.33.2",
|
||||
"vscode-nls-dev": "3.0.7"
|
||||
"vscode-nls-dev": "3.1.0",
|
||||
"webpack": "^4.16.5",
|
||||
"webpack-cli": "^3.1.0",
|
||||
"webpack-stream": "^5.1.1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
Loading…
Reference in a new issue