path-serializer 0.0.3 → 0.0.5-beta.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/esm/main.js CHANGED
@@ -1,10 +1,236 @@
1
+ import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";
1
2
  import * as __WEBPACK_EXTERNAL_MODULE_node_fs__ from "node:fs";
2
3
  import * as __WEBPACK_EXTERNAL_MODULE_node_os__ from "node:os";
3
4
  import * as __WEBPACK_EXTERNAL_MODULE_node_path__ from "node:path";
4
- // The require scope
5
- var __webpack_require__ = {};
5
+ var __webpack_modules__ = ({
6
+ "./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js": (function (__unused_webpack_module, exports, __webpack_require__) {
7
+ /**
8
+ * upath http://github.com/anodynos/upath/
9
+ *
10
+ * A proxy to `path`, replacing `\` with `/` for all results (supports UNC paths) & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.
11
+ * Version 2.0.1 - Compiled on 2020-11-07 16:59:47
12
+ * Repository git://github.com/anodynos/upath
13
+ * Copyright(c) 2020 Angelos Pikoulas <agelos.pikoulas@gmail.com>
14
+ * License MIT
15
+ */
16
+
17
+ // Generated by uRequire v0.7.0-beta.33 target: 'lib' template: 'nodejs'
18
+
19
+
20
+ var VERSION = '2.0.1'; // injected by urequire-rc-inject-version
21
+
22
+ var extraFn, extraFunctions, isFunction, isString, isValidExt, name, path, propName, propValue, toUnix, upath, slice = [].slice, indexOf = [].indexOf || function (item) {
23
+ for (var i = 0, l = this.length; i < l; i++) {
24
+ if (i in this && this[i] === item)
25
+ return i;
26
+ }
27
+ return -1;
28
+ }, hasProp = {}.hasOwnProperty;
29
+ path = __webpack_require__("path");
30
+ isFunction = function (val) {
31
+ return typeof val === "function";
32
+ };
33
+ isString = function (val) {
34
+ return typeof val === "string" || !!val && typeof val === "object" && Object.prototype.toString.call(val) === "[object String]";
35
+ };
36
+ upath = exports;
37
+ upath.VERSION = typeof VERSION !== "undefined" && VERSION !== null ? VERSION : "NO-VERSION";
38
+ toUnix = function (p) {
39
+ p = p.replace(/\\/g, "/");
40
+ p = p.replace(/(?<!^)\/+/g, "/");
41
+ return p;
42
+ };
43
+ for (propName in path) {
44
+ propValue = path[propName];
45
+ if (isFunction(propValue)) {
46
+ upath[propName] = function (propName) {
47
+ return function () {
48
+ var args, result;
49
+ args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
50
+ args = args.map(function (p) {
51
+ if (isString(p)) {
52
+ return toUnix(p);
53
+ } else {
54
+ return p;
55
+ }
56
+ });
57
+ result = path[propName].apply(path, args);
58
+ if (isString(result)) {
59
+ return toUnix(result);
60
+ } else {
61
+ return result;
62
+ }
63
+ };
64
+ }(propName);
65
+ } else {
66
+ upath[propName] = propValue;
67
+ }
68
+ }
69
+ upath.sep = "/";
70
+ extraFunctions = {
71
+ toUnix: toUnix,
72
+ normalizeSafe: function (p) {
73
+ var result;
74
+ p = toUnix(p);
75
+ result = upath.normalize(p);
76
+ if (p.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) {
77
+ result = "./" + result;
78
+ } else if (p.startsWith("//") && !result.startsWith("//")) {
79
+ if (p.startsWith("//./")) {
80
+ result = "//." + result;
81
+ } else {
82
+ result = "/" + result;
83
+ }
84
+ }
85
+ return result;
86
+ },
87
+ normalizeTrim: function (p) {
88
+ p = upath.normalizeSafe(p);
89
+ if (p.endsWith("/")) {
90
+ return p.slice(0, +(p.length - 2) + 1 || 9000000000);
91
+ } else {
92
+ return p;
93
+ }
94
+ },
95
+ joinSafe: function () {
96
+ var p, p0, result;
97
+ p = 1 <= arguments.length ? slice.call(arguments, 0) : [];
98
+ result = upath.join.apply(null, p);
99
+ if (p.length > 0) {
100
+ p0 = toUnix(p[0]);
101
+ if (p0.startsWith("./") && !result.startsWith("./") && !result.startsWith("..")) {
102
+ result = "./" + result;
103
+ } else if (p0.startsWith("//") && !result.startsWith("//")) {
104
+ if (p0.startsWith("//./")) {
105
+ result = "//." + result;
106
+ } else {
107
+ result = "/" + result;
108
+ }
109
+ }
110
+ }
111
+ return result;
112
+ },
113
+ addExt: function (file, ext) {
114
+ if (!ext) {
115
+ return file;
116
+ } else {
117
+ if (ext[0] !== ".") {
118
+ ext = "." + ext;
119
+ }
120
+ return file + (file.endsWith(ext) ? "" : ext);
121
+ }
122
+ },
123
+ trimExt: function (filename, ignoreExts, maxSize) {
124
+ var oldExt;
125
+ if (maxSize == null) {
126
+ maxSize = 7;
127
+ }
128
+ oldExt = upath.extname(filename);
129
+ if (isValidExt(oldExt, ignoreExts, maxSize)) {
130
+ return filename.slice(0, +(filename.length - oldExt.length - 1) + 1 || 9000000000);
131
+ } else {
132
+ return filename;
133
+ }
134
+ },
135
+ removeExt: function (filename, ext) {
136
+ if (!ext) {
137
+ return filename;
138
+ } else {
139
+ ext = ext[0] === "." ? ext : "." + ext;
140
+ if (upath.extname(filename) === ext) {
141
+ return upath.trimExt(filename, [], ext.length);
142
+ } else {
143
+ return filename;
144
+ }
145
+ }
146
+ },
147
+ changeExt: function (filename, ext, ignoreExts, maxSize) {
148
+ if (maxSize == null) {
149
+ maxSize = 7;
150
+ }
151
+ return upath.trimExt(filename, ignoreExts, maxSize) + (!ext ? "" : ext[0] === "." ? ext : "." + ext);
152
+ },
153
+ defaultExt: function (filename, ext, ignoreExts, maxSize) {
154
+ var oldExt;
155
+ if (maxSize == null) {
156
+ maxSize = 7;
157
+ }
158
+ oldExt = upath.extname(filename);
159
+ if (isValidExt(oldExt, ignoreExts, maxSize)) {
160
+ return filename;
161
+ } else {
162
+ return upath.addExt(filename, ext);
163
+ }
164
+ }
165
+ };
166
+ isValidExt = function (ext, ignoreExts, maxSize) {
167
+ if (ignoreExts == null) {
168
+ ignoreExts = [];
169
+ }
170
+ return ext && ext.length <= maxSize && indexOf.call(ignoreExts.map(function (e) {
171
+ return (e && e[0] !== "." ? "." : "") + e;
172
+ }), ext) < 0;
173
+ };
174
+ for (name in extraFunctions) {
175
+ if (!hasProp.call(extraFunctions, name))
176
+ continue;
177
+ extraFn = extraFunctions[name];
178
+ if (upath[name] !== void 0) {
179
+ throw new Error("path." + name + " already exists.");
180
+ } else {
181
+ upath[name] = extraFn;
182
+ }
183
+ }
184
+
185
+ ;
186
+
187
+ }),
188
+ "path": (function (module) {
189
+ module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("path");
6
190
 
191
+ }),
192
+
193
+ });
7
194
  /************************************************************************/
195
+ // The module cache
196
+ var __webpack_module_cache__ = {};
197
+
198
+ // The require function
199
+ function __webpack_require__(moduleId) {
200
+
201
+ // Check if module is in cache
202
+ var cachedModule = __webpack_module_cache__[moduleId];
203
+ if (cachedModule !== undefined) {
204
+ return cachedModule.exports;
205
+ }
206
+ // Create a new module (and put it into the cache)
207
+ var module = (__webpack_module_cache__[moduleId] = {
208
+ exports: {}
209
+ });
210
+ // Execute the module function
211
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
212
+
213
+ // Return the exports of the module
214
+ return module.exports;
215
+
216
+ }
217
+
218
+ /************************************************************************/
219
+ // webpack/runtime/compat_get_default_export
220
+ (() => {
221
+ // getDefaultExport function for compatibility with non-harmony modules
222
+ __webpack_require__.n = function (module) {
223
+ var getter = module && module.__esModule ?
224
+ function () { return module['default']; } :
225
+ function () { return module; };
226
+ __webpack_require__.d(getter, { a: getter });
227
+ return getter;
228
+ };
229
+
230
+
231
+
232
+
233
+ })();
8
234
  // webpack/runtime/define_property_getters
9
235
  (() => {
10
236
  __webpack_require__.d = function(exports, definition) {
@@ -23,6 +249,7 @@ __webpack_require__.o = function (obj, prop) {
23
249
 
24
250
  })();
25
251
  /************************************************************************/
252
+ var __webpack_exports__ = {};
26
253
 
27
254
  ;// CONCATENATED MODULE: ./node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_arrayReduce.js
28
255
  /**
@@ -747,184 +974,14 @@ function escapeRegExp(string) {
747
974
 
748
975
  /* harmony default export */ const lodash_es_escapeRegExp = (escapeRegExp);
749
976
 
750
- ;// CONCATENATED MODULE: ./src/upath.mjs
751
- // @ts-nocheck
752
- /**
753
- * upath http://github.com/anodynos/upath/
754
- *
755
- * A proxy to `path`, replacing `\` with `/` for all results (supports UNC paths) & new methods to normalize & join keeping leading `./` and add, change, default, trim file extensions.
756
- * Version 2.0.1 - Compiled on 2020-11-07 16:59:47
757
- * Repository git://github.com/anodynos/upath
758
- * Copyright(c) 2020 Angelos Pikoulas <agelos.pikoulas@gmail.com>
759
- * License MIT
760
- */ // Generated by uRequire v0.7.0-beta.33 target: 'lib' template: 'nodejs'
761
-
762
- const VERSION = '2.0.1';
763
- // injected by urequire-rc-inject-version
764
- let extraFn;
765
- let extraFunctions;
766
- let isFunction;
767
- let isString;
768
- let isValidExt;
769
- let upath_name;
770
- let upath_propName;
771
- let propValue;
772
- let toUnix;
773
- let upath;
774
- const slice = [].slice;
775
- const indexOf = [].indexOf || function(item) {
776
- for(let i = 0, l = this.length; i < l; i++){
777
- if (i in this && this[i] === item) return i;
778
- }
779
- return -1;
780
- };
781
- const hasProp = {}.hasOwnProperty;
782
- isFunction = (val)=>typeof val === 'function';
783
- isString = (val)=>typeof val === 'string' || !!val && typeof val === 'object' && Object.prototype.toString.call(val) === '[object String]';
784
- upath.VERSION = typeof VERSION !== 'undefined' && VERSION !== null ? VERSION : 'NO-VERSION';
785
- toUnix = (p)=>{
786
- p = p.replace(/\\/g, '/');
787
- p = p.replace(/(?<!^)\/+/g, '/');
788
- return p;
789
- };
790
- for(upath_propName in external_node_path_namespaceObject["default"]){
791
- propValue = external_node_path_namespaceObject["default"][upath_propName];
792
- if (isFunction(propValue)) {
793
- upath[upath_propName] = ((propName)=>()=>{
794
- let args;
795
- let result;
796
- args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
797
- args = args.map((p)=>{
798
- if (isString(p)) {
799
- return toUnix(p);
800
- }
801
- return p;
802
- });
803
- result = external_node_path_namespaceObject["default"][propName].apply(external_node_path_namespaceObject["default"], args);
804
- if (isString(result)) {
805
- return toUnix(result);
806
- }
807
- return result;
808
- })(upath_propName);
809
- } else {
810
- upath[upath_propName] = propValue;
811
- }
812
- }
813
- upath.sep = '/';
814
- extraFunctions = {
815
- toUnix: toUnix,
816
- normalizeSafe: (p)=>{
817
- let result;
818
- p = toUnix(p);
819
- result = upath.normalize(p);
820
- if (p.startsWith('./') && !result.startsWith('./') && !result.startsWith('..')) {
821
- result = `./${result}`;
822
- } else if (p.startsWith('//') && !result.startsWith('//')) {
823
- if (p.startsWith('//./')) {
824
- result = `//.${result}`;
825
- } else {
826
- result = `/${result}`;
827
- }
828
- }
829
- return result;
830
- },
831
- normalizeTrim: (p)=>{
832
- p = upath.normalizeSafe(p);
833
- if (p.endsWith('/')) {
834
- return p.slice(0, +(p.length - 2) + 1 || 9000000000);
835
- }
836
- return p;
837
- },
838
- joinSafe: ()=>{
839
- let p;
840
- let p0;
841
- let result;
842
- p = 1 <= arguments.length ? slice.call(arguments, 0) : [];
843
- result = upath.join.apply(null, p);
844
- if (p.length > 0) {
845
- p0 = toUnix(p[0]);
846
- if (p0.startsWith('./') && !result.startsWith('./') && !result.startsWith('..')) {
847
- result = `./${result}`;
848
- } else if (p0.startsWith('//') && !result.startsWith('//')) {
849
- if (p0.startsWith('//./')) {
850
- result = `//.${result}`;
851
- } else {
852
- result = `/${result}`;
853
- }
854
- }
855
- }
856
- return result;
857
- },
858
- addExt: (file, ext)=>{
859
- if (!ext) {
860
- return file;
861
- }
862
- if (ext[0] !== '.') {
863
- ext = `.${ext}`;
864
- }
865
- return file + (file.endsWith(ext) ? '' : ext);
866
- },
867
- trimExt: (filename, ignoreExts, maxSize)=>{
868
- let oldExt;
869
- if (maxSize == null) {
870
- maxSize = 7;
871
- }
872
- oldExt = upath.extname(filename);
873
- if (isValidExt(oldExt, ignoreExts, maxSize)) {
874
- return filename.slice(0, +(filename.length - oldExt.length - 1) + 1 || 9000000000);
875
- }
876
- return filename;
877
- },
878
- removeExt: (filename, ext)=>{
879
- if (!ext) {
880
- return filename;
881
- }
882
- ext = ext[0] === '.' ? ext : `.${ext}`;
883
- if (upath.extname(filename) === ext) {
884
- return upath.trimExt(filename, [], ext.length);
885
- }
886
- return filename;
887
- },
888
- changeExt: (filename, ext, ignoreExts, maxSize)=>{
889
- if (maxSize == null) {
890
- maxSize = 7;
891
- }
892
- return upath.trimExt(filename, ignoreExts, maxSize) + (!ext ? '' : ext[0] === '.' ? ext : `.${ext}`);
893
- },
894
- defaultExt: (filename, ext, ignoreExts, maxSize)=>{
895
- let oldExt;
896
- if (maxSize == null) {
897
- maxSize = 7;
898
- }
899
- oldExt = upath.extname(filename);
900
- if (isValidExt(oldExt, ignoreExts, maxSize)) {
901
- return filename;
902
- }
903
- return upath.addExt(filename, ext);
904
- }
905
- };
906
- isValidExt = (ext, ignoreExts, maxSize)=>{
907
- if (ignoreExts == null) {
908
- ignoreExts = [];
909
- }
910
- return ext && ext.length <= maxSize && indexOf.call(ignoreExts.map((e)=>(e && e[0] !== '.' ? '.' : '') + e), ext) < 0;
911
- };
912
- for(upath_name in extraFunctions){
913
- if (!hasProp.call(extraFunctions, upath_name)) continue;
914
- extraFn = extraFunctions[upath_name];
915
- if (upath[upath_name] !== void 0) {
916
- throw new Error(`path.${upath_name} already exists.`);
917
- }
918
- upath[upath_name] = extraFn;
919
- }
920
-
921
-
977
+ // EXTERNAL MODULE: ./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js
978
+ var upath = __webpack_require__("./node_modules/.pnpm/upath@2.0.1/node_modules/upath/build/code/upath.js");
979
+ var upath_default = /*#__PURE__*/__webpack_require__.n(upath);
922
980
  ;// CONCATENATED MODULE: ./src/utils.ts
923
981
 
924
982
 
925
983
 
926
984
 
927
- // @ts-ignore
928
985
 
929
986
  const isPathString = (test)=>external_node_path_namespaceObject["default"].posix.basename(test) !== test || external_node_path_namespaceObject["default"].win32.basename(test) !== test;
930
987
  function getRealTemporaryDirectory() {
@@ -936,7 +993,7 @@ function getRealTemporaryDirectory() {
936
993
  return ret;
937
994
  }
938
995
  const normalizeToPosixPath = (p)=>{
939
- return upath.normalizeSafe(external_node_path_namespaceObject["default"].normalize(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
996
+ return upath_default().normalizeSafe(external_node_path_namespaceObject["default"].normalize(p || '')).replace(/^([a-zA-Z]+):/, (_, m)=>`/${m.toLowerCase()}`);
940
997
  };
941
998
  /**
942
999
  * Compile path string to RegExp.
@@ -978,7 +1035,7 @@ function applyMatcherReplacement(matchers, str, options = {}) {
978
1035
  const createDefaultPathMatchers = ()=>{
979
1036
  const ret = [
980
1037
  {
981
- match: /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/,
1038
+ match: /(?<=\/)(\.pnpm\/.+?\/node_modules)(?=\/)/g,
982
1039
  mark: 'pnpmInner'
983
1040
  }
984
1041
  ];
@@ -998,10 +1055,20 @@ const createDefaultPathMatchers = ()=>{
998
1055
  return ret;
999
1056
  };
1000
1057
 
1058
+ ;// CONCATENATED MODULE: ./src/transformCodeToPosixPath.ts
1059
+
1060
+ function transformCodeToPosixPath(code) {
1061
+ return code.replace(/([a-zA-Z]:\\)([-\u4e00-\u9fa5\w\s.()~!@#$%^&()\[\]{}+=]+\\)*/g, (match)=>{
1062
+ return normalizeToPosixPath(match);
1063
+ });
1064
+ }
1065
+
1066
+
1001
1067
  ;// CONCATENATED MODULE: ./src/createSnapshotSerializer.ts
1002
1068
 
1003
1069
 
1004
1070
 
1071
+
1005
1072
  function createSnapshotSerializer(options) {
1006
1073
  const { cwd = process.cwd(), workspace = process.cwd(), replace: customMatchers = [] } = options || {};
1007
1074
  const pathMatchers = [
@@ -1026,7 +1093,7 @@ function createSnapshotSerializer(options) {
1026
1093
  // match path-format string
1027
1094
  test: (val)=>typeof val === 'string' && isPathString(val),
1028
1095
  print: (val)=>{
1029
- const normalized = normalizeToPosixPath(val);
1096
+ const normalized = transformCodeToPosixPath(val);
1030
1097
  const replaced = applyMatcherReplacement(pathMatchers, normalized).replace(/"/g, '\\"');
1031
1098
  return `"${replaced}"`;
1032
1099
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "path-serializer",
3
- "version": "0.0.3",
3
+ "version": "0.0.5-beta.0",
4
4
  "description": "path-serializer",
5
5
  "keywords": [
6
6
  "snapshot",
@@ -36,6 +36,7 @@
36
36
  "pre-commit": "npx nano-staged"
37
37
  },
38
38
  "devDependencies": {
39
+ "vitest": "^2.0.5",
39
40
  "@biomejs/biome": "^1.8.3",
40
41
  "@microsoft/api-extractor": "^7.47.5",
41
42
  "@rslib/core": "file:./scripts/rslib-core-0.0.0.tgz",
@@ -44,6 +45,7 @@
44
45
  "lodash-es": "^4.17.21",
45
46
  "nano-staged": "^0.8.0",
46
47
  "simple-git-hooks": "^2.11.1",
48
+ "slash": "5.1.0",
47
49
  "typescript": "^5.5.2",
48
50
  "upath": "^2.0.1"
49
51
  },
@@ -59,6 +61,9 @@
59
61
  "scripts": {
60
62
  "build": "rslib build",
61
63
  "dev": "rslib build --watch",
62
- "lint": "biome check --write"
64
+ "lint": "biome check --write",
65
+ "test:watch": "vitest",
66
+ "test": "vitest run",
67
+ "prepublish": "pnpm run build"
63
68
  }
64
69
  }