From 77e8c4f69e481854f5513a378ef31666df9e95a9 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Wed, 23 Sep 2020 20:04:43 +0200 Subject: [PATCH 1/7] chore(graphql): literally import @kocal/rollup-plugin-graphql --- packages/graphql/CHANGELOG.md | 9 +++ packages/graphql/LICENSE | 21 ++++++ packages/graphql/README.md | 44 +++++++++++++ packages/graphql/package.json | 66 +++++++++++++++++++ packages/graphql/rollup.config.js | 16 +++++ packages/graphql/src/index.js | 31 +++++++++ packages/graphql/src/toESModules.js | 40 +++++++++++ packages/graphql/tests/index.spec.js | 63 ++++++++++++++++++ .../graphql/tests/samples/basic/basic.graphql | 6 ++ packages/graphql/tests/samples/basic/index.js | 1 + .../samples/fragments/allHeroesQuery.graphql | 7 ++ .../samples/fragments/heroFragment.graphql | 4 ++ .../graphql/tests/samples/fragments/index.js | 1 + .../tests/samples/multi-imports/hero.graphql | 14 ++++ .../tests/samples/multi-imports/index.js | 1 + 15 files changed, 324 insertions(+) create mode 100644 packages/graphql/CHANGELOG.md create mode 100644 packages/graphql/LICENSE create mode 100644 packages/graphql/README.md create mode 100644 packages/graphql/package.json create mode 100644 packages/graphql/rollup.config.js create mode 100644 packages/graphql/src/index.js create mode 100644 packages/graphql/src/toESModules.js create mode 100644 packages/graphql/tests/index.spec.js create mode 100644 packages/graphql/tests/samples/basic/basic.graphql create mode 100644 packages/graphql/tests/samples/basic/index.js create mode 100644 packages/graphql/tests/samples/fragments/allHeroesQuery.graphql create mode 100644 packages/graphql/tests/samples/fragments/heroFragment.graphql create mode 100644 packages/graphql/tests/samples/fragments/index.js create mode 100644 packages/graphql/tests/samples/multi-imports/hero.graphql create mode 100644 packages/graphql/tests/samples/multi-imports/index.js diff --git a/packages/graphql/CHANGELOG.md b/packages/graphql/CHANGELOG.md new file mode 100644 index 000000000..83eb4dea4 --- /dev/null +++ b/packages/graphql/CHANGELOG.md @@ -0,0 +1,9 @@ +# rollup-plugin-json changelog + +## 0.1.0 + +- Use `graphql-tag/loader` directly [PR #3](https://github.com/kamilkisiela/rollup-plugin-graphql/pull/3) + +## 0.0.1 + +- First release diff --git a/packages/graphql/LICENSE b/packages/graphql/LICENSE new file mode 100644 index 000000000..a6d618ad1 --- /dev/null +++ b/packages/graphql/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Kamil Kisiela + +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. diff --git a/packages/graphql/README.md b/packages/graphql/README.md new file mode 100644 index 000000000..6c203dcc1 --- /dev/null +++ b/packages/graphql/README.md @@ -0,0 +1,44 @@ +# rollup-plugin-graphql + +Convert GraphQL files to ES6 modules: + +:warning: This package is a fork of the [initial rollup-plugin-graphql](https://github.com/kamilkisiela/rollup-plugin-graphql). + +This fork is compatible with Rollup ^1.0 - thanks to [@bennypowers](https://github.com/bennypowers) (https://github.com/kamilkisiela/rollup-plugin-graphql/pull/7). + +And myself, I've just published the module on NPM to make the fork more easier to install on a project. + +```js +// import a GraphQL Document from a GraphQL file, +import schema from './schema.graphql'; + +// or import named Query/Mutation +import { FooQuery, FooMutation } from './schema.graphql'; +``` + + +## Installation + +```bash +npm install --save-dev @kocal/rollup-plugin-graphql +``` + + +## Usage + +```js +import { rollup } from 'rollup'; +import graphql from '@kocal/rollup-plugin-graphql'; + +rollup({ + entry: 'main.js', + plugins: [ + graphql() + ] +}); +``` + + +## License + +MIT diff --git a/packages/graphql/package.json b/packages/graphql/package.json new file mode 100644 index 000000000..e5b31bcde --- /dev/null +++ b/packages/graphql/package.json @@ -0,0 +1,66 @@ +{ + "name": "@kocal/rollup-plugin-graphql", + "version": "1.0.0", + "description": "Convert graphql files to ES6 modules", + "main": "dist/rollup-plugin-graphql.cjs.js", + "module": "dist/rollup-plugin-graphql.es.js", + "jsnext:main": "dist/rollup-plugin-graphql.es.js", + "files": [ + "src", + "dist", + "README.md" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/Kocal/rollup-plugin-graphql.git" + }, + "keywords": [ + "graphql", + "rollup", + "rollupjs" + ], + "author": "Kamil Kisiela ", + "license": "MIT", + "bugs": { + "url": "https://github.com/Kocal/rollup-plugin-graphql/issues" + }, + "homepage": "https://github.com/Kocal/rollup-plugin-graphql#readme", + "contributors": [ + "Benny Powers (https://github.com/bennypowers)", + "Hugo Alliaume (https://github.com/Kocal)" + ], + "publishConfig": { + "access": "public" + }, + "scripts": { + "test": "jest", + "pretest": "npm run build", + "posttest": "npm run lint", + "build": "rollup -c", + "prebuild": "rm -rf dist/*", + "prepublish": "npm test", + "lint": "eslint src" + }, + "dependencies": { + "graphql-tag": "^2.2.2", + "rollup-pluginutils": "^2.0.1" + }, + "peerDependencies": { + "graphql": ">=0.9.0" + }, + "devDependencies": { + "babel-jest": "^24.0.0", + "eslint": "^5.13.0", + "eslint-plugin-import": "^2.3.0", + "eslint-plugin-jest": "^20.0.3", + "graphql": "^14.1.1", + "jest": "^24.0.0", + "rollup": "^1.1.2", + "rollup-plugin-buble": "^0.19.6", + "rollup-plugin-node-resolve": "^4.0.0" + }, + "jest": { + "testRegex": "/tests/.*\\.spec.js$", + "testEnvironment": "node" + } +} diff --git a/packages/graphql/rollup.config.js b/packages/graphql/rollup.config.js new file mode 100644 index 000000000..fde6236df --- /dev/null +++ b/packages/graphql/rollup.config.js @@ -0,0 +1,16 @@ +import buble from 'rollup-plugin-buble'; + +const pkg = require('./package.json'); + +const external = Object.keys(pkg.dependencies); + +export default { + input: 'src/index.js', + output: [ + { file: pkg.main, format: 'cjs' }, + { file: pkg.module, format: 'es' } + ], + plugins: [ buble() ], + external, + sourceMap: true +}; diff --git a/packages/graphql/src/index.js b/packages/graphql/src/index.js new file mode 100644 index 000000000..0a3a6ca84 --- /dev/null +++ b/packages/graphql/src/index.js @@ -0,0 +1,31 @@ +import { createFilter } from 'rollup-pluginutils'; +import loader from 'graphql-tag/loader'; + +import toESModules from './toESModules'; + +export default function graphql({ include, exclude } = {}) { + // path filter + const filter = createFilter(include, exclude); + // only .graphql and .gql files + const filterExt = /\.(graphql|gql)$/i; + + return { + name: 'graphql', + transform(source, id) { + if (!filter(id)) return null; + if (!filterExt.test(id)) return null; + + // XXX: this.cachable() in graphql-tag/loader + const code = toESModules(loader.call({ + cacheable() { } + }, source)); + + const map = { mappings: '' }; + + return { + code, + map + }; + } + }; +} diff --git a/packages/graphql/src/toESModules.js b/packages/graphql/src/toESModules.js new file mode 100644 index 000000000..e69f3d828 --- /dev/null +++ b/packages/graphql/src/toESModules.js @@ -0,0 +1,40 @@ +import { + EOL +} from 'os'; + +export default function(source) { + if (typeof source !== "string") { + return source; + } + + return replaceRequires(replaceModuleExports(source)); +} + +function replaceModuleExports(source) { + return source + .replace('module.exports = doc', 'export default doc') + .replace(/module\.exports\["(.*)"] = oneQuery\(doc, "(.*)"\)/g, (match, g1, g2) => `export const ${g1} = oneQuery(doc, "${g2}")`); +} + +function replaceRequires(source) { + const imports = {}; + let index = 0; + + // replace a require statement with a variable + source = source.replace(/require\(([^)]+)\)/ig, (match, path) => { + path = path.replace(/["']+/g, ''); + + if (!imports[path]) { + imports[path] = `frgmt${++index}`; + } + + return imports[path]; + }); + + // prepare import statements + const importsOutput = Object.keys(imports) + .map((path) => `import ${imports[path]} from "${path}";`) + .join(EOL); + + return importsOutput + EOL + source; +} diff --git a/packages/graphql/tests/index.spec.js b/packages/graphql/tests/index.spec.js new file mode 100644 index 000000000..2e7276561 --- /dev/null +++ b/packages/graphql/tests/index.spec.js @@ -0,0 +1,63 @@ +const rollup = require('rollup'); +const graphql = require('..'); + +process.chdir(__dirname); + +describe('plugin', () => { + it('should parse a simple graphql file', async function() { + const bundle = await rollup.rollup({ + input: 'samples/basic/index.js', + plugins: [graphql()] + }); + const { output: [{ code }] } = await bundle.generate({ + format: 'cjs' + }); + const exports = {}; + const fn = new Function('exports', code); + + fn(exports); + + expect(exports.doc).toBeDefined(); + expect(exports.doc.kind).toBe('Document'); + }); + + it('should include a fragment', async function() { + const bundle = await rollup.rollup({ + input: 'samples/fragments/index.js', + plugins: [graphql()] + }); + const { output: [{ code }] } = await bundle.generate({ + format: 'cjs' + }); + const exports = {}; + const fn = new Function('exports', code); + + fn(exports); + + expect(exports.doc).toBeDefined(); + expect(exports.doc.kind).toBe('Document'); + expect(exports.doc.definitions[1].name.value).toBe('HeroFragment'); + }); + + it('should support multi-imports', async function () { + const bundle = await rollup.rollup({ + input: 'samples/multi-imports/index.js', + plugins: [graphql()] + }); + const { output: [{ code }] } = await bundle.generate({ + format: 'cjs' + }); + const exports = {}; + const fn = new Function('exports', code); + + fn(exports); + + expect(exports.GetHero).toBeDefined(); + expect(exports.GetHero.kind).toBe('Document'); + expect(exports.GetHero.definitions[0].name.value).toBe('GetHero'); + + expect(exports.GetHeros).toBeDefined(); + expect(exports.GetHeros.kind).toBe('Document'); + expect(exports.GetHeros.definitions[0].name.value).toBe('GetHeros'); + }); +}); diff --git a/packages/graphql/tests/samples/basic/basic.graphql b/packages/graphql/tests/samples/basic/basic.graphql new file mode 100644 index 000000000..12e5e6392 --- /dev/null +++ b/packages/graphql/tests/samples/basic/basic.graphql @@ -0,0 +1,6 @@ +query GetHero { + hero { + id + name + } +} diff --git a/packages/graphql/tests/samples/basic/index.js b/packages/graphql/tests/samples/basic/index.js new file mode 100644 index 000000000..9011a505f --- /dev/null +++ b/packages/graphql/tests/samples/basic/index.js @@ -0,0 +1 @@ +export { default as doc } from './basic.graphql'; diff --git a/packages/graphql/tests/samples/fragments/allHeroesQuery.graphql b/packages/graphql/tests/samples/fragments/allHeroesQuery.graphql new file mode 100644 index 000000000..9e2f11275 --- /dev/null +++ b/packages/graphql/tests/samples/fragments/allHeroesQuery.graphql @@ -0,0 +1,7 @@ +#import "./heroFragment.graphql" + +query AllHeroes { + heros { + ...HeroFragment + } +} diff --git a/packages/graphql/tests/samples/fragments/heroFragment.graphql b/packages/graphql/tests/samples/fragments/heroFragment.graphql new file mode 100644 index 000000000..21002acae --- /dev/null +++ b/packages/graphql/tests/samples/fragments/heroFragment.graphql @@ -0,0 +1,4 @@ +fragment HeroFragment on Hero { + id + name +} \ No newline at end of file diff --git a/packages/graphql/tests/samples/fragments/index.js b/packages/graphql/tests/samples/fragments/index.js new file mode 100644 index 000000000..1615809a0 --- /dev/null +++ b/packages/graphql/tests/samples/fragments/index.js @@ -0,0 +1 @@ +export { default as doc } from './allHeroesQuery.graphql'; diff --git a/packages/graphql/tests/samples/multi-imports/hero.graphql b/packages/graphql/tests/samples/multi-imports/hero.graphql new file mode 100644 index 000000000..53e61e399 --- /dev/null +++ b/packages/graphql/tests/samples/multi-imports/hero.graphql @@ -0,0 +1,14 @@ +query GetHero ($id: ID!) { + hero(id: $id) { + id + name + } +} + +query GetHeros { + hero { + id + name + } +} + diff --git a/packages/graphql/tests/samples/multi-imports/index.js b/packages/graphql/tests/samples/multi-imports/index.js new file mode 100644 index 000000000..2d37fc182 --- /dev/null +++ b/packages/graphql/tests/samples/multi-imports/index.js @@ -0,0 +1 @@ +export { GetHero, GetHeros } from './hero.graphql'; From 7922b9a3d1fb3d19908ae873547dbef6f7ae7639 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Wed, 23 Sep 2020 21:53:18 +0200 Subject: [PATCH 2/7] chore(graphql): migrate plugin --- packages/graphql/CHANGELOG.md | 20 +++- packages/graphql/LICENSE | 21 ---- packages/graphql/README.md | 100 +++++++++++++---- packages/graphql/package.json | 106 +++++++++--------- packages/graphql/rollup.config.js | 21 ++-- packages/graphql/src/index.js | 13 ++- packages/graphql/src/toESModules.js | 16 +-- .../fixtures}/basic/basic.graphql | 0 packages/graphql/test/fixtures/basic/index.js | 2 + .../fragments/allHeroesQuery.graphql | 0 .../fixtures}/fragments/heroFragment.graphql | 2 +- .../fixtures}/fragments/index.js | 1 + .../fixtures}/multi-imports/hero.graphql | 3 +- .../fixtures}/multi-imports/index.js | 0 packages/graphql/test/test.js | 52 +++++++++ packages/graphql/test/types.ts | 19 ++++ packages/graphql/tests/index.spec.js | 63 ----------- packages/graphql/tests/samples/basic/index.js | 1 - packages/graphql/types/index.d.ts | 20 ++++ pnpm-lock.yaml | 60 ++++++++++ 20 files changed, 335 insertions(+), 185 deletions(-) delete mode 100644 packages/graphql/LICENSE rename packages/graphql/{tests/samples => test/fixtures}/basic/basic.graphql (100%) create mode 100644 packages/graphql/test/fixtures/basic/index.js rename packages/graphql/{tests/samples => test/fixtures}/fragments/allHeroesQuery.graphql (100%) rename packages/graphql/{tests/samples => test/fixtures}/fragments/heroFragment.graphql (95%) rename packages/graphql/{tests/samples => test/fixtures}/fragments/index.js (50%) rename packages/graphql/{tests/samples => test/fixtures}/multi-imports/hero.graphql (76%) rename packages/graphql/{tests/samples => test/fixtures}/multi-imports/index.js (100%) create mode 100755 packages/graphql/test/test.js create mode 100755 packages/graphql/test/types.ts delete mode 100644 packages/graphql/tests/index.spec.js delete mode 100644 packages/graphql/tests/samples/basic/index.js create mode 100755 packages/graphql/types/index.d.ts diff --git a/packages/graphql/CHANGELOG.md b/packages/graphql/CHANGELOG.md index 83eb4dea4..053509583 100644 --- a/packages/graphql/CHANGELOG.md +++ b/packages/graphql/CHANGELOG.md @@ -1,9 +1,23 @@ -# rollup-plugin-json changelog +# @rollup/plugin-graphql ChangeLog -## 0.1.0 +## v1.0.0 + +_2019-02-18_ + +### Features + +- Add support for multiple exports + +## v0.1.0 + +_2017-01-16_ + +### Features - Use `graphql-tag/loader` directly [PR #3](https://github.com/kamilkisiela/rollup-plugin-graphql/pull/3) -## 0.0.1 +## v0.0.1 + +_2017-01-07_ - First release diff --git a/packages/graphql/LICENSE b/packages/graphql/LICENSE deleted file mode 100644 index a6d618ad1..000000000 --- a/packages/graphql/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2017 Kamil Kisiela - -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. diff --git a/packages/graphql/README.md b/packages/graphql/README.md index 6c203dcc1..e53b9cc35 100644 --- a/packages/graphql/README.md +++ b/packages/graphql/README.md @@ -1,14 +1,52 @@ -# rollup-plugin-graphql +[npm]: https://img.shields.io/npm/v/@rollup/plugin-graphql +[npm-url]: https://www.npmjs.com/package/@rollup/plugin-graphql +[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-graphql +[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-graphql -Convert GraphQL files to ES6 modules: +[![npm][npm]][npm-url] +[![size][size]][size-url] +[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com) -:warning: This package is a fork of the [initial rollup-plugin-graphql](https://github.com/kamilkisiela/rollup-plugin-graphql). +# @rollup/plugin-graphql -This fork is compatible with Rollup ^1.0 - thanks to [@bennypowers](https://github.com/bennypowers) (https://github.com/kamilkisiela/rollup-plugin-graphql/pull/7). +🍣 A Rollup plugin which Converts .gql/.graphql files to ES6 modules. -And myself, I've just published the module on NPM to make the fork more easier to install on a project. +## Requirements + +This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+. + +## Install + +Using npm: + +```console +npm install @rollup/plugin-graphql --save-dev +``` + +## Usage + +Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin: + +```js +import graphql from '@rollup/plugin-graphql'; + +export default { + input: 'src/index.js', + output: { + dir: 'output', + format: 'cjs', + }, + plugins: [graphql()], +}; +``` + +Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api). + +With an accompanying file `src/index.js`, you can import GraphQL files or named queries/mutations: ```js +// src/index.js + // import a GraphQL Document from a GraphQL file, import schema from './schema.graphql'; @@ -16,29 +54,49 @@ import schema from './schema.graphql'; import { FooQuery, FooMutation } from './schema.graphql'; ``` +#### Fragments + +Thanks to [graphql-tag](https://github.com/apollographql/graphql-tag), fragments import is supported by using `#import "..."`. -## Installation +Given the following file `heroFragment.graphql`: -```bash -npm install --save-dev @kocal/rollup-plugin-graphql +```graphql +fragment HeroFragment on Hero { + id + name +} ``` +You can import it like this: -## Usage +```graphql +#import "./heroFragment.graphql" -```js -import { rollup } from 'rollup'; -import graphql from '@kocal/rollup-plugin-graphql'; - -rollup({ - entry: 'main.js', - plugins: [ - graphql() - ] -}); +query AllHeroes { + heros { + ...HeroFragment + } +} ``` +## Options + +### `exclude` + +Type: `String` | `Array[...String]`
+Default: `null` + +A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored. + +### `include` + +Type: `String` | `Array[...String]`
+Default: `null` + +A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted. + +## Meta -## License +[CONTRIBUTING](/.github/CONTRIBUTING.md) -MIT +[LICENSE (MIT)](/LICENSE) diff --git a/packages/graphql/package.json b/packages/graphql/package.json index e5b31bcde..6103e443e 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -1,66 +1,72 @@ { - "name": "@kocal/rollup-plugin-graphql", + "name": "@rollup/plugin-graphql", "version": "1.0.0", - "description": "Convert graphql files to ES6 modules", - "main": "dist/rollup-plugin-graphql.cjs.js", - "module": "dist/rollup-plugin-graphql.es.js", - "jsnext:main": "dist/rollup-plugin-graphql.es.js", + "publishConfig": { + "access": "public" + }, + "description": "Convert .gql/.graphql files to ES6 modules", + "license": "MIT", + "repository": "rollup/plugins", + "author": "rollup", + "homepage": "https://github.com/rollup/plugins/tree/master/packages/json#readme", + "bugs": "https://github.com/rollup/plugins/issues", + "main": "dist/index.js", + "module": "dist/index.es.js", + "scripts": { + "build": "rollup -c", + "ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov", + "ci:lint": "pnpm run build && pnpm run lint", + "ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", + "ci:test": "pnpm run test -- --verbose && pnpm run test:ts", + "lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:graphql && pnpm run lint:package", + "lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md", + "lint:graphql": "prettier --write \"test/fixtures/**/*.graphql\"", + "lint:js": "eslint --fix --cache src test types --ext .js,.ts", + "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", + "prebuild": "del-cli dist", + "prepare": "pnpm run build", + "prepublishOnly": "pnpm run lint && pnpm run test", + "pretest": "pnpm run build", + "test": "ava", + "test:ts": "tsc types/index.d.ts test/types.ts --noEmit" + }, "files": [ - "src", "dist", - "README.md" + "types", + "README.md", + "LICENSE" ], - "repository": { - "type": "git", - "url": "git+https://github.com/Kocal/rollup-plugin-graphql.git" - }, "keywords": [ - "graphql", "rollup", - "rollupjs" + "plugin", + "json", + "es2015", + "npm", + "modules" ], - "author": "Kamil Kisiela ", - "license": "MIT", - "bugs": { - "url": "https://github.com/Kocal/rollup-plugin-graphql/issues" - }, - "homepage": "https://github.com/Kocal/rollup-plugin-graphql#readme", - "contributors": [ - "Benny Powers (https://github.com/bennypowers)", - "Hugo Alliaume (https://github.com/Kocal)" - ], - "publishConfig": { - "access": "public" - }, - "scripts": { - "test": "jest", - "pretest": "npm run build", - "posttest": "npm run lint", - "build": "rollup -c", - "prebuild": "rm -rf dist/*", - "prepublish": "npm test", - "lint": "eslint src" + "peerDependencies": { + "graphql": ">=0.9.0", + "rollup": "^1.20.0 || ^2.0.0" }, "dependencies": { - "graphql-tag": "^2.2.2", - "rollup-pluginutils": "^2.0.1" - }, - "peerDependencies": { - "graphql": ">=0.9.0" + "@rollup/pluginutils": "^4.0.0", + "graphql-tag": "^2.2.2" }, "devDependencies": { - "babel-jest": "^24.0.0", - "eslint": "^5.13.0", - "eslint-plugin-import": "^2.3.0", - "eslint-plugin-jest": "^20.0.3", + "@rollup/plugin-buble": "^0.21.0", "graphql": "^14.1.1", - "jest": "^24.0.0", - "rollup": "^1.1.2", - "rollup-plugin-buble": "^0.19.6", - "rollup-plugin-node-resolve": "^4.0.0" + "rollup": "^2.23.0" }, - "jest": { - "testRegex": "/tests/.*\\.spec.js$", - "testEnvironment": "node" + "types": "types/index.d.ts", + "ava": { + "babel": { + "compileEnhancements": false + }, + "files": [ + "!**/fixtures/**", + "!**/helpers/**", + "!**/recipes/**", + "!**/types.ts" + ] } } diff --git a/packages/graphql/rollup.config.js b/packages/graphql/rollup.config.js index fde6236df..dc0bbeb24 100644 --- a/packages/graphql/rollup.config.js +++ b/packages/graphql/rollup.config.js @@ -1,16 +1,13 @@ -import buble from 'rollup-plugin-buble'; +import buble from '@rollup/plugin-buble'; -const pkg = require('./package.json'); - -const external = Object.keys(pkg.dependencies); +import pkg from './package.json'; export default { - input: 'src/index.js', - output: [ - { file: pkg.main, format: 'cjs' }, - { file: pkg.module, format: 'es' } - ], - plugins: [ buble() ], - external, - sourceMap: true + input: 'src/index.js', + external: [...Object.keys(pkg.dependencies), 'os'], + output: [ + { file: pkg.main, format: 'cjs', sourcemap: true, exports: 'auto' }, + { file: pkg.module, format: 'es', sourcemap: true } + ], + plugins: [buble()] }; diff --git a/packages/graphql/src/index.js b/packages/graphql/src/index.js index 0a3a6ca84..a5d04432a 100644 --- a/packages/graphql/src/index.js +++ b/packages/graphql/src/index.js @@ -1,4 +1,4 @@ -import { createFilter } from 'rollup-pluginutils'; +import { createFilter } from '@rollup/pluginutils'; import loader from 'graphql-tag/loader'; import toESModules from './toESModules'; @@ -16,9 +16,14 @@ export default function graphql({ include, exclude } = {}) { if (!filterExt.test(id)) return null; // XXX: this.cachable() in graphql-tag/loader - const code = toESModules(loader.call({ - cacheable() { } - }, source)); + const code = toESModules( + loader.call( + { + cacheable() {} + }, + source + ) + ); const map = { mappings: '' }; diff --git a/packages/graphql/src/toESModules.js b/packages/graphql/src/toESModules.js index e69f3d828..7e62ea7d1 100644 --- a/packages/graphql/src/toESModules.js +++ b/packages/graphql/src/toESModules.js @@ -1,9 +1,7 @@ -import { - EOL -} from 'os'; +import { EOL } from 'os'; export default function(source) { - if (typeof source !== "string") { + if (typeof source !== 'string') { return source; } @@ -13,7 +11,10 @@ export default function(source) { function replaceModuleExports(source) { return source .replace('module.exports = doc', 'export default doc') - .replace(/module\.exports\["(.*)"] = oneQuery\(doc, "(.*)"\)/g, (match, g1, g2) => `export const ${g1} = oneQuery(doc, "${g2}")`); + .replace( + /module\.exports\["(.*)"] = oneQuery\(doc, "(.*)"\)/g, + (match, g1, g2) => `export const ${g1} = oneQuery(doc, "${g2}")` + ); } function replaceRequires(source) { @@ -21,11 +22,12 @@ function replaceRequires(source) { let index = 0; // replace a require statement with a variable - source = source.replace(/require\(([^)]+)\)/ig, (match, path) => { + source = source.replace(/require\(([^)]+)\)/gi, (match, path) => { path = path.replace(/["']+/g, ''); if (!imports[path]) { - imports[path] = `frgmt${++index}`; + index += 1; + imports[path] = `frgmt${index}`; } return imports[path]; diff --git a/packages/graphql/tests/samples/basic/basic.graphql b/packages/graphql/test/fixtures/basic/basic.graphql similarity index 100% rename from packages/graphql/tests/samples/basic/basic.graphql rename to packages/graphql/test/fixtures/basic/basic.graphql diff --git a/packages/graphql/test/fixtures/basic/index.js b/packages/graphql/test/fixtures/basic/index.js new file mode 100644 index 000000000..0602f6ea2 --- /dev/null +++ b/packages/graphql/test/fixtures/basic/index.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/prefer-default-export +export { default as doc } from './basic.graphql'; diff --git a/packages/graphql/tests/samples/fragments/allHeroesQuery.graphql b/packages/graphql/test/fixtures/fragments/allHeroesQuery.graphql similarity index 100% rename from packages/graphql/tests/samples/fragments/allHeroesQuery.graphql rename to packages/graphql/test/fixtures/fragments/allHeroesQuery.graphql diff --git a/packages/graphql/tests/samples/fragments/heroFragment.graphql b/packages/graphql/test/fixtures/fragments/heroFragment.graphql similarity index 95% rename from packages/graphql/tests/samples/fragments/heroFragment.graphql rename to packages/graphql/test/fixtures/fragments/heroFragment.graphql index 21002acae..f84ab580f 100644 --- a/packages/graphql/tests/samples/fragments/heroFragment.graphql +++ b/packages/graphql/test/fixtures/fragments/heroFragment.graphql @@ -1,4 +1,4 @@ fragment HeroFragment on Hero { id name -} \ No newline at end of file +} diff --git a/packages/graphql/tests/samples/fragments/index.js b/packages/graphql/test/fixtures/fragments/index.js similarity index 50% rename from packages/graphql/tests/samples/fragments/index.js rename to packages/graphql/test/fixtures/fragments/index.js index 1615809a0..95ab5e8a8 100644 --- a/packages/graphql/tests/samples/fragments/index.js +++ b/packages/graphql/test/fixtures/fragments/index.js @@ -1 +1,2 @@ +// eslint-disable-next-line import/prefer-default-export export { default as doc } from './allHeroesQuery.graphql'; diff --git a/packages/graphql/tests/samples/multi-imports/hero.graphql b/packages/graphql/test/fixtures/multi-imports/hero.graphql similarity index 76% rename from packages/graphql/tests/samples/multi-imports/hero.graphql rename to packages/graphql/test/fixtures/multi-imports/hero.graphql index 53e61e399..be5e50aae 100644 --- a/packages/graphql/tests/samples/multi-imports/hero.graphql +++ b/packages/graphql/test/fixtures/multi-imports/hero.graphql @@ -1,4 +1,4 @@ -query GetHero ($id: ID!) { +query GetHero($id: ID!) { hero(id: $id) { id name @@ -11,4 +11,3 @@ query GetHeros { name } } - diff --git a/packages/graphql/tests/samples/multi-imports/index.js b/packages/graphql/test/fixtures/multi-imports/index.js similarity index 100% rename from packages/graphql/tests/samples/multi-imports/index.js rename to packages/graphql/test/fixtures/multi-imports/index.js diff --git a/packages/graphql/test/test.js b/packages/graphql/test/test.js new file mode 100755 index 000000000..ec52012c7 --- /dev/null +++ b/packages/graphql/test/test.js @@ -0,0 +1,52 @@ +const test = require('ava'); +const { rollup } = require('rollup'); + +const { testBundle } = require('../../../util/test'); + +const graphql = require('..'); + +require('source-map-support').install(); + +process.chdir(__dirname); + +test('should parse a simple graphql file', async (t) => { + const bundle = await rollup({ + input: 'fixtures/basic/index.js', + plugins: [graphql()] + }); + + const { module } = await testBundle(t, bundle); + + t.truthy('doc' in module.exports); + t.is(module.exports.doc.kind, 'Document'); +}); + +test('should include a fragment', async (t) => { + const bundle = await rollup({ + input: 'fixtures/fragments/index.js', + plugins: [graphql()] + }); + + const { module } = await testBundle(t, bundle); + + t.truthy('doc' in module.exports); + t.is(module.exports.doc.kind, 'Document'); + t.is(module.exports.doc.definitions[1].name.value, 'HeroFragment'); +}); + +test('should support multi-imports', async (t) => { + const bundle = await rollup({ + input: 'fixtures/multi-imports/index.js', + plugins: [graphql()] + }); + + const { module } = await testBundle(t, bundle); + + t.truthy('GetHero' in module.exports); + t.is(module.exports.GetHero.kind, 'Document'); + t.is(module.exports.GetHero.definitions[0].name.value, 'GetHero'); + + t.truthy('GetHeros' in module.exports); + t.is(module.exports.GetHeros.kind, 'Document'); + t.is(module.exports.GetHeros.definitions[0].name.value, 'GetHeros'); +}); diff --git a/packages/graphql/test/types.ts b/packages/graphql/test/types.ts new file mode 100755 index 000000000..4cc4a6d5d --- /dev/null +++ b/packages/graphql/test/types.ts @@ -0,0 +1,19 @@ +import { RollupOptions } from 'rollup'; + +import graphql from '..'; + +const config: RollupOptions = { + input: 'main.js', + output: { + file: 'bundle.js', + format: 'iife' + }, + plugins: [ + graphql({ + include: 'node_modules/**', + exclude: ['node_modules/foo/**', 'node_modules/bar/**'] + }) + ] +}; + +export default config; diff --git a/packages/graphql/tests/index.spec.js b/packages/graphql/tests/index.spec.js deleted file mode 100644 index 2e7276561..000000000 --- a/packages/graphql/tests/index.spec.js +++ /dev/null @@ -1,63 +0,0 @@ -const rollup = require('rollup'); -const graphql = require('..'); - -process.chdir(__dirname); - -describe('plugin', () => { - it('should parse a simple graphql file', async function() { - const bundle = await rollup.rollup({ - input: 'samples/basic/index.js', - plugins: [graphql()] - }); - const { output: [{ code }] } = await bundle.generate({ - format: 'cjs' - }); - const exports = {}; - const fn = new Function('exports', code); - - fn(exports); - - expect(exports.doc).toBeDefined(); - expect(exports.doc.kind).toBe('Document'); - }); - - it('should include a fragment', async function() { - const bundle = await rollup.rollup({ - input: 'samples/fragments/index.js', - plugins: [graphql()] - }); - const { output: [{ code }] } = await bundle.generate({ - format: 'cjs' - }); - const exports = {}; - const fn = new Function('exports', code); - - fn(exports); - - expect(exports.doc).toBeDefined(); - expect(exports.doc.kind).toBe('Document'); - expect(exports.doc.definitions[1].name.value).toBe('HeroFragment'); - }); - - it('should support multi-imports', async function () { - const bundle = await rollup.rollup({ - input: 'samples/multi-imports/index.js', - plugins: [graphql()] - }); - const { output: [{ code }] } = await bundle.generate({ - format: 'cjs' - }); - const exports = {}; - const fn = new Function('exports', code); - - fn(exports); - - expect(exports.GetHero).toBeDefined(); - expect(exports.GetHero.kind).toBe('Document'); - expect(exports.GetHero.definitions[0].name.value).toBe('GetHero'); - - expect(exports.GetHeros).toBeDefined(); - expect(exports.GetHeros.kind).toBe('Document'); - expect(exports.GetHeros.definitions[0].name.value).toBe('GetHeros'); - }); -}); diff --git a/packages/graphql/tests/samples/basic/index.js b/packages/graphql/tests/samples/basic/index.js deleted file mode 100644 index 9011a505f..000000000 --- a/packages/graphql/tests/samples/basic/index.js +++ /dev/null @@ -1 +0,0 @@ -export { default as doc } from './basic.graphql'; diff --git a/packages/graphql/types/index.d.ts b/packages/graphql/types/index.d.ts new file mode 100755 index 000000000..369e620d7 --- /dev/null +++ b/packages/graphql/types/index.d.ts @@ -0,0 +1,20 @@ +import { FilterPattern } from '@rollup/pluginutils'; +import { Plugin } from 'rollup'; + +export interface RollupGraphqlOptions { + /** + * All JSON files will be parsed by default, + * but you can also specifically include files + */ + include?: FilterPattern; + /** + * All JSON files will be parsed by default, + * but you can also specifically exclude files + */ + exclude?: FilterPattern; +} + +/** + * Convert .gql/.graphql files to ES6 modules + */ +export default function graphql(options?: RollupGraphqlOptions): Plugin; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 901d68cc0..cb994f077 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -212,6 +212,20 @@ importers: magic-string: ^0.25.7 prettier: ^2.0.5 rollup: ^2.23.0 + packages/graphql: + dependencies: + '@rollup/pluginutils': 4.0.0_rollup@2.30.0 + graphql-tag: 2.11.0_graphql@14.7.0 + devDependencies: + '@rollup/plugin-buble': 0.21.3_rollup@2.30.0 + graphql: 14.7.0 + rollup: 2.30.0 + specifiers: + '@rollup/plugin-buble': ^0.21.0 + '@rollup/pluginutils': ^4.0.0 + graphql: ^14.1.1 + graphql-tag: ^2.2.2 + rollup: ^2.23.0 packages/html: devDependencies: rollup: 2.23.0 @@ -1533,6 +1547,19 @@ packages: rollup: ^1.20.0||^2.0.0 resolution: integrity: sha512-Iv8cCuFPnMdqV4pcyU+OrfjOfagPArRQ1PyQjx5KgHk3dARedI+8PNTLSMpJts0lQJr8yF2pAU4GxpxCBJ9HYw== + /@rollup/plugin-buble/0.21.3_rollup@2.30.0: + dependencies: + '@rollup/pluginutils': 3.1.0_rollup@2.30.0 + '@types/buble': 0.19.2 + buble: 0.20.0 + rollup: 2.30.0 + dev: true + engines: + node: '>= 8.0.0' + peerDependencies: + rollup: ^1.20.0||^2.0.0 + resolution: + integrity: sha512-Iv8cCuFPnMdqV4pcyU+OrfjOfagPArRQ1PyQjx5KgHk3dARedI+8PNTLSMpJts0lQJr8yF2pAU4GxpxCBJ9HYw== /@rollup/plugin-commonjs/11.1.0_rollup@2.23.0: dependencies: '@rollup/pluginutils': 3.1.0_rollup@2.23.0 @@ -1694,6 +1721,19 @@ packages: rollup: ^1.20.0||^2.0.0 resolution: integrity: sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg== + /@rollup/pluginutils/4.0.0_rollup@2.30.0: + dependencies: + '@types/estree': 0.0.45 + estree-walker: 2.0.1 + picomatch: 2.2.2 + rollup: 2.30.0 + dev: false + engines: + node: '>= 8.0.0' + peerDependencies: + rollup: ^1.20.0||^2.0.0 + resolution: + integrity: sha512-b5QiJRye4JlSg29bKNEECoKbLuPXZkPEHSgEjjP1CJV1CPdDBybfYHfm6kyq8yK51h/Zsyl8OvWUrp0FUBukEQ== /@sindresorhus/is/0.14.0: dev: true engines: @@ -3968,6 +4008,22 @@ packages: /graceful-fs/4.2.4: resolution: integrity: sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== + /graphql-tag/2.11.0_graphql@14.7.0: + dependencies: + graphql: 14.7.0 + dev: false + peerDependencies: + graphql: ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 + resolution: + integrity: sha512-VmsD5pJqWJnQZMUeRwrDhfgoyqcfwEkvtpANqcoUG8/tOLkwNgU9mzub/Mc78OJMhHjx7gfAMTxzdG43VGg3bA== + /graphql/14.7.0: + dependencies: + iterall: 1.3.0 + dev: true + engines: + node: '>= 6.x' + resolution: + integrity: sha512-l0xWZpoPKpppFzMfvVyFmp9vLN7w/ZZJPefUicMCepfJeQ8sMcztloGYY9DfjVPo6tIUDzU5Hw3MUbIjj9AVVA== /hard-rejection/2.1.0: engines: node: '>=6' @@ -4569,6 +4625,10 @@ packages: node: '>=8' resolution: integrity: sha512-9tZvz7AiR3PEDNGiV9vIouQ/EAcqMXFmkcA1CDFTwOB98OZVDL0PH9glHotf5Ugp6GCOTypfzGWI/OqjWNCRUw== + /iterall/1.3.0: + dev: true + resolution: + integrity: sha512-QZ9qOMdF+QLHxy1QIpUHUU1D5pS2CG2P69LF6L6CPjPYA/XMOmKV3PZpawHoAjHNyB0swdVTRxdYT4tbBbxqwg== /js-string-escape/1.0.1: dev: true engines: From f22515418a715d9c4dd2b5b70eb11e42000d5e17 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Wed, 23 Sep 2020 21:58:08 +0200 Subject: [PATCH 3/7] doc: list graphql and dynamic-import-vars plugins --- README.md | 56 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index abe8a295c..4b03bc917 100644 --- a/README.md +++ b/README.md @@ -15,33 +15,35 @@ This repository houses plugins that Rollup considers critical to every day use o ## Plugins Found Here -| | | -| ------------------------------------- | ----------------------------------------------------------------------------------------- | -| [alias](packages/alias) | Define and resolve aliases for bundle dependencies | -| [auto-install](packages/auto-install) | Automatically install dependencies that are imported by a bundle | -| [babel](packages/babel) | Compile your files with Babel | -| [beep](packages/beep) | System beeps on errors and warnings | -| [buble](packages/buble) | Compile ES2015 with buble | -| [commonjs](packages/commonjs) | Convert CommonJS modules to ES6 | -| [data-uri](packages/data-uri) | Import modules from Data URIs | -| [dsv](packages/dsv) | Convert .csv and .tsv files into JavaScript modules with d3-dsv | -| [html](packages/html) | Create HTML files to serve Rollup bundles | -| [image](packages/image) | Import JPG, PNG, GIF, SVG, and WebP files | -| [inject](packages/inject) | Scan modules for global variables and injects `import` statements where necessary | -| [json](packages/json) | Convert .json files to ES6 modules | -| [legacy](packages/legacy) | Add `export` declarations to legacy non-module scripts | -| [multi-entry](packages/multi-entry) | Use multiple entry points for a bundle | -| [node-resolve](packages/node-resolve) | Locate and bundle third-party dependencies in node_modules | -| [replace](packages/replace) | Replace strings in files while bundling | -| [run](packages/run) | Run your bundles in Node once they're built | -| [strip](packages/strip) | Remove debugger statements and functions like assert.equal and console.log from your code | -| [sucrase](packages/sucrase) | Compile TypeScript, Flow, JSX, etc with Sucrase | -| [typescript](packages/typescript) | Integration between Rollup and Typescript | -| [url](packages/url) | Import files as data-URIs or ES Modules | -| [virtual](packages/virtual) | Load virtual modules from memory | -| [wasm](packages/wasm) | Import WebAssembly code with Rollup | -| [yaml](packages/yaml) | Convert YAML files to ES6 modules | -| | | +| | | +| --------------------------------------------------- | ----------------------------------------------------------------------------------------- | +| [alias](packages/alias) | Define and resolve aliases for bundle dependencies | +| [auto-install](packages/auto-install) | Automatically install dependencies that are imported by a bundle | +| [babel](packages/babel) | Compile your files with Babel | +| [beep](packages/beep) | System beeps on errors and warnings | +| [buble](packages/buble) | Compile ES2015 with buble | +| [commonjs](packages/commonjs) | Convert CommonJS modules to ES6 | +| [data-uri](packages/data-uri) | Import modules from Data URIs | +| [dsv](packages/dsv) | Convert .csv and .tsv files into JavaScript modules with d3-dsv | +| [dynamic-import-vars](packages/dynamic-import-vars) | Resolving dynamic imports that contain variables. | +| [graphql](packages/graphql) | Convert .gql/.graphql files to ES6 modules | +| [html](packages/html) | Create HTML files to serve Rollup bundles | +| [image](packages/image) | Import JPG, PNG, GIF, SVG, and WebP files | +| [inject](packages/inject) | Scan modules for global variables and injects `import` statements where necessary | +| [json](packages/json) | Convert .json files to ES6 modules | +| [legacy](packages/legacy) | Add `export` declarations to legacy non-module scripts | +| [multi-entry](packages/multi-entry) | Use multiple entry points for a bundle | +| [node-resolve](packages/node-resolve) | Locate and bundle third-party dependencies in node_modules | +| [replace](packages/replace) | Replace strings in files while bundling | +| [run](packages/run) | Run your bundles in Node once they're built | +| [strip](packages/strip) | Remove debugger statements and functions like assert.equal and console.log from your code | +| [sucrase](packages/sucrase) | Compile TypeScript, Flow, JSX, etc with Sucrase | +| [typescript](packages/typescript) | Integration between Rollup and Typescript | +| [url](packages/url) | Import files as data-URIs or ES Modules | +| [virtual](packages/virtual) | Load virtual modules from memory | +| [wasm](packages/wasm) | Import WebAssembly code with Rollup | +| [yaml](packages/yaml) | Convert YAML files to ES6 modules | +| | | ## Other Packages Found Here From 5056d6d05a014391a455a0cd7afd80887a03ccc0 Mon Sep 17 00:00:00 2001 From: Hugo Alliaume Date: Thu, 24 Sep 2020 22:23:38 +0200 Subject: [PATCH 4/7] chore(graphql): use named export --- packages/graphql/src/index.js | 2 +- packages/graphql/src/toESModules.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/graphql/src/index.js b/packages/graphql/src/index.js index a5d04432a..2950d3c06 100644 --- a/packages/graphql/src/index.js +++ b/packages/graphql/src/index.js @@ -1,7 +1,7 @@ import { createFilter } from '@rollup/pluginutils'; import loader from 'graphql-tag/loader'; -import toESModules from './toESModules'; +import { toESModules } from './toESModules'; export default function graphql({ include, exclude } = {}) { // path filter diff --git a/packages/graphql/src/toESModules.js b/packages/graphql/src/toESModules.js index 7e62ea7d1..bd5260d43 100644 --- a/packages/graphql/src/toESModules.js +++ b/packages/graphql/src/toESModules.js @@ -1,6 +1,13 @@ +/* eslint-disable import/prefer-default-export */ + import { EOL } from 'os'; -export default function(source) { +/** + * Convert CommonJS exports to ES modules exports + * @param source Source code to convert + * @returns The converted source code + */ +export function toESModules(source) { if (typeof source !== 'string') { return source; } From 6f049c52ea3bba7622fd66efbc1de64e3c49b7f2 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 26 Oct 2020 21:40:01 -0400 Subject: [PATCH 5/7] chore: update readme, make tests use src --- packages/graphql/README.md | 4 ++-- packages/graphql/test/test.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/graphql/README.md b/packages/graphql/README.md index e53b9cc35..d61725df6 100644 --- a/packages/graphql/README.md +++ b/packages/graphql/README.md @@ -13,7 +13,7 @@ ## Requirements -This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+. +This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v10.0.0+) and Rollup v1.20.0+. ## Install @@ -51,7 +51,7 @@ With an accompanying file `src/index.js`, you can import GraphQL files or named import schema from './schema.graphql'; // or import named Query/Mutation -import { FooQuery, FooMutation } from './schema.graphql'; +import { BatmanQuery, JokerMutation } from './schema.graphql'; ``` #### Fragments diff --git a/packages/graphql/test/test.js b/packages/graphql/test/test.js index ec52012c7..a1a42f4e6 100755 --- a/packages/graphql/test/test.js +++ b/packages/graphql/test/test.js @@ -3,7 +3,7 @@ const { rollup } = require('rollup'); const { testBundle } = require('../../../util/test'); -const graphql = require('..'); +const graphql = require('../src'); require('source-map-support').install(); From 32ad749290ce404403bff7173f1db4b5b65c3bca Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 26 Oct 2020 21:40:24 -0400 Subject: [PATCH 6/7] chore(eslint): remove static license file, this is added dynamically on publish --- packages/eslint/LICENSE | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100755 packages/eslint/LICENSE diff --git a/packages/eslint/LICENSE b/packages/eslint/LICENSE deleted file mode 100755 index 2f3c321f7..000000000 --- a/packages/eslint/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2020 RollupJS Plugin Contributors (https://github.com/rollup/plugins/graphs/contributors) - -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. From 1d3899ffc5f1a6908650e30aa14665cc24b8e2a9 Mon Sep 17 00:00:00 2001 From: shellscape Date: Mon, 26 Oct 2020 21:44:38 -0400 Subject: [PATCH 7/7] chore: few things to clean up, tests use compiled again --- packages/graphql/package.json | 10 +++++----- packages/graphql/test/test.js | 2 +- pnpm-lock.yaml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/graphql/package.json b/packages/graphql/package.json index 6103e443e..163c87216 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -8,7 +8,7 @@ "license": "MIT", "repository": "rollup/plugins", "author": "rollup", - "homepage": "https://github.com/rollup/plugins/tree/master/packages/json#readme", + "homepage": "https://github.com/rollup/plugins/tree/master/packages/graphql#readme", "bugs": "https://github.com/rollup/plugins/issues", "main": "dist/index.js", "module": "dist/index.es.js", @@ -39,9 +39,9 @@ "keywords": [ "rollup", "plugin", - "json", - "es2015", - "npm", + "graphql", + "apollo", + "import", "modules" ], "peerDependencies": { @@ -53,7 +53,7 @@ "graphql-tag": "^2.2.2" }, "devDependencies": { - "@rollup/plugin-buble": "^0.21.0", + "@rollup/plugin-buble": "^0.21.3", "graphql": "^14.1.1", "rollup": "^2.23.0" }, diff --git a/packages/graphql/test/test.js b/packages/graphql/test/test.js index a1a42f4e6..ec52012c7 100755 --- a/packages/graphql/test/test.js +++ b/packages/graphql/test/test.js @@ -3,7 +3,7 @@ const { rollup } = require('rollup'); const { testBundle } = require('../../../util/test'); -const graphql = require('../src'); +const graphql = require('..'); require('source-map-support').install(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e8951f812..5a9d401be 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -237,7 +237,7 @@ importers: graphql: 14.7.0 rollup: 2.32.1 specifiers: - '@rollup/plugin-buble': ^0.21.0 + '@rollup/plugin-buble': ^0.21.3 '@rollup/pluginutils': ^4.0.0 graphql: ^14.1.1 graphql-tag: ^2.2.2