*.min.js and entry.* naming conventions (#8968)

* use min.js convention

* rename to entry

* rename main.ts

* fix electorn builder config

* fix types

* fix hidden window entry

* rename esbuild.main.ts to entrypoints
This commit is contained in:
Jack Kavanagh
2025-08-13 13:05:56 +02:00
committed by GitHub
parent 2f220d4747
commit 3ac3965b45
18 changed files with 60 additions and 61 deletions

9
.vscode/tasks.json vendored
View File

@@ -5,7 +5,7 @@
"tasks": [
{
"label": "Insomnia: Compile Main",
"detail": "esbuild.main.ts",
"detail": "esbuild.entrypoints.ts",
"type": "shell",
"promptOnClose": false,
"options": {
@@ -14,7 +14,7 @@
"NODE_ENV": "development"
}
},
"command": "${workspaceRoot}/node_modules/.bin/esr esbuild.main.ts"
"command": "${workspaceRoot}/node_modules/.bin/esr esbuild.entrypoints.ts"
},
{
"label": "Insomnia: Compile Renderer (Watch)",
@@ -57,7 +57,10 @@
{
"label": "Insomnia: Compile (Watch)",
"detail": "Compile Renderer (Watch) | Compile Main",
"dependsOn": ["Insomnia: Compile Renderer (Watch)", "Insomnia: Compile Main"]
"dependsOn": [
"Insomnia: Compile Renderer (Watch)",
"Insomnia: Compile Main"
]
},
{
"label": "Inso: Compile (Watch)",

View File

@@ -56,7 +56,7 @@ Unexplored ideas in this area.
There are a few notable directories inside it:
- `/main.development.js` Entry for Electron.
- `/entry.main.js` Entry for Electron.
- `/src/main` Stuff that runs inside Electron's main process.
- `/src/ui` React components and styling.
- `/src/common` Utilities used across both main and render processes.

View File

@@ -166,10 +166,7 @@ export default tseslint.config(
'**/docker/*',
'**/electron/index.js',
'**/fixtures',
'**/hidden-window.js',
'**/hidden-window-preload.js',
'**/node_modules/*',
'**/preload.js',
'**/svgr',
'**/traces/*',
'**/verify-pkg.js',

View File

@@ -31,7 +31,7 @@
"install-libcurl-electron": "node_modules/.bin/node-pre-gyp install --directory node_modules/@getinsomnia/node-libcurl --update-binary --runtime=electron --target=$target",
"inso-start": "npm start -w insomnia-inso",
"inso-package": "npm run build -w insomnia-inso && npm run package -w insomnia-inso",
"watch:app": "cross-env PLAYWRIGHT=1 npm run build:main.min.js -w insomnia && npm run start:dev-server -w insomnia",
"watch:app": "cross-env PLAYWRIGHT=1 npm run build:electron-entrypoints -w insomnia && npm run start:dev-server -w insomnia",
"app-build": "cross-env PLAYWRIGHT=1 npm run build -w insomnia",
"app-package": "npm run package -w insomnia",
"test:smoke:dev": "npm run test:dev -w insomnia-smoke-test -- --project=Smoke",

View File

@@ -33,7 +33,7 @@ export async function sendRequest(
cb(undefined, transformedOutput);
resolve(transformedOutput);
})
.catch(e => {
.catch((e: string | undefined) => {
cb(e, undefined);
resolve(undefined);
});

View File

@@ -60,8 +60,8 @@ const electronBinary = path.join(
export const executablePath = bundleType() === 'package' ? insomniaBinary : electronBinary;
// NOTE: main.min.js is built by app-build in /build and also by the watcher in /src
export const mainPath = path.join(bundleType() === 'dev' ? 'src' : 'build', 'main.min.js');
// NOTE: entry.main.min.js is built by app-build in /build and also by the watcher in /src
export const mainPath = path.join(bundleType() === 'dev' ? 'src' : 'build', 'entry.main.min.js');
const hasMainBeenBuilt = fs.existsSync(path.resolve(cwd, mainPath));
const hasBinaryBeenBuilt = fs.existsSync(path.resolve(cwd, insomniaBinary));

View File

@@ -33,7 +33,7 @@ const config = {
},
],
extraMetadata: {
main: 'main.min.js', // Override the main path in package.json
main: 'entry.main.min.js', // Override the main path in package.json
},
fileAssociations: [],
mac: {

View File

@@ -35,8 +35,8 @@ export default async function build(options: Options) {
};
const preloadBuildOptions: BuildOptions = {
entryPoints: ['./src/preload.ts'],
outfile: path.join(outdir, 'preload.js'),
entryPoints: ['./src/entry.preload.ts'],
outfile: path.join(outdir, 'entry.preload.min.js'),
target: 'esnext',
bundle: true,
platform: 'node',
@@ -46,8 +46,8 @@ export default async function build(options: Options) {
};
const hiddenBrowserWindowPreloadBuildOptions: BuildOptions = {
entryPoints: ['./src/hidden-window-preload.ts'],
outfile: path.join(outdir, 'hidden-window-preload.js'),
entryPoints: ['./src/entry.hidden-window-preload.ts'],
outfile: path.join(outdir, 'entry.hidden-window-preload.min.js'),
target: 'esnext',
bundle: true,
platform: 'node',
@@ -60,9 +60,8 @@ export default async function build(options: Options) {
};
const hiddenBrowserWindowBuildOptions: BuildOptions = {
entryPoints: ['./src/hidden-window.ts'],
// TODO: make all of these outputs use a .min.js convention to simplify ignore files
outfile: path.join(outdir, 'hidden-window.js'),
entryPoints: ['./src/entry.hidden-window.ts'],
outfile: path.join(outdir, 'entry.hidden-window.min.js'),
target: 'esnext',
bundle: true,
platform: 'node',
@@ -76,8 +75,8 @@ export default async function build(options: Options) {
};
const mainBuildOptions: BuildOptions = {
entryPoints: ['./src/main.development.ts'],
outfile: path.join(outdir, 'main.min.js'),
entryPoints: ['./src/entry.main.ts'],
outfile: path.join(outdir, 'entry.main.min.js'),
bundle: true,
platform: 'node',
sourcemap: true,

View File

@@ -15,13 +15,13 @@
},
"license": "Apache-2.0",
"author": "Kong <office@konghq.com>",
"main": "src/main.min.js",
"main": "src/entry.main.min.js",
"scripts": {
"verify-bundle-plugins": "esr --cache ./scripts/verify-bundle-plugins.ts",
"build": "react-router build && esr --cache ./scripts/build.ts --noErrorTruncation",
"build:react-router": "react-router build",
"generate:schema": "esr ./src/schema.ts",
"build:main.min.js": "cross-env NODE_ENV=development esr esbuild.main.ts",
"build:electron-entrypoints": "cross-env NODE_ENV=development esr esbuild.entrypoints.ts",
"lint": "eslint . --ext .js,.ts,.tsx --cache",
"package": "npm run build && cross-env USE_HARD_LINKS=false electron-builder build --config electron-builder.config.js",
"package:windows:unpacked": "npm run build && cross-env USE_HARD_LINKS=false electron-builder build --config electron-builder.config.js --win squirrel nsis --dir",
@@ -29,18 +29,18 @@
"start": "npx -y concurrently -n browser,main --kill-others \"npm run start:dev-server\" \"npm run start:electron\"",
"start:autoRestart": "npx -y concurrently -n browser,main --kill-others \"npm run start:dev-server\" \"npm run start:electron:autoRestart\"",
"start:dev-server": "vite dev",
"start:electron": "cross-env NODE_ENV=development esr esbuild.main.ts && electron --inspect=5858 .",
"start:electron:autoRestart": "cross-env NODE_ENV=development esr esbuild.main.ts --autoRestart",
"start:electron": "cross-env NODE_ENV=development esr esbuild.entrypoints.ts && electron --inspect=5858 .",
"start:electron:autoRestart": "cross-env NODE_ENV=development esr esbuild.entrypoints.ts --autoRestart",
"test": "vitest run",
"type-check": "react-router typegen && tsc --noEmit --project tsconfig.json",
"type-check:watch": "npm run type-check -- --watch",
"convert-svg": "npm_config_yes=true npx @svgr/cli@6.4.0 --no-index --config-file svgr.config.js --out-dir src/ui/components/assets/svgr src/ui/components/assets/"
},
"//": [
"dependencies will be external to the vite bundle and electron main (commonjs)",
"dependencies will be external to the vite bundle and electron entrypoints (commonjs)",
"devDependencies will be included in the vite bundle (esm)",
"See: packages/insomnia/vite.config.ts",
"and: packages/insomnia/esbuild.main.ts"
"and: packages/insomnia/esbuild.entrypoints.ts"
],
"dependencies": {
"@apideck/better-ajv-errors": "^0.3.6",

View File

@@ -1,7 +1,7 @@
import { cp, mkdir } from 'node:fs/promises';
import path from 'node:path';
import buildMainAndPreload from '../esbuild.main';
import buildEntrypoints from '../esbuild.entrypoints';
// Start build if ran from CLI
if (require.main === module) {
@@ -27,8 +27,8 @@ export const start = async () => {
const buildFolder = path.join('../build');
console.log('[build] Building main.min.js and preload');
await buildMainAndPreload({
console.log('[build] Building entry.main.min.js and entry.preload.min.js');
await buildEntrypoints({
mode: 'production',
});

View File

@@ -24,32 +24,34 @@ Sentry.init({
...SENTRY_OPTIONS,
});
window.bridge.onmessage(async (data, callback) => {
window.bridge.setBusy(true);
window.bridge.onmessage(
async (data: { script: string; context: RequestContext }, callback: ({ error }: { error: string }) => void) => {
window.bridge.setBusy(true);
try {
const timeout = data.context.timeout || 5000;
const timeoutPromise = new window.bridge.Promise(resolve => {
setTimeout(() => {
resolve({ error: 'Timeout: Running script took too long' });
}, timeout);
});
const result = await window.bridge.Promise.race([timeoutPromise, runScript(data)]);
callback(result);
} catch (err) {
const errMessage = err.message ? `Error from Pre-request or after-response script:\n${err.message};` : err;
const errStack = err.stack ? `Stack: ${err.stack};` : '';
const fullErrMessage = `${errMessage}\n${errStack}`;
Sentry.captureException(errMessage, {
tags: {
source: 'hidden-window',
},
});
callback({ error: fullErrMessage });
} finally {
window.bridge.setBusy(false);
}
});
try {
const timeout = data.context.timeout || 5000;
const timeoutPromise = new window.bridge.Promise((resolve: ({ error }: { error: string }) => void) => {
setTimeout(() => {
resolve({ error: 'Timeout: Running script took too long' });
}, timeout);
});
const result = await window.bridge.Promise.race([timeoutPromise, runScript(data)]);
callback(result);
} catch (err) {
const errMessage = err.message ? `Error from Pre-request or after-response script:\n${err.message};` : err;
const errStack = err.stack ? `Stack: ${err.stack};` : '';
const fullErrMessage = `${errMessage}\n${errStack}`;
Sentry.captureException(errMessage, {
tags: {
source: 'hidden-window',
},
});
callback({ error: fullErrMessage });
} finally {
window.bridge.setBusy(false);
}
},
);
// This function is duplicated in scriptExecutor.ts to run in nodejs
// TODO: consider removing this implementation and using only nodejs scripting

View File

@@ -11,6 +11,6 @@
<body>
<h1>Hidden Browser Window</h1>
<script src="./hidden-window.js"></script>
<script src="./entry.hidden-window.min.js"></script>
</body>
</html>

View File

@@ -15,7 +15,7 @@ import {
import type { UtilityProcess } from 'electron/main';
import iconv from 'iconv-lite';
import type { HiddenBrowserWindowBridgeAPI } from '../../hidden-window';
import type { HiddenBrowserWindowBridgeAPI } from '../../entry.hidden-window';
import * as models from '../../models';
import type { PluginTemplateTag } from '../../templating/types';
import type { SegmentEvent } from '../analytics';

View File

@@ -110,7 +110,7 @@ export async function createHiddenBrowserWindow() {
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
preload: path.join(__dirname, 'hidden-window-preload.js'),
preload: path.join(__dirname, 'entry.hidden-window-preload.min.js'),
spellcheck: false,
devTools: process.env.NODE_ENV === 'development',
},
@@ -209,7 +209,7 @@ export function createWindow(): ElectronBrowserWindow {
acceptFirstMouse: true,
icon: path.resolve(__dirname, appLogo),
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
preload: path.join(__dirname, 'entry.preload.min.js'),
zoomFactor: getZoomFactor(),
nodeIntegration: true,
nodeIntegrationInWorker: false, // must remain false to ensure the nunjucks web worker sandbox does not have access to Node.js APIs

View File

@@ -57,8 +57,6 @@
"config",
"node_modules",
"src/coverage",
"src/hidden-window-preload.js",
"src/preload.js",
"svgr.config.js",
]
}