-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: disable nodeIntegration in renderer mainWindow, remove Node import check tooling #9996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7358b67
ff8cdd1
3d7345f
8bd134e
9d52cda
906cce7
87ed759
1c602ee
929ec2a
51b9ba9
7938df8
799b310
26659eb
7d243fd
907aaa5
1e4251a
198517d
2c59904
9f7c7b5
8b30634
e6f1c57
4ec3b4e
ed4dea8
71e9030
bcbf1fc
ed77673
799e2bc
3fb1174
3b2ef88
58ef319
475c8b6
bf2299c
e1f38ce
f4e0f0c
bf30241
9d432b9
e435015
024e012
3d8c9cc
373a320
af95e62
9750add
d5fbc46
9d447de
7ecae8e
4f7cd72
6b3adaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,22 @@ | ||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { analyzeMetafile, build, type BuildOptions, context } from 'esbuild'; | ||
| import { analyzeMetafile, build, type BuildOptions, context, type Plugin } from 'esbuild'; | ||
|
|
||
| const isProd = Boolean(process.env.NODE_ENV === 'production'); | ||
| const watch = Boolean(process.env.ESBUILD_WATCH); | ||
| const isDebug = Boolean(process.env.DEBUG); | ||
| const version = process.env.VERSION || 'dev'; | ||
| // Redirects *.renderer imports to their *.node equivalents for node/CLI builds. | ||
| const rendererToNodePlugin: Plugin = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit hacky. Should this be handled by the bundler by process.type in the adapter? Why do we need this plugin?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because that approach is equally hacky, and doesn't help vite determine what not to bundle, because vite only sets type to renderer in prod not dev, theres an explanation in the comment. a better approach might be window !== undefined, you are welcome to experiment with this branch to your satisfaction.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no preference for the solution. But it should be consistent and won't introduce misunderstandings.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll look into it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looked into it, inso is hacky, hacks on hacks isn't new. |
||
| name: 'renderer-to-node', | ||
| setup(build) { | ||
| build.onResolve({ filter: /\.renderer$/ }, args => ({ | ||
| path: path.resolve(args.resolveDir, args.path.replace('.renderer', '.node') + '.ts'), | ||
| })); | ||
| }, | ||
| }; | ||
|
|
||
| const config: BuildOptions = { | ||
| outfile: './dist/index.js', | ||
| bundle: true, | ||
|
|
@@ -20,6 +31,7 @@ const config: BuildOptions = { | |
| electron: '../insomnia/send-request/electron', | ||
| }, | ||
| plugins: [ | ||
| rendererToNodePlugin, | ||
| // taken from https://github.com/tjx666/awesome-vscode-extension-boilerplate/blob/main/scripts/esbuild.ts | ||
| { | ||
| name: 'umd2esm', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import { vi } from 'vitest'; | ||
|
|
||
| export const generate = vi.fn(); | ||
| export const generateToFile = vi.fn(); | ||
| export const runTests = vi.fn(); | ||
| export const runTestsCli = vi.fn(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| module.exports = { | ||
| esbuild: { | ||
| external: ['@getinsomnia/node-libcurl', 'electron'], | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Regenerate src/autocomplete-snippets.json from the live scripting API. | ||
| // Run from the package root: npm run generate:autocomplete | ||
| // | ||
| // This script instantiates the scripting classes in Node.js (where tough-cookie is fine) | ||
| // and walks the object graph to derive autocomplete snippets. The output is committed as a | ||
| // static JSON file so the renderer never has to import the scripting classes. | ||
| // | ||
| // Re-run this script whenever the public scripting API surface changes. | ||
|
|
||
| import { writeFileSync } from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| // Import directly from source files to avoid pulling in send-request.ts (which | ||
| // transitively imports the Electron-only libcurl native addon via the main package). | ||
| const { CookieObject } = require('../src/objects/cookies.ts'); | ||
| const { Environment, Variables, Vault } = require('../src/objects/environments.ts'); | ||
| const { Execution } = require('../src/objects/execution.ts'); | ||
| const { InsomniaObject } = require('../src/objects/insomnia.ts'); | ||
| const { Request: ScriptRequest } = require('../src/objects/request.ts'); | ||
| const { RequestInfo } = require('../src/objects/request-info.ts'); | ||
| const { Response: ScriptResponse } = require('../src/objects/response.ts'); | ||
| const { Url } = require('../src/objects/urls.ts'); | ||
| const { ParentFolders } = require('../src/objects/folders.ts'); | ||
|
|
||
| interface Snippet { | ||
| displayValue: string; | ||
| name: string; | ||
| value: string; | ||
| } | ||
|
|
||
| function walk(obj: object, path: string): Snippet[] { | ||
| let snippets: Snippet[] = []; | ||
| const refs = new Set<unknown>(); | ||
| const record = obj as Record<string, unknown>; | ||
|
|
||
| for (const key in obj) { | ||
| if (key.startsWith('_')) { | ||
| continue; | ||
| } | ||
|
|
||
| const value = record[key]; | ||
|
|
||
| if (typeof value === 'object' && value !== null) { | ||
| if (refs.has(value)) { | ||
| continue; | ||
| } | ||
| refs.add(value); | ||
| } | ||
|
|
||
| if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') { | ||
| snippets.push({ displayValue: `${path}.${value}`, name: `${path}.${key}`, value: `${path}.${key}` }); | ||
| } else if (typeof value === 'function') { | ||
| snippets.push({ displayValue: `${path}.${key}()`, name: `${path}.${key}()`, value: `${path}.${key}()` }); | ||
| } else if (Array.isArray(value)) { | ||
| for (const item of value) { | ||
| snippets = snippets.concat(walk(item, `${path}.${key}`)); | ||
| } | ||
| } else if (value !== null && typeof value === 'object') { | ||
| snippets = snippets.concat(walk(value as object, `${path}.${key}`)); | ||
| } | ||
| } | ||
|
|
||
| return snippets; | ||
| } | ||
|
|
||
| const settings: any = { enableVaultInScripts: true }; | ||
| const req = new ScriptRequest({ url: new Url('http://placeholder.com') }); | ||
|
|
||
| const insomnia = new InsomniaObject({ | ||
| globals: new Environment('globals', {}), | ||
| baseGlobals: new Environment('baseGlobals', {}), | ||
| iterationData: new Environment('iterationData', {}), | ||
| environment: new Environment('environment', {}), | ||
| baseEnvironment: new Environment('baseEnvironment', {}), | ||
| variables: new Variables({ | ||
| baseGlobalVars: new Environment('baseGlobals', {}), | ||
| globalVars: new Environment('globals', {}), | ||
| environmentVars: new Environment('environment', {}), | ||
| collectionVars: new Environment('collection', {}), | ||
| iterationDataVars: new Environment('data', {}), | ||
| folderLevelVars: [], | ||
| localVars: new Environment('data', {}), | ||
| }), | ||
| vault: new Vault('vault', {}, true), | ||
| request: req, | ||
| response: new ScriptResponse({ | ||
| code: 200, | ||
| reason: 'OK', | ||
| header: [ | ||
| { key: 'header1', value: 'val1' }, | ||
| { key: 'header2', value: 'val2' }, | ||
| ], | ||
| cookie: [ | ||
| { key: 'header1', value: 'val1' }, | ||
| { key: 'header2', value: 'val2' }, | ||
| ], | ||
| body: '{"key": 888}', | ||
| stream: undefined, | ||
| responseTime: 100, | ||
| originalRequest: req, | ||
| }), | ||
| settings, | ||
| clientCertificates: [], | ||
| cookies: new CookieObject({ | ||
| _id: '', | ||
| type: 'CookieJar', | ||
| parentId: '', | ||
| modified: 0, | ||
| created: 0, | ||
| isPrivate: false, | ||
| name: '', | ||
| cookies: [], | ||
| }), | ||
| requestInfo: new RequestInfo({ | ||
| eventName: 'prerequest', | ||
| iteration: 1, | ||
| iterationCount: 1, | ||
| requestName: '', | ||
| requestId: '', | ||
| }), | ||
| execution: new Execution({ location: ['path'] }), | ||
| parentFolders: new ParentFolders([]), | ||
| }); | ||
|
|
||
| const snippets = walk(insomnia, 'insomnia'); | ||
|
|
||
| const outputPath = path.join(__dirname, '../src/autocomplete-snippets.json'); | ||
| writeFileSync(outputPath, JSON.stringify(snippets, null, 2) + '\n'); | ||
| console.log(`Wrote ${snippets.length} snippets to src/autocomplete-snippets.json`); |
Uh oh!
There was an error while loading. Please reload this page.