Skip to content
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

refactor: flatten and reduce tsconfigs #7716

Merged
merged 11 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,35 @@ Insomnia uses [`npm workspaces`](https://docs.npmjs.com/cli/v9/using-npm/workspa

- `/packages` contains related packages that are consumed by `insomnia` or externally.

Insomnia Inso CLI is built using a series of steps

1. `packages/insomnia-send-request/dist/index.js` is transpiled from `packages/insomnia` using esbuild to expose `getSendRequestCallbackMemDb` in order to send a request without writing to database
1. `insomnia-testing` is connected to both `packages/insomnia` `packages/insomnia-inso` using "project references" to expose `generate`, `runTests` and `runTestsCli`
1. `insomnia-inso` uses"project references" to import `insomnia-send-request` and `insomnia-testing`.
1. `packages/insomnia-inso/dist/index.js` is transpiled with esbuild
1. `packages/insomnia-inso/bin/inso` is shell script which points at `packages/insomnia-inso/dist/index.js` and is used for local development
1. `packages/insomnia-inso/binaries/inso` is an executable made with `pkg`

What `insomnia-send-request` is an abstraction which trades-off CLI build complexity against refactoring the insomnia app into modules which both could share. It exposes some behaviour from the insomnia renderer.

- database: to fetch needed models
- nunjucks templates: to interpolate the fields containing tags
- node-libcurl: to send the request
- fs: to persist responses
- plugins: potentially needed by the community, unclear if the implementation works

Problems

- send-request bundles almost the entire renderer, react components included, meaning that although we are intending to use this code in node we are bundling it using rules intended for browsers.
- node-libcurl present bundling issues because it needs to re-download a different version from npm each time you want to work on either insomnia or inso.
- nunjucks codepaths haven't been touched in a long time, they need some love in order to be able to understand how to make them composable.

Unexplored ideas in this area.

- create a database package with nunjucks templating and have both insomnia and inso use it with project references, use node-libcurl directly, eliminating `insomnia-send-request`.
- use an adapter pattern in inso to replace node-libcurl with fetch in order to avoid the bundling issues NaN modules present.
- remove plugin support from inso and reimplement later with a fixed and supported API.

## The `insomnia` Main Package

`/packages/insomnia` is the entry point for the app. All other packages are imported from this one.
Expand Down Expand Up @@ -81,9 +110,9 @@ This is just a brief summary of Insomnia's current technical debt.
- [x] styling vision (react-aria + tailwind)
- [ ] de-polymorph database
- [ ] codemirror is unmaintained
- [ ] nedb is unmaintained
- [x] nedb is unmaintained
- [ ] grpc state state should be in main rather than renderer
- [ ] drag and drop is flakey
- [x] drag and drop is flakey
- [ ] sync code is spaghetti
- [ ] template rendering is spaghetti and has poor discoverability
- [ ] inso abstraction limits networking improvements
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions packages/insomnia-inso/src/scripts/verify-pkg.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// import { spawn } from 'child_process';
// import { resolve } from 'path';
const spawn = require('child_process').spawn;
const resolve = require('path').resolve;
const basePath = resolve('binaries/inso');
const childProcess = spawn(basePath, ['--help']);
childProcess.stdout.on('data', data => {
console.log(`stdout: ${data}`);
});
childProcess.stderr.on('data', data => {
console.log(`stderr: ${data}`);
});
childProcess.on('error', err => {
console.error(`Error: ${err.message}`);
});
Expand Down
34 changes: 19 additions & 15 deletions packages/insomnia-inso/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
{
"compilerOptions": {
/* Basic */
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": true,
"allowUnusedLabels": false,
"checkJs": true,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"lib": ["DOM", "ES2019"],
"module": "CommonJS",
"resolveJsonModule": true,
"moduleResolution": "node",
"isolatedModules": true,
/* Transpiling Options */
"module": "CommonJS",
"sourceMap": true,
/* Runs in the DOM NOTE: this is inconsistent with reality */
"lib": [
"ES2020",
"DOM.Iterable",
"DOM"
],
/* Strictness */
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"target": "ES2019",
"types": ["node"],
"useUnknownInCatchVariables": false
"noFallthroughCasesInSwitch": true,
"useUnknownInCatchVariables": false,
},
"include": [
".eslintrc.js",
Expand Down
4 changes: 1 addition & 3 deletions packages/insomnia-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
"types": "src/index.ts",
"scripts": {
"lint": "eslint . --ext .js,.ts,.tsx --cache",
"test": "jest",
"build": "tsc --build tsconfig.build.json",
"watch": "npm run build -- --watch"
"test": "jest"
},
"homepage": "https://github.com/Kong/insomnia#readme",
"description": ""
Expand Down
25 changes: 0 additions & 25 deletions packages/insomnia-testing/tsconfig.jest.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"allowUnreachableCode": true,
"allowUnusedLabels": false,
"checkJs": true,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"lib": [
"DOM",
"ES2019"
],
"module": "CommonJS",
"moduleResolution": "node",
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"pretty": true,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"target": "ES2019",
"types": [
"node"
],
"useUnknownInCatchVariables": false
}
}
5 changes: 3 additions & 2 deletions packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "npm run build:sr && npm run build:app",
"build:app": "esr --cache ./scripts/build.ts --noErrorTruncation",
"build:main.min.js": "cross-env NODE_ENV=development esr esbuild.main.ts",
"build:sr": "esr esbuild.sr.ts && tsc --build tsconfig.build.sr.json",
"build:sr": "esr esbuild.sr.ts",
"lint": "eslint . --ext .js,.ts,.tsx --cache",
"package": "npm run build:app && cross-env USE_HARD_LINKS=false electron-builder build --config electron-builder.config.js",
"start": "concurrently -n browser,main --kill-others \"npm run start:dev-server\" \"npm run start:electron\"",
Expand All @@ -29,7 +29,7 @@
"test": "jest",
"electron:dev-build": "electron ./build/main.min.js",
"test:watch": "jest --watch",
"type-check": "tsc --noEmit --project tsconfig.build.json",
"type-check": "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/"
},
Expand Down Expand Up @@ -112,6 +112,7 @@
"@types/hosted-git-info": "3.0.5",
"@types/js-yaml": "^4.0.9",
"@types/jshint": "^2.12.4",
"@types/jsonpath-plus": "^5.0.5",
"@types/license-checker": "^25.0.6",
"@types/marked": "^5.0.2",
"@types/mime-types": "^2.1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const RequestRenderErrorModal = forwardRef<RequestRenderErrorModalHandle,

const fullPath = `Request.${error?.path}`;
const result = JSONPath({ json: request, path: `$.${error?.path}` });
const template = result && result.length ? result[0] : null;
const template = result && Array.isArray(result) && result.length ? result[0] : null;
const locationLabel = template?.includes('\n') ? `line ${error?.location.line} of` : null;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ const localTemplatePlugins: { templateTag: PluginTemplateTag }[] = [

if (JSONPath && ['userInfo', 'cpus'].includes(fnName)) {
try {
value = JSONPath({ json: value, path: filter })[0];
const results = JSONPath({ json: value, path: filter });
value = Array.isArray(results) ? results[0] : results;
} catch (err) { }
}

Expand Down Expand Up @@ -303,6 +304,9 @@ const localTemplatePlugins: { templateTag: PluginTemplateTag }[] = [
let results;
try {
results = JSONPath({ json: body, path: filter });
if (!Array.isArray(results)) {
results = [results];
}
} catch (err) {
throw new Error(`Invalid JSONPath query: ${filter}`);
}
Expand Down Expand Up @@ -715,6 +719,9 @@ const localTemplatePlugins: { templateTag: PluginTemplateTag }[] = [

try {
results = JSONPath({ json: bodyJSON, path: sanitizedFilter });
if (!Array.isArray(results)) {
results = [results];
}
} catch (err) {
throw new Error(`Invalid JSONPath query: ${sanitizedFilter}`);
}
Expand Down
56 changes: 0 additions & 56 deletions packages/insomnia/tsconfig.build.json

This file was deleted.

31 changes: 29 additions & 2 deletions packages/insomnia/tsconfig.build.sr.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"compilerOptions": {
/* Basic */
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"isolatedModules": true,
/* Transpiling Options */
"module": "ESNext",
"sourceMap": true,
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"outDir": "../insomnia-send-request/dist",
"rootDir": ".",
/* Runs in the DOM */
"lib": [
"ES2020",
"DOM.Iterable",
"DOM"
],
"jsx": "react",
/* Strictness */
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"useUnknownInCatchVariables": false,
},
"include": [
"**/*.d.ts",
Expand Down
48 changes: 46 additions & 2 deletions packages/insomnia/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
/* Basic */
"esModuleInterop": true,
"skipLibCheck": true,
"target": "es2022",
"allowJs": true,
"resolveJsonModule": true,
"moduleResolution": "node",
"isolatedModules": true,
/* Transpiling Options */
"module": "ESNext",
"sourceMap": true,
/* Runs in the DOM */
"lib": [
"ES2020",
"DOM.Iterable",
"DOM"
],
"jsx": "react",
/* Strictness */
"strict": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"useUnknownInCatchVariables": false,
},
"include": [
".eslintrc.js",
"config",
Expand All @@ -14,7 +40,8 @@
"tailwind.config.js",
"postcss.config.js",
"vite.config.ts",
"vite-plugin-electron-node-require"
"vite-plugin-electron-node-require",
"**/*.d.ts",
],
"exclude": [
"bin",
Expand All @@ -25,5 +52,22 @@
"src/main.min.js",
"src/preload.js",
"svgr.config.js",
"**/*.test.ts",
"**/*.test.tsx",
"**/__jest__",
"**/__mocks__",
"**/__snapshots__",
"**/__tests__",
"**/main.min.js",
"__jest__",
"assets",
"bin",
"config",
"jest.config.js",
"node_modules",
"src/coverage",
"src/main.min.js",
"src/preload.js",
"src/hidden-window-preload.js",
],
}
Loading