- Notifications
You must be signed in to change notification settings - Fork471
Proof of concept: one shot file compilation#8002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
pkg-pr-newbot commentedNov 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
rescript@rescript/darwin-arm64@rescript/darwin-x64@rescript/linux-arm64@rescript/linux-x64@rescript/runtime@rescript/win32-x64commit: |
Split bsc module system flags for stdout compilationProblemWhen (* compiler/core/lam_compile_main.ml:295 - old code*)ifJs_packages_info.is_empty package_info&&!Js_config.js_stdoutthenJs_dump_program.dump_deps_program~output_prefixCommonjs(* <- hardcoded!*) This meant stdout output was always Commonjs, regardless of project configuration. Since the new SolutionSplit Before (coupled): -bs-package-output esmodule:lib/es6:.mjs# Format: module_system:path:suffix (all three or none)After (decoupled): -bs-module-system esmodule# Controls import/export syntax-bs-suffix .mjs# Controls import path extensions-bs-package-output lib/es6# Output directory (optional) ImplementationNew compiler state ( let default_module_system=refExt_module_system.Commonjslet default_suffix=refLiterals.suffix_js New flags ( ("-bs-module-system", string_call set_module_system,"Set module system: commonjs, esmodule, es6-global");("-bs-suffix", string_call set_suffix,"Set import file suffix: .js, .mjs, .cjs"); Stdout output now uses configured values ( ifJs_packages_info.is_empty package_info&&!Js_config.js_stdoutthen(* Use configured module system instead of hardcoded Commonjs*)Js_dump_program.dump_deps_program~output_prefix!Js_config.default_module_system Import path generation uses configured suffix ( (* For Package_script mode (stdout), use configured suffix*)let js_file=Ext_namespace.js_name_of_modulename dep_module_id.id.name case!Js_config.default_suffix Critical exception: Runtime package imports ( (* Runtime package is pre-compiled and always uses .js suffix*)let js_file=Ext_namespace.js_name_of_modulename dep_module_id.id.nameUpperLiterals.suffix_js Build System UpdatesRewatch ( // Old format:"-bs-package-output","esmodule:lib/es6:.mjs"// New format:"-bs-module-system","esmodule","-bs-suffix",".mjs","-bs-package-output","lib/es6" Legacy bsb ( (* Old: single compound flag*)"-bs-package-output esmodule:lib/es6:.mjs"(* New: three separate flags*)"-bs-module-system esmodule -bs-suffix .mjs -bs-package-output lib/es6" Backward CompatibilityThe
This allows gradual migration, though since these are internal flags (users don't call Result
$ bsc -bs-module-system esmodule -bs-suffix .mjs file.ast// Generated by ReScript, PLEASE EDIT WITH CAREimport* as MyDep from"./MyDep.mjs";import* as Belt_Array from"@rescript/runtime/lib/es6/Belt_Array.js";export { ... } Notice:
This enables //cc@cristianoc ,@zth |
The previous implementation used a ninja variable $in_d which doesn't exist,causing files to be written to the wrong location. Now bsc extracts thesource subdirectory directly from the output_prefix parameter.For in-source builds with output_prefix='src/Node', files are written to: project_root / '.' / 'src' / 'Node.mjs'For out-of-source builds with output_prefix='src/Node', files go to: project_root / 'lib/es6' / 'src' / 'Node.mjs'This ensures source directory structure is preserved in the output.
bsb passes path='.' and expects source_subdir to be extracted from output_prefix.rewatch passes path=file_path.parent() which already contains the full directory.Now check if path is a base directory (., lib/es6, etc.) and only thenextract source_subdir from output_prefix. Otherwise use path as-is.
…ng -bs-package-output
…package-outputFor in-source builds, extract source subdirectories from output_prefix and .cmj file locations to generate correct relative import paths.
Hi@cristianoc , the splitting of the bsc arg turned out quite ugly. |
Use case: I want to compile a single ReScript file and run it immediately.
With this PR I could do
rescript compile-file MyFile.res | bun -and bun automatically runs it.(Would not be a stretch to create aBun plugin and just be able to run
bun run MyFile.resif plugin is configured)Going to keep this as draft until after v12.