cspell-lib 8.1.3 → 8.2.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/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 -52
- 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 +45 -36
- package/dist/esm/util/resolveFile.js +238 -180
- 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,200 +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 {
|
|
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';
|
|
11
13
|
const regExpStartsWidthNodeModules = /^node_modules[/\\]/;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export function resolveFile(filename, relativeTo) {
|
|
19
|
-
const result = _resolveFile(filename, relativeTo);
|
|
20
|
-
const match = filename.match(regExpStartsWidthNodeModules);
|
|
21
|
-
if (match) {
|
|
22
|
-
result.warning ??= `Import of '${filename}' should not start with '${match[0]}' in '${toFilePathOrHref(relativeTo)}'. Use '${filename.replace(regExpStartsWidthNodeModules, '')}' or a relative path instead.`;
|
|
23
|
-
}
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
export function _resolveFile(filename, relativeTo) {
|
|
27
|
-
filename = filename.replace(/^~/, os.homedir());
|
|
28
|
-
const steps = [
|
|
29
|
-
{ filename, fn: tryUrl },
|
|
30
|
-
{ filename, fn: tryCreateRequire },
|
|
31
|
-
{ filename, fn: tryNodeRequireResolve },
|
|
32
|
-
{ filename, fn: tryImportResolve },
|
|
33
|
-
{ filename, fn: tryResolveExists },
|
|
34
|
-
{ filename, fn: tryNodeResolveDefaultPaths },
|
|
35
|
-
{ filename, fn: tryResolveFrom },
|
|
36
|
-
{ filename, fn: tryResolveGlobal },
|
|
37
|
-
{ filename, fn: tryLegacyResolve },
|
|
38
|
-
];
|
|
39
|
-
for (const step of steps) {
|
|
40
|
-
const r = step.fn(step.filename, relativeTo);
|
|
41
|
-
if (r?.found)
|
|
42
|
-
return r;
|
|
14
|
+
export class FileResolver {
|
|
15
|
+
fs;
|
|
16
|
+
templateReplacements;
|
|
17
|
+
constructor(fs, templateReplacements) {
|
|
18
|
+
this.fs = fs;
|
|
19
|
+
this.templateReplacements = templateReplacements;
|
|
43
20
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
* Note: URLs are absolute!
|
|
55
|
-
* If relativeTo is a non-file URL, then it will try to resolve the filename relative to it.
|
|
56
|
-
* @param filename - url string
|
|
57
|
-
* @returns ResolveFileResult
|
|
58
|
-
*/
|
|
59
|
-
function tryUrl(filename, relativeToURL) {
|
|
60
|
-
if (isURLLike(filename)) {
|
|
61
|
-
if (isFileURL(filename)) {
|
|
62
|
-
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) {
|
|
63
31
|
return {
|
|
64
|
-
filename:
|
|
65
|
-
relativeTo:
|
|
66
|
-
found:
|
|
67
|
-
method: '
|
|
32
|
+
filename: toFilePathOrHref(filename),
|
|
33
|
+
relativeTo: relativeTo.toString(),
|
|
34
|
+
found: await this.doesExist(filename),
|
|
35
|
+
method: 'url',
|
|
68
36
|
};
|
|
69
37
|
}
|
|
70
|
-
|
|
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;
|
|
71
44
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
filename:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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',
|
|
81
68
|
};
|
|
69
|
+
return result;
|
|
82
70
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return { filename: r, relativeTo: relativeTo.toString(), found: true, method: 'tryCreateRequire' };
|
|
92
|
-
}
|
|
93
|
-
catch (_) {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function tryNodeResolveDefaultPaths(filename) {
|
|
98
|
-
try {
|
|
99
|
-
const r = require.resolve(filename);
|
|
100
|
-
return { filename: r, relativeTo: undefined, found: true, method: 'tryNodeResolveDefaultPaths' };
|
|
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
|
+
}
|
|
101
79
|
}
|
|
102
|
-
|
|
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
|
+
}
|
|
103
107
|
return undefined;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
}
|
|
114
146
|
return paths;
|
|
115
147
|
}
|
|
116
|
-
|
|
117
|
-
|
|
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;
|
|
118
155
|
}
|
|
119
|
-
return paths;
|
|
120
|
-
}
|
|
121
|
-
const paths = calcPaths(path.resolve(relativeToPath));
|
|
122
|
-
try {
|
|
123
|
-
const r = require.resolve(filename, { paths });
|
|
124
|
-
return { filename: r, relativeTo: relativeToPath, found: true, method: 'tryNodeRequireResolve' };
|
|
125
|
-
}
|
|
126
|
-
catch (_) {
|
|
127
|
-
return undefined;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function tryImportResolve(filename, relativeTo) {
|
|
131
|
-
try {
|
|
132
|
-
const paths = isRelative(filename) ? [relativeTo] : [relativeTo, srcDirectory];
|
|
133
|
-
const resolved = fileURLToPath(importResolveModuleName(filename, paths));
|
|
134
|
-
return { filename: resolved, relativeTo: relativeTo.toString(), found: true, method: 'tryImportResolve' };
|
|
135
|
-
}
|
|
136
|
-
catch (_) {
|
|
137
|
-
return undefined;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
function tryResolveGlobal(filename) {
|
|
141
|
-
const r = resolveGlobal(filename);
|
|
142
|
-
return (r && { filename: r, relativeTo: undefined, found: true, method: 'tryResolveGlobal' }) || undefined;
|
|
143
|
-
}
|
|
144
|
-
function tryResolveExists(filename, relativeTo) {
|
|
145
|
-
if (filename instanceof URL || isURLLike(filename) || (isURLLike(relativeTo) && !isFileURL(relativeTo))) {
|
|
146
|
-
return undefined;
|
|
147
|
-
}
|
|
148
|
-
relativeTo = pathFromRelativeTo(relativeTo);
|
|
149
|
-
const toTry = [{ filename }, { filename: path.resolve(relativeTo, filename), relativeTo }];
|
|
150
|
-
for (const { filename, relativeTo } of toTry) {
|
|
151
|
-
const found = path.isAbsolute(filename) && fs.existsSync(filename);
|
|
152
|
-
if (found)
|
|
153
|
-
return { filename, relativeTo: relativeTo?.toString(), found, method: 'tryResolveExists' };
|
|
154
|
-
}
|
|
155
|
-
filename = path.resolve(filename);
|
|
156
|
-
return {
|
|
157
|
-
filename,
|
|
158
|
-
relativeTo: path.resolve('.'),
|
|
159
|
-
found: fs.existsSync(filename),
|
|
160
|
-
method: 'tryResolveExists',
|
|
161
156
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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);
|
|
167
183
|
return {
|
|
168
|
-
filename
|
|
169
|
-
relativeTo,
|
|
170
|
-
found:
|
|
171
|
-
method: '
|
|
184
|
+
filename,
|
|
185
|
+
relativeTo: path.resolve('.'),
|
|
186
|
+
found: await this.doesExist(toFileUrl(filename)),
|
|
187
|
+
method: 'tryResolveExists',
|
|
172
188
|
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
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
|
+
}
|
|
220
|
+
}
|
|
176
221
|
return undefined;
|
|
177
|
-
}
|
|
222
|
+
};
|
|
178
223
|
}
|
|
179
|
-
function
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
224
|
+
export function patchFilename(filename, templateReplacements) {
|
|
225
|
+
const defaultReplacements = {
|
|
226
|
+
cwd: process.cwd(),
|
|
227
|
+
pathSeparator: path.sep,
|
|
228
|
+
userHome: os.homedir(),
|
|
229
|
+
};
|
|
230
|
+
filename = filename.replace(/^~(?=[/\\])/, defaultReplacements.userHome);
|
|
231
|
+
filename = replaceTemplate(filename, { ...defaultReplacements, ...templateReplacements });
|
|
232
|
+
return filename;
|
|
233
|
+
}
|
|
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);
|
|
194
250
|
}
|
|
195
251
|
function isRelative(filename) {
|
|
196
252
|
if (filename instanceof URL)
|
|
197
253
|
return false;
|
|
254
|
+
if (isURLLike(filename))
|
|
255
|
+
return false;
|
|
198
256
|
if (filename.startsWith('./'))
|
|
199
257
|
return true;
|
|
200
258
|
if (filename.startsWith('../'))
|
|
@@ -213,17 +271,17 @@ function joinWith(filename, relativeTo) {
|
|
|
213
271
|
function pathFromRelativeTo(relativeTo) {
|
|
214
272
|
return relativeTo instanceof URL || isURLLike(relativeTo) ? fileURLToPath(new URL('./', relativeTo)) : relativeTo;
|
|
215
273
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
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
|
+
}
|
|
229
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.1
|
|
3
|
+
"version": "8.2.1",
|
|
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.1
|
|
61
|
-
"@cspell/cspell-pipe": "8.1
|
|
62
|
-
"@cspell/cspell-resolver": "8.1
|
|
63
|
-
"@cspell/cspell-types": "8.1
|
|
64
|
-
"@cspell/dynamic-import": "8.1
|
|
65
|
-
"@cspell/strong-weak-map": "8.1
|
|
60
|
+
"@cspell/cspell-bundled-dicts": "8.2.1",
|
|
61
|
+
"@cspell/cspell-pipe": "8.2.1",
|
|
62
|
+
"@cspell/cspell-resolver": "8.2.1",
|
|
63
|
+
"@cspell/cspell-types": "8.2.1",
|
|
64
|
+
"@cspell/dynamic-import": "8.2.1",
|
|
65
|
+
"@cspell/strong-weak-map": "8.2.1",
|
|
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.1
|
|
70
|
-
"cspell-dictionary": "8.1
|
|
71
|
-
"cspell-glob": "8.1
|
|
72
|
-
"cspell-grammar": "8.1
|
|
73
|
-
"cspell-io": "8.1
|
|
74
|
-
"cspell-trie-lib": "8.1
|
|
69
|
+
"cspell-config-lib": "8.2.1",
|
|
70
|
+
"cspell-dictionary": "8.2.1",
|
|
71
|
+
"cspell-glob": "8.2.1",
|
|
72
|
+
"cspell-grammar": "8.2.1",
|
|
73
|
+
"cspell-io": "8.2.1",
|
|
74
|
+
"cspell-trie-lib": "8.2.1",
|
|
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": "b0c889ee4068aa8a2447106c5c7f449debc85bdd"
|
|
99
99
|
}
|
package/dist/esm/static.d.ts
DELETED