diff --git a/.gitignore b/.gitignore index 736b3124ec5da..584490c228540 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,7 @@ out/ out-build/ out-editor/ out-editor-min/ -out-editor-ossfree/ -out-editor-ossfree-min/ +out-monaco-editor-core/ out-vscode/ out-vscode-min/ build/node_modules \ No newline at end of file diff --git a/build/gulpfile.common.js b/build/gulpfile.common.js index 926167f0ac8d4..eec3e80911708 100644 --- a/build/gulpfile.common.js +++ b/build/gulpfile.common.js @@ -167,7 +167,9 @@ exports.optimizeTask = function(opts) { addComment: true, includeContent: true })) - .pipe(i18n.processNlsFiles()) + .pipe(i18n.processNlsFiles({ + fileHeader: bundledFileHeader + })) .pipe(gulp.dest(out)); }; }; diff --git a/build/gulpfile.editor.js b/build/gulpfile.editor.js index 868e7dc0cd9f6..8862cc8c8a175 100644 --- a/build/gulpfile.editor.js +++ b/build/gulpfile.editor.js @@ -9,9 +9,12 @@ var _ = require('underscore'); var buildfile = require('../src/buildfile'); var util = require('./lib/util'); var common = require('./gulpfile.common'); +var es = require('event-stream'); var root = path.dirname(__dirname); -var headerVersion = process.env['BUILD_SOURCEVERSION'] || util.getVersion(root); +var sha1 = util.getVersion(root); +var semver = require('./monaco/package.json').version; +var headerVersion = semver + '(' + sha1 + ')'; // Build @@ -63,7 +66,7 @@ function editorLoaderConfig(removeAllOSS) { } gulp.task('clean-optimized-editor', util.rimraf('out-editor')); -gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common.optimizeTask({ +gulp.task('optimize-editor', ['clean-optimized-editor'/*, 'compile-build'*/], common.optimizeTask({ entryPoints: editorEntryPoints, otherSources: editorOtherSources, resources: editorResources, @@ -74,4 +77,61 @@ gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common gulp.task('clean-minified-editor', util.rimraf('out-editor-min')); gulp.task('minify-editor', ['clean-minified-editor', 'optimize-editor'], common.minifyTask('out-editor', true)); -gulp.task('editor-distro', ['minify-editor', 'optimize-editor']); + +gulp.task('clean-editor-distro', util.rimraf('out-monaco-editor-core')); +gulp.task('editor-distro', ['clean-editor-distro'/*, 'minify-editor', 'optimize-editor'*/], function() { + return es.merge( + // other assets + es.merge( + gulp.src('build/monaco/package.json'), + gulp.src('build/monaco/LICENSE'), + gulp.src('build/monaco/ThirdPartyNotices.txt'), + gulp.src('src/vs/monaco.d.ts') + ).pipe(gulp.dest('out-monaco-editor-core')), + + // dev folder + es.merge( + gulp.src('out-editor/**/*') + ).pipe(gulp.dest('out-monaco-editor-core/dev')), + + // min folder + es.merge( + gulp.src('out-editor-min/**/*') + ).pipe(filterStream(function(path) { + // no map files + return !/\.js\.map$|nls\.metadata\.json/.test(path); + })).pipe(es.through(function(data) { + // tweak the sourceMappingURL + if (!/\.js$/.test(data.path)) { + this.emit('data', data); + return; + } + + var relativePathToMap = path.relative(path.join(data.relative), path.join('min-maps', data.relative + '.map')); + + var strContents = data.contents.toString(); + var newStr = '//# sourceMappingURL=' + relativePathToMap.replace(/\\/g, '/'); + strContents = strContents.replace(/\/\/\# sourceMappingURL=[^ ]+$/, newStr); + + data.contents = new Buffer(strContents); + this.emit('data', data); + })).pipe(gulp.dest('out-monaco-editor-core/min')), + + // min-maps folder + es.merge( + gulp.src('out-editor-min/**/*') + ).pipe(filterStream(function(path) { + // no map files + return !/\.js\.map$/.test(path); + })).pipe(gulp.dest('out-monaco-editor-core/min-maps')) + ); +}); + +function filterStream(testFunc) { + return es.through(function(data) { + if (!testFunc(data.relative)) { + return; + } + this.emit('data', data); + }); +} diff --git a/build/gulpfile.hygiene.js b/build/gulpfile.hygiene.js index 5d6e2a64ffc5b..2c7a06735403a 100644 --- a/build/gulpfile.hygiene.js +++ b/build/gulpfile.hygiene.js @@ -26,7 +26,8 @@ var eolFilter = [ '!**/node_modules/**', '!**/fixtures/**', '!**/*.{svg,exe,png,scpt,bat,cmd,cur,ttf,woff,eot}', - '!build/{lib,monaco,tslintRules}/**/*.js' + '!build/{lib,tslintRules}/**/*.js', + '!build/monaco/**/*' ]; var indentationFilter = [ diff --git a/build/lib/i18n.js b/build/lib/i18n.js index 430fd0b748063..5669ae38a051b 100644 --- a/build/lib/i18n.js +++ b/build/lib/i18n.js @@ -91,12 +91,6 @@ function sortLanguages(directoryNames) { return a.iso639_2 < b.iso639_2 ? -1 : (a.iso639_2 > b.iso639_2 ? 1 : 0); }); } -var headerComment = [ - '/*---------------------------------------------------------------------------------------------', - ' * Copyright (c) Microsoft Corporation. All rights reserved.', - ' * Licensed under the MIT License. See License.txt in the project root for license information.', - ' *---------------------------------------------------------------------------------------------*/' -].join('\n'); function stripComments(content) { /** * First capturing group matches double quoted string @@ -164,7 +158,7 @@ function escapeCharacters(value) { } return result.join(''); } -function processCoreBundleFormat(json, emitter) { +function processCoreBundleFormat(fileHeader, json, emitter) { var keysSection = json.keys; var messageSection = json.messages; var bundleSection = json.bundles; @@ -236,7 +230,7 @@ function processCoreBundleFormat(json, emitter) { Object.keys(bundleSection).forEach(function (bundle) { var modules = bundleSection[bundle]; var contents = [ - headerComment, + fileHeader, ("define(\"" + bundle + ".nls." + language.iso639_2 + "\", {") ]; modules.forEach(function (module, index) { @@ -273,7 +267,7 @@ function processCoreBundleFormat(json, emitter) { } }); } -function processNlsFiles() { +function processNlsFiles(opts) { return event_stream_1.through(function (file) { var fileName = path.basename(file.path); if (fileName === 'nls.metadata.json') { @@ -285,7 +279,7 @@ function processNlsFiles() { this.emit('error', "Failed to read component file: " + file.relative); } if (BundledFormat.is(json)) { - processCoreBundleFormat(json, this); + processCoreBundleFormat(opts.fileHeader, json, this); } } this.emit('data', file); diff --git a/build/lib/i18n.ts b/build/lib/i18n.ts index 51b55fbb2b487..e8cd6ec771a17 100644 --- a/build/lib/i18n.ts +++ b/build/lib/i18n.ts @@ -115,15 +115,6 @@ function sortLanguages(directoryNames: string[]): IDirectoryInfo[] { }); } -const headerComment: string = - [ - '/*---------------------------------------------------------------------------------------------', - ' * Copyright (c) Microsoft Corporation. All rights reserved.', - ' * Licensed under the MIT License. See License.txt in the project root for license information.', - ' *---------------------------------------------------------------------------------------------*/' - ].join('\n'); - - function stripComments(content: string): string { /** * First capturing group matches double quoted string @@ -189,7 +180,7 @@ function escapeCharacters(value:string):string { return result.join(''); } -function processCoreBundleFormat(json: BundledFormat, emitter: any) { +function processCoreBundleFormat(fileHeader:string, json: BundledFormat, emitter: any) { let keysSection = json.keys; let messageSection = json.messages; let bundleSection = json.bundles; @@ -262,7 +253,7 @@ function processCoreBundleFormat(json: BundledFormat, emitter: any) { Object.keys(bundleSection).forEach((bundle) => { let modules = bundleSection[bundle]; let contents: string[] = [ - headerComment, + fileHeader, `define("${bundle}.nls.${language.iso639_2}", {` ]; modules.forEach((module, index) => { @@ -299,7 +290,7 @@ function processCoreBundleFormat(json: BundledFormat, emitter: any) { }); } -export function processNlsFiles(): ThroughStream { +export function processNlsFiles(opts:{fileHeader:string;}): ThroughStream { return through(function(file: File) { let fileName = path.basename(file.path); if (fileName === 'nls.metadata.json') { @@ -310,7 +301,7 @@ export function processNlsFiles(): ThroughStream { this.emit('error', `Failed to read component file: ${file.relative}`) } if (BundledFormat.is(json)) { - processCoreBundleFormat(json, this); + processCoreBundleFormat(opts.fileHeader, json, this); } } this.emit('data', file); diff --git a/build/monaco/LICENSE b/build/monaco/LICENSE new file mode 100644 index 0000000000000..9f66f02b0e00b --- /dev/null +++ b/build/monaco/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Microsoft Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/build/monaco/ThirdPartyNotices.txt b/build/monaco/ThirdPartyNotices.txt new file mode 100644 index 0000000000000..065cabdaf9c62 --- /dev/null +++ b/build/monaco/ThirdPartyNotices.txt @@ -0,0 +1,103 @@ +THIRD-PARTY SOFTWARE NOTICES AND INFORMATION +Do Not Translate or Localize + +This project incorporates components from the projects listed below. The original copyright notices and the licenses +under which Microsoft received such components are set forth below. Microsoft reserves all rights not expressly granted +herein, whether by implication, estoppel or otherwise. + +1. HTML 5.1 W3C Working Draft version 08 October 2015 (http://www.w3.org/TR/2015/WD-html51-20151008/) +2. js-beautify version 1.5.10 (https://github.com/beautify-web/js-beautify) +3. string_scorer version 0.1.20 (https://github.com/joshaven/string_score) +4. vscode-swift version 0.0.1 (https://github.com/owensd/vscode-swift) + + +%% HTML 5.1 W3C Working Draft NOTICES AND INFORMATION BEGIN HERE +========================================= +Copyright © 2015 W3C® (MIT, ERCIM, Keio, Beihang). This software or document includes material copied +from or derived from HTML 5.1 W3C Working Draft (http://www.w3.org/TR/2015/WD-html51-20151008/.) + +THIS DOCUMENT IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT +NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, OR TITLE; THAT THE CONTENTS OF +THE DOCUMENT ARE SUITABLE FOR ANY PURPOSE; NOR THAT THE IMPLEMENTATION OF SUCH CONTENTS WILL NOT INFRINGE ANY THIRD PARTY +PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. + +COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE +DOCUMENT OR THE PERFORMANCE OR IMPLEMENTATION OF THE CONTENTS THEREOF. + +The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to this document or its contents +without specific, written prior permission. Title to copyright in this document will at all times remain with copyright holders. +========================================= +END OF HTML 5.1 W3C Working Draft NOTICES AND INFORMATION + + + + +%% js-beautify NOTICES AND INFORMATION BEGIN HERE +========================================= +The MIT License (MIT) + +Copyright (c) 2007-2013 Einar Lielmanis and contributors. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================= +END OF js-beautify NOTICES AND INFORMATION + + + + +%% string_scorer NOTICES AND INFORMATION BEGIN HERE +========================================= +This software is released under the MIT license: + +Copyright (c) Joshaven Potter + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================= +END OF string_scorer NOTICES AND INFORMATION + + + + +%% vscode-swift NOTICES AND INFORMATION BEGIN HERE +========================================= +The MIT License (MIT) + +Copyright (c) 2015 David Owens II + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +========================================= +END OF vscode-swift NOTICES AND INFORMATION diff --git a/build/monaco/api.js b/build/monaco/api.js index 2afc92ae1f340..70dc1547ab5fa 100644 --- a/build/monaco/api.js +++ b/build/monaco/api.js @@ -1,295 +1,292 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ -"use strict"; -// PREREQUISITE: -// SET VSCODE_BUILD_DECLARATION_FILES=1 -// run gulp watch once -var fs = require('fs'); -var ts = require('typescript'); -var path = require('path'); -var SRC = path.join(__dirname, '../../src'); -var OUT = path.join(__dirname, '../../out'); -function moduleIdToPath(moduleId) { - if (/\.d\.ts/.test(moduleId)) { - return path.join(SRC, moduleId); - } - return path.join(OUT, moduleId) + '.d.ts'; -} -var SOURCE_FILE_MAP = {}; -function getSourceFile(moduleId) { - if (!SOURCE_FILE_MAP[moduleId]) { - var filePath = moduleIdToPath(moduleId); - var fileContents = void 0; - try { - fileContents = fs.readFileSync(filePath).toString(); - } - catch (err) { - console.error('======================================================================'); - console.error('=> Have you compiled (gulp watch) with env variable VSCODE_BUILD_DECLARATION_FILES=1 ?'); - console.error('======================================================================'); - throw err; - } - var sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5); - SOURCE_FILE_MAP[moduleId] = sourceFile; - } - return SOURCE_FILE_MAP[moduleId]; -} -function isDeclaration(a) { - return (a.kind === ts.SyntaxKind.InterfaceDeclaration - || a.kind === ts.SyntaxKind.EnumDeclaration - || a.kind === ts.SyntaxKind.ClassDeclaration - || a.kind === ts.SyntaxKind.TypeAliasDeclaration - || a.kind === ts.SyntaxKind.FunctionDeclaration - || a.kind === ts.SyntaxKind.ModuleDeclaration); -} -function visitTopLevelDeclarations(sourceFile, visitor) { - var stop = false; - var visit = function (node) { - if (stop) { - return; - } - switch (node.kind) { - case ts.SyntaxKind.InterfaceDeclaration: - case ts.SyntaxKind.EnumDeclaration: - case ts.SyntaxKind.ClassDeclaration: - case ts.SyntaxKind.VariableStatement: - case ts.SyntaxKind.TypeAliasDeclaration: - case ts.SyntaxKind.FunctionDeclaration: - case ts.SyntaxKind.ModuleDeclaration: - stop = visitor(node); - } - // if (node.kind !== ts.SyntaxKind.SourceFile) { - // if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) { - // console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]); - // console.log(getNodeText(sourceFile, node)); - // } - // } - if (stop) { - return; - } - ts.forEachChild(node, visit); - }; - visit(sourceFile); -} -function getAllTopLevelDeclarations(sourceFile) { - var all = []; - visitTopLevelDeclarations(sourceFile, function (node) { - if (node.kind === ts.SyntaxKind.InterfaceDeclaration || node.kind === ts.SyntaxKind.ClassDeclaration || node.kind === ts.SyntaxKind.ModuleDeclaration) { - var interfaceDeclaration = node; - var triviaStart = interfaceDeclaration.pos; - var triviaEnd = interfaceDeclaration.name.pos; - var triviaText = getNodeText(sourceFile, { pos: triviaStart, end: triviaEnd }); - // // let nodeText = getNodeText(sourceFile, node); - // if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) { - // console.log('TRIVIA: ', triviaText); - // } - if (triviaText.indexOf('@internal') === -1) { - all.push(node); - } - } - else { - var nodeText = getNodeText(sourceFile, node); - if (nodeText.indexOf('@internal') === -1) { - all.push(node); - } - } - return false /*continue*/; - }); - return all; -} -function getTopLevelDeclaration(sourceFile, typeName) { - var result = null; - visitTopLevelDeclarations(sourceFile, function (node) { - if (isDeclaration(node)) { - if (node.name.text === typeName) { - result = node; - return true /*stop*/; - } - return false /*continue*/; - } - // node is ts.VariableStatement - if (getNodeText(sourceFile, node).indexOf(typeName) >= 0) { - result = node; - return true /*stop*/; - } - return false /*continue*/; - }); - if (result === null) { - console.log('COULD NOT FIND ' + typeName + '!'); - } - return result; -} -function getNodeText(sourceFile, node) { - return sourceFile.getFullText().substring(node.pos, node.end); -} -function getMassagedTopLevelDeclarationText(sourceFile, declaration) { - var result = getNodeText(sourceFile, declaration); - // if (result.indexOf('MonacoWorker') >= 0) { - // console.log('here!'); - // // console.log(ts.SyntaxKind[declaration.kind]); - // } - if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration || declaration.kind === ts.SyntaxKind.ClassDeclaration) { - var interfaceDeclaration = declaration; - var members = interfaceDeclaration.members; - members.forEach(function (member) { - try { - var memberText = getNodeText(sourceFile, member); - if (memberText.indexOf('@internal') >= 0 || memberText.indexOf('private') >= 0) { - // console.log('BEFORE: ', result); - result = result.replace(memberText, ''); - } - } - catch (err) { - } - }); - } - result = result.replace(/export default/g, 'export'); - result = result.replace(/export declare/g, 'export'); - return result; -} -function format(text) { - var options = getDefaultOptions(); - // Parse the source text - var sourceFile = ts.createSourceFile('file.ts', text, ts.ScriptTarget.Latest, /*setParentPointers*/ true); - // Get the formatting edits on the input sources - var edits = ts.formatting.formatDocument(sourceFile, getRuleProvider(options), options); - // Apply the edits on the input code - return applyEdits(text, edits); - function getRuleProvider(options) { - // Share this between multiple formatters using the same options. - // This represents the bulk of the space the formatter uses. - var ruleProvider = new ts.formatting.RulesProvider(); - ruleProvider.ensureUpToDate(options); - return ruleProvider; - } - function applyEdits(text, edits) { - // Apply edits in reverse on the existing text - var result = text; - for (var i = edits.length - 1; i >= 0; i--) { - var change = edits[i]; - var head = result.slice(0, change.span.start); - var tail = result.slice(change.span.start + change.span.length); - result = head + change.newText + tail; - } - return result; - } - function getDefaultOptions() { - return { - IndentSize: 4, - TabSize: 4, - NewLineCharacter: '\r\n', - ConvertTabsToSpaces: true, - IndentStyle: ts.IndentStyle.Block, - InsertSpaceAfterCommaDelimiter: true, - InsertSpaceAfterSemicolonInForStatements: true, - InsertSpaceBeforeAndAfterBinaryOperators: true, - InsertSpaceAfterKeywordsInControlFlowStatements: true, - InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false, - InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false, - InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, - InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: true, - PlaceOpenBraceOnNewLineForFunctions: false, - PlaceOpenBraceOnNewLineForControlBlocks: false - }; - } -} -function createReplacer(data) { - data = data || ''; - var rawDirectives = data.split(';'); - var directives = []; - rawDirectives.forEach(function (rawDirective) { - if (rawDirective.length === 0) { - return; - } - var pieces = rawDirective.split('=>'); - var findStr = pieces[0]; - var replaceStr = pieces[1]; - findStr = findStr.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&'); - findStr = '\\b' + findStr + '\\b'; - directives.push([new RegExp(findStr, 'g'), replaceStr]); - }); - return function (str) { - for (var i = 0; i < directives.length; i++) { - str = str.replace(directives[i][0], directives[i][1]); - } - return str; - }; -} -function generateDeclarationFile(recipe) { - var lines = recipe.split(/\r\n|\n|\r/); - var result = []; - lines.forEach(function (line) { - var m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/); - if (m1) { - console.log('HANDLING META: ' + line); - var moduleId = m1[1]; - var sourceFile_1 = getSourceFile(moduleId); - var replacer_1 = createReplacer(m1[2]); - var typeNames = m1[3].split(/,/); - typeNames.forEach(function (typeName) { - typeName = typeName.trim(); - if (typeName.length === 0) { - return; - } - var declaration = getTopLevelDeclaration(sourceFile_1, typeName); - result.push(replacer_1(getMassagedTopLevelDeclarationText(sourceFile_1, declaration))); - }); - return; - } - var m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/); - if (m2) { - console.log('HANDLING META: ' + line); - var moduleId = m2[1]; - var sourceFile_2 = getSourceFile(moduleId); - var replacer_2 = createReplacer(m2[2]); - var typeNames = m2[3].split(/,/); - var typesToExcludeMap_1 = {}; - var typesToExcludeArr_1 = []; - typeNames.forEach(function (typeName) { - typeName = typeName.trim(); - if (typeName.length === 0) { - return; - } - typesToExcludeMap_1[typeName] = true; - typesToExcludeArr_1.push(typeName); - }); - getAllTopLevelDeclarations(sourceFile_2).forEach(function (declaration) { - if (isDeclaration(declaration)) { - if (typesToExcludeMap_1[declaration.name.text]) { - return; - } - } - else { - // node is ts.VariableStatement - var nodeText = getNodeText(sourceFile_2, declaration); - for (var i = 0; i < typesToExcludeArr_1.length; i++) { - if (nodeText.indexOf(typesToExcludeArr_1[i]) >= 0) { - return; - } - } - } - result.push(replacer_2(getMassagedTopLevelDeclarationText(sourceFile_2, declaration))); - }); - return; - } - result.push(line); - }); - var resultTxt = result.join('\n'); - resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri'); - resultTxt = resultTxt.replace(/\bEvent Have you compiled with env variable VSCODE_BUILD_DECLARATION_FILES=1 ?'); + console.error('========================================================================='); + throw err; + } + var sourceFile = ts.createSourceFile(filePath, fileContents, ts.ScriptTarget.ES5); + SOURCE_FILE_MAP[moduleId] = sourceFile; + } + return SOURCE_FILE_MAP[moduleId]; +} +function isDeclaration(a) { + return (a.kind === ts.SyntaxKind.InterfaceDeclaration + || a.kind === ts.SyntaxKind.EnumDeclaration + || a.kind === ts.SyntaxKind.ClassDeclaration + || a.kind === ts.SyntaxKind.TypeAliasDeclaration + || a.kind === ts.SyntaxKind.FunctionDeclaration + || a.kind === ts.SyntaxKind.ModuleDeclaration); +} +function visitTopLevelDeclarations(sourceFile, visitor) { + var stop = false; + var visit = function (node) { + if (stop) { + return; + } + switch (node.kind) { + case ts.SyntaxKind.InterfaceDeclaration: + case ts.SyntaxKind.EnumDeclaration: + case ts.SyntaxKind.ClassDeclaration: + case ts.SyntaxKind.VariableStatement: + case ts.SyntaxKind.TypeAliasDeclaration: + case ts.SyntaxKind.FunctionDeclaration: + case ts.SyntaxKind.ModuleDeclaration: + stop = visitor(node); + } + // if (node.kind !== ts.SyntaxKind.SourceFile) { + // if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) { + // console.log('FOUND TEXT IN NODE: ' + ts.SyntaxKind[node.kind]); + // console.log(getNodeText(sourceFile, node)); + // } + // } + if (stop) { + return; + } + ts.forEachChild(node, visit); + }; + visit(sourceFile); +} +function getAllTopLevelDeclarations(sourceFile) { + var all = []; + visitTopLevelDeclarations(sourceFile, function (node) { + if (node.kind === ts.SyntaxKind.InterfaceDeclaration || node.kind === ts.SyntaxKind.ClassDeclaration || node.kind === ts.SyntaxKind.ModuleDeclaration) { + var interfaceDeclaration = node; + var triviaStart = interfaceDeclaration.pos; + var triviaEnd = interfaceDeclaration.name.pos; + var triviaText = getNodeText(sourceFile, { pos: triviaStart, end: triviaEnd }); + // // let nodeText = getNodeText(sourceFile, node); + // if (getNodeText(sourceFile, node).indexOf('SymbolKind') >= 0) { + // console.log('TRIVIA: ', triviaText); + // } + if (triviaText.indexOf('@internal') === -1) { + all.push(node); + } + } + else { + var nodeText = getNodeText(sourceFile, node); + if (nodeText.indexOf('@internal') === -1) { + all.push(node); + } + } + return false /*continue*/; + }); + return all; +} +function getTopLevelDeclaration(sourceFile, typeName) { + var result = null; + visitTopLevelDeclarations(sourceFile, function (node) { + if (isDeclaration(node)) { + if (node.name.text === typeName) { + result = node; + return true /*stop*/; + } + return false /*continue*/; + } + // node is ts.VariableStatement + if (getNodeText(sourceFile, node).indexOf(typeName) >= 0) { + result = node; + return true /*stop*/; + } + return false /*continue*/; + }); + if (result === null) { + console.log('COULD NOT FIND ' + typeName + '!'); + } + return result; +} +function getNodeText(sourceFile, node) { + return sourceFile.getFullText().substring(node.pos, node.end); +} +function getMassagedTopLevelDeclarationText(sourceFile, declaration) { + var result = getNodeText(sourceFile, declaration); + // if (result.indexOf('MonacoWorker') >= 0) { + // console.log('here!'); + // // console.log(ts.SyntaxKind[declaration.kind]); + // } + if (declaration.kind === ts.SyntaxKind.InterfaceDeclaration || declaration.kind === ts.SyntaxKind.ClassDeclaration) { + var interfaceDeclaration = declaration; + var members = interfaceDeclaration.members; + members.forEach(function (member) { + try { + var memberText = getNodeText(sourceFile, member); + if (memberText.indexOf('@internal') >= 0 || memberText.indexOf('private') >= 0) { + // console.log('BEFORE: ', result); + result = result.replace(memberText, ''); + } + } + catch (err) { + } + }); + } + result = result.replace(/export default/g, 'export'); + result = result.replace(/export declare/g, 'export'); + return result; +} +function format(text) { + var options = getDefaultOptions(); + // Parse the source text + var sourceFile = ts.createSourceFile('file.ts', text, ts.ScriptTarget.Latest, /*setParentPointers*/ true); + // Get the formatting edits on the input sources + var edits = ts.formatting.formatDocument(sourceFile, getRuleProvider(options), options); + // Apply the edits on the input code + return applyEdits(text, edits); + function getRuleProvider(options) { + // Share this between multiple formatters using the same options. + // This represents the bulk of the space the formatter uses. + var ruleProvider = new ts.formatting.RulesProvider(); + ruleProvider.ensureUpToDate(options); + return ruleProvider; + } + function applyEdits(text, edits) { + // Apply edits in reverse on the existing text + var result = text; + for (var i = edits.length - 1; i >= 0; i--) { + var change = edits[i]; + var head = result.slice(0, change.span.start); + var tail = result.slice(change.span.start + change.span.length); + result = head + change.newText + tail; + } + return result; + } + function getDefaultOptions() { + return { + IndentSize: 4, + TabSize: 4, + NewLineCharacter: '\r\n', + ConvertTabsToSpaces: true, + IndentStyle: ts.IndentStyle.Block, + InsertSpaceAfterCommaDelimiter: true, + InsertSpaceAfterSemicolonInForStatements: true, + InsertSpaceBeforeAndAfterBinaryOperators: true, + InsertSpaceAfterKeywordsInControlFlowStatements: true, + InsertSpaceAfterFunctionKeywordForAnonymousFunctions: false, + InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false, + InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false, + InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: true, + PlaceOpenBraceOnNewLineForFunctions: false, + PlaceOpenBraceOnNewLineForControlBlocks: false, + }; + } +} +function createReplacer(data) { + data = data || ''; + var rawDirectives = data.split(';'); + var directives = []; + rawDirectives.forEach(function (rawDirective) { + if (rawDirective.length === 0) { + return; + } + var pieces = rawDirective.split('=>'); + var findStr = pieces[0]; + var replaceStr = pieces[1]; + findStr = findStr.replace(/[\-\\\{\}\*\+\?\|\^\$\.\,\[\]\(\)\#\s]/g, '\\$&'); + findStr = '\\b' + findStr + '\\b'; + directives.push([new RegExp(findStr, 'g'), replaceStr]); + }); + return function (str) { + for (var i = 0; i < directives.length; i++) { + str = str.replace(directives[i][0], directives[i][1]); + } + return str; + }; +} +function generateDeclarationFile(recipe) { + var lines = recipe.split(/\r\n|\n|\r/); + var result = []; + lines.forEach(function (line) { + var m1 = line.match(/^\s*#include\(([^;)]*)(;[^)]*)?\)\:(.*)$/); + if (m1) { + console.log('HANDLING META: ' + line); + var moduleId = m1[1]; + var sourceFile_1 = getSourceFile(moduleId); + var replacer_1 = createReplacer(m1[2]); + var typeNames = m1[3].split(/,/); + typeNames.forEach(function (typeName) { + typeName = typeName.trim(); + if (typeName.length === 0) { + return; + } + var declaration = getTopLevelDeclaration(sourceFile_1, typeName); + result.push(replacer_1(getMassagedTopLevelDeclarationText(sourceFile_1, declaration))); + }); + return; + } + var m2 = line.match(/^\s*#includeAll\(([^;)]*)(;[^)]*)?\)\:(.*)$/); + if (m2) { + console.log('HANDLING META: ' + line); + var moduleId = m2[1]; + var sourceFile_2 = getSourceFile(moduleId); + var replacer_2 = createReplacer(m2[2]); + var typeNames = m2[3].split(/,/); + var typesToExcludeMap_1 = {}; + var typesToExcludeArr_1 = []; + typeNames.forEach(function (typeName) { + typeName = typeName.trim(); + if (typeName.length === 0) { + return; + } + typesToExcludeMap_1[typeName] = true; + typesToExcludeArr_1.push(typeName); + }); + getAllTopLevelDeclarations(sourceFile_2).forEach(function (declaration) { + if (isDeclaration(declaration)) { + if (typesToExcludeMap_1[declaration.name.text]) { + return; + } + } + else { + // node is ts.VariableStatement + var nodeText = getNodeText(sourceFile_2, declaration); + for (var i = 0; i < typesToExcludeArr_1.length; i++) { + if (nodeText.indexOf(typesToExcludeArr_1[i]) >= 0) { + return; + } + } + } + result.push(replacer_2(getMassagedTopLevelDeclarationText(sourceFile_2, declaration))); + }); + return; + } + result.push(line); + }); + var resultTxt = result.join('\n'); + resultTxt = resultTxt.replace(/\bURI\b/g, 'Uri'); + resultTxt = resultTxt.replace(/\bEvent Have you compiled (gulp watch) with env variable VSCODE_BUILD_DECLARATION_FILES=1 ?'); - console.error('======================================================================'); + console.error('========================================================================='); + console.error('=> Have you compiled with env variable VSCODE_BUILD_DECLARATION_FILES=1 ?'); + console.error('========================================================================='); throw err; } @@ -347,9 +347,3 @@ let result = generateDeclarationFile(recipe); const DECLARATION_PATH = path.join(__dirname, '../../src/vs/monaco.d.ts'); fs.writeFileSync(DECLARATION_PATH, result); - -// let result = generateDeclarationFile - -// var recipe = fs.readFileSync(path.join(__dirname, './monaco-editor.d.ts.recipe')).toString(); - -// fs.writeFileSync(path.join(__dirname, './monaco-editor.d.ts'), resultTxt); diff --git a/build/monaco/package.json b/build/monaco/package.json new file mode 100644 index 0000000000000..03e2c47dfcd77 --- /dev/null +++ b/build/monaco/package.json @@ -0,0 +1,11 @@ +{ + "name": "monaco-editor-core", + "version": "0.2.1", + "description": "A browser based code editor", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "Microsoft Corporation", + "license": "MIT" +}