Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(build): replace source in environments with `environmentDe… #4476

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@ By default, the development build target and environment are used.
The mapping used to determine which environment file is used can be found in `angular-cli.json`:

```json
"environmentSource": "environments/environment.ts",
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}

```

These options also apply to the serve command. If you do not pass a value for `environment`,
Expand Down
2 changes: 1 addition & 1 deletion docs/documentation/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ By default, the development build target and environment are used.
The mapping used to determine which environment file is used can be found in `angular-cli.json`:

```json
"environmentSource": "environments/environment.ts",
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"styles.<%= styleExt %>"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
Expand Down
5 changes: 5 additions & 0 deletions packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
},
"additionalProperties": false
},
"environmentSource": {
"description": "Source file for environment config.",
"type": "string",
"additionalProperties": true
},
"environments": {
"description": "Name and corresponding file for environment config.",
"type": "object",
Expand Down
7 changes: 4 additions & 3 deletions packages/@angular/cli/models/webpack-configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ export function getCommonConfig(wco: WebpackConfigOptions) {

// process environment file replacement
if (appConfig.environments) {
if (!('source' in appConfig.environments)) {
throw new SilentError(`Environment configuration does not contain "source" entry.`);
if (!('source' in appConfig.environmentSource)) {
throw new SilentError(`Environment configuration does not contain
"environmentSource" entry.`);
}
if (!(buildOptions.environment in appConfig.environments)) {
throw new SilentError(`Environment "${buildOptions.environment}" does not exist.`);
Expand All @@ -84,7 +85,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
// This plugin is responsible for swapping the environment files.
// Since it takes a RegExp as first parameter, we need to escape the path.
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
new RegExp(path.resolve(appRoot, appConfig['environmentSource'])
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
path.resolve(appRoot, appConfig.environments[buildOptions.environment])
));
Expand Down
2 changes: 1 addition & 1 deletion packages/@angular/cli/models/webpack-configs/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const getTestConfig = function (projectRoot, environment, appConfig, testConfig)
// This plugin is responsible for swapping the environment files.
// Since it takes a RegExp as first parameter, we need to escape the path.
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
new RegExp(path.resolve(appRoot, appConfig['source'])
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
path.resolve(appRoot, appConfig.environments[environment])
),
Expand Down