@avantstay/graphql-ts-client 10.8.0 → 10.9.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
@@ -33,10 +33,10 @@ import { myAwesomeApi, AssetType, Granularity, OnBoardingStage } from './myAweso
33
33
  async function somewhereOverTheRainbow() {
34
34
  // Set an specific header if needed
35
35
  myAwesomeApi.setHeader('Authorization', 'Bearer 010101010101')
36
-
36
+
37
37
  // You can also change the API url
38
38
  myAwesomeApi.setUrl('https://my-runtime-url.com/graphql')
39
-
39
+
40
40
  // And configure how retrials should work
41
41
  myAwesomeApi.setRetryConfig({
42
42
  max: 3,
@@ -44,12 +44,12 @@ async function somewhereOverTheRainbow() {
44
44
  // do something before retrying
45
45
  },
46
46
  })
47
-
47
+
48
48
  // Adding response listeners is also possible
49
49
  myAwesomeApi.addResponseListener(({ queryName, query, variables, response }) => {
50
50
  // do something whenever a request is responded
51
51
  })
52
-
52
+
53
53
  const response = await myAwesomeApi.queries.globalIndicators({
54
54
  // Optionally you can define an alias for this request
55
55
  __alias: 'myCustomGlobalIndicators',
@@ -0,0 +1,27 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw new Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/types.ts
10
+ var GraphQLClientError = class extends Error {
11
+ constructor(responseData) {
12
+ super();
13
+ this.responseData = responseData;
14
+ Object.setPrototypeOf(this, GraphQLClientError.prototype);
15
+ }
16
+ get message() {
17
+ return this.response.errors.map((it) => it.message).join(";\n");
18
+ }
19
+ get response() {
20
+ return this.responseData;
21
+ }
22
+ };
23
+
24
+ export {
25
+ __require,
26
+ GraphQLClientError
27
+ };
@@ -1,13 +1,13 @@
1
- import { C as ClientConfig, I as IResponseListener, E as Endpoint } from './types-85e628f6.js';
1
+ import { C as ClientConfig, I as IResponseListener, E as Endpoint } from './types-23d2d6aa.js';
2
2
 
3
- declare const getApiEndpointCreator: (apiConfig: {
4
- getClient: () => ClientConfig;
5
- responseListeners: IResponseListener[];
6
- typesTree: any;
7
- maxAge: number;
8
- verbose: boolean;
9
- formatGraphQL: any;
10
- errorsParser?: ((errors: any[]) => any) | undefined;
3
+ declare const getApiEndpointCreator: (apiConfig: {
4
+ getClient: () => ClientConfig;
5
+ responseListeners: IResponseListener[];
6
+ typesTree: any;
7
+ maxAge: number;
8
+ verbose: boolean;
9
+ formatGraphQL: any;
10
+ errorsParser?: ((errors: any[]) => any) | undefined;
11
11
  }) => <I = any, O = any, E = any>(kind: 'mutation' | 'query', queryName: string) => Endpoint<I, O, E>;
12
12
 
13
13
  export { getApiEndpointCreator };
@@ -0,0 +1,275 @@
1
+ import {
2
+ GraphQLClientError,
3
+ __require
4
+ } from "./chunk-I4QOADOI.mjs";
5
+
6
+ // src/endpoint.ts
7
+ import memoize from "moize";
8
+
9
+ // src/graphqlRequest.ts
10
+ import _axios from "axios";
11
+ var sleep = (ms = 0) => new Promise((resolve) => {
12
+ setTimeout(() => resolve(), ms);
13
+ });
14
+ async function graphqlRequest({
15
+ shouldRetry = true,
16
+ axios = _axios,
17
+ queryName,
18
+ client,
19
+ query,
20
+ requestHeaders = {},
21
+ variables,
22
+ failureMode,
23
+ errorsParser
24
+ }) {
25
+ let lastResponse;
26
+ const maxRetrials = shouldRetry ? client.retryConfig.max : 0;
27
+ for (let trial = 0; true; trial++) {
28
+ const infoParams = {
29
+ _q: queryName,
30
+ ...trial > 0 ? { _retrial: trial + 1 } : {}
31
+ };
32
+ const {
33
+ data: responseData = {},
34
+ headers,
35
+ status
36
+ } = await axios.post(
37
+ client.url,
38
+ { query, variables, operationName: queryName },
39
+ {
40
+ params: infoParams,
41
+ headers: {
42
+ "Content-Type": "application/json",
43
+ ...client.headers,
44
+ ...requestHeaders
45
+ },
46
+ validateStatus: () => true
47
+ }
48
+ );
49
+ let { data, errors, warnings } = responseData;
50
+ if (status >= 400 && !errors?.length) {
51
+ errors = [{ message: `Request "${queryName}" failed with status ${status}` }];
52
+ }
53
+ lastResponse = {
54
+ errors: errorsParser ? errorsParser(errors) : errors,
55
+ data,
56
+ warnings,
57
+ headers,
58
+ status
59
+ };
60
+ if (!errors?.length) {
61
+ break;
62
+ } else if (trial < maxRetrials && typeof client.retryConfig?.before === "function") {
63
+ await client.retryConfig?.before({
64
+ queryName,
65
+ query,
66
+ variables,
67
+ response: lastResponse
68
+ });
69
+ if (client.retryConfig.waitBeforeRetry) {
70
+ await sleep(client.retryConfig.waitBeforeRetry);
71
+ }
72
+ } else if (trial >= maxRetrials) {
73
+ break;
74
+ }
75
+ }
76
+ if (failureMode === "loud" && lastResponse.errors && lastResponse.errors?.length) {
77
+ throw new GraphQLClientError(lastResponse);
78
+ }
79
+ return lastResponse;
80
+ }
81
+
82
+ // src/jsonToGraphQLQuery.ts
83
+ import omit from "lodash/omit";
84
+ var VAR_PREFIX = "@@VAR@@";
85
+ var VAR_PREFIX_LENGTH = VAR_PREFIX.length;
86
+ var fromEntries = __require("lodash/fromPairs");
87
+ var entries = __require("lodash/toPairs");
88
+ var cloneDeep = __require("lodash/cloneDeep");
89
+ function jsonToGraphQLQuery({
90
+ kind,
91
+ queryName,
92
+ jsonQuery = {},
93
+ typesTree
94
+ }) {
95
+ const variablesData = {};
96
+ const alias = jsonQuery.__alias;
97
+ const newJsonQuery = cloneDeep(omit(jsonQuery, ["__alias", "__headers", "__url"]));
98
+ extractVariables({
99
+ jsonQuery: { [queryName]: newJsonQuery },
100
+ variables: variablesData,
101
+ parentType: kind === "query" ? typesTree.Query : typesTree.Mutation
102
+ });
103
+ const variableItems = Object.values(variablesData).reduce(
104
+ (variablesObj, variables2) => {
105
+ variables2.forEach((variable, index) => {
106
+ const name = variable.update(variables2.length > 1 ? index : void 0);
107
+ variablesObj[name] = { type: variable.type, value: variable.value };
108
+ });
109
+ return variablesObj;
110
+ },
111
+ {}
112
+ );
113
+ const variablesQuery = Object.keys(variableItems).length ? `(${entries(variableItems).map(([queryName2, { type }]) => `$${queryName2}: ${type}`).join(", ")})` : "";
114
+ const query = `${kind} ${alias || queryName}${variablesQuery} { ${alias ? `${alias}:` : ""}${queryName}${toGraphql(
115
+ newJsonQuery
116
+ )} }`;
117
+ const variables = fromEntries(entries(variableItems).map(([k, v]) => [k, v.value]));
118
+ return {
119
+ query,
120
+ variables
121
+ };
122
+ }
123
+ function extractVariables({
124
+ jsonQuery,
125
+ variables,
126
+ parentType
127
+ }) {
128
+ if (!parentType)
129
+ return;
130
+ if (jsonQuery.__args) {
131
+ Object.keys(jsonQuery.__args).forEach((k) => {
132
+ if (typeof jsonQuery.__args[k] === "string" && jsonQuery.__args[k].startsWith(VAR_PREFIX))
133
+ return;
134
+ if (jsonQuery.__args[k] === void 0)
135
+ return;
136
+ const variableName = k;
137
+ if (!variables[variableName]) {
138
+ variables[variableName] = [];
139
+ }
140
+ variables[variableName].push({
141
+ name: variableName,
142
+ type: parentType.__args[k],
143
+ value: jsonQuery.__args[k],
144
+ update: (index) => {
145
+ const name = `${variableName}${index !== void 0 ? `_${index}` : ""}`;
146
+ jsonQuery.__args[k] = `${VAR_PREFIX}$${name}`;
147
+ return name;
148
+ }
149
+ });
150
+ jsonQuery.__args[k] = VAR_PREFIX;
151
+ });
152
+ }
153
+ Object.keys(jsonQuery).filter((k) => k !== "__args" && typeof jsonQuery[k] === "object").forEach(
154
+ (k) => extractVariables({
155
+ jsonQuery: jsonQuery[k],
156
+ variables,
157
+ parentType: parentType.hasOwnProperty(k) ? parentType[k] : parentType.__fields ? parentType.__fields[k] : void 0
158
+ })
159
+ );
160
+ }
161
+ function toGraphql(jsonQuery) {
162
+ const fields = entries(jsonQuery).filter(([k, v]) => k !== "__args" && v !== false && v !== void 0).map(([k, v]) => typeof v === "object" ? `${k}${toGraphql(v)}` : k).join(" ");
163
+ const validArgs = jsonQuery.__args ? entries(jsonQuery.__args).filter(([_, v]) => v !== void 0) : [];
164
+ const argsQuery = validArgs.length ? `(${validArgs.map(([k, v]) => `${k}:${v.substr(VAR_PREFIX_LENGTH)}`).join(",")})` : "";
165
+ return `${argsQuery} ${fields ? `{ ${fields} }` : ""}`;
166
+ }
167
+
168
+ // src/logging.ts
169
+ function logRequest(logInfo) {
170
+ let identifier = `%c#graphql-ts-client ${logInfo.kind} ${logInfo.queryName}`;
171
+ let identifierStyles = "color: transparent; font-size: 0px";
172
+ console.groupCollapsed(
173
+ `%c#graphql-ts-client %c${logInfo.kind} %c${logInfo.queryName} %c(${logInfo.duration.toFixed(2)}ms)`,
174
+ "color: #f90",
175
+ "color: #999",
176
+ `color: ${logInfo.response ? "unset" : "#f00"}; font-weight: bold`,
177
+ "color: #999"
178
+ );
179
+ console.groupCollapsed(`%cQuery ${identifier}`, "color: #999", identifierStyles);
180
+ console.log(logInfo.formatGraphQL(logInfo.query) + identifier, identifierStyles);
181
+ console.groupEnd();
182
+ console.groupCollapsed(`%cVariables ${identifier}`, "color: #999", identifierStyles);
183
+ console.log(JSON.stringify(logInfo.variables, null, " ") + identifier, identifierStyles);
184
+ console.groupEnd();
185
+ console.groupCollapsed(`%cTrace ${identifier}`, "color: #999", identifierStyles);
186
+ console.trace(identifier, identifierStyles);
187
+ console.groupEnd();
188
+ if (logInfo.response) {
189
+ console.log("%cResponse".padEnd(15, " ") + identifier, "color: #999", identifierStyles, logInfo.response);
190
+ }
191
+ if (logInfo.error) {
192
+ console.log("%cError".padEnd(15, " ") + identifier, "color: #999", identifierStyles, logInfo.error);
193
+ }
194
+ console.groupEnd();
195
+ }
196
+
197
+ // src/endpoint.ts
198
+ var executeListeners = (listeners, data) => setTimeout(() => listeners.forEach((runResponseListener) => runResponseListener(data)));
199
+ var getApiEndpointCreator = (apiConfig) => (kind, queryName) => {
200
+ const rawEndpoint = async (failureMode, jsonQuery) => {
201
+ const clientConfig = apiConfig.getClient();
202
+ const alias = jsonQuery?.__alias ?? queryName;
203
+ const url = jsonQuery?.__url ?? clientConfig.url;
204
+ const shouldRetry = jsonQuery?.__retry ?? true;
205
+ const requestHeaders = jsonQuery?.__headers ?? {};
206
+ const { query, variables } = jsonToGraphQLQuery({ kind, queryName, jsonQuery, typesTree: apiConfig.typesTree });
207
+ const start = +new Date();
208
+ const logOptions = {
209
+ kind,
210
+ queryName: alias,
211
+ formatGraphQL: apiConfig.formatGraphQL,
212
+ requestHeaders,
213
+ query,
214
+ variables
215
+ };
216
+ const responseListenerData = {
217
+ queryName: alias,
218
+ query: apiConfig.formatGraphQL(query),
219
+ variables
220
+ };
221
+ try {
222
+ const { data, errors, warnings, headers, status } = await graphqlRequest({
223
+ shouldRetry,
224
+ failureMode,
225
+ queryName: alias,
226
+ client: { ...clientConfig, url },
227
+ requestHeaders,
228
+ query,
229
+ variables,
230
+ errorsParser: apiConfig.errorsParser
231
+ });
232
+ const response = { data, warnings, headers, status, errors };
233
+ if (apiConfig.verbose && globalThis.document) {
234
+ logRequest({
235
+ ...logOptions,
236
+ response,
237
+ duration: +new Date() - start
238
+ });
239
+ }
240
+ executeListeners(apiConfig.responseListeners, {
241
+ ...responseListenerData,
242
+ response
243
+ });
244
+ return { data: data?.[alias], errors, warnings, headers, status };
245
+ } catch (error) {
246
+ if (apiConfig.verbose && globalThis.document) {
247
+ logRequest({
248
+ ...logOptions,
249
+ error,
250
+ duration: +new Date() - start
251
+ });
252
+ }
253
+ executeListeners(apiConfig.responseListeners, {
254
+ ...responseListenerData,
255
+ response: error.response
256
+ });
257
+ throw error;
258
+ }
259
+ };
260
+ const endpoint = async (jsonQuery) => {
261
+ const { data } = await rawEndpoint("loud", jsonQuery);
262
+ return data;
263
+ };
264
+ const memoizeeOptions = {
265
+ maxAge: apiConfig.maxAge,
266
+ isSerialized: true
267
+ };
268
+ endpoint.raw = rawEndpoint.bind(null, "silent");
269
+ endpoint.memo = memoize(endpoint, memoizeeOptions);
270
+ endpoint.memoRaw = memoize(endpoint.raw, memoizeeOptions);
271
+ return endpoint;
272
+ };
273
+ export {
274
+ getApiEndpointCreator
275
+ };
package/dist/index.d.ts CHANGED
@@ -1,24 +1,21 @@
1
1
  import { PathLike } from 'fs';
2
- export { C as ClientConfig, c as DeepReplace, D as Defined, E as Endpoint, G as GraphQLClientError, I as IResponseListener, J as JsonOutput, L as LogInfo, M as Maybe, P as Projection, d as RawEndpoint, b as Replacement, R as ResponseData, a as ResponseListenerInfo, U as Unpacked } from './types-85e628f6.js';
2
+ import { T as TypescriptClientOutput } from './types-23d2d6aa.js';
3
+ export { C as ClientConfig, c as DeepReplace, D as Defined, E as Endpoint, G as GraphQLClientError, I as IResponseListener, J as JsonOutput, L as LogInfo, M as Maybe, P as Projection, d as RawEndpoint, b as Replacement, R as ResponseData, a as ResponseListenerInfo, T as TypescriptClientOutput, U as Unpacked } from './types-23d2d6aa.js';
3
4
 
4
- type IClientOptions = {
5
- output?: PathLike;
6
- clientName?: string;
7
- headers?: {
8
- [key: string]: string;
9
- };
10
- introspectionEndpoint?: string;
11
- endpoint: string;
12
- verbose?: boolean;
13
- formatGraphQL?: boolean;
14
- skipCache?: boolean;
15
- errorsParser?: (errors: any[]) => any;
16
- };
17
- type Client = {
18
- typings: string;
19
- js: string;
20
- };
21
- declare function generateTypescriptClient({ introspectionEndpoint, ...options }: IClientOptions): Promise<Client>;
22
- declare function generateTypescriptClientFromSDL(SDL: string, options: IClientOptions): Client;
5
+ type IClientOptions = {
6
+ output?: PathLike;
7
+ clientName?: string;
8
+ headers?: {
9
+ [key: string]: string;
10
+ };
11
+ introspectionEndpoint?: string;
12
+ endpoint: string;
13
+ verbose?: boolean;
14
+ formatGraphQL?: boolean;
15
+ skipCache?: boolean;
16
+ errorsParser?: (errors: any[]) => any;
17
+ };
18
+ declare function generateTypescriptClient({ introspectionEndpoint, ...options }: IClientOptions): Promise<TypescriptClientOutput>;
19
+ declare function generateTypescriptClientFromSDL(SDL: string, options: IClientOptions): TypescriptClientOutput;
23
20
 
24
21
  export { generateTypescriptClient, generateTypescriptClientFromSDL };
package/dist/index.js CHANGED
@@ -487,58 +487,45 @@ var prettier = __toESM(require("prettier"));
487
487
  // package.json
488
488
  var package_default = {
489
489
  name: "@avantstay/graphql-ts-client",
490
- version: "10.8.0",
490
+ version: "10.9.0",
491
491
  description: "GraphQL Typescript Client Generator",
492
- author: "Wellington Guimaraes",
493
- license: "MIT",
494
- main: "dist/index.js",
495
- typings: "dist/index.d.ts",
496
- scripts: {
497
- build: "tsup src/index.ts src/endpoint.ts --dts",
498
- test: "cross-env GQL_CLIENT_DIST_PATH='.' jest --watch",
499
- prepublishOnly: "yarn build"
500
- },
501
- files: [
502
- "dist",
503
- "src"
504
- ],
505
- engines: {
506
- node: ">=12"
507
- },
492
+ homepage: "https://github.com/avantstay/graphql-ts-client",
508
493
  bugs: {
509
494
  url: "https://github.com/avantstay/graphql-ts-client/issues"
510
495
  },
511
- homepage: "https://github.com/avantstay/graphql-ts-client#readme",
512
496
  repository: {
513
497
  type: "git",
514
498
  url: "git+https://github.com/avantstay/graphql-ts-client.git"
515
499
  },
516
- peerDependencies: {},
517
- prettier: {
518
- trailingComma: "es5",
519
- tabWidth: 2,
520
- proseWrap: "always",
521
- bracketSpacing: true,
522
- jsxBracketSameLine: false,
523
- semi: false,
524
- singleQuote: true,
525
- arrowParens: "avoid",
526
- endOfLine: "lf",
527
- printWidth: 130,
528
- htmlWhitespaceSensitivity: "ignore",
529
- jsxSingleQuote: false
530
- },
531
- module: "dist/graphql-ts-client.esm.js",
532
- "size-limit": [
533
- {
534
- path: "dist/graphql-ts-client.cjs.production.min.js",
535
- limit: "10 KB"
500
+ license: "MIT",
501
+ author: "Wellington Guimaraes",
502
+ contributors: [
503
+ "Felipe Pinheiro <felipe.pinheiro.90@hotmail.com>"
504
+ ],
505
+ exports: {
506
+ ".": {
507
+ import: "./dist/index.mjs",
508
+ require: "./dist/index.js",
509
+ types: "./dist/index.d.ts"
536
510
  },
537
- {
538
- path: "dist/graphql-ts-client.esm.js",
539
- limit: "10 KB"
511
+ "./dist/endpoint": {
512
+ import: "./dist/endpoint.mjs",
513
+ require: "./dist/endpoint.js",
514
+ types: "./dist/endpoint.d.ts"
540
515
  }
516
+ },
517
+ main: "dist/index.js",
518
+ module: "dist/index.mjs",
519
+ typings: "dist/index.d.ts",
520
+ files: [
521
+ "dist",
522
+ "src"
541
523
  ],
524
+ scripts: {
525
+ build: "tsup src/index.ts src/endpoint.ts --dts --format cjs,esm",
526
+ prepublishOnly: "yarn build",
527
+ test: "cross-env GQL_CLIENT_DIST_PATH='.' jest --watch"
528
+ },
542
529
  dependencies: {
543
530
  "@types/md5": "^2.3.2",
544
531
  axios: "^0.24.0",
@@ -574,9 +561,23 @@ var package_default = {
574
561
  tsup: "^6.5.0",
575
562
  typescript: "^4.9.4"
576
563
  },
564
+ peerDependencies: {},
565
+ engines: {
566
+ node: ">=12"
567
+ },
577
568
  publishConfig: {
578
569
  "@avantstay:registry": "https://registry.npmjs.org/"
579
- }
570
+ },
571
+ "size-limit": [
572
+ {
573
+ path: "dist/graphql-ts-client.cjs.production.min.js",
574
+ limit: "10 KB"
575
+ },
576
+ {
577
+ path: "dist/graphql-ts-client.esm.js",
578
+ limit: "10 KB"
579
+ }
580
+ ]
580
581
  };
581
582
  // src/generateTypescriptClient.ts
582
583
  var tempDir = fs.realpathSync(import_os.default.tmpdir());
@@ -683,8 +684,7 @@ function gqlEndpointToCode(kind, endpoint, codeOutputType) {
683
684
  var outputType = gqlTypeToTypescript(endpoint.type, {
684
685
  required: true
685
686
  });
686
- var wrappedOutputType = /^(string|number|boolean)$/.test(outputType) ? outputType : "DeepRequired<".concat(outputType, ">");
687
- return codeOutputType === "ts" ? "".concat(endpoint.name, ": Endpoint<").concat(inputType, ", ").concat(wrappedOutputType, ", AllEnums>") : "".concat(endpoint.name, ": apiEndpoint('").concat(kind, "', '").concat(endpoint.name, "')");
687
+ return codeOutputType === "ts" ? "".concat(endpoint.name, ": Endpoint<").concat(inputType, ", ").concat(outputType, ", AllEnums>") : "".concat(endpoint.name, ": apiEndpoint('").concat(kind, "', '").concat(endpoint.name, "')");
688
688
  }
689
689
  function gqlSchemaToCode(gqlType, param) {
690
690
  var _param_selection = param.selection, selection = _param_selection === void 0 ? false : _param_selection, outputType = param.outputType;
@@ -774,9 +774,12 @@ function generateClientCode(types, options) {
774
774
  var clientCacheFileName = "gql-ts-client__client__".concat(typesHash, "__").concat(package_default.version, ".json");
775
775
  var clientCacheFilePath = import_path.default.resolve(tempDir, clientCacheFileName);
776
776
  if (!options.skipCache && fs.existsSync(clientCacheFilePath)) {
777
- return JSON.parse(fs.readFileSync(clientCacheFilePath, {
777
+ var output2 = JSON.parse(fs.readFileSync(clientCacheFilePath, {
778
778
  encoding: "utf8"
779
779
  }));
780
+ if (output2.js && output2.mjs && output2.typings) {
781
+ return output2;
782
+ }
780
783
  }
781
784
  var queries = ((_types_find = types.find(function(it) {
782
785
  return it.name === "Query";
@@ -849,6 +852,10 @@ function generateClientCode(types, options) {
849
852
  format: "cjs",
850
853
  loader: "js"
851
854
  }).code,
855
+ mjs: esbuild.transformSync(jsCode, {
856
+ format: "esm",
857
+ loader: "js"
858
+ }).code,
852
859
  typings: prettier.format(typingsCode, {
853
860
  semi: false,
854
861
  parser: "typescript"
@@ -917,7 +924,7 @@ function generateClient(introspectionTypes, _param) {
917
924
  var output = _param.output, restOptions = _objectWithoutProperties(_param, [
918
925
  "output"
919
926
  ]);
920
- var _generateClientCode = generateClientCode(introspectionTypes, restOptions), js = _generateClientCode.js, typings = _generateClientCode.typings;
927
+ var _generateClientCode = generateClientCode(introspectionTypes, restOptions), js = _generateClientCode.js, mjs = _generateClientCode.mjs, typings = _generateClientCode.typings;
921
928
  if (output && typeof output === "string") {
922
929
  var outputDir = import_path.default.dirname(output);
923
930
  if (!fs.existsSync(outputDir)) {
@@ -931,9 +938,13 @@ function generateClient(introspectionTypes, _param) {
931
938
  fs.writeFileSync(output.replace(/(\.(ts|js))?$/, ".js"), js, {
932
939
  encoding: "utf8"
933
940
  });
941
+ fs.writeFileSync(output.replace(/(\.(ts|js))?$/, ".mjs"), mjs, {
942
+ encoding: "utf8"
943
+ });
934
944
  }
935
945
  return {
936
946
  js: js,
947
+ mjs: mjs,
937
948
  typings: typings
938
949
  };
939
950
  }