Skip to content

Commit

Permalink
chore(packages): move packages into their own scope. (#3413)
Browse files Browse the repository at this point in the history
This will facilitate management of packages internally.
  • Loading branch information
hansl committed Dec 6, 2016
1 parent 8b0ad7a commit 61dd440
Show file tree
Hide file tree
Showing 40 changed files with 68 additions and 233 deletions.
48 changes: 31 additions & 17 deletions lib/packages.js
@@ -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));
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -7,7 +7,7 @@
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
"outDir": "../../dist/ast-tools",
"outDir": "../../../dist/@angular-cli/ast-tools",
"rootDir": ".",
"sourceMap": true,
"sourceRoot": "/",
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -7,7 +7,7 @@
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
"outDir": "../../dist/base-href-webpack",
"outDir": "../../../dist/@angular-cli/base-href-webpack",
"rootDir": ".",
"sourceMap": true,
"sourceRoot": "/",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -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"
Expand Down
77 changes: 0 additions & 77 deletions packages/angular-cli/models/find-lazy-modules.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/angular-cli/tsconfig.json
Expand Up @@ -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": [
Expand Down
50 changes: 0 additions & 50 deletions tests/acceptance/find-lazy-module.spec.ts

This file was deleted.

1 change: 1 addition & 0 deletions tests/e2e/assets/webpack/test-app-weird/package.json
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/assets/webpack/test-app/package.json
Expand Up @@ -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"
Expand Down
14 changes: 3 additions & 11 deletions tests/e2e/tests/packages/webpack/test.ts
@@ -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';


Expand All @@ -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))
Expand Down
13 changes: 3 additions & 10 deletions tests/e2e/tests/packages/webpack/weird.ts
@@ -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';

Expand All @@ -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'))
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/utils/assets.ts
Expand Up @@ -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) {
Expand All @@ -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'));
}
60 changes: 0 additions & 60 deletions tests/models/find-lazy-modules.spec.ts

This file was deleted.

0 comments on commit 61dd440

Please sign in to comment.