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

Feat/add config hook #864

Merged
merged 3 commits into from Aug 22, 2020
Merged

Conversation

MoonBall
Copy link
Contributor

Changes

do the stage 1 and stage 2 of #621

Testing

@MoonBall MoonBall requested a review from a team as a code owner August 21, 2020 08:39
@vercel
Copy link

vercel bot commented Aug 21, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/3mra2hcje
✅ Preview: https://snowpack-git-fork-moonball-feat-add-config-hook.pikapkg.vercel.app

Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Left some comments

packages/snowpack/src/config.ts Outdated Show resolved Hide resolved
let needWarnAfterCreated = false;
let warned = false;
let plugin: SnowpackPlugin | null = null;
let name: string;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's an ordering problem here, where "name" may not yet be defined. Can execPluginFactory take an additional name argument, to make it explicit for the logger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We maybe not know the name of plugin when we call the execPluginFactory function. So the name is assigned by name = plugin.name || pluginFactory.name.
The assign of name is executed before the executing of logWarn.
There is no case that name is undefined through running the yarn test.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering issue looks like it's at:

plugin = pluginFactory(configProxy, pluginOptions) as SnowpackPlugin;
  // This triggers the proxy, which triggers logWarn, which references `name` before it's set
name = plugin.name || pluginFactory.name;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the name of plugin is known after the pluginFactory returns, I delay the warn until the return of pluginFactory if plugin references snowpackConfig while generating plugin object.

Copy link
Contributor Author

@MoonBall MoonBall Aug 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering issue looks like it's at:

plugin = pluginFactory(configProxy, pluginOptions) as SnowpackPlugin;
  // This triggers the proxy, which triggers logWarn, which references `name` before it's set
name = plugin.name || pluginFactory.name;

It's not happen. The assign of name is synchronously executed after the pluginFactory executes and returns.

Edit: if executing pluginFactory triggers the proxy, I set a flag needWarnAfterCreated = true and execute logWarn after assign of name.

packages/snowpack/src/config.ts Outdated Show resolved Hide resolved
packages/snowpack/src/types/snowpack.ts Outdated Show resolved Hide resolved
Copy link
Owner

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I may move a few things around before release but overall this is great! Thanks for tackling!

@FredKSchott FredKSchott merged commit 5b0fe76 into FredKSchott:master Aug 22, 2020
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

Successfully merging this pull request may close these issues.

None yet

2 participants