cus-loader-utils
Advanced tools
| type TypeBeforeExitHook = (cb: () => void) => void; | ||
| declare const beforeExitHook: TypeBeforeExitHook; | ||
| export default beforeExitHook; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var process = require("node:process"); | ||
| var beforeExitHook = function (cb) { | ||
| // 执行结束,释放内存 | ||
| process.on('beforeExit', function () { | ||
| console.log('执行结束,释放内存'); | ||
| cb(); | ||
| }); | ||
| }; | ||
| exports.default = beforeExitHook; |
| /// <reference types="node" /> | ||
| declare const getDiffByDirAndLogFile: () => { | ||
| writeResultToFile: (writePath: string, list: string[]) => void; | ||
| removeSameItemByList: (liata: string[], listb: string[]) => string[]; | ||
| getListByLogFile: (logPath: string | Buffer) => string[]; | ||
| getAllFileByDir: (dirPath: string, endsWith: string) => string[]; | ||
| }; | ||
| export default getDiffByDirAndLogFile; |
| "use strict"; | ||
| var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
| if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
| if (ar || !(i in from)) { | ||
| if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
| ar[i] = from[i]; | ||
| } | ||
| } | ||
| return to.concat(ar || Array.prototype.slice.call(from)); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var fs = require("fs"); | ||
| var path = require("path"); | ||
| var removeRepeatByList = function (list) { | ||
| return list.reduce(function (result, item) { | ||
| var flag = result.find(function (_) { return _ === item; }); | ||
| if (!flag) { | ||
| result.push(item); | ||
| } | ||
| return result; | ||
| }, []); | ||
| }; | ||
| var getDiffByDirAndLogFile = function () { | ||
| return { | ||
| writeResultToFile: function (writePath, list) { | ||
| try { | ||
| fs.writeFileSync(writePath, JSON.stringify(list)); | ||
| } | ||
| catch (_a) { | ||
| throw new Error('写入最终结果失败'); | ||
| } | ||
| }, | ||
| removeSameItemByList: function (liata, listb) { | ||
| return liata.reduce(function (result, item) { | ||
| var matched = listb.find(function (i) { return i === item; }); | ||
| if (!matched) { | ||
| result.push(item); | ||
| } | ||
| return result; | ||
| }, []); | ||
| }, | ||
| getListByLogFile: function (logPath) { | ||
| try { | ||
| var logFile = fs.readFileSync(logPath, 'utf8'); | ||
| var list = logFile.split('\n'); | ||
| return removeRepeatByList(list); | ||
| } | ||
| catch (_a) { | ||
| throw new Error('logFile 不存在'); | ||
| } | ||
| }, | ||
| getAllFileByDir: function getAllFileByDir(dirPath, endsWith) { | ||
| if (!endsWith) { | ||
| throw new Error('endsWith 不能为空'); | ||
| } | ||
| var files = fs.readdirSync(dirPath); | ||
| return files.reduce(function (result, filename) { | ||
| var filedir = path.join(dirPath, filename); | ||
| var stats = fs.statSync(filedir); | ||
| var isFile = stats.isFile(); | ||
| var isDir = stats.isDirectory(); | ||
| if (isFile && filedir.endsWith(endsWith)) { | ||
| result.push(filedir); | ||
| } | ||
| if (isDir) { | ||
| var childResult = getAllFileByDir(filedir, endsWith); //递归,如果是文件夹,就继续遍历该文件夹下面的文件 | ||
| result = __spreadArray(__spreadArray([], result, true), childResult, true); | ||
| } | ||
| return result; | ||
| }, []); | ||
| }, | ||
| }; | ||
| }; | ||
| exports.default = getDiffByDirAndLogFile; |
| import * as process from 'node:process'; | ||
| type TypeBeforeExitHook = (cb: () => void) => void; | ||
| const beforeExitHook: TypeBeforeExitHook = (cb) => { | ||
| // 执行结束,释放内存 | ||
| process.on('beforeExit', function () { | ||
| console.log('执行结束,释放内存'); | ||
| cb(); | ||
| }); | ||
| }; | ||
| export default beforeExitHook; |
| import * as fs from 'fs'; | ||
| import * as path from 'path'; | ||
| const removeRepeatByList = (list: string[]) => { | ||
| return list.reduce((result, item) => { | ||
| const flag = result.find((_) => _ === item); | ||
| if (!flag) { | ||
| result.push(item); | ||
| } | ||
| return result; | ||
| }, <string[]>[]); | ||
| }; | ||
| const getDiffByDirAndLogFile = () => { | ||
| return { | ||
| writeResultToFile: (writePath: string, list: string[]) => { | ||
| try { | ||
| fs.writeFileSync(writePath, JSON.stringify(list)); | ||
| } catch { | ||
| throw new Error('写入最终结果失败'); | ||
| } | ||
| }, | ||
| removeSameItemByList: (liata: string[], listb: string[]) => { | ||
| return liata.reduce((result, item) => { | ||
| const matched = listb.find((i) => i === item); | ||
| if (!matched) { | ||
| result.push(item); | ||
| } | ||
| return result; | ||
| }, <string[]>[]); | ||
| }, | ||
| getListByLogFile: function (logPath: string | Buffer) { | ||
| try { | ||
| const logFile = fs.readFileSync(logPath, 'utf8'); | ||
| const list = logFile.split('\n'); | ||
| return removeRepeatByList(list); | ||
| } catch { | ||
| throw new Error('logFile 不存在'); | ||
| } | ||
| }, | ||
| getAllFileByDir: function getAllFileByDir(dirPath: string, endsWith: string) { | ||
| if (!endsWith) { | ||
| throw new Error('endsWith 不能为空'); | ||
| } | ||
| const files = fs.readdirSync(dirPath); | ||
| return files.reduce((result, filename) => { | ||
| const filedir = path.join(dirPath, filename); | ||
| const stats = fs.statSync(filedir); | ||
| const isFile = stats.isFile(); | ||
| const isDir = stats.isDirectory(); | ||
| if (isFile && filedir.endsWith(endsWith)) { | ||
| result.push(filedir); | ||
| } | ||
| if (isDir) { | ||
| const childResult = getAllFileByDir(filedir, endsWith); //递归,如果是文件夹,就继续遍历该文件夹下面的文件 | ||
| result = [...result, ...childResult]; | ||
| } | ||
| return result; | ||
| }, <string[]>[]); | ||
| }, | ||
| }; | ||
| }; | ||
| export default getDiffByDirAndLogFile; |
+20
| # cus-loader-utils | ||
| ### Installation | ||
| `npm i cus-loader-utils` | ||
| ## Usage | ||
| ```javascript | ||
| const { beforeExitHook, getDiffByDirAndLogFile } = require('cus-loader-utils'); | ||
| // 退出执行进程前的 清理函数 | ||
| beforeExitHook(); | ||
| // getAllFileByDir(dirPath, endsWidth) 执行 从指定目录下获取所有文件 <dirPath 表示从哪个目录开始,endsWidth 表示过滤这个目录下的那些后缀名文件> | ||
| // getListByLogFile(logPath) 执行 从指定目录下获取 log 文件 并且进行切割为数组 <logPath 表示 log文件 绝对路径> | ||
| // removeSameItemByList(liata, liatb) 执行 两个数组的对比 <liata 表示所有数据源的数组,liatb 表示需要被过滤的数组> | ||
| // writeResultToFile(writePath, list) 执行 拿到的数组进行写文件 <writePath 表示从写入路径,list 表示 写入的数组> | ||
| const { writeResultToFile, removeSameItemByList, getListByLogFile, getAllFileByDir } = getDiffByDirAndLogFile(); | ||
| ``` |
+2
-3
@@ -1,3 +0,2 @@ | ||
| type TypeBeforeExitHook = (cb: () => void) => void; | ||
| declare const beforeExitHook: TypeBeforeExitHook; | ||
| export default beforeExitHook; | ||
| export { default as beforeExitHook } from './beforeExitHook'; | ||
| export { default as getDiffByDirAndLogFile } from './getDiffByDirAndLogFile'; |
+5
-9
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var process = require("node:process"); | ||
| var beforeExitHook = function (cb) { | ||
| // 执行结束,释放内存 | ||
| process.on('beforeExit', function () { | ||
| console.log('执行结束,释放内存'); | ||
| cb(); | ||
| }); | ||
| }; | ||
| exports.default = beforeExitHook; | ||
| exports.getDiffByDirAndLogFile = exports.beforeExitHook = void 0; | ||
| var beforeExitHook_1 = require("./beforeExitHook"); | ||
| Object.defineProperty(exports, "beforeExitHook", { enumerable: true, get: function () { return beforeExitHook_1.default; } }); | ||
| var getDiffByDirAndLogFile_1 = require("./getDiffByDirAndLogFile"); | ||
| Object.defineProperty(exports, "getDiffByDirAndLogFile", { enumerable: true, get: function () { return getDiffByDirAndLogFile_1.default; } }); |
+2
-12
@@ -1,12 +0,2 @@ | ||
| import * as process from 'node:process'; | ||
| type TypeBeforeExitHook = (cb: () => void) => void; | ||
| const beforeExitHook: TypeBeforeExitHook = (cb) => { | ||
| // 执行结束,释放内存 | ||
| process.on('beforeExit', function () { | ||
| console.log('执行结束,释放内存'); | ||
| cb(); | ||
| }); | ||
| }; | ||
| export default beforeExitHook; | ||
| export { default as beforeExitHook } from './beforeExitHook'; | ||
| export { default as getDiffByDirAndLogFile } from './getDiffByDirAndLogFile'; |
+30
-30
| { | ||
| "name": "cus-loader-utils", | ||
| "version": "1.0.0", | ||
| "description": "cus loader utils", | ||
| "main": "dist/index.js", | ||
| "scripts": { | ||
| "build": "tsc ./lib/index.ts -outDir ./dist -declaration true", | ||
| "showConfig": "npx tsc --showConfig" | ||
| }, | ||
| "license": "ISC", | ||
| "directories": { | ||
| "lib": "lib", | ||
| "test": "__tests__" | ||
| }, | ||
| "keywords": [ | ||
| "cus", | ||
| "loader", | ||
| "utils" | ||
| ], | ||
| "typings": "dist/index.d.ts", | ||
| "files": [ | ||
| "lib", | ||
| "dist", | ||
| "types" | ||
| ], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/webgzh907247189/webpack-loader.git" | ||
| }, | ||
| "author": "" | ||
| } | ||
| "name": "cus-loader-utils", | ||
| "version": "1.0.1", | ||
| "description": "cus loader utils", | ||
| "main": "dist/index.js", | ||
| "license": "ISC", | ||
| "directories": { | ||
| "lib": "lib", | ||
| "test": "__tests__" | ||
| }, | ||
| "keywords": [ | ||
| "cus", | ||
| "loader", | ||
| "utils" | ||
| ], | ||
| "typings": "dist/index.d.ts", | ||
| "files": [ | ||
| "lib", | ||
| "dist", | ||
| "types" | ||
| ], | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/webgzh907247189/webpack-loader.git" | ||
| }, | ||
| "author": "", | ||
| "scripts": { | ||
| "build": "tsc ./lib/index.ts -outDir ./dist -declaration true", | ||
| "showConfig": "npx tsc --showConfig" | ||
| } | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
8702
481.3%11
175%178
641.67%1
-50%21
Infinity%2
Infinity%1
Infinity%