Skip to content

Commit 91cc55e

Browse files
authored
Merge pull request #669 from typed-ember/handle-packages
Handle package/addon name mismatch
2 parents c01c6bc + 9e61d18 commit 91cc55e

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Debug Tests",
11+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
12+
"args": [
13+
"-r", "register-ts-node",
14+
"-f", "generates .d.ts files when addon and package names do not match",
15+
"ts/tests/**/*.{ts,js}"
16+
],
17+
"internalConsoleOptions": "openOnSessionStart"
18+
}
19+
]
20+
}

ts/lib/commands/precompile.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ export default command({
3636

3737
let manifestPath = options.manifestPath;
3838
let packageName = this.project.pkg.name;
39+
40+
// Ensure that if we are dealing with an addon that is using a different
41+
// addon name from its package name, we use the addon name, since that is
42+
// how it will be written for imports.
43+
let addon = this.project.addons.find(addon => addon.root === this.project.root);
44+
if (addon && addon.name !== packageName) {
45+
packageName = addon.name;
46+
}
47+
3948
let createdFiles = copyDeclarations(pathRoots, paths, packageName, this.project.root);
4049

4150
fs.mkdirsSync(path.dirname(manifestPath));
@@ -66,5 +75,5 @@ export default command({
6675
];
6776

6877
return { rootDir, paths, pathRoots };
69-
}
78+
},
7079
});

ts/tests/commands/precompile-test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ describe('Acceptance: ts:precompile command', function() {
6060
});
6161
});
6262

63-
describe('remapped addon-test-support', function() {
64-
it('generates .d.ts files in the mapped location', function() {
63+
describe('addon-test-support', function() {
64+
it('generates .d.ts files in remapped locations', function() {
6565
fs.ensureDirSync('addon-test-support');
6666
fs.writeFileSync('addon-test-support/test-file.ts', `export const testString: string = 'hello';`);
6767

@@ -79,4 +79,21 @@ describe('Acceptance: ts:precompile command', function() {
7979
});
8080
});
8181
});
82+
83+
it('generates .d.ts files when addon and package names do not match', function() {
84+
fs.ensureDirSync('addon-test-support');
85+
fs.writeFileSync('addon-test-support/test-file.ts', `export const testString: string = 'hello';`);
86+
fs.writeFileSync('index.js', `module.exports = { name: 'my-addon' };`);
87+
88+
const pkg = fs.readJSONSync('package.json');
89+
pkg.name = '@foo/my-addon'; // addon `name` is `my-addon`
90+
fs.writeJSONSync('package.json', pkg);
91+
92+
return ember(['ts:precompile'])
93+
.then(() => {
94+
const declaration = file('test-support/test-file.d.ts');
95+
expect(declaration).to.exist;
96+
expect(declaration.content.trim()).to.equal(`export declare const testString: string;`);
97+
});
98+
});
8299
});

0 commit comments

Comments
 (0)