Skip to content

Commit fe5315b

Browse files
committed
Ship codicon with the standalone editor
1 parent 14d47d3 commit fe5315b

4 files changed

Lines changed: 57 additions & 85 deletions

File tree

build/gulpfile.editor.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,7 @@ var editorEntryPoints = [
4141
];
4242

4343
var editorResources = [
44-
'out-build/vs/{base,editor}/**/*.{svg,png}',
45-
'!out-build/vs/base/browser/ui/splitview/**/*',
46-
'!out-build/vs/base/browser/ui/toolbar/**/*',
47-
'!out-build/vs/base/browser/ui/octiconLabel/**/*',
48-
'!out-build/vs/base/browser/ui/codiconLabel/**/*',
49-
'!out-build/vs/workbench/**',
50-
'!**/test/**'
44+
'out-editor-build/vs/base/browser/ui/codiconLabel/**/*.ttf'
5145
];
5246

5347
var BUNDLED_FILE_HEADER = [
@@ -92,7 +86,6 @@ const extractEditorSrcTask = task.define('extract-editor-src', () => {
9286
],
9387
redirects: {
9488
'vs/base/browser/ui/octiconLabel/octiconLabel': 'vs/base/browser/ui/octiconLabel/octiconLabel.mock',
95-
'vs/base/browser/ui/codiconLabel/codiconLabel': 'vs/base/browser/ui/codiconLabel/codiconLabel.mock',
9689
},
9790
shakeLevel: 2, // 0-Files, 1-InnerFile, 2-ClassMembers
9891
importIgnorePattern: /(^vs\/css!)|(promise-polyfill\/polyfill)/,

build/lib/standalone.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function createESMSourcesAndResources2(options) {
130130
write(getDestAbsoluteFilePath(file), JSON.stringify(tsConfig, null, '\t'));
131131
continue;
132132
}
133-
if (/\.d\.ts$/.test(file) || /\.css$/.test(file) || /\.js$/.test(file)) {
133+
if (/\.d\.ts$/.test(file) || /\.css$/.test(file) || /\.js$/.test(file) || /\.ttf$/.test(file)) {
134134
// Transport the files directly
135135
write(getDestAbsoluteFilePath(file), fs.readFileSync(path.join(SRC_FOLDER, file)));
136136
continue;
@@ -250,35 +250,37 @@ function transportCSS(module, enqueue, write) {
250250
const filename = path.join(SRC_DIR, module);
251251
const fileContents = fs.readFileSync(filename).toString();
252252
const inlineResources = 'base64'; // see https://github.com/Microsoft/monaco-editor/issues/148
253-
const inlineResourcesLimit = 300000; //3000; // see https://github.com/Microsoft/monaco-editor/issues/336
254-
const newContents = _rewriteOrInlineUrls(fileContents, inlineResources === 'base64', inlineResourcesLimit);
253+
const newContents = _rewriteOrInlineUrls(fileContents, inlineResources === 'base64');
255254
write(module, newContents);
256255
return true;
257-
function _rewriteOrInlineUrls(contents, forceBase64, inlineByteLimit) {
256+
function _rewriteOrInlineUrls(contents, forceBase64) {
258257
return _replaceURL(contents, (url) => {
259-
let imagePath = path.join(path.dirname(module), url);
260-
let fileContents = fs.readFileSync(path.join(SRC_DIR, imagePath));
261-
if (fileContents.length < inlineByteLimit) {
262-
const MIME = /\.svg$/.test(url) ? 'image/svg+xml' : 'image/png';
263-
let DATA = ';base64,' + fileContents.toString('base64');
264-
if (!forceBase64 && /\.svg$/.test(url)) {
265-
// .svg => url encode as explained at https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
266-
let newText = fileContents.toString()
267-
.replace(/"/g, '\'')
268-
.replace(/</g, '%3C')
269-
.replace(/>/g, '%3E')
270-
.replace(/&/g, '%26')
271-
.replace(/#/g, '%23')
272-
.replace(/\s+/g, ' ');
273-
let encodedData = ',' + newText;
274-
if (encodedData.length < DATA.length) {
275-
DATA = encodedData;
276-
}
258+
const fontMatch = url.match(/^(.*).ttf\?(.*)$/);
259+
if (fontMatch) {
260+
const relativeFontPath = `${fontMatch[1]}.ttf`; // trim the query parameter
261+
const fontPath = path.join(path.dirname(module), relativeFontPath);
262+
enqueue(fontPath);
263+
return relativeFontPath;
264+
}
265+
const imagePath = path.join(path.dirname(module), url);
266+
const fileContents = fs.readFileSync(path.join(SRC_DIR, imagePath));
267+
const MIME = /\.svg$/.test(url) ? 'image/svg+xml' : 'image/png';
268+
let DATA = ';base64,' + fileContents.toString('base64');
269+
if (!forceBase64 && /\.svg$/.test(url)) {
270+
// .svg => url encode as explained at https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
271+
let newText = fileContents.toString()
272+
.replace(/"/g, '\'')
273+
.replace(/</g, '%3C')
274+
.replace(/>/g, '%3E')
275+
.replace(/&/g, '%26')
276+
.replace(/#/g, '%23')
277+
.replace(/\s+/g, ' ');
278+
let encodedData = ',' + newText;
279+
if (encodedData.length < DATA.length) {
280+
DATA = encodedData;
277281
}
278-
return '"data:' + MIME + DATA + '"';
279282
}
280-
enqueue(imagePath);
281-
return url;
283+
return '"data:' + MIME + DATA + '"';
282284
});
283285
}
284286
function _replaceURL(contents, replacer) {

build/lib/standalone.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export function createESMSourcesAndResources2(options: IOptions2): void {
154154
continue;
155155
}
156156

157-
if (/\.d\.ts$/.test(file) || /\.css$/.test(file) || /\.js$/.test(file)) {
157+
if (/\.d\.ts$/.test(file) || /\.css$/.test(file) || /\.js$/.test(file) || /\.ttf$/.test(file)) {
158158
// Transport the files directly
159159
write(getDestAbsoluteFilePath(file), fs.readFileSync(path.join(SRC_FOLDER, file)));
160160
continue;
@@ -290,40 +290,41 @@ function transportCSS(module: string, enqueue: (module: string) => void, write:
290290
const filename = path.join(SRC_DIR, module);
291291
const fileContents = fs.readFileSync(filename).toString();
292292
const inlineResources = 'base64'; // see https://github.com/Microsoft/monaco-editor/issues/148
293-
const inlineResourcesLimit = 300000;//3000; // see https://github.com/Microsoft/monaco-editor/issues/336
294293

295-
const newContents = _rewriteOrInlineUrls(fileContents, inlineResources === 'base64', inlineResourcesLimit);
294+
const newContents = _rewriteOrInlineUrls(fileContents, inlineResources === 'base64');
296295
write(module, newContents);
297296
return true;
298297

299-
function _rewriteOrInlineUrls(contents: string, forceBase64: boolean, inlineByteLimit: number): string {
298+
function _rewriteOrInlineUrls(contents: string, forceBase64: boolean): string {
300299
return _replaceURL(contents, (url) => {
301-
let imagePath = path.join(path.dirname(module), url);
302-
let fileContents = fs.readFileSync(path.join(SRC_DIR, imagePath));
303-
304-
if (fileContents.length < inlineByteLimit) {
305-
const MIME = /\.svg$/.test(url) ? 'image/svg+xml' : 'image/png';
306-
let DATA = ';base64,' + fileContents.toString('base64');
307-
308-
if (!forceBase64 && /\.svg$/.test(url)) {
309-
// .svg => url encode as explained at https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
310-
let newText = fileContents.toString()
311-
.replace(/"/g, '\'')
312-
.replace(/</g, '%3C')
313-
.replace(/>/g, '%3E')
314-
.replace(/&/g, '%26')
315-
.replace(/#/g, '%23')
316-
.replace(/\s+/g, ' ');
317-
let encodedData = ',' + newText;
318-
if (encodedData.length < DATA.length) {
319-
DATA = encodedData;
320-
}
321-
}
322-
return '"data:' + MIME + DATA + '"';
300+
const fontMatch = url.match(/^(.*).ttf\?(.*)$/);
301+
if (fontMatch) {
302+
const relativeFontPath = `${fontMatch[1]}.ttf`; // trim the query parameter
303+
const fontPath = path.join(path.dirname(module), relativeFontPath);
304+
enqueue(fontPath);
305+
return relativeFontPath;
323306
}
324307

325-
enqueue(imagePath);
326-
return url;
308+
const imagePath = path.join(path.dirname(module), url);
309+
const fileContents = fs.readFileSync(path.join(SRC_DIR, imagePath));
310+
const MIME = /\.svg$/.test(url) ? 'image/svg+xml' : 'image/png';
311+
let DATA = ';base64,' + fileContents.toString('base64');
312+
313+
if (!forceBase64 && /\.svg$/.test(url)) {
314+
// .svg => url encode as explained at https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
315+
let newText = fileContents.toString()
316+
.replace(/"/g, '\'')
317+
.replace(/</g, '%3C')
318+
.replace(/>/g, '%3E')
319+
.replace(/&/g, '%26')
320+
.replace(/#/g, '%23')
321+
.replace(/\s+/g, ' ');
322+
let encodedData = ',' + newText;
323+
if (encodedData.length < DATA.length) {
324+
DATA = encodedData;
325+
}
326+
}
327+
return '"data:' + MIME + DATA + '"';
327328
});
328329
}
329330

src/vs/base/browser/ui/codiconLabel/codiconLabel.mock.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)