break loader plugins into build and runtime version to keep the size low

This commit is contained in:
Johannes Rieken
2017-06-23 16:31:32 +02:00
parent 65ab56d1d6
commit c75389b974
10 changed files with 660 additions and 416 deletions
+3 -1
View File
@@ -98,9 +98,11 @@ const copyrightFilter = [
const eslintFilter = [
'src/**/*.js',
'!src/vs/css.js',
'!src/vs/loader.js',
'!src/vs/css.js',
'!src/vs/nls.js',
'!src/vs/css.build.js',
'!src/vs/nls.build.js',
'!src/**/winjs.base.raw.js',
'!src/**/raw.marked.js',
'!**/test/**'
+3
View File
@@ -31,6 +31,9 @@ function bundle(entryPoints, config, callback) {
r.call({}, require, loaderModule, loaderModule.exports);
var loader = loaderModule.exports;
config.isBuild = true;
config.paths = config.paths || {};
config.paths['vs/nls'] = 'out-build/vs/nls.build';
config.paths['vs/css'] = 'out-build/vs/css.build';
loader.config(config);
loader(['require'], function (localRequire) {
var resolvePath = function (path) {
+4
View File
@@ -91,6 +91,7 @@ interface IPartialBundleResult {
export interface ILoaderConfig {
isBuild?: boolean;
paths?: { [path: string]: any; };
}
/**
@@ -121,6 +122,9 @@ export function bundle(entryPoints: IEntryPoint[], config: ILoaderConfig, callba
var loader: any = loaderModule.exports;
config.isBuild = true;
config.paths = config.paths || {};
config.paths['vs/nls'] = 'out-build/vs/nls.build';
config.paths['vs/css'] = 'out-build/vs/css.build';
loader.config(config);
loader(['require'], (localRequire) => {
-1
View File
@@ -41,7 +41,6 @@ function createCompile(build, emitError) {
.pipe(tsFilter)
.pipe(util.loadSourcemaps())
.pipe(ts(token))
.pipe(build ? reloadTypeScriptNodeModule() : es.through())
.pipe(noDeclarationsFilter)
.pipe(build ? nls() : es.through())
.pipe(noDeclarationsFilter.restore)
+1 -1
View File
@@ -49,7 +49,7 @@ function createCompile(build: boolean, emitError?: boolean): (token?: util.ICanc
.pipe(tsFilter)
.pipe(util.loadSourcemaps())
.pipe(ts(token))
.pipe(build ? reloadTypeScriptNodeModule() : es.through())
// .pipe(build ? reloadTypeScriptNodeModule() : es.through())
.pipe(noDeclarationsFilter)
.pipe(build ? nls() : es.through())
.pipe(noDeclarationsFilter.restore)
+362
View File
@@ -0,0 +1,362 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
* Please make sure to make edits in the .ts file at https://github.com/Microsoft/vscode-loader/
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*--------------------------------------------------------------------------------------------*/
'use strict';
var _cssPluginGlobal = this;
var CSSBuildLoaderPlugin;
(function (CSSBuildLoaderPlugin) {
var global = _cssPluginGlobal || {};
/**
* Known issue:
* - In IE there is no way to know if the CSS file loaded successfully or not.
*/
var BrowserCSSLoader = (function () {
function BrowserCSSLoader() {
this._pendingLoads = 0;
}
BrowserCSSLoader.prototype.attachListeners = function (name, linkNode, callback, errorback) {
var unbind = function () {
linkNode.removeEventListener('load', loadEventListener);
linkNode.removeEventListener('error', errorEventListener);
};
var loadEventListener = function (e) {
unbind();
callback();
};
var errorEventListener = function (e) {
unbind();
errorback(e);
};
linkNode.addEventListener('load', loadEventListener);
linkNode.addEventListener('error', errorEventListener);
};
BrowserCSSLoader.prototype._onLoad = function (name, callback) {
this._pendingLoads--;
callback();
};
BrowserCSSLoader.prototype._onLoadError = function (name, errorback, err) {
this._pendingLoads--;
errorback(err);
};
BrowserCSSLoader.prototype._insertLinkNode = function (linkNode) {
this._pendingLoads++;
var head = document.head || document.getElementsByTagName('head')[0];
var other = head.getElementsByTagName('link') || document.head.getElementsByTagName('script');
if (other.length > 0) {
head.insertBefore(linkNode, other[other.length - 1]);
}
else {
head.appendChild(linkNode);
}
};
BrowserCSSLoader.prototype.createLinkTag = function (name, cssUrl, externalCallback, externalErrorback) {
var _this = this;
var linkNode = document.createElement('link');
linkNode.setAttribute('rel', 'stylesheet');
linkNode.setAttribute('type', 'text/css');
linkNode.setAttribute('data-name', name);
var callback = function () { return _this._onLoad(name, externalCallback); };
var errorback = function (err) { return _this._onLoadError(name, externalErrorback, err); };
this.attachListeners(name, linkNode, callback, errorback);
linkNode.setAttribute('href', cssUrl);
return linkNode;
};
BrowserCSSLoader.prototype._linkTagExists = function (name, cssUrl) {
var i, len, nameAttr, hrefAttr, links = document.getElementsByTagName('link');
for (i = 0, len = links.length; i < len; i++) {
nameAttr = links[i].getAttribute('data-name');
hrefAttr = links[i].getAttribute('href');
if (nameAttr === name || hrefAttr === cssUrl) {
return true;
}
}
return false;
};
BrowserCSSLoader.prototype.load = function (name, cssUrl, externalCallback, externalErrorback) {
if (this._linkTagExists(name, cssUrl)) {
externalCallback();
return;
}
var linkNode = this.createLinkTag(name, cssUrl, externalCallback, externalErrorback);
this._insertLinkNode(linkNode);
};
return BrowserCSSLoader;
}());
var NodeCSSLoader = (function () {
function NodeCSSLoader() {
this.fs = require.nodeRequire('fs');
}
NodeCSSLoader.prototype.load = function (name, cssUrl, externalCallback, externalErrorback) {
var contents = this.fs.readFileSync(cssUrl, 'utf8');
// Remove BOM
if (contents.charCodeAt(0) === NodeCSSLoader.BOM_CHAR_CODE) {
contents = contents.substring(1);
}
externalCallback(contents);
};
return NodeCSSLoader;
}());
NodeCSSLoader.BOM_CHAR_CODE = 65279;
// ------------------------------ Finally, the plugin
var CSSPlugin = (function () {
function CSSPlugin(cssLoader) {
this.cssLoader = cssLoader;
}
CSSPlugin.prototype.load = function (name, req, load, config) {
config = config || {};
var myConfig = config['vs/css'] || {};
global.inlineResources = myConfig.inlineResources;
global.inlineResourcesLimit = myConfig.inlineResourcesLimit || 5000;
var cssUrl = req.toUrl(name + '.css');
this.cssLoader.load(name, cssUrl, function (contents) {
// Contents has the CSS file contents if we are in a build
if (config.isBuild) {
CSSPlugin.BUILD_MAP[name] = contents;
CSSPlugin.BUILD_PATH_MAP[name] = cssUrl;
}
load({});
}, function (err) {
if (typeof load.error === 'function') {
load.error('Could not find ' + cssUrl + ' or it was empty');
}
});
};
CSSPlugin.prototype.write = function (pluginName, moduleName, write) {
// getEntryPoint is a Monaco extension to r.js
var entryPoint = write.getEntryPoint();
// r.js destroys the context of this plugin between calling 'write' and 'writeFile'
// so the only option at this point is to leak the data to a global
global.cssPluginEntryPoints = global.cssPluginEntryPoints || {};
global.cssPluginEntryPoints[entryPoint] = global.cssPluginEntryPoints[entryPoint] || [];
global.cssPluginEntryPoints[entryPoint].push({
moduleName: moduleName,
contents: CSSPlugin.BUILD_MAP[moduleName],
fsPath: CSSPlugin.BUILD_PATH_MAP[moduleName],
});
write.asModule(pluginName + '!' + moduleName, 'define([\'vs/css!' + entryPoint + '\'], {});');
};
CSSPlugin.prototype.writeFile = function (pluginName, moduleName, req, write, config) {
if (global.cssPluginEntryPoints && global.cssPluginEntryPoints.hasOwnProperty(moduleName)) {
var fileName = req.toUrl(moduleName + '.css');
var contents = [
'/*---------------------------------------------------------',
' * Copyright (c) Microsoft Corporation. All rights reserved.',
' *--------------------------------------------------------*/'
], entries = global.cssPluginEntryPoints[moduleName];
for (var i = 0; i < entries.length; i++) {
if (global.inlineResources) {
contents.push(Utilities.rewriteOrInlineUrls(entries[i].fsPath, entries[i].moduleName, moduleName, entries[i].contents, global.inlineResources === 'base64', global.inlineResourcesLimit));
}
else {
contents.push(Utilities.rewriteUrls(entries[i].moduleName, moduleName, entries[i].contents));
}
}
write(fileName, contents.join('\r\n'));
}
};
CSSPlugin.prototype.getInlinedResources = function () {
return global.cssInlinedResources || [];
};
return CSSPlugin;
}());
CSSPlugin.BUILD_MAP = {};
CSSPlugin.BUILD_PATH_MAP = {};
CSSBuildLoaderPlugin.CSSPlugin = CSSPlugin;
var Utilities = (function () {
function Utilities() {
}
Utilities.startsWith = function (haystack, needle) {
return haystack.length >= needle.length && haystack.substr(0, needle.length) === needle;
};
/**
* Find the path of a file.
*/
Utilities.pathOf = function (filename) {
var lastSlash = filename.lastIndexOf('/');
if (lastSlash !== -1) {
return filename.substr(0, lastSlash + 1);
}
else {
return '';
}
};
/**
* A conceptual a + b for paths.
* Takes into account if `a` contains a protocol.
* Also normalizes the result: e.g.: a/b/ + ../c => a/c
*/
Utilities.joinPaths = function (a, b) {
function findSlashIndexAfterPrefix(haystack, prefix) {
if (Utilities.startsWith(haystack, prefix)) {
return Math.max(prefix.length, haystack.indexOf('/', prefix.length));
}
return 0;
}
var aPathStartIndex = 0;
aPathStartIndex = aPathStartIndex || findSlashIndexAfterPrefix(a, '//');
aPathStartIndex = aPathStartIndex || findSlashIndexAfterPrefix(a, 'http://');
aPathStartIndex = aPathStartIndex || findSlashIndexAfterPrefix(a, 'https://');
function pushPiece(pieces, piece) {
if (piece === './') {
// Ignore
return;
}
if (piece === '../') {
var prevPiece = (pieces.length > 0 ? pieces[pieces.length - 1] : null);
if (prevPiece && prevPiece === '/') {
// Ignore
return;
}
if (prevPiece && prevPiece !== '../') {
// Pop
pieces.pop();
return;
}
}
// Push
pieces.push(piece);
}
function push(pieces, path) {
while (path.length > 0) {
var slashIndex = path.indexOf('/');
var piece = (slashIndex >= 0 ? path.substring(0, slashIndex + 1) : path);
path = (slashIndex >= 0 ? path.substring(slashIndex + 1) : '');
pushPiece(pieces, piece);
}
}
var pieces = [];
push(pieces, a.substr(aPathStartIndex));
if (b.length > 0 && b.charAt(0) === '/') {
pieces = [];
}
push(pieces, b);
return a.substring(0, aPathStartIndex) + pieces.join('');
};
Utilities.commonPrefix = function (str1, str2) {
var len = Math.min(str1.length, str2.length);
for (var i = 0; i < len; i++) {
if (str1.charCodeAt(i) !== str2.charCodeAt(i)) {
break;
}
}
return str1.substring(0, i);
};
Utilities.commonFolderPrefix = function (fromPath, toPath) {
var prefix = Utilities.commonPrefix(fromPath, toPath);
var slashIndex = prefix.lastIndexOf('/');
if (slashIndex === -1) {
return '';
}
return prefix.substring(0, slashIndex + 1);
};
Utilities.relativePath = function (fromPath, toPath) {
if (Utilities.startsWith(toPath, '/') || Utilities.startsWith(toPath, 'http://') || Utilities.startsWith(toPath, 'https://')) {
return toPath;
}
// Ignore common folder prefix
var prefix = Utilities.commonFolderPrefix(fromPath, toPath);
fromPath = fromPath.substr(prefix.length);
toPath = toPath.substr(prefix.length);
var upCount = fromPath.split('/').length;
var result = '';
for (var i = 1; i < upCount; i++) {
result += '../';
}
return result + toPath;
};
Utilities._replaceURL = function (contents, replacer) {
// Use ")" as the terminator as quotes are oftentimes not used at all
return contents.replace(/url\(\s*([^\)]+)\s*\)?/g, function (_) {
var matches = [];
for (var _i = 1; _i < arguments.length; _i++) {
matches[_i - 1] = arguments[_i];
}
var url = matches[0];
// Eliminate starting quotes (the initial whitespace is not captured)
if (url.charAt(0) === '"' || url.charAt(0) === '\'') {
url = url.substring(1);
}
// The ending whitespace is captured
while (url.length > 0 && (url.charAt(url.length - 1) === ' ' || url.charAt(url.length - 1) === '\t')) {
url = url.substring(0, url.length - 1);
}
// Eliminate ending quotes
if (url.charAt(url.length - 1) === '"' || url.charAt(url.length - 1) === '\'') {
url = url.substring(0, url.length - 1);
}
if (!Utilities.startsWith(url, 'data:') && !Utilities.startsWith(url, 'http://') && !Utilities.startsWith(url, 'https://')) {
url = replacer(url);
}
return 'url(' + url + ')';
});
};
Utilities.rewriteUrls = function (originalFile, newFile, contents) {
return this._replaceURL(contents, function (url) {
var absoluteUrl = Utilities.joinPaths(Utilities.pathOf(originalFile), url);
return Utilities.relativePath(newFile, absoluteUrl);
});
};
Utilities.rewriteOrInlineUrls = function (originalFileFSPath, originalFile, newFile, contents, forceBase64, inlineByteLimit) {
var fs = require.nodeRequire('fs');
var path = require.nodeRequire('path');
return this._replaceURL(contents, function (url) {
if (/\.(svg|png)$/.test(url)) {
var fsPath = path.join(path.dirname(originalFileFSPath), url);
var fileContents = fs.readFileSync(fsPath);
if (fileContents.length < inlineByteLimit) {
global.cssInlinedResources = global.cssInlinedResources || [];
var normalizedFSPath = fsPath.replace(/\\/g, '/');
if (global.cssInlinedResources.indexOf(normalizedFSPath) >= 0) {
console.warn('CSS INLINING IMAGE AT ' + fsPath + ' MORE THAN ONCE. CONSIDER CONSOLIDATING CSS RULES');
}
global.cssInlinedResources.push(normalizedFSPath);
var MIME = /\.svg$/.test(url) ? 'image/svg+xml' : 'image/png';
var DATA = ';base64,' + fileContents.toString('base64');
if (!forceBase64 && /\.svg$/.test(url)) {
// .svg => url encode as explained at https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
var newText = fileContents.toString()
.replace(/"/g, '\'')
.replace(/</g, '%3C')
.replace(/>/g, '%3E')
.replace(/&/g, '%26')
.replace(/#/g, '%23')
.replace(/\s+/g, ' ');
var encodedData = ',' + newText;
if (encodedData.length < DATA.length) {
DATA = encodedData;
}
}
return '"data:' + MIME + DATA + '"';
}
}
var absoluteUrl = Utilities.joinPaths(Utilities.pathOf(originalFile), url);
return Utilities.relativePath(newFile, absoluteUrl);
});
};
return Utilities;
}());
CSSBuildLoaderPlugin.Utilities = Utilities;
(function () {
var cssLoader = null;
var isElectron = (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions['electron'] !== 'undefined');
if (typeof process !== 'undefined' && process.versions && !!process.versions.node && !isElectron) {
cssLoader = new NodeCSSLoader();
}
else {
cssLoader = new BrowserCSSLoader();
}
define('vs/css', new CSSPlugin(cssLoader));
})();
})(CSSBuildLoaderPlugin || (CSSBuildLoaderPlugin = {}));
+12 -253
View File
@@ -14,10 +14,8 @@
*---------------------------------------------------------------------------------------------
*--------------------------------------------------------------------------------------------*/
'use strict';
var _cssPluginGlobal = this;
var CSSLoaderPlugin;
(function (CSSLoaderPlugin) {
var global = _cssPluginGlobal || {};
/**
* Known issue:
* - In IE there is no way to know if the CSS file loaded successfully or not.
@@ -94,38 +92,14 @@ var CSSLoaderPlugin;
};
return BrowserCSSLoader;
}());
var NodeCSSLoader = (function () {
function NodeCSSLoader() {
this.fs = require.nodeRequire('fs');
}
NodeCSSLoader.prototype.load = function (name, cssUrl, externalCallback, externalErrorback) {
var contents = this.fs.readFileSync(cssUrl, 'utf8');
// Remove BOM
if (contents.charCodeAt(0) === NodeCSSLoader.BOM_CHAR_CODE) {
contents = contents.substring(1);
}
externalCallback(contents);
};
return NodeCSSLoader;
}());
NodeCSSLoader.BOM_CHAR_CODE = 65279;
// ------------------------------ Finally, the plugin
var CSSPlugin = (function () {
function CSSPlugin(cssLoader) {
this.cssLoader = cssLoader;
function CSSPlugin() {
this._cssLoader = new BrowserCSSLoader();
}
CSSPlugin.prototype.load = function (name, req, load, config) {
config = config || {};
var myConfig = config['vs/css'] || {};
global.inlineResources = myConfig.inlineResources;
global.inlineResourcesLimit = myConfig.inlineResourcesLimit || 5000;
CSSPlugin.prototype.load = function (name, req, load) {
var cssUrl = req.toUrl(name + '.css');
this.cssLoader.load(name, cssUrl, function (contents) {
// Contents has the CSS file contents if we are in a build
if (config.isBuild) {
CSSPlugin.BUILD_MAP[name] = contents;
CSSPlugin.BUILD_PATH_MAP[name] = cssUrl;
}
this._cssLoader.load(name, cssUrl, function (contents) {
load({});
}, function (err) {
if (typeof load.error === 'function') {
@@ -133,230 +107,15 @@ var CSSLoaderPlugin;
}
});
};
CSSPlugin.prototype.write = function (pluginName, moduleName, write) {
// getEntryPoint is a Monaco extension to r.js
var entryPoint = write.getEntryPoint();
// r.js destroys the context of this plugin between calling 'write' and 'writeFile'
// so the only option at this point is to leak the data to a global
global.cssPluginEntryPoints = global.cssPluginEntryPoints || {};
global.cssPluginEntryPoints[entryPoint] = global.cssPluginEntryPoints[entryPoint] || [];
global.cssPluginEntryPoints[entryPoint].push({
moduleName: moduleName,
contents: CSSPlugin.BUILD_MAP[moduleName],
fsPath: CSSPlugin.BUILD_PATH_MAP[moduleName],
});
write.asModule(pluginName + '!' + moduleName, 'define([\'vs/css!' + entryPoint + '\'], {});');
};
CSSPlugin.prototype.writeFile = function (pluginName, moduleName, req, write, config) {
if (global.cssPluginEntryPoints && global.cssPluginEntryPoints.hasOwnProperty(moduleName)) {
var fileName = req.toUrl(moduleName + '.css');
var contents = [
'/*---------------------------------------------------------',
' * Copyright (c) Microsoft Corporation. All rights reserved.',
' *--------------------------------------------------------*/'
], entries = global.cssPluginEntryPoints[moduleName];
for (var i = 0; i < entries.length; i++) {
if (global.inlineResources) {
contents.push(Utilities.rewriteOrInlineUrls(entries[i].fsPath, entries[i].moduleName, moduleName, entries[i].contents, global.inlineResources === 'base64', global.inlineResourcesLimit));
}
else {
contents.push(Utilities.rewriteUrls(entries[i].moduleName, moduleName, entries[i].contents));
}
}
write(fileName, contents.join('\r\n'));
}
};
CSSPlugin.prototype.getInlinedResources = function () {
return global.cssInlinedResources || [];
};
return CSSPlugin;
}());
CSSPlugin.BUILD_MAP = {};
CSSPlugin.BUILD_PATH_MAP = {};
CSSLoaderPlugin.CSSPlugin = CSSPlugin;
var Utilities = (function () {
function Utilities() {
}
Utilities.startsWith = function (haystack, needle) {
return haystack.length >= needle.length && haystack.substr(0, needle.length) === needle;
};
/**
* Find the path of a file.
*/
Utilities.pathOf = function (filename) {
var lastSlash = filename.lastIndexOf('/');
if (lastSlash !== -1) {
return filename.substr(0, lastSlash + 1);
}
else {
return '';
}
};
/**
* A conceptual a + b for paths.
* Takes into account if `a` contains a protocol.
* Also normalizes the result: e.g.: a/b/ + ../c => a/c
*/
Utilities.joinPaths = function (a, b) {
function findSlashIndexAfterPrefix(haystack, prefix) {
if (Utilities.startsWith(haystack, prefix)) {
return Math.max(prefix.length, haystack.indexOf('/', prefix.length));
}
return 0;
}
var aPathStartIndex = 0;
aPathStartIndex = aPathStartIndex || findSlashIndexAfterPrefix(a, '//');
aPathStartIndex = aPathStartIndex || findSlashIndexAfterPrefix(a, 'http://');
aPathStartIndex = aPathStartIndex || findSlashIndexAfterPrefix(a, 'https://');
function pushPiece(pieces, piece) {
if (piece === './') {
// Ignore
return;
}
if (piece === '../') {
var prevPiece = (pieces.length > 0 ? pieces[pieces.length - 1] : null);
if (prevPiece && prevPiece === '/') {
// Ignore
return;
}
if (prevPiece && prevPiece !== '../') {
// Pop
pieces.pop();
return;
}
}
// Push
pieces.push(piece);
}
function push(pieces, path) {
while (path.length > 0) {
var slashIndex = path.indexOf('/');
var piece = (slashIndex >= 0 ? path.substring(0, slashIndex + 1) : path);
path = (slashIndex >= 0 ? path.substring(slashIndex + 1) : '');
pushPiece(pieces, piece);
}
}
var pieces = [];
push(pieces, a.substr(aPathStartIndex));
if (b.length > 0 && b.charAt(0) === '/') {
pieces = [];
}
push(pieces, b);
return a.substring(0, aPathStartIndex) + pieces.join('');
};
Utilities.commonPrefix = function (str1, str2) {
var len = Math.min(str1.length, str2.length);
for (var i = 0; i < len; i++) {
if (str1.charCodeAt(i) !== str2.charCodeAt(i)) {
break;
}
}
return str1.substring(0, i);
};
Utilities.commonFolderPrefix = function (fromPath, toPath) {
var prefix = Utilities.commonPrefix(fromPath, toPath);
var slashIndex = prefix.lastIndexOf('/');
if (slashIndex === -1) {
return '';
}
return prefix.substring(0, slashIndex + 1);
};
Utilities.relativePath = function (fromPath, toPath) {
if (Utilities.startsWith(toPath, '/') || Utilities.startsWith(toPath, 'http://') || Utilities.startsWith(toPath, 'https://')) {
return toPath;
}
// Ignore common folder prefix
var prefix = Utilities.commonFolderPrefix(fromPath, toPath);
fromPath = fromPath.substr(prefix.length);
toPath = toPath.substr(prefix.length);
var upCount = fromPath.split('/').length;
var result = '';
for (var i = 1; i < upCount; i++) {
result += '../';
}
return result + toPath;
};
Utilities._replaceURL = function (contents, replacer) {
// Use ")" as the terminator as quotes are oftentimes not used at all
return contents.replace(/url\(\s*([^\)]+)\s*\)?/g, function (_) {
var matches = [];
for (var _i = 1; _i < arguments.length; _i++) {
matches[_i - 1] = arguments[_i];
}
var url = matches[0];
// Eliminate starting quotes (the initial whitespace is not captured)
if (url.charAt(0) === '"' || url.charAt(0) === '\'') {
url = url.substring(1);
}
// The ending whitespace is captured
while (url.length > 0 && (url.charAt(url.length - 1) === ' ' || url.charAt(url.length - 1) === '\t')) {
url = url.substring(0, url.length - 1);
}
// Eliminate ending quotes
if (url.charAt(url.length - 1) === '"' || url.charAt(url.length - 1) === '\'') {
url = url.substring(0, url.length - 1);
}
if (!Utilities.startsWith(url, 'data:') && !Utilities.startsWith(url, 'http://') && !Utilities.startsWith(url, 'https://')) {
url = replacer(url);
}
return 'url(' + url + ')';
});
};
Utilities.rewriteUrls = function (originalFile, newFile, contents) {
return this._replaceURL(contents, function (url) {
var absoluteUrl = Utilities.joinPaths(Utilities.pathOf(originalFile), url);
return Utilities.relativePath(newFile, absoluteUrl);
});
};
Utilities.rewriteOrInlineUrls = function (originalFileFSPath, originalFile, newFile, contents, forceBase64, inlineByteLimit) {
var fs = require.nodeRequire('fs');
var path = require.nodeRequire('path');
return this._replaceURL(contents, function (url) {
if (/\.(svg|png)$/.test(url)) {
var fsPath = path.join(path.dirname(originalFileFSPath), url);
var fileContents = fs.readFileSync(fsPath);
if (fileContents.length < inlineByteLimit) {
global.cssInlinedResources = global.cssInlinedResources || [];
var normalizedFSPath = fsPath.replace(/\\/g, '/');
if (global.cssInlinedResources.indexOf(normalizedFSPath) >= 0) {
console.warn('CSS INLINING IMAGE AT ' + fsPath + ' MORE THAN ONCE. CONSIDER CONSOLIDATING CSS RULES');
}
global.cssInlinedResources.push(normalizedFSPath);
var MIME = /\.svg$/.test(url) ? 'image/svg+xml' : 'image/png';
var DATA = ';base64,' + fileContents.toString('base64');
if (!forceBase64 && /\.svg$/.test(url)) {
// .svg => url encode as explained at https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
var newText = fileContents.toString()
.replace(/"/g, '\'')
.replace(/</g, '%3C')
.replace(/>/g, '%3E')
.replace(/&/g, '%26')
.replace(/#/g, '%23')
.replace(/\s+/g, ' ');
var encodedData = ',' + newText;
if (encodedData.length < DATA.length) {
DATA = encodedData;
}
}
return '"data:' + MIME + DATA + '"';
}
}
var absoluteUrl = Utilities.joinPaths(Utilities.pathOf(originalFile), url);
return Utilities.relativePath(newFile, absoluteUrl);
});
};
return Utilities;
}());
CSSLoaderPlugin.Utilities = Utilities;
(function () {
var cssLoader = null;
var isElectron = (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions['electron'] !== 'undefined');
if (typeof process !== 'undefined' && process.versions && !!process.versions.node && !isElectron) {
cssLoader = new NodeCSSLoader();
}
else {
cssLoader = new BrowserCSSLoader();
}
define('vs/css', new CSSPlugin(cssLoader));
})();
function init() {
define('vs/css', new CSSPlugin());
}
CSSLoaderPlugin.init = init;
;
if (typeof doNotInitLoader === 'undefined') {
init();
}
})(CSSLoaderPlugin || (CSSLoaderPlugin = {}));
+49 -53
View File
@@ -1,23 +1,23 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
* Please make sure to make edits in the .ts file at https://github.com/Microsoft/vscode-loader/
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*--------------------------------------------------------------------------------------------*/
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
* Please make sure to make edits in the .ts file at https://github.com/Microsoft/vscode-loader/
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*--------------------------------------------------------------------------------------------*/
var _amdLoaderGlobal = this;
var AMDLoader;
(function (AMDLoader) {
@@ -53,9 +53,9 @@ var AMDLoader;
AMDLoader.Environment = Environment;
})(AMDLoader || (AMDLoader = {}));
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var AMDLoader;
(function (AMDLoader) {
var LoaderEventType;
@@ -108,9 +108,9 @@ var AMDLoader;
AMDLoader.NullLoaderEventRecorder = NullLoaderEventRecorder;
})(AMDLoader || (AMDLoader = {}));
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var AMDLoader;
(function (AMDLoader) {
var Utilities = (function () {
@@ -207,9 +207,9 @@ var AMDLoader;
AMDLoader.Utilities = Utilities;
})(AMDLoader || (AMDLoader = {}));
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var AMDLoader;
(function (AMDLoader) {
var ConfigurationOptionsUtil = (function () {
@@ -522,9 +522,9 @@ var AMDLoader;
AMDLoader.Configuration = Configuration;
})(AMDLoader || (AMDLoader = {}));
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var AMDLoader;
(function (AMDLoader) {
/**
@@ -782,17 +782,15 @@ var AMDLoader;
errorCode: 'cachedDataRejected',
path: cachedDataPath
});
NodeScriptLoader._runSoon(function () {
return _this._fs.unlink(cachedDataPath, function (err) {
if (err) {
moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
errorCode: 'unlink',
path: cachedDataPath,
detail: err
});
}
});
}, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
NodeScriptLoader._runSoon(function () { return _this._fs.unlink(cachedDataPath, function (err) {
if (err) {
moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
errorCode: 'unlink',
path: cachedDataPath,
detail: err
});
}
}); }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
}
else if (script.cachedDataProduced) {
// data produced => tell outside world
@@ -801,17 +799,15 @@ var AMDLoader;
length: script.cachedData.length
});
// data produced => write cache file
NodeScriptLoader._runSoon(function () {
return _this._fs.writeFile(cachedDataPath, script.cachedData, function (err) {
if (err) {
moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
errorCode: 'writeFile',
path: cachedDataPath,
detail: err
});
}
});
}, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
NodeScriptLoader._runSoon(function () { return _this._fs.writeFile(cachedDataPath, script.cachedData, function (err) {
if (err) {
moduleManager.getConfig().getOptionsLiteral().onNodeCachedData({
errorCode: 'writeFile',
path: cachedDataPath,
detail: err
});
}
}); }, moduleManager.getConfig().getOptionsLiteral().nodeCachedDataWriteDelay);
}
};
NodeScriptLoader._runSoon = function (callback, minTimeout) {
@@ -831,9 +827,9 @@ var AMDLoader;
AMDLoader.createScriptLoader = createScriptLoader;
})(AMDLoader || (AMDLoader = {}));
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var AMDLoader;
(function (AMDLoader) {
// ------------------------------------------------------------------------
+182
View File
@@ -0,0 +1,182 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
* Please make sure to make edits in the .ts file at https://github.com/Microsoft/vscode-loader/
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*---------------------------------------------------------------------------------------------
*--------------------------------------------------------------------------------------------*/
'use strict';
var _nlsPluginGlobal = this;
var NLSBuildLoaderPlugin;
(function (NLSBuildLoaderPlugin) {
var global = _nlsPluginGlobal || {};
var Resources = global.Plugin && global.Plugin.Resources ? global.Plugin.Resources : undefined;
var IS_PSEUDO = (global && global.document && global.document.location && global.document.location.hash.indexOf('pseudo=true') >= 0);
function _format(message, args) {
var result;
if (args.length === 0) {
result = message;
}
else {
result = message.replace(/\{(\d+)\}/g, function (match, rest) {
var index = rest[0];
return typeof args[index] !== 'undefined' ? args[index] : match;
});
}
if (IS_PSEUDO) {
// FF3B and FF3D is the Unicode zenkaku representation for [ and ]
result = '\uFF3B' + result.replace(/[aouei]/g, '$&$&') + '\uFF3D';
}
return result;
}
function findLanguageForModule(config, name) {
var result = config[name];
if (result)
return result;
result = config['*'];
if (result)
return result;
return null;
}
function localize(data, message) {
var args = [];
for (var _i = 0; _i < (arguments.length - 2); _i++) {
args[_i] = arguments[_i + 2];
}
return _format(message, args);
}
function createScopedLocalize(scope) {
return function (idx, defaultValue) {
var restArgs = Array.prototype.slice.call(arguments, 2);
return _format(scope[idx], restArgs);
};
}
var NLSPlugin = (function () {
function NLSPlugin() {
this.localize = localize;
}
NLSPlugin.prototype.setPseudoTranslation = function (value) {
IS_PSEUDO = value;
};
NLSPlugin.prototype.create = function (key, data) {
return {
localize: createScopedLocalize(data[key])
};
};
NLSPlugin.prototype.load = function (name, req, load, config) {
config = config || {};
if (!name || name.length === 0) {
load({
localize: localize
});
}
else {
var suffix = void 0;
if (Resources && Resources.getString) {
suffix = '.nls.keys';
req([name + suffix], function (keyMap) {
load({
localize: function (moduleKey, index) {
if (!keyMap[moduleKey])
return 'NLS error: unknown key ' + moduleKey;
var mk = keyMap[moduleKey].keys;
if (index >= mk.length)
return 'NLS error unknow index ' + index;
var subKey = mk[index];
var args = [];
args[0] = moduleKey + '_' + subKey;
for (var _i = 0; _i < (arguments.length - 2); _i++) {
args[_i + 1] = arguments[_i + 2];
}
return Resources.getString.apply(Resources, args);
}
});
});
}
else {
if (config.isBuild) {
req([name + '.nls', name + '.nls.keys'], function (messages, keys) {
NLSPlugin.BUILD_MAP[name] = messages;
NLSPlugin.BUILD_MAP_KEYS[name] = keys;
load(messages);
});
}
else {
var pluginConfig = config['vs/nls'] || {};
var language = pluginConfig.availableLanguages ? findLanguageForModule(pluginConfig.availableLanguages, name) : null;
suffix = '.nls';
if (language !== null && language !== NLSPlugin.DEFAULT_TAG) {
suffix = suffix + '.' + language;
}
req([name + suffix], function (messages) {
if (Array.isArray(messages)) {
messages.localize = createScopedLocalize(messages);
}
else {
messages.localize = createScopedLocalize(messages[name]);
}
load(messages);
});
}
}
}
};
NLSPlugin.prototype._getEntryPointsMap = function () {
global.nlsPluginEntryPoints = global.nlsPluginEntryPoints || {};
return global.nlsPluginEntryPoints;
};
NLSPlugin.prototype.write = function (pluginName, moduleName, write) {
// getEntryPoint is a Monaco extension to r.js
var entryPoint = write.getEntryPoint();
// r.js destroys the context of this plugin between calling 'write' and 'writeFile'
// so the only option at this point is to leak the data to a global
var entryPointsMap = this._getEntryPointsMap();
entryPointsMap[entryPoint] = entryPointsMap[entryPoint] || [];
entryPointsMap[entryPoint].push(moduleName);
if (moduleName !== entryPoint) {
write.asModule(pluginName + '!' + moduleName, 'define([\'vs/nls\', \'vs/nls!' + entryPoint + '\'], function(nls, data) { return nls.create("' + moduleName + '", data); });');
}
};
NLSPlugin.prototype.writeFile = function (pluginName, moduleName, req, write, config) {
var entryPointsMap = this._getEntryPointsMap();
if (entryPointsMap.hasOwnProperty(moduleName)) {
var fileName = req.toUrl(moduleName + '.nls.js');
var contents = [
'/*---------------------------------------------------------',
' * Copyright (c) Microsoft Corporation. All rights reserved.',
' *--------------------------------------------------------*/'
], entries = entryPointsMap[moduleName];
var data = {};
for (var i = 0; i < entries.length; i++) {
data[entries[i]] = NLSPlugin.BUILD_MAP[entries[i]];
}
contents.push('define("' + moduleName + '.nls", ' + JSON.stringify(data, null, '\t') + ');');
write(fileName, contents.join('\r\n'));
}
};
NLSPlugin.prototype.finishBuild = function (write) {
write('nls.metadata.json', JSON.stringify({
keys: NLSPlugin.BUILD_MAP_KEYS,
messages: NLSPlugin.BUILD_MAP,
bundles: this._getEntryPointsMap()
}, null, '\t'));
};
;
return NLSPlugin;
}());
NLSPlugin.DEFAULT_TAG = 'i-default';
NLSPlugin.BUILD_MAP = {};
NLSPlugin.BUILD_MAP_KEYS = {};
NLSBuildLoaderPlugin.NLSPlugin = NLSPlugin;
(function () {
define('vs/nls', new NLSPlugin());
})();
})(NLSBuildLoaderPlugin || (NLSBuildLoaderPlugin = {}));
+44 -107
View File
@@ -14,15 +14,20 @@
*---------------------------------------------------------------------------------------------
*--------------------------------------------------------------------------------------------*/
'use strict';
var _nlsPluginGlobal = this;
var NLSLoaderPlugin;
(function (NLSLoaderPlugin) {
var global = _nlsPluginGlobal || {};
var Resources = global.Plugin && global.Plugin.Resources ? global.Plugin.Resources : undefined;
var DEFAULT_TAG = 'i-default';
var IS_PSEUDO = (global && global.document && global.document.location && global.document.location.hash.indexOf('pseudo=true') >= 0);
var slice = Array.prototype.slice;
function _format(message, args) {
var Environment = (function () {
function Environment(isPseudo) {
this.isPseudo = isPseudo;
//
}
Environment.detect = function () {
var isPseudo = (typeof document !== 'undefined' && document.location && document.location.hash.indexOf('pseudo=true') >= 0);
return new Environment(isPseudo);
};
return Environment;
}());
function _format(message, args, env) {
var result;
if (args.length === 0) {
result = message;
@@ -33,7 +38,7 @@ var NLSLoaderPlugin;
return typeof args[index] !== 'undefined' ? args[index] : match;
});
}
if (IS_PSEUDO) {
if (env.isPseudo) {
// FF3B and FF3D is the Unicode zenkaku representation for [ and ]
result = '\uFF3B' + result.replace(/[aouei]/g, '$&$&') + '\uFF3D';
}
@@ -48,32 +53,35 @@ var NLSLoaderPlugin;
return result;
return null;
}
function localize(data, message) {
function localize(data, message, env) {
var args = [];
for (var _i = 0; _i < (arguments.length - 2); _i++) {
args[_i] = arguments[_i + 2];
}
return _format(message, args);
return _format(message, args, env);
}
function createScopedLocalize(scope) {
function createScopedLocalize(scope, env) {
return function (idx, defaultValue) {
var restArgs = slice.call(arguments, 2);
return _format(scope[idx], restArgs);
var restArgs = Array.prototype.slice.call(arguments, 2);
return _format(scope[idx], restArgs, env);
};
}
var NLSPlugin = (function () {
function NLSPlugin() {
this.localize = localize;
function NLSPlugin(env) {
var _this = this;
this._env = env;
this.localize = function (data, message) { return localize(data, message, _this._env); };
}
NLSPlugin.prototype.setPseudoTranslation = function (value) {
IS_PSEUDO = value;
this._env = new Environment(value);
};
NLSPlugin.prototype.create = function (key, data) {
return {
localize: createScopedLocalize(data[key])
localize: createScopedLocalize(data[key], this._env)
};
};
NLSPlugin.prototype.load = function (name, req, load, config) {
var _this = this;
config = config || {};
if (!name || name.length === 0) {
load({
@@ -81,103 +89,32 @@ var NLSLoaderPlugin;
});
}
else {
var suffix = void 0;
if (Resources && Resources.getString) {
suffix = '.nls.keys';
req([name + suffix], function (keyMap) {
load({
localize: function (moduleKey, index) {
if (!keyMap[moduleKey])
return 'NLS error: unknown key ' + moduleKey;
var mk = keyMap[moduleKey].keys;
if (index >= mk.length)
return 'NLS error unknow index ' + index;
var subKey = mk[index];
var args = [];
args[0] = moduleKey + '_' + subKey;
for (var _i = 0; _i < (arguments.length - 2); _i++) {
args[_i + 1] = arguments[_i + 2];
}
return Resources.getString.apply(Resources, args);
}
});
});
var pluginConfig = config['vs/nls'] || {};
var language = pluginConfig.availableLanguages ? findLanguageForModule(pluginConfig.availableLanguages, name) : null;
var suffix = '.nls';
if (language !== null && language !== NLSPlugin.DEFAULT_TAG) {
suffix = suffix + '.' + language;
}
else {
if (config.isBuild) {
req([name + '.nls', name + '.nls.keys'], function (messages, keys) {
NLSPlugin.BUILD_MAP[name] = messages;
NLSPlugin.BUILD_MAP_KEYS[name] = keys;
load(messages);
});
req([name + suffix], function (messages) {
if (Array.isArray(messages)) {
messages.localize = createScopedLocalize(messages, _this._env);
}
else {
var pluginConfig = config['vs/nls'] || {};
var language = pluginConfig.availableLanguages ? findLanguageForModule(pluginConfig.availableLanguages, name) : null;
suffix = '.nls';
if (language !== null && language !== DEFAULT_TAG) {
suffix = suffix + '.' + language;
}
req([name + suffix], function (messages) {
if (Array.isArray(messages)) {
messages.localize = createScopedLocalize(messages);
}
else {
messages.localize = createScopedLocalize(messages[name]);
}
load(messages);
});
messages.localize = createScopedLocalize(messages[name], _this._env);
}
}
load(messages);
});
}
};
NLSPlugin.prototype._getEntryPointsMap = function () {
global.nlsPluginEntryPoints = global.nlsPluginEntryPoints || {};
return global.nlsPluginEntryPoints;
};
NLSPlugin.prototype.write = function (pluginName, moduleName, write) {
// getEntryPoint is a Monaco extension to r.js
var entryPoint = write.getEntryPoint();
// r.js destroys the context of this plugin between calling 'write' and 'writeFile'
// so the only option at this point is to leak the data to a global
var entryPointsMap = this._getEntryPointsMap();
entryPointsMap[entryPoint] = entryPointsMap[entryPoint] || [];
entryPointsMap[entryPoint].push(moduleName);
if (moduleName !== entryPoint) {
write.asModule(pluginName + '!' + moduleName, 'define([\'vs/nls\', \'vs/nls!' + entryPoint + '\'], function(nls, data) { return nls.create("' + moduleName + '", data); });');
}
};
NLSPlugin.prototype.writeFile = function (pluginName, moduleName, req, write, config) {
var entryPointsMap = this._getEntryPointsMap();
if (entryPointsMap.hasOwnProperty(moduleName)) {
var fileName = req.toUrl(moduleName + '.nls.js');
var contents = [
'/*---------------------------------------------------------',
' * Copyright (c) Microsoft Corporation. All rights reserved.',
' *--------------------------------------------------------*/'
], entries = entryPointsMap[moduleName];
var data = {};
for (var i = 0; i < entries.length; i++) {
data[entries[i]] = NLSPlugin.BUILD_MAP[entries[i]];
}
contents.push('define("' + moduleName + '.nls", ' + JSON.stringify(data, null, '\t') + ');');
write(fileName, contents.join('\r\n'));
}
};
NLSPlugin.prototype.finishBuild = function (write) {
write('nls.metadata.json', JSON.stringify({
keys: NLSPlugin.BUILD_MAP_KEYS,
messages: NLSPlugin.BUILD_MAP,
bundles: this._getEntryPointsMap()
}, null, '\t'));
};
;
return NLSPlugin;
}());
NLSPlugin.BUILD_MAP = {};
NLSPlugin.BUILD_MAP_KEYS = {};
NLSPlugin.DEFAULT_TAG = 'i-default';
NLSLoaderPlugin.NLSPlugin = NLSPlugin;
(function () {
define('vs/nls', new NLSPlugin());
})();
function init() {
define('vs/nls', new NLSPlugin(Environment.detect()));
}
NLSLoaderPlugin.init = init;
if (typeof doNotInitLoader === 'undefined') {
init();
}
})(NLSLoaderPlugin || (NLSLoaderPlugin = {}));