1 | ;
|
2 | // *****************************************************************************
|
3 | // Copyright (C) 2017 TypeFox and others.
|
4 | //
|
5 | // This program and the accompanying materials are made available under the
|
6 | // terms of the Eclipse Public License v. 2.0 which is available at
|
7 | // http://www.eclipse.org/legal/epl-2.0.
|
8 | //
|
9 | // This Source Code may also be made available under the following Secondary
|
10 | // Licenses when the conditions for such availability set forth in the Eclipse
|
11 | // Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
12 | // with the GNU Classpath Exception which is available at
|
13 | // https://www.gnu.org/software/classpath/license.html.
|
14 | //
|
15 | // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
16 | // *****************************************************************************
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.FileUri = void 0;
|
19 | const vscode_uri_1 = require("vscode-uri");
|
20 | const uri_1 = require("../common/uri");
|
21 | const os_1 = require("../common/os");
|
22 | var FileUri;
|
23 | (function (FileUri) {
|
24 | const windowsDriveRegex = /^([^:/?#]+?):$/;
|
25 | /**
|
26 | * Creates a new file URI from the filesystem path argument.
|
27 | * @param fsPath the filesystem path.
|
28 | */
|
29 | function create(fsPath_) {
|
30 | return new uri_1.default(vscode_uri_1.URI.file(fsPath_));
|
31 | }
|
32 | FileUri.create = create;
|
33 | /**
|
34 | * Returns with the platform specific FS path that is represented by the URI argument.
|
35 | *
|
36 | * @param uri the file URI that has to be resolved to a platform specific FS path.
|
37 | */
|
38 | function fsPath(uri) {
|
39 | if (typeof uri === 'string') {
|
40 | return fsPath(new uri_1.default(uri));
|
41 | }
|
42 | else {
|
43 | /*
|
44 | * A uri for the root of a Windows drive, eg file:\\\c%3A, is converted to c:
|
45 | * by the Uri class. However file:\\\c%3A is unambiguously a uri to the root of
|
46 | * the drive and c: is interpreted as the default directory for the c drive
|
47 | * (by, for example, the readdir function in the fs-extra module).
|
48 | * A backslash must be appended to the drive, eg c:\, to ensure the correct path.
|
49 | */
|
50 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
51 | const fsPathFromVsCodeUri = uri.codeUri.fsPath;
|
52 | if (os_1.isWindows) {
|
53 | const isWindowsDriveRoot = windowsDriveRegex.exec(fsPathFromVsCodeUri);
|
54 | if (isWindowsDriveRoot) {
|
55 | return fsPathFromVsCodeUri + '\\';
|
56 | }
|
57 | }
|
58 | return fsPathFromVsCodeUri;
|
59 | }
|
60 | }
|
61 | FileUri.fsPath = fsPath;
|
62 | })(FileUri = exports.FileUri || (exports.FileUri = {}));
|
63 | //# sourceMappingURL=file-uri.js.map |
\ | No newline at end of file |