mirror of https://github.com/microsoft/vscode.git
Remove `registerAndGetAmdImageURL` and support for it in the build scripts
This commit is contained in:
parent
053ee8ed67
commit
cc46bf5cfd
|
@ -93,7 +93,6 @@ const optimizeVSCodeTask = task.define('optimize-vscode', task.series(
|
||||||
resources: vscodeResources,
|
resources: vscodeResources,
|
||||||
loaderConfig: common.loaderConfig(nodeModules),
|
loaderConfig: common.loaderConfig(nodeModules),
|
||||||
out: 'out-vscode',
|
out: 'out-vscode',
|
||||||
inlineAmdImages: true,
|
|
||||||
bundleInfo: undefined
|
bundleInfo: undefined
|
||||||
})
|
})
|
||||||
));
|
));
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.minifyTask = exports.optimizeTask = exports.loaderConfig = void 0;
|
exports.minifyTask = exports.optimizeTask = exports.loaderConfig = void 0;
|
||||||
const es = require("event-stream");
|
const es = require("event-stream");
|
||||||
const fs = require("fs");
|
|
||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const concat = require("gulp-concat");
|
const concat = require("gulp-concat");
|
||||||
const minifyCSS = require("gulp-cssnano");
|
const minifyCSS = require("gulp-cssnano");
|
||||||
|
@ -134,14 +133,6 @@ function optimizeTask(opts) {
|
||||||
if (err || !result) {
|
if (err || !result) {
|
||||||
return bundlesStream.emit('error', JSON.stringify(err));
|
return bundlesStream.emit('error', JSON.stringify(err));
|
||||||
}
|
}
|
||||||
if (opts.inlineAmdImages) {
|
|
||||||
try {
|
|
||||||
result = inlineAmdImages(src, result);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
return bundlesStream.emit('error', JSON.stringify(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toBundleStream(src, bundledFileHeader, result.files).pipe(bundlesStream);
|
toBundleStream(src, bundledFileHeader, result.files).pipe(bundlesStream);
|
||||||
// Remove css inlined resources
|
// Remove css inlined resources
|
||||||
const filteredResources = resources.slice();
|
const filteredResources = resources.slice();
|
||||||
|
@ -177,39 +168,6 @@ function optimizeTask(opts) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
exports.optimizeTask = optimizeTask;
|
exports.optimizeTask = optimizeTask;
|
||||||
function inlineAmdImages(src, result) {
|
|
||||||
for (const outputFile of result.files) {
|
|
||||||
for (const sourceFile of outputFile.sources) {
|
|
||||||
if (sourceFile.path && /\.js$/.test(sourceFile.path)) {
|
|
||||||
sourceFile.contents = sourceFile.contents.replace(/\([^.]+\.registerAndGetAmdImageURL\(([^)]+)\)\)/g, (_, m0) => {
|
|
||||||
let imagePath = m0;
|
|
||||||
// remove `` or ''
|
|
||||||
if ((imagePath.charAt(0) === '`' && imagePath.charAt(imagePath.length - 1) === '`')
|
|
||||||
|| (imagePath.charAt(0) === '\'' && imagePath.charAt(imagePath.length - 1) === '\'')) {
|
|
||||||
imagePath = imagePath.substr(1, imagePath.length - 2);
|
|
||||||
}
|
|
||||||
if (!/\.(png|svg)$/.test(imagePath)) {
|
|
||||||
console.log(`original: ${_}`);
|
|
||||||
return _;
|
|
||||||
}
|
|
||||||
const repoLocation = path.join(src, imagePath);
|
|
||||||
const absoluteLocation = path.join(REPO_ROOT_PATH, repoLocation);
|
|
||||||
if (!fs.existsSync(absoluteLocation)) {
|
|
||||||
const message = `Invalid amd image url in file ${sourceFile.path}: ${imagePath}`;
|
|
||||||
console.log(message);
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
|
||||||
const fileContents = fs.readFileSync(absoluteLocation);
|
|
||||||
const mime = /\.svg$/.test(imagePath) ? 'image/svg+xml' : 'image/png';
|
|
||||||
// Mark the file as inlined so we don't ship it by itself
|
|
||||||
result.cssInlinedResources.push(repoLocation);
|
|
||||||
return `("data:${mime};base64,${fileContents.toString('base64')}")`;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Wrap around uglify and allow the preserveComments function
|
* Wrap around uglify and allow the preserveComments function
|
||||||
* to have a file "context" to include our copyright only once per file.
|
* to have a file "context" to include our copyright only once per file.
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import * as es from 'event-stream';
|
import * as es from 'event-stream';
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as gulp from 'gulp';
|
import * as gulp from 'gulp';
|
||||||
import * as concat from 'gulp-concat';
|
import * as concat from 'gulp-concat';
|
||||||
import * as minifyCSS from 'gulp-cssnano';
|
import * as minifyCSS from 'gulp-cssnano';
|
||||||
|
@ -160,10 +159,6 @@ export interface IOptimizeTaskOpts {
|
||||||
* (emit bundleInfo.json file)
|
* (emit bundleInfo.json file)
|
||||||
*/
|
*/
|
||||||
bundleInfo: boolean;
|
bundleInfo: boolean;
|
||||||
/**
|
|
||||||
* replace calls to `registerAndGetAmdImageURL` with data uris
|
|
||||||
*/
|
|
||||||
inlineAmdImages: boolean;
|
|
||||||
/**
|
/**
|
||||||
* (out folder name)
|
* (out folder name)
|
||||||
*/
|
*/
|
||||||
|
@ -197,14 +192,6 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
|
||||||
bundle.bundle(entryPoints, loaderConfig, function (err, result) {
|
bundle.bundle(entryPoints, loaderConfig, function (err, result) {
|
||||||
if (err || !result) { return bundlesStream.emit('error', JSON.stringify(err)); }
|
if (err || !result) { return bundlesStream.emit('error', JSON.stringify(err)); }
|
||||||
|
|
||||||
if (opts.inlineAmdImages) {
|
|
||||||
try {
|
|
||||||
result = inlineAmdImages(src, result);
|
|
||||||
} catch (err) {
|
|
||||||
return bundlesStream.emit('error', JSON.stringify(err));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toBundleStream(src, bundledFileHeader, result.files).pipe(bundlesStream);
|
toBundleStream(src, bundledFileHeader, result.files).pipe(bundlesStream);
|
||||||
|
|
||||||
// Remove css inlined resources
|
// Remove css inlined resources
|
||||||
|
@ -249,42 +236,6 @@ export function optimizeTask(opts: IOptimizeTaskOpts): () => NodeJS.ReadWriteStr
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function inlineAmdImages(src: string, result: bundle.IBundleResult): bundle.IBundleResult {
|
|
||||||
for (const outputFile of result.files) {
|
|
||||||
for (const sourceFile of outputFile.sources) {
|
|
||||||
if (sourceFile.path && /\.js$/.test(sourceFile.path)) {
|
|
||||||
sourceFile.contents = sourceFile.contents.replace(/\([^.]+\.registerAndGetAmdImageURL\(([^)]+)\)\)/g, (_, m0) => {
|
|
||||||
let imagePath = m0;
|
|
||||||
// remove `` or ''
|
|
||||||
if ((imagePath.charAt(0) === '`' && imagePath.charAt(imagePath.length - 1) === '`')
|
|
||||||
|| (imagePath.charAt(0) === '\'' && imagePath.charAt(imagePath.length - 1) === '\'')) {
|
|
||||||
imagePath = imagePath.substr(1, imagePath.length - 2);
|
|
||||||
}
|
|
||||||
if (!/\.(png|svg)$/.test(imagePath)) {
|
|
||||||
console.log(`original: ${_}`);
|
|
||||||
return _;
|
|
||||||
}
|
|
||||||
const repoLocation = path.join(src, imagePath);
|
|
||||||
const absoluteLocation = path.join(REPO_ROOT_PATH, repoLocation);
|
|
||||||
if (!fs.existsSync(absoluteLocation)) {
|
|
||||||
const message = `Invalid amd image url in file ${sourceFile.path}: ${imagePath}`;
|
|
||||||
console.log(message);
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
|
||||||
const fileContents = fs.readFileSync(absoluteLocation);
|
|
||||||
const mime = /\.svg$/.test(imagePath) ? 'image/svg+xml' : 'image/png';
|
|
||||||
|
|
||||||
// Mark the file as inlined so we don't ship it by itself
|
|
||||||
result.cssInlinedResources.push(repoLocation);
|
|
||||||
|
|
||||||
return `("data:${mime};base64,${fileContents.toString('base64')}")`;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
declare class FileWithCopyright extends VinylFile {
|
declare class FileWithCopyright extends VinylFile {
|
||||||
public __hasOurCopyright: boolean;
|
public __hasOurCopyright: boolean;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,12 +12,3 @@ export function getPathFromAmdModule(requirefn: typeof require, relativePath: st
|
||||||
export function getUriFromAmdModule(requirefn: typeof require, relativePath: string): URI {
|
export function getUriFromAmdModule(requirefn: typeof require, relativePath: string): URI {
|
||||||
return URI.parse(requirefn.toUrl(relativePath));
|
return URI.parse(requirefn.toUrl(relativePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Reference a resource that might be inlined.
|
|
||||||
* Do not inline icons that will be used by the native mac touchbar.
|
|
||||||
* Do not rename this method unless you adopt the build scripts.
|
|
||||||
*/
|
|
||||||
export function registerAndGetAmdImageURL(absolutePath: string): string {
|
|
||||||
return require.toUrl(absolutePath);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue