Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/lib/snapshotLoader.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
export namespace snaps {
7
8
const fs = require('fs');
9
const path = require('path');
10
const os = require('os');
11
const cp = require('child_process');
12
13
const mksnapshot = path.join(__dirname, `../../node_modules/.bin/${process.platform === 'win32' ? 'mksnapshot.cmd' : 'mksnapshot'}`);
14
const product = require('../../product.json');
15
const arch = (process.argv.join('').match(/--arch=(.*)/) || [])[1];
16
17
//
18
let loaderFilepath: string;
19
let startupBlobFilepath: string;
20
21
switch (process.platform) {
22
case 'darwin':
23
loaderFilepath = `VSCode-darwin/${product.nameLong}.app/Contents/Resources/app/out/vs/loader.js`;
24
startupBlobFilepath = `VSCode-darwin/${product.nameLong}.app/Contents/Frameworks/Electron Framework.framework/Resources/snapshot_blob.bin`;
25
break;
26
27
case 'win32':
28
case 'linux':
29
loaderFilepath = `VSCode-${process.platform}-${arch}/resources/app/out/vs/loader.js`;
30
startupBlobFilepath = `VSCode-${process.platform}-${arch}/snapshot_blob.bin`;
31
break;
32
33
default:
34
throw new Error('Unknown platform');
35
}
36
37
loaderFilepath = path.join(__dirname, '../../../', loaderFilepath);
38
startupBlobFilepath = path.join(__dirname, '../../../', startupBlobFilepath);
39
40
snapshotLoader(loaderFilepath, startupBlobFilepath);
41
42
function snapshotLoader(loaderFilepath: string, startupBlobFilepath: string): void {
43
44
const inputFile = fs.readFileSync(loaderFilepath);
45
const wrappedInputFile = `
46
var Monaco_Loader_Init;
47
(function() {
48
var doNotInitLoader = true;
49
${inputFile.toString()};
50
Monaco_Loader_Init = function() {
51
AMDLoader.init();
52
CSSLoaderPlugin.init();
53
NLSLoaderPlugin.init();
54
55
return { define, require };
56
}
57
})();
58
`;
59
const wrappedInputFilepath = path.join(os.tmpdir(), 'wrapped-loader.js');
60
console.log(wrappedInputFilepath);
61
fs.writeFileSync(wrappedInputFilepath, wrappedInputFile);
62
63
cp.execFileSync(mksnapshot, [wrappedInputFilepath, `--startup_blob`, startupBlobFilepath]);
64
}
65
}
66
67