@file-services/typescript
Advanced tools
Comparing version 2.2.0 to 3.0.0
import ts from 'typescript'; | ||
import { IFileSystemSync, IFileSystemPath } from '@file-services/types'; | ||
import type { IFileSystemSync, IFileSystemPath } from '@file-services/types'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Combines all required functionality for parsing config files, |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLanguageServiceHost = exports.createBaseHost = void 0; | ||
const typescript_1 = __importDefault(require("typescript")); | ||
@@ -22,3 +23,3 @@ const UNIX_NEW_LINE = '\n'; | ||
function createBaseHost(fs) { | ||
const { caseSensitive, statSync, readFileSync, readdirSync, fileExistsSync, directoryExistsSync, cwd, realpathSync, join, dirname, normalize } = fs; | ||
const { caseSensitive, statSync, readFileSync, readdirSync, fileExistsSync, directoryExistsSync, cwd, realpathSync, join, dirname, normalize, } = fs; | ||
function getFileSystemEntries(path) { | ||
@@ -87,3 +88,3 @@ const files = []; | ||
normalize, | ||
join | ||
join, | ||
}; | ||
@@ -115,4 +116,4 @@ } | ||
getNewLine: () => typescript_1.default.getNewLineCharacter(getCompilationSettings(), getNewLine), | ||
getDefaultLibFileName: options => join(defaultLibsDirectory, typescript_1.default.getDefaultLibFileName(options)), | ||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames | ||
getDefaultLibFileName: (options) => join(defaultLibsDirectory, typescript_1.default.getDefaultLibFileName(options)), | ||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames, | ||
}; | ||
@@ -119,0 +120,0 @@ } |
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./create-host")); | ||
__exportStar(require("./create-host"), exports); | ||
//# sourceMappingURL=index.js.map |
import ts from 'typescript'; | ||
import { IFileSystemSync, IFileSystemPath } from '@file-services/types'; | ||
import type { IFileSystemSync, IFileSystemPath } from '@file-services/types'; | ||
/** | ||
@@ -4,0 +4,0 @@ * Combines all required functionality for parsing config files, |
@@ -16,3 +16,3 @@ import ts from 'typescript'; | ||
export function createBaseHost(fs) { | ||
const { caseSensitive, statSync, readFileSync, readdirSync, fileExistsSync, directoryExistsSync, cwd, realpathSync, join, dirname, normalize } = fs; | ||
const { caseSensitive, statSync, readFileSync, readdirSync, fileExistsSync, directoryExistsSync, cwd, realpathSync, join, dirname, normalize, } = fs; | ||
function getFileSystemEntries(path) { | ||
@@ -81,3 +81,3 @@ const files = []; | ||
normalize, | ||
join | ||
join, | ||
}; | ||
@@ -108,6 +108,6 @@ } | ||
getNewLine: () => ts.getNewLineCharacter(getCompilationSettings(), getNewLine), | ||
getDefaultLibFileName: options => join(defaultLibsDirectory, ts.getDefaultLibFileName(options)), | ||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames | ||
getDefaultLibFileName: (options) => join(defaultLibsDirectory, ts.getDefaultLibFileName(options)), | ||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames, | ||
}; | ||
} | ||
//# sourceMappingURL=create-host.js.map |
{ | ||
"name": "@file-services/typescript", | ||
"description": "Helpers for creation of TypeScript hosts", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"main": "cjs/index.js", | ||
@@ -17,3 +17,3 @@ "module": "esm/index.js", | ||
"dependencies": { | ||
"@file-services/types": "^2.2.0" | ||
"@file-services/types": "^3.0.0" | ||
}, | ||
@@ -20,0 +20,0 @@ "files": [ |
# @file-services/typescript | ||
[![npm version](https://img.shields.io/npm/v/@file-services/typescript.svg)](https://www.npmjs.com/package/@file-services/typescript) | ||
@@ -10,2 +11,3 @@ [![package size](https://badgen.net/bundlephobia/minzip/@file-services/typescript)](https://bundlephobia.com/result?p=@file-services/typescript) | ||
Install library in project: | ||
```sh | ||
@@ -29,3 +31,2 @@ yarn add @file-services/typescript | ||
/** | ||
@@ -44,8 +45,8 @@ * Create a TypeScript `LanguageServiceHost` using provided file system. | ||
export function createLanguageServiceHost( | ||
fs: IFileSystemSync, | ||
baseHost: IBaseHost, | ||
fileNames: string[], | ||
compilerOptions: ts.CompilerOptions, | ||
defaultLibsDirectory: string, | ||
customTransformers?: ts.CustomTransformers, | ||
fs: IFileSystemSync, | ||
baseHost: IBaseHost, | ||
fileNames: string[], | ||
compilerOptions: ts.CompilerOptions, | ||
defaultLibsDirectory: string, | ||
customTransformers?: ts.CustomTransformers | ||
): ts.LanguageServiceHost; | ||
@@ -52,0 +53,0 @@ ``` |
import ts from 'typescript'; | ||
import { IFileSystemSync, IFileSystemPath } from '@file-services/types'; | ||
import type { IFileSystemSync, IFileSystemPath } from '@file-services/types'; | ||
@@ -13,13 +13,13 @@ const UNIX_NEW_LINE = '\n'; | ||
export interface IBaseHost extends ts.ParseConfigHost, ts.FormatDiagnosticsHost, ts.ModuleResolutionHost { | ||
getCurrentDirectory: IFileSystemSync['cwd']; | ||
directoryExists: IFileSystemSync['directoryExistsSync']; | ||
getCurrentDirectory: IFileSystemSync['cwd']; | ||
directoryExists: IFileSystemSync['directoryExistsSync']; | ||
readDirectory: NonNullable<ts.LanguageServiceHost['readDirectory']>; | ||
getDirectories: NonNullable<ts.ModuleResolutionHost['getDirectories']>; | ||
readDirectory: NonNullable<ts.LanguageServiceHost['readDirectory']>; | ||
getDirectories: NonNullable<ts.ModuleResolutionHost['getDirectories']>; | ||
getScriptVersion: ts.LanguageServiceHost['getScriptVersion']; | ||
getScriptVersion: ts.LanguageServiceHost['getScriptVersion']; | ||
dirname: IFileSystemPath['dirname']; | ||
normalize: IFileSystemPath['normalize']; | ||
join: IFileSystemPath['join']; | ||
dirname: IFileSystemPath['dirname']; | ||
normalize: IFileSystemPath['normalize']; | ||
join: IFileSystemPath['join']; | ||
} | ||
@@ -37,90 +37,90 @@ | ||
export function createBaseHost(fs: IFileSystemSync): IBaseHost { | ||
const { | ||
caseSensitive, | ||
statSync, | ||
readFileSync, | ||
readdirSync, | ||
fileExistsSync, | ||
directoryExistsSync, | ||
cwd, | ||
realpathSync, | ||
join, | ||
dirname, | ||
normalize | ||
} = fs; | ||
const { | ||
caseSensitive, | ||
statSync, | ||
readFileSync, | ||
readdirSync, | ||
fileExistsSync, | ||
directoryExistsSync, | ||
cwd, | ||
realpathSync, | ||
join, | ||
dirname, | ||
normalize, | ||
} = fs; | ||
function getFileSystemEntries(path: string): { files: string[]; directories: string[] } { | ||
const files: string[] = []; | ||
const directories: string[] = []; | ||
function getFileSystemEntries(path: string): { files: string[]; directories: string[] } { | ||
const files: string[] = []; | ||
const directories: string[] = []; | ||
try { | ||
const dirEntries = readdirSync(path); | ||
for (const entryName of dirEntries) { | ||
const entryStats = statSync(join(path, entryName)); | ||
if (!entryStats) { | ||
continue; | ||
} | ||
if (entryStats.isFile()) { | ||
files.push(entryName); | ||
} else if (entryStats.isDirectory()) { | ||
directories.push(entryName); | ||
} | ||
} | ||
} catch { | ||
/* */ | ||
try { | ||
const dirEntries = readdirSync(path); | ||
for (const entryName of dirEntries) { | ||
const entryStats = statSync(join(path, entryName)); | ||
if (!entryStats) { | ||
continue; | ||
} | ||
return { files, directories }; | ||
if (entryStats.isFile()) { | ||
files.push(entryName); | ||
} else if (entryStats.isDirectory()) { | ||
directories.push(entryName); | ||
} | ||
} | ||
} catch { | ||
/* */ | ||
} | ||
function realpath(path: string): string { | ||
try { | ||
return realpathSync(path); | ||
} catch (e) { | ||
return path; | ||
} | ||
return { files, directories }; | ||
} | ||
function realpath(path: string): string { | ||
try { | ||
return realpathSync(path); | ||
} catch (e) { | ||
return path; | ||
} | ||
} | ||
return { | ||
readDirectory(rootDir, extensions, excludes, includes, depth) { | ||
return ts.matchFiles( | ||
rootDir, | ||
extensions, | ||
excludes, | ||
includes, | ||
caseSensitive, | ||
rootDir, | ||
depth, | ||
getFileSystemEntries, | ||
realpath | ||
); | ||
}, | ||
getDirectories(path) { | ||
return getFileSystemEntries(path).directories; | ||
}, | ||
fileExists: fileExistsSync, | ||
directoryExists: directoryExistsSync, | ||
readFile(filePath) { | ||
try { | ||
return readFileSync(filePath, 'utf8'); | ||
} catch { | ||
return undefined; | ||
} | ||
}, | ||
getScriptVersion(filePath) { | ||
try { | ||
return `${statSync(filePath).mtime.getTime()}`; | ||
} catch { | ||
return `${Date.now()}`; | ||
} | ||
}, | ||
useCaseSensitiveFileNames: caseSensitive, | ||
getCanonicalFileName: caseSensitive ? identity : toLowerCase, | ||
getCurrentDirectory: cwd, | ||
getNewLine: defaultGetNewLine, | ||
realpath, | ||
dirname, | ||
normalize, | ||
join | ||
}; | ||
return { | ||
readDirectory(rootDir, extensions, excludes, includes, depth) { | ||
return ts.matchFiles( | ||
rootDir, | ||
extensions, | ||
excludes, | ||
includes, | ||
caseSensitive, | ||
rootDir, | ||
depth, | ||
getFileSystemEntries, | ||
realpath | ||
); | ||
}, | ||
getDirectories(path) { | ||
return getFileSystemEntries(path).directories; | ||
}, | ||
fileExists: fileExistsSync, | ||
directoryExists: directoryExistsSync, | ||
readFile(filePath) { | ||
try { | ||
return readFileSync(filePath, 'utf8'); | ||
} catch { | ||
return undefined; | ||
} | ||
}, | ||
getScriptVersion(filePath) { | ||
try { | ||
return `${statSync(filePath).mtime.getTime()}`; | ||
} catch { | ||
return `${Date.now()}`; | ||
} | ||
}, | ||
useCaseSensitiveFileNames: caseSensitive, | ||
getCanonicalFileName: caseSensitive ? identity : toLowerCase, | ||
getCurrentDirectory: cwd, | ||
getNewLine: defaultGetNewLine, | ||
realpath, | ||
dirname, | ||
normalize, | ||
join, | ||
}; | ||
} | ||
@@ -140,23 +140,23 @@ | ||
export function createLanguageServiceHost( | ||
baseHost: IBaseHost, | ||
getScriptFileNames: () => string[], | ||
getCompilationSettings: () => ts.CompilerOptions, | ||
defaultLibsDirectory: string, | ||
getCustomTransformers?: () => ts.CustomTransformers | undefined | ||
baseHost: IBaseHost, | ||
getScriptFileNames: () => string[], | ||
getCompilationSettings: () => ts.CompilerOptions, | ||
defaultLibsDirectory: string, | ||
getCustomTransformers?: () => ts.CustomTransformers | undefined | ||
): ts.LanguageServiceHost { | ||
const { readFile, join, useCaseSensitiveFileNames, getNewLine } = baseHost; | ||
const { readFile, join, useCaseSensitiveFileNames, getNewLine } = baseHost; | ||
return { | ||
...baseHost, | ||
getCompilationSettings, | ||
getScriptFileNames, | ||
getCustomTransformers, | ||
getScriptSnapshot(filePath) { | ||
const fileContents = readFile(filePath); | ||
return fileContents !== undefined ? ts.ScriptSnapshot.fromString(fileContents) : undefined; | ||
}, | ||
getNewLine: () => ts.getNewLineCharacter(getCompilationSettings(), getNewLine), | ||
getDefaultLibFileName: options => join(defaultLibsDirectory, ts.getDefaultLibFileName(options)), | ||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames | ||
}; | ||
return { | ||
...baseHost, | ||
getCompilationSettings, | ||
getScriptFileNames, | ||
getCustomTransformers, | ||
getScriptSnapshot(filePath) { | ||
const fileContents = readFile(filePath); | ||
return fileContents !== undefined ? ts.ScriptSnapshot.fromString(fileContents) : undefined; | ||
}, | ||
getNewLine: () => ts.getNewLineCharacter(getCompilationSettings(), getNewLine), | ||
getDefaultLibFileName: (options) => join(defaultLibsDirectory, ts.getDefaultLibFileName(options)), | ||
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames, | ||
}; | ||
} |
import ts from 'typescript'; | ||
declare module 'typescript' { | ||
// needed for custom readDirectory | ||
export function matchFiles( | ||
path: string, | ||
extensions: ReadonlyArray<string> | undefined, | ||
excludes: ReadonlyArray<string> | undefined, | ||
includes: ReadonlyArray<string> | undefined, | ||
useCaseSensitiveFileNames: boolean, | ||
currentDirectory: string, | ||
depth: number | undefined, | ||
getFileSystemEntries: (path: string) => FileSystemEntries, | ||
realpath: (path: string) => string | ||
): string[]; | ||
// needed for custom readDirectory | ||
export function matchFiles( | ||
path: string, | ||
extensions: ReadonlyArray<string> | undefined, | ||
excludes: ReadonlyArray<string> | undefined, | ||
includes: ReadonlyArray<string> | undefined, | ||
useCaseSensitiveFileNames: boolean, | ||
currentDirectory: string, | ||
depth: number | undefined, | ||
getFileSystemEntries: (path: string) => FileSystemEntries, | ||
realpath: (path: string) => string | ||
): string[]; | ||
// used by matchFiles above | ||
export interface FileSystemEntries { | ||
readonly files: ReadonlyArray<string>; | ||
readonly directories: ReadonlyArray<string>; | ||
} | ||
// used by matchFiles above | ||
export interface FileSystemEntries { | ||
readonly files: ReadonlyArray<string>; | ||
readonly directories: ReadonlyArray<string>; | ||
} | ||
// needed to resolve newLine, while taking compilerOptions into consideration, for each `LanguageServiceHost` | ||
export function getNewLineCharacter( | ||
options: ts.CompilerOptions | ts.PrinterOptions, | ||
getNewLine?: () => string | ||
): string; | ||
// needed to resolve newLine, while taking compilerOptions into consideration, for each `LanguageServiceHost` | ||
export function getNewLineCharacter( | ||
options: ts.CompilerOptions | ts.PrinterOptions, | ||
getNewLine?: () => string | ||
): string; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
491
55
0
32875
+ Added@file-services/types@3.1.1(transitive)
- Removed@file-services/types@2.2.0(transitive)
Updated@file-services/types@^3.0.0