Permalink
Browse files

chore(packages): move packages into their own scope. (#3413)

This will facilitate management of packages internally.
  • Loading branch information...
1 parent 8b0ad7a commit 61dd440f4d2ea2db00d15f45f5a55af82f0c3599 @hansl hansl committed on GitHub Dec 6, 2016
Showing with 68 additions and 233 deletions.
  1. +31 −17 lib/packages.js
  2. 0 packages/{ → @angular-cli}/ast-tools/package.json
  3. 0 packages/{ → @angular-cli}/ast-tools/src/ast-utils.spec.ts
  4. 0 packages/{ → @angular-cli}/ast-tools/src/ast-utils.ts
  5. 0 packages/{ → @angular-cli}/ast-tools/src/change.spec.ts
  6. 0 packages/{ → @angular-cli}/ast-tools/src/change.ts
  7. 0 packages/{ → @angular-cli}/ast-tools/src/index.ts
  8. 0 packages/{ → @angular-cli}/ast-tools/src/node.ts
  9. 0 packages/{ → @angular-cli}/ast-tools/src/route-utils.spec.ts
  10. 0 packages/{ → @angular-cli}/ast-tools/src/route-utils.ts
  11. 0 packages/{ → @angular-cli}/ast-tools/src/spec-utils.ts
  12. +1 −1 packages/{base-href-webpack → @angular-cli/ast-tools}/tsconfig.json
  13. 0 packages/{ → @angular-cli}/base-href-webpack/package.json
  14. 0 packages/{ → @angular-cli}/base-href-webpack/src/base-href-webpack-plugin.spec.ts
  15. 0 packages/{ → @angular-cli}/base-href-webpack/src/base-href-webpack-plugin.ts
  16. 0 packages/{ → @angular-cli}/base-href-webpack/src/index.ts
  17. +1 −1 packages/{ast-tools → @angular-cli/base-href-webpack}/tsconfig.json
  18. 0 packages/{ → @ngtools}/webpack/README.md
  19. 0 packages/{ → @ngtools}/webpack/package.json
  20. 0 packages/{ → @ngtools}/webpack/src/compiler_host.ts
  21. 0 packages/{ → @ngtools}/webpack/src/entry_resolver.ts
  22. 0 packages/{ → @ngtools}/webpack/src/index.ts
  23. 0 packages/{ → @ngtools}/webpack/src/loader.ts
  24. 0 packages/{ → @ngtools}/webpack/src/paths-plugin.ts
  25. 0 packages/{ → @ngtools}/webpack/src/plugin.ts
  26. 0 packages/{ → @ngtools}/webpack/src/refactor.ts
  27. 0 packages/{ → @ngtools}/webpack/src/reflector_host.ts
  28. 0 packages/{ → @ngtools}/webpack/src/resource_loader.ts
  29. 0 packages/{ → @ngtools}/webpack/src/utils.ts
  30. 0 packages/{ → @ngtools}/webpack/src/webpack.ts
  31. +3 −3 packages/{ → @ngtools}/webpack/tsconfig.json
  32. +0 −77 packages/angular-cli/models/find-lazy-modules.ts
  33. +3 −3 packages/angular-cli/tsconfig.json
  34. +0 −50 tests/acceptance/find-lazy-module.spec.ts
  35. +1 −0 tests/e2e/assets/webpack/test-app-weird/package.json
  36. +1 −0 tests/e2e/assets/webpack/test-app/package.json
  37. +3 −11 tests/e2e/tests/packages/webpack/test.ts
  38. +3 −10 tests/e2e/tests/packages/webpack/weird.ts
  39. +21 −0 tests/e2e/utils/assets.ts
  40. +0 −60 tests/models/find-lazy-modules.spec.ts
View
@@ -1,26 +1,40 @@
'use strict';
const fs = require('fs');
+const glob = require('glob');
const path = require('path');
const packageRoot = path.join(__dirname, '../packages');
// All the supported packages. Go through the packages directory and create a map of
// name => fullPath.
-const packages = fs.readdirSync(packageRoot)
- .map(pkgName => ({ name: pkgName, root: path.join(packageRoot, pkgName) }))
- .filter(pkg => fs.statSync(pkg.root).isDirectory())
- .reduce((packages, pkg) => {
- let pkgJson = JSON.parse(fs.readFileSync(path.join(pkg.root, 'package.json'), 'utf8'));
- let name = pkgJson['name'];
- packages[name] = {
- dist: path.join(__dirname, '../dist', pkg.name),
- packageJson: path.join(pkg.root, 'package.json'),
- root: pkg.root,
- relative: path.relative(path.dirname(__dirname), pkg.root),
- main: path.resolve(pkg.root, 'src/index.ts')
- };
- return packages;
- }, {});
-
-module.exports = packages;
+const packages =
+ glob.sync(path.join(packageRoot, '**/package.json'))
+ .filter(p => !p.match(/blueprints/))
+ .map(pkgPath => path.relative(packageRoot, path.dirname(pkgPath)))
+ .map(pkgName => {
+ return { name: pkgName, root: path.join(packageRoot, pkgName) };
+ })
+ .reduce((packages, pkg) => {
+ let pkgJson = JSON.parse(fs.readFileSync(path.join(pkg.root, 'package.json'), 'utf8'));
+ let name = pkgJson['name'];
+
+ packages[name] = {
+ dist: path.join(__dirname, '../dist', pkg.name),
+ packageJson: path.join(pkg.root, 'package.json'),
+ root: pkg.root,
+ relative: path.relative(path.dirname(__dirname), pkg.root),
+ main: path.resolve(pkg.root, 'src/index.ts')
+ };
+ return packages;
+ }, {});
+
+
+module.exports = packages;
+
+
+// If we run this from the command line, just output the list of modules neatly formatted.
+if (require.main === module) {
+ // eslint-disable-next-line no-console
+ console.log(JSON.stringify(packages, null, 2));
+}
@@ -7,7 +7,7 @@
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
- "outDir": "../../dist/base-href-webpack",
+ "outDir": "../../../dist/@angular-cli/ast-tools",
"rootDir": ".",
"sourceMap": true,
"sourceRoot": "/",
@@ -7,7 +7,7 @@
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
- "outDir": "../../dist/ast-tools",
+ "outDir": "../../../dist/@angular-cli/base-href-webpack",
"rootDir": ".",
"sourceMap": true,
"sourceRoot": "/",
@@ -7,15 +7,15 @@
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
- "outDir": "../../dist/webpack",
+ "outDir": "../../../dist/@ngtools/webpack",
"rootDir": ".",
"lib": ["es2015", "es6", "dom"],
"target": "es5",
"sourceMap": true,
"sourceRoot": "/",
- "baseUrl": ".",
+ "baseUrl": "./",
"paths": {
- "@angular-cli/ast-tools": [ "../../dist/ast-tools/src" ]
+ "@angular-cli/ast-tools": [ "../../../dist/ast-tools/src" ]
},
"typeRoots": [
"../../node_modules/@types"
@@ -1,77 +0,0 @@
-import * as fs from 'fs';
-import * as glob from 'glob';
-import * as path from 'path';
-import * as ts from 'typescript';
-const resolve = require('resolve');
-
-import {getSource, findNodes, getContentOfKeyLiteral} from '../utilities/ast-utils';
-
-
-export function findLoadChildren(tsFilePath: string): string[] {
- const source = getSource(tsFilePath);
- const unique: { [path: string]: boolean } = {};
-
- return (
- // Find all object literals.
- findNodes(source, ts.SyntaxKind.ObjectLiteralExpression)
- // Get all their property assignments.
- .map(node => findNodes(node, ts.SyntaxKind.PropertyAssignment))
- // Flatten into a single array (from an array of array<property assignments>).
- .reduce((prev, curr) => curr ? prev.concat(curr) : prev, [])
- // Remove every property assignment that aren't 'loadChildren'.
- .filter((node: ts.PropertyAssignment) => {
- const key = getContentOfKeyLiteral(source, node.name);
- if (!key) {
- // key is an expression, can't do anything.
- return false;
- }
- return key == 'loadChildren';
- })
- // Remove initializers that are not files.
- .filter((node: ts.PropertyAssignment) => {
- return node.initializer.kind === ts.SyntaxKind.StringLiteral;
- })
- // Get the full text of the initializer.
- .map((node: ts.PropertyAssignment) => {
- const literal = node.initializer as ts.StringLiteral;
- return literal.text;
- })
- // Map to the module name itself.
- .map((moduleName: string) => moduleName.split('#')[0])
- // Only get unique values (there might be multiple modules from a single URL, or a module used
- // multiple times).
- .filter((value: string) => {
- if (unique[value]) {
- return false;
- } else {
- unique[value] = true;
- return true;
- }
- }));
-}
-
-export function findLazyModules(projectRoot: any): {[key: string]: string} {
- const result: {[key: string]: string} = {};
- glob.sync(path.join(projectRoot, '/**/*.ts'))
- .forEach(tsPath => {
- findLoadChildren(tsPath).forEach(moduleName => {
- let fileName = moduleName.startsWith('.')
- ? path.resolve(path.dirname(tsPath), moduleName) + '.ts'
- : path.resolve(projectRoot, moduleName) + '.ts';
-
- if (fs.existsSync(fileName)) {
- // Put the moduleName as relative to the main.ts.
- result[moduleName] = fileName;
- } else {
- try {
- let res = resolve.sync(moduleName, { basedir: projectRoot });
- if (res) {
- result[moduleName] = res;
- }
- } catch (e) {
- }
- }
- });
- });
- return result;
-}
@@ -20,9 +20,9 @@
],
"baseUrl": "",
"paths": {
- "@angular-cli/ast-tools": [ "../../dist/ast-tools/src" ],
- "@angular-cli/base-href-webpack": [ "../../dist/base-href-webpack/src" ],
- "@ngtools/webpack": [ "../../dist/webpack/src" ]
+ "@angular-cli/ast-tools": [ "../../dist/@angular-cli/ast-tools/src" ],
+ "@angular-cli/base-href-webpack": [ "../../dist/@angular-cli/base-href-webpack/src" ],
+ "@ngtools/webpack": [ "../../dist/@ngtools/webpack/src" ]
}
},
"include": [
@@ -1,50 +0,0 @@
-import * as mockFs from 'mock-fs';
-import {stripIndents} from 'common-tags';
-import {expect} from 'chai';
-import {join} from 'path';
-
-import {findLazyModules} from 'angular-cli/models/find-lazy-modules';
-
-
-describe('find-lazy-module', () => {
- beforeEach(() => {
- mockFs({
- 'project-root': {
- 'fileA.ts': stripIndents`
- const r1 = {
- "loadChildren": "moduleA"
- };
- const r2 = {
- loadChildren: "moduleB"
- };
- const r3 = {
- 'loadChildren': 'moduleC'
- };
- const r4 = {
- "loadChildren": 'app/+workspace/+settings/settings.module#SettingsModule'
- };
- const r5 = {
- loadChildren: 'unexistentModule'
- };
- `,
- // Create those files too as they have to exist.
- 'moduleA.ts': '',
- 'moduleB.ts': '',
- 'moduleC.ts': '',
- 'moduleD.ts': '',
- 'app': { '+workspace': { '+settings': { 'settings.module.ts': '' } } }
- }
- });
- });
- afterEach(() => mockFs.restore());
-
- it('works', () => {
- expect(findLazyModules('project-root')).to.eql({
- 'moduleA': join(process.cwd(), 'project-root', 'moduleA.ts'),
- 'moduleB': join(process.cwd(), 'project-root', 'moduleB.ts'),
- 'moduleC': join(process.cwd(), 'project-root', 'moduleC.ts'),
- 'app/+workspace/+settings/settings.module':
- join(process.cwd(), 'project-root', 'app/+workspace/+settings/settings.module.ts'),
- });
- });
-});
@@ -11,6 +11,7 @@
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@angular/router": "3.2.1",
+ "@ngtools/webpack": "0.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.0.0-beta.12",
"zone.js": "^0.6.21"
@@ -11,6 +11,7 @@
"@angular/platform-browser-dynamic": "2.2.3",
"@angular/platform-server": "2.2.3",
"@angular/router": "3.2.3",
+ "@ngtools/webpack": "0.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.0.0-beta.12",
"zone.js": "^0.6.21"
@@ -1,7 +1,5 @@
-import {copyAssets} from '../../../utils/assets';
-import {exec, silentNpm} from '../../../utils/process';
-import {updateJsonFile} from '../../../utils/project';
-import {join} from 'path';
+import {createProjectFromAsset} from '../../../utils/assets';
+import {exec} from '../../../utils/process';
import {expectFileSizeToBeUnder} from '../../../utils/fs';
@@ -12,13 +10,7 @@ export default function(skipCleaning: () => void) {
}
return Promise.resolve()
- .then(() => copyAssets('webpack/test-app'))
- .then(dir => process.chdir(dir))
- .then(() => updateJsonFile('package.json', json => {
- const dist = '../../../../../dist/';
- json['dependencies']['@ngtools/webpack'] = join(__dirname, dist, 'webpack');
- }))
- .then(() => silentNpm('install'))
+ .then(() => createProjectFromAsset('webpack/test-app'))
.then(() => exec('node_modules/.bin/webpack', '-p'))
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 400000))
.then(() => expectFileSizeToBeUnder('dist/0.app.main.js', 40000))
@@ -1,7 +1,6 @@
-import {copyAssets} from '../../../utils/assets';
-import {exec, silentNpm} from '../../../utils/process';
+import {createProjectFromAsset} from '../../../utils/assets';
+import {exec} from '../../../utils/process';
import {updateJsonFile} from '../../../utils/project';
-import {join} from 'path';
import {expectFileSizeToBeUnder, expectFileToExist} from '../../../utils/fs';
import {expectToFail} from '../../../utils/utils';
@@ -13,13 +12,7 @@ export default function(skipCleaning: () => void) {
}
return Promise.resolve()
- .then(() => copyAssets('webpack/test-app-weird'))
- .then(dir => process.chdir(dir))
- .then(() => updateJsonFile('package.json', json => {
- const dist = '../../../../../dist/';
- json['dependencies']['@ngtools/webpack'] = join(__dirname, dist, 'webpack');
- }))
- .then(() => silentNpm('install'))
+ .then(() => createProjectFromAsset('webpack/test-app-weird'))
.then(() => exec('node_modules/.bin/webpack', '-p'))
.then(() => expectFileToExist('dist/app.main.js'))
.then(() => expectFileToExist('dist/0.app.main.js'))
@@ -3,6 +3,8 @@ import * as glob from 'glob';
import {getGlobalVariable} from './env';
import {relative} from 'path';
import {copyFile} from './fs';
+import {updateJsonFile} from './project';
+import {silentNpm} from './process';
export function assetDir(assetName: string) {
@@ -27,3 +29,22 @@ export function copyAssets(assetName: string) {
})
.then(() => tempRoot);
}
+
+
+export function createProjectFromAsset(assetName: string) {
+ const packages = require('../../../lib/packages');
+
+ return Promise.resolve()
+ .then(() => copyAssets(assetName))
+ .then(dir => process.chdir(dir))
+ .then(() => updateJsonFile('package.json', json => {
+ for (const packageName of Object.keys(packages)) {
+ if (json['dependencies'].hasOwnProperty(packageName)) {
+ json['dependencies'][packageName] = packages[packageName].dist;
+ } else if (json['devDependencies'].hasOwnProperty(packageName)) {
+ json['devDependencies'][packageName] = packages[packageName].dist;
+ }
+ }
+ }))
+ .then(() => silentNpm('install'));
+}
@@ -1,60 +0,0 @@
-const mockFs = require('mock-fs');
-const expect = require('chai').expect;
-import * as path from 'path';
-import {findLoadChildren, findLazyModules} from 'angular-cli/models/find-lazy-modules';
-
-describe('find-lazy-modules', () => {
- beforeEach(() => {
- let mockDrive = {
- 'node_modules/feature-module': {
- 'package.json': '{ "main": "index.js" }',
- 'index.js': ''
- },
- 'src/app': {
- 'app.module.ts': `RouterModule.forRoot([
- { path: 'relative', loadChildren: './feature-a/feature-a.module' },
- { path: 'absolute', loadChildren: 'src/app/feature-b/feature-b.module' },
- { path: 'module', loadChildren: 'feature-module' },
- { path: 'module2', loadChildren: 'feature-module/index.js' },
- { path: 'invalid', loadChildren: 'invalid' }
- ]);`,
- 'feature-a': {
- 'feature-a.module.ts': ''
- },
- 'feature-b': {
- 'feature-b.module.ts': ''
- }
- }
- };
- mockFs(mockDrive);
- });
- afterEach(() => {
- mockFs.restore();
- });
-
- it('should find children', () => {
- let children = findLoadChildren('src/app/app.module.ts');
- expect(children.length).to.equal(5);
- expect(children.sort()).to.deep.equal([
- './feature-a/feature-a.module',
- 'feature-module',
- 'feature-module/index.js',
- 'invalid',
- 'src/app/feature-b/feature-b.module'
- ]);
- });
-
- it('should find lazy modules', () => {
- let modules = findLazyModules('.');
- expect(modules).to.deep.equal({
- './feature-a/feature-a.module':
- path.join(__dirname, '../../src/app/feature-a/feature-a.module.ts'),
- 'src/app/feature-b/feature-b.module':
- path.join(__dirname, '../../src/app/feature-b/feature-b.module.ts'),
- 'feature-module':
- path.join(__dirname, '../../node_modules/feature-module/index.js'),
- 'feature-module/index.js':
- path.join(__dirname, '../../node_modules/feature-module/index.js')
- });
- });
-});

0 comments on commit 61dd440

Please sign in to comment.