From 580780e38c952bc353a3f74d0cfee69064dcfe0d Mon Sep 17 00:00:00 2001 From: Chris Manson Date: Tue, 23 Jun 2026 11:54:22 +0100 Subject: [PATCH 1/7] convert to v2 addon --- .eslintrc.js | 56 - .gitignore | 3 + .prettierignore | 2 + .prettierrc.js | 12 - .prettierrc.mjs | 12 + .stylelintrc.js | 5 - .template-lintrc.js | 5 - .template-lintrc.mjs | 4 + .tool-versions | 1 - .try.mjs | 160 + CONTRIBUTING.md | 20 +- README.md | 58 +- addon-main.cjs | 4 + addon/.gitkeep | 0 addon/components/markdown-to-html.hbs | 1 - app/.gitkeep | 0 app/components/markdown-to-html.js | 1 - babel.config.cjs | 42 + babel.publish.config.cjs | 28 + demo-app/app.js | 12 + demo-app/config/environment.js | 4 + {tests/dummy/app => demo-app}/router.js | 2 +- {tests/dummy/app => demo-app}/styles/app.css | 6 + demo-app/templates/application.gjs | 31 + ember-cli-build.js | 25 - eslint.config.mjs | 103 + index.html | 20 + index.js | 5 - package.json | 101 +- pnpm-lock.yaml | 5414 +++++++++++------ rollup.config.mjs | 69 + .../components/markdown-to-html.gjs | 14 +- src/index.js | 1 + testem.cjs | 26 + testem.js | 23 - tests/dummy/app/app.js | 12 - tests/dummy/app/components/.gitkeep | 0 tests/dummy/app/controllers/.gitkeep | 0 tests/dummy/app/helpers/.gitkeep | 0 tests/dummy/app/index.html | 24 - tests/dummy/app/models/.gitkeep | 0 tests/dummy/app/routes/.gitkeep | 0 tests/dummy/app/templates/application.hbs | 9 - tests/dummy/config/ember-cli-update.json | 21 - tests/dummy/config/ember-try.js | 177 - tests/dummy/config/environment.js | 48 - tests/dummy/config/optional-features.json | 6 - tests/dummy/config/targets.js | 11 - tests/dummy/public/robots.txt | 3 - tests/index.html | 39 +- .../components/markdown-to-html-test.gjs | 208 + .../components/markdown-to-html-test.js | 154 - tests/test-helper.js | 35 +- vite.config.mjs | 30 + 54 files changed, 4465 insertions(+), 2582 deletions(-) delete mode 100644 .eslintrc.js delete mode 100644 .prettierrc.js create mode 100644 .prettierrc.mjs delete mode 100644 .stylelintrc.js delete mode 100644 .template-lintrc.js create mode 100644 .template-lintrc.mjs delete mode 100644 .tool-versions create mode 100644 .try.mjs create mode 100644 addon-main.cjs delete mode 100644 addon/.gitkeep delete mode 100644 addon/components/markdown-to-html.hbs delete mode 100644 app/.gitkeep delete mode 100644 app/components/markdown-to-html.js create mode 100644 babel.config.cjs create mode 100644 babel.publish.config.cjs create mode 100644 demo-app/app.js create mode 100644 demo-app/config/environment.js rename {tests/dummy/app => demo-app}/router.js (80%) rename {tests/dummy/app => demo-app}/styles/app.css (58%) create mode 100644 demo-app/templates/application.gjs delete mode 100644 ember-cli-build.js create mode 100644 eslint.config.mjs create mode 100644 index.html delete mode 100644 index.js create mode 100644 rollup.config.mjs rename addon/components/markdown-to-html.js => src/components/markdown-to-html.gjs (87%) create mode 100644 src/index.js create mode 100644 testem.cjs delete mode 100644 testem.js delete mode 100644 tests/dummy/app/app.js delete mode 100644 tests/dummy/app/components/.gitkeep delete mode 100644 tests/dummy/app/controllers/.gitkeep delete mode 100644 tests/dummy/app/helpers/.gitkeep delete mode 100644 tests/dummy/app/index.html delete mode 100644 tests/dummy/app/models/.gitkeep delete mode 100644 tests/dummy/app/routes/.gitkeep delete mode 100644 tests/dummy/app/templates/application.hbs delete mode 100644 tests/dummy/config/ember-cli-update.json delete mode 100644 tests/dummy/config/ember-try.js delete mode 100644 tests/dummy/config/environment.js delete mode 100644 tests/dummy/config/optional-features.json delete mode 100644 tests/dummy/config/targets.js delete mode 100644 tests/dummy/public/robots.txt create mode 100644 tests/integration/components/markdown-to-html-test.gjs delete mode 100644 tests/integration/components/markdown-to-html-test.js create mode 100644 vite.config.mjs diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index ade61fb..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,56 +0,0 @@ -'use strict'; - -module.exports = { - root: true, - parser: '@babel/eslint-parser', - parserOptions: { - ecmaVersion: 'latest', - sourceType: 'module', - requireConfigFile: false, - babelOptions: { - plugins: [ - ['@babel/plugin-proposal-decorators', { decoratorsBeforeExport: true }], - ], - }, - }, - plugins: ['ember'], - extends: [ - 'eslint:recommended', - 'plugin:ember/recommended', - 'plugin:prettier/recommended', - ], - env: { - browser: true, - }, - rules: {}, - overrides: [ - // node files - { - files: [ - './.eslintrc.js', - './.prettierrc.js', - './.stylelintrc.js', - './.template-lintrc.js', - './ember-cli-build.js', - './index.js', - './testem.js', - './blueprints/*/index.js', - './config/**/*.js', - './tests/dummy/config/**/*.js', - ], - parserOptions: { - sourceType: 'script', - }, - env: { - browser: false, - node: true, - }, - extends: ['plugin:n/recommended'], - }, - { - // test files - files: ['tests/**/*-test.{js,ts}'], - extends: ['plugin:qunit/recommended'], - }, - ], -}; diff --git a/.gitignore b/.gitignore index 9518c8d..5b31d44 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ +/tmp/ + # compiled output /dist/ +/dist-tests/ /declarations/ # dependencies diff --git a/.prettierignore b/.prettierignore index 9385391..7bd9b21 100644 --- a/.prettierignore +++ b/.prettierignore @@ -11,3 +11,5 @@ # ember-try /.node_modules.ember-try/ + +CHANGELOG.md diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index e5f7b6d..0000000 --- a/.prettierrc.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict'; - -module.exports = { - overrides: [ - { - files: '*.{js,ts}', - options: { - singleQuote: true, - }, - }, - ], -}; diff --git a/.prettierrc.mjs b/.prettierrc.mjs new file mode 100644 index 0000000..9cc6b3d --- /dev/null +++ b/.prettierrc.mjs @@ -0,0 +1,12 @@ +export default { + plugins: ['prettier-plugin-ember-template-tag'], + overrides: [ + { + files: '*.{js,gjs,ts,gts,mjs,mts,cjs,cts}', + options: { + singleQuote: true, + templateSingleQuote: false, + }, + }, + ], +}; diff --git a/.stylelintrc.js b/.stylelintrc.js deleted file mode 100644 index 021c539..0000000 --- a/.stylelintrc.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -module.exports = { - extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'], -}; diff --git a/.template-lintrc.js b/.template-lintrc.js deleted file mode 100644 index f35f61c..0000000 --- a/.template-lintrc.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -module.exports = { - extends: 'recommended', -}; diff --git a/.template-lintrc.mjs b/.template-lintrc.mjs new file mode 100644 index 0000000..8b6625c --- /dev/null +++ b/.template-lintrc.mjs @@ -0,0 +1,4 @@ +export default { + extends: 'recommended', + checkHbsTemplateLiterals: false, +}; diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index 1e04d79..0000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -nodejs 18.17.0 diff --git a/.try.mjs b/.try.mjs new file mode 100644 index 0000000..8566563 --- /dev/null +++ b/.try.mjs @@ -0,0 +1,160 @@ +// When building your addon for older Ember versions you need to have the required files +const compatFiles = { + 'ember-cli-build.cjs': `const EmberApp = require('ember-cli/lib/broccoli/ember-app'); +const { compatBuild } = require('@embroider/compat'); +module.exports = async function (defaults) { + const { buildOnce } = await import('@embroider/vite'); + let app = new EmberApp(defaults); + return compatBuild(app, buildOnce); +};`, + 'config/optional-features.json': JSON.stringify({ + 'application-template-wrapper': false, + 'default-async-observers': true, + 'jquery-integration': false, + 'template-only-glimmer-components': true, + 'no-implicit-route-model': true, + }), +}; + +const compatDeps = { + '@embroider/compat': '^4.0.3', + 'ember-cli': '^5.12.0', + 'ember-auto-import': '^2.10.0', + '@ember/optional-features': '^2.2.0', +}; + +export default { + scenarios: [ + { + name: 'ember-lts-3.28', + npm: { + devDependencies: { + 'ember-source': '~3.28.0', + ...compatDeps, + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-4.4', + npm: { + devDependencies: { + 'ember-source': '~4.4.0', + ...compatDeps, + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-4.8', + npm: { + devDependencies: { + 'ember-source': '~4.8.0', + ...compatDeps, + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-4.12', + npm: { + devDependencies: { + 'ember-source': '~4.12.0', + ...compatDeps, + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-5.4', + npm: { + devDependencies: { + 'ember-source': '~5.4.0', + ...compatDeps, + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-5.8', + npm: { + devDependencies: { + 'ember-source': '~5.8.0', + ...compatDeps, + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-5.12', + npm: { + devDependencies: { + 'ember-source': '~5.12.0', + ...compatDeps, + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-6.4', + npm: { + devDependencies: { + 'ember-source': 'npm:ember-source@~6.4.0', + }, + }, + }, + { + name: 'ember-lts-6.8', + npm: { + devDependencies: { + 'ember-source': 'npm:ember-source@~6.8.0', + }, + }, + }, + { + name: 'ember-latest', + npm: { + devDependencies: { + 'ember-source': 'npm:ember-source@latest', + }, + }, + }, + { + name: 'ember-beta', + npm: { + devDependencies: { + 'ember-source': 'npm:ember-source@beta', + }, + }, + }, + { + name: 'ember-alpha', + npm: { + devDependencies: { + 'ember-source': 'npm:ember-source@alpha', + }, + }, + }, + ], +}; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a9a374b..69ad46e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,24 +2,24 @@ ## Installation -* `git clone ` -* `cd ember-cli-showdown` -* `pnpm install` +- `git clone ` +- `cd ember-cli-showdown` +- `pnpm install` ## Linting -* `pnpm lint` -* `pnpm lint:fix` +- `pnpm lint` +- `pnpm lint:fix` ## Running tests -* `ember test` – Runs the test suite on the current Ember version -* `ember test --server` – Runs the test suite in "watch mode" -* `ember try:each` – Runs the test suite against multiple Ember versions +- `ember test` – Runs the test suite on the current Ember version +- `ember test --server` – Runs the test suite in "watch mode" +- `ember try:each` – Runs the test suite against multiple Ember versions ## Running the dummy application -* `ember serve` -* Visit the dummy application at [http://localhost:4200](http://localhost:4200). +- `ember serve` +- Visit the dummy application at [http://localhost:4200](http://localhost:4200). For more information on using ember-cli, visit [https://cli.emberjs.com/release/](https://cli.emberjs.com/release/). diff --git a/README.md b/README.md index fac07e7..598ed08 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,12 @@ This addon provides a component that transforms [Markdown](http://en.wikipedia.org/wiki/Markdown) into valid HTML. -* Fastboot compatible +- Fastboot compatible ## Compatibility -* Ember.js v3.16 or above -* Ember CLI v3.16 or above -* Node.js v18 or above +- Ember.js v3.28 or above +- Embroider or ember-auto-import v2 ## Installation @@ -52,22 +51,22 @@ You can use [configuration settings from Showdown][showdown-config]: #### Global Showdown Options -Global options are supported as of 2.11.x. This lets you define options that will be used +Global options are supported as of 2.11.x. This lets you define options that will be used for showdown options that were not provided as an attribute. An example where you always want to auto link: ```js // config/environment.js -module.exports = function(environment) { +module.exports = function (environment) { var ENV = { showdown: { - simplifiedAutoLink: true - } - } + simplifiedAutoLink: true, + }, + }; return ENV; -} +}; ``` ### Showdown Extensions @@ -76,17 +75,11 @@ You can load [Showdown Extensions](https://github.com/showdownjs/showdown/wiki/e "extensions" property when initializing your component: ```handlebars - + ``` ```handlebars - + ``` (`myExtensionList` can be an array of strings or a space separated string) @@ -96,21 +89,23 @@ For example, in an initializer: ```js // app/initializers/register-showdown-extensions.js -import showdown from 'showdown'; +import showdown from "showdown"; export function initialize() { - showdown.extension("myExtensionName", function() { - return [{ - type: 'html', - regex: '
', - replace: '
' - }]; + showdown.extension("myExtensionName", function () { + return [ + { + type: "html", + regex: "
", + replace: '
', + }, + ]; }); } export default { - name: 'register-showdown-extensions', - initialize + name: "register-showdown-extensions", + initialize, }; ``` @@ -118,15 +113,16 @@ export default { ## 3.x to 4.3 migration -* Global `showdown` is no longer supported. Must be imported via `import showdown from 'showdown'` -* Remove any use of `FastBoot.require('require')` with `import showdown from 'showdown'` +- Global `showdown` is no longer supported. Must be imported via `import showdown from 'showdown'` +- Remove any use of `FastBoot.require('require')` with `import showdown from 'showdown'` ## 7.x to 8.x migration -* Positional parameters are no longer supported. Use the `@markdown` argument to provide the markdown content to ``. +- Positional parameters are no longer supported. Use the `@markdown` argument to provide the markdown content to ``. ## Dependencies -* [Showdown](https://github.com/showdownjs/showdown) + +- [Showdown](https://github.com/showdownjs/showdown) ## Contributing diff --git a/addon-main.cjs b/addon-main.cjs new file mode 100644 index 0000000..f868d6b --- /dev/null +++ b/addon-main.cjs @@ -0,0 +1,4 @@ +'use strict'; + +const { addonV1Shim } = require('@embroider/addon-shim'); +module.exports = addonV1Shim(__dirname); diff --git a/addon/.gitkeep b/addon/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/addon/components/markdown-to-html.hbs b/addon/components/markdown-to-html.hbs deleted file mode 100644 index 5d20b58..0000000 --- a/addon/components/markdown-to-html.hbs +++ /dev/null @@ -1 +0,0 @@ -
{{this.html}}
\ No newline at end of file diff --git a/app/.gitkeep b/app/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/app/components/markdown-to-html.js b/app/components/markdown-to-html.js deleted file mode 100644 index 74bd605..0000000 --- a/app/components/markdown-to-html.js +++ /dev/null @@ -1 +0,0 @@ -export { default } from 'ember-cli-showdown/components/markdown-to-html'; diff --git a/babel.config.cjs b/babel.config.cjs new file mode 100644 index 0000000..da25628 --- /dev/null +++ b/babel.config.cjs @@ -0,0 +1,42 @@ +/** + * This babel.config is not used for publishing. + * It's only for the local editing experience + * (and linting) + */ +const { buildMacros } = require('@embroider/macros/babel'); + +const { + babelCompatSupport, + templateCompatSupport, +} = require('@embroider/compat/babel'); + +const macros = buildMacros(); + +// For scenario testing +const isCompat = Boolean(process.env.ENABLE_COMPAT_BUILD); + +module.exports = { + plugins: [ + [ + 'babel-plugin-ember-template-compilation', + { + transforms: [ + ...(isCompat ? templateCompatSupport() : macros.templateMacros), + ], + }, + ], + [ + 'module:decorator-transforms', + { + runtime: { + import: require.resolve('decorator-transforms/runtime-esm'), + }, + }, + ], + ...(isCompat ? babelCompatSupport() : macros.babelMacros), + ], + + generatorOpts: { + compact: false, + }, +}; diff --git a/babel.publish.config.cjs b/babel.publish.config.cjs new file mode 100644 index 0000000..ec0a2a1 --- /dev/null +++ b/babel.publish.config.cjs @@ -0,0 +1,28 @@ +/** + * This babel.config is only used for publishing. + * + * For local dev experience, see the babel.config + */ +module.exports = { + plugins: [ + [ + 'babel-plugin-ember-template-compilation', + { + targetFormat: 'hbs', + transforms: [], + }, + ], + [ + 'module:decorator-transforms', + { + runtime: { + import: 'decorator-transforms/runtime-esm', + }, + }, + ], + ], + + generatorOpts: { + compact: false, + }, +}; diff --git a/demo-app/app.js b/demo-app/app.js new file mode 100644 index 0000000..d4cff48 --- /dev/null +++ b/demo-app/app.js @@ -0,0 +1,12 @@ +import setupInspector from '@embroider/legacy-inspector-support/ember-source-4.12'; + +import EmberApp from 'ember-strict-application-resolver'; +import Router from './router'; + +export default class App extends EmberApp { + modules = { + './router': { default: Router }, + ...import.meta.glob('./templates/**/*.gjs', { eager: true }), + }; + inspector = setupInspector(this); +} diff --git a/demo-app/config/environment.js b/demo-app/config/environment.js new file mode 100644 index 0000000..4ad77d6 --- /dev/null +++ b/demo-app/config/environment.js @@ -0,0 +1,4 @@ +export default { + locationType: 'history', + rootUrl: '/', +}; diff --git a/tests/dummy/app/router.js b/demo-app/router.js similarity index 80% rename from tests/dummy/app/router.js rename to demo-app/router.js index 64e543a..818c8d4 100644 --- a/tests/dummy/app/router.js +++ b/demo-app/router.js @@ -1,5 +1,5 @@ import EmberRouter from '@ember/routing/router'; -import config from 'dummy/config/environment'; +import config from './config/environment'; export default class Router extends EmberRouter { location = config.locationType; diff --git a/tests/dummy/app/styles/app.css b/demo-app/styles/app.css similarity index 58% rename from tests/dummy/app/styles/app.css rename to demo-app/styles/app.css index 2763afa..c111311 100644 --- a/tests/dummy/app/styles/app.css +++ b/demo-app/styles/app.css @@ -1 +1,7 @@ /* Ember supports plain CSS out of the box. More info: https://cli.emberjs.com/release/advanced-use/stylesheets/ */ + +.split-view { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 10px; +} diff --git a/demo-app/templates/application.gjs b/demo-app/templates/application.gjs new file mode 100644 index 0000000..e3d058c --- /dev/null +++ b/demo-app/templates/application.gjs @@ -0,0 +1,31 @@ +import { Textarea } from '@ember/component'; +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { MarkdownToHtml } from 'ember-cli-showdown'; + +export default class ApplicationRoute extends Component { + @tracked + editableText = '**TODO** _edit me_'; + +