Skip to content

Commit 560b565

Browse files
author
Ruslan Hrabovyi
committed
feat: install ec-typescript as a dependecy for addons
1 parent 067e15b commit 560b565

File tree

6 files changed

+55
-94
lines changed

6 files changed

+55
-94
lines changed

README.md

Lines changed: 3 additions & 42 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,39 +97,13 @@ 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
124-
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.**
126-
127-
1. Remove ember-cli-typescript from your dependencies.
128-
129-
With yarn:
130-
131-
```sh
132-
yarn remove ember-cli-typescript
133-
```
134-
135-
With npm:
136-
137-
```sh
138-
npm uninstall ember-cli-typescript
139-
```
140-
141-
2. Re-install it with `ember install`:
142-
143-
```sh
144-
ember install ember-cli-typescript@latest --save
145-
```
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.**
146107

147108
##### Account for addon build pipeline changes
148109

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: 9 additions & 34 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,39 +44,13 @@ 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
58-
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.**
60-
61-
1. Remove ember-cli-typescript from your dependencies.
62-
63-
With yarn:
64-
65-
```sh
66-
yarn remove ember-cli-typescript
67-
```
68-
69-
With npm:
70-
71-
```sh
72-
npm uninstall ember-cli-typescript
73-
```
74-
75-
2. Re-install it with `ember install`:
76-
77-
```sh
78-
ember install ember-cli-typescript@latest --save
79-
```
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.**
8054

8155
### Account for addon build pipeline changes
8256

@@ -104,7 +78,7 @@ Any place where a type annotation overrides a *getter*
10478

10579
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)`.
10680

107-
Two solutions
81+
Two solutions:
10882

10983
1. Annotate locally (slightly more annoying, but less likely to troll you):
11084

@@ -144,6 +118,7 @@ Any place where a type annotation overrides a *getter*
144118
```ts
145119
export { FooType } from 'foo';
146120
```
121+
147122
```ts
148123
import { FooType } from 'foo';
149124
export { FooType };

ts/addon.ts

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

19+
export const ADDON_NAME = 'ember-cli-typescript';
20+
1921
export default addon({
20-
name: 'ember-cli-typescript',
22+
name: ADDON_NAME,
2123

2224
included() {
2325
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 = [
@@ -209,22 +211,29 @@ module.exports = {
209211
return this.project.isModuleUnification && this.project.isModuleUnification();
210212
},
211213

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

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

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

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

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)