Merge pull request #57257 from Microsoft/aeschli/webpack2

Aeschli/webpack2
This commit is contained in:
Martin Aeschlimann 2018-08-27 14:48:06 +02:00 committed by GitHub
commit f707828426
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 552 additions and 182 deletions

View file

@ -44,11 +44,20 @@ function fromLocal(extensionPath, sourceMappingURLBase) {
contents: fs.createReadStream(filePath)
}); });
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
// file to a new entry point
if (fs.existsSync(path.join(extensionPath, 'extension.webpack.config.js'))) {
var packageJsonFilter = filter('package.json', { restore: true });
var pattern = path.join(extensionPath, '/**/extension.webpack.config.js');
var webpackConfigLocations = glob.sync(pattern, { ignore: ['**/node_modules'] });
if (webpackConfigLocations.length) {
var packageJsonFilter = filter(function (f) {
if (path.basename(f.path) === 'package.json') {
// only modify package.json's next to the webpack file.
// to be safe, use existsSync instead of path comparison.
return fs.existsSync(path.join(path.dirname(f.path), 'extension.webpack.config.js'));
}
return false;
}, { restore: true });
var patchFilesStream = filesStream
.pipe(packageJsonFilter)
.pipe(buffer())
@ -58,38 +67,36 @@ function fromLocal(extensionPath, sourceMappingURLBase) {
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));
var webpackStreams = webpackConfigLocations.map(function (webpackConfigPath) {
var webpackConfig = __assign({}, require(webpackConfigPath), { mode: 'production', stats: 'errors-only' });
var relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
var webpackBaseDir = path.dirname(webpackConfigPath);
return 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) + "/" + 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);
}));
es.merge(webpackStream, patchFilesStream)
// .pipe(es.through(function (data) {
// // debug
// console.log('out', data.path, data.contents.length);
// this.emit('data', data);
// }))
.pipe(result);
this.emit('data', data);
}));
});
es.merge.apply(es, webpackStreams.concat([patchFilesStream])).pipe(result);
}
else {
filesStream.pipe(result);

View file

@ -41,11 +41,21 @@ export function fromLocal(extensionPath: string, sourceMappingURLBase?: string):
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
// file to a new entry point
if (fs.existsSync(path.join(extensionPath, 'extension.webpack.config.js'))) {
const packageJsonFilter = filter('package.json', { restore: true });
const pattern = path.join(extensionPath, '/**/extension.webpack.config.js');
const webpackConfigLocations = (<string[]>glob.sync(pattern, { ignore: ['**/node_modules'] }));
if (webpackConfigLocations.length) {
const packageJsonFilter = filter(f => {
if (path.basename(f.path) === 'package.json') {
// only modify package.json's next to the webpack file.
// to be safe, use existsSync instead of path comparison.
return fs.existsSync(path.join(path.dirname(f.path), 'extension.webpack.config.js'));
}
return false;
}, { restore: true });
const patchFilesStream = filesStream
.pipe(packageJsonFilter)
@ -57,38 +67,42 @@ export function fromLocal(extensionPath: string, sourceMappingURLBase?: string):
}))
.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');
const webpackStreams = webpackConfigLocations.map(webpackConfigPath => {
const webpackConfig = {
...require(webpackConfigPath),
...{ mode: 'production', stats: 'errors-only' }
};
let relativeOutputPath = path.relative(extensionPath, webpackConfig.output.path);
let webpackBaseDir = path.dirname(webpackConfigPath);
if (/\.js\.map$/.test(data.path)) {
if (!fs.existsSync(path.dirname(data.path))) {
fs.mkdirSync(path.dirname(data.path));
return 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)}/${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) {
// // debug
// console.log('out', data.path, data.contents.length);

View file

@ -1,11 +1,21 @@
test/**
.vscode/**
client/src/**
client/tsconfig.json
server/src/**
server/test/**
server/out/test/**
server/.vscode/**
node_modules/**
server/node_modules/**
client/src/**
server/src/**
client/out/**
server/out/**
client/tsconfig.json
server/tsconfig.json
**/node_modules/@types/**
**/node_modules/*/lib/esm/**
server/test/**
server/bin/**
server/build/**
server/yarn.lock
server/.npmignore
yarn.lock
server/extension.webpack.config.js
extension.webpack.config.js
!node_modules/vscode-nls/**
!server/node_modules/vscode-nls/**

View file

@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as path from 'path';
import * as fs from 'fs';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
@ -14,8 +15,9 @@ import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Di
// this method is called when vs code is activated
export function activate(context: ExtensionContext) {
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'cssServerMain.js'));
let serverMain = readJSONFile(context.asAbsolutePath('./server/package.json')).main;
let serverModule = context.asAbsolutePath(path.join('server', serverMain));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--inspect=6044'] };
@ -120,3 +122,12 @@ export function activate(context: ExtensionContext) {
}
}
function readJSONFile(location: string) {
try {
return JSON.parse(fs.readFileSync(location).toString());
} catch (e) {
console.log(`Problems reading ${location}: ${e}`);
return {};
}
}

View file

@ -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/cssMain.ts',
},
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'] // support ts-files and js-files
},
node: {
__dirname: false // leave the __dirname-behaviour intact
},
output: {
filename: 'cssMain.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' }
])
]
});

View file

@ -708,7 +708,7 @@
]
},
"dependencies": {
"vscode-languageclient": "^4.4.0",
"vscode-languageclient": "^5.1.0-next.4",
"vscode-nls": "^3.2.4"
},
"devDependencies": {

View file

@ -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 = {};

View file

@ -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/cssServerMain.ts',
},
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'] // support ts-files and js-files
},
node: {
__dirname: false // leave the __dirname-behaviour intact
},
output: {
filename: 'cssServerMain.js',
path: path.join(__dirname, 'dist'),
libraryTarget: "commonjs",
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
/\/vscode-languageserver\/lib\/files\.js/,
require.resolve('./build/filesFillIn')
),
new webpack.IgnorePlugin(/vertx/)
],
});

View file

@ -7,9 +7,10 @@
"engines": {
"node": "*"
},
"main": "./out/cssServerMain",
"dependencies": {
"vscode-css-languageservice": "^3.0.10-next.3",
"vscode-languageserver": "^4.4.0"
"vscode-languageserver": "^5.1.0-next.3"
},
"devDependencies": {
"@types/mocha": "2.2.33",
@ -28,4 +29,4 @@
"install-server-local": "npm install ../../../../vscode-languageserver-node/server -f",
"test": "../../../node_modules/.bin/mocha"
}
}
}

View file

@ -100,16 +100,19 @@ function stripQuotes(fullValue: string) {
* Get a list of path suggestions. Folder suggestions are suffixed with a slash.
*/
function providePaths(valueBeforeCursor: string, activeDocFsPath: string, root?: string): string[] {
if (startsWith(valueBeforeCursor, '/') && !root) {
return [];
}
const lastIndexOfSlash = valueBeforeCursor.lastIndexOf('/');
const valueBeforeLastSlash = valueBeforeCursor.slice(0, lastIndexOfSlash + 1);
const parentDir = startsWith(valueBeforeCursor, '/')
? path.resolve(root, '.' + valueBeforeLastSlash)
: path.resolve(activeDocFsPath, '..', valueBeforeLastSlash);
const startsWithSlash = startsWith(valueBeforeCursor, '/');
let parentDir: string;
if (startsWithSlash) {
if (!root) {
return [];
}
parentDir = path.resolve(root, '.' + valueBeforeLastSlash);
} else {
parentDir = path.resolve(activeDocFsPath, '..', valueBeforeLastSlash);
}
try {
return fs.readdirSync(parentDir).map(f => {

View file

@ -205,35 +205,35 @@ vscode-jsonrpc@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8"
vscode-languageserver-protocol@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.10.0.tgz#f8dcdf987687f64a26e7c32d498fc781a0e886dc"
vscode-languageserver-protocol@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.12.0.tgz#5b23501292abad88f0463b01e83ff98e64a37652"
dependencies:
vscode-jsonrpc "^3.6.2"
vscode-languageserver-types "^3.10.0"
vscode-languageserver-types@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.10.0.tgz#944e5308f3b36a3f372c766f1a344e903ec9c389"
vscode-languageserver-types "^3.12.0"
vscode-languageserver-types@^3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.10.1.tgz#d5d5f44f688a3b2aa9857dc53cb9cacca73fe35a"
vscode-languageserver@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-4.4.0.tgz#b6e8b37a739ccb629d92f3635f0099d191c856fa"
vscode-languageserver-types@^3.12.0:
version "3.12.0"
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:
vscode-languageserver-protocol "^3.10.0"
vscode-uri "^1.0.3"
vscode-languageserver-protocol "^3.12.0"
vscode-uri "^1.0.5"
vscode-nls@^3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-3.2.4.tgz#2166b4183c8aea884d20727f5449e62be69fd398"
vscode-uri@^1.0.3:
version "1.0.5"
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-1.0.5.tgz#3b899a8ef71c37f3054d79bdbdda31c7bf36f20d"
vscode-uri@^1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-1.0.6.tgz#6b8f141b0bbc44ad7b07e94f82f168ac7608ad4d"
wrappy@1:
version "1.0.2"

View file

@ -127,6 +127,10 @@ path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
semver@^5.5.0:
version "5.5.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477"
supports-color@5.4.0:
version "5.4.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.4.0.tgz#1c6b337402c2137605efe19f10fec390f6faab54"
@ -137,22 +141,23 @@ vscode-jsonrpc@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8"
vscode-languageclient@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-4.4.0.tgz#b05868f6477b6f0c9910b24daae4f3e8c4b65902"
vscode-languageclient@^5.1.0-next.4:
version "5.1.0-next.4"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-5.1.0-next.4.tgz#2f96b4aa198c45f3e897b7f330c597a401ca95f2"
dependencies:
vscode-languageserver-protocol "^3.10.0"
semver "^5.5.0"
vscode-languageserver-protocol "^3.12.0"
vscode-languageserver-protocol@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.10.0.tgz#f8dcdf987687f64a26e7c32d498fc781a0e886dc"
vscode-languageserver-protocol@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.12.0.tgz#5b23501292abad88f0463b01e83ff98e64a37652"
dependencies:
vscode-jsonrpc "^3.6.2"
vscode-languageserver-types "^3.10.0"
vscode-languageserver-types "^3.12.0"
vscode-languageserver-types@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.10.0.tgz#944e5308f3b36a3f372c766f1a344e903ec9c389"
vscode-languageserver-types@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.12.0.tgz#f96051381b6a050b7175b37d6cb5d2f2eb64b944"
vscode-nls@^3.2.4:
version "3.2.4"

View file

@ -1,10 +1,27 @@
test/**
.vscode/**
server/tsconfig.json
server/src/**
server/test/**
server/out/test/**
client/tsconfig.json
server/.vscode/**
node_modules/**
server/node_modules/**
client/src/**
**/node_modules/*/lib/esm/**
**/node_modules/@types/**
server/src/**
client/out/**
server/out/**
client/tsconfig.json
server/tsconfig.json
server/test/**
server/bin/**
server/build/**
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/**

View file

@ -5,6 +5,7 @@
'use strict';
import * as path from 'path';
import * as fs from 'fs';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
@ -33,8 +34,9 @@ export function activate(context: ExtensionContext) {
let packageInfo = getPackageInfo(context);
telemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'htmlServerMain.js'));
let serverMain = readJSONFile(context.asAbsolutePath('./server/package.json')).main;
let serverModule = context.asAbsolutePath(path.join('server', serverMain));
// The debug options for the server
let debugOptions = { execArgv: ['--nolazy', '--inspect=6045'] };
@ -157,7 +159,7 @@ export function activate(context: ExtensionContext) {
}
function getPackageInfo(context: ExtensionContext): IPackageInfo | null {
let extensionPackage = require(context.asAbsolutePath('./package.json'));
let extensionPackage = readJSONFile(context.asAbsolutePath('./package.json'));
if (extensionPackage) {
return {
name: extensionPackage.name,
@ -168,6 +170,16 @@ function getPackageInfo(context: ExtensionContext): IPackageInfo | null {
return null;
}
function readJSONFile(location: string) {
try {
return JSON.parse(fs.readFileSync(location).toString());
} catch (e) {
console.log(`Problems reading ${location}: ${e}`);
return {};
}
}
export function deactivate(): Promise<any> {
return telemetryReporter ? telemetryReporter.dispose() : Promise.resolve(null);
}

View file

@ -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/htmlMain.ts',
},
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'] // support ts-files and js-files
},
node: {
__dirname: false // leave the __dirname-behaviour intact
},
output: {
filename: 'htmlMain.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' }
])
]
});

View file

@ -174,10 +174,10 @@
},
"dependencies": {
"vscode-extension-telemetry": "0.0.18",
"vscode-languageclient": "^4.4.0",
"vscode-languageclient": "^5.1.0-next.4",
"vscode-nls": "^3.2.4"
},
"devDependencies": {
"@types/node": "^8.10.25"
}
}
}

View file

@ -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 = {};

View file

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------------------------
* 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/htmlServerMain.ts',
},
resolve: {
mainFields: ['module', 'main'],
extensions: ['.ts', '.js'] // support ts-files and js-files
},
node: {
__dirname: false // leave the __dirname-behaviour intact
},
output: {
filename: 'htmlServerMain.js',
path: path.join(__dirname, 'dist'),
libraryTarget: "commonjs",
},
externals: {
'typescript': 'commonjs typescript',
"vscode-nls": 'commonjs vscode-nls',
},
plugins: [
new webpack.NormalModuleReplacementPlugin(
/\/vscode-languageserver\/lib\/files\.js/,
require.resolve('./build/filesFillIn')
),
new webpack.IgnorePlugin(/vertx/)
],
});

View file

@ -7,10 +7,11 @@
"engines": {
"node": "*"
},
"main": "./out/htmlServerMain",
"dependencies": {
"vscode-css-languageservice": "^3.0.9",
"vscode-html-languageservice": "^2.1.3",
"vscode-languageserver": "^4.4.0",
"vscode-languageserver": "^5.1.0-next.3",
"vscode-languageserver-types": "^3.10.0",
"vscode-nls": "^3.2.4",
"vscode-uri": "^1.0.5"
@ -32,4 +33,4 @@
"install-server-local": "npm install ../../../../vscode-languageserver-node/server -f",
"test": "npm run compile && ../../../node_modules/.bin/mocha"
}
}
}

View file

@ -63,16 +63,19 @@ function shouldDoPathCompletion(tag: string, attr: string, value: string) {
* Get a list of path suggestions. Folder suggestions are suffixed with a slash.
*/
function providePaths(valueBeforeCursor: string, activeDocFsPath: string, root?: string): string[] {
if (startsWith(valueBeforeCursor, '/') && !root) {
return [];
}
const lastIndexOfSlash = valueBeforeCursor.lastIndexOf('/');
const valueBeforeLastSlash = valueBeforeCursor.slice(0, lastIndexOfSlash + 1);
const parentDir = startsWith(valueBeforeCursor, '/')
? path.resolve(root, '.' + valueBeforeLastSlash)
: path.resolve(activeDocFsPath, '..', valueBeforeLastSlash);
const startsWithSlash = startsWith(valueBeforeCursor, '/');
let parentDir: string;
if (startsWithSlash) {
if (!root) {
return [];
}
parentDir = path.resolve(root, '.' + valueBeforeLastSlash);
} else {
parentDir = path.resolve(activeDocFsPath, '..', valueBeforeLastSlash);
}
try {
return fs.readdirSync(parentDir).map(f => {

View file

@ -213,32 +213,32 @@ vscode-jsonrpc@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8"
vscode-languageserver-protocol@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.10.0.tgz#f8dcdf987687f64a26e7c32d498fc781a0e886dc"
vscode-languageserver-protocol@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.12.0.tgz#5b23501292abad88f0463b01e83ff98e64a37652"
dependencies:
vscode-jsonrpc "^3.6.2"
vscode-languageserver-types "^3.10.0"
vscode-languageserver-types "^3.12.0"
vscode-languageserver-types@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.10.0.tgz#944e5308f3b36a3f372c766f1a344e903ec9c389"
vscode-languageserver@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-4.4.0.tgz#b6e8b37a739ccb629d92f3635f0099d191c856fa"
vscode-languageserver-types@^3.12.0:
version "3.12.0"
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:
vscode-languageserver-protocol "^3.10.0"
vscode-uri "^1.0.3"
vscode-languageserver-protocol "^3.12.0"
vscode-uri "^1.0.5"
vscode-nls@^3.2.4:
version "3.2.4"
resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-3.2.4.tgz#2166b4183c8aea884d20727f5449e62be69fd398"
vscode-uri@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-1.0.3.tgz#631bdbf716dccab0e65291a8dc25c23232085a52"
vscode-uri@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/vscode-uri/-/vscode-uri-1.0.5.tgz#3b899a8ef71c37f3054d79bdbdda31c7bf36f20d"

View file

@ -24,9 +24,9 @@ diagnostic-channel@0.2.0:
dependencies:
semver "^5.3.0"
semver@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"
semver@^5.3.0, semver@^5.5.0:
version "5.5.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.1.tgz#7dfdd8814bdb7cabc7be0fb1d734cfb66c940477"
vscode-extension-telemetry@0.0.18:
version "0.0.18"
@ -38,22 +38,23 @@ vscode-jsonrpc@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8"
vscode-languageclient@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-4.4.0.tgz#b05868f6477b6f0c9910b24daae4f3e8c4b65902"
vscode-languageclient@^5.1.0-next.4:
version "5.1.0-next.4"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-5.1.0-next.4.tgz#2f96b4aa198c45f3e897b7f330c597a401ca95f2"
dependencies:
vscode-languageserver-protocol "^3.10.0"
semver "^5.5.0"
vscode-languageserver-protocol "^3.12.0"
vscode-languageserver-protocol@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.10.0.tgz#f8dcdf987687f64a26e7c32d498fc781a0e886dc"
vscode-languageserver-protocol@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.12.0.tgz#5b23501292abad88f0463b01e83ff98e64a37652"
dependencies:
vscode-jsonrpc "^3.6.2"
vscode-languageserver-types "^3.10.0"
vscode-languageserver-types "^3.12.0"
vscode-languageserver-types@^3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.10.0.tgz#944e5308f3b36a3f372c766f1a344e903ec9c389"
vscode-languageserver-types@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.12.0.tgz#f96051381b6a050b7175b37d6cb5d2f2eb64b944"
vscode-nls@^3.2.4:
version "3.2.4"

View file

@ -1,11 +1,26 @@
test/**
.vscode/**
client/tsconfig.json
server/.vscode/**
node_modules/**
server/node_modules/**
client/src/**
server/bin
server/tsconfig.json
server/src/**
client/out/**
server/out/**
client/tsconfig.json
server/tsconfig.json
server/test/**
server/node_modules/@types/**
**/node_modules/*/lib/esm/**
**/node_modules/@types/**
server/bin/**
server/build/**
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/**

View file

@ -5,6 +5,7 @@
'use strict';
import * as path from 'path';
import * as fs from 'fs';
import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
@ -62,8 +63,9 @@ export function activate(context: ExtensionContext) {
let packageInfo = getPackageInfo(context);
telemetryReporter = packageInfo && new TelemetryReporter(packageInfo.name, packageInfo.version, packageInfo.aiKey);
// The server is implemented in node
let serverModule = context.asAbsolutePath(path.join('server', 'out', 'jsonServerMain.js'));
let serverMain = readJSONFile(context.asAbsolutePath('./server/package.json')).main;
let serverModule = context.asAbsolutePath(path.join('server', serverMain));
// The debug options for the server
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 {
let extensionPackage = require(context.asAbsolutePath('./package.json'));
let extensionPackage = readJSONFile(context.asAbsolutePath('./package.json'));
if (extensionPackage) {
return {
name: extensionPackage.name,
@ -269,3 +271,13 @@ function getPackageInfo(context: ExtensionContext): IPackageInfo | undefined {
}
return void 0;
}
function readJSONFile(location: string) {
try {
return JSON.parse(fs.readFileSync(location).toString());
} catch (e) {
console.log(`Problems reading ${location}: ${e}`);
return {};
}
}

View file

@ -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' }
])
]
});

View file

@ -101,7 +101,7 @@
},
"dependencies": {
"vscode-extension-telemetry": "0.0.18",
"vscode-languageclient": "^4.4.2",
"vscode-languageclient": "^5.1.0-next.4",
"vscode-nls": "^3.2.4"
},
"devDependencies": {

View file

@ -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 = {};

View file

@ -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/)
],
});

View file

@ -10,11 +10,12 @@
"bin": {
"vscode-json-languageserver": "./bin/vscode-json-languageserver"
},
"main": "./dist/jsonServerMain",
"dependencies": {
"jsonc-parser": "^2.0.1",
"request-light": "^0.2.3",
"vscode-json-languageservice": "^3.1.5",
"vscode-languageserver": "^4.4.2",
"vscode-languageserver": "^5.1.0-next.3",
"vscode-nls": "^3.2.4",
"vscode-uri": "^1.0.5"
},
@ -34,4 +35,4 @@
"install-server-local": "yarn link vscode-languageserver-server",
"version": "git commit -m \"JSON Language Server $npm_package_version\" package.json"
}
}
}

View file

@ -75,22 +75,26 @@ vscode-jsonrpc@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8"
vscode-languageserver-protocol@^3.10.3:
version "3.10.3"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.10.3.tgz#59841c9602a6a6baab68613c2a47760994657196"
vscode-languageserver-protocol@^3.12.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/vscode-languageserver-protocol/-/vscode-languageserver-protocol-3.12.0.tgz#5b23501292abad88f0463b01e83ff98e64a37652"
dependencies:
vscode-jsonrpc "^3.6.2"
vscode-languageserver-types "^3.10.1"
vscode-languageserver-types "^3.12.0"
vscode-languageserver-types@^3.10.1:
version "3.10.1"
resolved "https://registry.yarnpkg.com/vscode-languageserver-types/-/vscode-languageserver-types-3.10.1.tgz#d5d5f44f688a3b2aa9857dc53cb9cacca73fe35a"
vscode-languageserver@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/vscode-languageserver/-/vscode-languageserver-4.4.2.tgz#600ae9cc7a6ff1e84d93c7807840c2cb5b22821b"
vscode-languageserver-types@^3.12.0:
version "3.12.0"
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:
vscode-languageserver-protocol "^3.10.3"
vscode-languageserver-protocol "^3.12.0"
vscode-uri "^1.0.5"
vscode-nls@^3.2.2, vscode-nls@^3.2.4:

View file

@ -38,9 +38,9 @@ vscode-jsonrpc@^3.6.2:
version "3.6.2"
resolved "https://registry.yarnpkg.com/vscode-jsonrpc/-/vscode-jsonrpc-3.6.2.tgz#3b5eef691159a15556ecc500e9a8a0dd143470c8"
vscode-languageclient@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-4.4.2.tgz#a341a7b4ac403e481f011ed4572854646e8968c4"
vscode-languageclient@^5.1.0-next.4:
version "5.1.0-next.4"
resolved "https://registry.yarnpkg.com/vscode-languageclient/-/vscode-languageclient-5.1.0-next.4.tgz#2f96b4aa198c45f3e897b7f330c597a401ca95f2"
dependencies:
vscode-languageserver-protocol "^3.10.3"