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

Allow resolver plugins to invalidateOnEnvChange #8094

Closed
tonyhallett opened this issue May 14, 2022 · 2 comments · Fixed by #8103
Closed

Allow resolver plugins to invalidateOnEnvChange #8094

tonyhallett opened this issue May 14, 2022 · 2 comments · Fixed by #8103

Comments

@tonyhallett
Copy link
Contributor

🙋 feature request

Allow resolver plugins to return in result - invalidateOnEnvChange string array

🤔 Expected Behavior

In a similar manner to how other plugin types can invalidateOnEnvChange - see Config type https://parceljs.org/plugin-system/transformer/#Config

😯 Current Behavior

Cannot invalidateOnEnvChange

💁 Possible Solution

ResolverRunner resolve

    let invalidateOnFileCreate = [];
    let invalidateOnFileChange = [];
    let invalidateOnEnvChange = [];//************************** and ensure that it available in the returned object
    for (let resolver of resolvers) {
      try {
        let result = await resolver.plugin.resolve({
          specifier,
          pipeline,
          dependency: dep,
          options: this.pluginOptions,
          logger: new PluginLogger({origin: resolver.name}),
        });

        if (result) {
          if (result.meta) {
            dependency.resolverMeta = result.meta;
            dependency.meta = {
              ...dependency.meta,
              ...result.meta,
            };
          }

          if (result.priority != null) {
            dependency.priority = Priority[result.priority];
          }

          if (result.invalidateOnFileCreate) {
            invalidateOnFileCreate.push(...result.invalidateOnFileCreate);
          }

          if (result.invalidateOnFileChange) {
            invalidateOnFileChange.push(...result.invalidateOnFileChange);
          }

          if (result.invalidateOnEnvChange ) { // *********************
            invalidateOnEnvChange .push(...result.invalidateOnEnvChange );
          }

PathRequest after ResolverRunner

async function run({input, api, options}: RunOpts) {
  let configResult = nullthrows(
    await api.runRequest<null, ConfigAndCachePath>(createParcelConfigRequest()),
  );
  let config = getCachedParcelConfig(configResult, options);
  let resolverRunner = new ResolverRunner({
    options,
    config,
  });
  let result: ResolverResult = await resolverRunner.resolve(input.dependency);

  if (result.invalidateOnEnvChange) { //***************************************************
    for (let env of result.invalidateOnEnvChange) {
      api.invalidateOnEnvChange(env);
    }
  }

🔦 Context

I have created a Resolver that aliases through an environment variable instead of package.json.
I would like to invalidateOnEnvChange.

💻 Examples

(https://gist.github.com/bvaughn/25e6233aeb1b4f0cdb8d8366e54a3977?permalink_comment_id=4166747#gistcomment-4166747)

@mischnic
Copy link
Member

Could you open a PR with your changes? That looks good to me, we just need a test case.

@tonyhallett
Copy link
Contributor Author

@mischnic I will create a pull request in the coming days

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

Successfully merging a pull request may close this issue.

2 participants