Compare commits

..

44 Commits
v2.1.0 ... main

Author SHA1 Message Date
91c0f4c0b2 Make filepath optional in riotconfig. 2022-02-10 06:00:03 -06:00
gianlucaguarini
8903b91d44 removed: warning from readme file 2021-10-24 17:23:47 +02:00
gianlucaguarini
552f3af503 7.0.2 2021-10-24 17:19:45 +02:00
gianlucaguarini
dff002586d updated: clean up code base 2021-10-24 17:18:50 +02:00
gianlucaguarini
141269364e closes #21 2021-10-24 17:14:11 +02:00
gianlucaguarini
57c28c90d6 7.0.1 2021-10-24 17:14:11 +02:00
Gianluca Guarini
d73842fa0d
updated: readme file 2021-10-16 21:20:30 +02:00
gianlucaguarini
fd04821b33 fixed: transformation without config file 2021-10-16 20:38:40 +02:00
gianlucaguarini
c4ab1cd473 7.0.0 2021-10-16 20:10:52 +02:00
gianlucaguarini
2b94698f2f updated: setup alias for the test 2021-10-16 20:08:46 +02:00
gianlucaguarini
d8955bc96b updated: test dependencies 2021-10-16 20:05:15 +02:00
gianlucaguarini
b6c95134b4 updated: import in unit test 2021-10-16 20:02:16 +02:00
gianlucaguarini
1e04cae511 Attempt to fix the ci 2021-10-16 20:00:38 +02:00
gianlucaguarini
59b84ff83e fixed: small typos 2021-10-16 19:51:26 +02:00
gianlucaguarini
12829a45a8 updated: documentation 2021-10-16 19:40:07 +02:00
gianlucaguarini
4ee51ea76f updated: dependencies 2021-10-16 16:19:32 +02:00
gianlucaguarini
08e9c11480 Add support for parcel v2 2021-10-16 16:17:12 +02:00
gianlucaguarini
ab2416bab6 6.0.0 2021-07-11 16:46:05 +02:00
gianlucaguarini
5032ed536a updated: ci 2021-07-11 16:43:53 +02:00
gianlucaguarini
9a82f62a50 updated: dependencies 2021-07-11 16:42:17 +02:00
gianlucaguarini
bd3ef98534 5.0.1 2020-11-21 13:44:23 +01:00
gianlucaguarini
7e2418f3c3 updated: optimize npm package.json file peerDependencies handling 2020-11-21 13:44:10 +01:00
gianlucaguarini
e3350f8612 5.0.0 2020-11-21 13:35:46 +01:00
gianlucaguarini
2873ca6065 updated: Riot.js 5 and npm dependencies 2020-11-21 13:35:30 +01:00
Gianluca Guarini
212a74fbab
Merge pull request #15 from riot/dependabot/npm_and_yarn/lodash-4.17.15
build(deps): bump lodash from 4.17.11 to 4.17.15
2020-03-14 08:32:06 +01:00
dependabot[bot]
70747732bd
build(deps): bump lodash from 4.17.11 to 4.17.15
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.11 to 4.17.15.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.11...4.17.15)

Signed-off-by: dependabot[bot] <support@github.com>
2020-03-14 07:30:25 +00:00
Gianluca Guarini
0c7d929eaf
Merge pull request #14 from riot/dependabot/npm_and_yarn/acorn-6.4.1
build(deps): bump acorn from 6.1.1 to 6.4.1
2020-03-14 08:29:05 +01:00
dependabot[bot]
23b9f554ee
build(deps): bump acorn from 6.1.1 to 6.4.1
Bumps [acorn](https://github.com/acornjs/acorn) from 6.1.1 to 6.4.1.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/6.1.1...6.4.1)

Signed-off-by: dependabot[bot] <support@github.com>
2020-03-14 06:58:37 +00:00
Gianluca Guarini
951bd76ecc
Merge pull request #10 from Rydez/master
Add documentation for using Pug
2019-08-03 18:17:02 +02:00
Rydez
a1a3678838 Add documentation for using Pug 2019-08-03 09:27:50 -04:00
Gianluca Guarini
8dfe3239bb updated: badges 2019-05-30 17:23:07 +02:00
Gianluca Guarini
7f73df104f updated: fix travis build 2019-05-14 22:32:54 +02:00
Gianluca Guarini
ea1aedd7cf 4.0.1 2019-05-14 22:15:14 +02:00
Gianluca Guarini
97a1479fef fixes #8 and hot reload 2019-05-14 22:14:59 +02:00
Gianluca Guarini
602a65c82f removed: locked dependencies for the tests 2019-04-20 01:06:38 +02:00
Gianluca Guarini
11f029d42c updated: readme 2019-04-20 01:02:06 +02:00
Gianluca Guarini
6f091b89d4 closes #7 2019-04-20 00:59:09 +02:00
Gianluca Guarini
46113df053 updated: use the latest riot compiler 2019-04-20 00:41:12 +02:00
Gianluca Guarini
7c74849634 added: documentation about the config file 2019-03-23 16:10:44 +01:00
Gianluca Guarini
4c31a0caae fixed: npm path 2019-03-23 16:06:30 +01:00
Gianluca Guarini
7cd6d4f0d3 removed: codeclimate because it's not yet necessary 2019-03-23 16:05:44 +01:00
Gianluca Guarini
4470e4fcfd added: license and project badges 2019-03-23 16:04:56 +01:00
Gianluca Guarini
07dd2e9abe added: travis file 2019-03-23 16:01:50 +01:00
Gianluca Guarini
4f468d1d80 updated: well at least let's lint it #7 2019-03-23 15:59:28 +01:00
16 changed files with 5208 additions and 6230 deletions

12
.eslintrc Normal file
View File

@ -0,0 +1,12 @@
extends: eslint-config-riot
parserOptions:
ecmaVersion: 2021
sourceType: 'module'
globals:
sinon: true
expect: true
rules:
fp/no-class: off

View File

@ -1,25 +0,0 @@
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
},
"rules": {
"no-const-assign": "warn",
"no-this-before-super": "warn",
"no-undef": "warn",
"no-unreachable": "warn",
"no-unused-vars": "warn",
"constructor-super": "warn",
"valid-typeof": "warn",
"semi": [2, "always"]
}
}

24
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: test
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ dev ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 15.x]
steps:
- uses: actions/checkout@v2
- name: Local Unit Test ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm i
- run: npm test

6
.gitignore vendored
View File

@ -1 +1,5 @@
node_modules/*
node_modules
/test/.parcel-cache/
/test/package-lock.json
/test/dist
.idea

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2018 Riot
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,20 +1,95 @@
# parcel-plugin-riot
[![Build Status][ci-image]][ci-url]
[![NPM version][npm-version-image]][npm-url]
[![NPM downloads][npm-downloads-image]][npm-url]
[![MIT License][license-image]][license-url]
A parcel plugin for riot.js
The Riot.js official parcel transformer.
## Important
- If you are using Parcel < 2.0.0 please check the [this branch](https://github.com/riot/parcel-transformer-riot/tree/parcel-v1)
- If you are using Riot.js < 4.0.0 please check the [v3 branch](https://github.com/riot/parcel-transformer-riot/tree/v3)
## Using
Add parcel-plugin-riot to your project.
### 1. Add the riot parcel transformer to your project.
```bash
npm i -D @riotjs/parcel-transformer-riot @riotjs/compiler
```
npm i parcel-plugin-riot
### 2. Configure your .parcelrc file
```json
{
"extends": "@parcel/config-default",
"transformers": {
"*.riot": ["@riotjs/parcel-transformer-riot"]
}
}
```
-> You are ready!
```javascript
```js
import App from './src/App.riot'
import {component} from 'riot'
const riot = require('riot')
require('./src/App.tag')
riot.mount('*')
component(App)(document.querySelector('#root'), {
message: 'Hello there'
})
```
## Configuration
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
// add here all the other @riotjs/compiler options riot.js.org/compiler
// template: 'pug' for example
}
```
If you want to use `pug` as your template engine, your `riot.config.js` might look like this
```js
const { registerPreprocessor } = require('@riotjs/compiler')
const { render } = require('pug')
// register the pug preprocessor
registerPreprocessor('template', 'pug', (code, options) => {
const { file } = options
return {
code: render(code, {
filename: file,
pretty: true,
doctype: 'html'
})
}
})
module.exports = {
template: 'pug'
}
```
If you want to enable hmr via `hot` option you will need to install also [`@riotjs/hot-reload`](https://www.npmjs.com/package/@riotjs/hot-reload)
```bash
npm i @riotjs/hot-reload -D
```
[ci-image]:https://img.shields.io/github/workflow/status/riot/parcel-transformer-riot/test?style=flat-square
[ci-url]:https://github.com/riot/parcel-transformer-riot/actions
[license-image]: https://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
[license-url]: LICENSE
[npm-version-image]: https://img.shields.io/npm/v/@riotjs/parcel-transformer-riot.svg?style=flat-square
[npm-downloads-image]: https://img.shields.io/npm/dm/@riotjs/parcel-transformer-riot.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@riotjs/parcel-transformer-riot

View File

@ -1,27 +0,0 @@
const { compile } = require('riot-compiler');
const { Asset } = require('parcel-bundler');
const preamble = "const riot = require('riot');\n";
class RiotAsset extends Asset {
constructor(name, options) {
super(name, options);
this.type = 'js';
}
async generate() {
const riotOpts = (await this.getConfig(['.riotrc', '.riotrc.js', 'riot.config.js'])) || {};
let code = compile(this.contents, riotOpts, this.name);
code = `${ preamble }${ code }`;
this.contents = code;
return [
{
type: 'js',
value: this.contents
}
];
}
}
module.exports = RiotAsset;

View File

@ -1,3 +1,63 @@
module.exports = function (bundler) {
bundler.addAssetType('tag', require.resolve('./RiotAsset'));
};
const { compile } = require('@riotjs/compiler')
const { Transformer } = require('@parcel/plugin')
const SourceMap = require('@parcel/source-map').default
const { basename } = require('path')
const CONFIG_FILES = ['.riotrc', '.riotrc.js', 'riot.config.js']
const PACKAGE_KEY = 'riot'
/**
* Generate the hmr code depending on the tag generated by the compiler
* @param {string} path - path to the component file
* @returns {string} the code needed to handle the riot hot reload
*/
function hotReload(path) {
return `;(() => {
if (module.hot) {
const hotReload = require('@riotjs/hot-reload').default
module.hot.accept()
if (module.hot.data) {
const component = require('./${path}').default;
hotReload(component)
}
}
})()`
}
module.exports = 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) {
config.invalidateOnStartup()
}
return riotConfig?.contents ?? {}
},
async transform({asset, config, options}) {
const source = await asset.getCode()
const sourceMap = new SourceMap(options.projectRoot)
const {code, map} = compile(source, {
file: asset.filePath,
...config
})
// the suffix will be added only for the HMR
const suffix = config?.hot ? hotReload(basename(asset.filePath)) : ''
asset.type = 'js'
asset.setCode(`${code}${suffix}`)
asset.setMap(sourceMap.addVLQMap(map))
return [asset]
}
})

11076
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,30 @@
{
"name": "parcel-plugin-riot",
"version": "2.1.0",
"description": "A parcel plugin for riot.js",
"name": "@riotjs/parcel-transformer-riot",
"version": "7.0.2",
"description": "The Riot.js official parcel transformer",
"main": "index.js",
"scripts": {},
"author": {
"name": "andruschka",
"url": "https://92digital.com"
"scripts": {
"prepare": "npm i --no-save @riotjs/compiler@6 @riotjs/hot-reload@6 riot@6",
"test": "npx eslint *.js && npm run test-bundle",
"test-bundle": "cd test && npm i"
},
"engines": {
"parcel": "2.x"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/andruschka/parcel-plugin-riot"
"url": "https://github.com/riot/parcel-plugin-riot"
},
"peerDependencies": {
"@riotjs/compiler": "^6.0.4"
},
"devDependencies": {
"eslint": "^8.1.0",
"eslint-config-riot": "^3.0.0"
},
"dependencies": {
"parcel-bundler": "^1.12.3",
"riot": "^3.13.2",
"riot-compiler": "^3.4.0"
"@parcel/plugin": "^2.0.0",
"@parcel/source-map": "^2.0.0"
}
}

6
test/.parcelrc Normal file
View File

@ -0,0 +1,6 @@
{
"extends": "@parcel/config-default",
"transformers": {
"*.riot": ["@riotjs/parcel-transformer-riot"]
}
}

13
test/index.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Parcel Plugin Riot Example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="./main.js"></script>
</body>
</html>

5
test/main.js Normal file
View File

@ -0,0 +1,5 @@
import MyComponent from './my-component.riot'
import { component } from 'riot'
component(MyComponent)(document.getElementById('root'))

9
test/my-component.riot Normal file
View File

@ -0,0 +1,9 @@
<my-component>
<p>{message}</p>
<script>
export default {
message: 'hello world'
}
</script>
</my-component>

20
test/package.json Normal file
View File

@ -0,0 +1,20 @@
{
"name": "riot-parcel-test",
"private": true,
"scripts": {
"postinstall": "parcel build index.html --no-cache"
},
"alias": {
"./test/*.riot": "./$1"
},
"dependencies": {
"riot": "^6.0.0",
"@riotjs/hot-reload": "^6.0.0"
},
"devDependencies": {
"parcel": "^2.0.0",
"@parcel/config-default": "^2.0.0",
"@riotjs/compiler": "^6.0.0",
"@riotjs/parcel-transformer-riot": "file:../"
}
}

3
test/riot.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
hot: true
}