Skip to content

Commit

Permalink
Merge pull request #1 from dfreeman/exclude-ts-declarations
Browse files Browse the repository at this point in the history
Don't emit modules for .d.ts files
  • Loading branch information
jamescdavis authored Jan 20, 2020
2 parents 9bf6424 + f6adfe1 commit bcbddff
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ module.exports = {
return this._cachedDebugTree.apply(null, arguments);
},

transpileTree(inputTree, config) {
transpileTree(inputTree, _config) {
let config = _config || this._getAddonOptions();
let description = `000${++count}`.slice(-3);
let postDebugTree = this._debugTree(inputTree, `${description}:input`);

Expand All @@ -51,7 +52,15 @@ module.exports = {
output = postDebugTree;
} else {
let BabelTranspiler = require('broccoli-babel-transpiler');
output = new BabelTranspiler(postDebugTree, options);
let transpilationInput = postDebugTree;

if (this._shouldHandleTypeScript(config)) {
let Funnel = require('broccoli-funnel');
let inputWithoutDeclarations = new Funnel(transpilationInput, { exclude: ['**/*.d.ts'] });
transpilationInput = this._debugTree(inputWithoutDeclarations, `${description}:filtered-input`);
}

output = new BabelTranspiler(transpilationInput, options);
}

return this._debugTree(output, `${description}:output`);
Expand Down
36 changes: 36 additions & 0 deletions node-tests/addon-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,42 @@ describe('ember-cli-babel', function() {
}));
});

describe('TypeScript transpilation', function() {
beforeEach(function() {
this.addon.parent.addons.push({
name: 'ember-cli-typescript',
pkg: {
version: '4.0.0-alpha.1'
}
});
});

it('should transpile .ts files', co.wrap(function*() {
input.write({ 'foo.ts': `let foo: string = "hi";` });

subject = this.addon.transpileTree(input.path());
output = createBuilder(subject);

yield output.build();

expect(
output.read()
).to.deep.equal({
'foo.js': `define("foo", [], function () {\n "use strict";\n\n var foo = "hi";\n});`
});
}));

it('should exclude .d.ts files', co.wrap(function*() {
input.write({ 'foo.d.ts': `declare let foo: string;` });

subject = this.addon.transpileTree(input.path());
output = createBuilder(subject);

yield output.build();

expect(output.read()).to.deep.equal({});
}))
});

describe('_shouldDoNothing', function() {
it("will no-op if nothing to do", co.wrap(function* () {
Expand Down

0 comments on commit bcbddff

Please sign in to comment.