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

Fixing #504. Jspm compatibility and static declaration of dependencies #614

Closed
wants to merge 2 commits into from

Conversation

joeldenning
Copy link

@joeldenning joeldenning commented Oct 14, 2016

This fixes #504. There are definitely pros and cons to doing this, and am interested to hear your thoughts on what is best for the svgo project. My opinion, of course, is that this the pros outweigh the cons, but I can see the other side too.

Pros:

  1. This makes svgo compatible with JSPM. Up until now, anybody who uses jspm and depends on svgo (directly or indirectly) has to create a configuration file in the jspm registry for each version of svgo. @MeoMix did this for [email protected], and now I have a pull request to do so for 0.7.1. Merging this svgo pull request will make it so that there will be no need anymore to create a configuration file in the jspm registry for each version of svgo.
  2. This will make upgrading svgo to es6 modules (instead of commonjs) easier. I don't know if there are plans to do that or not, but once you switch to import, System.import(), or import(), you can no longer synchronously load dynamic plugin code like you can with require. Instead, you can either import all of the plugins upfront (similar to what I've done in this pull request) or you can change the preparePluginsArray function to be an asynchronous function that returns a System.import() promise.

Cons:

  1. The pluginMap is sort of an annoying manifesty thing that introduces one more step to the process of writing a new svgo plugin.

@@ -73,8 +118,11 @@ function preparePluginsArray(plugins) {
plugin = setupCustomPlugin(key, item[key]);

} else {
if (!pluginMap[key]) {
throw new Error("Unknown plugin '" + key + "'");
Copy link
Author

Choose a reason for hiding this comment

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

This is to maintain a similar behavior to what happens when you try to require a plugin that doesn't exist. Now that the plugins are not being required in this function, this Error maintains backwards compatibility of what should happen for non-existent plugins.

@@ -73,8 +118,11 @@ function preparePluginsArray(plugins) {
plugin = setupCustomPlugin(key, item[key]);

} else {
if (!pluginMap[key]) {
throw new Error('Unknown plugin "' + key + '"');
Copy link
Author

Choose a reason for hiding this comment

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

This is to maintain a similar behavior to what happens when you try to require a plugin that doesn't exist. Now that the plugins are not being required in this function, this Error maintains backwards compatibility of what should happen for non-existent plugins.

@joeldenning
Copy link
Author

Looks like the build is failing only in node 6. The tests passed but after the tests coverall failed and I'm not sure exactly why. Any ideas on why I'm getting Bad response: 422 {"message":"Couldn't find a repository matching this job.","error":true} from the node 6 build?

@GreLI
Copy link
Member

GreLI commented Oct 15, 2016

That happens sometime. Dont't worry, it should be ok.

@GreLI
Copy link
Member

GreLI commented Nov 13, 2016

I don't like the implementation since it loads all plugins including non-used one. It'll certainly slow down svgo execution for all users which I cannot accept.

Also I cannot verify that it solves the issue. Is there a less kludgy solution?

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.

Please consider using static declaration of plugin dependencies.
2 participants