简体   繁体   中英

How to Override Meteor Core Packages in a Project?

For a Meteor project I want to make changes to a Meteor Core library file.

Is this possible and if so, how?

So far I've tried just copying the files into my project directory hoping that the respective Objects are just overwritten from the originals but the problem herewith was that dependent functions or variables were only defined locally.

Then I tried to git clone them into the project's packages directory like you would do with a community package, but that didn't function either since the clone command failed ( fatal: repository ... not found ) and also the package is not explicitly called in the .meteor/packages file.

Any idea?

Meteor allows having local packages in a project, including ones that override existing (community or core) packages.

While overriding a community package locally often simply requires cloning (or extracting or adding as submodule) the GitHub repository into the /packages folder, core packages currently live inside sub-directories of the main meteor/meteor repository, which makes cloning them trickier.

Overriding a core package may require you to manually apply changes to the package as Meteor or the package update (as Meteor used to be dependent on specific package versions).

Therefore, before taking such step, make sure that you actually need to do it .

Make sure that you cannot you make your changes using local files or your own local package (eg, by wrapping or replacing a function or monkey-patching it).

There are a few approaches that I used in order to override a core package.

Clone the entire repository and link the directories

This is useful if you want to contribute your changes to the project. You should probably fork the repository and clone your own fork.

  1. Clone the meteor repository:

    \ngit clone https://github.com/meteor/meteor.git \n

    or

    git clone git@github.com:<username>/meteor.git if you forked it

  2. Link the package directory (in your project's packages directory)
    \nln -s ../../(...)/meteor/packages/ \n
    You can checkout the desired branch/commit and copy them to the local packages directory instead, of course.

Statically download only the package directory

There is a neat trick that allows you to download a given directory from GitHub using svn .

This is obtained by issuing:

svn export https://github.com/meteor/meteor/[trunk|branches/]/packages/

for example:

cloning ddp-client from the devel branch:

svn export https://github.com/meteor/meteor/branches/devel/packages/ddp-client

or from the master branch:

svn export https://github.com/meteor/meteor/trunk/packages/ddp-client

Notes:

  1. As mentioned earlier, you may need to manually apply changes if you update Meteor.
  2. Don't forget to add the package to the project ( meteor add <package> ) if you haven't already.
  3. Meteor is expected to switch to NPM at some point (possibly in Meteor v1.5), so make sure to use the methods specified in this answer only for meteor's own packaging system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM