Informal notes on working with org-scoped projects in the npm registry.
- Create a new org-scoped project
- Modify an existing project to have an org scope
- Publish
dist
or other untracked files - References
- Initialize the project directory:
mkdir lame
- Create the
lame
project on github - Initialize the git project locally:
git init
- Associate the local project with github:
git remote add origin https://github.com/brainthinks/lame-test.git
- Add some stuff to the project
touch README.md
touch .gitignore
touch .npmrc
- Add the
.npmrc
file with the following:scope=bandress-dumbasses
access=public
- Initialize the node project:
yarn init
- Provide the name of the project as
@bandress-dumbasses/lame
- Commit and push all the files:
git add .
git commit -m "message"
git push -u origin master
- Version the project:
yarn version --new-version 0.0.1
git push --tags
- Publish the project
npm publish
Observe that the project was published to the org's namespace.
- Add the
.npmrc
file that contains thescope
andaccess
configurations - Add the
repository
property to thepackage.json
file, where the value is the git url- e.g.
"repository": "https://github.com/brainthinks/lame-test.git",
- e.g.
- Find all instances in the project where the
name
property from thepackage.json
is used- You may need to change them from
name
toname.split('/').pop()
- You may need to change them from
- Commit and push all changes
- Version the project:
yarn version --new-version 0.0.1
- Publish the project
npm publish
We have a few projects that have build steps which result in dist
(as opposed to src
) files that need to be included with the published version of the project. Here are the steps I used to implement the build and clean-up steps as part of the publish lifecycle:
- add
dist
to your.gitignore
:- the
dist
files shouldn't be source-controlled - the
dist
files will be version-controlled via npm packages
- the
- add a
prepublish
script:- e.g.
"prepublish": "npm run build",
- e.g.
- add a
postpublish
script:- e.g.
"postpublish": "rm -rf dist",
- e.g.
- Create a
.npmignore
filecp .gitignore .npmignore
- remove the
dist
entry from.npmignore
- you will have to keep
.npmignore
maintained along with.gitignore
now...