path-serializer 0.1.3 → 0.2.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 +12 -3
- package/dist/cjs/{index.cjs → index.js} +25 -13
- package/dist/esm/index.d.ts +12 -3
- package/dist/esm/{index.js → index.mjs} +25 -13
- package/package.json +5 -6
package/dist/cjs/index.d.ts
CHANGED
|
@@ -20,11 +20,19 @@ declare interface Features {
|
|
|
20
20
|
/**
|
|
21
21
|
* @default true
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
addDoubleQuotes?: boolean;
|
|
24
24
|
/**
|
|
25
25
|
* @default true
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
transformWin32Path?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
escapeDoubleQuotes?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
escapeEOL?: boolean;
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
declare interface PathMatcher {
|
|
@@ -40,9 +48,10 @@ declare interface SnapshotSerializer {
|
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
declare interface SnapshotSerializerOptions {
|
|
43
|
-
|
|
51
|
+
root?: string;
|
|
44
52
|
workspace?: string;
|
|
45
53
|
replace?: PathMatcher[];
|
|
54
|
+
replacePost?: PathMatcher[];
|
|
46
55
|
features?: Features;
|
|
47
56
|
}
|
|
48
57
|
|
|
@@ -425,8 +425,8 @@ function __webpack_require__(moduleId) {
|
|
|
425
425
|
/** Detect free variable `global` from Node.js. */ var freeGlobal = 'object' == typeof global && global && global.Object === Object && global;
|
|
426
426
|
/* harmony default export */ const _freeGlobal = freeGlobal;
|
|
427
427
|
/** Detect free variable `self`. */ var freeSelf = 'object' == typeof self && self && self.Object === Object && self;
|
|
428
|
-
/** Used as a reference to the global object. */ var
|
|
429
|
-
/* harmony default export */ const _root =
|
|
428
|
+
/** Used as a reference to the global object. */ var _root_root = _freeGlobal || freeSelf || Function('return this')();
|
|
429
|
+
/* harmony default export */ const _root = _root_root;
|
|
430
430
|
/** Built-in value references. */ var Symbol1 = _root.Symbol;
|
|
431
431
|
/* harmony default export */ const _Symbol = Symbol1;
|
|
432
432
|
/**
|
|
@@ -849,29 +849,39 @@ function __webpack_require__(moduleId) {
|
|
|
849
849
|
});
|
|
850
850
|
return ret;
|
|
851
851
|
};
|
|
852
|
+
const createPnpmInnerMatchers = ()=>[
|
|
853
|
+
// posix
|
|
854
|
+
{
|
|
855
|
+
match: /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/g,
|
|
856
|
+
mark: 'pnpmInner'
|
|
857
|
+
},
|
|
858
|
+
// win32
|
|
859
|
+
{
|
|
860
|
+
match: /(?<=\\)(\.pnpm\\.+?\\node_modules)(?=\\)/g,
|
|
861
|
+
mark: 'pnpmInner'
|
|
862
|
+
}
|
|
863
|
+
];
|
|
852
864
|
function transformCodeToPosixPath(code) {
|
|
853
865
|
return code.replace(// ignore http, https, file
|
|
854
866
|
/(?<![a-zA-Z])([a-zA-Z]:[\\/])([-\u4e00-\u9fa5\w\s.()~!@#$%^&()\[\]{}+=]+[\\/])*/g, (match, _diskName)=>normalizeToPosixPath(match));
|
|
855
867
|
}
|
|
856
868
|
function createSnapshotSerializer(options) {
|
|
857
|
-
const {
|
|
858
|
-
const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true,
|
|
869
|
+
const { root = process.cwd(), workspace = process.cwd(), replace: customMatchers = [], replacePost: customPostMatchers = [], features = {} } = options || {};
|
|
870
|
+
const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true } = features;
|
|
859
871
|
function createPathMatchers() {
|
|
860
872
|
const pathMatchers = [];
|
|
873
|
+
pathMatchers.push(...customMatchers);
|
|
861
874
|
if (replaceRoot) pathMatchers.push({
|
|
862
875
|
mark: 'root',
|
|
863
|
-
match:
|
|
876
|
+
match: root
|
|
864
877
|
});
|
|
865
878
|
if (replaceWorkspace) pathMatchers.push({
|
|
866
879
|
mark: 'workspace',
|
|
867
880
|
match: workspace
|
|
868
881
|
});
|
|
869
|
-
if (replacePnpmInner) pathMatchers.push(
|
|
870
|
-
match: /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/g,
|
|
871
|
-
mark: 'pnpmInner'
|
|
872
|
-
});
|
|
882
|
+
if (replacePnpmInner) pathMatchers.push(...createPnpmInnerMatchers());
|
|
873
883
|
if (replaceTmpDir) pathMatchers.push(...createTmpDirMatchers());
|
|
874
|
-
pathMatchers.push(...
|
|
884
|
+
pathMatchers.push(...customPostMatchers);
|
|
875
885
|
return pathMatchers;
|
|
876
886
|
}
|
|
877
887
|
const pathMatchers = createPathMatchers();
|
|
@@ -882,9 +892,11 @@ function __webpack_require__(moduleId) {
|
|
|
882
892
|
return 'string' == typeof val;
|
|
883
893
|
},
|
|
884
894
|
serialize (val) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
895
|
+
let replaced = val;
|
|
896
|
+
if (transformWin32Path) replaced = transformCodeToPosixPath(replaced);
|
|
897
|
+
replaced = applyMatcherReplacement(pathMatchers, replaced);
|
|
898
|
+
if (escapeDoubleQuotes) replaced = replaced.replace(/"/g, '\\"');
|
|
899
|
+
if (escapeEOL) replaced = replaced.replace(/\\r\\n/g, '\n');
|
|
888
900
|
if (addDoubleQuotes) replaced = `"${replaced}"`;
|
|
889
901
|
return replaced;
|
|
890
902
|
}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -20,11 +20,19 @@ declare interface Features {
|
|
|
20
20
|
/**
|
|
21
21
|
* @default true
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
addDoubleQuotes?: boolean;
|
|
24
24
|
/**
|
|
25
25
|
* @default true
|
|
26
26
|
*/
|
|
27
|
-
|
|
27
|
+
transformWin32Path?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
escapeDoubleQuotes?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
escapeEOL?: boolean;
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
declare interface PathMatcher {
|
|
@@ -40,9 +48,10 @@ declare interface SnapshotSerializer {
|
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
declare interface SnapshotSerializerOptions {
|
|
43
|
-
|
|
51
|
+
root?: string;
|
|
44
52
|
workspace?: string;
|
|
45
53
|
replace?: PathMatcher[];
|
|
54
|
+
replacePost?: PathMatcher[];
|
|
46
55
|
features?: Features;
|
|
47
56
|
}
|
|
48
57
|
|
|
@@ -406,8 +406,8 @@ function __webpack_require__(moduleId) {
|
|
|
406
406
|
/** Detect free variable `global` from Node.js. */ var freeGlobal = 'object' == typeof global && global && global.Object === Object && global;
|
|
407
407
|
/* harmony default export */ const _freeGlobal = freeGlobal;
|
|
408
408
|
/** Detect free variable `self`. */ var freeSelf = 'object' == typeof self && self && self.Object === Object && self;
|
|
409
|
-
/** Used as a reference to the global object. */ var
|
|
410
|
-
/* harmony default export */ const _root =
|
|
409
|
+
/** Used as a reference to the global object. */ var _root_root = _freeGlobal || freeSelf || Function('return this')();
|
|
410
|
+
/* harmony default export */ const _root = _root_root;
|
|
411
411
|
/** Built-in value references. */ var Symbol = _root.Symbol;
|
|
412
412
|
/* harmony default export */ const _Symbol = Symbol;
|
|
413
413
|
/**
|
|
@@ -824,29 +824,39 @@ const createTmpDirMatchers = ()=>{
|
|
|
824
824
|
});
|
|
825
825
|
return ret;
|
|
826
826
|
};
|
|
827
|
+
const createPnpmInnerMatchers = ()=>[
|
|
828
|
+
// posix
|
|
829
|
+
{
|
|
830
|
+
match: /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/g,
|
|
831
|
+
mark: 'pnpmInner'
|
|
832
|
+
},
|
|
833
|
+
// win32
|
|
834
|
+
{
|
|
835
|
+
match: /(?<=\\)(\.pnpm\\.+?\\node_modules)(?=\\)/g,
|
|
836
|
+
mark: 'pnpmInner'
|
|
837
|
+
}
|
|
838
|
+
];
|
|
827
839
|
function transformCodeToPosixPath(code) {
|
|
828
840
|
return code.replace(// ignore http, https, file
|
|
829
841
|
/(?<![a-zA-Z])([a-zA-Z]:[\\/])([-\u4e00-\u9fa5\w\s.()~!@#$%^&()\[\]{}+=]+[\\/])*/g, (match, _diskName)=>normalizeToPosixPath(match));
|
|
830
842
|
}
|
|
831
843
|
function createSnapshotSerializer(options) {
|
|
832
|
-
const {
|
|
833
|
-
const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true,
|
|
844
|
+
const { root = process.cwd(), workspace = process.cwd(), replace: customMatchers = [], replacePost: customPostMatchers = [], features = {} } = options || {};
|
|
845
|
+
const { replaceRoot = true, replaceWorkspace = true, replacePnpmInner = true, replaceTmpDir = true, addDoubleQuotes = true, transformWin32Path = true, escapeDoubleQuotes = true, escapeEOL = true } = features;
|
|
834
846
|
function createPathMatchers() {
|
|
835
847
|
const pathMatchers = [];
|
|
848
|
+
pathMatchers.push(...customMatchers);
|
|
836
849
|
if (replaceRoot) pathMatchers.push({
|
|
837
850
|
mark: 'root',
|
|
838
|
-
match:
|
|
851
|
+
match: root
|
|
839
852
|
});
|
|
840
853
|
if (replaceWorkspace) pathMatchers.push({
|
|
841
854
|
mark: 'workspace',
|
|
842
855
|
match: workspace
|
|
843
856
|
});
|
|
844
|
-
if (replacePnpmInner) pathMatchers.push(
|
|
845
|
-
match: /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/g,
|
|
846
|
-
mark: 'pnpmInner'
|
|
847
|
-
});
|
|
857
|
+
if (replacePnpmInner) pathMatchers.push(...createPnpmInnerMatchers());
|
|
848
858
|
if (replaceTmpDir) pathMatchers.push(...createTmpDirMatchers());
|
|
849
|
-
pathMatchers.push(...
|
|
859
|
+
pathMatchers.push(...customPostMatchers);
|
|
850
860
|
return pathMatchers;
|
|
851
861
|
}
|
|
852
862
|
const pathMatchers = createPathMatchers();
|
|
@@ -857,9 +867,11 @@ function createSnapshotSerializer(options) {
|
|
|
857
867
|
return 'string' == typeof val;
|
|
858
868
|
},
|
|
859
869
|
serialize (val) {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
870
|
+
let replaced = val;
|
|
871
|
+
if (transformWin32Path) replaced = transformCodeToPosixPath(replaced);
|
|
872
|
+
replaced = applyMatcherReplacement(pathMatchers, replaced);
|
|
873
|
+
if (escapeDoubleQuotes) replaced = replaced.replace(/"/g, '\\"');
|
|
874
|
+
if (escapeEOL) replaced = replaced.replace(/\\r\\n/g, '\n');
|
|
863
875
|
if (addDoubleQuotes) replaced = `"${replaced}"`;
|
|
864
876
|
return replaced;
|
|
865
877
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "path-serializer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "path-serializer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"snapshot",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"ci",
|
|
10
10
|
"test"
|
|
11
11
|
],
|
|
12
|
-
"type": "module",
|
|
13
12
|
"repository": {
|
|
14
13
|
"type": "git",
|
|
15
14
|
"url": "https://github.com/rspack-contrib/path-serializer.git"
|
|
@@ -19,13 +18,13 @@
|
|
|
19
18
|
"exports": {
|
|
20
19
|
".": {
|
|
21
20
|
"types": "./dist/esm/index.d.ts",
|
|
22
|
-
"import": "./dist/esm/index.
|
|
23
|
-
"require": "./dist/cjs/index.
|
|
21
|
+
"import": "./dist/esm/index.mjs",
|
|
22
|
+
"require": "./dist/cjs/index.js"
|
|
24
23
|
},
|
|
25
24
|
"./package.json": "./package.json"
|
|
26
25
|
},
|
|
27
|
-
"main": "./dist/cjs/index.
|
|
28
|
-
"module": "./dist/esm/index.
|
|
26
|
+
"main": "./dist/cjs/index.js",
|
|
27
|
+
"module": "./dist/esm/index.mjs",
|
|
29
28
|
"types": "./dist/esm/index.d.ts",
|
|
30
29
|
"files": [
|
|
31
30
|
"dist",
|