Skip to content

Commit 7493f07

Browse files
authored
Merge branch 'master' into dependabot/npm_and_yarn/tmpl-1.0.5
2 parents 181f3d1 + 1fc5ca3 commit 7493f07

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

blueprint-files/ember-cli-typescript/__config_root__/config/environment.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare const config: {
88
environment: string;
99
modulePrefix: string;
1010
podModulePrefix: string;
11-
locationType: string;
11+
locationType: 'history' | 'hash' | 'none' | 'auto';
1212
rootURL: string;
1313
APP: Record<string, unknown>;
1414
};

ts/lib/commands/precompile.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ export default command({
5353
// addon name from its package name, we use the addon name, since that is
5454
// how it will be written for imports.
5555
let addon = this.project.addons.find((addon) => addon.root === this.project.root);
56-
if (addon && addon.name !== packageName) {
57-
packageName = addon.name;
56+
if (addon) {
57+
let addonName = addon.moduleName ? addon.moduleName() : addon.name;
58+
packageName = addonName;
5859
}
5960

6061
let createdFiles = copyDeclarations(pathRoots, paths, packageName, this.project.root);

ts/tests/commands/precompile-test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as fs from 'fs-extra';
2+
import * as path from 'path';
23
import { hook } from 'capture-console';
34
import ember from 'ember-cli-blueprint-test-helpers/lib/helpers/ember';
45
import blueprintHelpers from 'ember-cli-blueprint-test-helpers/helpers';
@@ -109,10 +110,57 @@ describe('Acceptance: ts:precompile command', function () {
109110
pkg.name = '@foo/my-addon'; // addon `name` is `my-addon`
110111
fs.writeJSONSync('package.json', pkg);
111112

113+
// CAUTION! HACKY CODE AHEAD!
114+
// The ember blueprint helper stays in the same node process, so require
115+
// keeps any previously read files cached. We need to clear out these
116+
// caches so it picks up the changes properly.
117+
delete require.cache[path.join(process.cwd(), 'index.js')];
118+
delete require.cache[path.join(process.cwd(), 'package.json')];
119+
112120
return ember(['ts:precompile']).then(() => {
113121
const declaration = file('test-support/test-file.d.ts');
114122
expect(declaration).to.exist;
115123
expect(declaration.content.trim()).to.equal(`export declare const testString: string;`);
116124
});
117125
});
126+
127+
it('generates .d.ts files for components when addon and moduleName do not match', function () {
128+
fs.ensureDirSync('addon/components');
129+
fs.writeFileSync(
130+
'addon/components/my-component.ts',
131+
`export const testString: string = 'hello';`
132+
);
133+
fs.ensureDirSync('addon-test-support');
134+
fs.writeFileSync(
135+
'addon-test-support/test-file.ts',
136+
`export const anotherTestString: string = 'hello';`
137+
);
138+
fs.writeFileSync(
139+
'index.js',
140+
`module.exports = { name: '@foo/my-addon', moduleName() { return 'my-addon'; } };`
141+
);
142+
143+
const pkg = fs.readJSONSync('package.json');
144+
pkg.name = '@foo/my-addon'; // addon `moduleName()` is `my-addon`
145+
fs.writeJSONSync('package.json', pkg);
146+
147+
// CAUTION! HACKY CODE AHEAD!
148+
// The ember blueprint helper stays in the same node process, so require
149+
// keeps any previously read files cached. We need to clear out these
150+
// caches so it picks up the changes properly.
151+
delete require.cache[path.join(process.cwd(), 'index.js')];
152+
delete require.cache[path.join(process.cwd(), 'package.json')];
153+
154+
return ember(['ts:precompile']).then(() => {
155+
const componentDecl = file('components/my-component.d.ts');
156+
expect(componentDecl).to.exist;
157+
expect(componentDecl.content.trim()).to.equal(`export declare const testString: string;`);
158+
159+
const testSupportDecl = file('test-support/test-file.d.ts');
160+
expect(testSupportDecl).to.exist;
161+
expect(testSupportDecl.content.trim()).to.equal(
162+
`export declare const anotherTestString: string;`
163+
);
164+
});
165+
});
118166
});

ts/types/ember-cli/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ declare module 'ember-cli/lib/models/addon' {
4040
serverMiddleware(options: { app: Application; options?: TaskOptions }): void | Promise<void>;
4141
testemMiddleware(app: Application, options?: TaskOptions): void;
4242
setupPreprocessorRegistry(type: 'self' | 'parent', registry: PreprocessRegistry): void;
43+
moduleName(): string;
4344
}
4445
}
4546

yarn.lock

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,21 +4550,21 @@ debug@3.1.0, debug@~3.1.0:
45504550
dependencies:
45514551
ms "2.0.0"
45524552

4553-
debug@4.2.0, debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
4553+
debug@4.2.0:
45544554
version "4.2.0"
45554555
resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1"
45564556
integrity sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==
45574557
dependencies:
45584558
ms "2.1.2"
45594559

4560-
debug@^3.0.0, debug@^3.0.1, debug@^3.1.0, debug@^3.1.1:
4560+
debug@^3.0.1, debug@^3.1.0, debug@^3.1.1:
45614561
version "3.2.6"
45624562
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
45634563
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
45644564
dependencies:
45654565
ms "^2.1.1"
45664566

4567-
debug@^4.3.2:
4567+
debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.3.2:
45684568
version "4.3.3"
45694569
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
45704570
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
@@ -6390,11 +6390,9 @@ flush-write-stream@^1.0.0:
63906390
readable-stream "^2.3.6"
63916391

63926392
follow-redirects@^1.0.0:
6393-
version "1.11.0"
6394-
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.11.0.tgz#afa14f08ba12a52963140fe43212658897bc0ecb"
6395-
integrity sha512-KZm0V+ll8PfBrKwMzdo5D13b1bur9Iq9Zd/RMmAoQQcl2PxxFml8cxXPaaPYVbV0RjNjq1CU7zIzAOqtUPudmA==
6396-
dependencies:
6397-
debug "^3.0.0"
6393+
version "1.14.7"
6394+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.7.tgz#2004c02eb9436eee9a21446a6477debf17e81685"
6395+
integrity sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==
63986396

63996397
for-in@^1.0.2:
64006398
version "1.0.2"

0 commit comments

Comments
 (0)