@zwa73/dev-utils 1.0.42 → 1.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,7 @@ const CmdMapPath = (program) => program
27
27
  if (!DupMethodList.includes(options.duplicateHandling))
28
28
  (0, utils_1.throwError)(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
29
29
  const duplicateHandling = options.duplicateHandling;
30
- const basePath = process.cwd();
30
+ const basePath = (0, utils_1.posixizePath)(process.cwd());
31
31
  // 遍历当前目录下的所有文件
32
32
  const filePaths = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, { relative: options.recursive, style: "posix" })
33
33
  .map((filePath) => path_1.default.posix.relative(basePath, filePath))
@@ -27,7 +27,7 @@ const CmdScanDups = (program) => program
27
27
  .option("-r, --recursive", "是否处理子目录, 默认 true", true)
28
28
  .action(async (options) => {
29
29
  const regex = new RegExp(options.regex);
30
- const basePath = process.cwd();
30
+ const basePath = (0, utils_1.posixizePath)(process.cwd());
31
31
  const pList = utils_1.UtilFT.fileSearchRegex(basePath, regex.source, {
32
32
  relative: options.recursive,
33
33
  style: "posix",
@@ -124,7 +124,7 @@ var UtilDT;
124
124
  if (!Array.isArray(filepath))
125
125
  filepath = [filepath];
126
126
  // 将所有的相对路径转换为绝对路径
127
- const absolutePaths = filepath.map(fp => path.resolve(process.cwd(), fp).replaceAll("\\", "/"));
127
+ const absolutePaths = filepath.map(fp => path.posix.resolve((0, utils_1.posixizePath)(process.cwd()), (0, utils_1.posixizePath)(fp)));
128
128
  // 创建一个字符串,其中包含所有文件的 require 语句
129
129
  const requires = absolutePaths.map(fp => `require('${fp}')`).join(';');
130
130
  // 创建并执行 ts-node 命令
@@ -142,9 +142,9 @@ var UtilDT;
142
142
  ? opt.glob
143
143
  ? utils_1.UtilFT.fileSearchGlob(process.cwd(), opt.filePath, { style: "posix" })
144
144
  : typeof opt?.filePath === "string"
145
- ? [opt?.filePath.replaceAll('\\', '/')]
146
- : opt?.filePath.map((filepath) => filepath.replaceAll('\\', '/'))
147
- : [basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2").replaceAll('\\', '/')];
145
+ ? [(0, utils_1.posixizePath)(opt?.filePath)]
146
+ : opt?.filePath.map((filepath) => (0, utils_1.posixizePath)(filepath))
147
+ : [(0, utils_1.posixizePath)(basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/, "$1.$2"))];
148
148
  };
149
149
  const readFile = async (basePath) => (await fs.promises.readFile(basePath, 'utf-8')).replaceAll("\r\n", "\n");
150
150
  const parseCodeText = async (codeText, opt) => {
package/dist/UtilMacro.js CHANGED
@@ -15,7 +15,7 @@ var UtilMacro;
15
15
  */
16
16
  function exportComment(glob) {
17
17
  (0, QuickFunc_1.commentMacro)(/export (\S*)/, ({ filePath, matchId, execArr }) => {
18
- const basedir = path_1.default.dirname(filePath).replaceAll('\\', '/');
18
+ const basedir = (0, utils_1.posixizePath)(path_1.default.dirname(filePath));
19
19
  const result = utils_1.UtilFT.fileSearchGlob(basedir, execArr[1], { style: 'posix' })
20
20
  .map((file) => path_1.default.posix.relative(basedir, file))
21
21
  .map((file) => path_1.default.parse(file).name)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zwa73/dev-utils",
3
- "version": "1.0.42",
3
+ "version": "1.0.44",
4
4
  "description": "编译与调试工具",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  "author": "zwa73",
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
- "@zwa73/utils": "^1.0.118",
19
+ "@zwa73/utils": "^1.0.119",
20
20
  "commander": "^11.1.0",
21
21
  "ts-node": "^10.9.2",
22
22
  "tsconfig-paths": "^4.2.0",
@@ -1,4 +1,4 @@
1
- import { SLogger, UtilFT, matchProc, throwError } from "@zwa73/utils";
1
+ import { SLogger, UtilFT, matchProc, posixizePath, throwError } from "@zwa73/utils";
2
2
  import { Command } from "commander";
3
3
  import fs from "fs";
4
4
  import path from "path";
@@ -25,7 +25,7 @@ export const CmdMapPath = (program: Command) => program
25
25
  if(!DupMethodList.includes(options.duplicateHandling))
26
26
  throwError(`${options.duplicateHandling} 不是有效的 duplicate-handling`);
27
27
  const duplicateHandling = options.duplicateHandling as DupMethod;
28
- const basePath = process.cwd();
28
+ const basePath = posixizePath(process.cwd());
29
29
  // 遍历当前目录下的所有文件
30
30
  const filePaths = UtilFT.fileSearchRegex(basePath, regex.source,{relative:options.recursive,style:"posix"})
31
31
  .map((filePath)=>path.posix.relative(basePath, filePath))
@@ -1,4 +1,4 @@
1
- import { SLogger, UtilFT } from "@zwa73/utils";
1
+ import { SLogger, UtilFT, posixizePath, stylizePath } from "@zwa73/utils";
2
2
  import { Command } from "commander";
3
3
  import fs from "fs";
4
4
  import crypto from 'crypto';
@@ -25,7 +25,7 @@ export const CmdScanDups = (program: Command) => program
25
25
  .option("-r, --recursive", "是否处理子目录, 默认 true", true)
26
26
  .action(async (options) => {
27
27
  const regex = new RegExp(options.regex);
28
- const basePath = process.cwd()
28
+ const basePath = posixizePath(process.cwd());
29
29
  const pList = UtilFT.fileSearchRegex(basePath, regex.source, {
30
30
  relative: options.recursive,
31
31
  style: "posix",
@@ -1,7 +1,7 @@
1
1
  import * as path from 'path';
2
2
  import * as TJS from 'typescript-json-schema';
3
3
  import * as fs from 'fs';
4
- import { JObject, SLogger, UtilFT, UtilFunc, dedent, throwError } from '@zwa73/utils';
4
+ import { JObject, SLogger, UtilFT, UtilFunc, dedent, posixizePath, stylizePath, throwError } from '@zwa73/utils';
5
5
 
6
6
  export namespace UtilDT{
7
7
 
@@ -123,7 +123,7 @@ export async function batchNode(filepath:string|string[],opt?:BatchNodeOpt) {
123
123
  // 确保 filepath 总是一个数组
124
124
  if (!Array.isArray(filepath)) filepath = [filepath];
125
125
  // 将所有的相对路径转换为绝对路径
126
- const absolutePaths = filepath.map(fp => path.resolve(process.cwd(), fp).replaceAll("\\","/"));
126
+ const absolutePaths = filepath.map(fp => path.posix.resolve(posixizePath(process.cwd()), posixizePath(fp)));
127
127
  // 创建一个字符串,其中包含所有文件的 require 语句
128
128
  const requires = absolutePaths.map(fp => `require('${fp}')`).join(';');
129
129
  // 创建并执行 ts-node 命令
@@ -160,9 +160,9 @@ const parseMacroPaths = (opt?:MacroOpt)=>{
160
160
  ? opt.glob
161
161
  ? UtilFT.fileSearchGlob(process.cwd(),opt.filePath,{style:"posix"})
162
162
  : typeof opt?.filePath==="string"
163
- ? [opt?.filePath.replaceAll('\\','/')]
164
- : opt?.filePath.map((filepath)=>filepath.replaceAll('\\','/'))
165
- : [basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/,"$1.$2").replaceAll('\\','/')];
163
+ ? [posixizePath(opt?.filePath)]
164
+ : opt?.filePath.map((filepath)=>posixizePath(filepath))
165
+ : [posixizePath(basePath.replace(/(.+)\.macro\.(js|ts|cjs|mjs)$/,"$1.$2"))];
166
166
  }
167
167
  const readFile = async (basePath:string)=>
168
168
  (await fs.promises.readFile(basePath,'utf-8')).replaceAll("\r\n","\n");
package/src/UtilMacro.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UtilFT } from "@zwa73/utils";
1
+ import { UtilFT, posixizePath, stylizePath } from "@zwa73/utils";
2
2
  import { commentMacro } from "./QuickFunc"
3
3
  import path from "path";
4
4
 
@@ -10,7 +10,7 @@ export namespace UtilMacro{
10
10
  */
11
11
  export function exportComment(glob:string){
12
12
  commentMacro(/export (\S*)/,({filePath,matchId,execArr})=>{
13
- const basedir = path.dirname(filePath).replaceAll('\\','/');
13
+ const basedir = posixizePath(path.dirname(filePath));
14
14
  const result = UtilFT.fileSearchGlob(basedir,execArr[1],{style:'posix'})
15
15
  .map((file)=>path.posix.relative(basedir,file))
16
16
  .map((file)=>path.parse(file).name)