@netlify/edge-bundler 8.8.0 → 8.8.1
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/deno/lib/common.ts +3 -3
- package/deno/lib/stage2.ts +2 -2
- package/deno/vendor/deno.land/std@0.178.0/_util/asserts.ts +25 -0
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/_util/os.ts +4 -3
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/_constants.ts +1 -1
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/_interface.ts +1 -1
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/_util.ts +63 -2
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/common.ts +1 -1
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/glob.ts +10 -5
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/mod.ts +20 -2
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/posix.ts +76 -105
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/separator.ts +1 -1
- package/deno/vendor/deno.land/{std@0.127.0 → std@0.178.0}/path/win32.ts +36 -82
- package/deno/vendor/deno.land/x/{eszip@v0.28.0 → eszip@v0.37.0}/eszip_wasm.generated.js +350 -114
- package/deno/vendor/deno.land/x/eszip@v0.37.0/eszip_wasm_bg.wasm +0 -0
- package/deno/vendor/deno.land/x/{eszip@v0.28.0 → eszip@v0.37.0}/loader.ts +1 -1
- package/deno/vendor/deno.land/x/{eszip@v0.28.0 → eszip@v0.37.0}/mod.ts +4 -2
- package/dist/test/util.js +1 -1
- package/package.json +1 -1
- package/deno/vendor/deno.land/std@0.127.0/_util/assert.ts +0 -15
- package/deno/vendor/deno.land/x/eszip@v0.28.0/eszip_wasm_bg.wasm +0 -0
package/deno/lib/common.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { load } from "https://deno.land/x/eszip@v0.
|
|
2
|
-
import { LoadResponse } from "https://deno.land/x/eszip@v0.
|
|
3
|
-
import * as path from "https://deno.land/std@0.
|
|
1
|
+
import { load } from "https://deno.land/x/eszip@v0.37.0/loader.ts";
|
|
2
|
+
import { LoadResponse } from "https://deno.land/x/eszip@v0.37.0/mod.ts";
|
|
3
|
+
import * as path from "https://deno.land/std@0.178.0/path/mod.ts";
|
|
4
4
|
import { retryAsync } from "https://deno.land/x/retry@v2.0.0/mod.ts";
|
|
5
5
|
import { isTooManyTries } from "https://deno.land/x/retry@v2.0.0/retry/tooManyTries.ts";
|
|
6
6
|
|
package/deno/lib/stage2.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { build, LoadResponse } from 'https://deno.land/x/eszip@v0.
|
|
1
|
+
import { build, LoadResponse } from 'https://deno.land/x/eszip@v0.37.0/mod.ts'
|
|
2
2
|
|
|
3
|
-
import * as path from 'https://deno.land/std@0.
|
|
3
|
+
import * as path from 'https://deno.land/std@0.178.0/path/mod.ts'
|
|
4
4
|
|
|
5
5
|
import type { InputFunction, WriteStage2Options } from '../../shared/stage2.ts'
|
|
6
6
|
import { importMapSpecifier, virtualRoot } from '../../shared/consts.ts'
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
|
+
// This module is browser compatible.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* All internal non-test code, that is files that do not have `test` or `bench` in the name, must use the assertion functions within `_utils/asserts.ts` and not `testing/asserts.ts`. This is to create a separation of concerns between internal and testing assertions.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class DenoStdInternalError extends Error {
|
|
9
|
+
constructor(message: string) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "DenoStdInternalError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Make an assertion, if not `true`, then throw. */
|
|
16
|
+
export function assert(expr: unknown, msg = ""): asserts expr {
|
|
17
|
+
if (!expr) {
|
|
18
|
+
throw new DenoStdInternalError(msg);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Use this to assert unreachable code. */
|
|
23
|
+
export function unreachable(): never {
|
|
24
|
+
throw new DenoStdInternalError("unreachable");
|
|
25
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
3
|
|
|
4
|
-
export type OSType = "windows" | "linux" | "darwin";
|
|
4
|
+
export type OSType = "windows" | "linux" | "darwin" | "freebsd";
|
|
5
5
|
|
|
6
6
|
export const osType: OSType = (() => {
|
|
7
7
|
// deno-lint-ignore no-explicit-any
|
|
@@ -12,7 +12,7 @@ export const osType: OSType = (() => {
|
|
|
12
12
|
|
|
13
13
|
// deno-lint-ignore no-explicit-any
|
|
14
14
|
const { navigator } = globalThis as any;
|
|
15
|
-
if (navigator?.appVersion?.includes?.("Win")
|
|
15
|
+
if (navigator?.appVersion?.includes?.("Win")) {
|
|
16
16
|
return "windows";
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -20,3 +20,4 @@ export const osType: OSType = (() => {
|
|
|
20
20
|
})();
|
|
21
21
|
|
|
22
22
|
export const isWindows = osType === "windows";
|
|
23
|
+
export const isLinux = osType === "linux";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// Copyright the Browserify authors. MIT License.
|
|
3
3
|
// Ported from https://github.com/browserify/path-browserify/
|
|
4
4
|
// This module is browser compatible.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// Copyright the Browserify authors. MIT License.
|
|
3
3
|
// Ported from https://github.com/browserify/path-browserify/
|
|
4
4
|
// This module is browser compatible.
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
CHAR_UPPERCASE_Z,
|
|
15
15
|
} from "./_constants.ts";
|
|
16
16
|
|
|
17
|
-
export function assertPath(path: string)
|
|
17
|
+
export function assertPath(path: string) {
|
|
18
18
|
if (typeof path !== "string") {
|
|
19
19
|
throw new TypeError(
|
|
20
20
|
`Path must be a string. Received ${JSON.stringify(path)}`,
|
|
@@ -113,6 +113,7 @@ export function _format(
|
|
|
113
113
|
const base: string = pathObject.base ||
|
|
114
114
|
(pathObject.name || "") + (pathObject.ext || "");
|
|
115
115
|
if (!dir) return base;
|
|
116
|
+
if (base === sep) return dir;
|
|
116
117
|
if (dir === pathObject.root) return dir + base;
|
|
117
118
|
return dir + sep + base;
|
|
118
119
|
}
|
|
@@ -131,3 +132,63 @@ export function encodeWhitespace(string: string): string {
|
|
|
131
132
|
return WHITESPACE_ENCODINGS[c] ?? c;
|
|
132
133
|
});
|
|
133
134
|
}
|
|
135
|
+
|
|
136
|
+
export function lastPathSegment(
|
|
137
|
+
path: string,
|
|
138
|
+
isSep: (char: number) => boolean,
|
|
139
|
+
start = 0,
|
|
140
|
+
): string {
|
|
141
|
+
let matchedNonSeparator = false;
|
|
142
|
+
let end = path.length;
|
|
143
|
+
|
|
144
|
+
for (let i = path.length - 1; i >= start; --i) {
|
|
145
|
+
if (isSep(path.charCodeAt(i))) {
|
|
146
|
+
if (matchedNonSeparator) {
|
|
147
|
+
start = i + 1;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
} else if (!matchedNonSeparator) {
|
|
151
|
+
matchedNonSeparator = true;
|
|
152
|
+
end = i + 1;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return path.slice(start, end);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function stripTrailingSeparators(
|
|
160
|
+
segment: string,
|
|
161
|
+
isSep: (char: number) => boolean,
|
|
162
|
+
): string {
|
|
163
|
+
if (segment.length <= 1) {
|
|
164
|
+
return segment;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let end = segment.length;
|
|
168
|
+
|
|
169
|
+
for (let i = segment.length - 1; i > 0; i--) {
|
|
170
|
+
if (isSep(segment.charCodeAt(i))) {
|
|
171
|
+
end = i;
|
|
172
|
+
} else {
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return segment.slice(0, end);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function stripSuffix(name: string, suffix: string): string {
|
|
181
|
+
if (suffix.length >= name.length) {
|
|
182
|
+
return name;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const lenDiff = name.length - suffix.length;
|
|
186
|
+
|
|
187
|
+
for (let i = suffix.length - 1; i >= 0; --i) {
|
|
188
|
+
if (name.charCodeAt(lenDiff + i) !== suffix.charCodeAt(i)) {
|
|
189
|
+
return name;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return name.slice(0, -suffix.length);
|
|
194
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// This module is browser compatible.
|
|
3
3
|
|
|
4
4
|
import { isWindows, osType } from "../_util/os.ts";
|
|
@@ -12,14 +12,19 @@ const { join, normalize } = path;
|
|
|
12
12
|
|
|
13
13
|
export interface GlobOptions {
|
|
14
14
|
/** Extended glob syntax.
|
|
15
|
-
* See https://www.linuxjournal.com/content/bash-extended-globbing.
|
|
16
|
-
*
|
|
15
|
+
* See https://www.linuxjournal.com/content/bash-extended-globbing.
|
|
16
|
+
*
|
|
17
|
+
* @default {true}
|
|
18
|
+
*/
|
|
17
19
|
extended?: boolean;
|
|
18
20
|
/** Globstar syntax.
|
|
19
21
|
* See https://www.linuxjournal.com/content/globstar-new-bash-globbing-option.
|
|
20
|
-
* If false, `**` is treated like `*`.
|
|
22
|
+
* If false, `**` is treated like `*`.
|
|
23
|
+
*
|
|
24
|
+
* @default {true}
|
|
25
|
+
*/
|
|
21
26
|
globstar?: boolean;
|
|
22
|
-
/** Whether globstar should be case
|
|
27
|
+
/** Whether globstar should be case-insensitive. */
|
|
23
28
|
caseInsensitive?: boolean;
|
|
24
29
|
/** Operating system. Defaults to the native OS. */
|
|
25
30
|
os?: OSType;
|
|
@@ -1,7 +1,25 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// Copyright the Browserify authors. MIT License.
|
|
3
3
|
// Ported mostly from https://github.com/browserify/path-browserify/
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Utilities for working with OS-specific file paths.
|
|
7
|
+
*
|
|
8
|
+
* Codes in the examples uses POSIX path but it automatically use Windows path
|
|
9
|
+
* on Windows. Use methods under `posix` or `win32` object instead to handle non
|
|
10
|
+
* platform specific path like:
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { posix, win32 } from "https://deno.land/std@$STD_VERSION/path/mod.ts";
|
|
13
|
+
* const p1 = posix.fromFileUrl("file:///home/foo");
|
|
14
|
+
* const p2 = win32.fromFileUrl("file:///home/foo");
|
|
15
|
+
* console.log(p1); // "/home/foo"
|
|
16
|
+
* console.log(p2); // "\\home\\foo"
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* This module is browser compatible.
|
|
20
|
+
*
|
|
21
|
+
* @module
|
|
22
|
+
*/
|
|
5
23
|
|
|
6
24
|
import { isWindows } from "../_util/os.ts";
|
|
7
25
|
import * as _win32 from "./win32.ts";
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
// Copyright 2018-
|
|
1
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
2
2
|
// Copyright the Browserify authors. MIT License.
|
|
3
3
|
// Ported from https://github.com/browserify/path-browserify/
|
|
4
4
|
// This module is browser compatible.
|
|
5
5
|
|
|
6
6
|
import type { FormatInputPathObject, ParsedPath } from "./_interface.ts";
|
|
7
|
-
import { CHAR_DOT
|
|
7
|
+
import { CHAR_DOT } from "./_constants.ts";
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
10
|
_format,
|
|
11
11
|
assertPath,
|
|
12
12
|
encodeWhitespace,
|
|
13
13
|
isPosixPathSeparator,
|
|
14
|
+
lastPathSegment,
|
|
14
15
|
normalizeString,
|
|
16
|
+
stripSuffix,
|
|
17
|
+
stripTrailingSeparators,
|
|
15
18
|
} from "./_util.ts";
|
|
16
19
|
|
|
17
20
|
export const sep = "/";
|
|
@@ -47,7 +50,7 @@ export function resolve(...pathSegments: string[]): string {
|
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
resolvedPath = `${path}/${resolvedPath}`;
|
|
50
|
-
resolvedAbsolute = path.charCodeAt(0)
|
|
53
|
+
resolvedAbsolute = isPosixPathSeparator(path.charCodeAt(0));
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
// At this point the path should be resolved to a full absolute path, but
|
|
@@ -70,6 +73,8 @@ export function resolve(...pathSegments: string[]): string {
|
|
|
70
73
|
|
|
71
74
|
/**
|
|
72
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 `'.'`.
|
|
73
78
|
* @param path to be normalized
|
|
74
79
|
*/
|
|
75
80
|
export function normalize(path: string): string {
|
|
@@ -77,9 +82,10 @@ export function normalize(path: string): string {
|
|
|
77
82
|
|
|
78
83
|
if (path.length === 0) return ".";
|
|
79
84
|
|
|
80
|
-
const isAbsolute = path.charCodeAt(0)
|
|
81
|
-
const trailingSeparator =
|
|
82
|
-
path.charCodeAt(path.length - 1)
|
|
85
|
+
const isAbsolute = isPosixPathSeparator(path.charCodeAt(0));
|
|
86
|
+
const trailingSeparator = isPosixPathSeparator(
|
|
87
|
+
path.charCodeAt(path.length - 1),
|
|
88
|
+
);
|
|
83
89
|
|
|
84
90
|
// Normalize the path
|
|
85
91
|
path = normalizeString(path, !isAbsolute, "/", isPosixPathSeparator);
|
|
@@ -97,7 +103,7 @@ export function normalize(path: string): string {
|
|
|
97
103
|
*/
|
|
98
104
|
export function isAbsolute(path: string): boolean {
|
|
99
105
|
assertPath(path);
|
|
100
|
-
return path.length > 0 && path.charCodeAt(0)
|
|
106
|
+
return path.length > 0 && isPosixPathSeparator(path.charCodeAt(0));
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
/**
|
|
@@ -139,7 +145,7 @@ export function relative(from: string, to: string): string {
|
|
|
139
145
|
let fromStart = 1;
|
|
140
146
|
const fromEnd = from.length;
|
|
141
147
|
for (; fromStart < fromEnd; ++fromStart) {
|
|
142
|
-
if (from.charCodeAt(fromStart)
|
|
148
|
+
if (!isPosixPathSeparator(from.charCodeAt(fromStart))) break;
|
|
143
149
|
}
|
|
144
150
|
const fromLen = fromEnd - fromStart;
|
|
145
151
|
|
|
@@ -147,7 +153,7 @@ export function relative(from: string, to: string): string {
|
|
|
147
153
|
let toStart = 1;
|
|
148
154
|
const toEnd = to.length;
|
|
149
155
|
for (; toStart < toEnd; ++toStart) {
|
|
150
|
-
if (to.charCodeAt(toStart)
|
|
156
|
+
if (!isPosixPathSeparator(to.charCodeAt(toStart))) break;
|
|
151
157
|
}
|
|
152
158
|
const toLen = toEnd - toStart;
|
|
153
159
|
|
|
@@ -158,7 +164,7 @@ export function relative(from: string, to: string): string {
|
|
|
158
164
|
for (; i <= length; ++i) {
|
|
159
165
|
if (i === length) {
|
|
160
166
|
if (toLen > length) {
|
|
161
|
-
if (to.charCodeAt(toStart + i)
|
|
167
|
+
if (isPosixPathSeparator(to.charCodeAt(toStart + i))) {
|
|
162
168
|
// We get here if `from` is the exact base path for `to`.
|
|
163
169
|
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
|
164
170
|
return to.slice(toStart + i + 1);
|
|
@@ -168,7 +174,7 @@ export function relative(from: string, to: string): string {
|
|
|
168
174
|
return to.slice(toStart + i);
|
|
169
175
|
}
|
|
170
176
|
} else if (fromLen > length) {
|
|
171
|
-
if (from.charCodeAt(fromStart + i)
|
|
177
|
+
if (isPosixPathSeparator(from.charCodeAt(fromStart + i))) {
|
|
172
178
|
// We get here if `to` is the exact base path for `from`.
|
|
173
179
|
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
|
174
180
|
lastCommonSep = i;
|
|
@@ -183,14 +189,14 @@ export function relative(from: string, to: string): string {
|
|
|
183
189
|
const fromCode = from.charCodeAt(fromStart + i);
|
|
184
190
|
const toCode = to.charCodeAt(toStart + i);
|
|
185
191
|
if (fromCode !== toCode) break;
|
|
186
|
-
else if (fromCode
|
|
192
|
+
else if (isPosixPathSeparator(fromCode)) lastCommonSep = i;
|
|
187
193
|
}
|
|
188
194
|
|
|
189
195
|
let out = "";
|
|
190
196
|
// Generate the relative path based on the path difference between `to`
|
|
191
197
|
// and `from`
|
|
192
198
|
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
|
193
|
-
if (i === fromEnd || from.charCodeAt(i)
|
|
199
|
+
if (i === fromEnd || isPosixPathSeparator(from.charCodeAt(i))) {
|
|
194
200
|
if (out.length === 0) out += "..";
|
|
195
201
|
else out += "/..";
|
|
196
202
|
}
|
|
@@ -201,7 +207,7 @@ export function relative(from: string, to: string): string {
|
|
|
201
207
|
if (out.length > 0) return out + to.slice(toStart + lastCommonSep);
|
|
202
208
|
else {
|
|
203
209
|
toStart += lastCommonSep;
|
|
204
|
-
if (to.charCodeAt(toStart)
|
|
210
|
+
if (isPosixPathSeparator(to.charCodeAt(toStart))) ++toStart;
|
|
205
211
|
return to.slice(toStart);
|
|
206
212
|
}
|
|
207
213
|
}
|
|
@@ -216,114 +222,73 @@ export function toNamespacedPath(path: string): string {
|
|
|
216
222
|
}
|
|
217
223
|
|
|
218
224
|
/**
|
|
219
|
-
* Return the directory
|
|
220
|
-
* @param path to
|
|
225
|
+
* Return the directory path of a `path`.
|
|
226
|
+
* @param path - path to extract the directory from.
|
|
221
227
|
*/
|
|
222
228
|
export function dirname(path: string): string {
|
|
223
|
-
assertPath(path);
|
|
224
229
|
if (path.length === 0) return ".";
|
|
225
|
-
|
|
230
|
+
|
|
226
231
|
let end = -1;
|
|
227
|
-
let
|
|
232
|
+
let matchedNonSeparator = false;
|
|
233
|
+
|
|
228
234
|
for (let i = path.length - 1; i >= 1; --i) {
|
|
229
|
-
if (path.charCodeAt(i)
|
|
230
|
-
if (
|
|
235
|
+
if (isPosixPathSeparator(path.charCodeAt(i))) {
|
|
236
|
+
if (matchedNonSeparator) {
|
|
231
237
|
end = i;
|
|
232
238
|
break;
|
|
233
239
|
}
|
|
234
240
|
} else {
|
|
235
|
-
|
|
236
|
-
matchedSlash = false;
|
|
241
|
+
matchedNonSeparator = true;
|
|
237
242
|
}
|
|
238
243
|
}
|
|
239
244
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
+
);
|
|
243
260
|
}
|
|
244
261
|
|
|
245
262
|
/**
|
|
246
|
-
* Return the last portion of a `path`.
|
|
247
|
-
*
|
|
248
|
-
*
|
|
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.
|
|
249
268
|
*/
|
|
250
|
-
export function basename(path: string,
|
|
251
|
-
if (ext !== undefined && typeof ext !== "string") {
|
|
252
|
-
throw new TypeError('"ext" argument must be a string');
|
|
253
|
-
}
|
|
269
|
+
export function basename(path: string, suffix = ""): string {
|
|
254
270
|
assertPath(path);
|
|
255
271
|
|
|
256
|
-
|
|
257
|
-
let end = -1;
|
|
258
|
-
let matchedSlash = true;
|
|
259
|
-
let i: number;
|
|
260
|
-
|
|
261
|
-
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
262
|
-
if (ext.length === path.length && ext === path) return "";
|
|
263
|
-
let extIdx = ext.length - 1;
|
|
264
|
-
let firstNonSlashEnd = -1;
|
|
265
|
-
for (i = path.length - 1; i >= 0; --i) {
|
|
266
|
-
const code = path.charCodeAt(i);
|
|
267
|
-
if (code === CHAR_FORWARD_SLASH) {
|
|
268
|
-
// If we reached a path separator that was not part of a set of path
|
|
269
|
-
// separators at the end of the string, stop now
|
|
270
|
-
if (!matchedSlash) {
|
|
271
|
-
start = i + 1;
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
} else {
|
|
275
|
-
if (firstNonSlashEnd === -1) {
|
|
276
|
-
// We saw the first non-path separator, remember this index in case
|
|
277
|
-
// we need it if the extension ends up not matching
|
|
278
|
-
matchedSlash = false;
|
|
279
|
-
firstNonSlashEnd = i + 1;
|
|
280
|
-
}
|
|
281
|
-
if (extIdx >= 0) {
|
|
282
|
-
// Try to match the explicit extension
|
|
283
|
-
if (code === ext.charCodeAt(extIdx)) {
|
|
284
|
-
if (--extIdx === -1) {
|
|
285
|
-
// We matched the extension, so mark this as the end of our path
|
|
286
|
-
// component
|
|
287
|
-
end = i;
|
|
288
|
-
}
|
|
289
|
-
} else {
|
|
290
|
-
// Extension does not match, so our result is the entire path
|
|
291
|
-
// component
|
|
292
|
-
extIdx = -1;
|
|
293
|
-
end = firstNonSlashEnd;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (start === end) end = firstNonSlashEnd;
|
|
300
|
-
else if (end === -1) end = path.length;
|
|
301
|
-
return path.slice(start, end);
|
|
302
|
-
} else {
|
|
303
|
-
for (i = path.length - 1; i >= 0; --i) {
|
|
304
|
-
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
|
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
|
-
start = i + 1;
|
|
309
|
-
break;
|
|
310
|
-
}
|
|
311
|
-
} else if (end === -1) {
|
|
312
|
-
// We saw the first non-path separator, mark this as the end of our
|
|
313
|
-
// path component
|
|
314
|
-
matchedSlash = false;
|
|
315
|
-
end = i + 1;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
272
|
+
if (path.length === 0) return path;
|
|
318
273
|
|
|
319
|
-
|
|
320
|
-
|
|
274
|
+
if (typeof suffix !== "string") {
|
|
275
|
+
throw new TypeError(
|
|
276
|
+
`Suffix must be a string. Received ${JSON.stringify(suffix)}`,
|
|
277
|
+
);
|
|
321
278
|
}
|
|
279
|
+
|
|
280
|
+
const lastSegment = lastPathSegment(path, isPosixPathSeparator);
|
|
281
|
+
const strippedSegment = stripTrailingSeparators(
|
|
282
|
+
lastSegment,
|
|
283
|
+
isPosixPathSeparator,
|
|
284
|
+
);
|
|
285
|
+
return suffix ? stripSuffix(strippedSegment, suffix) : strippedSegment;
|
|
322
286
|
}
|
|
323
287
|
|
|
324
288
|
/**
|
|
325
|
-
* Return the extension of the `path
|
|
289
|
+
* Return the extension of the `path` with leading period.
|
|
326
290
|
* @param path with extension
|
|
291
|
+
* @returns extension (ex. for `file.ts` returns `.ts`)
|
|
327
292
|
*/
|
|
328
293
|
export function extname(path: string): string {
|
|
329
294
|
assertPath(path);
|
|
@@ -336,7 +301,7 @@ export function extname(path: string): string {
|
|
|
336
301
|
let preDotState = 0;
|
|
337
302
|
for (let i = path.length - 1; i >= 0; --i) {
|
|
338
303
|
const code = path.charCodeAt(i);
|
|
339
|
-
if (code
|
|
304
|
+
if (isPosixPathSeparator(code)) {
|
|
340
305
|
// If we reached a path separator that was not part of a set of path
|
|
341
306
|
// separators at the end of the string, stop now
|
|
342
307
|
if (!matchedSlash) {
|
|
@@ -397,7 +362,7 @@ export function parse(path: string): ParsedPath {
|
|
|
397
362
|
|
|
398
363
|
const ret: ParsedPath = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
399
364
|
if (path.length === 0) return ret;
|
|
400
|
-
const isAbsolute = path.charCodeAt(0)
|
|
365
|
+
const isAbsolute = isPosixPathSeparator(path.charCodeAt(0));
|
|
401
366
|
let start: number;
|
|
402
367
|
if (isAbsolute) {
|
|
403
368
|
ret.root = "/";
|
|
@@ -418,7 +383,7 @@ export function parse(path: string): ParsedPath {
|
|
|
418
383
|
// Get non-dir info
|
|
419
384
|
for (; i >= start; --i) {
|
|
420
385
|
const code = path.charCodeAt(i);
|
|
421
|
-
if (code
|
|
386
|
+
if (isPosixPathSeparator(code)) {
|
|
422
387
|
// If we reached a path separator that was not part of a set of path
|
|
423
388
|
// separators at the end of the string, stop now
|
|
424
389
|
if (!matchedSlash) {
|
|
@@ -459,6 +424,8 @@ export function parse(path: string): ParsedPath {
|
|
|
459
424
|
ret.base = ret.name = path.slice(startPart, end);
|
|
460
425
|
}
|
|
461
426
|
}
|
|
427
|
+
// Fallback to '/' in case there is no basename
|
|
428
|
+
ret.base = ret.base || "/";
|
|
462
429
|
} else {
|
|
463
430
|
if (startPart === 0 && isAbsolute) {
|
|
464
431
|
ret.name = path.slice(1, startDot);
|
|
@@ -470,8 +437,12 @@ export function parse(path: string): ParsedPath {
|
|
|
470
437
|
ret.ext = path.slice(startDot, end);
|
|
471
438
|
}
|
|
472
439
|
|
|
473
|
-
if (startPart > 0)
|
|
474
|
-
|
|
440
|
+
if (startPart > 0) {
|
|
441
|
+
ret.dir = stripTrailingSeparators(
|
|
442
|
+
path.slice(0, startPart - 1),
|
|
443
|
+
isPosixPathSeparator,
|
|
444
|
+
);
|
|
445
|
+
} else if (isAbsolute) ret.dir = "/";
|
|
475
446
|
|
|
476
447
|
return ret;
|
|
477
448
|
}
|
|
@@ -480,7 +451,7 @@ export function parse(path: string): ParsedPath {
|
|
|
480
451
|
* Converts a file URL to a path string.
|
|
481
452
|
*
|
|
482
453
|
* ```ts
|
|
483
|
-
* import { fromFileUrl } from "
|
|
454
|
+
* import { fromFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
484
455
|
* fromFileUrl("file:///home/foo"); // "/home/foo"
|
|
485
456
|
* ```
|
|
486
457
|
* @param url of a file URL
|
|
@@ -499,7 +470,7 @@ export function fromFileUrl(url: string | URL): string {
|
|
|
499
470
|
* Converts a path string to a file URL.
|
|
500
471
|
*
|
|
501
472
|
* ```ts
|
|
502
|
-
* import { toFileUrl } from "
|
|
473
|
+
* import { toFileUrl } from "https://deno.land/std@$STD_VERSION/path/posix.ts";
|
|
503
474
|
* toFileUrl("/home/foo"); // new URL("file:///home/foo")
|
|
504
475
|
* ```
|
|
505
476
|
* @param path to convert to file URL
|