猴子补丁节点模块

时间:2018-03-07 01:21:20

标签: node.js typescript electron

我试图在this node module应用程序中修补补丁electron。我想更改if (process.platform == "darwin") { let refSCapt = screenshot.capture; console.log("Outside"); screenshot.capture = function(output: string, callback: any) { console.log("Inside"); // Override output path of a temp .png file let tempOutput = output.split("/")[-1]; refSCapt(this.screenshotsPath + tempOutput, callback); }; } 方法输入参数。

到目前为止我的代码看起来像这样:

Outside

问题在于补丁没有反映,并且原始方法被称为好像什么都不会改变。已记录Inside获取,但永远不会调用import pandas def build_dataframe(data2): tuple_list = [] data_dict = {} for source in sorted(data2.keys()): tuple_list.extend([(source, target) for target in sorted(data2[source])]) data_dict.update({(source, target): data2[source][target] for target in sorted(data2[source])}) multi_index = pandas.MultiIndex.from_tuples(tuple_list, names=["index1", "index2"]) df = pandas.DataFrame(index=multi_index, columns=[0], data={0: data_dict}) return df def dataframe_get(df, index2, default_value=0): return df.loc(axis=0)[:, index2] def dict_get(input_dict, key, default_value=0): return {index1: dictionary.get(key, default_value) for index1, dictionary in input_dict.iteritems()} data = {123: {6544: 44, 23423: 66, 12: 65}, 234: {725: 42, 7245: 62}} df_data = build_dataframe(data) print df_data print dict_get(data, 12, 999) print dataframe_get(df_data, 12, 999)

那我怎么能修补这个模块方法呢?

1 个答案:

答案 0 :(得分:4)

  

那么我怎么能修补这个模块方法?

如果您的代码在其他地方使用之前运行,那么您拥有的功能可以正常工作......但。为了实现可靠的修补,我建议https://github.com/ds300/patch-package安装补丁模块。