@tybys/wasm-util 0.6.0 → 0.8.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.
Files changed (41) hide show
  1. package/README.md +193 -193
  2. package/dist/tsdoc-metadata.json +1 -1
  3. package/dist/wasm-util.d.ts +13 -7
  4. package/dist/wasm-util.esm-bundler.js +2639 -2604
  5. package/dist/wasm-util.esm.js +2639 -2604
  6. package/dist/wasm-util.esm.min.js +1 -1
  7. package/dist/wasm-util.js +2639 -2603
  8. package/dist/wasm-util.min.js +1 -1
  9. package/lib/cjs/asyncify.js +157 -157
  10. package/lib/cjs/index.js +12 -12
  11. package/lib/cjs/jspi.js +45 -45
  12. package/lib/cjs/load.js +96 -85
  13. package/lib/cjs/memfs.js +2689 -0
  14. package/lib/cjs/memory.js +34 -34
  15. package/lib/cjs/wasi/error.js +102 -102
  16. package/lib/cjs/wasi/fd.js +267 -267
  17. package/lib/cjs/wasi/fs.js +2 -2
  18. package/lib/cjs/wasi/index.js +193 -168
  19. package/lib/cjs/wasi/path.js +173 -173
  20. package/lib/cjs/wasi/preview1.js +1478 -1478
  21. package/lib/cjs/wasi/rights.js +139 -139
  22. package/lib/cjs/wasi/types.js +219 -219
  23. package/lib/cjs/wasi/util.js +121 -121
  24. package/lib/cjs/webassembly.js +12 -12
  25. package/lib/mjs/asyncify.mjs +153 -153
  26. package/lib/mjs/index.mjs +9 -9
  27. package/lib/mjs/jspi.mjs +39 -39
  28. package/lib/mjs/load.mjs +89 -78
  29. package/lib/mjs/memfs.mjs +2688 -0
  30. package/lib/mjs/memory.mjs +28 -28
  31. package/lib/mjs/wasi/error.mjs +97 -97
  32. package/lib/mjs/wasi/fd.mjs +256 -256
  33. package/lib/mjs/wasi/fs.mjs +1 -1
  34. package/lib/mjs/wasi/index.mjs +188 -164
  35. package/lib/mjs/wasi/path.mjs +168 -168
  36. package/lib/mjs/wasi/preview1.mjs +1474 -1474
  37. package/lib/mjs/wasi/rights.mjs +134 -134
  38. package/lib/mjs/wasi/types.mjs +216 -216
  39. package/lib/mjs/wasi/util.mjs +108 -108
  40. package/lib/mjs/webassembly.mjs +9 -9
  41. package/package.json +58 -58
@@ -1,174 +1,174 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.relative = exports.resolve = void 0;
4
- const util_1 = require("./util");
5
- const CHAR_DOT = 46; /* . */
6
- const CHAR_FORWARD_SLASH = 47; /* / */
7
- function isPosixPathSeparator(code) {
8
- return code === CHAR_FORWARD_SLASH;
9
- }
10
- function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
11
- let res = '';
12
- let lastSegmentLength = 0;
13
- let lastSlash = -1;
14
- let dots = 0;
15
- let code = 0;
16
- for (let i = 0; i <= path.length; ++i) {
17
- if (i < path.length) {
18
- code = path.charCodeAt(i);
19
- }
20
- else if (isPathSeparator(code)) {
21
- break;
22
- }
23
- else {
24
- code = CHAR_FORWARD_SLASH;
25
- }
26
- if (isPathSeparator(code)) {
27
- if (lastSlash === i - 1 || dots === 1) {
28
- // NOOP
29
- }
30
- else if (dots === 2) {
31
- if (res.length < 2 || lastSegmentLength !== 2 ||
32
- res.charCodeAt(res.length - 1) !== CHAR_DOT ||
33
- res.charCodeAt(res.length - 2) !== CHAR_DOT) {
34
- if (res.length > 2) {
35
- const lastSlashIndex = res.indexOf(separator);
36
- if (lastSlashIndex === -1) {
37
- res = '';
38
- lastSegmentLength = 0;
39
- }
40
- else {
41
- res = res.slice(0, lastSlashIndex);
42
- lastSegmentLength =
43
- res.length - 1 - res.indexOf(separator);
44
- }
45
- lastSlash = i;
46
- dots = 0;
47
- continue;
48
- }
49
- else if (res.length !== 0) {
50
- res = '';
51
- lastSegmentLength = 0;
52
- lastSlash = i;
53
- dots = 0;
54
- continue;
55
- }
56
- }
57
- if (allowAboveRoot) {
58
- res += res.length > 0 ? `${separator}..` : '..';
59
- lastSegmentLength = 2;
60
- }
61
- }
62
- else {
63
- if (res.length > 0) {
64
- res += `${separator}${path.slice(lastSlash + 1, i)}`;
65
- }
66
- else {
67
- res = path.slice(lastSlash + 1, i);
68
- }
69
- lastSegmentLength = i - lastSlash - 1;
70
- }
71
- lastSlash = i;
72
- dots = 0;
73
- }
74
- else if (code === CHAR_DOT && dots !== -1) {
75
- ++dots;
76
- }
77
- else {
78
- dots = -1;
79
- }
80
- }
81
- return res;
82
- }
83
- function resolve(...args) {
84
- let resolvedPath = '';
85
- let resolvedAbsolute = false;
86
- for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
87
- const path = i >= 0 ? args[i] : '/';
88
- (0, util_1.validateString)(path, 'path');
89
- // Skip empty entries
90
- if (path.length === 0) {
91
- continue;
92
- }
93
- resolvedPath = `${path}/${resolvedPath}`;
94
- resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
95
- }
96
- // At this point the path should be resolved to a full absolute path, but
97
- // handle relative paths to be safe (might happen when process.cwd() fails)
98
- // Normalize the path
99
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
100
- if (resolvedAbsolute) {
101
- return `/${resolvedPath}`;
102
- }
103
- return resolvedPath.length > 0 ? resolvedPath : '.';
104
- }
105
- exports.resolve = resolve;
106
- function relative(from, to) {
107
- (0, util_1.validateString)(from, 'from');
108
- (0, util_1.validateString)(to, 'to');
109
- if (from === to)
110
- return '';
111
- // Trim leading forward slashes.
112
- from = resolve(from);
113
- to = resolve(to);
114
- if (from === to)
115
- return '';
116
- const fromStart = 1;
117
- const fromEnd = from.length;
118
- const fromLen = fromEnd - fromStart;
119
- const toStart = 1;
120
- const toLen = to.length - toStart;
121
- // Compare paths to find the longest common path from root
122
- const length = (fromLen < toLen ? fromLen : toLen);
123
- let lastCommonSep = -1;
124
- let i = 0;
125
- for (; i < length; i++) {
126
- const fromCode = from.charCodeAt(fromStart + i);
127
- if (fromCode !== to.charCodeAt(toStart + i)) {
128
- break;
129
- }
130
- else if (fromCode === CHAR_FORWARD_SLASH) {
131
- lastCommonSep = i;
132
- }
133
- }
134
- if (i === length) {
135
- if (toLen > length) {
136
- if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
137
- // We get here if `from` is the exact base path for `to`.
138
- // For example: from='/foo/bar'; to='/foo/bar/baz'
139
- return to.slice(toStart + i + 1);
140
- }
141
- if (i === 0) {
142
- // We get here if `from` is the root
143
- // For example: from='/'; to='/foo'
144
- return to.slice(toStart + i);
145
- }
146
- }
147
- else if (fromLen > length) {
148
- if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
149
- // We get here if `to` is the exact base path for `from`.
150
- // For example: from='/foo/bar/baz'; to='/foo/bar'
151
- lastCommonSep = i;
152
- }
153
- else if (i === 0) {
154
- // We get here if `to` is the root.
155
- // For example: from='/foo/bar'; to='/'
156
- lastCommonSep = 0;
157
- }
158
- }
159
- }
160
- let out = '';
161
- // Generate the relative path based on the path difference between `to`
162
- // and `from`.
163
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
164
- if (i === fromEnd ||
165
- from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
166
- out += out.length === 0 ? '..' : '/..';
167
- }
168
- }
169
- // Lastly, append the rest of the destination (`to`) path that comes after
170
- // the common path parts.
171
- return `${out}${to.slice(toStart + lastCommonSep)}`;
172
- }
173
- exports.relative = relative;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.relative = exports.resolve = void 0;
4
+ const util_1 = require("./util");
5
+ const CHAR_DOT = 46; /* . */
6
+ const CHAR_FORWARD_SLASH = 47; /* / */
7
+ function isPosixPathSeparator(code) {
8
+ return code === CHAR_FORWARD_SLASH;
9
+ }
10
+ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
11
+ let res = '';
12
+ let lastSegmentLength = 0;
13
+ let lastSlash = -1;
14
+ let dots = 0;
15
+ let code = 0;
16
+ for (let i = 0; i <= path.length; ++i) {
17
+ if (i < path.length) {
18
+ code = path.charCodeAt(i);
19
+ }
20
+ else if (isPathSeparator(code)) {
21
+ break;
22
+ }
23
+ else {
24
+ code = CHAR_FORWARD_SLASH;
25
+ }
26
+ if (isPathSeparator(code)) {
27
+ if (lastSlash === i - 1 || dots === 1) {
28
+ // NOOP
29
+ }
30
+ else if (dots === 2) {
31
+ if (res.length < 2 || lastSegmentLength !== 2 ||
32
+ res.charCodeAt(res.length - 1) !== CHAR_DOT ||
33
+ res.charCodeAt(res.length - 2) !== CHAR_DOT) {
34
+ if (res.length > 2) {
35
+ const lastSlashIndex = res.indexOf(separator);
36
+ if (lastSlashIndex === -1) {
37
+ res = '';
38
+ lastSegmentLength = 0;
39
+ }
40
+ else {
41
+ res = res.slice(0, lastSlashIndex);
42
+ lastSegmentLength =
43
+ res.length - 1 - res.indexOf(separator);
44
+ }
45
+ lastSlash = i;
46
+ dots = 0;
47
+ continue;
48
+ }
49
+ else if (res.length !== 0) {
50
+ res = '';
51
+ lastSegmentLength = 0;
52
+ lastSlash = i;
53
+ dots = 0;
54
+ continue;
55
+ }
56
+ }
57
+ if (allowAboveRoot) {
58
+ res += res.length > 0 ? `${separator}..` : '..';
59
+ lastSegmentLength = 2;
60
+ }
61
+ }
62
+ else {
63
+ if (res.length > 0) {
64
+ res += `${separator}${path.slice(lastSlash + 1, i)}`;
65
+ }
66
+ else {
67
+ res = path.slice(lastSlash + 1, i);
68
+ }
69
+ lastSegmentLength = i - lastSlash - 1;
70
+ }
71
+ lastSlash = i;
72
+ dots = 0;
73
+ }
74
+ else if (code === CHAR_DOT && dots !== -1) {
75
+ ++dots;
76
+ }
77
+ else {
78
+ dots = -1;
79
+ }
80
+ }
81
+ return res;
82
+ }
83
+ function resolve(...args) {
84
+ let resolvedPath = '';
85
+ let resolvedAbsolute = false;
86
+ for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
87
+ const path = i >= 0 ? args[i] : '/';
88
+ (0, util_1.validateString)(path, 'path');
89
+ // Skip empty entries
90
+ if (path.length === 0) {
91
+ continue;
92
+ }
93
+ resolvedPath = `${path}/${resolvedPath}`;
94
+ resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
95
+ }
96
+ // At this point the path should be resolved to a full absolute path, but
97
+ // handle relative paths to be safe (might happen when process.cwd() fails)
98
+ // Normalize the path
99
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
100
+ if (resolvedAbsolute) {
101
+ return `/${resolvedPath}`;
102
+ }
103
+ return resolvedPath.length > 0 ? resolvedPath : '.';
104
+ }
105
+ exports.resolve = resolve;
106
+ function relative(from, to) {
107
+ (0, util_1.validateString)(from, 'from');
108
+ (0, util_1.validateString)(to, 'to');
109
+ if (from === to)
110
+ return '';
111
+ // Trim leading forward slashes.
112
+ from = resolve(from);
113
+ to = resolve(to);
114
+ if (from === to)
115
+ return '';
116
+ const fromStart = 1;
117
+ const fromEnd = from.length;
118
+ const fromLen = fromEnd - fromStart;
119
+ const toStart = 1;
120
+ const toLen = to.length - toStart;
121
+ // Compare paths to find the longest common path from root
122
+ const length = (fromLen < toLen ? fromLen : toLen);
123
+ let lastCommonSep = -1;
124
+ let i = 0;
125
+ for (; i < length; i++) {
126
+ const fromCode = from.charCodeAt(fromStart + i);
127
+ if (fromCode !== to.charCodeAt(toStart + i)) {
128
+ break;
129
+ }
130
+ else if (fromCode === CHAR_FORWARD_SLASH) {
131
+ lastCommonSep = i;
132
+ }
133
+ }
134
+ if (i === length) {
135
+ if (toLen > length) {
136
+ if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
137
+ // We get here if `from` is the exact base path for `to`.
138
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
139
+ return to.slice(toStart + i + 1);
140
+ }
141
+ if (i === 0) {
142
+ // We get here if `from` is the root
143
+ // For example: from='/'; to='/foo'
144
+ return to.slice(toStart + i);
145
+ }
146
+ }
147
+ else if (fromLen > length) {
148
+ if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
149
+ // We get here if `to` is the exact base path for `from`.
150
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
151
+ lastCommonSep = i;
152
+ }
153
+ else if (i === 0) {
154
+ // We get here if `to` is the root.
155
+ // For example: from='/foo/bar'; to='/'
156
+ lastCommonSep = 0;
157
+ }
158
+ }
159
+ }
160
+ let out = '';
161
+ // Generate the relative path based on the path difference between `to`
162
+ // and `from`.
163
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
164
+ if (i === fromEnd ||
165
+ from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
166
+ out += out.length === 0 ? '..' : '/..';
167
+ }
168
+ }
169
+ // Lastly, append the rest of the destination (`to`) path that comes after
170
+ // the common path parts.
171
+ return `${out}${to.slice(toStart + lastCommonSep)}`;
172
+ }
173
+ exports.relative = relative;
174
174
  //# sourceMappingURL=path.js.map