https://github.com/yarnpkg/example-yarn-package
An example package to be used for yarn testing and documentation
https://github.com/yarnpkg/example-yarn-package
Last synced: 10 months ago
JSON representation
An example package to be used for yarn testing and documentation
- Host: GitHub
- URL: https://github.com/yarnpkg/example-yarn-package
- Owner: yarnpkg
- License: other
- Created: 2016-09-27T23:13:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-12-16T15:47:08.000Z (over 7 years ago)
- Last Synced: 2024-10-29T14:35:31.424Z (over 1 year ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 69
- Watchers: 7
- Forks: 73
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This is an example package that can be used to test Yarn.
It has the common default fields in its `package.json`, along with production and development dependencies as well that are specific to the package we have created.
## The `package.json`
### Default Package Fields
`yarn init` produces a default `package.json` similar to:
```
{
"name": "example-yarn-package",
"version": "1.0.0",
"description": "An example package to demonstrate Yarn",
"main": "index.js",
"repository": {
"url": "github.com/yarnpkg/example-yarn-package",
"type": "git"
},
"author": "Yarn Contributors",
"license": "BSD-2-Clause",
}
```
### Custom Package Fields
You can add custom fields to your `package.json` as well. In our case, we have added 4 custom fields.
The `scripts` field are for any special scripts that you want to use when running `yarn`. For example, here we add a script called `test` that calls the Jest test runner because we added Jest tests to our Yarn package.
```
"scripts": {
"test": "jest"
},
```
The `dependencies` field lists the other packages that this package is dependent upon. Our example package is dependent on [Lodash](https://lodash.com/) since we use its `multiply` function.
```
"dependencies": {
"lodash": "^4.16.2"
},
```
The `devDependencies` field lists the other packages that this package is dependent upon *during development*. Our example package is dependent on [Jest](https://facebook.github.io/jest/) since we created some Jest-enabled tests for our package.
```
"devDependencies": {
"jest-cli": "15.1.1"
},
```
The `jest` field is a custom field specific to the Jest package we included as a dev dependency. In this case, we are testing
in a node environment at the command-line.
```
"jest": {
"testEnvironment": "node"
}
```
> It is important to note that Lodash and Jest are not required for Yarn. They are just examples of what can be used when you are creating the code for your Yarn package.
## Development
```
$ yarn install
$ yarn run test
```
## Production
```
$ yarn install --production
```