diff --git a/packages/rollup-plugin/package.json b/packages/rollup-plugin/package.json index fc78519..b954231 100644 --- a/packages/rollup-plugin/package.json +++ b/packages/rollup-plugin/package.json @@ -43,10 +43,7 @@ }, "prettier": { "filepath": "input.js", - "trailingComma": "none", - "arrowParens": "avoid", - "tabWidth": 4, - "singleQuote": true + "tabWidth": 4 }, "babel": { "presets": [ diff --git a/packages/rollup-plugin/src/__tests__/fixtures/plugin/Component.js b/packages/rollup-plugin/src/__tests__/fixtures/plugin/Component.js index f910023..47bb821 100644 --- a/packages/rollup-plugin/src/__tests__/fixtures/plugin/Component.js +++ b/packages/rollup-plugin/src/__tests__/fixtures/plugin/Component.js @@ -1,12 +1,12 @@ -import React from 'react'; -import { usePluginState } from '@wq/react'; -import { List, ListItem } from '@wq/material'; +import React from "react"; +import { usePluginState } from "@wq/react"; +import { List, ListItem } from "@wq/material"; export default function Test() { - const state = usePluginState('myPlugin'); + const state = usePluginState("myPlugin"); return ( - {state.values.map(value => ( + {state.values.map((value) => ( {value.label} ))} diff --git a/packages/rollup-plugin/src/__tests__/fixtures/plugin/input.js b/packages/rollup-plugin/src/__tests__/fixtures/plugin/input.js index 0362efd..b63e455 100644 --- a/packages/rollup-plugin/src/__tests__/fixtures/plugin/input.js +++ b/packages/rollup-plugin/src/__tests__/fixtures/plugin/input.js @@ -1,24 +1,24 @@ -import Test from './Component'; +import Test from "./Component"; export default { - name: 'myPlugin', + name: "myPlugin", actions: { setValues(payload) { return { - type: 'MYPLUGIN_SET_VALUES', - payload + type: "MYPLUGIN_SET_VALUES", + payload, }; - } + }, }, reducer(state, action) { switch (action.type) { - case 'MYPLUGIN_SET_VALUES': + case "MYPLUGIN_SET_VALUES": return { values: action.payload }; default: return state || { values: [] }; } }, components: { - Test - } + Test, + }, }; diff --git a/packages/rollup-plugin/src/__tests__/fixtures/plugin/output.js b/packages/rollup-plugin/src/__tests__/fixtures/plugin/output.js index 8035c6f..28bef8b 100644 --- a/packages/rollup-plugin/src/__tests__/fixtures/plugin/output.js +++ b/packages/rollup-plugin/src/__tests__/fixtures/plugin/output.js @@ -1,21 +1,21 @@ -import { modules } from './wq.js'; +import { modules } from "./wq.js"; const { react: React } = modules; -const { '@wq/react': react } = modules; +const { "@wq/react": react } = modules; -const { '@wq/material': material } = modules; +const { "@wq/material": material } = modules; function Test() { - const state = react.usePluginState('myPlugin'); + const state = react.usePluginState("myPlugin"); return /*#__PURE__*/ React.createElement( material.List, null, - state.values.map(value => + state.values.map((value) => /*#__PURE__*/ React.createElement( material.ListItem, { - key: value.id + key: value.id, }, value.label ) @@ -24,35 +24,35 @@ function Test() { } var input = { - name: 'myPlugin', + name: "myPlugin", actions: { setValues(payload) { return { - type: 'MYPLUGIN_SET_VALUES', - payload + type: "MYPLUGIN_SET_VALUES", + payload, }; - } + }, }, reducer(state, action) { switch (action.type) { - case 'MYPLUGIN_SET_VALUES': + case "MYPLUGIN_SET_VALUES": return { - values: action.payload + values: action.payload, }; default: return ( state || { - values: [] + values: [], } ); } }, components: { - Test - } + Test, + }, }; export default input; diff --git a/packages/rollup-plugin/src/__tests__/fixtures/project/input.js b/packages/rollup-plugin/src/__tests__/fixtures/project/input.js index 54c2d36..338f502 100644 --- a/packages/rollup-plugin/src/__tests__/fixtures/project/input.js +++ b/packages/rollup-plugin/src/__tests__/fixtures/project/input.js @@ -1,6 +1,6 @@ -import app from '@wq/app'; -import material from '@wq/material'; -import mapgl from '@wq/map-gl'; -import myPlugin from './plugin.js'; +import app from "@wq/app"; +import material from "@wq/material"; +import mapgl from "@wq/map-gl"; +import myPlugin from "./plugin.js"; app.use([material, mapgl, myPlugin]); diff --git a/packages/rollup-plugin/src/__tests__/fixtures/project/output.js b/packages/rollup-plugin/src/__tests__/fixtures/project/output.js index c79fce0..3df9704 100644 --- a/packages/rollup-plugin/src/__tests__/fixtures/project/output.js +++ b/packages/rollup-plugin/src/__tests__/fixtures/project/output.js @@ -1,12 +1,12 @@ -import { modules } from './wq.js'; -import myPlugin from './plugin.js'; +import { modules } from "./wq.js"; +import myPlugin from "./plugin.js"; -const { '@wq/app': app } = modules; +const { "@wq/app": app } = modules; -const { '@wq/material': material } = modules; +const { "@wq/material": material } = modules; const materialPlugin = material.default; -const { '@wq/map-gl': mapgl } = modules; +const { "@wq/map-gl": mapgl } = modules; const mapglPlugin = mapgl.default; app.use([materialPlugin, mapglPlugin, myPlugin]); diff --git a/packages/rollup-plugin/src/__tests__/index.js b/packages/rollup-plugin/src/__tests__/index.js index a0791e6..26de148 100644 --- a/packages/rollup-plugin/src/__tests__/index.js +++ b/packages/rollup-plugin/src/__tests__/index.js @@ -1,59 +1,59 @@ -import { rollup } from 'rollup'; -import wqBundle from '../index.js'; -import babel from '@rollup/plugin-babel'; -import prettier from 'rollup-plugin-prettier'; -import util from 'util'; -import fs from 'fs'; +import { rollup } from "rollup"; +import wqBundle from "../index.js"; +import babel from "@rollup/plugin-babel"; +import prettier from "rollup-plugin-prettier"; +import util from "util"; +import fs from "fs"; const readFile = util.promisify(fs.readFile); process.chdir(__dirname); -test('plugin', async () => { +test("plugin", async () => { const bundle = await rollup({ - input: 'fixtures/plugin/input.js', + input: "fixtures/plugin/input.js", treeshake: { - propertyReadSideEffects: false + propertyReadSideEffects: false, }, plugins: [ wqBundle(), babel({ - plugins: ['@babel/transform-react-jsx'], - babelHelpers: 'inline' + plugins: ["@babel/transform-react-jsx"], + babelHelpers: "inline", }), - prettier() - ] + prettier(), + ], }), output = await bundle.generate({ - file: 'output.js', - format: 'esm' + file: "output.js", + format: "esm", }), - expected = await readFile('fixtures/plugin/output.js', 'utf8'); + expected = await readFile("fixtures/plugin/output.js", "utf8"); expect(output.output[0].code).toBe(expected); }); -test('project', async () => { +test("project", async () => { const bundle = await rollup({ - input: 'fixtures/project/input.js', + input: "fixtures/project/input.js", treeshake: { - propertyReadSideEffects: false + propertyReadSideEffects: false, }, - external: ['./plugin.js'], + external: ["./plugin.js"], plugins: [ wqBundle(), babel({ - plugins: ['@babel/transform-react-jsx'], - babelHelpers: 'inline' + plugins: ["@babel/transform-react-jsx"], + babelHelpers: "inline", }), - prettier() - ] + prettier(), + ], }), output = await bundle.generate({ - file: 'output.js', - format: 'esm' + file: "output.js", + format: "esm", }), - expected = await readFile('fixtures/project/output.js', 'utf8'); + expected = await readFile("fixtures/project/output.js", "utf8"); expect(output.output[0].code).toBe(expected); }); diff --git a/packages/rollup-plugin/src/index.js b/packages/rollup-plugin/src/index.js index 7f5942e..75c464c 100644 --- a/packages/rollup-plugin/src/index.js +++ b/packages/rollup-plugin/src/index.js @@ -1,88 +1,88 @@ -const prefix = '\0wq-bundle:', +const prefix = "\0wq-bundle:", modules = { react: { - name: 'React' + name: "React", }, - 'react-dom': { - name: 'ReactDOM' + "react-dom": { + name: "ReactDOM", }, - 'react-is': { - name: 'ReactIs' + "react-is": { + name: "ReactIs", }, - 'prop-types': { - name: 'PropTypes' + "prop-types": { + name: "PropTypes", }, formik: { - name: 'formik' + name: "formik", }, - '@material-ui/styles': { - name: 'muiStyles' + "@material-ui/styles": { + name: "muiStyles", }, - '@material-ui/utils': { - name: 'muiUtils' + "@material-ui/utils": { + name: "muiUtils", }, - '@material-ui/core/ButtonBase': { - name: 'ButtonBase' + "@material-ui/core/ButtonBase": { + name: "ButtonBase", }, - '@material-ui/core/Paper': { - name: 'Paper' + "@material-ui/core/Paper": { + name: "Paper", }, - '@material-ui/core/styles/withStyles': { - name: 'withStyles' + "@material-ui/core/styles/withStyles": { + name: "withStyles", }, - '@material-ui/core/styles/colorManipulator': { - name: 'colorManipulator' + "@material-ui/core/styles/colorManipulator": { + name: "colorManipulator", }, - 'mapbox-gl': { - name: 'MapboxGL' + "mapbox-gl": { + name: "MapboxGL", }, - 'react-mapbox-gl': { - name: 'ReactMapboxGl', - hasDefault: true + "react-mapbox-gl": { + name: "ReactMapboxGl", + hasDefault: true, }, - '@mapbox/mapbox-gl-draw': { - name: 'MapboxDraw' + "@mapbox/mapbox-gl-draw": { + name: "MapboxDraw", }, - 'react-mapbox-gl-draw': { - name: 'DrawControl' + "react-mapbox-gl-draw": { + name: "DrawControl", }, - '@wq/app': { - name: 'app' + "@wq/app": { + name: "app", }, - '@wq/react': { - name: 'react', - hasDefault: true + "@wq/react": { + name: "react", + hasDefault: true, }, - '@wq/material': { - name: 'material', - hasDefault: true + "@wq/material": { + name: "material", + hasDefault: true, }, - '@wq/map': { - name: 'map', - hasDefault: true + "@wq/map": { + name: "map", + hasDefault: true, + }, + "@wq/map-gl": { + name: "mapgl", + hasDefault: true, }, - '@wq/map-gl': { - name: 'mapgl', - hasDefault: true - } }, muiCoreImports = {}; Object.keys(modules) - .filter(id => id.match('@material-ui/core')) + .filter((id) => id.match("@material-ui/core")) .forEach( - id => (muiCoreImports[id.replace('@material-ui/core', '..')] = id) + (id) => (muiCoreImports[id.replace("@material-ui/core", "..")] = id) ); module.exports = function wq() { return { - name: '@wq/rollup-plugin', + name: "@wq/rollup-plugin", resolveId(id, importer) { - if (id == './wq.js') { + if (id == "./wq.js") { return { id, external: true }; } if (id.match(/\?commonjs-proxy$/)) { - id = id.replace(/^\0/, '').replace(/\?commonjs-proxy$/, ''); + id = id.replace(/^\0/, "").replace(/\?commonjs-proxy$/, ""); } if ( importer && @@ -94,15 +94,15 @@ module.exports = function wq() { if (modules[id]) { return { id: `${prefix}${id}`, - syntheticNamedExports: `${modules[id].name}` + syntheticNamedExports: `${modules[id].name}`, }; } }, load(id) { if (id.startsWith(prefix)) { - return createVirtualModule(id.replace(prefix, '')); + return createVirtualModule(id.replace(prefix, "")); } - } + }, }; };