Skip to content

Commit

Permalink
updated: use esm module syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Dec 1, 2023
1 parent 82cd7fd commit e121a1f
Show file tree
Hide file tree
Showing 12 changed files with 2,046 additions and 802 deletions.
12 changes: 0 additions & 12 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends: eslint-config-riot
7 changes: 3 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ name: test

on:
push:
branches: [ main, dev ]
branches: [main, dev]
pull_request:
branches: [ dev ]
branches: [dev]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 15.x]
node-version: [18.x, 20.x]
steps:
- uses: actions/checkout@v2
- name: Local Unit Test ${{ matrix.node-version }}
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@riotjs/prettier-config')
16 changes: 8 additions & 8 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The Riot.js official parcel transformer.
npm i -D @riotjs/parcel-transformer-riot @riotjs/compiler
```

### 2. Configure your .parcelrc file
### 2. Configure your .parcelrc file

```json
{
Expand All @@ -33,10 +33,10 @@ npm i -D @riotjs/parcel-transformer-riot @riotjs/compiler

```js
import App from './src/App.riot'
import {component} from 'riot'
import { component } from 'riot'

component(App)(document.querySelector('#root'), {
message: 'Hello there'
message: 'Hello there',
})
```

Expand All @@ -45,8 +45,8 @@ component(App)(document.querySelector('#root'), {
If you want compile your tags using custom riot compiler options you can create a `riot.config.js` in the root folder of your project

```js
module.exports = {
hot: false // set it to true if you are using hmr
export default {
hot: false, // set it to true if you are using hmr
// add here all the other @riotjs/compiler options riot.js.org/compiler
// template: 'pug' for example
}
Expand All @@ -66,13 +66,13 @@ registerPreprocessor('template', 'pug', (code, options) => {
code: render(code, {
filename: file,
pretty: true,
doctype: 'html'
})
doctype: 'html',
}),
}
})

module.exports = {
template: 'pug'
template: 'pug',
}
```

Expand Down
35 changes: 17 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const { compile } = require('@riotjs/compiler')
const { Transformer } = require('@parcel/plugin')
const SourceMap = require('@parcel/source-map').default
const { basename } = require('path')
import { compile } from '@riotjs/compiler'
import { Transformer } from '@parcel/plugin'
import sourceMap from '@parcel/source-map'
import { basename } from 'path'

const SourceMap = sourceMap.default
const CONFIG_FILES = ['.riotrc', '.riotrc.js', 'riot.config.js']
const PACKAGE_KEY = 'riot'

Expand All @@ -24,16 +25,14 @@ function hotReload(path) {
})()`
}

module.exports = new Transformer({
async loadConfig({config}) {
const riotConfig = (await config.getConfig(
CONFIG_FILES,
{
packageKey: PACKAGE_KEY
}
)) || {}
const shouldInvalidateOnStartup = riotConfig &&
riotConfig.filePath.endsWith('.js') ||
export default new Transformer({
async loadConfig({ config }) {
const riotConfig =
(await config.getConfig(CONFIG_FILES, {
packageKey: PACKAGE_KEY,
})) || {}
const shouldInvalidateOnStartup =
(riotConfig && riotConfig.filePath.endsWith('.js')) ||
riotConfig.filePath.endsWith(CONFIG_FILES[0])

if (shouldInvalidateOnStartup) {
Expand All @@ -42,13 +41,13 @@ module.exports = new Transformer({

return riotConfig.contents || {}
},
async transform({asset, config = {}, options}) {
async transform({ asset, config = {}, options }) {
const source = await asset.getCode()
const sourceMap = new SourceMap(options.projectRoot)

const {code, map} = compile(source, {
const { code, map } = compile(source, {
file: asset.filePath,
...config
...config,
})

// the suffix will be added only for the HMR
Expand All @@ -59,5 +58,5 @@ module.exports = new Transformer({
asset.setMap(sourceMap.addVLQMap(map))

return [asset]
}
},
})
Loading

0 comments on commit e121a1f

Please sign in to comment.