mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Get app data dir from process.env, update webpack (#2352)
This commit is contained in:
parent
a35664d4dd
commit
96cfe7ea45
@ -1 +1,3 @@
|
||||
jest.mock('node-libcurl');
|
||||
|
||||
process.env.DEFAULT_APP_DATA_DIR = process.env.DEFAULT_APP_DATA_DIR || 'insomnia-app';
|
||||
|
36
packages/insomnia-inso/package-lock.json
generated
36
packages/insomnia-inso/package-lock.json
generated
@ -2898,6 +2898,17 @@
|
||||
"wrap-ansi": "^6.2.0"
|
||||
}
|
||||
},
|
||||
"clone-deep": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz",
|
||||
"integrity": "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"is-plain-object": "^2.0.4",
|
||||
"kind-of": "^6.0.2",
|
||||
"shallow-clone": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"co": {
|
||||
"version": "4.6.0",
|
||||
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
|
||||
@ -7508,6 +7519,15 @@
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"shallow-clone": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz",
|
||||
"integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"kind-of": "^6.0.2"
|
||||
}
|
||||
},
|
||||
"shebang-command": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
||||
@ -9013,6 +9033,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"webpack-merge": {
|
||||
"version": "5.0.7",
|
||||
"resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-5.0.7.tgz",
|
||||
"integrity": "sha512-IxTERB8mNelEUN7YLSBhKMA0t/AySs0GGcUczNWWZTsNMKEFst4MM1t4aHX4ANAqVHO02A2zPPVXcdfv5Qpslw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"clone-deep": "^4.0.1",
|
||||
"wildcard": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"webpack-node-externals": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/webpack-node-externals/-/webpack-node-externals-1.7.2.tgz",
|
||||
@ -9077,6 +9107,12 @@
|
||||
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz",
|
||||
"integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho="
|
||||
},
|
||||
"wildcard": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/wildcard/-/wildcard-2.0.0.tgz",
|
||||
"integrity": "sha512-JcKqAHLPxcdb9KM49dufGXn2x3ssnfjbcaQdLlfZsL9rH9wgDQjUtDxbo8NE0F6SFvydeu1VhZe7hZuHsB2/pw==",
|
||||
"dev": true
|
||||
},
|
||||
"wolfy87-eventemitter": {
|
||||
"version": "5.2.9",
|
||||
"resolved": "https://registry.npmjs.org/wolfy87-eventemitter/-/wolfy87-eventemitter-5.2.9.tgz",
|
||||
|
@ -12,11 +12,11 @@
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:snapshots": "npm run build && jest -u",
|
||||
"start": "npm run build:watch",
|
||||
"build": "webpack --config webpack.config.js --display errors-only",
|
||||
"build:watch": "npm run build -- --watch",
|
||||
"build": "webpack --config webpack/webpack.config.development.js --display errors-only",
|
||||
"build:production": "webpack --config webpack/webpack.config.production.js --display errors-only",
|
||||
"start": "npm run build -- --watch",
|
||||
"bootstrap": "npm run build",
|
||||
"prepublish": "npm run build"
|
||||
"prepare": "npm run build:production"
|
||||
},
|
||||
"jest": {
|
||||
"setupFiles": [
|
||||
@ -41,6 +41,7 @@
|
||||
"rimraf": "^3.0.2",
|
||||
"webpack": "^4.43.0",
|
||||
"webpack-cli": "^3.3.12",
|
||||
"webpack-merge": "^5.0.7",
|
||||
"webpack-node-externals": "^1.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
// @flow
|
||||
import commander from 'commander';
|
||||
import { getAllOptions, exit, logErrorExit1 } from '../util';
|
||||
import { getAllOptions, exit, logErrorExit1, getDefaultAppDataDir } from '../util';
|
||||
|
||||
describe('getAllOptions()', () => {
|
||||
it('should combine options from all commands into one object', () => {
|
||||
@ -63,3 +63,29 @@ describe('logErrorExit1()', () => {
|
||||
expect(exitSpy).toHaveBeenCalledWith(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDefaultAppDataDir()', () => {
|
||||
const OLD_ENV = process.env;
|
||||
|
||||
beforeEach(() => {
|
||||
process.env = { ...OLD_ENV }; // make a copy
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
process.env = OLD_ENV; // restore old env
|
||||
});
|
||||
|
||||
it('should return value if set', () => {
|
||||
const value = 'dir';
|
||||
process.env.DEFAULT_APP_DATA_DIR = value;
|
||||
expect(getDefaultAppDataDir()).toBe(value);
|
||||
});
|
||||
|
||||
it('should throw error if not set', () => {
|
||||
process.env.DEFAULT_APP_DATA_DIR = '';
|
||||
|
||||
expect(getDefaultAppDataDir).toThrowError(
|
||||
'Environment variable DEFAULT_APP_DATA_DIR is not set.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -3,6 +3,7 @@ import type { ApiSpec, BaseModel, Environment, UnitTest, UnitTestSuite, Workspac
|
||||
import envPaths from 'env-paths';
|
||||
import gitAdapter from './adapters/git-adapter';
|
||||
import neDbAdapter from './adapters/ne-db-adapter';
|
||||
import { getDefaultAppDataDir } from '../util';
|
||||
|
||||
export type Database = {|
|
||||
ApiSpec: Array<ApiSpec>,
|
||||
@ -49,9 +50,8 @@ export const loadDb = async ({
|
||||
|
||||
// try load from nedb
|
||||
if (!db) {
|
||||
// TODO: Note, unit tests will also try to access the Insomnia Designer app data directory. We should configure this depending on development or production.
|
||||
db = await neDbAdapter(
|
||||
appDataDir || envPaths('Insomnia Designer', { suffix: '' }).data,
|
||||
appDataDir || envPaths(getDefaultAppDataDir(), { suffix: '' }).data,
|
||||
filterTypes,
|
||||
);
|
||||
}
|
||||
|
@ -44,3 +44,13 @@ export function logErrorExit1(err: Error) {
|
||||
export async function exit(result: Promise<boolean>): Promise<void> {
|
||||
return result.then(r => process.exit(r ? 0 : 1)).catch(logErrorExit1);
|
||||
}
|
||||
|
||||
export function getDefaultAppDataDir(): string {
|
||||
const dir = process.env.DEFAULT_APP_DATA_DIR;
|
||||
|
||||
if (!dir) {
|
||||
throw new Error('Environment variable DEFAULT_APP_DATA_DIR is not set.');
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
@ -4,13 +4,9 @@ const nodeExternals = require('webpack-node-externals');
|
||||
module.exports = {
|
||||
entry: { index: './src/cli.js' },
|
||||
target: 'node',
|
||||
mode: 'production',
|
||||
devtool: 'source-map',
|
||||
optimization: {
|
||||
minimize: false,
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
path: path.resolve(__dirname, '..', 'dist'),
|
||||
filename: '[name].js',
|
||||
library: 'insomniacli',
|
||||
libraryTarget: 'commonjs2',
|
13
packages/insomnia-inso/webpack/webpack.config.development.js
Normal file
13
packages/insomnia-inso/webpack/webpack.config.development.js
Normal file
@ -0,0 +1,13 @@
|
||||
const webpack = require('webpack');
|
||||
const {merge} = require('webpack-merge');
|
||||
const base = require('./webpack.config.base');
|
||||
|
||||
module.exports = merge(base, {
|
||||
mode: 'development',
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
__DEV__: true,
|
||||
'process.env.DEFAULT_APP_DATA_DIR': JSON.stringify('insomnia-app'),
|
||||
}),
|
||||
],
|
||||
});
|
15
packages/insomnia-inso/webpack/webpack.config.production.js
Normal file
15
packages/insomnia-inso/webpack/webpack.config.production.js
Normal file
@ -0,0 +1,15 @@
|
||||
const webpack = require('webpack');
|
||||
const {merge} = require('webpack-merge');
|
||||
const base = require('./webpack.config.base');
|
||||
|
||||
module.exports = merge(base, {
|
||||
mode: 'production',
|
||||
optimization: {
|
||||
minimize: true,
|
||||
},
|
||||
plugins: [
|
||||
new webpack.DefinePlugin({
|
||||
'process.env.DEFAULT_APP_DATA_DIR': JSON.stringify('Insomnia Designer'),
|
||||
}),
|
||||
],
|
||||
});
|
Loading…
Reference in New Issue
Block a user