Skip to content

Commit 25c145a

Browse files
committed
Update ts:precompile to only produce declarations
1 parent 3d4d122 commit 25c145a

File tree

2 files changed

+11
-38
lines changed

2 files changed

+11
-38
lines changed

ts/lib/commands/precompile.js

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,14 @@ module.exports = Command.extend({
4141
return execa('tsc', flags).then(() => {
4242
let output = [];
4343
for (let declSource of walkSync(outDir, { globs: ['**/*.d.ts'] })) {
44-
if (this._shouldCopy(declSource)) {
45-
let compiled = declSource.replace(/\.d\.ts$/, '.js');
46-
this._copyFile(output, `${outDir}/${compiled}`, compiled);
47-
48-
// We can only do anything meaningful with declarations for files in addon/ or src/
49-
if (this._isAddonFile(declSource)) {
50-
let declDest = declSource
51-
.replace(/^addon\//, '')
52-
.replace(/^addon-test-support/, 'test-support');
53-
this._copyFile(output, `${outDir}/${declSource}`, declDest);
54-
} else if (this._isSrcFile(declSource)) {
55-
this._copyFile(output, `${outDir}/${declSource}`, declSource);
56-
}
44+
// We can only do anything meaningful with declarations for files in addon/ or src/
45+
if (this._isAddonFile(declSource)) {
46+
let declDest = declSource
47+
.replace(/^addon\//, '')
48+
.replace(/^addon-test-support/, 'test-support');
49+
this._copyFile(output, `${outDir}/${declSource}`, declDest);
50+
} else if (this._isSrcFile(declSource)) {
51+
this._copyFile(output, `${outDir}/${declSource}`, declSource);
5752
}
5853
}
5954

@@ -63,16 +58,6 @@ module.exports = Command.extend({
6358
});
6459
},
6560

66-
_shouldCopy(source) {
67-
return this._isAppFile(source)
68-
|| this._isAddonFile(source)
69-
|| this._isSrcFile(source);
70-
},
71-
72-
_isAppFile(source) {
73-
return source.indexOf('app') === 0;
74-
},
75-
7661
_isAddonFile(source) {
7762
return source.indexOf('addon') === 0;
7863
},

ts/tests/commands/precompile-test.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('Acceptance: ts:precompile command', function() {
1818
return emberNew({ target: 'addon' }).then(() => ember(['generate', 'ember-cli-typescript']));
1919
});
2020

21-
it('generates .js and .d.ts files from the addon tree', function() {
21+
it('generates .d.ts files from the addon tree', function() {
2222
fs.ensureDirSync('addon');
2323
fs.writeFileSync('addon/test-file.ts', `export const testString: string = 'hello';`);
2424

@@ -27,29 +27,21 @@ describe('Acceptance: ts:precompile command', function() {
2727
let declaration = file('test-file.d.ts');
2828
expect(declaration).to.exist;
2929
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';`);
3430
});
3531
});
3632

37-
it('generates .js files only from the app tree', function() {
33+
it('generates nothing from the app tree', function() {
3834
fs.ensureDirSync('app');
3935
fs.writeFileSync('app/test-file.ts', `export const testString: string = 'hello';`);
4036

4137
return ember(['ts:precompile']).then(() => {
4238
let declaration = file('test-file.d.ts');
4339
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';`);
4840
});
4941
});
5042

5143
describe('module unification', function() {
52-
it('generates .js and .d.ts files from the src tree', function() {
44+
it('generates .d.ts files from the src tree', function() {
5345
fs.ensureDirSync('src');
5446
fs.writeFileSync('src/test-file.ts', `export const testString: string = 'hello';`);
5547

@@ -62,10 +54,6 @@ describe('Acceptance: ts:precompile command', function() {
6254
let declaration = file('src/test-file.d.ts');
6355
expect(declaration).to.exist;
6456
expect(declaration.content.trim()).to.equal(`export declare const testString: string;`);
65-
66-
let transpiled = file('src/test-file.js');
67-
expect(transpiled).to.exist;
68-
expect(transpiled.content.trim()).to.equal(`export const testString = 'hello';`);
6957
});
7058
});
7159
});

0 commit comments

Comments
 (0)