Skip to content

Commit

Permalink
closes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Apr 26, 2024
1 parent aee4b1c commit a540f4a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"scripts": {
"lint": "prettier -c ./ && eslint src test --ext .cjs,.js",
"test": "npm run lint && node --import ./test/setup.js test/core.spec.js",
"test": "npm run lint && node --import ./test/setup.js test/core.spec.js && RIOT_COMPONENTS_FILE_EXTENSION=.html node --import ./test/setup.js test/custom-extension.spec.js",
"prepublishOnly": "npm run test"
},
"version": "9.0.0"
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { compile } from '@riotjs/compiler'

// Only module format is supported
const format = 'module'
// Allow the use of custom file extensions https://github.com/riot/register/issues/3
const FILE_EXTENSION_REGEX = new RegExp(
`${process.env.RIOT_COMPONENTS_FILE_EXTENSION || '.riot'}$`,
)

export async function load(url, context, nextLoad) {
// non riot files will be skipped
if (!/\.riot$/.test(url)) return nextLoad(url)
if (!FILE_EXTENSION_REGEX.test(url)) return nextLoad(url)

// get the source code of the riot file
const { source } = await nextLoad(url, {
Expand Down
6 changes: 6 additions & 0 deletions test/custom-extension.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import assert from 'node:assert/strict'

const component = await import('./test.html')
assert.ok(component)

console.log('All tests passed :)')
3 changes: 3 additions & 0 deletions test/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<test>
<p>hello</p>
</test>

0 comments on commit a540f4a

Please sign in to comment.