Skip to content

Commit 5f6a171

Browse files
authored
Merge pull request #1029 from emberjs/deprecate-app-prefix
Deprecate app-prefix et al
2 parents be4aca6 + fdcd3ec commit 5f6a171

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

text/1029-deprecate-app-prefix.md

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
stage: accepted
3+
start-date: 2024-05-20T00:00:00.000Z
4+
release-date:
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/1029
11+
project-link:
12+
---
13+
14+
<!---
15+
Directions for above:
16+
17+
stage: Leave as is
18+
start-date: Fill in with today's date, 2032-12-01T00:00:00.000Z
19+
release-date: Leave as is
20+
release-versions: Leave as is
21+
teams: Include only the [team(s)](README.md#relevant-teams) for which this RFC applies
22+
prs:
23+
accepted: Fill this in with the URL for the Proposal RFC PR
24+
project-link: Leave as is
25+
-->
26+
27+
# Deprecate app-prefix, app-suffix, tests-prefix, and tests-suffix
28+
29+
## Summary
30+
31+
ember-cli addons can use their `contentFor` method to emit arbitrary Javascript into many places. This RFC proposes deprecating and removing several of them:
32+
33+
- app-prefix
34+
- app-suffix
35+
- tests-prefix
36+
- tests-suffix
37+
- vendor-prefix
38+
- vendor-suffix
39+
40+
## Motivation
41+
42+
All of these assume there's going to be one "app" bundle, one "vendor" bundle, and one "tests" bundle. But those assumptions are now nonsense, given code-splitting and builds that can directly evaluate the module graph in the browser.
43+
44+
They are also seldom used based on code searches on emberobserver.com:
45+
46+
| Feature | Usage Count | Relevance |
47+
| ---------| ------------- | ----------------------------------------------------------------------------------- |
48+
| app-prefix | 2 addons | Last updated 6 and 8 years ago |
49+
| app-suffix | 1 addon | Last updated 6 years ago |
50+
| tests-prefix | 0 addons | Never appears in emberobserver at all |
51+
| tests-suffix | 0 addons | Only some embroider testing infrastructure ever refers to this at all. |
52+
| vendor-prefix | 3 addons | Last updated 6, 7, and 9 years ago |
53+
| vendor-suffix | 2 addons | Last updated 6 and 9 years ago |
54+
55+
## Transition Path
56+
57+
For all of these types of `contentFor` we will emit a deprecation if an addon returns content for the given `type` argument. An example of the deprecated behavior looks like:
58+
59+
```js
60+
contentFor(type, config, contents) {
61+
if (type === 'app-prefix') {
62+
return `console.log("LOL");`
63+
}
64+
}
65+
```
66+
67+
## How We Teach This
68+
69+
The CLI docs [mention contentFor](https://ember-cli.com/api/classes/addon#method_contentFor) but they don't actually document any of the use cases we are deprecating. They describe using contentFor to target index.html instead. That is not being deprecated by this RFC.
70+
71+
72+
### Deprecation Guide Content
73+
74+
#### app-prefix
75+
76+
Returning content from an addon's `contentFor()` hook for `type="app-prefix"` is deprecated. Addons will no longer be allowed to inject arbitrary javascript here. If you need to provide code that apps will run before booting, document that app authors should import and call your code at the start of their own `app.js` file.
77+
78+
#### app-suffix
79+
80+
Returning content from an addon's `contentFor()` hook for `type="app-suffix"` is deprecated. Addons will no longer be allowed to inject arbitrary javascript here. If you need to provide code that apps will run before booting, document that app authors should import and call your code at the start of their own `app.js` file.
81+
82+
If you were using app-suffix to overwrites modules provided by the app, that is intentionally not supported. Adjust your API to tell app authors to import your code and invoke it where appropriate.
83+
84+
#### tests-prefix
85+
86+
Returning content from an addon's `contentFor()` hook for `type="tests-prefix"` is deprecated. Addons will no longer be allowed to inject arbitrary javascript here. Provide utilities that users can import into their own test setup code instead.
87+
88+
#### tests-suffix
89+
90+
Returning content from an addon's `contentFor()` hook for `type="tests-suffix"` is deprecated. Addons will no longer be allowed to inject arbitrary javascript here. Provide utilities that users can import into their own test setup code instead.
91+
92+
#### vendor-prefix
93+
94+
Returning content from an addon's `contentFor()` hook for `type="vendor-prefix"` is deprecated. Addons will no longer be allowed to inject arbitrary javascript here. If you really need to run script (non-module) code, provides your own script via your addon's `/public` directory and either document that app authors should createa a `<script>` element in their HTML that includes it, or use `contentFor()` with one of the `type`s that appears in `index.html` to emit the scrip tag automatically. (`contentFor` targeting HTML is not deprecated, this deprecation only covers targeting javascript bundles.)
95+
96+
#### vendor-suffix
97+
98+
Returning content from an addon's `contentFor()` hook for `type="vendor-suffix"` is deprecated. Addons will no longer be allowed to inject arbitrary javascript here. If you really need to run script (non-module) code, provides your own script via your addon's `/public` directory and either document that app authors should createa a `<script>` element in their HTML that includes it, or use `contentFor()` with one of the `type`s that appears in `index.html` to emit the scrip tag automatically. (`contentFor` targeting HTML is not deprecated, this deprecation only covers targeting javascript bundles.)
99+
100+
## Drawbacks
101+
102+
This is a change to the v1 addon API. V2 addons already cannot use the contentFor hooks this RFC aims to deprecate. One could argue against bothering to change the v1 addon API.
103+
104+
## Alternatives
105+
106+
We could leave this API alone, on the assumption that it will get included in a wider "deprecate v1 addons" RFC. I'm not advocating that because I don't think it's practical to deprecate v1 addons any time soon.
107+
108+
We could include `app-boot` in this RFC. It certainly deserves to be deprecated, and has only a single use in the ecosystem (ember-cli-fastboot). But I think it's proper replacement should get designed in a "v2 app format" RFC instead, so that the booting of an app (or a test suite) is codified clearly as code the user controls.

0 commit comments

Comments
 (0)