提交 09ec2eb1 编写于 作者: A Alex Dima

Use the new optimize-editor task

上级 5a52c24f
......@@ -13,6 +13,8 @@ const i18n = require('./lib/i18n');
const standalone = require('./lib/standalone');
const cp = require('child_process');
const compilation = require('./lib/compilation');
const monacoapi = require('./monaco/api');
const fs = require('fs');
var root = path.dirname(__dirname);
var sha1 = util.getVersion(root);
......@@ -59,33 +61,23 @@ var BUNDLED_FILE_HEADER = [
''
].join('\n');
function editorLoaderConfig() {
var result = common.loaderConfig();
// never ship octicons in editor
result.paths['vs/base/browser/ui/octiconLabel/octiconLabel'] = 'out-build/vs/base/browser/ui/octiconLabel/octiconLabel.mock';
// force css inlining to use base64 -- see https://github.com/Microsoft/monaco-editor/issues/148
result['vs/css'] = {
inlineResources: 'base64',
inlineResourcesLimit: 3000 // see https://github.com/Microsoft/monaco-editor/issues/336
};
return result;
}
const languages = i18n.defaultLanguages.concat([]); // i18n.defaultLanguages.concat(process.env.VSCODE_QUALITY !== 'stable' ? i18n.extraLanguages : []);
gulp.task('clean-editor-src', util.rimraf('out-editor-src'));
gulp.task('extract-editor-src', ['clean-editor-src'], function() {
gulp.task('extract-editor-src', ['clean-editor-src'], function () {
console.log(`If the build fails, consider tweaking shakeLevel below to a lower value.`);
const apiusages = monacoapi.execute().usageContent;
const extrausages = fs.readFileSync(path.join(root, 'build', 'monaco', 'monaco.usage.recipe')).toString();
standalone.extractEditor({
sourcesRoot: path.join(root, 'src'),
entryPoints: [
'vs/editor/editor.main',
'vs/editor/editor.worker',
'vs/base/worker/workerMain',
// 'user',
// 'user2',
],
inlineEntryPoints: [
apiusages,
extrausages
],
libs: [
`lib.d.ts`,
......@@ -96,33 +88,19 @@ gulp.task('extract-editor-src', ['clean-editor-src'], function() {
},
compilerOptions: {
module: 2, // ModuleKind.AMD
// moduleResolution: 'classic'
},
shakeLevel: 1, // 1-InnerFile, 2-ClassMembers
shakeLevel: 2, // 0-Files, 1-InnerFile, 2-ClassMembers
importIgnorePattern: /^vs\/css!/,
destRoot: path.join(root, 'out-editor-src')
});
});
gulp.task('clean-optimized-editor', util.rimraf('out-editor'));
gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-client-build'], common.optimizeTask({
src: 'out-build',
entryPoints: editorEntryPoints,
otherSources: editorOtherSources,
resources: editorResources,
loaderConfig: editorLoaderConfig(),
bundleLoader: false,
header: BUNDLED_FILE_HEADER,
bundleInfo: true,
out: 'out-editor',
languages: languages
}));
// Full compile, including nls and inline sources in sourcemaps, for build
gulp.task('clean-editor-build', util.rimraf('out-editor-build'));
gulp.task('compile-editor-build', ['clean-editor-build', 'extract-editor-src'], compilation.compileTask('out-editor-src', 'out-editor-build', true));
gulp.task('optimize-editor2', ['clean-optimized-editor', 'compile-editor-build'], common.optimizeTask({
gulp.task('clean-optimized-editor', util.rimraf('out-editor'));
gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-editor-build'], common.optimizeTask({
src: 'out-editor-build',
entryPoints: editorEntryPoints,
otherSources: editorOtherSources,
......
......@@ -16,7 +16,7 @@ var ShakeLevel;
})(ShakeLevel = exports.ShakeLevel || (exports.ShakeLevel = {}));
function shake(options) {
var languageService = createTypeScriptLanguageService(options);
markNodes(languageService, options.shakeLevel, options.entryPoints.map(function (moduleId) { return moduleId + '.ts'; }), options.importIgnorePattern);
markNodes(languageService, options);
return generateResult(languageService, options.shakeLevel);
}
exports.shake = shake;
......@@ -24,6 +24,10 @@ exports.shake = shake;
function createTypeScriptLanguageService(options) {
// Discover referenced files
var FILES = discoverAndReadFiles(options);
// Add fake usage files
options.inlineEntryPoints.forEach(function (inlineEntryPoint, index) {
FILES["inlineEntryPoint:" + index + ".ts"] = inlineEntryPoint;
});
// Resolve libs
var RESOLVED_LIBS = {};
options.libs.forEach(function (filename) {
......@@ -166,9 +170,9 @@ function nodeOrChildIsBlack(node) {
}
return false;
}
function markNodes(languageService, shakeLevel, entryPointFiles, importIgnorePattern) {
function markNodes(languageService, options) {
var program = languageService.getProgram();
if (shakeLevel === 0 /* Files */) {
if (options.shakeLevel === 0 /* Files */) {
// Mark all source files Black
program.getSourceFiles().forEach(function (sourceFile) {
setColor(sourceFile, 2 /* Black */);
......@@ -249,7 +253,7 @@ function markNodes(languageService, shakeLevel, entryPointFiles, importIgnorePat
}
setColor(node, 2 /* Black */);
black_queue.push(node);
if (shakeLevel === 2 /* ClassMembers */ && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) || ts.isPropertySignature(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node))) {
if (options.shakeLevel === 2 /* ClassMembers */ && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) || ts.isPropertySignature(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node))) {
var references = languageService.getReferencesAtPosition(node.getSourceFile().fileName, node.name.pos + node.name.getLeadingTriviaWidth());
if (references) {
for (var i = 0, len = references.length; i < len; i++) {
......@@ -275,7 +279,7 @@ function markNodes(languageService, shakeLevel, entryPointFiles, importIgnorePat
enqueue_black(sourceFile);
}
function enqueueImport(node, importText) {
if (importIgnorePattern.test(importText)) {
if (options.importIgnorePattern.test(importText)) {
// this import should be ignored
return;
}
......@@ -289,7 +293,9 @@ function markNodes(languageService, shakeLevel, entryPointFiles, importIgnorePat
}
enqueueFile(fullPath);
}
entryPointFiles.forEach(function (filename) { return enqueueFile(filename); });
options.entryPoints.forEach(function (moduleId) { return enqueueFile(moduleId + '.ts'); });
// Add fake usage files
options.inlineEntryPoints.forEach(function (_, index) { return enqueueFile("inlineEntryPoint:" + index + ".ts"); });
var step = 0;
var checker = program.getTypeChecker();
var _loop_1 = function () {
......@@ -330,7 +336,7 @@ function markNodes(languageService, shakeLevel, entryPointFiles, importIgnorePat
// (they can be the declaration of a module import)
continue;
}
if (shakeLevel === 2 /* ClassMembers */ && (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration))) {
if (options.shakeLevel === 2 /* ClassMembers */ && (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration))) {
enqueue_black(declaration.name);
for (var j = 0; j < declaration.members.length; j++) {
var member = declaration.members[j];
......
......@@ -27,6 +27,10 @@ export interface ITreeShakingOptions {
* e.g. `vs/editor/editor.main` or `index`
*/
entryPoints: string[];
/**
* Inline usages.
*/
inlineEntryPoints: string[];
/**
* TypeScript libs.
* e.g. `lib.d.ts`, `lib.es2015.collection.d.ts`
......@@ -55,7 +59,7 @@ export interface ITreeShakingResult {
export function shake(options: ITreeShakingOptions): ITreeShakingResult {
const languageService = createTypeScriptLanguageService(options);
markNodes(languageService, options.shakeLevel, options.entryPoints.map(moduleId => moduleId + '.ts'), options.importIgnorePattern);
markNodes(languageService, options);
return generateResult(languageService, options.shakeLevel);
}
......@@ -65,6 +69,11 @@ function createTypeScriptLanguageService(options: ITreeShakingOptions): ts.Langu
// Discover referenced files
const FILES = discoverAndReadFiles(options);
// Add fake usage files
options.inlineEntryPoints.forEach((inlineEntryPoint, index) => {
FILES[`inlineEntryPoint:${index}.ts`] = inlineEntryPoint;
});
// Resolve libs
const RESOLVED_LIBS: ILibMap = {};
options.libs.forEach((filename) => {
......@@ -229,10 +238,10 @@ function nodeOrChildIsBlack(node: ts.Node): boolean {
return false;
}
function markNodes(languageService: ts.LanguageService, shakeLevel: ShakeLevel, entryPointFiles: string[], importIgnorePattern: RegExp) {
function markNodes(languageService: ts.LanguageService, options: ITreeShakingOptions) {
const program = languageService.getProgram();
if (shakeLevel === ShakeLevel.Files) {
if (options.shakeLevel === ShakeLevel.Files) {
// Mark all source files Black
program.getSourceFiles().forEach((sourceFile) => {
setColor(sourceFile, NodeColor.Black);
......@@ -335,7 +344,7 @@ function markNodes(languageService: ts.LanguageService, shakeLevel: ShakeLevel,
setColor(node, NodeColor.Black);
black_queue.push(node);
if (shakeLevel === ShakeLevel.ClassMembers && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) || ts.isPropertySignature(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node))) {
if (options.shakeLevel === ShakeLevel.ClassMembers && (ts.isMethodDeclaration(node) || ts.isMethodSignature(node) || ts.isPropertySignature(node) || ts.isGetAccessor(node) || ts.isSetAccessor(node))) {
const references = languageService.getReferencesAtPosition(node.getSourceFile().fileName, node.name.pos + node.name.getLeadingTriviaWidth());
if (references) {
for (let i = 0, len = references.length; i < len; i++) {
......@@ -365,7 +374,7 @@ function markNodes(languageService: ts.LanguageService, shakeLevel: ShakeLevel,
}
function enqueueImport(node: ts.Node, importText: string): void {
if (importIgnorePattern.test(importText)) {
if (options.importIgnorePattern.test(importText)) {
// this import should be ignored
return;
}
......@@ -380,7 +389,9 @@ function markNodes(languageService: ts.LanguageService, shakeLevel: ShakeLevel,
enqueueFile(fullPath);
}
entryPointFiles.forEach((filename) => enqueueFile(filename));
options.entryPoints.forEach(moduleId => enqueueFile(moduleId + '.ts'));
// Add fake usage files
options.inlineEntryPoints.forEach((_, index) => enqueueFile(`inlineEntryPoint:${index}.ts`));
let step = 0;
......@@ -429,7 +440,7 @@ function markNodes(languageService: ts.LanguageService, shakeLevel: ShakeLevel,
continue;
}
if (shakeLevel === ShakeLevel.ClassMembers && (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration))) {
if (options.shakeLevel === ShakeLevel.ClassMembers && (ts.isClassDeclaration(declaration) || ts.isInterfaceDeclaration(declaration))) {
enqueue_black(declaration.name);
for (let j = 0; j < declaration.members.length; j++) {
......
......@@ -450,12 +450,12 @@ function execute() {
var t = Date.now();
var emitOutput = languageService.getEmitOutput(fileName, true);
OUTPUT_FILES[SRC_FILE_TO_EXPECTED_NAME[fileName]] = emitOutput.outputFiles[0].text;
console.log("Generating .d.ts for " + fileName + " took " + (Date.now() - t) + " ms");
// console.log(`Generating .d.ts for ${fileName} took ${Date.now() - t} ms`);
});
console.log("Generating .d.ts took " + (Date.now() - t1) + " ms");
var result = run('src', OUTPUT_FILES);
console.log(result.filePath);
fs.writeFileSync(result.filePath, result.content.replace(/\r\n/gm, '\n'));
fs.writeFileSync(path.join(SRC, 'user.ts'), result.usageContent.replace(/\r\n/gm, '\n'));
// console.log(result.filePath);
// fs.writeFileSync(result.filePath, result.content.replace(/\r\n/gm, '\n'));
// fs.writeFileSync(path.join(SRC, 'user.ts'), result.usageContent.replace(/\r\n/gm, '\n'));
return run('src', OUTPUT_FILES);
}
// execute();
exports.execute = execute;
......@@ -512,7 +512,7 @@ class TypeScriptLanguageServiceHost implements ts.LanguageServiceHost {
}
}
function execute() {
export function execute(): IMonacoDeclarationResult {
const OUTPUT_FILES: { [file: string]: string; } = {};
const SRC_FILES: IFileMap = {};
......@@ -536,15 +536,13 @@ function execute() {
var t = Date.now();
const emitOutput = languageService.getEmitOutput(fileName, true);
OUTPUT_FILES[SRC_FILE_TO_EXPECTED_NAME[fileName]] = emitOutput.outputFiles[0].text;
console.log(`Generating .d.ts for ${fileName} took ${Date.now() - t} ms`);
// console.log(`Generating .d.ts for ${fileName} took ${Date.now() - t} ms`);
});
console.log(`Generating .d.ts took ${Date.now() - t1} ms`);
const result = run('src', OUTPUT_FILES);
// console.log(result.filePath);
// fs.writeFileSync(result.filePath, result.content.replace(/\r\n/gm, '\n'));
// fs.writeFileSync(path.join(SRC, 'user.ts'), result.usageContent.replace(/\r\n/gm, '\n'));
console.log(result.filePath);
fs.writeFileSync(result.filePath, result.content.replace(/\r\n/gm, '\n'));
fs.writeFileSync(path.join(SRC, 'user.ts'), result.usageContent.replace(/\r\n/gm, '\n'));
return run('src', OUTPUT_FILES);
}
// execute();
// This file is adding references to various symbols which should not be removed via tree shaking
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IHighlight } from 'vs/base/parts/quickopen/browser/quickOpenModel';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { CountBadge } from 'vs/base/browser/ui/countBadge/countBadge';
import { SimpleWorkerClient, create as create1 } from 'vs/base/common/worker/simpleWorker';
import { create as create2 } from 'vs/editor/common/services/editorSimpleWorker';
import { QuickOpenWidget } from 'vs/base/parts/quickopen/browser/quickOpenWidget';
import { SyncDescriptor0, SyncDescriptor1, SyncDescriptor2, SyncDescriptor3, SyncDescriptor4, SyncDescriptor5, SyncDescriptor6, SyncDescriptor7, SyncDescriptor8 } from 'vs/platform/instantiation/common/descriptors';
import { PolyfillPromise } from 'vs/base/common/winjs.polyfill.promise';
import { DiffNavigator } from 'vs/editor/browser/widget/diffNavigator';
import * as editorAPI from 'vs/editor/editor.api';
(function () {
var a: any;
var b: any;
a = (<IContextViewService>b).layout; // IContextViewProvider
a = (<IWorkspaceContextService>b).getWorkspaceFolder; // IWorkspaceFolderProvider
a = (<IWorkspaceContextService>b).getWorkspace; // IWorkspaceFolderProvider
a = (<CountBadge>b).style; // IThemable
a = (<QuickOpenWidget>b).style; // IThemable
a = (<IEnvironmentService>b).userHome; // IUserHomeProvider
a = (<DiffNavigator>b).previous; // IDiffNavigator
a = (<ServiceIdentifier<any>>b).type;
a = (<IHighlight>b).start;
a = (<IHighlight>b).end;
a = (<SimpleWorkerClient<any>>b).getProxyObject; // IWorkerClient
a = create1;
a = create2;
// promise polyfill
a = PolyfillPromise.all;
a = PolyfillPromise.race;
a = PolyfillPromise.resolve;
a = PolyfillPromise.reject;
a = (<PolyfillPromise>b).then;
a = (<PolyfillPromise>b).catch;
// injection madness
a = (<SyncDescriptor0<any>>b).ctor;
a = (<SyncDescriptor0<any>>b).bind;
a = (<SyncDescriptor1<any, any>>b).ctor;
a = (<SyncDescriptor1<any, any>>b).bind;
a = (<SyncDescriptor1<any, any>>b).ctor;
a = (<SyncDescriptor1<any, any>>b).bind;
a = (<SyncDescriptor2<any, any, any>>b).ctor;
a = (<SyncDescriptor2<any, any, any>>b).bind;
a = (<SyncDescriptor3<any, any, any, any>>b).ctor;
a = (<SyncDescriptor3<any, any, any, any>>b).bind;
a = (<SyncDescriptor4<any, any, any, any, any>>b).ctor;
a = (<SyncDescriptor4<any, any, any, any, any>>b).bind;
a = (<SyncDescriptor5<any, any, any, any, any, any>>b).ctor;
a = (<SyncDescriptor5<any, any, any, any, any, any>>b).bind;
a = (<SyncDescriptor6<any, any, any, any, any, any, any>>b).ctor;
a = (<SyncDescriptor6<any, any, any, any, any, any, any>>b).bind;
a = (<SyncDescriptor7<any, any, any, any, any, any, any, any>>b).ctor;
a = (<SyncDescriptor7<any, any, any, any, any, any, any, any>>b).bind;
a = (<SyncDescriptor8<any, any, any, any, any, any, any, any, any>>b).ctor;
a = (<SyncDescriptor8<any, any, any, any, any, any, any, any, any>>b).bind;
// exported API
a = editorAPI.CancellationTokenSource;
a = editorAPI.Emitter;
a = editorAPI.KeyCode;
a = editorAPI.KeyMod;
a = editorAPI.Position;
a = editorAPI.Range;
a = editorAPI.Selection;
a = editorAPI.SelectionDirection;
a = editorAPI.Severity;
a = editorAPI.MarkerSeverity;
a = editorAPI.MarkerTag;
a = editorAPI.Promise;
a = editorAPI.Uri;
a = editorAPI.Token;
a = editorAPI.editor;
a = editorAPI.languages;
})();
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册