Merge pull request #30395 from TeamworkGuy2/master

[deps-sort] Add deps-sort@2.0.0 definition
This commit is contained in:
Benjamin Lichtman
2018-11-20 10:30:01 -08:00
committed by GitHub
4 changed files with 140 additions and 0 deletions
+31
View File
@@ -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);
});
}
+85
View File
@@ -0,0 +1,85 @@
// Type definitions for deps-sort 2.0
// Project: https://github.com/browserify/deps-sort
// Definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
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;
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }