Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ package-lock.json
.pipelines/
.config/
img/
node_modules/
# VSCE includes npm production dependencies; bundled libraries are devDependencies.
node_modules/@vscode/codicons/
!node_modules/@vscode/codicons/dist/codicon.css
!node_modules/@vscode/codicons/dist/codicon.ttf
out/edge/
Expand Down
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ Here are a list of recommended VS Code extensions to use when developing for vsc
* Select `Launch Tests` debug configuration
* Press `F5` to attach the debugger and start the tests

## Packaging dependencies

Libraries bundled by webpack belong in `devDependencies`: their code ships in the generated bundles,
so their package directories do not need to be included in the VSIX. Keep packages in `dependencies`
only when their files are needed at runtime. VSCE automatically includes their production dependency
trees. This preserves the external `vscode-chrome-debug-core` modules and localization resources;
`.vscodeignore` limits `@vscode/codicons` to the CSS and font used by the webviews.

## Issue tags
* "Bug": Something that should work is broken
* "Enhancement": AKA feature request - adds new functionality
Expand Down
68 changes: 55 additions & 13 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,7 @@
},
"dependencies": {
"@vscode/codicons": "0.0.45",
"@vscode/extension-telemetry": "1.5.2",
"bufferutil": "4.1.0",
"lit-html": "^3.3.3",
"puppeteer-core": "25.16.0",
"utf-8-validate": "6.0.6",
"vscode-chrome-debug-core": "6.8.11",
"ws": "8.22.0",
"xmlhttprequest": "1.8.0"
"vscode-chrome-debug-core": "6.8.11"
},
"devDependencies": {
"@opentelemetry/tracing": "0.24.0",
Expand All @@ -687,21 +680,28 @@
"@types/ws": "8.18.2",
"@typescript-eslint/eslint-plugin": "8.72.0",
"@typescript-eslint/parser": "8.72.0",
"@vscode/extension-telemetry": "1.5.2",
"@vscode/vsce": "^3.9.2",
"bufferutil": "4.1.0",
"copy-webpack-plugin": "14.0.0",
"eslint": "9.39.5",
"eslint-plugin-import": "2.32.0",
"eslint-plugin-jsdoc": "60.8.3",
"eslint-plugin-prefer-arrow": "1.2.3",
"fs-extra": "11.4.1",
"jest": "30.5.2",
"lit-html": "^3.3.3",
"puppeteer-core": "25.16.0",
"ts-jest": "29.4.15",
"ts-loader": "9.6.2",
"typescript": "6.0.3",
"uglify-js": "3.19.3",
"unzipper": "0.12.5",
"utf-8-validate": "6.0.6",
"jest-environment-jsdom": "^30.5.2",
"webpack": "5.112.2",
"webpack-cli": "7.2.3"
"webpack-cli": "7.2.3",
"ws": "8.22.0",
"xmlhttprequest": "1.8.0"
}
}
4 changes: 2 additions & 2 deletions src/devtoolsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
import * as path from 'path';
import * as vscode from 'vscode';
import * as debugCore from 'vscode-chrome-debug-core';
import { UrlPathTransformer } from 'vscode-chrome-debug-core/out/src/transformers/urlPathTransformer';
import { performance } from 'perf_hooks';
import { TelemetryReporter } from '@vscode/extension-telemetry';
import { SettingsProvider } from './common/settingsProvider';
Expand Down Expand Up @@ -524,7 +524,7 @@ export class DevToolsPanel {
}

// Convert the local url to a workspace path
const transformer = new debugCore.UrlPathTransformer();
const transformer = new UrlPathTransformer();
void transformer.launch({ pathMapping: this.config.pathMapping });

// origin in this case is trivial since we expect fixSource to take it out
Expand Down
10 changes: 6 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import { Browser, Target, TargetType } from 'puppeteer-core';
import * as vscode from 'vscode';
import * as debugCore from 'vscode-chrome-debug-core';
import type { ITarget } from 'vscode-chrome-debug-core/out/src/chrome/chromeConnection';
import { getMatchingTargets } from 'vscode-chrome-debug-core/out/src/chrome/chromeUtils';
import { retryAsync } from 'vscode-chrome-debug-core/out/src/utils';
import { TelemetryReporter } from '@vscode/extension-telemetry';
import { CDPTarget } from './cdpTarget';
import { CDPTargetsProvider } from './cdpTargetsProvider';
Expand Down Expand Up @@ -310,7 +312,7 @@ export async function attach(
do {
try {
// Keep trying to attach to the list endpoint until timeout
responseArray = await debugCore.utils.retryAsync(
responseArray = await retryAsync(
() => getListOfTargets(hostname, port, useHttps),
timeout,
/* intervalDelay=*/ SETTINGS_DEFAULT_ATTACH_INTERVAL) as IRemoteTargetJson[];
Expand All @@ -323,9 +325,9 @@ export async function attach(
let targetWebsocketUrl = '';
if (attachUrl) {
// Match the targets using the edge debug adapter logic
let matchedTargets: debugCore.chromeConnection.ITarget[] | undefined;
let matchedTargets: ITarget[] | undefined;
try {
matchedTargets = debugCore.chromeUtils.getMatchingTargets(responseArray as unknown as debugCore.chromeConnection.ITarget[], attachUrl);
matchedTargets = getMatchingTargets(responseArray as unknown as ITarget[], attachUrl);
} catch (e) {
void ErrorReporter.showErrorDialog({
errorCode: ErrorCodes.Error,
Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as os from 'os';
import * as path from 'path';
import * as url from 'url';
import * as vscode from 'vscode';
import * as debugCore from 'vscode-chrome-debug-core';
import { canonicalizeUrl, escapeRegexSpecialChars, properJoin } from 'vscode-chrome-debug-core/out/src/utils';
import { TelemetryReporter } from '@vscode/extension-telemetry';
import packageJson from '../package.json';
import { DebugTelemetryReporter } from './debugTelemetryReporter';
Expand Down Expand Up @@ -579,7 +579,7 @@ export function applyPathMapping(
}

// Does it match?
const escapedLeftPattern = debugCore.utils.escapeRegexSpecialChars(leftPattern, '/*');
const escapedLeftPattern = escapeRegexSpecialChars(leftPattern, '/*');
const leftRegexSegment = escapedLeftPattern
.replace(/\*/g, '(.*)')
.replace(/\\\\/g, '/');
Expand All @@ -599,7 +599,7 @@ export function applyPathMapping(
return mappedPath;
}

mappedPath = debugCore.utils.properJoin(mappedPath); // Fix any ..'s
mappedPath = properJoin(mappedPath); // Fix any ..'s
mappedPath = replaceWorkSpaceFolderPlaceholder(mappedPath);
return mappedPath;
}
Expand Down Expand Up @@ -659,7 +659,7 @@ function replaceWorkSpaceFolderPlaceholder(customPath: string) {
*/
parsedPath = vscode.workspace.workspaceFolders[0].uri.toString();
const replacedPath = customPath.replace('${workspaceFolder}', parsedPath);
return debugCore.utils.canonicalizeUrl(replacedPath);
return canonicalizeUrl(replacedPath);
}
return parsedPath;

Expand Down
157 changes: 157 additions & 0 deletions test/chromeDebugCoreNls.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/** @jest-environment node */
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as fs from 'fs';
import * as path from 'path';
import type { Configuration } from 'webpack';

const extensionRoot = path.resolve(__dirname, '..');
const bundleRoot = path.resolve(path.dirname(require.resolve('vscode-chrome-debug-core/package.json')), 'out');
const createWebpackConfig = require('../webpack.config') as (env: Record<string, unknown>) => Configuration[];

describe('external debug-core localization', () => {
let nls: typeof import('vscode-nls');
let consoleError: jest.SpyInstance;
let consoleWarn: jest.SpyInstance;
const originalNlsConfig = process.env.VSCODE_NLS_CONFIG;

beforeAll(() => {
process.env.VSCODE_NLS_CONFIG = '{}';
nls = jest.requireActual('vscode-nls');
});

beforeEach(() => {
nls.config({ locale: 'en', bundleFormat: nls.BundleFormat.standalone });
consoleError = jest.spyOn(console, 'error');
consoleWarn = jest.spyOn(console, 'warn');
});

afterEach(() => {
try {
expect(consoleError).not.toHaveBeenCalled();
expect(consoleWarn).not.toHaveBeenCalled();
} finally {
consoleError.mockRestore();
consoleWarn.mockRestore();
}
});

afterAll(() => {
if (originalNlsConfig === undefined) {
delete process.env.VSCODE_NLS_CONFIG;
} else {
process.env.VSCODE_NLS_CONFIG = originalNlsConfig;
}
});

function localize(modulePath: string, key: number, ...args: string[]): string {
const messages = nls.loadMessageBundle(path.join(bundleRoot, modulePath));
// The published dependency uses numeric indexes, which its NLS declarations do not expose.
return Reflect.apply(messages, undefined, [key, null, ...args]) as string;
}

it('keeps debug-core and its subpath imports external without matching other packages', () => {
const config = createWebpackConfig({}).find(config => config.name === 'extension');
expect(config?.externalsType).toBe('commonjs');
const externals = config?.externals;
if (!Array.isArray(externals)) {
throw new Error('Expected extension webpack externals to include the debug-core package matcher.');
}
for (const request of [
'vscode-chrome-debug-core',
'vscode-chrome-debug-core/out/src/utils',
'vscode-chrome-debug-core/out/src/chrome/chromeUtils',
'vscode-chrome-debug-core/out/src/transformers/urlPathTransformer',
]) {
expect(externals.some(external => external instanceof RegExp && external.test(request))).toBe(true);
}
expect(externals.some(external => external instanceof RegExp && external.test('vscode-chrome-debug-core-other'))).toBe(false);
});

it('keeps overlapping message indexes separate for each original module', () => {
expect(localize('src/errors.js', 0)).toBe('not available');
expect(localize('src/chrome/stoppedEvent.js', 0)).toBe('Paused on step');
});

it('loads the real errors module without losing its messages', () => {
const errors = jest.requireActual<typeof import('vscode-chrome-debug-core/out/src/errors')>(
'vscode-chrome-debug-core/out/src/errors',
);
expect(errors.evalNotAvailableMsg).toBe('not available');
expect(errors.runtimeNotConnectedMsg).toBe('not connected to runtime');
expect(errors.noRestartFrame).toBe("Can't restart frame");
});

it('preserves message argument substitution', () => {
expect(localize('src/errors.js', 3, 'webRoot', 'missing'))
.toBe("Attribute 'webRoot' does not exist ('missing').");
});

it('uses the existing translation and falls back from a regional locale', () => {
nls.config({ locale: 'de-de' });
const messages = JSON.parse(fs.readFileSync(path.join(bundleRoot, 'nls.bundle.de.json'), 'utf8')) as Record<string, string[]>;
expect(localize('src/errors.js', 0)).toBe(messages['src/errors'][0]);
expect(localize('src/chrome/stoppedEvent.js', 0)).toBe(messages['src/chrome/stoppedEvent'][0]);
expect(messages['src/errors'][0]).not.toBe('not available');
});

it('falls back to the default messages for an unsupported locale', () => {
nls.config({ locale: 'unsupported-locale' });
expect(localize('src/errors.js', 0)).toBe('not available');
});

it('includes the original modules, NLS resources, runtime dependencies, and codicons in the VSIX file list', async () => {
const { listFiles } = jest.requireActual<typeof import('@vscode/vsce')>('@vscode/vsce');
const files = await listFiles({ cwd: extensionRoot });
const packagedPath = (filename: string): string => path.relative(extensionRoot, filename).split(path.sep).join('/');
for (const request of [
'vscode-chrome-debug-core/out/src/utils',
'vscode-chrome-debug-core/out/src/chrome/chromeUtils',
'vscode-chrome-debug-core/out/src/transformers/urlPathTransformer',
'vscode-chrome-debug-core/out/src/errors',
'vscode-nls',
'vscode-debugadapter',
'ws',
]) {
expect(files).toContain(packagedPath(require.resolve(request, { paths: [bundleRoot] })));
}
for (const name of fs.readdirSync(bundleRoot).filter(name => /^nls.*\.json$/.test(name))) {
expect(files).toContain(packagedPath(path.join(bundleRoot, name)));
}
const visited = new Set<string>();
function expectDependencyTree(name: string, from: string): void {
const manifestPath = require.resolve(`${name}/package.json`, { paths: [from] });
if (visited.has(manifestPath)) {
return;
}
visited.add(manifestPath);
expect(files).toContain(packagedPath(manifestPath));
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as {
dependencies?: Record<string, string>;
};
for (const dependency of Object.keys(manifest.dependencies ?? {})) {
expectDependencyTree(dependency, path.dirname(manifestPath));
}
}
expectDependencyTree('vscode-chrome-debug-core', extensionRoot);
expect(files.filter(file => file.startsWith('node_modules/@vscode/codicons/')).sort()).toEqual([
'node_modules/@vscode/codicons/dist/codicon.css',
'node_modules/@vscode/codicons/dist/codicon.ttf',
]);
for (const dependency of [
'puppeteer-core',
'@puppeteer',
'@vscode/extension-telemetry',
'@microsoft',
'@opentelemetry',
'applicationinsights',
'bufferutil',
'lit-html',
'utf-8-validate',
'xmlhttprequest',
]) {
expect(files.some(file => file.startsWith(`node_modules/${dependency}/`))).toBe(false);
}
}, 30000);
});
8 changes: 4 additions & 4 deletions test/devtoolsPanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ describe("devtoolsPanel", () => {
isHeadlessEnabled: jest.fn(),
};
jest.doMock("../src/utils", () => mockUtils);
jest.mock("vscode-chrome-debug-core", () => mockDebugCore);
jest.mock("vscode-chrome-debug-core/out/src/transformers/urlPathTransformer", () => mockDebugCore);

const mockVsCode = jest.requireMock("vscode");
mockVsCode.Uri.file = jest.fn();
Expand Down Expand Up @@ -570,7 +570,7 @@ describe("devtoolsPanel", () => {
isHeadlessEnabled: jest.fn(),
};
jest.doMock("../src/utils", () => mockUtils);
jest.mock("vscode-chrome-debug-core", () => mockDebugCore);
jest.mock("vscode-chrome-debug-core/out/src/transformers/urlPathTransformer", () => mockDebugCore);

const mockVsCode = jest.requireMock("vscode");
mockVsCode.Uri.file = jest.fn();
Expand Down Expand Up @@ -605,7 +605,7 @@ describe("devtoolsPanel", () => {
isHeadlessEnabled: jest.fn(),
};
jest.doMock("../src/utils", () => mockUtils);
jest.mock("vscode-chrome-debug-core", () => mockDebugCore);
jest.mock("vscode-chrome-debug-core/out/src/transformers/urlPathTransformer", () => mockDebugCore);

const mockVsCode = jest.requireMock("vscode");
const dtp = await import("../src/devtoolsPanel");
Expand Down Expand Up @@ -638,7 +638,7 @@ describe("devtoolsPanel", () => {
isHeadlessEnabled: jest.fn(),
};
jest.doMock("../src/utils", () => mockUtils);
jest.mock("vscode-chrome-debug-core", () => mockDebugCore);
jest.mock("vscode-chrome-debug-core/out/src/transformers/urlPathTransformer", () => mockDebugCore);

const mockVsCode = jest.requireMock("vscode");
mockVsCode.Uri.file = jest.fn();
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"esModuleInterop": true,
"noImplicitAny": true,
"moduleResolution": "bundler",
// The dependency publishes JavaScript under out/src and declarations under lib/src.
"paths": {
"vscode-chrome-debug-core/out/src/*": [
"./node_modules/vscode-chrome-debug-core/lib/src/*"
]
},
// TypeScript 6 no longer includes every node_modules/@types package
// automatically, so the ambient globals used here must be listed.
"types": [
Expand Down
13 changes: 9 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ module.exports = env => {
entry: {
extension: './src/extension.ts',
},
externals: {
vscode: 'commonjs vscode',
'applicationinsights-native-metrics': 'commonjs applicationinsights-native-metrics', // We're not native
},
externalsType: 'commonjs',
externals: [
{
vscode: 'commonjs vscode',
'applicationinsights-native-metrics': 'commonjs applicationinsights-native-metrics', // We're not native
},
// Keep debug-core's original filenames so its adjacent NLS resources resolve normally.
/^vscode-chrome-debug-core(?:\/.*)?$/,
],
name: 'extension',
target: 'node',
resolve: {
Expand Down
Loading