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