Skip to content

Commit ebf9dd3

Browse files
authored
Merge branch 'master' into work-out-of-the-box
2 parents 4f1a7c7 + 690dbe1 commit ebf9dd3

File tree

20 files changed

+244
-17
lines changed

20 files changed

+244
-17
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ module.exports = {
2626
}
2727
},
2828

29+
shouldIncludeChildAddon(addon) {
30+
// For testing, we have dummy in-repo addons set up, but e-c-ts doesn't depend on them;
31+
// its dummy app does. Otherwise we'd have a circular dependency.
32+
return addon.name !== 'in-repo-a' && addon.name !== 'in-repo-b';
33+
},
34+
2935
setupPreprocessorRegistry(type, registry) {
3036
if (type !== 'parent') {
3137
return;

lib/commands/precompile.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
const tmpdir = require('../utilities/tmpdir');
5-
const fs = require('fs');
5+
const fs = require('fs-extra');
66
const path = require('path');
77
const walkSync = require('walk-sync');
88
const mkdirp = require('mkdirp');
@@ -23,7 +23,14 @@ module.exports = Command.extend({
2323
let manifestPath = options.manifestPath;
2424
let project = this.project;
2525
let outDir = `${tmpdir()}/e-c-ts-precompile-${process.pid}`;
26-
let flags = ['--declaration', '--sourceMap', 'false'];
26+
27+
// prettier-ignore
28+
let flags = [
29+
'--declaration',
30+
'--sourceMap', 'false',
31+
'--inlineSourceMap', 'false',
32+
'--inlineSources', 'false',
33+
];
2734

2835
return compile({ project, outDir, flags }).then(() => {
2936
let output = [];
@@ -42,6 +49,7 @@ module.exports = Command.extend({
4249

4350
mkdirp.sync(path.dirname(manifestPath));
4451
fs.writeFileSync(manifestPath, JSON.stringify(output.reverse()));
52+
fs.remove(outDir);
4553
});
4654
},
4755

@@ -71,7 +79,7 @@ module.exports = Command.extend({
7179

7280
fs.writeFileSync(dest, fs.readFileSync(source));
7381
output.push(dest);
74-
}
82+
},
7583
});
7684

7785
module.exports.PRECOMPILE_MANIFEST = PRECOMPILE_MANIFEST;

node-tests/commands/clean-test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
const fs = require('fs-extra');
4+
const walkSync = require('walk-sync');
5+
6+
const ember = require('ember-cli-blueprint-test-helpers/lib/helpers/ember');
7+
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
8+
const setupTestHooks = blueprintHelpers.setupTestHooks;
9+
const emberNew = blueprintHelpers.emberNew;
10+
11+
const chai = require('ember-cli-blueprint-test-helpers/chai');
12+
const expect = chai.expect;
13+
14+
describe('Acceptance: ts:clean command', function() {
15+
setupTestHooks(this);
16+
17+
beforeEach(function() {
18+
return emberNew({ target: 'addon' }).then(() => ember(['generate', 'ember-cli-typescript']));
19+
});
20+
21+
it('removes all generated files', function() {
22+
fs.ensureDirSync('tmp');
23+
fs.ensureDirSync('app');
24+
fs.ensureDirSync('addon');
25+
fs.writeFileSync('app/test-file.ts', `export const testString: string = 'app';`);
26+
fs.writeFileSync('addon/test-file.ts', `export const testString: string = 'addon';`);
27+
28+
let before = walkSync(process.cwd());
29+
return ember(['ts:precompile'])
30+
.then(() => ember(['ts:clean']))
31+
.then(() => {
32+
let after = walkSync(process.cwd());
33+
expect(after).to.deep.equal(before);
34+
});
35+
});
36+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
const fs = require('fs-extra');
4+
5+
const ember = require('ember-cli-blueprint-test-helpers/lib/helpers/ember');
6+
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
7+
const setupTestHooks = blueprintHelpers.setupTestHooks;
8+
const emberNew = blueprintHelpers.emberNew;
9+
10+
const chai = require('ember-cli-blueprint-test-helpers/chai');
11+
const expect = chai.expect;
12+
const file = chai.file;
13+
14+
describe('Acceptance: ts:precompile command', function() {
15+
setupTestHooks(this);
16+
17+
beforeEach(function() {
18+
return emberNew({ target: 'addon' }).then(() => ember(['generate', 'ember-cli-typescript']));
19+
});
20+
21+
it('generates .js and .d.ts files from the addon tree', function() {
22+
fs.ensureDirSync('addon');
23+
fs.writeFileSync('addon/test-file.ts', `export const testString: string = 'hello';`);
24+
25+
return ember(['ts:precompile'])
26+
.then(() => {
27+
let declaration = file('test-file.d.ts');
28+
expect(declaration).to.exist;
29+
expect(declaration.content.trim()).to.equal(`export declare const testString: string;`);
30+
31+
let transpiled = file('addon/test-file.js');
32+
expect(transpiled).to.exist;
33+
expect(transpiled.content.trim()).to.equal(`export const testString = 'hello';`);
34+
});
35+
});
36+
37+
it('generates .js files only from the app tree', function() {
38+
fs.ensureDirSync('app');
39+
fs.writeFileSync('app/test-file.ts', `export const testString: string = 'hello';`);
40+
41+
return ember(['ts:precompile']).then(() => {
42+
let declaration = file('test-file.d.ts');
43+
expect(declaration).not.to.exist;
44+
45+
let transpiled = file('app/test-file.js');
46+
expect(transpiled).to.exist;
47+
expect(transpiled.content.trim()).to.equal(`export const testString = 'hello';`);
48+
});
49+
});
50+
});

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"ember-router-generator": "^1.2.3",
4949
"execa": "^0.9.0",
5050
"exists-sync": "^0.0.4",
51+
"fs-extra": "^5.0.0",
5152
"inflection": "^1.12.0",
5253
"mkdirp": "^0.5.1",
5354
"resolve": "^1.5.0",
@@ -58,8 +59,10 @@
5859
"walk-sync": "^0.3.2"
5960
},
6061
"devDependencies": {
61-
"@types/ember": "2.8.8",
62+
"@types/ember": "2.8.13",
63+
"@types/ember-qunit": "^3.0.1",
6264
"@types/node": "*",
65+
"@types/qunit": "^2.0.31",
6366
"broccoli-asset-rev": "^2.6.0",
6467
"ember-cli": "~2.18.2",
6568
"ember-cli-app-version": "^3.1.3",
@@ -84,10 +87,12 @@
8487
"eslint": "^4.17.0",
8588
"eslint-plugin-ember": "^5.0.3",
8689
"eslint-plugin-node": "^6.0.0",
87-
"fs-extra": "^5.0.0",
8890
"loader.js": "^4.2.3",
8991
"mocha": "^5.0.0",
90-
"typescript": "^2.7.1"
92+
"typescript": "^2.7.2"
93+
},
94+
"resolutions": {
95+
"@types/ember": "2.8.13"
9196
},
9297
"peerDependencies": {
9398
"typescript": "^2.4.2"
@@ -99,6 +104,10 @@
99104
"configPath": "tests/dummy/config",
100105
"before": [
101106
"ember-cli-babel"
107+
],
108+
"paths": [
109+
"tests/dummy/lib/in-repo-a",
110+
"tests/dummy/lib/in-repo-b"
102111
]
103112
},
104113
"prettier": {

tests/dummy/app/shadowed-file.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file should win out over `shadowed-file.ts` and `shadowed-file.js`
2+
// in our two in-repo addons.
3+
const value: string = 'dummy/shadowed-file';
4+
5+
export default value;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This should wind up in the addon tree
2+
const value: string = 'in-repo-a/test-file';
3+
4+
export default value;

tests/dummy/lib/in-repo-a/app/a.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This should wind up in the app tree
2+
const value: string = 'dummy/a';
3+
4+
export default value;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This should be shadowed by the dummy app's own `shadowed-file.ts`
2+
const value: string = 'bad';
3+
4+
export default value;

tests/dummy/lib/in-repo-a/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-env node */
2+
'use strict';
3+
4+
module.exports = {
5+
name: 'in-repo-a',
6+
7+
isDevelopingAddon() {
8+
return true;
9+
}
10+
};

0 commit comments

Comments
 (0)