Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createInstance (loader: WebPackLoader, options: Options): LoaderInstance {
const context = loader.context
const rootFile = loader.resourcePath
const files: FilesMap = {}
const ignoreWarnings = arrify(options.ignoreWarnings).map(Number)
// Allow custom TypeScript compilers to be used.
const TS: typeof ts = require(options.compiler || 'typescript')
// Allow `configFile` option to override `tsconfig.json` lookup.
const configFile = options.configFile ?
resolve(context, options.configFile) :
tsconfig.resolveSync(context)
const config = readConfig(configFile, loader, TS)
// Emit configuration errors.
config.errors.forEach((error: ts.Diagnostic) => {
loader.emitError(formatDiagnostic(error, TS))
})
const serviceHost: ts.LanguageServiceHost = {
getScriptFileNames (): string[] {
// Return an array of all file names. We can't return just the default
// files because webpack may have traversed through a regular JS file
// back to a TypeScript file and if we don't have that file in the array,
// TypeScript will give us a file not found compilation error.
return config.fileNames.concat(Object.keys(files))
},
init: function(options) {
var project = options['project']
compiler.log = options.log
compiler.tsConfigPath =
resolveSync(cwd, typeof project === 'string' ? project : undefined) || ''
var originalJsHandler = require.extensions['.js']
require.extensions['.ts'] = empty
require.extensions['.tsx'] = empty
tmpDir = options['cache-directory']
? path.resolve(options['cache-directory'])
: fs.mkdtempSync(path.join(os.tmpdir(), '.ts-node'))
var compilerOptionsArg =
options['compilerOptions'] || options['compiler-options']
var compilerOptions
if (compilerOptionsArg) {
try {
compilerOptions = JSON.parse(compilerOptionsArg)
} catch (e) {
console.log(
'Could not parse compilerOptions',
function isModuleRoot(dir: string) {
if (fs.existsSync(path.join(dir, pkgFileName))) {
return !!tsconfig.resolveSync(dir);
}
return false;
}
function getProjectSync(pathOrSrcFile) {
if (!fs.existsSync(pathOrSrcFile)) {
throw new Error(exports.errors.GET_PROJECT_INVALID_PATH);
}
var dir = fs.lstatSync(pathOrSrcFile).isDirectory() ? pathOrSrcFile : path.dirname(pathOrSrcFile);
var projectFile = tsconfig.resolveSync(dir);
if (!projectFile) {
throw errorWithDetails(new Error(exports.errors.GET_PROJECT_NO_PROJECT_FOUND), { projectFilePath: fsu.consistentPath(pathOrSrcFile), errorMessage: 'not found' });
}
var projectFileDirectory = path.dirname(projectFile) + path.sep;
var projectSpec;
var projectFileTextContent;
try {
projectFileTextContent = fs.readFileSync(projectFile, 'utf8');
}
catch (ex) {
throw new Error(exports.errors.GET_PROJECT_FAILED_TO_OPEN_PROJECT_FILE);
}
try {
projectSpec = tsconfig.parseFileSync(projectFileTextContent, projectFile, { resolvePaths: false });
}
catch (ex) {
export function handler(argv: GenerateCommand) {
let manifest = resolveManifestSync()
let tsconfigPath = tsconfig.resolveSync(argv.sourceDir)
if (!tsconfigPath) {
throw new Error('Cannot resolve tsconfig.json in sourceDir')
}
let { files, compilerOptions } = tsconfig.loadSync(tsconfigPath)
let tsCompilerOptions = helpers.rawToTsCompilerOptions(compilerOptions, process.cwd(), ts)
let ctx = helpers.generateFiles(files, manifest.package, tsCompilerOptions)
ctx.generateForeignModules(argv.deepForeign)
let writer = new DocWriter(ctx)
writer.ensureDir(argv.docDir)
writer
.writeModules(path.join(argv.docDir, 'generated'), !argv.withoutSearch)