Skip to content

Commit aca0345

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 2301fdb + 39b9522 commit aca0345

File tree

12 files changed

+79
-6198
lines changed

12 files changed

+79
-6198
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
dist/
22
node_modules/
33
npm-debug.log*
4+
yarn.lock
45

56
# IDEs
67
.idea/

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ To use these preprocessors simply add the file to your component's `styleUrls`:
328328
```javascript
329329
@Component({
330330
selector: 'app-root',
331-
templateUrl: 'app.component.html',
332-
styleUrls: ['app.component.scss']
331+
templateUrl: './app.component.html',
332+
styleUrls: ['./app.component.scss']
333333
})
334334
export class AppComponent {
335335
title = 'app works!';

packages/@ngtools/webpack/src/loader.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ function _removeModuleId(refactor: TypeScriptFileRefactor) {
108108
});
109109
}
110110

111+
function _getResourceRequest(element: ts.Expression, sourceFile: ts.SourceFile) {
112+
if (element.kind == ts.SyntaxKind.StringLiteral) {
113+
// if string, assume relative path unless it start with /
114+
return `'${loaderUtils.urlToRequest((element as ts.StringLiteral).text, '')}'`;
115+
} else {
116+
// if not string, just use expression directly
117+
return element.getFullText(sourceFile);
118+
}
119+
}
120+
111121
function _replaceResources(refactor: TypeScriptFileRefactor): void {
112122
const sourceFile = refactor.sourceFile;
113123

@@ -132,7 +142,7 @@ function _replaceResources(refactor: TypeScriptFileRefactor): void {
132142

133143
if (key == 'templateUrl') {
134144
refactor.replaceNode(node,
135-
`template: require(${node.initializer.getFullText(sourceFile)})`);
145+
`template: require(${_getResourceRequest(node.initializer, sourceFile)})`);
136146
} else if (key == 'styleUrls') {
137147
const arr = <ts.ArrayLiteralExpression[]>(
138148
refactor.findAstNodes(node, ts.SyntaxKind.ArrayLiteralExpression, false));
@@ -141,7 +151,7 @@ function _replaceResources(refactor: TypeScriptFileRefactor): void {
141151
}
142152

143153
const initializer = arr[0].elements.map((element: ts.Expression) => {
144-
return element.getFullText(sourceFile);
154+
return _getResourceRequest(element, sourceFile);
145155
});
146156
refactor.replaceNode(node, `styles: [require(${initializer.join('), require(')})]`);
147157
}

packages/angular-cli/blueprints/ng2/files/tslint.json

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"no-empty-interface": true,
4747
"no-eval": true,
4848
"no-inferrable-types": true,
49-
"no-inferred-empty-object-type": true,
5049
"no-shadowed-variable": true,
5150
"no-string-literal": false,
5251
"no-string-throw": true,

packages/angular-cli/lib/config/schema.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"type": "string"
6060
},
6161
"tsconfig": {
62-
"type": "string"
62+
"type": "string",
63+
"default": "tsconfig.json"
6364
},
6465
"prefix": {
6566
"type": "string"

packages/angular-cli/models/json-schema/schema-tree.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,11 @@ export abstract class NonLeafSchemaTreeNode<T> extends SchemaTreeNode<T> {
134134
if (!schema['oneOf']) {
135135
type = schema['type'];
136136
} else {
137+
let testValue = value || schema['default'];
138+
// Match existing value to one of the schema types
137139
for (let testSchema of schema['oneOf']) {
138-
if ((testSchema['type'] === 'array' && Array.isArray(value))
139-
|| typeof value === testSchema['type']) {
140+
if ((testSchema['type'] === 'array' && Array.isArray(testValue))
141+
|| typeof testValue === testSchema['type']) {
140142
type = testSchema['type'];
141143
schema = testSchema;
142144
break;

packages/angular-cli/models/webpack-build-common.ts

+29-18
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,8 @@ export function getWebpackCommonConfig(
4646
main: [appMain]
4747
};
4848

49-
if (!(environment in appConfig.environments)) {
50-
throw new SilentError(`Environment "${environment}" does not exist.`);
51-
}
52-
5349
// process global scripts
54-
if (appConfig.scripts.length > 0) {
50+
if (appConfig.scripts && appConfig.scripts.length > 0) {
5551
const globalScripts = extraEntryParser(appConfig.scripts, appRoot, 'scripts');
5652

5753
// add entry points and lazy chunks
@@ -67,7 +63,7 @@ export function getWebpackCommonConfig(
6763
}
6864

6965
// process global styles
70-
if (appConfig.styles.length === 0) {
66+
if (!appConfig.styles || appConfig.styles.length === 0) {
7167
// create css loaders for component css
7268
extraRules.push(...makeCssLoaders());
7369
} else {
@@ -104,6 +100,33 @@ export function getWebpackCommonConfig(
104100
}));
105101
}
106102

103+
// process environment file replacement
104+
if (appConfig.environments) {
105+
if (!('source' in appConfig.environments)) {
106+
throw new SilentError(`Environment configuration does not contain "source" entry.`);
107+
}
108+
if (!(environment in appConfig.environments)) {
109+
throw new SilentError(`Environment "${environment}" does not exist.`);
110+
}
111+
112+
extraPlugins.push(new webpack.NormalModuleReplacementPlugin(
113+
// This plugin is responsible for swapping the environment files.
114+
// Since it takes a RegExp as first parameter, we need to escape the path.
115+
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
116+
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
117+
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
118+
path.resolve(appRoot, appConfig.environments[environment])
119+
));
120+
}
121+
122+
// process asset entries
123+
if (appConfig.assets) {
124+
extraPlugins.push(new GlobCopyWebpackPlugin({
125+
patterns: appConfig.assets,
126+
globOptions: { cwd: appRoot, dot: true, ignore: '**/.gitkeep' }
127+
}));
128+
}
129+
107130
if (progress) { extraPlugins.push(new ProgressPlugin({ profile: verbose, colors: true })); }
108131

109132
return {
@@ -145,22 +168,10 @@ export function getWebpackCommonConfig(
145168
new BaseHrefWebpackPlugin({
146169
baseHref: baseHref
147170
}),
148-
new webpack.NormalModuleReplacementPlugin(
149-
// This plugin is responsible for swapping the environment files.
150-
// Since it takes a RegExp as first parameter, we need to escape the path.
151-
// See https://webpack.github.io/docs/list-of-plugins.html#normalmodulereplacementplugin
152-
new RegExp(path.resolve(appRoot, appConfig.environments['source'])
153-
.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')),
154-
path.resolve(appRoot, appConfig.environments[environment])
155-
),
156171
new webpack.optimize.CommonsChunkPlugin({
157172
minChunks: Infinity,
158173
name: 'inline'
159174
}),
160-
new GlobCopyWebpackPlugin({
161-
patterns: appConfig.assets,
162-
globOptions: { cwd: appRoot, dot: true, ignore: '**/.gitkeep' }
163-
}),
164175
new webpack.LoaderOptionsPlugin({
165176
test: /\.(css|scss|sass|less|styl)$/,
166177
options: {

packages/angular-cli/models/webpack-build-typescript.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const webpackLoader: string = g['angularCliIsLocal']
99

1010

1111
export const getWebpackNonAotConfigPartial = function(projectRoot: string, appConfig: any) {
12+
let exclude = [ '**/*.spec.ts' ];
13+
if (appConfig.test) { exclude.push(path.join(projectRoot, appConfig.root, appConfig.test)); };
1214
return {
1315
module: {
1416
rules: [
@@ -23,10 +25,7 @@ export const getWebpackNonAotConfigPartial = function(projectRoot: string, appCo
2325
new AotPlugin({
2426
tsConfigPath: path.resolve(projectRoot, appConfig.root, appConfig.tsconfig),
2527
mainPath: path.join(projectRoot, appConfig.root, appConfig.main),
26-
exclude: [
27-
path.join(projectRoot, appConfig.root, appConfig.test),
28-
'**/*.spec.ts'
29-
],
28+
exclude: exclude,
3029
skipCodeGeneration: true
3130
}),
3231
]
@@ -35,6 +34,8 @@ export const getWebpackNonAotConfigPartial = function(projectRoot: string, appCo
3534

3635
export const getWebpackAotConfigPartial = function(projectRoot: string, appConfig: any,
3736
i18nFile: string, i18nFormat: string, locale: string) {
37+
let exclude = [ '**/*.spec.ts' ];
38+
if (appConfig.test) { exclude.push(path.join(projectRoot, appConfig.root, appConfig.test)); };
3839
return {
3940
module: {
4041
rules: [
@@ -52,10 +53,7 @@ export const getWebpackAotConfigPartial = function(projectRoot: string, appConfi
5253
i18nFile: i18nFile,
5354
i18nFormat: i18nFormat,
5455
locale: locale,
55-
exclude: [
56-
path.join(projectRoot, appConfig.root, appConfig.test),
57-
'**/*.spec.ts'
58-
]
56+
exclude: exclude
5957
})
6058
]
6159
};

packages/angular-cli/tasks/serve-webpack.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ export default Task.extend({
9898
proxy: proxyConfig,
9999
compress: serveTaskOptions.target === 'production',
100100
watchOptions: {
101-
poll: CliConfig.fromProject().config.defaults.poll
101+
poll: CliConfig.fromProject().config.defaults &&
102+
CliConfig.fromProject().config.defaults.poll
102103
},
103104
https: serveTaskOptions.ssl
104105
};
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { writeFile } from '../../utils/fs';
2+
import { ng } from '../../utils/process';
3+
4+
5+
export default function () {
6+
return Promise.resolve()
7+
.then(() => writeFile('angular-cli.json', JSON.stringify({
8+
apps: [{
9+
root: 'src',
10+
main: 'main.ts'
11+
}]
12+
})))
13+
.then(() => ng('build'));
14+
}
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {normalize} from 'path';
22
import {createProjectFromAsset} from '../../../utils/assets';
33
import {exec} from '../../../utils/process';
4-
import {expectFileSizeToBeUnder} from '../../../utils/fs';
4+
import {expectFileSizeToBeUnder, replaceInFile} from '../../../utils/fs';
55

66

77
export default function(skipCleaning: () => void) {
@@ -10,5 +10,11 @@ export default function(skipCleaning: () => void) {
1010
.then(() => exec(normalize('node_modules/.bin/webpack'), '-p'))
1111
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 420000))
1212
.then(() => expectFileSizeToBeUnder('dist/0.app.main.js', 40000))
13+
// test resource urls without ./
14+
.then(() => replaceInFile('app/app.component.ts',
15+
'./app.component.html', 'app.component.html'))
16+
.then(() => replaceInFile('app/app.component.ts',
17+
'./app.component.scss', 'app.component.scss'))
18+
.then(() => exec(normalize('node_modules/.bin/webpack'), '-p'))
1319
.then(() => skipCleaning());
1420
}

0 commit comments

Comments
 (0)