|
1 | 1 | import * as fs from 'node:fs'; |
2 | 2 |
|
3 | | -import ajv from 'ajv'; |
4 | | -import chai from 'chai'; |
5 | | -import * as cheerio from 'cheerio'; |
6 | | -import cryptojs from 'crypto-js'; |
7 | | -import * as csvParseSync from 'csv-parse/sync'; |
8 | 3 | import { contextBridge, ipcRenderer, type IpcRendererEvent } from 'electron'; |
9 | | -import { asyncTasksAllSettled, Collection as CollectionModule, OriginalPromise, ProxiedPromise, type RequestContext, resetAsyncTasks, stopMonitorAsyncTasks } from 'insomnia-sdk'; |
10 | | -import lodash from 'lodash'; |
11 | | -import moment from 'moment'; |
12 | | -import tv4 from 'tv4'; |
13 | | -import * as uuid from 'uuid'; |
14 | | -import xml2js from 'xml2js'; |
| 4 | +import { asyncTasksAllSettled, OriginalPromise, ProxiedPromise, type RequestContext, resetAsyncTasks, stopMonitorAsyncTasks } from 'insomnia-sdk'; |
15 | 5 |
|
16 | 6 | import type { Compression } from './models/response'; |
17 | | - |
18 | | -const externalModules = new Map<string, object>([ |
19 | | - ['ajv', ajv], |
20 | | - ['chai', chai], |
21 | | - ['cheerio', cheerio], |
22 | | - ['crypto-js', cryptojs], |
23 | | - ['csv-parse/lib/sync', csvParseSync], |
24 | | - ['lodash', lodash], |
25 | | - ['moment', moment], |
26 | | - ['tv4', tv4], |
27 | | - ['uuid', uuid], |
28 | | - ['xml2js', xml2js], |
29 | | -]); |
| 7 | +// this will also import lots of node_modules into the preload script, consider moving this file insomnia-sdk |
| 8 | +import { requireInterceptor } from './requireInterceptor'; |
30 | 9 |
|
31 | 10 | export interface HiddenBrowserWindowToMainBridgeAPI { |
32 | 11 | requireInterceptor: (module: string) => any; |
@@ -55,61 +34,7 @@ const bridge: HiddenBrowserWindowToMainBridgeAPI = { |
55 | 34 | ipcRenderer.invoke('renderer-listener-ready'); |
56 | 35 | return () => ipcRenderer.removeListener('renderer-listener', rendererListener); |
57 | 36 | }, |
58 | | - |
59 | | - requireInterceptor: (moduleName: string) => { |
60 | | - if ( |
61 | | - [ |
62 | | - // node.js modules |
63 | | - 'path', |
64 | | - 'assert', |
65 | | - 'buffer', |
66 | | - 'util', |
67 | | - 'url', |
68 | | - 'punycode', |
69 | | - 'querystring', |
70 | | - 'string_decoder', |
71 | | - 'stream', |
72 | | - 'timers', |
73 | | - 'events', |
74 | | - // follows should be npm modules |
75 | | - // but they are moved to here to avoid introducing additional dependencies |
76 | | - ].includes(moduleName) |
77 | | - ) { |
78 | | - return require(moduleName); |
79 | | - } else if ( |
80 | | - [ |
81 | | - 'atob', |
82 | | - 'btoa', |
83 | | - ].includes(moduleName) |
84 | | - ) { |
85 | | - return moduleName === 'atob' ? atob : btoa; |
86 | | - } else if ( |
87 | | - [ |
88 | | - // external modules |
89 | | - 'ajv', |
90 | | - 'chai', |
91 | | - 'cheerio', |
92 | | - 'crypto-js', |
93 | | - 'csv-parse/lib/sync', |
94 | | - 'lodash', |
95 | | - 'moment', |
96 | | - 'tv4', |
97 | | - 'uuid', |
98 | | - 'xml2js', |
99 | | - ].includes(moduleName) |
100 | | - ) { |
101 | | - const externalModule = externalModules.get(moduleName); |
102 | | - if (!externalModule) { |
103 | | - throw Error(`no module is found for "${moduleName}"`); |
104 | | - } |
105 | | - return externalModule; |
106 | | - } else if (moduleName === 'insomnia-collection' || moduleName === 'postman-collection') { |
107 | | - return CollectionModule; |
108 | | - } |
109 | | - |
110 | | - throw Error(`no module is found for "${moduleName}"`); |
111 | | - }, |
112 | | - |
| 37 | + requireInterceptor, |
113 | 38 | curlRequest: options => ipcRenderer.invoke('curlRequest', options), |
114 | 39 | readCurlResponse: options => ipcRenderer.invoke('readCurlResponse', options), |
115 | 40 | setBusy: busy => ipcRenderer.send('set-hidden-window-busy-status', busy), |
|
0 commit comments