-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Refactor --typescript support in blueprints
#10283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ff3e15e
c67d20f
cc93e93
d337b6f
05797ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = { | ||
| name: require('./package').name, | ||
| name: require('./package').name,<% if (typescript) {%> | ||
|
|
||
| options: { | ||
| 'ember-cli-babel': { enableTypeScriptTransform: true }, | ||
| },<% } %> | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "declarationDir": "declarations", | ||
| "emitDeclarationOnly": true, | ||
| "noEmit": false, | ||
| "rootDir": "." | ||
| }, | ||
| "include": ["addon", "addon-test-support"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| { | ||
| "extends": "@tsconfig/ember/tsconfig.json", | ||
| "compilerOptions": { | ||
| // The combination of `baseUrl` with `paths` allows Ember's classic package | ||
| // layout, which is not resolvable with the Node resolution algorithm, to | ||
| // work with TypeScript. | ||
| "baseUrl": ".", | ||
| "paths": { | ||
| "dummy/tests/*": ["tests/*"], | ||
| "dummy/*": ["tests/dummy/app/*", "app/*"], | ||
| "<%= addonName %>": ["addon"], | ||
| "<%= addonName %>/*": ["addon/*"], | ||
| "<%= addonName %>/test-support": ["addon-test-support"], | ||
| "<%= addonName %>/test-support/*": ["addon-test-support/*"], | ||
| "*": ["types/*"] | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,11 @@ module.exports = { | |
|
|
||
| // 95% of addons don't need ember-data or ember-fetch, make them opt-in instead | ||
| delete contents.devDependencies['ember-data']; | ||
| delete contents.devDependencies['@types/ember-data']; | ||
| delete contents.devDependencies['@types/ember-data__adapter']; | ||
| delete contents.devDependencies['@types/ember-data__model']; | ||
| delete contents.devDependencies['@types/ember-data__serializer']; | ||
| delete contents.devDependencies['@types/ember-data__store']; | ||
| delete contents.devDependencies['ember-fetch']; | ||
|
|
||
| // Per RFC #811, addons should not have this dependency. | ||
|
|
@@ -77,6 +82,22 @@ module.exports = { | |
| // 100% of addons don't need ember-cli-app-version, make it opt-in instead | ||
| delete contents.devDependencies['ember-cli-app-version']; | ||
|
|
||
| // add scripts to build type declarations for TypeScript addons | ||
| if (this.options.typescript) { | ||
| contents.devDependencies.rimraf = '^5.0.1'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How are we going to keep this up to date automatically? The dev/update-blueprint-dependencies.js doesn't play well with this currently. |
||
|
|
||
| contents.scripts.prepack = 'tsc --project tsconfig.declarations.json'; | ||
| contents.scripts.postpack = 'rimraf declarations'; | ||
simonihmig marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+89
to
+90
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, thought about this as well... but then we don't really need that rimraf script anymore, right? The previous behaviour of e-c-ts was to create the declarations only before publishing and immediately delete them afterwards, without them being git-ignored. And this is what is basically happening here as well. So should we git-ignore
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that the declarations are in their own directory instead of scattered directly throughout the project, I think removing them isn't such a big deal, but I don't feel particularly strongly about it either way 🙂
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussed with embroider core meeting and we recommend adding to gitignore and also calling rimraf either before a fresh build or after (so that extra files are not left around and picked up by typescript).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just did that! The |
||
|
|
||
| contents.typesVersions = { | ||
| '*': { | ||
| 'test-support': ['declarations/addon-test-support/index.d.ts'], | ||
| 'test-support/*': ['declarations/addon-test-support/*', 'declarations/addon-test-support/*/index.d.ts'], | ||
| '*': ['declarations/addon/*', 'declarations/addon/*/index.d.ts'], | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| merge(contents, ADDITIONAL_PACKAGE); | ||
|
|
||
| return stringifyAndNormalize(sortPackageJson(contents)); | ||
|
|
@@ -110,15 +131,6 @@ module.exports = { | |
| this.ui.writeLine(prependEmoji('✨', `Creating a new Ember addon in ${chalk.yellow(process.cwd())}:`)); | ||
| }, | ||
|
|
||
| async afterInstall(options) { | ||
| if (options.typescript) { | ||
| await this.addAddonToProject({ | ||
| name: 'ember-cli-typescript', | ||
| blueprintOptions: { ...options, save: true }, | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| locals(options) { | ||
| let entity = { name: 'dummy' }; | ||
| let rawName = entity.name; | ||
|
|
@@ -172,7 +184,9 @@ module.exports = { | |
| }, | ||
|
|
||
| files(options) { | ||
| let appFiles = this.lookupBlueprint(this.appBlueprintName).files(options); | ||
| let appFiles = this.lookupBlueprint(this.appBlueprintName) | ||
| .files(options) | ||
| .filter((file) => !['types/ember-data/types/registries/model.d.ts'].includes(file)); | ||
| let addonFilesPath = this.filesPath(this.options); | ||
| let ignoredCITemplate = this.options.ciProvider !== 'travis' ? '.travis.yml' : '.github'; | ||
|
|
||
|
|
@@ -182,6 +196,10 @@ module.exports = { | |
| addonFiles = addonFiles.filter((file) => !file.endsWith('.npmrc')); | ||
| } | ||
|
|
||
| if (!options.typescript) { | ||
| addonFiles = addonFiles.filter((file) => file !== 'tsconfig.json' && !file.endsWith('.d.ts')); | ||
| } | ||
|
|
||
| return uniq(appFiles.concat(addonFiles)); | ||
| }, | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * Type declarations for | ||
| * import config from '<%= name %>/config/environment' | ||
| */ | ||
| declare const config: { | ||
| environment: string; | ||
| modulePrefix: string; | ||
| podModulePrefix: string; | ||
| locationType: 'history' | 'hash' | 'none' | 'auto'; | ||
| rootURL: string; | ||
| APP: Record<string, unknown>; | ||
| }; | ||
|
|
||
| export default config; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # compiled output | ||
| /dist/ | ||
| /declarations/ | ||
|
|
||
| # dependencies | ||
| /node_modules/ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "extends": "@tsconfig/ember/tsconfig.json", | ||
| "compilerOptions": { | ||
| // The combination of `baseUrl` with `paths` allows Ember's classic package | ||
| // layout, which is not resolvable with the Node resolution algorithm, to | ||
| // work with TypeScript. | ||
| "baseUrl": ".", | ||
| "paths": { | ||
| "<%= name %>/tests/*": ["tests/*"], | ||
| "<%= name %>/*": ["app/*"], | ||
| "*": ["types/*"] | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** | ||
| * Catch-all for ember-data. | ||
| */ | ||
| export default interface ModelRegistry { | ||
| [key: string]: any; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import '@glint/environment-ember-loose'; |
Uh oh!
There was an error while loading. Please reload this page.