ember-cli-typescript
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -10,3 +10,4 @@ { | ||
"noEmit": true, | ||
"sourceMap": true, | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"baseUrl": ".", | ||
@@ -13,0 +14,0 @@ "module": "es6", |
@@ -34,3 +34,3 @@ 'use strict'; | ||
let isAddon = this.project.isEmberCLIAddon(); | ||
let includes = [isAddon ? 'addon' : 'app', 'tests'].concat(inRepoAddons); | ||
let includes = ['app', isAddon && 'addon', 'tests'].concat(inRepoAddons).filter(Boolean); | ||
@@ -55,3 +55,3 @@ // Mirage is already covered for addons because it's under `tests/` | ||
if (isAddon) { | ||
paths[`${appName}/*`] = ['tests/dummy/app/*']; | ||
paths[`${appName}/*`] = ['tests/dummy/app/*', 'app/*']; | ||
} else { | ||
@@ -58,0 +58,0 @@ paths[`${appName}/*`] = ['app/*']; |
@@ -9,5 +9,16 @@ # Changelog | ||
## [1.1.4] - 2018-02-20 | ||
### Changed | ||
* The default `tsconfig.json` now includes inline source maps to support integrating with Babel sourcemaps, and the README has instructions for configuring Ember CLI's Babel integration. | ||
### Fixed | ||
* TypeScript files in addon `app` trees now get compiled properly. | ||
* App files now correctly take precedence over any files of the same name earlier in the tree. (If you had a component with the same name as an addon-supplied component, for example, the addon version could override yours.) | ||
## [1.1.3] - 2018-02-16 | ||
### Fixes | ||
### Fixed | ||
@@ -161,3 +172,4 @@ * Fix default blueprint for `types/<my app>/index.d.ts`: add missing import and an export statement so ambient declarations work. | ||
[ember-cli-typify]: https://github.com/winding-lines/ember-cli-typify | ||
[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.1.3...HEAD | ||
[unreleased]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.1.4...HEAD | ||
[1.1.4]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.1.3...v1.1.4 | ||
[1.1.3]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.1.2...v1.1.3 | ||
@@ -164,0 +176,0 @@ [1.1.2]: https://github.com/typed-ember/ember-cli-typescript/compare/v1.1.1...v1.1.2 |
20
index.js
@@ -5,2 +5,4 @@ // @ts-check | ||
const IncrementalTypescriptCompiler = require('./lib/incremental-typescript-compiler'); | ||
const Funnel = require('broccoli-funnel'); | ||
const MergeTrees = require('broccoli-merge-trees'); | ||
@@ -28,2 +30,20 @@ module.exports = { | ||
setupPreprocessorRegistry(type, registry) { | ||
if (type !== 'parent') { | ||
return; | ||
} | ||
registry.add('js', { | ||
name: 'ember-cli-typescript', | ||
toTree: (original, inputPath, outputPath) => { | ||
if (!this.compiler || inputPath !== '/') { | ||
return original; | ||
} | ||
let ts = new Funnel(this.compiler.treeForHost(), { destDir: outputPath }); | ||
return new MergeTrees([original, ts], { overwrite: true }); | ||
}, | ||
}); | ||
}, | ||
treeForApp() { | ||
@@ -30,0 +50,0 @@ if (this.compiler) { |
@@ -9,6 +9,4 @@ /* eslint-env node */ | ||
const mkdirp = require('mkdirp'); | ||
const SilentError = require('silent-error'); | ||
const Command = require('ember-cli/lib/models/command'); // eslint-disable-line node/no-unpublished-require | ||
const compile = require('../utilities/compile'); | ||
const debug = require('debug')('ember-cli-typescript:precompile'); | ||
@@ -34,12 +32,12 @@ const PRECOMPILE_MANIFEST = 'tmp/.ts-precompile-manifest'; | ||
for (let declSource of walkSync(outDir, { globs: ['**/*.d.ts'] })) { | ||
if (!this._isAddonFile(declSource)) { | ||
debug('skipping non-addon file %s', declSource); | ||
continue; | ||
if (this._shouldCopy(declSource)) { | ||
let compiled = declSource.replace(/\.d\.ts$/, '.js'); | ||
this._copyFile(output, `${outDir}/${compiled}`, compiled); | ||
// We can only do anything meaningful with declarations for files in addon/ | ||
if (this._isAddonFile(declSource)) { | ||
let declDest = declSource.replace(/^addon\//, ''); | ||
this._copyFile(output, `${outDir}/${declSource}`, declDest); | ||
} | ||
} | ||
let declDest = declSource.replace(/^addon\//, ''); | ||
let compiled = declSource.replace(/\.d\.ts$/, '.js'); | ||
this._copyFile(output, `${outDir}/${declSource}`, declDest); | ||
this._copyFile(output, `${outDir}/${compiled}`, compiled); | ||
} | ||
@@ -52,10 +50,11 @@ | ||
_shouldCopy(source) { | ||
return this._isAppFile(source) || this._isAddonFile(source); | ||
}, | ||
_isAppFile(source) { | ||
return source.indexOf('app') === 0; | ||
}, | ||
_isAddonFile(source) { | ||
if (source.indexOf('app') === 0) { | ||
throw new SilentError( | ||
"Including .ts files in your addon's `app` directory is unsupported. " + | ||
'See <link to README or something>.' | ||
); | ||
} | ||
return source.indexOf('addon') === 0; | ||
@@ -62,0 +61,0 @@ }, |
@@ -41,13 +41,3 @@ 'use strict'; | ||
treeForApp() { | ||
// This could be more efficient, but we can hopefully assume there won't be dozens | ||
// or hundreds of TS addons in dev mode all at once. | ||
// Using node-merge-trees in the TypescriptOutput plugin would allow for mappings | ||
// like { foo: 'out', bar: 'out' } so we'd only need one Broccoli node for this. | ||
let addonAppTrees = this.addons.map(addon => { | ||
return new TypescriptOutput(this, { | ||
[`${this._relativeAddonRoot(addon)}/app`]: 'app', | ||
}); | ||
}); | ||
treeForHost() { | ||
let triggerTree = new Funnel(this._triggerDir, { destDir: 'app' }); | ||
@@ -64,6 +54,19 @@ | ||
let tree = new MergeTrees(addonAppTrees.concat([triggerTree, appTree, mirageTree].filter(Boolean)), { overwrite: true }); | ||
let tree = new MergeTrees([triggerTree, mirageTree, appTree].filter(Boolean), { overwrite: true }); | ||
return new Funnel(tree, { srcDir: 'app' }); | ||
} | ||
// Returns any developing addons' app trees. Note that the host app itself is managed | ||
// by treeForHost() above, as it needs to be treated specially by the build to always | ||
// 'win' when the host and an addon have clashing files. | ||
treeForApp() { | ||
let addonAppTrees = this.addons.map(addon => { | ||
return new TypescriptOutput(this, { | ||
[`${this._relativeAddonRoot(addon)}/app`]: 'app', | ||
}); | ||
}); | ||
return new MergeTrees(addonAppTrees, { overwrite: true }); | ||
} | ||
treeForAddons() { | ||
@@ -70,0 +73,0 @@ let paths = {}; |
{ | ||
"name": "ember-cli-typescript", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Allow ember apps to use typescript files.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -10,2 +10,3 @@ # ember-cli-typescript | ||
* [`tsconfig.json`](#tsconfigjson) | ||
* [Sourcemaps](#sourcemaps) | ||
* [Using TypeScript with Ember effectively](#using-typescript-with-ember-effectively) | ||
@@ -88,2 +89,16 @@ * [Incremental adoption](#incremental-adoption) | ||
### Sourcemaps | ||
To enable TypeScript sourcemaps, you'll need to add the corresponding configuration for Babel to your `ember-cli-build.js` file: | ||
```ts | ||
const app = new EmberApp(defaults, { | ||
babel: { | ||
sourceMaps: 'inline', | ||
}, | ||
}); | ||
``` | ||
(Note that this _will_ noticeably slow down your app rebuilds.) | ||
## Using TypeScript with Ember effectively | ||
@@ -512,2 +527,4 @@ | ||
**Note**: While `.ts` files from both the `app` and `addon` directories of your addon will be transpiled by `ts:precompile`, only the declaration files from `addon` will be published. Since the final import paths for `app` files will depend on the name of the consuming application, we can't put those declaration files in a meaningful place. | ||
### Linking Addons | ||
@@ -514,0 +531,0 @@ |
158857
2136
607