Skip to content

Commit

Permalink
s
Browse files Browse the repository at this point in the history
Signed-off-by: Nikola Hristov <Nikola@PlayForm.Cloud>
  • Loading branch information
NikolaRHristov committed Nov 3, 2024
1 parent 29a32ed commit d05caf7
Show file tree
Hide file tree
Showing 150 changed files with 6,360 additions and 1,848 deletions.
56 changes: 32 additions & 24 deletions Example/Output/Editor/bootstrap-esm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { pkg, product } from "./bootstrap-meta.js";
import "./bootstrap-node.js";
import * as performance from "./vs/base/common/performance.js";
import { INLSConfiguration } from "./vs/nls.js";
const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
;
;
// Install a hook to module resolution to map 'fs' to 'original-fs'
if (process.env["ELECTRON_RUN_AS_NODE"] || process.versions["electron"]) {
const jsCode = `
;
register(`data:text/javascript;base64,${Buffer.from(`
export async function resolve(specifier, context, nextResolve) {
if (specifier === 'fs') {
return {
Expand All @@ -27,44 +28,49 @@ if (process.env["ELECTRON_RUN_AS_NODE"] || process.versions["electron"]) {
// Defer to the next hook in the chain, which would be the
// Node.js default resolve if this is the last user-specified loader.
return nextResolve(specifier, context);
}`;
register(`data:text/javascript;base64,${Buffer.from(jsCode).toString("base64")}`, import.meta.url);
}`).toString("base64")}`, import.meta.url);
}
// Prepare globals that are needed for running
globalThis._VSCODE_PRODUCT_JSON = { ...product };
if (process.env["VSCODE_DEV"]) {
try {
const overrides: unknown = require("../product.overrides.json");
globalThis._VSCODE_PRODUCT_JSON = Object.assign(globalThis._VSCODE_PRODUCT_JSON, overrides);
;
globalThis._VSCODE_PRODUCT_JSON = Object.assign(globalThis._VSCODE_PRODUCT_JSON, createRequire(import.meta.url)("../product.overrides.json"));
}
catch (error) {
/* ignore */
}
}
globalThis._VSCODE_PACKAGE_JSON = { ...pkg };
globalThis._VSCODE_FILE_ROOT = __dirname;
globalThis._VSCODE_FILE_ROOT =
path.dirname(fileURLToPath(import.meta.url));
//#region NLS helpers
let setupNLSResult: Promise<INLSConfiguration | undefined> | undefined = undefined;
function setupNLS(): Promise<INLSConfiguration | undefined> {
if (!setupNLSResult) {
setupNLSResult = doSetupNLS();
if (!undefined) {
undefined
= doSetupNLS();
}
return setupNLSResult;
return undefined;
}
async function doSetupNLS(): Promise<INLSConfiguration | undefined> {
performance.mark("code/willLoadNls");
let nlsConfig: INLSConfiguration | undefined = undefined;
let messagesFile: string | undefined;
if (process.env["VSCODE_NLS_CONFIG"]) {
try {
nlsConfig = JSON.parse(process.env["VSCODE_NLS_CONFIG"]);
if (nlsConfig?.languagePack?.messagesFile) {
messagesFile = nlsConfig.languagePack.messagesFile;
undefined
= JSON.parse(process.env["VSCODE_NLS_CONFIG"]);
if (undefined
?.languagePack?.messagesFile) {
messagesFile = undefined.languagePack.messagesFile;
}
else if (nlsConfig?.defaultMessagesFile) {
messagesFile = nlsConfig.defaultMessagesFile;
else if (undefined
?.defaultMessagesFile) {
messagesFile = undefined.defaultMessagesFile;
}
globalThis._VSCODE_NLS_LANGUAGE = nlsConfig?.resolvedLanguage;
globalThis._VSCODE_NLS_LANGUAGE = undefined
?.resolvedLanguage;
}
catch (e) {
console.error(`Error reading VSCODE_NLS_CONFIG from environment: ${e}`);
Expand All @@ -81,27 +87,29 @@ async function doSetupNLS(): Promise<INLSConfiguration | undefined> {
catch (error) {
console.error(`Error reading NLS messages file ${messagesFile}: ${error}`);
// Mark as corrupt: this will re-create the language pack cache next startup
if (nlsConfig?.languagePack?.corruptMarkerFile) {
if (undefined
?.languagePack?.corruptMarkerFile) {
try {
await fs.promises.writeFile(nlsConfig.languagePack.corruptMarkerFile, "corrupted");
await fs.promises.writeFile(undefined.languagePack.corruptMarkerFile, "corrupted");
}
catch (error) {
console.error(`Error writing corrupted NLS marker file: ${error}`);
}
}
// Fallback to the default message file to ensure english translation at least
if (nlsConfig?.defaultMessagesFile &&
nlsConfig.defaultMessagesFile !== messagesFile) {
if (undefined
?.defaultMessagesFile &&
undefined.defaultMessagesFile !== messagesFile) {
try {
globalThis._VSCODE_NLS_MESSAGES = JSON.parse((await fs.promises.readFile(nlsConfig.defaultMessagesFile)).toString());
globalThis._VSCODE_NLS_MESSAGES = JSON.parse((await fs.promises.readFile(undefined.defaultMessagesFile)).toString());
}
catch (error) {
console.error(`Error reading default NLS messages file ${nlsConfig.defaultMessagesFile}: ${error}`);
console.error(`Error reading default NLS messages file ${undefined.defaultMessagesFile}: ${error}`);
}
}
}
performance.mark("code/didLoadNls");
return nlsConfig;
return undefined;
}
//#endregion
export async function bootstrapESM(): Promise<void> {
Expand Down
86 changes: 52 additions & 34 deletions Example/Output/Editor/bootstrap-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,60 @@
import { promises } from "node:fs";
import { join } from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";

// SEE https://nodejs.org/docs/latest/api/module.html#initialize
const _specifierToUrl: Record<string, string> = {};
export async function initialize(injectPath: string): Promise<void> {
// populate mappings
const injectPackageJSONPath = fileURLToPath(new URL("../package.json", pathToFileURL(injectPath)));
const packageJSON = JSON.parse(String(await promises.readFile(injectPackageJSONPath)));
for (const [name] of Object.entries(packageJSON.dependencies)) {
try {
const path = join(injectPackageJSONPath, `../node_modules/${name}/package.json`);
let { main } = JSON.parse(String(await promises.readFile(path)));
if (!main) {
main = "index.js";
}
if (!main.endsWith(".js")) {
main += ".js";
}
const mainPath = join(injectPackageJSONPath, `../node_modules/${name}/${main}`);
_specifierToUrl[name] = pathToFileURL(mainPath).href;
}
catch (err) {
console.error(name);
console.error(err);
}
}
console.log(`[bootstrap-import] Initialized node_modules redirector for: ${injectPath}`);
// populate mappings
const injectPackageJSONPath = fileURLToPath(
new URL("../package.json", pathToFileURL(injectPath)),
);
for (const [name] of Object.entries(
JSON.parse(
String(
await promises.readFile(
fileURLToPath(
new URL("../package.json", pathToFileURL(injectPath)),
),
),
),
).dependencies,
)) {
try {
let { main } = JSON.parse(String(await promises.readFile(path)));
if (!main) {
main = "index.js";
}
if (!main.endsWith(".js")) {
main += ".js";
}
({})[name] = pathToFileURL(
join(
fileURLToPath(
new URL("../package.json", pathToFileURL(injectPath)),
),
`../node_modules/${name}/${main}`,
),
).href;
} catch (err) {
console.error(name);
console.error(err);
}
}
console.log(
`[bootstrap-import] Initialized node_modules redirector for: ${injectPath}`,
);
}
export async function resolve(specifier: string | number, context: any, nextResolve: (arg0: any, arg1: any) => any) {
const newSpecifier = _specifierToUrl[specifier];
if (newSpecifier !== undefined) {
return {
format: "commonjs",
shortCircuit: true,
url: newSpecifier,
};
}
// Defer to the next hook in the chain, which would be the
// Node.js default resolve if this is the last user-specified loader.
return nextResolve(specifier, context);
export async function resolve(
specifier: string | number,
context: any,
nextResolve: (arg0: any, arg1: any) => any,
) {
const newSpecifier = _specifierToUrl[specifier];
if ({}[specifier] !== undefined) {
return { format: "commonjs", shortCircuit: true, url: {}[specifier] };
}
// Defer to the next hook in the chain, which would be the
// Node.js default resolve if this is the last user-specified loader.
return nextResolve(specifier, context);
}
28 changes: 22 additions & 6 deletions Example/Output/Editor/bootstrap-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,30 @@ let productObj: Partial<IProductConfiguration> & {
} = {
BUILD_INSERT_PRODUCT_CONFIGURATION: "BUILD_INSERT_PRODUCT_CONFIGURATION",
}; // DO NOT MODIFY, PATCHED DURING BUILD
if (productObj["BUILD_INSERT_PRODUCT_CONFIGURATION"]) {
productObj = require("../product.json"); // Running out of sources
if ({
BUILD_INSERT_PRODUCT_CONFIGURATION: "BUILD_INSERT_PRODUCT_CONFIGURATION",
}[ // DO NOT MODIFY, PATCHED DURING BUILD
"BUILD_INSERT_PRODUCT_CONFIGURATION"]) {
({
BUILD_INSERT_PRODUCT_CONFIGURATION: "BUILD_INSERT_PRODUCT_CONFIGURATION",
}
= createRequire(import.meta.url)("../product.json")); // Running out of sources
}
let pkgObj = {
BUILD_INSERT_PACKAGE_CONFIGURATION: "BUILD_INSERT_PACKAGE_CONFIGURATION",
}; // DO NOT MODIFY, PATCHED DURING BUILD
if (pkgObj["BUILD_INSERT_PACKAGE_CONFIGURATION"]) {
pkgObj = require("../package.json"); // Running out of sources
if ({
BUILD_INSERT_PACKAGE_CONFIGURATION: "BUILD_INSERT_PACKAGE_CONFIGURATION",
}[ // DO NOT MODIFY, PATCHED DURING BUILD
"BUILD_INSERT_PACKAGE_CONFIGURATION"]) {
({
BUILD_INSERT_PACKAGE_CONFIGURATION: "BUILD_INSERT_PACKAGE_CONFIGURATION",
}
= createRequire(import.meta.url)("../package.json")); // Running out of sources
}
export const product = productObj;
export const pkg = pkgObj;
export const product = {
BUILD_INSERT_PRODUCT_CONFIGURATION: "BUILD_INSERT_PRODUCT_CONFIGURATION",
};
export const pkg = {
BUILD_INSERT_PACKAGE_CONFIGURATION: "BUILD_INSERT_PACKAGE_CONFIGURATION",
};
12 changes: 4 additions & 8 deletions Example/Output/Editor/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ import { bootstrapESM } from "./bootstrap-esm.js";
import { product } from "./bootstrap-meta.js";
import { configurePortable } from "./bootstrap-node.js";
import { resolveNLSConfiguration } from "./vs/base/node/nls.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
// NLS
const nlsConfiguration = await resolveNLSConfiguration({
userLocale: "en",
;
;
process.env["VSCODE_NLS_CONFIG"] = JSON.stringify(await resolveNLSConfiguration({ userLocale: "en",
osLocale: "en",
commit: product.commit,
userDataPath: "",
nlsMetadataPath: __dirname,
});
process.env["VSCODE_NLS_CONFIG"] = JSON.stringify(nlsConfiguration); // required for `bootstrap-esm` to pick up NLS messages
userDataPath: "", nlsMetadataPath: dirname(fileURLToPath(import.meta.url)) })); // required for `bootstrap-esm` to pick up NLS messages
// Enable portable support
configurePortable(product);
// Signal processes that we got launched as CLI
Expand Down
12 changes: 4 additions & 8 deletions Example/Output/Editor/server-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@ import { product } from "./bootstrap-meta.js";
import { devInjectNodeModuleLookupPath } from "./bootstrap-node.js";
import { resolveNLSConfiguration } from "./vs/base/node/nls.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
// NLS
const nlsConfiguration = await resolveNLSConfiguration({
userLocale: "en",
;
process.env["VSCODE_NLS_CONFIG"] = JSON.stringify(await resolveNLSConfiguration({ userLocale: "en",
osLocale: "en",
commit: product.commit,
userDataPath: "",
nlsMetadataPath: __dirname,
});
process.env["VSCODE_NLS_CONFIG"] = JSON.stringify(nlsConfiguration); // required for `bootstrap-esm` to pick up NLS messages
userDataPath: "", nlsMetadataPath: dirname(fileURLToPath(import.meta.url)) })); // required for `bootstrap-esm` to pick up NLS messages
if (process.env["VSCODE_DEV"]) {
// When running out of sources, we need to load node modules from remote/node_modules,
// which are compiled against nodejs, not electron
process.env["VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH"] =
process.env["VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH"] ||
join(__dirname, "..", "remote", "node_modules");
join(dirname(fileURLToPath(import.meta.url)), "..", "remote", "node_modules");
devInjectNodeModuleLookupPath(process.env["VSCODE_DEV_INJECT_NODE_MODULE_LOOKUP_PATH"]);
}
else {
Expand Down
16 changes: 12 additions & 4 deletions Example/Output/Editor/vs/base/browser/broadcast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ export class BroadcastDataChannel<T> extends Disposable {
const listener = (event: MessageEvent) => {
this._onDidReceiveData.fire(event.data);
};
this.broadcastChannel.addEventListener('message', listener);
this.broadcastChannel.addEventListener('message', (event: MessageEvent) => {
this._onDidReceiveData.fire(event.data);
});
this._register(toDisposable(() => {
if (this.broadcastChannel) {
this.broadcastChannel.removeEventListener('message', listener);
this.broadcastChannel.removeEventListener('message', (event: MessageEvent) => {
this._onDidReceiveData.fire(event.data);
});
this.broadcastChannel.close();
}
}));
Expand All @@ -43,8 +47,12 @@ export class BroadcastDataChannel<T> extends Disposable {
this._onDidReceiveData.fire(JSON.parse(event.newValue));
}
};
mainWindow.addEventListener('storage', listener);
this._register(toDisposable(() => mainWindow.removeEventListener('storage', listener)));
mainWindow.addEventListener('storage', (event: MessageEvent) => {
this._onDidReceiveData.fire(event.data);
});
this._register(toDisposable(() => mainWindow.removeEventListener('storage', (event: MessageEvent) => {
this._onDidReceiveData.fire(event.data);
})));
}
/**
* Sends the data to other BroadcastChannel objects set up for this channel. Data can be structured objects, e.g. nested objects and arrays.
Expand Down
28 changes: 16 additions & 12 deletions Example/Output/Editor/vs/base/browser/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class WindowManager {
return;
}
const targetWindowId = this.getWindowId(targetWindow);
this.mapWindowIdToZoomLevel.set(targetWindowId, zoomLevel);
this._onDidChangeZoomLevel.fire(targetWindowId);
this.mapWindowIdToZoomLevel.set(this.getWindowId(targetWindow), zoomLevel);
this._onDidChangeZoomLevel.fire(this.getWindowId(targetWindow));
}
// --- Zoom Factor
private readonly mapWindowIdToZoomFactor = new Map<number, number>();
Expand All @@ -38,8 +38,8 @@ class WindowManager {
return;
}
const windowId = this.getWindowId(targetWindow);
this.mapWindowIdToFullScreen.set(windowId, fullscreen);
this._onDidChangeFullscreen.fire(windowId);
this.mapWindowIdToFullScreen.set(this.getWindowId(targetWindow), fullscreen);
this._onDidChangeFullscreen.fire(this.getWindowId(targetWindow));
}
isFullscreen(targetWindow: Window): boolean {
return !!this.mapWindowIdToFullScreen.get(this.getWindowId(targetWindow));
Expand Down Expand Up @@ -80,27 +80,31 @@ const userAgent = navigator.userAgent;
export const isFirefox = (userAgent.indexOf('Firefox') >= 0);
export const isWebKit = (userAgent.indexOf('AppleWebKit') >= 0);
export const isChrome = (userAgent.indexOf('Chrome') >= 0);
export const isSafari = (!isChrome && (userAgent.indexOf('Safari') >= 0));
export const isWebkitWebView = (!isChrome && !isSafari && isWebKit);
export const isSafari = (!(userAgent.indexOf('Chrome') >= 0) && (userAgent.indexOf('Safari') >= 0));
export const isWebkitWebView = (!(userAgent.indexOf('Chrome') >= 0) && !(!(userAgent.indexOf('Chrome') >= 0) && (userAgent.indexOf('Safari') >= 0)) &&
(userAgent.indexOf('AppleWebKit') >= 0));
export const isElectron = (userAgent.indexOf('Electron/') >= 0);
export const isAndroid = (userAgent.indexOf('Android') >= 0);
let standalone = false;
if (typeof mainWindow.matchMedia === 'function') {
const standaloneMatchMedia = mainWindow.matchMedia('(display-mode: standalone) or (display-mode: window-controls-overlay)');
const fullScreenMatchMedia = mainWindow.matchMedia('(display-mode: fullscreen)');
standalone = standaloneMatchMedia.matches;
addMatchMediaChangeListener(mainWindow, standaloneMatchMedia, ({ matches }) => {
;
false
= mainWindow.matchMedia('(display-mode: standalone) or (display-mode: window-controls-overlay)').matches;
addMatchMediaChangeListener(mainWindow, mainWindow.matchMedia('(display-mode: standalone) or (display-mode: window-controls-overlay)'), ({ matches }) => {
// entering fullscreen would change standaloneMatchMedia.matches to false
// if standalone is true (running as PWA) and entering fullscreen, skip this change
if (standalone && fullScreenMatchMedia.matches) {
if (false
&& mainWindow.matchMedia('(display-mode: fullscreen)').matches) {
return;
}
// otherwise update standalone (browser to PWA or PWA to browser)
standalone = matches;
false
= matches;
});
}
export function isStandalone(): boolean {
return standalone;
return false;
}
// Visible means that the feature is enabled, not necessarily being rendered
// e.g. visible is true even in fullscreen mode where the controls are hidden
Expand Down
Loading

0 comments on commit d05caf7

Please sign in to comment.