Skip to content

Commit ea2c866

Browse files
authored
Merge branch 'master' into docs-bootstrap
2 parents 9619878 + 0a68cc5 commit ea2c866

File tree

10 files changed

+79
-47
lines changed

10 files changed

+79
-47
lines changed

README.md

+16-7
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,23 @@ npm install @types/d3 --save-dev
358358

359359
If the library doesn't have typings available at `@types/`, you can still use it by
360360
manually adding typings for it:
361-
```
362-
// in src/typings.d.ts
363-
declare module 'typeless-package';
364361

365-
// in src/app/app.component.ts
366-
import * as typelessPackage from 'typeless-package';
367-
typelessPackage.method();
368-
```
362+
1. First, create a `typings.d.ts` file in your `src/` folder. This file will be automatically included as global type definition.
363+
364+
2. Then, in `src/typings.d.ts`, add the following code:
365+
366+
```typescript
367+
declare module 'typeless-package';
368+
```
369+
370+
3. Finally, in the component or file that uses the library, add the following code:
371+
372+
```typescript
373+
import * as typelessPackage from 'typeless-package';
374+
typelessPackage.method();
375+
```
376+
377+
Done. Note: you might need or find useful to define more typings for the library that you're trying to use.
369378

370379
### Global Library Installation
371380

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

+26-25
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ export class AotPlugin implements Tapable {
196196
});
197197

198198
// Virtual file system.
199-
compiler.resolvers.normal.plugin('resolve', (request: any, cb?: () => void) => {
199+
compiler.resolvers.normal.plugin('resolve', (request: any, cb?: (err?: any) => void) => {
200200
if (request.request.match(/\.ts$/)) {
201-
this.done.then(() => cb());
201+
this.done
202+
.then(() => cb())
203+
.catch((err) => cb(err));
202204
} else {
203205
cb();
204206
}
@@ -212,9 +214,8 @@ export class AotPlugin implements Tapable {
212214

213215
private _make(compilation: any, cb: (err?: any, request?: any) => void) {
214216
this._compilation = compilation;
215-
216217
if (this._compilation._ngToolsWebpackPluginInstance) {
217-
cb(new Error('An @ngtools/webpack plugin already exist for this compilation.'));
218+
return cb(new Error('An @ngtools/webpack plugin already exist for this compilation.'));
218219
}
219220
this._compilation._ngToolsWebpackPluginInstance = this;
220221

@@ -227,28 +228,28 @@ export class AotPlugin implements Tapable {
227228
basePath: this.basePath
228229
};
229230

230-
let promise = Promise.resolve();
231-
if (!this._skipCodeGeneration) {
232-
// Create the Code Generator.
233-
const codeGenerator = ngCompiler.CodeGenerator.create(
234-
this._angularCompilerOptions,
235-
i18nOptions,
236-
this._program,
237-
this._compilerHost,
238-
new ngCompiler.NodeReflectorHostContext(this._compilerHost),
239-
this._resourceLoader
240-
);
241-
242-
// We need to temporarily patch the CodeGenerator until either it's patched or allows us
243-
// to pass in our own ReflectorHost.
244-
// TODO: remove this.
245-
patchReflectorHost(codeGenerator);
246-
promise = promise.then(() => codeGenerator.codegen({
247-
transitiveModules: true
248-
}));
249-
}
231+
this._donePromise = Promise.resolve()
232+
.then(() => {
233+
if (this._skipCodeGeneration) {
234+
return;
235+
}
250236

251-
this._donePromise = promise
237+
// Create the Code Generator.
238+
const codeGenerator = ngCompiler.CodeGenerator.create(
239+
this._angularCompilerOptions,
240+
i18nOptions,
241+
this._program,
242+
this._compilerHost,
243+
new ngCompiler.NodeReflectorHostContext(this._compilerHost),
244+
this._resourceLoader
245+
);
246+
247+
// We need to temporarily patch the CodeGenerator until either it's patched or allows us
248+
// to pass in our own ReflectorHost.
249+
// TODO: remove this.
250+
patchReflectorHost(codeGenerator);
251+
return codeGenerator.codegen({ transitiveModules: true });
252+
})
252253
.then(() => {
253254
// Create a new Program, based on the old one. This will trigger a resolution of all
254255
// transitive modules, which include files that might just have been generated.

packages/angular-cli/blueprints/ng2/files/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app w
77

88
## Code scaffolding
99

10-
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class`.
10+
Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class/module`.
1111

1212
## Build
1313

packages/angular-cli/blueprints/ng2/files/__path__/typings.d.ts

-2
This file was deleted.

packages/angular-cli/commands/github-pages-deploy.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ const githubPagesDeployCommand = Command.extend({
217217
files = files.concat(`"${f}" `);
218218
}
219219
});
220-
return execPromise(`git rm -r ${files}`);
220+
return execPromise(`git rm -r ${files}`)
221+
.catch(() => {
222+
// Ignoring errors when trying to erase files.
223+
});
221224
});
222225
}
223226

packages/angular-cli/commands/help.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const HelpCommand = Command.extend({
1818

1919
availableOptions: [],
2020

21+
anonymousOptions: ['command-name (Default: all)'],
22+
2123
run: function (commandOptions: any, rawArgs: any) {
2224
let commandFiles = fs.readdirSync(__dirname)
2325
// Remove files that are not JavaScript or Typescript
@@ -38,6 +40,10 @@ const HelpCommand = Command.extend({
3840
return acc;
3941
}, {});
4042

43+
if (rawArgs.indexOf('all') !== -1) {
44+
rawArgs = []; // just act as if command not specified
45+
}
46+
4147
commandFiles.forEach(cmd => {
4248
let Command = lookupCommand(commandMap, cmd);
4349

@@ -50,7 +56,7 @@ const HelpCommand = Command.extend({
5056

5157
if (rawArgs.length > 0) {
5258
if (cmd === rawArgs[0]) {
53-
this.ui.writeLine(command.printDetailedHelp(commandOptions));
59+
this.ui.writeLine(command.printBasicHelp(commandOptions));
5460
}
5561
} else {
5662
this.ui.writeLine(command.printBasicHelp(commandOptions));

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,12 @@ export function getWebpackCommonConfig(
5858
devtool: sourcemap ? 'source-map' : false,
5959
resolve: {
6060
extensions: ['.ts', '.js'],
61-
modules: [nodeModules]
61+
modules: [nodeModules],
6262
},
63-
context: path.resolve(__dirname, './'),
63+
resolveLoader: {
64+
modules: [path.resolve(projectRoot, 'node_modules')]
65+
},
66+
context: projectRoot,
6467
entry: entry,
6568
output: {
6669
path: path.resolve(projectRoot, appConfig.outDir),

packages/angular-cli/models/webpack-build-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig, test
5656

5757
return {
5858
devtool: testConfig.sourcemap ? 'inline-source-map' : 'eval',
59-
context: path.resolve(__dirname, './'),
59+
context: projectRoot,
6060
resolve: {
6161
extensions: ['.ts', '.js'],
6262
plugins: [

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

+15-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { NgCliWebpackConfig } from '../models/webpack-config';
77
import { getWebpackStatsConfig } from '../models/';
88
import { CliConfig } from '../models/config';
99

10+
1011
// Configure build and output;
1112
let lastHash: any = null;
1213

@@ -36,7 +37,9 @@ export default <any>Task.extend({
3637

3738
return new Promise((resolve, reject) => {
3839
webpackCompiler.run((err: any, stats: any) => {
39-
if (err) { return reject(err); }
40+
if (err) {
41+
return reject(err);
42+
}
4043

4144
// Don't keep cache
4245
// TODO: Make conditional if using --watch
@@ -47,8 +50,18 @@ export default <any>Task.extend({
4750
process.stdout.write(stats.toString(statsConfig) + '\n');
4851
}
4952

50-
return stats.hasErrors() ? reject() : resolve();
53+
if (stats.hasErrors()) {
54+
reject();
55+
} else {
56+
resolve();
57+
}
5158
});
59+
})
60+
.catch((err: Error) => {
61+
if (err) {
62+
this.ui.writeError('\nAn error occured during the build:\n' + ((err && err.stack) || err));
63+
}
64+
throw err;
5265
});
5366
}
5467
});

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,16 @@ export default Task.extend({
115115

116116
const server = new WebpackDevServer(webpackCompiler, webpackDevServerConfiguration);
117117
return new Promise((resolve, reject) => {
118-
server.listen(serveTaskOptions.port,
119-
`${serveTaskOptions.host}`,
120-
function(err: any, stats: any) {
118+
server.listen(serveTaskOptions.port, `${serveTaskOptions.host}`, (err: any, stats: any) => {
121119
if (err) {
122120
console.error(err.stack || err);
123121
if (err.details) { console.error(err.details); }
124122
reject(err.details);
125123
} else {
126-
const { open, host, port } = serveTaskOptions;
124+
const { open, ssl, host, port } = serveTaskOptions;
127125
if (open) {
128-
opn(url.format({ protocol: 'http', hostname: host, port: port.toString() }));
126+
let protocol = ssl ? 'https' : 'http';
127+
opn(url.format({ protocol: protocol, hostname: host, port: port.toString() }));
129128
}
130129
}
131130
});

0 commit comments

Comments
 (0)