From 119bbabf530b13abb650840a261f2eb4912297bd Mon Sep 17 00:00:00 2001 From: dwieeb Date: Wed, 22 Aug 2018 16:28:44 -0500 Subject: [PATCH 01/18] refactor(network): split out into utils-network package (#3537) --- .../@ionic/cli-framework/src/definitions.ts | 4 -- .../src/utils/__tests__/network.ts | 54 --------------- packages/@ionic/cli-utils/package.json | 1 + packages/@ionic/cli-utils/src/definitions.ts | 3 +- .../src/lib/project/angular/serve.ts | 2 +- .../cli-utils/src/lib/project/common.ts | 4 +- packages/@ionic/cli-utils/src/lib/serve.ts | 4 +- packages/@ionic/utils-network/.gitignore | 2 + packages/@ionic/utils-network/.npmrc | 1 + packages/@ionic/utils-network/CHANGELOG.md | 1 + packages/@ionic/utils-network/LICENSE | 21 ++++++ packages/@ionic/utils-network/README.md | 1 + packages/@ionic/utils-network/package.json | 66 +++++++++++++++++++ .../utils-network/src/__tests__/index.ts | 50 ++++++++++++++ .../network.ts => utils-network/src/index.ts} | 12 ++-- packages/@ionic/utils-network/tsconfig.json | 13 ++++ packages/@ionic/utils-network/tslint.js | 3 + 17 files changed, 170 insertions(+), 72 deletions(-) delete mode 100644 packages/@ionic/cli-framework/src/utils/__tests__/network.ts create mode 100644 packages/@ionic/utils-network/.gitignore create mode 100644 packages/@ionic/utils-network/.npmrc create mode 100644 packages/@ionic/utils-network/CHANGELOG.md create mode 100644 packages/@ionic/utils-network/LICENSE create mode 100644 packages/@ionic/utils-network/README.md create mode 100644 packages/@ionic/utils-network/package.json create mode 100644 packages/@ionic/utils-network/src/__tests__/index.ts rename packages/@ionic/{cli-framework/src/utils/network.ts => utils-network/src/index.ts} (93%) create mode 100644 packages/@ionic/utils-network/tsconfig.json create mode 100644 packages/@ionic/utils-network/tslint.js diff --git a/packages/@ionic/cli-framework/src/definitions.ts b/packages/@ionic/cli-framework/src/definitions.ts index 0127f98005..2084446e9d 100644 --- a/packages/@ionic/cli-framework/src/definitions.ts +++ b/packages/@ionic/cli-framework/src/definitions.ts @@ -1,11 +1,7 @@ -import * as os from 'os'; - import { Opts as ParseArgsOptions, ParsedArgs } from 'minimist'; import * as ζobject from './utils/object'; -export type NetworkInterface = { device: string; } & os.NetworkInterfaceInfo; - export type ParsedArg = string | boolean | null | undefined | string[]; export type Validator = (input?: string, key?: string) => true | string; diff --git a/packages/@ionic/cli-framework/src/utils/__tests__/network.ts b/packages/@ionic/cli-framework/src/utils/__tests__/network.ts deleted file mode 100644 index 0ff5573030..0000000000 --- a/packages/@ionic/cli-framework/src/utils/__tests__/network.ts +++ /dev/null @@ -1,54 +0,0 @@ -import * as osSpy from 'os'; -import { getExternalIPv4Interfaces } from '../network'; - -describe('@ionic/cli-framework', () => { - - describe('utils/network', () => { - - describe('getExternalIPv4Interfaces', () => { - - const networkInterfaces1 = {}; - - const networkInterfaces2 = { - lo: [ - { internal: true, family: 'IPv4' }, - ], - eth0: [ - { internal: false, family: 'IPv6' }, - ], - }; - - const networkInterfaces3 = { - lo: [ - ...networkInterfaces2.lo, - ], - eth0: [ - { internal: false, family: 'IPv4' }, - ...networkInterfaces2.eth0, - ], - }; - - it('should return empty array if no network interfaces', () => { - spyOn(osSpy, 'networkInterfaces').and.callFake(() => networkInterfaces1); - const result = getExternalIPv4Interfaces(); - expect(result).toEqual([]); - }); - - it('should return empty array if unsuitable network interfaces found', () => { - spyOn(osSpy, 'networkInterfaces').and.callFake(() => networkInterfaces2); - const result = getExternalIPv4Interfaces(); - expect(result).toEqual([]); - }); - - it('should find the suitable network interface', () => { - spyOn(osSpy, 'networkInterfaces').and.callFake(() => networkInterfaces3); - const result = getExternalIPv4Interfaces(); - expect(result.length).toEqual(1); - expect(result[0].device).toEqual('eth0'); - }); - - }); - - }); - -}); diff --git a/packages/@ionic/cli-utils/package.json b/packages/@ionic/cli-utils/package.json index 99cd60dd8b..4e9b6dde55 100644 --- a/packages/@ionic/cli-utils/package.json +++ b/packages/@ionic/cli-utils/package.json @@ -67,6 +67,7 @@ "uuid": "^3.2.1" }, "devDependencies": { + "@ionic/utils-network": "0.0.1", "@types/clean-css": "^3.4.30", "@types/debug": "0.0.30", "@types/diff": "^3.2.2", diff --git a/packages/@ionic/cli-utils/src/definitions.ts b/packages/@ionic/cli-utils/src/definitions.ts index 19ab42b0ab..f571183f30 100644 --- a/packages/@ionic/cli-utils/src/definitions.ts +++ b/packages/@ionic/cli-utils/src/definitions.ts @@ -1,5 +1,6 @@ import * as ζframework from '@ionic/cli-framework'; import { ShellCommandOptions } from '@ionic/cli-framework/utils/shell'; +import { NetworkInterface } from '@ionic/utils-network'; import { ChildProcess, SpawnOptions } from 'child_process'; import * as fs from 'fs'; import * as ζsuperagent from 'superagent'; @@ -604,7 +605,7 @@ export interface ServeDetails { localAddress: string; externalAddress: string; port: number; - externalNetworkInterfaces: ζframework.NetworkInterface[]; + externalNetworkInterfaces: NetworkInterface[]; externallyAccessible: boolean; } diff --git a/packages/@ionic/cli-utils/src/lib/project/angular/serve.ts b/packages/@ionic/cli-utils/src/lib/project/angular/serve.ts index cad4cc190e..3b5b61f5a0 100644 --- a/packages/@ionic/cli-utils/src/lib/project/angular/serve.ts +++ b/packages/@ionic/cli-utils/src/lib/project/angular/serve.ts @@ -1,7 +1,7 @@ import chalk from 'chalk'; import { CommandGroup, OptionGroup, ParsedArgs, unparseArgs } from '@ionic/cli-framework'; -import { findClosestOpenPort } from '@ionic/cli-framework/utils/network'; +import { findClosestOpenPort } from '@ionic/utils-network'; import { AngularServeOptions, CommandLineInputs, CommandLineOptions, CommandMetadata, ServeDetails } from '../../../definitions'; import { BIND_ALL_ADDRESS, LOCAL_ADDRESSES, SERVE_SCRIPT, ServeCLI, ServeRunner, ServeRunnerDeps } from '../../serve'; diff --git a/packages/@ionic/cli-utils/src/lib/project/common.ts b/packages/@ionic/cli-utils/src/lib/project/common.ts index 7e8cc62412..bef7b7aaf0 100644 --- a/packages/@ionic/cli-utils/src/lib/project/common.ts +++ b/packages/@ionic/cli-utils/src/lib/project/common.ts @@ -1,4 +1,4 @@ -import { ERROR_NETWORK_ADDRESS_NOT_AVAIL, findClosestOpenPort } from '@ionic/cli-framework/utils/network'; +import { findClosestOpenPort } from '@ionic/utils-network'; import chalk from 'chalk'; import * as Debug from 'debug'; @@ -43,7 +43,7 @@ export async function findOpenIonicPorts(address: string, ports: Ports): Promise return { port, livereloadPort, notificationPort }; } catch (e) { - if (e !== ERROR_NETWORK_ADDRESS_NOT_AVAIL) { + if (e.code !== 'EADDRNOTAVAIL') { throw e; } diff --git a/packages/@ionic/cli-utils/src/lib/serve.ts b/packages/@ionic/cli-utils/src/lib/serve.ts index 49c7828408..b97b040d2b 100644 --- a/packages/@ionic/cli-utils/src/lib/serve.ts +++ b/packages/@ionic/cli-utils/src/lib/serve.ts @@ -1,8 +1,8 @@ -import { BaseError, LOGGER_LEVELS, NetworkInterface, OptionGroup, PromptModule, createPrefixedFormatter } from '@ionic/cli-framework'; +import { BaseError, LOGGER_LEVELS, OptionGroup, PromptModule, createPrefixedFormatter } from '@ionic/cli-framework'; import { fsReadJsonFile } from '@ionic/cli-framework/utils/fs'; -import { findClosestOpenPort, getExternalIPv4Interfaces, isHostConnectable } from '@ionic/cli-framework/utils/network'; import { killProcessTree, onBeforeExit, processExit } from '@ionic/cli-framework/utils/process'; import { str2num } from '@ionic/cli-framework/utils/string'; +import { NetworkInterface, findClosestOpenPort, getExternalIPv4Interfaces, isHostConnectable } from '@ionic/utils-network'; import chalk from 'chalk'; import * as Debug from 'debug'; import { EventEmitter } from 'events'; diff --git a/packages/@ionic/utils-network/.gitignore b/packages/@ionic/utils-network/.gitignore new file mode 100644 index 0000000000..de4d1f007d --- /dev/null +++ b/packages/@ionic/utils-network/.gitignore @@ -0,0 +1,2 @@ +dist +node_modules diff --git a/packages/@ionic/utils-network/.npmrc b/packages/@ionic/utils-network/.npmrc new file mode 100644 index 0000000000..43c97e719a --- /dev/null +++ b/packages/@ionic/utils-network/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/@ionic/utils-network/CHANGELOG.md b/packages/@ionic/utils-network/CHANGELOG.md new file mode 100644 index 0000000000..420e6f23d0 --- /dev/null +++ b/packages/@ionic/utils-network/CHANGELOG.md @@ -0,0 +1 @@ +# Change Log diff --git a/packages/@ionic/utils-network/LICENSE b/packages/@ionic/utils-network/LICENSE new file mode 100644 index 0000000000..7c5808ced6 --- /dev/null +++ b/packages/@ionic/utils-network/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Drifty Co + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/@ionic/utils-network/README.md b/packages/@ionic/utils-network/README.md new file mode 100644 index 0000000000..87b5b758b8 --- /dev/null +++ b/packages/@ionic/utils-network/README.md @@ -0,0 +1 @@ +# @ionic/utils-network diff --git a/packages/@ionic/utils-network/package.json b/packages/@ionic/utils-network/package.json new file mode 100644 index 0000000000..e80f862ae4 --- /dev/null +++ b/packages/@ionic/utils-network/package.json @@ -0,0 +1,66 @@ +{ + "name": "@ionic/utils-network", + "version": "0.0.1", + "description": "Network utils for Node", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "homepage": "https://ionicframework.com/", + "author": "Ionic Team (https://ionic.io)", + "license": "MIT", + "files": [ + "dist/", + "LICENSE", + "README.md" + ], + "repository": { + "type": "git", + "url": "https://github.com/ionic-team/ionic-cli.git" + }, + "bugs": { + "url": "https://github.com/ionic-team/ionic-cli/issues" + }, + "scripts": { + "clean": "rimraf dist", + "lint": "tslint --config tslint.js --project tsconfig.json", + "build": "npm run clean && tsc", + "watch": "tsc -w --preserveWatchOutput", + "test": "jest", + "prepublishOnly": "npm run build", + "precommit": "lint-staged" + }, + "lint-staged": { + "linters": { + "*.{ts,tsx}": "npm run lint" + }, + "ignore": [ + "**/__tests__/*.{ts,tsx}" + ] + }, + "dependencies": { + "debug": "^3.1.0" + }, + "devDependencies": { + "@types/debug": "0.0.30", + "@types/node": "^6.0.101", + "jest": "^23.0.1", + "jest-cli": "^23.0.1", + "lint-staged": "^7.2.0", + "rimraf": "^2.6.2", + "ts-jest": "^23.0.0", + "tslint": "^5.9.1", + "typescript": "~3.0.1" + }, + "jest": { + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json" + ] + } +} diff --git a/packages/@ionic/utils-network/src/__tests__/index.ts b/packages/@ionic/utils-network/src/__tests__/index.ts new file mode 100644 index 0000000000..f08d710b90 --- /dev/null +++ b/packages/@ionic/utils-network/src/__tests__/index.ts @@ -0,0 +1,50 @@ +import * as osSpy from 'os'; +import { getExternalIPv4Interfaces } from '../'; + +describe('@ionic/utils-network', () => { + + describe('getExternalIPv4Interfaces', () => { + + const networkInterfaces1 = {}; + + const networkInterfaces2 = { + lo: [ + { internal: true, family: 'IPv4' }, + ], + eth0: [ + { internal: false, family: 'IPv6' }, + ], + }; + + const networkInterfaces3 = { + lo: [ + ...networkInterfaces2.lo, + ], + eth0: [ + { internal: false, family: 'IPv4' }, + ...networkInterfaces2.eth0, + ], + }; + + it('should return empty array if no network interfaces', () => { + spyOn(osSpy, 'networkInterfaces').and.callFake(() => networkInterfaces1); + const result = getExternalIPv4Interfaces(); + expect(result).toEqual([]); + }); + + it('should return empty array if unsuitable network interfaces found', () => { + spyOn(osSpy, 'networkInterfaces').and.callFake(() => networkInterfaces2); + const result = getExternalIPv4Interfaces(); + expect(result).toEqual([]); + }); + + it('should find the suitable network interface', () => { + spyOn(osSpy, 'networkInterfaces').and.callFake(() => networkInterfaces3); + const result = getExternalIPv4Interfaces(); + expect(result.length).toEqual(1); + expect(result[0].device).toEqual('eth0'); + }); + + }); + +}); diff --git a/packages/@ionic/cli-framework/src/utils/network.ts b/packages/@ionic/utils-network/src/index.ts similarity index 93% rename from packages/@ionic/cli-framework/src/utils/network.ts rename to packages/@ionic/utils-network/src/index.ts index 9a3e61837f..537113200c 100644 --- a/packages/@ionic/cli-framework/src/utils/network.ts +++ b/packages/@ionic/utils-network/src/index.ts @@ -3,14 +3,12 @@ import * as os from 'os'; import * as Debug from 'debug'; -import { NetworkInterface } from '../definitions'; - -const debug = Debug('ionic:cli-framework:utils:network'); - -export const ERROR_NETWORK_ADDRESS_NOT_AVAIL = 'NETWORK_ADDRESS_NOT_AVAIL'; +const debug = Debug('ionic:utils-network'); export const DEFAULT_ADDRESSES: ReadonlyArray = getDefaultAddresses(); +export type NetworkInterface = { device: string; } & os.NetworkInterfaceInfo; + function getDefaultAddresses(): string[] { const addresses: string[] = ['0.0.0.0']; @@ -96,9 +94,7 @@ export function isPortAvailableForHost(host: string, port: number): Promise((resolve, reject) => { const tester = net.createServer() .once('error', (err: any) => { - if (err.code === 'EADDRNOTAVAIL') { - reject(ERROR_NETWORK_ADDRESS_NOT_AVAIL); - } else if (err.code === 'EADDRINUSE') { + if (err.code === 'EADDRINUSE') { resolve(false); // host/port in use } else { reject(err); diff --git a/packages/@ionic/utils-network/tsconfig.json b/packages/@ionic/utils-network/tsconfig.json new file mode 100644 index 0000000000..5dbdd53737 --- /dev/null +++ b/packages/@ionic/utils-network/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./dist" + }, + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "src/**/__tests__/*.ts" + ] +} diff --git a/packages/@ionic/utils-network/tslint.js b/packages/@ionic/utils-network/tslint.js new file mode 100644 index 0000000000..922c453b48 --- /dev/null +++ b/packages/@ionic/utils-network/tslint.js @@ -0,0 +1,3 @@ +module.exports = { + "extends": "../../../tslint.base", +}; From 90fde69cd5ee37fb001ea3c432166d4fb0556950 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Wed, 22 Aug 2018 16:32:39 -0500 Subject: [PATCH 02/18] chore(ci): add utils-network to dependency cache --- .circleci/config.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index e055b1d32a..13f06104c7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,6 +11,7 @@ aliases: - dependency-cache-{{ checksum "packages/@ionic/discover/package.json" }} - dependency-cache-{{ checksum "packages/@ionic/lab/package.json" }} - dependency-cache-{{ checksum "packages/@ionic/schematics-angular/package.json" }} + - dependency-cache-{{ checksum "packages/@ionic/utils-network/package.json" }} - dependency-cache-{{ checksum "packages/@ionic/v1-toolkit/package.json" }} - dependency-cache-{{ checksum "packages/cli-scripts/package.json" }} - dependency-cache-{{ checksum "packages/ionic/package.json" }} @@ -45,6 +46,11 @@ aliases: paths: - packages/@ionic/schematics-angular/node_modules + - &save-cache-utils-network + key: dependency-cache-{{ checksum "packages/@ionic/utils-network/package.json" }} + paths: + - packages/@ionic/utils-network/node_modules + - &save-cache-v1-toolkit key: dependency-cache-{{ checksum "packages/@ionic/v1-toolkit/package.json" }} paths: @@ -92,6 +98,7 @@ jobs: - save_cache: *save-cache-discover - save_cache: *save-cache-lab - save_cache: *save-cache-schematics-angular + - save_cache: *save-cache-utils-network - save_cache: *save-cache-v1-toolkit - save_cache: *save-cache-cli-scripts - save_cache: *save-cache-ionic From 19dd5bc32e8761c19652d583ea22e812aa490e18 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Wed, 22 Aug 2018 16:35:52 -0500 Subject: [PATCH 03/18] chore(package): start with 0.0.0 for utils-network --- packages/@ionic/cli-utils/package.json | 2 +- packages/@ionic/utils-network/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@ionic/cli-utils/package.json b/packages/@ionic/cli-utils/package.json index 4e9b6dde55..b2d5f9aea5 100644 --- a/packages/@ionic/cli-utils/package.json +++ b/packages/@ionic/cli-utils/package.json @@ -48,6 +48,7 @@ "dependencies": { "@ionic/cli-framework": "1.0.6", "@ionic/discover": "1.0.4", + "@ionic/utils-network": "0.0.0", "chalk": "^2.3.0", "debug": "^3.1.0", "diff": "^3.4.0", @@ -67,7 +68,6 @@ "uuid": "^3.2.1" }, "devDependencies": { - "@ionic/utils-network": "0.0.1", "@types/clean-css": "^3.4.30", "@types/debug": "0.0.30", "@types/diff": "^3.2.2", diff --git a/packages/@ionic/utils-network/package.json b/packages/@ionic/utils-network/package.json index e80f862ae4..04e927e2f8 100644 --- a/packages/@ionic/utils-network/package.json +++ b/packages/@ionic/utils-network/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/utils-network", - "version": "0.0.1", + "version": "0.0.0", "description": "Network utils for Node", "main": "dist/index.js", "types": "dist/index.d.ts", From 6dde02028144c9f3117168c9becd90226036bab0 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 13:51:13 -0500 Subject: [PATCH 04/18] chore(deps): switch to elementtree types in DT --- packages/@ionic/cli-utils/package.json | 1 + .../src/lib/integrations/cordova/config.ts | 4 +-- packages/@ionic/cli-utils/tsconfig.json | 1 - packages/ionic/tsconfig.json | 1 - types/elementtree.d.ts | 35 ------------------- 5 files changed, 3 insertions(+), 39 deletions(-) delete mode 100644 types/elementtree.d.ts diff --git a/packages/@ionic/cli-utils/package.json b/packages/@ionic/cli-utils/package.json index b2d5f9aea5..b6f0e8da3c 100644 --- a/packages/@ionic/cli-utils/package.json +++ b/packages/@ionic/cli-utils/package.json @@ -71,6 +71,7 @@ "@types/clean-css": "^3.4.30", "@types/debug": "0.0.30", "@types/diff": "^3.2.2", + "@types/elementtree": "^0.1.0", "@types/lodash": "^4.14.104", "@types/node": "^6.0.101", "@types/opn": "^5.1.0", diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts index a5ecba3e11..1bc40d990e 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts @@ -186,7 +186,7 @@ export class ConfigXml { nameElement.text = 'MyApp'; } - const name = nameElement.text; + const name = nameElement.text.toString(); return { id, name, version }; } @@ -283,7 +283,7 @@ export class ConfigXml { return contents; } - protected engineElementToPlatformEngine(engine: et.IElement): PlatformEngine { + protected engineElementToPlatformEngine(engine: et.Element): PlatformEngine { const name = engine.get('name'); const spec = engine.get('spec'); diff --git a/packages/@ionic/cli-utils/tsconfig.json b/packages/@ionic/cli-utils/tsconfig.json index 8e03cdab33..b809fa6110 100644 --- a/packages/@ionic/cli-utils/tsconfig.json +++ b/packages/@ionic/cli-utils/tsconfig.json @@ -4,7 +4,6 @@ "outDir": "./" }, "include": [ - "../../../types/elementtree.d.ts", "../../../types/leek.d.ts", "../../../types/slice-ansi.d.ts", "../../../types/ssh-config.d.ts", diff --git a/packages/ionic/tsconfig.json b/packages/ionic/tsconfig.json index 227fa7be81..fcaf416eac 100644 --- a/packages/ionic/tsconfig.json +++ b/packages/ionic/tsconfig.json @@ -4,7 +4,6 @@ "outDir": "./dist" }, "include": [ - "../../types/elementtree.d.ts", "../../types/slice-ansi.d.ts", "../../types/ssh-config.d.ts", "../../types/superagent.d.ts", diff --git a/types/elementtree.d.ts b/types/elementtree.d.ts deleted file mode 100644 index 353bd3d7e9..0000000000 --- a/types/elementtree.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -declare module 'elementtree' { - namespace et { - class ElementTree { - getroot(): IElement; - find(p: string): IElement | null; - findall(p: string): IElement[]; - write(opts?: { indent?: number }): string; - } - - interface IElement { - tag: string; - attrib: { [key: string]: string }; - text: null | string; - tail: null | string; - - find(p: string): IElement | null; - findall(p: string): IElement[]; - getchildren(): IElement[]; - append(e: IElement): void; - remove(e: IElement): void; - extend(e: IElement[]): void; - clear(): void; - get(k: string): string | undefined; - set(k: string, v?: string): string; - keys(): string[]; - items(): [string, string][]; - } - - function Element(tag: string, attrib: { [key: string]: string }): IElement; - function SubElement(parent: IElement, tag: string, attrib: { [key: string]: string }): IElement; - function parse(data: string): ElementTree; - } - - export = et; -} From 3cd537c7e3ddc1d4cf9f64905a447d478e226feb Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 14:01:05 -0500 Subject: [PATCH 05/18] chore(deps): upgrade devkit to 0.8.0-rc --- packages/@ionic/ng-toolkit/package.json | 18 +++++++++--------- .../@ionic/schematics-angular/package.json | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/@ionic/ng-toolkit/package.json b/packages/@ionic/ng-toolkit/package.json index 22d4885a34..dfcfa4a97d 100644 --- a/packages/@ionic/ng-toolkit/package.json +++ b/packages/@ionic/ng-toolkit/package.json @@ -45,14 +45,14 @@ "@ionic/cli-framework": "1.0.6", "chalk": "^2.3.0", "debug": "^3.1.0", - "rxjs": "^6.2.0", + "rxjs": "~6.2.0", "tslib": "^1.9.0" }, "devDependencies": { - "@angular-devkit/architect": "~0.7.2", - "@angular-devkit/build-angular": "~0.7.2", - "@angular-devkit/core": "~0.7.2", - "@angular-devkit/schematics": "~0.7.2", + "@angular-devkit/architect": "~0.8.0-rc.1", + "@angular-devkit/build-angular": "~0.8.0-rc.1", + "@angular-devkit/core": "~0.8.0-rc.1", + "@angular-devkit/schematics": "~0.8.0-rc.1", "@types/debug": "0.0.30", "@types/node": "^6.0.101", "lint-staged": "^7.2.0", @@ -61,9 +61,9 @@ "typescript": "~3.0.1" }, "peerDependencies": { - "@angular-devkit/architect": "~0.7.2", - "@angular-devkit/build-angular": "~0.7.2", - "@angular-devkit/core": "~0.7.2", - "@angular-devkit/schematics": "~0.7.2" + "@angular-devkit/architect": "~0.8.0-rc.1", + "@angular-devkit/build-angular": "~0.8.0-rc.1", + "@angular-devkit/core": "~0.8.0-rc.1", + "@angular-devkit/schematics": "~0.8.0-rc.1" } } diff --git a/packages/@ionic/schematics-angular/package.json b/packages/@ionic/schematics-angular/package.json index 0bb35b96dc..d86f3bac67 100644 --- a/packages/@ionic/schematics-angular/package.json +++ b/packages/@ionic/schematics-angular/package.json @@ -30,14 +30,14 @@ ], "schematics": "./collection.json", "dependencies": { - "@schematics/angular": "~0.7.2", + "@schematics/angular": "~0.8.0-rc.1", "lodash": "^4.17.5", "tslib": "^1.9.0", "typescript": ">=2.6.2 <2.10" }, "devDependencies": { - "@angular-devkit/core": "~0.7.2", - "@angular-devkit/schematics": "~0.7.2", + "@angular-devkit/core": "~0.8.0-rc.1", + "@angular-devkit/schematics": "~0.8.0-rc.1", "@types/lodash": "^4.14.104", "@types/node": "^6.0.101", "jest": "^23.0.1", @@ -49,7 +49,7 @@ "tslint": "^5.9.1" }, "peerDependencies": { - "@angular-devkit/core": "~0.7.2", - "@angular-devkit/schematics": "~0.7.2" + "@angular-devkit/core": "~0.8.0-rc.1", + "@angular-devkit/schematics": "~0.8.0-rc.1" } } From 694710cc897babfa4f68feb19b32a675b16f614f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 4 Sep 2018 14:17:32 -0500 Subject: [PATCH 06/18] build(deps): update wrap-ansi requirement from ^3.0.1 to ^4.0.0 in /packages/@ionic/cli-framework (#3556) Updates the requirements on [wrap-ansi](https://github.com/chalk/wrap-ansi) to permit the latest version. - [Release notes](https://github.com/chalk/wrap-ansi/releases) - [Commits](https://github.com/chalk/wrap-ansi/commits/v4.0.0) Signed-off-by: dependabot[bot] --- packages/@ionic/cli-framework/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ionic/cli-framework/package.json b/packages/@ionic/cli-framework/package.json index 6e98c7e80f..f280d28e6f 100644 --- a/packages/@ionic/cli-framework/package.json +++ b/packages/@ionic/cli-framework/package.json @@ -59,7 +59,7 @@ "tree-kill": "1.2.0", "tslib": "^1.9.0", "untildify": "^3.0.2", - "wrap-ansi": "^3.0.1", + "wrap-ansi": "^4.0.0", "write-file-atomic": "^2.3.0" }, "devDependencies": { From ad554f5840c9abfd5c2b984f1d0b8ec07ad70065 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 4 Sep 2018 15:28:11 -0500 Subject: [PATCH 07/18] build(deps-dev): update concurrently requirement from ^3.5.1 to ^4.0.1 in /packages/@ionic/lab (#3543) Updates the requirements on [concurrently](https://github.com/kimmobrunfeldt/concurrently) to permit the latest version. - [Release notes](https://github.com/kimmobrunfeldt/concurrently/releases) - [Commits](https://github.com/kimmobrunfeldt/concurrently/commits/v4.0.1) Signed-off-by: dependabot[bot] --- packages/@ionic/lab/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ionic/lab/package.json b/packages/@ionic/lab/package.json index ee1c2a48e0..544d748e6b 100644 --- a/packages/@ionic/lab/package.json +++ b/packages/@ionic/lab/package.json @@ -57,7 +57,7 @@ "@stencil/dev-server": "0.0.18", "@types/express": "^4.11.0", "@types/node": "^6.0.101", - "concurrently": "^3.5.1", + "concurrently": "^4.0.1", "jest": "^23.0.1", "jest-cli": "^23.0.1", "lint-staged": "^7.2.0", From d039835fd4ed9c0dcd8a24859ad2c0dafb212833 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 4 Sep 2018 15:42:50 -0500 Subject: [PATCH 08/18] build(deps): update http-proxy-middleware requirement from ^0.18.0 to ^0.19.0 in /packages/@ionic/v1-toolkit (#3551) Updates the requirements on [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware) to permit the latest version. - [Release notes](https://github.com/chimurai/http-proxy-middleware/releases) - [Changelog](https://github.com/chimurai/http-proxy-middleware/blob/master/CHANGELOG.md) - [Commits](https://github.com/chimurai/http-proxy-middleware/commits/v0.19.0) Signed-off-by: dependabot[bot] --- packages/@ionic/v1-toolkit/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ionic/v1-toolkit/package.json b/packages/@ionic/v1-toolkit/package.json index 621585a462..84bcf8f6b8 100644 --- a/packages/@ionic/v1-toolkit/package.json +++ b/packages/@ionic/v1-toolkit/package.json @@ -48,7 +48,7 @@ "debug": "^3.1.0", "express": "^4.16.2", "gulp": "^3.9.1", - "http-proxy-middleware": "^0.18.0", + "http-proxy-middleware": "^0.19.0", "tiny-lr": "^1.1.0", "tslib": "^1.9.0", "ws": "^6.0.0" From b02d57ddb342730a1639f3f95feaa0a862c5ee76 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Tue, 4 Sep 2018 16:08:23 -0500 Subject: [PATCH 09/18] build(deps-dev): update @stencil/core requirement from ^0.11.0 to ^0.12.4 in /packages/@ionic/lab (#3554) Updates the requirements on [@stencil/core](https://github.com/ionic-team/stencil) to permit the latest version. - [Release notes](https://github.com/ionic-team/stencil/releases) - [Changelog](https://github.com/ionic-team/stencil/blob/master/CHANGELOG.md) - [Commits](https://github.com/ionic-team/stencil/commits/v0.12.4) Signed-off-by: dependabot[bot] --- packages/@ionic/lab/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@ionic/lab/package.json b/packages/@ionic/lab/package.json index 544d748e6b..f1a282a7a0 100644 --- a/packages/@ionic/lab/package.json +++ b/packages/@ionic/lab/package.json @@ -53,7 +53,7 @@ "tslib": "^1.9.0" }, "devDependencies": { - "@stencil/core": "^0.11.0", + "@stencil/core": "^0.12.4", "@stencil/dev-server": "0.0.18", "@types/express": "^4.11.0", "@types/node": "^6.0.101", From 14837f76e54eea00c41ee5a50219ffaf155788cb Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 15:24:40 -0500 Subject: [PATCH 10/18] refactor(fs): split out into utils-fs package --- packages/@ionic/cli-framework/package.json | 11 +-- .../cli-framework/src/lib/__tests__/config.ts | 4 +- .../@ionic/cli-framework/src/lib/config.ts | 3 +- .../cli-framework/src/utils/__tests__/path.ts | 61 -------------- .../@ionic/cli-framework/src/utils/node.ts | 4 +- .../@ionic/cli-framework/src/utils/path.ts | 44 ---------- packages/@ionic/cli-utils/package.json | 1 + packages/@ionic/cli-utils/src/index.ts | 2 +- .../cli-utils/src/lib/__tests__/ssh-config.ts | 2 +- .../src/lib/doctor/ailments/index.ts | 2 +- packages/@ionic/cli-utils/src/lib/git.ts | 2 +- packages/@ionic/cli-utils/src/lib/helper.ts | 2 +- .../integrations/cordova/__tests__/android.ts | 2 +- .../integrations/cordova/__tests__/project.ts | 2 +- .../cordova/__tests__/resources.ts | 2 +- .../src/lib/integrations/cordova/android.ts | 2 +- .../src/lib/integrations/cordova/config.ts | 2 +- .../src/lib/integrations/cordova/project.ts | 2 +- .../src/lib/integrations/cordova/resources.ts | 3 +- .../cli-utils/src/lib/integrations/index.ts | 2 +- .../@ionic/cli-utils/src/lib/project/index.ts | 4 +- .../cli-utils/src/lib/project/ionic1/index.ts | 4 +- packages/@ionic/cli-utils/src/lib/serve.ts | 2 +- .../@ionic/cli-utils/src/lib/ssh-config.ts | 2 +- packages/@ionic/cli-utils/src/lib/ssh.ts | 12 +-- packages/@ionic/cli-utils/src/lib/start.ts | 6 +- .../@ionic/cli-utils/src/lib/utils/http.ts | 2 +- packages/@ionic/lab/package.json | 1 + packages/@ionic/lab/src/index.ts | 20 +---- packages/@ionic/utils-fs/.gitignore | 2 + packages/@ionic/utils-fs/.npmrc | 1 + packages/@ionic/utils-fs/CHANGELOG.md | 1 + packages/@ionic/utils-fs/LICENSE | 21 +++++ packages/@ionic/utils-fs/README.md | 1 + packages/@ionic/utils-fs/package.json | 75 +++++++++++++++++ .../fs.ts => utils-fs/src/__tests__/index.ts} | 56 ++++++++++++- .../src/utils/fs.ts => utils-fs/src/index.ts} | 81 +++++++++++++++---- packages/@ionic/utils-fs/tsconfig.json | 13 +++ packages/@ionic/utils-fs/tslint.js | 3 + packages/@ionic/utils-network/package.json | 3 +- packages/@ionic/v1-toolkit/package.json | 1 + .../src/lib/__tests__/dev-server.ts | 2 +- .../@ionic/v1-toolkit/src/lib/dev-server.ts | 8 +- packages/@ionic/v1-toolkit/src/lib/serve.ts | 6 +- packages/cli-scripts/package.json | 1 + packages/cli-scripts/src/docs/index.ts | 2 +- packages/ionic/package.json | 1 + packages/ionic/src/commands/capacitor/base.ts | 2 +- packages/ionic/src/commands/cordova/base.ts | 2 +- .../ionic/src/commands/cordova/resources.ts | 2 +- .../ionic/src/commands/deploy/manifest.ts | 2 +- .../ionic/src/commands/monitoring/syncmaps.ts | 2 +- packages/ionic/src/commands/ssh/add.ts | 5 +- packages/ionic/src/commands/ssh/generate.ts | 3 +- packages/ionic/src/commands/ssh/setup.ts | 3 +- packages/ionic/src/commands/ssh/use.ts | 3 +- packages/ionic/src/commands/ssl/generate.ts | 3 +- packages/ionic/src/commands/start.ts | 2 +- 58 files changed, 295 insertions(+), 220 deletions(-) delete mode 100644 packages/@ionic/cli-framework/src/utils/__tests__/path.ts delete mode 100644 packages/@ionic/cli-framework/src/utils/path.ts create mode 100644 packages/@ionic/utils-fs/.gitignore create mode 100644 packages/@ionic/utils-fs/.npmrc create mode 100644 packages/@ionic/utils-fs/CHANGELOG.md create mode 100644 packages/@ionic/utils-fs/LICENSE create mode 100644 packages/@ionic/utils-fs/README.md create mode 100644 packages/@ionic/utils-fs/package.json rename packages/@ionic/{cli-framework/src/utils/__tests__/fs.ts => utils-fs/src/__tests__/index.ts} (71%) rename packages/@ionic/{cli-framework/src/utils/fs.ts => utils-fs/src/index.ts} (73%) create mode 100644 packages/@ionic/utils-fs/tsconfig.json create mode 100644 packages/@ionic/utils-fs/tslint.js diff --git a/packages/@ionic/cli-framework/package.json b/packages/@ionic/cli-framework/package.json index f280d28e6f..f353241cfd 100644 --- a/packages/@ionic/cli-framework/package.json +++ b/packages/@ionic/cli-framework/package.json @@ -28,29 +28,23 @@ }, "license": "MIT", "dependencies": { + "@ionic/utils-fs": "0.0.0", "@types/cross-spawn": "^6.0.0", "@types/debug": "0.0.30", "@types/inquirer": "0.0.43", - "@types/klaw": "^2.1.1", "@types/lodash": "^4.14.104", - "@types/make-dir": "^1.0.3", "@types/minimist": "^1.2.0", - "@types/ncp": "^2.0.1", "@types/node": "^6.0.101", "@types/rimraf": "^2.0.2", "@types/string-width": "^2.0.0", "@types/strip-ansi": "^3.0.0", "@types/untildify": "^3.0.0", "@types/wrap-ansi": "^3.0.0", - "@types/write-file-atomic": "^2.1.1", "chalk": "^2.3.0", "debug": "^3.1.0", "inquirer": "^6.0.0", - "klaw": "^3.0.0", "lodash": "^4.17.5", - "make-dir": "^1.3.0", "minimist": "^1.2.0", - "ncp": "^2.0.0", "rimraf": "^2.6.2", "slice-ansi": "^1.0.0", "stream-combiner2": "^1.1.1", @@ -59,8 +53,7 @@ "tree-kill": "1.2.0", "tslib": "^1.9.0", "untildify": "^3.0.2", - "wrap-ansi": "^4.0.0", - "write-file-atomic": "^2.3.0" + "wrap-ansi": "^4.0.0" }, "devDependencies": { "jest": "^23.0.1", diff --git a/packages/@ionic/cli-framework/src/lib/__tests__/config.ts b/packages/@ionic/cli-framework/src/lib/__tests__/config.ts index b9c52493b7..4528beb14c 100644 --- a/packages/@ionic/cli-framework/src/lib/__tests__/config.ts +++ b/packages/@ionic/cli-framework/src/lib/__tests__/config.ts @@ -10,7 +10,7 @@ describe('@ionic/cli-framework', () => { mockWriteFileAtomicSync = jest.fn(); jest.resetModules(); jest.mock('fs', () => ({ readFileSync: mockReadFileSync })); - jest.mock('../../utils/fs', () => ({ makeDir: { sync: mockMakeDirSync }, writeFileAtomicSync: mockWriteFileAtomicSync })); + jest.mock('@ionic/utils-fs', () => ({ makeDir: { sync: mockMakeDirSync }, writeFileAtomicSync: mockWriteFileAtomicSync })); const { BaseConfig } = require('../config'); @@ -164,7 +164,7 @@ describe('@ionic/cli-framework', () => { mockWriteFileAtomicSync = jest.fn(); jest.resetModules(); jest.mock('fs', () => ({ readFileSync: mockReadFileSync })); - jest.mock('../../utils/fs', () => ({ makeDir: { sync: mockMakeDirSync }, writeFileAtomicSync: mockWriteFileAtomicSync })); + jest.mock('@ionic/utils-fs', () => ({ makeDir: { sync: mockMakeDirSync }, writeFileAtomicSync: mockWriteFileAtomicSync })); const { BaseConfig } = require('../config'); diff --git a/packages/@ionic/cli-framework/src/lib/config.ts b/packages/@ionic/cli-framework/src/lib/config.ts index 3743f82a67..fa75659a83 100644 --- a/packages/@ionic/cli-framework/src/lib/config.ts +++ b/packages/@ionic/cli-framework/src/lib/config.ts @@ -1,9 +1,8 @@ +import { makeDir, writeFileAtomicSync } from '@ionic/utils-fs'; import * as fs from 'fs'; import * as lodash from 'lodash'; import * as path from 'path'; -import { makeDir, writeFileAtomicSync } from '../utils/fs'; - export interface BaseConfigOptions { /** * If specified, the class will operate on a nested object within the config diff --git a/packages/@ionic/cli-framework/src/utils/__tests__/path.ts b/packages/@ionic/cli-framework/src/utils/__tests__/path.ts deleted file mode 100644 index 4b88804850..0000000000 --- a/packages/@ionic/cli-framework/src/utils/__tests__/path.ts +++ /dev/null @@ -1,61 +0,0 @@ -import * as path from 'path'; - -describe('@ionic/cli-framework', () => { - - describe('utils/path', () => { - - describe('compilePaths', () => { - - describe('posix', () => { - - const mock_path_posix = path.posix; - jest.resetModules(); - jest.mock('path', () => mock_path_posix); - - const pathlib = require('../path'); - - it('should not accept a malformed path', () => { - expect(() => pathlib.compilePaths('.')).toThrowError('. is not an absolute path'); - }); - - it('should compile an array of paths working backwards from a base directory', () => { - const result = pathlib.compilePaths('/some/dir'); - expect(result).toEqual(['/some/dir', '/some', '/']); - }); - - it('should work for the root directory', () => { - const result = pathlib.compilePaths('/'); - expect(result).toEqual(['/']); - }); - - }); - - describe('windows', () => { - - const mock_path_win32 = path.win32; - jest.resetModules(); - jest.mock('path', () => mock_path_win32); - - const pathlib = require('../path'); - - it('should not accept a malformed path', () => { - expect(() => pathlib.compilePaths('.')).toThrowError('. is not an absolute path'); - }); - - it('should compile an array of paths working backwards from a base directory', () => { - const result = pathlib.compilePaths('C:\\some\\dir'); - expect(result).toEqual(['C:\\some\\dir', 'C:\\some', 'C:\\']); - }); - - it('should work for the root directory', () => { - const result = pathlib.compilePaths('C:\\'); - expect(result).toEqual(['C:\\']); - }); - - }); - - }); - - }); - -}); diff --git a/packages/@ionic/cli-framework/src/utils/node.ts b/packages/@ionic/cli-framework/src/utils/node.ts index aeefc297b5..091e1cd510 100644 --- a/packages/@ionic/cli-framework/src/utils/node.ts +++ b/packages/@ionic/cli-framework/src/utils/node.ts @@ -1,12 +1,10 @@ +import { compilePaths, fsReadJsonFile } from '@ionic/utils-fs'; import * as fs from 'fs'; import * as path from 'path'; import { PackageJson } from '../definitions'; import { isPackageJson } from '../guards'; -import { fsReadJsonFile } from './fs'; -import { compilePaths } from './path'; - export const ERROR_INVALID_PACKAGE_JSON = 'INVALID_PACKAGE_JSON'; export const ERROR_BIN_NOT_FOUND = 'BIN_NOT_FOUND'; diff --git a/packages/@ionic/cli-framework/src/utils/path.ts b/packages/@ionic/cli-framework/src/utils/path.ts deleted file mode 100644 index 2988ad329f..0000000000 --- a/packages/@ionic/cli-framework/src/utils/path.ts +++ /dev/null @@ -1,44 +0,0 @@ -import * as os from 'os'; -import * as path from 'path'; - -export const tmpdir = os.tmpdir(); - -/** - * Generate a random file path within the computer's temporary directory. - * - * @param prefix Optionally provide a filename prefix. - */ -export function tmpfilepath(prefix?: string): string { - const rn = Math.random().toString(16).substring(2, 8); - const p = path.resolve(tmpdir, prefix ? `${prefix}-${rn}` : rn); - - return p; -} - -/** - * Given an absolute system path, compile an array of paths working backwards - * one directory at a time, always ending in the root directory. - * - * For example, `'/some/dir'` => `['/some/dir', '/some', '/']` - * - * @param filePath Absolute system base path. - */ -export function compilePaths(filePath: string): string[] { - filePath = path.normalize(filePath); - - if (!path.isAbsolute(filePath)) { - throw new Error(`${filePath} is not an absolute path`); - } - - const parsed = path.parse(filePath); - - if (filePath === parsed.root) { - return [filePath]; - } - - return filePath - .slice(parsed.root.length) - .split(path.sep) - .map((segment, i, array) => parsed.root + path.join(...array.slice(0, array.length - i))) - .concat(parsed.root); -} diff --git a/packages/@ionic/cli-utils/package.json b/packages/@ionic/cli-utils/package.json index b6f0e8da3c..a5ed1502f6 100644 --- a/packages/@ionic/cli-utils/package.json +++ b/packages/@ionic/cli-utils/package.json @@ -48,6 +48,7 @@ "dependencies": { "@ionic/cli-framework": "1.0.6", "@ionic/discover": "1.0.4", + "@ionic/utils-fs": "0.0.0", "@ionic/utils-network": "0.0.0", "chalk": "^2.3.0", "debug": "^3.1.0", diff --git a/packages/@ionic/cli-utils/src/index.ts b/packages/@ionic/cli-utils/src/index.ts index b0495e82f9..fefcd6259a 100644 --- a/packages/@ionic/cli-utils/src/index.ts +++ b/packages/@ionic/cli-utils/src/index.ts @@ -1,7 +1,7 @@ import { LOGGER_LEVELS, createPromptModule } from '@ionic/cli-framework'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { findBaseDirectory, fsReadJsonFile } from '@ionic/cli-framework/utils/fs'; import { TERMINAL_INFO } from '@ionic/cli-framework/utils/terminal'; +import { findBaseDirectory, fsReadJsonFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as path from 'path'; diff --git a/packages/@ionic/cli-utils/src/lib/__tests__/ssh-config.ts b/packages/@ionic/cli-utils/src/lib/__tests__/ssh-config.ts index 421e8f20ed..0bfc9e5862 100644 --- a/packages/@ionic/cli-utils/src/lib/__tests__/ssh-config.ts +++ b/packages/@ionic/cli-utils/src/lib/__tests__/ssh-config.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import * as SSHConfig from 'ssh-config'; -import { fsReadFile } from '@ionic/cli-framework/utils/fs'; +import { fsReadFile } from '@ionic/utils-fs'; import { ensureHostAndKeyPath } from '../ssh-config'; diff --git a/packages/@ionic/cli-utils/src/lib/doctor/ailments/index.ts b/packages/@ionic/cli-utils/src/lib/doctor/ailments/index.ts index 42ed08745c..32d6be5c9d 100644 --- a/packages/@ionic/cli-utils/src/lib/doctor/ailments/index.ts +++ b/packages/@ionic/cli-utils/src/lib/doctor/ailments/index.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import chalk from 'chalk'; -import { fsReadFile } from '@ionic/cli-framework/utils/fs'; +import { fsReadFile } from '@ionic/utils-fs'; import { TreatableAilment } from '../../../definitions'; import { AppClient } from '../../app'; diff --git a/packages/@ionic/cli-utils/src/lib/git.ts b/packages/@ionic/cli-utils/src/lib/git.ts index e2257c3995..dfb54d9bd3 100644 --- a/packages/@ionic/cli-utils/src/lib/git.ts +++ b/packages/@ionic/cli-utils/src/lib/git.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import { pathExists } from '@ionic/cli-framework/utils/fs'; +import { pathExists } from '@ionic/utils-fs'; import { IShell } from '../definitions'; diff --git a/packages/@ionic/cli-utils/src/lib/helper.ts b/packages/@ionic/cli-utils/src/lib/helper.ts index e844405ade..f27825b789 100644 --- a/packages/@ionic/cli-utils/src/lib/helper.ts +++ b/packages/@ionic/cli-utils/src/lib/helper.ts @@ -1,7 +1,7 @@ import * as path from 'path'; -import { fsMkdirp, fsOpen } from '@ionic/cli-framework/utils/fs'; import { fork } from '@ionic/cli-framework/utils/shell'; +import { fsMkdirp, fsOpen } from '@ionic/utils-fs'; import { IConfig, IPCMessage, IonicContext } from '../definitions'; diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/android.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/android.ts index f69f68839d..8660150d2d 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/android.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/android.ts @@ -11,7 +11,7 @@ describe('@ionic/cli-utils', () => { }); it('should return undefined for a missing source.properties file', async () => { - jest.mock('@ionic/cli-framework/utils/fs', () => ({ + jest.mock('@ionic/utils-fs', () => ({ fsReadFile: () => { const err = new Error(); err.code = 'ENOENT'; diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/project.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/project.ts index 1cfa982f74..c24c4eb2b1 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/project.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/project.ts @@ -1,4 +1,4 @@ -import * as fsSpy from '@ionic/cli-framework/utils/fs'; +import * as fsSpy from '@ionic/utils-fs'; import * as project from '../project'; describe('@ionic/cli-utils', () => { diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/resources.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/resources.ts index a053c9db8b..226d209062 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/resources.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/resources.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import * as fsSpy from '@ionic/cli-framework/utils/fs'; +import * as fsSpy from '@ionic/utils-fs'; import * as httpSpy from '../../../utils/http'; import * as resources from '../resources'; diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/android.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/android.ts index d469c58d77..66fe603c60 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/android.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/android.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import { fsReadFile } from '@ionic/cli-framework/utils/fs'; +import { fsReadFile } from '@ionic/utils-fs'; export async function getAndroidSdkToolsVersion(): Promise { const androidHome = await locateSDKHome(); diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts index 1bc40d990e..eeb08f3f64 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsReadFile, fsWriteFile } from '@ionic/cli-framework/utils/fs'; +import { fsReadFile, fsWriteFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as et from 'elementtree'; diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/project.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/project.ts index 3203fcaa32..8503051eb9 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/project.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/project.ts @@ -1,6 +1,6 @@ import * as path from 'path'; -import { readDir } from '@ionic/cli-framework/utils/fs'; +import { readDir } from '@ionic/utils-fs'; export async function getPlatforms(projectDir: string): Promise { const platformsDir = path.resolve(projectDir, 'platforms'); diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts index af6de1c9fc..7bd88b932a 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts @@ -1,7 +1,6 @@ import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsMkdirp, getFileChecksums, readDir } from '@ionic/cli-framework/utils/fs'; -import { tmpfilepath } from '@ionic/cli-framework/utils/path'; import { WritableStreamBuffer } from '@ionic/cli-framework/utils/streams'; +import { fsMkdirp, getFileChecksums, readDir, tmpfilepath } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as fs from 'fs'; diff --git a/packages/@ionic/cli-utils/src/lib/integrations/index.ts b/packages/@ionic/cli-utils/src/lib/integrations/index.ts index d0410c9fb0..c92a1fc23c 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/index.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/index.ts @@ -5,7 +5,7 @@ import chalk from 'chalk'; import * as Debug from 'debug'; import * as lodash from 'lodash'; -import { copyDirectory, fsMkdirp, fsStat, pathExists, readDir, removeDirectory } from '@ionic/cli-framework/utils/fs'; +import { copyDirectory, fsMkdirp, fsStat, pathExists, readDir, removeDirectory } from '@ionic/utils-fs'; import { IConfig, IIntegration, IIntegrationAddOptions, ILogger, IProject, IShell, InfoItem, IntegrationName, ProjectPersonalizationDetails } from '../../definitions'; import { IntegrationNotFoundException } from '../errors'; diff --git a/packages/@ionic/cli-utils/src/lib/project/index.ts b/packages/@ionic/cli-utils/src/lib/project/index.ts index 50b66abf9c..682b57f3e3 100644 --- a/packages/@ionic/cli-utils/src/lib/project/index.ts +++ b/packages/@ionic/cli-utils/src/lib/project/index.ts @@ -1,7 +1,7 @@ import { BaseConfig, BaseConfigOptions, PromptModule } from '@ionic/cli-framework'; import { TTY_WIDTH, prettyPath, wordWrap } from '@ionic/cli-framework/utils/format'; -import { ERROR_FILE_INVALID_JSON, fsWriteJsonFile } from '@ionic/cli-framework/utils/fs'; import { ERROR_INVALID_PACKAGE_JSON, compileNodeModulesPaths, readPackageJsonFile, resolve } from '@ionic/cli-framework/utils/node'; +import { fsWriteJsonFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as lodash from 'lodash'; @@ -240,7 +240,7 @@ export abstract class Project implements IProject { const pkgPath = pkgName ? resolve(`${pkgName}/package`, { paths: compileNodeModulesPaths(this.directory) }) : this.packageJsonPath; return await readPackageJsonFile(pkgPath); } catch (e) { - if (e === ERROR_FILE_INVALID_JSON) { + if (e instanceof SyntaxError) { throw new FatalException(`Could not parse ${chalk.bold(pkgName ? pkgName : `project's`)} ${chalk.bold('package.json')}. Is it a valid JSON file?`); } else if (e === ERROR_INVALID_PACKAGE_JSON) { throw new FatalException(`The ${chalk.bold(pkgName ? pkgName : `project's`)} ${chalk.bold('package.json')} file seems malformed.`); diff --git a/packages/@ionic/cli-utils/src/lib/project/ionic1/index.ts b/packages/@ionic/cli-utils/src/lib/project/ionic1/index.ts index 725fb12175..9fe9cb903d 100644 --- a/packages/@ionic/cli-utils/src/lib/project/ionic1/index.ts +++ b/packages/@ionic/cli-utils/src/lib/project/ionic1/index.ts @@ -1,5 +1,5 @@ import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { ERROR_FILE_INVALID_JSON, fsReadJsonFile } from '@ionic/cli-framework/utils/fs'; +import { fsReadJsonFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as lodash from 'lodash'; @@ -112,7 +112,7 @@ export class Ionic1Project extends Project { try { this.bowerJsonFile = await readBowerJsonFile(bowerJsonPath); } catch (e) { - if (e === ERROR_FILE_INVALID_JSON) { + if (e instanceof SyntaxError) { throw new FatalException(`Could not parse ${chalk.bold('bower.json')}. Is it a valid JSON file?`); } else if (e === ERROR_INVALID_BOWER_JSON) { throw new FatalException(`The ${chalk.bold('bower.json')} file seems malformed.`); diff --git a/packages/@ionic/cli-utils/src/lib/serve.ts b/packages/@ionic/cli-utils/src/lib/serve.ts index b97b040d2b..e75af0c0e3 100644 --- a/packages/@ionic/cli-utils/src/lib/serve.ts +++ b/packages/@ionic/cli-utils/src/lib/serve.ts @@ -1,7 +1,7 @@ import { BaseError, LOGGER_LEVELS, OptionGroup, PromptModule, createPrefixedFormatter } from '@ionic/cli-framework'; -import { fsReadJsonFile } from '@ionic/cli-framework/utils/fs'; import { killProcessTree, onBeforeExit, processExit } from '@ionic/cli-framework/utils/process'; import { str2num } from '@ionic/cli-framework/utils/string'; +import { fsReadJsonFile } from '@ionic/utils-fs'; import { NetworkInterface, findClosestOpenPort, getExternalIPv4Interfaces, isHostConnectable } from '@ionic/utils-network'; import chalk from 'chalk'; import * as Debug from 'debug'; diff --git a/packages/@ionic/cli-utils/src/lib/ssh-config.ts b/packages/@ionic/cli-utils/src/lib/ssh-config.ts index c8ce98295e..19a6d85603 100644 --- a/packages/@ionic/cli-utils/src/lib/ssh-config.ts +++ b/packages/@ionic/cli-utils/src/lib/ssh-config.ts @@ -1,7 +1,7 @@ import * as os from 'os'; import * as path from 'path'; -import { fileToString } from '@ionic/cli-framework/utils/fs'; +import { fileToString } from '@ionic/utils-fs'; import * as SSHConfig from 'ssh-config'; export { SSHConfig }; diff --git a/packages/@ionic/cli-utils/src/lib/ssh.ts b/packages/@ionic/cli-utils/src/lib/ssh.ts index bb79fd3408..419145bf34 100644 --- a/packages/@ionic/cli-utils/src/lib/ssh.ts +++ b/packages/@ionic/cli-utils/src/lib/ssh.ts @@ -1,4 +1,4 @@ -import { ERROR_FILE_NOT_FOUND, fsReadFile, fsStat } from '@ionic/cli-framework/utils/fs'; +import { fsReadFile, fsStat } from '@ionic/utils-fs'; import * as os from 'os'; import * as path from 'path'; @@ -16,16 +16,6 @@ export async function getGeneratedPrivateKeyPath(userId = 0): Promise { } export async function parsePublicKeyFile(pubkeyPath: string): Promise<[string, string, string, string]> { - try { - await fsStat(pubkeyPath); - } catch (e) { - if (e.code === 'ENOENT') { - throw ERROR_FILE_NOT_FOUND; - } - - throw e; - } - return parsePublicKey((await fsReadFile(pubkeyPath, { encoding: 'utf8' })).trim()); } diff --git a/packages/@ionic/cli-utils/src/lib/start.ts b/packages/@ionic/cli-utils/src/lib/start.ts index 5f4cd4dc55..48351f58a4 100644 --- a/packages/@ionic/cli-utils/src/lib/start.ts +++ b/packages/@ionic/cli-utils/src/lib/start.ts @@ -1,4 +1,4 @@ -import { ERROR_FILE_INVALID_JSON, ERROR_FILE_NOT_FOUND, fsReadJsonFile } from '@ionic/cli-framework/utils/fs'; +import { fsReadJsonFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import { IConfig, StarterList, StarterManifest, StarterTemplate } from '../definitions'; @@ -19,9 +19,9 @@ export async function readStarterManifest(p: string): Promise { return manifest; } catch (e) { - if (e === ERROR_FILE_NOT_FOUND) { + if (e.code === 'ENOENT') { throw new Error(`${p} not found`); - } else if (e === ERROR_FILE_INVALID_JSON) { + } else if (e instanceof SyntaxError) { throw new Error(`${p} is not valid JSON.`); } diff --git a/packages/@ionic/cli-utils/src/lib/utils/http.ts b/packages/@ionic/cli-utils/src/lib/utils/http.ts index 733f173e52..3186e98e05 100644 --- a/packages/@ionic/cli-utils/src/lib/utils/http.ts +++ b/packages/@ionic/cli-utils/src/lib/utils/http.ts @@ -3,7 +3,7 @@ import * as Debug from 'debug'; import * as ζsuperagent from 'superagent'; import { conform } from '@ionic/cli-framework/utils/array'; -import { fsReadFile } from '@ionic/cli-framework/utils/fs'; +import { fsReadFile } from '@ionic/utils-fs'; import { CreateRequestOptions, HttpMethod } from '../../definitions'; diff --git a/packages/@ionic/lab/package.json b/packages/@ionic/lab/package.json index f1a282a7a0..5ef411e104 100644 --- a/packages/@ionic/lab/package.json +++ b/packages/@ionic/lab/package.json @@ -48,6 +48,7 @@ }, "dependencies": { "@ionic/cli-framework": "1.0.6", + "@ionic/utils-fs": "0.0.0", "chalk": "^2.3.0", "express": "^4.16.2", "tslib": "^1.9.0" diff --git a/packages/@ionic/lab/src/index.ts b/packages/@ionic/lab/src/index.ts index ba605e2865..f5cb2ea631 100644 --- a/packages/@ionic/lab/src/index.ts +++ b/packages/@ionic/lab/src/index.ts @@ -1,24 +1,12 @@ +import { Command, CommandLineInputs, CommandLineOptions, CommandMap, CommandMapDefault, Namespace, execute, validators } from '@ionic/cli-framework'; +import { fsReadFile } from '@ionic/utils-fs'; +import chalk from 'chalk'; +import * as express from 'express'; import * as http from 'http'; import * as https from 'https'; import * as path from 'path'; import * as tls from 'tls'; -import chalk from 'chalk'; -import * as express from 'express'; - -import { - Command, - CommandLineInputs, - CommandLineOptions, - CommandMap, - CommandMapDefault, - Namespace, - execute, - validators, -} from '@ionic/cli-framework'; - -import { fsReadFile } from '@ionic/cli-framework/utils/fs'; - const WWW_DIRECTORY = path.join(__dirname, '..', 'www'); class DefaultCommand extends Command { diff --git a/packages/@ionic/utils-fs/.gitignore b/packages/@ionic/utils-fs/.gitignore new file mode 100644 index 0000000000..de4d1f007d --- /dev/null +++ b/packages/@ionic/utils-fs/.gitignore @@ -0,0 +1,2 @@ +dist +node_modules diff --git a/packages/@ionic/utils-fs/.npmrc b/packages/@ionic/utils-fs/.npmrc new file mode 100644 index 0000000000..43c97e719a --- /dev/null +++ b/packages/@ionic/utils-fs/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/@ionic/utils-fs/CHANGELOG.md b/packages/@ionic/utils-fs/CHANGELOG.md new file mode 100644 index 0000000000..420e6f23d0 --- /dev/null +++ b/packages/@ionic/utils-fs/CHANGELOG.md @@ -0,0 +1 @@ +# Change Log diff --git a/packages/@ionic/utils-fs/LICENSE b/packages/@ionic/utils-fs/LICENSE new file mode 100644 index 0000000000..7c5808ced6 --- /dev/null +++ b/packages/@ionic/utils-fs/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Drifty Co + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/@ionic/utils-fs/README.md b/packages/@ionic/utils-fs/README.md new file mode 100644 index 0000000000..8370453ed0 --- /dev/null +++ b/packages/@ionic/utils-fs/README.md @@ -0,0 +1 @@ +# @ionic/utils-fs diff --git a/packages/@ionic/utils-fs/package.json b/packages/@ionic/utils-fs/package.json new file mode 100644 index 0000000000..59d21e6455 --- /dev/null +++ b/packages/@ionic/utils-fs/package.json @@ -0,0 +1,75 @@ +{ + "name": "@ionic/utils-fs", + "version": "0.0.0", + "description": "Filesystem utils for Node", + "main": "dist/index.js", + "types": "dist/index.d.ts", + "homepage": "https://ionicframework.com/", + "author": "Ionic Team (https://ionic.io)", + "license": "MIT", + "files": [ + "dist/", + "LICENSE", + "README.md" + ], + "repository": { + "type": "git", + "url": "https://github.com/ionic-team/ionic-cli.git" + }, + "bugs": { + "url": "https://github.com/ionic-team/ionic-cli/issues" + }, + "scripts": { + "clean": "rimraf dist", + "lint": "tslint --config tslint.js --project tsconfig.json", + "build": "npm run clean && tsc", + "watch": "tsc -w --preserveWatchOutput", + "test": "jest", + "prepublishOnly": "npm run build", + "precommit": "lint-staged" + }, + "lint-staged": { + "linters": { + "*.{ts,tsx}": "npm run lint" + }, + "ignore": [ + "**/__tests__/*.{ts,tsx}" + ] + }, + "dependencies": { + "debug": "^3.1.0", + "klaw": "^3.0.0", + "make-dir": "^1.3.0", + "ncp": "^2.0.0", + "tslib": "^1.9.0", + "write-file-atomic": "^2.3.0" + }, + "devDependencies": { + "@types/debug": "0.0.30", + "@types/klaw": "^2.1.1", + "@types/make-dir": "^1.0.3", + "@types/ncp": "^2.0.1", + "@types/node": "^6.0.101", + "@types/write-file-atomic": "^2.1.1", + "jest": "^23.0.1", + "jest-cli": "^23.0.1", + "lint-staged": "^7.2.0", + "rimraf": "^2.6.2", + "ts-jest": "^23.0.0", + "tslint": "^5.9.1", + "typescript": "~3.0.1" + }, + "jest": { + "transform": { + "^.+\\.tsx?$": "ts-jest" + }, + "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json" + ] + } +} diff --git a/packages/@ionic/cli-framework/src/utils/__tests__/fs.ts b/packages/@ionic/utils-fs/src/__tests__/index.ts similarity index 71% rename from packages/@ionic/cli-framework/src/utils/__tests__/fs.ts rename to packages/@ionic/utils-fs/src/__tests__/index.ts index e5415f81f6..d0db194ee6 100644 --- a/packages/@ionic/cli-framework/src/utils/__tests__/fs.ts +++ b/packages/@ionic/utils-fs/src/__tests__/index.ts @@ -12,7 +12,7 @@ describe('@ionic/cli-framework', () => { jest.resetModules(); jest.mock('path', () => mock_path_posix); - const fslib = require('../fs'); + const fslib = require('../'); it('should get undefined with empty input', async () => { const result = await fslib.findBaseDirectory('', ''); @@ -59,7 +59,7 @@ describe('@ionic/cli-framework', () => { jest.resetModules(); jest.mock('path', () => mock_path_win32); - const fslib = require('../fs'); + const fslib = require('../'); it('should get undefined with empty input', async () => { const result = await fslib.findBaseDirectory('', ''); @@ -102,6 +102,58 @@ describe('@ionic/cli-framework', () => { }); + describe('compilePaths', () => { + + describe('posix', () => { + + const mock_path_posix = path.posix; + jest.resetModules(); + jest.mock('path', () => mock_path_posix); + + const fslib = require('../'); + + it('should not accept a malformed path', () => { + expect(() => fslib.compilePaths('.')).toThrowError('. is not an absolute path'); + }); + + it('should compile an array of paths working backwards from a base directory', () => { + const result = fslib.compilePaths('/some/dir'); + expect(result).toEqual(['/some/dir', '/some', '/']); + }); + + it('should work for the root directory', () => { + const result = fslib.compilePaths('/'); + expect(result).toEqual(['/']); + }); + + }); + + describe('windows', () => { + + const mock_path_win32 = path.win32; + jest.resetModules(); + jest.mock('path', () => mock_path_win32); + + const fslib = require('../'); + + it('should not accept a malformed path', () => { + expect(() => fslib.compilePaths('.')).toThrowError('. is not an absolute path'); + }); + + it('should compile an array of paths working backwards from a base directory', () => { + const result = fslib.compilePaths('C:\\some\\dir'); + expect(result).toEqual(['C:\\some\\dir', 'C:\\some', 'C:\\']); + }); + + it('should work for the root directory', () => { + const result = fslib.compilePaths('C:\\'); + expect(result).toEqual(['C:\\']); + }); + + }); + + }); + }); }); diff --git a/packages/@ionic/cli-framework/src/utils/fs.ts b/packages/@ionic/utils-fs/src/index.ts similarity index 73% rename from packages/@ionic/cli-framework/src/utils/fs.ts rename to packages/@ionic/utils-fs/src/index.ts index 24e772f452..118adc8cfc 100644 --- a/packages/@ionic/cli-framework/src/utils/fs.ts +++ b/packages/@ionic/utils-fs/src/index.ts @@ -1,16 +1,33 @@ import * as fs from 'fs'; +import * as os from 'os'; import * as path from 'path'; import * as makeDir from 'make-dir'; import * as ζncp from 'ncp'; import * as wfa from 'write-file-atomic'; -import { compilePaths } from './path'; -import { promisify } from './promise'; +interface Promisify { + (func: (callback: (err: any, result?: T) => void) => void): () => Promise; + (func: (arg1: A1, callback: (err: any, result?: T) => void) => void): (arg1: A1) => Promise; + (func: (arg1: A1, arg2: A2, callback: (err: any, result?: T) => void) => void): (arg1: A1, arg2: A2) => Promise; + (func: (arg1: A1, arg2: A2, arg3: A3, callback: (err: any, result?: T) => void) => void): (arg1: A1, arg2: A2, arg3: A3) => Promise; + (func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, callback: (err: any, result?: T) => void) => void): (arg1: A1, arg2: A2, arg3: A3, arg4: A4) => Promise; + (func: (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5, callback: (err: any, result?: T) => void) => void): (arg1: A1, arg2: A2, arg3: A3, arg4: A4, arg5: A5) => Promise; +} + +const promisify: Promisify = (func: any) => { + return (...args: any[]) => { + return new Promise((resolve, reject) => { + func(...args, (err: any, response: any) => { + if (err) { + return reject(err); + } -export const ERROR_FILE_NOT_FOUND = 'FILE_NOT_FOUND'; -export const ERROR_FILE_INVALID_JSON = 'FILE_INVALID_JSON'; -export const ERROR_OVERWRITE_DENIED = 'OVERWRITE_DENIED'; + resolve(response); + }); + }); + }; +}; export interface FSReadFileOptions { encoding: string; @@ -72,18 +89,8 @@ export async function readDir(dir: string, options?: { recursive?: boolean; }): } export async function fsReadJsonFile(filePath: string, options: FSReadFileOptions = { encoding: 'utf8' }): Promise<{ [key: string]: any }> { - try { - const f = await fsReadFile(filePath, options); - return JSON.parse(f); - } catch (e) { - if (e.code === 'ENOENT') { - throw ERROR_FILE_NOT_FOUND; - } else if (e instanceof SyntaxError) { - throw ERROR_FILE_INVALID_JSON; - } - - throw e; - } + const f = await fsReadFile(filePath, options); + return JSON.parse(f); } export async function fsWriteJsonFile(filePath: string, json: { [key: string]: any; }, options: FSWriteFileOptions): Promise { @@ -250,3 +257,43 @@ export async function findBaseDirectory(dir: string, file: string): Promise `['/some/dir', '/some', '/']` + * + * @param filePath Absolute system base path. + */ +export function compilePaths(filePath: string): string[] { + filePath = path.normalize(filePath); + + if (!path.isAbsolute(filePath)) { + throw new Error(`${filePath} is not an absolute path`); + } + + const parsed = path.parse(filePath); + + if (filePath === parsed.root) { + return [filePath]; + } + + return filePath + .slice(parsed.root.length) + .split(path.sep) + .map((segment, i, array) => parsed.root + path.join(...array.slice(0, array.length - i))) + .concat(parsed.root); +} diff --git a/packages/@ionic/utils-fs/tsconfig.json b/packages/@ionic/utils-fs/tsconfig.json new file mode 100644 index 0000000000..5dbdd53737 --- /dev/null +++ b/packages/@ionic/utils-fs/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "./dist" + }, + "include": [ + "src/**/*.ts" + ], + "exclude": [ + "node_modules", + "src/**/__tests__/*.ts" + ] +} diff --git a/packages/@ionic/utils-fs/tslint.js b/packages/@ionic/utils-fs/tslint.js new file mode 100644 index 0000000000..922c453b48 --- /dev/null +++ b/packages/@ionic/utils-fs/tslint.js @@ -0,0 +1,3 @@ +module.exports = { + "extends": "../../../tslint.base", +}; diff --git a/packages/@ionic/utils-network/package.json b/packages/@ionic/utils-network/package.json index 04e927e2f8..e402e6b341 100644 --- a/packages/@ionic/utils-network/package.json +++ b/packages/@ionic/utils-network/package.json @@ -37,7 +37,8 @@ ] }, "dependencies": { - "debug": "^3.1.0" + "debug": "^3.1.0", + "tslib": "^1.9.0" }, "devDependencies": { "@types/debug": "0.0.30", diff --git a/packages/@ionic/v1-toolkit/package.json b/packages/@ionic/v1-toolkit/package.json index 84bcf8f6b8..8918066065 100644 --- a/packages/@ionic/v1-toolkit/package.json +++ b/packages/@ionic/v1-toolkit/package.json @@ -43,6 +43,7 @@ }, "dependencies": { "@ionic/cli-framework": "1.0.6", + "@ionic/utils-fs": "0.0.0", "chalk": "^2.3.0", "chokidar": "^2.0.0", "debug": "^3.1.0", diff --git a/packages/@ionic/v1-toolkit/src/lib/__tests__/dev-server.ts b/packages/@ionic/v1-toolkit/src/lib/__tests__/dev-server.ts index 52ef38b313..09aeb4873d 100644 --- a/packages/@ionic/v1-toolkit/src/lib/__tests__/dev-server.ts +++ b/packages/@ionic/v1-toolkit/src/lib/__tests__/dev-server.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import { injectScript } from '../dev-server'; -import { fsReadFile } from '@ionic/cli-framework/utils/fs'; +import { fsReadFile } from '@ionic/utils-fs'; describe('@ionic/ionic-v1', () => { diff --git a/packages/@ionic/v1-toolkit/src/lib/dev-server.ts b/packages/@ionic/v1-toolkit/src/lib/dev-server.ts index 0300a674eb..d8266e6d8d 100644 --- a/packages/@ionic/v1-toolkit/src/lib/dev-server.ts +++ b/packages/@ionic/v1-toolkit/src/lib/dev-server.ts @@ -1,12 +1,10 @@ +import { fsReadFile } from '@ionic/utils-fs'; +import chalk, { Chalk } from 'chalk'; +import * as ζexpress from 'express'; import * as path from 'path'; import * as util from 'util'; - -import { fsReadFile } from '@ionic/cli-framework/utils/fs'; -import * as ζexpress from 'express'; import * as ζws from 'ws'; -import chalk, { Chalk } from 'chalk'; - export const DEV_SERVER_PREFIX = '__ionic'; export interface DevServerMessage { diff --git a/packages/@ionic/v1-toolkit/src/lib/serve.ts b/packages/@ionic/v1-toolkit/src/lib/serve.ts index f7093ec724..e8a904fbc2 100644 --- a/packages/@ionic/v1-toolkit/src/lib/serve.ts +++ b/packages/@ionic/v1-toolkit/src/lib/serve.ts @@ -1,10 +1,8 @@ -import * as path from 'path'; - -import { fsReadFile, pathExists } from '@ionic/cli-framework/utils/fs'; +import { fsReadFile, pathExists } from '@ionic/utils-fs'; import chalk from 'chalk'; - import * as ζexpress from 'express'; import * as ζproxyMiddleware from 'http-proxy-middleware'; +import * as path from 'path'; import { ConfigFileProxy } from './config'; import { DEV_SERVER_PREFIX, LiveReloadFunction, createDevLoggerServer, createDevServerHandler, createLiveReloadServer, injectDevServerScript, injectLiveReloadScript } from './dev-server'; diff --git a/packages/cli-scripts/package.json b/packages/cli-scripts/package.json index 2378c64e8f..e6ae9367f2 100644 --- a/packages/cli-scripts/package.json +++ b/packages/cli-scripts/package.json @@ -27,6 +27,7 @@ "dependencies": { "@ionic/cli-framework": "1.0.6", "@ionic/cli-utils": "2.2.0", + "@ionic/utils-fs": "0.0.0", "ansi-styles": "^3.2.0", "chalk": "^2.3.0", "escape-string-regexp": "^1.0.5", diff --git a/packages/cli-scripts/src/docs/index.ts b/packages/cli-scripts/src/docs/index.ts index fab51b9be0..f4a802e0d2 100644 --- a/packages/cli-scripts/src/docs/index.ts +++ b/packages/cli-scripts/src/docs/index.ts @@ -4,8 +4,8 @@ import chalk from 'chalk'; import stripAnsi = require('strip-ansi'); import { Command, CommandHelpSchemaInput, CommandHelpSchemaOption, CommandLineInputs, CommandLineOptions, CommandMetadata } from '@ionic/cli-framework'; -import { fsMkdirp, fsWriteFile, removeDirectory } from '@ionic/cli-framework/utils/fs'; import { strcmp } from '@ionic/cli-framework/utils/string'; +import { fsMkdirp, fsWriteFile, removeDirectory } from '@ionic/utils-fs'; import { ProjectType } from '@ionic/cli-utils'; import { CommandHelpSchema, NamespaceSchemaHelpFormatter } from '@ionic/cli-utils/lib/help'; diff --git a/packages/ionic/package.json b/packages/ionic/package.json index 7f8b31e432..aa29fb6c05 100644 --- a/packages/ionic/package.json +++ b/packages/ionic/package.json @@ -55,6 +55,7 @@ "dependencies": { "@ionic/cli-framework": "1.0.6", "@ionic/cli-utils": "2.2.0", + "@ionic/utils-fs": "0.0.0", "chalk": "^2.3.0", "debug": "^3.1.0", "lodash": "^4.17.5", diff --git a/packages/ionic/src/commands/capacitor/base.ts b/packages/ionic/src/commands/capacitor/base.ts index 5d40eda8ed..0672dc5eb5 100644 --- a/packages/ionic/src/commands/capacitor/base.ts +++ b/packages/ionic/src/commands/capacitor/base.ts @@ -2,11 +2,11 @@ import chalk from 'chalk'; import * as path from 'path'; import { ERROR_SHELL_COMMAND_NOT_FOUND, ShellCommandError } from '@ionic/cli-framework'; -import { pathExists } from '@ionic/cli-framework/utils/fs'; import { CommandInstanceInfo } from '@ionic/cli-utils'; import { Command } from '@ionic/cli-utils/lib/command'; import { FatalException } from '@ionic/cli-utils/lib/errors'; import { runCommand } from '@ionic/cli-utils/lib/executor'; +import { pathExists } from '@ionic/utils-fs'; export abstract class CapacitorCommand extends Command { async checkCapacitor(runinfo: CommandInstanceInfo) { diff --git a/packages/ionic/src/commands/cordova/base.ts b/packages/ionic/src/commands/cordova/base.ts index 48f2ec9f3b..6c59928513 100644 --- a/packages/ionic/src/commands/cordova/base.ts +++ b/packages/ionic/src/commands/cordova/base.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { ERROR_SHELL_COMMAND_NOT_FOUND, OptionGroup, ShellCommandError } from '@ionic/cli-framework'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsMkdir, pathExists } from '@ionic/cli-framework/utils/fs'; +import { fsMkdir, pathExists } from '@ionic/utils-fs'; import { CommandInstanceInfo, CommandMetadataOption, IShellRunOptions } from '@ionic/cli-utils'; import { Command } from '@ionic/cli-utils/lib/command'; diff --git a/packages/ionic/src/commands/cordova/resources.ts b/packages/ionic/src/commands/cordova/resources.ts index 12c8e836dd..947b6cfdf1 100644 --- a/packages/ionic/src/commands/cordova/resources.ts +++ b/packages/ionic/src/commands/cordova/resources.ts @@ -2,9 +2,9 @@ import chalk from 'chalk'; import * as Debug from 'debug'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { cacheFileChecksum, copyFile, pathExists } from '@ionic/cli-framework/utils/fs'; import { CommandInstanceInfo, CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun, KnownPlatform, ResourcesConfig, ResourcesImageConfig, SourceImage } from '@ionic/cli-utils'; import { FatalException } from '@ionic/cli-utils/lib/errors'; +import { cacheFileChecksum, copyFile, pathExists } from '@ionic/utils-fs'; import { CordovaCommand } from './base'; diff --git a/packages/ionic/src/commands/deploy/manifest.ts b/packages/ionic/src/commands/deploy/manifest.ts index 6a32e4e1bf..72c09b63ce 100644 --- a/packages/ionic/src/commands/deploy/manifest.ts +++ b/packages/ionic/src/commands/deploy/manifest.ts @@ -4,10 +4,10 @@ import * as fs from 'fs'; import * as path from 'path'; import { map } from '@ionic/cli-framework/utils/array'; -import { fsStat, fsWriteFile, readDir } from '@ionic/cli-framework/utils/fs'; import { CommandMetadata } from '@ionic/cli-utils'; import { Command } from '@ionic/cli-utils/lib/command'; import { FatalException } from '@ionic/cli-utils/lib/errors'; +import { fsStat, fsWriteFile, readDir } from '@ionic/utils-fs'; interface DeployManifestItem { href: string; diff --git a/packages/ionic/src/commands/monitoring/syncmaps.ts b/packages/ionic/src/commands/monitoring/syncmaps.ts index 5515023011..f41b8a94eb 100644 --- a/packages/ionic/src/commands/monitoring/syncmaps.ts +++ b/packages/ionic/src/commands/monitoring/syncmaps.ts @@ -4,11 +4,11 @@ import chalk from 'chalk'; import * as Debug from 'debug'; import { columnar, prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsReadFile, pathExists, readDir } from '@ionic/cli-framework/utils/fs'; import { APIResponseSuccess, CommandLineInputs, CommandLineOptions, CommandMetadata, isSuperAgentError } from '@ionic/cli-utils'; import { build } from '@ionic/cli-utils/lib/build'; import { Command } from '@ionic/cli-utils/lib/command'; import { FatalException } from '@ionic/cli-utils/lib/errors'; +import { fsReadFile, pathExists, readDir } from '@ionic/utils-fs'; const debug = Debug('ionic:cli:commands:monitoring:syncmaps'); diff --git a/packages/ionic/src/commands/ssh/add.ts b/packages/ionic/src/commands/ssh/add.ts index 49f1b1d202..e7b737afdf 100644 --- a/packages/ionic/src/commands/ssh/add.ts +++ b/packages/ionic/src/commands/ssh/add.ts @@ -6,11 +6,10 @@ import chalk from 'chalk'; import { validators } from '@ionic/cli-framework'; import { expandPath, prettyPath } from '@ionic/cli-framework/utils/format'; -import { ERROR_FILE_NOT_FOUND, pathAccessible, pathExists } from '@ionic/cli-framework/utils/fs'; - import { CommandInstanceInfo, CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun, isSuperAgentError } from '@ionic/cli-utils'; import { FatalException } from '@ionic/cli-utils/lib/errors'; import { runCommand } from '@ionic/cli-utils/lib/executor'; +import { pathAccessible, pathExists } from '@ionic/utils-fs'; import { SSHBaseCommand } from './base'; @@ -64,7 +63,7 @@ export class SSHAddCommand extends SSHBaseCommand implements CommandPreRun { try { [ pubkey ] = await parsePublicKeyFile(pubkeyPath); } catch (e) { - if (e === ERROR_FILE_NOT_FOUND) { + if (e.code === 'ENOENT') { throw new FatalException( `${chalk.bold(prettyPath(pubkeyPath))} does not appear to exist. Please specify a valid SSH public key.\n` + `If you are having issues, try using ${chalk.green('ionic ssh setup')}.` diff --git a/packages/ionic/src/commands/ssh/generate.ts b/packages/ionic/src/commands/ssh/generate.ts index 977d2afcf2..2311c01a71 100644 --- a/packages/ionic/src/commands/ssh/generate.ts +++ b/packages/ionic/src/commands/ssh/generate.ts @@ -4,9 +4,8 @@ import chalk from 'chalk'; import { OptionGroup, contains, validate } from '@ionic/cli-framework'; import { expandPath, prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsMkdirp, fsUnlink, pathExists } from '@ionic/cli-framework/utils/fs'; - import { CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun } from '@ionic/cli-utils'; +import { fsMkdirp, fsUnlink, pathExists } from '@ionic/utils-fs'; import { SSHBaseCommand } from './base'; diff --git a/packages/ionic/src/commands/ssh/setup.ts b/packages/ionic/src/commands/ssh/setup.ts index 02e8648b5b..2dfa8ce1db 100644 --- a/packages/ionic/src/commands/ssh/setup.ts +++ b/packages/ionic/src/commands/ssh/setup.ts @@ -1,11 +1,10 @@ import chalk from 'chalk'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { pathExists } from '@ionic/cli-framework/utils/fs'; - import { CommandInstanceInfo, CommandLineInputs, CommandLineOptions, CommandMetadata } from '@ionic/cli-utils'; import { FatalException } from '@ionic/cli-utils/lib/errors'; import { runCommand } from '@ionic/cli-utils/lib/executor'; +import { pathExists } from '@ionic/utils-fs'; import { SSHBaseCommand } from './base'; diff --git a/packages/ionic/src/commands/ssh/use.ts b/packages/ionic/src/commands/ssh/use.ts index 4a8a314825..0f668351b3 100644 --- a/packages/ionic/src/commands/ssh/use.ts +++ b/packages/ionic/src/commands/ssh/use.ts @@ -2,10 +2,9 @@ import chalk from 'chalk'; import { validators } from '@ionic/cli-framework'; import { expandPath, prettyPath } from '@ionic/cli-framework/utils/format'; -import { fileToString, fsWriteFile } from '@ionic/cli-framework/utils/fs'; - import { CommandLineInputs, CommandLineOptions, CommandMetadata } from '@ionic/cli-utils'; import { FatalException } from '@ionic/cli-utils/lib/errors'; +import { fileToString, fsWriteFile } from '@ionic/utils-fs'; import { SSHBaseCommand } from './base'; diff --git a/packages/ionic/src/commands/ssl/generate.ts b/packages/ionic/src/commands/ssl/generate.ts index a72887eb16..6f0febc0c6 100644 --- a/packages/ionic/src/commands/ssl/generate.ts +++ b/packages/ionic/src/commands/ssl/generate.ts @@ -5,8 +5,7 @@ import * as lodash from 'lodash'; import { CommandGroup, OptionGroup } from '@ionic/cli-framework'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsMkdirp, fsUnlink, fsWriteFile, pathExists } from '@ionic/cli-framework/utils/fs'; -import { tmpfilepath } from '@ionic/cli-framework/utils/path'; +import { fsMkdirp, fsUnlink, fsWriteFile, pathExists, tmpfilepath } from '@ionic/utils-fs'; import { CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun } from '@ionic/cli-utils'; import { FatalException } from '@ionic/cli-utils/lib/errors'; diff --git a/packages/ionic/src/commands/start.ts b/packages/ionic/src/commands/start.ts index d12e6a0613..0f6cccad8a 100644 --- a/packages/ionic/src/commands/start.ts +++ b/packages/ionic/src/commands/start.ts @@ -6,9 +6,9 @@ import * as lodash from 'lodash'; import { OptionGroup, validators } from '@ionic/cli-framework'; import { columnar, prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsMkdir, fsUnlink, pathExists, removeDirectory } from '@ionic/cli-framework/utils/fs'; import { isValidPackageName } from '@ionic/cli-framework/utils/node'; import { isValidURL, slugify } from '@ionic/cli-framework/utils/string'; +import { fsMkdir, fsUnlink, pathExists, removeDirectory } from '@ionic/utils-fs'; import { CommandInstanceInfo, CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun, ResolvedStarterTemplate, StarterManifest, StarterTemplate, getProject } from '@ionic/cli-utils'; import { Command } from '@ionic/cli-utils/lib/command'; From 32d2fe358752a7060282a0e9b17a6c1c2884c8c6 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 15:26:41 -0500 Subject: [PATCH 11/18] chore(ci): add utils-fs to dependency cache --- .circleci/config.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 13f06104c7..85a7a01376 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,6 +11,7 @@ aliases: - dependency-cache-{{ checksum "packages/@ionic/discover/package.json" }} - dependency-cache-{{ checksum "packages/@ionic/lab/package.json" }} - dependency-cache-{{ checksum "packages/@ionic/schematics-angular/package.json" }} + - dependency-cache-{{ checksum "packages/@ionic/utils-fs/package.json" }} - dependency-cache-{{ checksum "packages/@ionic/utils-network/package.json" }} - dependency-cache-{{ checksum "packages/@ionic/v1-toolkit/package.json" }} - dependency-cache-{{ checksum "packages/cli-scripts/package.json" }} @@ -46,6 +47,11 @@ aliases: paths: - packages/@ionic/schematics-angular/node_modules + - &save-cache-utils-fs + key: dependency-cache-{{ checksum "packages/@ionic/utils-fs/package.json" }} + paths: + - packages/@ionic/utils-fs/node_modules + - &save-cache-utils-network key: dependency-cache-{{ checksum "packages/@ionic/utils-network/package.json" }} paths: @@ -98,6 +104,7 @@ jobs: - save_cache: *save-cache-discover - save_cache: *save-cache-lab - save_cache: *save-cache-schematics-angular + - save_cache: *save-cache-utils-fs - save_cache: *save-cache-utils-network - save_cache: *save-cache-v1-toolkit - save_cache: *save-cache-cli-scripts From 2c2c9b6edabd3bb4b9aa9c9d1eab2e4a3f67feb4 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 16:12:10 -0500 Subject: [PATCH 12/18] chore(deps): move type defs back to devDeps --- packages/@ionic/cli-framework/package.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/@ionic/cli-framework/package.json b/packages/@ionic/cli-framework/package.json index f353241cfd..61c3c9985f 100644 --- a/packages/@ionic/cli-framework/package.json +++ b/packages/@ionic/cli-framework/package.json @@ -29,17 +29,6 @@ "license": "MIT", "dependencies": { "@ionic/utils-fs": "0.0.0", - "@types/cross-spawn": "^6.0.0", - "@types/debug": "0.0.30", - "@types/inquirer": "0.0.43", - "@types/lodash": "^4.14.104", - "@types/minimist": "^1.2.0", - "@types/node": "^6.0.101", - "@types/rimraf": "^2.0.2", - "@types/string-width": "^2.0.0", - "@types/strip-ansi": "^3.0.0", - "@types/untildify": "^3.0.0", - "@types/wrap-ansi": "^3.0.0", "chalk": "^2.3.0", "debug": "^3.1.0", "inquirer": "^6.0.0", @@ -56,6 +45,17 @@ "wrap-ansi": "^4.0.0" }, "devDependencies": { + "@types/cross-spawn": "^6.0.0", + "@types/debug": "0.0.30", + "@types/inquirer": "0.0.43", + "@types/lodash": "^4.14.104", + "@types/minimist": "^1.2.0", + "@types/node": "^6.0.101", + "@types/rimraf": "^2.0.2", + "@types/string-width": "^2.0.0", + "@types/strip-ansi": "^3.0.0", + "@types/untildify": "^3.0.0", + "@types/wrap-ansi": "^3.0.0", "jest": "^23.0.1", "jest-cli": "^23.0.1", "lint-staged": "^7.2.0", From f2e75dbd957b38cc30d779408f526a11c7ae79e8 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 17:19:55 -0500 Subject: [PATCH 13/18] refactor(fs): remove fs prefix, rename functions --- .../cli-framework/src/lib/__tests__/config.ts | 6 +- .../@ionic/cli-framework/src/lib/config.ts | 4 +- .../@ionic/cli-framework/src/utils/node.ts | 4 +- packages/@ionic/cli-utils/src/index.ts | 4 +- .../cli-utils/src/lib/__tests__/ssh-config.ts | 14 +-- .../src/lib/doctor/ailments/index.ts | 4 +- packages/@ionic/cli-utils/src/lib/helper.ts | 6 +- .../integrations/cordova/__tests__/android.ts | 2 +- .../cordova/__tests__/resources.ts | 8 +- .../src/lib/integrations/cordova/android.ts | 4 +- .../src/lib/integrations/cordova/config.ts | 6 +- .../src/lib/integrations/cordova/resources.ts | 4 +- .../cli-utils/src/lib/integrations/index.ts | 6 +- .../@ionic/cli-utils/src/lib/project/index.ts | 4 +- .../cli-utils/src/lib/project/ionic1/index.ts | 6 +- packages/@ionic/cli-utils/src/lib/serve.ts | 4 +- packages/@ionic/cli-utils/src/lib/ssh.ts | 8 +- packages/@ionic/cli-utils/src/lib/start.ts | 4 +- .../@ionic/cli-utils/src/lib/utils/http.ts | 8 +- packages/@ionic/lab/src/index.ts | 4 +- packages/@ionic/utils-fs/package.json | 2 - .../@ionic/utils-fs/src/__tests__/index.ts | 16 ++-- packages/@ionic/utils-fs/src/index.ts | 91 ++++++++++--------- .../src/lib/__tests__/dev-server.ts | 4 +- .../@ionic/v1-toolkit/src/lib/dev-server.ts | 4 +- packages/@ionic/v1-toolkit/src/lib/serve.ts | 4 +- packages/cli-scripts/src/docs/index.ts | 6 +- packages/ionic/src/commands/cordova/base.ts | 4 +- .../ionic/src/commands/deploy/manifest.ts | 8 +- .../ionic/src/commands/monitoring/syncmaps.ts | 4 +- packages/ionic/src/commands/ssh/generate.ts | 6 +- packages/ionic/src/commands/ssh/use.ts | 4 +- packages/ionic/src/commands/ssl/generate.ts | 10 +- packages/ionic/src/commands/start.ts | 6 +- 34 files changed, 139 insertions(+), 140 deletions(-) diff --git a/packages/@ionic/cli-framework/src/lib/__tests__/config.ts b/packages/@ionic/cli-framework/src/lib/__tests__/config.ts index 4528beb14c..bfd3b1efa3 100644 --- a/packages/@ionic/cli-framework/src/lib/__tests__/config.ts +++ b/packages/@ionic/cli-framework/src/lib/__tests__/config.ts @@ -10,7 +10,7 @@ describe('@ionic/cli-framework', () => { mockWriteFileAtomicSync = jest.fn(); jest.resetModules(); jest.mock('fs', () => ({ readFileSync: mockReadFileSync })); - jest.mock('@ionic/utils-fs', () => ({ makeDir: { sync: mockMakeDirSync }, writeFileAtomicSync: mockWriteFileAtomicSync })); + jest.mock('@ionic/utils-fs', () => ({ mkdirpSync: mockMakeDirSync, writeFileAtomicSync: mockWriteFileAtomicSync })); const { BaseConfig } = require('../config'); @@ -28,7 +28,7 @@ describe('@ionic/cli-framework', () => { expect(config.p).toEqual('/path/to/file'); }); - it('should call makeDir upon setting c', () => { + it('should call mkdirpSync upon setting c', () => { const config = new Config('/path/to/file'); config.c = {}; expect(mockMakeDirSync).toHaveBeenCalledTimes(1); @@ -164,7 +164,7 @@ describe('@ionic/cli-framework', () => { mockWriteFileAtomicSync = jest.fn(); jest.resetModules(); jest.mock('fs', () => ({ readFileSync: mockReadFileSync })); - jest.mock('@ionic/utils-fs', () => ({ makeDir: { sync: mockMakeDirSync }, writeFileAtomicSync: mockWriteFileAtomicSync })); + jest.mock('@ionic/utils-fs', () => ({ mkdirpSync: mockMakeDirSync, writeFileAtomicSync: mockWriteFileAtomicSync })); const { BaseConfig } = require('../config'); diff --git a/packages/@ionic/cli-framework/src/lib/config.ts b/packages/@ionic/cli-framework/src/lib/config.ts index fa75659a83..f49ff4f1dc 100644 --- a/packages/@ionic/cli-framework/src/lib/config.ts +++ b/packages/@ionic/cli-framework/src/lib/config.ts @@ -1,4 +1,4 @@ -import { makeDir, writeFileAtomicSync } from '@ionic/utils-fs'; +import { mkdirpSync, writeFileAtomicSync } from '@ionic/utils-fs'; import * as fs from 'fs'; import * as lodash from 'lodash'; import * as path from 'path'; @@ -50,7 +50,7 @@ export abstract class BaseConfig { set c(value: T) { const v = this.pathPrefix.length === 0 ? value : lodash.set(this.file, [...this.pathPrefix], value); - makeDir.sync(path.dirname(this.p)); + mkdirpSync(path.dirname(this.p)); writeFileAtomicSync(this.p, JSON.stringify(v, undefined, 2)); } diff --git a/packages/@ionic/cli-framework/src/utils/node.ts b/packages/@ionic/cli-framework/src/utils/node.ts index 091e1cd510..a988d3fe12 100644 --- a/packages/@ionic/cli-framework/src/utils/node.ts +++ b/packages/@ionic/cli-framework/src/utils/node.ts @@ -1,4 +1,4 @@ -import { compilePaths, fsReadJsonFile } from '@ionic/utils-fs'; +import { compilePaths, readJsonFile } from '@ionic/utils-fs'; import * as fs from 'fs'; import * as path from 'path'; @@ -16,7 +16,7 @@ export function isValidPackageName(name: string): boolean { } export async function readPackageJsonFile(p: string): Promise { - const packageJson = await fsReadJsonFile(p); + const packageJson = await readJsonFile(p); if (!isPackageJson(packageJson)) { throw ERROR_INVALID_PACKAGE_JSON; diff --git a/packages/@ionic/cli-utils/src/index.ts b/packages/@ionic/cli-utils/src/index.ts index fefcd6259a..03bb2a9e6a 100644 --- a/packages/@ionic/cli-utils/src/index.ts +++ b/packages/@ionic/cli-utils/src/index.ts @@ -1,7 +1,7 @@ import { LOGGER_LEVELS, createPromptModule } from '@ionic/cli-framework'; import { prettyPath } from '@ionic/cli-framework/utils/format'; import { TERMINAL_INFO } from '@ionic/cli-framework/utils/terminal'; -import { findBaseDirectory, fsReadJsonFile } from '@ionic/utils-fs'; +import { findBaseDirectory, readJsonFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as path from 'path'; @@ -36,7 +36,7 @@ export async function getProject(projectDir: string | undefined, projectName: st let type: ProjectType | undefined; try { - projectFile = await fsReadJsonFile(projectFilePath); + projectFile = await readJsonFile(projectFilePath); } catch (e) { log.error( `Error while loading project config file.\n` + diff --git a/packages/@ionic/cli-utils/src/lib/__tests__/ssh-config.ts b/packages/@ionic/cli-utils/src/lib/__tests__/ssh-config.ts index 0bfc9e5862..9146e8eaa3 100644 --- a/packages/@ionic/cli-utils/src/lib/__tests__/ssh-config.ts +++ b/packages/@ionic/cli-utils/src/lib/__tests__/ssh-config.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import * as SSHConfig from 'ssh-config'; -import { fsReadFile } from '@ionic/utils-fs'; +import { readFile } from '@ionic/utils-fs'; import { ensureHostAndKeyPath } from '../ssh-config'; @@ -20,28 +20,28 @@ describe('@ionic/cli-utils', () => { }); it('should stringify with config1 file', async () => { - const config1 = await fsReadFile(path.resolve(__dirname, 'fixtures/ssh-config/config1'), { encoding: 'utf8' }); + const config1 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config1'), { encoding: 'utf8' }); const conf = SSHConfig.parse(config1); ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa'); expect(SSHConfig.stringify(conf)).toEqual(`${config1}\n${expected}`); }); it('should stringify with config2 file', async () => { - const config2 = await fsReadFile(path.resolve(__dirname, 'fixtures/ssh-config/config2'), { encoding: 'utf8' }); + const config2 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config2'), { encoding: 'utf8' }); const conf = SSHConfig.parse(config2); ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa'); expect(SSHConfig.stringify(conf)).toEqual(`${config2}\n\n${expected}`); }); it('should stringify with config3 file', async () => { - const config3 = await fsReadFile(path.resolve(__dirname, 'fixtures/ssh-config/config3'), { encoding: 'utf8' }); + const config3 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config3'), { encoding: 'utf8' }); const conf = SSHConfig.parse(config3); ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa'); expect(SSHConfig.stringify(conf)).toEqual(config3); }); it('should stringify with config4 file', async () => { - const config4 = await fsReadFile(path.resolve(__dirname, 'fixtures/ssh-config/config4'), { encoding: 'utf8' }); + const config4 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config4'), { encoding: 'utf8' }); const conf = SSHConfig.parse(config4); ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa'); const s = config4.split('\n'); @@ -50,14 +50,14 @@ describe('@ionic/cli-utils', () => { }); it('should stringify with config5 file', async () => { - const config5 = await fsReadFile(path.resolve(__dirname, 'fixtures/ssh-config/config5'), { encoding: 'utf8' }); + const config5 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config5'), { encoding: 'utf8' }); const conf = SSHConfig.parse(config5); ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa'); expect(SSHConfig.stringify(conf)).toEqual(config5); }); it('should stringify with config6 file', async () => { - const config6 = await fsReadFile(path.resolve(__dirname, 'fixtures/ssh-config/config6'), { encoding: 'utf8' }); + const config6 = await readFile(path.resolve(__dirname, 'fixtures/ssh-config/config6'), { encoding: 'utf8' }); const conf = SSHConfig.parse(config6); ensureHostAndKeyPath(conf, { host: 'bar' }, '/id_rsa'); expect(SSHConfig.stringify(conf)).toEqual(`${config6}\n${expected}`); diff --git a/packages/@ionic/cli-utils/src/lib/doctor/ailments/index.ts b/packages/@ionic/cli-utils/src/lib/doctor/ailments/index.ts index 32d6be5c9d..01e9bdf27e 100644 --- a/packages/@ionic/cli-utils/src/lib/doctor/ailments/index.ts +++ b/packages/@ionic/cli-utils/src/lib/doctor/ailments/index.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import chalk from 'chalk'; -import { fsReadFile } from '@ionic/utils-fs'; +import { readFile } from '@ionic/utils-fs'; import { TreatableAilment } from '../../../definitions'; import { AppClient } from '../../app'; @@ -276,7 +276,7 @@ export class ViewportFitNotSet extends Ailment { } async detected() { - const indexHtml = await fsReadFile(path.resolve(await this.project.getSourceDir(), 'index.html'), { encoding: 'utf8' }); + const indexHtml = await readFile(path.resolve(await this.project.getSourceDir(), 'index.html'), { encoding: 'utf8' }); const m = indexHtml.match(/\ { it('should return undefined for a missing source.properties file', async () => { jest.mock('@ionic/utils-fs', () => ({ - fsReadFile: () => { + readFile: () => { const err = new Error(); err.code = 'ENOENT'; return Promise.reject(err); diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/resources.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/resources.ts index 226d209062..e6d1287c06 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/resources.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/__tests__/resources.ts @@ -72,12 +72,12 @@ describe('@ionic/cli-utils', () => { })); it('should create directories that required for all of the images', async () => { - spyOn(fsSpy, 'fsMkdirp').and.callFake((dir) => Promise.resolve(dir)); + spyOn(fsSpy, 'mkdirp').and.callFake((dir) => Promise.resolve(dir)); await resources.createImgDestinationDirectories(imgResources); - expect(fsSpy.fsMkdirp.calls.count()).toEqual(2); - expect(fsSpy.fsMkdirp.calls.argsFor(0)).toEqual([path.normalize('/resourcesDir/ios/splash')]); - expect(fsSpy.fsMkdirp.calls.argsFor(1)).toEqual([path.normalize('/resourcesDir/android/splash')]); + expect(fsSpy.mkdirp.calls.count()).toEqual(2); + expect(fsSpy.mkdirp.calls.argsFor(0)).toEqual([path.normalize('/resourcesDir/ios/splash')]); + expect(fsSpy.mkdirp.calls.argsFor(1)).toEqual([path.normalize('/resourcesDir/android/splash')]); }); }); diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/android.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/android.ts index 66fe603c60..1b655a6d0f 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/android.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/android.ts @@ -1,13 +1,13 @@ import * as path from 'path'; -import { fsReadFile } from '@ionic/utils-fs'; +import { readFile } from '@ionic/utils-fs'; export async function getAndroidSdkToolsVersion(): Promise { const androidHome = await locateSDKHome(); if (androidHome) { try { - const f = await fsReadFile(path.join(androidHome, 'tools', 'source.properties'), { encoding: 'utf8' }); + const f = await readFile(path.join(androidHome, 'tools', 'source.properties'), { encoding: 'utf8' }); return `${await parseSDKVersion(f)} (${androidHome})`; } catch (e) { if (e.code !== 'ENOENT') { diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts index eeb08f3f64..9f10db8b8d 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/config.ts @@ -1,7 +1,7 @@ import * as path from 'path'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsReadFile, fsWriteFile } from '@ionic/utils-fs'; +import { readFile, writeFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as et from 'elementtree'; @@ -53,7 +53,7 @@ export class ConfigXml { } async reload(): Promise { - const configFileContents = await fsReadFile(this.filePath, { encoding: 'utf8' }); + const configFileContents = await readFile(this.filePath, { encoding: 'utf8' }); if (!configFileContents) { throw new Error(`Cannot load empty config.xml file.`); @@ -70,7 +70,7 @@ export class ConfigXml { async save(): Promise { if (!this.saving) { this.saving = true; - await fsWriteFile(this.filePath, this.write(), { encoding: 'utf8' }); + await writeFile(this.filePath, this.write(), { encoding: 'utf8' }); this.saving = false; } } diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts index 7bd88b932a..5d014512af 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts @@ -1,6 +1,6 @@ import { prettyPath } from '@ionic/cli-framework/utils/format'; import { WritableStreamBuffer } from '@ionic/cli-framework/utils/streams'; -import { fsMkdirp, getFileChecksums, readDir, tmpfilepath } from '@ionic/utils-fs'; +import { getFileChecksums, mkdirp, readDir, tmpfilepath } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as fs from 'fs'; @@ -54,7 +54,7 @@ export async function createImgDestinationDirectories(imgResources: ImageResourc const buildDirPromises = imgResources .map(img => path.dirname(img.dest)) .filter((dir, i, dirNames) => dirNames.indexOf(dir) === i) - .map(dir => fsMkdirp(dir)); + .map(dir => mkdirp(dir)); return Promise.all(buildDirPromises); } diff --git a/packages/@ionic/cli-utils/src/lib/integrations/index.ts b/packages/@ionic/cli-utils/src/lib/integrations/index.ts index c92a1fc23c..0de9e077b8 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/index.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/index.ts @@ -5,7 +5,7 @@ import chalk from 'chalk'; import * as Debug from 'debug'; import * as lodash from 'lodash'; -import { copyDirectory, fsMkdirp, fsStat, pathExists, readDir, removeDirectory } from '@ionic/utils-fs'; +import { copyDirectory, mkdirp, pathExists, readDir, removeDirectory, stat } from '@ionic/utils-fs'; import { IConfig, IIntegration, IIntegrationAddOptions, ILogger, IProject, IShell, InfoItem, IntegrationName, ProjectPersonalizationDetails } from '../../definitions'; import { IntegrationNotFoundException } from '../errors'; @@ -86,7 +86,7 @@ export abstract class BaseIntegration implements IIntegration { await removeDirectory(tmpdir); } - await fsMkdirp(tmpdir, 0o777); + await mkdirp(tmpdir, 0o777); const ws = tar.extract({ cwd: tmpdir }); const { req } = await createRequest('GET', this.archiveUrl, this.e.config.getHTTPConfig()); @@ -101,7 +101,7 @@ export abstract class BaseIntegration implements IIntegration { const projectf = path.resolve(this.e.project.directory, f); try { - const stats = await fsStat(projectf); + const stats = await stat(projectf); const overwrite = await conflictHandler(projectf, stats); if (!overwrite) { diff --git a/packages/@ionic/cli-utils/src/lib/project/index.ts b/packages/@ionic/cli-utils/src/lib/project/index.ts index 682b57f3e3..f85f72dc90 100644 --- a/packages/@ionic/cli-utils/src/lib/project/index.ts +++ b/packages/@ionic/cli-utils/src/lib/project/index.ts @@ -1,7 +1,7 @@ import { BaseConfig, BaseConfigOptions, PromptModule } from '@ionic/cli-framework'; import { TTY_WIDTH, prettyPath, wordWrap } from '@ionic/cli-framework/utils/format'; import { ERROR_INVALID_PACKAGE_JSON, compileNodeModulesPaths, readPackageJsonFile, resolve } from '@ionic/cli-framework/utils/node'; -import { fsWriteJsonFile } from '@ionic/utils-fs'; +import { writeJsonFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as lodash from 'lodash'; @@ -280,7 +280,7 @@ export abstract class Project implements IProject { pkg.version = version ? version : '0.0.1'; pkg.description = description ? description : 'An Ionic project'; - await fsWriteJsonFile(this.packageJsonPath, pkg, { encoding: 'utf8' }); + await writeJsonFile(this.packageJsonPath, pkg, { encoding: 'utf8' }); const integrations = await this.getIntegrations(); diff --git a/packages/@ionic/cli-utils/src/lib/project/ionic1/index.ts b/packages/@ionic/cli-utils/src/lib/project/ionic1/index.ts index 9fe9cb903d..ddcba6c78a 100644 --- a/packages/@ionic/cli-utils/src/lib/project/ionic1/index.ts +++ b/packages/@ionic/cli-utils/src/lib/project/ionic1/index.ts @@ -1,5 +1,5 @@ import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsReadJsonFile } from '@ionic/utils-fs'; +import { readJsonFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as lodash from 'lodash'; @@ -27,7 +27,7 @@ function isBowerJson(obj: any): obj is BowerJson { } async function readBowerJsonFile(p: string): Promise { - const bowerJson = await fsReadJsonFile(p); + const bowerJson = await readJsonFile(p); if (!isBowerJson(bowerJson)) { throw ERROR_INVALID_BOWER_JSON; @@ -83,7 +83,7 @@ export class Ionic1Project extends Project { try { try { - const ionicVersionJson = await fsReadJsonFile(ionicVersionFilePath); + const ionicVersionJson = await readJsonFile(ionicVersionFilePath); return ionicVersionJson['version']; } catch (e) { const bwr = await this.loadBowerJson(); diff --git a/packages/@ionic/cli-utils/src/lib/serve.ts b/packages/@ionic/cli-utils/src/lib/serve.ts index e75af0c0e3..00a1f09b1d 100644 --- a/packages/@ionic/cli-utils/src/lib/serve.ts +++ b/packages/@ionic/cli-utils/src/lib/serve.ts @@ -1,7 +1,7 @@ import { BaseError, LOGGER_LEVELS, OptionGroup, PromptModule, createPrefixedFormatter } from '@ionic/cli-framework'; import { killProcessTree, onBeforeExit, processExit } from '@ionic/cli-framework/utils/process'; import { str2num } from '@ionic/cli-framework/utils/string'; -import { fsReadJsonFile } from '@ionic/utils-fs'; +import { readJsonFile } from '@ionic/utils-fs'; import { NetworkInterface, findClosestOpenPort, getExternalIPv4Interfaces, isHostConnectable } from '@ionic/utils-network'; import chalk from 'chalk'; import * as Debug from 'debug'; @@ -296,7 +296,7 @@ export abstract class ServeRunner implements Runner> { const p = path.resolve(ASSETS_DIRECTORY, 'devapp', 'plugins.json'); - const plugins = await fsReadJsonFile(p); + const plugins = await readJsonFile(p); if (!Array.isArray(plugins)) { throw new Error(`Cannot read ${p} file of supported plugins.`); diff --git a/packages/@ionic/cli-utils/src/lib/ssh.ts b/packages/@ionic/cli-utils/src/lib/ssh.ts index 419145bf34..b89cbe63ef 100644 --- a/packages/@ionic/cli-utils/src/lib/ssh.ts +++ b/packages/@ionic/cli-utils/src/lib/ssh.ts @@ -1,4 +1,4 @@ -import { fsReadFile, fsStat } from '@ionic/utils-fs'; +import { readFile, stat } from '@ionic/utils-fs'; import * as os from 'os'; import * as path from 'path'; @@ -16,7 +16,7 @@ export async function getGeneratedPrivateKeyPath(userId = 0): Promise { } export async function parsePublicKeyFile(pubkeyPath: string): Promise<[string, string, string, string]> { - return parsePublicKey((await fsReadFile(pubkeyPath, { encoding: 'utf8' })).trim()); + return parsePublicKey((await readFile(pubkeyPath, { encoding: 'utf8' })).trim()); } /** @@ -42,7 +42,7 @@ export async function parsePublicKey(pubkey: string): Promise<[string, string, s export async function validatePrivateKey(keyPath: string): Promise { try { - await fsStat(keyPath); + await stat(keyPath); } catch (e) { if (e.code === 'ENOENT') { throw ERROR_SSH_MISSING_PRIVKEY; @@ -51,7 +51,7 @@ export async function validatePrivateKey(keyPath: string): Promise { throw e; } - const f = await fsReadFile(keyPath, { encoding: 'utf8' }); + const f = await readFile(keyPath, { encoding: 'utf8' }); const lines = f.split('\n'); if (!lines[0].match(/^\-{5}BEGIN [R|D]SA PRIVATE KEY\-{5}$/)) { diff --git a/packages/@ionic/cli-utils/src/lib/start.ts b/packages/@ionic/cli-utils/src/lib/start.ts index 48351f58a4..c4f3e5dfe7 100644 --- a/packages/@ionic/cli-utils/src/lib/start.ts +++ b/packages/@ionic/cli-utils/src/lib/start.ts @@ -1,4 +1,4 @@ -import { fsReadJsonFile } from '@ionic/utils-fs'; +import { readJsonFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import { IConfig, StarterList, StarterManifest, StarterTemplate } from '../definitions'; @@ -11,7 +11,7 @@ export const STARTER_BASE_URL = 'https://d2ql0qc7j8u4b2.cloudfront.net'; export async function readStarterManifest(p: string): Promise { try { - const manifest = await fsReadJsonFile(p); + const manifest = await readJsonFile(p); if (!isStarterManifest(manifest)) { throw new Error(`${p} is not a valid starter manifest.`); diff --git a/packages/@ionic/cli-utils/src/lib/utils/http.ts b/packages/@ionic/cli-utils/src/lib/utils/http.ts index 3186e98e05..f0fc71c232 100644 --- a/packages/@ionic/cli-utils/src/lib/utils/http.ts +++ b/packages/@ionic/cli-utils/src/lib/utils/http.ts @@ -3,7 +3,7 @@ import * as Debug from 'debug'; import * as ζsuperagent from 'superagent'; import { conform } from '@ionic/cli-framework/utils/array'; -import { fsReadFile } from '@ionic/utils-fs'; +import { readFile } from '@ionic/utils-fs'; import { CreateRequestOptions, HttpMethod } from '../../definitions'; @@ -53,15 +53,15 @@ export async function createRequest(method: HttpMethod, url: string, { proxy, ss const keyfiles = conform(ssl.keyfile); if (cafiles.length > 0) { - req.ca(await Promise.all(cafiles.map(p => fsReadFile(p, { encoding: 'utf8' })))); + req.ca(await Promise.all(cafiles.map(p => readFile(p, { encoding: 'utf8' })))); } if (certfiles.length > 0) { - req.cert(await Promise.all(certfiles.map(p => fsReadFile(p, { encoding: 'utf8' })))); + req.cert(await Promise.all(certfiles.map(p => readFile(p, { encoding: 'utf8' })))); } if (keyfiles.length > 0) { - req.key(await Promise.all(keyfiles.map(p => fsReadFile(p, { encoding: 'utf8' })))); + req.key(await Promise.all(keyfiles.map(p => readFile(p, { encoding: 'utf8' })))); } } diff --git a/packages/@ionic/lab/src/index.ts b/packages/@ionic/lab/src/index.ts index f5cb2ea631..3cf2a51096 100644 --- a/packages/@ionic/lab/src/index.ts +++ b/packages/@ionic/lab/src/index.ts @@ -1,5 +1,5 @@ import { Command, CommandLineInputs, CommandLineOptions, CommandMap, CommandMapDefault, Namespace, execute, validators } from '@ionic/cli-framework'; -import { fsReadFile } from '@ionic/utils-fs'; +import { readFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as express from 'express'; import * as http from 'http'; @@ -102,7 +102,7 @@ class DefaultCommand extends Command { async readPem(p: string): Promise { try { - return await fsReadFile(p, { encoding: 'utf8' }); + return await readFile(p, { encoding: 'utf8' }); } catch (e) { process.stderr.write(String(e.stack ? e.stack : e) + '\n'); throw new Error(`Error encountered with ${p}`); diff --git a/packages/@ionic/utils-fs/package.json b/packages/@ionic/utils-fs/package.json index 59d21e6455..27cc1e14e3 100644 --- a/packages/@ionic/utils-fs/package.json +++ b/packages/@ionic/utils-fs/package.json @@ -39,7 +39,6 @@ "dependencies": { "debug": "^3.1.0", "klaw": "^3.0.0", - "make-dir": "^1.3.0", "ncp": "^2.0.0", "tslib": "^1.9.0", "write-file-atomic": "^2.3.0" @@ -47,7 +46,6 @@ "devDependencies": { "@types/debug": "0.0.30", "@types/klaw": "^2.1.1", - "@types/make-dir": "^1.0.3", "@types/ncp": "^2.0.1", "@types/node": "^6.0.101", "@types/write-file-atomic": "^2.1.1", diff --git a/packages/@ionic/utils-fs/src/__tests__/index.ts b/packages/@ionic/utils-fs/src/__tests__/index.ts index d0db194ee6..40a96acb77 100644 --- a/packages/@ionic/utils-fs/src/__tests__/index.ts +++ b/packages/@ionic/utils-fs/src/__tests__/index.ts @@ -20,19 +20,19 @@ describe('@ionic/cli-framework', () => { }); it('should return undefined if marker file not found', async () => { - jest.spyOn(fslib, 'fsReadDir').mockImplementation(async () => ['bar']); + jest.spyOn(fslib, 'readDir').mockImplementation(async () => ['bar']); const result = await fslib.findBaseDirectory('/some/dir', 'foo'); expect(result).toEqual(undefined); }); it('should return path when marker file found in cwd', async () => { - jest.spyOn(fslib, 'fsReadDir').mockImplementation(async () => ['foo']); + jest.spyOn(fslib, 'readDir').mockImplementation(async () => ['foo']); const result = await fslib.findBaseDirectory('/some/dir', 'foo'); expect(result).toEqual('/some/dir'); }); it('should return path when marker file found in one directory back', async () => { - jest.spyOn(fslib, 'fsReadDir') + jest.spyOn(fslib, 'readDir') .mockImplementationOnce(async () => ['garbage']) .mockImplementationOnce(async () => ['dir', 'foo']); const result = await fslib.findBaseDirectory('/some/dir', 'foo'); @@ -40,7 +40,7 @@ describe('@ionic/cli-framework', () => { }); it('should return path when marker file found in really nested path', async () => { - jest.spyOn(fslib, 'fsReadDir') + jest.spyOn(fslib, 'readDir') .mockImplementationOnce(async () => ['']) .mockImplementationOnce(async () => ['nested']) .mockImplementationOnce(async () => ['really']) @@ -67,19 +67,19 @@ describe('@ionic/cli-framework', () => { }); it('should return undefined if marker file not found', async () => { - jest.spyOn(fslib, 'fsReadDir').mockImplementation(async () => ['bar']); + jest.spyOn(fslib, 'readDir').mockImplementation(async () => ['bar']); const result = await fslib.findBaseDirectory('C:\\some\\dir', 'foo'); expect(result).toEqual(undefined); }); it('should return path when marker file found in cwd', async () => { - jest.spyOn(fslib, 'fsReadDir').mockImplementation(async () => ['foo']); + jest.spyOn(fslib, 'readDir').mockImplementation(async () => ['foo']); const result = await fslib.findBaseDirectory('C:\\some\\dir', 'foo'); expect(result).toEqual('C:\\some\\dir'); }); it('should return path when marker file found in one directory back', async () => { - jest.spyOn(fslib, 'fsReadDir') + jest.spyOn(fslib, 'readDir') .mockImplementationOnce(async () => ['garbage']) .mockImplementationOnce(async () => ['dir', 'foo']); const result = await fslib.findBaseDirectory('C:\\some\\dir', 'foo'); @@ -87,7 +87,7 @@ describe('@ionic/cli-framework', () => { }); it('should return path when marker file found in really nested path', async () => { - jest.spyOn(fslib, 'fsReadDir') + jest.spyOn(fslib, 'readDir') .mockImplementationOnce(async () => ['']) .mockImplementationOnce(async () => ['nested']) .mockImplementationOnce(async () => ['really']) diff --git a/packages/@ionic/utils-fs/src/index.ts b/packages/@ionic/utils-fs/src/index.ts index 118adc8cfc..d01e838876 100644 --- a/packages/@ionic/utils-fs/src/index.ts +++ b/packages/@ionic/utils-fs/src/index.ts @@ -2,7 +2,6 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; -import * as makeDir from 'make-dir'; import * as ζncp from 'ncp'; import * as wfa from 'write-file-atomic'; @@ -40,66 +39,51 @@ export interface FSWriteFileOptions { flag?: string; } -export const fsAccess = promisify(fs.access); -export const fsMkdir = promisify(fs.mkdir); -export const fsOpen = promisify(fs.open); -export const fsStat = promisify(fs.stat); -export const fsUnlink = promisify(fs.unlink); -export const fsReadFile = promisify(fs.readFile); -export const fsWriteFile = promisify(fs.writeFile); -export const fsReadDir = promisify(fs.readdir); +export const access = promisify(fs.access); +export const mkdir = promisify(fs.mkdir); +export const open = promisify(fs.open); +export const stat = promisify(fs.stat); +export const unlink = promisify(fs.unlink); +export const readFile = promisify(fs.readFile); +export const writeFile = promisify(fs.writeFile); +export const readDir = promisify(fs.readdir); export const writeFileAtomic = promisify(wfa); export const writeFileAtomicSync = wfa.sync; -export { makeDir }; - /** - * Error-less, promisified `fs.readdir` with an option to recurse into - * subdirectories. + * Error-less, promisified `fs.readdir` that recurses into subdirectories. * * This function will not throw errors. If there is an issue with the * directory, an empty array is returned. * * @param dir The path to the directory to read. - * @param options.recursive If true, compile an array of all files in all - * subdirectories. */ -export async function readDir(dir: string, options?: { recursive?: boolean; }): Promise { - options = options ? options : {}; - - if (options.recursive) { - const klaw = await import('klaw'); +export async function readDirp(dir: string): Promise { + const klaw = await import('klaw'); - return new Promise((resolve, reject) => { - const items: string[] = []; + return new Promise((resolve, reject) => { + const items: string[] = []; - klaw(dir) - .on('error', err => { /* ignore */ }) - .on('data', item => items.push(item.path)) - .on('end', () => resolve(items)); - }); - } else { - try { - return await fsReadDir(dir); - } catch (e) { - return []; - } - } + klaw(dir) + .on('error', err => { /* ignore */ }) + .on('data', item => items.push(item.path)) + .on('end', () => resolve(items)); + }); } -export async function fsReadJsonFile(filePath: string, options: FSReadFileOptions = { encoding: 'utf8' }): Promise<{ [key: string]: any }> { - const f = await fsReadFile(filePath, options); +export async function readJsonFile(filePath: string, options: FSReadFileOptions = { encoding: 'utf8' }): Promise<{ [key: string]: any }> { + const f = await readFile(filePath, options); return JSON.parse(f); } -export async function fsWriteJsonFile(filePath: string, json: { [key: string]: any; }, options: FSWriteFileOptions): Promise { - return fsWriteFile(filePath, JSON.stringify(json, undefined, 2) + '\n', options); +export async function writeJsonFile(filePath: string, json: { [key: string]: any; }, options: FSWriteFileOptions): Promise { + return writeFile(filePath, JSON.stringify(json, undefined, 2) + '\n', options); } export async function fileToString(filePath: string): Promise { try { - return await fsReadFile(filePath, { encoding: 'utf8' }); + return await readFile(filePath, { encoding: 'utf8' }); } catch (e) { if (e.code === 'ENOENT') { return ''; @@ -109,7 +93,24 @@ export async function fileToString(filePath: string): Promise { } } -export async function fsMkdirp(p: string, mode = 0o777): Promise { +export async function mkdirp(p: string, mode = 0o777): Promise { + const absPath = path.resolve(p); + const pathObj = path.parse(absPath); + const dirnames = absPath.split(path.sep).splice(1); + const dirs = dirnames.map((v, i) => path.resolve(pathObj.root, ...dirnames.slice(0, i), v)); + + for (const dir of dirs) { + try { + await mkdir(dir, mode); + } catch (e) { + if (e.code !== 'EEXIST') { + throw e; + } + } + } +} + +export function mkdirpSync(p: string, mode = 0o777): void { const absPath = path.resolve(p); const pathObj = path.parse(absPath); const dirnames = absPath.split(path.sep).splice(1); @@ -117,7 +118,7 @@ export async function fsMkdirp(p: string, mode = 0o777): Promise { for (const dir of dirs) { try { - await fsMkdir(dir, mode); + fs.mkdirSync(dir, mode); } catch (e) { if (e.code !== 'EEXIST') { throw e; @@ -160,7 +161,7 @@ export async function getFileChecksums(p: string): Promise<[string, string | und getFileChecksum(p), (async () => { try { - const md5 = await fsReadFile(`${p}.md5`, { encoding: 'utf8' }); + const md5 = await readFile(`${p}.md5`, { encoding: 'utf8' }); return md5.trim(); } catch (e) { if (e.code !== 'ENOENT') { @@ -179,7 +180,7 @@ export async function getFileChecksums(p: string): Promise<[string, string | und */ export async function cacheFileChecksum(p: string, checksum?: string): Promise { const md5 = await getFileChecksum(p); - await fsWriteFile(`${p}.md5`, md5, { encoding: 'utf8' }); + await writeFile(`${p}.md5`, md5, { encoding: 'utf8' }); } export function writeStreamToFile(stream: NodeJS.ReadableStream, destination: string): Promise { @@ -229,7 +230,7 @@ export function copyFile(fileName: string, target: string, mode = 0o666) { export async function pathAccessible(filePath: string, mode: number): Promise { try { - await fsAccess(filePath, mode); + await access(filePath, mode); } catch (e) { return false; } @@ -250,7 +251,7 @@ export async function findBaseDirectory(dir: string, file: string): Promise { @@ -42,7 +42,7 @@ describe('@ionic/ionic-v1', () => { it('should inject script into app template', async () => { // TODO: this test is fragile and gross - const apphtml = await fsReadFile(path.resolve(__dirname, 'fixtures/dev-server/app.html'), { encoding: 'utf8' }); + const apphtml = await readFile(path.resolve(__dirname, 'fixtures/dev-server/app.html'), { encoding: 'utf8' }); const code = ` `; diff --git a/packages/@ionic/v1-toolkit/src/lib/dev-server.ts b/packages/@ionic/v1-toolkit/src/lib/dev-server.ts index d8266e6d8d..d44841a02c 100644 --- a/packages/@ionic/v1-toolkit/src/lib/dev-server.ts +++ b/packages/@ionic/v1-toolkit/src/lib/dev-server.ts @@ -1,4 +1,4 @@ -import { fsReadFile } from '@ionic/utils-fs'; +import { readFile } from '@ionic/utils-fs'; import chalk, { Chalk } from 'chalk'; import * as ζexpress from 'express'; import * as path from 'path'; @@ -49,7 +49,7 @@ export async function createDevServerHandler(options: DevServerOptions): Promise wsPort: options.devPort, }; - const devServerJs = await fsReadFile(path.join(__dirname, '..', '..', 'assets', 'dev-server.js'), { encoding: 'utf8' }); + const devServerJs = await readFile(path.join(__dirname, '..', '..', 'assets', 'dev-server.js'), { encoding: 'utf8' }); return (req, res) => { res.set('Content-Type', 'application/javascript'); diff --git a/packages/@ionic/v1-toolkit/src/lib/serve.ts b/packages/@ionic/v1-toolkit/src/lib/serve.ts index e8a904fbc2..a921cfe486 100644 --- a/packages/@ionic/v1-toolkit/src/lib/serve.ts +++ b/packages/@ionic/v1-toolkit/src/lib/serve.ts @@ -1,4 +1,4 @@ -import { fsReadFile, pathExists } from '@ionic/utils-fs'; +import { pathExists, readFile } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as ζexpress from 'express'; import * as ζproxyMiddleware from 'http-proxy-middleware'; @@ -101,7 +101,7 @@ async function createHttpServer(options: ServeOptions): Promise<ζexpress.Applic const serveIndex = async (req: ζexpress.Request, res: ζexpress.Response) => { // respond with the index.html file const indexFileName = path.join(options.wwwDir, 'index.html'); - let indexHtml = await fsReadFile(indexFileName, { encoding: 'utf8' }); + let indexHtml = await readFile(indexFileName, { encoding: 'utf8' }); indexHtml = injectDevServerScript(indexHtml); diff --git a/packages/cli-scripts/src/docs/index.ts b/packages/cli-scripts/src/docs/index.ts index f4a802e0d2..517bc9b1bb 100644 --- a/packages/cli-scripts/src/docs/index.ts +++ b/packages/cli-scripts/src/docs/index.ts @@ -5,7 +5,7 @@ import stripAnsi = require('strip-ansi'); import { Command, CommandHelpSchemaInput, CommandHelpSchemaOption, CommandLineInputs, CommandLineOptions, CommandMetadata } from '@ionic/cli-framework'; import { strcmp } from '@ionic/cli-framework/utils/string'; -import { fsMkdirp, fsWriteFile, removeDirectory } from '@ionic/utils-fs'; +import { mkdirp, removeDirectory, writeFile } from '@ionic/utils-fs'; import { ProjectType } from '@ionic/cli-utils'; import { CommandHelpSchema, NamespaceSchemaHelpFormatter } from '@ionic/cli-utils/lib/help'; @@ -26,7 +26,7 @@ export class DocsCommand extends Command { async run(inputs: CommandLineInputs, options: CommandLineOptions) { await removeDirectory(STAGING_DIRECTORY); - await fsMkdirp(STAGING_DIRECTORY); + await mkdirp(STAGING_DIRECTORY); const projectTypes: ProjectType[] = ['angular', 'ionic-angular', 'ionic1']; const baseCtx = await generateContext(); @@ -45,7 +45,7 @@ export class DocsCommand extends Command { projectJson.commands = await Promise.all(projectJson.commands.map(async cmd => this.extractCommand(cmd as CommandHelpSchema))); projectJson.commands.sort((a, b) => strcmp(a.name, b.name)); - await fsWriteFile(path.resolve(STAGING_DIRECTORY, `${projectType}.json`), JSON.stringify(projectJson, undefined, 2), { encoding: 'utf8' }); + await writeFile(path.resolve(STAGING_DIRECTORY, `${projectType}.json`), JSON.stringify(projectJson, undefined, 2), { encoding: 'utf8' }); } process.stdout.write(`${chalk.green('Done.')}\n`); diff --git a/packages/ionic/src/commands/cordova/base.ts b/packages/ionic/src/commands/cordova/base.ts index 6c59928513..8ec2da1540 100644 --- a/packages/ionic/src/commands/cordova/base.ts +++ b/packages/ionic/src/commands/cordova/base.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import { ERROR_SHELL_COMMAND_NOT_FOUND, OptionGroup, ShellCommandError } from '@ionic/cli-framework'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsMkdir, pathExists } from '@ionic/utils-fs'; +import { mkdirp, pathExists } from '@ionic/utils-fs'; import { CommandInstanceInfo, CommandMetadataOption, IShellRunOptions } from '@ionic/cli-utils'; import { Command } from '@ionic/cli-utils/lib/command'; @@ -99,7 +99,7 @@ export abstract class CordovaCommand extends Command { const tasks = this.createTaskChain(); tasks.next(`Creating ${chalk.bold(prettyPath(wwwPath))} directory for you`); - await fsMkdir(wwwPath, 0o777); + await mkdirp(wwwPath, 0o777); tasks.end(); } } diff --git a/packages/ionic/src/commands/deploy/manifest.ts b/packages/ionic/src/commands/deploy/manifest.ts index 72c09b63ce..8a60fb6836 100644 --- a/packages/ionic/src/commands/deploy/manifest.ts +++ b/packages/ionic/src/commands/deploy/manifest.ts @@ -7,7 +7,7 @@ import { map } from '@ionic/cli-framework/utils/array'; import { CommandMetadata } from '@ionic/cli-utils'; import { Command } from '@ionic/cli-utils/lib/command'; import { FatalException } from '@ionic/cli-utils/lib/errors'; -import { fsStat, fsWriteFile, readDir } from '@ionic/utils-fs'; +import { readDirp, stat, writeFile } from '@ionic/utils-fs'; interface DeployManifestItem { href: string; @@ -32,12 +32,12 @@ export class DeployManifestCommand extends Command { const buildDir = path.resolve(this.project.directory, 'www'); // TODO: this is hard-coded const manifest = await this.getFilesAndSizesAndHashesForGlobPattern(buildDir); - await fsWriteFile(path.resolve(buildDir, 'pro-manifest.json'), JSON.stringify(manifest, undefined, 2), { encoding: 'utf8' }); + await writeFile(path.resolve(buildDir, 'pro-manifest.json'), JSON.stringify(manifest, undefined, 2), { encoding: 'utf8' }); } private async getFilesAndSizesAndHashesForGlobPattern(buildDir: string): Promise { - const contents = await readDir(buildDir, { recursive: true }); - const stats = await map(contents, async (f): Promise<[string, fs.Stats]> => [f, await fsStat(f)]); + const contents = await readDirp(buildDir); + const stats = await map(contents, async (f): Promise<[string, fs.Stats]> => [f, await stat(f)]); const files = stats.filter(([ , stat ]) => !stat.isDirectory()); const items = await Promise.all(files.map(([f, stat]) => this.getFileAndSizeAndHashForFile(buildDir, f, stat))); diff --git a/packages/ionic/src/commands/monitoring/syncmaps.ts b/packages/ionic/src/commands/monitoring/syncmaps.ts index f41b8a94eb..730a1fe848 100644 --- a/packages/ionic/src/commands/monitoring/syncmaps.ts +++ b/packages/ionic/src/commands/monitoring/syncmaps.ts @@ -8,7 +8,7 @@ import { APIResponseSuccess, CommandLineInputs, CommandLineOptions, CommandMetad import { build } from '@ionic/cli-utils/lib/build'; import { Command } from '@ionic/cli-utils/lib/command'; import { FatalException } from '@ionic/cli-utils/lib/errors'; -import { fsReadFile, pathExists, readDir } from '@ionic/utils-fs'; +import { pathExists, readDir, readFile } from '@ionic/utils-fs'; const debug = Debug('ionic:cli:commands:monitoring:syncmaps'); @@ -140,7 +140,7 @@ By default, ${chalk.green('ionic monitoring syncmaps')} will upload the sourcema const sm = sourcemap as any; - const fileData = await fsReadFile(file, { encoding: 'utf8' }); + const fileData = await readFile(file, { encoding: 'utf8' }); const sourcemapPost = sm.data.sourcemap_post; const { req } = await createRequest('POST', sourcemapPost.url, this.env.config.getHTTPConfig()); diff --git a/packages/ionic/src/commands/ssh/generate.ts b/packages/ionic/src/commands/ssh/generate.ts index 2311c01a71..b84f75ba07 100644 --- a/packages/ionic/src/commands/ssh/generate.ts +++ b/packages/ionic/src/commands/ssh/generate.ts @@ -5,7 +5,7 @@ import chalk from 'chalk'; import { OptionGroup, contains, validate } from '@ionic/cli-framework'; import { expandPath, prettyPath } from '@ionic/cli-framework/utils/format'; import { CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun } from '@ionic/cli-utils'; -import { fsMkdirp, fsUnlink, pathExists } from '@ionic/utils-fs'; +import { mkdirp, pathExists, unlink } from '@ionic/utils-fs'; import { SSHBaseCommand } from './base'; @@ -70,7 +70,7 @@ export class SSHGenerateCommand extends SSHBaseCommand implements CommandPreRun const pubkeyPath = `${keyPath}.pub`; if (!(await pathExists(keyPathDir))) { - await fsMkdirp(keyPathDir, 0o700); + await mkdirp(keyPathDir, 0o700); this.env.log.msg(`Created ${chalk.bold(prettyPath(keyPathDir))} directory for you.`); } @@ -82,7 +82,7 @@ export class SSHGenerateCommand extends SSHBaseCommand implements CommandPreRun }); if (confirm) { - await fsUnlink(keyPath); + await unlink(keyPath); } else { this.env.log.msg(`Not overwriting ${chalk.bold(prettyPath(keyPath))}.`); return; diff --git a/packages/ionic/src/commands/ssh/use.ts b/packages/ionic/src/commands/ssh/use.ts index 0f668351b3..cf9e687c65 100644 --- a/packages/ionic/src/commands/ssh/use.ts +++ b/packages/ionic/src/commands/ssh/use.ts @@ -4,7 +4,7 @@ import { validators } from '@ionic/cli-framework'; import { expandPath, prettyPath } from '@ionic/cli-framework/utils/format'; import { CommandLineInputs, CommandLineOptions, CommandMetadata } from '@ionic/cli-utils'; import { FatalException } from '@ionic/cli-utils/lib/errors'; -import { fileToString, fsWriteFile } from '@ionic/utils-fs'; +import { fileToString, writeFile } from '@ionic/utils-fs'; import { SSHBaseCommand } from './base'; @@ -83,7 +83,7 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://linux.die.net/man/5/ssh_config')} } } - await fsWriteFile(sshConfigPath, text2, { encoding: 'utf8', mode: 0o600 }); + await writeFile(sshConfigPath, text2, { encoding: 'utf8', mode: 0o600 }); this.env.log.ok(`Your active Ionic SSH key has been set to ${chalk.bold(keyPath)}!`); } diff --git a/packages/ionic/src/commands/ssl/generate.ts b/packages/ionic/src/commands/ssl/generate.ts index 6f0febc0c6..0c61c54e53 100644 --- a/packages/ionic/src/commands/ssl/generate.ts +++ b/packages/ionic/src/commands/ssl/generate.ts @@ -5,7 +5,7 @@ import * as lodash from 'lodash'; import { CommandGroup, OptionGroup } from '@ionic/cli-framework'; import { prettyPath } from '@ionic/cli-framework/utils/format'; -import { fsMkdirp, fsUnlink, fsWriteFile, pathExists, tmpfilepath } from '@ionic/utils-fs'; +import { mkdirp, pathExists, tmpfilepath, unlink, writeFile } from '@ionic/utils-fs'; import { CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun } from '@ionic/cli-utils'; import { FatalException } from '@ionic/cli-utils/lib/errors'; @@ -137,11 +137,11 @@ The default directory for ${chalk.green('--key-path')} and ${chalk.green('--cert const overwriteCertPath = await this.checkExistingFile(certPath); if (overwriteKeyPath) { - await fsUnlink(keyPath); + await unlink(keyPath); } if (overwriteCertPath) { - await fsUnlink(certPath); + await unlink(certPath); } const cnf = { bits, countryName, stateOrProvinceName, localityName, organizationName, commonName }; @@ -173,7 +173,7 @@ The default directory for ${chalk.green('--key-path')} and ${chalk.green('--cert private async ensureDirectory(p: string) { if (!(await pathExists(p))) { - await fsMkdirp(p, 0o700); + await mkdirp(p, 0o700); this.env.log.msg(`Created ${chalk.bold(prettyPath(p))} directory for you.`); } } @@ -212,7 +212,7 @@ subjectAltName=DNS:${commonName} `.trim(); const p = tmpfilepath('ionic-ssl'); - await fsWriteFile(p, cnf, { encoding: 'utf8' }); + await writeFile(p, cnf, { encoding: 'utf8' }); return p; } } diff --git a/packages/ionic/src/commands/start.ts b/packages/ionic/src/commands/start.ts index 0f6cccad8a..c0b5828b88 100644 --- a/packages/ionic/src/commands/start.ts +++ b/packages/ionic/src/commands/start.ts @@ -8,7 +8,7 @@ import { OptionGroup, validators } from '@ionic/cli-framework'; import { columnar, prettyPath } from '@ionic/cli-framework/utils/format'; import { isValidPackageName } from '@ionic/cli-framework/utils/node'; import { isValidURL, slugify } from '@ionic/cli-framework/utils/string'; -import { fsMkdir, fsUnlink, pathExists, removeDirectory } from '@ionic/utils-fs'; +import { mkdir, pathExists, removeDirectory, unlink } from '@ionic/utils-fs'; import { CommandInstanceInfo, CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun, ResolvedStarterTemplate, StarterManifest, StarterTemplate, getProject } from '@ionic/cli-utils'; import { Command } from '@ionic/cli-utils/lib/command'; @@ -396,7 +396,7 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://ionicframework.com/docs/cli/starters await removeDirectory(projectDir); } - await fsMkdir(projectDir, 0o777); + await mkdir(projectDir, 0o777); tasks.end(); @@ -499,7 +499,7 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://ionicframework.com/docs/cli/starters const manifest = await this.loadManifest(manifestPath); if (manifest) { - await fsUnlink(manifestPath); + await unlink(manifestPath); } if (gitIntegration) { From df4919ba0cf26fd37347a09fdbade25acb08104a Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 18:34:10 -0500 Subject: [PATCH 14/18] refactor(fs): implement file walker --- .../src/lib/integrations/cordova/project.ts | 4 +- .../src/lib/integrations/cordova/resources.ts | 4 +- .../cli-utils/src/lib/integrations/index.ts | 4 +- packages/@ionic/utils-fs/package.json | 4 +- packages/@ionic/utils-fs/src/index.ts | 140 +++++++++++++++--- .../ionic/src/commands/monitoring/syncmaps.ts | 4 +- 6 files changed, 130 insertions(+), 30 deletions(-) diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/project.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/project.ts index 8503051eb9..cdb4736c38 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/project.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/project.ts @@ -1,9 +1,9 @@ import * as path from 'path'; -import { readDir } from '@ionic/utils-fs'; +import { readDirSafe } from '@ionic/utils-fs'; export async function getPlatforms(projectDir: string): Promise { const platformsDir = path.resolve(projectDir, 'platforms'); - const dirContents = await readDir(platformsDir); + const dirContents = await readDirSafe(platformsDir); return dirContents.filter(f => f && f !== 'platforms.json' && !f.startsWith('.')); } diff --git a/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts b/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts index 5d014512af..392f1734fa 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/cordova/resources.ts @@ -1,6 +1,6 @@ import { prettyPath } from '@ionic/cli-framework/utils/format'; import { WritableStreamBuffer } from '@ionic/cli-framework/utils/streams'; -import { getFileChecksums, mkdirp, readDir, tmpfilepath } from '@ionic/utils-fs'; +import { getFileChecksums, mkdirp, readDirSafe, tmpfilepath } from '@ionic/utils-fs'; import chalk from 'chalk'; import * as Debug from 'debug'; import * as fs from 'fs'; @@ -72,7 +72,7 @@ export async function getSourceImages(projectDir: string, buildPlatforms: string const sourceImages: SourceImage[] = []; for (const srcImgDir of srcDirList) { - const srcImageDirContents = await readDir(srcImgDir.path); + const srcImageDirContents = await readDirSafe(srcImgDir.path); for (const srcImage of srcImageDirContents) { const ext = path.extname(srcImage); diff --git a/packages/@ionic/cli-utils/src/lib/integrations/index.ts b/packages/@ionic/cli-utils/src/lib/integrations/index.ts index 0de9e077b8..2e7613e1f7 100644 --- a/packages/@ionic/cli-utils/src/lib/integrations/index.ts +++ b/packages/@ionic/cli-utils/src/lib/integrations/index.ts @@ -5,7 +5,7 @@ import chalk from 'chalk'; import * as Debug from 'debug'; import * as lodash from 'lodash'; -import { copyDirectory, mkdirp, pathExists, readDir, removeDirectory, stat } from '@ionic/utils-fs'; +import { copyDirectory, mkdirp, pathExists, readDirSafe, removeDirectory, stat } from '@ionic/utils-fs'; import { IConfig, IIntegration, IIntegrationAddOptions, ILogger, IProject, IShell, InfoItem, IntegrationName, ProjectPersonalizationDetails } from '../../definitions'; import { IntegrationNotFoundException } from '../errors'; @@ -92,7 +92,7 @@ export abstract class BaseIntegration implements IIntegration { const { req } = await createRequest('GET', this.archiveUrl, this.e.config.getHTTPConfig()); await download(req, ws, {}); - const contents = await readDir(tmpdir); + const contents = await readDirSafe(tmpdir); const blacklist: string[] = []; debug(`Integration files downloaded to ${chalk.bold(tmpdir)} (files: ${contents.map(f => chalk.bold(f)).join(', ')})`); diff --git a/packages/@ionic/utils-fs/package.json b/packages/@ionic/utils-fs/package.json index 27cc1e14e3..17d07dbc06 100644 --- a/packages/@ionic/utils-fs/package.json +++ b/packages/@ionic/utils-fs/package.json @@ -38,16 +38,16 @@ }, "dependencies": { "debug": "^3.1.0", - "klaw": "^3.0.0", "ncp": "^2.0.0", + "through2": "^2.0.3", "tslib": "^1.9.0", "write-file-atomic": "^2.3.0" }, "devDependencies": { "@types/debug": "0.0.30", - "@types/klaw": "^2.1.1", "@types/ncp": "^2.0.1", "@types/node": "^6.0.101", + "@types/through2": "^2.0.33", "@types/write-file-atomic": "^2.1.1", "jest": "^23.0.1", "jest-cli": "^23.0.1", diff --git a/packages/@ionic/utils-fs/src/index.ts b/packages/@ionic/utils-fs/src/index.ts index d01e838876..954d6dddb9 100644 --- a/packages/@ionic/utils-fs/src/index.ts +++ b/packages/@ionic/utils-fs/src/index.ts @@ -1,6 +1,8 @@ import * as fs from 'fs'; import * as os from 'os'; import * as path from 'path'; +import * as stream from 'stream'; +import * as through2 from 'through2'; import * as ζncp from 'ncp'; import * as wfa from 'write-file-atomic'; @@ -28,12 +30,12 @@ const promisify: Promisify = (func: any) => { }; }; -export interface FSReadFileOptions { +export interface ReadFileOptions { encoding: string; flag?: string; } -export interface FSWriteFileOptions { +export interface WriteFileOptions { encoding: string; mode?: number; flag?: string; @@ -44,40 +46,63 @@ export const mkdir = promisify(fs.mkdir); export const open = promisify(fs.open); export const stat = promisify(fs.stat); export const unlink = promisify(fs.unlink); -export const readFile = promisify(fs.readFile); -export const writeFile = promisify(fs.writeFile); +export const readFile = promisify(fs.readFile); +export const writeFile = promisify(fs.writeFile); export const readDir = promisify(fs.readdir); export const writeFileAtomic = promisify(wfa); export const writeFileAtomicSync = wfa.sync; -/** - * Error-less, promisified `fs.readdir` that recurses into subdirectories. - * - * This function will not throw errors. If there is an issue with the - * directory, an empty array is returned. - * - * @param dir The path to the directory to read. - */ -export async function readDirp(dir: string): Promise { - const klaw = await import('klaw'); +export async function statSafe(p: string): Promise { + try { + return await stat(p); + } catch (e) { + // ignore + } +} + +export interface ReadDirROptions { + readonly filter?: (item: WalkerItem) => boolean; + readonly walkerOptions?: WalkerOptions; +} +export async function readDirp(dir: string, { filter, walkerOptions }: ReadDirROptions = {}): Promise { return new Promise((resolve, reject) => { const items: string[] = []; - klaw(dir) - .on('error', err => { /* ignore */ }) - .on('data', item => items.push(item.path)) + let rs: NodeJS.ReadableStream = walk(dir, walkerOptions); + + if (filter) { + rs = rs.pipe(through2.obj(function(obj: WalkerItem, enc, cb) { + if (!filter || filter(obj)) { + this.push(obj); + } + + cb(); + })); + } + + rs + .on('error', (err: Error) => reject(err)) + .on('data', (item: WalkerItem) => items.push(item.path)) .on('end', () => resolve(items)); }); } -export async function readJsonFile(filePath: string, options: FSReadFileOptions = { encoding: 'utf8' }): Promise<{ [key: string]: any }> { +export async function readDirSafe(dir: string): Promise { + try { + return await readDir(dir); + } catch (e) { + return []; + } +} + +export async function readJsonFile(filePath: string, options: ReadFileOptions = { encoding: 'utf8' }): Promise<{ [key: string]: any }> { const f = await readFile(filePath, options); return JSON.parse(f); } -export async function writeJsonFile(filePath: string, json: { [key: string]: any; }, options: FSWriteFileOptions): Promise { +export async function writeJsonFile(filePath: string, json: { [key: string]: any; }, options: WriteFileOptions): Promise { return writeFile(filePath, JSON.stringify(json, undefined, 2) + '\n', options); } @@ -251,7 +276,7 @@ export async function findBaseDirectory(dir: string, file: string): Promise parsed.root + path.join(...array.slice(0, array.length - i))) .concat(parsed.root); } + +export async function isDir(p: string): Promise { + const stats = await statSafe(p); + + if (stats && stats.isDirectory()) { + return true; + } + + return false; +} + +export interface WalkerItem { + readonly path: string; + readonly stats: fs.Stats; +} + +export interface Walker extends stream.Readable { + on(event: 'data', callback: (item: WalkerItem) => void): this; + on(event: string, callback: (...args: any[]) => any): this; +} + +export interface WalkerOptions { + pathFilter?: (p: string) => boolean; +} + +export class Walker extends stream.Readable { + readonly paths: string[] = [this.p]; + + constructor(readonly p: string, readonly options: WalkerOptions = {}) { + super({ objectMode: true }); + } + + _read() { + const p = this.paths.shift(); + const { pathFilter } = this.options; + + if (!p) { + this.push(null); // tslint:disable-line:no-null-keyword + return; + } + + fs.stat(p, (err, stats) => { + if (err) { + this.emit('error', err); + return; + } + + const item: WalkerItem = { path: p, stats }; + + if (stats.isDirectory()) { + fs.readdir(p, (err, contents) => { + if (err) { + this.emit('error', err); + return; + } + + let paths = contents.map(file => path.join(p, file)); + + if (pathFilter) { + paths = paths.filter(p => pathFilter(p.substring(this.p.length + 1))); + } + + this.paths.push(...paths); + this.push(item); + }); + } else { + this.push(item); + } + }); + } +} + +export function walk(p: string, options: WalkerOptions = {}): Walker { + return new Walker(p, options); +} diff --git a/packages/ionic/src/commands/monitoring/syncmaps.ts b/packages/ionic/src/commands/monitoring/syncmaps.ts index 730a1fe848..ad87b711b3 100644 --- a/packages/ionic/src/commands/monitoring/syncmaps.ts +++ b/packages/ionic/src/commands/monitoring/syncmaps.ts @@ -8,7 +8,7 @@ import { APIResponseSuccess, CommandLineInputs, CommandLineOptions, CommandMetad import { build } from '@ionic/cli-utils/lib/build'; import { Command } from '@ionic/cli-utils/lib/command'; import { FatalException } from '@ionic/cli-utils/lib/errors'; -import { pathExists, readDir, readFile } from '@ionic/utils-fs'; +import { pathExists, readDirSafe, readFile } from '@ionic/utils-fs'; const debug = Debug('ionic:cli:commands:monitoring:syncmaps'); @@ -81,7 +81,7 @@ By default, ${chalk.green('ionic monitoring syncmaps')} will upload the sourcema const tasks = this.createTaskChain(); const syncTask = tasks.next('Syncing sourcemaps'); - const sourcemapFiles = (await readDir(sourcemapsDir)).filter(f => f.endsWith('.js.map')); + const sourcemapFiles = (await readDirSafe(sourcemapsDir)).filter(f => f.endsWith('.js.map')); debug(`Found ${sourcemapFiles.length} sourcemap files: ${sourcemapFiles.map(f => chalk.bold(f)).join(', ')}`); await Promise.all(sourcemapFiles.map(async f => { From c289f1cb4f0af78248f5d0305f11a778b5439bdd Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 18:42:22 -0500 Subject: [PATCH 15/18] refactor(fs): do not require write-file-atomic --- packages/@ionic/cli-framework/package.json | 4 +++- packages/@ionic/cli-framework/src/lib/__tests__/config.ts | 6 ++++-- packages/@ionic/cli-framework/src/lib/config.ts | 7 ++++--- packages/@ionic/utils-fs/package.json | 4 +--- packages/@ionic/utils-fs/src/index.ts | 4 ---- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/@ionic/cli-framework/package.json b/packages/@ionic/cli-framework/package.json index 61c3c9985f..e8d797e9fe 100644 --- a/packages/@ionic/cli-framework/package.json +++ b/packages/@ionic/cli-framework/package.json @@ -42,7 +42,8 @@ "tree-kill": "1.2.0", "tslib": "^1.9.0", "untildify": "^3.0.2", - "wrap-ansi": "^4.0.0" + "wrap-ansi": "^4.0.0", + "write-file-atomic": "^2.3.0" }, "devDependencies": { "@types/cross-spawn": "^6.0.0", @@ -56,6 +57,7 @@ "@types/strip-ansi": "^3.0.0", "@types/untildify": "^3.0.0", "@types/wrap-ansi": "^3.0.0", + "@types/write-file-atomic": "^2.1.1", "jest": "^23.0.1", "jest-cli": "^23.0.1", "lint-staged": "^7.2.0", diff --git a/packages/@ionic/cli-framework/src/lib/__tests__/config.ts b/packages/@ionic/cli-framework/src/lib/__tests__/config.ts index bfd3b1efa3..03cda61eea 100644 --- a/packages/@ionic/cli-framework/src/lib/__tests__/config.ts +++ b/packages/@ionic/cli-framework/src/lib/__tests__/config.ts @@ -10,7 +10,8 @@ describe('@ionic/cli-framework', () => { mockWriteFileAtomicSync = jest.fn(); jest.resetModules(); jest.mock('fs', () => ({ readFileSync: mockReadFileSync })); - jest.mock('@ionic/utils-fs', () => ({ mkdirpSync: mockMakeDirSync, writeFileAtomicSync: mockWriteFileAtomicSync })); + jest.mock('@ionic/utils-fs', () => ({ mkdirpSync: mockMakeDirSync })); + jest.mock('write-file-atomic', () => ({ sync: mockWriteFileAtomicSync })); const { BaseConfig } = require('../config'); @@ -164,7 +165,8 @@ describe('@ionic/cli-framework', () => { mockWriteFileAtomicSync = jest.fn(); jest.resetModules(); jest.mock('fs', () => ({ readFileSync: mockReadFileSync })); - jest.mock('@ionic/utils-fs', () => ({ mkdirpSync: mockMakeDirSync, writeFileAtomicSync: mockWriteFileAtomicSync })); + jest.mock('@ionic/utils-fs', () => ({ mkdirpSync: mockMakeDirSync })); + jest.mock('write-file-atomic', () => ({ sync: mockWriteFileAtomicSync })); const { BaseConfig } = require('../config'); diff --git a/packages/@ionic/cli-framework/src/lib/config.ts b/packages/@ionic/cli-framework/src/lib/config.ts index f49ff4f1dc..7c38cc48f2 100644 --- a/packages/@ionic/cli-framework/src/lib/config.ts +++ b/packages/@ionic/cli-framework/src/lib/config.ts @@ -1,7 +1,8 @@ -import { mkdirpSync, writeFileAtomicSync } from '@ionic/utils-fs'; +import { mkdirpSync } from '@ionic/utils-fs'; import * as fs from 'fs'; import * as lodash from 'lodash'; import * as path from 'path'; +import * as writeFileAtomic from 'write-file-atomic'; export interface BaseConfigOptions { /** @@ -39,7 +40,7 @@ export abstract class BaseConfig { } if (e.name === 'SyntaxError') { - writeFileAtomicSync(this.p, ''); + writeFileAtomic.sync(this.p, ''); return this.provideDefaults({}); } @@ -51,7 +52,7 @@ export abstract class BaseConfig { const v = this.pathPrefix.length === 0 ? value : lodash.set(this.file, [...this.pathPrefix], value); mkdirpSync(path.dirname(this.p)); - writeFileAtomicSync(this.p, JSON.stringify(v, undefined, 2)); + writeFileAtomic.sync(this.p, JSON.stringify(v, undefined, 2)); } get

(property: P): T[P]; diff --git a/packages/@ionic/utils-fs/package.json b/packages/@ionic/utils-fs/package.json index 17d07dbc06..15c0ffce72 100644 --- a/packages/@ionic/utils-fs/package.json +++ b/packages/@ionic/utils-fs/package.json @@ -40,15 +40,13 @@ "debug": "^3.1.0", "ncp": "^2.0.0", "through2": "^2.0.3", - "tslib": "^1.9.0", - "write-file-atomic": "^2.3.0" + "tslib": "^1.9.0" }, "devDependencies": { "@types/debug": "0.0.30", "@types/ncp": "^2.0.1", "@types/node": "^6.0.101", "@types/through2": "^2.0.33", - "@types/write-file-atomic": "^2.1.1", "jest": "^23.0.1", "jest-cli": "^23.0.1", "lint-staged": "^7.2.0", diff --git a/packages/@ionic/utils-fs/src/index.ts b/packages/@ionic/utils-fs/src/index.ts index 954d6dddb9..a77409f54c 100644 --- a/packages/@ionic/utils-fs/src/index.ts +++ b/packages/@ionic/utils-fs/src/index.ts @@ -5,7 +5,6 @@ import * as stream from 'stream'; import * as through2 from 'through2'; import * as ζncp from 'ncp'; -import * as wfa from 'write-file-atomic'; interface Promisify { (func: (callback: (err: any, result?: T) => void) => void): () => Promise; @@ -50,9 +49,6 @@ export const readFile = promisify(fs.readFile); export const writeFile = promisify(fs.writeFile); export const readDir = promisify(fs.readdir); -export const writeFileAtomic = promisify(wfa); -export const writeFileAtomicSync = wfa.sync; - export async function statSafe(p: string): Promise { try { return await stat(p); From d2a1450b4cd6f1300a9e0e2fa8f5c0d243d1efb1 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 18:52:54 -0500 Subject: [PATCH 16/18] chore: add license to @ionic/schematics-angular fixes https://github.com/ionic-team/ionic-cli/issues/3553 --- packages/@ionic/schematics-angular/LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 packages/@ionic/schematics-angular/LICENSE diff --git a/packages/@ionic/schematics-angular/LICENSE b/packages/@ionic/schematics-angular/LICENSE new file mode 100644 index 0000000000..7c5808ced6 --- /dev/null +++ b/packages/@ionic/schematics-angular/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Drifty Co + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 81a45d5302964c463f26ec3bbe35a779f62e6343 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Tue, 4 Sep 2018 19:28:38 -0500 Subject: [PATCH 17/18] fix(capacitor): use integration root for Capacitor CLI related to https://github.com/ionic-team/ionic-cli/issues/3494 --- packages/ionic/src/commands/capacitor/base.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/ionic/src/commands/capacitor/base.ts b/packages/ionic/src/commands/capacitor/base.ts index 0672dc5eb5..ecd42ad1fe 100644 --- a/packages/ionic/src/commands/capacitor/base.ts +++ b/packages/ionic/src/commands/capacitor/base.ts @@ -98,6 +98,12 @@ export abstract class CapacitorCommand extends Command { } private async _runCapacitor(argList: string[]) { - await this.env.shell.run('capacitor', argList, { fatalOnNotFound: false, truncateErrorOutput: 5000, stdio: 'inherit' }); + if (!this.project) { + throw new FatalException(`Cannot use Capacitor outside a project directory.`); + } + + const { root: cwd } = await this.project.getIntegration('capacitor'); + + await this.env.shell.run('capacitor', argList, { fatalOnNotFound: false, truncateErrorOutput: 5000, stdio: 'inherit', cwd }); } } From 08c9d1e634be70b2cba9c8d2111e71e615cb8bd5 Mon Sep 17 00:00:00 2001 From: Ionitron Date: Wed, 5 Sep 2018 00:39:19 +0000 Subject: [PATCH 18/18] chore(release): publish [skip ci] - @ionic/cli-framework@1.0.7 - @ionic/cli-utils@2.2.1 - @ionic/lab@1.0.9 - @ionic/ng-toolkit@1.0.8 - @ionic/schematics-angular@1.0.6 - @ionic/utils-fs@0.0.1 - @ionic/utils-network@0.0.1 - @ionic/v1-toolkit@1.0.8 - cli-scripts@0.0.18 - ionic@4.1.2 --- packages/@ionic/cli-framework/CHANGELOG.md | 8 ++++++++ packages/@ionic/cli-framework/package.json | 4 ++-- packages/@ionic/cli-utils/CHANGELOG.md | 8 ++++++++ packages/@ionic/cli-utils/package.json | 8 ++++---- packages/@ionic/lab/CHANGELOG.md | 8 ++++++++ packages/@ionic/lab/package.json | 6 +++--- packages/@ionic/ng-toolkit/CHANGELOG.md | 8 ++++++++ packages/@ionic/ng-toolkit/package.json | 4 ++-- packages/@ionic/schematics-angular/CHANGELOG.md | 8 ++++++++ packages/@ionic/schematics-angular/package.json | 2 +- packages/@ionic/utils-fs/CHANGELOG.md | 13 +++++++++++++ packages/@ionic/utils-fs/package.json | 2 +- packages/@ionic/utils-network/CHANGELOG.md | 13 +++++++++++++ packages/@ionic/utils-network/package.json | 2 +- packages/@ionic/v1-toolkit/CHANGELOG.md | 8 ++++++++ packages/@ionic/v1-toolkit/package.json | 6 +++--- packages/cli-scripts/CHANGELOG.md | 8 ++++++++ packages/cli-scripts/package.json | 10 +++++----- packages/ionic/CHANGELOG.md | 11 +++++++++++ packages/ionic/package.json | 8 ++++---- 20 files changed, 119 insertions(+), 26 deletions(-) diff --git a/packages/@ionic/cli-framework/CHANGELOG.md b/packages/@ionic/cli-framework/CHANGELOG.md index 901431290e..86c196400e 100644 --- a/packages/@ionic/cli-framework/CHANGELOG.md +++ b/packages/@ionic/cli-framework/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.0.7](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-framework@1.0.6...@ionic/cli-framework@1.0.7) (2018-09-05) + + + + +**Note:** Version bump only for package @ionic/cli-framework + ## [1.0.6](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-framework@1.0.5...@ionic/cli-framework@1.0.6) (2018-08-20) diff --git a/packages/@ionic/cli-framework/package.json b/packages/@ionic/cli-framework/package.json index e8d797e9fe..ca01f11cf8 100644 --- a/packages/@ionic/cli-framework/package.json +++ b/packages/@ionic/cli-framework/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/cli-framework", - "version": "1.0.6", + "version": "1.0.7", "description": "The foundation framework of the Ionic CLI", "homepage": "https://ionicframework.com/", "author": "Ionic Team (https://ionicframework.com) ", @@ -28,7 +28,7 @@ }, "license": "MIT", "dependencies": { - "@ionic/utils-fs": "0.0.0", + "@ionic/utils-fs": "0.0.1", "chalk": "^2.3.0", "debug": "^3.1.0", "inquirer": "^6.0.0", diff --git a/packages/@ionic/cli-utils/CHANGELOG.md b/packages/@ionic/cli-utils/CHANGELOG.md index 929a521b2c..b4ae3682f0 100644 --- a/packages/@ionic/cli-utils/CHANGELOG.md +++ b/packages/@ionic/cli-utils/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [2.2.1](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-utils@2.2.0...@ionic/cli-utils@2.2.1) (2018-09-05) + + + + +**Note:** Version bump only for package @ionic/cli-utils + # [2.2.0](https://github.com/ionic-team/ionic-cli/compare/@ionic/cli-utils@2.1.0...@ionic/cli-utils@2.2.0) (2018-08-20) diff --git a/packages/@ionic/cli-utils/package.json b/packages/@ionic/cli-utils/package.json index a5ed1502f6..3d98181152 100644 --- a/packages/@ionic/cli-utils/package.json +++ b/packages/@ionic/cli-utils/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/cli-utils", - "version": "2.2.0", + "version": "2.2.1", "description": "Ionic CLI Utils", "homepage": "https://ionicframework.com", "author": "Ionic Team (https://ionicframework.com)", @@ -46,10 +46,10 @@ }, "license": "MIT", "dependencies": { - "@ionic/cli-framework": "1.0.6", + "@ionic/cli-framework": "1.0.7", "@ionic/discover": "1.0.4", - "@ionic/utils-fs": "0.0.0", - "@ionic/utils-network": "0.0.0", + "@ionic/utils-fs": "0.0.1", + "@ionic/utils-network": "0.0.1", "chalk": "^2.3.0", "debug": "^3.1.0", "diff": "^3.4.0", diff --git a/packages/@ionic/lab/CHANGELOG.md b/packages/@ionic/lab/CHANGELOG.md index 44527bb01c..2bfe3e9634 100644 --- a/packages/@ionic/lab/CHANGELOG.md +++ b/packages/@ionic/lab/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.0.9](https://github.com/ionic-team/ionic-cli/compare/@ionic/lab@1.0.8...@ionic/lab@1.0.9) (2018-09-05) + + + + +**Note:** Version bump only for package @ionic/lab + ## [1.0.8](https://github.com/ionic-team/ionic-cli/compare/@ionic/lab@1.0.7...@ionic/lab@1.0.8) (2018-08-20) diff --git a/packages/@ionic/lab/package.json b/packages/@ionic/lab/package.json index 5ef411e104..3093efcac4 100644 --- a/packages/@ionic/lab/package.json +++ b/packages/@ionic/lab/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/lab", - "version": "1.0.8", + "version": "1.0.9", "description": "Ionic Lab utility for developing Ionic apps, used by Ionic CLI", "bin": { "ionic-lab": "./bin/ionic-lab" @@ -47,8 +47,8 @@ ] }, "dependencies": { - "@ionic/cli-framework": "1.0.6", - "@ionic/utils-fs": "0.0.0", + "@ionic/cli-framework": "1.0.7", + "@ionic/utils-fs": "0.0.1", "chalk": "^2.3.0", "express": "^4.16.2", "tslib": "^1.9.0" diff --git a/packages/@ionic/ng-toolkit/CHANGELOG.md b/packages/@ionic/ng-toolkit/CHANGELOG.md index dd373764cc..1a970f1b10 100644 --- a/packages/@ionic/ng-toolkit/CHANGELOG.md +++ b/packages/@ionic/ng-toolkit/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.0.8](https://github.com/ionic-team/ionic-cli/compare/@ionic/ng-toolkit@1.0.7...@ionic/ng-toolkit@1.0.8) (2018-09-05) + + + + +**Note:** Version bump only for package @ionic/ng-toolkit + ## [1.0.7](https://github.com/ionic-team/ionic-cli/compare/@ionic/ng-toolkit@1.0.6...@ionic/ng-toolkit@1.0.7) (2018-08-20) diff --git a/packages/@ionic/ng-toolkit/package.json b/packages/@ionic/ng-toolkit/package.json index dfcfa4a97d..1093e533a6 100644 --- a/packages/@ionic/ng-toolkit/package.json +++ b/packages/@ionic/ng-toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/ng-toolkit", - "version": "1.0.7", + "version": "1.0.8", "description": "Utilities for ionic/angular v4+ apps, used by Ionic CLI", "bin": { "ionic-ng": "./bin/ionic-ng" @@ -42,7 +42,7 @@ ] }, "dependencies": { - "@ionic/cli-framework": "1.0.6", + "@ionic/cli-framework": "1.0.7", "chalk": "^2.3.0", "debug": "^3.1.0", "rxjs": "~6.2.0", diff --git a/packages/@ionic/schematics-angular/CHANGELOG.md b/packages/@ionic/schematics-angular/CHANGELOG.md index 4c0f6140ef..cf4945f375 100644 --- a/packages/@ionic/schematics-angular/CHANGELOG.md +++ b/packages/@ionic/schematics-angular/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.0.6](https://github.com/ionic-team/ionic-cli/compare/@ionic/schematics-angular@1.0.5...@ionic/schematics-angular@1.0.6) (2018-09-05) + + + + +**Note:** Version bump only for package @ionic/schematics-angular + ## [1.0.5](https://github.com/ionic-team/ionic-cli/compare/@ionic/schematics-angular@1.0.4...@ionic/schematics-angular@1.0.5) (2018-08-15) diff --git a/packages/@ionic/schematics-angular/package.json b/packages/@ionic/schematics-angular/package.json index d86f3bac67..a1dd86fd18 100644 --- a/packages/@ionic/schematics-angular/package.json +++ b/packages/@ionic/schematics-angular/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/schematics-angular", - "version": "1.0.5", + "version": "1.0.6", "description": "Schematics specific to Ionic for Angular", "homepage": "https://ionicframework.com/", "author": "Ionic Team (https://ionicframework.com) ", diff --git a/packages/@ionic/utils-fs/CHANGELOG.md b/packages/@ionic/utils-fs/CHANGELOG.md index 420e6f23d0..51df87e1aa 100644 --- a/packages/@ionic/utils-fs/CHANGELOG.md +++ b/packages/@ionic/utils-fs/CHANGELOG.md @@ -1 +1,14 @@ # Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + + +## 0.0.1 (2018-09-05) + + + + +**Note:** Version bump only for package @ionic/utils-fs + +# Change Log diff --git a/packages/@ionic/utils-fs/package.json b/packages/@ionic/utils-fs/package.json index 15c0ffce72..fe0abd1119 100644 --- a/packages/@ionic/utils-fs/package.json +++ b/packages/@ionic/utils-fs/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/utils-fs", - "version": "0.0.0", + "version": "0.0.1", "description": "Filesystem utils for Node", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/@ionic/utils-network/CHANGELOG.md b/packages/@ionic/utils-network/CHANGELOG.md index 420e6f23d0..c9bbc634ff 100644 --- a/packages/@ionic/utils-network/CHANGELOG.md +++ b/packages/@ionic/utils-network/CHANGELOG.md @@ -1 +1,14 @@ # Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + + +## 0.0.1 (2018-09-05) + + + + +**Note:** Version bump only for package @ionic/utils-network + +# Change Log diff --git a/packages/@ionic/utils-network/package.json b/packages/@ionic/utils-network/package.json index e402e6b341..971dbcb888 100644 --- a/packages/@ionic/utils-network/package.json +++ b/packages/@ionic/utils-network/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/utils-network", - "version": "0.0.0", + "version": "0.0.1", "description": "Network utils for Node", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/@ionic/v1-toolkit/CHANGELOG.md b/packages/@ionic/v1-toolkit/CHANGELOG.md index 7e83621e50..378da66782 100644 --- a/packages/@ionic/v1-toolkit/CHANGELOG.md +++ b/packages/@ionic/v1-toolkit/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [1.0.8](https://github.com/ionic-team/ionic-cli/compare/@ionic/v1-toolkit@1.0.7...@ionic/v1-toolkit@1.0.8) (2018-09-05) + + + + +**Note:** Version bump only for package @ionic/v1-toolkit + ## [1.0.7](https://github.com/ionic-team/ionic-cli/compare/@ionic/v1-toolkit@1.0.6...@ionic/v1-toolkit@1.0.7) (2018-08-20) diff --git a/packages/@ionic/v1-toolkit/package.json b/packages/@ionic/v1-toolkit/package.json index 8918066065..455248148d 100644 --- a/packages/@ionic/v1-toolkit/package.json +++ b/packages/@ionic/v1-toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@ionic/v1-toolkit", - "version": "1.0.7", + "version": "1.0.8", "description": "Utility CLI for Ionic 1.x apps, used by Ionic CLI", "bin": { "ionic-v1": "./bin/ionic-v1" @@ -42,8 +42,8 @@ ] }, "dependencies": { - "@ionic/cli-framework": "1.0.6", - "@ionic/utils-fs": "0.0.0", + "@ionic/cli-framework": "1.0.7", + "@ionic/utils-fs": "0.0.1", "chalk": "^2.3.0", "chokidar": "^2.0.0", "debug": "^3.1.0", diff --git a/packages/cli-scripts/CHANGELOG.md b/packages/cli-scripts/CHANGELOG.md index ee98966b65..cc2cbbd42a 100644 --- a/packages/cli-scripts/CHANGELOG.md +++ b/packages/cli-scripts/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [0.0.18](https://github.com/ionic-team/ionic-cli/compare/cli-scripts@0.0.17...cli-scripts@0.0.18) (2018-09-05) + + + + +**Note:** Version bump only for package cli-scripts + ## [0.0.17](https://github.com/ionic-team/ionic-cli/compare/cli-scripts@0.0.16...cli-scripts@0.0.17) (2018-08-20) diff --git a/packages/cli-scripts/package.json b/packages/cli-scripts/package.json index e6ae9367f2..40c8f4c0b4 100644 --- a/packages/cli-scripts/package.json +++ b/packages/cli-scripts/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "cli-scripts", - "version": "0.0.17", + "version": "0.0.18", "bin": { "ionic-cli-scripts": "./bin/ionic-cli-scripts" }, @@ -25,13 +25,13 @@ "main": "./dist/index.js", "types": "./dist/index.d.ts", "dependencies": { - "@ionic/cli-framework": "1.0.6", - "@ionic/cli-utils": "2.2.0", - "@ionic/utils-fs": "0.0.0", + "@ionic/cli-framework": "1.0.7", + "@ionic/cli-utils": "2.2.1", + "@ionic/utils-fs": "0.0.1", "ansi-styles": "^3.2.0", "chalk": "^2.3.0", "escape-string-regexp": "^1.0.5", - "ionic": "4.1.1", + "ionic": "4.1.2", "strip-ansi": "^4.0.0", "tslib": "^1.9.0" }, diff --git a/packages/ionic/CHANGELOG.md b/packages/ionic/CHANGELOG.md index afd9f2a72c..da7ded734c 100644 --- a/packages/ionic/CHANGELOG.md +++ b/packages/ionic/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. + +## [4.1.2](https://github.com/ionic-team/ionic-cli/compare/ionic@4.1.1...ionic@4.1.2) (2018-09-05) + + +### Bug Fixes + +* **capacitor:** use integration root for Capacitor CLI ([81a45d5](https://github.com/ionic-team/ionic-cli/commit/81a45d5)) + + + + ## [4.1.1](https://github.com/ionic-team/ionic-cli/compare/ionic@4.1.0...ionic@4.1.1) (2018-08-20) diff --git a/packages/ionic/package.json b/packages/ionic/package.json index aa29fb6c05..b17f8432bf 100644 --- a/packages/ionic/package.json +++ b/packages/ionic/package.json @@ -1,6 +1,6 @@ { "name": "ionic", - "version": "4.1.1", + "version": "4.1.2", "description": "A tool for creating and developing Ionic Framework mobile apps.", "homepage": "https://ionicframework.com", "author": "Ionic Team (https://ionicframework.com) ", @@ -53,9 +53,9 @@ }, "license": "MIT", "dependencies": { - "@ionic/cli-framework": "1.0.6", - "@ionic/cli-utils": "2.2.0", - "@ionic/utils-fs": "0.0.0", + "@ionic/cli-framework": "1.0.7", + "@ionic/cli-utils": "2.2.1", + "@ionic/utils-fs": "0.0.1", "chalk": "^2.3.0", "debug": "^3.1.0", "lodash": "^4.17.5",