refactor: getOwnPackage util (#409)
This commit is contained in:
parent
3156f9bc46
commit
b9df04b883
|
@ -8,7 +8,6 @@ import { completeValue, plugin } from "../plugin";
|
||||||
import {
|
import {
|
||||||
ArgsValue,
|
ArgsValue,
|
||||||
GetGen,
|
GetGen,
|
||||||
getPackageNameForImport,
|
|
||||||
MaybePromise,
|
MaybePromise,
|
||||||
MaybePromiseDeep,
|
MaybePromiseDeep,
|
||||||
ResultValue,
|
ResultValue,
|
||||||
|
@ -16,6 +15,7 @@ import {
|
||||||
} from "../typegenTypeHelpers";
|
} from "../typegenTypeHelpers";
|
||||||
import {
|
import {
|
||||||
eachObj,
|
eachObj,
|
||||||
|
getOwnPackage,
|
||||||
isObject,
|
isObject,
|
||||||
isPromiseLike,
|
isPromiseLike,
|
||||||
mapObj,
|
mapObj,
|
||||||
|
@ -340,7 +340,7 @@ export const connectionPlugin = (
|
||||||
name: "ConnectionPlugin",
|
name: "ConnectionPlugin",
|
||||||
fieldDefTypes: [
|
fieldDefTypes: [
|
||||||
printedGenTypingImport({
|
printedGenTypingImport({
|
||||||
module: getPackageNameForImport(),
|
module: getOwnPackage().name,
|
||||||
bindings: ["core", "connectionPluginCore"],
|
bindings: ["core", "connectionPluginCore"],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
@ -29,9 +29,9 @@ import {
|
||||||
} from "./definitions/wrapping";
|
} from "./definitions/wrapping";
|
||||||
import { NexusGraphQLSchema } from "./definitions/_types";
|
import { NexusGraphQLSchema } from "./definitions/_types";
|
||||||
import { StringLike } from "./plugin";
|
import { StringLike } from "./plugin";
|
||||||
import { getPackageNameForImport } from "./typegenTypeHelpers";
|
|
||||||
import {
|
import {
|
||||||
eachObj,
|
eachObj,
|
||||||
|
getOwnPackage,
|
||||||
GroupedTypes,
|
GroupedTypes,
|
||||||
groupTypes,
|
groupTypes,
|
||||||
mapObj,
|
mapObj,
|
||||||
|
@ -155,7 +155,7 @@ export class TypegenPrinter {
|
||||||
const outputPath = this.typegenInfo.typegenFile;
|
const outputPath = this.typegenInfo.typegenFile;
|
||||||
// For backward compat.
|
// For backward compat.
|
||||||
|
|
||||||
const packName = getPackageNameForImport();
|
const packName = getOwnPackage().name;
|
||||||
if (!this.printImports[packName]) {
|
if (!this.printImports[packName]) {
|
||||||
if (
|
if (
|
||||||
[dynamicInputFields, dynamicOutputFields].some(
|
[dynamicInputFields, dynamicOutputFields].some(
|
||||||
|
|
|
@ -1,17 +1,5 @@
|
||||||
import { GraphQLResolveInfo } from "graphql";
|
import { GraphQLResolveInfo } from "graphql";
|
||||||
|
|
||||||
export function getPackageNameForImport(): string {
|
|
||||||
try {
|
|
||||||
return require("../package.json").name;
|
|
||||||
} catch (e) {
|
|
||||||
console.error(
|
|
||||||
'Failed to get name from package manifest for typegen. Falling back to hardcoded "@nexus/schema". Error was:\n\n'
|
|
||||||
);
|
|
||||||
console.error(e);
|
|
||||||
return "@nexus/schema";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface NexusGen {}
|
interface NexusGen {}
|
||||||
interface NexusGenCustomInputMethods<TypeName extends string> {}
|
interface NexusGenCustomInputMethods<TypeName extends string> {}
|
||||||
|
|
|
@ -488,3 +488,7 @@ export function pathToArray(
|
||||||
}
|
}
|
||||||
return flattened.reverse();
|
return flattened.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getOwnPackage(): { name: string } {
|
||||||
|
return require("../package.json");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue