Skip to content

Commit

Permalink
fixup! Use await import in findBuildFile
Browse files Browse the repository at this point in the history
  • Loading branch information
hjdivad committed Oct 18, 2022
1 parent a9d2f7d commit 4c1a28f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/models/server-watcher.js
Expand Up @@ -3,8 +3,8 @@
const Watcher = require('./watcher');

module.exports = class ServerWatcher extends Watcher {
constructor(options) {
super(options);
constructor(options, build) {
super(options, build);

this.watcher.on('add', this.didAdd.bind(this));
this.watcher.on('delete', this.didDelete.bind(this));
Expand Down
11 changes: 8 additions & 3 deletions lib/models/watcher.js
Expand Up @@ -12,10 +12,12 @@ const eventTypeNormalization = {
change: 'changed',
};

const ConstructedFromBuilder = Symbol('Watcher.build');

module.exports = class Watcher extends CoreObject {
constructor(_options, build) {
if (!build) {
throw new Error('instantiate Watcher with await Watcher.build().watcher, not new Watcher()');
if (build !== ConstructedFromBuilder) {
throw new Error('instantiate Watcher with (await Watcher.build()).watcher, not new Watcher()');
}

super(_options);
Expand All @@ -25,9 +27,12 @@ module.exports = class Watcher extends CoreObject {
}

static async build(_options) {
let watcher = new Watcher(_options, true);
let watcher = new this(_options, ConstructedFromBuilder);
await watcher.setupBroccoliWatcher(_options);

// This indirection is because Watcher instances are themselves spec
// noncompliant thennables (see the then() method) so returning watcher
// directly will interfere with `await Watcher.build()`
return { watcher };
}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/models/server-watcher-test.js
Expand Up @@ -12,12 +12,12 @@ describe('Server Watcher', function () {
let analytics;
let watcher;

beforeEach(function () {
beforeEach(async function () {
ui = new MockUI();
analytics = new MockAnalytics();
watcher = new MockServerWatcher();

new ServerWatcher({
await ServerWatcher.build({
ui,
analytics,
watcher,
Expand Down

0 comments on commit 4c1a28f

Please sign in to comment.