Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions blueprints/addon/additional-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"keywords": [
"ember-addon"
],
"keywords": ["ember-addon"],
"scripts": {
"test:ember-compatibility": "ember try:each"
},
Expand Down
4 changes: 3 additions & 1 deletion blueprints/addon/files/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');

module.exports = function (defaults) {
const app = new EmberAddon(defaults, {
// Add options here
<% if (typescript) {%>'ember-cli-babel': { enableTypeScriptTransform: true },

<% } %>// Add options here
});

/*
Expand Down
6 changes: 5 additions & 1 deletion blueprints/addon/files/index.js
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 },
},<% } %>
};
10 changes: 10 additions & 0 deletions blueprints/addon/files/tsconfig.declarations.json
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"]
}
18 changes: 18 additions & 0 deletions blueprints/addon/files/tsconfig.json
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/*"]
}
}
}
38 changes: 28 additions & 10 deletions blueprints/addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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';
Copy link
Member

@kellyselden kellyselden Oct 30, 2023

Choose a reason for hiding this comment

The 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';
Comment on lines +89 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add declarations/ to .gitignore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 declarations and remove rimraf, or have both?

Copy link
Contributor

Choose a reason for hiding this comment

The 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 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add declarations/ to .gitignore?

Just did that!

The .gitignore blueprint file is used for both apps and addons, so apps now also get this change. Which isn't really needed. But also that file is already a bit blurry (yarn vs. npm, ember-try stuff for apps), so I think it's ok?


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));
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';

Expand All @@ -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));
},

Expand Down
14 changes: 14 additions & 0 deletions blueprints/app/files/app/config/environment.d.ts
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;
4 changes: 3 additions & 1 deletion blueprints/app/files/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function (defaults) {
const app = new EmberApp(defaults, {
// Add options here
<% if (typescript) {%>'ember-cli-babel': { enableTypeScriptTransform: true },

<% } %>// Add options here
});

<% if (embroider) { %>const { Webpack } = require('@embroider/webpack');
Expand Down
1 change: 1 addition & 0 deletions blueprints/app/files/gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# compiled output
/dist/
/declarations/

# dependencies
/node_modules/
Expand Down
34 changes: 33 additions & 1 deletion blueprints/app/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@
"@embroider/webpack": "^3.0.0<% } %>",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2<% if (typescript) { %>",
"@glint/environment-ember-loose": "^1.0.2",
"@glint/template": "^1.0.2",
"@tsconfig/ember": "^2.0.0",
"@types/ember": "^4.0.3",
"@types/ember-data": "^4.4.10",
"@types/ember-data__adapter": "^4.0.1",
"@types/ember-data__model": "^4.0.0",
"@types/ember-data__serializer": "^4.0.1",
"@types/ember-data__store": "^4.0.2",
"@types/ember__application": "^4.0.5",
"@types/ember__array": "^4.0.3",
"@types/ember__component": "^4.0.13",
"@types/ember__controller": "^4.0.4",
"@types/ember__debug": "^4.0.3",
"@types/ember__destroyable": "^4.0.1",
"@types/ember__engine": "^4.0.4",
"@types/ember__error": "^4.0.2",
"@types/ember__helper": "^4.0.1",
"@types/ember__modifier": "^4.0.3",
"@types/ember__object": "^4.0.5",
"@types/ember__owner": "^4.0.3",
"@types/ember__polyfills": "^4.0.1",
"@types/ember__routing": "^4.0.12",
"@types/ember__runloop": "^4.0.2",
"@types/ember__service": "^4.0.2",
"@types/ember__string": "^3.0.10",
"@types/ember__template": "^4.0.1",
"@types/ember__test": "^4.0.1",
"@types/ember__utils": "^4.0.2",
"@types/qunit": "^2.19.5",
"@types/rsvp": "^4.0.4",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0<% } %>",
"broccoli-asset-rev": "^3.0.0",
Expand Down Expand Up @@ -73,7 +104,8 @@
"stylelint": "^15.8.0",
"stylelint-config-standard": "^33.0.0",
"stylelint-prettier": "^3.0.0",
"tracked-built-ins": "^3.1.1",
"tracked-built-ins": "^3.1.1<% if (typescript) { %>",
"typescript": "^5.0.4<% } %>",
"webpack": "^5.87.0"
},
"engines": {
Expand Down
14 changes: 14 additions & 0 deletions blueprints/app/files/tsconfig.json
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;
}
1 change: 1 addition & 0 deletions blueprints/app/files/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@glint/environment-ember-loose';
18 changes: 10 additions & 8 deletions blueprints/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ module.exports = {

let files = this._super();
if (options.ciProvider !== 'travis') {
this._files = files.filter((file) => file !== '.travis.yml');
files = files.filter((file) => file !== '.travis.yml');
} else {
this._files = files.filter((file) => file.indexOf('.github') < 0);
files = files.filter((file) => file.indexOf('.github') < 0);
}

if (!options.typescript) {
files = files.filter(
(file) => !['tsconfig.json', 'app/config/', 'types/'].includes(file) && !file.endsWith('.d.ts')
);
}

this._files = files;

return this._files;
},

Expand All @@ -88,10 +96,4 @@ module.exports = {
this.ui.writeLine('');
this.ui.writeLine(prependEmoji('✨', `Creating a new Ember app in ${chalk.yellow(process.cwd())}:`));
},

async afterInstall(options) {
if (options.typescript) {
await this.addAddonToProject({ name: 'ember-cli-typescript', blueprintOptions: options });
}
},
};
6 changes: 4 additions & 2 deletions tests/acceptance/init-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ describe('Acceptance: ember init', function () {

function confirmBlueprinted(typescript = false) {
let blueprintPath = path.join(root, 'blueprints', 'app', 'files');
// ignore .travis.yml
let expected = walkSync(blueprintPath, { ignore: ['.travis.yml'] })
// ignore .travis.yml and TypeScript files
let expected = walkSync(blueprintPath, {
ignore: ['.travis.yml', 'tsconfig.json', 'types', 'app/config'],
})
.map((name) => (typescript ? name : name.replace(/\.ts$/, '.js')))
.sort();
let actual = walkSync('.').sort();
Expand Down
Loading