Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kubb/react

Package Overview
Dependencies
Maintainers
1
Versions
401
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kubb/react - npm Package Compare versions

Comparing version 0.0.0-canary-20241111180316 to 0.0.0-canary-20241112200135

src/hooks/useLifecycle.tsx

16

dist/index.d.ts

@@ -70,5 +70,9 @@ import * as KubbFile from '@kubb/fs/types';

logger?: Logger;
/**
* Set this to true to always see the result of the render in the console(line per render)
*/
debug?: boolean;
};
declare class ReactTemplate<Context extends RootContextProps = RootContextProps> {
type Context = Omit<RootContextProps, 'exit'>;
declare class ReactTemplate<TMeta extends Record<string, unknown> = Record<string, unknown>> {
#private;

@@ -87,2 +91,3 @@ constructor(options: ReactTemplateOptions);

unmount(error?: Error | number | null): void;
write(): Promise<KubbFile.ResolvedFile<object>[]>;
waitUntilExit(): Promise<RendererResult>;

@@ -323,2 +328,9 @@ }

export { App, Const, File, Function, FunctionParams, Text, Type, createFunctionParams, createRoot, createRoot as createRootServer, useApp, useFile };
/**
* `useLifecycle` will return some helpers to exit/restart the generation.
*/
declare function useLifecycle(): {
exit: (error?: Error) => void;
};
export { App, Const, File, Function, FunctionParams, Text, Type, createFunctionParams, createRoot, createRoot as createRootServer, useApp, useFile, useLifecycle };

98

dist/index.js

@@ -11,3 +11,3 @@ import process from 'node:process';

import * as factory from '@kubb/parser-ts/factory';
import autoBind from 'auto-bind';
import { FileManager, processFiles } from '@kubb/core';
import transformers, { createJSDocBlockText } from '@kubb/core/transformers';

@@ -41,12 +41,16 @@ import { orderBy } from 'natural-orderby';

function Root({ onError, onExit: onExit2, logger, meta, children }) {
return /* @__PURE__ */ jsx(
ErrorBoundary,
{
logger,
onError: (error) => {
onError(error);
},
children: /* @__PURE__ */ jsx(RootContext.Provider, { value: { meta, exit: onExit2 }, children })
}
);
try {
return /* @__PURE__ */ jsx(
ErrorBoundary,
{
logger,
onError: (error) => {
onError(error);
},
children: /* @__PURE__ */ jsx(RootContext.Provider, { value: { meta, exit: onExit2 }, children })
}
);
} catch (e) {
return null;
}
}

@@ -439,3 +443,2 @@ Root.Context = RootContext;

constructor(options) {
autoBind(this);
this.#options = options;

@@ -446,2 +449,3 @@ this.#rootNode = createNode("kubb-root");

this.#isUnmounted = false;
this.unmount.bind(this);
this.#lastRendererResult = {

@@ -453,2 +457,14 @@ exports: [],

};
const originalError = console.error;
console.error = (data) => {
if (typeof data === "string") {
if (data.match(/React will try to recreat/gi)) {
return;
}
if (data.match(/The above error occurred in the <KubbErrorBoundary/gi)) {
return;
}
}
originalError(data);
};
this.#container = KubbRenderer.createContainer(

@@ -471,3 +487,3 @@ this.#rootNode,

{ alwaysLast: false }
);
).bind(this);
KubbRenderer.injectIntoDevTools({

@@ -500,5 +516,9 @@ bundleType: 0,

if (this.#options.debug) {
console.log("Render", result.output);
console.log(result.output);
}
this.#options.stdout?.write(result.output);
if (this.#options.stdout) {
this.#options.stdout.clearLine(0);
this.#options.stdout.cursorTo(0);
this.#options.stdout.write(result.output);
}
this.#lastRendererResult = result;

@@ -516,3 +536,3 @@ };

render(node, context) {
const element = /* @__PURE__ */ jsx(Root, { logger: this.#options.logger, meta: context?.meta || {}, onExit: this.onExit, onError: this.onError, children: node });
const element = /* @__PURE__ */ jsx(Root, { logger: this.#options.logger, meta: context?.meta || {}, onExit: this.onExit.bind(this), onError: this.onError.bind(this), children: node });
KubbRenderer.updateContainer(element, this.#container, null, noop);

@@ -528,2 +548,5 @@ }

}
if (this.#options.debug) {
console.log("Unmount", error);
}
this.onRender();

@@ -533,14 +556,22 @@ this.unsubscribeExit();

KubbRenderer.updateContainer(null, this.#container, null, noop);
if (this.#options.stdout) {
this.#options.stdout.clearLine(0);
this.#options.stdout.cursorTo(0);
this.#options.stdout.write(`${this.#lastRendererResult.output}
`);
}
if (error instanceof Error) {
if (this.#options.debug) {
console.log("Unmount", error);
}
this.rejectExitPromise(error);
} else {
if (this.#options.debug) {
console.log("Unmount", error);
}
this.resolveExitPromise(this.#lastRendererResult);
return;
}
this.resolveExitPromise(this.#lastRendererResult);
}
async write() {
const fileManager = new FileManager();
await fileManager.add(...this.#lastRendererResult.files);
return processFiles({
root: process.cwd(),
files: fileManager.files
});
}
async waitUntilExit() {

@@ -667,4 +698,3 @@ this.#exitPromise ||= new Promise((resolve, reject) => {

/* @__PURE__ */ jsx("br", {}),
/* @__PURE__ */ jsx(Text, { children: "}" }),
/* @__PURE__ */ jsx("br", {})
/* @__PURE__ */ jsx(Text, { children: "}" })
] });

@@ -749,4 +779,3 @@ }

] }),
/* @__PURE__ */ jsx(Text, { children }),
/* @__PURE__ */ jsx("br", {})
/* @__PURE__ */ jsx(Text, { children })
] });

@@ -775,4 +804,3 @@ }

"as const"
] }),
/* @__PURE__ */ jsx("br", {})
] })
] });

@@ -795,3 +823,3 @@ }

if (!app) {
throw new Error("<App/> should be set");
throw new Error("<App /> should be set");
}

@@ -807,2 +835,8 @@ return {

}
function useLifecycle() {
const { exit } = useContext(Root.Context);
return {
exit
};
}
function order(items) {

@@ -963,4 +997,4 @@ return orderBy(

export { App, Const, File, Function, FunctionParams, Text, Type, createFunctionParams, createRoot, createRoot as createRootServer, useApp, useFile };
export { App, Const, File, Function, FunctionParams, Text, Type, createFunctionParams, createRoot, createRoot as createRootServer, useApp, useFile, useLifecycle };
//# sourceMappingURL=index.js.map
//# sourceMappingURL=index.js.map
{
"name": "@kubb/react",
"version": "0.0.0-canary-20241111180316",
"version": "0.0.0-canary-20241112200135",
"description": "Generator react",

@@ -72,3 +72,2 @@ "keywords": [

"dependencies": {
"auto-bind": "^5.0.1",
"execa": "^9.5.1",

@@ -81,5 +80,5 @@ "natural-orderby": "^4.0.0",

"ws": "8.15.0",
"@kubb/core": "0.0.0-canary-20241111180316",
"@kubb/fs": "0.0.0-canary-20241111180316",
"@kubb/parser-ts": "0.0.0-canary-20241111180316"
"@kubb/core": "0.0.0-canary-20241112200135",
"@kubb/fs": "0.0.0-canary-20241112200135",
"@kubb/parser-ts": "0.0.0-canary-20241112200135"
},

@@ -93,4 +92,4 @@ "devDependencies": {

"typescript": "^5.6.3",
"@kubb/config-ts": "0.0.0-canary-20241111180316",
"@kubb/config-tsup": "0.0.0-canary-20241111180316"
"@kubb/config-ts": "0.0.0-canary-20241112200135",
"@kubb/config-tsup": "0.0.0-canary-20241112200135"
},

@@ -97,0 +96,0 @@ "engines": {

@@ -25,3 +25,3 @@ import type { FileManager, Plugin, PluginFactoryOptions, PluginManager } from '@kubb/core'

if (!app) {
throw new Error('<App/> should be set')
throw new Error('<App /> should be set')
}

@@ -28,0 +28,0 @@

@@ -10,4 +10,5 @@ export { createRoot, createRoot as createRootServer } from './createRoot.ts'

export { useApp } from './hooks/useApp.ts'
export { useLifecycle } from './hooks/useLifecycle.tsx'
export { createFunctionParams, FunctionParams } from './utils/getFunctionParams.ts'
export { createContext, useContext } from 'react'

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc