From d06d2d2eef8a28295537eab85951343a29b7129e Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Wed, 8 Oct 2025 10:27:57 +0000 Subject: [PATCH] build: improve source map configuration for better debugging This commit refactors the jasmine_test rule in tools/defaults.bzl to use the centralized version from @devinfra//bazel/jasmine:jasmine.bzl. This simplifies the rule by removing manual source-map-support handling. Source map generation has been standardized across the project by enabling the sourceMap option in the root tsconfig.json and removing conflicting inline source map settings from test-specific configurations. These changes significantly improve the developer experience by enabling breakpoints to be set directly within TypeScript source files when debugging tests in editors like VSCode. Additionally, the exclusion rules for .vscode/tasks.json and .vscode/launch.json have been removed from .gitignore, aligning with the standard practice of not tracking user-specific editor configurations. --- .gitignore | 2 +- .vscode/launch.json | 49 +++++++++++++++++++ .vscode/settings.json | 26 ++++++++++ .../angular/workspace/index_spec.ts | 1 - tools/defaults.bzl | 14 ++---- tsconfig-test-esm.json | 3 -- tsconfig-test.json | 6 --- tsconfig.json | 1 + 8 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index de3ad9a9154d..83582f8ece43 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,7 @@ jsconfig.json # VSCode # https://github.com/github/gitignore/blob/master/Global/VisualStudioCode.gitignore -.vscode/ +.vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000000..6f3e0e3d3375 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,49 @@ +// A launch configuration that compiles the extension and then opens it inside a new window +{ + "version": "0.2.0", + "configurations": [ + { + "name": "DEBUG: Attach to bazel test", + "type": "node", + "request": "attach", + "port": 9229, + "restart": true, + "timeout": 600000, + "sourceMaps": true, + "skipFiles": ["/**"], + "sourceMapPathOverrides": { + "?:*@0.0.0/node_modules/@angular-devkit/build-angular/*": "${workspaceFolder}/packages/angular_devkit/build_angular/*", + "?:*@0.0.0/node_modules/@angular-devkit/build-webpack/*": "${workspaceFolder}/packages/angular_devkit/build_webpack/*", + "?:*@0.0.0/node_modules/@angular-devkit/*": "${workspaceFolder}/packages/angular_devkit/*", + "?:*@0.0.0/node_modules/@angular/*": "${workspaceFolder}/packages/angular/*", + "?:*/bin/*": "${workspaceFolder}/*" + }, + "resolveSourceMapLocations": ["*/**", "!**/rxjs**"] + }, + { + "name": "DEBUG: Run bazel test (Custom Target)", + "type": "node", + "request": "launch", + "restart": true, + "timeout": 600000, + "runtimeExecutable": "pnpm", + "runtimeArgs": ["bazel", "test", "${input:bazelTarget}", "--config=debug"], + "console": "integratedTerminal", + "cwd": "${workspaceFolder}" + } + ], + "compounds": [ + { + "name": "DEBUG: Run bazel test (Custom Target) + Attach", + "configurations": ["DEBUG: Attach to bazel test", "DEBUG: Run bazel test (Custom Target)"] + } + ], + "inputs": [ + { + "id": "bazelTarget", + "type": "promptString", + "description": "Enter the Bazel test target (e.g., //path/to/my:unit_test)", + "default": "//packages/..." + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000000..b98a874af297 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,26 @@ +{ + "[javascript]": { + "editor.formatOnSave": true + }, + "[typescript]": { + "editor.formatOnSave": true + }, + // Exclude third party modules and build artifacts from the editor watchers/searches. + "files.watcherExclude": { + "**/.git/objects/**": true, + "**/.git/subtree-cache/**": true, + "**/node_modules/**": true, + "**/bazel-out/**": true, + "**/dist/**": true, + "**/dist-schema/**": true + }, + "search.exclude": { + "**/node_modules": true, + "**/bazel-out": true, + "**/dist": true, + "**/dist-schema": true, + ".history": true + }, + "git.ignoreLimitWarning": true, + "gitlens.advanced.blame.customArguments": ["--ignore-revs-file .git-blame-ignore-revs"] +} diff --git a/packages/schematics/angular/workspace/index_spec.ts b/packages/schematics/angular/workspace/index_spec.ts index b5c75b4a6d61..22be6e797e14 100644 --- a/packages/schematics/angular/workspace/index_spec.ts +++ b/packages/schematics/angular/workspace/index_spec.ts @@ -23,7 +23,6 @@ describe('Workspace Schematic', () => { it('should create all files of a workspace', async () => { const options = { ...defaultOptions }; - const tree = await schematicRunner.runSchematic('workspace', options); const files = tree.files; expect(files).toEqual( diff --git a/tools/defaults.bzl b/tools/defaults.bzl index dc99b2b24e56..2304bec17698 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -1,6 +1,6 @@ load("@aspect_bazel_lib//lib:copy_to_bin.bzl", _copy_to_bin = "copy_to_bin") -load("@aspect_rules_jasmine//jasmine:defs.bzl", _jasmine_test = "jasmine_test") load("@aspect_rules_js//js:defs.bzl", _js_binary = "js_binary") +load("@devinfra//bazel/jasmine:jasmine.bzl", _jasmine_test = "jasmine_test") load("@devinfra//bazel/ts_project:index.bzl", "strict_deps_test") load("@rules_angular//src/ng_package:index.bzl", _ng_package = "ng_package") load("@rules_angular//src/ts_project:index.bzl", _ts_project = "ts_project") @@ -12,6 +12,7 @@ def ts_project( deps = [], tsconfig = None, testonly = False, + source_map = True, visibility = None, **kwargs): if tsconfig == None: @@ -21,6 +22,7 @@ def ts_project( name = name, testonly = testonly, declaration = True, + source_map = source_map, tsconfig = tsconfig, visibility = visibility, deps = deps, @@ -54,21 +56,15 @@ def ng_package(deps = [], **kwargs): **kwargs ) -def jasmine_test(data = [], args = [], **kwargs): - # Create relative path to root, from current package dir. Necessary as - # we change the `chdir` below to the package directory. - relative_to_root = "/".join([".."] * len(native.package_name().split("/"))) - +def jasmine_test(args = [], tsconfig = "//:test-tsconfig", **kwargs): _jasmine_test( node_modules = "//:node_modules", + tsconfig = tsconfig, chdir = native.package_name(), args = [ - "--require=%s/node_modules/source-map-support/register.js" % relative_to_root, - # Escape so that the `js_binary` launcher triggers Bash expansion. "'**/*+(.|_)spec.js'", "'**/*+(.|_)spec.mjs'", "'**/*+(.|_)spec.cjs'", ] + args, - data = data + ["//:node_modules/source-map-support"], **kwargs ) diff --git a/tsconfig-test-esm.json b/tsconfig-test-esm.json index 4f582716d3eb..1f65ce7b7698 100644 --- a/tsconfig-test-esm.json +++ b/tsconfig-test-esm.json @@ -6,9 +6,6 @@ { "extends": "./tsconfig-build-esm.json", "compilerOptions": { - "sourceMap": false, - "inlineSourceMap": true, - "inlineSources": true, "types": ["node", "jasmine"] } } diff --git a/tsconfig-test.json b/tsconfig-test.json index cae29f3a3cac..d022089a5513 100644 --- a/tsconfig-test.json +++ b/tsconfig-test.json @@ -1,12 +1,6 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "inlineSourceMap": true, - "sourceRoot": ".", - // Inline sources are necessary for our tests to show the proper sources, since we are using - // Istanbul (not Constantinople) as well, and applying both source maps to get the original - // source in devtools. - "inlineSources": true, "types": ["node", "jasmine"] } } diff --git a/tsconfig.json b/tsconfig.json index f00528f2698f..12256cd116ed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "noImplicitOverride": true, "isolatedModules": true, "skipLibCheck": true, + "sourceMap": true, "strict": true, "target": "es2023", "lib": ["es2023"],