Skip to content

Commit bd33242

Browse files
authored
Merge pull request #831 from MehulKChaudhari/standardize-npm-yarn
Standardize use of scripts in package.json for common tasks
2 parents 7fae745 + bcbc0ce commit bd33242

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

images/ember_test.png

15.5 KB
Loading

images/npm_test.png

25.9 KB
Loading

text/0831-standardize-use-npm-yarn.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
stage: accepted
3+
start-date: 2022-07-22
4+
release-date: Unreleased
5+
release-versions:
6+
teams: # delete teams that aren't relevant
7+
- cli
8+
- learning
9+
prs:
10+
accepted: https://github.com/emberjs/rfcs/pull/831
11+
project-link: https://github.com/ember-learn/cli-guides/issues/272
12+
suite:
13+
---
14+
15+
<!---
16+
Directions for above:
17+
18+
Stage: Leave as is
19+
Start Date: Fill in with today's date, YYYY-MM-DD
20+
Release Date: Leave as is
21+
Release Versions: Leave as is
22+
Relevant Team(s): Fill this in with the [team(s)](README.md#relevant-teams) to which this RFC applies
23+
RFC PR: Fill this in with the URL for the Proposal RFC PR
24+
-->
25+
26+
# <RFC title>
27+
Standardize the use of yarn and npm scripts in the Ember experience
28+
29+
## Summary
30+
31+
This change encourages developers to use scripts in `package.json`
32+
for certain commands when working with Ember
33+
applications, rather than using global Ember CLI commands like `ember serve` or focusing on npm/yarn.
34+
This aligns Ember with norms in the JavaScript community, and
35+
helps in reducing the confusion around Ember-specific commands.
36+
37+
## Motivation
38+
39+
In many JavaScript projects, the following commands are very common:
40+
41+
```
42+
npm start
43+
npm test
44+
```
45+
46+
These scripts are defined in the `package.json` of Ember apps, however,
47+
Ember's documentation tells developers to run these commands instead:
48+
49+
```
50+
ember serve
51+
ember test
52+
```
53+
54+
Notably, `ember test` and `npm test` give different results.
55+
56+
When we run `ember test`, it sets the environment to test and performs `Ember.onerror` validation by default.
57+
Whereas, in the case of `npm test`, there is an abstraction of the underlying commands that allows the user to run extra checks such as lint tests across the files and finally performs `ember test`.
58+
This is useful in carrying on a sequence of instructions and using them without having to worry about how they function behind the hood.
59+
As a result, a lot of developer time is saved and it also reduces the human error that might have been made if the abstract tooling was not used.
60+
61+
`ember test`
62+
![Ember test](/images/ember_test.png)
63+
64+
`npm test`
65+
![Npm test](/images/npm_test.png)
66+
67+
If documentation encouraged using `yarn` or `npm`, this would allow developers to customize the scripts
68+
themselves while also having a standard command that everyone can run in any project
69+
and get an expected output, regardless of what's going on under the hood. We can include a link to "prior art" of showing `npm start` in CLI output.
70+
71+
Consider cases where the author of an addon sets up `yarn test` to run with `ember-exam`.
72+
In such cases, one shouldn't be manually changing the default documentation for a script that already existed.
73+
74+
In another case of using the `package.json` script for start/test, it allows teams to abstract details about their specific dev environment,
75+
which makes developers' jobs easier. They can use `yarn start` or
76+
`pnpm start` without actually having to know which command starts the server.
77+
Moreover, using tooling abstraction provided by npm/yarn helps in staying consistent with industry standards rather than having to use bespoke
78+
tools.
79+
80+
## Detailed design
81+
82+
This will involve two steps
83+
84+
1. We should decide whether we want a Standardize the use of yarn/npm scripts.
85+
86+
2. Then we make the changes in READMEs, contributing guides, CLI output, and in learning docs.
87+
88+
## How we teach this
89+
90+
The following resources would need to change:
91+
92+
* Ember-cli guides
93+
* Ember guides
94+
* Ember API documentation
95+
* The Super Rentals tutorial
96+
* Readme.md and Contributing.md of repos
97+
* Blueprints in `ember-cli`
98+
* We should mention that developers should always refer to Contributing.md for full instructions when working with a new app or addon. And following commands as examples: start, test, build, and prepare.
99+
100+
## Drawbacks
101+
102+
> Why should we *not* do this? Please consider the impact on teaching Ember,
103+
on the integration of this feature with other existing and planned features,
104+
on the impact of the API churn on existing apps, etc.
105+
https://github.com/ember-cli/ember-cli/issues/8969#issuecomment-1167894022
106+
107+
> There are tradeoffs to choosing any path, please attempt to identify them here.
108+
109+
## Alternatives
110+
111+
* No change
112+
113+
## Unresolved questions
114+
115+
* How does the difference between yarn 1, 2, and 3 affect us if we made this change?
116+
* Should we show yarn and npm for every example?

0 commit comments

Comments
 (0)