UNPKG

@ts-bridge/cli

Version:

Bridge the gap between ES modules and CommonJS modules with an easy-to-use alternative to `tsc`.

131 lines 5 kB
import type { FileSystemInterface, FileFormat } from '@ts-bridge/resolver'; import type { System } from 'typescript'; /** * Check if a specifier is relative. * * @param specifier - The specifier to check. * @returns Whether the specifier is relative. */ export declare function isRelative(specifier: string): boolean; export type ResolvedModule = { /** * The specifier for the module. */ specifier: string; /** * The path to the module. */ path: string; /** * The type of the module. */ format: FileFormat | null; }; /** * Resolve a package specifier to a file in a package. This function will try to * resolve the package specifier to a file in the package's directory. * * @param packageSpecifier - The specifier for the package. * @param parentUrl - The URL of the parent module. * @param system - The TypeScript system. * @param extensions - The extensions to use for resolving the package. * @returns The resolved package specifier, or `null` if the package could not * be resolved. */ export declare function resolvePackageSpecifier(packageSpecifier: string, parentUrl: string, system: System, extensions?: string[]): ResolvedModule | null; /** * Resolve a relative package specifier to a file in the package. This function * will try to resolve the package specifier to a file in the package's * directory. * * @param packageSpecifier - The specifier for the package. * @param parentUrl - The URL of the parent module. * @param system - The TypeScript system. * @param extensions - The extensions to use for resolving the package. * @returns The resolved package specifier, or `null` if the package could not * be resolved. */ export declare function resolveRelativePackageSpecifier(packageSpecifier: string, parentUrl: string, system: System, extensions?: string[]): ResolvedModule | null; export type GetModulePathOptions = { /** * The specifier for the module. */ packageSpecifier: string; /** * The extension to use for relative source paths. */ extension: string; /** * The URL of the parent module. */ parentUrl: string; /** * The TypeScript system. */ system: System; /** * Whether to show verbose output. */ verbose?: boolean; }; /** * Replace the extension of a path. * * @param path - The path to replace the extension of. * @param extension - The new extension. * @returns The path with the new extension. */ export declare function replaceExtension(path: string, extension: string): string; /** * Get the path to a module. * * @param options - The options for resolving the module. * @param options.packageSpecifier - The specifier for the module. * @param options.extension - The extension to use for relative source paths. * @param options.parentUrl - The URL of the parent module. * @param options.system - The TypeScript system. * @param options.verbose - Whether to show verbose output. * @returns The path to the module, or the original specifier if the module * could not be resolved. */ export declare function getModulePath({ packageSpecifier, extension, parentUrl, system, verbose, }: GetModulePathOptions): string; /** * Get a {@link FileSystemInterface} from a TypeScript system. This is used * for module resolution. * * @param system - The TypeScript system. * @returns The file system interface. */ export declare function getFileSystemFromTypeScript(system: System): FileSystemInterface; /** * Get the module type for a given package specifier. * * @param packageSpecifier - The specifier for the package. * @param system - The TypeScript system. * @param parentUrl - The URL of the parent module. * @returns The module type for the package. */ export declare function getModuleType(packageSpecifier: string, system: System, parentUrl: string): FileFormat | null; /** * Check if a package specifier is a CommonJS package. * * @param packageSpecifier - The specifier for the package. * @param system - The TypeScript system. * @param parentUrl - The URL of the parent module. * @returns Whether the package is a CommonJS package. */ export declare function isCommonJs(packageSpecifier: string, system: System, parentUrl: string): boolean; /** * Get the exports for a CommonJS package. This uses `cjs-module-lexer` to parse * the CommonJS module and extract the exports, which matches the behaviour of * Node.js. This function will return an empty array if the package is not a * CommonJS package, or if the package could not be resolved. * * @param packageSpecifier - The specifier for the package. * @param system - The TypeScript system. * @param parentUrl - The URL of the parent module. * @returns The exports for the CommonJS package. * @throws If the package could not be parsed. */ export declare function getCommonJsExports(packageSpecifier: string, system: System, parentUrl: string): Set<string>; //# sourceMappingURL=module-resolver.d.ts.map