Skip to content

Commit 3302352

Browse files
committed
refactor(@angular-devkit/build-angular): remove redundant webpack-sources dependency
The `webpack` package now exports the `Source` based classes directly.
1 parent 36dd4cc commit 3302352

File tree

8 files changed

+36
-48
lines changed

8 files changed

+36
-48
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"@types/text-table": "^0.2.1",
121121
"@types/uuid": "^8.0.0",
122122
"@types/webpack-dev-server": "^3.1.7",
123-
"@types/webpack-sources": "^2.0.0",
124123
"@yarnpkg/lockfile": "1.1.0",
125124
"ajv": "8.1.0",
126125
"ajv-formats": "2.0.2",
@@ -228,7 +227,6 @@
228227
"webpack-dev-middleware": "4.1.0",
229228
"webpack-dev-server": "3.11.2",
230229
"webpack-merge": "5.7.3",
231-
"webpack-sources": "2.2.0",
232230
"webpack-subresource-integrity": "1.5.2",
233231
"zone.js": "^0.11.3"
234232
}

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ ts_library(
135135
"@npm//@types/semver",
136136
"@npm//@types/text-table",
137137
"@npm//@types/webpack-dev-server",
138-
"@npm//@types/webpack-sources",
139138
"@npm//ajv",
140139
"@npm//ansi-colors",
141140
"@npm//babel-loader",
@@ -193,7 +192,6 @@ ts_library(
193192
"@npm//webpack-dev-middleware",
194193
"@npm//webpack-dev-server",
195194
"@npm//webpack-merge",
196-
"@npm//webpack-sources",
197195
"@npm//webpack-subresource-integrity",
198196
],
199197
)

packages/angular_devkit/build_angular/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"webpack-dev-middleware": "4.1.0",
7474
"webpack-dev-server": "3.11.2",
7575
"webpack-merge": "5.7.3",
76-
"webpack-sources": "2.2.0",
7776
"webpack-subresource-integrity": "1.5.2"
7877
},
7978
"peerDependencies": {

packages/angular_devkit/build_angular/src/utils/process-bundle.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ import * as path from 'path';
2323
import { RawSourceMap, SourceMapConsumer, SourceMapGenerator } from 'source-map';
2424
import { minify } from 'terser';
2525
import * as v8 from 'v8';
26-
import {
26+
import { sources } from 'webpack';
27+
import { allowMangle, allowMinify, shouldBeautify } from './environment-options';
28+
import { I18nOptions } from './i18n-options';
29+
30+
const {
2731
ConcatSource,
2832
OriginalSource,
2933
ReplaceSource,
30-
Source,
3134
SourceMapSource,
32-
} from 'webpack-sources';
33-
import { allowMangle, allowMinify, shouldBeautify } from './environment-options';
34-
import { I18nOptions } from './i18n-options';
35+
} = sources;
3536

3637
type LocalizeUtilities = typeof import('@angular/localize/src/tools/src/source_file_utils');
3738

@@ -233,7 +234,7 @@ async function mergeSourceMaps(
233234
true,
234235
).map()!;
235236

236-
return finalSourceMap;
237+
return finalSourceMap as RawSourceMap;
237238
}
238239

239240
async function mergeSourceMapsFast(first: RawSourceMap, second: RawSourceMap) {
@@ -773,12 +774,12 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
773774
content.replace(position.start, position.end - 1, code);
774775
}
775776

776-
let outputSource: Source = content;
777+
let outputSource: sources.Source = content;
777778
if (options.setLocale) {
778779
const setLocaleText = `var $localize=Object.assign(void 0===$localize?{}:$localize,{locale:"${locale}"});\n`;
779780

780781
// If locale data is provided, load it and prepend to file
781-
let localeDataSource: Source | null = null;
782+
let localeDataSource: sources.Source | null = null;
782783
const localeDataPath = i18n.locales[locale] && i18n.locales[locale].dataPath;
783784
if (localeDataPath) {
784785
const localeDataContent = await loadLocaleData(localeDataPath, true, options.es5);
@@ -791,7 +792,10 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
791792
: new ConcatSource(setLocaleText, content);
792793
}
793794

794-
const { source: outputCode, map: outputMap } = outputSource.sourceAndMap();
795+
const { source: outputCode, map: outputMap } = outputSource.sourceAndMap() as {
796+
source: string;
797+
map: RawSourceMap;
798+
};
795799
const outputPath = path.join(
796800
options.outputPath,
797801
i18n.flatOutput ? '' : locale,

packages/angular_devkit/build_angular/src/webpack/plugins/analytics.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
Compiler,
1212
Module,
1313
Stats,
14+
sources,
1415
} from 'webpack';
15-
import { OriginalSource } from 'webpack-sources';
1616

1717
const NormalModule = require('webpack/lib/NormalModule');
1818

1919
interface NormalModule extends Module {
20-
_source?: OriginalSource | null;
20+
_source?: sources.OriginalSource | null;
2121
resource?: string;
2222
}
2323

@@ -154,14 +154,14 @@ export class NgBuildAnalyticsPlugin {
154154

155155
// Just count the ngOnInit occurences. Comments/Strings/calls occurences should be sparse
156156
// so we just consider them within the margin of error. We do break on word break though.
157-
this._stats.numberOfNgOnInit += countOccurrences(module._source.source(), 'ngOnInit', true);
157+
this._stats.numberOfNgOnInit += countOccurrences(module._source.source().toString(), 'ngOnInit', true);
158158

159159
// Count the number of `Component({` strings (case sensitive), which happens in __decorate().
160-
this._stats.numberOfComponents += countOccurrences(module._source.source(), 'Component({');
160+
this._stats.numberOfComponents += countOccurrences(module._source.source().toString(), 'Component({');
161161
// For Ivy we just count ɵcmp.
162-
this._stats.numberOfComponents += countOccurrences(module._source.source(), '.ɵcmp', true);
162+
this._stats.numberOfComponents += countOccurrences(module._source.source().toString(), '.ɵcmp', true);
163163
// for ascii_only true
164-
this._stats.numberOfComponents += countOccurrences(module._source.source(), '.\u0275cmp', true);
164+
this._stats.numberOfComponents += countOccurrences(module._source.source().toString(), '.\u0275cmp', true);
165165
}
166166
}
167167

packages/angular_devkit/build_angular/src/webpack/plugins/index-html-webpack-plugin.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import { basename, dirname, extname } from 'path';
9-
import { Compilation, Compiler } from 'webpack';
10-
import { RawSource } from 'webpack-sources';
9+
import { Compilation, Compiler, sources } from 'webpack';
1110
import { FileInfo } from '../../utils/index-file/augment-index-html';
1211
import { IndexHtmlGenerator, IndexHtmlGeneratorOptions, IndexHtmlGeneratorProcessOptions } from '../../utils/index-file/index-html-generator';
1312
import { addError, addWarning } from '../../utils/webpack-diagnostics';
@@ -80,7 +79,7 @@ export class IndexHtmlWebpackPlugin extends IndexHtmlGenerator {
8079
lang: this.options.lang,
8180
});
8281

83-
assets[this.options.outputPath] = new RawSource(content);
82+
assets[this.options.outputPath] = new sources.RawSource(content);
8483

8584
warnings.forEach(msg => addWarning(this.compilation, msg));
8685
errors.forEach(msg => addError(this.compilation, msg));

packages/angular_devkit/build_angular/src/webpack/plugins/scripts-webpack-plugin.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
import { interpolateName } from 'loader-utils';
1010
import * as path from 'path';
11-
import { Chunk, Compilation, Compiler } from 'webpack';
12-
import { CachedSource, ConcatSource, OriginalSource, RawSource, Source } from 'webpack-sources';
11+
import { Chunk, Compilation, Compiler, sources as webpackSources } from 'webpack';
1312

1413
const Entrypoint = require('webpack/lib/Entrypoint');
1514
export interface ScriptsWebpackPluginOptions {
@@ -22,7 +21,7 @@ export interface ScriptsWebpackPluginOptions {
2221

2322
interface ScriptOutput {
2423
filename: string;
25-
source: CachedSource;
24+
source: webpackSources.CachedSource;
2625
}
2726

2827
function addDependencies(compilation: Compilation, scripts: string[]): void {
@@ -107,7 +106,7 @@ export class ScriptsWebpackPlugin {
107106
}
108107

109108
const sourceGetters = scripts.map(fullPath => {
110-
return new Promise<Source>((resolve, reject) => {
109+
return new Promise<webpackSources.Source>((resolve, reject) => {
111110
compilation.inputFileSystem.readFile(fullPath, (err?: Error, data?: string | Buffer) => {
112111
if (err) {
113112
reject(err);
@@ -125,9 +124,9 @@ export class ScriptsWebpackPlugin {
125124
if (this.options.basePath) {
126125
adjustedPath = path.relative(this.options.basePath, fullPath);
127126
}
128-
source = new OriginalSource(content, adjustedPath);
127+
source = new webpackSources.OriginalSource(content, adjustedPath);
129128
} else {
130-
source = new RawSource(content);
129+
source = new webpackSources.RawSource(content);
131130
}
132131

133132
resolve(source);
@@ -136,13 +135,13 @@ export class ScriptsWebpackPlugin {
136135
});
137136

138137
const sources = await Promise.all(sourceGetters);
139-
const concatSource = new ConcatSource();
138+
const concatSource = new webpackSources.ConcatSource();
140139
sources.forEach(source => {
141140
concatSource.add(source);
142141
concatSource.add('\n;');
143142
});
144143

145-
const combinedSource = new CachedSource(concatSource);
144+
const combinedSource = new webpackSources.CachedSource(concatSource);
146145
const filename = interpolateName(
147146
{ resourcePath: 'scripts.js' },
148147
this.options.filename as string,

yarn.lock

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,15 +2138,6 @@
21382138
"@types/source-list-map" "*"
21392139
source-map "^0.6.1"
21402140

2141-
"@types/webpack-sources@^2.0.0":
2142-
version "2.1.0"
2143-
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-2.1.0.tgz#8882b0bd62d1e0ce62f183d0d01b72e6e82e8c10"
2144-
integrity sha512-LXn/oYIpBeucgP1EIJbKQ2/4ZmpvRl+dlrFdX7+94SKRUV3Evy3FsfMZY318vGhkWUS5MPhtOM3w1/hCOAOXcg==
2145-
dependencies:
2146-
"@types/node" "*"
2147-
"@types/source-list-map" "*"
2148-
source-map "^0.7.3"
2149-
21502141
"@types/webpack@*":
21512142
version "5.28.0"
21522143
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-5.28.0.tgz#78dde06212f038d77e54116cfe69e88ae9ed2c03"
@@ -12726,14 +12717,6 @@ webpack-merge@5.7.3:
1272612717
clone-deep "^4.0.1"
1272712718
wildcard "^2.0.0"
1272812719

12729-
webpack-sources@2.2.0, webpack-sources@^2.1.1:
12730-
version "2.2.0"
12731-
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-2.2.0.tgz#058926f39e3d443193b6c31547229806ffd02bac"
12732-
integrity sha512-bQsA24JLwcnWGArOKUxYKhX3Mz/nK1Xf6hxullKERyktjNMC4x8koOeaDNTA2fEJ09BdWLbM/iTW0ithREUP0w==
12733-
dependencies:
12734-
source-list-map "^2.0.1"
12735-
source-map "^0.6.1"
12736-
1273712720
webpack-sources@^1.1.0, webpack-sources@^1.2.0, webpack-sources@^1.3.0, webpack-sources@^1.4.3:
1273812721
version "1.4.3"
1273912722
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933"
@@ -12742,6 +12725,14 @@ webpack-sources@^1.1.0, webpack-sources@^1.2.0, webpack-sources@^1.3.0, webpack-
1274212725
source-list-map "^2.0.0"
1274312726
source-map "~0.6.1"
1274412727

12728+
webpack-sources@^2.1.1:
12729+
version "2.2.0"
12730+
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-2.2.0.tgz#058926f39e3d443193b6c31547229806ffd02bac"
12731+
integrity sha512-bQsA24JLwcnWGArOKUxYKhX3Mz/nK1Xf6hxullKERyktjNMC4x8koOeaDNTA2fEJ09BdWLbM/iTW0ithREUP0w==
12732+
dependencies:
12733+
source-list-map "^2.0.1"
12734+
source-map "^0.6.1"
12735+
1274512736
webpack-subresource-integrity@1.5.2:
1274612737
version "1.5.2"
1274712738
resolved "https://registry.yarnpkg.com/webpack-subresource-integrity/-/webpack-subresource-integrity-1.5.2.tgz#e40b6578d3072e2d24104975249c52c66e9a743e"

0 commit comments

Comments
 (0)