New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@medux/dev-utils

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@medux/dev-utils - npm Package Compare versions

Comparing version
3.0.4
to
3.0.5
+1
-1
lib/api-mock/index.d.ts
import { NextFunction, Request, Response } from 'express';
declare const _default: (mockDir: string) => (req: Request, res: Response, next: NextFunction) => any;
declare const _default: (mockFile: string) => (req: Request, res: Response, next: NextFunction) => any;
export = _default;

@@ -5,17 +5,17 @@ "use strict";

const chalk = require("chalk");
module.exports = function createMiddleware(mockDir) {
const indexFile = path.join(mockDir, 'index.js');
console.info(`enable ${chalk.magenta('api mock')} file: ${chalk.underline(indexFile)}`);
module.exports = function createMiddleware(mockFile) {
console.info(`enable ${chalk.magenta('api mock')} file: ${chalk.underline(mockFile)}`);
const mockDir = path.dirname(mockFile);
if (!fs.existsSync(mockDir)) {
fs.mkdirSync(mockDir);
}
if (!fs.existsSync(indexFile)) {
fs.writeFileSync(indexFile, 'module.exports = {}');
if (!fs.existsSync(mockFile)) {
fs.writeFileSync(mockFile, 'module.exports = {}');
}
return (req, res, next) => {
const str = fs
.readFileSync(indexFile)
.readFileSync(mockFile)
.toString()
.replace(/^[^{]+/, 'return ')
.replace(/\brequire\(/g, '(');
.replace(/\b(require|import)\(/g, '(');
const indexMap = new Function(str)();

@@ -27,3 +27,13 @@ let mockPath;

const extname = path.extname(indexMap[rule]);
mockPath = extname ? path.join(mockDir, indexMap[rule]) : path.join(mockDir, `${indexMap[rule]}.js`);
if (extname) {
if (fs.existsSync(path.join(mockDir, indexMap[rule]))) {
mockPath = path.join(mockDir, indexMap[rule]);
}
}
else if (fs.existsSync(path.join(mockDir, `${indexMap[rule]}.js`))) {
mockPath = path.join(mockDir, `${indexMap[rule]}.js`);
}
else if (fs.existsSync(path.join(mockDir, `${indexMap[rule]}.ts`))) {
mockPath = path.join(mockDir, `${indexMap[rule]}.ts`);
}
return true;

@@ -33,3 +43,3 @@ }

});
if (mockPath && fs.existsSync(mockPath)) {
if (mockPath) {
delete require.cache[mockPath];

@@ -36,0 +46,0 @@ const middleware = require(mockPath);

@@ -9,6 +9,13 @@ "use strict";

function patch(_tsconfig, _entryFilePath, _echo) {
const RootPath = process.cwd();
const rootPath = process.cwd();
const srcPath = path.join(rootPath, 'src');
let tsconfig;
if (!_tsconfig) {
tsconfig = require(path.join(RootPath, './tsconfig.json'));
if (fs.existsSync(path.join(srcPath, './tsconfig.json'))) {
tsconfig = require(path.join(srcPath, './tsconfig.json'));
process.chdir('./src');
}
else {
tsconfig = require(path.join(rootPath, './tsconfig.json'));
}
}

@@ -21,3 +28,2 @@ else if (typeof _tsconfig === 'string') {

}
const srcPath = path.join(RootPath, 'src');
const entryFilePath = _entryFilePath || (fs.existsSync(path.join(srcPath, 'Global.ts')) ? path.join(srcPath, 'Global.ts') : path.join(srcPath, 'Global.tsx'));

@@ -24,0 +30,0 @@ const source = fs.readFileSync(entryFilePath).toString();

{
"name": "@medux/dev-utils",
"version": "3.0.4",
"version": "3.0.5",
"description": "Common development tools.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/wooline/medux/tree/master/packages/dev-utils",