From 769b0f793ebbd2a3bd2e21963724606360e8c625 Mon Sep 17 00:00:00 2001 From: Sergey Astapov Date: Wed, 27 Nov 2024 23:06:58 -0500 Subject: [PATCH 1/2] Convert to TypeScript --- package.json | 49 ++++-- pnpm-lock.yaml | 196 +++++++++++++++++------ rollup.config.mjs | 1 + src/{index.js => index.gts} | 0 src/modifiers/{pikaday.js => pikaday.ts} | 45 ++++-- src/template-registry.ts | 11 ++ tsconfig.json | 54 +++++++ unpublished-development-types/index.d.ts | 14 ++ 8 files changed, 299 insertions(+), 71 deletions(-) rename src/{index.js => index.gts} (100%) rename src/modifiers/{pikaday.js => pikaday.ts} (62%) create mode 100644 src/template-registry.ts create mode 100644 tsconfig.json create mode 100644 unpublished-development-types/index.d.ts diff --git a/package.json b/package.json index adc5042..5be42ee 100644 --- a/package.json +++ b/package.json @@ -11,33 +11,48 @@ "license": "MIT", "author": "David Strauß", "exports": { - ".": "./dist/index.js", - "./*": "./dist/*", - "./test-support": "./dist/test-support/index.js", - "./addon-main.js": "./addon-main.js", + ".": { + "types": "./declarations/index.d.ts", + "default": "./dist/index.js" + }, + "./*": { + "types": "./declarations/*.d.ts", + "default": "./dist/*.js" + }, + "./test-support": { + "types": "./declarations/test-support/index.d.ts", + "default": "./dist/test-support/index.js" + }, + "./addon-main.js": "./addon-main.cjs", "./pikaday.css": "./vendor/pikaday.css" }, "files": [ - "addon-main.js", + "addon-main.cjs", + "declarations", "dist", "vendor/pikaday.css" ], "scripts": { + "build": "concurrently 'pnpm:build:*'", + "build:js": "rollup --config", + "build:types": "glint --declaration", "clean": "rm -rf dist node_modules test-app/node_modules", "lint": "concurrently 'pnpm:lint:*(!fix)' --names 'lint:'", - "lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\" --prefixColors auto", - "lint:hbs": "ember-template-lint .", - "lint:hbs:fix": "ember-template-lint . --fix", + "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", - "prepare": "rollup --config", - "prepublishOnly": "rollup --config", + "lint:types": "glint", + "prepack": "concurrently 'pnpm:build:*'", + "prepare": "concurrently 'pnpm:build:*'", "scenario:list": "scenario-tester list --files test-app/scenarios.js", "scenario:output": "scenario-tester output --files test-app/scenarios.js --outdir scenario --scenario ", "scenario:run": "cd test-app && qunit scenarios.js --filter ", "start": "concurrently 'pnpm:start:*' --restart-after 5000 --prefix-colors cyan,white,yellow", - "start:build": "rollup --config --watch", + "start:js": "rollup --config --watch --no-watch.clearScreen", "start:test-app": "cd test-app && ember serve", + "start:types": "glint --declaration --watch", "test": "concurrently 'pnpm:lint:*(!fix)' 'pnpm:test:*'", "test:ember": "cd test-app && ember test", "test:ember-compatibility": "cd test-app && pnpm qunit scenarios.js" @@ -60,7 +75,12 @@ "@embroider/test-setup": "npm:@embroider/test-setup@latest", "@embroider/webpack": "npm:@embroider/webpack@latest", "@eslint/js": "^9.15.0", + "@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.6", "babel-plugin-ember-template-compilation": "^2.3.0", "concurrently": "^9.1.0", "ember-cli-beta": "npm:ember-cli@beta", @@ -97,6 +117,7 @@ "prettier-plugin-ember-template-tag": "^2.0.4", "release-plan": "^0.11.0", "rollup": "^4.27.4", + "typescript": "^5.7.2", "typescript-eslint": "^8.16.0" }, "peerDependencies": { @@ -120,6 +141,12 @@ "node": "20.18.0", "pnpm": "9.14.2" }, + "publishConfig": { + "registry": "https://registry.npmjs.org" + }, + "ember": { + "edition": "octane" + }, "ember-addon": { "version": 2, "type": "addon", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49a6307..8e3e8d0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,9 +60,24 @@ importers: '@eslint/js': specifier: ^9.15.0 version: 9.15.0 + '@glint/core': + specifier: ^1.4.0 + version: 1.5.0(typescript@5.7.2) + '@glint/environment-ember-loose': + specifier: ^1.4.0 + version: 1.5.0(@glimmer/component@2.0.0)(@glint/template@1.5.0)(ember-cli-htmlbars@6.3.0)(ember-modifier@4.2.0(@babel/core@7.26.0)(ember-source@6.2.0-alpha.4(@glimmer/component@2.0.0)(@glint/template@1.5.0)(rsvp@4.8.5)(webpack@4.47.0))) + '@glint/environment-ember-template-imports': + specifier: ^1.4.0 + version: 1.5.0(@glint/environment-ember-loose@1.5.0(@glimmer/component@2.0.0)(@glint/template@1.5.0)(ember-cli-htmlbars@6.3.0)(ember-modifier@4.2.0(@babel/core@7.26.0)(ember-source@6.2.0-alpha.4(@glimmer/component@2.0.0)(@glint/template@1.5.0)(rsvp@4.8.5)(webpack@4.47.0))))(@glint/template@1.5.0) + '@glint/template': + specifier: ^1.4.0 + version: 1.5.0 '@rollup/plugin-babel': specifier: ^6.0.4 version: 6.0.4(@babel/core@7.26.0)(rollup@4.27.4) + '@tsconfig/ember': + specifier: ^3.0.6 + version: 3.0.8 babel-plugin-ember-template-compilation: specifier: ^2.3.0 version: 2.3.0 @@ -143,10 +158,10 @@ importers: version: 9.1.0(eslint@9.15.0) eslint-plugin-ember: specifier: ^12.3.3 - version: 12.3.3(@babel/core@7.26.0)(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint@9.15.0) + version: 12.3.3(@babel/core@7.26.0)(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint@9.15.0) eslint-plugin-import: specifier: ^2.31.0 - version: 2.31.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint@9.15.0) + version: 2.31.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint@9.15.0) eslint-plugin-n: specifier: ^17.14.0 version: 17.14.0(eslint@9.15.0) @@ -171,9 +186,12 @@ importers: rollup: specifier: ^4.27.4 version: 4.27.4 + typescript: + specifier: ^5.7.2 + version: 5.7.2 typescript-eslint: specifier: ^8.16.0 - version: 8.16.0(eslint@9.15.0)(typescript@5.6.3) + version: 8.16.0(eslint@9.15.0)(typescript@5.7.2) test-app: devDependencies: @@ -1299,6 +1317,12 @@ packages: '@glimmer/wire-format@0.92.3': resolution: {integrity: sha512-gFz81Q9+V7Xs0X8mSq6y8qacHm0dPaGJo2/Bfcsdow1hLOKNgTCLr4XeDBhRML8f6I6Gk9ugH4QDxyIOXOpC4w==} + '@glint/core@1.5.0': + resolution: {integrity: sha512-oo6ZDwX2S0Qqjai/CJH72LHg1U6rvzH1IyiFlWofaFiu/nSg04CDWZuJNPC3r47jz1+SaSI+mVMUaKJznzxzzQ==} + hasBin: true + peerDependencies: + typescript: '>=4.8.0' + '@glint/environment-ember-loose@1.5.0': resolution: {integrity: sha512-QCP4pVupq8zGcBmMDcEq9XI5lfrnklwNOIuzdXb8OnbcY6qpuwz5Y6VOsA1WNGRcip/5wwOsmI6gsAEUTlbvPQ==} peerDependencies: @@ -1327,6 +1351,25 @@ packages: ember-modifier: optional: true + '@glint/environment-ember-template-imports@1.5.0': + resolution: {integrity: sha512-SS+KNffLuNYcsT7iEmCr2jp2538E7KTMEAWY+KWNvUJ0ZMd6oe6xbIIF50+9BgCgGHWwj7oL/NdgCVkS3OqRdw==} + peerDependencies: + '@glint/environment-ember-loose': ^1.5.0 + '@glint/template': ^1.5.0 + '@types/ember__component': ^4.0.10 + '@types/ember__helper': ^4.0.1 + '@types/ember__modifier': ^4.0.3 + '@types/ember__routing': ^4.0.12 + peerDependenciesMeta: + '@types/ember__component': + optional: true + '@types/ember__helper': + optional: true + '@types/ember__modifier': + optional: true + '@types/ember__routing': + optional: true + '@glint/template@1.5.0': resolution: {integrity: sha512-KyQUCWifxl8wDxo3SXzJcGKttHbIPgFBtqsoiu13Edx/o4CgGXr5rrM64jJR7Wvunn8sRM+Rq7Y0cHoB068Wuw==} @@ -1686,6 +1729,9 @@ packages: resolution: {integrity: sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==} engines: {node: '>= 6'} + '@tsconfig/ember@3.0.8': + resolution: {integrity: sha512-OVnIsZIt/8q0VEtcdz3rRryNrm6gdJTxXlxefkGIrkZnME0wqslmwHlUEZ7mvh377df9FqBhNKrYNarhCW8zJA==} + '@types/babel__code-frame@7.0.6': resolution: {integrity: sha512-Anitqkl3+KrzcW2k77lRlg/GfLZLWXBuNgbEcIOU6M92yw42vsd3xV/Z/yAHEj8m+KUjL6bWOVOFqX8PFPJ4LA==} @@ -7468,8 +7514,8 @@ packages: typescript-memoize@1.1.1: resolution: {integrity: sha512-GQ90TcKpIH4XxYTI2F98yEQYZgjNMOGPpOgdjIBhaLaWji5HPWlRnZ4AeA1hfBxtY7bCGDJsqDDHk/KaHOl5bA==} - typescript@5.6.3: - resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==} + typescript@5.7.2: + resolution: {integrity: sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==} engines: {node: '>=14.17'} hasBin: true @@ -7637,6 +7683,26 @@ packages: vm-browserify@1.1.2: resolution: {integrity: sha512-2ham8XPWTONajOR0ohOKOHXkm3+gaBmGut3SRuu75xLd/RRaY6vqgh8NBYYk7+RW3u5AtzPQZG8F10LHkl0lAQ==} + vscode-jsonrpc@8.1.0: + resolution: {integrity: sha512-6TDy/abTQk+zDGYazgbIPc+4JoXdwC8NHU9Pbn4UJP1fehUyZmM4RHp5IthX7A6L5KS30PRui+j+tbbMMMafdw==} + engines: {node: '>=14.0.0'} + + vscode-languageserver-protocol@3.17.3: + resolution: {integrity: sha512-924/h0AqsMtA5yK22GgMtCYiMdCOtWTSGgUOkgEDX+wk2b0x4sAfLiO4NxBxqbiVtz7K7/1/RgVrVI0NClZwqA==} + + vscode-languageserver-textdocument@1.0.12: + resolution: {integrity: sha512-cxWNPesCnQCcMPeenjKKsOCKQZ/L6Tv19DTRIGuLWe32lyzWhihGVJ/rcckZXJxfdKCFvRLS3fpBIsV/ZGX4zA==} + + vscode-languageserver-types@3.17.3: + resolution: {integrity: sha512-SYU4z1dL0PyIMd4Vj8YOqFvHu7Hz/enbWtpfnVbJHU4Nd1YNYx8u0ennumc6h48GQNeOLxmwySmnADouT/AuZA==} + + vscode-languageserver@8.1.0: + resolution: {integrity: sha512-eUt8f1z2N2IEUDBsKaNapkz7jl5QpskN2Y0G01T/ItMxBxw1fJwvtySGB9QMecatne8jFIWJGWI61dWjyTLQsw==} + hasBin: true + + vscode-uri@3.0.8: + resolution: {integrity: sha512-AyFQ0EVmsOZOlAnxoFOGOq1SQDWAB7C6aqMGS23svWAllfOaxbuFvcT8D1i8z3Gyn8fraVeZNNmN6e9bxxXkKw==} + w3c-xmlserializer@5.0.0: resolution: {integrity: sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==} engines: {node: '>=18'} @@ -9610,6 +9676,21 @@ snapshots: '@glimmer/interfaces': 0.92.3 '@glimmer/util': 0.92.3 + '@glint/core@1.5.0(typescript@5.7.2)': + dependencies: + '@glimmer/syntax': 0.84.3 + escape-string-regexp: 4.0.0 + semver: 7.6.3 + silent-error: 1.1.1 + typescript: 5.7.2 + uuid: 8.3.2 + vscode-languageserver: 8.1.0 + vscode-languageserver-textdocument: 1.0.12 + vscode-uri: 3.0.8 + yargs: 17.7.2 + transitivePeerDependencies: + - supports-color + '@glint/environment-ember-loose@1.5.0(@glimmer/component@2.0.0)(@glint/template@1.5.0)(ember-cli-htmlbars@6.3.0)(ember-modifier@4.2.0(@babel/core@7.26.0)(ember-source@6.2.0-alpha.4(@glimmer/component@2.0.0)(@glint/template@1.5.0)(rsvp@4.8.5)(webpack@4.47.0)))': dependencies: '@glimmer/component': 2.0.0 @@ -9617,10 +9698,14 @@ snapshots: optionalDependencies: ember-cli-htmlbars: 6.3.0 ember-modifier: 4.2.0(@babel/core@7.26.0)(ember-source@6.2.0-alpha.4(@glimmer/component@2.0.0)(@glint/template@1.5.0)(rsvp@4.8.5)(webpack@4.47.0)) - optional: true - '@glint/template@1.5.0': - optional: true + '@glint/environment-ember-template-imports@1.5.0(@glint/environment-ember-loose@1.5.0(@glimmer/component@2.0.0)(@glint/template@1.5.0)(ember-cli-htmlbars@6.3.0)(ember-modifier@4.2.0(@babel/core@7.26.0)(ember-source@6.2.0-alpha.4(@glimmer/component@2.0.0)(@glint/template@1.5.0)(rsvp@4.8.5)(webpack@4.47.0))))(@glint/template@1.5.0)': + dependencies: + '@glint/environment-ember-loose': 1.5.0(@glimmer/component@2.0.0)(@glint/template@1.5.0)(ember-cli-htmlbars@6.3.0)(ember-modifier@4.2.0(@babel/core@7.26.0)(ember-source@6.2.0-alpha.4(@glimmer/component@2.0.0)(@glint/template@1.5.0)(rsvp@4.8.5)(webpack@4.47.0))) + '@glint/template': 1.5.0 + content-tag: 2.0.3 + + '@glint/template@1.5.0': {} '@handlebars/parser@2.0.0': {} @@ -9984,6 +10069,8 @@ snapshots: '@tootallnate/once@1.1.2': {} + '@tsconfig/ember@3.0.8': {} + '@types/babel__code-frame@7.0.6': {} '@types/body-parser@1.19.5': @@ -10099,34 +10186,34 @@ snapshots: dependencies: '@types/yargs-parser': 21.0.3 - '@typescript-eslint/eslint-plugin@8.16.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint@9.15.0)(typescript@5.6.3)': + '@typescript-eslint/eslint-plugin@8.16.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint@9.15.0)(typescript@5.7.2)': dependencies: '@eslint-community/regexpp': 4.12.1 - '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.6.3) + '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.7.2) '@typescript-eslint/scope-manager': 8.16.0 - '@typescript-eslint/type-utils': 8.16.0(eslint@9.15.0)(typescript@5.6.3) - '@typescript-eslint/utils': 8.16.0(eslint@9.15.0)(typescript@5.6.3) + '@typescript-eslint/type-utils': 8.16.0(eslint@9.15.0)(typescript@5.7.2) + '@typescript-eslint/utils': 8.16.0(eslint@9.15.0)(typescript@5.7.2) '@typescript-eslint/visitor-keys': 8.16.0 eslint: 9.15.0 graphemer: 1.4.0 ignore: 5.3.2 natural-compare: 1.4.0 - ts-api-utils: 1.4.0(typescript@5.6.3) + ts-api-utils: 1.4.0(typescript@5.7.2) optionalDependencies: - typescript: 5.6.3 + typescript: 5.7.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3)': + '@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2)': dependencies: '@typescript-eslint/scope-manager': 8.16.0 '@typescript-eslint/types': 8.16.0 - '@typescript-eslint/typescript-estree': 8.16.0(typescript@5.6.3) + '@typescript-eslint/typescript-estree': 8.16.0(typescript@5.7.2) '@typescript-eslint/visitor-keys': 8.16.0 debug: 4.3.7(supports-color@8.1.1) eslint: 9.15.0 optionalDependencies: - typescript: 5.6.3 + typescript: 5.7.2 transitivePeerDependencies: - supports-color @@ -10135,21 +10222,21 @@ snapshots: '@typescript-eslint/types': 8.16.0 '@typescript-eslint/visitor-keys': 8.16.0 - '@typescript-eslint/type-utils@8.16.0(eslint@9.15.0)(typescript@5.6.3)': + '@typescript-eslint/type-utils@8.16.0(eslint@9.15.0)(typescript@5.7.2)': dependencies: - '@typescript-eslint/typescript-estree': 8.16.0(typescript@5.6.3) - '@typescript-eslint/utils': 8.16.0(eslint@9.15.0)(typescript@5.6.3) + '@typescript-eslint/typescript-estree': 8.16.0(typescript@5.7.2) + '@typescript-eslint/utils': 8.16.0(eslint@9.15.0)(typescript@5.7.2) debug: 4.3.7(supports-color@8.1.1) eslint: 9.15.0 - ts-api-utils: 1.4.0(typescript@5.6.3) + ts-api-utils: 1.4.0(typescript@5.7.2) optionalDependencies: - typescript: 5.6.3 + typescript: 5.7.2 transitivePeerDependencies: - supports-color '@typescript-eslint/types@8.16.0': {} - '@typescript-eslint/typescript-estree@8.16.0(typescript@5.6.3)': + '@typescript-eslint/typescript-estree@8.16.0(typescript@5.7.2)': dependencies: '@typescript-eslint/types': 8.16.0 '@typescript-eslint/visitor-keys': 8.16.0 @@ -10158,21 +10245,21 @@ snapshots: is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 - ts-api-utils: 1.4.0(typescript@5.6.3) + ts-api-utils: 1.4.0(typescript@5.7.2) optionalDependencies: - typescript: 5.6.3 + typescript: 5.7.2 transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@8.16.0(eslint@9.15.0)(typescript@5.6.3)': + '@typescript-eslint/utils@8.16.0(eslint@9.15.0)(typescript@5.7.2)': dependencies: '@eslint-community/eslint-utils': 4.4.1(eslint@9.15.0) '@typescript-eslint/scope-manager': 8.16.0 '@typescript-eslint/types': 8.16.0 - '@typescript-eslint/typescript-estree': 8.16.0(typescript@5.6.3) + '@typescript-eslint/typescript-estree': 8.16.0(typescript@5.7.2) eslint: 9.15.0 optionalDependencies: - typescript: 5.6.3 + typescript: 5.7.2 transitivePeerDependencies: - supports-color @@ -13897,7 +13984,7 @@ snapshots: - '@babel/core' - supports-color - ember-eslint-parser@0.5.6(@babel/core@7.26.0)(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint@9.15.0): + ember-eslint-parser@0.5.6(@babel/core@7.26.0)(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint@9.15.0): dependencies: '@babel/core': 7.26.0(supports-color@8.1.1) '@babel/eslint-parser': 7.25.9(@babel/core@7.26.0)(eslint@9.15.0) @@ -13908,7 +13995,7 @@ snapshots: mathml-tag-names: 2.1.3 svg-tags: 1.0.0 optionalDependencies: - '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.6.3) + '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.7.2) transitivePeerDependencies: - eslint @@ -14725,21 +14812,21 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint@9.15.0): + eslint-module-utils@2.12.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint-import-resolver-node@0.3.9)(eslint@9.15.0): dependencies: debug: 3.2.7 optionalDependencies: - '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.6.3) + '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.7.2) eslint: 9.15.0 eslint-import-resolver-node: 0.3.9 transitivePeerDependencies: - supports-color - eslint-plugin-ember@12.3.3(@babel/core@7.26.0)(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint@9.15.0): + eslint-plugin-ember@12.3.3(@babel/core@7.26.0)(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint@9.15.0): dependencies: '@ember-data/rfc395-data': 0.0.4 css-tree: 3.0.1 - ember-eslint-parser: 0.5.6(@babel/core@7.26.0)(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint@9.15.0) + ember-eslint-parser: 0.5.6(@babel/core@7.26.0)(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint@9.15.0) ember-rfc176-data: 0.3.18 eslint: 9.15.0 eslint-utils: 3.0.0(eslint@9.15.0) @@ -14749,7 +14836,7 @@ snapshots: requireindex: 1.2.0 snake-case: 3.0.4 optionalDependencies: - '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.6.3) + '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.7.2) transitivePeerDependencies: - '@babel/core' @@ -14760,7 +14847,7 @@ snapshots: eslint: 9.15.0 eslint-compat-utils: 0.5.1(eslint@9.15.0) - eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint@9.15.0): + eslint-plugin-import@2.31.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint@9.15.0): dependencies: '@rtsao/scc': 1.1.0 array-includes: 3.1.8 @@ -14771,7 +14858,7 @@ snapshots: doctrine: 2.1.0 eslint: 9.15.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint@9.15.0) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint-import-resolver-node@0.3.9)(eslint@9.15.0) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -14783,7 +14870,7 @@ snapshots: string.prototype.trimend: 1.0.8 tsconfig-paths: 3.15.0 optionalDependencies: - '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.6.3) + '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.7.2) transitivePeerDependencies: - eslint-import-resolver-typescript - eslint-import-resolver-webpack @@ -18964,9 +19051,9 @@ snapshots: trim-right@1.0.1: {} - ts-api-utils@1.4.0(typescript@5.6.3): + ts-api-utils@1.4.0(typescript@5.7.2): dependencies: - typescript: 5.6.3 + typescript: 5.7.2 tsconfig-paths@3.15.0: dependencies: @@ -19065,20 +19152,20 @@ snapshots: typedarray@0.0.6: {} - typescript-eslint@8.16.0(eslint@9.15.0)(typescript@5.6.3): + typescript-eslint@8.16.0(eslint@9.15.0)(typescript@5.7.2): dependencies: - '@typescript-eslint/eslint-plugin': 8.16.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.6.3))(eslint@9.15.0)(typescript@5.6.3) - '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.6.3) - '@typescript-eslint/utils': 8.16.0(eslint@9.15.0)(typescript@5.6.3) + '@typescript-eslint/eslint-plugin': 8.16.0(@typescript-eslint/parser@8.16.0(eslint@9.15.0)(typescript@5.7.2))(eslint@9.15.0)(typescript@5.7.2) + '@typescript-eslint/parser': 8.16.0(eslint@9.15.0)(typescript@5.7.2) + '@typescript-eslint/utils': 8.16.0(eslint@9.15.0)(typescript@5.7.2) eslint: 9.15.0 optionalDependencies: - typescript: 5.6.3 + typescript: 5.7.2 transitivePeerDependencies: - supports-color typescript-memoize@1.1.1: {} - typescript@5.6.3: {} + typescript@5.7.2: {} uc.micro@1.0.6: {} @@ -19224,6 +19311,23 @@ snapshots: vm-browserify@1.1.2: {} + vscode-jsonrpc@8.1.0: {} + + vscode-languageserver-protocol@3.17.3: + dependencies: + vscode-jsonrpc: 8.1.0 + vscode-languageserver-types: 3.17.3 + + vscode-languageserver-textdocument@1.0.12: {} + + vscode-languageserver-types@3.17.3: {} + + vscode-languageserver@8.1.0: + dependencies: + vscode-languageserver-protocol: 3.17.3 + + vscode-uri@3.0.8: {} + w3c-xmlserializer@5.0.0: dependencies: xml-name-validator: 5.0.0 diff --git a/rollup.config.mjs b/rollup.config.mjs index edbe4d4..21ec9b7 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -24,6 +24,7 @@ export default { 'components/**/*.js', 'modifiers/**/*.js', 'test-support/index.js', + 'template-registry.js', ]), // These are the modules that should get reexported into the traditional diff --git a/src/index.js b/src/index.gts similarity index 100% rename from src/index.js rename to src/index.gts diff --git a/src/modifiers/pikaday.js b/src/modifiers/pikaday.ts similarity index 62% rename from src/modifiers/pikaday.js rename to src/modifiers/pikaday.ts index 60194ff..8a69b42 100644 --- a/src/modifiers/pikaday.js +++ b/src/modifiers/pikaday.ts @@ -1,24 +1,41 @@ import { registerDestructor } from '@ember/destroyable'; -import Modifier from 'ember-modifier'; +import type Owner from '@ember/owner'; +import Modifier, { type ArgsFor } from 'ember-modifier'; import makePikaday from '../../vendor/pikaday'; import { maybeFindMoment } from '../find-moment'; const Pikaday = makePikaday(maybeFindMoment()); -export default class PikadayModifier extends Modifier { - #pikaday; - #observer; +interface Positional {} +interface Named {} +interface Options {} - constructor(owner, args) { +interface PikadaySignature { + Element: HTMLElement; + Args: { + Positional: Positional; + Named: Named; + }; +} + +export default class PikadayModifier extends Modifier { + #pikaday: typeof Pikaday | null = null; + #observer: MutationObserver | null = null; + + constructor(owner: Owner, args: ArgsFor) { super(owner, args); registerDestructor(this, () => { - this.#pikaday.destroy(); - this.#observer.disconnect(); + this.#pikaday?.destroy(); + this.#observer?.disconnect(); }); } - getPikadayOptions(element, positional, named) { - let opts = { + getPikadayOptions( + element: HTMLElement, + positional: Positional, + named: Named, + ): Options { + const opts = { // Our element is Pikaday's field field: element, @@ -40,12 +57,12 @@ export default class PikadayModifier extends Modifier { return opts; } - modify(element, positional, named) { + modify(element: HTMLElement, positional: Positional, named: Named) { const pikadayOptions = this.getPikadayOptions(element, positional, named); if (!this.#pikaday) { this.#pikaday = new Pikaday(pikadayOptions); - let { value, register } = named; + const { value, register } = named; if (value) { this.#pikaday.setDate(value, true); } @@ -54,16 +71,16 @@ export default class PikadayModifier extends Modifier { this.#observer.observe(element, { attributes: true }); register?.(this.#pikaday); } else { - let { value } = named; + const { value } = named; this.#pikaday.setDate(value, true); this.#pikaday.config(pikadayOptions); } } - syncDisabled(element) { + syncDisabled(element: HTMLElement) { if (element.hasAttribute('disabled')) { - this.#pikaday.hide(); + this.#pikaday?.hide(); } } } diff --git a/src/template-registry.ts b/src/template-registry.ts new file mode 100644 index 0000000..0758d89 --- /dev/null +++ b/src/template-registry.ts @@ -0,0 +1,11 @@ +// Easily allow apps, which are not yet using strict mode templates, to consume your Glint types, by importing this file. +// Add all your components, helpers and modifiers to the template registry here, so apps don't have to do this. +// See https://typed-ember.gitbook.io/glint/environments/ember/authoring-addons + +// import type MyComponent from './components/my-component'; + +// Remove this once entries have been added! πŸ‘‡ +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export default interface Registry { + // MyComponent: typeof MyComponent +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..83dd32d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,54 @@ +{ + "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": ["./node_modules/ember-source-latest/types/stable"] + } +} diff --git a/unpublished-development-types/index.d.ts b/unpublished-development-types/index.d.ts new file mode 100644 index 0000000..1793551 --- /dev/null +++ b/unpublished-development-types/index.d.ts @@ -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 + } +} From 2400696034f35e10ef38adf716bed55fdd23fe25 Mon Sep 17 00:00:00 2001 From: Sergey Astapov Date: Wed, 27 Nov 2024 23:10:46 -0500 Subject: [PATCH 2/2] Update template-registry.ts --- src/template-registry.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/template-registry.ts b/src/template-registry.ts index 0758d89..f2338dd 100644 --- a/src/template-registry.ts +++ b/src/template-registry.ts @@ -2,10 +2,14 @@ // Add all your components, helpers and modifiers to the template registry here, so apps don't have to do this. // See https://typed-ember.gitbook.io/glint/environments/ember/authoring-addons -// import type MyComponent from './components/my-component'; +import type pikaday from './modifiers/pikaday'; +import type PikadayInput from './components/pikaday-input'; +import type PikadayInputless from './components/pikaday-inputless'; -// Remove this once entries have been added! πŸ‘‡ -// eslint-disable-next-line @typescript-eslint/no-empty-interface -export default interface Registry { - // MyComponent: typeof MyComponent +export default interface PikadayRegistry { + pikaday: typeof pikaday; + 'pikaday-input': typeof PikadayInput; + PikadayInput: typeof PikadayInput; + 'pikaday-inputless': typeof PikadayInputless; + PikadayInputless: typeof PikadayInputless; }