@madeji/npm-package-test-1
v1.1.0
Published
A test for npm package
Downloads
28
Readme
npm-package-test-1
A test for npm package.
0. Create a git repository and a package
git initorgit clone xxx.gitignore:libandnode_modulesnpm initforpackage.json("type": "module")- change name to
@your-name-space/package-name(scoped package)- you need to run
npm publish --access public(the first time)
- you need to run
- change name to
1. tsconfig.json and source files
npx tsc --init(tsconfig.json)
{
"compilerOptions": {
"declaration": true,
"declarationDir": "lib/types",
"target": "es2016",
"moduleResolution": "node"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "lib"]
}- src:
ask.ts,answer.ts,index.ts
2. rollup settings
npm i -D rollup @rollup/plugin-typescript rollup-plugin-deleterollup.config.js: input, output (file, format), pluginsnpm run build("build": "rollup -c")
3. publish settings
- update
package.jsonwithexports(what others can use your package) (mainfor CommonJS entry point,moduleorbrowserfor esm entry point, andtypes.exportsreplaces esm and types) - set
filesfor publish (npm publish --dry-run: see the files)- default output files:
package.json,LICENSE,README.md
- default output files:
npm:
0.1 npm whoami
0.2 npm login
npm publish --access public
4. @changesets/cli setup
git switch -c changesets-installnpm i -D @changesets/clinpx changeset init- change
"access": "restricted"to"access": "public"in.changeset/config.json
5. github workflows setup
- add new file
.github/workflows/release.yml - add scripts in
package.json:"release-package": "npm run build && npx changeset publish"(for github actions to publish)
5.1 github tokens and secrets
- github -> settings -> Developer Settings -> Personal access tokens -> Tokens (classic) (check repo and workflow)
- a repo -> settings -> secrets and variables -> actions -> new repository secrets
- put the name of the secrets to release.yml
5.2 npm tokens
- npm -> access tokens -> name -> publish
- github step 2
- github step 3
6. publish with changesets
- a repo -> Settings -> Branches -> add classic branch protection rule -> name and Require a pull request before merging (not Require approvals)
npx changeset(after changing our code, before committing)- commit and push
- merge the PR created by committing
- merge the versioning PR created by changesets (Version Packages #n, with new version, updating changelog, deleting the changeset created by changesets; will run changesets again, and publish (through github actions), add a tag in github)
7. pre release
7.1 link
- provider:
npm link(npm run buildbefore linking) (npm unlink -g) - consumer: npm link provider-package-name
(npm root -g)
7.2 pre release
- setup pre-release branch
git switch -c pre-releasenpx changeset pre enter alpharelease.yml: addpre-releasethe same level asmainin branches- add, commit and push
- do your job in another branch frome the pre-release branch
- coding
npx changesetand commit and push
- merge
- Open a PR to the pre-release branch and merge to it
- automatically: changesets actions will opens a versioning PR in pre-release mode
- merge this versioning PR (will create a alpha package)
- merge to main
- switch to a new branch
- exit the pre-release mode and open a PR to merge to the main branch (
npx changeset pre exit) - add, commit and push
- merge the exit branch to main
- merge the PR of changesets to publish the new version
