webpack json-language-features

json
This commit is contained in:
Martin Aeschlimann
2018-08-25 20:48:56 +02:00
parent 3f8088b5c5
commit df77466bfa
11 changed files with 214 additions and 88 deletions
+35 -33
View File
@@ -44,11 +44,15 @@ function fromLocal(extensionPath, sourceMappingURLBase) {
contents: fs.createReadStream(filePath) contents: fs.createReadStream(filePath)
}); }); }); });
var filesStream = es.readArray(files); var filesStream = es.readArray(files);
// check for a webpack configuration file, then invoke webpack // check for a webpack configuration files, then invoke webpack
// and merge its output with the files stream. also rewrite the package.json // and merge its output with the files stream. also rewrite the package.json
// file to a new entry point // file to a new entry point
if (fs.existsSync(path.join(extensionPath, 'extension.webpack.config.js'))) { var pattern = path.join(extensionPath, '/**/extension.webpack.config.js');
var packageJsonFilter = filter('package.json', { restore: true }); var webpackConfigLocations = glob.sync(pattern, { ignore: ['**/node_modules'] });
if (webpackConfigLocations.length) {
//console.log('-----' + webpackConfigLocations.join(','));
//console.log('-----' + fileNames.join(','));
var packageJsonFilter = filter('**/package.json', { restore: true });
var patchFilesStream = filesStream var patchFilesStream = filesStream
.pipe(packageJsonFilter) .pipe(packageJsonFilter)
.pipe(buffer()) .pipe(buffer())
@@ -58,38 +62,36 @@ function fromLocal(extensionPath, sourceMappingURLBase) {
return data; return data;
})) }))
.pipe(packageJsonFilter.restore); .pipe(packageJsonFilter.restore);
var webpackConfig = __assign({}, require(path.join(extensionPath, 'extension.webpack.config.js')), { mode: 'production', stats: 'errors-only' }); var webpackStreams = webpackConfigLocations.map(function (webpackConfigPath) {
var webpackStream = webpackGulp(webpackConfig, webpack) var webpackConfig = __assign({}, require(webpackConfigPath), { mode: 'production', stats: 'errors-only' });
.pipe(es.through(function (data) { var relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
data.stat = data.stat || {}; var webpackBaseDir = path.dirname(webpackConfigPath);
data.base = extensionPath; return webpackGulp(webpackConfig, webpack)
this.emit('data', data); .pipe(es.through(function (data) {
})) data.stat = data.stat || {};
.pipe(es.through(function (data) { data.base = extensionPath;
// source map handling: this.emit('data', data);
// * rewrite sourceMappingURL }))
// * save to disk so that upload-task picks this up .pipe(es.through(function (data) {
if (sourceMappingURLBase) { // source map handling:
var contents = data.contents.toString('utf8'); // * rewrite sourceMappingURL
data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) { // * save to disk so that upload-task picks this up
return "\n//# sourceMappingURL=" + sourceMappingURLBase + "/extensions/" + path.basename(extensionPath) + "/dist/" + g1; if (sourceMappingURLBase) {
}), 'utf8'); var contents = data.contents.toString('utf8');
if (/\.js\.map$/.test(data.path)) { data.contents = Buffer.from(contents.replace(/\n\/\/# sourceMappingURL=(.*)$/gm, function (_m, g1) {
if (!fs.existsSync(path.dirname(data.path))) { return "\n//# sourceMappingURL=" + sourceMappingURLBase + "/extensions/" + path.basename(extensionPath) + "/" + relativeOutputPath + "/" + g1;
fs.mkdirSync(path.dirname(data.path)); }), '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);
} }
fs.writeFileSync(data.path, data.contents);
} }
} this.emit('data', data);
this.emit('data', data); }));
})); });
es.merge(webpackStream, patchFilesStream) es.merge.apply(es, webpackStreams.concat([patchFilesStream])).pipe(result);
// .pipe(es.through(function (data) {
// // debug
// console.log('out', data.path, data.contents.length);
// this.emit('data', data);
// }))
.pipe(result);
} }
else { else {
filesStream.pipe(result); filesStream.pipe(result);
+40 -31
View File
@@ -41,11 +41,16 @@ export function fromLocal(extensionPath: string, sourceMappingURLBase?: string):
const filesStream = es.readArray(files); const filesStream = es.readArray(files);
// check for a webpack configuration file, then invoke webpack // check for a webpack configuration files, then invoke webpack
// and merge its output with the files stream. also rewrite the package.json // and merge its output with the files stream. also rewrite the package.json
// file to a new entry point // file to a new entry point
if (fs.existsSync(path.join(extensionPath, 'extension.webpack.config.js'))) { const pattern = path.join(extensionPath, '/**/extension.webpack.config.js');
const packageJsonFilter = filter('package.json', { restore: true }); const webpackConfigLocations = (<string[]>glob.sync(pattern, { ignore: ['**/node_modules'] }));
if (webpackConfigLocations.length) {
//console.log('-----' + webpackConfigLocations.join(','));
//console.log('-----' + fileNames.join(','));
const packageJsonFilter = filter('**/package.json', { restore: true });
const patchFilesStream = filesStream const patchFilesStream = filesStream
.pipe(packageJsonFilter) .pipe(packageJsonFilter)
@@ -57,38 +62,42 @@ export function fromLocal(extensionPath: string, sourceMappingURLBase?: string):
})) }))
.pipe(packageJsonFilter.restore); .pipe(packageJsonFilter.restore);
const webpackConfig = { const webpackStreams = webpackConfigLocations.map(webpackConfigPath => {
...require(path.join(extensionPath, 'extension.webpack.config.js')), const webpackConfig = {
...{ mode: 'production', stats: 'errors-only' } ...require(webpackConfigPath),
}; ...{ mode: 'production', stats: 'errors-only' }
const webpackStream = webpackGulp(webpackConfig, webpack) };
.pipe(es.through(function (data) { let relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
data.stat = data.stat || {}; let webpackBaseDir = path.dirname(webpackConfigPath);
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)) { return webpackGulp(webpackConfig, webpack)
if (!fs.existsSync(path.dirname(data.path))) { .pipe(es.through(function (data) {
fs.mkdirSync(path.dirname(data.path)); 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)}/${relativeOutputPath}/${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);
} }
fs.writeFileSync(data.path, data.contents);
} }
} this.emit('data', data);
this.emit('data', data); }));
})) });
;
es.merge(webpackStream, patchFilesStream) es.merge(...webpackStreams, patchFilesStream)
// .pipe(es.through(function (data) { // .pipe(es.through(function (data) {
// // debug // // debug
// console.log('out', data.path, data.contents.length); // console.log('out', data.path, data.contents.length);
@@ -1,11 +1,26 @@
test/**
.vscode/** .vscode/**
client/tsconfig.json server/.vscode/**
node_modules/**
server/node_modules/**
client/src/** client/src/**
server/bin
server/tsconfig.json
server/src/** server/src/**
client/out/**
server/out/**
client/tsconfig.json
server/tsconfig.json
server/test/** server/test/**
server/node_modules/@types/** server/bin/**
**/node_modules/*/lib/esm/** server/build/**
**/node_modules/@types/** server/yarn.lock
server/.npmignore
yarn.lock
server/extension.webpack.config.js
extension.webpack.config.js
!node_modules/vscode-nls/**
!node_modules/applicationinsights/**
!node_modules/diagnostic-channel-publishers/**
!node_modules/diagnostic-channel/**
!node_modules/semver/**
!node_modules/vscode-extension-telemetry/**
!node_modules/zone.js/**
!server/node_modules/vscode-nls/**
@@ -5,6 +5,7 @@
'use strict'; 'use strict';
import * as path from 'path'; import * as path from 'path';
import * as fs from 'fs';
import * as nls from 'vscode-nls'; import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle(); const localize = nls.loadMessageBundle();
@@ -62,8 +63,9 @@ export function activate(context: ExtensionContext) {
let packageInfo = getPackageInfo(context); let packageInfo = getPackageInfo(context);
telemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey); telemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
// The server is implemented in node let serverMain = readJSONFile(context.asAbsolutePath('./server/package.json')).main;
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'jsonServerMain.js')); let serverModule = context.asAbsolutePath(path.join('server', serverMain));
// The debug options for the server // The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--inspect=' + (9000 + Math.round(Math.random() * 10000))] }; let debugOptions = { execArgv: ['--nolazy', '--inspect=' + (9000 + Math.round(Math.random() * 10000))] };
@@ -259,7 +261,7 @@ function getSchemaId(schema: JSONSchemaSettings, rootPath?: string) {
} }
function getPackageInfo(context: ExtensionContext): IPackageInfo | undefined { function getPackageInfo(context: ExtensionContext): IPackageInfo | undefined {
let extensionPackage = require(context.asAbsolutePath('./package.json')); let extensionPackage = readJSONFile(context.asAbsolutePath('./package.json'));
if (extensionPackage) { if (extensionPackage) {
return { return {
name: extensionPackage.name, name: extensionPackage.name,
@@ -269,3 +271,13 @@ function getPackageInfo(context: ExtensionContext): IPackageInfo | undefined {
} }
return void 0; return void 0;
} }
function readJSONFile(location: string) {
try {
return JSON.parse(fs.readFileSync(location).toString());
} catch (e) {
console.log(`Problems reading ${location}: ${e}`);
return {};
}
}
@@ -0,0 +1,40 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
'use strict';
const withDefaults = require('../shared.webpack.config');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
module.exports = withDefaults({
context: path.join(__dirname, 'client'),
entry: {
extension: './src/jsonMain.ts',
},
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'] // support ts-files and js-files
},
node: {
__dirname: false // leave the __dirname-behaviour intact
},
output: {
filename: 'jsonMain.js',
path: path.join(__dirname, 'client', 'dist'),
libraryTarget: "commonjs",
},
externals: {
'./files': 'commonjs', // ignored because it doesn't exist
},
plugins: [
new CopyWebpackPlugin([
{ from: './out/*.sh', to: '[name].sh' },
{ from: './out/nls.*.json', to: '[name].json' }
])
]
});
@@ -101,7 +101,7 @@
}, },
"dependencies": { "dependencies": {
"vscode-extension-telemetry": "0.0.18", "vscode-extension-telemetry": "0.0.18",
"vscode-languageclient": "^4.4.2", "vscode-languageclient": "^5.1.0-next.4",
"vscode-nls": "^3.2.4" "vscode-nls": "^3.2.4"
}, },
"devDependencies": { "devDependencies": {
@@ -0,0 +1,5 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
module.exports = {};
@@ -0,0 +1,38 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
'use strict';
const withDefaults = require('../../shared.webpack.config');
const path = require('path');
var webpack = require('webpack');
module.exports = withDefaults({
context: path.join(__dirname),
entry: {
extension: './src/jsonServerMain.ts',
},
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'] // support ts-files and js-files
},
node: {
__dirname: false // leave the __dirname-behaviour intact
},
output: {
filename: 'jsonServerMain.js',
path: path.join(__dirname, 'dist'),
libraryTarget: "commonjs",
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
/\/vscode-languageserver\/lib\/files\.js/,
require.resolve('./build/files')
),
new webpack.IgnorePlugin(/vertx/)
],
});
@@ -10,11 +10,12 @@
"bin": { "bin": {
"vscode-json-languageserver": "./bin/vscode-json-languageserver" "vscode-json-languageserver": "./bin/vscode-json-languageserver"
}, },
"main": "./dist/jsonServerMain",
"dependencies": { "dependencies": {
"jsonc-parser": "^2.0.1", "jsonc-parser": "^2.0.1",
"request-light": "^0.2.3", "request-light": "^0.2.3",
"vscode-json-languageservice": "^3.1.5", "vscode-json-languageservice": "^3.1.5",
"vscode-languageserver": "^4.4.2", "vscode-languageserver": "^5.1.0-next.3",
"vscode-nls": "^3.2.4", "vscode-nls": "^3.2.4",
"vscode-uri": "^1.0.5" "vscode-uri": "^1.0.5"
}, },
@@ -34,4 +35,4 @@
"install-server-local": "yarn link vscode-languageserver-server", "install-server-local": "yarn link vscode-languageserver-server",
"version": "git commit -m \"JSON Language Server $npm_package_version\" package.json" "version": "git commit -m \"JSON Language Server $npm_package_version\" package.json"
} }
} }
@@ -75,22 +75,26 @@ vscode-jsonrpc@^3.6.2:
version "3.6.2" version "3.6.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8" resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8"
vscode-languageserver-protocol@^3.10.3: vscode-languageserver-protocol@^3.12.0:
version "3.10.3" version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.10.3.tgz#59841c9602a6a6baab68613c2a47760994657196" resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.12.0.tgz#5b23501292abad88f0463b01e83ff98e64a37652"
dependencies: dependencies:
vscode-jsonrpc "^3.6.2" vscode-jsonrpc "^3.6.2"
vscode-languageserver-types "^3.10.1" vscode-languageserver-types "^3.12.0"
vscode-languageserver-types@^3.10.1: vscode-languageserver-types@^3.10.1:
version "3.10.1" version "3.10.1"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.10.1.tgz#d5d5f44f688a3b2aa9857dc53cb9cacca73fe35a" resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.10.1.tgz#d5d5f44f688a3b2aa9857dc53cb9cacca73fe35a"
vscode-languageserver@^4.4.2: vscode-languageserver-types@^3.12.0:
version "4.4.2" version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-4.4.2.tgz#600ae9cc7a6ff1e84d93c7807840c2cb5b22821b" resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.12.0.tgz#f96051381b6a050b7175b37d6cb5d2f2eb64b944"
vscode-languageserver@^5.1.0-next.3:
version "5.1.0-next.3"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-5.1.0-next.3.tgz#352ce1f0f8bdfc47c1236277ebe865e25b087ccd"
dependencies: dependencies:
vscode-languageserver-protocol "^3.10.3" vscode-languageserver-protocol "^3.12.0"
vscode-uri "^1.0.5" vscode-uri "^1.0.5"
vscode-nls@^3.2.2, vscode-nls@^3.2.4: vscode-nls@^3.2.2, vscode-nls@^3.2.4:
+3 -3
View File
@@ -38,9 +38,9 @@ vscode-jsonrpc@^3.6.2:
version "3.6.2" version "3.6.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8" resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8"
vscode-languageclient@^4.4.2: vscode-languageclient@^5.1.0-next.4:
version "4.4.2" version "5.1.0-next.4"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-4.4.2.tgz#a341a7b4ac403e481f011ed4572854646e8968c4" resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-5.1.0-next.4.tgz#2f96b4aa198c45f3e897b7f330c597a401ca95f2"
dependencies: dependencies:
vscode-languageserver-protocol "^3.10.3" vscode-languageserver-protocol "^3.10.3"