question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support async plugins / extensions

See original GitHub issue

Code I’d like to write:

import { ghauth } from "../util/promised_ghauth"
import { Context } from "../context"

const setGithubCredentials = async (context: Context) => {
  context.githubAuth = await ghauth()
}

module.exports = setGithubCredentials

and

import { getSettings } from "../util/settings"
import { Context } from "../context"

const setSettings = async (context: Context) => {
  context.settings = await getSettings()
}

module.exports = setSettings

The GH Auth prompt does a bunch of pre-requisite work, it’s feasible that I can add a function to handle it per-command but it’s basically something I want on the first time user flow anyway.

I took a quick look at this and it seems like it’d add async code everywhere so opted to not PR right now and to move it to a function my command can handle as I only have one 😉

Opened so people can decide if this is something you want

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
RichiCoder1commented, Jan 15, 2019

I really like the idea of is-outdated being built in to Gluegun. Perhaps on toolbox.meta.outdated() as an async function?

Indeed! I like it. Though it might also be good to have it on builder too. Something like:

// ready
const { build } = require('gluegun')
const package = require('../package.json')

// aim
const movieCLI = build('movie')
  .src(`${__dirname}/core-plugins`)
  .plugins('node_modules', { matching: 'movie-*' })
  .help()
  .version()
  .checkForUpdates(package.name, package.version)
  .defaultCommand()
  .create()

// fire!
movieCLI.run()

Probably worth it’s own issue.

1reaction
RichiCoder1commented, Jan 15, 2019

I’m realizing that my use case may be slightly different than the authors. But the idea would be like this: https://github.com/infinitered/gluegun/pull/449

Basically so I can have an extension like: companySettings.ts which has

import { getSettingsAsync } from "../my/helper";

function async setupPluginRemoteConfig(toolbox: MyCompanyToolbox) {
    const settings = await getSettingsAsync();
    toolbox.plugin = ((plugin) => {
        plugin.settings = settings;
    })(toolbox.plugin || {}):    
}
export default setupPluginRemoteConfig;

Edit: or something like updateCheck.ts

import { isOutdated } from 'is-outdated';
const  = require('./package.json');
 
function async checkForNewVersion(toolbox) {
    const { version, outdated } = await isOutdated(pkg.name, pkg.version);
    const { print: { warn } } = toolbox;
    if (outdated) {
        warn('The latest version of this app is %s', res.version);
        warn(`Please updated it with: npm update -g ${pkg.name}`);
    }
}
export default checkForNewVersion;

Though there’s an argument to be made for the latter being in gluegun itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AsyncPanel - Client-side Extensions - Atlassian Developer
An asynchronous panel extension allows the creation of custom HTML content in a container provided by the plugin system. This API works similar...
Read more >
Chrome Extensions: Using promises
Promises are designed to deliver asynchronous results, both success and failure. A failure in a promise (a promise rejection) is handled ...
Read more >
Updates to synchronous autoload of extensions in Visual ...
First, most extensions now support async background loading, which improves startup and solution load performance across the board.
Read more >
Can extensions use async/await #1556 - microsoft/vscode
Using async/await works fine in a simple samples: https://github.com/egamma/vscode-extension-async (target set to ES6).
Read more >
Javascript Async & Defer - Plugins - DayCounts
Install and publish the plugin. In the "scripts to modify" field, enter the path to the scripts to be loaded either in async...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found