Skip to content
This repository has been archived by the owner. It is now read-only.

Add sections on creating an npm package and overriding a published one #381

Merged
merged 4 commits into from Apr 16, 2016
Merged

Add sections on creating an npm package and overriding a published one #381

merged 4 commits into from Apr 16, 2016

Conversation

@lorensr
Copy link
Member

@lorensr lorensr commented Apr 16, 2016

The previously linked npm explanation of creating an npm package is heavyweight for a Meteor dev's purposes (and doesn't cover the common case of private code). Using their method, you need to publish and update after each change. A Meteor dev is usually creating a package in support of their app, and is usually developing it inside the app, so using source control makes more sense. Also, the source control way is more familiar coming from packages/.

Also fixes #378

git add -f node_modules/left_pad/
```

Now you can edit the package, commit, and push, and your teammates will get your version of the package. To ensure that your package doesn't get overwritten during an `npm update`, change the default caret version range in your `package.json` to an exact version. Before:
Copy link
Member Author

@lorensr lorensr Apr 16, 2016

Choose a reason for hiding this comment

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

Should the package name be changed instead of using exact version?

Loading

Copy link
Contributor

@tmeasday tmeasday Apr 16, 2016

Choose a reason for hiding this comment

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

Alternatively the package could be removed completely from the package.json (although that won't help with dependencies)

Loading

Copy link
Contributor

@tmeasday tmeasday Apr 16, 2016

Choose a reason for hiding this comment

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

Another option is to set it to a path. Maybe this is better?

https://docs.npmjs.com/files/package.json#local-paths

Loading

When you are developing a new npm package for your app, there are a couple ways to include the package in your app:

1. Place the package in your app's `node_modules/` directory, and add the package to source control. Do this when you want everything in a single repository.
1. Place the package outside your app's directory in a separate repository and use `npm link`. Do this when you want to use the package in multiple apps.
Copy link
Contributor

@tmeasday tmeasday Apr 16, 2016

Choose a reason for hiding this comment

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

Can we link to the docs for npm link? Also I think it's important to mention this won't go out to others developing your app.

Loading

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Apr 16, 2016

Thanks a lot @lorensr! I think this is useful stuff.

I made a few comments. I do just wonder if the best practice is to commit things in node_modules/ or a file:// dependency to another directory.

Loading

@lorensr
Copy link
Member Author

@lorensr lorensr commented Apr 16, 2016

Thanks! That would be better for avoiding npm overwriting, but where should they go? packages/? In which case the dependency would be "my-package": "file:packages/my-package"

They shouldn't interfere w/ atmo packages because they don't have a package.js? But it might be nice for a dev to be able to know which type of package they are without looking for a package.js. Maybe packages/npm/my-package/ or private/npm/? Will meteor follow a file dep in package.json into private/*?

Loading

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Apr 16, 2016

Oh, yeah, putting in another directory is a bad idea because it'll stuff up node's loading (like you'll need to require('path/to/package') rather than require('package')). Scratch that.

Loading

@lorensr
Copy link
Member Author

@lorensr lorensr commented Apr 16, 2016

Ah, got it.

Finished changes.

Loading

@tmeasday
Copy link
Contributor

@tmeasday tmeasday commented Apr 16, 2016

Great work!

Loading

@tmeasday tmeasday merged commit 763fb95 into meteor:master Apr 16, 2016
2 checks passed
Loading
@stubailo
Copy link
Contributor

@stubailo stubailo commented Apr 16, 2016

Awesome contribution!

Loading

@lorensr
Copy link
Member Author

@lorensr lorensr commented Apr 16, 2016

Thanks!

On Saturday, April 16, 2016, Sashko Stubailo notifications@github.com
wrote:

Awesome contribution!


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#381 (comment)

Loading

@lorensr lorensr deleted the creating-npm branch Apr 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants