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.

Consider refactoring presets config into repo/package

See original GitHub issue

Summary Following a discussion with @brendankenny on configuring Lighthouse, I improved the docs a little recently around using and extending presets with the node module programmatically. (https://github.com/GoogleChrome/lighthouse/pull/7354)

You can currently extend a preset like so:

{
    extends: 'lighthouse:default',
    settings: {
        emulatedFormFactor: 'desktop',
        ...
    },
}

The limitation is that you can only use lighthouse:default or lighthouse:full in this way. I clarified this limitation in the docs after I was unable to extend one of the other presets I found in the lighthouse-core/config directory.

Option 1: We could update the logic to allow you to extend any preset found in the lighthouse-core/config. However, the problem with that is you have to make sure the configs are named in a particular format to be picked up. It’s also not very visible to the user about what presets are available. The fact I went looking in Lighthouse internals is a bit of a red flag here.

The other big issue for me is that we’re basically re-inventing object composition. In JavaScript, we extend objects with Object.assign (or using spread operator), so it seems totally unnecessary to be building our own extends logic here.

So I’m not super keen on this personally.

Option 2:

What if we created a lighthouse-presets repository or at least a package that contains a number of useful preset configs that you can import into your own project? lighthouse-core could also bring it in interally as a dependency so it’s all managed in one place.

At that point, if a user wants to extend any of those presets, they can import one and do an object merge with their own config, rather than relying on the extends property. It seems like a much more natural way to me to do in my opinion.

const lighthouse = require('lighthouse');
const desktopPreset = require('lighthouse-presets/desktop'); 

const myConfig = Object.assign({}, desktopPreset, {
    cpuSlowdownMultiplier: 5
});

await lighthouse(url, opts, myConfig);

I don’t know how many presets we’re likely to have, but with more and more settings being available, there’s a chance we could see a lot more standard variations, and with a separate repository or package, there’s more visibility of what’s available.

Option 3:

We don’t think configs will scale and the current mechanism is good enough, provided we remain clear in the docs. This is still a perfectly valid option.

I’m happy to help around this.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
patrickhulcecommented, Mar 20, 2019

If it’s a string, look up the config as normal (including any in the directory). If the config object is passed in, use that as the base config and continue to merge that and the user’s config internally.

This sounds good to me!

Or just have a shortcut export to the configs directory.

This also works for me. I’m a big fan of export aliases 👍

It seems like there are a few concrete steps then to make this happen:

  • Add support for recursively extending configs. (Fairly difficult and complicated)
  • Add support for extends to use any preset, not just lighthouse:default/lighthouse:full. (Relatively easy)
  • Add support for accepting an object as the extends property. (Relatively easy)
  • Add folder for aliasing and exporting the presets. (Relatively easy)

The recursive extension is definitely the hardest step in here. What are we going to do when multiple configs have onlyAudits for example, concat them or override? Lots to think through here for each property that we didn’t have to worry about when it’s just full configs that are being extended.

This step in particular seems like work that would require a decent amount of care in implementing, so I think it makes sense to validate this need is broad enough to prioritize before getting started.

Open call for +1s if you’ve needed this functionality before repo watchers 😃

0reactions
connorjclarkcommented, Jun 9, 2020

We’re open to making the config more extensible, but probably not gonna put these files in a separate repo. (extends implies more than is possible atm). May come back to this in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating from packages.config to PackageReference formats
Details on how to migrate a project from the packages.config management format to PackageReference as supported by NuGet 4.0+ and VS2017 and ...
Read more >
conventional-changelog/standard-version - GitHub
This preset: Adheres closely to the conventionalcommits.org specification. Is highly configurable, following the configuration specification maintained here. We ...
Read more >
Autowire doesn't work after moving subpackage to new package
Action: Consider defining a bean of type 'com.company.myappcommon.repository.myVersionsRepository' in your configuration. @Autowired was working ...
Read more >
8.2.3. Displaying Package Information
Listing Files Contained in a Package. repoquery is a program for querying information from yum repositories similarly to rpm queries. You can query...
Read more >
Measurement and refactoring for package structure based on ...
In this paper, we propose two metrics of cohesion and coupling to characterize package structure. We consider not only the dependencies of ...
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