1

Project A contains a few functions and data models I use in diff't repos, all tied to the same product. I'd like to turn them into an npm module, but without extracting the code from project A.

When I see other modules on npm, they generally tie to a github repo that contains all the source code, as well as a full stack to run/modify the module.

Does this mean I have to extract the code from project A into its own repository, build/configure a stack to allow it to run in isolation from project A, and then import it back into project A & other projects?

Or is it possible to just export the functions w/o a full stack, and without moving the code from my main project?

an attempt to pre-empt 'duplicate' comments:

this Q talks about working with an existing module, which doesn't answer my concern, as it has to do w/ worrying about pull requests being merged on time

npm link, discussed here, looks like it'd do the trick if I'd already extracted the code from the project, but I'd like to avoid that.

Community
  • 1
  • 1
Brandon
  • 7,736
  • 9
  • 47
  • 72
  • 1
    (not the downvoter) you could extract the code into its own repo, but still use it inside your project as a git sub-module. – Emile Bergeron Sep 27 '16 at 16:02
  • thx emile--reading on it and this looks like the best path. do you know if it's standard for npm modules in their own repos to include the full stack for running them? or is that something specific to projects intended to draw open source contributors? – Brandon Sep 27 '16 at 16:11
  • 1
    Ideally, it's to test them and ease the development, but it's totally optional. You could only put a JavaScript file and the `package.json` and it would work. – Emile Bergeron Sep 27 '16 at 16:13
  • 1
    ah great, that's a relief. if you'll make that an answer, i'll gladly accept it – Brandon Sep 27 '16 at 16:18

1 Answers1

2

If you really want to share a snippet through npm but still use the code at the same place in your project, you could extract the code into its own repo, but still use it inside your project as a git sub-module.

Create a submodule repository from a folder and keep its git commit history

Do you know if it's standard for npm modules in their own repos to include the full stack for running them?

Ideally, it's to test them and ease the development, but it's totally optional. You could only put a JavaScript file and the package.json and it would work.

Community
  • 1
  • 1
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129