Skip to content

Commit 5e4cf38

Browse files
authored
Revert "feat: reenable asar support" (microsoft#272935)
Revert "feat: reenable asar support (microsoft#272552)" This reverts commit ff89137.
1 parent 8b2b505 commit 5e4cf38

File tree

14 files changed

+53
-124
lines changed

14 files changed

+53
-124
lines changed

build/gulpfile.vscode.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,14 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op
288288
const productionDependencies = getProductionDependencies(root);
289289
const dependenciesSrc = productionDependencies.map(d => path.relative(root, d)).map(d => [`${d}/**`, `!${d}/**/{test,tests}/**`]).flat().concat('!**/*.mk');
290290

291-
const deps = es.merge(
292-
gulp.src(dependenciesSrc, { base: '.', dot: true }),
293-
gulp.src(['node_modules/vsda/**'], { base: 'node_modules', dot: true }) // retain vsda at root level of asar for backward compatibility
294-
)
291+
const deps = gulp.src(dependenciesSrc, { base: '.', dot: true })
295292
.pipe(filter(['**', `!**/${config.version}/**`, '!**/bin/darwin-arm64-87/**', '!**/package-lock.json', '!**/yarn.lock', '!**/*.{js,css}.map']))
296293
.pipe(util.cleanNodeModules(path.join(__dirname, '.moduleignore')))
297294
.pipe(util.cleanNodeModules(path.join(__dirname, `.moduleignore.${process.platform}`)))
298295
.pipe(jsFilter)
299296
.pipe(util.rewriteSourceMappingURL(sourceMappingURLBase))
300297
.pipe(jsFilter.restore)
301-
.pipe(createAsar(process.cwd(), [
298+
.pipe(createAsar(path.join(process.cwd(), 'node_modules'), [
302299
'**/*.node',
303300
'**/@vscode/ripgrep/bin/*',
304301
'**/node-pty/build/Release/*',
@@ -309,8 +306,9 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op
309306
'**/@vscode/vsce-sign/bin/*',
310307
], [
311308
'**/*.mk',
309+
'!node_modules/vsda/**' // stay compatible with extensions that depend on us shipping `vsda` into ASAR
312310
], [
313-
'node_modules/vsda/**', // duplicate vsda in node_modules.asar.unpacked for backward compatibility
311+
'node_modules/vsda/**' // retain copy of `vsda` in node_modules for internal use
314312
], 'node_modules.asar'));
315313

316314
let all = es.merge(

build/lib/asar.js

Lines changed: 9 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/lib/asar.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs:
3838
};
3939

4040
// Files that should be duplicated between
41-
// node_modules.asar.unpacked/node_modules and node_modules.asar.unpacked
41+
// node_modules.asar and node_modules
4242
const shouldDuplicateFile = (file: VinylFile): boolean => {
4343
for (const duplicateGlob of duplicateGlobs) {
4444
if (minimatch(file.relative, duplicateGlob)) {
@@ -107,7 +107,14 @@ export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs:
107107
}));
108108
return;
109109
}
110-
110+
if (shouldDuplicateFile(file)) {
111+
this.queue(new VinylFile({
112+
base: '.',
113+
path: file.path,
114+
stat: file.stat,
115+
contents: file.contents
116+
}));
117+
}
111118
const shouldUnpack = shouldUnpackFile(file);
112119
insertFile(file.relative, { size: file.contents.length, mode: file.stat.mode }, shouldUnpack);
113120

@@ -120,17 +127,6 @@ export function createAsar(folderPath: string, unpackGlobs: string[], skipGlobs:
120127
stat: file.stat,
121128
contents: file.contents
122129
}));
123-
124-
const shouldDuplicate = shouldDuplicateFile(file);
125-
if (shouldDuplicate) {
126-
const rootRelative = file.relative.replace(/^node_modules\//, '');
127-
this.queue(new VinylFile({
128-
base: '.',
129-
path: path.join(destFilename + '.unpacked', rootRelative),
130-
stat: file.stat,
131-
contents: file.contents
132-
}));
133-
}
134130
} else {
135131
// The file goes inside of xx.asar
136132
out.push(file.contents);

build/linux/dependencies-generator.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/linux/dependencies-generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export async function getDependencies(packageType: 'deb' | 'rpm', buildDir: stri
4747
}
4848

4949
// Get the files for which we want to find dependencies.
50-
const nativeModulesPath = path.join(buildDir, 'resources', 'app', 'node_modules.asar.unpacked');
50+
const canAsar = false; // TODO@esm ASAR disabled in ESM
51+
const nativeModulesPath = path.join(buildDir, 'resources', 'app', canAsar ? 'node_modules.asar.unpacked' : 'node_modules');
5152
const findResult = spawnSync('find', [nativeModulesPath, '-name', '*.node']);
5253
if (findResult.status) {
5354
console.error('Error finding files:');

src/bootstrap-esm.ts

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,34 @@
55

66
import * as fs from 'node:fs';
77
import { register } from 'node:module';
8-
import { sep } from 'node:path';
98
import { product, pkg } from './bootstrap-meta.js';
109
import './bootstrap-node.js';
1110
import * as performance from './vs/base/common/performance.js';
1211
import { INLSConfiguration } from './vs/nls.js';
1312

14-
// Prepare globals that are needed for running
15-
globalThis._VSCODE_PRODUCT_JSON = { ...product };
16-
globalThis._VSCODE_PACKAGE_JSON = { ...pkg };
17-
globalThis._VSCODE_FILE_ROOT = import.meta.dirname;
18-
19-
// Install a hook to module resolution to map dependencies into the asar archive
20-
function enableASARSupport() {
21-
if (!process.env['ELECTRON_RUN_AS_NODE'] && !process.versions['electron']) {
22-
return;
23-
}
24-
25-
if (process.env['VSCODE_DEV']) {
26-
return;
27-
}
28-
13+
// Install a hook to module resolution to map 'fs' to 'original-fs'
14+
if (process.env['ELECTRON_RUN_AS_NODE'] || process.versions['electron']) {
2915
const jsCode = `
30-
import { pathToFileURL, fileURLToPath } from 'node:url';
31-
function isRelativeSpecifier(specifier) {
32-
if (specifier[0] === '.') {
33-
if (specifier.length === 1 || specifier[1] === '/') { return true; }
34-
if (specifier[1] === '.') {
35-
if (specifier.length === 2 || specifier[2] === '/') { return true; }
36-
}
37-
}
38-
return false;
39-
}
40-
function normalizeDriveLetter(path) {
41-
if (process.platform === 'win32'
42-
&& path.length >= 2
43-
&& (path.charCodeAt(0) >= 65 && path.charCodeAt(0) <= 90 || path.charCodeAt(0) >= 97 && path.charCodeAt(0) <= 122)
44-
&& path.charCodeAt(1) === 58) {
45-
return path[0].toLowerCase() + path.slice(1);
46-
}
47-
return path;
48-
}
49-
export async function initialize({ resourcesPath, asarPath }) {
50-
globalThis.__resourcesPath = normalizeDriveLetter(resourcesPath);
51-
globalThis.__asarPath = asarPath;
52-
}
5316
export async function resolve(specifier, context, nextResolve) {
54-
if (!isRelativeSpecifier(specifier) && context.parentURL) {
55-
const currentPath = fileURLToPath(context.parentURL);
56-
const normalizedCurrentPath = normalizeDriveLetter(currentPath);
57-
if (normalizedCurrentPath.startsWith(globalThis.__resourcesPath)) {
58-
const asarPath = normalizedCurrentPath.replace(globalThis.__resourcesPath, globalThis.__asarPath);
59-
context.parentURL = pathToFileURL(asarPath);
60-
}
17+
if (specifier === 'fs') {
18+
return {
19+
format: 'builtin',
20+
shortCircuit: true,
21+
url: 'node:original-fs'
22+
};
6123
}
6224
6325
// Defer to the next hook in the chain, which would be the
6426
// Node.js default resolve if this is the last user-specified loader.
6527
return nextResolve(specifier, context);
6628
}`;
67-
register(`data:text/javascript;base64,${Buffer.from(jsCode).toString('base64')}`, import.meta.url, {
68-
data: {
69-
resourcesPath: `${process.resourcesPath}${sep}app`,
70-
asarPath: `${process.resourcesPath}${sep}app${sep}node_modules.asar`,
71-
}
72-
});
29+
register(`data:text/javascript;base64,${Buffer.from(jsCode).toString('base64')}`, import.meta.url);
7330
}
7431

75-
enableASARSupport();
32+
// Prepare globals that are needed for running
33+
globalThis._VSCODE_PRODUCT_JSON = { ...product };
34+
globalThis._VSCODE_PACKAGE_JSON = { ...pkg };
35+
globalThis._VSCODE_FILE_ROOT = import.meta.dirname;
7636

7737
//#region NLS helpers
7838

src/bootstrap-node.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,6 @@ if (!process.env['VSCODE_HANDLES_SIGPIPE']) {
2929
});
3030
}
3131

32-
/**
33-
* Helper to enable ASAR support.
34-
*/
35-
function enableASARSupport(): void {
36-
if (process.env['ELECTRON_RUN_AS_NODE'] || process.versions['electron']) {
37-
const Module = require('node:module');
38-
const NODE_MODULES_PATH = path.join(import.meta.dirname, '../node_modules');
39-
const NODE_MODULES_ASAR_PATH = path.join(import.meta.dirname, '../node_modules.asar');
40-
// @ts-ignore
41-
const originalResolveLookupPaths = Module._resolveLookupPaths;
42-
// @ts-ignore
43-
Module._resolveLookupPaths = function (request, parent) {
44-
const paths = originalResolveLookupPaths(request, parent);
45-
if (Array.isArray(paths)) {
46-
for (let i = 0, len = paths.length; i < len; i++) {
47-
if (paths[i] === NODE_MODULES_PATH) {
48-
paths.splice(i, 0, NODE_MODULES_ASAR_PATH);
49-
break;
50-
}
51-
}
52-
}
53-
return paths;
54-
};
55-
}
56-
}
57-
58-
enableASARSupport();
59-
6032
// Setup current working directory in all our node & electron processes
6133
// - Windows: call `process.chdir()` to always set application folder as cwd
6234
// - all OS: store the `process.cwd()` inside `VSCODE_CWD` for consistent lookups

src/vs/amdX.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { IProductConfiguration } from './base/common/product.js';
99
import { URI } from './base/common/uri.js';
1010
import { generateUuid } from './base/common/uuid.js';
1111

12+
export const canASAR = false; // TODO@esm: ASAR disabled in ESM
13+
1214
declare const window: any;
1315
declare const document: any;
1416
declare const self: any;
@@ -216,7 +218,7 @@ export async function importAMDNodeModule<T>(nodeModuleName: string, pathInsideN
216218
// bit of a special case for: src/vs/workbench/services/languageDetection/browser/languageDetectionWebWorker.ts
217219
scriptSrc = nodeModulePath;
218220
} else {
219-
const useASAR = (isBuilt && (platform.isElectron || (platform.isWebWorker && platform.hasElectronUserAgent)));
221+
const useASAR = (canASAR && isBuilt && !platform.isWeb);
220222
const actualNodeModulesPath = (useASAR ? nodeModulesAsarPath : nodeModulesPath);
221223
const resourcePath: AppResourcePath = `${actualNodeModulesPath}/${nodeModulePath}`;
222224
scriptSrc = FileAccess.asBrowserUri(resourcePath).toString(true);
@@ -229,7 +231,7 @@ export async function importAMDNodeModule<T>(nodeModuleName: string, pathInsideN
229231
export function resolveAmdNodeModulePath(nodeModuleName: string, pathInsideNodeModule: string): string {
230232
const product = globalThis._VSCODE_PRODUCT_JSON as unknown as IProductConfiguration;
231233
const isBuilt = Boolean((product ?? globalThis.vscode?.context?.configuration()?.product)?.commit);
232-
const useASAR = (isBuilt && (platform.isElectron || (platform.isWebWorker && platform.hasElectronUserAgent)));
234+
const useASAR = (canASAR && isBuilt && !platform.isWeb);
233235

234236
const nodeModulePath = `${nodeModuleName}/${pathInsideNodeModule}`;
235237
const actualNodeModulesPath = (useASAR ? nodeModulesAsarPath : nodeModulesPath);

src/vs/base/common/network.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ export type AppResourcePath = (
257257

258258
export const builtinExtensionsPath: AppResourcePath = 'vs/../../extensions';
259259
export const nodeModulesPath: AppResourcePath = 'vs/../../node_modules';
260-
export const nodeModulesAsarPath: AppResourcePath = 'vs/../../node_modules.asar/node_modules';
261-
export const nodeModulesAsarUnpackedPath: AppResourcePath = 'vs/../../node_modules.asar.unpacked/node_modules';
260+
export const nodeModulesAsarPath: AppResourcePath = 'vs/../../node_modules.asar';
261+
export const nodeModulesAsarUnpackedPath: AppResourcePath = 'vs/../../node_modules.asar.unpacked';
262262

263263
export const VSCODE_AUTHORITY = 'vscode-app';
264264

src/vs/base/common/platform.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ export const isFirefox = !!(userAgent && userAgent.indexOf('Firefox') >= 0);
274274
export const isSafari = !!(!isChrome && (userAgent && userAgent.indexOf('Safari') >= 0));
275275
export const isEdge = !!(userAgent && userAgent.indexOf('Edg/') >= 0);
276276
export const isAndroid = !!(userAgent && userAgent.indexOf('Android') >= 0);
277-
export const hasElectronUserAgent = !!(userAgent && userAgent.indexOf('Electron') >= 0);
278277

279278
export function isBigSurOrNewer(osVersion: string): boolean {
280279
return parseFloat(osVersion) >= 20;

0 commit comments

Comments
 (0)