Skip to content

Commit

Permalink
Merge pull request #1043 from typed-ember/v4
Browse files Browse the repository at this point in the history
v4
  • Loading branch information
jamescdavis authored Jul 2, 2020
2 parents ec3aedf + c964f50 commit ff97605
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 75 deletions.
24 changes: 22 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a

## [Unreleased]

## [4.0.0-alpha.1] - 2020-01-18

### Breaking 💥

- Drop support for Node 8 ([#1017])
- Don't configure Babel for TS transpilation ([#1018])

### Under the hood 🚗

- Upgrade [✨ Prettier ✨](https://prettier.io) to a version that supports optional chaining and nullish coalescing ([#1018])
- Add test for optional chaining and nullish coalescing ([#1018])
- Add test for class field declaration ([#1018])

[#1017]: https://github.com/typed-ember/ember-cli-typescript/pull/1017
[#1018]: https://github.com/typed-ember/ember-cli-typescript/pull/1018

## [3.1.4] - 2020-05-29

### Fixed 🔧
Expand All @@ -19,7 +35,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
[#1153]: https://github.com/typed-ember/ember-cli-typescript/pull/1153
[3.1.4-deps-bumps]: https://github.com/typed-ember/ember-cli-typescript/pulls?q=is%3Apr+is%3Amerged+base%3Amaster+merged%3A2020-01-22T13%3A00%3A00-0600..2020-05-29T11%3A00%3A00-0500+chore%28deps%29+in%3Atitle+


## [3.1.3] - 2020-01-22

### Fixed 🔧
Expand Down Expand Up @@ -636,7 +651,12 @@ We now use Babel 7's support for TypeScript to build apps and addons. Most of th
* Basic, semi-working functionality.

[ember-cli-typify]: https://github.com/winding-lines/ember-cli-typify
[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.3...HEAD
[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v4.0.0-alpha.1...HEAD
<!--
This is correctly compared against v3.1.3 because it was released on a branch
before v3.1.4 was released.
-->
[4.0.0-alpha.1]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.3...v4.0.0-alpha.1
[3.1.4]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.3...v3.1.4
[3.1.3]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.2...v3.1.3
[3.1.2]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.1...v3.1.2
Expand Down
11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-cli-typescript",
"version": "3.1.4",
"version": "4.0.0-alpha.1",
"description": "Allow ember apps to use typescript files.",
"keywords": [
"ember-addon",
Expand Down Expand Up @@ -39,13 +39,9 @@
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -u"
},
"dependencies": {
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
"@babel/plugin-transform-typescript": "~7.10.4",
"ansi-to-html": "^0.6.6",
"broccoli-stew": "^3.0.0",
"debug": "^4.0.0",
"ember-cli-babel-plugin-helpers": "^1.0.0",
"execa": "^3.0.0",
"fs-extra": "^9.0.1",
"resolve": "^1.5.0",
Expand Down Expand Up @@ -138,13 +134,12 @@
"hawk": "7"
},
"engines": {
"node": "8.* || >= 10.*"
"node": "10.* || >= 12.*"
},
"ember-addon": {
"configPath": "tests/dummy/config",
"before": [
"broccoli-watcher",
"ember-cli-babel"
"broccoli-watcher"
]
},
"husky": {
Expand Down
29 changes: 12 additions & 17 deletions tests/unit/build-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,19 @@ module('Unit | Build', function () {
assert.equal(fromTs, 'From test-support');
});

test('property initialization occurs in the right order', function (assert) {
class TestClass {
// we shouldn't encourage folks to write code like this, but tsc ensures
// that constructor param fields are set before field initializers run
field = this.constructorParam;
constructor(private constructorParam: string) {}
test('optional chaining and nullish coalescing are transpiled correctly', function (assert) {
let value = { a: 'hello' } as { a?: string; b?: string };
assert.equal(value?.a, 'hello');
assert.equal(value?.b, undefined);
assert.equal(value?.a ?? 'ok', 'hello');
assert.equal(value?.b ?? 'ok', 'ok');
});

test('class field declarations work', function (assert) {
class MyClass {
declare foo: string;
}

let instance = new TestClass('hello');
assert.equal(instance.field, 'hello');
assert.notOk('foo' in new MyClass());
});

// TODO: enable once a release of Prettier comes out that supports this syntax
// test('optional chaining and nullish coalescing are transpiled correctly', function(assert) {
// let value = { a: 'hello' } as { a?: string; b?: string };
// assert.equal(value?.a, 'hello');
// assert.equal(value?.b, undefined);
// assert.equal(value?.a ?? 'ok', 'hello');
// assert.equal(value?.b ?? 'ok', 'ok');
// });
});
49 changes: 3 additions & 46 deletions ts/addon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import semver from 'semver';
import { Remote } from 'stagehand';
import { connect } from 'stagehand/lib/adapters/child-process';
import { hasPlugin, addPlugin, AddPluginOptions } from 'ember-cli-babel-plugin-helpers';
import Addon from 'ember-cli/lib/models/addon';
import PreprocessRegistry from 'ember-cli-preprocess-registry';
import { addon } from './lib/utilities/ember-cli-entities';
Expand Down Expand Up @@ -80,24 +79,6 @@ export default addon({
if (this.parent === this.project) {
this._registerCollisionDetectionPreprocessor(registry);
}

// Normally this is the sort of logic that would live in `included()`, but
// ember-cli-babel reads the configured extensions when setting up the
// preprocessor registry, so we need to beat it to the punch.
this._registerBabelExtension();

// As of 3.7, TS supports the optional chaining and nullish coalescing proposals.
// https://devblogs.microsoft.com/typescript/announcing-typescript-3-7-beta/
// Since we can't necessarily know what version of TS an addon was developed with,
// we unconditionally add the Babel plugins for both proposals.
this._addBabelPluginIfNotPresent('@babel/plugin-proposal-optional-chaining');
this._addBabelPluginIfNotPresent('@babel/plugin-proposal-nullish-coalescing-operator');

// Needs to come after the class properties plugin (see tests/unit/build-test.ts -
// "property initialization occurs in the right order")
this._addBabelPluginIfNotPresent('@babel/plugin-transform-typescript', {
after: ['@babel/plugin-proposal-class-properties'],
});
},

shouldIncludeChildAddon(addon) {
Expand Down Expand Up @@ -150,10 +131,11 @@ export default addon({
_checkBabelVersion() {
let babel = this.parent.addons.find((addon) => addon.name === 'ember-cli-babel');
let version = babel && babel.pkg.version;
if (!babel || !(semver.gte(version!, '7.7.3') && semver.lt(version!, '8.0.0'))) {

if (!babel || !(semver.gte(version!, '7.17.0') && semver.lt(version!, '8.0.0'))) {
let versionString = babel ? `version ${babel.pkg.version}` : `no instance of ember-cli-babel`;
this.ui.writeWarnLine(
`ember-cli-typescript requires ember-cli-babel ^7.7.3, but you have ${versionString} installed; ` +
`ember-cli-typescript requires ember-cli-babel ^7.17.0, but you have ${versionString} installed; ` +
'your TypeScript files may not be transpiled correctly.'
);
}
Expand Down Expand Up @@ -214,31 +196,6 @@ export default addon({
}
},

_getConfigurationTarget() {
// If `this.app` isn't present, we know `this.parent` is an addon
return this.app || (this.parent as Addon);
},

_registerBabelExtension() {
let target = this._getConfigurationTarget();
let options: Record<string, any> = target.options || (target.options = {});
let babelAddonOptions: Record<string, any> =
options['ember-cli-babel'] || (options['ember-cli-babel'] = {});
let extensions: string[] =
babelAddonOptions.extensions || (babelAddonOptions.extensions = ['js']);

if (!extensions.includes('ts')) {
extensions.push('ts');
}
},

_addBabelPluginIfNotPresent(pluginName: string, pluginOptions?: AddPluginOptions) {
let target = this._getConfigurationTarget();
if (!hasPlugin(target, pluginName)) {
addPlugin(target, require.resolve(pluginName), pluginOptions);
}
},

_addTypecheckMiddleware(app: Application) {
let workerPromise = this._getTypecheckWorker();
let middleware = new TypecheckMiddleware(this.project, workerPromise);
Expand Down
9 changes: 7 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@
dependencies:
"@babel/helper-plugin-utils" "^7.10.4"

"@babel/plugin-transform-typescript@^7.10.1", "@babel/plugin-transform-typescript@~7.10.4":
"@babel/plugin-transform-typescript@^7.10.1":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.10.4.tgz#8b01cb8d77f795422277cc3fcf45af72bc68ba78"
integrity sha512-3WpXIKDJl/MHoAN0fNkSr7iHdUMHZoppXjf2HJ9/ed5Xht5wNIsXllJXdityKOxeA3Z8heYRb1D3p2H5rfCdPw==
Expand Down Expand Up @@ -14970,7 +14970,12 @@ semver@^6.0.0, semver@^6.1.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semve
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.0.0, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2:
semver@^7.0.0:
version "7.1.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.1.2.tgz#847bae5bce68c5d08889824f02667199b70e3d87"
integrity sha512-BJs9T/H8sEVHbeigqzIEo57Iu/3DG6c4QoqTfbQB3BPA4zgzAomh/Fk9E7QtjWQ8mx2dgA9YCfSF4y9k9bHNpQ==

semver@^7.1.3, semver@^7.2.1, semver@^7.3.2:
version "7.3.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==
Expand Down

0 comments on commit ff97605

Please sign in to comment.