-
Notifications
You must be signed in to change notification settings - Fork 99
Set up build-time code for TypeScript development #288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
592845c
Move addon build code and tests under `ts`
dfreeman 4e5e693
Update blueprint and file search paths
dfreeman 6b30223
Configure TS addon build
dfreeman 6780761
Create addon entry point
dfreeman bfa4031
Convert one small utility to verify the build works
dfreeman 2b4df21
Update CI configuration
dfreeman 1e48845
Merge branch 'master' into build-code-typescript-setup
dfreeman 9cbb681
Merge branch 'master' into build-code-typescript-setup
dfreeman 511d7af
Warn when not running from within /ts in development
dfreeman 23d9c3a
Enable ESLint with our current rule set for .ts files
dfreeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
/blueprints/*/files/**/*.js | ||
# unconventional js | ||
/blueprint-files/ | ||
/test-fixtures/ | ||
/vendor/ | ||
|
||
# compiled output | ||
/dist/ | ||
/tmp/ | ||
/js/ | ||
|
||
# dependencies | ||
/bower_components/ | ||
/tests/dummy/lib/*/node_modules/ | ||
|
||
# misc | ||
/coverage/ | ||
|
||
# ember-try | ||
/.node_modules.ember-try/ | ||
/bower.json.ember-try | ||
/package.json.ember-try |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# compiled output | ||
/dist | ||
/tmp | ||
/js | ||
|
||
# dependencies | ||
/node_modules | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
/dist | ||
/tests | ||
/tmp | ||
/test-fixtures | ||
/ts | ||
/js/tests | ||
|
||
**/.gitkeep | ||
.bowerrc | ||
.editorconfig | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,15 @@ | ||
// @ts-check | ||
'use strict'; | ||
|
||
const IncrementalTypescriptCompiler = require('./lib/incremental-typescript-compiler'); | ||
const Funnel = require('broccoli-funnel'); | ||
const MergeTrees = require('broccoli-merge-trees'); | ||
const stew = require('broccoli-stew'); | ||
const fs = require('fs'); | ||
|
||
module.exports = { | ||
name: 'ember-cli-typescript', | ||
// If transpiled output is present, always default to loading that first. | ||
// Otherwise, register ts-node if necessary and load from source. | ||
if (fs.existsSync(`${__dirname}/js/addon.js`)) { | ||
// eslint-disable-next-line node/no-missing-require | ||
module.exports = require('./js/addon'); | ||
} else { | ||
require('./register-ts-node'); | ||
|
||
included(includer) { | ||
this._super.included.apply(this, arguments); | ||
|
||
if (includer === this.app) { | ||
this.compiler = new IncrementalTypescriptCompiler(this.app, this.project); | ||
this.compiler.launch(); | ||
} | ||
}, | ||
|
||
includedCommands() { | ||
// If we're a direct dependency of the app, we cheat and add our instance of the blueprints | ||
// addon to the project, as only top-level addons contribute blueprints. We need to be careful | ||
// with the timing of when we do this, as it has to happen after addon initialization is | ||
// complete, but before blueprint paths are resolved. | ||
// This won't be necessary in 2.x if we shift to adding the blueprints addon as a host | ||
// dependency on install. | ||
if (this.project.addons.includes(this)) { | ||
this.project.addons.push(this.addons.find(addon => addon.name === 'ember-cli-typescript-blueprints')); | ||
} | ||
|
||
if (this.project.isEmberCLIAddon()) { | ||
return { | ||
'ts:precompile': require('./lib/commands/precompile'), | ||
'ts:clean': require('./lib/commands/clean'), | ||
}; | ||
} | ||
}, | ||
|
||
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. | ||
return !['in-repo-a', 'in-repo-b', 'in-repo-c'].includes(addon.name); | ||
}, | ||
|
||
setupPreprocessorRegistry(type, registry) { | ||
if (type !== 'parent') { | ||
return; | ||
} | ||
|
||
registry.add('js', { | ||
name: 'ember-cli-typescript', | ||
ext: 'ts', | ||
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() { | ||
if (this.compiler) { | ||
let tree = this.compiler.treeForApp(); | ||
return this._super.treeForApp.call(this, tree); | ||
} | ||
}, | ||
|
||
// We manually invoke Babel for treeForAddon and treeForAddonTestSupport | ||
// rather than calling _super because we're returning content on behalf of addons that aren't | ||
// ember-cli-typescript, and the _super impl would namespace all the files under our own name. | ||
treeForAddon() { | ||
if (this.compiler) { | ||
let babel = this.project.addons.find(addon => addon.name === 'ember-cli-babel'); | ||
let tree = this.compiler.treeForAddons(); | ||
return babel.transpileTree(tree); | ||
} | ||
}, | ||
|
||
treeForTestSupport() { | ||
let trees = []; | ||
if (this.compiler) { | ||
trees.push(this.compiler.treeForTests()); | ||
trees.push(this.compiler.treeForTestSupport()); | ||
} | ||
return this._super.treeForTestSupport.call(this, | ||
stew.mv(new MergeTrees(trees), 'test-support/*', '/') | ||
); | ||
}, | ||
|
||
treeForAddonTestSupport() { | ||
if (this.compiler) { | ||
let babel = this.project.addons.find(addon => addon.name === 'ember-cli-babel'); | ||
let tree = this.compiler.treeForAddonTestSupport(); | ||
return babel.transpileTree(tree); | ||
} | ||
}, | ||
}; | ||
// eslint-disable-next-line node/no-unpublished-require | ||
module.exports = require('./ts/addon'); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,11 +24,15 @@ | |
"homepage": "https://github.com/typed-ember/ember-cli-typescript", | ||
"scripts": { | ||
"build": "ember build", | ||
"lint:js": "eslint ./*.js addon addon-test-support app blueprints config lib server test-support tests", | ||
"lint:js": "eslint --ext js,ts .", | ||
"start": "ember serve", | ||
"test": "ember test", | ||
"nodetest": "mocha node-tests --recursive", | ||
"test:all": "ember try:each" | ||
"ci:prepare": "yarn prepublishOnly && rimraf ts", | ||
"ci:test": "ember test && mocha --recursive js/tests", | ||
"test:node": "mocha -r register-ts-node 'ts/tests/**/*.{ts,js}'", | ||
"test:all": "ember try:each", | ||
"prepublishOnly": "yarn tsc --project ts --noEmit false", | ||
"postpublish": "rimraf js" | ||
}, | ||
"dependencies": { | ||
"broccoli-funnel": "^2.0.1", | ||
|
@@ -87,8 +91,11 @@ | |
"loader.js": "^4.2.3", | ||
"mktemp": "^0.4.0", | ||
"mocha": "^5.0.0", | ||
"rimraf": "^2.6.2", | ||
"testdouble": "^3.5.0", | ||
"typescript": "^2.7.2" | ||
"ts-node": "^7.0.1", | ||
"typescript": "^2.7.2", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion for follow-up: given this is for us, let's update soon to use latest TS here. It fixes quite a few bugs in the type system from what I've seen, and while we're unlikely to hit most of them outside Ember code. |
||
"typescript-eslint-parser": "^15.0.0" | ||
}, | ||
"resolutions": { | ||
"@types/ember": "2.8.13" | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
// eslint-disable-next-line node/no-deprecated-api | ||
if (!require.extensions['.ts']) { | ||
// eslint-disable-next-line node/no-unpublished-require | ||
require('ts-node').register({ | ||
project: `${__dirname}/ts/tsconfig.json` | ||
}); | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 This will help tremendously with: