Skip to content

Commit

Permalink
add support to snapshot the loader and its plugins, #28492
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jun 23, 2017
1 parent 76b37f8 commit 5b06b19
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
49 changes: 49 additions & 0 deletions build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const shrinkwrap = require('../npm-shrinkwrap.json');
const crypto = require('crypto');
const i18n = require('./lib/i18n');
const glob = require('glob');
const os = require('os');
const cp = require('child_process');

const productDependencies = Object.keys(product.dependencies || {});
const dependencies = Object.keys(shrinkwrap.dependencies)
Expand Down Expand Up @@ -369,6 +371,53 @@ gulp.task('vscode-linux-ia32-min', ['minify-vscode', 'clean-vscode-linux-ia32'],
gulp.task('vscode-linux-x64-min', ['minify-vscode', 'clean-vscode-linux-x64'], packageTask('linux', 'x64', { minified: true }));
gulp.task('vscode-linux-arm-min', ['minify-vscode', 'clean-vscode-linux-arm'], packageTask('linux', 'arm', { minified: true }));

// --- v8 snapshots ---

function snapshotTask(platform, arch) {

const destination = path.join(path.dirname(root), 'VSCode') + (platform ? '-' + platform : '') + (arch ? '-' + arch : '');
const command = path.join(process.cwd(), 'node_modules/.bin/mksnapshot');

let startupBlobFilepath;

if (platform === 'darwin') {
startupBlobFilepath = path.join(destination, 'Code - OSS.app/Contents/Frameworks/Electron Framework.framework/Resources/snapshot_blob.bin')
} else if (platform === 'windows') {
startupBlobFilepath = path.join(destination, 'snapshot_blob.bin')
// TODO
return () => { };
} else if (platform === 'linux') {
// TODO
return () => { };
}

return () => {
const inputFile = fs.readFileSync(path.join(destination, 'Code - OSS.app/Contents/Resources/app/out/vs/loader.js'));
const wrappedInputFile = `
var Monaco_Loader_Init;
(function() {
var doNotInitLoader = true;
${inputFile.toString()};
Monaco_Loader_Init = function() {
AMDLoader.init();
CSSLoaderPlugin.init();
NLSLoaderPlugin.init();
return define;
}
})();
`;
const wrappedInputFilepath = path.join(os.tmpdir(), 'wrapped-loader.js');
console.log(wrappedInputFilepath);
fs.writeFileSync(wrappedInputFilepath, wrappedInputFile);

cp.execFileSync(command, [wrappedInputFilepath, `--startup_blob`, startupBlobFilepath]);
}
}

gulp.task('vscode-darwin-snapshots', ['vscode-darwin'], snapshotTask('darwin', undefined));


// Transifex Localizations
const vscodeLanguages = [
'zh-hans',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"cson-parser": "^1.3.3",
"debounce": "^1.0.0",
"documentdb": "^1.5.1",
"electron-mksnapshot": "1.6.0",
"eslint": "^3.4.0",
"event-stream": "^3.1.7",
"express": "^4.13.1",
Expand Down Expand Up @@ -127,4 +128,4 @@
"windows-mutex": "^0.2.0",
"fsevents": "0.3.8"
}
}
}
21 changes: 15 additions & 6 deletions src/vs/workbench/electron-browser/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (window.location.search.indexOf('prof-startup') >= 0) {
profiler.startProfiling('renderer', true);
}

/*global window,document,define*/
/*global window,document,define,Monaco_Loader_Init*/

const startTimer = require('../../../base/node/startupTimers').startTimer;
const path = require('path');
Expand Down Expand Up @@ -157,10 +157,7 @@ function main() {
// Load the loader and start loading the workbench
const rootUrl = uriFromPath(configuration.appRoot) + '/out';

// In the bundled version the nls plugin is packaged with the loader so the NLS Plugins
// loads as soon as the loader loads. To be able to have pseudo translation
const loaderTimer = startTimer('load:loader');
createScript(rootUrl + '/vs/loader.js', function () {
function onLoader() {
define('fs', ['original-fs'], function (originalFS) { return originalFS; }); // replace the patched electron fs with the original node fs for all AMD code
loaderTimer.stop();

Expand Down Expand Up @@ -211,7 +208,19 @@ function main() {
});
});
});
});
}

// In the bundled version the nls plugin is packaged with the loader so the NLS Plugins
// loads as soon as the loader loads. To be able to have pseudo translation
const loaderTimer = startTimer('load:loader');
if (typeof Monaco_Loader_Init === 'function') {
//eslint-disable-next-line no-global-assign
define = Monaco_Loader_Init();
onLoader();

} else {
createScript(rootUrl + '/vs/loader.js', onLoader);
}
}

main();

0 comments on commit 5b06b19

Please sign in to comment.