Skip to content

Implement targets RFC#6776

Merged
homu merged 1 commit intoember-cli:masterfrom
cibernox:implement-targets-rfc
Feb 21, 2017
Merged

Implement targets RFC#6776
homu merged 1 commit intoember-cli:masterfrom
cibernox:implement-targets-rfc

Conversation

@cibernox
Copy link
Contributor

This PR implements ember-cli/rfcs#95 (still unmerged).

API example

app.project.targets; // { browsers: [...], node: '6.6.0' };

let targetsPath = path.join(this.root, configPath, 'targets');

let appTargets;
if (existsSync(`${targetsPath}.js`)) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe this should use require since the targets file isn't valid JSON and we want to allow usage of node-land things anyways.

Copy link
Contributor Author

@cibernox cibernox Feb 15, 2017

Choose a reason for hiding this comment

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

Done, but test fail. I've created the file with the right content, but I can't require it.
I suspect that must be something obvious related with how the fake filesystem works in tests.

/* eslint-env node */

module.exports = {
browsers: [] // ["last 2 versions", "safari >= 7"]
Copy link
Member

Choose a reason for hiding this comment

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

Let's inline the default here also (instead of the comment). This lets us update the default for new apps without potentially breaking existing ones.

@method targets
@return {Object} Targets object
*/
get targets() {
Copy link
Member

Choose a reason for hiding this comment

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

we should memoize this to avoid reading from disk on every access

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@cibernox
Copy link
Contributor Author

cibernox commented Feb 15, 2017

All feedback applied. There is still the issue of the failing test because this.require can't find the ${projectPath}/config/targets, while fs.readFileSync(${projectPath}/config/targets.js) can read it.

@cibernox
Copy link
Contributor Author

I've fixed the tests and validated its behaviour in app (installing it from my github).

Open implementation questions:

  • At the moment the config/targets.js exports a simple POJO. /config/ember-try.js follows the same approach. config/environment.js instead exports a function that when called with the environment returns the POJO. If you think that function-that-returns-pojo provides some value now it's the time.

  • When the package.json doesn't have an engines property the targets don't include the node property. I can leave it that way or I can return the minimum supported version of node, ATM node 4, although this supporter version afaik refers to ember-cli, and ember itself is not tested against any version of node so I lean towards just not including it.

  • The POJO I return is currently memoized and it's not frozen. In its current implementation an addon could grab it and modify it. I'm sitting on the fence wether of not that is a weakness or a strenght. By example, I can imagine ember-fastboot being node 6+ despite of ember-cli being node4+. Also I can imagine ember-electron doing something similar. I'd rather leave it unfrozen for now.

@cibernox
Copy link
Contributor Author

@rwjblue Removed references to node since it was withdrawn from the RFC.

@cibernox cibernox force-pushed the implement-targets-rfc branch from 71aa2b1 to 25e24d9 Compare February 21, 2017 00:35
@cibernox
Copy link
Contributor Author

@rwjblue Added to experiments.

@rwjblue
Copy link
Member

rwjblue commented Feb 21, 2017

@homu r+

@homu
Copy link
Contributor

homu commented Feb 21, 2017

📌 Commit 25e24d9 has been approved by rwjblue

homu added a commit that referenced this pull request Feb 21, 2017
Implement targets RFC

This PR implements ember-cli/rfcs#95 (still unmerged).

API example

```js
app.project.targets; // { browsers: [...], node: '6.6.0' };
```
@homu
Copy link
Contributor

homu commented Feb 21, 2017

⌛ Testing commit 25e24d9 with merge 2db75f1...

@homu
Copy link
Contributor

homu commented Feb 21, 2017

☀️ Test successful - status

@homu homu merged commit 25e24d9 into ember-cli:master Feb 21, 2017
@cibernox cibernox deleted the implement-targets-rfc branch March 13, 2017 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants