Skip to content

Commit 1572270

Browse files
authored
refactor(all): Repackaging (#2056)
Moving Angular-CLI into `packages/` and building the angular-cli. The published packages will now have JavaScript only (with their d.ts), instead of being a mix of TypeScript and JavaScript, and it won't have the hacks of having a custom require extension to load the TypeScript. Our development flow will be more streamlined, tools are going to be better (no more undefined symbols that are actually defined), and the npm packages will boot up way faster (since there's no more compilation during runtime). Locally nothing changes, use `npm link` and run your local `ng`. Using the `npm` releases though it should be all javascript from the release. The E2E tests also now uses the `dist` folder output to install in the new E2E app, making sure the process works for an app published to npm. Note: Even though we're following the lerna structure, we won't be using their tool anytime soon.
1 parent 126c82b commit 1572270

File tree

187 files changed

+503
-242
lines changed

Some content is hidden

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

187 files changed

+503
-242
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ tmp/
55
typings/
66

77
# Ignore all blueprint files. We e2e tests those later on.
8-
addon/ng2/blueprints/*/files/
8+
packages/angular-cli/blueprints/*/files/

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
- DBUS_SESSION_BUS_ADDRESS=/dev/null
1313
matrix:
1414
- SCRIPT=lint
15-
# - SCRIPT=build
15+
- SCRIPT=build
1616
- SCRIPT=e2e
1717
- SCRIPT=e2e:nightly
1818
- SCRIPT=test

addon/ng2/index.js

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

addon/ng2/package.json

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

bin/ng

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,5 @@
44
// Provide a title to the process in `ps`
55
process.title = 'angular-cli';
66

7-
const resolve = require('resolve');
8-
const exit = require('exit');
9-
const packageJson = require('../package.json');
10-
const Leek = require('leek');
11-
127
require('../lib/bootstrap-local');
13-
14-
15-
resolve('angular-cli', { basedir: process.cwd() },
16-
function (error, projectLocalCli) {
17-
var cli;
18-
if (error) {
19-
// If there is an error, resolve could not find the ng-cli
20-
// library from a package.json. Instead, include it from a relative
21-
// path to this script file (which is likely a globally installed
22-
// npm package). Most common cause for hitting this is `ng new`
23-
cli = require('../lib/cli');
24-
} else {
25-
// No error implies a projectLocalCli, which will load whatever
26-
// version of ng-cli you have installed in a local package.json
27-
cli = require(projectLocalCli);
28-
}
29-
30-
if ('default' in cli) {
31-
cli = cli['default'];
32-
}
33-
34-
cli({
35-
cliArgs: process.argv.slice(2),
36-
inputStream: process.stdin,
37-
outputStream: process.stdout,
38-
Leek: CustomLeek
39-
}).then(function (result) {
40-
var exitCode = typeof result === 'object' ? result.exitCode : result;
41-
exit(exitCode);
42-
});
43-
44-
function CustomLeek(options) {
45-
options.trackingCode = packageJson.trackingCode;
46-
options.globalName = packageJson.name;
47-
options.name = packageJson.name;
48-
options.version = packageJson.version;
49-
return new Leek(options);
50-
}
51-
});
8+
require('../packages/angular-cli/bin/ng');

index.js

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

lib/bootstrap-local.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const path = require('path');
66
const ts = require('typescript');
77

88

9+
global.angularCliIsLocal = true;
10+
911
const compilerOptions = JSON.parse(fs.readFileSync(path.join(__dirname, '../tsconfig.json')));
1012

1113
const oldRequireTs = require.extensions['.ts'];
@@ -51,6 +53,12 @@ if (!__dirname.match(new RegExp(`\\${path.sep}node_modules\\${path.sep}`))) {
5153
Module._load = function (request, parent) {
5254
if (request in packages) {
5355
return oldLoad.call(this, packages[request].main, parent);
56+
} else if (request.startsWith('angular-cli/')) {
57+
// We allow deep imports (for now).
58+
// TODO: move tests to inside angular-cli package so they don't have to deep import.
59+
const dir = path.dirname(parent.filename);
60+
const newRequest = path.relative(dir, path.join(__dirname, '../packages', request));
61+
return oldLoad.call(this, newRequest, parent);
5462
} else {
5563
return oldLoad.apply(this, arguments);
5664
}

lib/packages.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict';
2+
13
const fs = require('fs');
24
const path = require('path');
35

@@ -9,7 +11,8 @@ const packages = fs.readdirSync(packageRoot)
911
.map(pkgName => ({ name: pkgName, root: path.join(packageRoot, pkgName) }))
1012
.filter(pkg => fs.statSync(pkg.root).isDirectory())
1113
.reduce((packages, pkg) => {
12-
packages[`@angular-cli/${pkg.name}`] = {
14+
let name = pkg == 'angular-cli' ? 'angular-cli' : `@angular-cli/${pkg.name}`;
15+
packages[name] = {
1316
root: pkg.root,
1417
main: path.resolve(pkg.root, 'src/index.ts')
1518
};

package.json

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "angular-cli",
3-
"version": "1.0.0-beta.11-webpack.8",
3+
"version": "0.0.0",
44
"description": "CLI tool for Angular",
5-
"main": "lib/cli/index.js",
5+
"main": "packages/angular-cli/lib/cli/index.js",
66
"trackingCode": "UA-8594346-19",
77
"bin": {
88
"ng": "./bin/ng"
99
},
1010
"keywords": [],
1111
"scripts": {
12-
"build": "npm-run-all -c build:main build:packages",
13-
"build:main": "tsc -p addon/ng2",
14-
"build:packages": "for PKG in packages/*; do echo Building $PKG...; tsc -P $PKG; done",
12+
"build": "node ./scripts/publish/build.js",
13+
"build:patch": "node ./scripts/patch.js",
14+
"build:packages": "for PKG in packages/*; do echo Building $PKG...; tsc -p $PKG; done",
1515
"test": "npm run test:packages && npm run test:cli",
1616
"e2e": "npm run test:e2e",
1717
"e2e:nightly": "node tests/e2e_runner.js --nightly",
@@ -47,7 +47,7 @@
4747
"@angular/compiler": "^2.0.0-rc.6",
4848
"@angular/compiler-cli": "^0.6.0",
4949
"@angular/core": "^2.0.0-rc.6",
50-
"@angular/tsc-wrapped": "^0.2.2",
50+
"@angular/tsc-wrapped": "^0.3.0",
5151
"angular2-template-loader": "^0.5.0",
5252
"awesome-typescript-loader": "^2.2.3",
5353
"chalk": "^1.1.3",
@@ -113,13 +113,13 @@
113113
},
114114
"ember-addon": {
115115
"paths": [
116-
"./addon/ng2/"
116+
"./packages/angular-cli/lib/addon"
117117
]
118118
},
119119
"devDependencies": {
120120
"@types/chai": "^3.4.32",
121121
"@types/chalk": "^0.4.28",
122-
"@types/common-tags": "^1.2.3",
122+
"@types/common-tags": "^1.2.4",
123123
"@types/denodeify": "^1.2.29",
124124
"@types/express": "^4.0.32",
125125
"@types/fs-extra": "^0.0.31",
@@ -143,8 +143,10 @@
143143
"minimist": "^1.2.0",
144144
"mocha": "^2.4.5",
145145
"mock-fs": "3.10.0",
146+
"npm-run": "^4.1.0",
146147
"object-assign": "^4.0.1",
147148
"request": "^2.74.0",
149+
"resolve-bin": "^0.4.0",
148150
"rewire": "^2.5.1",
149151
"sinon": "^1.17.3",
150152
"through": "^2.3.8",

packages/angular-cli/addon/index.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* jshint node: true */
2+
'use strict';
3+
4+
const config = require('../models/config');
5+
const path = require('path');
6+
7+
module.exports = {
8+
name: 'ng2',
9+
10+
config: function () {
11+
this.project.ngConfig = this.project.ngConfig || config.CliConfig.fromProject().config;
12+
},
13+
14+
blueprintsPath: function () {
15+
return path.join(__dirname, '../blueprints');
16+
},
17+
18+
includedCommands: function () {
19+
return {
20+
'build': require('../commands/build').default,
21+
'serve': require('../commands/serve').default,
22+
'new': require('../commands/new').default,
23+
'generate': require('../commands/generate').default,
24+
'init': require('../commands/init').default,
25+
'test': require('../commands/test').default,
26+
'e2e': require('../commands/e2e').default,
27+
'help': require('../commands/help').default,
28+
'lint': require('../commands/lint').default,
29+
'version': require('../commands/version').default,
30+
'completion': require('../commands/completion').default,
31+
'doc': require('../commands/doc').default,
32+
'github-pages-deploy': require('../commands/github-pages-deploy').default,
33+
34+
// Easter eggs.
35+
'make-this-awesome': require('../commands/easter-egg').default,
36+
37+
// Configuration.
38+
'set': require('../commands/set').default,
39+
'get': require('../commands/get').default
40+
};
41+
}
42+
};

packages/angular-cli/bin/ng

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
// Provide a title to the process in `ps`
5+
process.title = 'angular-cli';
6+
7+
const resolve = require('resolve');
8+
const exit = require('exit');
9+
const packageJson = require('../package.json');
10+
const Leek = require('leek');
11+
12+
13+
resolve('angular-cli', { basedir: process.cwd() },
14+
function (error, projectLocalCli) {
15+
var cli;
16+
if (error) {
17+
// If there is an error, resolve could not find the ng-cli
18+
// library from a package.json. Instead, include it from a relative
19+
// path to this script file (which is likely a globally installed
20+
// npm package). Most common cause for hitting this is `ng new`
21+
cli = require('../lib/cli');
22+
} else {
23+
// No error implies a projectLocalCli, which will load whatever
24+
// version of ng-cli you have installed in a local package.json
25+
cli = require(projectLocalCli);
26+
}
27+
28+
if ('default' in cli) {
29+
cli = cli['default'];
30+
}
31+
32+
cli({
33+
cliArgs: process.argv.slice(2),
34+
inputStream: process.stdin,
35+
outputStream: process.stdout,
36+
Leek: CustomLeek
37+
}).then(function (result) {
38+
var exitCode = typeof result === 'object' ? result.exitCode : result;
39+
exit(exitCode);
40+
});
41+
42+
function CustomLeek(options) {
43+
options.trackingCode = packageJson.trackingCode;
44+
options.globalName = packageJson.name;
45+
options.name = packageJson.name;
46+
options.version = packageJson.version;
47+
return new Leek(options);
48+
}
49+
});

addon/ng2/blueprints/ng2/files/karma.conf.js renamed to packages/angular-cli/blueprints/ng2/files/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
module.exports = function (config) {
55
config.set({
6-
basePath: './',
6+
basePath: '',
77
frameworks: ['jasmine', 'angular-cli'],
88
plugins: [
99
require('karma-jasmine'),

addon/ng2/blueprints/ng2/index.js renamed to packages/angular-cli/blueprints/ng2/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121

2222
locals: function(options) {
2323
this.styleExt = options.style;
24-
this.version = require(path.resolve(__dirname, '../../../../package.json')).version;
24+
this.version = require(path.resolve(__dirname, '../../package.json')).version;
2525

2626
// Join with / not path.sep as reference to typings require forward slashes.
2727
const relativeRootPath = options.sourceDir.split(path.sep).map(() => '..').join('/');
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

addon/ng2/commands/init.ts renamed to packages/angular-cli/commands/init.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@ const InitCommand: any = Command.extend({
3232
anonymousOptions: ['<glob-pattern>'],
3333

3434
_defaultBlueprint: function () {
35-
if (this.project.isEmberCLIAddon()) {
36-
return 'addon';
37-
} else {
38-
return 'ng2';
39-
}
35+
return 'ng2';
4036
},
4137

4238
run: function (commandOptions: any, rawArgs: string[]) {
File renamed without changes.
File renamed without changes.

addon/ng2/commands/serve.ts renamed to packages/angular-cli/commands/serve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as denodeify from 'denodeify';
33
const Command = require('ember-cli/lib/models/command');
44
const SilentError = require('silent-error');
55
const PortFinder = require('portfinder');
6-
import ServeWebpackTask from '../tasks/serve-webpack.ts';
6+
import ServeWebpackTask from '../tasks/serve-webpack';
77

88
PortFinder.basePort = 49152;
99

File renamed without changes.
File renamed without changes.

addon/ng2/commands/version.ts renamed to packages/angular-cli/commands/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const VersionCommand = Command.extend({
1515

1616
run: function (options: any) {
1717
const versions: any = process.versions;
18-
const pkg = require(path.resolve(__dirname, '..', '..', '..', 'package.json'));
18+
const pkg = require(path.resolve(__dirname, '..', 'package.json'));
1919

2020
versions['os'] = process.platform + ' ' + process.arch;
2121

lib/cli/index.js renamed to packages/angular-cli/lib/cli/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
const cli = require('ember-cli/lib/cli');
55
const path = require('path');
66

7+
Error.stackTraceLimit = Infinity;
78

89
module.exports = function(options) {
910
const oldStdoutWrite = process.stdout.write;
File renamed without changes.
File renamed without changes.

addon/ng2/models/config.ts renamed to packages/angular-cli/models/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {CliConfig as CliConfigBase} from './config/config';
2-
import {CliConfig as ConfigInterface} from '../../../lib/config/schema';
2+
import {CliConfig as ConfigInterface} from '../lib/config/schema';
33
import { oneLine } from 'common-tags';
44
import * as chalk from 'chalk';
55
import * as fs from 'fs';

addon/ng2/models/config/config.ts renamed to packages/angular-cli/models/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as path from 'path';
44
import {SchemaClass, SchemaClassFactory} from '../json-schema/schema-class-factory';
55

66

7-
const DEFAULT_CONFIG_SCHEMA_PATH = path.join(__dirname, '../../../../lib/config/schema.json');
7+
const DEFAULT_CONFIG_SCHEMA_PATH = path.join(__dirname, '../../lib/config/schema.json');
88

99

1010
export class InvalidConfigError extends Error {
File renamed without changes.

addon/ng2/models/find-lazy-modules.ts renamed to packages/angular-cli/models/find-lazy-modules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function findLoadChildren(tsFilePath: string): string[] {
5050
}
5151

5252

53-
export function findLazyModules(projectRoot: any): string[] {
53+
export function findLazyModules(projectRoot: any): {[key: string]: string} {
5454
const result: {[key: string]: string} = {};
5555
glob.sync(path.join(projectRoot, '/**/*.ts'))
5656
.forEach(tsPath => {
File renamed without changes.

0 commit comments

Comments
 (0)