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/.github/workflows/ci.yml b/.github/workflows/ci.yml index ccc3664..44fb166 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,34 +7,50 @@ on: - master pull_request: {} -env: - NODE_VERSION: 18 - FORCE_COLOR: 1 - concurrency: group: ci-${{ github.head_ref || github.ref }} cancel-in-progress: true jobs: + lint: + name: "Lints" + runs-on: ubuntu-latest + timeout-minutes: 10 + + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - name: Install Dependencies + run: pnpm install --frozen-lockfile + - name: Lint + run: pnpm lint + test: name: "Tests" runs-on: ubuntu-latest timeout-minutes: 10 + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 - - name: Install Node - uses: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: - node-version: ${{ env.NODE_VERSION }} + node-version: 22 cache: pnpm - name: Install Dependencies run: pnpm install --frozen-lockfile - - name: Lint - run: pnpm run lint - name: Run Tests - run: pnpm run test:ember + run: pnpm test + # For the Try Scenarios + - id: set-matrix + run: | + echo "matrix=$(pnpm -s dlx @embroider/try list)" >> $GITHUB_OUTPUT floating: name: "Floating Dependencies" @@ -46,48 +62,35 @@ jobs: - uses: pnpm/action-setup@v4 - uses: actions/setup-node@v4 with: - node-version: ${{ env.NODE_VERSION }} + node-version: 22 cache: pnpm - name: Install Dependencies run: pnpm install --no-lockfile - name: Run Tests - run: pnpm run test:ember + run: pnpm test try-scenarios: - name: ${{ matrix.try-scenario }} + name: ${{ matrix.name }} runs-on: ubuntu-latest needs: "test" timeout-minutes: 10 - strategy: fail-fast: false - matrix: - try-scenario: - - ember-lts-3.16 - - ember-lts-3.20 - - ember-lts-3.24 - - ember-lts-3.28 - - ember-lts-4.4 - - ember-lts-4.8 - - ember-lts-4.12 - - ember-release - - ember-beta - - ember-canary - - ember-classic - - embroider-safe - - embroider-optimized - - no-deprecations - - ember-release-no-deprecations + matrix: ${{fromJson(needs.test.outputs.matrix)}} steps: - uses: actions/checkout@v4 - uses: pnpm/action-setup@v4 - - name: Install Node - uses: actions/setup-node@v4 + - uses: actions/setup-node@v4 with: - node-version: ${{ env.NODE_VERSION }} + node-version: 22 cache: pnpm + - name: Apply Scenario + run: | + pnpm dlx @embroider/try apply ${{ matrix.name }} - name: Install Dependencies - run: pnpm install --frozen-lockfile + run: pnpm install --no-lockfile - name: Run Tests - run: pnpm ember try:one ${{ matrix.try-scenario }} + run: | + pnpm test + env: ${{ matrix.env }} 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..2911a15 100644 --- a/.prettierignore +++ b/.prettierignore @@ -11,3 +11,6 @@ # ember-try /.node_modules.ember-try/ + +CHANGELOG.md +pnpm-lock.yaml 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..5029b6c --- /dev/null +++ b/.try.mjs @@ -0,0 +1,164 @@ +// 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', + '@glimmer/component': '^1.0.0', + ...compatDeps, + 'ember-cli': '^4.12.0', + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-4.4', + npm: { + devDependencies: { + 'ember-source': '~4.4.0', + '@glimmer/component': '^1.0.0', + ...compatDeps, + }, + }, + env: { + ENABLE_COMPAT_BUILD: true, + }, + files: compatFiles, + }, + { + name: 'ember-lts-4.8', + npm: { + devDependencies: { + 'ember-source': '~4.8.0', + '@glimmer/component': '^1.0.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..2bf9422 --- /dev/null +++ b/demo-app/templates/application.gjs @@ -0,0 +1,34 @@ +import { Textarea } from '@ember/component'; +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { MarkdownToHtml } from 'ember-cli-showdown'; +import RouteTemplate from 'ember-route-template'; + +class ApplicationRoute extends Component { + @tracked + editableText = '**TODO** _edit me_'; + +