@tailwindcss/oxide-wasm32-wasi 0.0.0-insiders.00ef99d

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 (115) hide show
  1. package/README.md +3 -0
  2. package/node_modules/@emnapi/core/LICENSE +21 -0
  3. package/node_modules/@emnapi/core/README.md +1 -0
  4. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.js +7746 -0
  5. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.d.ts +428 -0
  6. package/node_modules/@emnapi/core/dist/emnapi-core.cjs.min.js +1 -0
  7. package/node_modules/@emnapi/core/dist/emnapi-core.d.mts +428 -0
  8. package/node_modules/@emnapi/core/dist/emnapi-core.d.ts +430 -0
  9. package/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.js +8741 -0
  10. package/node_modules/@emnapi/core/dist/emnapi-core.js +9777 -0
  11. package/node_modules/@emnapi/core/dist/emnapi-core.min.d.mts +428 -0
  12. package/node_modules/@emnapi/core/dist/emnapi-core.min.js +1 -0
  13. package/node_modules/@emnapi/core/dist/emnapi-core.min.mjs +1 -0
  14. package/node_modules/@emnapi/core/dist/emnapi-core.mjs +7735 -0
  15. package/node_modules/@emnapi/core/index.js +5 -0
  16. package/node_modules/@emnapi/core/package.json +49 -0
  17. package/node_modules/@emnapi/runtime/LICENSE +21 -0
  18. package/node_modules/@emnapi/runtime/README.md +1 -0
  19. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.js +1398 -0
  20. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.d.ts +671 -0
  21. package/node_modules/@emnapi/runtime/dist/emnapi.cjs.min.js +1 -0
  22. package/node_modules/@emnapi/runtime/dist/emnapi.d.mts +671 -0
  23. package/node_modules/@emnapi/runtime/dist/emnapi.d.ts +673 -0
  24. package/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.js +1457 -0
  25. package/node_modules/@emnapi/runtime/dist/emnapi.iife.d.ts +426 -0
  26. package/node_modules/@emnapi/runtime/dist/emnapi.iife.js +1528 -0
  27. package/node_modules/@emnapi/runtime/dist/emnapi.js +1529 -0
  28. package/node_modules/@emnapi/runtime/dist/emnapi.min.d.mts +671 -0
  29. package/node_modules/@emnapi/runtime/dist/emnapi.min.js +1 -0
  30. package/node_modules/@emnapi/runtime/dist/emnapi.min.mjs +1 -0
  31. package/node_modules/@emnapi/runtime/dist/emnapi.mjs +1367 -0
  32. package/node_modules/@emnapi/runtime/index.js +5 -0
  33. package/node_modules/@emnapi/runtime/package.json +48 -0
  34. package/node_modules/@emnapi/wasi-threads/LICENSE +21 -0
  35. package/node_modules/@emnapi/wasi-threads/README.md +203 -0
  36. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.js +915 -0
  37. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.d.ts +271 -0
  38. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.cjs.min.js +1 -0
  39. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.mts +271 -0
  40. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.d.ts +273 -0
  41. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.js +975 -0
  42. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.js +987 -0
  43. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.d.mts +271 -0
  44. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.js +1 -0
  45. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.min.mjs +1 -0
  46. package/node_modules/@emnapi/wasi-threads/dist/wasi-threads.mjs +910 -0
  47. package/node_modules/@emnapi/wasi-threads/index.js +5 -0
  48. package/node_modules/@emnapi/wasi-threads/package.json +50 -0
  49. package/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.cjs +1826 -0
  50. package/node_modules/@napi-rs/wasm-runtime/dist/emnapi-plugins.js +1823 -0
  51. package/node_modules/@napi-rs/wasm-runtime/dist/fs-proxy.cjs +321 -0
  52. package/node_modules/@napi-rs/wasm-runtime/dist/fs.js +25524 -0
  53. package/node_modules/@napi-rs/wasm-runtime/fs-proxy.js +316 -0
  54. package/node_modules/@napi-rs/wasm-runtime/package.json +74 -0
  55. package/node_modules/@napi-rs/wasm-runtime/runtime.cjs +39 -0
  56. package/node_modules/@napi-rs/wasm-runtime/runtime.js +36 -0
  57. package/node_modules/@tybys/wasm-util/README.md +193 -0
  58. package/node_modules/@tybys/wasm-util/dist/tsdoc-metadata.json +11 -0
  59. package/node_modules/@tybys/wasm-util/dist/wasm-util.d.ts +423 -0
  60. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.js +2932 -0
  61. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.js +2932 -0
  62. package/node_modules/@tybys/wasm-util/dist/wasm-util.esm.min.js +1 -0
  63. package/node_modules/@tybys/wasm-util/dist/wasm-util.js +2954 -0
  64. package/node_modules/@tybys/wasm-util/dist/wasm-util.min.js +1 -0
  65. package/node_modules/@tybys/wasm-util/lib/cjs/asyncify.js +158 -0
  66. package/node_modules/@tybys/wasm-util/lib/cjs/index.js +13 -0
  67. package/node_modules/@tybys/wasm-util/lib/cjs/jspi.js +46 -0
  68. package/node_modules/@tybys/wasm-util/lib/cjs/load.js +97 -0
  69. package/node_modules/@tybys/wasm-util/lib/cjs/memory.js +35 -0
  70. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/error.js +103 -0
  71. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/fd.js +268 -0
  72. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/fs.js +3 -0
  73. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/index.js +192 -0
  74. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/path.js +316 -0
  75. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/preview1.js +1599 -0
  76. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/rights.js +141 -0
  77. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/types.js +220 -0
  78. package/node_modules/@tybys/wasm-util/lib/cjs/wasi/util.js +128 -0
  79. package/node_modules/@tybys/wasm-util/lib/cjs/webassembly.js +13 -0
  80. package/node_modules/@tybys/wasm-util/lib/mjs/asyncify.mjs +153 -0
  81. package/node_modules/@tybys/wasm-util/lib/mjs/index.mjs +9 -0
  82. package/node_modules/@tybys/wasm-util/lib/mjs/jspi.mjs +39 -0
  83. package/node_modules/@tybys/wasm-util/lib/mjs/load.mjs +89 -0
  84. package/node_modules/@tybys/wasm-util/lib/mjs/memory.mjs +28 -0
  85. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/error.mjs +97 -0
  86. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/fd.mjs +256 -0
  87. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/fs.mjs +1 -0
  88. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/index.mjs +186 -0
  89. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/path.mjs +310 -0
  90. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/preview1.mjs +1593 -0
  91. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/rights.mjs +135 -0
  92. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/types.mjs +216 -0
  93. package/node_modules/@tybys/wasm-util/lib/mjs/wasi/util.mjs +113 -0
  94. package/node_modules/@tybys/wasm-util/lib/mjs/webassembly.mjs +9 -0
  95. package/node_modules/@tybys/wasm-util/package.json +58 -0
  96. package/node_modules/tslib/CopyrightNotice.txt +15 -0
  97. package/node_modules/tslib/LICENSE.txt +12 -0
  98. package/node_modules/tslib/README.md +164 -0
  99. package/node_modules/tslib/SECURITY.md +41 -0
  100. package/node_modules/tslib/modules/index.d.ts +38 -0
  101. package/node_modules/tslib/modules/index.js +70 -0
  102. package/node_modules/tslib/modules/package.json +3 -0
  103. package/node_modules/tslib/package.json +47 -0
  104. package/node_modules/tslib/tslib.d.ts +460 -0
  105. package/node_modules/tslib/tslib.es6.html +1 -0
  106. package/node_modules/tslib/tslib.es6.js +402 -0
  107. package/node_modules/tslib/tslib.es6.mjs +401 -0
  108. package/node_modules/tslib/tslib.html +1 -0
  109. package/node_modules/tslib/tslib.js +484 -0
  110. package/package.json +42 -0
  111. package/tailwindcss-oxide.wasi-browser.js +67 -0
  112. package/tailwindcss-oxide.wasi.cjs +123 -0
  113. package/tailwindcss-oxide.wasm32-wasi.wasm +0 -0
  114. package/wasi-worker-browser.mjs +41 -0
  115. package/wasi-worker.mjs +72 -0
@@ -0,0 +1,186 @@
1
+ import { WASI as WASIPreview1 } from "./preview1.mjs";
2
+ import { validateObject, validateArray, validateBoolean, validateFunction, validateUndefined, validateString } from "./util.mjs";
3
+ // eslint-disable-next-line spaced-comment
4
+ const kEmptyObject = /*#__PURE__*/ Object.freeze(/*#__PURE__*/ Object.create(null));
5
+ const kExitCode = Symbol('kExitCode');
6
+ const kSetMemory = Symbol('kSetMemory');
7
+ const kStarted = Symbol('kStarted');
8
+ const kInstance = Symbol('kInstance');
9
+ const kBindingName = Symbol('kBindingName');
10
+ function validateOptions(options) {
11
+ var _a;
12
+ validateObject(options, 'options');
13
+ let _WASI;
14
+ if (options.version !== undefined) {
15
+ validateString(options.version, 'options.version');
16
+ switch (options.version) {
17
+ case 'unstable':
18
+ _WASI = WASIPreview1;
19
+ this[kBindingName] = 'wasi_unstable';
20
+ break;
21
+ case 'preview1':
22
+ _WASI = WASIPreview1;
23
+ this[kBindingName] = 'wasi_snapshot_preview1';
24
+ break;
25
+ default:
26
+ throw new TypeError(`unsupported WASI version "${options.version}"`);
27
+ }
28
+ }
29
+ else {
30
+ _WASI = WASIPreview1;
31
+ this[kBindingName] = 'wasi_snapshot_preview1';
32
+ }
33
+ if (options.args !== undefined) {
34
+ validateArray(options.args, 'options.args');
35
+ }
36
+ const args = ((_a = options.args) !== null && _a !== void 0 ? _a : []).map(String);
37
+ const env = [];
38
+ if (options.env !== undefined) {
39
+ validateObject(options.env, 'options.env');
40
+ Object.entries(options.env).forEach(({ 0: key, 1: value }) => {
41
+ if (value !== undefined) {
42
+ env.push(`${key}=${value}`);
43
+ }
44
+ });
45
+ }
46
+ const preopens = [];
47
+ if (options.preopens !== undefined) {
48
+ validateObject(options.preopens, 'options.preopens');
49
+ Object.entries(options.preopens).forEach(({ 0: key, 1: value }) => preopens.push({ mappedPath: String(key), realPath: String(value) }));
50
+ }
51
+ if (preopens.length > 0) {
52
+ if (options.fs === undefined) {
53
+ throw new Error('filesystem is disabled, can not preopen directory');
54
+ }
55
+ try {
56
+ validateObject(options.fs, 'options.fs');
57
+ }
58
+ catch (_) {
59
+ throw new TypeError('Node.js fs like implementation is not provided');
60
+ }
61
+ }
62
+ // if (options.filesystem !== undefined) {
63
+ // validateObject(options.filesystem, 'options.filesystem')
64
+ // validateString(options.filesystem.type, 'options.filesystem.type')
65
+ // if (options.filesystem.type !== 'memfs' && options.filesystem.type !== 'file-system-access-api') {
66
+ // throw new Error(`Filesystem type ${(options.filesystem as any).type as string} is not supported, only "memfs" and "file-system-access-api" is supported currently`)
67
+ // }
68
+ // try {
69
+ // validateObject(options.filesystem.fs, 'options.filesystem.fs')
70
+ // } catch (_) {
71
+ // throw new Error('Node.js fs like implementation is not provided')
72
+ // }
73
+ // }
74
+ if (options.print !== undefined)
75
+ validateFunction(options.print, 'options.print');
76
+ if (options.printErr !== undefined)
77
+ validateFunction(options.printErr, 'options.printErr');
78
+ if (options.returnOnExit !== undefined) {
79
+ validateBoolean(options.returnOnExit, 'options.returnOnExit');
80
+ }
81
+ // const { stdin = 0, stdout = 1, stderr = 2 } = options
82
+ // validateInt32(stdin, 'options.stdin', 0)
83
+ // validateInt32(stdout, 'options.stdout', 0)
84
+ // validateInt32(stderr, 'options.stderr', 0)
85
+ // const stdio = [stdin, stdout, stderr] as const
86
+ const stdio = [0, 1, 2];
87
+ return {
88
+ args,
89
+ env,
90
+ preopens,
91
+ stdio,
92
+ _WASI
93
+ };
94
+ }
95
+ function initWASI(setMemory, wrap) {
96
+ this[kSetMemory] = setMemory;
97
+ this.wasiImport = wrap;
98
+ this[kStarted] = false;
99
+ this[kExitCode] = 0;
100
+ this[kInstance] = undefined;
101
+ }
102
+ /** @public */
103
+ export class WASI {
104
+ constructor(options = kEmptyObject) {
105
+ const { args, env, preopens, stdio, _WASI } = validateOptions.call(this, options);
106
+ const wrap = _WASI.createSync(args, env, preopens, stdio, options.fs, options.print, options.printErr);
107
+ const setMemory = wrap._setMemory;
108
+ delete wrap._setMemory;
109
+ initWASI.call(this, setMemory, wrap);
110
+ if (options.returnOnExit) {
111
+ wrap.proc_exit = wasiReturnOnProcExit.bind(this);
112
+ }
113
+ }
114
+ finalizeBindings(instance, _a) {
115
+ var _b;
116
+ var { memory = (_b = instance === null || instance === void 0 ? void 0 : instance.exports) === null || _b === void 0 ? void 0 : _b.memory } = _a === void 0 ? {} : _a;
117
+ if (this[kStarted]) {
118
+ throw new Error('WASI instance has already started');
119
+ }
120
+ validateObject(instance, 'instance');
121
+ validateObject(instance.exports, 'instance.exports');
122
+ this[kSetMemory](memory);
123
+ this[kInstance] = instance;
124
+ this[kStarted] = true;
125
+ }
126
+ // Must not export _initialize, must export _start
127
+ start(instance) {
128
+ this.finalizeBindings(instance);
129
+ const { _start, _initialize } = this[kInstance].exports;
130
+ validateFunction(_start, 'instance.exports._start');
131
+ validateUndefined(_initialize, 'instance.exports._initialize');
132
+ let ret;
133
+ try {
134
+ ret = _start();
135
+ }
136
+ catch (err) {
137
+ if (err !== kExitCode) {
138
+ throw err;
139
+ }
140
+ }
141
+ if (ret instanceof Promise) {
142
+ return ret.then(() => this[kExitCode], (err) => {
143
+ if (err !== kExitCode) {
144
+ throw err;
145
+ }
146
+ return this[kExitCode];
147
+ });
148
+ }
149
+ return this[kExitCode];
150
+ }
151
+ // Must not export _start, may optionally export _initialize
152
+ initialize(instance) {
153
+ this.finalizeBindings(instance);
154
+ const { _start, _initialize } = this[kInstance].exports;
155
+ validateUndefined(_start, 'instance.exports._start');
156
+ if (_initialize !== undefined) {
157
+ validateFunction(_initialize, 'instance.exports._initialize');
158
+ return _initialize();
159
+ }
160
+ }
161
+ getImportObject() {
162
+ return { [this[kBindingName]]: this.wasiImport };
163
+ }
164
+ }
165
+ function wasiReturnOnProcExit(rval) {
166
+ this[kExitCode] = rval;
167
+ // eslint-disable-next-line @typescript-eslint/no-throw-literal
168
+ throw kExitCode;
169
+ }
170
+ /** @public */
171
+ export async function createAsyncWASI(options = kEmptyObject) {
172
+ const _this = Object.create(WASI.prototype);
173
+ const { args, env, preopens, stdio, _WASI } = validateOptions.call(_this, options);
174
+ if (options.asyncify !== undefined) {
175
+ validateObject(options.asyncify, 'options.asyncify');
176
+ validateFunction(options.asyncify.wrapImportFunction, 'options.asyncify.wrapImportFunction');
177
+ }
178
+ const wrap = await _WASI.createAsync(args, env, preopens, stdio, options.fs, options.print, options.printErr, options.asyncify);
179
+ const setMemory = wrap._setMemory;
180
+ delete wrap._setMemory;
181
+ initWASI.call(_this, setMemory, wrap);
182
+ if (options.returnOnExit) {
183
+ wrap.proc_exit = wasiReturnOnProcExit.bind(_this);
184
+ }
185
+ return _this;
186
+ }
@@ -0,0 +1,310 @@
1
+ import { validateString } from "./util.mjs";
2
+ const CHAR_DOT = 46; /* . */
3
+ const CHAR_FORWARD_SLASH = 47; /* / */
4
+ const CHAR_BACKWARD_SLASH = 92; /* \ */
5
+ const CHAR_COLON = 58; /* : */
6
+ const CHAR_UPPERCASE_A = 65; /* A */
7
+ const CHAR_UPPERCASE_Z = 90; /* Z */
8
+ const CHAR_LOWERCASE_A = 97; /* a */
9
+ const CHAR_LOWERCASE_Z = 122; /* z */
10
+ function isPathSeparatorWin(code) {
11
+ return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
12
+ }
13
+ function isWindowsDeviceRoot(code) {
14
+ return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
15
+ (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
16
+ }
17
+ const _isWin32 = typeof process !== 'undefined' && process.platform === 'win32';
18
+ /**
19
+ * Windows variant of `resolve()`. Mirrors Node's `path.win32.resolve`
20
+ * semantics enough for the WASI shim's needs (drive-letter absolutes
21
+ * + UNC paths + per-drive cwd lookups via `process.env`/`process.cwd`).
22
+ *
23
+ * Why this is needed: on Windows, `FileDescriptor.realPath` is the
24
+ * host realpath returned by `fs.realpathSync(realPath, 'utf8')` — the
25
+ * backslash form `D:\…`. The POSIX-only `resolveImpl` below only
26
+ * treats `/` as a separator, reads `D` as non-`/`, decides realPath
27
+ * is "relative", and produces a garbage joined path. Downstream
28
+ * `fs.openSync(garbage)` then returns `EINVAL` and the WASI caller
29
+ * sees a permanent failure. This function gives us the correct
30
+ * Windows-style resolution without taking a Node-only `path` import
31
+ * (which would break browser bundles of this package).
32
+ *
33
+ * Cribbed from Node's `lib/path.js` `win32.resolve()` (MIT-licensed),
34
+ * trimmed to what WASI realpath resolution actually exercises.
35
+ */
36
+ function resolveWin32(args) {
37
+ let resolvedDevice = '';
38
+ let resolvedTail = '';
39
+ let resolvedAbsolute = false;
40
+ for (let i = args.length - 1; i >= -1; i--) {
41
+ let path;
42
+ if (i >= 0) {
43
+ path = args[i];
44
+ validateString(path, 'path');
45
+ if (path.length === 0)
46
+ continue;
47
+ }
48
+ else if (resolvedDevice.length === 0) {
49
+ path = (typeof process !== 'undefined' && typeof process.cwd === 'function')
50
+ ? process.cwd()
51
+ : '';
52
+ }
53
+ else {
54
+ // Look up per-drive cwd via the `=X:` env var convention; fall back
55
+ // to the global cwd if absent.
56
+ const envKey = `=${resolvedDevice}`;
57
+ const env = (typeof process !== 'undefined') ? process.env : undefined;
58
+ path = (env && typeof env[envKey] === 'string')
59
+ ? env[envKey]
60
+ : (typeof process !== 'undefined' && typeof process.cwd === 'function')
61
+ ? process.cwd()
62
+ : '';
63
+ if (path === undefined ||
64
+ (path.slice(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() &&
65
+ path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) {
66
+ path = `${resolvedDevice}\\`;
67
+ }
68
+ }
69
+ const len = path.length;
70
+ let rootEnd = 0;
71
+ let device = '';
72
+ let isAbsolute = false;
73
+ const code = path.charCodeAt(0);
74
+ if (len === 1) {
75
+ if (isPathSeparatorWin(code)) {
76
+ rootEnd = 1;
77
+ isAbsolute = true;
78
+ }
79
+ }
80
+ else if (isPathSeparatorWin(code)) {
81
+ isAbsolute = true;
82
+ if (isPathSeparatorWin(path.charCodeAt(1))) {
83
+ // UNC path: `\\server\share\…`
84
+ let j = 2;
85
+ let last = j;
86
+ while (j < len && !isPathSeparatorWin(path.charCodeAt(j)))
87
+ j++;
88
+ if (j < len && j !== last) {
89
+ const firstPart = path.slice(last, j);
90
+ last = j;
91
+ while (j < len && isPathSeparatorWin(path.charCodeAt(j)))
92
+ j++;
93
+ if (j < len && j !== last) {
94
+ last = j;
95
+ while (j < len && !isPathSeparatorWin(path.charCodeAt(j)))
96
+ j++;
97
+ if (j === len || j !== last) {
98
+ device = `\\\\${firstPart}\\${path.slice(last, j)}`;
99
+ rootEnd = j;
100
+ }
101
+ }
102
+ }
103
+ }
104
+ else {
105
+ rootEnd = 1;
106
+ }
107
+ }
108
+ else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
109
+ device = path.slice(0, 2);
110
+ rootEnd = 2;
111
+ if (len > 2 && isPathSeparatorWin(path.charCodeAt(2))) {
112
+ isAbsolute = true;
113
+ rootEnd = 3;
114
+ }
115
+ }
116
+ if (device.length > 0) {
117
+ if (resolvedDevice.length > 0) {
118
+ if (device.toLowerCase() !== resolvedDevice.toLowerCase())
119
+ continue;
120
+ }
121
+ else {
122
+ resolvedDevice = device;
123
+ }
124
+ }
125
+ if (resolvedAbsolute) {
126
+ if (resolvedDevice.length > 0)
127
+ break;
128
+ }
129
+ else {
130
+ resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
131
+ resolvedAbsolute = isAbsolute;
132
+ if (isAbsolute && resolvedDevice.length > 0)
133
+ break;
134
+ }
135
+ }
136
+ resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\', isPathSeparatorWin);
137
+ return resolvedDevice + (resolvedAbsolute ? '\\' : '') + resolvedTail || '.';
138
+ }
139
+ function isPosixPathSeparator(code) {
140
+ return code === CHAR_FORWARD_SLASH;
141
+ }
142
+ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) {
143
+ let res = '';
144
+ let lastSegmentLength = 0;
145
+ let lastSlash = -1;
146
+ let dots = 0;
147
+ let code = 0;
148
+ for (let i = 0; i <= path.length; ++i) {
149
+ if (i < path.length) {
150
+ code = path.charCodeAt(i);
151
+ }
152
+ else if (isPathSeparator(code)) {
153
+ break;
154
+ }
155
+ else {
156
+ code = CHAR_FORWARD_SLASH;
157
+ }
158
+ if (isPathSeparator(code)) {
159
+ if (lastSlash === i - 1 || dots === 1) {
160
+ // NOOP
161
+ }
162
+ else if (dots === 2) {
163
+ if (res.length < 2 || lastSegmentLength !== 2 ||
164
+ res.charCodeAt(res.length - 1) !== CHAR_DOT ||
165
+ res.charCodeAt(res.length - 2) !== CHAR_DOT) {
166
+ if (res.length > 2) {
167
+ const lastSlashIndex = res.indexOf(separator);
168
+ if (lastSlashIndex === -1) {
169
+ res = '';
170
+ lastSegmentLength = 0;
171
+ }
172
+ else {
173
+ res = res.slice(0, lastSlashIndex);
174
+ lastSegmentLength =
175
+ res.length - 1 - res.indexOf(separator);
176
+ }
177
+ lastSlash = i;
178
+ dots = 0;
179
+ continue;
180
+ }
181
+ else if (res.length !== 0) {
182
+ res = '';
183
+ lastSegmentLength = 0;
184
+ lastSlash = i;
185
+ dots = 0;
186
+ continue;
187
+ }
188
+ }
189
+ if (allowAboveRoot) {
190
+ res += res.length > 0 ? `${separator}..` : '..';
191
+ lastSegmentLength = 2;
192
+ }
193
+ }
194
+ else {
195
+ if (res.length > 0) {
196
+ res += `${separator}${path.slice(lastSlash + 1, i)}`;
197
+ }
198
+ else {
199
+ res = path.slice(lastSlash + 1, i);
200
+ }
201
+ lastSegmentLength = i - lastSlash - 1;
202
+ }
203
+ lastSlash = i;
204
+ dots = 0;
205
+ }
206
+ else if (code === CHAR_DOT && dots !== -1) {
207
+ ++dots;
208
+ }
209
+ else {
210
+ dots = -1;
211
+ }
212
+ }
213
+ return res;
214
+ }
215
+ export function resolve(...args) {
216
+ // On Windows, host paths are `D:\…` style. The POSIX-only resolver
217
+ // below treats `D` as a non-`/` character and produces garbage; route
218
+ // to the Windows-aware variant. POSIX hosts (Linux/macOS/browser)
219
+ // run the original code path unchanged — `_isWin32` is constant-folded
220
+ // away on those targets.
221
+ if (_isWin32)
222
+ return resolveWin32(args);
223
+ let resolvedPath = '';
224
+ let resolvedAbsolute = false;
225
+ for (let i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) {
226
+ const path = i >= 0 ? args[i] : '/';
227
+ validateString(path, 'path');
228
+ // Skip empty entries
229
+ if (path.length === 0) {
230
+ continue;
231
+ }
232
+ resolvedPath = `${path}/${resolvedPath}`;
233
+ resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
234
+ }
235
+ // At this point the path should be resolved to a full absolute path, but
236
+ // handle relative paths to be safe (might happen when process.cwd() fails)
237
+ // Normalize the path
238
+ resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);
239
+ if (resolvedAbsolute) {
240
+ return `/${resolvedPath}`;
241
+ }
242
+ return resolvedPath.length > 0 ? resolvedPath : '.';
243
+ }
244
+ export function relative(from, to) {
245
+ validateString(from, 'from');
246
+ validateString(to, 'to');
247
+ if (from === to)
248
+ return '';
249
+ // Trim leading forward slashes.
250
+ from = resolve(from);
251
+ to = resolve(to);
252
+ if (from === to)
253
+ return '';
254
+ const fromStart = 1;
255
+ const fromEnd = from.length;
256
+ const fromLen = fromEnd - fromStart;
257
+ const toStart = 1;
258
+ const toLen = to.length - toStart;
259
+ // Compare paths to find the longest common path from root
260
+ const length = (fromLen < toLen ? fromLen : toLen);
261
+ let lastCommonSep = -1;
262
+ let i = 0;
263
+ for (; i < length; i++) {
264
+ const fromCode = from.charCodeAt(fromStart + i);
265
+ if (fromCode !== to.charCodeAt(toStart + i)) {
266
+ break;
267
+ }
268
+ else if (fromCode === CHAR_FORWARD_SLASH) {
269
+ lastCommonSep = i;
270
+ }
271
+ }
272
+ if (i === length) {
273
+ if (toLen > length) {
274
+ if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
275
+ // We get here if `from` is the exact base path for `to`.
276
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
277
+ return to.slice(toStart + i + 1);
278
+ }
279
+ if (i === 0) {
280
+ // We get here if `from` is the root
281
+ // For example: from='/'; to='/foo'
282
+ return to.slice(toStart + i);
283
+ }
284
+ }
285
+ else if (fromLen > length) {
286
+ if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
287
+ // We get here if `to` is the exact base path for `from`.
288
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
289
+ lastCommonSep = i;
290
+ }
291
+ else if (i === 0) {
292
+ // We get here if `to` is the root.
293
+ // For example: from='/foo/bar'; to='/'
294
+ lastCommonSep = 0;
295
+ }
296
+ }
297
+ }
298
+ let out = '';
299
+ // Generate the relative path based on the path difference between `to`
300
+ // and `from`.
301
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
302
+ if (i === fromEnd ||
303
+ from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
304
+ out += out.length === 0 ? '..' : '/..';
305
+ }
306
+ }
307
+ // Lastly, append the rest of the destination (`to`) path that comes after
308
+ // the common path parts.
309
+ return `${out}${to.slice(toStart + lastCommonSep)}`;
310
+ }