path-serializer 0.4.1 → 0.5.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.
@@ -2,58 +2,73 @@ export declare function createSnapshotSerializer(options?: SnapshotSerializerOpt
2
2
 
3
3
  export declare interface Features {
4
4
  /**
5
- * /foo/node_modules/.pnpm -> <ROOT>/node_modules/.pnpm
5
+ * `file:///foo/rspack/packages/core/src` -> `<WORKSPACE>/src`
6
6
  * @default true
7
7
  */
8
- replaceRoot?: boolean;
8
+ replaceWorkspaceWithFileProtocol?: boolean;
9
+ /**
10
+ * `file:///foo/node_modules/.pnpm` -> `<ROOT>/node_modules/.pnpm`
11
+ * @default true
12
+ */
13
+ replaceRootWithFileProtocol?: boolean;
14
+ /**
15
+ * `D:\\foo\\node_modules\\<PNPM_INNER>\\css-loader\\utils.ts`
16
+ *
17
+ * ->
18
+ *
19
+ * `/d/foo/node_modules/<PNPM_INNER>/css-loader/utils.ts`
20
+ * @default true
21
+ */
22
+ transformWin32Path?: boolean;
9
23
  /**
10
- * /foo/rspack/packages/core/src -> <WORKSPACE>/src
24
+ * `/foo/rspack/packages/core/src` -> `<WORKSPACE>/src`
11
25
  * @default true
12
26
  */
13
27
  replaceWorkspace?: boolean;
14
28
  /**
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
29
+ * `/foo/node_modules/.pnpm` -> `<ROOT>/node_modules/.pnpm`
17
30
  * @default true
18
31
  */
19
- replacePnpmInner?: boolean;
32
+ replaceRoot?: boolean;
20
33
  /**
21
- * <TEMP>
34
+ * `/foo/node_modules/.pnpm/@swc+helpers@0.5.11/node_modules/@swc/helpers/esm/_class_private_method_get.js`
35
+ *
36
+ * ->
37
+ *
38
+ * `/foo/node_modules/<PNPM_INNER>/@swc/helpers/esm/_class_private_method_get.js`
22
39
  * @default true
23
40
  */
24
- replaceTmpDir?: boolean;
41
+ replacePnpmInner?: boolean;
25
42
  /**
26
- * <HOME>
43
+ * `${os.tmpdir()}/src/index.ts` -> `<TEMP>/src/index.ts`
27
44
  * @default true
28
45
  */
29
- replaceHomeDir?: boolean;
46
+ replaceTmpDir?: boolean;
30
47
  /**
31
- * foo -> "foo"
48
+ * `${os.homedir()}/src/index.ts` -> `<HOME>/src/index.ts`
32
49
  * @default true
33
50
  */
34
- addDoubleQuotes?: boolean;
51
+ replaceHomeDir?: boolean;
35
52
  /**
36
- * D:\\foo\\node_modules\\<PNPM_INNER>\\css-loader\\utils.ts
37
- * -> /d/foo/node_modules/<PNPM_INNER>/css-loader/utils.ts
53
+ * `\u001b[1mBold Text\u001b[0m` -> `<CLR=BOLD>Bold Text<CLR=0>`
38
54
  * @default true
39
55
  */
40
- transformWin32Path?: boolean;
56
+ transformCLR?: boolean;
41
57
  /**
42
- * "" -> \"\"
58
+ * `""` -> `\"\"`
43
59
  * @default true
44
60
  */
45
61
  escapeDoubleQuotes?: boolean;
46
62
  /**
47
- * \r\n -> \n
63
+ * `\r\n` -> `\n`
48
64
  * @default true
49
65
  */
50
66
  escapeEOL?: boolean;
51
67
  /**
52
- * \u001b[1mBold Text\u001b[0m
53
- * -> <CLR=BOLD>Bold Text<CLR=0>
68
+ * `foo` -> `"foo"`
54
69
  * @default true
55
70
  */
56
- transformCLR?: boolean;
71
+ addDoubleQuotes?: boolean;
57
72
  }
58
73
 
59
74
  export declare interface PathMatcher {
@@ -89,6 +104,10 @@ export declare interface SnapshotSerializerOptions {
89
104
  * @description beforeSerialize -> replace -> workspace root pnpmInner temp home -> replacePost -> afterSerialize
90
105
  */
91
106
  replace?: PathMatcher[];
107
+ /**
108
+ * @description all the features is executed in order
109
+ */
110
+ features?: Features;
92
111
  /**
93
112
  * @description beforeSerialize -> replace -> workspace root pnpmInner temp home -> replacePost -> afterSerialize
94
113
  */
@@ -97,7 +116,6 @@ export declare interface SnapshotSerializerOptions {
97
116
  * @description beforeSerialize -> replace -> workspace root pnpmInner temp home -> replacePost -> afterSerialize
98
117
  */
99
118
  afterSerialize?: (val: string) => string;
100
- features?: Features;
101
119
  }
102
120
 
103
121
  export { }
package/dist/cjs/index.js CHANGED
@@ -189,6 +189,7 @@ function __webpack_require__(moduleId) {
189
189
  __webpack_require__.d(__webpack_exports__, {
190
190
  createSnapshotSerializer: ()=>/* reexport */ createSnapshotSerializer
191
191
  });
192
+ const external_node_url_namespaceObject = require("node:url");
192
193
  /**
193
194
  * A specialized version of `_.reduce` for arrays without support for
194
195
  * iteratee shorthands.
@@ -876,7 +877,7 @@ function __webpack_require__(moduleId) {
876
877
  .replace(/[0-9]+(\.[0-9]+)*(<\/CLR>)?(\s?s)/g, 'X$2$3');
877
878
  function createSnapshotSerializer(options) {
878
879
  const { root = process.cwd(), workspace = '', replace: customMatchers = [], replacePost: customPostMatchers = [], features = {}, beforeSerialize, afterSerialize } = options || {};
879
- const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true, replaceHomeDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true, transformCLR = true } = features;
880
+ const { replaceWorkspaceWithFileProtocol = true, replaceWorkspace = true, replaceRootWithFileProtocol = true, replaceRoot = true, replacePnpmInner = true, replaceTmpDir = true, replaceHomeDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true, transformCLR = true } = features;
880
881
  function createPathMatchers() {
881
882
  const pathMatchers = [];
882
883
  pathMatchers.push(...customMatchers);
@@ -904,6 +905,10 @@ function __webpack_require__(moduleId) {
904
905
  serialize (val) {
905
906
  let replaced = val;
906
907
  if (beforeSerialize) replaced = beforeSerialize(replaced);
908
+ if (replaceWorkspaceWithFileProtocol && workspace) // this is a polyfill for .replaceAll(string, string)
909
+ replaced = replaced.split((0, external_node_url_namespaceObject.pathToFileURL)(workspace).toString()).join('<WORKSPACE>');
910
+ if (replaceRootWithFileProtocol && root) // this is a polyfill for .replaceAll(string, string)
911
+ replaced = replaced.split((0, external_node_url_namespaceObject.pathToFileURL)(root).toString()).join('<ROOT>');
907
912
  if (transformWin32Path) replaced = normalizeCodeToPosix(replaced);
908
913
  replaced = applyMatcherReplacement(pathMatchers, replaced);
909
914
  if (transformCLR) replaced = normalizeCLR(replaced);
@@ -2,58 +2,73 @@ export declare function createSnapshotSerializer(options?: SnapshotSerializerOpt
2
2
 
3
3
  export declare interface Features {
4
4
  /**
5
- * /foo/node_modules/.pnpm -> <ROOT>/node_modules/.pnpm
5
+ * `file:///foo/rspack/packages/core/src` -> `<WORKSPACE>/src`
6
6
  * @default true
7
7
  */
8
- replaceRoot?: boolean;
8
+ replaceWorkspaceWithFileProtocol?: boolean;
9
+ /**
10
+ * `file:///foo/node_modules/.pnpm` -> `<ROOT>/node_modules/.pnpm`
11
+ * @default true
12
+ */
13
+ replaceRootWithFileProtocol?: boolean;
14
+ /**
15
+ * `D:\\foo\\node_modules\\<PNPM_INNER>\\css-loader\\utils.ts`
16
+ *
17
+ * ->
18
+ *
19
+ * `/d/foo/node_modules/<PNPM_INNER>/css-loader/utils.ts`
20
+ * @default true
21
+ */
22
+ transformWin32Path?: boolean;
9
23
  /**
10
- * /foo/rspack/packages/core/src -> <WORKSPACE>/src
24
+ * `/foo/rspack/packages/core/src` -> `<WORKSPACE>/src`
11
25
  * @default true
12
26
  */
13
27
  replaceWorkspace?: boolean;
14
28
  /**
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
29
+ * `/foo/node_modules/.pnpm` -> `<ROOT>/node_modules/.pnpm`
17
30
  * @default true
18
31
  */
19
- replacePnpmInner?: boolean;
32
+ replaceRoot?: boolean;
20
33
  /**
21
- * <TEMP>
34
+ * `/foo/node_modules/.pnpm/@swc+helpers@0.5.11/node_modules/@swc/helpers/esm/_class_private_method_get.js`
35
+ *
36
+ * ->
37
+ *
38
+ * `/foo/node_modules/<PNPM_INNER>/@swc/helpers/esm/_class_private_method_get.js`
22
39
  * @default true
23
40
  */
24
- replaceTmpDir?: boolean;
41
+ replacePnpmInner?: boolean;
25
42
  /**
26
- * <HOME>
43
+ * `${os.tmpdir()}/src/index.ts` -> `<TEMP>/src/index.ts`
27
44
  * @default true
28
45
  */
29
- replaceHomeDir?: boolean;
46
+ replaceTmpDir?: boolean;
30
47
  /**
31
- * foo -> "foo"
48
+ * `${os.homedir()}/src/index.ts` -> `<HOME>/src/index.ts`
32
49
  * @default true
33
50
  */
34
- addDoubleQuotes?: boolean;
51
+ replaceHomeDir?: boolean;
35
52
  /**
36
- * D:\\foo\\node_modules\\<PNPM_INNER>\\css-loader\\utils.ts
37
- * -> /d/foo/node_modules/<PNPM_INNER>/css-loader/utils.ts
53
+ * `\u001b[1mBold Text\u001b[0m` -> `<CLR=BOLD>Bold Text<CLR=0>`
38
54
  * @default true
39
55
  */
40
- transformWin32Path?: boolean;
56
+ transformCLR?: boolean;
41
57
  /**
42
- * "" -> \"\"
58
+ * `""` -> `\"\"`
43
59
  * @default true
44
60
  */
45
61
  escapeDoubleQuotes?: boolean;
46
62
  /**
47
- * \r\n -> \n
63
+ * `\r\n` -> `\n`
48
64
  * @default true
49
65
  */
50
66
  escapeEOL?: boolean;
51
67
  /**
52
- * \u001b[1mBold Text\u001b[0m
53
- * -> <CLR=BOLD>Bold Text<CLR=0>
68
+ * `foo` -> `"foo"`
54
69
  * @default true
55
70
  */
56
- transformCLR?: boolean;
71
+ addDoubleQuotes?: boolean;
57
72
  }
58
73
 
59
74
  export declare interface PathMatcher {
@@ -89,6 +104,10 @@ export declare interface SnapshotSerializerOptions {
89
104
  * @description beforeSerialize -> replace -> workspace root pnpmInner temp home -> replacePost -> afterSerialize
90
105
  */
91
106
  replace?: PathMatcher[];
107
+ /**
108
+ * @description all the features is executed in order
109
+ */
110
+ features?: Features;
92
111
  /**
93
112
  * @description beforeSerialize -> replace -> workspace root pnpmInner temp home -> replacePost -> afterSerialize
94
113
  */
@@ -97,7 +116,6 @@ export declare interface SnapshotSerializerOptions {
97
116
  * @description beforeSerialize -> replace -> workspace root pnpmInner temp home -> replacePost -> afterSerialize
98
117
  */
99
118
  afterSerialize?: (val: string) => string;
100
- features?: Features;
101
119
  }
102
120
 
103
121
  export { }
@@ -1,4 +1,5 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_node_url__ from "node:url";
2
3
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
3
4
  import * as __WEBPACK_EXTERNAL_MODULE_node_os__ from "node:os";
4
5
  import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
@@ -851,7 +852,7 @@ const normalizeCLR = (str)=>str.replace(/\u001b\[1m\u001b\[([0-9;]*)m/g, '<CLR=$
851
852
  .replace(/[0-9]+(\.[0-9]+)*(<\/CLR>)?(\s?s)/g, 'X$2$3');
852
853
  function createSnapshotSerializer(options) {
853
854
  const { root = process.cwd(), workspace = '', replace: customMatchers = [], replacePost: customPostMatchers = [], features = {}, beforeSerialize, afterSerialize } = options || {};
854
- const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true, replaceHomeDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true, transformCLR = true } = features;
855
+ const { replaceWorkspaceWithFileProtocol = true, replaceWorkspace = true, replaceRootWithFileProtocol = true, replaceRoot = true, replacePnpmInner = true, replaceTmpDir = true, replaceHomeDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true, transformCLR = true } = features;
855
856
  function createPathMatchers() {
856
857
  const pathMatchers = [];
857
858
  pathMatchers.push(...customMatchers);
@@ -879,6 +880,10 @@ function createSnapshotSerializer(options) {
879
880
  serialize (val) {
880
881
  let replaced = val;
881
882
  if (beforeSerialize) replaced = beforeSerialize(replaced);
883
+ if (replaceWorkspaceWithFileProtocol && workspace) // this is a polyfill for .replaceAll(string, string)
884
+ replaced = replaced.split((0, __WEBPACK_EXTERNAL_MODULE_node_url__.pathToFileURL)(workspace).toString()).join('<WORKSPACE>');
885
+ if (replaceRootWithFileProtocol && root) // this is a polyfill for .replaceAll(string, string)
886
+ replaced = replaced.split((0, __WEBPACK_EXTERNAL_MODULE_node_url__.pathToFileURL)(root).toString()).join('<ROOT>');
882
887
  if (transformWin32Path) replaced = normalizeCodeToPosix(replaced);
883
888
  replaced = applyMatcherReplacement(pathMatchers, replaced);
884
889
  if (transformCLR) replaced = normalizeCLR(replaced);
package/package.json CHANGED
@@ -1,14 +1,8 @@
1
1
  {
2
2
  "name": "path-serializer",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "path-serializer",
5
- "keywords": [
6
- "snapshot",
7
- "vitest",
8
- "jest",
9
- "ci",
10
- "test"
11
- ],
5
+ "keywords": ["snapshot", "rstest", "vitest", "jest", "ci", "test"],
12
6
  "repository": {
13
7
  "type": "git",
14
8
  "url": "https://github.com/rspack-contrib/path-serializer.git"
@@ -26,11 +20,17 @@
26
20
  "main": "./dist/cjs/index.js",
27
21
  "module": "./dist/esm/index.mjs",
28
22
  "types": "./dist/esm/index.d.ts",
29
- "files": [
30
- "dist",
31
- "README.md",
32
- "LICENSE"
33
- ],
23
+ "files": ["dist", "README.md", "LICENSE"],
24
+ "scripts": {
25
+ "build": "rslib build",
26
+ "dev": "rslib build --watch",
27
+ "lint": "biome check --write",
28
+ "prepare": "pnpm run build && simple-git-hooks",
29
+ "test:watch": "vitest",
30
+ "test": "vitest run",
31
+ "prepublish": "pnpm run build",
32
+ "bump": "npx bumpp"
33
+ },
34
34
  "simple-git-hooks": {
35
35
  "pre-commit": "npx nano-staged"
36
36
  },
@@ -51,6 +51,7 @@
51
51
  "fs-extra": "11.2.0",
52
52
  "semver": "7.6.3"
53
53
  },
54
+ "packageManager": "pnpm@9.14.4",
54
55
  "publishConfig": {
55
56
  "access": "public",
56
57
  "registry": "https://registry.npmjs.org/"
@@ -59,14 +60,5 @@
59
60
  "*.{js,jsx,ts,tsx,mjs,cjs,json}": [
60
61
  "biome check --write --no-errors-on-unmatched"
61
62
  ]
62
- },
63
- "scripts": {
64
- "build": "rslib build",
65
- "dev": "rslib build --watch",
66
- "lint": "biome check --write",
67
- "test:watch": "vitest",
68
- "test": "vitest run",
69
- "prepublish": "pnpm run build",
70
- "release": "node ./scripts/release.mjs"
71
63
  }
72
- }
64
+ }