diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 3d8a8cfe942..53fc40a16d7 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -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. @@ -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 diff --git a/package-lock.json b/package-lock.json index 026f22c5b38..f544886943d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6572,6 +6572,12 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "node_modules/@types/jsonpath-plus": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@types/jsonpath-plus/-/jsonpath-plus-5.0.5.tgz", + "integrity": "sha512-aaqqDf5LcGOtAfEntO5qKZS6ixT0MpNhUXNwbVPdLf7ET9hKsufJq+buZr7eXSnWoLRyGzVj2Yz2hbjVSK3wsA==", + "dev": true + }, "node_modules/@types/keygrip": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/keygrip/-/keygrip-1.0.6.tgz", @@ -23503,6 +23509,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", diff --git a/packages/insomnia-inso/src/scripts/verify-pkg.js b/packages/insomnia-inso/src/scripts/verify-pkg.js index 2f848310f51..d77ae5c49a2 100644 --- a/packages/insomnia-inso/src/scripts/verify-pkg.js +++ b/packages/insomnia-inso/src/scripts/verify-pkg.js @@ -1,5 +1,3 @@ -// 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'); @@ -7,6 +5,9 @@ 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}`); }); diff --git a/packages/insomnia-inso/tsconfig.json b/packages/insomnia-inso/tsconfig.json index d1afaae7ac3..b562bc72887 100644 --- a/packages/insomnia-inso/tsconfig.json +++ b/packages/insomnia-inso/tsconfig.json @@ -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", diff --git a/packages/insomnia-testing/package.json b/packages/insomnia-testing/package.json index 3550845d460..a6a68674fc9 100644 --- a/packages/insomnia-testing/package.json +++ b/packages/insomnia-testing/package.json @@ -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": "" diff --git a/packages/insomnia-testing/tsconfig.jest.json b/packages/insomnia-testing/tsconfig.jest.json index 167210bce90..b6955c086e7 100644 --- a/packages/insomnia-testing/tsconfig.jest.json +++ b/packages/insomnia-testing/tsconfig.jest.json @@ -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 } } diff --git a/packages/insomnia/package.json b/packages/insomnia/package.json index 57524525bee..36d47cc5d14 100644 --- a/packages/insomnia/package.json +++ b/packages/insomnia/package.json @@ -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\"", @@ -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/" }, @@ -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", diff --git a/packages/insomnia/src/ui/components/modals/request-render-error-modal.tsx b/packages/insomnia/src/ui/components/modals/request-render-error-modal.tsx index 024b4846201..7d2e9789841 100644 --- a/packages/insomnia/src/ui/components/modals/request-render-error-modal.tsx +++ b/packages/insomnia/src/ui/components/modals/request-render-error-modal.tsx @@ -39,7 +39,7 @@ export const RequestRenderErrorModal = forwardRef