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.

Flatten `plugin.config.properties`

See original GitHub issue

At the moment plugin configuration properties can be declared like this:

module.exports = {
  name: 'netlify-plugin-example',
  config: {
    properties: {
      url: { type: 'string' }
    }
  },
  onInit({ pluginConfig: { url } }) {
    console.log(url)
  }
}

We had a discussion with @DavidWells where he proposed flattening it to simply config.

module.exports = {
  name: 'netlify-plugin-example',
  config: {
    url: { type: 'string' }
  },
  onInit({ pluginConfig: { url } }) {
    console.log(url)
  }
}

I agree this is a simpler and more natural DX. There are two reasons config.properties is currently used instead of simply config.

  1. This follows the JSON schema standard, where required is an array of property names, not a boolean.
module.exports = {
  name: 'netlify-plugin-example',
  config: {
    required: ['url'],
    properties: {
      url: { type: 'string' }
    }
  },
  onInit({ pluginConfig: { url } }) {
    console.log(url)
  }
}

If we were to use a boolean instead, users would need to remove that property if they wanted to re-use the JSON schema.

const plugin = {
  name: 'netlify-plugin-example',
  config: {
    url: { type: 'string', required: true }
  },
  onInit({ pluginConfig: { url } }) {
    console.log(url)
  }
}

// Invalid: this is not a standard JSON schema
validateWithJsonSchema(data, plugin.config.url)
  1. This allows validating properties as a whole instead of individually with the JSON schema validation keywords related to object properties: minProperties, maxProperties, additionalProperties, patternProperties, propertyNames and dependencies. This allows for properties validation like:
  • if foo is defined, then bar should be defined.
  • foo and bar are exclusive
  • foo can also be called foo-* where * is any sequence of digits
  • explicitly forbidding or allowing custom properties
  • and more
module.exports = {
  name: 'netlify-plugin-example',
  config: {
    // If 'url' is defined, 'host' must be defined too
    dependencies: { url: ['host'] },
    properties: {
      url: { type: 'string' },
      host: { type: 'string' }
    }
  },
  onInit({ pluginConfig: { url } }) {
    console.log(url)
  }
}

Now if we chose not to follow the JSON schema standard, we could instead whitelist specific validation keywords and forbid those as property names, so they can be use while still flattening config.properties.* to config.*.

module.exports = {
  name: 'netlify-plugin-example',
  config: {
    url: { type: 'string' },
    host: { type: 'string' },
    dependencies: { url: ['host'] }, 
  },
  onInit({ pluginConfig: { url } }) {
    console.log(url)
  }
}

We could also introduce a separate property to put those validation keywords together in the same namespace.

Working with outputs (#611) I realized that flattening properties might make sense from a DX standpoint, but I still have concerns about the two points above.

I wanted to know if I could gather other people’s opinions here to reach the best solution? @RaeesBhatti @erquhart @verythorough @jlengstorf @philhawksworth

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

4reactions
erquhartcommented, Feb 21, 2020

The core requirement of placing properties directly on config makes sense. The only reason not to do it is strict adherence to JSON schema, which I’m okay with not being tied to - we can consider the config/inputs API “inspired by” JSON schema.

@ehmicky communicated the following understood requirements for implementing:

  • flatten plugin.config.properties.* to plugin.config.*
  • use a required boolean option instead of an array of properties
  • remove the cross-properties validation keywords for the moment

I’ll also add the following:

  • update any repo documentation stating that we use JSON schema to the “inspired” verbiage

We’ll move forward with that plan, any other topics covered in the conversation above should be moved to dedicated issues.

2reactions
verythoroughcommented, Feb 20, 2020

Good points about the object vs array question. In either case, it doesn’t seem to impact the question of flattening (which is mainly why I brought it up). If anyone did want discuss whether to change from objects to arrays, we should probably start a separate issue for that conversation. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maven Flatten Plugin
Flatten both direct and transitive dependencies. This will examine the full dependency tree, and pull up all transitive dependencies as a direct ...
Read more >
flatten plugin is replacing ${} properties when profiles ... - GitHub
Suppose that we have two POM files, the POM Parent A and the POM Child B. Inside the POM A we declare a...
Read more >
The Flatten Maven plugin - A Java geek
You can configure which sections you keep and don't via the POM. ... The Maven Flatten plugin separates between build and consumer POMs....
Read more >
The Flatten Maven plugin - foojay.io
You can configure which sections you keep and don't via the POM. ... The Maven Flatten plugin separates between build and consumer POMs....
Read more >
Maven flatten plugin not working does not substitute my ...
You need to move the plugin from <pluginManagement><plugins> to <plugins> . Alternatively, you can leave it there and just add a short ...
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