Skip to content

Commit

Permalink
Try use requier from string to eval inside the inline runner
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Oct 14, 2017
1 parent a9536b3 commit 21ce74d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
8 changes: 5 additions & 3 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// This means we can re-use the type infra from the app, without having to
// fake the import.

console.log(global)
console.log(require)
console.log(require.extensions)
// console.log(global)
// console.log(require)
// console.log(require.extensions)

import { DangerDSL } from "./source/dsl/DangerDSL"
declare var danger: DangerDSL
Expand Down Expand Up @@ -46,6 +46,8 @@ schedule(yarn())
// This also serves as the "one true DSL" for a Danger run against a PR
// which tools can then work against.

// debugger

import dtsGenerator from "./scripts/danger-dts"
const currentDTS = dtsGenerator()
const savedDTS = fs.readFileSync("source/danger.d.ts").toString()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"parse-diff": "^0.4.0",
"parse-link-header": "^1.0.1",
"pinpoint": "^1.1.0",
"require-from-string": "^2.0.1",
"rfc6902": "^1.3.0",
"vm2": "patriksimek/vm2#custom_files",
"voca": "^1.2.0"
Expand Down
1 change: 1 addition & 0 deletions source/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ declare module "pinpoint"
declare module "*/package.json"

declare module "require-from-string"
declare module "node-eval"

// declare module "require-from-string" {
// export interface RequireOptions {
Expand Down
9 changes: 8 additions & 1 deletion source/runner/runners/inline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as fs from "fs"

import * as _require from "require-from-string"

import { DangerResults } from "../../dsl/DangerResults"
import { DangerContext } from "../../runner/Dangerfile"

Expand Down Expand Up @@ -80,8 +82,13 @@ export async function runDangerfileEnvironment(
// this[key] = element
}
}
// const myCWD = path.dirname(process.cwd())
// process.chdir(path.dirname(filename))
// eval(compiled)
// process.chdir(myCWD)

eval(compiled)
// _eval(compiled, filename, environment, true)
_require(compiled, filename, {})

const results = environment.results
await Promise.all(
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3826,6 +3826,10 @@ require-from-string@^1.1.0:
version "1.2.1"
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-1.2.1.tgz#529c9ccef27380adfec9a2f965b649bbee636418"

require-from-string@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.1.tgz#c545233e9d7da6616e9d59adfb39fc9f588676ff"

require-main-filename@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
Expand Down

0 comments on commit 21ce74d

Please sign in to comment.