Skip to content

Commit

Permalink
feat: package is now ESM (#909)
Browse files Browse the repository at this point in the history
* feat: package is now ESM

BREAKING CHANGE: package is now ESM

* fix(deps): bump execa

* fix: correct `fs` import

* fix: replace usage of `require()`

* style: prettier

* fix: update execa import

* test: remove default export tests
  • Loading branch information
wolfy1339 authored Mar 4, 2024
1 parent 5d2cd03 commit f419cdd
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 499 deletions.
11 changes: 6 additions & 5 deletions bin/download.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env node

const writeFileSync = require("fs").writeFileSync;

require("dotenv").config();
import { writeFileSync } from "node:fs";
import dotenv from "dotenv";
dotenv.config();

if (!process.env.GITHUB_TOKEN) {
console.log("GITHUB_TOKEN not set");
process.exit(1);
}

const execa = require("execa");
const request = require("@octokit/request").request.defaults({
import { execa } from "execa";
import { request as octokitRequest } from "@octokit/request";
const request = octokitRequest.defaults({
headers: {
authorization: `bearer ${process.env.GITHUB_TOKEN}`,
},
Expand Down
7 changes: 0 additions & 7 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ type Schema = {

type Validate = (query: ReadonlyArray<string> | Readonly<string>) => ReadonlyArray<GraphQLError>;

declare namespace GraphqlSchema {
const validate: Validate;
const schema: Schema;
}

export const schema: Schema
export const validate: Validate

export * from './schema'

export default GraphqlSchema
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
validate: require('./lib/validate'),
schema: {
get idl () {
const join = require('path').join
return require('fs').readFileSync(join(__dirname, 'schema.graphql'), 'utf8')
},
json: require('./schema.json')
}
import { readFileSync } from 'node:fs';
import validate from './lib/validate.js';

export { validate };
export const schema = {
get idl () {
return readFileSync(new URL('./schema.graphql', import.meta.url), 'utf8')
},
json: JSON.parse(readFileSync(new URL('./schema.json', import.meta.url), 'utf8'))
}
13 changes: 8 additions & 5 deletions lib/validate.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
module.exports = validateQuery;
export default validateQuery;

const graphql = require("graphql");
const gql = require("graphql-tag");
import { readFileSync } from "node:fs";
import { buildClientSchema, validate } from "graphql";
import gql from "graphql-tag";

const schema = graphql.buildClientSchema(require("../schema.json"));
const schema = buildClientSchema(
JSON.parse(readFileSync(new URL("../schema.json", import.meta.url), "utf8")),
);

function validateQuery(query) {
return graphql.validate(schema, gql(query));
return validate(schema, gql(query));
}
Loading

0 comments on commit f419cdd

Please sign in to comment.