refactor(@angular/cli): remove lodash and ember-cli-string-utils usage

This commit is contained in:
Charles Lyding 2018-04-07 21:20:37 -04:00 committed by Hans
parent 40efd9d740
commit bda0dd724b
8 changed files with 27 additions and 354 deletions

46
package-lock.json generated
View File

@ -5,14 +5,14 @@
"requires": true,
"dependencies": {
"@angular-devkit/architect": {
"version": "github:angular/angular-devkit-architect-builds#ff7c4cefe491b39441ac966977b56b2e03955815",
"version": "github:angular/angular-devkit-architect-builds#3ea1cf219eb913308da8a8a96e23abf65f535523",
"requires": {
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#7ce6b00a1a7f0c0b527341b8ca7e431333362c28",
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"rxjs": "6.0.0-smoosh.2"
},
"dependencies": {
"@angular-devkit/core": {
"version": "github:angular/angular-devkit-core-builds#7ce6b00a1a7f0c0b527341b8ca7e431333362c28",
"version": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"requires": {
"ajv": "5.5.2",
"chokidar": "1.7.0",
@ -34,7 +34,7 @@
}
},
"@angular-devkit/core": {
"version": "github:angular/angular-devkit-core-builds#7ce6b00a1a7f0c0b527341b8ca7e431333362c28",
"version": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"requires": {
"ajv": "5.5.2",
"chokidar": "1.7.0",
@ -56,15 +56,15 @@
}
},
"@angular-devkit/schematics": {
"version": "github:angular/angular-devkit-schematics-builds#f47c7096d2d87848a4e8d44836918819709d9cbb",
"version": "github:angular/angular-devkit-schematics-builds#1397f3aeb8d2da1f88989a2413f4d82763ac2fc4",
"requires": {
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#1fe059e91c5f5df097bd78e3c0f26890323ebfd3",
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"@ngtools/json-schema": "1.1.0",
"rxjs": "6.0.0-smoosh.2"
},
"dependencies": {
"@angular-devkit/core": {
"version": "github:angular/angular-devkit-core-builds#1fe059e91c5f5df097bd78e3c0f26890323ebfd3",
"version": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"requires": {
"ajv": "5.5.2",
"chokidar": "1.7.0",
@ -91,15 +91,15 @@
"integrity": "sha1-w6DFRNYjkqzCgTpCyKDcb1j4aSI="
},
"@schematics/angular": {
"version": "github:angular/schematics-angular-builds#343acf0e3fff894c26ea52da289475d24de7249c",
"version": "github:angular/schematics-angular-builds#65313b642dfc9fb8394ac61be0aa997f49abd73f",
"requires": {
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#1fe059e91c5f5df097bd78e3c0f26890323ebfd3",
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds#f47c7096d2d87848a4e8d44836918819709d9cbb",
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds#1397f3aeb8d2da1f88989a2413f4d82763ac2fc4",
"typescript": "2.6.2"
},
"dependencies": {
"@angular-devkit/core": {
"version": "github:angular/angular-devkit-core-builds#1fe059e91c5f5df097bd78e3c0f26890323ebfd3",
"version": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"requires": {
"ajv": "5.5.2",
"chokidar": "1.7.0",
@ -108,9 +108,9 @@
}
},
"@angular-devkit/schematics": {
"version": "github:angular/angular-devkit-schematics-builds#f47c7096d2d87848a4e8d44836918819709d9cbb",
"version": "github:angular/angular-devkit-schematics-builds#1397f3aeb8d2da1f88989a2413f4d82763ac2fc4",
"requires": {
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#1fe059e91c5f5df097bd78e3c0f26890323ebfd3",
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"@ngtools/json-schema": "1.1.0",
"rxjs": "6.0.0-smoosh.2"
}
@ -129,17 +129,17 @@
}
},
"@schematics/update": {
"version": "github:angular/schematics-update-builds#0d2659e95cf9cb8589cf312939580fdb12fd2534",
"version": "github:angular/schematics-update-builds#1b91cc652817f975792a8fc24e8712f91f4604f4",
"requires": {
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#1fe059e91c5f5df097bd78e3c0f26890323ebfd3",
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds#f47c7096d2d87848a4e8d44836918819709d9cbb",
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"@angular-devkit/schematics": "github:angular/angular-devkit-schematics-builds#1397f3aeb8d2da1f88989a2413f4d82763ac2fc4",
"rxjs": "6.0.0-smoosh.2",
"semver": "5.5.0",
"semver-intersect": "1.3.1"
},
"dependencies": {
"@angular-devkit/core": {
"version": "github:angular/angular-devkit-core-builds#1fe059e91c5f5df097bd78e3c0f26890323ebfd3",
"version": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"requires": {
"ajv": "5.5.2",
"chokidar": "1.7.0",
@ -148,9 +148,9 @@
}
},
"@angular-devkit/schematics": {
"version": "github:angular/angular-devkit-schematics-builds#f47c7096d2d87848a4e8d44836918819709d9cbb",
"version": "github:angular/angular-devkit-schematics-builds#1397f3aeb8d2da1f88989a2413f4d82763ac2fc4",
"requires": {
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#1fe059e91c5f5df097bd78e3c0f26890323ebfd3",
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#d35b9ae56969ef21a4d0e8e5b307f25e89cdf3f6",
"@ngtools/json-schema": "1.1.0",
"rxjs": "6.0.0-smoosh.2"
}
@ -1447,11 +1447,6 @@
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=",
"dev": true
},
"ember-cli-string-utils": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/ember-cli-string-utils/-/ember-cli-string-utils-1.1.0.tgz",
"integrity": "sha1-ObZ3/CgF9VFzc1N2/O8njqpEUqE="
},
"encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
@ -3975,7 +3970,8 @@
"lodash": {
"version": "4.17.5",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.5.tgz",
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw=="
"integrity": "sha512-svL3uiZf1RwhH+cWrfZn3A4+U58wbP0tGVTLQPbjplZxZ8ROD9VLuNgsRniTlLe7OlSqR79RUehXgpBW/s0IQw==",
"dev": true
},
"lodash._reinterpolate": {
"version": "3.0.0",

View File

@ -47,9 +47,7 @@
"@schematics/angular": "angular/schematics-angular-builds",
"@schematics/update": "angular/schematics-update-builds",
"chalk": "~2.2.0",
"ember-cli-string-utils": "^1.0.0",
"fs-extra": "^4.0.0",
"lodash": "^4.11.1",
"node-modules-path": "^1.0.0",
"opn": "~5.1.0",
"resolve": "^1.1.7",
@ -79,6 +77,7 @@
"glob": "^7.1.2",
"jasmine": "^2.6.0",
"license-checker": "^15.0.0",
"lodash": "^4.11.1",
"minimist": "^1.2.0",
"mock-fs": "^4.0.0",
"npm-run": "^4.1.0",

View File

@ -8,7 +8,6 @@ const findUp = require('../../../utilities/find-up').findUp;
const { promisify } = require('util');
let resolve = promisify(require('resolve'));
const fs = require('fs-extra');
const _ = require('lodash');
const nodeModulesPath = require('node-modules-path');
let processCwd = process.cwd();
@ -129,7 +128,8 @@ class Project {
return this.addons.reduce((config, addon) => {
if (addon.config) {
_.merge(config, addon.config(env, config));
// No addon support
// _.merge(config, addon.config(env, config));
}
return config;
@ -208,7 +208,7 @@ class Project {
devDependencies = {};
}
return _.assign({}, devDependencies, pkg['dependencies']);
return Object.assign({}, devDependencies, pkg['dependencies']);
}
/**

View File

@ -1,4 +1,4 @@
import { experimental } from '@angular-devkit/core';
import { experimental, strings } from '@angular-devkit/core';
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
import {
Architect, BuilderDescription, BuildEvent,
@ -9,7 +9,6 @@ import { of } from 'rxjs';
import { from } from 'rxjs';
import { concatMap, map, tap, toArray } from 'rxjs/operators';
import { WorkspaceLoader } from '../models/workspace-loader';
const stringUtils = require('ember-cli-string-utils');
export interface GenericTargetTargetSpecifier {
@ -93,7 +92,7 @@ export abstract class ArchitectCommand extends Command {
const properties = schema.properties;
const keys = Object.keys(properties);
keys
.map(key => ({ ...properties[key], ...{ name: stringUtils.dasherize(key) } }))
.map(key => ({ ...properties[key], ...{ name: strings.dasherize(key) } }))
.map(opt => {
let type;
const schematicType = opt.type;

View File

@ -33,9 +33,7 @@
"@schematics/angular": "0.5.4",
"@schematics/update": "0.5.4",
"chalk": "~2.2.0",
"ember-cli-string-utils": "^1.0.0",
"fs-extra": "^4.0.0",
"lodash": "^4.11.1",
"node-modules-path": "^1.0.0",
"opn": "~5.1.0",
"resolve": "^1.1.7",

View File

@ -1,77 +0,0 @@
import * as path from 'path';
import * as process from 'process';
import * as fs from 'fs-extra';
const stringUtils = require('ember-cli-string-utils');
export interface DynamicPathOptions {
project: any;
entityName: string;
appConfig: any;
dryRun: boolean;
}
export function dynamicPathParser(options: DynamicPathOptions) {
const projectRoot = options.project.root;
const sourceDir = options.appConfig.root.replace(/\//g, path.sep);
const p = options.appConfig.appRoot === undefined
? 'app'
: options.appConfig.appRoot.replace(/\//g, path.sep);
const appRoot = path.join(sourceDir, p);
const cwd = process.env.PWD;
const rootPath = path.join(projectRoot, appRoot);
let outputPath = path.join(rootPath, options.entityName);
if (options.entityName.indexOf(path.sep) === 0) {
outputPath = path.join(rootPath, options.entityName.substr(1));
} else if (cwd.indexOf(rootPath) >= 0) {
outputPath = path.join(cwd, options.entityName);
}
if (!fs.existsSync(outputPath)) {
// Verify the path exists on disk.
const parsedOutputPath = path.parse(outputPath);
const parts = parsedOutputPath.dir.split(path.sep).slice(1);
const newPath = parts.reduce((tempPath: string, part: string) => {
// if (tempPath === '') {
// return part;
// }
const withoutPlus = path.join(tempPath, part);
const withPlus = path.join(tempPath, '+' + part);
if (fs.existsSync(withoutPlus)) {
return withoutPlus;
} else if (fs.existsSync(withPlus)) {
return withPlus;
}
// Folder not found, create it, and return it
const dasherizedPart = stringUtils.dasherize(part);
const dasherizedDirName = path.join(tempPath, dasherizedPart);
if (!options.dryRun) {
fs.mkdirpSync(dasherizedDirName);
}
return dasherizedDirName;
}, parsedOutputPath.root);
outputPath = path.join(newPath, parsedOutputPath.name);
}
if (outputPath.indexOf(rootPath) < 0) {
throw `Invalid path: "${options.entityName}" cannot be ` +
`above the "${appRoot}" directory`;
}
const adjustedPath = outputPath.replace(projectRoot, '');
const parsedPath = path.parse(adjustedPath);
if (parsedPath.dir.indexOf(path.sep) === 0) {
parsedPath.dir = parsedPath.dir.substr(1);
}
parsedPath.dir = parsedPath.dir === path.sep ? '' : parsedPath.dir;
return { ...parsedPath, appRoot, sourceDir };
}

View File

@ -1,12 +0,0 @@
const cloneDeep = require('lodash/cloneDeep');
export function overrideOptions(original: any[], overrides: any[]) {
let copy = cloneDeep(original);
overrides.forEach(override => {
const option = copy.find((opt: any) => opt.name == override.name);
if (option) {
Object.assign(option, override);
}
});
return copy;
}

View File

@ -1,230 +0,0 @@
import * as path from 'path';
import { dynamicPathParser } from '@angular/cli/utilities/dynamic-path-parser';
import mockFs = require('mock-fs');
const appDir = `src${path.sep}app`;
const appConfig = {
root: 'src'
};
describe('dynamic path parser', () => {
let project: any;
const entityName = 'temp-name';
const rootName = path.parse(process.cwd()).root + 'project';
const root = 'src';
beforeEach(() => {
project = {
root: rootName,
ngConfig: {
apps: [{
root: root
}]
}
};
const mockFolder: any = {};
mockFolder[rootName] = {
src: {
app: {
'index.html': '<html></html>',
'temp-name': {}
}
}
};
mockFs(mockFolder);
});
afterEach(() => {
mockFs.restore();
});
it('parse from proj root dir', () => {
process.env.PWD = project.root;
const options = {
project,
entityName,
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(appDir);
expect(result.name).toBe(entityName);
});
it('respects the appRoot configuration', () => {
process.env.PWD = project.root;
const options = {
project,
entityName,
appConfig: {...appConfig, appRoot: 'other'},
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(`src${path.sep}other`);
expect(result.name).toBe(entityName);
});
it('respects the empty appRoot configuration', () => {
process.env.PWD = project.root;
const options = {
project,
entityName,
appConfig: <any>{...appConfig, appRoot: ''},
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(`src`);
expect(result.name).toBe(entityName);
});
it('parse from proj src dir', () => {
process.env.PWD = path.join(project.root, 'src');
const options = {
project,
entityName,
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(appDir);
expect(result.name).toBe(entityName);
});
it(`parse from proj src${path.sep}client dir`, () => {
process.env.PWD = path.join(project.root, 'src', 'client');
const options = {
project,
entityName,
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(appDir);
expect(result.name).toBe(entityName);
});
it(`parse from proj src${path.sep}client${path.sep}app dir`, () => {
process.env.PWD = path.join(project.root, 'src', 'client', 'app');
const options = {
project,
entityName,
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(appDir);
expect(result.name).toBe(entityName);
});
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir`, () => {
const mockFolder: any = {};
mockFolder[rootName] = {
src: {
app: {
'index.html': '<html></html>',
'child-dir': {
'temp-name': {}
}
}
}
};
mockFs(mockFolder);
process.env.PWD = path.join(project.root, 'src', 'app', 'child-dir');
const options = {
project,
entityName,
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(`${appDir}${path.sep}child-dir`);
expect(result.name).toBe(entityName);
});
// tslint:disable-next-line:max-line-length
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir w/ ..${path.sep}`, () => {
const mockFolder: any = {};
mockFolder[rootName] = {
src: {
app: {
'index.html': '<html></html>',
'child-dir': {},
'temp-name': {}
}
}
};
mockFs(mockFolder);
process.env.PWD = path.join(project.root, 'src', 'app', 'child-dir');
const options = {
project,
entityName: '..' + path.sep + entityName,
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(appDir);
expect(result.name).toBe(entityName);
});
// tslint:disable-next-line:max-line-length
it(`parse from proj src${path.sep}client${path.sep}app${path.sep}child-dir${path.sep}grand-child-dir w/ ..${path.sep}`,
() => {
const mockFolder: any = {};
mockFolder[rootName] = {
src: {
app: {
'index.html': '<html></html>',
'child-dir': {
'grand-child-dir': {},
'temp-name': {}
}
}
}
};
mockFs(mockFolder);
process.env.PWD = path.join(project.root, 'src', 'app', 'child-dir', 'grand-child-dir');
const options = {
project,
entityName: '..' + path.sep + entityName,
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(`${appDir}${path.sep}child-dir`);
expect(result.name).toBe(entityName);
});
it('auto look for dirs with a "+" when not specified', () => {
const mockFolder: any = {};
mockFolder[rootName] = {
src: {
app: {
'+my-route': {}
}
}
};
mockFs(mockFolder);
process.env.PWD = path.join(project.root, 'src', 'app', 'my-route');
const options = {
project,
entityName,
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(`${appDir}${path.sep}+my-route`);
expect(result.name).toBe(entityName);
});
it('create new dirs as dasherized', () => {
process.env.PWD = project.root;
const options = {
project,
entityName: path.join('NewDir', entityName),
appConfig,
dryRun: false
};
const result = dynamicPathParser(options);
expect(result.dir).toBe(`${appDir}${path.sep}new-dir`);
expect(result.name).toBe(entityName);
});
});