Skip to content

Commit

Permalink
Make ornode dev server reload when dependencies change
Browse files Browse the repository at this point in the history
Tried to solve the same problem for gui. Currently you have to re-save
the vite.config.ts file in order for dev server to rebuild with changed
dependencies. Had to add force flag and optimizeDeps.force: true to
vite.config.ts to make this work. This problem is bugging a lot of vite
users: vitejs/vite#8619 .

Also refactored clientToNodeTransformer to not depend on z.instanceof,
because it is not reliable...
  • Loading branch information
sim31 committed Jun 24, 2024
1 parent 1b32a0c commit 1eb8fa8
Show file tree
Hide file tree
Showing 15 changed files with 375 additions and 317 deletions.
4 changes: 2 additions & 2 deletions impl/orclient/src/orclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export interface Config {
export const defaultConfig: Config = {
propConfirms: 3,
otherConfirms: 3,
propSubmitRetries: 3,
propResubmitInterval: 2000
propSubmitRetries: 4,
propResubmitInterval: 3000
}

export interface PutProposalRes {
Expand Down
2 changes: 1 addition & 1 deletion impl/ordao/gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"dev": "vite --force",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
Expand Down
4 changes: 3 additions & 1 deletion impl/ordao/gui/src/global/orclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const ctxCfg: ConfigWithOrnode = {
ornode,
contractRunner: bp
}
export const ctx = ORContext.create(ctxCfg);
const ctx = ORContext.create<ConfigWithOrnode>(ctxCfg);

ctx.catch((reason) => {
console.error(`Failed creating orContext. Reason: ${JSON.stringify(reason)}`);
})

export const orclient = ctx.then((context) => {
console.debug("is a 2: ", context instanceof ORContext)
context.callTest();
const orclient = new ORClient(context);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).cli = orclient;
Expand Down
10 changes: 8 additions & 2 deletions impl/ordao/gui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import react from '@vitejs/plugin-react-swc'
export default defineConfig({
plugins: [react()],
optimizeDeps: {
esbuildOptions: { preserveSymlinks: true }
esbuildOptions: { preserveSymlinks: true },
force: true,
},
resolve: {
preserveSymlinks: true
preserveSymlinks: true,
},
server: {
watch: {
followSymlinks: true
}
}
})
2 changes: 1 addition & 1 deletion impl/ordao/sys/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"dev-gui": "node src/devGui.js",
"dev-ornode": "node src/devOrnode.js",
"dev-ornode-swagger-ui": "cd $npm_package_config_ornode && ORNODE_CFG_PATH=../ordao/sys/tmp/ornode-dev-cfg.json npm run swagger-ui",
"dev-servers": "npm run build-clean && concurrently --kill-others \"npm:dev-ornode\" \"npm:watch-*\" \"npm:dev-ornode-swagger-ui\" \"npm:dev-gui\"",
"dev-servers": "npm run build-clean && concurrently --kill-others \"npm:dev-ornode\" \"npm:dev-gui\" \"npm:watch-*\" \"npm:dev-ornode-swagger-ui\"",
"dev": "node src/dev.js"
},
"keywords": [],
Expand Down
14 changes: 13 additions & 1 deletion impl/ordao/sys/src/devOrnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,19 @@ async function main() {
};
jsonfile.writeFileSync("./tmp/ornode-dev-cfg.json", config);

shelljs.exec("cd $npm_package_config_ornode && ORNODE_CFG_PATH=../ordao/sys/tmp/ornode-dev-cfg.json npx nodemon dist/index.js");
// shelljs.exec("cd $npm_package_config_ornode && ORNODE_CFG_PATH=../ordao/sys/tmp/ornode-dev-cfg.json npx nodemon --watch node_modules/ortypes node_modules/ts-utils dist/index.js");
shelljs.exec(`cd $npm_package_config_ornode && \
ORNODE_CFG_PATH=../ordao/sys/tmp/ornode-dev-cfg.json \
\
npx nodemon \
--watch ../ortypes/dist \
--watch ../ts-utils/dist \
--watch ../respect1155/sc/dist \
--watch ../orec/dist/
--watch ./
\
dist/index.js`
);
}

main();
2 changes: 1 addition & 1 deletion impl/ordao/sys/src/testOrdao.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async function main() {

shelljs.exec("npm run test-deployment"); // Synchronous

const ornode = shelljs.exec("npm run ornode-dev > ./tmp/ornode-test.log", { async: true })
const ornode = shelljs.exec("npm run dev-ornode > ./tmp/ornode-test.log", { async: true })

shelljs.exec("npm run hh-test-ordao");

Expand Down
4 changes: 4 additions & 0 deletions impl/orec/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ export function propId(msg: Orec.MessageStruct) {
[msg.addr, msg.cdata, msg.memo]
);
}

export function testVersion() {
console.debug("orec: 10");
}
2 changes: 1 addition & 1 deletion impl/ornode/run-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

npx tsc --watch &
sleep 5
npx nodemon dist/index.js
npx nodemon --watch node_modules/ortypes node_modules/ts-utils dist/index.js

# TODO: run hardhat node as well...

Expand Down
2 changes: 1 addition & 1 deletion impl/ornode/src/memOrnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export class MemOrnode implements IORNode {

// TODO:
async getPeriodNum(): Promise<number> {
this._ctx.callTest();
return this._periodNum;

}

}
2 changes: 2 additions & 0 deletions impl/ornode/src/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { config } from "./config.js";
import { zORNodePropStatus, zProposal, zProposalFull } from "ortypes/ornode.js";
import { zPropId } from "ortypes";
import { resultHandler } from "./resultHandler.js";
import { testStr } from "ortypes/orContext.js";

const ornode = MemOrnode.create({
newRespect: config.contracts.newRespect,
Expand Down Expand Up @@ -40,6 +41,7 @@ const getPeriodNum = factory.build({
output: z.object({ periodNum: z.number() }),
handler: async ({ input, options, logger }) => {
logger.debug(`getPeriodNumber ${JSON.stringify(input)}. options: ${JSON.stringify(options)}`);
logger.debug("Test str: ", testStr);
const n = await getOrnode();
const periodNum = await n.getPeriodNum();
return { periodNum };
Expand Down
34 changes: 26 additions & 8 deletions impl/ortypes/src/orContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { OnchainProp, PropId, zProposalState, zStage, zVoteStatus } from "./orec
import { InvalidArgumentError, Url, zUrl } from "./common.js";
import { Required } from "utility-types";
import { expect } from "chai";
import { testVersion } from "orec/utils";

export interface State {
orec: Orec,
Expand All @@ -17,7 +18,10 @@ export interface State {
ornode?: IORNode
}

export type StateWithOrnode = Required<State, 'ornode'>
// export type StateWithOrnode = Required<State, 'ornode'>
export interface StateWithOrnode extends State {
ornode: IORNode;
}

export interface Config {
orec: EthAddress | Orec,
Expand All @@ -26,7 +30,11 @@ export interface Config {
contractRunner?: ContractRunner | Url
}

export type ConfigWithOrnode = Required<Config, 'ornode'>;
export interface ConfigWithOrnode extends Config {
ornode: IORNode
}

// export type ConfigWithOrnode = Required<Config, 'ornode'>;

export type StateForConfig<CT extends Config> =
CT extends ConfigWithOrnode ? StateWithOrnode : State;
Expand Down Expand Up @@ -84,13 +92,13 @@ export class ORContext<CT extends Config> {
}
}
if (!runner) {
throw new InvalidArgumentError("Could not determine provider");
throw new InvalidArgumentError("Could not determine contract runner");
}

return runner;
}

static async create<CT extends Config>(config: CT): Promise<ORContext<CT>> {
static async create<CT_ extends Config>(config: CT_): Promise<ORContext<CT_>> {
const runner = this._determineRunner(config);

const network = await runner.provider?.getNetwork();
Expand All @@ -108,19 +116,25 @@ export class ORContext<CT extends Config> {
console.debug("oldRespectAddr: ", oldRespAddr);
const oldRespect = FractalRespectFactory.connect(oldRespAddr, runner);

const st: State = {
const st = {
orec, newRespect, oldRespect,
ornode: config.ornode
ornode: config.ornode as CT_['ornode'],
};

const ctx = new ORContext(st, false);
const ctx = new ORContext<CT_>(st as any, false);
ctx._oldRespectAddr = oldRespAddr;

await ctx.validate();

console.debug("This is new 4");

return ctx;
}

callTest() {
testVersion();
}

switchSigner(signer: Signer) {
this._st.orec = this._st.orec.connect(signer);
}
Expand Down Expand Up @@ -183,4 +197,8 @@ export class ORContext<CT extends Config> {

return r;
}
}
}

export const zORContext = z.instanceof(ORContext);

export const testStr = "aaaa 2!";
Loading

0 comments on commit 1eb8fa8

Please sign in to comment.