Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: add a way to register dependencies by plugins #877

Open
sapphi-red opened this issue Dec 25, 2024 · 0 comments
Open

Feature Request: add a way to register dependencies by plugins #877

sapphi-red opened this issue Dec 25, 2024 · 0 comments

Comments

@sapphi-red
Copy link

sapphi-red commented Dec 25, 2024

Plugins may rely on a different file but there's no way to tell that information to lightningcss.

For example, the plugin below depends on .json placed next to the input file.

export function fooVisitor() {
  /** @type {string[]} */
  let currentStyleSheetSources
  return {
    StyleSheet(stylesheet) {
      currentStyleSheetSources = stylesheet.sources
    },
    Rule: {
      unknown: {
        foo(rule) {
          const from = currentStyleSheetSources[rule.loc.source_index]
          const importedFile = JSON.parse(fs.readFileSync(from + '.json', 'utf8'))
          const cssAst = convertJsonToAst(importedFile) // convert json to lightningcss somehow
          return cssAst
        },
      },
    },
  }
}

To make the re-transform happen when the json file is changed, the user that calls lightningcss.bundle needs to know which css file depends on which json file.

Simply having a convention (e.g. expose dependencies property from the visitor) would work if composeVisitors supports it, but having the information in TransformResult.dependency feels natural.

For reference postcss, achieves this via messages.
https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#31-use-messages-to-specify-dependencies
Maybe it makes sense to have a way to emit warnings from visitors as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant