diff --git a/build/gulpfile.common.js b/build/gulpfile.common.js index 63faa9bcfe1..c3fb56583cd 100644 --- a/build/gulpfile.common.js +++ b/build/gulpfile.common.js @@ -39,13 +39,21 @@ exports.loaderConfig = function (emptyPaths) { const IS_OUR_COPYRIGHT_REGEXP = /Copyright \(C\) Microsoft Corporation/i; -function loader(bundledFileHeader) { +function loader(bundledFileHeader, bundleLoader) { + let sources = [ + 'out-build/vs/loader.js' + ]; + if (bundleLoader) { + sources = sources.concat([ + 'out-build/vs/css.js', + 'out-build/vs/nls.js' + ]); + } + let isFirst = true; - return gulp.src([ - 'out-build/vs/loader.js', - 'out-build/vs/css.js', - 'out-build/vs/nls.js' - ], { base: 'out-build' }) + return ( + gulp + .src(sources, { base: 'out-build' }) .pipe(es.through(function(data) { if (isFirst) { isFirst = false; @@ -64,7 +72,8 @@ function loader(bundledFileHeader) { .pipe(es.mapSync(function (f) { f.sourceMap.sourceRoot = util.toFileUri(path.join(path.dirname(__dirname), 'src')); return f; - })); + })) + ); } function toConcatStream(bundledFileHeader, sources, dest) { @@ -116,6 +125,7 @@ function toBundleStream(bundledFileHeader, bundles) { * - otherSources (for non-AMD files that should get Copyright treatment) * - resources (svg, etc.) * - loaderConfig + * - bundleLoader (boolean - true by default - append css and nls to loader) * - header (basically the Copyright treatment) * - bundleInfo (boolean - emit bundleInfo.json file) * - out (out folder name) @@ -126,6 +136,7 @@ exports.optimizeTask = function(opts) { const resources = opts.resources; const loaderConfig = opts.loaderConfig; const bundledFileHeader = opts.header; + const bundleLoader = (typeof opts.bundleLoader === 'undefined' ? true : opts.bundleLoader); const out = opts.out; return function() { @@ -174,7 +185,7 @@ exports.optimizeTask = function(opts) { })); const result = es.merge( - loader(bundledFileHeader), + loader(bundledFileHeader, bundleLoader), bundlesStream, otherSourcesStream, resourcesStream, diff --git a/build/gulpfile.editor.js b/build/gulpfile.editor.js index 99d6f0dfcca..2bddf8fcd8b 100644 --- a/build/gulpfile.editor.js +++ b/build/gulpfile.editor.js @@ -22,12 +22,15 @@ var editorEntryPoints = [ { name: 'vs/editor/editor.main', include: [], - exclude: [ 'vs/css', 'vs/nls' ] + exclude: [], + prepend: [ 'vs/css.js', 'vs/nls.js' ], }, { name: 'vs/base/common/worker/simpleWorker', include: [ 'vs/editor/common/services/editorSimpleWorker' ], - exclude: [ 'vs/css', 'vs/nls' ] + prepend: [ 'vs/loader.js' ], + append: [ 'vs/base/worker/workerMain' ], + dest: 'vs/base/worker/workerMain.js' }, ] @@ -37,14 +40,11 @@ var editorResources = [ '!out-build/vs/base/browser/ui/toolbar/**/*', '!out-build/vs/base/browser/ui/octiconLabel/**/*', '!out-build/vs/editor/contrib/defineKeybinding/**/*', - 'out-build/vs/base/worker/workerMain.{js,js.map}', '!out-build/vs/workbench/**', '!**/test/**' ]; var editorOtherSources = [ - 'out-build/vs/css.js', - 'out-build/vs/nls.js' ]; var BUNDLED_FILE_HEADER = [ @@ -75,6 +75,7 @@ gulp.task('optimize-editor', ['clean-optimized-editor', 'compile-build'], common otherSources: editorOtherSources, resources: editorResources, loaderConfig: editorLoaderConfig(), + bundleLoader: false, header: BUNDLED_FILE_HEADER, bundleInfo: true, out: 'out-editor' diff --git a/build/lib/bundle.js b/build/lib/bundle.js index cbc7e92e55d..9325d6d623f 100644 --- a/build/lib/bundle.js +++ b/build/lib/bundle.js @@ -31,6 +31,24 @@ function bundle(entryPoints, config, callback) { var loader = loaderModule.exports; config.isBuild = true; loader.config(config); + loader(['require'], function (localRequire) { + var resolvePath = function (path) { + var r = localRequire.toUrl(path); + if (!/\.js/.test(r)) { + return r + '.js'; + } + return r; + }; + for (var moduleId in entryPointsMap) { + var entryPoint = entryPointsMap[moduleId]; + if (entryPoint.append) { + entryPoint.append = entryPoint.append.map(resolvePath); + } + if (entryPoint.prepend) { + entryPoint.prepend = entryPoint.prepend.map(resolvePath); + } + } + }); loader(Object.keys(allMentionedModulesMap), function () { var modules = loader.getBuildInfo(); var partialResult = emitEntryPoints(modules, entryPointsMap); @@ -74,7 +92,7 @@ function emitEntryPoints(modules, entryPoints) { return allDependencies[module]; }); bundleData.bundles[moduleToBundle] = includedModules; - var res = emitEntryPoint(modulesMap, modulesGraph, moduleToBundle, includedModules); + var res = emitEntryPoint(modulesMap, modulesGraph, moduleToBundle, includedModules, info.prepend, info.append, info.dest); result = result.concat(res.files); for (var pluginName in res.usedPlugins) { usedPlugins[pluginName] = usedPlugins[pluginName] || res.usedPlugins[pluginName]; @@ -235,10 +253,13 @@ function removeDuplicateTSBoilerplate(destFiles) { }); return destFiles; } -function emitEntryPoint(modulesMap, deps, entryPoint, includedModules) { +function emitEntryPoint(modulesMap, deps, entryPoint, includedModules, prepend, append, dest) { + if (!dest) { + dest = entryPoint + '.js'; + } var mainResult = { sources: [], - dest: entryPoint + '.js' + dest: dest }, results = [mainResult]; var usedPlugins = {}; var getLoaderPlugin = function (pluginName) { @@ -286,6 +307,16 @@ function emitEntryPoint(modulesMap, deps, entryPoint, includedModules) { plugin.writeFile(pluginName, entryPoint, req, write, {}); } }); + var toIFile = function (path) { + var contents = readFileAndRemoveBOM(path); + return { + path: path, + contents: contents + }; + }; + var toPrepend = (prepend || []).map(toIFile); + var toAppend = (append || []).map(toIFile); + mainResult.sources = toPrepend.concat(mainResult.sources).concat(toAppend); return { files: results, usedPlugins: usedPlugins diff --git a/build/lib/bundle.ts b/build/lib/bundle.ts index bf500e5c92b..25fd2617448 100644 --- a/build/lib/bundle.ts +++ b/build/lib/bundle.ts @@ -46,6 +46,9 @@ export interface IEntryPoint { name: string; include: string[]; exclude: string[]; + prepend: string[]; + append: string[]; + dest: string; } interface IEntryPointMap { @@ -120,6 +123,25 @@ export function bundle(entryPoints:IEntryPoint[], config:ILoaderConfig, callback config.isBuild = true; loader.config(config); + loader(['require'], (localRequire) => { + let resolvePath = (path:string) => { + let r = localRequire.toUrl(path); + if (!/\.js/.test(r)) { + return r + '.js'; + } + return r; + }; + for (let moduleId in entryPointsMap) { + let entryPoint = entryPointsMap[moduleId]; + if (entryPoint.append) { + entryPoint.append = entryPoint.append.map(resolvePath); + } + if (entryPoint.prepend) { + entryPoint.prepend = entryPoint.prepend.map(resolvePath); + } + } + }); + loader(Object.keys(allMentionedModulesMap), () => { let modules = loader.getBuildInfo(); let partialResult = emitEntryPoints(modules, entryPointsMap); @@ -171,7 +193,15 @@ function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap) bundleData.bundles[moduleToBundle] = includedModules; - let res = emitEntryPoint(modulesMap, modulesGraph, moduleToBundle, includedModules); + let res = emitEntryPoint( + modulesMap, + modulesGraph, + moduleToBundle, + includedModules, + info.prepend, + info.append, + info.dest + ); result = result.concat(res.files); for (let pluginName in res.usedPlugins) { @@ -355,10 +385,21 @@ interface IEmitEntryPointResult { usedPlugins: IPluginMap; } -function emitEntryPoint(modulesMap:IBuildModuleInfoMap, deps:IGraph, entryPoint:string, includedModules:string[]): IEmitEntryPointResult { +function emitEntryPoint( + modulesMap:IBuildModuleInfoMap, + deps:IGraph, + entryPoint:string, + includedModules:string[], + prepend: string[], + append: string[], + dest: string +): IEmitEntryPointResult { + if (!dest) { + dest = entryPoint + '.js'; + } let mainResult: IConcatFile = { sources: [], - dest: entryPoint + '.js' + dest: dest }, results: IConcatFile[] = [mainResult]; @@ -416,6 +457,19 @@ function emitEntryPoint(modulesMap:IBuildModuleInfoMap, deps:IGraph, entryPoint: } }); + let toIFile = (path):IFile => { + let contents = readFileAndRemoveBOM(path); + return { + path: path, + contents: contents + }; + }; + + let toPrepend = (prepend||[]).map(toIFile); + let toAppend = (append||[]).map(toIFile); + + mainResult.sources = toPrepend.concat(mainResult.sources).concat(toAppend); + return { files: results, usedPlugins: usedPlugins diff --git a/build/monaco/package.json b/build/monaco/package.json index 53e240b2d0b..e9b918f6983 100644 --- a/build/monaco/package.json +++ b/build/monaco/package.json @@ -1,7 +1,7 @@ { "name": "monaco-editor-core", "private": true, - "version": "0.7.0-next.5", + "version": "0.7.1", "description": "A browser based code editor", "author": "Microsoft Corporation", "license": "MIT", diff --git a/src/vs/base/worker/workerMain.ts b/src/vs/base/worker/workerMain.ts index 461c9a52374..97dbf33fb41 100644 --- a/src/vs/base/worker/workerMain.ts +++ b/src/vs/base/worker/workerMain.ts @@ -9,7 +9,9 @@ let MonacoEnvironment = (self).MonacoEnvironment; let monacoBaseUrl = MonacoEnvironment && MonacoEnvironment.baseUrl ? MonacoEnvironment.baseUrl : '../../../'; - importScripts(monacoBaseUrl + 'vs/loader.js'); + if (typeof (self).define !== 'function' || !(self).define.amd) { + importScripts(monacoBaseUrl + 'vs/loader.js'); + } require.config({ baseUrl: monacoBaseUrl, diff --git a/src/vs/loader.js b/src/vs/loader.js index 49317011d21..0de79c30df7 100644 --- a/src/vs/loader.js +++ b/src/vs/loader.js @@ -1926,7 +1926,7 @@ var AMDLoader; RequireFunc.config(global.require); } if (!isElectronRenderer) { - global.define = DefineFunc; + global.define = define = DefineFunc; } else { define = function () {