@angular/build 21.0.0-next.3 → 21.0.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/package.json +11 -11
  2. package/src/builders/application/index.js +2 -1
  3. package/src/builders/karma/application_builder.d.ts +0 -2
  4. package/src/builders/karma/application_builder.js +44 -352
  5. package/src/builders/karma/assets-middleware.d.ts +26 -0
  6. package/src/builders/karma/assets-middleware.js +65 -0
  7. package/src/builders/karma/coverage.d.ts +9 -0
  8. package/src/builders/karma/coverage.js +31 -0
  9. package/src/builders/karma/find-tests.d.ts +1 -9
  10. package/src/builders/karma/find-tests.js +6 -106
  11. package/src/builders/karma/karma-config.d.ts +11 -0
  12. package/src/builders/karma/karma-config.js +79 -0
  13. package/src/builders/karma/polyfills-plugin.d.ts +13 -0
  14. package/src/builders/karma/polyfills-plugin.js +74 -0
  15. package/src/builders/karma/progress-reporter.d.ts +17 -0
  16. package/src/builders/karma/progress-reporter.js +73 -0
  17. package/src/builders/karma/utils.d.ts +17 -0
  18. package/src/builders/karma/utils.js +66 -0
  19. package/src/builders/unit-test/builder.js +150 -44
  20. package/src/builders/unit-test/options.d.ts +5 -1
  21. package/src/builders/unit-test/options.js +12 -5
  22. package/src/builders/unit-test/runners/api.d.ts +19 -1
  23. package/src/builders/unit-test/runners/dependency-checker.d.ts +43 -0
  24. package/src/builders/unit-test/runners/dependency-checker.js +82 -0
  25. package/src/builders/unit-test/runners/karma/executor.js +26 -2
  26. package/src/builders/unit-test/runners/karma/index.js +17 -0
  27. package/src/builders/unit-test/runners/vitest/browser-provider.d.ts +3 -2
  28. package/src/builders/unit-test/runners/vitest/build-options.js +6 -4
  29. package/src/builders/unit-test/runners/vitest/executor.d.ts +4 -5
  30. package/src/builders/unit-test/runners/vitest/executor.js +23 -135
  31. package/src/builders/unit-test/runners/vitest/index.js +19 -2
  32. package/src/builders/unit-test/runners/vitest/plugins.d.ts +23 -0
  33. package/src/builders/unit-test/runners/vitest/plugins.js +131 -0
  34. package/src/builders/unit-test/schema.d.ts +59 -30
  35. package/src/builders/unit-test/schema.js +1 -1
  36. package/src/builders/unit-test/schema.json +70 -16
  37. package/src/builders/unit-test/test-discovery.d.ts +25 -1
  38. package/src/builders/unit-test/test-discovery.js +194 -5
  39. package/src/tools/angular/transformers/jit-bootstrap-transformer.js +1 -1
  40. package/src/tools/angular/transformers/jit-resource-transformer.js +1 -1
  41. package/src/tools/esbuild/application-code-bundle.js +4 -7
  42. package/src/tools/esbuild/stylesheets/less-language.js +2 -26
  43. package/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.js +2 -1
  44. package/src/tools/vite/middlewares/assets-middleware.d.ts +2 -0
  45. package/src/tools/vite/middlewares/assets-middleware.js +31 -0
  46. package/src/tools/vite/utils.js +0 -1
  47. package/src/utils/normalize-cache.js +1 -1
  48. package/src/utils/supported-browsers.js +7 -3
  49. package/src/utils/test-files.d.ts +17 -0
  50. package/src/utils/test-files.js +82 -0
  51. package/.browserslistrc +0 -7
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.AngularAssetsMiddleware = void 0;
14
+ const node_path_1 = __importDefault(require("node:path"));
15
+ const isWindows = process.platform === 'win32';
16
+ const LATEST_BUILD_FILES_TOKEN = 'angularLatestBuildFiles';
17
+ class AngularAssetsMiddleware {
18
+ serveFile;
19
+ latestBuildFiles;
20
+ static $inject = ['serveFile', LATEST_BUILD_FILES_TOKEN];
21
+ static NAME = 'angular-test-assets';
22
+ constructor(serveFile, latestBuildFiles) {
23
+ this.serveFile = serveFile;
24
+ this.latestBuildFiles = latestBuildFiles;
25
+ }
26
+ handle(req, res, next) {
27
+ const url = new URL(`http://${req.headers['host'] ?? ''}${req.url ?? ''}`);
28
+ // Remove the leading slash from the URL path and convert to platform specific.
29
+ // The latest build files will use the platform path separator.
30
+ let pathname = url.pathname.slice(1);
31
+ if (isWindows) {
32
+ pathname = pathname.replaceAll(node_path_1.default.posix.sep, node_path_1.default.win32.sep);
33
+ }
34
+ const file = this.latestBuildFiles.files[pathname];
35
+ if (!file) {
36
+ next();
37
+ return;
38
+ }
39
+ // Implementation of serverFile can be found here:
40
+ // https://github.com/karma-runner/karma/blob/84f85e7016efc2266fa6b3465f494a3fa151c85c/lib/middleware/common.js#L10
41
+ switch (file.origin) {
42
+ case 'disk':
43
+ this.serveFile(file.inputPath, undefined, res, undefined, undefined, /* doNotCache */ true);
44
+ break;
45
+ case 'memory':
46
+ // Include pathname to help with Content-Type headers.
47
+ this.serveFile(`/unused/${url.pathname}`, undefined, res, undefined, file.contents,
48
+ /* doNotCache */ false);
49
+ break;
50
+ }
51
+ }
52
+ static createPlugin(initialFiles) {
53
+ return {
54
+ [LATEST_BUILD_FILES_TOKEN]: ['value', { files: { ...initialFiles.files } }],
55
+ [`middleware:${AngularAssetsMiddleware.NAME}`]: [
56
+ 'factory',
57
+ Object.assign((...args) => {
58
+ const inst = new AngularAssetsMiddleware(...args);
59
+ return inst.handle.bind(inst);
60
+ }, AngularAssetsMiddleware),
61
+ ],
62
+ };
63
+ }
64
+ }
65
+ exports.AngularAssetsMiddleware = AngularAssetsMiddleware;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ export declare function createInstrumentationFilter(includedBasePath: string, excludedPaths: Set<string>): (request: string) => boolean;
9
+ export declare function getInstrumentationExcludedPaths(root: string, excludedPaths: string[]): Set<string>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.createInstrumentationFilter = createInstrumentationFilter;
14
+ exports.getInstrumentationExcludedPaths = getInstrumentationExcludedPaths;
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ const tinyglobby_1 = require("tinyglobby");
17
+ function createInstrumentationFilter(includedBasePath, excludedPaths) {
18
+ return (request) => {
19
+ return (!excludedPaths.has(request) &&
20
+ !/\.(e2e|spec)\.tsx?$|[\\/]node_modules[\\/]|[\\/]\.angular[\\/]/.test(request) &&
21
+ request.startsWith(includedBasePath));
22
+ };
23
+ }
24
+ function getInstrumentationExcludedPaths(root, excludedPaths) {
25
+ const excluded = new Set();
26
+ for (const excludeGlob of excludedPaths) {
27
+ const excludePath = excludeGlob[0] === '/' ? excludeGlob.slice(1) : excludeGlob;
28
+ (0, tinyglobby_1.globSync)(excludePath, { cwd: root }).forEach((p) => excluded.add(node_path_1.default.join(root, p)));
29
+ }
30
+ return excluded;
31
+ }
@@ -5,12 +5,4 @@
5
5
  * Use of this source code is governed by an MIT-style license that can be
6
6
  * found in the LICENSE file at https://angular.dev/license
7
7
  */
8
- export declare function findTests(include: string[], exclude: string[], workspaceRoot: string, projectSourceRoot: string): Promise<string[]>;
9
- interface TestEntrypointsOptions {
10
- projectSourceRoot: string;
11
- workspaceRoot: string;
12
- removeTestExtension?: boolean;
13
- }
14
- /** Generate unique bundle names for a set of test files. */
15
- export declare function getTestEntrypoints(testFiles: string[], { projectSourceRoot, workspaceRoot, removeTestExtension }: TestEntrypointsOptions): Map<string, string>;
16
- export {};
8
+ export { findTests, getTestEntrypoints } from '../unit-test/test-discovery';
@@ -7,109 +7,9 @@
7
7
  * found in the LICENSE file at https://angular.dev/license
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.findTests = findTests;
11
- exports.getTestEntrypoints = getTestEntrypoints;
12
- const node_fs_1 = require("node:fs");
13
- const node_path_1 = require("node:path");
14
- const tinyglobby_1 = require("tinyglobby");
15
- const path_1 = require("../../utils/path");
16
- /* Go through all patterns and find unique list of files */
17
- async function findTests(include, exclude, workspaceRoot, projectSourceRoot) {
18
- const matchingTestsPromises = include.map((pattern) => findMatchingTests(pattern, exclude, workspaceRoot, projectSourceRoot));
19
- const files = await Promise.all(matchingTestsPromises);
20
- // Unique file names
21
- return [...new Set(files.flat())];
22
- }
23
- /** Generate unique bundle names for a set of test files. */
24
- function getTestEntrypoints(testFiles, { projectSourceRoot, workspaceRoot, removeTestExtension }) {
25
- const seen = new Set();
26
- return new Map(Array.from(testFiles, (testFile) => {
27
- const relativePath = removeRoots(testFile, [projectSourceRoot, workspaceRoot])
28
- // Strip leading dots and path separators.
29
- .replace(/^[./\\]+/, '')
30
- // Replace any path separators with dashes.
31
- .replace(/[/\\]/g, '-');
32
- let fileName = (0, node_path_1.basename)(relativePath, (0, node_path_1.extname)(relativePath));
33
- if (removeTestExtension) {
34
- fileName = fileName.replace(/\.(spec|test)$/, '');
35
- }
36
- const baseName = `spec-${fileName}`;
37
- let uniqueName = baseName;
38
- let suffix = 2;
39
- while (seen.has(uniqueName)) {
40
- uniqueName = `${baseName}-${suffix}`.replace(/([^\w](?:spec|test))-([\d]+)$/, '-$2$1');
41
- ++suffix;
42
- }
43
- seen.add(uniqueName);
44
- return [uniqueName, testFile];
45
- }));
46
- }
47
- const removeLeadingSlash = (pattern) => {
48
- if (pattern.charAt(0) === '/') {
49
- return pattern.substring(1);
50
- }
51
- return pattern;
52
- };
53
- const removeRelativeRoot = (path, root) => {
54
- if (path.startsWith(root)) {
55
- return path.substring(root.length);
56
- }
57
- return path;
58
- };
59
- function removeRoots(path, roots) {
60
- for (const root of roots) {
61
- if (path.startsWith(root)) {
62
- return path.substring(root.length);
63
- }
64
- }
65
- return (0, node_path_1.basename)(path);
66
- }
67
- async function findMatchingTests(pattern, ignore, workspaceRoot, projectSourceRoot) {
68
- // normalize pattern, glob lib only accepts forward slashes
69
- let normalizedPattern = (0, path_1.toPosixPath)(pattern);
70
- normalizedPattern = removeLeadingSlash(normalizedPattern);
71
- const relativeProjectRoot = (0, path_1.toPosixPath)((0, node_path_1.relative)(workspaceRoot, projectSourceRoot) + '/');
72
- // remove relativeProjectRoot to support relative paths from root
73
- // such paths are easy to get when running scripts via IDEs
74
- normalizedPattern = removeRelativeRoot(normalizedPattern, relativeProjectRoot);
75
- // special logic when pattern does not look like a glob
76
- if (!(0, tinyglobby_1.isDynamicPattern)(normalizedPattern)) {
77
- if (await isDirectory((0, node_path_1.join)(projectSourceRoot, normalizedPattern))) {
78
- normalizedPattern = `${normalizedPattern}/**/*.spec.@(ts|tsx)`;
79
- }
80
- else {
81
- // see if matching spec file exists
82
- const fileExt = (0, node_path_1.extname)(normalizedPattern);
83
- // Replace extension to `.spec.ext`. Example: `src/app/app.component.ts`-> `src/app/app.component.spec.ts`
84
- const potentialSpec = (0, node_path_1.join)(projectSourceRoot, (0, node_path_1.dirname)(normalizedPattern), `${(0, node_path_1.basename)(normalizedPattern, fileExt)}.spec${fileExt}`);
85
- if (await exists(potentialSpec)) {
86
- return [potentialSpec];
87
- }
88
- }
89
- }
90
- // normalize the patterns in the ignore list
91
- const normalizedIgnorePatternList = ignore.map((pattern) => removeRelativeRoot(removeLeadingSlash((0, path_1.toPosixPath)(pattern)), relativeProjectRoot));
92
- return (0, tinyglobby_1.glob)(normalizedPattern, {
93
- cwd: projectSourceRoot,
94
- absolute: true,
95
- ignore: ['**/node_modules/**', ...normalizedIgnorePatternList],
96
- });
97
- }
98
- async function isDirectory(path) {
99
- try {
100
- const stats = await node_fs_1.promises.stat(path);
101
- return stats.isDirectory();
102
- }
103
- catch {
104
- return false;
105
- }
106
- }
107
- async function exists(path) {
108
- try {
109
- await node_fs_1.promises.access(path, node_fs_1.constants.F_OK);
110
- return true;
111
- }
112
- catch {
113
- return false;
114
- }
115
- }
10
+ exports.getTestEntrypoints = exports.findTests = void 0;
11
+ // This file is a compatibility layer that re-exports the test discovery logic from its new location.
12
+ // This is necessary to avoid breaking the Karma builder, which still depends on this file.
13
+ var test_discovery_1 = require("../unit-test/test-discovery");
14
+ Object.defineProperty(exports, "findTests", { enumerable: true, get: function () { return test_discovery_1.findTests; } });
15
+ Object.defineProperty(exports, "getTestEntrypoints", { enumerable: true, get: function () { return test_discovery_1.getTestEntrypoints; } });
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import type { BuilderContext } from '@angular-devkit/architect';
9
+ import type { ConfigOptions } from 'karma';
10
+ import type { NormalizedKarmaBuilderOptions } from './options';
11
+ export declare function getBaseKarmaOptions(options: NormalizedKarmaBuilderOptions, context: BuilderContext): ConfigOptions;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.getBaseKarmaOptions = getBaseKarmaOptions;
14
+ const node_module_1 = require("node:module");
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ function getBaseKarmaOptions(options, context) {
17
+ // Determine project name from builder context target
18
+ const projectName = context.target?.project;
19
+ if (!projectName) {
20
+ throw new Error(`The 'karma' builder requires a target to be specified.`);
21
+ }
22
+ const karmaOptions = options.karmaConfig
23
+ ? {}
24
+ : getBuiltInKarmaConfig(context.workspaceRoot, projectName);
25
+ const singleRun = !options.watch;
26
+ karmaOptions.singleRun = singleRun;
27
+ // Workaround https://github.com/angular/angular-cli/issues/28271, by clearing context by default
28
+ // for single run executions. Not clearing context for multi-run (watched) builds allows the
29
+ // Jasmine Spec Runner to be visible in the browser after test execution.
30
+ karmaOptions.client ??= {};
31
+ karmaOptions.client.clearContext ??= singleRun;
32
+ // Convert browsers from a string to an array
33
+ if (options.browsers) {
34
+ karmaOptions.browsers = options.browsers;
35
+ }
36
+ if (options.reporters) {
37
+ karmaOptions.reporters = options.reporters;
38
+ }
39
+ return karmaOptions;
40
+ }
41
+ function getBuiltInKarmaConfig(workspaceRoot, projectName) {
42
+ let coverageFolderName = projectName.charAt(0) === '@' ? projectName.slice(1) : projectName;
43
+ coverageFolderName = coverageFolderName.toLowerCase();
44
+ const workspaceRootRequire = (0, node_module_1.createRequire)(workspaceRoot + '/');
45
+ // Any changes to the config here need to be synced to: packages/schematics/angular/config/files/karma.conf.js.template
46
+ return {
47
+ basePath: '',
48
+ frameworks: ['jasmine'],
49
+ plugins: [
50
+ 'karma-jasmine',
51
+ 'karma-chrome-launcher',
52
+ 'karma-jasmine-html-reporter',
53
+ 'karma-coverage',
54
+ ].map((p) => workspaceRootRequire(p)),
55
+ jasmineHtmlReporter: {
56
+ suppressAll: true, // removes the duplicated traces
57
+ },
58
+ coverageReporter: {
59
+ dir: node_path_1.default.join(workspaceRoot, 'coverage', coverageFolderName),
60
+ subdir: '.',
61
+ reporters: [{ type: 'html' }, { type: 'text-summary' }],
62
+ },
63
+ reporters: ['progress', 'kjhtml'],
64
+ browsers: ['Chrome'],
65
+ customLaunchers: {
66
+ // Chrome configured to run in a bazel sandbox.
67
+ // Disable the use of the gpu and `/dev/shm` because it causes Chrome to
68
+ // crash on some environments.
69
+ // See:
70
+ // https://github.com/puppeteer/puppeteer/blob/v1.0.0/docs/troubleshooting.md#tips
71
+ // https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t
72
+ ChromeHeadlessNoSandbox: {
73
+ base: 'ChromeHeadless',
74
+ flags: ['--no-sandbox', '--headless', '--disable-gpu', '--disable-dev-shm-usage'],
75
+ },
76
+ },
77
+ restartOnFileChange: true,
78
+ };
79
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import type { FilePattern, InlinePluginDef } from 'karma';
9
+ export declare class AngularPolyfillsPlugin {
10
+ static readonly $inject: string[];
11
+ static readonly NAME = "angular-polyfills";
12
+ static createPlugin(polyfillsFile: FilePattern, jasmineCleanupFiles: FilePattern, scriptsFiles: FilePattern[]): InlinePluginDef;
13
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.AngularPolyfillsPlugin = void 0;
11
+ const node_module_1 = require("node:module");
12
+ const localResolve = (0, node_module_1.createRequire)(__filename).resolve;
13
+ class AngularPolyfillsPlugin {
14
+ static $inject = ['config.files'];
15
+ static NAME = 'angular-polyfills';
16
+ static createPlugin(polyfillsFile, jasmineCleanupFiles, scriptsFiles) {
17
+ return {
18
+ // This has to be a "reporter" because reporters run _after_ frameworks
19
+ // and karma-jasmine-html-reporter injects additional scripts that may
20
+ // depend on Jasmine but aren't modules - which means that they would run
21
+ // _before_ all module code (including jasmine).
22
+ [`reporter:${AngularPolyfillsPlugin.NAME}`]: [
23
+ 'factory',
24
+ Object.assign((files) => {
25
+ // The correct order is zone.js -> jasmine -> zone.js/testing.
26
+ // Jasmine has to see the patched version of the global `setTimeout`
27
+ // function so it doesn't cache the unpatched version. And /testing
28
+ // needs to see the global `jasmine` object so it can patch it.
29
+ const polyfillsIndex = 0;
30
+ files.splice(polyfillsIndex, 0, polyfillsFile);
31
+ // Insert just before test_main.js.
32
+ const zoneTestingIndex = files.findIndex((f) => {
33
+ if (typeof f === 'string') {
34
+ return false;
35
+ }
36
+ return f.pattern.endsWith('/test_main.js');
37
+ });
38
+ if (zoneTestingIndex === -1) {
39
+ throw new Error('Could not find test entrypoint file.');
40
+ }
41
+ files.splice(zoneTestingIndex, 0, jasmineCleanupFiles);
42
+ // We need to ensure that all files are served as modules, otherwise
43
+ // the order in the files list gets really confusing: Karma doesn't
44
+ // set defer on scripts, so all scripts with type=js will run first,
45
+ // even if type=module files appeared earlier in `files`.
46
+ for (const f of files) {
47
+ if (typeof f === 'string') {
48
+ throw new Error(`Unexpected string-based file: "${f}"`);
49
+ }
50
+ if (f.included === false) {
51
+ // Don't worry about files that aren't included on the initial
52
+ // page load. `type` won't affect them.
53
+ continue;
54
+ }
55
+ if (f.pattern.endsWith('.js') && 'js' === (f.type ?? 'js')) {
56
+ f.type = 'module';
57
+ }
58
+ }
59
+ // Add "scripts" option files as classic scripts
60
+ files.unshift(...scriptsFiles);
61
+ // Add browser sourcemap support as a classic script
62
+ files.unshift({
63
+ pattern: localResolve('source-map-support/browser-source-map-support.js'),
64
+ included: true,
65
+ watched: false,
66
+ });
67
+ // Karma needs a return value for a factory and Karma's multi-reporter expects an `adapters` array
68
+ return { adapters: [] };
69
+ }, AngularPolyfillsPlugin),
70
+ ],
71
+ };
72
+ }
73
+ }
74
+ exports.AngularPolyfillsPlugin = AngularPolyfillsPlugin;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import type { BuilderOutput } from '@angular-devkit/architect';
9
+ import type { Config, ConfigOptions } from 'karma';
10
+ import type { ReadableStreamController } from 'node:stream/web';
11
+ import type { ApplicationBuilderInternalOptions } from '../application/options';
12
+ import type { Result } from '../application/results';
13
+ interface BuildOptions extends ApplicationBuilderInternalOptions {
14
+ outputPath: string;
15
+ }
16
+ export declare function injectKarmaReporter(buildOptions: BuildOptions, buildIterator: AsyncIterator<Result>, karmaConfig: Config & ConfigOptions, controller: ReadableStreamController<BuilderOutput>): void;
17
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.injectKarmaReporter = injectKarmaReporter;
11
+ const test_files_1 = require("../../utils/test-files");
12
+ const results_1 = require("../application/results");
13
+ const LATEST_BUILD_FILES_TOKEN = 'angularLatestBuildFiles';
14
+ function injectKarmaReporter(buildOptions, buildIterator, karmaConfig, controller) {
15
+ const reporterName = 'angular-progress-notifier';
16
+ class ProgressNotifierReporter {
17
+ emitter;
18
+ latestBuildFiles;
19
+ static $inject = ['emitter', LATEST_BUILD_FILES_TOKEN];
20
+ constructor(emitter, latestBuildFiles) {
21
+ this.emitter = emitter;
22
+ this.latestBuildFiles = latestBuildFiles;
23
+ this.startWatchingBuild();
24
+ }
25
+ startWatchingBuild() {
26
+ void (async () => {
27
+ // This is effectively "for await of but skip what's already consumed".
28
+ let isDone = false; // to mark the loop condition as "not constant".
29
+ while (!isDone) {
30
+ const { done, value: buildOutput } = await buildIterator.next();
31
+ if (done) {
32
+ isDone = true;
33
+ break;
34
+ }
35
+ if (buildOutput.kind === results_1.ResultKind.Failure) {
36
+ controller.enqueue({ success: false, message: 'Build failed' });
37
+ }
38
+ else if (buildOutput.kind === results_1.ResultKind.Incremental ||
39
+ buildOutput.kind === results_1.ResultKind.Full) {
40
+ if (buildOutput.kind === results_1.ResultKind.Full) {
41
+ this.latestBuildFiles.files = buildOutput.files;
42
+ }
43
+ else {
44
+ this.latestBuildFiles.files = {
45
+ ...this.latestBuildFiles.files,
46
+ ...buildOutput.files,
47
+ };
48
+ }
49
+ await (0, test_files_1.writeTestFiles)(buildOutput.files, buildOptions.outputPath);
50
+ this.emitter.refreshFiles();
51
+ }
52
+ }
53
+ })();
54
+ }
55
+ onRunComplete = function (_browsers, results) {
56
+ if (results.exitCode === 0) {
57
+ controller.enqueue({ success: true });
58
+ }
59
+ else {
60
+ controller.enqueue({ success: false });
61
+ }
62
+ };
63
+ }
64
+ karmaConfig.reporters ??= [];
65
+ karmaConfig.reporters.push(reporterName);
66
+ karmaConfig.plugins ??= [];
67
+ karmaConfig.plugins.push({
68
+ [`reporter:${reporterName}`]: [
69
+ 'factory',
70
+ Object.assign((...args) => new ProgressNotifierReporter(...args), ProgressNotifierReporter),
71
+ ],
72
+ });
73
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright Google LLC All Rights Reserved.
4
+ *
5
+ * Use of this source code is governed by an MIT-style license that can be
6
+ * found in the LICENSE file at https://angular.dev/license
7
+ */
8
+ import type { BuilderContext } from '@angular-devkit/architect';
9
+ import type { NormalizedKarmaBuilderOptions } from './options';
10
+ export declare function getProjectSourceRoot(context: BuilderContext): Promise<string>;
11
+ export declare function normalizePolyfills(polyfills?: string[]): [polyfills: string[], jasmineCleanup: string[]];
12
+ export declare function collectEntrypoints(options: NormalizedKarmaBuilderOptions, context: BuilderContext, projectSourceRoot: string): Promise<Map<string, string>>;
13
+ export declare function hasChunkOrWorkerFiles(files: Record<string, unknown>): boolean;
14
+ /** Returns the first item yielded by the given generator and cancels the execution. */
15
+ export declare function first<T>(generator: AsyncIterable<T>, { cancel }: {
16
+ cancel: boolean;
17
+ }): Promise<[T, AsyncIterator<T> | null]>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ /**
3
+ * @license
4
+ * Copyright Google LLC All Rights Reserved.
5
+ *
6
+ * Use of this source code is governed by an MIT-style license that can be
7
+ * found in the LICENSE file at https://angular.dev/license
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.getProjectSourceRoot = getProjectSourceRoot;
11
+ exports.normalizePolyfills = normalizePolyfills;
12
+ exports.collectEntrypoints = collectEntrypoints;
13
+ exports.hasChunkOrWorkerFiles = hasChunkOrWorkerFiles;
14
+ exports.first = first;
15
+ const node_module_1 = require("node:module");
16
+ const project_metadata_1 = require("../../utils/project-metadata");
17
+ const find_tests_1 = require("./find-tests");
18
+ const localResolve = (0, node_module_1.createRequire)(__filename).resolve;
19
+ async function getProjectSourceRoot(context) {
20
+ // We have already validated that the project name is set before calling this function.
21
+ const projectName = context.target?.project;
22
+ if (!projectName) {
23
+ return context.workspaceRoot;
24
+ }
25
+ const projectMetadata = await context.getProjectMetadata(projectName);
26
+ const { projectSourceRoot } = (0, project_metadata_1.getProjectRootPaths)(context.workspaceRoot, projectMetadata);
27
+ return projectSourceRoot;
28
+ }
29
+ function normalizePolyfills(polyfills = []) {
30
+ const jasmineGlobalEntryPoint = localResolve('./polyfills/jasmine_global.js');
31
+ const jasmineGlobalCleanupEntrypoint = localResolve('./polyfills/jasmine_global_cleanup.js');
32
+ const sourcemapEntrypoint = localResolve('./polyfills/init_sourcemaps.js');
33
+ const zoneTestingEntryPoint = 'zone.js/testing';
34
+ const polyfillsExludingZoneTesting = polyfills.filter((p) => p !== zoneTestingEntryPoint);
35
+ return [
36
+ polyfillsExludingZoneTesting.concat([jasmineGlobalEntryPoint, sourcemapEntrypoint]),
37
+ polyfillsExludingZoneTesting.length === polyfills.length
38
+ ? [jasmineGlobalCleanupEntrypoint]
39
+ : [jasmineGlobalCleanupEntrypoint, zoneTestingEntryPoint],
40
+ ];
41
+ }
42
+ async function collectEntrypoints(options, context, projectSourceRoot) {
43
+ // Glob for files to test.
44
+ const testFiles = await (0, find_tests_1.findTests)(options.include, options.exclude, context.workspaceRoot, projectSourceRoot);
45
+ return (0, find_tests_1.getTestEntrypoints)(testFiles, { projectSourceRoot, workspaceRoot: context.workspaceRoot });
46
+ }
47
+ function hasChunkOrWorkerFiles(files) {
48
+ return Object.keys(files).some((filename) => {
49
+ return /(?:^|\/)(?:worker|chunk)[^/]+\.js$/.test(filename);
50
+ });
51
+ }
52
+ /** Returns the first item yielded by the given generator and cancels the execution. */
53
+ async function first(generator, { cancel }) {
54
+ if (!cancel) {
55
+ const iterator = generator[Symbol.asyncIterator]();
56
+ const firstValue = await iterator.next();
57
+ if (firstValue.done) {
58
+ throw new Error('Expected generator to emit at least once.');
59
+ }
60
+ return [firstValue.value, iterator];
61
+ }
62
+ for await (const value of generator) {
63
+ return [value, null];
64
+ }
65
+ throw new Error('Expected generator to emit at least once.');
66
+ }