path-serializer 0.2.2 → 0.3.1

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.
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  [![npm latest version](https://img.shields.io/npm/v/path-serializer?style=flat-square&color=98c379)](https://www.npmjs.com/package/path-serializer)
4
4
 
5
+ 1. stabilize pnpm dependencies path and update dependencies smoothly
6
+ 2. transform win32 path to posix path
7
+ and more...
8
+
5
9
  ```ts
6
10
  // __snapshots__/index.test.ts.snap
7
11
  {
@@ -2,14 +2,18 @@ export declare function createSnapshotSerializer(options?: SnapshotSerializerOpt
2
2
 
3
3
  declare interface Features {
4
4
  /**
5
+ * /foo/node_modules/.pnpm -> <ROOT>/node_modules/.pnpm
5
6
  * @default true
6
7
  */
7
8
  replaceRoot?: boolean;
8
9
  /**
10
+ * /foo/rspack/packages/core/src -> <WORKSPACE>/src
9
11
  * @default true
10
12
  */
11
13
  replaceWorkspace?: boolean;
12
14
  /**
15
+ * /foo/node_modules/.pnpm/@swc+helpers@0.5.11/node_modules/@swc/helpers/esm/_class_private_method_get.js
16
+ * -> /foo/node_modules/<PNPM_INNER>/@swc/helpers/esm/_class_private_method_get.js
13
17
  * @default true
14
18
  */
15
19
  replacePnpmInner?: boolean;
@@ -22,10 +26,13 @@ declare interface Features {
22
26
  */
23
27
  replaceHomeDir?: boolean;
24
28
  /**
29
+ * foo -> "foo"
25
30
  * @default true
26
31
  */
27
32
  addDoubleQuotes?: boolean;
28
33
  /**
34
+ * D:\\foo\\node_modules\\<PNPM_INNER>\\css-loader\\utils.ts
35
+ * -> /d/foo/node_modules/<PNPM_INNER>/css-loader/utils.ts
29
36
  * @default true
30
37
  */
31
38
  transformWin32Path?: boolean;
@@ -34,9 +41,16 @@ declare interface Features {
34
41
  */
35
42
  escapeDoubleQuotes?: boolean;
36
43
  /**
44
+ * \r\n -> \n
37
45
  * @default true
38
46
  */
39
47
  escapeEOL?: boolean;
48
+ /**
49
+ * \u001b[1mBold Text\u001b[0m
50
+ * -> <CLR=BOLD>Bold Text<CLR=0>
51
+ * @default true
52
+ */
53
+ transformCLR?: boolean;
40
54
  }
41
55
 
42
56
  declare interface PathMatcher {
package/dist/cjs/index.js CHANGED
@@ -772,8 +772,6 @@ function __webpack_require__(moduleId) {
772
772
  var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
773
773
  const external_node_os_namespaceObject = require("node:os");
774
774
  var external_node_os_default = /*#__PURE__*/ __webpack_require__.n(external_node_os_namespaceObject);
775
- const external_node_path_namespaceObject = require("node:path");
776
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
777
775
  /**
778
776
  * Used to match `RegExp`
779
777
  * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
@@ -797,9 +795,6 @@ function __webpack_require__(moduleId) {
797
795
  return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, '\\$&') : string;
798
796
  }
799
797
  /* harmony default export */ const lodash_es_escapeRegExp = escapeRegExp;
800
- // EXTERNAL MODULE: ./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js
801
- var upath = __webpack_require__("./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js");
802
- var upath_default = /*#__PURE__*/ __webpack_require__.n(upath);
803
798
  function getRealTemporaryDirectory() {
804
799
  let ret = null;
805
800
  try {
@@ -808,7 +803,6 @@ function __webpack_require__(moduleId) {
808
803
  } catch {}
809
804
  return ret;
810
805
  }
811
- const normalizeToPosixPath = (p)=>upath_default().normalizeSafe(external_node_path_default().normalize(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
812
806
  /**
813
807
  * Compile path string to RegExp.
814
808
  * @note Only support posix path.
@@ -867,13 +861,20 @@ function __webpack_require__(moduleId) {
867
861
  mark: 'pnpmInner'
868
862
  }
869
863
  ];
870
- function transformCodeToPosixPath(code) {
871
- return code.replace(// ignore http, https, file
872
- /(?<![a-zA-Z])([a-zA-Z]:[\\/])([-\u4e00-\u9fa5\w\s.()~!@#$%^&()\[\]{}+=]+[\\/])*/g, (match, _diskName)=>normalizeToPosixPath(match));
873
- }
864
+ const external_node_path_namespaceObject = require("node:path");
865
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
866
+ // EXTERNAL MODULE: ./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js
867
+ var upath = __webpack_require__("./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js");
868
+ var upath_default = /*#__PURE__*/ __webpack_require__.n(upath);
869
+ const normalizePathToPosix = (p)=>upath_default().normalizeSafe(external_node_path_default().normalize(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
870
+ // find the path in code and replace it with normalizePathToPosix
871
+ const normalizeCodeToPosix = (code)=>code.replace(// ignore http, https, file
872
+ /(?<![a-zA-Z])([a-zA-Z]:[\\/])([-\u4e00-\u9fa5\w\s.()~!@#$%^&()\[\]{}+=]+[\\/])*/g, (match, _diskName)=>normalizePathToPosix(match));
873
+ const normalizeCLR = (str)=>str.replace(/\u001b\[1m\u001b\[([0-9;]*)m/g, '<CLR=$1,BOLD>').replace(/\u001b\[1m/g, '<CLR=BOLD>').replace(/\u001b\[39m\u001b\[22m/g, '</CLR>').replace(/\u001b\[([0-9;]*)m/g, '<CLR=$1>') // CHANGE: The time unit display in Rspack is second
874
+ .replace(/[.0-9]+(<\/CLR>)?(\s?s)/g, 'X$1$2');
874
875
  function createSnapshotSerializer(options) {
875
876
  const { root = process.cwd(), workspace = '', replace: customMatchers = [], replacePost: customPostMatchers = [], features = {} } = options || {};
876
- const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true, replaceHomeDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true } = features;
877
+ const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true, replaceHomeDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true, transformCLR = true } = features;
877
878
  function createPathMatchers() {
878
879
  const pathMatchers = [];
879
880
  pathMatchers.push(...customMatchers);
@@ -892,7 +893,7 @@ function __webpack_require__(moduleId) {
892
893
  return pathMatchers;
893
894
  }
894
895
  const pathMatchers = createPathMatchers();
895
- for (const matcher of pathMatchers)if ('string' == typeof matcher.match) matcher.match = normalizeToPosixPath(matcher.match);
896
+ for (const matcher of pathMatchers)if ('string' == typeof matcher.match) matcher.match = normalizePathToPosix(matcher.match);
896
897
  const serializer = {
897
898
  // match path-format string
898
899
  test (val) {
@@ -900,8 +901,9 @@ function __webpack_require__(moduleId) {
900
901
  },
901
902
  serialize (val) {
902
903
  let replaced = val;
903
- if (transformWin32Path) replaced = transformCodeToPosixPath(replaced);
904
+ if (transformWin32Path) replaced = normalizeCodeToPosix(replaced);
904
905
  replaced = applyMatcherReplacement(pathMatchers, replaced);
906
+ if (transformCLR) replaced = normalizeCLR(replaced);
905
907
  if (escapeDoubleQuotes) replaced = replaced.replace(/"/g, '\\"');
906
908
  if (escapeEOL) replaced = replaced.replace(/\\r\\n/g, '\\n');
907
909
  if (addDoubleQuotes) replaced = `"${replaced}"`;
@@ -2,14 +2,18 @@ export declare function createSnapshotSerializer(options?: SnapshotSerializerOpt
2
2
 
3
3
  declare interface Features {
4
4
  /**
5
+ * /foo/node_modules/.pnpm -> <ROOT>/node_modules/.pnpm
5
6
  * @default true
6
7
  */
7
8
  replaceRoot?: boolean;
8
9
  /**
10
+ * /foo/rspack/packages/core/src -> <WORKSPACE>/src
9
11
  * @default true
10
12
  */
11
13
  replaceWorkspace?: boolean;
12
14
  /**
15
+ * /foo/node_modules/.pnpm/@swc+helpers@0.5.11/node_modules/@swc/helpers/esm/_class_private_method_get.js
16
+ * -> /foo/node_modules/<PNPM_INNER>/@swc/helpers/esm/_class_private_method_get.js
13
17
  * @default true
14
18
  */
15
19
  replacePnpmInner?: boolean;
@@ -22,10 +26,13 @@ declare interface Features {
22
26
  */
23
27
  replaceHomeDir?: boolean;
24
28
  /**
29
+ * foo -> "foo"
25
30
  * @default true
26
31
  */
27
32
  addDoubleQuotes?: boolean;
28
33
  /**
34
+ * D:\\foo\\node_modules\\<PNPM_INNER>\\css-loader\\utils.ts
35
+ * -> /d/foo/node_modules/<PNPM_INNER>/css-loader/utils.ts
29
36
  * @default true
30
37
  */
31
38
  transformWin32Path?: boolean;
@@ -34,9 +41,16 @@ declare interface Features {
34
41
  */
35
42
  escapeDoubleQuotes?: boolean;
36
43
  /**
44
+ * \r\n -> \n
37
45
  * @default true
38
46
  */
39
47
  escapeEOL?: boolean;
48
+ /**
49
+ * \u001b[1mBold Text\u001b[0m
50
+ * -> <CLR=BOLD>Bold Text<CLR=0>
51
+ * @default true
52
+ */
53
+ transformCLR?: boolean;
40
54
  }
41
55
 
42
56
  declare interface PathMatcher {
@@ -772,9 +772,6 @@ function __webpack_require__(moduleId) {
772
772
  return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, '\\$&') : string;
773
773
  }
774
774
  /* harmony default export */ const lodash_es_escapeRegExp = escapeRegExp;
775
- // EXTERNAL MODULE: ./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js
776
- var upath = __webpack_require__("./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js");
777
- var upath_default = /*#__PURE__*/ __webpack_require__.n(upath);
778
775
  function getRealTemporaryDirectory() {
779
776
  let ret = null;
780
777
  try {
@@ -783,7 +780,6 @@ function getRealTemporaryDirectory() {
783
780
  } catch {}
784
781
  return ret;
785
782
  }
786
- const normalizeToPosixPath = (p)=>upath_default().normalizeSafe(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].normalize(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
787
783
  /**
788
784
  * Compile path string to RegExp.
789
785
  * @note Only support posix path.
@@ -842,13 +838,18 @@ const createPnpmInnerMatchers = ()=>[
842
838
  mark: 'pnpmInner'
843
839
  }
844
840
  ];
845
- function transformCodeToPosixPath(code) {
846
- return code.replace(// ignore http, https, file
847
- /(?<![a-zA-Z])([a-zA-Z]:[\\/])([-\u4e00-\u9fa5\w\s.()~!@#$%^&()\[\]{}+=]+[\\/])*/g, (match, _diskName)=>normalizeToPosixPath(match));
848
- }
841
+ // EXTERNAL MODULE: ./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js
842
+ var upath = __webpack_require__("./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js");
843
+ var upath_default = /*#__PURE__*/ __webpack_require__.n(upath);
844
+ const normalizePathToPosix = (p)=>upath_default().normalizeSafe(__WEBPACK_EXTERNAL_MODULE_node_path__["default"].normalize(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
845
+ // find the path in code and replace it with normalizePathToPosix
846
+ const normalizeCodeToPosix = (code)=>code.replace(// ignore http, https, file
847
+ /(?<![a-zA-Z])([a-zA-Z]:[\\/])([-\u4e00-\u9fa5\w\s.()~!@#$%^&()\[\]{}+=]+[\\/])*/g, (match, _diskName)=>normalizePathToPosix(match));
848
+ const normalizeCLR = (str)=>str.replace(/\u001b\[1m\u001b\[([0-9;]*)m/g, '<CLR=$1,BOLD>').replace(/\u001b\[1m/g, '<CLR=BOLD>').replace(/\u001b\[39m\u001b\[22m/g, '</CLR>').replace(/\u001b\[([0-9;]*)m/g, '<CLR=$1>') // CHANGE: The time unit display in Rspack is second
849
+ .replace(/[.0-9]+(<\/CLR>)?(\s?s)/g, 'X$1$2');
849
850
  function createSnapshotSerializer(options) {
850
851
  const { root = process.cwd(), workspace = '', replace: customMatchers = [], replacePost: customPostMatchers = [], features = {} } = options || {};
851
- const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true, replaceHomeDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true } = features;
852
+ const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true, replaceHomeDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true, transformCLR = true } = features;
852
853
  function createPathMatchers() {
853
854
  const pathMatchers = [];
854
855
  pathMatchers.push(...customMatchers);
@@ -867,7 +868,7 @@ function createSnapshotSerializer(options) {
867
868
  return pathMatchers;
868
869
  }
869
870
  const pathMatchers = createPathMatchers();
870
- for (const matcher of pathMatchers)if ('string' == typeof matcher.match) matcher.match = normalizeToPosixPath(matcher.match);
871
+ for (const matcher of pathMatchers)if ('string' == typeof matcher.match) matcher.match = normalizePathToPosix(matcher.match);
871
872
  const serializer = {
872
873
  // match path-format string
873
874
  test (val) {
@@ -875,8 +876,9 @@ function createSnapshotSerializer(options) {
875
876
  },
876
877
  serialize (val) {
877
878
  let replaced = val;
878
- if (transformWin32Path) replaced = transformCodeToPosixPath(replaced);
879
+ if (transformWin32Path) replaced = normalizeCodeToPosix(replaced);
879
880
  replaced = applyMatcherReplacement(pathMatchers, replaced);
881
+ if (transformCLR) replaced = normalizeCLR(replaced);
880
882
  if (escapeDoubleQuotes) replaced = replaced.replace(/"/g, '\\"');
881
883
  if (escapeEOL) replaced = replaced.replace(/\\r\\n/g, '\\n');
882
884
  if (addDoubleQuotes) replaced = `"${replaced}"`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "path-serializer",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "description": "path-serializer",
5
5
  "keywords": [
6
6
  "snapshot",