Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add license test #4561

Merged
merged 10 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"guard-for-in": "off",
"handle-callback-err": "off",
"id-length": "off",
"indent": [2,2],
"indent": [2,2, { "SwitchCase": 1 }],
"init-declarations": "off",
"jsx-quotes": "off",
"key-spacing": [2, {
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
"build": "node ./scripts/publish/build.js",
"build:patch": "node ./scripts/patch.js",
"build:packages": "for PKG in packages/*; do echo Building $PKG...; tsc -p $PKG; done",
"test": "npm-run-all -c test:packages test:cli test:deps",
"test": "npm-run-all -c test:packages test:cli test:deps test:licenses",
"e2e": "npm run test:e2e",
"e2e:nightly": "node tests/run_e2e.js --nightly",
"test:e2e": "node tests/run_e2e.js",
"test:cli": "node tests/runner",
"test:deps": "node scripts/publish/validate_dependencies.js",
"test:inspect": "node --inspect --debug-brk tests/runner",
"test:licenses": "node scripts/test-licenses.js",
"test:packages": "node scripts/run-packages-spec.js",
"eslint": "eslint .",
"tslint": "tslint \"**/*.ts\" -c tslint.json -e \"**/config/schema.d.ts\" -e \"**/tests/**\" -e \"**/blueprints/*/files/**/*.ts\" -e \"node_modules/**\" -e \"tmp/**\" -e \"dist/**\"",
Expand Down Expand Up @@ -57,7 +58,6 @@
"exports-loader": "^0.6.3",
"extract-text-webpack-plugin": "^2.0.0-rc.3",
"file-loader": "^0.10.0",
"findup": "0.1.5",
"fs-extra": "~2.0.0",
"get-caller-file": "^1.0.0",
"glob": "^7.0.3",
Expand Down Expand Up @@ -144,6 +144,7 @@
"resolve-bin": "^0.4.0",
"rewire": "^2.5.1",
"sinon": "^1.17.3",
"spdx-satisfies": "^0.1.3",
"through": "^2.3.6",
"tree-kill": "^1.0.0",
"ts-node": "^2.0.0",
Expand Down
44 changes: 15 additions & 29 deletions packages/@angular/cli/ember-cli/lib/models/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
var Promise = require('../ext/promise');
var path = require('path');
var findup = Promise.denodeify(require('findup'));
var findUp = require('../../../utilities/find-up').findUp;
var resolve = Promise.denodeify(require('resolve'));
var fs = require('fs');
var find = require('lodash/find');
Expand Down Expand Up @@ -470,7 +470,7 @@ Project.closest = function(pathName, _ui, _cli) {
return new Project(result.directory, result.pkg, ui, _cli);
})
.catch(function(reason) {
handleFindupError(pathName, reason);
handleFindupError(pathName);
});
};

Expand Down Expand Up @@ -546,7 +546,7 @@ Project.projectOrnullProject = function(_ui, _cli) {
*/
Project.getProjectRoot = function () {
try {
var directory = findup.sync(process.cwd(), 'package.json');
var directory = path.dirname(findUp(process.cwd(), 'package.json'));
var pkg = require(path.join(directory, 'package.json'));

if (pkg && pkg.name === 'ember-cli') {
Expand All @@ -557,12 +557,8 @@ Project.getProjectRoot = function () {
debug('getProjectRoot %s -> %s', process.cwd(), directory);
return directory;
} catch (reason) {
if (isFindupError(reason)) {
debug('getProjectRoot: not found. Will use cwd: %s', process.cwd());
return process.cwd();
} else {
throw reason;
}
debug('getProjectRoot: not found. Will use cwd: %s', process.cwd());
return process.cwd();
}
};

Expand Down Expand Up @@ -594,34 +590,24 @@ function ensureUI(_ui) {
}

function closestPackageJSON(pathName) {
return findup(pathName, 'package.json')
.then(function(directory) {
return Promise.hash({
directory: directory,
pkg: require(path.join(directory, 'package.json'))
});
});
return Promise.resolve()
.then(() => findUp('package.json', pathName))
.then(filePath => ({
directory: path.dirname(filePath),
pkg: require(filePath)
}));
}

function findupPath(pathName) {
try {
return findup.sync(pathName, 'package.json');
return path.dirname(findUp('package.json', pathName));
} catch (reason) {
handleFindupError(pathName, reason);
handleFindupError(pathName);
}
}

function isFindupError(reason) {
// Would be nice if findup threw error subclasses
return reason && /not found/i.test(reason.message);
}

function handleFindupError(pathName, reason) {
if (isFindupError(reason)) {
throw new NotFoundError('No project found at or up from: `' + pathName + '`');
} else {
throw reason;
}
function handleFindupError(pathName) {
throw new NotFoundError('No project found at or up from: `' + pathName + '`');
}

// Export
Expand Down
35 changes: 9 additions & 26 deletions packages/@angular/cli/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,11 @@ import * as chalk from 'chalk';
import * as fs from 'fs';
import * as path from 'path';

export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json';


function _findUp(name: string, from: string) {
let currentDir = from;
while (currentDir && currentDir !== path.parse(currentDir).root) {
const p = path.join(currentDir, name);
if (fs.existsSync(p)) {
return p;
}

const nodeModuleP = path.join(currentDir, 'node_modules');
if (fs.existsSync(nodeModuleP)) {
return null;
}
import {findUp} from '../utilities/find-up';

currentDir = path.dirname(currentDir);
}

return null;
}
export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json';


function getUserHome() {
Expand All @@ -38,12 +21,12 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
static configFilePath(projectPath?: string): string {
// Find the configuration, either where specified, in the Angular CLI project
// (if it's in node_modules) or from the current process.
return (projectPath && _findUp(CLI_CONFIG_FILE_NAME, projectPath))
|| (projectPath && _findUp(CLI_CONFIG_FILE_NAME_ALT, projectPath))
|| _findUp(CLI_CONFIG_FILE_NAME, process.cwd())
|| _findUp(CLI_CONFIG_FILE_NAME_ALT, process.cwd())
|| _findUp(CLI_CONFIG_FILE_NAME, __dirname)
|| _findUp(CLI_CONFIG_FILE_NAME_ALT, __dirname);
return (projectPath && findUp(CLI_CONFIG_FILE_NAME, projectPath))
|| (projectPath && findUp(CLI_CONFIG_FILE_NAME_ALT, projectPath))
|| findUp(CLI_CONFIG_FILE_NAME, process.cwd())
|| findUp(CLI_CONFIG_FILE_NAME_ALT, process.cwd())
|| findUp(CLI_CONFIG_FILE_NAME, __dirname)
|| findUp(CLI_CONFIG_FILE_NAME_ALT, __dirname);
}

static fromGlobal(): CliConfig {
Expand Down
1 change: 0 additions & 1 deletion packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"exports-loader": "^0.6.3",
"extract-text-webpack-plugin": "^2.0.0-rc.3",
"file-loader": "^0.10.0",
"findup": "0.1.5",
"fs-extra": "^2.0.0",
"get-caller-file": "^1.0.0",
"glob": "^7.0.3",
Expand Down
30 changes: 8 additions & 22 deletions packages/@angular/cli/upgrade/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,18 @@ import {readFileSync, existsSync} from 'fs';
import * as path from 'path';

import {CliConfig} from '../models/config';
import {findUp} from '../utilities/find-up';

const resolve = require('resolve');


function _findUp(name: string, from: string) {
let currentDir = from;
while (currentDir && currentDir !== path.parse(currentDir).root) {
const p = path.join(currentDir, name);
if (existsSync(p)) {
return p;
}

currentDir = path.dirname(currentDir);
}

return null;
}


function _hasOldCliBuildFile() {
return existsSync(_findUp('angular-cli-build.js', process.cwd()))
|| existsSync(_findUp('angular-cli-build.ts', process.cwd()))
|| existsSync(_findUp('ember-cli-build.js', process.cwd()))
|| existsSync(_findUp('angular-cli-build.js', __dirname))
|| existsSync(_findUp('angular-cli-build.ts', __dirname))
|| existsSync(_findUp('ember-cli-build.js', __dirname));
return existsSync(findUp('angular-cli-build.js', process.cwd()))
|| existsSync(findUp('angular-cli-build.ts', process.cwd()))
|| existsSync(findUp('ember-cli-build.js', process.cwd()))
|| existsSync(findUp('angular-cli-build.js', __dirname))
|| existsSync(findUp('angular-cli-build.ts', __dirname))
|| existsSync(findUp('ember-cli-build.js', __dirname));
}


Expand Down Expand Up @@ -112,7 +98,7 @@ export class Version {
console.error(bold(red(stripIndents`
This version of CLI is only compatible with angular version 2.3.1 or better. Please
upgrade your angular version, e.g. by running:

npm install @angular/core@latest
` + '\n')));
process.exit(3);
Expand Down
23 changes: 23 additions & 0 deletions packages/@angular/cli/utilities/find-up.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as path from 'path';
import { existsSync } from 'fs';

export function findUp(name: string, from: string, stopOnNodeModules = false) {
let currentDir = from;
while (currentDir && currentDir !== path.parse(currentDir).root) {
const p = path.join(currentDir, name);
if (existsSync(p)) {
return p;
}

if (stopOnNodeModules) {
const nodeModuleP = path.join(currentDir, 'node_modules');
if (existsSync(nodeModuleP)) {
return null;
}
}

currentDir = path.dirname(currentDir);
}

return null;
}