Skip to content

Commit 6d5dfa0

Browse files
authored
test: add license test (angular#4561)
* test: add license test * only check prod dependencies * remove findup dep * also check dev deps * add map-stream to ignore list * remove license-checker * add comment * use logger * fix lint errors
1 parent ab06196 commit 6d5dfa0

File tree

8 files changed

+207
-81
lines changed

8 files changed

+207
-81
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"guard-for-in": "off",
165165
"handle-callback-err": "off",
166166
"id-length": "off",
167-
"indent": [2,2],
167+
"indent": [2,2, { "SwitchCase": 1 }],
168168
"init-declarations": "off",
169169
"jsx-quotes": "off",
170170
"key-spacing": [2, {

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
"build": "node ./scripts/publish/build.js",
1313
"build:patch": "node ./scripts/patch.js",
1414
"build:packages": "for PKG in packages/*; do echo Building $PKG...; tsc -p $PKG; done",
15-
"test": "npm-run-all -c test:packages test:cli test:deps",
15+
"test": "npm-run-all -c test:packages test:cli test:deps test:licenses",
1616
"e2e": "npm run test:e2e",
1717
"e2e:nightly": "node tests/run_e2e.js --nightly",
1818
"test:e2e": "node tests/run_e2e.js",
1919
"test:cli": "node tests/runner",
2020
"test:deps": "node scripts/publish/validate_dependencies.js",
2121
"test:inspect": "node --inspect --debug-brk tests/runner",
22+
"test:licenses": "node scripts/test-licenses.js",
2223
"test:packages": "node scripts/run-packages-spec.js",
2324
"eslint": "eslint .",
2425
"tslint": "tslint \"**/*.ts\" -c tslint.json -e \"**/config/schema.d.ts\" -e \"**/tests/**\" -e \"**/blueprints/*/files/**/*.ts\" -e \"node_modules/**\" -e \"tmp/**\" -e \"dist/**\"",
@@ -57,7 +58,6 @@
5758
"exports-loader": "^0.6.3",
5859
"extract-text-webpack-plugin": "^2.0.0-rc.3",
5960
"file-loader": "^0.10.0",
60-
"findup": "0.1.5",
6161
"fs-extra": "~2.0.0",
6262
"get-caller-file": "^1.0.0",
6363
"glob": "^7.0.3",
@@ -144,6 +144,7 @@
144144
"resolve-bin": "^0.4.0",
145145
"rewire": "^2.5.1",
146146
"sinon": "^1.17.3",
147+
"spdx-satisfies": "^0.1.3",
147148
"through": "^2.3.6",
148149
"tree-kill": "^1.0.0",
149150
"ts-node": "^2.0.0",

packages/@angular/cli/ember-cli/lib/models/project.js

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
var Promise = require('../ext/promise');
77
var path = require('path');
8-
var findup = Promise.denodeify(require('findup'));
8+
var findUp = require('../../../utilities/find-up').findUp;
99
var resolve = Promise.denodeify(require('resolve'));
1010
var fs = require('fs');
1111
var find = require('lodash/find');
@@ -470,7 +470,7 @@ Project.closest = function(pathName, _ui, _cli) {
470470
return new Project(result.directory, result.pkg, ui, _cli);
471471
})
472472
.catch(function(reason) {
473-
handleFindupError(pathName, reason);
473+
handleFindupError(pathName);
474474
});
475475
};
476476

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

552552
if (pkg && pkg.name === 'ember-cli') {
@@ -557,12 +557,8 @@ Project.getProjectRoot = function () {
557557
debug('getProjectRoot %s -> %s', process.cwd(), directory);
558558
return directory;
559559
} catch (reason) {
560-
if (isFindupError(reason)) {
561-
debug('getProjectRoot: not found. Will use cwd: %s', process.cwd());
562-
return process.cwd();
563-
} else {
564-
throw reason;
565-
}
560+
debug('getProjectRoot: not found. Will use cwd: %s', process.cwd());
561+
return process.cwd();
566562
}
567563
};
568564

@@ -594,34 +590,24 @@ function ensureUI(_ui) {
594590
}
595591

596592
function closestPackageJSON(pathName) {
597-
return findup(pathName, 'package.json')
598-
.then(function(directory) {
599-
return Promise.hash({
600-
directory: directory,
601-
pkg: require(path.join(directory, 'package.json'))
602-
});
603-
});
593+
return Promise.resolve()
594+
.then(() => findUp('package.json', pathName))
595+
.then(filePath => ({
596+
directory: path.dirname(filePath),
597+
pkg: require(filePath)
598+
}));
604599
}
605600

606601
function findupPath(pathName) {
607602
try {
608-
return findup.sync(pathName, 'package.json');
603+
return path.dirname(findUp('package.json', pathName));
609604
} catch (reason) {
610-
handleFindupError(pathName, reason);
605+
handleFindupError(pathName);
611606
}
612607
}
613608

614-
function isFindupError(reason) {
615-
// Would be nice if findup threw error subclasses
616-
return reason && /not found/i.test(reason.message);
617-
}
618-
619-
function handleFindupError(pathName, reason) {
620-
if (isFindupError(reason)) {
621-
throw new NotFoundError('No project found at or up from: `' + pathName + '`');
622-
} else {
623-
throw reason;
624-
}
609+
function handleFindupError(pathName) {
610+
throw new NotFoundError('No project found at or up from: `' + pathName + '`');
625611
}
626612

627613
// Export

packages/@angular/cli/models/config.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,11 @@ import * as chalk from 'chalk';
55
import * as fs from 'fs';
66
import * as path from 'path';
77

8-
export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
9-
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json';
10-
11-
12-
function _findUp(name: string, from: string) {
13-
let currentDir = from;
14-
while (currentDir && currentDir !== path.parse(currentDir).root) {
15-
const p = path.join(currentDir, name);
16-
if (fs.existsSync(p)) {
17-
return p;
18-
}
19-
20-
const nodeModuleP = path.join(currentDir, 'node_modules');
21-
if (fs.existsSync(nodeModuleP)) {
22-
return null;
23-
}
8+
import {findUp} from '../utilities/find-up';
249

25-
currentDir = path.dirname(currentDir);
26-
}
2710

28-
return null;
29-
}
11+
export const CLI_CONFIG_FILE_NAME = '.angular-cli.json';
12+
const CLI_CONFIG_FILE_NAME_ALT = 'angular-cli.json';
3013

3114

3215
function getUserHome() {
@@ -38,12 +21,12 @@ export class CliConfig extends CliConfigBase<ConfigInterface> {
3821
static configFilePath(projectPath?: string): string {
3922
// Find the configuration, either where specified, in the Angular CLI project
4023
// (if it's in node_modules) or from the current process.
41-
return (projectPath && _findUp(CLI_CONFIG_FILE_NAME, projectPath))
42-
|| (projectPath && _findUp(CLI_CONFIG_FILE_NAME_ALT, projectPath))
43-
|| _findUp(CLI_CONFIG_FILE_NAME, process.cwd())
44-
|| _findUp(CLI_CONFIG_FILE_NAME_ALT, process.cwd())
45-
|| _findUp(CLI_CONFIG_FILE_NAME, __dirname)
46-
|| _findUp(CLI_CONFIG_FILE_NAME_ALT, __dirname);
24+
return (projectPath && findUp(CLI_CONFIG_FILE_NAME, projectPath))
25+
|| (projectPath && findUp(CLI_CONFIG_FILE_NAME_ALT, projectPath))
26+
|| findUp(CLI_CONFIG_FILE_NAME, process.cwd())
27+
|| findUp(CLI_CONFIG_FILE_NAME_ALT, process.cwd())
28+
|| findUp(CLI_CONFIG_FILE_NAME, __dirname)
29+
|| findUp(CLI_CONFIG_FILE_NAME_ALT, __dirname);
4730
}
4831

4932
static fromGlobal(): CliConfig {

packages/@angular/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"exports-loader": "^0.6.3",
4747
"extract-text-webpack-plugin": "^2.0.0-rc.3",
4848
"file-loader": "^0.10.0",
49-
"findup": "0.1.5",
5049
"fs-extra": "^2.0.0",
5150
"get-caller-file": "^1.0.0",
5251
"glob": "^7.0.3",

packages/@angular/cli/upgrade/version.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,18 @@ import {readFileSync, existsSync} from 'fs';
55
import * as path from 'path';
66

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

910
const resolve = require('resolve');
1011

1112

12-
function _findUp(name: string, from: string) {
13-
let currentDir = from;
14-
while (currentDir && currentDir !== path.parse(currentDir).root) {
15-
const p = path.join(currentDir, name);
16-
if (existsSync(p)) {
17-
return p;
18-
}
19-
20-
currentDir = path.dirname(currentDir);
21-
}
22-
23-
return null;
24-
}
25-
26-
2713
function _hasOldCliBuildFile() {
28-
return existsSync(_findUp('angular-cli-build.js', process.cwd()))
29-
|| existsSync(_findUp('angular-cli-build.ts', process.cwd()))
30-
|| existsSync(_findUp('ember-cli-build.js', process.cwd()))
31-
|| existsSync(_findUp('angular-cli-build.js', __dirname))
32-
|| existsSync(_findUp('angular-cli-build.ts', __dirname))
33-
|| existsSync(_findUp('ember-cli-build.js', __dirname));
14+
return existsSync(findUp('angular-cli-build.js', process.cwd()))
15+
|| existsSync(findUp('angular-cli-build.ts', process.cwd()))
16+
|| existsSync(findUp('ember-cli-build.js', process.cwd()))
17+
|| existsSync(findUp('angular-cli-build.js', __dirname))
18+
|| existsSync(findUp('angular-cli-build.ts', __dirname))
19+
|| existsSync(findUp('ember-cli-build.js', __dirname));
3420
}
3521

3622

@@ -112,7 +98,7 @@ export class Version {
11298
console.error(bold(red(stripIndents`
11399
This version of CLI is only compatible with angular version 2.3.1 or better. Please
114100
upgrade your angular version, e.g. by running:
115-
101+
116102
npm install @angular/core@latest
117103
` + '\n')));
118104
process.exit(3);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as path from 'path';
2+
import { existsSync } from 'fs';
3+
4+
export function findUp(name: string, from: string, stopOnNodeModules = false) {
5+
let currentDir = from;
6+
while (currentDir && currentDir !== path.parse(currentDir).root) {
7+
const p = path.join(currentDir, name);
8+
if (existsSync(p)) {
9+
return p;
10+
}
11+
12+
if (stopOnNodeModules) {
13+
const nodeModuleP = path.join(currentDir, 'node_modules');
14+
if (existsSync(nodeModuleP)) {
15+
return null;
16+
}
17+
}
18+
19+
currentDir = path.dirname(currentDir);
20+
}
21+
22+
return null;
23+
}

0 commit comments

Comments
 (0)