index.d.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import { Stats } from "fs";
  2. interface IMinimatchOptions {
  3. /**
  4. * Dump a ton of stuff to stderr.
  5. *
  6. * @default false
  7. */
  8. debug?: boolean | undefined;
  9. /**
  10. * Do not expand `{a,b}` and `{1..3}` brace sets.
  11. *
  12. * @default false
  13. */
  14. nobrace?: boolean | undefined;
  15. /**
  16. * Disable `**` matching against multiple folder names.
  17. *
  18. * @default false
  19. */
  20. noglobstar?: boolean | undefined;
  21. /**
  22. * Allow patterns to match filenames starting with a period,
  23. * even if the pattern does not explicitly have a period in that spot.
  24. *
  25. * Note that by default, `'a/**' + '/b'` will **not** match `a/.d/b`, unless `dot` is set.
  26. *
  27. * @default false
  28. */
  29. dot?: boolean | undefined;
  30. /**
  31. * Disable "extglob" style patterns like `+(a|b)`.
  32. *
  33. * @default false
  34. */
  35. noext?: boolean | undefined;
  36. /**
  37. * Perform a case-insensitive match.
  38. *
  39. * @default false
  40. */
  41. nocase?: boolean | undefined;
  42. /**
  43. * When a match is not found by `minimatch.match`,
  44. * return a list containing the pattern itself if this option is set.
  45. * Otherwise, an empty list is returned if there are no matches.
  46. *
  47. * @default false
  48. */
  49. nonull?: boolean | undefined;
  50. /**
  51. * If set, then patterns without slashes will be matched
  52. * against the basename of the path if it contains slashes. For example,
  53. * `a?b` would match the path `/xyz/123/acb`, but not `/xyz/acb/123`.
  54. *
  55. * @default false
  56. */
  57. matchBase?: boolean | undefined;
  58. /**
  59. * Suppress the behavior of treating `#` at the start of a pattern as a comment.
  60. *
  61. * @default false
  62. */
  63. nocomment?: boolean | undefined;
  64. /**
  65. * Suppress the behavior of treating a leading `!` character as negation.
  66. *
  67. * @default false
  68. */
  69. nonegate?: boolean | undefined;
  70. /**
  71. * Returns from negate expressions the same as if they were not negated.
  72. * (Ie, true on a hit, false on a miss.)
  73. *
  74. * @default false
  75. */
  76. flipNegate?: boolean | undefined;
  77. /**
  78. * Compare a partial path to a pattern. As long as the parts of the path that
  79. * are present are not contradicted by the pattern, it will be treated as a
  80. * match. This is useful in applications where you're walking through a
  81. * folder structure, and don't yet have the full path, but want to ensure that
  82. * you do not walk down paths that can never be a match.
  83. *
  84. * @default false
  85. *
  86. * @example
  87. * import minimatch = require("minimatch");
  88. *
  89. * minimatch('/a/b', '/a/*' + '/c/d', { partial: true }) // true, might be /a/b/c/d
  90. * minimatch('/a/b', '/**' + '/d', { partial: true }) // true, might be /a/b/.../d
  91. * minimatch('/x/y/z', '/a/**' + '/z', { partial: true }) // false, because x !== a
  92. */
  93. partial?: boolean;
  94. /**
  95. * Use `\\` as a path separator _only_, and _never_ as an escape
  96. * character. If set, all `\\` characters are replaced with `/` in
  97. * the pattern. Note that this makes it **impossible** to match
  98. * against paths containing literal glob pattern characters, but
  99. * allows matching with patterns constructed using `path.join()` and
  100. * `path.resolve()` on Windows platforms, mimicking the (buggy!)
  101. * behavior of earlier versions on Windows. Please use with
  102. * caution, and be mindful of the caveat about Windows paths
  103. *
  104. * For legacy reasons, this is also set if
  105. * `options.allowWindowsEscape` is set to the exact value `false`.
  106. *
  107. * @default false
  108. */
  109. windowsPathsNoEscape?: boolean;
  110. }
  111. import fs = require("fs");
  112. interface IGlobOptions extends IMinimatchOptions {
  113. cwd?: string | undefined;
  114. root?: string | undefined;
  115. dot?: boolean | undefined;
  116. nomount?: boolean | undefined;
  117. mark?: boolean | undefined;
  118. nosort?: boolean | undefined;
  119. stat?: boolean | undefined;
  120. silent?: boolean | undefined;
  121. strict?: boolean | undefined;
  122. cache?:
  123. | { [path: string]: boolean | "DIR" | "FILE" | ReadonlyArray<string> }
  124. | undefined;
  125. statCache?:
  126. | { [path: string]: false | { isDirectory(): boolean } | undefined }
  127. | undefined;
  128. symlinks?: { [path: string]: boolean | undefined } | undefined;
  129. realpathCache?: { [path: string]: string } | undefined;
  130. sync?: boolean | undefined;
  131. nounique?: boolean | undefined;
  132. nonull?: boolean | undefined;
  133. debug?: boolean | undefined;
  134. nobrace?: boolean | undefined;
  135. noglobstar?: boolean | undefined;
  136. noext?: boolean | undefined;
  137. nocase?: boolean | undefined;
  138. matchBase?: any;
  139. nodir?: boolean | undefined;
  140. ignore?: string | ReadonlyArray<string> | undefined;
  141. follow?: boolean | undefined;
  142. realpath?: boolean | undefined;
  143. nonegate?: boolean | undefined;
  144. nocomment?: boolean | undefined;
  145. absolute?: boolean | undefined;
  146. allowWindowsEscape?: boolean | undefined;
  147. fs?: typeof fs;
  148. }
  149. export type CreateOptions = {
  150. dot?: boolean;
  151. globOptions?: IGlobOptions;
  152. ordering?: string;
  153. pattern?: string;
  154. transform?: (filePath: string) => NodeJS.ReadWriteStream | void;
  155. unpack?: string;
  156. unpackDir?: string;
  157. };
  158. export type ListOptions = {
  159. isPack: boolean;
  160. };
  161. export type EntryMetadata = {
  162. unpacked: boolean;
  163. };
  164. export type DirectoryMetadata = EntryMetadata & {
  165. files: { [property: string]: EntryMetadata };
  166. };
  167. export type FileMetadata = EntryMetadata & {
  168. executable?: true;
  169. offset?: number;
  170. size?: number;
  171. };
  172. export type LinkMetadata = {
  173. link: string;
  174. };
  175. export type Metadata = DirectoryMetadata | FileMetadata | LinkMetadata;
  176. export type InputMetadataType = 'directory' | 'file' | 'link';
  177. export type InputMetadata = {
  178. [property: string]: {
  179. type: InputMetadataType;
  180. stat: Stats;
  181. }
  182. };
  183. export type DirectoryRecord = {
  184. files: Record<string, DirectoryRecord | FileRecord>;
  185. };
  186. export type FileRecord = {
  187. offset: string;
  188. size: number;
  189. executable?: boolean;
  190. integrity: {
  191. hash: string;
  192. algorithm: 'SHA256';
  193. blocks: string[];
  194. blockSize: number;
  195. };
  196. }
  197. export type ArchiveHeader = {
  198. // The JSON parsed header string
  199. header: DirectoryRecord;
  200. headerString: string;
  201. headerSize: number;
  202. }
  203. export function createPackage(src: string, dest: string): Promise<void>;
  204. export function createPackageWithOptions(
  205. src: string,
  206. dest: string,
  207. options: CreateOptions
  208. ): Promise<void>;
  209. export function createPackageFromFiles(
  210. src: string,
  211. dest: string,
  212. filenames: string[],
  213. metadata?: InputMetadata,
  214. options?: CreateOptions
  215. ): Promise<void>;
  216. export function statFile(archive: string, filename: string, followLinks?: boolean): Metadata;
  217. export function getRawHeader(archive: string): ArchiveHeader;
  218. export function listPackage(archive: string, options?: ListOptions): string[];
  219. export function extractFile(archive: string, filename: string): Buffer;
  220. export function extractAll(archive: string, dest: string): void;
  221. export function uncache(archive: string): boolean;
  222. export function uncacheAll(): void;