-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Increased specificity of Windows platform check #2262
Conversation
@@ -68,7 +68,7 @@ export async function run( | |||
for (const action of actions) { | |||
const cmd = scripts[action]; | |||
if (cmd) { | |||
const isWin = /win/.test(process.platform); | |||
const isWin = /win32/.test(process.platform); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this just be process.platform === 'win32'
? Looks like that's what Node.js itself does, so it should be safe: https://github.com/nodejs/node/blob/db1087c9757c31a82c50a1eba368d8cba95b57d0/lib/os.js#L6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly. I noticed another section in execute-lifecycle that does just that.
@@ -131,3 +131,11 @@ export async function run<T, R>( | |||
throw new Error(`${err && err.stack} \nConsole output:\n ${out}`); | |||
} | |||
} | |||
export const setPlatform = (platform : string) : string => { | |||
const previous = process.platform; | |||
Object.defineProperty(process, 'platform', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish Node.js had a decent dependency injection framework, this is super hacky 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to redo that. It's not effective at all 😰 I originally was pondering just passing platform into run so the test could directly send it, but, to your point, that seems corny.
The original test asserts that window cmd line formatting is properly applied or not applied, for only the target platform the tests are executed on - that will have to be good enough. It is not possible to test both branches from one platform because the path module employed in the test alters its export based on process.platform in Node bootstrap, well before one can mock it.
Summary
Extended regex to match only Windows. Previous regex was matching Darwin in addition to Windows.
yarn run test > all tests pass.
#2261