path-serializer 0.4.1 → 0.5.0
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/dist/cjs/index.d.ts +39 -21
- package/dist/cjs/index.js +6 -1
- package/dist/esm/index.d.ts +39 -21
- package/dist/esm/index.mjs +6 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
|
@@ -2,58 +2,73 @@ export declare function createSnapshotSerializer(options?: SnapshotSerializerOpt
|
|
|
2
2
|
|
|
3
3
|
export declare interface Features {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* `file:///foo/rspack/packages/core/src` -> `<WORKSPACE>/src`
|
|
6
6
|
* @default true
|
|
7
7
|
*/
|
|
8
|
-
|
|
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
|
-
*
|
|
24
|
+
* `/foo/rspack/packages/core/src` -> `<WORKSPACE>/src`
|
|
11
25
|
* @default true
|
|
12
26
|
*/
|
|
13
27
|
replaceWorkspace?: boolean;
|
|
14
28
|
/**
|
|
15
|
-
*
|
|
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
|
-
|
|
32
|
+
replaceRoot?: boolean;
|
|
20
33
|
/**
|
|
21
|
-
*
|
|
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
|
-
|
|
41
|
+
replacePnpmInner?: boolean;
|
|
25
42
|
/**
|
|
26
|
-
*
|
|
43
|
+
* `${os.tmpdir()}/src/index.ts` -> `<TEMP>/src/index.ts`
|
|
27
44
|
* @default true
|
|
28
45
|
*/
|
|
29
|
-
|
|
46
|
+
replaceTmpDir?: boolean;
|
|
30
47
|
/**
|
|
31
|
-
*
|
|
48
|
+
* `${os.homedir()}/src/index.ts` -> `<HOME>/src/index.ts`
|
|
32
49
|
* @default true
|
|
33
50
|
*/
|
|
34
|
-
|
|
51
|
+
replaceHomeDir?: boolean;
|
|
35
52
|
/**
|
|
36
|
-
*
|
|
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
|
-
|
|
56
|
+
transformCLR?: boolean;
|
|
41
57
|
/**
|
|
42
|
-
* "" ->
|
|
58
|
+
* `""` -> `\"\"`
|
|
43
59
|
* @default true
|
|
44
60
|
*/
|
|
45
61
|
escapeDoubleQuotes?: boolean;
|
|
46
62
|
/**
|
|
47
|
-
*
|
|
63
|
+
* `\r\n` -> `\n`
|
|
48
64
|
* @default true
|
|
49
65
|
*/
|
|
50
66
|
escapeEOL?: boolean;
|
|
51
67
|
/**
|
|
52
|
-
*
|
|
53
|
-
* -> <CLR=BOLD>Bold Text<CLR=0>
|
|
68
|
+
* `foo` -> `"foo"`
|
|
54
69
|
* @default true
|
|
55
70
|
*/
|
|
56
|
-
|
|
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 {
|
|
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);
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -2,58 +2,73 @@ export declare function createSnapshotSerializer(options?: SnapshotSerializerOpt
|
|
|
2
2
|
|
|
3
3
|
export declare interface Features {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* `file:///foo/rspack/packages/core/src` -> `<WORKSPACE>/src`
|
|
6
6
|
* @default true
|
|
7
7
|
*/
|
|
8
|
-
|
|
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
|
-
*
|
|
24
|
+
* `/foo/rspack/packages/core/src` -> `<WORKSPACE>/src`
|
|
11
25
|
* @default true
|
|
12
26
|
*/
|
|
13
27
|
replaceWorkspace?: boolean;
|
|
14
28
|
/**
|
|
15
|
-
*
|
|
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
|
-
|
|
32
|
+
replaceRoot?: boolean;
|
|
20
33
|
/**
|
|
21
|
-
*
|
|
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
|
-
|
|
41
|
+
replacePnpmInner?: boolean;
|
|
25
42
|
/**
|
|
26
|
-
*
|
|
43
|
+
* `${os.tmpdir()}/src/index.ts` -> `<TEMP>/src/index.ts`
|
|
27
44
|
* @default true
|
|
28
45
|
*/
|
|
29
|
-
|
|
46
|
+
replaceTmpDir?: boolean;
|
|
30
47
|
/**
|
|
31
|
-
*
|
|
48
|
+
* `${os.homedir()}/src/index.ts` -> `<HOME>/src/index.ts`
|
|
32
49
|
* @default true
|
|
33
50
|
*/
|
|
34
|
-
|
|
51
|
+
replaceHomeDir?: boolean;
|
|
35
52
|
/**
|
|
36
|
-
*
|
|
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
|
-
|
|
56
|
+
transformCLR?: boolean;
|
|
41
57
|
/**
|
|
42
|
-
* "" ->
|
|
58
|
+
* `""` -> `\"\"`
|
|
43
59
|
* @default true
|
|
44
60
|
*/
|
|
45
61
|
escapeDoubleQuotes?: boolean;
|
|
46
62
|
/**
|
|
47
|
-
*
|
|
63
|
+
* `\r\n` -> `\n`
|
|
48
64
|
* @default true
|
|
49
65
|
*/
|
|
50
66
|
escapeEOL?: boolean;
|
|
51
67
|
/**
|
|
52
|
-
*
|
|
53
|
-
* -> <CLR=BOLD>Bold Text<CLR=0>
|
|
68
|
+
* `foo` -> `"foo"`
|
|
54
69
|
* @default true
|
|
55
70
|
*/
|
|
56
|
-
|
|
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/esm/index.mjs
CHANGED
|
@@ -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 {
|
|
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);
|