share TypeScipt node_module amongst extensions

This commit is contained in:
Martin Aeschlimann 2016-11-23 16:09:58 +01:00
parent 38c5406ba4
commit 1c4e72aa68
13 changed files with 120 additions and 64320 deletions

View file

@ -6,6 +6,19 @@
const cp = require('child_process');
const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
function npmInstall(location) {
const result = cp.spawnSync(npm, ['install'], {
cwd: location ,
stdio: 'inherit'
});
if (result.error || result.status !== 0) {
process.exit(1);
}
}
npmInstall('extensions'); // node modules shared by all extensions
const extensions = [
'vscode-api-tests',
'vscode-colorize-tests',
@ -20,13 +33,4 @@ const extensions = [
'html'
];
extensions.forEach(extension => {
const result = cp.spawnSync(npm, ['install'], {
cwd: `extensions/${extension}`,
stdio: 'inherit'
});
if (result.error || result.status !== 0) {
process.exit(1);
}
});
extensions.forEach(extension => npmInstall(`extensions/${extension}`));

View file

@ -2,10 +2,5 @@
"name": "extension-editing",
"version": "0.0.1",
"dependencies": {
"typescript": {
"version": "1.8.10",
"from": "typescript@>=1.8.10 <2.0.0",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-1.8.10.tgz"
}
}
}

View file

@ -13,13 +13,9 @@
],
"main": "./out/extension",
"scripts": {
"postinstall": "node ./postinstall",
"compile": "gulp compile-extension:extension-editing",
"watch": "gulp watch-extension:extension-editing"
},
"dependencies": {
"typescript": "^1.8.10"
},
"contributes": {
"jsonValidation": [
{

View file

@ -1,23 +0,0 @@
/*---------------------------------------------------------------------------------------------
* 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 fs = require('fs');
const path = require('path');
// delete unused typescript stuff
const root = path.dirname(require.resolve('typescript'));
for (let name of fs.readdirSync(root)) {
if (name !== 'typescript.d.ts' && name !== 'typescript.js') {
try {
fs.unlinkSync(path.join(root, name));
console.log(`removed '${path.join(root, name)}'`);
} catch (e) {
console.warn(e);
}
}
}

View file

@ -9,14 +9,9 @@ import { CompletionItem, Location, SignatureHelp, SignatureInformation, Paramete
import { LanguageMode } from './languageModes';
import { getWordAtText } from '../utils/words';
import ts = require('./typescript/typescriptServices');
import { contents as libdts } from './typescript/lib-ts';
import * as ts from 'typescript';
const DEFAULT_LIB = {
NAME: 'defaultLib:lib.d.ts',
CONTENTS: libdts
};
const FILE_NAME = 'typescript://singlefile/1'; // the same 'file' is used for all contents
const FILE_NAME = 'vscode://javascript/1'; // the same 'file' is used for all contents
const JS_WORD_REGEX = /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g;
@ -33,15 +28,15 @@ export function getJavascriptMode(jsDocuments: LanguageModelCache<TextDocument>)
return '1'; // default lib is static
},
getScriptSnapshot: (fileName: string) => {
let text = fileName === FILE_NAME ? currentTextDocument.getText() : DEFAULT_LIB.CONTENTS;
let text = fileName === FILE_NAME ? currentTextDocument.getText() : ts.sys.readFile(fileName);
return {
getText: (start, end) => text.substring(start, end),
getLength: () => text.length,
getChangeRange: () => void 0
};
},
getCurrentDirectory: () => '',
getDefaultLibFileName: options => DEFAULT_LIB.NAME
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options)
};
let jsLanguageService = ts.createLanguageService(host);

View file

@ -1,6 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export declare var contents: string;

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as assert from 'assert';
import { getJavascriptMode } from '../modes/javascriptMode';
import { TextDocument, Range, TextEdit, FormattingOptions } from 'vscode-languageserver-types';
import { getLanguageModelCache } from '../languageModelCache';
import { getLanguageService } from 'vscode-html-languageservice';
import * as embeddedSupport from '../modes/embeddedSupport';
suite('HTML Javascript Support', () => {
var htmlLanguageService = getLanguageService();
function assertCompletions(value: string, expectedProposals: string[]): void {
let offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);
let document = TextDocument.create('test://test/test.html', 'html', 0, value);
let documentRegions = embeddedSupport.getDocumentRegions(htmlLanguageService, document);
let embeddedJSDocuments = getLanguageModelCache<TextDocument>(10, 60, document => documentRegions.getEmbeddedDocument('javascript'));
var mode = getJavascriptMode(embeddedJSDocuments);
let position = document.positionAt(offset);
let list = mode.doComplete(document, position);
assert.ok(list);
let actualLabels = list.items.map(c => c.label).sort();
for (let expected of expectedProposals) {
assert.ok(actualLabels.indexOf(expected) !== -1, 'Not found:' + expected + ' is ' + actualLabels.join(', '));
}
}
test('Completions', function (): any {
assertCompletions('<html><script>window.|</script></html>', ['location']);
});
});

11
extensions/npm-shrinkwrap.json generated Normal file
View file

@ -0,0 +1,11 @@
{
"name": "vscode-extensions",
"version": "0.0.1",
"dependencies": {
"typescript": {
"version": "2.0.10",
"from": "typescript@>=2.0.10 <3.0.0",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.0.10.tgz"
}
}
}

12
extensions/package.json Normal file
View file

@ -0,0 +1,12 @@
{
"name": "vscode-extensions",
"version": "0.0.1",
"private": true,
"description": "Dependencies shared by all extensions",
"dependencies": {
"typescript": "^2.0.10"
},
"scripts": {
"postinstall": "node ./postinstall"
}
}

34
extensions/postinstall.js Normal file
View file

@ -0,0 +1,34 @@
/*---------------------------------------------------------------------------------------------
* 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 fs = require('fs');
const path = require('path');
function removeFile(filePath) {
try {
fs.unlinkSync(filePath);
console.log(`removed '${filePath}'`);
} catch (e) {
console.warn(e);
}
}
// delete unused typescript stuff in lib folder
const libPath = path.dirname(require.resolve('typescript'));
for (let name of fs.readdirSync(libPath)) {
if (name !== 'typescript.d.ts' && name !== 'typescript.js' && name !== 'lib.es6.d.ts') {
removeFile(path.join(libPath, name));
}
}
// delete unused typescript stuff in bin folder
const binPath = path.join(path.dirname(libPath), 'bin');
for (let name of fs.readdirSync(binPath)) {
removeFile(path.join(binPath, name));
}
removeFile(path.join(path.dirname(libPath), 'Gulpfile.ts'));