Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Rollup to build also as ESM #273

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": [ "es2015" ]
"presets": [ "@babel/preset-env" ]
}
4 changes: 2 additions & 2 deletions loader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const os = require('os');
const gql = require('./src');
import os from 'os';
import gql from './src';

// Takes `source` (the source GraphQL query string)
// and `doc` (the parsed GraphQL document) and tacks on
Expand Down
4,706 changes: 3,847 additions & 859 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "2.11.0",
"description": "A JavaScript template literal tag that parses GraphQL queries",
"main": "./lib/graphql-tag.umd.js",
"module": "./src/index.js",
"jsnext:main": "./src/index.js",
"module": "./lib/graphql-tag.js",
"jsnext:main": "./lib/graphql-tag.js",
"sideEffects": false,
"scripts": {
"bundle": "rollup -c && cp src/index.js.flow lib/graphql-tag.umd.js.flow",
Expand All @@ -23,15 +23,19 @@
"homepage": "https://github.com/apollographql/graphql-tag#readme",
"dependencies": {},
"devDependencies": {
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"chai": "^4.0.2",
"graphql": "^15.0.0",
"mocha": "^3.4.1",
"rollup": "^0.45.0",
"test-all-versions": "^3.3.2"
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@babel/register": "^7.12.10",
"chai": "^4.2.0",
"graphql": "^15.4.0",
"mocha": "^8.2.1",
"rollup": "^2.37.0",
"test-all-versions": "^5.0.1"
},
"peerDependencies": {
"graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
},
"mocha": {
"require": "@babel/register"
}
}
23 changes: 18 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
export default {
entry: 'src/index.js',
dest: 'lib/graphql-tag.umd.js',
format: 'umd',
sourceMap: true,
moduleName: 'graphql-tag',
input: 'src/index.js',
output: [
{
file: 'lib/graphql-tag.js',
format: 'esm',
sourcemap: true
},
{
file: 'lib/graphql-tag.umd.js',
format: 'umd',
globals: {
'graphql/language': 'language'
},
name: 'graphql-tag',
sourcemap: true,
exports: 'named'
}
],
onwarn
};

Expand Down
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var parser = require('graphql/language/parser');

var parse = parser.parse;
import { parse } from 'graphql/language';

// Strip insignificant whitespace
// Note that this could do a lot more, such as reorder fields etc.
Expand Down Expand Up @@ -177,4 +175,4 @@ gql.disableFragmentWarnings = disableFragmentWarnings;
gql.enableExperimentalFragmentVariables = enableExperimentalFragmentVariables;
gql.disableExperimentalFragmentVariables = disableExperimentalFragmentVariables;

module.exports = gql;
export default gql;
7 changes: 4 additions & 3 deletions test/graphql.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const gql = require('../src');
const loader = require('../loader');
const assert = require('chai').assert;
import { assert } from 'chai';

import gql from '../src';
import loader from '../loader';

describe('gql', () => {
it('parses queries', () => {
Expand Down
1 change: 0 additions & 1 deletion test/mocha.opts

This file was deleted.

Loading