jsconfig-paths-plugin.d.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { webpack } from 'next/dist/compiled/webpack/webpack';
  2. export interface Pattern {
  3. prefix: string;
  4. suffix: string;
  5. }
  6. export declare function hasZeroOrOneAsteriskCharacter(str: string): boolean;
  7. /**
  8. * Determines whether a path starts with a relative path component (i.e. `.` or `..`).
  9. */
  10. export declare function pathIsRelative(testPath: string): boolean;
  11. export declare function tryParsePattern(pattern: string): Pattern | undefined;
  12. /** Return the object corresponding to the best pattern to match `candidate`. */
  13. export declare function findBestPatternMatch<T>(values: readonly T[], getPattern: (value: T) => Pattern, candidate: string): T | undefined;
  14. /**
  15. * patternStrings contains both pattern strings (containing "*") and regular strings.
  16. * Return an exact match if possible, or a pattern match, or undefined.
  17. * (These are verified by verifyCompilerOptions to have 0 or 1 "*" characters.)
  18. */
  19. export declare function matchPatternOrExact(patternStrings: readonly string[], candidate: string): string | Pattern | undefined;
  20. /**
  21. * Tests whether a value is string
  22. */
  23. export declare function isString(text: unknown): text is string;
  24. /**
  25. * Given that candidate matches pattern, returns the text matching the '*'.
  26. * E.g.: matchedText(tryParsePattern("foo*baz"), "foobarbaz") === "bar"
  27. */
  28. export declare function matchedText(pattern: Pattern, candidate: string): string;
  29. export declare function patternText({ prefix, suffix }: Pattern): string;
  30. declare type Paths = {
  31. [match: string]: string[];
  32. };
  33. /**
  34. * Handles tsconfig.json or jsconfig.js "paths" option for webpack
  35. * Largely based on how the TypeScript compiler handles it:
  36. * https://github.com/microsoft/TypeScript/blob/1a9c8197fffe3dace5f8dca6633d450a88cba66d/src/compiler/moduleNameResolver.ts#L1362
  37. */
  38. export declare class JsConfigPathsPlugin implements webpack.ResolvePluginInstance {
  39. paths: Paths;
  40. resolvedBaseUrl: string;
  41. jsConfigPlugin: true;
  42. constructor(paths: Paths, resolvedBaseUrl: string);
  43. apply(resolver: any): void;
  44. }
  45. export {};