Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Provide package.json fields so we can defer requiring packages' main modules - #9687

Merged
maxbrunsfeld merged 15 commits into
masterfrom
mb-deprecate-load-time-package-code
Nov 30, 2015
Merged

maxbrunsfeld merged 15 commits into
masterfrom
mb-deprecate-load-time-package-code

Conversation

@maxbrunsfeld

Copy link
Copy Markdown
Contributor

The Problem

In order to interoperate with the deserialization of the Atom workspace, there are some APIs that packages have to call as soon as they are loaded (as opposed to inside of their activate method):

  • atom.views.addViewProvider
  • atom.deserializers.add

This forces Atom to load all packages' main modules at an early point in startup, even though many packages can be activated lazily. This allows packages to affect the app even if they are disabled, and may reduce our ability to optimize startup time.

The Proposed API Change

This PR will add 3 new optional fields to packages' package.json files:

  • configSchema - an object specifying the package's config schema
  • deserializers - an object whose keys are deserializer names, and whose values are paths to files that export deserialization functions
  • viewProviders - an array whose values are paths to files that export view-providing functions. These will need to work a little bit differently than normal view providers, because they can't be specified in relation to a particular model constructor. Maybe they will just be functions that return null if they do not apply to the given model.

It will also add a deprecation warning when packages accesses the atom global at load time.

Changes to Package Loading

When packages use the new package.json fields, we can defer loading any of their code until it is used, because we can know that there is no reason for them to run code at load time.

  • The main module will be loaded when the package is activated.
  • View providers will be loaded when either the package is activated.
  • Deserializers will be loaded when deserialize is called with one of the specified deserializer names.

Once the deprecation period is over, we can use this approach for all packages.

Todo

  • Respect the 3 new fields in package.json.
  • Use new fields to optimize package loading
    • If a package has configSchema, viewProviders, or deserializers, don't load its main module until it is activated.
    • Don't load a package's view providers until either it is activated or one of its deserializers is used.
  • Remember which packages use the atom global at require time, and for those that don't, don't require the main module until they are activated.

/cc @nathansobo

@nathansobo

Copy link
Copy Markdown
Contributor

Great. We've needed this for a very long time. Some thoughts on the key names.

  • Seems like they should be camelCased rather than dash-separated to blend in with other keys in package.json.
  • We haven't prefixed several keys with the word "atom" thus far. Maybe we should have, but these are Atom packages after all and starting now seems to introduce inconsistencies.

@maxbrunsfeld
maxbrunsfeld force-pushed the mb-deprecate-load-time-package-code branch from 8c3b782 to a0a402c Compare November 19, 2015 22:12
@maxbrunsfeld

Copy link
Copy Markdown
Contributor Author

Some thoughts on the key names...

😭 D'oh; of course. Updated.

@nathansobo How do you think the view providers should work? I was thinking we could have a simple array of view providers functions that will always be called, but should return null/undefined unless they apply to a given model.

@as-cii as-cii mentioned this pull request Nov 23, 2015
@maxbrunsfeld maxbrunsfeld changed the title Deprecate calling atom APIs at package load time Provide package.json fields so we can defer requiring packages' main modules Nov 23, 2015
@maxbrunsfeld
maxbrunsfeld force-pushed the mb-deprecate-load-time-package-code branch from e09b3fb to 5f1947e Compare November 23, 2015 23:53
maxbrunsfeld pushed a commit that referenced this pull request Nov 30, 2015
Provide package.json fields so we can defer requiring packages' main modules
@maxbrunsfeld
maxbrunsfeld merged commit 3827b19 into master Nov 30, 2015
@maxbrunsfeld
maxbrunsfeld deleted the mb-deprecate-load-time-package-code branch November 30, 2015 23:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants