Skip to content

Commit

Permalink
Ensure auto-import processes the same extensions as ember-cli-babel
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreeman committed May 22, 2020
1 parent 9121945 commit 9b6da01
Show file tree
Hide file tree
Showing 43 changed files with 1,698 additions and 10 deletions.
17 changes: 10 additions & 7 deletions packages/ember-auto-import/ts/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export default class Package {
private _hasBabelDetails = false;
private _babelMajorVersion?: number;
private _babelOptions: any;
private _emberCLIBabelExtensions?: string[];
private autoImportOptions: Options | undefined;
private emberCLIBabelExtensions: string[];
private isAddonCache = new Map<string, boolean>();
private isDeveloping: boolean;
private pkgGeneration: number;
Expand Down Expand Up @@ -57,17 +57,15 @@ export default class Package {
// Stash our own config options
this.autoImportOptions = this._options.autoImport;

this.emberCLIBabelExtensions = this._options['ember-cli-babel']
&& this._options['ember-cli-babel'].extensions || ['js'];

this.pkgCache = appOrAddon.parent.pkg;
this.pkgGeneration = pkgGeneration;
}

_ensureBabelDetails() {
if (this._hasBabelDetails) { return; }
let { babelOptions, version } = this.buildBabelOptions(this._parent, this._options);
let { babelOptions, extensions, version } = this.buildBabelOptions(this._parent, this._options);

this._emberCLIBabelExtensions = extensions;
this._babelOptions = babelOptions;
this._babelMajorVersion = version;
this._hasBabelDetails = true;
Expand All @@ -91,6 +89,8 @@ export default class Package {
(addon: any) => addon.name === 'ember-cli-babel'
);
let babelOptions = babelAddon.buildBabelOptions(options);
let extensions = babelOptions.filterExtensions || ['js'];

// https://github.com/babel/ember-cli-babel/issues/227
delete babelOptions.annotation;
delete babelOptions.throwUnlessParallelizable;
Expand All @@ -101,7 +101,7 @@ export default class Package {
);
}
let version = parseInt(babelAddon.pkg.version.split('.')[0], 10);
return { babelOptions, version };
return { babelOptions, extensions, version };
}

private get pkg() {
Expand Down Expand Up @@ -189,7 +189,10 @@ export default class Package {
}

get fileExtensions(): string[] {
return this.emberCLIBabelExtensions;
this._ensureBabelDetails();

// type safety: this will have been populated by the call above
return this._emberCLIBabelExtensions!;
}

get publicAssetURL(): string | undefined {
Expand Down
20 changes: 20 additions & 0 deletions packages/sample-typescript4/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2

[*.hbs]
insert_final_newline = false

[*.{diff,md}]
trim_trailing_whitespace = false
9 changes: 9 additions & 0 deletions packages/sample-typescript4/.ember-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
}
20 changes: 20 additions & 0 deletions packages/sample-typescript4/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
42 changes: 42 additions & 0 deletions packages/sample-typescript4/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2017,
sourceType: 'module'
},
plugins: [
'ember'
],
extends: [
'eslint:recommended',
'plugin:ember/recommended'
],
env: {
browser: true
},
rules: {
},
overrides: [
// node files
{
files: [
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'lib/*/index.js'
],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015
},
env: {
browser: false,
node: true
}
}
]
};
23 changes: 23 additions & 0 deletions packages/sample-typescript4/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/.sass-cache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
5 changes: 5 additions & 0 deletions packages/sample-typescript4/.template-lintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
extends: 'recommended'
};
27 changes: 27 additions & 0 deletions packages/sample-typescript4/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
language: node_js
node_js:
- "6"

sudo: false
dist: trusty

addons:
chrome: stable

cache:
directories:
- $HOME/.npm

env:
global:
# See https://git.io/vdao3 for details.
- JOBS=1

before_install:
- npm config set spin false

script:
- npm run lint:hbs
- npm run lint:js
- npm test
3 changes: 3 additions & 0 deletions packages/sample-typescript4/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignore_dirs": ["tmp", "dist"]
}
57 changes: 57 additions & 0 deletions packages/sample-typescript4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# sample-typescript4

This README outlines the details of collaborating on this Ember application.
A short introduction of this app could easily go here.

## Prerequisites

You will need the following things properly installed on your computer.

* [Git](https://git-scm.com/)
* [Node.js](https://nodejs.org/) (with npm)
* [Ember CLI](https://ember-cli.com/)
* [Google Chrome](https://google.com/chrome/)

## Installation

* `git clone <repository-url>` this repository
* `cd sample-typescript4`
* `npm install`

## Running / Development

* `ember serve`
* Visit your app at [http://localhost:4200](http://localhost:4200).
* Visit your tests at [http://localhost:4200/tests](http://localhost:4200/tests).

### Code Generators

Make use of the many generators for code, try `ember help generate` for more details

### Running Tests

* `ember test`
* `ember test --server`

### Linting

* `npm run lint:hbs`
* `npm run lint:js`
* `npm run lint:js -- --fix`

### Building

* `ember build` (development)
* `ember build --environment production` (production)

### Deploying

Specify what it takes to deploy your app.

## Further Reading / Useful Links

* [ember.js](https://emberjs.com/)
* [ember-cli](https://ember-cli.com/)
* Development Browser Extensions
* [ember inspector for chrome](https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi)
* [ember inspector for firefox](https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/)
14 changes: 14 additions & 0 deletions packages/sample-typescript4/app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Application from '@ember/application';
import Resolver from './resolver';
import loadInitializers from 'ember-load-initializers';
import config from './config/environment';

const App = Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
Resolver
});

loadInitializers(App, config.modulePrefix);

export default App;
Empty file.
16 changes: 16 additions & 0 deletions packages/sample-typescript4/app/config/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default config;

/**
* Type declarations for
* import config from './config/environment'
*
* For now these need to be managed by the developer
* since different ember addons can materialize new entries.
*/
declare const config: {
environment: any;
modulePrefix: string;
podModulePrefix: string;
locationType: string;
rootURL: string;
};
Empty file.
10 changes: 10 additions & 0 deletions packages/sample-typescript4/app/controllers/application.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Controller from '@ember/controller';
import { computed } from '@ember-decorators/object';
import aDependency from 'a-dependency';

export default class extends Controller {
@computed()
get result() {
return aDependency();
}
}
Empty file.
25 changes: 25 additions & 0 deletions packages/sample-typescript4/app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>SampleTypescript2</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">

{{content-for "head"}}

<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/sample-typescript4.css">

{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}

<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/sample-typescript4.js"></script>

{{content-for "body-footer"}}
</body>
</html>
Empty file.
3 changes: 3 additions & 0 deletions packages/sample-typescript4/app/resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Resolver from 'ember-resolver';

export default Resolver;
12 changes: 12 additions & 0 deletions packages/sample-typescript4/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import EmberRouter from '@ember/routing/router';
import config from './config/environment';

const Router = EmberRouter.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
});

export default Router;
Empty file.
Empty file.
1 change: 1 addition & 0 deletions packages/sample-typescript4/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-test-import-result>{{result}}</div>
Empty file.
Loading

0 comments on commit 9b6da01

Please sign in to comment.