@netlify/plugin-nextjs 4.40.1 → 4.40.2

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 (161) hide show
  1. package/lib/helpers/edge.js +1 -0
  2. package/lib/templates/vendor.js +20 -0
  3. package/package.json +7 -4
  4. package/src/templates/edge/next-dev.js +3 -3
  5. package/src/templates/edge/shims.js +6 -6
  6. package/src/templates/edge-shared/next-utils.ts +3 -3
  7. package/src/templates/edge-shared/utils.ts +1 -1
  8. package/src/templates/vendor/deno.land/std@0.134.0/fmt/colors.ts +536 -0
  9. package/src/templates/vendor/deno.land/std@0.134.0/testing/_diff.ts +360 -0
  10. package/src/templates/vendor/deno.land/std@0.134.0/testing/asserts.ts +866 -0
  11. package/src/templates/vendor/deno.land/std@0.175.0/_util/asserts.ts +25 -0
  12. package/src/templates/vendor/deno.land/std@0.175.0/_util/os.ts +23 -0
  13. package/src/templates/vendor/deno.land/std@0.175.0/async/abortable.ts +149 -0
  14. package/src/templates/vendor/deno.land/std@0.175.0/async/deadline.ts +30 -0
  15. package/src/templates/vendor/deno.land/std@0.175.0/async/debounce.ts +79 -0
  16. package/src/templates/vendor/deno.land/std@0.175.0/async/deferred.ts +48 -0
  17. package/src/templates/vendor/deno.land/std@0.175.0/async/delay.ts +67 -0
  18. package/src/templates/vendor/deno.land/std@0.175.0/async/mod.ts +18 -0
  19. package/src/templates/vendor/deno.land/std@0.175.0/async/mux_async_iterator.ts +97 -0
  20. package/src/templates/vendor/deno.land/std@0.175.0/async/pool.ts +95 -0
  21. package/src/templates/vendor/deno.land/std@0.175.0/async/retry.ts +81 -0
  22. package/src/templates/vendor/deno.land/std@0.175.0/async/tee.ts +100 -0
  23. package/src/templates/vendor/deno.land/std@0.175.0/bytes/index_of_needle.ts +49 -0
  24. package/src/templates/vendor/deno.land/std@0.175.0/crypto/timing_safe_equal.ts +29 -0
  25. package/src/templates/vendor/deno.land/std@0.175.0/datetime/to_imf.ts +45 -0
  26. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64.ts +144 -0
  27. package/src/templates/vendor/deno.land/std@0.175.0/encoding/base64url.ts +70 -0
  28. package/src/templates/vendor/deno.land/std@0.175.0/flags/mod.ts +785 -0
  29. package/src/templates/vendor/deno.land/std@0.175.0/fmt/colors.ts +569 -0
  30. package/src/templates/vendor/deno.land/std@0.175.0/fmt/printf.ts +939 -0
  31. package/src/templates/vendor/deno.land/std@0.175.0/http/cookie.ts +403 -0
  32. package/src/templates/vendor/deno.land/std@0.175.0/node/_core.ts +77 -0
  33. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.d.ts +848 -0
  34. package/src/templates/vendor/deno.land/std@0.175.0/node/_events.mjs +1033 -0
  35. package/src/templates/vendor/deno.land/std@0.175.0/node/_global.d.ts +66 -0
  36. package/src/templates/vendor/deno.land/std@0.175.0/node/_next_tick.ts +173 -0
  37. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/exiting.ts +4 -0
  38. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/process.ts +131 -0
  39. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/stdio.mjs +7 -0
  40. package/src/templates/vendor/deno.land/std@0.175.0/node/_process/streams.mjs +146 -0
  41. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.d.ts +1488 -0
  42. package/src/templates/vendor/deno.land/std@0.175.0/node/_stream.mjs +746 -0
  43. package/src/templates/vendor/deno.land/std@0.175.0/node/_util/_util_callbackify.ts +129 -0
  44. package/src/templates/vendor/deno.land/std@0.175.0/node/_utils.ts +206 -0
  45. package/src/templates/vendor/deno.land/std@0.175.0/node/assert.ts +940 -0
  46. package/src/templates/vendor/deno.land/std@0.175.0/node/assertion_error.ts +579 -0
  47. package/src/templates/vendor/deno.land/std@0.175.0/node/async_hooks.ts +331 -0
  48. package/src/templates/vendor/deno.land/std@0.175.0/node/buffer.ts +13 -0
  49. package/src/templates/vendor/deno.land/std@0.175.0/node/events.ts +14 -0
  50. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.d.ts +2074 -0
  51. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/buffer.mjs +2607 -0
  52. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/_keys.ts +16 -0
  53. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/crypto/constants.ts +5 -0
  54. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/error_codes.ts +7 -0
  55. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/errors.ts +2867 -0
  56. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/fixed_queue.ts +123 -0
  57. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/hide_stack_frames.ts +16 -0
  58. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/net.ts +95 -0
  59. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/normalize_encoding.mjs +72 -0
  60. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/options.ts +45 -0
  61. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/primordials.mjs +30 -0
  62. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/process/per_thread.mjs +272 -0
  63. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/callbacks.mjs +137 -0
  64. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/readline/utils.mjs +580 -0
  65. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/destroy.mjs +320 -0
  66. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/end-of-stream.mjs +229 -0
  67. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/streams/utils.mjs +242 -0
  68. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/comparisons.ts +669 -0
  69. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/debuglog.ts +118 -0
  70. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/inspect.mjs +2237 -0
  71. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util/types.ts +113 -0
  72. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/util.mjs +143 -0
  73. package/src/templates/vendor/deno.land/std@0.175.0/node/internal/validators.mjs +317 -0
  74. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_libuv_winerror.ts +229 -0
  75. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_listen.ts +16 -0
  76. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_node.ts +18 -0
  77. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_timingSafeEqual.ts +12 -0
  78. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_utils.ts +86 -0
  79. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/_winerror.ts +16873 -0
  80. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/ares.ts +66 -0
  81. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/async_wrap.ts +152 -0
  82. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/buffer.ts +130 -0
  83. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/cares_wrap.ts +541 -0
  84. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/config.ts +3 -0
  85. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/connection_wrap.ts +80 -0
  86. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/constants.ts +900 -0
  87. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/contextify.ts +3 -0
  88. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/credentials.ts +3 -0
  89. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/crypto.ts +14 -0
  90. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/errors.ts +3 -0
  91. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs.ts +3 -0
  92. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_dir.ts +3 -0
  93. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/fs_event_wrap.ts +3 -0
  94. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/handle_wrap.ts +50 -0
  95. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/heap_utils.ts +3 -0
  96. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/http_parser.ts +3 -0
  97. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/icu.ts +3 -0
  98. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/inspector.ts +3 -0
  99. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/js_stream.ts +3 -0
  100. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/messaging.ts +3 -0
  101. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/mod.ts +108 -0
  102. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/module_wrap.ts +3 -0
  103. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/native_module.ts +3 -0
  104. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/natives.ts +3 -0
  105. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_file.ts +84 -0
  106. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/node_options.ts +39 -0
  107. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/options.ts +3 -0
  108. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/os.ts +3 -0
  109. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/performance.ts +3 -0
  110. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/pipe_wrap.ts +392 -0
  111. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/process_methods.ts +3 -0
  112. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/report.ts +3 -0
  113. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/serdes.ts +3 -0
  114. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/signal_wrap.ts +3 -0
  115. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/spawn_sync.ts +3 -0
  116. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/stream_wrap.ts +354 -0
  117. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/string_decoder.ts +15 -0
  118. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/symbols.ts +27 -0
  119. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/task_queue.ts +3 -0
  120. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tcp_wrap.ts +488 -0
  121. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/timers.ts +3 -0
  122. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tls_wrap.ts +3 -0
  123. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/trace_events.ts +3 -0
  124. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/tty_wrap.ts +3 -0
  125. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/types.ts +186 -0
  126. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/udp_wrap.ts +496 -0
  127. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/url.ts +3 -0
  128. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/util.ts +126 -0
  129. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/uv.ts +437 -0
  130. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/v8.ts +3 -0
  131. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/worker.ts +3 -0
  132. package/src/templates/vendor/deno.land/std@0.175.0/node/internal_binding/zlib.ts +3 -0
  133. package/src/templates/vendor/deno.land/std@0.175.0/node/process.ts +705 -0
  134. package/src/templates/vendor/deno.land/std@0.175.0/node/stream.ts +37 -0
  135. package/src/templates/vendor/deno.land/std@0.175.0/node/string_decoder.ts +337 -0
  136. package/src/templates/vendor/deno.land/std@0.175.0/node/util/types.ts +4 -0
  137. package/src/templates/vendor/deno.land/std@0.175.0/node/util.ts +289 -0
  138. package/src/templates/vendor/deno.land/std@0.175.0/path/_constants.ts +49 -0
  139. package/src/templates/vendor/deno.land/std@0.175.0/path/_interface.ts +30 -0
  140. package/src/templates/vendor/deno.land/std@0.175.0/path/_util.ts +194 -0
  141. package/src/templates/vendor/deno.land/std@0.175.0/path/common.ts +40 -0
  142. package/src/templates/vendor/deno.land/std@0.175.0/path/glob.ts +418 -0
  143. package/src/templates/vendor/deno.land/std@0.175.0/path/mod.ts +53 -0
  144. package/src/templates/vendor/deno.land/std@0.175.0/path/posix.ts +487 -0
  145. package/src/templates/vendor/deno.land/std@0.175.0/path/separator.ts +7 -0
  146. package/src/templates/vendor/deno.land/std@0.175.0/path/win32.ts +962 -0
  147. package/src/templates/vendor/deno.land/std@0.175.0/streams/write_all.ts +64 -0
  148. package/src/templates/vendor/deno.land/std@0.175.0/testing/_diff.ts +440 -0
  149. package/src/templates/vendor/deno.land/std@0.175.0/testing/_format.ts +23 -0
  150. package/src/templates/vendor/deno.land/std@0.175.0/testing/asserts.ts +906 -0
  151. package/src/templates/vendor/deno.land/std@0.175.0/types.d.ts +89 -0
  152. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/index.ts +133 -0
  153. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/asyncify.js +112 -0
  154. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.d.ts +88 -0
  155. package/src/templates/vendor/deno.land/x/html_rewriter@v0.1.0-pre.17/vendor/html_rewriter.js +974 -0
  156. package/src/templates/vendor/deno.land/x/path_to_regexp@v6.2.1/index.ts +621 -0
  157. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +13 -0
  158. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +12 -0
  159. package/src/templates/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +5 -0
  160. package/src/templates/vendor/import_map.json +13 -0
  161. package/src/templates/vendor/raw.githubusercontent.com/worker-tools/resolvable-promise/master/index.ts +50 -0
@@ -0,0 +1,487 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // Copyright the Browserify authors. MIT License.
3
+ // Ported from https://github.com/browserify/path-browserify/
4
+ // This module is browser compatible.
5
+
6
+ import type { FormatInputPathObject, ParsedPath } from "./_interface.ts";
7
+ import { CHAR_DOT } from "./_constants.ts";
8
+
9
+ import {
10
+ _format,
11
+ assertPath,
12
+ encodeWhitespace,
13
+ isPosixPathSeparator,
14
+ lastPathSegment,
15
+ normalizeString,
16
+ stripSuffix,
17
+ stripTrailingSeparators,
18
+ } from "./_util.ts";
19
+
20
+ export const sep = "/";
21
+ export const delimiter = ":";
22
+
23
+ // path.resolve([from ...], to)
24
+ /**
25
+ * Resolves `pathSegments` into an absolute path.
26
+ * @param pathSegments an array of path segments
27
+ */
28
+ export function resolve(...pathSegments: string[]): string {
29
+ let resolvedPath = "";
30
+ let resolvedAbsolute = false;
31
+
32
+ for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
33
+ let path: string;
34
+
35
+ if (i >= 0) path = pathSegments[i];
36
+ else {
37
+ // deno-lint-ignore no-explicit-any
38
+ const { Deno } = globalThis as any;
39
+ if (typeof Deno?.cwd !== "function") {
40
+ throw new TypeError("Resolved a relative path without a CWD.");
41
+ }
42
+ path = Deno.cwd();
43
+ }
44
+
45
+ assertPath(path);
46
+
47
+ // Skip empty entries
48
+ if (path.length === 0) {
49
+ continue;
50
+ }
51
+
52
+ resolvedPath = `${path}/${resolvedPath}`;
53
+ resolvedAbsolute = isPosixPathSeparator(path.charCodeAt(0));
54
+ }
55
+
56
+ // At this point the path should be resolved to a full absolute path, but
57
+ // handle relative paths to be safe (might happen when process.cwd() fails)
58
+
59
+ // Normalize the path
60
+ resolvedPath = normalizeString(
61
+ resolvedPath,
62
+ !resolvedAbsolute,
63
+ "/",
64
+ isPosixPathSeparator,
65
+ );
66
+
67
+ if (resolvedAbsolute) {
68
+ if (resolvedPath.length > 0) return `/${resolvedPath}`;
69
+ else return "/";
70
+ } else if (resolvedPath.length > 0) return resolvedPath;
71
+ else return ".";
72
+ }
73
+
74
+ /**
75
+ * Normalize the `path`, resolving `'..'` and `'.'` segments.
76
+ * Note that resolving these segments does not necessarily mean that all will be eliminated.
77
+ * A `'..'` at the top-level will be preserved, and an empty path is canonically `'.'`.
78
+ * @param path to be normalized
79
+ */
80
+ export function normalize(path: string): string {
81
+ assertPath(path);
82
+
83
+ if (path.length === 0) return ".";
84
+
85
+ const isAbsolute = isPosixPathSeparator(path.charCodeAt(0));
86
+ const trailingSeparator = isPosixPathSeparator(
87
+ path.charCodeAt(path.length - 1),
88
+ );
89
+
90
+ // Normalize the path
91
+ path = normalizeString(path, !isAbsolute, "/", isPosixPathSeparator);
92
+
93
+ if (path.length === 0 && !isAbsolute) path = ".";
94
+ if (path.length > 0 && trailingSeparator) path += "/";
95
+
96
+ if (isAbsolute) return `/${path}`;
97
+ return path;
98
+ }
99
+
100
+ /**
101
+ * Verifies whether provided path is absolute
102
+ * @param path to be verified as absolute
103
+ */
104
+ export function isAbsolute(path: string): boolean {
105
+ assertPath(path);
106
+ return path.length > 0 && isPosixPathSeparator(path.charCodeAt(0));
107
+ }
108
+
109
+ /**
110
+ * Join all given a sequence of `paths`,then normalizes the resulting path.
111
+ * @param paths to be joined and normalized
112
+ */
113
+ export function join(...paths: string[]): string {
114
+ if (paths.length === 0) return ".";
115
+ let joined: string | undefined;
116
+ for (let i = 0, len = paths.length; i < len; ++i) {
117
+ const path = paths[i];
118
+ assertPath(path);
119
+ if (path.length > 0) {
120
+ if (!joined) joined = path;
121
+ else joined += `/${path}`;
122
+ }
123
+ }
124
+ if (!joined) return ".";
125
+ return normalize(joined);
126
+ }
127
+
128
+ /**
129
+ * Return the relative path from `from` to `to` based on current working directory.
130
+ * @param from path in current working directory
131
+ * @param to path in current working directory
132
+ */
133
+ export function relative(from: string, to: string): string {
134
+ assertPath(from);
135
+ assertPath(to);
136
+
137
+ if (from === to) return "";
138
+
139
+ from = resolve(from);
140
+ to = resolve(to);
141
+
142
+ if (from === to) return "";
143
+
144
+ // Trim any leading backslashes
145
+ let fromStart = 1;
146
+ const fromEnd = from.length;
147
+ for (; fromStart < fromEnd; ++fromStart) {
148
+ if (!isPosixPathSeparator(from.charCodeAt(fromStart))) break;
149
+ }
150
+ const fromLen = fromEnd - fromStart;
151
+
152
+ // Trim any leading backslashes
153
+ let toStart = 1;
154
+ const toEnd = to.length;
155
+ for (; toStart < toEnd; ++toStart) {
156
+ if (!isPosixPathSeparator(to.charCodeAt(toStart))) break;
157
+ }
158
+ const toLen = toEnd - toStart;
159
+
160
+ // Compare paths to find the longest common path from root
161
+ const length = fromLen < toLen ? fromLen : toLen;
162
+ let lastCommonSep = -1;
163
+ let i = 0;
164
+ for (; i <= length; ++i) {
165
+ if (i === length) {
166
+ if (toLen > length) {
167
+ if (isPosixPathSeparator(to.charCodeAt(toStart + i))) {
168
+ // We get here if `from` is the exact base path for `to`.
169
+ // For example: from='/foo/bar'; to='/foo/bar/baz'
170
+ return to.slice(toStart + i + 1);
171
+ } else if (i === 0) {
172
+ // We get here if `from` is the root
173
+ // For example: from='/'; to='/foo'
174
+ return to.slice(toStart + i);
175
+ }
176
+ } else if (fromLen > length) {
177
+ if (isPosixPathSeparator(from.charCodeAt(fromStart + i))) {
178
+ // We get here if `to` is the exact base path for `from`.
179
+ // For example: from='/foo/bar/baz'; to='/foo/bar'
180
+ lastCommonSep = i;
181
+ } else if (i === 0) {
182
+ // We get here if `to` is the root.
183
+ // For example: from='/foo'; to='/'
184
+ lastCommonSep = 0;
185
+ }
186
+ }
187
+ break;
188
+ }
189
+ const fromCode = from.charCodeAt(fromStart + i);
190
+ const toCode = to.charCodeAt(toStart + i);
191
+ if (fromCode !== toCode) break;
192
+ else if (isPosixPathSeparator(fromCode)) lastCommonSep = i;
193
+ }
194
+
195
+ let out = "";
196
+ // Generate the relative path based on the path difference between `to`
197
+ // and `from`
198
+ for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
199
+ if (i === fromEnd || isPosixPathSeparator(from.charCodeAt(i))) {
200
+ if (out.length === 0) out += "..";
201
+ else out += "/..";
202
+ }
203
+ }
204
+
205
+ // Lastly, append the rest of the destination (`to`) path that comes after
206
+ // the common path parts
207
+ if (out.length > 0) return out + to.slice(toStart + lastCommonSep);
208
+ else {
209
+ toStart += lastCommonSep;
210
+ if (isPosixPathSeparator(to.charCodeAt(toStart))) ++toStart;
211
+ return to.slice(toStart);
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Resolves path to a namespace path
217
+ * @param path to resolve to namespace
218
+ */
219
+ export function toNamespacedPath(path: string): string {
220
+ // Non-op on posix systems
221
+ return path;
222
+ }
223
+
224
+ /**
225
+ * Return the directory path of a `path`.
226
+ * @param path - path to extract the directory from.
227
+ */
228
+ export function dirname(path: string): string {
229
+ if (path.length === 0) return ".";
230
+
231
+ let end = -1;
232
+ let matchedNonSeparator = false;
233
+
234
+ for (let i = path.length - 1; i >= 1; --i) {
235
+ if (isPosixPathSeparator(path.charCodeAt(i))) {
236
+ if (matchedNonSeparator) {
237
+ end = i;
238
+ break;
239
+ }
240
+ } else {
241
+ matchedNonSeparator = true;
242
+ }
243
+ }
244
+
245
+ // No matches. Fallback based on provided path:
246
+ //
247
+ // - leading slashes paths
248
+ // "/foo" => "/"
249
+ // "///foo" => "/"
250
+ // - no slash path
251
+ // "foo" => "."
252
+ if (end === -1) {
253
+ return isPosixPathSeparator(path.charCodeAt(0)) ? "/" : ".";
254
+ }
255
+
256
+ return stripTrailingSeparators(
257
+ path.slice(0, end),
258
+ isPosixPathSeparator,
259
+ );
260
+ }
261
+
262
+ /**
263
+ * Return the last portion of a `path`.
264
+ * Trailing directory separators are ignored, and optional suffix is removed.
265
+ *
266
+ * @param path - path to extract the name from.
267
+ * @param [suffix] - suffix to remove from extracted name.
268
+ */
269
+ export function basename(path: string, suffix = ""): string {
270
+ assertPath(path);
271
+
272
+ if (path.length === 0) return path;
273
+
274
+ if (typeof suffix !== "string") {
275
+ throw new TypeError(
276
+ `Suffix must be a string. Received ${JSON.stringify(suffix)}`,
277
+ );
278
+ }
279
+
280
+ const lastSegment = lastPathSegment(path, isPosixPathSeparator);
281
+ const strippedSegment = stripTrailingSeparators(
282
+ lastSegment,
283
+ isPosixPathSeparator,
284
+ );
285
+ return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;
286
+ }
287
+
288
+ /**
289
+ * Return the extension of the `path` with leading period.
290
+ * @param path with extension
291
+ * @returns extension (ex. for `file.ts` returns `.ts`)
292
+ */
293
+ export function extname(path: string): string {
294
+ assertPath(path);
295
+ let startDot = -1;
296
+ let startPart = 0;
297
+ let end = -1;
298
+ let matchedSlash = true;
299
+ // Track the state of characters (if any) we see before our first dot and
300
+ // after any path separator we find
301
+ let preDotState = 0;
302
+ for (let i = path.length - 1; i >= 0; --i) {
303
+ const code = path.charCodeAt(i);
304
+ if (isPosixPathSeparator(code)) {
305
+ // If we reached a path separator that was not part of a set of path
306
+ // separators at the end of the string, stop now
307
+ if (!matchedSlash) {
308
+ startPart = i + 1;
309
+ break;
310
+ }
311
+ continue;
312
+ }
313
+ if (end === -1) {
314
+ // We saw the first non-path separator, mark this as the end of our
315
+ // extension
316
+ matchedSlash = false;
317
+ end = i + 1;
318
+ }
319
+ if (code === CHAR_DOT) {
320
+ // If this is our first dot, mark it as the start of our extension
321
+ if (startDot === -1) startDot = i;
322
+ else if (preDotState !== 1) preDotState = 1;
323
+ } else if (startDot !== -1) {
324
+ // We saw a non-dot and non-path separator before our dot, so we should
325
+ // have a good chance at having a non-empty extension
326
+ preDotState = -1;
327
+ }
328
+ }
329
+
330
+ if (
331
+ startDot === -1 ||
332
+ end === -1 ||
333
+ // We saw a non-dot character immediately before the dot
334
+ preDotState === 0 ||
335
+ // The (right-most) trimmed path component is exactly '..'
336
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
337
+ ) {
338
+ return "";
339
+ }
340
+ return path.slice(startDot, end);
341
+ }
342
+
343
+ /**
344
+ * Generate a path from `FormatInputPathObject` object.
345
+ * @param pathObject with path
346
+ */
347
+ export function format(pathObject: FormatInputPathObject): string {
348
+ if (pathObject === null || typeof pathObject !== "object") {
349
+ throw new TypeError(
350
+ `The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`,
351
+ );
352
+ }
353
+ return _format("/", pathObject);
354
+ }
355
+
356
+ /**
357
+ * Return a `ParsedPath` object of the `path`.
358
+ * @param path to process
359
+ */
360
+ export function parse(path: string): ParsedPath {
361
+ assertPath(path);
362
+
363
+ const ret: ParsedPath = { root: "", dir: "", base: "", ext: "", name: "" };
364
+ if (path.length === 0) return ret;
365
+ const isAbsolute = isPosixPathSeparator(path.charCodeAt(0));
366
+ let start: number;
367
+ if (isAbsolute) {
368
+ ret.root = "/";
369
+ start = 1;
370
+ } else {
371
+ start = 0;
372
+ }
373
+ let startDot = -1;
374
+ let startPart = 0;
375
+ let end = -1;
376
+ let matchedSlash = true;
377
+ let i = path.length - 1;
378
+
379
+ // Track the state of characters (if any) we see before our first dot and
380
+ // after any path separator we find
381
+ let preDotState = 0;
382
+
383
+ // Get non-dir info
384
+ for (; i >= start; --i) {
385
+ const code = path.charCodeAt(i);
386
+ if (isPosixPathSeparator(code)) {
387
+ // If we reached a path separator that was not part of a set of path
388
+ // separators at the end of the string, stop now
389
+ if (!matchedSlash) {
390
+ startPart = i + 1;
391
+ break;
392
+ }
393
+ continue;
394
+ }
395
+ if (end === -1) {
396
+ // We saw the first non-path separator, mark this as the end of our
397
+ // extension
398
+ matchedSlash = false;
399
+ end = i + 1;
400
+ }
401
+ if (code === CHAR_DOT) {
402
+ // If this is our first dot, mark it as the start of our extension
403
+ if (startDot === -1) startDot = i;
404
+ else if (preDotState !== 1) preDotState = 1;
405
+ } else if (startDot !== -1) {
406
+ // We saw a non-dot and non-path separator before our dot, so we should
407
+ // have a good chance at having a non-empty extension
408
+ preDotState = -1;
409
+ }
410
+ }
411
+
412
+ if (
413
+ startDot === -1 ||
414
+ end === -1 ||
415
+ // We saw a non-dot character immediately before the dot
416
+ preDotState === 0 ||
417
+ // The (right-most) trimmed path component is exactly '..'
418
+ (preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
419
+ ) {
420
+ if (end !== -1) {
421
+ if (startPart === 0 && isAbsolute) {
422
+ ret.base = ret.name = path.slice(1, end);
423
+ } else {
424
+ ret.base = ret.name = path.slice(startPart, end);
425
+ }
426
+ }
427
+ // Fallback to '/' in case there is no basename
428
+ ret.base = ret.base || "/";
429
+ } else {
430
+ if (startPart === 0 && isAbsolute) {
431
+ ret.name = path.slice(1, startDot);
432
+ ret.base = path.slice(1, end);
433
+ } else {
434
+ ret.name = path.slice(startPart, startDot);
435
+ ret.base = path.slice(startPart, end);
436
+ }
437
+ ret.ext = path.slice(startDot, end);
438
+ }
439
+
440
+ if (startPart > 0) {
441
+ ret.dir = stripTrailingSeparators(
442
+ path.slice(0, startPart - 1),
443
+ isPosixPathSeparator,
444
+ );
445
+ } else if (isAbsolute) ret.dir = "/";
446
+
447
+ return ret;
448
+ }
449
+
450
+ /**
451
+ * Converts a file URL to a path string.
452
+ *
453
+ * ```ts
454
+ * import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
455
+ * fromFileUrl("file:///home/foo"); // "/home/foo"
456
+ * ```
457
+ * @param url of a file URL
458
+ */
459
+ export function fromFileUrl(url: string | URL): string {
460
+ url = url instanceof URL ? url : new URL(url);
461
+ if (url.protocol != "file:") {
462
+ throw new TypeError("Must be a file URL.");
463
+ }
464
+ return decodeURIComponent(
465
+ url.pathname.replace(/%(?![0-9A-Fa-f]{2})/g, "%25"),
466
+ );
467
+ }
468
+
469
+ /**
470
+ * Converts a path string to a file URL.
471
+ *
472
+ * ```ts
473
+ * import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
474
+ * toFileUrl("/home/foo"); // new URL("file:///home/foo")
475
+ * ```
476
+ * @param path to convert to file URL
477
+ */
478
+ export function toFileUrl(path: string): URL {
479
+ if (!isAbsolute(path)) {
480
+ throw new TypeError("Must be an absolute path.");
481
+ }
482
+ const url = new URL("file:///");
483
+ url.pathname = encodeWhitespace(
484
+ path.replace(/%/g, "%25").replace(/\\/g, "%5C"),
485
+ );
486
+ return url;
487
+ }
@@ -0,0 +1,7 @@
1
+ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2
+ // This module is browser compatible.
3
+
4
+ import { isWindows } from "../_util/os.ts";
5
+
6
+ export const SEP = isWindows ? "\\" : "/";
7
+ export const SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/;