From a75fd0ef17b94f002166f894c357a1dee02cc97e Mon Sep 17 00:00:00 2001 From: bibo5088 Date: Sat, 31 Aug 2019 20:27:34 +0200 Subject: [PATCH] fix: remove is-windows dependency (#207) --- .all-contributorsrc | 9 ++++++++ README.md | 8 ++++--- package.json | 3 +-- {__mocks__ => src/__mocks__}/is-windows.js | 0 src/__tests__/command.js | 4 +++- src/__tests__/index.js | 4 +++- src/__tests__/is-windows.js | 25 ++++++++++++++++++++++ src/__tests__/variable.js | 4 +++- src/command.js | 2 +- src/is-windows.js | 1 + src/variable.js | 2 +- 11 files changed, 52 insertions(+), 10 deletions(-) rename {__mocks__ => src/__mocks__}/is-windows.js (100%) create mode 100644 src/__tests__/is-windows.js create mode 100644 src/is-windows.js diff --git a/.all-contributorsrc b/.all-contributorsrc index 4d0ab62..e1d3d42 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -193,6 +193,15 @@ "contributions": [ "doc" ] + }, + { + "login": "bibo5088", + "name": "bibo5088", + "avatar_url": "https://avatars0.githubusercontent.com/u/17709887?v=4", + "profile": "https://github.com/bibo5088", + "contributions": [ + "code" + ] } ], "repoHost": "https://github.com", diff --git a/README.md b/README.md index b4e3627..b973006 100755 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Run scripts that set and use environment variables across platforms [![downloads][downloads-badge]][npm-stat] [![MIT License][license-badge]][LICENSE] -[![All Contributors](https://img.shields.io/badge/all_contributors-18-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Donate][donate-badge]][donate] [![Code of Conduct][coc-badge]][coc] @@ -161,8 +161,10 @@ Thanks goes to these people ([emoji key][emojis]): -
Kent C. Dodds
Kent C. Dodds

πŸ’» πŸ“– πŸš‡ ⚠️
Ya Zhuang
Ya Zhuang

πŸ”Œ πŸ“–
James Harris
James Harris

πŸ“–
compumike08
compumike08

πŸ› πŸ“– ⚠️
Daniel RodrΓ­guez Rivero
Daniel RodrΓ­guez Rivero

πŸ› πŸ’» πŸ“–
Jonas Keinholz
Jonas Keinholz

πŸ› πŸ’» ⚠️
Hugo Wood
Hugo Wood

πŸ› πŸ’» ⚠️
Thiebaud Thomas
Thiebaud Thomas

πŸ› πŸ’» ⚠️
Daniel Rey LΓ³pez
Daniel Rey LΓ³pez

πŸ’» ⚠️
Amila Welihinda
Amila Welihinda

πŸš‡
Paul Betts
Paul Betts

πŸ› πŸ’»
Turner Hayes
Turner Hayes

πŸ› πŸ’» ⚠️
Suhas Karanth
Suhas Karanth

πŸ’» ⚠️
Sven
Sven

πŸ’» πŸ“– πŸ’‘ ⚠️
D. NicolΓ‘s Lopez Zelaya
D. NicolΓ‘s Lopez Zelaya

πŸ’»
Johan Hernandez
Johan Hernandez

πŸ’»
Jordan Nielson
Jordan Nielson

πŸ› πŸ’» ⚠️
Jason Cooke
Jason Cooke

πŸ“–
- +| [
Kent C. Dodds](https://kentcdodds.com)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Code") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Documentation") [πŸš‡](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=kentcdodds "Tests") | [
Ya Zhuang ](https://zhuangya.me)
[πŸ”Œ](#plugin-zhuangya "Plugin/utility libraries") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=zhuangya "Documentation") | [
James Harris](https://wopian.me)
[πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=wopian "Documentation") | [
compumike08](https://github.com/compumike08)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Acompumike08 "Bug reports") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=compumike08 "Documentation") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=compumike08 "Tests") | [
Daniel RodrΓ­guez Rivero](https://github.com/danielo515)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Adanielo515 "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=danielo515 "Code") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=danielo515 "Documentation") | [
Jonas Keinholz](https://github.com/inyono)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ainyono "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=inyono "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=inyono "Tests") | [
Hugo Wood](https://github.com/hgwood)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ahgwood "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=hgwood "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=hgwood "Tests") | +| :---: | :---: | :---: | :---: | :---: | :---: | :---: | +| [
Thiebaud Thomas](https://github.com/thomasthiebaud)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Athomasthiebaud "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=thomasthiebaud "Tests") | [
Daniel Rey LΓ³pez](https://daniel.blog)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=DanReyLop "Tests") | [
Amila Welihinda](http://amilajack.com)
[πŸš‡](#infra-amilajack "Infrastructure (Hosting, Build-Tools, etc)") | [
Paul Betts](https://twitter.com/paulcbetts)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Apaulcbetts "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=paulcbetts "Code") | [
Turner Hayes](https://github.com/turnerhayes)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Aturnerhayes "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=turnerhayes "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=turnerhayes "Tests") | [
Suhas Karanth](https://github.com/sudo-suhas)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=sudo-suhas "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=sudo-suhas "Tests") | [
Sven](https://github.com/sventschui)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=sventschui "Code") [πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=sventschui "Documentation") [πŸ’‘](#example-sventschui "Examples") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=sventschui "Tests") | +| [
D. NicolΓ‘s Lopez Zelaya](https://github.com/NicoZelaya)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=NicoZelaya "Code") | [
Johan Hernandez](http://bithavoc.io)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=bithavoc "Code") | [
Jordan Nielson](https://github.com/jnielson94)
[πŸ›](https://github.com/kentcdodds/cross-env/issues?q=author%3Ajnielson94 "Bug reports") [πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=jnielson94 "Code") [⚠️](https://github.com/kentcdodds/cross-env/commits?author=jnielson94 "Tests") | [
Jason Cooke](https://nz.linkedin.com/in/jsonc11)
[πŸ“–](https://github.com/kentcdodds/cross-env/commits?author=Jason-Cooke "Documentation") | [
bibo5088](https://github.com/bibo5088)
[πŸ’»](https://github.com/kentcdodds/cross-env/commits?author=bibo5088 "Code") | This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome! diff --git a/package.json b/package.json index c30e9fa..6123780 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,7 @@ "author": "Kent C. Dodds (http://kentcdodds.com/)", "license": "MIT", "dependencies": { - "cross-spawn": "^6.0.5", - "is-windows": "^1.0.0" + "cross-spawn": "^6.0.5" }, "devDependencies": { "kcd-scripts": "^0.3.4" diff --git a/__mocks__/is-windows.js b/src/__mocks__/is-windows.js similarity index 100% rename from __mocks__/is-windows.js rename to src/__mocks__/is-windows.js diff --git a/src/__tests__/command.js b/src/__tests__/command.js index eb7d8a2..f5dbf99 100644 --- a/src/__tests__/command.js +++ b/src/__tests__/command.js @@ -1,6 +1,8 @@ -import isWindowsMock from 'is-windows' +import isWindowsMock from '../is-windows' import commandConvert from '../command' +jest.mock('../is-windows') + const env = { test: 'a', test1: 'b', diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 0d073ce..5275528 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -1,5 +1,7 @@ import crossSpawnMock from 'cross-spawn' -import isWindowsMock from 'is-windows' +import isWindowsMock from '../is-windows' + +jest.mock('../is-windows') const crossEnv = require('../') diff --git a/src/__tests__/is-windows.js b/src/__tests__/is-windows.js new file mode 100644 index 0000000..aa1e128 --- /dev/null +++ b/src/__tests__/is-windows.js @@ -0,0 +1,25 @@ +import isWindows from "../is-windows" + +it(`should return true if the current OS is Windows`, () => { + process.platform = 'win32' + expect(isWindows()).toBe(true) + +}) + +it(`should return false if the current OS is not Windows`, () => { + process.platform = 'linux' + expect(isWindows()).toBe(false) +}) + +it(`should return true if the OSTYPE is cygwin or msys`, () => { + process.platform = 'linux' + + process.env.OSTYPE = 'cygwin' + expect(isWindows()).toBe(true) + + process.env.OSTYPE = 'msys' + expect(isWindows()).toBe(true) + + process.env.OSTYPE = '' + expect(isWindows()).toBe(false) +}) \ No newline at end of file diff --git a/src/__tests__/variable.js b/src/__tests__/variable.js index 9f3fbe9..a432a07 100644 --- a/src/__tests__/variable.js +++ b/src/__tests__/variable.js @@ -1,6 +1,8 @@ -import isWindowsMock from 'is-windows' +import isWindowsMock from '../is-windows' import varValueConvert from '../variable' +jest.mock('../is-windows') + const JSON_VALUE = '{\\"foo\\":\\"bar\\"}' beforeEach(() => { diff --git a/src/command.js b/src/command.js index a1605e0..af28f82 100644 --- a/src/command.js +++ b/src/command.js @@ -1,5 +1,5 @@ import path from 'path' -import isWindows from 'is-windows' +import isWindows from './is-windows' export default commandConvert diff --git a/src/is-windows.js b/src/is-windows.js new file mode 100644 index 0000000..b8e10d8 --- /dev/null +++ b/src/is-windows.js @@ -0,0 +1 @@ +export default () => process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE) \ No newline at end of file diff --git a/src/variable.js b/src/variable.js index 2bbcad9..ff14c0c 100644 --- a/src/variable.js +++ b/src/variable.js @@ -1,4 +1,4 @@ -import isWindows from 'is-windows' +import isWindows from './is-windows' const pathLikeEnvVarWhitelist = new Set(['PATH', 'NODE_PATH'])