Skip to content

Install ec-typescript as a dependency for addons #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,11 @@ This README focuses on basic information about setting up and using the addon. F

### Installation and Setup

***Note:* Because ember-cli-typescript is part of the build pipeline, the process for installing it differs slightly between apps and addons!**

#### In apps

In apps, you can simply `ember install` the dependency like normal:

You can simply `ember install` the dependency like normal:
```sh
ember install ember-cli-typescript@latest
```

#### In addons

To work properly, Ember addons must declare this library as a `dependency`, not a `devDependency`. You can `ember install` it by running:

```sh
ember install ember-cli-typescript@latest --save
```

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`.

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

#### Update ember-cli-typescript

***Note:* Because ember-cli-typescript is part of the build pipeline, the process for updating it differs slightly between apps and addons!**

##### In apps

In apps, you can simply `ember install` the dependency like normal:
Now you can simply `ember install` the dependency like normal:

```sh
ember install ember-cli-typescript@latest
```

##### In addons
***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.**

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

1. Remove ember-cli-typescript from your dependencies.
1. Remove ember-cli-typescript from your `devDependencies`.

With yarn:

```sh
yarn remove ember-cli-typescript
yarn remove ember-cli-typescript
```

With npm:

```sh
npm uninstall ember-cli-typescript
```

2. Re-install it with `ember install`:
2. Install the latest of ember-cli-typescript as a `dependency`:

With yarn:

```sh
yarn add ember-cli-typescript@latest
```

With npm:

```sh
npm install --save ember-cli-typescript@latest
```

3. Run `ember generate`:

```sh
ember install ember-cli-typescript@latest --save
ember generate ember-cli-typescript
```

##### Account for addon build pipeline changes
Expand Down
14 changes: 1 addition & 13 deletions tests/dummy/app/templates/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
# Installation

_**Note:** Because ember-cli-typescript is part of the build pipeline, the process for installing it differs slightly between apps and addons!_

## Installing in Apps

In apps, you can simply `ember install` the dependency like normal:
You can simply `ember install` the dependency like normal:

```sh
ember install ember-cli-typescript@latest
```

## Installing in Addons

To work properly, Ember addons must declare this library as a `dependency`, not a `devDependency`. You can `ember install` it by running:

```sh
ember install ember-cli-typescript@latest --save
```

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`.

## Installation Results
Expand Down
49 changes: 30 additions & 19 deletions tests/dummy/app/templates/docs/upgrade-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ ember-cli-typescript **requires** ember-cli-babel at version 7.1.0 or above, whi
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*.

If using yarn:
```

```sh
npx yarn-deduplicate
yarn remove ember-cli-babel
yarn add --dev ember-cli-babel
npx yarn-deduplicate
```

If using npm:
```

```sh
npm dedupe
npm uninstall ember-cli-babel
npm install --save-dev ember-cli-babel
Expand All @@ -34,7 +34,7 @@ npm dedupe

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):

```
```sh
ember install ember-decorators@^3.1.0 @ember-decorators/babel-transforms@^3.1.0
```

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

## Update ember-cli-typescript

***Note:* Because ember-cli-typescript is part of the build pipeline, the process for updating it differs slightly between apps and addons!**

### In apps

In apps, you can simply `ember install` the dependency like normal:
Now you can simply `ember install` the dependency like normal:

```sh
ember install ember-cli-typescript@latest
```

### In addons
***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.**

To work properly, Ember addons must declare this library as a `dependency`, not a `devDependency`. **This is a *change* from ember-cli-typescript v1.**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in the README.

If you choose to make the upgrade manually with yarn or npm, here are the steps you need to follow:

1. Remove ember-cli-typescript from your dependencies.
1. Remove ember-cli-typescript from your `devDependencies`.

With yarn:

```sh
yarn remove ember-cli-typescript
yarn remove ember-cli-typescript
```

With npm:

```sh
npm uninstall ember-cli-typescript
```

2. Re-install it with `ember install`:
2. Install the latest of ember-cli-typescript as a `dependency`:

With yarn:

```sh
yarn add ember-cli-typescript@latest
```

With npm:

```sh
npm install --save ember-cli-typescript@latest
```

3. Run `ember generate`:

```sh
ember install ember-cli-typescript@latest --save
ember generate ember-cli-typescript
```

### Account for addon build pipeline changes
Expand Down Expand Up @@ -104,7 +114,7 @@ Any place where a type annotation overrides a *getter*

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

Two solutions
Two solutions:

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

Expand Down Expand Up @@ -144,6 +154,7 @@ Any place where a type annotation overrides a *getter*
```ts
export { FooType } from 'foo';
```

```ts
import { FooType } from 'foo';
export { FooType };
Expand Down
4 changes: 3 additions & 1 deletion ts/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { Application } from 'express';
import walkSync from 'walk-sync';
import fs from 'fs-extra';

export const ADDON_NAME = 'ember-cli-typescript';

export default addon({
name: 'ember-cli-typescript',
name: ADDON_NAME,

included() {
this._super.included.apply(this, arguments);
Expand Down
17 changes: 13 additions & 4 deletions ts/blueprints/ember-cli-typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ declare module '${projectName}/ui/components/*/template' { ${moduleBody}}`;
}
}

const { ADDON_NAME } = require('../../addon');

module.exports = {
APP_DECLARATIONS,

Expand Down Expand Up @@ -157,7 +159,7 @@ module.exports = {

beforeInstall() {
if (this.project.isEmberCLIAddon()) {
this._installPrecompilationHooks();
this._transformAddonPackage();
}

let packages = [
Expand Down Expand Up @@ -207,22 +209,29 @@ module.exports = {
return this.project.isModuleUnification && this.project.isModuleUnification();
},

_installPrecompilationHooks() {
let pkgPath = `${this.project.root}/package.json`;
_transformAddonPackage() {
const pkgPath = `${this.project.root}/package.json`;

let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));

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

// avoid being placed in devDependencies
if (pkg.devDependencies[ADDON_NAME]) {
pkg.dependencies[ADDON_NAME] = pkg.devDependencies[ADDON_NAME];
delete pkg.devDependencies[ADDON_NAME];
}

fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
},

_addScript(scripts, type, script) {
if (scripts[type] && scripts[type] !== script) {
this.ui.writeWarnLine(
`Found a pre-existing \`${type}\` script in your package.json. ` +
`By default, ember-cli-typescripts expects to run \`${script}\` in this hook.`
`By default, ember-cli-typescript expects to run \`${script}\` in this hook.`
);
return;
}
Expand Down
26 changes: 26 additions & 0 deletions ts/tests/blueprints/ember-cli-typescript-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ describe('Acceptance: ember-cli-typescript generator', function() {
const pkgJson = JSON.parse(pkg.content);
expect(pkgJson.scripts.prepublishOnly).to.equal('ember ts:precompile');
expect(pkgJson.scripts.postpublish).to.equal('ember ts:clean');
expect(pkgJson.dependencies).to.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.not.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.not.have.any.keys('ember-data');
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-data');
expect(pkgJson.devDependencies).to.include.all.keys('ember-qunit');
Expand Down Expand Up @@ -148,6 +150,26 @@ describe('Acceptance: ember-cli-typescript generator', function() {
expect(emberDataCatchallTypes).not.to.exist;
});

it('moves from devDependencies to dependencies for addons', async function() {
const args = ['ember-cli-typescript'];

await helpers.emberNew({ target: 'addon' });
await helpers.modifyPackages([
{
dev: true,
name: 'ember-cli-typescript',
},
]);
await helpers.emberGenerate(args);

const pkg = file('package.json');
expect(pkg).to.exist;

const pkgJson = JSON.parse(pkg.content);
expect(pkgJson.devDependencies).to.not.have.any.keys('ember-cli-typescript');
expect(pkgJson.dependencies).to.include.all.keys('ember-cli-typescript');
});

describe('module unification', () => {
const originalIsMU = Project.prototype.isModuleUnification;

Expand All @@ -171,6 +193,8 @@ describe('Acceptance: ember-cli-typescript generator', function() {
const pkgJson = JSON.parse(pkg.content);
expect(pkgJson.scripts.prepublishOnly).to.be.undefined;
expect(pkgJson.scripts.postpublish).to.be.undefined;
expect(pkgJson.dependencies).to.not.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.include.all.keys('ember-data');
expect(pkgJson.devDependencies).to.include.all.keys('@types/ember-data');
expect(pkgJson.devDependencies).to.include.all.keys('ember-qunit');
Expand Down Expand Up @@ -222,6 +246,8 @@ describe('Acceptance: ember-cli-typescript generator', function() {
const pkgJson = JSON.parse(pkg.content);
expect(pkgJson.scripts.prepublishOnly).to.equal('ember ts:precompile');
expect(pkgJson.scripts.postpublish).to.equal('ember ts:clean');
expect(pkgJson.dependencies).to.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.not.include.all.keys('ember-cli-typescript');
expect(pkgJson.devDependencies).to.not.have.any.keys('ember-data');
expect(pkgJson.devDependencies).to.not.have.any.keys('@types/ember-data');
expect(pkgJson.devDependencies).to.include.all.keys('ember-qunit');
Expand Down