Skip to content

Commit 8480df7

Browse files
clydinhansl
authored andcommitted
refactor: remove support for Angular 2 and 4
1 parent bc10dd2 commit 8480df7

File tree

93 files changed

+119
-3453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+119
-3453
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"copy-webpack-plugin": "~4.4.1",
5757
"core-object": "^3.1.0",
5858
"ember-cli-string-utils": "^1.0.0",
59-
"enhanced-resolve": "^3.4.1",
6059
"extract-text-webpack-plugin": "^3.0.2",
6160
"file-loader": "^1.1.5",
6261
"fs-extra": "^4.0.0",

packages/@angular/cli/models/webpack-configs/production.ts

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import * as path from 'path';
21
import * as webpack from 'webpack';
32
import * as fs from 'fs';
43
import * as semver from 'semver';
54
import { stripIndent } from 'common-tags';
65
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
76
import { PurifyPlugin } from '@angular-devkit/build-optimizer';
87
import { BundleBudgetPlugin } from '../../plugins/bundle-budget';
9-
import { StaticAssetPlugin } from '../../plugins/static-asset';
10-
import { GlobCopyWebpackPlugin } from '../../plugins/glob-copy-webpack-plugin';
118
import { WebpackConfigOptions } from '../webpack-config';
129
import { resolveProjectModule } from '../../utilities/require-project-module';
1310
import { NEW_SW_VERSION } from '../../utilities/service-worker';
1411

1512
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
1613

17-
const OLD_SW_VERSION = '>= 1.0.0-beta.5 < 2.0.0';
1814

1915
/**
2016
* license-webpack-plugin has a peer dependency on webpack-sources, list it in a comment to
@@ -28,7 +24,6 @@ export function getProdConfig(wco: WebpackConfigOptions) {
2824
const { projectRoot, buildOptions, appConfig } = wco;
2925

3026
let extraPlugins: any[] = [];
31-
let entryPoints: { [key: string]: string[] } = {};
3227

3328
if (appConfig.serviceWorker) {
3429
let swPackageJsonPath;
@@ -48,70 +43,15 @@ export function getProdConfig(wco: WebpackConfigOptions) {
4843
// expected version.
4944
const swPackageJson = fs.readFileSync(swPackageJsonPath).toString();
5045
const swVersion = JSON.parse(swPackageJson)['version'];
51-
52-
const isLegacySw = semver.satisfies(swVersion, OLD_SW_VERSION);
5346
const isModernSw = semver.gte(swVersion, NEW_SW_VERSION);
5447

55-
if (!isLegacySw && !isModernSw) {
48+
if (!isModernSw) {
5649
throw new Error(stripIndent`
5750
The installed version of @angular/service-worker is ${swVersion}. This version of the CLI
58-
requires the @angular/service-worker version to satisfy ${OLD_SW_VERSION}. Please upgrade
51+
requires the @angular/service-worker version to satisfy ${NEW_SW_VERSION}. Please upgrade
5952
your service worker version.
6053
`);
6154
}
62-
63-
if (isLegacySw) {
64-
// Path to the @angular/service-worker package
65-
const swModule = path.dirname(swPackageJsonPath);
66-
67-
// Path to the worker script itself.
68-
const workerPath = path.resolve(swModule, 'bundles/worker-basic.min.js');
69-
70-
// Path to a small script to register a service worker.
71-
const registerPath = path.resolve(swModule, 'build/assets/register-basic.min.js');
72-
73-
// Sanity check - both of these files should be present in @angular/service-worker.
74-
if (!fs.existsSync(workerPath) || !fs.existsSync(registerPath)) {
75-
throw new Error(stripIndent`
76-
The installed version of @angular/service-worker isn't supported by the CLI.
77-
Please install a supported version. The following files should exist:
78-
- ${registerPath}
79-
- ${workerPath}
80-
`);
81-
}
82-
83-
// CopyWebpackPlugin replaces GlobCopyWebpackPlugin, but AngularServiceWorkerPlugin depends
84-
// on specific behaviour from latter.
85-
// AngularServiceWorkerPlugin expects the ngsw-manifest.json to be present in the 'emit' phase
86-
// but with CopyWebpackPlugin it's only there on 'after-emit'.
87-
// So for now we keep it here, but if AngularServiceWorkerPlugin changes we remove it.
88-
extraPlugins.push(new GlobCopyWebpackPlugin({
89-
patterns: [
90-
'ngsw-manifest.json',
91-
{ glob: 'ngsw-manifest.json',
92-
input: path.resolve(projectRoot, appConfig.root), output: '' }
93-
],
94-
globOptions: {
95-
cwd: projectRoot,
96-
optional: true,
97-
},
98-
}));
99-
100-
// Load the Webpack plugin for manifest generation and install it.
101-
const AngularServiceWorkerPlugin = require('@angular/service-worker/build/webpack')
102-
.AngularServiceWorkerPlugin;
103-
extraPlugins.push(new AngularServiceWorkerPlugin({
104-
baseHref: buildOptions.baseHref || '/',
105-
}));
106-
107-
// Copy the worker script into assets.
108-
const workerContents = fs.readFileSync(workerPath).toString();
109-
extraPlugins.push(new StaticAssetPlugin('worker-basic.min.js', workerContents));
110-
111-
// Add a script to index.html that registers the service worker.
112-
// TODO(alxhub): inline this script somehow.
113-
entryPoints['sw-register'] = [registerPath];
114-
}
11555
}
11656

11757
extraPlugins.push(new BundleBudgetPlugin({
@@ -145,7 +85,6 @@ export function getProdConfig(wco: WebpackConfigOptions) {
14585
}
14686

14787
return {
148-
entry: entryPoints,
14988
plugins: [
15089
new webpack.EnvironmentPlugin({
15190
'NODE_ENV': 'production'

packages/@angular/cli/models/webpack-configs/typescript.ts

Lines changed: 34 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as path from 'path';
22
import { stripIndent } from 'common-tags';
33
import {
4-
AotPlugin,
5-
AotPluginOptions,
64
AngularCompilerPlugin,
75
AngularCompilerPluginOptions,
86
PLATFORM
@@ -80,47 +78,31 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any, useMain = tru
8078
};
8179
}
8280

83-
if (AngularCompilerPlugin.isSupported()) {
84-
const additionalLazyModules: { [module: string]: string } = {};
85-
if (appConfig.lazyModules) {
86-
for (const lazyModule of appConfig.lazyModules) {
87-
additionalLazyModules[lazyModule] = path.resolve(
88-
projectRoot,
89-
appConfig.root,
90-
lazyModule,
91-
);
92-
}
81+
const additionalLazyModules: { [module: string]: string } = {};
82+
if (appConfig.lazyModules) {
83+
for (const lazyModule of appConfig.lazyModules) {
84+
additionalLazyModules[lazyModule] = path.resolve(
85+
projectRoot,
86+
appConfig.root,
87+
lazyModule,
88+
);
9389
}
94-
95-
const pluginOptions: AngularCompilerPluginOptions = Object.assign({}, {
96-
mainPath: useMain ? path.join(projectRoot, appConfig.root, appConfig.main) : undefined,
97-
i18nInFile: buildOptions.i18nFile,
98-
i18nInFormat: buildOptions.i18nFormat,
99-
i18nOutFile: buildOptions.i18nOutFile,
100-
i18nOutFormat: buildOptions.i18nOutFormat,
101-
locale: buildOptions.locale,
102-
platform: appConfig.platform === 'server' ? PLATFORM.Server : PLATFORM.Browser,
103-
missingTranslation: buildOptions.missingTranslation,
104-
hostReplacementPaths,
105-
sourceMap: buildOptions.sourcemaps,
106-
additionalLazyModules,
107-
}, options);
108-
return new AngularCompilerPlugin(pluginOptions);
109-
} else {
110-
const pluginOptions: AotPluginOptions = Object.assign({}, {
111-
mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
112-
i18nFile: buildOptions.i18nFile,
113-
i18nFormat: buildOptions.i18nFormat,
114-
locale: buildOptions.locale,
115-
replaceExport: appConfig.platform === 'server',
116-
missingTranslation: buildOptions.missingTranslation,
117-
hostReplacementPaths,
118-
sourceMap: buildOptions.sourcemaps,
119-
// If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`.
120-
exclude: []
121-
}, options);
122-
return new AotPlugin(pluginOptions);
12390
}
91+
92+
const pluginOptions: AngularCompilerPluginOptions = Object.assign({}, {
93+
mainPath: useMain ? path.join(projectRoot, appConfig.root, appConfig.main) : undefined,
94+
i18nInFile: buildOptions.i18nFile,
95+
i18nInFormat: buildOptions.i18nFormat,
96+
i18nOutFile: buildOptions.i18nOutFile,
97+
i18nOutFormat: buildOptions.i18nOutFormat,
98+
locale: buildOptions.locale,
99+
platform: appConfig.platform === 'server' ? PLATFORM.Server : PLATFORM.Browser,
100+
missingTranslation: buildOptions.missingTranslation,
101+
hostReplacementPaths,
102+
sourceMap: buildOptions.sourcemaps,
103+
additionalLazyModules,
104+
}, options);
105+
return new AngularCompilerPlugin(pluginOptions);
124106
}
125107

126108
export function getNonAotConfig(wco: WebpackConfigOptions) {
@@ -136,67 +118,34 @@ export function getNonAotConfig(wco: WebpackConfigOptions) {
136118
export function getAotConfig(wco: WebpackConfigOptions) {
137119
const { projectRoot, buildOptions, appConfig } = wco;
138120
const tsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.tsconfig);
139-
const testTsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.testTsconfig);
140121

141-
let pluginOptions: any = { tsConfigPath };
142-
143-
// Fallback to exclude spec files from AoT compilation on projects using a shared tsconfig.
144-
if (testTsConfigPath === tsConfigPath) {
145-
let exclude = [ '**/*.spec.ts' ];
146-
if (appConfig.test) {
147-
exclude.push(path.join(projectRoot, appConfig.root, appConfig.test));
148-
}
149-
pluginOptions.exclude = exclude;
150-
}
151-
152-
let boLoader: any = [];
122+
const loaders: any[] = [ webpackLoader ];
153123
if (buildOptions.buildOptimizer) {
154-
boLoader = [{
124+
loaders.unshift({
155125
loader: '@angular-devkit/build-optimizer/webpack-loader',
156126
options: { sourceMap: buildOptions.sourcemaps }
157-
}];
127+
});
158128
}
159129

160-
const test = AngularCompilerPlugin.isSupported()
161-
? /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/
162-
: /\.ts$/;
130+
const test = /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/;
163131

164132
return {
165-
module: { rules: [{ test, use: [...boLoader, webpackLoader] }] },
166-
plugins: [ _createAotPlugin(wco, pluginOptions) ]
133+
module: { rules: [{ test, use: loaders }] },
134+
plugins: [ _createAotPlugin(wco, { tsConfigPath }) ]
167135
};
168136
}
169137

170138
export function getNonAotTestConfig(wco: WebpackConfigOptions) {
171139
const { projectRoot, appConfig } = wco;
172140
const tsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.testTsconfig);
173-
const appTsConfigPath = path.resolve(projectRoot, appConfig.root, appConfig.tsconfig);
174141

175142
let pluginOptions: any = { tsConfigPath, skipCodeGeneration: true };
176143

177-
if (AngularCompilerPlugin.isSupported()) {
178-
if (appConfig.polyfills) {
179-
// TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
180-
// include 'polyfills.ts' in `tsconfig.spec.json'.
181-
const polyfillsPath = path.resolve(projectRoot, appConfig.root, appConfig.polyfills);
182-
pluginOptions.singleFileIncludes = [polyfillsPath];
183-
}
184-
} else {
185-
// The options below only apply to AoTPlugin.
186-
// Force include main and polyfills.
187-
// This is needed for AngularCompilerPlugin compatibility with existing projects,
188-
// since TS compilation there is stricter and tsconfig.spec.ts doesn't include them.
189-
const include = [appConfig.main, appConfig.polyfills, '**/*.spec.ts'];
190-
if (appConfig.test) {
191-
include.push(appConfig.test);
192-
}
193-
194-
pluginOptions.include = include;
195-
196-
// Fallback to correct module format on projects using a shared tsconfig.
197-
if (tsConfigPath === appTsConfigPath) {
198-
pluginOptions.compilerOptions = { module: 'commonjs' };
199-
}
144+
if (appConfig.polyfills) {
145+
// TODO: remove singleFileIncludes for 2.0, this is just to support old projects that did not
146+
// include 'polyfills.ts' in `tsconfig.spec.json'.
147+
const polyfillsPath = path.resolve(projectRoot, appConfig.root, appConfig.polyfills);
148+
pluginOptions.singleFileIncludes = [polyfillsPath];
200149
}
201150

202151
return {

packages/@angular/cli/plugins/glob-copy-webpack-plugin.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

packages/@angular/cli/plugins/static-asset.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/@angular/cli/plugins/webpack.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Exports the webpack plugins we use internally.
22
export { BaseHrefWebpackPlugin } from '../lib/base-href-webpack/base-href-webpack-plugin';
33
export { CleanCssWebpackPlugin, CleanCssWebpackPluginOptions } from './cleancss-webpack-plugin';
4-
export { GlobCopyWebpackPlugin, GlobCopyWebpackPluginOptions } from './glob-copy-webpack-plugin';
54
export { BundleBudgetPlugin, BundleBudgetPluginOptions } from './bundle-budget';
65
export { NamedLazyChunksWebpackPlugin } from './named-lazy-chunks-webpack-plugin';
76
export { ScriptsWebpackPlugin, ScriptsWebpackPluginOptions } from './scripts-webpack-plugin';

0 commit comments

Comments
 (0)