cspell-io
Advanced tools
Comparing version 8.1.3 to 8.2.0
@@ -34,2 +34,3 @@ import type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
export declare function isFileReference(ref: UrlOrReference): ref is FileReference; | ||
export declare function renameFileReference(ref: FileReference, newUrl: URL): FileReference; | ||
//# sourceMappingURL=CFileReference.d.ts.map |
@@ -54,2 +54,5 @@ import { toFileURL } from '../node/file/url.js'; | ||
} | ||
export function renameFileReference(ref, newUrl) { | ||
return new CFileReference(newUrl, ref.encoding, ref.baseFilename, ref.gz); | ||
} | ||
//# sourceMappingURL=CFileReference.js.map |
import type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
import type { FileReference, FileResource, FileResourceBase } from '../models/FileResource.js'; | ||
export declare class CFileResource implements FileResource { | ||
import type { FileReference, FileResource, TextFileResource } from '../models/FileResource.js'; | ||
export declare class CFileResource implements TextFileResource { | ||
readonly url: URL; | ||
@@ -21,6 +21,9 @@ readonly content: string | ArrayBufferView; | ||
static isCFileResource(obj: unknown): obj is CFileResource; | ||
static from(fileResource: FileResourceBase): CFileResource; | ||
static from(fileResource: FileResource): CFileResource; | ||
static from(fileReference: FileReference, content: string | ArrayBufferView): CFileResource; | ||
static from(url: URL, content: string | ArrayBufferView, encoding?: BufferEncoding, baseFilename?: string | undefined, gz?: boolean): CFileResource; | ||
static from(fileReference: FileReference | URL, content: string | ArrayBufferView): CFileResource; | ||
static from(url: URL, content: string | ArrayBufferView, encoding?: BufferEncoding | undefined, baseFilename?: string | undefined, gz?: boolean): CFileResource; | ||
} | ||
export declare function fromFileResource(fileResource: FileResource): TextFileResource; | ||
export declare function renameFileResource(fileResource: FileResource, url: URL): FileResource; | ||
//# sourceMappingURL=CFileResource.d.ts.map |
@@ -46,4 +46,9 @@ import { assert } from '../errors/assert.js'; | ||
static from(urlOrFileResource, content, encoding, baseFilename, gz) { | ||
if (CFileResource.isCFileResource(urlOrFileResource)) | ||
if (CFileResource.isCFileResource(urlOrFileResource)) { | ||
if (content) { | ||
const { url, encoding, baseFilename, gz } = urlOrFileResource; | ||
return new CFileResource(url, content, encoding, baseFilename, gz); | ||
} | ||
return urlOrFileResource; | ||
} | ||
if (urlOrFileResource instanceof URL) { | ||
@@ -62,2 +67,8 @@ assert(content !== undefined); | ||
} | ||
export function fromFileResource(fileResource) { | ||
return CFileResource.from(fileResource); | ||
} | ||
export function renameFileResource(fileResource, url) { | ||
return CFileResource.from(url, fileResource.content, fileResource.encoding, fileResource.baseFilename, fileResource.gz); | ||
} | ||
//# sourceMappingURL=CFileResource.js.map |
@@ -1,3 +0,4 @@ | ||
export { CFileReference } from './CFileReference.js'; | ||
export { CFileResource } from './CFileResource.js'; | ||
export { CFileReference, renameFileReference } from './CFileReference.js'; | ||
export { CFileResource, fromFileResource as createTextFileResource, renameFileResource } from './CFileResource.js'; | ||
export { urlOrReferenceToUrl } from './urlOrReferenceToUrl.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,3 +0,4 @@ | ||
export { CFileReference } from './CFileReference.js'; | ||
export { CFileResource } from './CFileResource.js'; | ||
export { CFileReference, renameFileReference } from './CFileReference.js'; | ||
export { CFileResource, fromFileResource as createTextFileResource, renameFileResource } from './CFileResource.js'; | ||
export { urlOrReferenceToUrl } from './urlOrReferenceToUrl.js'; | ||
//# sourceMappingURL=index.js.map |
import type { BufferEncoding } from './models/BufferEncoding.js'; | ||
import type { FileReference, FileResource, UrlOrFilename, UrlOrReference } from './models/FileResource.js'; | ||
import type { Stats } from './models/index.js'; | ||
import type { FileReference, TextFileResource, UrlOrFilename, UrlOrReference } from './models/FileResource.js'; | ||
import type { DirEntry, Stats } from './models/index.js'; | ||
export interface CSpellIO { | ||
/** | ||
* Read a file | ||
* @param uriOrFilename - uri of the file to read | ||
* @param urlOrFilename - uri of the file to read | ||
* @param encoding - optional encoding. | ||
* @returns A TextFileResource. | ||
*/ | ||
readFile(uriOrFilename: UrlOrReference, encoding?: BufferEncoding): Promise<FileResource>; | ||
readFile(urlOrFilename: UrlOrReference, encoding?: BufferEncoding): Promise<TextFileResource>; | ||
/** | ||
* Read a file in Sync mode. | ||
* Note: `http` requests will fail. | ||
* @param uriOrFilename - uri of the file to read | ||
* @param urlOrFilename - uri of the file to read | ||
* @param encoding - optional encoding. | ||
* @returns A TextFileResource. | ||
* @deprecated Use `readFile` instead. | ||
*/ | ||
readFileSync(uriOrFilename: UrlOrReference, encoding?: BufferEncoding): FileResource; | ||
readFileSync(urlOrFilename: UrlOrReference, encoding?: BufferEncoding): TextFileResource; | ||
/** | ||
* Write content to a file using utf-8 encoding. | ||
* It will fail to write to non-file uris. | ||
* @param uriOrFilename - uri | ||
* @param urlOrFilename - uri | ||
* @param content - string to write. | ||
*/ | ||
writeFile(uriOrFilename: UrlOrReference, content: string | ArrayBufferView): Promise<FileReference>; | ||
writeFile(urlOrFilename: UrlOrReference, content: string | ArrayBufferView): Promise<FileReference>; | ||
/** | ||
* Read a directory. | ||
* @param urlOrFilename - uri | ||
*/ | ||
readDirectory(urlOrFilename: string | URL): Promise<DirEntry[]>; | ||
/** | ||
* Get Stats on a uri. | ||
* @param uriOrFilename - uri to fetch stats on | ||
* @param urlOrFilename - uri to fetch stats on | ||
* @returns Stats if successful. | ||
*/ | ||
getStat(uriOrFilename: UrlOrReference): Promise<Stats>; | ||
getStat(urlOrFilename: UrlOrReference): Promise<Stats>; | ||
/** | ||
* Get Stats on a uri. | ||
* @param uriOrFilename - uri to fetch stats on | ||
* @param urlOrFilename - uri to fetch stats on | ||
* @returns Stats if successful, otherwise it throws an error. | ||
* @deprecated Use `getStat` instead. | ||
*/ | ||
getStatSync(uriOrFilename: UrlOrReference): Stats; | ||
getStatSync(urlOrFilename: UrlOrReference): Stats; | ||
/** | ||
@@ -40,0 +47,0 @@ * Compare two Stats. |
import { ServiceBus } from '@cspell/cspell-service-bus'; | ||
import type { CSpellIO } from './CSpellIO.js'; | ||
import type { BufferEncoding } from './models/BufferEncoding.js'; | ||
import type { FileReference, FileResource, UrlOrReference } from './models/FileResource.js'; | ||
import type { Stats } from './models/Stats.js'; | ||
import type { BufferEncoding, DirEntry, FileReference, Stats, TextFileResource, UrlOrReference } from './models/index.js'; | ||
export declare class CSpellIONode implements CSpellIO { | ||
readonly serviceBus: ServiceBus; | ||
constructor(serviceBus?: ServiceBus); | ||
readFile(urlOrFilename: UrlOrReference, encoding?: BufferEncoding): Promise<FileResource>; | ||
readFileSync(urlOrFilename: UrlOrReference, encoding?: BufferEncoding): FileResource; | ||
readFile(urlOrFilename: UrlOrReference, encoding?: BufferEncoding): Promise<TextFileResource>; | ||
readDirectory(urlOrFilename: string | URL): Promise<DirEntry[]>; | ||
readFileSync(urlOrFilename: UrlOrReference, encoding?: BufferEncoding): TextFileResource; | ||
writeFile(urlOrFilename: UrlOrReference, content: string | ArrayBufferView): Promise<FileReference>; | ||
@@ -12,0 +11,0 @@ getStat(urlOrFilename: UrlOrReference): Promise<Stats>; |
@@ -9,2 +9,3 @@ import { isServiceResponseSuccess, ServiceBus } from '@cspell/cspell-service-bus'; | ||
import { RequestFsReadFile, RequestFsReadFileSync, RequestFsStat, RequestFsStatSync, RequestFsWriteFile, } from './requests/index.js'; | ||
import { RequestFsReadDirectory } from './requests/RequestFsReadDirectory.js'; | ||
let defaultCSpellIONode = undefined; | ||
@@ -25,2 +26,10 @@ export class CSpellIONode { | ||
} | ||
readDirectory(urlOrFilename) { | ||
const ref = toFileReference(urlOrFilename); | ||
const res = this.serviceBus.dispatch(RequestFsReadDirectory.create(ref)); | ||
if (!isServiceResponseSuccess(res)) { | ||
throw genError(res.error, 'readDirectory'); | ||
} | ||
return res.value; | ||
} | ||
readFileSync(urlOrFilename, encoding) { | ||
@@ -27,0 +36,0 @@ const ref = toFileReference(urlOrFilename, encoding); |
import type { CSpellIO } from './CSpellIO.js'; | ||
import type { FileReference, FileResource, UrlOrFilename, UrlOrReference } from './models/FileResource.js'; | ||
import type { Stats } from './models/Stats.js'; | ||
import type { FileReference, TextFileResource, UrlOrFilename, UrlOrReference } from './models/FileResource.js'; | ||
import type { DirEntry, Stats } from './models/index.js'; | ||
export declare class CSpellIOWeb implements CSpellIO { | ||
readFile(_uriOrFilename: string | URL): Promise<FileResource>; | ||
readFileSync(_uriOrFilename: string | URL): FileResource; | ||
readFile(_uriOrFilename: string | URL): Promise<TextFileResource>; | ||
readFileSync(_uriOrFilename: string | URL): TextFileResource; | ||
readDirectory(_urlOrFilename: string | URL): Promise<DirEntry[]>; | ||
writeFile(_uriOrFilename: UrlOrReference, _content: string | ArrayBufferView): Promise<FileReference>; | ||
@@ -8,0 +9,0 @@ getStat(_uriOrFilename: string | URL): Promise<Stats>; |
@@ -10,2 +10,5 @@ import { compareStats } from './common/stat.js'; | ||
} | ||
readDirectory(_urlOrFilename) { | ||
throw new ErrorNotImplemented('readDirectory'); | ||
} | ||
writeFile(_uriOrFilename, _content) { | ||
@@ -12,0 +15,0 @@ throw new ErrorNotImplemented('writeFile'); |
@@ -11,2 +11,3 @@ import { createResponse, createResponseFail, isServiceResponseSuccess } from '@cspell/cspell-service-bus'; | ||
import { toError } from '../../errors/index.js'; | ||
import { FileType } from '../../models/index.js'; | ||
import { decodeDataUrl, guessMimeType, toDataUrl } from '../../node/dataUrl.js'; | ||
@@ -17,2 +18,3 @@ import { fetchURL } from '../../node/file/fetch.js'; | ||
import { RequestFsReadFile, RequestFsReadFileSync, RequestFsStat, RequestFsStatSync, RequestFsWriteFile, RequestZlibInflate, } from '../../requests/index.js'; | ||
import { RequestFsReadDirectory } from '../../requests/RequestFsReadDirectory.js'; | ||
const isGzFileRegExp = /\.gz($|[?#])/; | ||
@@ -40,2 +42,10 @@ function isGzFile(url) { | ||
/** | ||
* Handle Binary File Reads | ||
*/ | ||
const handleRequestFsReadDirectory = RequestFsReadDirectory.createRequestHandler(({ params }) => { | ||
return createResponse(fs | ||
.readdir(fileURLToPath(params.url), { withFileTypes: true }) | ||
.then((entries) => direntToDirEntries(params.url, entries))); | ||
}, undefined, 'Node: Read Directory.'); | ||
/** | ||
* Handle deflating gzip data | ||
@@ -80,3 +90,13 @@ */ | ||
*/ | ||
const handleRequestFsStat = RequestFsStat.createRequestHandler(({ params }) => createResponse(fs.stat(fileURLToPath(params.url))), undefined, 'Node: fs.stat.'); | ||
const handleRequestFsStat = RequestFsStat.createRequestHandler(({ params }) => createResponse(toPromiseStats(fs.stat(fileURLToPath(params.url)))), undefined, 'Node: fs.stat.'); | ||
function toStats(stat) { | ||
return { | ||
size: stat.size, | ||
mtimeMs: stat.mtimeMs, | ||
fileType: toFileType(stat), | ||
}; | ||
} | ||
function toPromiseStats(pStat) { | ||
return pStat.then(toStats); | ||
} | ||
/** | ||
@@ -165,2 +185,3 @@ * Handle fs:statSync | ||
handleRequestFsReadFileSyncData, | ||
handleRequestFsReadDirectory, | ||
handleRequestZlibInflate, | ||
@@ -181,2 +202,18 @@ handleRequestFsStatSync, | ||
} | ||
function mapperDirentToDirEntry(dir) { | ||
return (dirent) => direntToDirEntry(dir, dirent); | ||
} | ||
function direntToDirEntries(dir, dirent) { | ||
return dirent.map(mapperDirentToDirEntry(dir)); | ||
} | ||
function direntToDirEntry(dir, dirent) { | ||
return { | ||
name: dirent.name, | ||
dir, | ||
fileType: toFileType(dirent), | ||
}; | ||
} | ||
function toFileType(statLike) { | ||
return statLike.isFile() ? FileType.File : statLike.isDirectory() ? FileType.Directory : FileType.Unknown; | ||
} | ||
//# sourceMappingURL=file.js.map |
export { toArray as asyncIterableToArray } from './async/asyncIterable.js'; | ||
export * from './common/index.js'; | ||
export { createTextFileResource } from './common/index.js'; | ||
export type { CSpellIO } from './CSpellIO.js'; | ||
@@ -9,2 +10,6 @@ export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js'; | ||
export { encodeDataUrl, toDataUrl } from './node/dataUrl.js'; | ||
export { isFileURL, isUrlLike, toFileURL, toURL, urlBasename, urlDirname } from './node/file/url.js'; | ||
export type { VFileSystem as VFileSystem, VFileSystemProvider, VfsDirEntry, VfsStat, VirtualFS } from './VirtualFS.js'; | ||
export { createVirtualFS, FSCapabilityFlags, getDefaultVirtualFs } from './VirtualFS.js'; | ||
export { createRedirectProvider } from './VirtualFS/redirectProvider.js'; | ||
//# sourceMappingURL=index.d.ts.map |
export { toArray as asyncIterableToArray } from './async/asyncIterable.js'; | ||
export * from './common/index.js'; | ||
export { createTextFileResource } from './common/index.js'; | ||
export { CSpellIONode, getDefaultCSpellIO } from './CSpellIONode.js'; | ||
export { getStat, getStatSync, readFileText, readFileTextSync, writeToFile, writeToFileIterable, writeToFileIterableP, } from './file/index.js'; | ||
export { encodeDataUrl, toDataUrl } from './node/dataUrl.js'; | ||
export { isFileURL, isUrlLike, toFileURL, toURL, urlBasename, urlDirname } from './node/file/url.js'; | ||
export { createVirtualFS, FSCapabilityFlags, getDefaultVirtualFs } from './VirtualFS.js'; | ||
export { createRedirectProvider } from './VirtualFS/redirectProvider.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -23,3 +23,3 @@ import type { BufferEncoding } from './BufferEncoding.js'; | ||
} | ||
export interface FileResourceBase extends FileReference { | ||
export interface FileResource extends FileReference { | ||
/** | ||
@@ -30,3 +30,3 @@ * The contents of the file | ||
} | ||
export interface FileResource extends FileResourceBase { | ||
export interface TextFileResource extends FileResource { | ||
getText(): string; | ||
@@ -33,0 +33,0 @@ } |
@@ -1,2 +0,6 @@ | ||
export type { Stats } from './Stats.js'; | ||
export type { BufferEncoding, TextEncoding } from './BufferEncoding.js'; | ||
export type { Disposable } from './disposable.js'; | ||
export type { FileReference, FileResource, TextFileResource, UrlOrReference } from './FileResource.js'; | ||
export type { DirEntry, Stats } from './Stats.js'; | ||
export { FileType } from './Stats.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export {}; | ||
export { FileType } from './Stats.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -17,3 +17,26 @@ /** | ||
eTag?: string | undefined; | ||
/** | ||
* The file type. | ||
*/ | ||
fileType?: FileType | undefined; | ||
} | ||
export declare enum FileType { | ||
/** | ||
* The file type is unknown. | ||
*/ | ||
Unknown = 0, | ||
/** | ||
* A regular file. | ||
*/ | ||
File = 1, | ||
/** | ||
* A directory. | ||
*/ | ||
Directory = 2 | ||
} | ||
export interface DirEntry { | ||
name: string; | ||
dir: URL; | ||
fileType: FileType; | ||
} | ||
//# sourceMappingURL=Stats.d.ts.map |
@@ -1,5 +0,16 @@ | ||
/** | ||
* Subset of definition from the Node definition to avoid a dependency upon a specific version of Node | ||
*/ | ||
export {}; | ||
export var FileType; | ||
(function (FileType) { | ||
/** | ||
* The file type is unknown. | ||
*/ | ||
FileType[FileType["Unknown"] = 0] = "Unknown"; | ||
/** | ||
* A regular file. | ||
*/ | ||
FileType[FileType["File"] = 1] = "File"; | ||
/** | ||
* A directory. | ||
*/ | ||
FileType[FileType["Directory"] = 2] = "Directory"; | ||
})(FileType || (FileType = {})); | ||
//# sourceMappingURL=Stats.js.map |
@@ -7,2 +7,5 @@ import { _fetch as fetch } from './_fetch.js'; | ||
const r = await fetch(url, { method: 'HEAD' }); | ||
if (!r.ok) { | ||
throw FetchUrlError.create(url, r.status); | ||
} | ||
return r.headers; | ||
@@ -9,0 +12,0 @@ } |
@@ -29,2 +29,3 @@ export declare function isZipped(filename: string | URL): boolean; | ||
* Try to determine the parent directory URL of the uri. | ||
* If it is not a hierarchical URL, then it will return the URL. | ||
* @param url - url to extract the dirname from. | ||
@@ -40,2 +41,3 @@ * @returns a URL | ||
export declare function basename(path: string): string; | ||
export declare function normalizePathForUrl(filePath: string): string; | ||
//# sourceMappingURL=url.d.ts.map |
import path from 'path'; | ||
import { pathToFileURL } from 'url'; | ||
const isZippedRegExp = /\.gz($|[?#])/i; | ||
const isURLRegExp = /^(\w{2,64}:\/\/|data:)/i; | ||
const isURLRegExp = /^([\w-]{2,64}:\/\/|data:)/i; | ||
const isWindowsPath = /^[a-z]:[\\/]/i; | ||
const supportedProtocols = { 'file:': true, 'http:': true, 'https:': true }; | ||
@@ -33,3 +34,3 @@ export function isZipped(filename) { | ||
: relativeTo && isUrlLike(relativeTo) | ||
? new URL(normalizePath(filenameOrUrl), relativeTo) | ||
? new URL(normalizePathForUrl(filenameOrUrl), relativeTo) | ||
: relativeTo | ||
@@ -46,3 +47,3 @@ ? pathToFileURL(path.resolve(relativeTo.toString(), filenameOrUrl)) | ||
export function toURL(filenameOrUrl, relativeTo) { | ||
return typeof filenameOrUrl !== 'string' ? filenameOrUrl : new URL(filenameOrUrl, relativeTo); | ||
return filenameOrUrl instanceof URL ? filenameOrUrl : new URL(filenameOrUrl, relativeTo); | ||
} | ||
@@ -72,2 +73,3 @@ const regMatchFilename = /filename=([^;,]*)/; | ||
* Try to determine the parent directory URL of the uri. | ||
* If it is not a hierarchical URL, then it will return the URL. | ||
* @param url - url to extract the dirname from. | ||
@@ -79,5 +81,10 @@ * @returns a URL | ||
if (url.protocol === 'data:') { | ||
return new URL('data:'); | ||
return url; | ||
} | ||
return new URL(url.pathname.endsWith('/') ? '..' : '.', url); | ||
try { | ||
return new URL(url.pathname.endsWith('/') ? '..' : '.', url); | ||
} | ||
catch (e) { | ||
return url; | ||
} | ||
} | ||
@@ -94,5 +101,11 @@ /** | ||
} | ||
function normalizePath(filePath) { | ||
return filePath.split(path.sep).join('/'); | ||
export function normalizePathForUrl(filePath) { | ||
const pathname = filePath.replace(/\\/g, '/'); | ||
const raw = pathname.replace(isWindowsPath, '/$&'); | ||
return raw | ||
.split('/') | ||
.map(encodeURIComponent) | ||
.join('/') | ||
.replace(/^\/([a-z])%3A/i, '/$1:'); | ||
} | ||
//# sourceMappingURL=url.js.map |
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus'; | ||
import type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
import type { FileResource } from '../models/FileResource.js'; | ||
import type { TextFileResource } from '../models/FileResource.js'; | ||
interface RequestParams { | ||
@@ -8,5 +8,5 @@ readonly url: URL; | ||
} | ||
export declare const RequestFsReadFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<FileResource>>, RequestParams, "fs:readFile">; | ||
export declare const RequestFsReadFile: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFile", RequestParams, Promise<TextFileResource>>, RequestParams, "fs:readFile">; | ||
export type RequestFsReadFile = ServiceRequestFactoryRequestType<typeof RequestFsReadFile>; | ||
export {}; | ||
//# sourceMappingURL=RequestFsReadFile.d.ts.map |
import type { ServiceRequestFactoryRequestType } from '@cspell/cspell-service-bus'; | ||
import type { BufferEncoding } from '../models/BufferEncoding.js'; | ||
import type { FileResource } from '../models/FileResource.js'; | ||
import type { TextFileResource } from '../models/FileResource.js'; | ||
interface RequestParams { | ||
@@ -8,5 +8,5 @@ readonly url: URL; | ||
} | ||
export declare const RequestFsReadFileTextSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, FileResource>, RequestParams, "fs:readFileSync">; | ||
export declare const RequestFsReadFileTextSync: import("@cspell/cspell-service-bus").ServiceRequestFactory<import("@cspell/cspell-service-bus").ServiceRequest<"fs:readFileSync", RequestParams, TextFileResource>, RequestParams, "fs:readFileSync">; | ||
export type RequestFsReadFileTextSync = ServiceRequestFactoryRequestType<typeof RequestFsReadFileTextSync>; | ||
export {}; | ||
//# sourceMappingURL=RequestFsReadFileSync.d.ts.map |
export declare function pathToSample(...parts: string[]): string; | ||
export declare function pathToSampleURL(...parts: string[]): URL; | ||
export declare function pathToRoot(...parts: string[]): string; | ||
export declare function pathToRootURL(...parts: string[]): URL; | ||
export declare function makePathToFile(file: string): Promise<void>; | ||
/** | ||
* Make the directories to the url. If the url ends with a `/` then it is treated as a directory. | ||
* @param url - a URL | ||
* @returns void | ||
*/ | ||
export declare function makePathToURL(url: URL): Promise<void>; | ||
export declare function testNameToDir(testName: string): string; | ||
/** | ||
* Calculate a Uri for a path to a temporary directory that will be unique to the current test. | ||
* Calculate a filepath for a path to a temporary directory that will be unique to the current test. | ||
* Note: if a text is not currently running, then it is the path for the test file. | ||
* @param baseFilename - name of file / directory wanted | ||
* @param testFilename - optional full path to a test file. | ||
* @returns full path to the requested temp file. | ||
*/ | ||
export declare function pathToTemp(...parts: string[]): string; | ||
/** | ||
* Calculate a URL for a path to a temporary directory that will be unique to the current test. | ||
* Note: if a text is not currently running, then it is the path for the test file. | ||
* @returns a URL to the requested temp file. | ||
*/ | ||
export declare function pathToTempURL(...parts: string[]): URL; | ||
//# sourceMappingURL=test.helper.d.ts.map |
import { mkdir } from 'fs/promises'; | ||
import * as path from 'path'; | ||
import { fileURLToPath, pathToFileURL } from 'url'; | ||
import { expect } from 'vitest'; | ||
@@ -7,14 +8,34 @@ const mkdirp = async (p) => { | ||
}; | ||
const pathPackageRoot = path.join(__dirname, '../..'); | ||
const pathSamples = path.join(pathPackageRoot, 'samples'); | ||
const pathTemp = path.join(pathPackageRoot, 'temp'); | ||
const pathPackageRoot = path.join(__dirname, '../../'); | ||
const pathSamples = path.join(pathPackageRoot, 'samples/'); | ||
const pathTemp = path.join(pathPackageRoot, 'temp/'); | ||
export function pathToSample(...parts) { | ||
return path.resolve(pathSamples, ...parts); | ||
return resolve(pathSamples, ...parts); | ||
} | ||
export function pathToSampleURL(...parts) { | ||
return pathToFileURL(pathToSample(...parts)); | ||
} | ||
export function pathToRoot(...parts) { | ||
return path.resolve(pathPackageRoot, ...parts); | ||
return resolve(pathPackageRoot, ...parts); | ||
} | ||
export function pathToRootURL(...parts) { | ||
return pathToFileURL(pathToRoot(...parts)); | ||
} | ||
export function makePathToFile(file) { | ||
return mkdirp(path.dirname(file)); | ||
} | ||
/** | ||
* Make the directories to the url. If the url ends with a `/` then it is treated as a directory. | ||
* @param url - a URL | ||
* @returns void | ||
*/ | ||
export function makePathToURL(url) { | ||
const filePath = fileURLToPath(url); | ||
return url.pathname.endsWith('/') ? mkdirp(filePath) : makePathToFile(filePath); | ||
} | ||
function resolve(...parts) { | ||
const p = parts.join('/'); | ||
const suffix = /[/\\]$/.test(p) ? path.sep : ''; | ||
return path.normalize(path.resolve(...parts) + suffix); | ||
} | ||
export function testNameToDir(testName) { | ||
@@ -24,6 +45,4 @@ return `test_${testName.replace(/\s/g, '-').replace(/[^\w.-]/gi, '_')}_test`; | ||
/** | ||
* Calculate a Uri for a path to a temporary directory that will be unique to the current test. | ||
* Calculate a filepath for a path to a temporary directory that will be unique to the current test. | ||
* Note: if a text is not currently running, then it is the path for the test file. | ||
* @param baseFilename - name of file / directory wanted | ||
* @param testFilename - optional full path to a test file. | ||
* @returns full path to the requested temp file. | ||
@@ -38,4 +57,12 @@ */ | ||
const testDirName = testNameToDir(testName); | ||
return path.resolve(pathTemp, testFile, testDirName, ...parts); | ||
return resolve(pathTemp, testFile, testDirName, ...parts); | ||
} | ||
/** | ||
* Calculate a URL for a path to a temporary directory that will be unique to the current test. | ||
* Note: if a text is not currently running, then it is the path for the test file. | ||
* @returns a URL to the requested temp file. | ||
*/ | ||
export function pathToTempURL(...parts) { | ||
return pathToFileURL(pathToTemp(...parts)); | ||
} | ||
//# sourceMappingURL=test.helper.js.map |
{ | ||
"name": "cspell-io", | ||
"version": "8.1.3", | ||
"version": "8.2.0", | ||
"description": "A library of useful I/O functions used across various cspell tools.", | ||
@@ -51,8 +51,8 @@ "type": "module", | ||
"lorem-ipsum": "^2.0.8", | ||
"typescript": "^5.3.2" | ||
"typescript": "^5.3.3" | ||
}, | ||
"dependencies": { | ||
"@cspell/cspell-service-bus": "8.1.3" | ||
"@cspell/cspell-service-bus": "8.2.0" | ||
}, | ||
"gitHead": "ea4335117b7c0e7b9ec22738315c82fae24ea997" | ||
"gitHead": "3bcd6430bb33fb221d07030a60a2d61a2479e7ae" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102869
91
2450
+ Added@cspell/cspell-service-bus@8.2.0(transitive)
- Removed@cspell/cspell-service-bus@8.1.3(transitive)