forked from sphinx-labs/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sphinx-labs#245 from chugsplash/sg/develop
fix(pg): improve the harhdat node task
- Loading branch information
Showing
5 changed files
with
84 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@chugsplash/plugins': patch | ||
--- | ||
|
||
Improve the hardhat node task |
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,9 +1,27 @@ | ||
/** | ||
* Removes all command line args in the `process.argv` array that begin with '--'. This is necessary | ||
* to prevent an error that occurs when running the executor from within a Hardhat plugin task. This | ||
* error occurs because the BaseServiceV2 (inherited by the executor) parses these command line | ||
* arguments and throws an error when it sees arguments that it does not recognize. | ||
* Removes command line args in the `process.argv` array beginning with the first argument that | ||
* starts with '--'. This is necessary to prevent an error that occurs when running the executor | ||
* from within a Hardhat plugin task. This error occurs because the BaseServiceV2 (inherited by the | ||
* executor) parses these command line arguments and throws an error when it sees an unrecognized | ||
* argument that begins with '--'. | ||
* | ||
* @returns An array containing the removed command line args. | ||
*/ | ||
export const removeFlagsFromCommandLineArgs = (): void => { | ||
process.argv = process.argv.filter((arg) => !arg.startsWith('--')) | ||
export const removeFlagsFromCommandLineArgs = (): string[] => { | ||
const indexToRemove = process.argv.findIndex((arg) => arg.startsWith('--')) | ||
if (indexToRemove === -1) { | ||
return [] | ||
} | ||
const removed = process.argv.slice(indexToRemove) | ||
process.argv = process.argv.slice(0, indexToRemove) | ||
return removed | ||
} | ||
|
||
/** | ||
* Adds the given array of arguments to `process.argv`. | ||
* | ||
* @param args The command line arguments to add. | ||
*/ | ||
export const addCommandLineArgs = (args: string[]) => { | ||
process.argv = process.argv.concat(args) | ||
} |
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,18 @@ | ||
import { ChugSplashExecutor } from '@chugsplash/executor' | ||
|
||
import { addCommandLineArgs, removeFlagsFromCommandLineArgs } from './env' | ||
|
||
export const instantiateExecutor = (): ChugSplashExecutor => { | ||
// We must remove the command line arguments that begin with '--' from the process.argv array, | ||
// or else the BaseServiceV2 (inherited by the executor) will throw an error when we instantiate | ||
// it. | ||
const removed = removeFlagsFromCommandLineArgs() | ||
|
||
// Instantiate the executor. | ||
const executor = new ChugSplashExecutor() | ||
|
||
// Add the command line args back to the array. | ||
addCommandLineArgs(removed) | ||
|
||
return executor | ||
} |
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