Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion codegenerator/cli/npm/envio/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ pnpm-lock.yaml
lib

# ReScript artifacts
*.bs.js
*.res.js
*.res.mjs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do we use mjs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to migrate to it in v3 when we start using ESM. I decided to add it beforehand.

4 changes: 2 additions & 2 deletions codegenerator/cli/npm/envio/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Some parts like Sury reexport are impossible to implement
// on the JS side, so we need to do it here

const envioGen = require("./src/Envio.bs.js");
const envioGen = require("./src/Envio.res.js");
Object.assign(exports, envioGen);

const Sury = require("rescript-schema");
Expand Down Expand Up @@ -30,7 +30,7 @@ exports.S = {
merge: Sury.merge,
optional: Sury.optional,
nullable: Sury.nullable,
bigDecimal: require("./src/bindings/BigDecimal.bs.js").schema,
bigDecimal: require("./src/bindings/BigDecimal.res.js").schema,
// Nullish type will change in "sury@10"
// nullish: Sury.nullish,
assertOrThrow: Sury.assertOrThrow,
Expand Down
15 changes: 13 additions & 2 deletions codegenerator/cli/npm/envio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
"rescript": "11.1.3",
"rescript-schema": "9.3.0",
"viem": "2.21.0",
"bignumber.js": "9.1.2"
}
"bignumber.js": "9.1.2",
"pino": "8.16.1",
"pino-pretty": "10.2.3"
},
"files": [
"local-bin.mjs",
"evm.schema.json",
"fuel.schema.json",
"rescript.json",
"index.d.ts",
"index.js",
"src"
]
}
7 changes: 4 additions & 3 deletions codegenerator/cli/npm/envio/package.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"rescript": "11.1.3",
"rescript-schema": "9.3.0",
"viem": "2.21.0",
"bignumber.js": "9.1.2"
"bignumber.js": "9.1.2",
"pino": "8.16.1",
"pino-pretty": "10.2.3"
},
"files": [
"bin.js",
Expand All @@ -44,7 +46,6 @@
"rescript.json",
"index.d.ts",
"index.js",
"src",
"!src/**/*.bs.js"
"src"
]
}
2 changes: 1 addition & 1 deletion codegenerator/cli/npm/envio/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"subdirs": true
}
],
"suffix": ".bs.js",
"suffix": ".res.js",
"package-specs": {
"module": "commonjs",
"in-source": true
Expand Down
2 changes: 1 addition & 1 deletion codegenerator/cli/npm/envio/src/bindings/BigDecimal.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
/* tslint:disable */

const BigDecimalJS = require('./BigDecimal.bs.js');
const BigDecimalJS = require('./BigDecimal.res.js');

import type {S_t as RescriptSchema_S_t} from 'rescript-schema/RescriptSchema.gen';

Expand Down
2 changes: 1 addition & 1 deletion codegenerator/cli/npm/envio/src/bindings/Ethers.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable */
/* tslint:disable */

const EthersJS = require('./Ethers.bs.js');
const EthersJS = require('./Ethers.res.js');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid manual edits in generated files
This file is auto-generated by genType. Instead of patching the require path here, update your genType template/config to emit .res.js imports so the change persists across regenerations.

🤖 Prompt for AI Agents
In codegenerator/cli/npm/envio/src/bindings/Ethers.gen.ts at line 6, the require
path is manually edited to './Ethers.res.js' in a generated file. Instead of
modifying this file directly, update the genType template or configuration to
output imports with the '.res.js' extension so that the change is preserved when
the file is regenerated.


import type {t as Address_t} from '../../src/Address.gen';

Expand Down
2 changes: 1 addition & 1 deletion codegenerator/cli/src/cli_args/init_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl Language {
// Logic to get the event handler directory based on the language
pub fn get_event_handler_directory(&self) -> String {
match self {
Language::ReScript => "./src/EventHandlers.bs.js".to_string(),
Language::ReScript => "./src/EventHandlers.res.js".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify no remaining BuckleScript suffix references

Ensure all instances of the old .bs.js suffix have been removed across the codebase:


🏁 Script executed:

#!/bin/bash
rg '\.bs\.js' -n

Length of output: 275


🏁 Script executed:

#!/bin/bash
rg '\.bs\.js' -n -A2 -B2 codegenerator/cli/templates/static/codegen/src/Index.bs.js

Length of output: 475


Fix remaining .bs.js suffix references in static codegen templates

The search for .bs.js found two hard-coded references in your codegen template that need updating:

• codegenerator/cli/templates/static/codegen/src/Index.bs.js
– Line 49: /ts-node\s+generated\/src\/Index\.bs\.js/g
– Line 55: /node\s+generated\/src\/Index\.bs\.js/g

Please update both patterns to use the new .res.js suffix, for example:

- newScript = newScript.replace(
-   /ts-node\s+generated\/src\/Index\.bs\.js/g,
+ newScript = newScript.replace(
+   /ts-node\s+generated\/src\/Index\.res\.js/g,

- newScript = newScript.replace(
-   /node\s+generated\/src\/Index\.bs\.js/g,
+ newScript = newScript.replace(
+   /node\s+generated\/src\/Index\.res\.js/g,

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In codegenerator/cli/src/cli_args/init_config.rs at line 343, update the
hard-coded file suffix from ".bs.js" to ".res.js" to remove any remaining
BuckleScript suffix references. Additionally, in the
codegenerator/cli/templates/static/codegen/src/Index.bs.js file, locate lines 49
and 55 where the regex patterns reference "Index.bs.js" and change these to
"Index.res.js" to ensure consistency with the new suffix convention.

Language::TypeScript => "src/EventHandlers.ts".to_string(),
Language::JavaScript => "./src/EventHandlers.js".to_string(),
}
Expand Down
4 changes: 1 addition & 3 deletions codegenerator/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ pub mod start {
}
let cmd = "npm";
let args = vec!["run", "start"];
let current_dir = &project_paths.project_root;

let exit = execute_command(cmd, args, current_dir).await?;
let exit = execute_command(cmd, args, &project_paths.generated).await?;

if !exit.success() {
return Err(anyhow!(
Expand Down
4 changes: 2 additions & 2 deletions codegenerator/cli/src/config_parsing/graph_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub struct BlockHandler {
// Logic to get the event handler directory based on the language
fn get_event_handler_directory(language: &Language) -> String {
match language {
Language::ReScript => "./src/EventHandlers.bs.js".to_string(),
Language::ReScript => "./src/EventHandlers.res.js".to_string(),
Language::TypeScript => "src/EventHandlers.ts".to_string(),
Language::JavaScript => "./src/EventHandlers.js".to_string(),
}
Expand Down Expand Up @@ -554,7 +554,7 @@ mod test {
let event_handler_directory_1 = super::get_event_handler_directory(&language_1);
let event_handler_directory_2 = super::get_event_handler_directory(&language_2);
let event_handler_directory_3 = super::get_event_handler_directory(&language_3);
assert_eq!(event_handler_directory_1, "./src/EventHandlers.bs.js");
assert_eq!(event_handler_directory_1, "./src/EventHandlers.res.js");
assert_eq!(event_handler_directory_2, "./src/EventHandlers.js");
assert_eq!(event_handler_directory_3, "src/EventHandlers.ts");
}
Expand Down
6 changes: 6 additions & 0 deletions codegenerator/cli/src/hbs_templating/codegen_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@ struct SelectedFieldTemplate {
pub struct ProjectTemplate {
project_name: String,
codegen_contracts: Vec<ContractTemplate>,
has_typescript: bool,
entities: Vec<EntityRecordTypeTemplate>,
gql_enums: Vec<GraphQlEnumTypeTemplate>,
chain_configs: Vec<NetworkConfigTemplate>,
Expand Down Expand Up @@ -1331,8 +1332,13 @@ impl ProjectTemplate {
// TODO: Remove schemas for aggreaged, since they are not used in runtime
let aggregated_field_selection = FieldSelection::aggregated_selection(cfg);

let has_typescript = codegen_contracts
.iter()
.any(|contract| contract.handler.relative_to_config.ends_with(".ts"));

Ok(ProjectTemplate {
project_name: cfg.name.clone(),
has_typescript,
codegen_contracts,
entities,
gql_enums,
Expand Down
2 changes: 1 addition & 1 deletion codegenerator/cli/src/project_paths/handler_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::PathBuf;
pub struct HandlerPathsTemplate {
absolute: String,
relative_to_generated_src: String,
relative_to_config: String,
pub relative_to_config: String,
relative_to_project_root: String,
}

Expand Down
14 changes: 8 additions & 6 deletions codegenerator/cli/templates/dynamic/codegen/package.json.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"build": "rescript",
"watch": "rescript -w",
"format": "rescript format -all",
"db-up": "node -e 'require(`./src/db/Migrations.bs.js`).runUpMigrations(true)'",
"db-down": "node -e 'require(`./src/db/Migrations.bs.js`).runDownMigrations(true)'",
"db-setup": "node -e 'require(`./src/db/Migrations.bs.js`).runUpMigrations(true, true)'",
"print-benchmark-summary": "node -e 'require(`./src/Benchmark.bs.js`).Summary.printSummary()'",
"start": "node src/Index.bs.js"
"db-up": "node -e 'require(`./src/db/Migrations.res.js`).runUpMigrations(true)'",
"db-down": "node -e 'require(`./src/db/Migrations.res.js`).runDownMigrations(true)'",
"db-setup": "node -e 'require(`./src/db/Migrations.res.js`).runUpMigrations(true, true)'",
"print-benchmark-summary": "node -e 'require(`./src/Benchmark.res.js`).Summary.printSummary()'",
"start": "{{#if has_typescript}}ts-{{/if}}node src/Index.res.js"
},
"keywords": [
"ReScript"
Expand All @@ -36,6 +36,9 @@
"@fuel-ts/address": "0.96.1",
"@envio-dev/hyperfuel-client": "1.2.2",
{{/if}}
{{#if has_typescript}}
"ts-node": "10.9.1",
{{/if}}
"@elastic/ecs-pino-format": "1.4.0",
"@rescript/react": "0.12.1",
"bignumber.js": "9.1.2",
Expand All @@ -48,7 +51,6 @@
"ink-spinner": "4.0.3",
"js-sdsl": "4.4.2",
"pino": "8.16.1",
"pino-pretty": "10.2.3",
"postgres": "3.4.1",
"prom-client": "15.0.0",
"react": "18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@
{{/if}}
"codegen": "envio codegen",
"dev": "{{#if is_rescript}}pnpm build && {{/if}}envio dev",
"test": "pnpm mocha",
{{#if is_rescript}}
"start": "pnpm build && node generated/src/Index.bs.js"
{{else}}
{{#if is_typescript}}
"start": "ts-node generated/src/Index.bs.js"
{{else}}
"start": "node generated/src/Index.bs.js"
{{/if}}
{{/if}}
"start": "{{#if is_rescript}}pnpm build && {{/if}}envio start",
"test": "pnpm mocha"
},
"devDependencies": {
{{#if is_rescript}}
Expand All @@ -37,7 +29,6 @@
"@types/mocha": "10.0.6",
"@types/node": "20.8.8",
"ts-mocha": "^10.0.0",
"ts-node": "10.9.1",
"typescript": "5.2.2",
"chai": "4.3.10",
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const {
{{#each imported_contracts as |contract|}}
{{contract.name.capitalized}}{{#unless @last}},{{/unless}}
{{/each}}
} = require("../generated/src/Handlers.bs.js");
} = require("../generated/src/Handlers.res.js");

{{#each imported_contracts as |contract|}}
{{#each contract.imported_events as |event|}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"jsx": {
"version": 4
},
"suffix": ".bs.js",
"bs-dependencies": ["generated", "envio"]
"suffix": ".res.js",
"bs-dependencies": ["generated", "envio", "rescript-schema"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ artifacts
cache
generated
logs
*.bs.js
*.bs.mjs
*.res.js
*.res.mjs
*.gen.ts
build
.env
4 changes: 2 additions & 2 deletions codegenerator/cli/templates/static/codegen/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
.bsb.lock
/node_modules/
/benchmarks/
*.bs.js
*.bs.mjs
*.res.js
*.res.mjs
logs/*
*BenchmarkCache.json
4 changes: 2 additions & 2 deletions codegenerator/cli/templates/static/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
This file serves as an entry point when referencing generated as a node module
*/

const handlers = require("./src/Handlers.bs");
const TestHelpers = require("./src/TestHelpers.bs");
const handlers = require("./src/Handlers.res.js");
const TestHelpers = require("./src/TestHelpers.res.js");
const BigDecimal = require("bignumber.js");

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion codegenerator/cli/templates/static/codegen/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"jsx": {
"version": 4
},
"suffix": ".bs.js",
"suffix": ".res.js",
"bs-dependencies": [
"rescript-envsafe",
"rescript-schema",
Expand Down
2 changes: 1 addition & 1 deletion codegenerator/cli/templates/static/codegen/src/Config.res
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ let codegenPersistence = Persistence.make(
~schema=Db.schema,
~aggregateEntities=Env.Hasura.aggregateEntities,
)->Promise.catch(err => {
Logging.errorWithExn(err, `EE803: Error tracking tables`)->Promise.resolve
Logging.errorWithExn(err->Internal.prettifyExn, `EE803: Error tracking tables`)->Promise.resolve
})
},
)
Expand Down
Loading