Skip to content

Commit 76bd7ef

Browse files
Merge pull request #23 from angular/master
Update upstream
2 parents 912f03c + 9760ef9 commit 76bd7ef

File tree

13 files changed

+136
-36
lines changed

13 files changed

+136
-36
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
<a name="1.0.4"></a>
2+
## [1.0.4](https://github.com/angular/angular-cli/compare/v1.0.3...v1.0.4) (2017-05-18)
3+
4+
5+
### Bug Fixes
6+
7+
* **@angular/cli:** adds language to index.html for accessibility ([1d99472](https://github.com/angular/angular-cli/commit/1d99472))
8+
* **@angular/cli:** allow e2e multi capabilities ([8a7f6dd](https://github.com/angular/angular-cli/commit/8a7f6dd)), closes [#975](https://github.com/angular/angular-cli/issues/975)
9+
* **@angular/cli:** enable full node module resolution for project deps ([#6276](https://github.com/angular/angular-cli/issues/6276)) ([1659b74](https://github.com/angular/angular-cli/commit/1659b74))
10+
* **@angular/cli:** if user pass a full path, use the path ([#6341](https://github.com/angular/angular-cli/issues/6341)) ([013a3ea](https://github.com/angular/angular-cli/commit/013a3ea))
11+
* **@angular/cli:** prefix `historyApiFallback.index` with `deployUrl` ([#6279](https://github.com/angular/angular-cli/issues/6279)) ([26ecebf](https://github.com/angular/angular-cli/commit/26ecebf))
12+
* **@angular/cli:** proper generation when the target dir exists ([#5929](https://github.com/angular/angular-cli/issues/5929)) ([895b759](https://github.com/angular/angular-cli/commit/895b759))
13+
* **@angular/cli:** put vendor ngfactory in vendor chunk ([afa3ac5](https://github.com/angular/angular-cli/commit/afa3ac5))
14+
* **@angular/cli:** supress module file modification when generating guard with dry-run flag ([114ee50](https://github.com/angular/angular-cli/commit/114ee50))
15+
16+
117
<a name="1.1.0-rc.0"></a>
218
# [1.1.0-rc.0](https://github.com/angular/angular-cli/compare/v1.1.0-beta.1...v1.1.0-rc.0) (2017-05-15)
319

docs/documentation/stories.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
- [Application Environments](stories/application-environments)
2727
- [Autoprefixer Configuration](stories/autoprefixer)
2828
- [Deploy to GitHub Pages](stories/githug-pages)
29+
- [Linked Library](stories/linked-library)

docs/documentation/stories/global-scripts.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,25 @@ global library, and one imported as a module.
3232
This is especially bad for libraries with plugins, like JQuery, because each copy will have
3333
different plugins.
3434

35-
Instead, download typings for your library (`npm install @types/jquery`) which will give you
36-
access to the global variables exposed by that library.
35+
Instead, download typings for your library (`npm install @types/jquery`) and follow
36+
the [3rd Party Library Installation](https://github.com/angular/angular-cli/wiki/stories-third-party-lib) steps,
37+
this will give you access to the global variables exposed by that library.
3738

3839
If the global library you need to use does not have global typings, you can also declare them
3940
manually in `src/typings.d.ts` as `any`:
4041

4142
```
4243
declare var libraryName: any;
43-
```
44+
```
45+
46+
When working with scripts that extend other libraries, for instance with JQuery plugins
47+
(e.g, `$('.test').myPlugin();`), since the installed `@types/jquery` may not include `myPlugin`,
48+
you would need to add an interface like the one below in `src/typings.d.ts`.
49+
50+
```
51+
interface JQuery {
52+
myPlugin(options?: any): any;
53+
}
54+
```
55+
56+
Otherwise you may see `[TS][Error] Property 'myPlugin' does not exist on type 'JQuery'.` in your IDE.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Linked libraries
2+
3+
While working on a library, it is common to use [npm link](https://docs.npmjs.com/cli/link) to
4+
avoid reinstalling the library on every build.
5+
6+
While this is very useful there are a few caveats to keep in mind.
7+
8+
## The library needs to be AOT compatible
9+
10+
Angular CLI does static analysis even without the `--aot` flag in order to detect lazy-loade routes.
11+
If your library is not AOT compatible, you will likely get a static analysis error.
12+
13+
## The library still needs to be rebuilt on every change
14+
15+
Angular libraries are usually built using TypeScript and thus require to be built before they
16+
are published.
17+
For simple cases, a linked library might work even without a build step, but this is the exception
18+
rather than the norm.
19+
20+
If a library is not being built using its own build step, then it is being compiled by the
21+
Angular CLI build system and there is no guarantee that it will be correctly built.
22+
Even if it works on development it might not work when deployed.
23+
24+
When linking a library remember to have your build step running in watch mode and the library's
25+
`package.json` pointing at the correct entry points (e.g. 'main' should point at a `.js` file, not
26+
a `.ts` file).
27+
28+
## Use TypesScript path mapping for Peer Dependencies
29+
30+
Angular libraries should list all `@angular/*` dependencies as
31+
[Peer Dependencies](https://nodejs.org/en/blog/npm/peer-dependencies/).
32+
This insures that, when modules ask for Angular, they all get the exact same module.
33+
If a library lists `@angular/core` in `dependencies` instead of `peerDependencies` then it might
34+
get a *different* Angular module instead, which will cause your application to break.
35+
36+
While developing a library, you'll need to have all of your peer dependencies also installed
37+
via `devDependencies` - otherwise you could not compile.
38+
A linked library will then have it's own set of Angular libraries that it is using for building,
39+
located in it's `node_modules` folder.
40+
This can cause problems while building or running your application.
41+
42+
To get around this problem you can use the TypeScript
43+
[path mapping](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping).
44+
With it, you can tell TypeScript that it should load some modules from a specific location.
45+
46+
You should list all the peer dependencies that your library uses in `./tsconfig.json`, pointing
47+
them at the local copy in the apps `node_modules` folder.
48+
This ensures that you all will always load the local copies of the modules your library asks for.
49+
50+
```
51+
{
52+
"compilerOptions": {
53+
// ...
54+
// Note: these paths are relative to `baseUrl` path.
55+
"paths": {
56+
"@angular/*": [
57+
"../node_modules/@angular/*"
58+
]
59+
}
60+
}
61+
}
62+
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"loader-utils": "^1.0.2",
6969
"lodash": "^4.11.1",
7070
"magic-string": "^0.19.0",
71+
"memory-fs": "^0.4.1",
7172
"minimatch": "^3.0.3",
7273
"node-modules-path": "^1.0.0",
7374
"nopt": "^4.0.1",

packages/@angular/cli/blueprints/guard/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ export default Blueprint.extend({
9999
`;
100100
this._writeStatusToUI(chalk.yellow, 'WARNING', warningMessage);
101101
} else {
102+
if (options.dryRun) {
103+
this._writeStatusToUI(chalk.yellow,
104+
'update',
105+
path.relative(this.project.root, this.pathToModule));
106+
return;
107+
}
108+
102109
const className = stringUtils.classify(`${options.entity.name}Guard`);
103110
const fileName = stringUtils.dasherize(`${options.entity.name}.guard`);
104111
const fullGeneratePath = path.join(this.project.root, this.generatePath);

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
1212
const { projectRoot, buildOptions, appConfig } = wco;
1313

1414
const appRoot = path.resolve(projectRoot, appConfig.root);
15-
const nodeModules = path.resolve(projectRoot, 'node_modules');
1615

1716
let extraPlugins: any[] = [];
1817

@@ -23,10 +22,16 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
2322
]);
2423

2524
if (buildOptions.vendorChunk) {
25+
// Separate modules from node_modules into a vendor chunk.
26+
const nodeModules = path.resolve(projectRoot, 'node_modules');
27+
// --aot puts the generated *.ngfactory.ts in src/$$_gendir/node_modules.
28+
const genDirNodeModules = path.resolve(appRoot, '$$_gendir', 'node_modules');
29+
2630
extraPlugins.push(new webpack.optimize.CommonsChunkPlugin({
2731
name: 'vendor',
2832
chunks: ['main'],
29-
minChunks: (module: any) => module.resource && module.resource.startsWith(nodeModules)
33+
minChunks: (module: any) => module.resource &&
34+
(module.resource.startsWith(nodeModules) || module.resource.startsWith(genDirNodeModules))
3035
}));
3136
}
3237

packages/@angular/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"less": "^2.7.2",
5454
"less-loader": "^4.0.2",
5555
"lodash": "^4.11.1",
56+
"memory-fs": "^0.4.1",
5657
"minimatch": "^3.0.3",
5758
"node-modules-path": "^1.0.0",
5859
"nopt": "^4.0.1",

packages/@angular/cli/tasks/eject.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ class JsonWebpackSerializer {
3939
};
4040
public variables: {[name: string]: string} = {
4141
'nodeModules': `path.join(process.cwd(), 'node_modules')`,
42+
'genDirNodeModules':
43+
`path.join(process.cwd(), '${this._appRoot}', '$$_gendir', 'node_modules')`,
4244
};
4345
private _postcssProcessed = false;
4446

4547

46-
constructor(private _root: string, private _dist: string) {}
48+
constructor(private _root: string, private _dist: string, private _appRoot: string) {}
4749

4850
private _escape(str: string) {
4951
return '\uFF01' + str + '\uFF01';
@@ -398,7 +400,7 @@ export default Task.extend({
398400
}
399401

400402
const webpackConfig = new NgCliWebpackConfig(runTaskOptions, appConfig).buildConfig();
401-
const serializer = new JsonWebpackSerializer(process.cwd(), outputPath);
403+
const serializer = new JsonWebpackSerializer(process.cwd(), outputPath, appConfig.root);
402404
const output = serializer.serialize(webpackConfig);
403405
const webpackConfigStr = `${serializer.generateVariables()}\n\nmodule.exports = ${output};\n`;
404406

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
import * as webpack from 'webpack';
2-
import * as path from 'path';
3-
import * as rimraf from 'rimraf';
2+
import { XI18nWebpackConfig } from '../models/webpack-xi18n-config';
3+
import { getAppFromConfig } from '../utilities/app-utils';
44

55
const Task = require('../ember-cli/lib/models/task');
6+
const MemoryFS = require('memory-fs');
67

7-
import {XI18nWebpackConfig} from '../models/webpack-xi18n-config';
8-
import {getAppFromConfig} from '../utilities/app-utils';
98

109
export const Extracti18nTask = Task.extend({
1110
run: function (runTaskOptions: any) {
12-
13-
const project = this.project;
14-
1511
const appConfig = getAppFromConfig(runTaskOptions.app);
1612

17-
const buildDir = '.tmp';
18-
const genDir = runTaskOptions.outputPath || appConfig.root;
19-
2013
const config = new XI18nWebpackConfig({
21-
genDir,
22-
buildDir,
14+
genDir: runTaskOptions.outputPath || appConfig.root,
15+
buildDir: '.tmp',
2316
i18nFormat: runTaskOptions.i18nFormat,
2417
locale: runTaskOptions.locale,
2518
outFile: runTaskOptions.outFile,
@@ -29,6 +22,7 @@ export const Extracti18nTask = Task.extend({
2922
}, appConfig).buildConfig();
3023

3124
const webpackCompiler = webpack(config);
25+
webpackCompiler.outputFileSystem = new MemoryFS();
3226

3327
return new Promise((resolve, reject) => {
3428
const callback: webpack.compiler.CompilerCallback = (err, stats) => {
@@ -45,15 +39,11 @@ export const Extracti18nTask = Task.extend({
4539

4640
webpackCompiler.run(callback);
4741
})
48-
.then(() => {
49-
// Deletes temporary build folder
50-
rimraf.sync(path.resolve(project.root, buildDir));
51-
})
52-
.catch((err: Error) => {
53-
if (err) {
54-
this.ui.writeError('\nAn error occured during the i18n extraction:\n'
55-
+ ((err && err.stack) || err));
56-
}
57-
});
42+
.catch((err: Error) => {
43+
if (err) {
44+
this.ui.writeError('\nAn error occured during the i18n extraction:\n'
45+
+ ((err && err.stack) || err));
46+
}
47+
});
5848
}
5949
});

packages/@angular/cli/utilities/dynamic-path-parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path';
22
import * as process from 'process';
3-
import * as fs from 'fs';
3+
import * as fs from 'fs-extra';
44
const stringUtils = require('ember-cli-string-utils');
55

66
export function dynamicPathParser(project: any, entityName: string, appConfig: any) {
@@ -38,7 +38,7 @@ export function dynamicPathParser(project: any, entityName: string, appConfig: a
3838
// Folder not found, create it, and return it
3939
const dasherizedPart = stringUtils.dasherize(part);
4040
const dasherizedDirName = path.join(tempPath, dasherizedPart);
41-
fs.mkdirSync(dasherizedDirName);
41+
fs.mkdirpSync(dasherizedDirName);
4242
return dasherizedDirName;
4343

4444
}, parsedOutputPath.root);

packages/@angular/cli/utilities/find-parent-module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default function findParentModule(
2626
if (files.length === 1) {
2727
return path.join(pathToCheck, files[0]);
2828
} else if (files.length > 1) {
29-
throw new SilentError(`Multiple module files found: ${pathToCheck.replace(sourceRoot, '')}`);
29+
throw new SilentError(`Multiple module files found: ${JSON.stringify(files)}`);
3030
}
3131

3232
// move to parent directory

packages/@angular/cli/utilities/resolve-module-file.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@ export function resolveModulePath(
77
let baseModuleName = moduleNameFromFlag;
88
let parentFolders = '';
99

10+
// If it's a full path from the cwd, we use it as is.
11+
if (fs.existsSync(moduleNameFromFlag) && fs.statSync(moduleNameFromFlag).isFile()) {
12+
return path.resolve(moduleNameFromFlag);
13+
}
14+
1015
if (baseModuleName.includes(path.sep)) {
1116
const splitPath = baseModuleName.split(path.sep);
1217
baseModuleName = splitPath.pop();
1318
parentFolders = splitPath.join(path.sep);
1419
}
1520

1621
if (baseModuleName.includes('.')) {
17-
baseModuleName = baseModuleName
18-
.split('.')
19-
.filter(part => part !== 'module' && part !== 'ts')
20-
.join('.');
22+
baseModuleName = baseModuleName.replace(/(\.module)?(\.ts)?$/, '');
2123
}
2224

2325
const baseModuleWithFileSuffix = `${baseModuleName}.module.ts`;

0 commit comments

Comments
 (0)