Skip to content

Commit

Permalink
[browser-pack] update browser-pack definition to 6.1.0 from 6.0.1 (ad…
Browse files Browse the repository at this point in the history
…d 'sourceRoot' option and documentation) (DefinitelyTyped#44027)
  • Loading branch information
TeamworkGuy2 authored Apr 23, 2020
1 parent 94e4681 commit 26c370e
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 57 deletions.
48 changes: 25 additions & 23 deletions types/browser-pack/browser-pack-tests.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import browserPack = require("browser-pack");

module BrowserPackTest {
function packIt(opts: browserPack.Options) {
const packOpts: browserPack.Options = {
basedir: opts.basedir || "./",
externalRequireName: opts.externalRequireName || "require",
hasExports: opts.hasExports || false,
prelude: opts.prelude || undefined,
preludePath: opts.preludePath || undefined,
raw: opts.raw || false,
sourceMapPrefix: opts.sourceMapPrefix || '//#',
sourceRoot: opts.sourceRoot || undefined,
standalone: opts.standalone || undefined,
standaloneModule: opts.standaloneModule || undefined,
};

export function packIt(opts?: browserPack.Options) {
var packOpts: browserPack.Options = {
basedir: opts.basedir || "./",
externalRequireName: opts.externalRequireName || "require",
hasExports: opts.hasExports || false,
prelude: opts.prelude || undefined,
preludePath: opts.preludePath || undefined,
raw: opts.raw || false,
sourceMapPrefix: opts.sourceMapPrefix || '//#',
standalone: opts.standalone || undefined,
standaloneModule: opts.standaloneModule || undefined,
};
const bpack1 = browserPack(); // 'opts' is optional
const bpack2 = browserPack({ raw: true }); // options literal
const bpack3 = browserPack(packOpts); // all options

var res = browserPack(); // 'opts' are optional
var res2 = browserPack(packOpts);
// return value is a stream
const bpack4 = bpack1.pipe(bpack2);

// ensure return value is a stream
var res3 = res.pipe(res2);

res.on("error", function (err: any) {
console.error("browser-pack error: ", err);
});
}
bpack3.on("error", (err) => {
console.error("browser-pack error: ", err);
});

bpack4.end(() => {
console.log("end");
});
}

export = BrowserPackTest;
export = packIt;
53 changes: 38 additions & 15 deletions types/browser-pack/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,82 @@
// Type definitions for browser-pack v6.0.1
// Type definitions for browser-pack 6.1
// Project: https://github.com/substack/browser-pack
// Definitions by: TeamworkGuy2 <https://github.com/TeamworkGuy2>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node" />

/** pack node-style source files from a json stream into a browser bundle
/**
* pack node-style source files from a json stream into a browser bundle
*/
declare namespace browserPack {

export interface Options {
/** Whether the bundle should include require= (or the opts.externalRequireName) so that
interface Options {
/**
* Whether the bundle should include require= (or the opts.externalRequireName) so that
* require() is available outside the bundle
*/
hasExports?: boolean;

/** A string to use in place of 'require' if opts.hasExports is specified, default is 'require'
/**
* A string to use in place of 'require' if opts.hasExports is specified, default is 'require'
*/
externalRequireName?: string;

/** Specify a custom prelude, but know what you're doing first. See the prelude.js file in
/**
* Specify a custom prelude, but know what you're doing first. See the prelude.js file in
* this repo for the default prelude. If you specify a custom prelude, you must also specify
* a valid opts.preludePath to the prelude source file for sourcemaps to work
*/
prelude?: string;

/** prelude.js path if a custom opts.prelude is specified
/**
* prelude.js path if a custom opts.prelude is specified
*/
preludePath?: string;

/** Used if opts.preludePath is undefined, this is used to resolve the prelude.js file location, default: 'process.cwd()'
/**
* Used if opts.preludePath is undefined, this is used to resolve the prelude.js file location, default: 'process.cwd()'
*/
basedir?: string;

/** if given, the writable end of the stream will expect objects to be written to
/**
* If given, the writable end of the stream will expect objects to be written to
* it instead of expecting a stream of json text it will need to parse, default false
*/
raw?: boolean;

/** External string name to use for UMD, if not provided, UMD declaration is not wrapped around output
/**
* External string name to use for UMD, if not provided, UMD declaration is not wrapped around output
*/
standalone?: string;

/** Sets the internal module name to export for standalone
/**
* Sets the internal module name to export for standalone
*/
standaloneModule?: string;

/** If given and source maps are computed, the opts.sourceMapPrefix string will be used instead of default: '//#'
/**
* If given and source maps are computed, the opts.sourceMapPrefix string will be used instead of default: '//#'
*/
sourceMapPrefix?: string;

/**
* If given and source maps are computed, the root for the output source map will be defined. (default is no root)
*/
sourceRoot?: string;
}
}

/** pack node-style source files from a json stream into a browser bundle
/**
* Pack node-style source files from a json stream into a browser bundle.
* Source objects are written to browser-pack using 'write(row)'. browser-pack uses these properties of each row:
* - 'id' - A unique ID for this module.
* - 'deps' - An object mapping 'require()' argument strings to dependency row IDs, used for resolution at runtime.
* - 'entry' - When true, this module will be executed when the bundle loads. Otherwise, it will only be executed once some other module 'require()'s it.
* - 'order' - When 'row.entry' is true, this number indicates the order in which different entry modules are executed.
* - 'source' - The contents of the module.
* - 'nomap' - When true, a source map is not generated for this module.
* - 'sourceFile' - The file name to use for this module in the source map.
*/
declare function browserPack(opts?: browserPack.Options): NodeJS.ReadWriteStream;
export = browserPack;
export as namespace browserPack;
export as namespace browserPack;
2 changes: 1 addition & 1 deletion types/browser-pack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
Expand Down
19 changes: 1 addition & 18 deletions types/browser-pack/tslint.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
{
"extends": "dtslint/dt.json",
"rules": {
"callable-types": false,
"dt-header": false,
"eofline": false,
"export-just-namespace": false,
"jsdoc-format": false,
"no-internal-module": false,
"no-namespace": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-var-keyword": false,
"only-arrow-functions": false,
"prefer-const": false,
"prefer-method-signature": false,
"space-before-function-paren": false,
"strict-export-declare-modifiers": false
}
"extends": "dtslint/dt.json"
}

0 comments on commit 26c370e

Please sign in to comment.