Skip to content

Commit

Permalink
Using process.pkg to detect if it's running from brew binary
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloCore committed Jan 4, 2020
1 parent d48af07 commit 3bbcc44
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ x

<!-- Your comment below this -->

- Fix generated binary - [@hellocore]
<!-- Your comment above this -->

# 9.2.9
Expand Down
10 changes: 10 additions & 0 deletions source/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ declare module "parse-git-config"
declare module "parse-github-url"
// Basically does one thing
declare module "override-require"

declare namespace NodeJS {
interface Process {
// https://github.com/zeit/pkg#snapshot-filesystem
pkg?: {
entrypoint: string
defaultEntrypoint: string
}
}
}
34 changes: 34 additions & 0 deletions source/commands/utils/_tests/dangerRunToRunnerCLI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,37 @@ it("`danger pr --dangerfile 'myDanger file.ts'`", () => {
"myDanger file.ts",
])
})

describe("it can handle the command when running from pkg", () => {
beforeAll(() => {
process.pkg = {
defaultEntrypoint: "Hello",
entrypoint: "World",
}
})

afterAll(() => {
process.pkg = undefined
})

it("`./brew-distribution/danger /snapshot/danger-js/distribution/commands/danger-pr.js --dangerfile myDangerfile.ts`", () => {
/**
* The example of argv
* [ '/Users/core/Documents/project/danger-js/brew-distribution/danger',
* '/snapshot/danger-js/distribution/commands/danger-pr.js',
* 'https://bitbucket.org/foo/bar/pull-requests/381' ]
*/
expect(
dangerRunToRunnerCLI([
"./brew-distribution/danger",
"/snapshot/danger-js/distribution/commands/danger-pr.js",
"--dangerfile",
"myDangerfile.ts",
])
).toEqual(
"./brew-distribution/danger /snapshot/danger-js/distribution/commands/danger-runner.js --dangerfile myDangerfile.ts".split(
" "
)
)
})
})
2 changes: 1 addition & 1 deletion source/commands/utils/dangerRunToRunnerCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const dangerRunToRunnerCLI = (argv: string[]) => {

if (argv.length === 1) {
return ["danger", "runner"]
} else if (argv[0].includes("node")) {
} else if (argv[0].includes("node") || process.pkg != null) {
// convert
let newJSFile = argv[1]
usesProcessSeparationCommands.forEach(name => {
Expand Down

0 comments on commit 3bbcc44

Please sign in to comment.