Skip to content

Commit

Permalink
Add full TS/glint support (#1163)
Browse files Browse the repository at this point in the history
* Add full TS/glint support

* Remove and ignore declarations

* Update .eslintignore

* Update random.ts

* Update test watching

* Fix pnpm and tests
  • Loading branch information
RobbieTheWagner authored Nov 2, 2023
1 parent 857d10d commit 68c08dd
Show file tree
Hide file tree
Showing 135 changed files with 2,006 additions and 1,790 deletions.
5 changes: 4 additions & 1 deletion docs/ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ function isProduction() {

module.exports = function (defaults) {
const app = new EmberApp(defaults, {
// Add options here
'ember-cli-babel': { enableTypeScriptTransform: true },
autoImport: {
watchDependencies: ['ember-math-helpers'],
},
});

const { Webpack } = require('@embroider/webpack');
Expand Down
11 changes: 9 additions & 2 deletions ember-math-helpers/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
dist/
node_modules/
# unconventional js
/blueprints/*/files/

# compiled output
/dist/
/declarations/

# misc
/coverage/
51 changes: 48 additions & 3 deletions ember-math-helpers/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,50 @@
'use strict';

const { configs } = require('@nullvoxpopuli/eslint-configs');

module.exports = configs.ember({ prettierIntegration: true });
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
},
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true,
},
rules: {},
overrides: [
// ts files
{
files: ['**/*.ts', '**/*.gts'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
// Add any custom rules here
},
},
// node files
{
files: [
'./.eslintrc.cjs',
'./.prettierrc.cjs',
'./.template-lintrc.cjs',
'./addon-main.cjs',
],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
plugins: ['n'],
extends: ['plugin:n/recommended'],
},
],
};
12 changes: 12 additions & 0 deletions ember-math-helpers/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# The authoritative copies of these live in the monorepo root (because they're
# more useful on github that way), but the build copies them into here so they
# will also appear in published NPM packages.
/README.md
/LICENSE.md

# compiled output
/dist
/declarations

# npm/pnpm/yarn pack output
*.tgz
18 changes: 17 additions & 1 deletion ember-math-helpers/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
{
"plugins": [
[
"@babel/plugin-transform-typescript",
{
"allExtensions": true,
"onlyRemoveTypeImports": true,
"allowDeclareFields": true
}
],
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-transform-class-static-block",
[
"babel-plugin-ember-template-compilation",
{
"targetFormat": "hbs",
"transforms": []
}
],
["@babel/plugin-proposal-decorators", { "version": "legacy" }],
"@babel/plugin-proposal-class-properties"
]
}
99 changes: 67 additions & 32 deletions ember-math-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,77 @@
"email": "[email protected]",
"url": "https://github.com/RobbieTheWagner"
},
"exports": {
"./*": {
"types": "./types/*.d.ts",
"default": "./dist/*.js"
}
},
"typesVersions": {
"*": {
"*": [
"types/*"
]
}
},
"files": [
"dist",
"types",
"addon-main.cjs",
"CHANGELOG.md",
"README.md"
],
"scripts": {
"start": "concurrently 'npm:watch:*'",
"build": "concurrently 'npm:build:*'",
"build:docs": "cp ../README.md ./README.md",
"build:js": "rollup -c ./rollup.config.mjs",
"watch:js": "rollup -c --watch --no-watch.clearScreen",
"build:js": "rollup --config",
"build:types": "glint --declaration",
"lint": "concurrently 'npm:lint:js'",
"lint:fix": "concurrently 'npm:lint:js:fix'",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"test": "echo 'Addon does not have tests, run tests in test-app'",
"lint:types": "glint",
"start": "concurrently 'npm:start:*'",
"start:js": "rollup --config --watch --no-watch.clearScreen",
"start:types": "glint --declaration --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
"prepack": "rollup --config",
"prepare": "pnpm build",
"prepublishOnly": "pnpm build"
},
"dependencies": {
"@embroider/addon-shim": "^1.8.6"
},
"devDependencies": {
"@babel/core": "7.23.2",
"@babel/plugin-proposal-class-properties": "7.18.6",
"@babel/plugin-proposal-decorators": "7.23.2",
"@babel/plugin-syntax-decorators": "7.22.10",
"@babel/core": "^7.23.2",
"@babel/plugin-transform-typescript": "^7.22.15",
"@babel/plugin-proposal-class-properties": "^7.16.7",
"@babel/plugin-proposal-decorators": "^7.20.13",
"@babel/plugin-transform-class-static-block": "^7.20.0",
"@babel/runtime": "^7.17.0",
"@embroider/addon-dev": "^4.1.1",
"@glint/template": "^1.2.1",
"@nullvoxpopuli/eslint-configs": "3.2.2",
"@glint/core": "^1.2.0",
"@glint/environment-ember-loose": "^1.2.0",
"@glint/environment-ember-template-imports": "^1.2.0",
"@glint/template": "^1.2.0",
"@rollup/plugin-babel": "6.0.4",
"@tsconfig/ember": "^2.0.0",
"@types/ember": "^4.0.4",
"@types/ember__object": "^4.0.6",
"@types/ember__owner": "^4.0.4",
"@types/ember__service": "^4.0.3",
"@types/ember__controller": "^4.0.5",
"@types/ember__string": "^3.16.3",
"@types/ember__template": "^4.0.2",
"@types/ember__polyfills": "^4.0.2",
"@types/ember__utils": "^4.0.3",
"@types/ember__runloop": "^4.0.3",
"@types/ember__debug": "^4.0.4",
"@types/ember__engine": "^4.0.5",
"@types/ember__application": "^4.0.6",
"@types/ember__test": "^4.0.2",
"@types/ember__array": "^4.0.4",
"@types/ember__error": "^4.0.3",
"@types/ember__component": "^4.0.14",
"@types/ember__modifier": "^4.0.6",
"@types/ember__helper": "^4.0.3",
"@types/ember__routing": "^4.0.13",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"concurrently": "8.2.2",
"eslint": "^8.52.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-decorator-position": "5.0.2",
"eslint-plugin-ember": "11.11.1",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-json": "3.1.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-n": "^16.0.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-simple-import-sort": "10.0.0",
"prettier": "^3.0.3",
"rollup": "^4.2.0"
},
"peerDependencies": {
"@glint/template": "^1.2.1",
"ember-source": "^4.0.0 || ^5.0.0"
},
"publishConfig": {
Expand Down Expand Up @@ -130,6 +140,31 @@
"./helpers/trunc.js": "./dist/_app_/helpers/trunc.js"
}
},
"files": [
"addon-main.cjs",
"declarations",
"dist",
"CHANGELOG.md",
"README.md"
],
"exports": {
".": {
"types": "./declarations/index.d.ts",
"default": "./dist/index.js"
},
"./*": {
"types": "./declarations/*.d.ts",
"default": "./dist/*.js"
},
"./addon-main.js": "./addon-main.cjs"
},
"typesVersions": {
"*": {
"*": [
"declarations/*"
]
}
},
"engines": {
"node": "14.* || 16.* || >= 18"
}
Expand Down
17 changes: 11 additions & 6 deletions ember-math-helpers/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
plugins: [
// These are the modules that users should be able to import from your
// addon. Anything not listed here may get optimized away.
addon.publicEntrypoints(['helpers/**/*.js']),
addon.publicEntrypoints(['helpers/**/*.js', 'template-registry.js']),

// These are the modules that should get reexported into the traditional
// "app" tree. Things in here should also be in publicEntrypoints above, but
Expand All @@ -24,21 +24,26 @@ export default {
// This babel config should *not* apply presets or compile away ES modules.
// It exists only to provide development niceties for you, like automatic
// template colocation.

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
// package names.
addon.dependencies(),

//
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
extensions: ['.js', '.gjs', '.ts', '.gts'],
babelHelpers: 'bundled',
}),

// Follow the V2 Addon rules about dependencies. Your code can import from
// `dependencies` and `peerDependencies` as well as standard Ember-provided
// package names.
addon.dependencies(),

// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// Ensure that .gjs files are properly integrated as Javascript
addon.gjs(),

// addons are allowed to contain imports of .css files, which we want rollup
// to leave alone and keep in the published output.
addon.keepAssets(['**/*.css']),
Expand Down
17 changes: 0 additions & 17 deletions ember-math-helpers/src/helpers/abs.js

This file was deleted.

24 changes: 24 additions & 0 deletions ember-math-helpers/src/helpers/abs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { helper } from '@ember/component/helper';

export interface AbsSignature {
Args: {
Positional: [number];
};
Return: number;
}

/**
* Uses `Math.abs` to take the absolute value of the number passed to the helper.
*
* ```hbs
* {{abs a}}
* ```
*
* @param number The number to take the absolute value of
* @return The absolute value of the passed number
*/
export function abs([number]: [number]) {
return Math.abs(number);
}

export default helper<AbsSignature>(abs);
17 changes: 0 additions & 17 deletions ember-math-helpers/src/helpers/acos.js

This file was deleted.

24 changes: 24 additions & 0 deletions ember-math-helpers/src/helpers/acos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { helper } from '@ember/component/helper';

export interface AcosSignature {
Args: {
Positional: [number];
};
Return: number;
}

/**
* Executes `Math.acos` on the number passed to the helper.
*
* ```hbs
* {{acos a}}
* ```
*
* @param number The number to pass to `Math.acos`
* @return The acos of the passed number
*/
export function acos([number]: [number]) {
return Math.acos(number);
}

export default helper<AcosSignature>(acos);
Loading

0 comments on commit 68c08dd

Please sign in to comment.