Skip to content

Commit

Permalink
Merge pull request #581 from mkszepp/convert-to-ts
Browse files Browse the repository at this point in the history
Convert addon to TypeScript & add glint
  • Loading branch information
NullVoxPopuli authored Sep 21, 2024
2 parents 337873d + 2bee092 commit 1572469
Show file tree
Hide file tree
Showing 38 changed files with 1,802 additions and 472 deletions.
1 change: 1 addition & 0 deletions addon/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# compiled output
/dist/
/declarations/
/tmp/

# dependencies
Expand Down
89 changes: 89 additions & 0 deletions addon/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'use strict';

module.exports = {
root: true,
// Only use overrides
// https://github.com/ember-cli/eslint-plugin-ember?tab=readme-ov-file#gtsgjs
overrides: [
{
files: ['**/*.js', '**/*.ts'],
env: { browser: true },
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
},
plugins: ['ember', 'import'],
extends: ['eslint:recommended', 'plugin:ember/recommended', 'plugin:prettier/recommended'],
rules: {
// require relative imports use full extensions
'import/extensions': ['error', 'always', { ignorePackages: true }],
'ember/no-runloop': 0,
// Add any custom rules here
},
},
// 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': 0,
// Add any custom rules here
},
},
{
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',
plugins: ['ember', 'import'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:ember/recommended-gjs',
'plugin:prettier/recommended',
],
rules: {
// require relative imports use full extensions
'import/extensions': ['error', 'always', { ignorePackages: true }],
// 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: ['eslint:recommended', 'plugin:n/recommended', 'plugin:prettier/recommended'],
},
],
};
44 changes: 0 additions & 44 deletions addon/.eslintrc.js

This file was deleted.

1 change: 1 addition & 0 deletions addon/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LICENSE.md

# compiled output
/dist/
/declarations/
/tmp/

# dependencies
Expand Down
1 change: 1 addition & 0 deletions addon/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# compiled output
/dist/
/declarations/
/tmp/

# dependencies
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions addon/addon-main.js → addon/addon-main.cjs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
'use strict';

const { addonV1Shim } = require('@embroider/addon-shim');
module.exports = addonV1Shim(__dirname);
1 change: 1 addition & 0 deletions addon/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"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-proposal-class-properties"
Expand Down
85 changes: 72 additions & 13 deletions addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,48 @@
"test": "tests"
},
"exports": {
".": "./dist/index.js",
".": {
"types": "./declarations/index.d.ts",
"default": "./dist/index.js"
},
"./*": {
"types": "./declarations/*.d.ts",
"default": "./dist/*.js"
},
"./_app_/*": "./dist/_app_/*.js",
"./modifiers/*": "./dist/modifiers/*.js",
"./services/*": "./dist/services/*.js",
"./test-support": "./dist/test-support/index.js",
"./addon-main.js": "./addon-main.js"
"./addon-main.js": "./addon-main.cjs"
},
"typesVersions": {
"*": {
"*": [
"declarations/*"
]
}
},
"files": [
"addon-main.js",
"addon-main.cjs",
"declarations",
"dist"
],
"scripts": {
"build": "rollup --config",
"prepack": "rollup --config",
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
"build": "concurrently 'pnpm:build:*'",
"build:js": "rollup --config",
"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",
"start": "rollup --config --watch",
"test": "echo 'Addon does not have tests, run tests in test-app'"
"lint:types": "glint",
"prepack": "concurrently 'pnpm:build:*'",
"start": "concurrently 'pnpm: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'"
},
"peerDependencies": {
"ember-modifier": "^3.2.0 || >= 4.0.0",
Expand All @@ -41,26 +64,62 @@
"ember-source": "^3.28.0 || >= 4.0.0"
},
"dependencies": {
"@embroider/addon-shim": "^1.8.9"
"@embroider/addon-shim": "^1.8.9",
"@embroider/macros": "^1.16.6",
"@glimmer/env": "^0.1.7",
"rsvp": "^4.8.5"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/eslint-parser": "^7.11.0",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-proposal-decorators": "^7.24.7",
"@babel/plugin-transform-typescript": "^7.25.2",
"@ember/test-helpers": "^4.0.4",
"@ember/test-waiters": "^3.1.0",
"@embroider/addon-dev": "^5.0.0",
"@glimmer/component": "^1.1.2",
"@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",
"@babel/eslint-parser": "^7.25.1",
"@tsconfig/ember": "^3.0.8",
"@types/ember": "^4.0.11",
"@types/ember__application": "^4.0.11",
"@types/ember__array": "^4.0.10",
"@types/ember__component": "^4.0.22",
"@types/ember__controller": "^4.0.12",
"@types/ember__debug": "^4.0.8",
"@types/ember__engine": "^4.0.11",
"@types/ember__error": "^4.0.6",
"@types/ember__helper": "^4.0.8",
"@types/ember__modifier": "^4.0.9",
"@types/ember__object": "^4.0.12",
"@types/ember__owner": "^4.0.9",
"@types/ember__polyfills": "^4.0.6",
"@types/ember__routing": "^4.0.22",
"@types/ember__runloop": "^4.0.10",
"@types/ember__service": "^4.0.9",
"@types/ember__string": "^3.16.3",
"@types/ember__template": "^4.0.7",
"@types/ember__test": "^4.0.6",
"@types/ember__utils": "^4.0.7",
"@types/ember__destroyable": "^4.0.5",
"@types/rsvp": "^4.0.9",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"babel-plugin-ember-template-compilation": "^2.2.5",
"concurrently": "^9.0.1",
"ember-modifier": "^4.2.0",
"ember-template-lint": "^6.0.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-ember": "^12.2.0",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-qunit": "^8.1.2",
"npm-run-all2": "^6.2.3",
"prettier": "^3.3.3",
"rollup": "^3.29.5",
"rollup-plugin-copy": "^3.5.0",
Expand All @@ -77,9 +136,9 @@
"edition": "octane"
},
"ember-addon": {
"main": "addon-main.js",
"type": "addon",
"version": 2,
"type": "addon",
"main": "addon-main.cjs",
"demoURL": "https://ember-sortable.netlify.app/",
"app-js": {
"./modifiers/sortable-group.js": "./dist/_app_/modifiers/sortable-group.js",
Expand Down
11 changes: 10 additions & 1 deletion addon/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ 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(['**/*.js']),
addon.publicEntrypoints([
'modifiers/**/*.js',
'services/**/*.js',
'test-support/**/*.js',
'utils/**/*.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 @@ -29,6 +34,7 @@ export default {
// By default, this will load the actual babel config from the file
// babel.config.json.
babel({
extensions: ['.js', '.gjs', '.ts', '.gts'],
babelHelpers: 'bundled',
}),

Expand All @@ -40,6 +46,9 @@ export default {
// 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
Loading

0 comments on commit 1572469

Please sign in to comment.