Skip to content

Commit

Permalink
Run TypeScript blueprints (#1717)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbieTheWagner authored Dec 7, 2024
1 parent 1243a9d commit e003dd9
Show file tree
Hide file tree
Showing 24 changed files with 817 additions and 382 deletions.
21 changes: 21 additions & 0 deletions config/ember-cli-update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"schemaVersion": "1.0.0",
"projectName": "ember-shepherd",
"packages": [
{
"name": "@embroider/addon-blueprint",
"version": "2.18.0",
"blueprints": [
{
"name": "@embroider/addon-blueprint",
"isBaseBlueprint": true,
"options": [
"--ci-provider=github",
"--pnpm",
"--typescript"
]
}
]
}
]
}
44 changes: 37 additions & 7 deletions ember-shepherd/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ module.exports = {
// https://github.com/ember-cli/eslint-plugin-ember?tab=readme-ov-file#gtsgjs
overrides: [
{
files: ['**/*.js'],
files: ['**/*.js', '**/*.ts'],
env: { browser: true },
parser: '@babel/eslint-parser',
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
babelOptions: {
root: __dirname,
},
},
plugins: ['ember', 'import'],
extends: [
Expand All @@ -28,6 +24,40 @@ module.exports = {
'ember/no-runloop': 'off',
},
},
// ts files
{
files: ['**/*.ts'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
rules: {
// require relative imports use full extensions
'import/extensions': ['error', 'always', { ignorePackages: true }],
'ember/no-runloop': 'off',
},
},
{
files: ['**/*.gts'],
parser: 'ember-eslint-parser',
plugins: ['ember', 'import'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:ember/recommended',
'plugin:ember/recommended-gts',
'plugin:prettier/recommended',
],
rules: {
// require relative imports use full extensions
'import/extensions': ['error', 'always', { ignorePackages: true }],
// Add any custom rules here
},
},
{
files: ['**/*.gjs'],
parser: 'ember-eslint-parser',
Expand All @@ -41,7 +71,7 @@ module.exports = {
rules: {
// require relative imports use full extensions
'import/extensions': ['error', 'always', { ignorePackages: true }],
'ember/no-runloop': 'off',
// Add any custom rules here
},
},
// node files
Expand Down
24 changes: 6 additions & 18 deletions ember-shepherd/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
{
"plugins": [
[
"@babel/plugin-transform-typescript",
{
"allExtensions": true,
"allowDeclareFields": true,
"onlyRemoveTypeImports": true
}
],
["@babel/plugin-transform-typescript", { "allExtensions": true, "onlyRemoveTypeImports": true, "allowDeclareFields": true }],
"@embroider/addon-dev/template-colocation-plugin",
"@babel/plugin-transform-class-static-block",
[
"babel-plugin-ember-template-compilation",
{
"targetFormat": "hbs",
"transforms": []
}
],
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
"@babel/plugin-transform-class-properties"
["babel-plugin-ember-template-compilation", {
"targetFormat": "hbs",
"transforms": []
}],
["module:decorator-transforms", { "runtime": { "import": "decorator-transforms/runtime" } }],
]
}
38 changes: 20 additions & 18 deletions ember-shepherd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,34 @@
},
"./addon-main.js": "./addon-main.cjs"
},
"typesVersions": {
"*": {
"*": [
"declarations/*"
]
}
},
"files": [
"addon-main.cjs",
"declarations",
"dist"
],
"scripts": {
"build": "concurrently \"pnpm:build:*\" --names \"build:\"",
"build": "concurrently 'pnpm:build:*'",
"build:js": "rollup --config",
"build:types": "tsc",
"build:types": "glint --declaration",
"lint": "concurrently 'pnpm:lint:*(!fix)' --names 'lint:'",
"lint:fix": "concurrently 'pnpm:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:types": "tsc --emitDeclarationOnly false --noEmit",
"prepack": "pnpm run build",
"start": "concurrently \"pnpm:start:*\" --names \"start:\"",
"lint:types": "glint",
"prepack": "concurrently 'pnpm:build:*'",
"start": "concurrently 'pnpm:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "tsc --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
"prepare": "pnpm run build"
"start:types": "glint --declaration --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'"
},
"dependencies": {
"@babel/core": "^7.26.0",
Expand All @@ -55,10 +61,13 @@
},
"devDependencies": {
"@babel/core": "^7.24.4",
"@babel/eslint-parser": "^7.25.9",
"@babel/plugin-transform-typescript": "^7.25.9",
"@babel/runtime": "^7.26.0",
"@babel/plugin-transform-typescript": "^7.24.4",
"@babel/runtime": "^7.24.4",
"@embroider/addon-dev": "^4.3.1",
"@glint/core": "^1.4.0",
"@glint/environment-ember-loose": "^1.4.0",
"@glint/environment-ember-template-imports": "^1.4.0",
"@glint/template": "^1.4.0",
"@rollup/plugin-babel": "^6.0.4",
"@tsconfig/ember": "^3.0.8",
"babel-plugin-ember-template-compilation": "^2.3.0",
Expand Down Expand Up @@ -94,12 +103,5 @@
"app-js": {
"./services/tour.js": "./dist/_app_/services/tour.js"
}
},
"typesVersions": {
"*": {
"*": [
"declarations/*"
]
}
}
}
1 change: 0 additions & 1 deletion ember-shepherd/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default {
'helpers/**/*.js',
'modifiers/**/*.js',
'services/**/*.js',
'modifiers/**/*.js',
]),

// Follow the V2 Addon rules about dependencies. Your code can import from
Expand Down
Empty file added ember-shepherd/src/index.ts
Empty file.
2 changes: 1 addition & 1 deletion ember-shepherd/src/services/tour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Evented from '@ember/object/evented';
import { registerDestructor } from '@ember/destroyable';
import type Owner from '@ember/owner';
import { bind } from '@ember/runloop';
import { isTesting, macroCondition } from '@embroider/macros';
import { isTesting } from '@embroider/macros';
import { tracked } from '@glimmer/tracking';

import { type StepOptions, type Tour } from 'shepherd.js';
Expand Down
54 changes: 47 additions & 7 deletions ember-shepherd/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"include": [
"src/**/*",
"unpublished-development-types/**/*"
],
"glint": {
"environment": ["ember-loose", "ember-template-imports"]
},
"compilerOptions": {
"allowImportingTsExtensions": true,
"allowJs": true,
"skipLibCheck": true,
"declaration": true,
"declarationDir": "declarations",
/**
https://www.typescriptlang.org/tsconfig#noEmit
We want to emit declarations, so this option must be set to `false`.
@tsconfig/ember sets this to `true`, which is incompatible with our need to set `emitDeclarationOnly`.
@tsconfig/ember is more optimized for apps, which wouldn't emit anything, only type check.
*/
"noEmit": false,
/**
https://www.typescriptlang.org/tsconfig#emitDeclarationOnly
We want to only emit declarations as we use Rollup to emit JavaScript.
*/
"emitDeclarationOnly": true,
"noEmit": false
},
"include": ["src/**/*", "unpublished-development-types/**/*"],
"extends": "@tsconfig/ember/tsconfig.json"

/**
https://www.typescriptlang.org/tsconfig#noEmitOnError
Do not block emit on TS errors.
*/
"noEmitOnError": false,

/**
https://www.typescriptlang.org/tsconfig#rootDir
"Default: The longest common path of all non-declaration input files."
Because we want our declarations' structure to match our rollup output,
we need this "rootDir" to match the "srcDir" in the rollup.config.mjs.
This way, we can have simpler `package.json#exports` that matches
imports to files on disk
*/
"rootDir": "./src",

/**
https://www.typescriptlang.org/tsconfig#allowImportingTsExtensions
We want our tooling to know how to resolve our custom files so the appropriate plugins
can do the proper transformations on those files.
*/
"allowImportingTsExtensions": true
}
}
14 changes: 14 additions & 0 deletions ember-shepherd/unpublished-development-types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Add any types here that you need for local development only.
// These will *not* be published as part of your addon, so be careful that your published code does not rely on them!

import '@glint/environment-ember-loose';
import '@glint/environment-ember-template-imports';

declare module '@glint/environment-ember-loose/registry' {
// Remove this once entries have been added! 👇
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export default interface Registry {
// Add any registry entries from other addons here that your addon itself uses (in non-strict mode templates)
// See https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"test:ember": "pnpm --filter '*' test:ember"
},
"devDependencies": {
"@glint/core": "^1.2.1",
"@release-it-plugins/lerna-changelog": "^6.1.0",
"@release-it-plugins/workspaces": "^4.2.0",
"concurrently": "^8.2.2",
Expand Down Expand Up @@ -55,4 +56,4 @@
"npm": false
},
"version": "17.3.0"
}
}
Loading

0 comments on commit e003dd9

Please sign in to comment.