cspell-io 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/CSpellIO.d.ts +19 -12
- package/dist/esm/CSpellIONode.d.ts +4 -5
- package/dist/esm/CSpellIONode.js +9 -0
- package/dist/esm/CSpellIOWeb.d.ts +5 -4
- package/dist/esm/CSpellIOWeb.js +3 -0
- package/dist/esm/VirtualFS/redirectProvider.d.ts +30 -0
- package/dist/esm/VirtualFS/redirectProvider.js +147 -0
- package/dist/esm/VirtualFS.d.ts +107 -0
- package/dist/esm/VirtualFS.js +326 -0
- package/dist/esm/common/CFileReference.d.ts +1 -0
- package/dist/esm/common/CFileReference.js +3 -0
- package/dist/esm/common/CFileResource.d.ts +7 -4
- package/dist/esm/common/CFileResource.js +12 -1
- package/dist/esm/common/index.d.ts +3 -2
- package/dist/esm/common/index.js +3 -2
- package/dist/esm/common/urlOrReferenceToUrl.d.ts +5 -0
- package/dist/esm/common/urlOrReferenceToUrl.js +4 -0
- package/dist/esm/handlers/node/file.js +38 -1
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/models/FileResource.d.ts +2 -2
- package/dist/esm/models/Stats.d.ts +23 -0
- package/dist/esm/models/Stats.js +15 -4
- package/dist/esm/models/disposable.d.ts +4 -0
- package/dist/esm/models/disposable.js +2 -0
- package/dist/esm/models/index.d.ts +5 -1
- package/dist/esm/models/index.js +1 -1
- package/dist/esm/node/file/fetch.js +3 -0
- package/dist/esm/node/file/url.d.ts +2 -0
- package/dist/esm/node/file/url.js +20 -7
- package/dist/esm/requests/RequestFsReadDirectory.d.ts +9 -0
- package/dist/esm/requests/RequestFsReadDirectory.js +4 -0
- package/dist/esm/requests/RequestFsReadFile.d.ts +2 -2
- package/dist/esm/requests/RequestFsReadFileSync.d.ts +2 -2
- package/dist/esm/test/test.helper.d.ts +15 -3
- package/dist/esm/test/test.helper.js +36 -9
- package/package.json +4 -4
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { pathToFileURL } from 'url';
|
|
3
3
|
const isZippedRegExp = /\.gz($|[?#])/i;
|
|
4
|
-
const isURLRegExp = /^(\w{2,64}:\/\/|data:)/i;
|
|
4
|
+
const isURLRegExp = /^([\w-]{2,64}:\/\/|data:)/i;
|
|
5
|
+
const isWindowsPath = /^[a-z]:[\\/]/i;
|
|
5
6
|
const supportedProtocols = { 'file:': true, 'http:': true, 'https:': true };
|
|
6
7
|
export function isZipped(filename) {
|
|
7
8
|
const path = typeof filename === 'string' ? filename : filename.pathname;
|
|
@@ -30,7 +31,7 @@ export function toFileURL(filenameOrUrl, relativeTo) {
|
|
|
30
31
|
return isUrlLike(filenameOrUrl)
|
|
31
32
|
? new URL(filenameOrUrl)
|
|
32
33
|
: relativeTo && isUrlLike(relativeTo)
|
|
33
|
-
? new URL(
|
|
34
|
+
? new URL(normalizePathForUrl(filenameOrUrl), relativeTo)
|
|
34
35
|
: relativeTo
|
|
35
36
|
? pathToFileURL(path.resolve(relativeTo.toString(), filenameOrUrl))
|
|
36
37
|
: pathToFileURL(filenameOrUrl);
|
|
@@ -42,7 +43,7 @@ export function toFileURL(filenameOrUrl, relativeTo) {
|
|
|
42
43
|
* @returns a URL
|
|
43
44
|
*/
|
|
44
45
|
export function toURL(filenameOrUrl, relativeTo) {
|
|
45
|
-
return
|
|
46
|
+
return filenameOrUrl instanceof URL ? filenameOrUrl : new URL(filenameOrUrl, relativeTo);
|
|
46
47
|
}
|
|
47
48
|
const regMatchFilename = /filename=([^;,]*)/;
|
|
48
49
|
/**
|
|
@@ -67,15 +68,21 @@ export function urlBasename(url) {
|
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* Try to determine the parent directory URL of the uri.
|
|
71
|
+
* If it is not a hierarchical URL, then it will return the URL.
|
|
70
72
|
* @param url - url to extract the dirname from.
|
|
71
73
|
* @returns a URL
|
|
72
74
|
*/
|
|
73
75
|
export function urlDirname(url) {
|
|
74
76
|
url = toURL(url);
|
|
75
77
|
if (url.protocol === 'data:') {
|
|
76
|
-
return
|
|
78
|
+
return url;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return new URL(url.pathname.endsWith('/') ? '..' : '.', url);
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return url;
|
|
77
85
|
}
|
|
78
|
-
return new URL(url.pathname.endsWith('/') ? '..' : '.', url);
|
|
79
86
|
}
|
|
80
87
|
/**
|
|
81
88
|
* return the basename of a path, removing the trailing `/` if present.
|
|
@@ -87,7 +94,13 @@ export function basename(path) {
|
|
|
87
94
|
const idx = path.lastIndexOf('/');
|
|
88
95
|
return idx >= 0 ? path.slice(idx + 1) : path;
|
|
89
96
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
97
|
+
export function normalizePathForUrl(filePath) {
|
|
98
|
+
const pathname = filePath.replace(/\\/g, '/');
|
|
99
|
+
const raw = pathname.replace(isWindowsPath, '/$&');
|
|
100
|
+
return raw
|
|
101
|
+
.split('/')
|
|
102
|
+
.map(encodeURIComponent)
|
|
103
|
+
.join('/')
|
|
104
|
+
.replace(/^\/([a-z])%3A/i, '/$1:');
|
|
92
105
|
}
|
|
93
106
|
//# sourceMappingURL=url.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus';
|
|
2
|
+
import type { DirEntry } from '../models/Stats.js';
|
|
3
|
+
interface RequestParams {
|
|
4
|
+
readonly url: URL;
|
|
5
|
+
}
|
|
6
|
+
export declare const RequestFsReadDirectory: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readDir", RequestParams, Promise<DirEntry[]>>, RequestParams, "fs:readDir">;
|
|
7
|
+
export type RequestFsReadDirectory = ServiceRequestFactoryRequestType<typeof RequestFsReadDirectory>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=RequestFsReadDirectory.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus';
|
|
2
2
|
import type { BufferEncoding } from '../models/BufferEncoding.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TextFileResource } from '../models/FileResource.js';
|
|
4
4
|
interface RequestParams {
|
|
5
5
|
readonly url: URL;
|
|
6
6
|
readonly encoding?: BufferEncoding | undefined;
|
|
7
7
|
}
|
|
8
|
-
export declare const RequestFsReadFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<
|
|
8
|
+
export declare const RequestFsReadFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<TextFileResource>>, RequestParams, "fs:readFile">;
|
|
9
9
|
export type RequestFsReadFile = ServiceRequestFactoryRequestType<typeof RequestFsReadFile>;
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=RequestFsReadFile.d.ts.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus';
|
|
2
2
|
import type { BufferEncoding } from '../models/BufferEncoding.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TextFileResource } from '../models/FileResource.js';
|
|
4
4
|
interface RequestParams {
|
|
5
5
|
readonly url: URL;
|
|
6
6
|
readonly encoding?: BufferEncoding | undefined;
|
|
7
7
|
}
|
|
8
|
-
export declare const RequestFsReadFileTextSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams,
|
|
8
|
+
export declare const RequestFsReadFileTextSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, TextFileResource>, RequestParams, "fs:readFileSync">;
|
|
9
9
|
export type RequestFsReadFileTextSync = ServiceRequestFactoryRequestType<typeof RequestFsReadFileTextSync>;
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=RequestFsReadFileSync.d.ts.map
|
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
export declare function pathToSample(...parts: string[]): string;
|
|
2
|
+
export declare function pathToSampleURL(...parts: string[]): URL;
|
|
2
3
|
export declare function pathToRoot(...parts: string[]): string;
|
|
4
|
+
export declare function pathToRootURL(...parts: string[]): URL;
|
|
3
5
|
export declare function makePathToFile(file: string): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Make the directories to the url. If the url ends with a `/` then it is treated as a directory.
|
|
8
|
+
* @param url - a URL
|
|
9
|
+
* @returns void
|
|
10
|
+
*/
|
|
11
|
+
export declare function makePathToURL(url: URL): Promise<void>;
|
|
4
12
|
export declare function testNameToDir(testName: string): string;
|
|
5
13
|
/**
|
|
6
|
-
* Calculate a
|
|
14
|
+
* Calculate a filepath for a path to a temporary directory that will be unique to the current test.
|
|
7
15
|
* Note: if a text is not currently running, then it is the path for the test file.
|
|
8
|
-
* @param baseFilename - name of file / directory wanted
|
|
9
|
-
* @param testFilename - optional full path to a test file.
|
|
10
16
|
* @returns full path to the requested temp file.
|
|
11
17
|
*/
|
|
12
18
|
export declare function pathToTemp(...parts: string[]): string;
|
|
19
|
+
/**
|
|
20
|
+
* Calculate a URL for a path to a temporary directory that will be unique to the current test.
|
|
21
|
+
* Note: if a text is not currently running, then it is the path for the test file.
|
|
22
|
+
* @returns a URL to the requested temp file.
|
|
23
|
+
*/
|
|
24
|
+
export declare function pathToTempURL(...parts: string[]): URL;
|
|
13
25
|
//# sourceMappingURL=test.helper.d.ts.map
|
|
@@ -1,29 +1,48 @@
|
|
|
1
1
|
import { mkdir } from 'fs/promises';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
3
4
|
import { expect } from 'vitest';
|
|
4
5
|
const mkdirp = async (p) => {
|
|
5
6
|
await mkdir(p, { recursive: true });
|
|
6
7
|
};
|
|
7
|
-
const pathPackageRoot = path.join(__dirname, '
|
|
8
|
-
const pathSamples = path.join(pathPackageRoot, 'samples');
|
|
9
|
-
const pathTemp = path.join(pathPackageRoot, 'temp');
|
|
8
|
+
const pathPackageRoot = path.join(__dirname, '../../');
|
|
9
|
+
const pathSamples = path.join(pathPackageRoot, 'samples/');
|
|
10
|
+
const pathTemp = path.join(pathPackageRoot, 'temp/');
|
|
10
11
|
export function pathToSample(...parts) {
|
|
11
|
-
return
|
|
12
|
+
return resolve(pathSamples, ...parts);
|
|
13
|
+
}
|
|
14
|
+
export function pathToSampleURL(...parts) {
|
|
15
|
+
return pathToFileURL(pathToSample(...parts));
|
|
12
16
|
}
|
|
13
17
|
export function pathToRoot(...parts) {
|
|
14
|
-
return
|
|
18
|
+
return resolve(pathPackageRoot, ...parts);
|
|
19
|
+
}
|
|
20
|
+
export function pathToRootURL(...parts) {
|
|
21
|
+
return pathToFileURL(pathToRoot(...parts));
|
|
15
22
|
}
|
|
16
23
|
export function makePathToFile(file) {
|
|
17
24
|
return mkdirp(path.dirname(file));
|
|
18
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Make the directories to the url. If the url ends with a `/` then it is treated as a directory.
|
|
28
|
+
* @param url - a URL
|
|
29
|
+
* @returns void
|
|
30
|
+
*/
|
|
31
|
+
export function makePathToURL(url) {
|
|
32
|
+
const filePath = fileURLToPath(url);
|
|
33
|
+
return url.pathname.endsWith('/') ? mkdirp(filePath) : makePathToFile(filePath);
|
|
34
|
+
}
|
|
35
|
+
function resolve(...parts) {
|
|
36
|
+
const p = parts.join('/');
|
|
37
|
+
const suffix = /[/\\]$/.test(p) ? path.sep : '';
|
|
38
|
+
return path.normalize(path.resolve(...parts) + suffix);
|
|
39
|
+
}
|
|
19
40
|
export function testNameToDir(testName) {
|
|
20
41
|
return `test_${testName.replace(/\s/g, '-').replace(/[^\w.-]/gi, '_')}_test`;
|
|
21
42
|
}
|
|
22
43
|
/**
|
|
23
|
-
* Calculate a
|
|
44
|
+
* Calculate a filepath for a path to a temporary directory that will be unique to the current test.
|
|
24
45
|
* Note: if a text is not currently running, then it is the path for the test file.
|
|
25
|
-
* @param baseFilename - name of file / directory wanted
|
|
26
|
-
* @param testFilename - optional full path to a test file.
|
|
27
46
|
* @returns full path to the requested temp file.
|
|
28
47
|
*/
|
|
29
48
|
export function pathToTemp(...parts) {
|
|
@@ -33,6 +52,14 @@ export function pathToTemp(...parts) {
|
|
|
33
52
|
expect.getState();
|
|
34
53
|
const testName = testState.currentTestName || '.';
|
|
35
54
|
const testDirName = testNameToDir(testName);
|
|
36
|
-
return
|
|
55
|
+
return resolve(pathTemp, testFile, testDirName, ...parts);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Calculate a URL for a path to a temporary directory that will be unique to the current test.
|
|
59
|
+
* Note: if a text is not currently running, then it is the path for the test file.
|
|
60
|
+
* @returns a URL to the requested temp file.
|
|
61
|
+
*/
|
|
62
|
+
export function pathToTempURL(...parts) {
|
|
63
|
+
return pathToFileURL(pathToTemp(...parts));
|
|
37
64
|
}
|
|
38
65
|
//# sourceMappingURL=test.helper.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cspell-io",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "A library of useful I/O functions used across various cspell tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"lorem-ipsum": "^2.0.8",
|
|
51
|
-
"typescript": "^5.3.
|
|
51
|
+
"typescript": "^5.3.3"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@cspell/cspell-service-bus": "8.
|
|
54
|
+
"@cspell/cspell-service-bus": "8.2.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "3bcd6430bb33fb221d07030a60a2d61a2479e7ae"
|
|
57
57
|
}
|