From 2a6d09ded3f1cf93798be7f15db416c0522cc7db Mon Sep 17 00:00:00 2001 From: Liza Dayoub Date: Mon, 1 Oct 2018 19:06:58 -0600 Subject: [PATCH 1/2] Update paths to run on windows --- src/dev/file.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/dev/file.ts b/src/dev/file.ts index 2e576a02ed791..b7b4f6ca279f7 100644 --- a/src/dev/file.ts +++ b/src/dev/file.ts @@ -30,6 +30,10 @@ export class File { this.path = resolve(path); this.relativePath = relative(REPO_ROOT, this.path); this.ext = extname(this.path); + if (process.platform === 'win32') { + this.path = this.path.replace(/\\/g, '/'); + this.relativePath = this.relativePath.replace(/\\/g, '/'); + } } public getAbsolutePath() { @@ -57,13 +61,16 @@ export class File { while (true) { // NOTE: resolve() produces absolute paths, so we have to use join() - const parent = parents.length + let parent = parents.length ? join(parents[parents.length - 1], '..') : dirname(this.relativePath); if (parent === '..' || parent === '.') { break; } else { + if (process.platform === 'win32') { + parent = parent.replace(/\\/g, '/'); + } parents.push(parent); } } From 02824e0a3b7e57c5a08a6f080b48ebaefe8292f6 Mon Sep 17 00:00:00 2001 From: Liza Dayoub Date: Tue, 2 Oct 2018 10:32:46 -0600 Subject: [PATCH 2/2] Use upath package --- package.json | 1 + src/dev/file.ts | 11 ++--------- src/dev/npm/installed_packages.js | 2 +- yarn.lock | 4 ++++ 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index f2c760ed19cc1..f6700c45a1fb5 100644 --- a/package.json +++ b/package.json @@ -334,6 +334,7 @@ "tslint-config-prettier": "^1.15.0", "tslint-plugin-prettier": "^2.0.0", "typescript": "^3.0.3", + "upath": "^1.1.0", "vinyl-fs": "^3.0.2", "xml2js": "^0.4.19", "xmlbuilder": "9.0.4", diff --git a/src/dev/file.ts b/src/dev/file.ts index b7b4f6ca279f7..8e42f3be35b24 100644 --- a/src/dev/file.ts +++ b/src/dev/file.ts @@ -17,7 +17,7 @@ * under the License. */ -import { dirname, extname, join, relative, resolve, sep } from 'path'; +import { dirname, extname, join, relative, resolve, sep } from 'upath'; import { REPO_ROOT } from './constants'; @@ -30,10 +30,6 @@ export class File { this.path = resolve(path); this.relativePath = relative(REPO_ROOT, this.path); this.ext = extname(this.path); - if (process.platform === 'win32') { - this.path = this.path.replace(/\\/g, '/'); - this.relativePath = this.relativePath.replace(/\\/g, '/'); - } } public getAbsolutePath() { @@ -61,16 +57,13 @@ export class File { while (true) { // NOTE: resolve() produces absolute paths, so we have to use join() - let parent = parents.length + const parent = parents.length ? join(parents[parents.length - 1], '..') : dirname(this.relativePath); if (parent === '..' || parent === '.') { break; } else { - if (process.platform === 'win32') { - parent = parent.replace(/\\/g, '/'); - } parents.push(parent); } } diff --git a/src/dev/npm/installed_packages.js b/src/dev/npm/installed_packages.js index 4ec96084c38c5..75bc783dd2a12 100644 --- a/src/dev/npm/installed_packages.js +++ b/src/dev/npm/installed_packages.js @@ -17,7 +17,7 @@ * under the License. */ -import { relative, resolve } from 'path'; +import { relative, resolve } from 'upath'; import { readFileSync } from 'fs'; import { callLicenseChecker } from './license_checker'; diff --git a/yarn.lock b/yarn.lock index b7432f023e971..a1c062d529044 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13971,6 +13971,10 @@ upath@^1.0.0: version "1.0.4" resolved "https://registry.yarnpkg.com/upath/-/upath-1.0.4.tgz#ee2321ba0a786c50973db043a50b7bcba822361d" +upath@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/upath/-/upath-1.1.0.tgz#35256597e46a581db4793d0ce47fa9aebfc9fabd" + update-notifier@^0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/update-notifier/-/update-notifier-0.5.0.tgz#07b5dc2066b3627ab3b4f530130f7eddda07a4cc"