-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): append .cmd for npx & npm (#158)
Windows platform requires `npx` and `npm` cannot be directly invoked with `spawn`. To invoke them with `spawn` we now use the `*.cmd` executable. (this is probably due to the command interpreter on windows automagically appending `.cmd` when relevant. In the same vein, `ui:create:vue` has been fixed: Windows cannot spawn 'shebanged' NodeJS script directly (e.g. `spawn('foo.js')`). It needs to invoke it by passing the script path to node (e.g. `spawn(node, 'foo.js')`) https://coveord.atlassian.net/browse/CDX-245
- Loading branch information
1 parent
9a4743c
commit e67238b
Showing
18 changed files
with
133 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import {appendCmdIfWindows} from '../../utils/os'; | ||
import {getBinVersionPrecondition} from './binPreconditionsFactory'; | ||
|
||
export const IsNpmVersionInRange = getBinVersionPrecondition('npm'); | ||
export const IsNpmVersionInRange = getBinVersionPrecondition( | ||
appendCmdIfWindows`npm`, | ||
{prettyName: 'npm'} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import {appendCmdIfWindows} from '../../utils/os'; | ||
import {getBinInstalledPrecondition} from './binPreconditionsFactory'; | ||
|
||
export const IsNpxInstalled = getBinInstalledPrecondition('npx', { | ||
howToInstallBinText: 'Newer version Node.js comes bundled with npx.', | ||
}); | ||
export const IsNpxInstalled = getBinInstalledPrecondition( | ||
appendCmdIfWindows`npx`, | ||
{ | ||
prettyName: 'npx', | ||
howToInstallBinText: 'Newer version Node.js comes bundled with npx.', | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {appendCmdIfWindows} from './os'; | ||
|
||
describe('appendCmdIfWindows', () => { | ||
let originalProcess: PropertyDescriptor | undefined; | ||
afterEach(() => { | ||
originalProcess = Object.getOwnPropertyDescriptor(process, 'platform'); | ||
jest.resetAllMocks(); | ||
}); | ||
afterAll(() => { | ||
Object.defineProperty(process, 'platform', originalProcess!); | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should append cmd if process.platform is win32', () => { | ||
Object.defineProperty(process, 'platform', { | ||
writable: false, | ||
value: 'win32', | ||
}); | ||
|
||
return expect(appendCmdIfWindows`foo`).toEqual('foo.cmd'); | ||
}); | ||
|
||
it('should append cmd if process.platform is not win32', () => { | ||
Object.defineProperty(process, 'platform', { | ||
writable: false, | ||
value: 'linux', | ||
}); | ||
return expect(appendCmdIfWindows`foo`).toEqual('foo'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const appendCmdIfWindows = (cmd: TemplateStringsArray) => | ||
`${cmd}${process.platform === 'win32' ? '.cmd' : ''}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const {accessSync, constants} = require('fs'); | ||
const {resolve, join} = require('path'); | ||
const {setupSearchTokenServer} = require('./setup-server'); | ||
|
||
function main() { | ||
accessSync( | ||
resolve(join(process.cwd(), 'server', 'package.json')), | ||
constants.F_OK, | ||
() => { | ||
setupSearchTokenServer(); | ||
} | ||
); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const appendCmdIfWindows = (cmd) => | ||
`${cmd}${process.platform === 'win32' ? '.cmd' : ''}`; | ||
|
||
module.exports = {appendCmdIfWindows}; |
3 changes: 2 additions & 1 deletion
3
packages/vue-cli-plugin-typescript/generator/template/scripts/setup-server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
packages/vue-cli-plugin-typescript/generator/template/scripts/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
const appendCmdIfWindows = (cmd) => | ||
`${cmd}${process.platform === 'win32' ? '.cmd' : ''}`; | ||
|
||
module.exports = {appendCmdIfWindows}; |