How to use the @ts-tools/transpile.ensureDirectorySync function in @ts-tools/transpile

To help you get started, we’ve selected a few @ts-tools/transpile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AviVahl / ts-tools / packages / node / src / node-extension.ts View on Github external
if (autoScriptTarget) {
        const [nodeMajor] = process.versions.node.split('.'); // '12.0.0' => '12'
        compilerOptions.target = nodeVersionToScriptTarget(Number(nodeMajor));
    }

    if (typeof cacheDirectoryPath !== 'string') {
        // couldn't find a cache directory, so fall back to a non-caching implementation
        return createTransformerExtension(
            filePath =>
                ts.transpileModule(readFileSync(filePath, 'utf8'), { fileName: filePath, compilerOptions }).outputText
        );
    }

    const optionsScopedCachePath = join(cacheDirectoryPath, compilerOptionsToCacheName(compilerOptions));
    try {
        ensureDirectorySync(optionsScopedCachePath);
    } catch {
        /**/
    }

    if (installSourceMapSupport) {
        sourceMapSupport.install({
            environment: 'node',
            retrieveSourceMap(filePath) {
                const cacheFilePath = join(optionsScopedCachePath, filePathToCacheFileName(filePath));
                const cachedOutput = readCacheFileSync(cacheFilePath);
                if (cachedOutput && cachedOutput.mtime === statSync(filePath).mtime.getTime()) {
                    const { sourceMapText, outputText } = cachedOutput;
                    const map = sourceMapText || extractInlineSourceMap(outputText);
                    if (map) {
                        return { map, url: filePath };
                    }
github AviVahl / ts-tools / packages / webpack-loader / src / typescript-loader.ts View on Github external
// force declarations off, as we don't have .d.ts bundling.
    // output locations are irrelevant, as we bundle. this ensures source maps have proper relative paths.
    // noEmit will not give us any output, so force that off.
    compilerOptions.declaration = compilerOptions.declarationMap = undefined;
    compilerOptions.outDir = compilerOptions.out = compilerOptions.outFile = undefined;
    compilerOptions.noEmit = compilerOptions.noEmitOnError = compilerOptions.emitDeclarationOnly = undefined;

    // caching
    const optionsScopedCachePath = cacheDirectoryPath
        ? join(cacheDirectoryPath, compilerOptionsToCacheName(compilerOptions))
        : undefined;

    if (optionsScopedCachePath && !ensuredDirectories.has(optionsScopedCachePath)) {
        try {
            ensureDirectorySync(optionsScopedCachePath);
        } catch {
            /**/
        }
        ensuredDirectories.add(optionsScopedCachePath);
    }

    const transpileOptions = {
        fileName: resourcePath,
        compilerOptions,
        transformers,
        reportDiagnostics: true
    };

    // transpile
    const { sourceMapText, outputText, diagnostics } = optionsScopedCachePath
        ? transpileCached({