Access information about supported transpilers and file extensions, with runtime availability checking.
Get information about supported transpilers and their current availability.
/**
* Returns an array of supported transpilers with availability information
* @returns Array of transpiler information including version and availability
*/
function getAvailableTranspilers(): IAvailableTranspiler[];
interface IAvailableTranspiler {
/** Name of the transpiler (e.g., "typescript", "babel") */
name: string;
/** Supported version range (semver) */
version: string;
/** Whether transpiler is available in current environment */
available: boolean;
/** Current version installed (if available) */
currentVersion: string;
}Usage Examples:
import { getAvailableTranspilers } from "dependency-cruiser";
// Check all available transpilers
const transpilers = getAvailableTranspilers();
transpilers.forEach(transpiler => {
console.log(`${transpiler.name}: ${transpiler.available ? 'available' : 'not available'}`);
if (transpiler.available) {
console.log(` Version: ${transpiler.currentVersion} (supports ${transpiler.version})`);
}
});
// Check if specific transpiler is available
const typescript = transpilers.find(t => t.name === "typescript");
if (typescript?.available) {
console.log("TypeScript analysis available");
}
// Filter only available transpilers
const availableTranspilers = transpilers.filter(t => t.available);
console.log(`${availableTranspilers.length} transpilers available`);Get information about all supported file extensions and their availability.
/**
* All supported file extensions with availability status
*/
const allExtensions: IAvailableExtension[];
interface IAvailableExtension {
/** File extension (e.g., ".js", ".ts", ".vue") */
extension: string;
/** Whether extension is supported in current environment */
available: boolean;
}Usage Examples:
import { allExtensions } from "dependency-cruiser";
// List all supported extensions
console.log("Supported extensions:");
allExtensions.forEach(ext => {
const status = ext.available ? "✓" : "✗";
console.log(` ${status} ${ext.extension}`);
});
// Get only available extensions
const availableExts = allExtensions
.filter(ext => ext.available)
.map(ext => ext.extension);
console.log("Available:", availableExts.join(", "));
// Check if specific extension is supported
const typescriptSupported = allExtensions.find(
ext => ext.extension === ".ts"
)?.available;
if (typescriptSupported) {
console.log("TypeScript files can be analyzed");
}Detailed information about each supported transpiler and language.
JavaScript (Always Available):
.js, .cjs, .mjs, .jsxTypeScript:
.ts, .tsx, .d.ts, .cts, .mts, .d.cts, .d.mtstypescript (>=2.0.0 <6.0.0)tsconfig.jsonBabel:
.js, .jsx, .ts, .tsx)@babel/core (>=7.0.0 <8.0.0).babelrc, babel.config.js, or package.jsonCoffeeScript:
.coffee, .litcoffee, .coffee.md, .csx, .cjsxcoffeescript (>=1.0.0 <3.0.0) or coffee-script (>=1.0.0 <2.0.0)SWC (Fast Compiler):
.js, .cjs, .mjs, .jsx, .ts, .tsx, .d.ts@swc/core (>=1.0.0 <2.0.0)Svelte:
.sveltesvelte/compiler (>=3.0.0 <6.0.0)Vue.js:
.vuevue-template-compiler (>=2.0.0 <3.0.0) for Vue 2@vue/compiler-sfc (>=3.0.0 <4.0.0) for Vue 3LiveScript:
.lslivescript (>=1.0.0 <2.0.0)Determine transpiler availability and configuration in the current environment.
Check Environment Setup:
import { getAvailableTranspilers, allExtensions } from "dependency-cruiser";
function analyzeEnvironment() {
const transpilers = getAvailableTranspilers();
const extensions = allExtensions;
console.log("Environment Analysis:");
console.log("===================");
// Language support summary
const jsSupport = extensions.filter(e =>
[".js", ".cjs", ".mjs", ".jsx"].includes(e.extension)
).every(e => e.available);
const tsSupport = transpilers.find(t => t.name === "typescript")?.available;
const babelSupport = transpilers.find(t => t.name === "babel")?.available;
console.log(`JavaScript: ${jsSupport ? "✓" : "✗"}`);
console.log(`TypeScript: ${tsSupport ? "✓" : "✗"}`);
console.log(`Babel: ${babelSupport ? "✓" : "✗"}`);
// Recommended setup
if (!tsSupport && !babelSupport) {
console.log("\nRecommendation: Install typescript or @babel/core for enhanced analysis");
}
return {
javascript: jsSupport,
typescript: tsSupport,
babel: babelSupport,
availableExtensions: extensions.filter(e => e.available).map(e => e.extension)
};
}Understanding which transpiler is used for each file extension.
// Internal mapping (informational)
const extensionMappings = {
// JavaScript (always available)
".js": "javascript",
".cjs": "javascript",
".mjs": "javascript",
".jsx": "javascript",
// TypeScript (requires typescript package)
".ts": "typescript",
".tsx": "typescript",
".d.ts": "typescript",
".cts": "typescript",
".mts": "typescript",
".d.cts": "typescript",
".d.mts": "typescript",
// Vue (requires vue compiler)
".vue": "vue-template-compiler or @vue/compiler-sfc",
// Svelte (requires svelte)
".svelte": "svelte",
// CoffeeScript (requires coffeescript)
".coffee": "coffeescript",
".litcoffee": "coffeescript",
".coffee.md": "coffeescript",
".csx": "coffeescript",
".cjsx": "coffeescript",
// LiveScript (requires livescript)
".ls": "livescript"
};Control which parser is used for analysis (advanced usage).
type ParserType = "acorn" | "tsc" | "swc";
interface ICruiseOptions {
/** Override parser selection (experimental) */
parser?: ParserType;
}Parser Characteristics:
Usage:
import { cruise } from "dependency-cruiser";
// Force SWC parser for performance
const result = await cruise(
["src"],
{
parser: "swc",
// SWC must be available for this to work
}
);
// Force TypeScript parser for detailed analysis
const result = await cruise(
["src"],
{
parser: "tsc",
tsPreCompilationDeps: true
}
);Integrate transpiler configurations with dependency analysis.
TypeScript Integration:
import { cruise } from "dependency-cruiser";
const result = await cruise(
["src"],
{
tsPreCompilationDeps: true,
detectJSDocImports: true // Implies parser: "tsc"
},
{ extensions: [".ts", ".tsx", ".js"] },
{
tsConfig: {
fileName: "./tsconfig.json",
compilerOptions: {
paths: {
"@/*": ["./src/*"]
}
}
}
}
);Babel Integration:
import extractBabelConfig from "dependency-cruiser/config-utl/extract-babel-config";
const babelConfig = await extractBabelConfig("./.babelrc.js");
const result = await cruise(
["src"],
{ moduleSystems: ["es6", "cjs"] },
{},
{ babelConfig }
);Choose appropriate transpilers and configurations for optimal performance.
Performance Tips:
acorn for pure JavaScript, tsc only when TypeScript features neededextensions in resolve options to only necessary typesOptimized Setup:
import { getAvailableTranspilers } from "dependency-cruiser";
const transpilers = getAvailableTranspilers();
const hasSWC = transpilers.find(t => t.name === "swc")?.available;
const hasTypeScript = transpilers.find(t => t.name === "typescript")?.available;
const optimizedConfig = {
// Use fast parser if available
parser: hasSWC ? "swc" : "acorn",
// Only enable TypeScript features if needed
tsPreCompilationDeps: hasTypeScript && needsTypeScriptAnalysis,
// Cache expensive transpiler operations
cache: {
folder: "node_modules/.cache/dependency-cruiser",
strategy: "content" // More thorough for transpiled content
}
};Common issues and solutions when working with transpilers.
Missing Transpiler:
import { getAvailableTranspilers } from "dependency-cruiser";
const transpilers = getAvailableTranspilers();
const missing = transpilers.filter(t => !t.available);
if (missing.length > 0) {
console.log("Missing transpilers:");
missing.forEach(t => {
console.log(` ${t.name}: npm install ${t.name}@"${t.version}"`);
});
}Version Compatibility:
const typescript = transpilers.find(t => t.name === "typescript");
if (typescript && typescript.available) {
console.log(`TypeScript ${typescript.currentVersion} found`);
console.log(`Supports versions: ${typescript.version}`);
// Check if version might cause issues
const currentMajor = parseInt(typescript.currentVersion.split('.')[0]);
if (currentMajor >= 5) {
console.log("Note: TypeScript 5+ may have compatibility considerations");
}
}