Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-mock-api-middleware

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-mock-api-middleware - npm Package Compare versions

Comparing version 0.0.1-1.test to 0.0.1

.editorconfig

70

createMockMiddleware.js

@@ -1,2 +0,1 @@

import { existsSync } from 'fs';
import { join, basename } from 'path';

@@ -16,5 +15,3 @@ import bodyParser from 'body-parser';

const absMockPath = mockDir;
const absConfigPath = join(mockDir, '.umirc.mock.js');
const absPagesPath = join(mockDir, 'pages');
const debug = console.debug;
const { debug } = console;
const errors = [];

@@ -27,8 +24,5 @@

if (process.env.WATCH_FILES === 'none') return;
const watcher = chokidar.watch(
[absConfigPath, absMockPath, join(absPagesPath, '**/_mock.js')],
{
ignoreInitial: true,
}
);
const watcher = chokidar.watch([absMockPath], {
ignoreInitial: true,
});
watcher.on('all', (event, file) => {

@@ -49,33 +43,21 @@ debug(`[${event}] ${file}, reload mock data`);

let ret = {};
if (existsSync(absConfigPath)) {
debug(`load mock data from ${absConfigPath}`);
ret = require(absConfigPath); // eslint-disable-line
} else {
const mockFiles = glob
.sync('**/*.js', {
cwd: absMockPath,
})
.map(p => join(absMockPath, p))
.concat(
glob
.sync('**/_mock.js', {
cwd: absPagesPath,
})
.map(p => join(absPagesPath, p))
);
debug(`load mock data from ${absMockPath}, including files ${JSON.stringify(mockFiles)}`);
try {
ret = mockFiles.reduce((memo, mockFile) => {
const m = require(mockFile); // eslint-disable-line
memo = {
...memo,
...(m.default || m),
};
return memo;
}, {});
} catch (e) {
errors.push(e);
signale.error(`Mock file parse failed`);
console.error(e.message);
}
const mockFiles = glob
.sync('**/*.js', {
cwd: absMockPath,
})
.map(p => join(absMockPath, p));
debug(`load mock data from ${absMockPath}, including files ${JSON.stringify(mockFiles)}`);
try {
ret = mockFiles.reduce((memo, mockFile) => {
const m = require(mockFile); // eslint-disable-line
memo = {
...memo,
...(m.default || m),
};
return memo;
}, {});
} catch (e) {
errors.push(e);
signale.error(`Mock file parse failed`);
console.error(e.message);
}

@@ -151,7 +133,3 @@ return normalizeConfig(ret);

Object.keys(require.cache).forEach(file => {
if (
file === absConfigPath ||
file.indexOf(absMockPath) > -1 ||
basename(file) === '_mock.js'
) {
if (file.indexOf(absMockPath) > -1 || basename(file) === '_mock.js') {
delete require.cache[file];

@@ -158,0 +136,0 @@ }

{
"name": "express-mock-api-middleware",
"version": "0.0.1-001.test",
"description": "Webpack middleware for mocking restful APIs",
"version": "0.0.1",
"description": "Express middleware for mocking restful APIs",
"main": "index.js",

@@ -14,3 +14,3 @@ "scripts": {

"keywords": [
"webpack",
"express",
"middleware",

@@ -25,3 +25,22 @@ "api",

},
"homepage": "https://github.com/TechStark/express-mock-api-middleware#readme"
"homepage": "https://github.com/TechStark/express-mock-api-middleware#readme",
"dependencies": {
"assert": "^1.4.1",
"body-parser": "^1.18.3",
"chokidar": "^2.1.2",
"glob": "^7.1.3",
"multer": "^1.4.1",
"path-to-regexp": "^3.0.0",
"signale": "^1.4.0"
},
"devDependencies": {
"babel-eslint": "^10.0.1",
"eslint": "^5.3.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-plugin-babel": "^5.3.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^3.0.1",
"prettier": "^1.16.4"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc