From a93971e8f072a4d3ad041481aab682bac6282534 Mon Sep 17 00:00:00 2001 From: Tom Lawton Date: Thu, 21 Sep 2023 18:41:19 +0000 Subject: [PATCH] feature(#1): enable() / disable() --- lib/extension.js | 7 ++++--- lib/types.d.ts | 3 +++ src/extension.ts | 5 +++-- src/types.ts | 4 ++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/extension.js b/lib/extension.js index bc583e1..3221cbb 100644 --- a/lib/extension.js +++ b/lib/extension.js @@ -1,12 +1,12 @@ import { __decorate } from "tslib"; import { Bud } from '@roots/bud-framework'; import { Extension } from '@roots/bud-framework/extension'; -import { bind, label } from '@roots/bud-framework/extension/decorators'; +import { bind, label, expose } from '@roots/bud-framework/extension/decorators'; import localtunnel from 'localtunnel/localtunnel.js'; let BudLocaltunnel = class BudLocaltunnel extends Extension { #devTunnel; async configAfter(bud) { - if (bud.isDevelopment) { + if (bud.isDevelopment && this.enabled) { this.#devTunnel = await localtunnel({ subdomain: bud.context.label.length > 3 ? bud.context.label : undefined, local_host: bud.server?.url.hostname, port: bud.server?.url.port }); const tunnelUrl = new URL(this.#devTunnel.url); bud.setPublicUrl(tunnelUrl); @@ -23,6 +23,7 @@ __decorate([ bind ], BudLocaltunnel.prototype, "configAfter", null); BudLocaltunnel = __decorate([ - label(`bud-localtunnel`) + label(`bud-localtunnel`), + expose(`localtunnel`) ], BudLocaltunnel); export default BudLocaltunnel; diff --git a/lib/types.d.ts b/lib/types.d.ts index 9ac4df2..56de46b 100644 --- a/lib/types.d.ts +++ b/lib/types.d.ts @@ -3,4 +3,7 @@ declare module '@roots/bud-framework' { interface Modules { 'bud-localtunnel': BudLocaltunnel; } + interface Bud { + localtunnel: BudLocaltunnel; + } } diff --git a/src/extension.ts b/src/extension.ts index 4751409..b00c564 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,13 +3,14 @@ import {Bud} from '@roots/bud-framework' import {Extension} from '@roots/bud-framework/extension' import type {WebpackPluginInstance} from '@roots/bud-framework/config' -import {bind, label} from '@roots/bud-framework/extension/decorators' +import {bind, label, expose} from '@roots/bud-framework/extension/decorators' import localtunnel from 'localtunnel/localtunnel.js' interface Options {} @label(`bud-localtunnel`) +@expose(`localtunnel`) export default class BudLocaltunnel extends Extension< Options, WebpackPluginInstance @@ -19,7 +20,7 @@ export default class BudLocaltunnel extends Extension< @bind public override async configAfter(bud: Bud) { - if(bud.isDevelopment) { + if(bud.isDevelopment && this.enabled) { this.#devTunnel = await localtunnel({ subdomain: bud.context.label.length > 3 ? bud.context.label : undefined, local_host: bud.server?.url.hostname, port: bud.server?.url.port }) const tunnelUrl = new URL(this.#devTunnel.url); diff --git a/src/types.ts b/src/types.ts index 530890c..03ef136 100644 --- a/src/types.ts +++ b/src/types.ts @@ -4,4 +4,8 @@ declare module '@roots/bud-framework' { interface Modules { 'bud-localtunnel': BudLocaltunnel } + + interface Bud { + localtunnel: BudLocaltunnel + } }