cspell-lib 8.1.2 → 8.2.0
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/dist/esm/Settings/CSpellSettingsServer.d.ts +1 -1
- package/dist/esm/Settings/CSpellSettingsServer.js +1 -0
- package/dist/esm/Settings/Controller/configLoader/configLoader.d.ts +19 -8
- package/dist/esm/Settings/Controller/configLoader/configLoader.js +83 -49
- package/dist/esm/Settings/Controller/configLoader/configSearch.d.ts +7 -3
- package/dist/esm/Settings/Controller/configLoader/configSearch.js +68 -64
- package/dist/esm/Settings/Controller/configLoader/configToRawSettings.js +5 -2
- package/dist/esm/Settings/Controller/configLoader/normalizeRawSettings.d.ts +1 -1
- package/dist/esm/Settings/Controller/configLoader/normalizeRawSettings.js +6 -6
- package/dist/esm/Settings/DefaultSettings.js +5 -4
- package/dist/esm/Settings/DictionarySettings.js +4 -3
- package/dist/esm/Settings/GlobalSettings.js +5 -4
- package/dist/esm/Settings/mergeCache.d.ts +1 -0
- package/dist/esm/Settings/mergeCache.js +6 -1
- package/dist/esm/Settings/mergeList.d.ts +4 -0
- package/dist/esm/Settings/mergeList.js +6 -0
- package/dist/esm/SpellingDictionary/DictionaryLoader.js +1 -1
- package/dist/esm/fileSystem.d.ts +8 -0
- package/dist/esm/fileSystem.js +16 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/perf/perf.d.ts +11 -5
- package/dist/esm/perf/perf.js +16 -11
- package/dist/esm/util/AutoResolve.d.ts +12 -0
- package/dist/esm/util/AutoResolve.js +50 -1
- package/dist/esm/util/Uri.d.ts +10 -11
- package/dist/esm/util/Uri.js +5 -13
- package/dist/esm/util/findUp.d.ts +1 -1
- package/dist/esm/util/findUpFromUrl.d.ts +12 -0
- package/dist/esm/util/findUpFromUrl.js +44 -0
- package/dist/esm/util/resolveFile.d.ts +56 -35
- package/dist/esm/util/resolveFile.js +243 -147
- package/dist/esm/util/templates.d.ts +3 -0
- package/dist/esm/util/templates.js +36 -0
- package/dist/esm/util/url.d.ts +2 -1
- package/dist/esm/util/url.js +9 -3
- package/package.json +14 -14
- package/dist/esm/static.d.ts +0 -3
- package/dist/esm/static.js +0 -6
|
@@ -1,165 +1,258 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
2
3
|
import { resolveGlobal } from '@cspell/cspell-resolver';
|
|
3
4
|
import { importResolveModuleName } from '@cspell/dynamic-import';
|
|
4
|
-
import * as fs from 'fs';
|
|
5
5
|
import * as os from 'os';
|
|
6
6
|
import * as path from 'path';
|
|
7
7
|
import resolveFrom from 'resolve-from';
|
|
8
8
|
import { fileURLToPath } from 'url';
|
|
9
9
|
import { srcDirectory } from '../../lib-cjs/pkg-info.cjs';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const steps = [
|
|
21
|
-
{ filename, fn: tryUrl },
|
|
22
|
-
{ filename, fn: tryCreateRequire },
|
|
23
|
-
{ filename, fn: tryNodeRequireResolve },
|
|
24
|
-
{ filename, fn: tryImportResolve },
|
|
25
|
-
{ filename, fn: tryResolveExists },
|
|
26
|
-
{ filename, fn: tryNodeResolveDefaultPaths },
|
|
27
|
-
{ filename, fn: tryResolveFrom },
|
|
28
|
-
{ filename: filename.replace(testNodeModules, ''), fn: tryResolveFrom },
|
|
29
|
-
{ filename, fn: tryResolveGlobal },
|
|
30
|
-
];
|
|
31
|
-
for (const step of steps) {
|
|
32
|
-
const r = step.fn(step.filename, relativeTo);
|
|
33
|
-
if (r?.found)
|
|
34
|
-
return r;
|
|
10
|
+
import { getFileSystem } from '../fileSystem.js';
|
|
11
|
+
import { envToTemplateVars, replaceTemplate } from './templates.js';
|
|
12
|
+
import { fileURLOrPathToPath, isDataURL, isFileURL, isURLLike, resolveFileWithURL, toFilePathOrHref, toFileUrl, toURL, } from './url.js';
|
|
13
|
+
const regExpStartsWidthNodeModules = /^node_modules[/\\]/;
|
|
14
|
+
export class FileResolver {
|
|
15
|
+
fs;
|
|
16
|
+
templateReplacements;
|
|
17
|
+
constructor(fs, templateReplacements) {
|
|
18
|
+
this.fs = fs;
|
|
19
|
+
this.templateReplacements = templateReplacements;
|
|
35
20
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
* If relativeTo is a non-file URL, then it will try to resolve the filename relative to it.
|
|
47
|
-
* @param filename - url string
|
|
48
|
-
* @returns ResolveFileResult
|
|
49
|
-
*/
|
|
50
|
-
function tryUrl(filename, relativeToURL) {
|
|
51
|
-
if (isURLLike(filename)) {
|
|
52
|
-
if (isFileURL(filename)) {
|
|
53
|
-
const file = fileURLToPath(filename);
|
|
21
|
+
/**
|
|
22
|
+
* Resolve filename to absolute paths.
|
|
23
|
+
* - Replaces `${env:NAME}` with the value of the environment variable `NAME`.
|
|
24
|
+
* - Replaces `~` with the user's home directory.
|
|
25
|
+
* It tries to look for local files as well as node_modules
|
|
26
|
+
* @param filename an absolute path, relative path, `~` path, a node_module, or URL.
|
|
27
|
+
* @param relativeTo absolute path
|
|
28
|
+
*/
|
|
29
|
+
async resolveFile(filename, relativeTo) {
|
|
30
|
+
if (filename instanceof URL) {
|
|
54
31
|
return {
|
|
55
|
-
filename:
|
|
56
|
-
relativeTo:
|
|
57
|
-
found:
|
|
32
|
+
filename: toFilePathOrHref(filename),
|
|
33
|
+
relativeTo: relativeTo.toString(),
|
|
34
|
+
found: await this.doesExist(filename),
|
|
35
|
+
method: 'url',
|
|
58
36
|
};
|
|
59
37
|
}
|
|
60
|
-
|
|
38
|
+
const result = await this._resolveFile(filename, relativeTo);
|
|
39
|
+
const match = filename.match(regExpStartsWidthNodeModules);
|
|
40
|
+
if (match) {
|
|
41
|
+
result.warning ??= `Import of '${filename}' should not start with '${match[0]}' in '${toFilePathOrHref(relativeTo)}'. Use '${filename.replace(regExpStartsWidthNodeModules, '')}' or a relative path instead.`;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
61
44
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
filename:
|
|
68
|
-
|
|
69
|
-
|
|
45
|
+
async _resolveFile(filename, relativeTo) {
|
|
46
|
+
filename = patchFilename(filename, this.templateReplacements);
|
|
47
|
+
const steps = [
|
|
48
|
+
{ filename, fn: this.tryUrl },
|
|
49
|
+
{ filename, fn: this.tryCreateRequire },
|
|
50
|
+
{ filename, fn: this.tryNodeRequireResolve },
|
|
51
|
+
{ filename, fn: this.tryImportResolve },
|
|
52
|
+
{ filename, fn: this.tryResolveExists },
|
|
53
|
+
{ filename, fn: this.tryNodeResolveDefaultPaths },
|
|
54
|
+
{ filename, fn: this.tryResolveFrom },
|
|
55
|
+
{ filename, fn: this.tryResolveGlobal },
|
|
56
|
+
{ filename, fn: this.tryLegacyResolve },
|
|
57
|
+
];
|
|
58
|
+
for (const step of steps) {
|
|
59
|
+
const r = await step.fn(step.filename, relativeTo);
|
|
60
|
+
if (r?.found)
|
|
61
|
+
return r;
|
|
62
|
+
}
|
|
63
|
+
const result = (await this.tryUrl(filename, relativeTo)) || {
|
|
64
|
+
filename: isRelative(filename) ? joinWith(filename, relativeTo) : filename.toString(),
|
|
65
|
+
relativeTo: relativeTo.toString(),
|
|
66
|
+
found: false,
|
|
67
|
+
method: 'not found',
|
|
70
68
|
};
|
|
69
|
+
return result;
|
|
71
70
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return { filename: r, relativeTo: relativeTo.toString(), found: true };
|
|
81
|
-
}
|
|
82
|
-
catch (_) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function tryNodeResolveDefaultPaths(filename) {
|
|
87
|
-
try {
|
|
88
|
-
const r = require.resolve(filename);
|
|
89
|
-
return { filename: r, relativeTo: undefined, found: true };
|
|
71
|
+
async doesExist(file) {
|
|
72
|
+
try {
|
|
73
|
+
const s = await this.fs.stat(file);
|
|
74
|
+
return s.isFile() || s.isUnknown();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
90
79
|
}
|
|
91
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Check to see if it is a URL.
|
|
82
|
+
* Note: URLs are absolute!
|
|
83
|
+
* If relativeTo is a non-file URL, then it will try to resolve the filename relative to it.
|
|
84
|
+
* @param filename - url string
|
|
85
|
+
* @returns ResolveFileResult
|
|
86
|
+
*/
|
|
87
|
+
tryUrl = async (filename, relativeToURL) => {
|
|
88
|
+
if (isURLLike(filename)) {
|
|
89
|
+
const fileURL = toURL(filename);
|
|
90
|
+
return {
|
|
91
|
+
filename: toFilePathOrHref(fileURL),
|
|
92
|
+
relativeTo: undefined,
|
|
93
|
+
found: await this.doesExist(fileURL),
|
|
94
|
+
method: 'tryUrl',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (isURLLike(relativeToURL) && !isDataURL(relativeToURL)) {
|
|
98
|
+
const relToURL = toURL(relativeToURL);
|
|
99
|
+
const url = resolveFileWithURL(filename, relToURL);
|
|
100
|
+
return {
|
|
101
|
+
filename: toFilePathOrHref(url),
|
|
102
|
+
relativeTo: toFilePathOrHref(relToURL),
|
|
103
|
+
found: await this.doesExist(url),
|
|
104
|
+
method: 'tryUrl',
|
|
105
|
+
};
|
|
106
|
+
}
|
|
92
107
|
return undefined;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
108
|
+
};
|
|
109
|
+
tryCreateRequire = (filename, relativeTo) => {
|
|
110
|
+
if (filename instanceof URL)
|
|
111
|
+
return undefined;
|
|
112
|
+
const rel = !isURLLike(relativeTo) || isFileURL(relativeTo) ? relativeTo : pathToFileURL('./');
|
|
113
|
+
const require = createRequire(rel);
|
|
114
|
+
try {
|
|
115
|
+
const r = require.resolve(filename);
|
|
116
|
+
return { filename: r, relativeTo: rel.toString(), found: true, method: 'tryCreateRequire' };
|
|
117
|
+
}
|
|
118
|
+
catch (_) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
tryNodeResolveDefaultPaths = (filename) => {
|
|
123
|
+
try {
|
|
124
|
+
const r = require.resolve(filename);
|
|
125
|
+
return { filename: r, relativeTo: undefined, found: true, method: 'tryNodeResolveDefaultPaths' };
|
|
126
|
+
}
|
|
127
|
+
catch (_) {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
tryNodeRequireResolve = (filenameOrURL, relativeTo) => {
|
|
132
|
+
if (isURLLike(relativeTo) && !isFileURL(relativeTo))
|
|
133
|
+
return undefined;
|
|
134
|
+
const filename = fileURLOrPathToPath(filenameOrURL);
|
|
135
|
+
const relativeToPath = pathFromRelativeTo(relativeTo);
|
|
136
|
+
const home = os.homedir();
|
|
137
|
+
function calcPaths(p) {
|
|
138
|
+
const paths = [p];
|
|
139
|
+
// Do not progress towards the root if it is a relative filename.
|
|
140
|
+
if (isRelative(filename)) {
|
|
141
|
+
return paths;
|
|
142
|
+
}
|
|
143
|
+
for (; p && path.dirname(p) !== p && p !== home; p = path.dirname(p)) {
|
|
144
|
+
paths.push(p);
|
|
145
|
+
}
|
|
103
146
|
return paths;
|
|
104
147
|
}
|
|
105
|
-
|
|
106
|
-
|
|
148
|
+
const paths = calcPaths(path.resolve(relativeToPath));
|
|
149
|
+
try {
|
|
150
|
+
const r = require.resolve(filename, { paths });
|
|
151
|
+
return { filename: r, relativeTo: relativeToPath, found: true, method: 'tryNodeRequireResolve' };
|
|
152
|
+
}
|
|
153
|
+
catch (_) {
|
|
154
|
+
return undefined;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
tryImportResolve = (filename, relativeTo) => {
|
|
158
|
+
try {
|
|
159
|
+
const paths = isRelative(filename) ? [relativeTo] : [relativeTo, srcDirectory];
|
|
160
|
+
const resolved = fileURLToPath(importResolveModuleName(filename, paths));
|
|
161
|
+
return { filename: resolved, relativeTo: relativeTo.toString(), found: true, method: 'tryImportResolve' };
|
|
162
|
+
}
|
|
163
|
+
catch (_) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
tryResolveGlobal = (filename) => {
|
|
168
|
+
const r = resolveGlobal(filename);
|
|
169
|
+
return (r && { filename: r, relativeTo: undefined, found: true, method: 'tryResolveGlobal' }) || undefined;
|
|
170
|
+
};
|
|
171
|
+
tryResolveExists = async (filename, relativeTo) => {
|
|
172
|
+
if (filename instanceof URL || isURLLike(filename) || (isURLLike(relativeTo) && !isFileURL(relativeTo))) {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
relativeTo = pathFromRelativeTo(relativeTo);
|
|
176
|
+
const toTry = [{ filename }, { filename: path.resolve(relativeTo, filename), relativeTo }];
|
|
177
|
+
for (const { filename, relativeTo } of toTry) {
|
|
178
|
+
const found = path.isAbsolute(filename) && (await this.doesExist(toFileUrl(filename)));
|
|
179
|
+
if (found)
|
|
180
|
+
return { filename, relativeTo: relativeTo?.toString(), found, method: 'tryResolveExists' };
|
|
181
|
+
}
|
|
182
|
+
filename = path.resolve(filename);
|
|
183
|
+
return {
|
|
184
|
+
filename,
|
|
185
|
+
relativeTo: path.resolve('.'),
|
|
186
|
+
found: await this.doesExist(toFileUrl(filename)),
|
|
187
|
+
method: 'tryResolveExists',
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
tryResolveFrom = (filename, relativeTo) => {
|
|
191
|
+
if (relativeTo instanceof URL)
|
|
192
|
+
return undefined;
|
|
193
|
+
try {
|
|
194
|
+
return {
|
|
195
|
+
filename: resolveFrom(pathFromRelativeTo(relativeTo), filename),
|
|
196
|
+
relativeTo,
|
|
197
|
+
found: true,
|
|
198
|
+
method: 'tryResolveFrom',
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
// Failed to resolve a relative module request
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
tryLegacyResolve = (filename, relativeTo) => {
|
|
207
|
+
if (filename instanceof URL || isURLLike(filename) || (isURLLike(relativeTo) && !isFileURL(relativeTo))) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const relativeToPath = isURLLike(relativeTo) ? fileURLToPath(new URL('./', relativeTo)) : relativeTo.toString();
|
|
211
|
+
const match = filename.match(regExpStartsWidthNodeModules);
|
|
212
|
+
if (match) {
|
|
213
|
+
const fixedFilename = filename.replace(regExpStartsWidthNodeModules, '');
|
|
214
|
+
const found = this.tryImportResolve(fixedFilename, relativeToPath) ||
|
|
215
|
+
this.tryResolveFrom(fixedFilename, relativeToPath);
|
|
216
|
+
if (found?.found) {
|
|
217
|
+
found.method = 'tryLegacyResolve';
|
|
218
|
+
return found;
|
|
219
|
+
}
|
|
107
220
|
}
|
|
108
|
-
return paths;
|
|
109
|
-
}
|
|
110
|
-
const paths = calcPaths(path.resolve(relativeToPath));
|
|
111
|
-
try {
|
|
112
|
-
const r = require.resolve(filename, { paths });
|
|
113
|
-
return { filename: r, relativeTo: relativeToPath, found: true };
|
|
114
|
-
}
|
|
115
|
-
catch (_) {
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
function tryImportResolve(filename, relativeTo) {
|
|
120
|
-
try {
|
|
121
|
-
const paths = isRelative(filename) ? [relativeTo] : [relativeTo, srcDirectory];
|
|
122
|
-
const resolved = fileURLToPath(importResolveModuleName(filename, paths));
|
|
123
|
-
return { filename: resolved, relativeTo: relativeTo.toString(), found: true };
|
|
124
|
-
}
|
|
125
|
-
catch (_) {
|
|
126
221
|
return undefined;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
function tryResolveGlobal(filename) {
|
|
130
|
-
const r = resolveGlobal(filename);
|
|
131
|
-
return (r && { filename: r, relativeTo: undefined, found: true }) || undefined;
|
|
222
|
+
};
|
|
132
223
|
}
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const found = path.isAbsolute(filename) && fs.existsSync(filename);
|
|
139
|
-
if (found)
|
|
140
|
-
return { filename, relativeTo: relativeTo?.toString(), found };
|
|
141
|
-
}
|
|
142
|
-
filename = path.resolve(filename);
|
|
143
|
-
return {
|
|
144
|
-
filename,
|
|
145
|
-
relativeTo: path.resolve('.'),
|
|
146
|
-
found: fs.existsSync(filename),
|
|
224
|
+
export function patchFilename(filename, templateReplacements) {
|
|
225
|
+
const defaultReplacements = {
|
|
226
|
+
cwd: process.cwd(),
|
|
227
|
+
pathSeparator: path.sep,
|
|
228
|
+
userHome: os.homedir(),
|
|
147
229
|
};
|
|
230
|
+
filename = filename.replace(/^~(?=[/\\])/, defaultReplacements.userHome);
|
|
231
|
+
filename = replaceTemplate(filename, { ...defaultReplacements, ...templateReplacements });
|
|
232
|
+
return filename;
|
|
148
233
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Resolve filename to a URL
|
|
236
|
+
* - Replaces `${env:NAME}` with the value of the environment variable `NAME`.
|
|
237
|
+
* - Replaces `~` with the user's home directory.
|
|
238
|
+
* It will not resolve Node modules.
|
|
239
|
+
* @param filename - a filename, path, relative path, or URL.
|
|
240
|
+
* @param relativeTo - a path, or URL.
|
|
241
|
+
* @param env - environment variables used to patch the filename.
|
|
242
|
+
* @returns a URL
|
|
243
|
+
*/
|
|
244
|
+
export function resolveRelativeTo(filename, relativeTo, templateReplacements = envToTemplateVars(process.env)) {
|
|
245
|
+
if (filename instanceof URL)
|
|
246
|
+
return filename;
|
|
247
|
+
filename = patchFilename(filename, templateReplacements);
|
|
248
|
+
const relativeToUrl = toFileUrl(relativeTo);
|
|
249
|
+
return resolveFileWithURL(filename, relativeToUrl);
|
|
159
250
|
}
|
|
160
251
|
function isRelative(filename) {
|
|
161
252
|
if (filename instanceof URL)
|
|
162
253
|
return false;
|
|
254
|
+
if (isURLLike(filename))
|
|
255
|
+
return false;
|
|
163
256
|
if (filename.startsWith('./'))
|
|
164
257
|
return true;
|
|
165
258
|
if (filename.startsWith('../'))
|
|
@@ -175,17 +268,20 @@ function joinWith(filename, relativeTo) {
|
|
|
175
268
|
? toFilePathOrHref(new URL(filename, relativeTo))
|
|
176
269
|
: path.resolve(relativeTo, filename);
|
|
177
270
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
271
|
+
function pathFromRelativeTo(relativeTo) {
|
|
272
|
+
return relativeTo instanceof URL || isURLLike(relativeTo) ? fileURLToPath(new URL('./', relativeTo)) : relativeTo;
|
|
273
|
+
}
|
|
274
|
+
const loaderCache = new WeakMap();
|
|
275
|
+
export function createFileResolver(fs, templateVariables = envToTemplateVars(process.env)) {
|
|
276
|
+
let loader = loaderCache.get(fs);
|
|
277
|
+
if (!loader) {
|
|
278
|
+
loader = new FileResolver(fs, templateVariables);
|
|
279
|
+
loaderCache.set(fs, loader);
|
|
280
|
+
}
|
|
281
|
+
return loader;
|
|
282
|
+
}
|
|
283
|
+
export async function resolveFile(filename, relativeTo, fs = getFileSystem()) {
|
|
284
|
+
const resolver = createFileResolver(fs);
|
|
285
|
+
return resolver.resolveFile(filename, relativeTo);
|
|
286
|
+
}
|
|
191
287
|
//# sourceMappingURL=resolveFile.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function replaceTemplate(template, replacements) {
|
|
2
|
+
const templateStart = '${';
|
|
3
|
+
const tLen = templateStart.length;
|
|
4
|
+
const templateEnd = '}';
|
|
5
|
+
const parts = [];
|
|
6
|
+
let lastPos = 0;
|
|
7
|
+
let p = template.indexOf(templateStart, lastPos);
|
|
8
|
+
if (p < 0)
|
|
9
|
+
return template;
|
|
10
|
+
while (p >= 0) {
|
|
11
|
+
parts.push(template.substring(lastPos, p));
|
|
12
|
+
lastPos = p;
|
|
13
|
+
const end = template.indexOf(templateEnd, p);
|
|
14
|
+
if (end < 0)
|
|
15
|
+
break;
|
|
16
|
+
const name = template.substring(p + tLen, end);
|
|
17
|
+
if (name in replacements) {
|
|
18
|
+
parts.push(replacements[name] || '');
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
parts.push(template.substring(p, end + 1));
|
|
22
|
+
}
|
|
23
|
+
lastPos = end + 1;
|
|
24
|
+
p = template.indexOf(templateStart, lastPos);
|
|
25
|
+
}
|
|
26
|
+
parts.push(template.substring(lastPos));
|
|
27
|
+
return parts.join('');
|
|
28
|
+
}
|
|
29
|
+
export function envToTemplateVars(env) {
|
|
30
|
+
const vars = {};
|
|
31
|
+
for (const [key, value] of Object.entries(env)) {
|
|
32
|
+
vars[`env:${key}`] = value || '';
|
|
33
|
+
}
|
|
34
|
+
return vars;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=templates.js.map
|
package/dist/esm/util/url.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare function getSourceDirectoryUrl(): URL;
|
|
|
17
17
|
export declare function relativeTo(path: string, relativeTo?: URL | string): URL;
|
|
18
18
|
export declare function cwdURL(): URL;
|
|
19
19
|
export declare function resolveFileWithURL(file: string | URL, relativeToURL: URL): URL;
|
|
20
|
-
export declare function normalizePathSlashesForUrl(filePath: string, sep?:
|
|
20
|
+
export declare function normalizePathSlashesForUrl(filePath: string, sep?: string | RegExp): string;
|
|
21
21
|
export declare function toFileUrl(file: string | URL): URL;
|
|
22
22
|
export declare function toFileDirUrl(dir: string | URL): URL;
|
|
23
23
|
export declare function addTrailingSlash(url: URL): URL;
|
|
@@ -26,4 +26,5 @@ export declare function fileURLOrPathToPath(filenameOrURL: string | URL): string
|
|
|
26
26
|
export declare function isURLLike(url: string | URL): boolean;
|
|
27
27
|
export declare function isFileURL(url: string | URL): boolean;
|
|
28
28
|
export declare function isDataURL(url: string | URL): boolean;
|
|
29
|
+
export declare function windowsDriveLetterToUpper(absoluteFilePath: string): string;
|
|
29
30
|
//# sourceMappingURL=url.d.ts.map
|
package/dist/esm/util/url.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
3
3
|
import { srcDirectory } from '../../lib-cjs/pkg-info.cjs';
|
|
4
|
-
const isUrlRegExp = /^(
|
|
4
|
+
const isUrlRegExp = /^(?:[\w][\w-]+:\/|data:|untitled:)/i;
|
|
5
5
|
/**
|
|
6
6
|
* Convert a URL into a string. If it is a file URL, convert it to a path.
|
|
7
7
|
* @param url - URL
|
|
@@ -47,7 +47,7 @@ export function resolveFileWithURL(file, relativeToURL) {
|
|
|
47
47
|
}
|
|
48
48
|
return relativeTo(file, relativeToURL);
|
|
49
49
|
}
|
|
50
|
-
export function normalizePathSlashesForUrl(filePath, sep =
|
|
50
|
+
export function normalizePathSlashesForUrl(filePath, sep = /[/\\]/g) {
|
|
51
51
|
return filePath
|
|
52
52
|
.replace(/^([a-z]:)/i, '/$1')
|
|
53
53
|
.split(sep)
|
|
@@ -72,7 +72,10 @@ export function toURL(href, relativeTo) {
|
|
|
72
72
|
return href instanceof URL ? href : new URL(href, relativeTo);
|
|
73
73
|
}
|
|
74
74
|
export function fileURLOrPathToPath(filenameOrURL) {
|
|
75
|
-
return isFileURL(filenameOrURL) ?
|
|
75
|
+
return isFileURL(filenameOrURL) ? toFilePath(filenameOrURL) : filenameOrURL.toString();
|
|
76
|
+
}
|
|
77
|
+
function toFilePath(url) {
|
|
78
|
+
return windowsDriveLetterToUpper(fileURLToPath(url));
|
|
76
79
|
}
|
|
77
80
|
export function isURLLike(url) {
|
|
78
81
|
return url instanceof URL || isUrlRegExp.test(url);
|
|
@@ -87,4 +90,7 @@ function isUrlWithProtocol(url, protocol) {
|
|
|
87
90
|
protocol = protocol.endsWith(':') ? protocol : protocol + ':';
|
|
88
91
|
return url instanceof URL ? url.protocol === protocol : url.startsWith(protocol);
|
|
89
92
|
}
|
|
93
|
+
export function windowsDriveLetterToUpper(absoluteFilePath) {
|
|
94
|
+
return absoluteFilePath.replace(/^([a-z]):\\/, (s) => s.toUpperCase());
|
|
95
|
+
}
|
|
90
96
|
//# sourceMappingURL=url.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-lib",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "A library of useful functions used across various cspell tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -57,21 +57,21 @@
|
|
|
57
57
|
},
|
|
58
58
|
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@cspell/cspell-bundled-dicts": "8.
|
|
61
|
-
"@cspell/cspell-pipe": "8.
|
|
62
|
-
"@cspell/cspell-resolver": "8.
|
|
63
|
-
"@cspell/cspell-types": "8.
|
|
64
|
-
"@cspell/dynamic-import": "8.
|
|
65
|
-
"@cspell/strong-weak-map": "8.
|
|
60
|
+
"@cspell/cspell-bundled-dicts": "8.2.0",
|
|
61
|
+
"@cspell/cspell-pipe": "8.2.0",
|
|
62
|
+
"@cspell/cspell-resolver": "8.2.0",
|
|
63
|
+
"@cspell/cspell-types": "8.2.0",
|
|
64
|
+
"@cspell/dynamic-import": "8.2.0",
|
|
65
|
+
"@cspell/strong-weak-map": "8.2.0",
|
|
66
66
|
"clear-module": "^4.1.2",
|
|
67
67
|
"comment-json": "^4.2.3",
|
|
68
68
|
"configstore": "^6.0.0",
|
|
69
|
-
"cspell-config-lib": "8.
|
|
70
|
-
"cspell-dictionary": "8.
|
|
71
|
-
"cspell-glob": "8.
|
|
72
|
-
"cspell-grammar": "8.
|
|
73
|
-
"cspell-io": "8.
|
|
74
|
-
"cspell-trie-lib": "8.
|
|
69
|
+
"cspell-config-lib": "8.2.0",
|
|
70
|
+
"cspell-dictionary": "8.2.0",
|
|
71
|
+
"cspell-glob": "8.2.0",
|
|
72
|
+
"cspell-grammar": "8.2.0",
|
|
73
|
+
"cspell-io": "8.2.0",
|
|
74
|
+
"cspell-trie-lib": "8.2.0",
|
|
75
75
|
"fast-equals": "^5.0.1",
|
|
76
76
|
"gensequence": "^6.0.0",
|
|
77
77
|
"import-fresh": "^3.3.0",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"cspell-dict-nl-nl": "^1.1.2",
|
|
96
96
|
"lorem-ipsum": "^2.0.8"
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "3bcd6430bb33fb221d07030a60a2d61a2479e7ae"
|
|
99
99
|
}
|
package/dist/esm/static.d.ts
DELETED