From ce56f8e2f4a2a169cb84d3a7af30b5c1528f67b2 Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 29 Nov 2015 15:12:26 +0200 Subject: [PATCH 1/7] Update stream() signature and add tests --- browser-sync/browser-sync-tests.ts | 23 +++++++++++++++++++++++ browser-sync/browser-sync.d.ts | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/browser-sync/browser-sync-tests.ts b/browser-sync/browser-sync-tests.ts index 210a8cf1b..e54439afb 100644 --- a/browser-sync/browser-sync-tests.ts +++ b/browser-sync/browser-sync-tests.ts @@ -95,3 +95,26 @@ function browserSyncInit(): browserSync.BrowserSyncInstance { } var browser = browserSyncInit(); browser.exit(); + +// Stream method. + +// -- No options. +browser.stream(); + +// -- "once" option. +browser.stream({once: true}); + +// -- "match" option (string). +browser.stream({match: "**/*.js"}); + +// -- "match" option (RegExp). +browser.stream({match: /\.js$/}); + +// -- "match" option (function). +browser.stream({match: (testString) => true}); + +// -- "match" option (array). +browser.stream({match: ["**/*.js", /\.js$/, (testString) => true]}); + +// -- Both options. +browser.stream({once: true, match: ["**/*.js", /\.js$/, (testString) => true]}); diff --git a/browser-sync/browser-sync.d.ts b/browser-sync/browser-sync.d.ts index 9d4cbcce3..05dcaaaa3 100644 --- a/browser-sync/browser-sync.d.ts +++ b/browser-sync/browser-sync.d.ts @@ -365,7 +365,7 @@ declare module "browser-sync" { * The stream method returns a transform stream and can act once or on many files. * @param opts Configuration for the stream method */ - stream(opts?: { once: boolean }): NodeJS.ReadWriteStream; + stream(opts?: { once?: boolean, match?: string | RegExp | ((testString: string) => boolean) | (string | RegExp | ((testString: string) => boolean))[] }): NodeJS.ReadWriteStream; /** * Helper method for browser notifications * @param message Can be a simple message such as 'Connected' or HTML From 9f1a17eef4cd3d1b18c2fd9e6eed6a2cbb3c4a36 Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 29 Nov 2015 15:41:30 +0200 Subject: [PATCH 2/7] Add "instances" array + test --- browser-sync/browser-sync-tests.ts | 2 ++ browser-sync/browser-sync.d.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/browser-sync/browser-sync-tests.ts b/browser-sync/browser-sync-tests.ts index e54439afb..bb4f8c7c4 100644 --- a/browser-sync/browser-sync-tests.ts +++ b/browser-sync/browser-sync-tests.ts @@ -78,6 +78,8 @@ evt.on("init", function () { browserSync(config); +var instance = browserSync.instances[0]; + var bs = browserSync.create(); bs.init({ diff --git a/browser-sync/browser-sync.d.ts b/browser-sync/browser-sync.d.ts index 05dcaaaa3..1ffea1c0c 100644 --- a/browser-sync/browser-sync.d.ts +++ b/browser-sync/browser-sync.d.ts @@ -328,6 +328,8 @@ declare module "browser-sync" { * @param name the identifier used for retrieval */ get(name: string): BrowserSyncInstance; + + instances: BrowserSyncInstance[]; } interface BrowserSyncInstance { From 149185d2fa4401af1fe15cd9a94bae22fe9f3e57 Mon Sep 17 00:00:00 2001 From: Glen Date: Sun, 29 Nov 2015 15:43:59 +0200 Subject: [PATCH 3/7] Remove trailing whitespace and add missing semi-colon --- browser-sync/browser-sync-tests.ts | 2 +- browser-sync/browser-sync.d.ts | 52 +++++++++++++++--------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/browser-sync/browser-sync-tests.ts b/browser-sync/browser-sync-tests.ts index bb4f8c7c4..f79dd517b 100644 --- a/browser-sync/browser-sync-tests.ts +++ b/browser-sync/browser-sync-tests.ts @@ -87,7 +87,7 @@ bs.init({ }); bs.reload(); - + function browserSyncInit(): browserSync.BrowserSyncInstance { var browser = browserSync.create(); browser.init(); diff --git a/browser-sync/browser-sync.d.ts b/browser-sync/browser-sync.d.ts index 1ffea1c0c..fe4498e8f 100644 --- a/browser-sync/browser-sync.d.ts +++ b/browser-sync/browser-sync.d.ts @@ -14,16 +14,16 @@ declare module "browser-sync" { namespace browserSync { interface Options { /** - * Browsersync includes a user-interface that is accessed via a separate port. The UI allows to controls + * Browsersync includes a user-interface that is accessed via a separate port. The UI allows to controls * all devices, push sync updates and much more. - * + * * port - Default: 3001 * weinre.port - Default: 8080 * Note: requires at least version 2.0.0 */ ui?: UIOptions; /** - * Browsersync can watch your files as you work. Changes you make will either be injected into the page (CSS + * Browsersync can watch your files as you work. Changes you make will either be injected into the page (CSS * & images) or will cause all browsers to do a full-page refresh. See anymatch for more information on glob * patterns. * Default: false @@ -55,14 +55,14 @@ declare module "browser-sync" { */ port?: number; /** - * Add additional directories from which static files should be served. + * Add additional directories from which static files should be served. * Should only be used in proxy or snippet mode. * Default: [] * Note: requires at least version 2.8.0 */ serveStatic?: string[]; /** - * Enable https for localhost development. + * Enable https for localhost development. * Note - this is not needed for proxy option as it will be inferred from your target url. * Note: requires at least version 1.3.0 */ @@ -102,7 +102,7 @@ declare module "browser-sync" { */ logSnippet?: boolean; /** - * You can control how the snippet is injected onto each page via a custom regex + function. + * You can control how the snippet is injected onto each page via a custom regex + function. * You can also provide patterns for certain urls that should be ignored from the snippet injection. * Note: requires at least version 2.0.0 */ @@ -119,13 +119,13 @@ declare module "browser-sync" { */ tunnel?: string | boolean; /** - * Some features of Browsersync (such as xip & tunnel) require an internet connection, but if you're + * Some features of Browsersync (such as xip & tunnel) require an internet connection, but if you're * working offline, you can reduce start-up time by setting this option to false */ online?: boolean; /** * Default: true - * Decide which URL to open automatically when Browsersync starts. Defaults to "local" if none set. + * Decide which URL to open automatically when Browsersync starts. Defaults to "local" if none set. * Can be true, local, external, ui, ui-external, tunnel or false */ open?: string | boolean; @@ -135,7 +135,7 @@ declare module "browser-sync" { */ browser?: string | string[]; /** - * Requires an internet connection - useful for services such as Typekit as it allows you to configure + * Requires an internet connection - useful for services such as Typekit as it allows you to configure * domains such as *.xip.io in your kit settings * Default: false */ @@ -154,14 +154,14 @@ declare module "browser-sync" { * scrollProportionally: false // Sync viewports to TOP position * Default: true */ - scrollProportionally?: boolean + scrollProportionally?: boolean; /** * How often to send scroll events * Default: 0 */ scrollThrottle?: number; /** - * Decide which technique should be used to restore scroll position following a reload. + * Decide which technique should be used to restore scroll position following a reload. * Can be window.name or cookie * Default: 'window.name' */ @@ -175,13 +175,13 @@ declare module "browser-sync" { /** * Default: [] * Note: requires at least version 2.9.0 - * Sync the scroll position of any element on the page - where any scrolled element will cause - * all others to match scroll position. This is helpful when a breakpoint alters which element + * Sync the scroll position of any element on the page - where any scrolled element will cause + * all others to match scroll position. This is helpful when a breakpoint alters which element * is actually scrolling */ scrollElementMapping?: string[]; /** - * Time, in milliseconds, to wait before instructing the browser to reload/inject following a file + * Time, in milliseconds, to wait before instructing the browser to reload/inject following a file * change event * Default: 0 */ @@ -227,7 +227,7 @@ declare module "browser-sync" { */ timestamps?: boolean; /** - * Alter the script path for complete control over where the Browsersync Javascript is served + * Alter the script path for complete control over where the Browsersync Javascript is served * from. Whatever you return from this function will be used as the script path. * Note: requires at least version 1.5.0 */ @@ -250,7 +250,7 @@ declare module "browser-sync" { [path: string]: T; } - interface UIOptions { + interface UIOptions { /** set the default port */ port?: number; /** set the default weinre port */ @@ -266,9 +266,9 @@ declare module "browser-sync" { directory?: boolean; /** set index filename */ index?: string; - /** - * key-value object hash, where the key is the url to match, - * and the value is the folder to serve (relative to your working directory) + /** + * key-value object hash, where the key is the url to match, + * and the value is the folder to serve (relative to your working directory) */ routes?: Hash; /** configure custom middleware */ @@ -314,7 +314,7 @@ declare module "browser-sync" { interface BrowserSyncStatic extends BrowserSyncInstance { /** - * Start the Browsersync service. This will launch a server, proxy or start the snippet mode + * Start the Browsersync service. This will launch a server, proxy or start the snippet mode * depending on your use-case. */ (config?: Options, callback?: (err: Error, bs: Object) => any): BrowserSyncInstance; @@ -336,30 +336,30 @@ declare module "browser-sync" { /** the name of this instance of browser-sync */ name: string; /** - * Start the Browsersync service. This will launch a server, proxy or start the snippet mode + * Start the Browsersync service. This will launch a server, proxy or start the snippet mode * depending on your use-case. */ init(config?: Options, callback?: (err: Error, bs: Object) => any): BrowserSyncInstance; /** * Reload the browser - * The reload method will inform all browsers about changed files and will either cause the browser + * The reload method will inform all browsers about changed files and will either cause the browser * to refresh, or inject the files where possible. */ reload(): void; /** * Reload a single file - * The reload method will inform all browsers about changed files and will either cause the browser + * The reload method will inform all browsers about changed files and will either cause the browser * to refresh, or inject the files where possible. */ reload(file: string): void; /** * Reload multiple files - * The reload method will inform all browsers about changed files and will either cause the browser + * The reload method will inform all browsers about changed files and will either cause the browser * to refresh, or inject the files where possible. */ reload(files: string[]): void; /** - * The reload method will inform all browsers about changed files and will either cause the browser + * The reload method will inform all browsers about changed files and will either cause the browser * to refresh, or inject the files where possible. */ reload(options: { stream: boolean }): NodeJS.ReadWriteStream; @@ -392,7 +392,7 @@ declare module "browser-sync" { */ resume(): void; /** - * The internal Event Emitter used by the running Browsersync instance (if there is one). You can use + * The internal Event Emitter used by the running Browsersync instance (if there is one). You can use * this to emit your own events, such as changed files, logging etc. */ emitter: NodeJS.EventEmitter; From 620f9cc215be5377c03d0f66c609fe46149f08f2 Mon Sep 17 00:00:00 2001 From: Glen Date: Tue, 8 Dec 2015 09:45:34 +0200 Subject: [PATCH 4/7] Refactor (add MatchTest type and StreamOptions interface) --- browser-sync/browser-sync.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/browser-sync/browser-sync.d.ts b/browser-sync/browser-sync.d.ts index fe4498e8f..6f46d6c94 100644 --- a/browser-sync/browser-sync.d.ts +++ b/browser-sync/browser-sync.d.ts @@ -312,6 +312,13 @@ declare module "browser-sync" { fn: (match: string) => string; } + type MatchTest = (string | RegExp | ((testString: string) => boolean)); + + interface StreamOptions { + once?: boolean; + match?: MatchTest | MatchTest[]; + } + interface BrowserSyncStatic extends BrowserSyncInstance { /** * Start the Browsersync service. This will launch a server, proxy or start the snippet mode @@ -367,7 +374,7 @@ declare module "browser-sync" { * The stream method returns a transform stream and can act once or on many files. * @param opts Configuration for the stream method */ - stream(opts?: { once?: boolean, match?: string | RegExp | ((testString: string) => boolean) | (string | RegExp | ((testString: string) => boolean))[] }): NodeJS.ReadWriteStream; + stream(opts?: StreamOptions): NodeJS.ReadWriteStream; /** * Helper method for browser notifications * @param message Can be a simple message such as 'Connected' or HTML From b86d447665ed166ddea983d6878d7b120ee45daf Mon Sep 17 00:00:00 2001 From: Glen Date: Tue, 22 Dec 2015 10:43:47 +0200 Subject: [PATCH 5/7] Remove "instances" array + test --- browser-sync/browser-sync-tests.ts | 2 -- browser-sync/browser-sync.d.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/browser-sync/browser-sync-tests.ts b/browser-sync/browser-sync-tests.ts index f79dd517b..2d254ac3d 100644 --- a/browser-sync/browser-sync-tests.ts +++ b/browser-sync/browser-sync-tests.ts @@ -78,8 +78,6 @@ evt.on("init", function () { browserSync(config); -var instance = browserSync.instances[0]; - var bs = browserSync.create(); bs.init({ diff --git a/browser-sync/browser-sync.d.ts b/browser-sync/browser-sync.d.ts index 6f46d6c94..58c1dbf65 100644 --- a/browser-sync/browser-sync.d.ts +++ b/browser-sync/browser-sync.d.ts @@ -335,8 +335,6 @@ declare module "browser-sync" { * @param name the identifier used for retrieval */ get(name: string): BrowserSyncInstance; - - instances: BrowserSyncInstance[]; } interface BrowserSyncInstance { From 3467c722bdb2fab166ec142071c2b2e62171d17c Mon Sep 17 00:00:00 2001 From: Glen Date: Thu, 7 Jan 2016 16:23:59 +0200 Subject: [PATCH 6/7] Add new "has" method --- browser-sync/browser-sync-tests.ts | 2 ++ browser-sync/browser-sync.d.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/browser-sync/browser-sync-tests.ts b/browser-sync/browser-sync-tests.ts index 2d254ac3d..822c941d9 100644 --- a/browser-sync/browser-sync-tests.ts +++ b/browser-sync/browser-sync-tests.ts @@ -78,6 +78,8 @@ evt.on("init", function () { browserSync(config); +var has = browserSync.has("My server"); + var bs = browserSync.create(); bs.init({ diff --git a/browser-sync/browser-sync.d.ts b/browser-sync/browser-sync.d.ts index 58c1dbf65..50c00d9b9 100644 --- a/browser-sync/browser-sync.d.ts +++ b/browser-sync/browser-sync.d.ts @@ -335,6 +335,11 @@ declare module "browser-sync" { * @param name the identifier used for retrieval */ get(name: string): BrowserSyncInstance; + /** + * Check if an instance has been created. + * @param name the name of the instance + */ + has(name: string): boolean; } interface BrowserSyncInstance { From d9b5b35ba3a79ac778c5890531393442439df5dd Mon Sep 17 00:00:00 2001 From: Glen Date: Sat, 30 Jan 2016 21:44:02 +0200 Subject: [PATCH 7/7] Use Micromatch Pattern type --- browser-sync/browser-sync.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/browser-sync/browser-sync.d.ts b/browser-sync/browser-sync.d.ts index 50c00d9b9..6640090bc 100644 --- a/browser-sync/browser-sync.d.ts +++ b/browser-sync/browser-sync.d.ts @@ -5,11 +5,13 @@ /// /// +/// declare module "browser-sync" { import chokidar = require("chokidar"); import fs = require("fs"); import http = require("http"); + import mm = require("micromatch"); namespace browserSync { interface Options { @@ -312,11 +314,9 @@ declare module "browser-sync" { fn: (match: string) => string; } - type MatchTest = (string | RegExp | ((testString: string) => boolean)); - interface StreamOptions { once?: boolean; - match?: MatchTest | MatchTest[]; + match?: mm.Pattern | mm.Pattern[]; } interface BrowserSyncStatic extends BrowserSyncInstance {