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