diff --git a/types/deps-sort/deps-sort-tests.ts b/types/deps-sort/deps-sort-tests.ts new file mode 100644 index 0000000000..e706edaefb --- /dev/null +++ b/types/deps-sort/deps-sort-tests.ts @@ -0,0 +1,31 @@ +import depsSort = require("deps-sort"); + +function browserifyTest(opts: depsSort.Options) { + const depsOpts: depsSort.Options = { + index: opts != null && opts.index, + dedupe: opts != null && opts.dedupe, + expose: opts.expose || { id: "file.txt" } + }; + + const res = depsSort(); // 'opts' are optional + res.pipe(depsSort(depsOpts)); + + res.once("error", (err: any) => { + console.error("module-deps error: ", err); + }); + + const inst: NodeJS.ReadWriteStream = depsSort({ + index: true, + expose: { id: "file.txt" } + }); + + inst.on("file", (file, id) => { + console.log("file", file, id); + }); + inst.on("package", (pkg) => { + console.log("package", pkg); + }); + inst.on("transform", (tr, file) => { + console.log("transform", tr, file); + }); +} diff --git a/types/deps-sort/index.d.ts b/types/deps-sort/index.d.ts new file mode 100644 index 0000000000..e32c826771 --- /dev/null +++ b/types/deps-sort/index.d.ts @@ -0,0 +1,85 @@ +// Type definitions for deps-sort 2.0 +// Project: https://github.com/browserify/deps-sort +// Definitions by: TeamworkGuy2 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as stream from "stream"; + +/** + * Return a new through stream that should get written module-deps objects and will output sorted objects. + */ +declare function depsSort(opts?: depsSort.Options): stream.Transform; + +/** + * Sort module-deps output for deterministic browserify bundles. + */ +declare namespace depsSort { + /** + * module-deps constructor options + */ + interface Options { + /** + * When true, for each module-deps row, insert 'row.index' with the numeric index and + * 'row.indexDeps' like 'row.deps' but mapping require strings to row indices + */ + index?: boolean; + + /** + * array of names or object mapping names to true not to mangle with integer indexes when 'index' is turned on. + * If 'expose' maps names to strings, those strings will be used to resolve the indexed references. + */ + expose?: string[] | { [name: string]: boolean | string }; + + /** + * Set 'row.dedupe' for files that match existing contents. Sets 'row.dedupeIndex' when 'index' is enabled. + * When 'row.dedupe' is set, 'row.sameDeps' will be set to a boolean of whether the dependencies at the dedupe target match (true) or just the source content (false). + */ + dedupe?: boolean; + + [prop: string]: any; + } + + /** + * Input objects are file objects in the module-deps shape. They must at least have these properties: + */ + interface InputRow { + /** + * a unique identifier for the file + */ + id: string; + /** + * the file contents + */ + source: string; + /** + * dependencies for this file, mapping strings as used in require() to row IDs + */ + deps: string[]; + } + + /** + * All the input properties, and: + */ + interface OutputRow { + /** + * when 'opts.index' is true, the sorted numeric index of the row + */ + index: number; + /** + * like 'row.deps', but mapping to 'row.index' instead of 'row.id' + */ + indexDeps: { [id: string]: number }; + /** + * when 'opts.dedupe' is true, contains the row ID of a file with identical contents + */ + dedupe: string; + /** + * like 'row.dedupe', but contains the 'row.index' instead of 'row.id' + */ + dedupeIndex: number; + } +} + +export = depsSort; diff --git a/types/deps-sort/tsconfig.json b/types/deps-sort/tsconfig.json new file mode 100644 index 0000000000..15871fb95e --- /dev/null +++ b/types/deps-sort/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "deps-sort-tests.ts" + ] +} \ No newline at end of file diff --git a/types/deps-sort/tslint.json b/types/deps-sort/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/deps-sort/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }