Skip to content

Commit ff97605

Browse files
authored
Merge pull request #1043 from typed-ember/v4
v4
2 parents ec3aedf + c964f50 commit ff97605

File tree

5 files changed

+47
-75
lines changed

5 files changed

+47
-75
lines changed

CHANGELOG.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
## [4.0.0-alpha.1] - 2020-01-18
10+
11+
### Breaking 💥
12+
13+
- Drop support for Node 8 ([#1017])
14+
- Don't configure Babel for TS transpilation ([#1018])
15+
16+
### Under the hood 🚗
17+
18+
- Upgrade [✨ Prettier ✨](https://prettier.io) to a version that supports optional chaining and nullish coalescing ([#1018])
19+
- Add test for optional chaining and nullish coalescing ([#1018])
20+
- Add test for class field declaration ([#1018])
21+
22+
[#1017]: https://github.com/typed-ember/ember-cli-typescript/pull/1017
23+
[#1018]: https://github.com/typed-ember/ember-cli-typescript/pull/1018
24+
925
## [3.1.4] - 2020-05-29
1026

1127
### Fixed 🔧
@@ -19,7 +35,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
1935
[#1153]: https://github.com/typed-ember/ember-cli-typescript/pull/1153
2036
[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+
2137

22-
2338
## [3.1.3] - 2020-01-22
2439

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

638653
[ember-cli-typify]: https://github.com/winding-lines/ember-cli-typify
639-
[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.3...HEAD
654+
[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v4.0.0-alpha.1...HEAD
655+
<!--
656+
This is correctly compared against v3.1.3 because it was released on a branch
657+
before v3.1.4 was released.
658+
-->
659+
[4.0.0-alpha.1]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.3...v4.0.0-alpha.1
640660
[3.1.4]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.3...v3.1.4
641661
[3.1.3]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.2...v3.1.3
642662
[3.1.2]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.1...v3.1.2

package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ember-cli-typescript",
3-
"version": "3.1.4",
3+
"version": "4.0.0-alpha.1",
44
"description": "Allow ember apps to use typescript files.",
55
"keywords": [
66
"ember-addon",
@@ -39,13 +39,9 @@
3939
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -u"
4040
},
4141
"dependencies": {
42-
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.4",
43-
"@babel/plugin-proposal-optional-chaining": "^7.6.0",
44-
"@babel/plugin-transform-typescript": "~7.10.4",
4542
"ansi-to-html": "^0.6.6",
4643
"broccoli-stew": "^3.0.0",
4744
"debug": "^4.0.0",
48-
"ember-cli-babel-plugin-helpers": "^1.0.0",
4945
"execa": "^3.0.0",
5046
"fs-extra": "^9.0.1",
5147
"resolve": "^1.5.0",
@@ -138,13 +134,12 @@
138134
"hawk": "7"
139135
},
140136
"engines": {
141-
"node": "8.* || >= 10.*"
137+
"node": "10.* || >= 12.*"
142138
},
143139
"ember-addon": {
144140
"configPath": "tests/dummy/config",
145141
"before": [
146-
"broccoli-watcher",
147-
"ember-cli-babel"
142+
"broccoli-watcher"
148143
]
149144
},
150145
"husky": {

tests/unit/build-test.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,19 @@ module('Unit | Build', function () {
2828
assert.equal(fromTs, 'From test-support');
2929
});
3030

31-
test('property initialization occurs in the right order', function (assert) {
32-
class TestClass {
33-
// we shouldn't encourage folks to write code like this, but tsc ensures
34-
// that constructor param fields are set before field initializers run
35-
field = this.constructorParam;
36-
constructor(private constructorParam: string) {}
31+
test('optional chaining and nullish coalescing are transpiled correctly', function (assert) {
32+
let value = { a: 'hello' } as { a?: string; b?: string };
33+
assert.equal(value?.a, 'hello');
34+
assert.equal(value?.b, undefined);
35+
assert.equal(value?.a ?? 'ok', 'hello');
36+
assert.equal(value?.b ?? 'ok', 'ok');
37+
});
38+
39+
test('class field declarations work', function (assert) {
40+
class MyClass {
41+
declare foo: string;
3742
}
3843

39-
let instance = new TestClass('hello');
40-
assert.equal(instance.field, 'hello');
44+
assert.notOk('foo' in new MyClass());
4145
});
42-
43-
// TODO: enable once a release of Prettier comes out that supports this syntax
44-
// test('optional chaining and nullish coalescing are transpiled correctly', function(assert) {
45-
// let value = { a: 'hello' } as { a?: string; b?: string };
46-
// assert.equal(value?.a, 'hello');
47-
// assert.equal(value?.b, undefined);
48-
// assert.equal(value?.a ?? 'ok', 'hello');
49-
// assert.equal(value?.b ?? 'ok', 'ok');
50-
// });
5146
});

ts/addon.ts

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import semver from 'semver';
22
import { Remote } from 'stagehand';
33
import { connect } from 'stagehand/lib/adapters/child-process';
4-
import { hasPlugin, addPlugin, AddPluginOptions } from 'ember-cli-babel-plugin-helpers';
54
import Addon from 'ember-cli/lib/models/addon';
65
import PreprocessRegistry from 'ember-cli-preprocess-registry';
76
import { addon } from './lib/utilities/ember-cli-entities';
@@ -80,24 +79,6 @@ export default addon({
8079
if (this.parent === this.project) {
8180
this._registerCollisionDetectionPreprocessor(registry);
8281
}
83-
84-
// Normally this is the sort of logic that would live in `included()`, but
85-
// ember-cli-babel reads the configured extensions when setting up the
86-
// preprocessor registry, so we need to beat it to the punch.
87-
this._registerBabelExtension();
88-
89-
// As of 3.7, TS supports the optional chaining and nullish coalescing proposals.
90-
// https://devblogs.microsoft.com/typescript/announcing-typescript-3-7-beta/
91-
// Since we can't necessarily know what version of TS an addon was developed with,
92-
// we unconditionally add the Babel plugins for both proposals.
93-
this._addBabelPluginIfNotPresent('@babel/plugin-proposal-optional-chaining');
94-
this._addBabelPluginIfNotPresent('@babel/plugin-proposal-nullish-coalescing-operator');
95-
96-
// Needs to come after the class properties plugin (see tests/unit/build-test.ts -
97-
// "property initialization occurs in the right order")
98-
this._addBabelPluginIfNotPresent('@babel/plugin-transform-typescript', {
99-
after: ['@babel/plugin-proposal-class-properties'],
100-
});
10182
},
10283

10384
shouldIncludeChildAddon(addon) {
@@ -150,10 +131,11 @@ export default addon({
150131
_checkBabelVersion() {
151132
let babel = this.parent.addons.find((addon) => addon.name === 'ember-cli-babel');
152133
let version = babel && babel.pkg.version;
153-
if (!babel || !(semver.gte(version!, '7.7.3') && semver.lt(version!, '8.0.0'))) {
134+
135+
if (!babel || !(semver.gte(version!, '7.17.0') && semver.lt(version!, '8.0.0'))) {
154136
let versionString = babel ? `version ${babel.pkg.version}` : `no instance of ember-cli-babel`;
155137
this.ui.writeWarnLine(
156-
`ember-cli-typescript requires ember-cli-babel ^7.7.3, but you have ${versionString} installed; ` +
138+
`ember-cli-typescript requires ember-cli-babel ^7.17.0, but you have ${versionString} installed; ` +
157139
'your TypeScript files may not be transpiled correctly.'
158140
);
159141
}
@@ -214,31 +196,6 @@ export default addon({
214196
}
215197
},
216198

217-
_getConfigurationTarget() {
218-
// If `this.app` isn't present, we know `this.parent` is an addon
219-
return this.app || (this.parent as Addon);
220-
},
221-
222-
_registerBabelExtension() {
223-
let target = this._getConfigurationTarget();
224-
let options: Record<string, any> = target.options || (target.options = {});
225-
let babelAddonOptions: Record<string, any> =
226-
options['ember-cli-babel'] || (options['ember-cli-babel'] = {});
227-
let extensions: string[] =
228-
babelAddonOptions.extensions || (babelAddonOptions.extensions = ['js']);
229-
230-
if (!extensions.includes('ts')) {
231-
extensions.push('ts');
232-
}
233-
},
234-
235-
_addBabelPluginIfNotPresent(pluginName: string, pluginOptions?: AddPluginOptions) {
236-
let target = this._getConfigurationTarget();
237-
if (!hasPlugin(target, pluginName)) {
238-
addPlugin(target, require.resolve(pluginName), pluginOptions);
239-
}
240-
},
241-
242199
_addTypecheckMiddleware(app: Application) {
243200
let workerPromise = this._getTypecheckWorker();
244201
let middleware = new TypecheckMiddleware(this.project, workerPromise);

yarn.lock

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@
698698
dependencies:
699699
"@babel/helper-plugin-utils" "^7.10.4"
700700

701-
"@babel/plugin-transform-typescript@^7.10.1", "@babel/plugin-transform-typescript@~7.10.4":
701+
"@babel/plugin-transform-typescript@^7.10.1":
702702
version "7.10.4"
703703
resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.10.4.tgz#8b01cb8d77f795422277cc3fcf45af72bc68ba78"
704704
integrity sha512-3WpXIKDJl/MHoAN0fNkSr7iHdUMHZoppXjf2HJ9/ed5Xht5wNIsXllJXdityKOxeA3Z8heYRb1D3p2H5rfCdPw==
@@ -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
1497014970
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
1497114971
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
1497214972

14973-
semver@^7.0.0, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2:
14973+
semver@^7.0.0:
14974+
version "7.1.2"
14975+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.1.2.tgz#847bae5bce68c5d08889824f02667199b70e3d87"
14976+
integrity sha512-BJs9T/H8sEVHbeigqzIEo57Iu/3DG6c4QoqTfbQB3BPA4zgzAomh/Fk9E7QtjWQ8mx2dgA9YCfSF4y9k9bHNpQ==
14977+
14978+
semver@^7.1.3, semver@^7.2.1, semver@^7.3.2:
1497414979
version "7.3.2"
1497514980
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
1497614981
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==

0 commit comments

Comments
 (0)