1 | "use strict";
|
2 | var __importStar = (this && this.__importStar) || function (mod) {
|
3 | if (mod && mod.__esModule) return mod;
|
4 | var result = {};
|
5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6 | result["default"] = mod;
|
7 | return result;
|
8 | };
|
9 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
10 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | const fs = __importStar(require("fs"));
|
14 | const path = __importStar(require("path"));
|
15 | const crypto_1 = __importDefault(require("crypto"));
|
16 | const url_1 = require("url");
|
17 | function getDenoDir() {
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | let denoDir = process.env.DENO_DIR;
|
24 | if (denoDir === undefined) {
|
25 | switch (process.platform) {
|
26 | case "win32":
|
27 | denoDir = `${process.env.LOCALAPPDATA}\\deno`;
|
28 | break;
|
29 | case "darwin":
|
30 | denoDir = `${process.env.HOME}/Library/Caches/deno`;
|
31 | break;
|
32 | case "linux":
|
33 | denoDir = process.env.XDG_CACHE_HOME
|
34 | ? `${process.env.XDG_CACHE_HOME}/deno`
|
35 | : `${process.env.HOME}/.cache/deno`;
|
36 | break;
|
37 | default:
|
38 | denoDir = `${process.env.HOME}/.deno`;
|
39 | }
|
40 | }
|
41 | return denoDir;
|
42 | }
|
43 | exports.getDenoDir = getDenoDir;
|
44 | function getDenoDepsDir() {
|
45 | return path.join(getDenoDir(), "deps");
|
46 | }
|
47 | exports.getDenoDepsDir = getDenoDepsDir;
|
48 | function getPluginPath(tsLsHost) {
|
49 | return path.resolve(tsLsHost.getCurrentDirectory(), "node_modules", "typescript-deno-plugin");
|
50 | }
|
51 | exports.getPluginPath = getPluginPath;
|
52 | function getDenoDtsPath(tsLsHost, specifier) {
|
53 | let file = path.resolve(getDenoDir(), specifier);
|
54 | if (fs.existsSync(file)) {
|
55 | return file;
|
56 | }
|
57 | file = path.resolve(getPluginPath(tsLsHost), "lib", specifier);
|
58 | if (fs.existsSync(file)) {
|
59 | return file;
|
60 | }
|
61 | return undefined;
|
62 | }
|
63 | exports.getDenoDtsPath = getDenoDtsPath;
|
64 | function getModuleWithQueryString(moduleName) {
|
65 | let name = moduleName;
|
66 | for (const index = name.indexOf("?"); index !== -1; name = name.substring(index + 1)) {
|
67 | const sub = name.substring(0, index);
|
68 | if (sub.endsWith(".ts") || sub.endsWith(".tsx")) {
|
69 | const cutLength = moduleName.length - name.length;
|
70 | return moduleName.substring(0, index + cutLength) || undefined;
|
71 | }
|
72 | }
|
73 | return undefined;
|
74 | }
|
75 | exports.getModuleWithQueryString = getModuleWithQueryString;
|
76 | function normalizeFilepath(filepath) {
|
77 | return path.normalize(filepath
|
78 |
|
79 | .replace(/^([a-z]):\\/, (_, $1) => $1.toUpperCase() + ":\\")
|
80 |
|
81 | .replace(/\//gm, path.sep));
|
82 | }
|
83 | exports.normalizeFilepath = normalizeFilepath;
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | function escapeRegExp(str) {
|
90 | return str.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
|
91 | }
|
92 | exports.escapeRegExp = escapeRegExp;
|
93 | function sleep(ms) {
|
94 | return new Promise((resolve) => {
|
95 | setTimeout(() => {
|
96 | resolve();
|
97 | }, ms);
|
98 | });
|
99 | }
|
100 | exports.sleep = sleep;
|
101 | function isHttpURL(str) {
|
102 | if (!str.startsWith("http://") && !str.startsWith("https://")) {
|
103 | return false;
|
104 | }
|
105 | try {
|
106 | new url_1.URL(str);
|
107 | return true;
|
108 | }
|
109 | catch (_a) {
|
110 | return false;
|
111 | }
|
112 | }
|
113 | exports.isHttpURL = isHttpURL;
|
114 |
|
115 | function hashURL(url) {
|
116 | return crypto_1.default
|
117 | .createHash("sha256")
|
118 | .update(url.pathname + url.search)
|
119 | .digest("hex");
|
120 | }
|
121 | exports.hashURL = hashURL;
|
122 | function isValidDenoDocument(languageID) {
|
123 | return [
|
124 | "javascript",
|
125 | "javascriptreact",
|
126 | "typescript",
|
127 | "typescriptreact",
|
128 | ].includes(languageID);
|
129 | }
|
130 | exports.isValidDenoDocument = isValidDenoDocument;
|
131 | function isUntitledDocument(filename) {
|
132 |
|
133 | return /^untitled:/.test(filename);
|
134 | }
|
135 | exports.isUntitledDocument = isUntitledDocument;
|
136 | function pathExistsSync(filepath) {
|
137 | try {
|
138 | fs.statSync(filepath);
|
139 | return true;
|
140 | }
|
141 | catch (err) {
|
142 | return false;
|
143 | }
|
144 | }
|
145 | exports.pathExistsSync = pathExistsSync;
|
146 |
|
\ | No newline at end of file |