Skip to content

Commit

Permalink
Merge pull request mainmatter#2872 from mainmatter/typescript
Browse files Browse the repository at this point in the history
chore(typescript): ember-simple-auth initial setup
  • Loading branch information
BobrImperator authored Dec 26, 2024
2 parents db45580 + 611170e commit 9caa96c
Show file tree
Hide file tree
Showing 9 changed files with 1,196 additions and 561 deletions.
51 changes: 51 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ember from 'eslint-plugin-ember';
import prettier from 'eslint-plugin-prettier/recommended';
import globals from 'globals';
import babelParser from '@babel/eslint-parser';
import typescriptParser from '@typescript-eslint/parser';
import qunit from 'eslint-plugin-qunit';
import simplabsEmber from 'eslint-config-simplabs';
import n from 'eslint-plugin-n';
Expand Down Expand Up @@ -76,6 +77,56 @@ export default [
semi: 'off',
},
},
{
files: [
'**/app/**/*.ts',
'**/src/**/*.ts',
'**/lib/**/*.ts'
],
plugins: {
ember,
simplabsEmber,
},

languageOptions: {
globals: {
...globals.browser,
},

parser: typescriptParser,
ecmaVersion: 2020,
sourceType: 'module',

parserOptions: {
legacyDecorators: true,
},
},

rules: {
'ember/local-modules': 'off',
'ember/no-get': 'off',
'ember/avoid-leaking-state-in-components': 'off',

// Legacy Ember features
'ember/no-actions-hash': 'off',
'ember/no-classic-classes': 'off',
'ember/no-classic-components': 'off',
'ember/no-private-routing-service': 'off',
'ember/require-tagless-components': 'off',

// TODO: REMOVE
'no-implicit-coercion': 'off',
'no-multi-spaces': 'off',
'no-multi-str': 'off',
'no-trailing-spaces': 'off',
'no-unused-vars': 'off',
'no-var': 'off',
'prefer-template': 'off',
'no-prototype-builtins': 'off',
quotes: 'off',
semi: 'off',
},
},
{
files: [
'**/.babelrc.js',
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
"@eslint/js": "9.14.0",
"@mermaid-js/mermaid-cli": "11.4.2",
"@release-it-plugins/lerna-changelog": "7.0.0",
"eslint-config-simplabs": "0.4.0",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"eslint-config-prettier": "9.1.0",
"eslint-config-simplabs": "0.4.0",
"eslint-plugin-ember": "12.3.3",
"eslint-plugin-n": "17.13.2",
"eslint-plugin-prettier": "5.2.1",
Expand Down
1 change: 0 additions & 1 deletion packages/ember-simple-auth/.eslintignore

This file was deleted.

4 changes: 4 additions & 0 deletions packages/ember-simple-auth/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"plugins": [
[
"@babel/plugin-transform-typescript",
{ "allExtensions": true, "onlyRemoveTypeImports": true }
],
"@embroider/addon-dev/template-colocation-plugin",
["@babel/plugin-proposal-decorators", { "legacy": true }],
"@babel/plugin-proposal-class-properties"
Expand Down
30 changes: 22 additions & 8 deletions packages/ember-simple-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"lint:fix": "concurrently 'npm:lint:*:fix' --names 'fix:'",
"lint:hbs": "ember-template-lint . --no-error-on-unmatched-pattern",
"lint:js": "eslint . --cache",
"lint:types": "glint",
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
"lint:js:fix": "eslint . --fix",
"start": "rollup --config --watch",
Expand All @@ -41,15 +42,23 @@
"@babel/plugin-proposal-class-properties": "7.18.6",
"@babel/plugin-proposal-decorators": "7.25.9",
"@babel/runtime": "7.26.0",
"@embroider/addon-dev": "5.0.0",
"@embroider/addon-dev": "7.1.1",
"@glint/core": "^1.5.0",
"@glint/environment-ember-loose": "^1.5.0",
"@glint/environment-ember-template-imports": "^1.5.0",
"@rollup/plugin-babel": "6.0.4",
"@rollup/plugin-node-resolve": "15.3.1",
"@tsconfig/ember": "^3.0.8",
"@types/ember__service": "^4.0.9",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"concurrently": "9.1.0",
"ember-template-lint": "6.0.0",
"eslint": "8.57.1",
"prettier": "3.3.3",
"rollup": "4.25.0",
"rollup-plugin-copy": "3.5.0"
"rollup-plugin-copy": "3.5.0",
"typescript": "^5.7.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand All @@ -74,15 +83,20 @@
"exports": {
".": "./dist/index.js",
"./*": "./dist/*.js",
"./test-support": "./dist/test-support/index.js",
"./authenticators/oauth2-password-grant": "./dist/authenticators/oauth2-password-grant.js",
"./utils/is-fastboot": "./dist/utils/is-fastboot.js",
"./utils/location": "./dist/utils/location.js",
"./utils/objects-are-equal": "./dist/utils/objects-are-equal.js",
"./addon-main.js": "./addon-main.cjs"
"./addon-main.js": "./addon-main.cjs",
"./test-support": {
"types": "./declarations/test-support/*.d.ts",
"default": "./dist/test-support/index.js"
},
"./utils/*": {
"types": "./dist/utils/*.d.ts",
"default": "./dist/utils/*.js"
}
},
"peerDependencies": {
"@ember/test-helpers": ">= 3 || > 2.7"
"@ember/test-helpers": ">= 3 || > 2.7",
"ember-source": ">=4.0"
},
"peerDependenciesMeta": {
"@ember/test-helpers": {
Expand Down
5 changes: 4 additions & 1 deletion packages/ember-simple-auth/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const addon = new Addon({
});

// Add extensions here, such as ts, gjs, etc that you may import
const extensions = ['.js'];
const extensions = ['.js', '.ts'];

export default {
// This provides defaults that work well alongside `publicEntrypoints` below.
Expand Down Expand Up @@ -61,6 +61,9 @@ export default {
// Ensure that standalone .hbs files are properly integrated as Javascript.
addon.hbs(),

// Emit .d.ts
addon.declarations('declarations'),

// 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
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable no-unused-vars */
// @ts-check
import { assert } from '@ember/debug';

export default function isFastBoot(owner) {
export default function isFastBoot(owner: any) {
assert('You must pass in an owner to isFastBoot!', owner && typeof owner.lookup === 'function');
const fastboot = owner.lookup('service:fastboot');
return fastboot ? fastboot.get('isFastBoot') : false;
Expand Down
48 changes: 48 additions & 0 deletions packages/ember-simple-auth/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"extends": "@tsconfig/ember/tsconfig.json",
"include": ["src/**/*", "unpublished-development-types/**/*"],
"glint": {
"environment": ["ember-loose", "ember-template-imports"]
},
"compilerOptions": {
"allowJs": 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,

/**
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,

"types": ["ember-source/types"]
}
}
Loading

0 comments on commit 9caa96c

Please sign in to comment.