mirror of
https://github.com/Kong/insomnia.git
synced 2026-08-04 11:52:33 -04:00
* replace with __IS_RENDERER__ * fix: define __IS_RENDERER__ in inso and electron entrypoint builds process.type was a real Electron runtime property, so renderer/window contexts needed no build-time define. __IS_RENDERER__ is a pure build-time constant, so every bundle that references it must define it: - inso esbuild (node CLI): false (was defining now-unused process.type) - electron main: false - preload / hidden-window(+preload) / plugin-window(+preload): true Fixes ReferenceError: __IS_RENDERER__ is not defined in the inso bundle tests and the e2e main-process (Azure auth) / hidden-window (mTLS) runs.
83 lines
2.5 KiB
TypeScript
83 lines
2.5 KiB
TypeScript
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
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 = {
|
|
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,
|
|
metafile: isDebug,
|
|
platform: 'node',
|
|
minify: isProd,
|
|
target: 'node22',
|
|
sourcemap: true,
|
|
format: 'cjs',
|
|
tsconfig: 'tsconfig.json',
|
|
alias: {
|
|
electron: '../insomnia/send-request/electron',
|
|
},
|
|
plugins: [
|
|
rendererToNodePlugin,
|
|
// taken from https://github.com/tjx666/awesome-vscode-extension-boilerplate/blob/main/scripts/esbuild.ts
|
|
{
|
|
name: 'umd2esm',
|
|
setup(build) {
|
|
build.onResolve({ filter: /^(vscode-.*|estree-walker|jsonc-parser)/ }, args => {
|
|
const pathUmdMay = require.resolve(args.path, {
|
|
paths: [args.resolveDir],
|
|
});
|
|
// Call twice the replace is to solve the problem of the path in Windows
|
|
const pathEsm = pathUmdMay.replace('/umd/', '/esm/').replace('\\umd\\', '\\esm\\');
|
|
return { path: pathEsm };
|
|
});
|
|
},
|
|
},
|
|
],
|
|
define: {
|
|
'process.env.DEFAULT_APP_NAME': JSON.stringify(isProd ? 'Insomnia' : 'insomnia-app'),
|
|
'process.env.VERSION': JSON.stringify(isProd ? version : 'dev'),
|
|
'__DEV__': JSON.stringify(!isProd),
|
|
'__IS_RENDERER__': JSON.stringify(false),
|
|
},
|
|
// node-llama-cpp is not included here because inso does not need it
|
|
external: ['@getinsomnia/node-libcurl', 'fsevents', 'mocha'],
|
|
entryPoints: ['./src/index.ts'],
|
|
};
|
|
|
|
if (watch) {
|
|
async function watch() {
|
|
const ctx = await context(config);
|
|
await ctx.watch();
|
|
}
|
|
watch();
|
|
} else {
|
|
if (isDebug) {
|
|
async function buildWithDebug() {
|
|
const result = await build(config);
|
|
|
|
if (result.metafile) {
|
|
fs.mkdirSync('./artifacts', { recursive: true });
|
|
fs.writeFileSync('./artifacts/meta.json', JSON.stringify(result.metafile));
|
|
fs.writeFileSync('./artifacts/bundle-analysis.log', await analyzeMetafile(result.metafile));
|
|
}
|
|
}
|
|
|
|
buildWithDebug();
|
|
}
|
|
build(config);
|
|
}
|