vite-plugin-graphql-loader 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  A Vite plugin for loading GraphQL .gql and .graphql files, based on [graphql-tag/loader](https://github.com/apollographql/graphql-tag)
8
8
 
9
+ If you are using TypeScript, I recommend using GraphQL Codegen and [vite-plugin-graphql-codegen](https://www.npmjs.com/package/vite-plugin-graphql-codegen) instead to generate TypesScript interfaces for your queries and fragments.
10
+
9
11
  ## Install
10
12
 
11
13
  ```bash
@@ -60,6 +62,7 @@ If you are using TypeScript, you will have to declare `.gql` or `.graphql` files
60
62
 
61
63
  ```typescript
62
64
  declare module "*.gql";
65
+ declare module "*.graphql";
63
66
 
64
67
  // Or if you aren't using fragments:
65
68
  // declare module "*.gql" {
@@ -67,3 +70,7 @@ declare module "*.gql";
67
70
  // export default Query;
68
71
  // }
69
72
  ```
73
+
74
+ ## Changelog
75
+
76
+ **_v3.0.0_**: Moved from CJS to ESM, inline with Vite 5.0's CJS deprecation. If you are using CommonJS, continue using v2.0 of this package.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ declare module "*.graphql";
2
+ declare module "*.gql";
1
3
  export declare const vitePluginGraphqlLoader: () => {
2
4
  name: string;
3
5
  enforce: "pre";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA0BA,eAAO,MAAM,uBAAuB;;;sBAOV,MAAM,MAAM,MAAM;CAyE3C,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,QAAQ,WAAW,CAAC;AAC3B,OAAO,QAAQ,OAAO,CAAC;AAwBvB,eAAO,MAAM,uBAAuB;;;sBAOV,MAAM,MAAM,MAAM;CAoE3C,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
package/dist/index.js CHANGED
@@ -1,28 +1,22 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.vitePluginGraphqlLoader = void 0;
7
- const os_1 = __importDefault(require("os"));
8
- const graphql_tag_1 = __importDefault(require("graphql-tag"));
9
- const snippets_1 = require("./snippets");
1
+ import { EOL } from "os";
2
+ import { gql } from "graphql-tag";
3
+ import { ONE_QUERY, UNIQUE } from "./snippets.js";
10
4
  const expandImports = (source) => {
11
5
  const lines = source.split(/\r\n|\r|\n/);
12
- let outputCode = snippets_1.UNIQUE;
6
+ let outputCode = UNIQUE;
13
7
  lines.some((line) => {
14
8
  const result = line.match(/^#\s?import (.+)$/);
15
9
  if (result) {
16
10
  const [_, importFile] = result;
17
11
  const parseDocument = `(await import(${importFile})).default`;
18
12
  const appendDefinition = `doc.definitions = doc.definitions.concat(unique(${parseDocument}.definitions));`;
19
- outputCode += appendDefinition + os_1.default.EOL;
13
+ outputCode += appendDefinition + EOL;
20
14
  }
21
15
  return line.length > 0 && line[0] !== "#";
22
16
  });
23
17
  return outputCode;
24
18
  };
25
- const vitePluginGraphqlLoader = () => {
19
+ export const vitePluginGraphqlLoader = () => {
26
20
  const graphqlRegex = /\.(?:gql|graphql)$/;
27
21
  return {
28
22
  name: "graphql-loader",
@@ -31,7 +25,7 @@ const vitePluginGraphqlLoader = () => {
31
25
  if (!graphqlRegex.test(id)) {
32
26
  return;
33
27
  }
34
- const documentNode = (0, graphql_tag_1.default) `
28
+ const documentNode = gql `
35
29
  ${source}
36
30
  `;
37
31
  const headerCode = `
@@ -52,7 +46,7 @@ doc.loc.source = ${JSON.stringify(documentNode.loc.source)};
52
46
  `;
53
47
  }
54
48
  else {
55
- outputCode += snippets_1.ONE_QUERY;
49
+ outputCode += ONE_QUERY;
56
50
  for (const op of documentNode.definitions) {
57
51
  if (op.kind === "OperationDefinition" ||
58
52
  op.kind === "FragmentDefinition") {
@@ -72,16 +66,10 @@ export const ${opName} = oneQuery(doc, "${opName}");
72
66
  }
73
67
  }
74
68
  const importOutputCode = expandImports(source);
75
- const allCode = headerCode +
76
- os_1.default.EOL +
77
- importOutputCode +
78
- os_1.default.EOL +
79
- outputCode +
80
- os_1.default.EOL;
69
+ const allCode = headerCode + EOL + importOutputCode + EOL + outputCode + EOL;
81
70
  return allCode;
82
71
  },
83
72
  };
84
73
  };
85
- exports.vitePluginGraphqlLoader = vitePluginGraphqlLoader;
86
- exports.default = exports.vitePluginGraphqlLoader;
74
+ export default vitePluginGraphqlLoader;
87
75
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,8DAA8B;AAC9B,yCAA+C;AAK/C,MAAM,aAAa,GAAG,CAAC,MAAc,EAAE,EAAE;IACrC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACzC,IAAI,UAAU,GAAG,iBAAM,CAAC;IAExB,KAAK,CAAC,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;QAC/C,IAAI,MAAM,EAAE;YACR,MAAM,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,MAAM,CAAC;YAC/B,MAAM,aAAa,GAAG,iBAAiB,UAAU,YAAY,CAAC;YAC9D,MAAM,gBAAgB,GAAG,mDAAmD,aAAa,iBAAiB,CAAC;YAC3G,UAAU,IAAI,gBAAgB,GAAG,YAAE,CAAC,GAAG,CAAC;SAC3C;QACD,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;IAC9C,CA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B;wBACjC,EAAE,CAAC,IAAI,KAAK,oBAAoB,EAClC,CAAC;wBACC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;4BACX,IAAI,cAAc,GAAG,CAAC,EAAE,CAAC;gCACrB,MAAM,IAAI,KAAK,CACX,4EAA4E,CAC/E,CAAC;4BACN,CAAC;iCAAM,CAAC;gCACJ,SAAS;4BACb,CAAC;wBACL,CAAC;wBAED,MAAM,MAAM,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC;wBAC7B,UAAU,IAAI;eACvB,MAAM,qBAAqB,MAAM;iBAC/B,CAAC;oBACE,CAAC;gBACL,CAAC;YACL,CAAC;YAED,MAAM,gBAAgB,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;YAC/C,MAAM,OAAO,GACT,UAAU,GAAG,GAAG,GAAG,gBAAgB,GAAG,GAAG,GAAG,UAAU,GAAG,GAAG,CAAC;YAEjE,OAAO,OAAO,CAAC;QACnB,CAAC;KACJ,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,uBAAuB,CAAC"}
package/dist/snippets.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ONE_QUERY = exports.UNIQUE = void 0;
4
- exports.UNIQUE = `
1
+ export const UNIQUE = `
5
2
  const names = {};
6
3
  function unique(defs) {
7
4
  return defs.filter(
@@ -18,7 +15,7 @@ function unique(defs) {
18
15
  )
19
16
  }
20
17
  `;
21
- exports.ONE_QUERY = `
18
+ export const ONE_QUERY = `
22
19
  // Collect any fragment/type references from a node, adding them to the refs Set
23
20
  function collectFragmentReferences(node, refs) {
24
21
  if (node.kind === "FragmentSpread") {
@@ -1 +1 @@
1
- {"version":3,"file":"snippets.js","sourceRoot":"","sources":["../src/snippets.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAG;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAEW,QAAA,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFxB,CAAC"}
1
+ {"version":3,"file":"snippets.js","sourceRoot":"","sources":["../src/snippets.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;CAgBrB,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFxB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "vite-plugin-graphql-loader",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "A Vite plugin for loading GraphQL files.",
5
+ "type": "module",
5
6
  "main": "dist/index.js",
6
7
  "types": "dist/index.d.ts",
7
8
  "files": [
@@ -12,7 +13,8 @@
12
13
  "test": "vitest",
13
14
  "build": "rimraf ./dist && tsc",
14
15
  "package:bump": "yarn version --patch",
15
- "package:publish": "yarn build && yarn package:bump && yarn publish"
16
+ "package:publish": "yarn build && yarn package:bump && yarn publish",
17
+ "lint": "yarn prettier -w src tests/**/*.ts && yarn eslint --fix"
16
18
  },
17
19
  "repository": {
18
20
  "type": "git",
@@ -31,16 +33,20 @@
31
33
  },
32
34
  "homepage": "https://github.com/noiach/vite-plugin-graphql-loader#readme",
33
35
  "dependencies": {
34
- "graphql": "^16.6.0",
36
+ "graphql": "^16.8.1",
35
37
  "graphql-tag": "^2.12.6"
36
38
  },
37
39
  "devDependencies": {
38
- "@types/glob": "^8.0.1",
39
- "@types/node": "^16",
40
- "glob": "^8.1.0",
41
- "rimraf": "^4.3.1",
42
- "typescript": "^4.9.5",
43
- "vite": "^4.1.1",
44
- "vitest": "^0.28.5"
40
+ "@types/node": "^20",
41
+ "eslint": "^8.56.0",
42
+ "glob": "^10.3.10",
43
+ "prettier": "^3.2.4",
44
+ "rimraf": "^5.0.5",
45
+ "typescript": "^5.3.3",
46
+ "vite": "^5.0.12",
47
+ "vitest": "^1.2.1"
48
+ },
49
+ "prettier": {
50
+ "tabWidth": 4
45
51
  }
46
52
  }