Skip to content

Commit 5ecb154

Browse files
authored
Merge pull request #623 from ro0gr/deps-for-addon
Install ec-typescript as a dependecy for addons
2 parents 03134c3 + 2f8d23c commit 5ecb154

File tree

6 files changed

+97
-64
lines changed

6 files changed

+97
-64
lines changed

README.md

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,11 @@ This README focuses on basic information about setting up and using the addon. F
4444

4545
### Installation and Setup
4646

47-
***Note:* Because ember-cli-typescript is part of the build pipeline, the process for installing it differs slightly between apps and addons!**
48-
49-
#### In apps
50-
51-
In apps, you can simply `ember install` the dependency like normal:
52-
47+
You can simply `ember install` the dependency like normal:
5348
```sh
5449
ember install ember-cli-typescript@latest
5550
```
5651

57-
#### In addons
58-
59-
To work properly, Ember addons must declare this library as a `dependency`, not a `devDependency`. You can `ember install` it by running:
60-
61-
```sh
62-
ember install ember-cli-typescript@latest --save
63-
```
64-
6552
All dependencies will be added to your `package.json`, and you're ready to roll! **If you're upgrading from a previous release, see below!** you should check to merge any tweaks you've made to `tsconfig.json`.
6653

6754
### Upgrading from 1.x
@@ -110,38 +97,48 @@ Follow the same process of deduplication, reinstallation, and re-deduplication a
11097

11198
#### Update ember-cli-typescript
11299

113-
***Note:* Because ember-cli-typescript is part of the build pipeline, the process for updating it differs slightly between apps and addons!**
114-
115-
##### In apps
116-
117-
In apps, you can simply `ember install` the dependency like normal:
100+
Now you can simply `ember install` the dependency like normal:
118101

119102
```sh
120103
ember install ember-cli-typescript@latest
121104
```
122105

123-
##### In addons
106+
***Note:* To work properly, starting from v2, ember-cli-typescript must be declared as a `dependency`, not a `devDependency` for addons. With `ember install` this migration will be automatically handled for you.**
124107

125-
To work properly, Ember addons must declare this library as a `dependency`, not a `devDependency`. **This is a *change* from ember-cli-typescript v1.**
108+
If you choose to make the upgrade manually with yarn or npm, here are the steps you need to follow:
126109

127-
1. Remove ember-cli-typescript from your dependencies.
110+
1. Remove ember-cli-typescript from your `devDependencies`.
128111

129112
With yarn:
130-
113+
131114
```sh
132-
yarn remove ember-cli-typescript
115+
yarn remove ember-cli-typescript
133116
```
134117

135118
With npm:
136-
119+
137120
```sh
138121
npm uninstall ember-cli-typescript
139122
```
140123

141-
2. Re-install it with `ember install`:
124+
2. Install the latest of ember-cli-typescript as a `dependency`:
125+
126+
With yarn:
127+
128+
```sh
129+
yarn add ember-cli-typescript@latest
130+
```
131+
132+
With npm:
133+
134+
```sh
135+
npm install --save ember-cli-typescript@latest
136+
```
137+
138+
3. Run `ember generate`:
142139

143140
```sh
144-
ember install ember-cli-typescript@latest --save
141+
ember generate ember-cli-typescript
145142
```
146143

147144
##### Account for addon build pipeline changes

tests/dummy/app/templates/docs/index.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
# Installation
22

3-
_**Note:** Because ember-cli-typescript is part of the build pipeline, the process for installing it differs slightly between apps and addons!_
4-
5-
## Installing in Apps
6-
7-
In apps, you can simply `ember install` the dependency like normal:
3+
You can simply `ember install` the dependency like normal:
84

95
```sh
106
ember install ember-cli-typescript@latest
117
```
128

13-
## Installing in Addons
14-
15-
To work properly, Ember addons must declare this library as a `dependency`, not a `devDependency`. You can `ember install` it by running:
16-
17-
```sh
18-
ember install ember-cli-typescript@latest --save
19-
```
20-
219
All dependencies will be added to your `package.json`, and you're ready to roll! **If you're upgrading from a previous release, see below!** you should check to merge any tweaks you've made to `tsconfig.json`.
2210

2311
## Installation Results

tests/dummy/app/templates/docs/upgrade-notes.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ ember-cli-typescript **requires** ember-cli-babel at version 7.1.0 or above, whi
1515
The recommended approach here is to deduplicate existing installations of the dependency, remove and reinstall ember-cli-babel to make sure that all its transitive dependencies are updated to the latest possible, and then to deduplicate *again*.
1616

1717
If using yarn:
18-
19-
```
18+
19+
```sh
2020
npx yarn-deduplicate
2121
yarn remove ember-cli-babel
2222
yarn add --dev ember-cli-babel
2323
npx yarn-deduplicate
2424
```
2525

2626
If using npm:
27-
28-
```
27+
28+
```sh
2929
npm dedupe
3030
npm uninstall ember-cli-babel
3131
npm install --save-dev ember-cli-babel
@@ -34,7 +34,7 @@ npm dedupe
3434

3535
Note: If you are also using ember-decorators—and specifically the babel-transform that gets added with it—you will need update @ember-decorators/babel-transforms as well (anything over 3.1.0 should work):
3636

37-
```
37+
```sh
3838
ember install ember-decorators@^3.1.0 @ember-decorators/babel-transforms@^3.1.0
3939
```
4040

@@ -44,38 +44,48 @@ Follow the same process of deduplication, reinstallation, and re-deduplication a
4444

4545
## Update ember-cli-typescript
4646

47-
***Note:* Because ember-cli-typescript is part of the build pipeline, the process for updating it differs slightly between apps and addons!**
48-
49-
### In apps
50-
51-
In apps, you can simply `ember install` the dependency like normal:
47+
Now you can simply `ember install` the dependency like normal:
5248

5349
```sh
5450
ember install ember-cli-typescript@latest
5551
```
5652

57-
### In addons
53+
***Note:* To work properly, starting from v2, ember-cli-typescript must be declared as a `dependency`, not a `devDependency` for addons. With `ember install` this migration would be automatically handled for you.**
5854

59-
To work properly, Ember addons must declare this library as a `dependency`, not a `devDependency`. **This is a *change* from ember-cli-typescript v1.**
55+
If you choose to make the upgrade manually with yarn or npm, here are the steps you need to follow:
6056

61-
1. Remove ember-cli-typescript from your dependencies.
57+
1. Remove ember-cli-typescript from your `devDependencies`.
6258

6359
With yarn:
64-
60+
6561
```sh
66-
yarn remove ember-cli-typescript
62+
yarn remove ember-cli-typescript
6763
```
6864

6965
With npm:
70-
66+
7167
```sh
7268
npm uninstall ember-cli-typescript
7369
```
7470

75-
2. Re-install it with `ember install`:
71+
2. Install the latest of ember-cli-typescript as a `dependency`:
72+
73+
With yarn:
74+
75+
```sh
76+
yarn add ember-cli-typescript@latest
77+
```
78+
79+
With npm:
80+
81+
```sh
82+
npm install --save ember-cli-typescript@latest
83+
```
84+
85+
3. Run `ember generate`:
7686

7787
```sh
78-
ember install ember-cli-typescript@latest --save
88+
ember generate ember-cli-typescript
7989
```
8090

8191
### Account for addon build pipeline changes
@@ -104,7 +114,7 @@ Any place where a type annotation overrides a *getter*
104114
105115
This breaks because `element` is a getter on `Component`. This declaration then shadows the getter declaration on the base class and stomps it to `undefined` (effectively `Object.defineProperty(this, 'element', void 0)`.
106116
107-
Two solutions
117+
Two solutions:
108118
109119
1. Annotate locally (slightly more annoying, but less likely to troll you):
110120
@@ -144,6 +154,7 @@ Any place where a type annotation overrides a *getter*
144154
```ts
145155
export { FooType } from 'foo';
146156
```
157+
147158
```ts
148159
import { FooType } from 'foo';
149160
export { FooType };

ts/addon.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import { Application } from 'express';
1111
import walkSync from 'walk-sync';
1212
import fs from 'fs-extra';
1313

14+
export const ADDON_NAME = 'ember-cli-typescript';
15+
1416
export default addon({
15-
name: 'ember-cli-typescript',
17+
name: ADDON_NAME,
1618

1719
included() {
1820
this._super.included.apply(this, arguments);

ts/blueprints/ember-cli-typescript/index.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ declare module '${projectName}/ui/components/*/template' { ${moduleBody}}`;
3838
}
3939
}
4040

41+
const { ADDON_NAME } = require('../../addon');
42+
4143
module.exports = {
4244
APP_DECLARATIONS,
4345

@@ -157,7 +159,7 @@ module.exports = {
157159

158160
beforeInstall() {
159161
if (this.project.isEmberCLIAddon()) {
160-
this._installPrecompilationHooks();
162+
this._transformAddonPackage();
161163
}
162164

163165
let packages = [
@@ -207,22 +209,29 @@ module.exports = {
207209
return this.project.isModuleUnification && this.project.isModuleUnification();
208210
},
209211

210-
_installPrecompilationHooks() {
211-
let pkgPath = `${this.project.root}/package.json`;
212+
_transformAddonPackage() {
213+
const pkgPath = `${this.project.root}/package.json`;
214+
212215
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
213216

214217
// Really `prepack` and `postpack` would be ideal, but yarn doesn't execute those when publishing
215218
this._addScript(pkg.scripts, 'prepublishOnly', 'ember ts:precompile');
216219
this._addScript(pkg.scripts, 'postpublish', 'ember ts:clean');
217220

221+
// avoid being placed in devDependencies
222+
if (pkg.devDependencies[ADDON_NAME]) {
223+
pkg.dependencies[ADDON_NAME] = pkg.devDependencies[ADDON_NAME];
224+
delete pkg.devDependencies[ADDON_NAME];
225+
}
226+
218227
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
219228
},
220229

221230
_addScript(scripts, type, script) {
222231
if (scripts[type] && scripts[type] !== script) {
223232
this.ui.writeWarnLine(
224233
`Found a pre-existing \`${type}\` script in your package.json. ` +
225-
`By default, ember-cli-typescripts expects to run \`${script}\` in this hook.`
234+
`By default, ember-cli-typescript expects to run \`${script}\` in this hook.`
226235
);
227236
return;
228237
}

ts/tests/blueprints/ember-cli-typescript-test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ describe('Acceptance: ember-cli-typescript generator', function() {
100100
const pkgJson = JSON.parse(pkg.content);
101101
expect(pkgJson.scripts.prepublishOnly).to.equal('ember ts:precompile');
102102
expect(pkgJson.scripts.postpublish).to.equal('ember ts:clean');
103+
expect(pkgJson.dependencies).to.include.all.keys('ember-cli-typescript');
104+
expect(pkgJson.devDependencies).to.not.include.all.keys('ember-cli-typescript');
103105
expect(pkgJson.devDependencies).to.not.have.any.keys('ember-data');
104106
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-data');
105107
expect(pkgJson.devDependencies).to.include.all.keys('ember-qunit');
@@ -148,6 +150,26 @@ describe('Acceptance: ember-cli-typescript generator', function() {
148150
expect(emberDataCatchallTypes).not.to.exist;
149151
});
150152

153+
it('moves from devDependencies to dependencies for addons', async function() {
154+
const args = ['ember-cli-typescript'];
155+
156+
await helpers.emberNew({ target: 'addon' });
157+
await helpers.modifyPackages([
158+
{
159+
dev: true,
160+
name: 'ember-cli-typescript',
161+
},
162+
]);
163+
await helpers.emberGenerate(args);
164+
165+
const pkg = file('package.json');
166+
expect(pkg).to.exist;
167+
168+
const pkgJson = JSON.parse(pkg.content);
169+
expect(pkgJson.devDependencies).to.not.have.any.keys('ember-cli-typescript');
170+
expect(pkgJson.dependencies).to.include.all.keys('ember-cli-typescript');
171+
});
172+
151173
describe('module unification', () => {
152174
const originalIsMU = Project.prototype.isModuleUnification;
153175

@@ -171,6 +193,8 @@ describe('Acceptance: ember-cli-typescript generator', function() {
171193
const pkgJson = JSON.parse(pkg.content);
172194
expect(pkgJson.scripts.prepublishOnly).to.be.undefined;
173195
expect(pkgJson.scripts.postpublish).to.be.undefined;
196+
expect(pkgJson.dependencies).to.not.include.all.keys('ember-cli-typescript');
197+
expect(pkgJson.devDependencies).to.include.all.keys('ember-cli-typescript');
174198
expect(pkgJson.devDependencies).to.include.all.keys('ember-data');
175199
expect(pkgJson.devDependencies).to.include.all.keys('@types/ember-data');
176200
expect(pkgJson.devDependencies).to.include.all.keys('ember-qunit');
@@ -222,6 +246,8 @@ describe('Acceptance: ember-cli-typescript generator', function() {
222246
const pkgJson = JSON.parse(pkg.content);
223247
expect(pkgJson.scripts.prepublishOnly).to.equal('ember ts:precompile');
224248
expect(pkgJson.scripts.postpublish).to.equal('ember ts:clean');
249+
expect(pkgJson.dependencies).to.include.all.keys('ember-cli-typescript');
250+
expect(pkgJson.devDependencies).to.not.include.all.keys('ember-cli-typescript');
225251
expect(pkgJson.devDependencies).to.not.have.any.keys('ember-data');
226252
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-data');
227253
expect(pkgJson.devDependencies).to.include.all.keys('ember-qunit');

0 commit comments

Comments
 (0)