Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): ensure karma sourcemap support on…
Browse files Browse the repository at this point in the history
… Windows

The `glob`-based check when adding the sourcemap support packages to the karma setup was incorrectly
skipping the files due to Windows pathing issues. The `glob`-based check, however, is unneeded due
to the already present `require.resolve` checks for the sourcemap support packages which will
throw if the packages are not present.
  • Loading branch information
clydin authored and alan-agius4 committed Apr 16, 2022
1 parent c24be81 commit 1a160da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ jobs:
name: Execute E2E Tests
command: |
if (Test-Path env:CIRCLE_PULL_REQUEST) {
node tests\legacy-cli\run_e2e.js "--glob={tests/basic/**,tests/i18n/extract-ivy*.ts,tests/build/profile.ts}" --nb-shards=$env:CIRCLE_NODE_TOTAL --shard=$env:CIRCLE_NODE_INDEX
node tests\legacy-cli\run_e2e.js "--glob={tests/basic/**,tests/i18n/extract-ivy*.ts,tests/build/profile.ts,tests/test/test-sourcemap.ts}" --nb-shards=$env:CIRCLE_NODE_TOTAL --shard=$env:CIRCLE_NODE_INDEX
} else {
node tests\legacy-cli\run_e2e.js --nb-shards=$env:CIRCLE_NODE_TOTAL --shard=$env:CIRCLE_NODE_INDEX
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
// TODO: cleanup this file, it's copied as is from Angular CLI.
import * as http from 'http';
import * as path from 'path';
import * as glob from 'glob';
import webpack from 'webpack';
import webpackDevMiddleware from 'webpack-dev-middleware';

Expand All @@ -28,29 +27,6 @@ let webpackMiddleware: any;
let successCb: () => void;
let failureCb: () => void;

// Add files to the Karma files array.
function addKarmaFiles(files: any[], newFiles: any[], prepend = false) {
const defaults = {
included: true,
served: true,
watched: true,
};

const processedFiles = newFiles
// Remove globs that do not match any files, otherwise Karma will show a warning for these.
.filter((file) => glob.sync(file.pattern, { nodir: true }).length != 0)
// Fill in pattern properties with defaults.
.map((file) => ({ ...defaults, ...file }));

// It's important to not replace the array, because
// karma already has a reference to the existing array.
if (prepend) {
files.unshift(...processedFiles);
} else {
files.push(...processedFiles);
}
}

const init: any = (config: any, emitter: any) => {
if (!config.buildWebpack) {
throw new Error(
Expand All @@ -73,13 +49,14 @@ const init: any = (config: any, emitter: any) => {
const smsPath = path.dirname(require.resolve('source-map-support'));
const ksmsPath = path.dirname(require.resolve('karma-source-map-support'));

addKarmaFiles(
config.files,
[
{ pattern: path.join(smsPath, 'browser-source-map-support.js'), watched: false },
{ pattern: path.join(ksmsPath, 'client.js'), watched: false },
],
true,
config.files.unshift(
{
pattern: path.join(smsPath, 'browser-source-map-support.js'),
included: true,
served: true,
watched: false,
},
{ pattern: path.join(ksmsPath, 'client.js'), included: true, served: true, watched: false },
);
}

Expand Down

0 comments on commit 1a160da

Please sign in to comment.