From 4cbf07e3767f2aa8262613795771ab0a1172016f Mon Sep 17 00:00:00 2001 From: Dan Freeman Date: Tue, 17 Dec 2019 16:35:53 +0100 Subject: [PATCH 1/7] feat: allow ember-cli-babel to manage TS transpilation --- package.json | 7 +------ ts/addon.ts | 50 ++------------------------------------------------ yarn.lock | 45 ++++----------------------------------------- 3 files changed, 7 insertions(+), 95 deletions(-) diff --git a/package.json b/package.json index 198f99fd3..4eef3755c 100644 --- a/package.json +++ b/package.json @@ -39,12 +39,8 @@ "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.7.0", "ansi-to-html": "^0.6.6", "debug": "^4.0.0", - "ember-cli-babel-plugin-helpers": "^1.0.0", "execa": "^3.0.0", "fs-extra": "^8.0.0", "resolve": "^1.5.0", @@ -140,8 +136,7 @@ "ember-addon": { "configPath": "tests/dummy/config", "before": [ - "broccoli-watcher", - "ember-cli-babel" + "broccoli-watcher" ] }, "husky": { diff --git a/ts/addon.ts b/ts/addon.ts index 929288c82..4b0dcbe29 100644 --- a/ts/addon.ts +++ b/ts/addon.ts @@ -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 { addon } from './lib/utilities/ember-cli-entities'; import fork from './lib/utilities/fork'; @@ -69,28 +68,6 @@ export default addon({ } }, - setupPreprocessorRegistry(type) { - if (type !== 'parent') return; - - // 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) { // For testing, we have dummy in-repo addons set up, but e-c-ts doesn't depend on them; // its dummy app does. Otherwise we'd have a circular dependency. @@ -100,6 +77,8 @@ export default addon({ _checkBabelVersion() { let babel = this.parent.addons.find(addon => addon.name === 'ember-cli-babel'); let version = babel && babel.pkg.version; + + // TODO update this check and warning message once we have a Babel version to target if (!babel || !(semver.gte(version!, '7.7.3') && semver.lt(version!, '8.0.0'))) { let versionString = babel ? `version ${babel.pkg.version}` : `no instance of ember-cli-babel`; this.ui.writeWarnLine( @@ -164,31 +143,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 = target.options || (target.options = {}); - let babelAddonOptions: Record = - 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); diff --git a/yarn.lock b/yarn.lock index bb71ca224..f64e74874 100644 --- a/yarn.lock +++ b/yarn.lock @@ -441,14 +441,6 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-json-strings" "^7.2.0" -"@babel/plugin-proposal-nullish-coalescing-operator@^7.4.4": - version "7.4.4" - resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.4.4.tgz#41c360d59481d88e0ce3a3f837df10121a769b39" - integrity sha512-Amph7Epui1Dh/xxUxS2+K22/MUi6+6JVTvy3P58tja3B6yKTSjwwx0/d83rF7551D6PVSSoplQb8GCwqec7HRw== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-nullish-coalescing-operator" "^7.2.0" - "@babel/plugin-proposal-object-rest-spread@^7.3.4": version "7.3.4" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.3.4.tgz#47f73cf7f2a721aad5c0261205405c642e424654" @@ -473,14 +465,6 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-optional-catch-binding" "^7.2.0" -"@babel/plugin-proposal-optional-chaining@^7.6.0": - version "7.6.0" - resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.6.0.tgz#e9bf1f9b9ba10c77c033082da75f068389041af8" - integrity sha512-kj4gkZ6qUggkprRq3Uh5KP8XnE1MdIO0J7MhdDX8+rAbB6dJ2UrensGIS+0NPZAaaJ1Vr0PN6oLUgXMU1uMcSg== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-optional-chaining" "^7.2.0" - "@babel/plugin-proposal-unicode-property-regex@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-unicode-property-regex/-/plugin-proposal-unicode-property-regex-7.2.0.tgz#abe7281fe46c95ddc143a65e5358647792039520" @@ -526,13 +510,6 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" -"@babel/plugin-syntax-nullish-coalescing-operator@^7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.2.0.tgz#f75083dfd5ade73e783db729bbd87e7b9efb7624" - integrity sha512-lRCEaKE+LTxDQtgbYajI04ddt6WW0WJq57xqkAZ+s11h4YgfRHhVA/Y2VhfPzzFD4qeLHWg32DMp9HooY4Kqlg== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-object-rest-spread@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.2.0.tgz#3b7a3e733510c57e820b9142a6579ac8b0dfad2e" @@ -547,13 +524,6 @@ dependencies: "@babel/helper-plugin-utils" "^7.0.0" -"@babel/plugin-syntax-optional-chaining@^7.2.0": - version "7.2.0" - resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.2.0.tgz#a59d6ae8c167e7608eaa443fda9fa8fa6bf21dff" - integrity sha512-HtGCtvp5Uq/jH/WNUPkK6b7rufnCPLLlDAFN7cmACoIjaOOiXxUt3SswU5loHqrhtqTsa/WoLQ1OQ1AGuZqaWA== - dependencies: - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-top-level-await@^7.7.0": version "7.7.0" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.7.0.tgz#f5699549f50bbe8d12b1843a4e82f0a37bb65f4d" @@ -986,15 +956,6 @@ "@babel/helper-plugin-utils" "^7.0.0" "@babel/plugin-syntax-typescript" "^7.2.0" -"@babel/plugin-transform-typescript@~7.7.0": - version "7.7.0" - resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.7.0.tgz#182be03fa8bd2ffd0629791a1eaa4373b7589d38" - integrity sha512-y3KYbcfKe+8ziRXiGhhnGrVysDBo5+aJdB+x8sanM0K41cnmK7Q5vBlQLMbOnW/HPjLG9bg7dLgYDQZZG9T09g== - dependencies: - "@babel/helper-create-class-features-plugin" "^7.7.0" - "@babel/helper-plugin-utils" "^7.0.0" - "@babel/plugin-syntax-typescript" "^7.2.0" - "@babel/plugin-transform-unicode-regex@^7.2.0": version "7.2.0" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.2.0.tgz#4eb8db16f972f8abb5062c161b8b115546ade08b" @@ -9747,10 +9708,12 @@ imurmurhash@^0.1.4: integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= "in-repo-a@link:tests/dummy/lib/in-repo-a": - version "1.0.0" + version "0.0.0" + uid "" "in-repo-b@link:tests/dummy/lib/in-repo-b": - version "1.0.0" + version "0.0.0" + uid "" include-path-searcher@^0.1.0: version "0.1.0" From 89e066aa9531f4a4e8ffd143314309cfba619e65 Mon Sep 17 00:00:00 2001 From: Dan Freeman Date: Tue, 17 Dec 2019 16:42:16 +0100 Subject: [PATCH 2/7] chore: drop support for Node 8 --- .github/workflows/ci.yml | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37e52b39d..8e3920a4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,7 +40,7 @@ jobs: - name: Install Node uses: actions/setup-node@v1 with: - node-version: '^8.12' + node-version: '^10' # https://github.com/expo/expo-github-action/issues/20#issuecomment-541676895 - name: Raise Watched File Limit run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p @@ -64,7 +64,7 @@ jobs: - name: Install Node uses: actions/setup-node@v1 with: - node-version: '^8.12' + node-version: '^10' - name: Install Dependencies run: yarn install --frozen-lockfile - name: Prepare CI Environment @@ -84,7 +84,7 @@ jobs: - name: Install Node uses: actions/setup-node@v1 with: - node-version: '^8.12' + node-version: '^10' - name: Raise Watched File Limit run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p - name: Install Dependencies @@ -113,7 +113,7 @@ jobs: - name: Install Node uses: actions/setup-node@v1 with: - node-version: '^8.12' + node-version: '^10' - name: Raise Watched File Limit run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p - name: Install Dependencies diff --git a/package.json b/package.json index 198f99fd3..08b84697a 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "hawk": "7" }, "engines": { - "node": "8.* || >= 10.*" + "node": "10.* || >= 12.*" }, "ember-addon": { "configPath": "tests/dummy/config", From 2a6236ab6c03c27129bc022fcce04fb20dad9489 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Mon, 30 Dec 2019 16:25:58 -0500 Subject: [PATCH 3/7] test: update for TS 3.7/Babel 7.7.0 * remove property initialization order test * upgrade prettier (so it understands class field declarations) * add test for class field declarations * enable optional chaining and nullish coalescing test (bonus) --- package.json | 2 +- tests/unit/build-test.ts | 29 ++++++++++++----------------- yarn.lock | 8 ++++---- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 4eef3755c..7b0b9bc37 100644 --- a/package.json +++ b/package.json @@ -118,7 +118,7 @@ "in-repo-b": "link:tests/dummy/lib/in-repo-b", "loader.js": "4.7.0", "mocha": "6.2.2", - "prettier": "1.18.2", + "prettier": "1.19.1", "qunit-dom": "0.9.2", "testdouble": "3.12.4", "tmp": "0.1.0", diff --git a/tests/unit/build-test.ts b/tests/unit/build-test.ts index 4288edb83..8c19dd630 100644 --- a/tests/unit/build-test.ts +++ b/tests/unit/build-test.ts @@ -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'); - // }); }); diff --git a/yarn.lock b/yarn.lock index f64e74874..3b62a8fcd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13358,10 +13358,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier@1.18.2: - version "1.18.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea" - integrity sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw== +prettier@1.19.1: + version "1.19.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" + integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== pretty-hrtime@^1.0.3: version "1.0.3" From c2ebe192f11fd27e5540b4411777bb4795502ba2 Mon Sep 17 00:00:00 2001 From: "James C. Davis" Date: Sat, 18 Jan 2020 09:54:05 -0500 Subject: [PATCH 4/7] chore: release v4.0.0-alpha.1 --- CHANGELOG.md | 19 ++++++++++++++++++- package.json | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e45ea82cf..cbf1f7100 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.2] - 2019-12-14 ### Fixed 🔧 @@ -604,7 +620,8 @@ 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.2...HEAD +[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v4.0.0-alpha.1...HEAD +[4.0.0-alpha.1]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.2...v4.0.0-alpha.1 [3.1.2]: https://github.com/typed-ember/ember-cli-typescript/compare/v3.1.1...v3.1.2