1 | // Type definitions for Browserify 12.0
|
2 | // Project: http://browserify.org/
|
3 | // Definitions by: Andrew Gaspar <https://github.com/AndrewGaspar>
|
4 | // John Vilk <https://github.com/jvilk>
|
5 | // Leonard Thieu <https://github.com/leonard-thieu>
|
6 | // Linus Unnebäck <https://github.com/LinusU>
|
7 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
8 |
|
9 | /// <reference types="node" />
|
10 |
|
11 | import insertGlobals = require("insert-module-globals");
|
12 |
|
13 | declare var browserify: browserify.BrowserifyConstructor;
|
14 | export = browserify;
|
15 |
|
16 | declare namespace browserify {
|
17 | /**
|
18 | * Options pertaining to an individual file.
|
19 | */
|
20 | interface FileOptions {
|
21 | // If true, this is considered an entry point to your app.
|
22 | entry?: boolean | undefined;
|
23 | // Expose this file under a custom dependency name.
|
24 | // require('./vendor/angular/angular.js', {expose: 'angular'}) enables require('angular')
|
25 | expose?: string | undefined;
|
26 | // Basedir to use to resolve this file's path.
|
27 | basedir?: string | undefined;
|
28 | // The name/path to the file.
|
29 | file?: string | undefined;
|
30 | // Forward file to external() to be externalized.
|
31 | external?: boolean | undefined;
|
32 | // Disable transforms on file if set to false.
|
33 | transform?: boolean | undefined;
|
34 | // The ID to use for require() statements.
|
35 | id?: string | undefined;
|
36 | }
|
37 |
|
38 | // Browserify accepts a filename, an input stream for file inputs, or a FileOptions configuration
|
39 | // for each file in a bundle.
|
40 | type InputFile = string | NodeJS.ReadableStream | FileOptions;
|
41 |
|
42 | /**
|
43 | * Core options pertaining to a Browserify instance, extended by user options
|
44 | */
|
45 | interface CustomOptions {
|
46 | /**
|
47 | * Custom properties can be defined on Options.
|
48 | * These options are forwarded along to module-deps and browser-pack directly.
|
49 | */
|
50 | [propName: string]: any;
|
51 | /** the directory that Browserify starts bundling from for filenames that start with .. */
|
52 | basedir?: string | undefined;
|
53 | }
|
54 | /**
|
55 | * Options pertaining to a Browserify instance.
|
56 | */
|
57 | interface Options extends CustomOptions {
|
58 | // String, file object, or array of those types (they may be mixed) specifying entry file(s).
|
59 | entries?: InputFile | InputFile[] | undefined;
|
60 | // an array which will skip all require() and global parsing for each file in the array.
|
61 | // Use this for giant libs like jquery or threejs that don't have any requires or node-style globals but take forever to parse.
|
62 | noParse?: string[] | undefined;
|
63 | // an array of optional extra extensions for the module lookup machinery to use when the extension has not been specified.
|
64 | // By default Browserify considers only .js and .json files in such cases.
|
65 | extensions?: string[] | undefined;
|
66 | // an array of directories that Browserify searches when looking for modules which are not referenced using relative path.
|
67 | // Can be absolute or relative to basedir. Equivalent of setting NODE_PATH environmental variable when calling Browserify command.
|
68 | paths?: string[] | undefined;
|
69 | // sets the algorithm used to parse out the common paths. Use false to turn this off, otherwise it uses the commondir module.
|
70 | commondir?: boolean | undefined;
|
71 | // disables converting module ids into numerical indexes. This is useful for preserving the original paths that a bundle was generated with.
|
72 | fullPaths?: boolean | undefined;
|
73 | // sets the list of built-ins to use, which by default is set in lib/builtins.js in this distribution.
|
74 | builtins?: string[] | { [builtinName: string]: string } | boolean | undefined;
|
75 | // set if external modules should be bundled. Defaults to true.
|
76 | bundleExternal?: boolean | undefined;
|
77 | // When true, always insert process, global, __filename, and __dirname without analyzing the AST for faster builds but larger output bundles. Default false.
|
78 | insertGlobals?: boolean | undefined;
|
79 | // When true, scan all files for process, global, __filename, and __dirname, defining as necessary.
|
80 | // With this option npm modules are more likely to work but bundling takes longer. Default true.
|
81 | detectGlobals?: boolean | undefined;
|
82 | // When true, add a source map inline to the end of the bundle. This makes debugging easier because you can see all the original files if you are in a modern enough browser.
|
83 | debug?: boolean | undefined;
|
84 | // When a non-empty string, a standalone module is created with that name and a umd wrapper.
|
85 | // You can use namespaces in the standalone global export using a . in the string name as a separator, for example 'A.B.C'.
|
86 | // The global export will be sanitized and camel cased.
|
87 | standalone?: string | undefined;
|
88 | // will be passed to insert-module-globals as the opts.vars parameter.
|
89 | insertGlobalVars?: insertGlobals.VarsOption | undefined;
|
90 | // defaults to 'require' in expose mode but you can use another name.
|
91 | externalRequireName?: string | undefined;
|
92 | }
|
93 |
|
94 | interface BrowserifyConstructor {
|
95 | (files: InputFile[], opts?: Options): BrowserifyObject;
|
96 | (file: InputFile, opts?: Options): BrowserifyObject;
|
97 | (opts?: Options): BrowserifyObject;
|
98 | new(files: InputFile[], opts?: Options): BrowserifyObject;
|
99 | new(file: InputFile, opts?: Options): BrowserifyObject;
|
100 | new(opts?: Options): BrowserifyObject;
|
101 | }
|
102 |
|
103 | interface BrowserifyObject extends NodeJS.EventEmitter {
|
104 | /**
|
105 | * Add an entry file from file that will be executed when the bundle loads.
|
106 | * If file is an array, each item in file will be added as an entry file.
|
107 | */
|
108 | add(file: InputFile | InputFile[], opts?: FileOptions): BrowserifyObject;
|
109 | /**
|
110 | * Make file available from outside the bundle with require(file).
|
111 | * The file param is anything that can be resolved by require.resolve().
|
112 | * file can also be a stream, but you should also use opts.basedir so that relative requires will be resolvable.
|
113 | * If file is an array, each item in file will be required. In file array form, you can use a string or object for each item. Object items should have a file property and the rest of the parameters will be used for the opts.
|
114 | * Use the expose property of opts to specify a custom dependency name. require('./vendor/angular/angular.js', {expose: 'angular'}) enables require('angular')
|
115 | */
|
116 | require(file: InputFile, opts?: FileOptions): BrowserifyObject;
|
117 | /**
|
118 | * Bundle the files and their dependencies into a single javascript file.
|
119 | * Return a readable stream with the javascript file contents or optionally specify a cb(err, buf) to get the buffered results.
|
120 | */
|
121 | bundle(cb?: (err: any, src: Buffer) => any): NodeJS.ReadableStream;
|
122 | /**
|
123 | * Prevent file from being loaded into the current bundle, instead referencing from another bundle.
|
124 | * If file is an array, each item in file will be externalized.
|
125 | * If file is another bundle, that bundle's contents will be read and excluded from the current bundle as the bundle in file gets bundled.
|
126 | */
|
127 | external(file: string[], opts?: CustomOptions): BrowserifyObject;
|
128 | external(file: string, opts?: CustomOptions): BrowserifyObject;
|
129 | external(file: BrowserifyObject): BrowserifyObject;
|
130 | /**
|
131 | * Prevent the module name or file at file from showing up in the output bundle.
|
132 | * Instead you will get a file with module.exports = {}.
|
133 | */
|
134 | ignore(file: string, opts?: CustomOptions): BrowserifyObject;
|
135 | /**
|
136 | * Prevent the module name or file at file from showing up in the output bundle.
|
137 | * If your code tries to require() that file it will throw unless you've provided another mechanism for loading it.
|
138 | */
|
139 | exclude(file: string, opts?: CustomOptions): BrowserifyObject;
|
140 | /**
|
141 | * Transform source code before parsing it for require() calls with the transform function or module name tr.
|
142 | * If tr is a function, it will be called with tr(file) and it should return a through-stream that takes the raw file contents and produces the transformed source.
|
143 | * If tr is a string, it should be a module name or file path of a transform module
|
144 | */
|
145 | transform<T extends CustomOptions>(tr: string, opts?: T): BrowserifyObject;
|
146 | transform<T extends CustomOptions>(
|
147 | tr: (file: string, opts: T) => NodeJS.ReadWriteStream,
|
148 | opts?: T,
|
149 | ): BrowserifyObject;
|
150 | /**
|
151 | * Register a plugin with opts. Plugins can be a string module name or a function the same as transforms.
|
152 | * plugin(b, opts) is called with the Browserify instance b.
|
153 | */
|
154 | plugin<T extends CustomOptions>(plugin: string, opts?: T): BrowserifyObject;
|
155 | plugin<T extends CustomOptions>(plugin: (b: BrowserifyObject, opts: T) => any, opts?: T): BrowserifyObject;
|
156 | /**
|
157 | * Reset the pipeline back to a normal state. This function is called automatically when bundle() is called multiple times.
|
158 | * This function triggers a 'reset' event.
|
159 | */
|
160 | reset(opts?: Options): void;
|
161 |
|
162 | /**
|
163 | * When a file is resolved for the bundle, the bundle emits a 'file' event with the full file path, the id string passed to require(), and the parent object used by browser-resolve.
|
164 | * You could use the file event to implement a file watcher to regenerate bundles when files change.
|
165 | */
|
166 | on(event: "file", listener: (file: string, id: string, parent: any) => any): this;
|
167 | /**
|
168 | * When a package.json file is read, this event fires with the contents.
|
169 | * The package directory is available at pkg.__dirname.
|
170 | */
|
171 | on(event: "package", listener: (pkg: any) => any): this;
|
172 | /**
|
173 | * When .bundle() is called, this event fires with the bundle output stream.
|
174 | */
|
175 | on(event: "bundle", listener: (bundle: NodeJS.ReadableStream) => any): this;
|
176 | /**
|
177 | * When the .reset() method is called or implicitly called by another call to .bundle(), this event fires.
|
178 | */
|
179 | on(event: "reset", listener: () => any): this;
|
180 | /**
|
181 | * When a transform is applied to a file, the 'transform' event fires on the bundle stream with the transform stream tr and the file that the transform is being applied to.
|
182 | */
|
183 | on(event: "transform", listener: (tr: NodeJS.ReadWriteStream, file: string) => any): this;
|
184 | on(event: string, listener: Function): this;
|
185 |
|
186 | /**
|
187 | * Set to any until substack/labeled-stream-splicer is defined
|
188 | */
|
189 | pipeline: any;
|
190 | }
|
191 | }
|
192 |
|
\ | No newline at end of file |