Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lift the restriction that -bs-package-name is mandatory for -bs-package-output #384

Merged
merged 23 commits into from Oct 28, 2022

Conversation

anmonteiro
Copy link
Member

Also:

  • add -bs-module-type to simplify generating JS files
  • add a test exercising the new flow

Copy link
Member

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

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

thanks!!

jscomp/main/melc_cli.ml Show resolved Hide resolved
jscomp/core/js_packages_info.ml Show resolved Hide resolved
let bs_module_type_sentinel = "MELANGE_INVALID_PACKAGE_OUTPUT"

let add_npm_module_system (packages_info : t) module_system =
let m = { module_system; path = bs_module_type_sentinel; suffix = Js } in
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there could be any issues later on due to the path being set to this sentinel value, I guess we rely here on the constraint where Dune private libs can't be consumed from public ones, right? Or what's the path used for?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bit unfortunate, but it's here because I want to support 2 workflows, and I don't wanna break the CLI interface just yet.

  1. the flow where you emit (possibly multiple) JS files next to the .cmj
  2. the flow where those (possibly multiple) package specs are generated one JS file at a time (implies CMJ generation with -bs-stop-after-cmj

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that, in the future, we can separate all these concerns into a better command line interface:

  1. "batch" mode gets (potentially multiple) -bs-package-output commonjs:./folder:.bs.js
  2. "separate compilation" mode gets -bs-path-inside-package folder -bs-stop-after-cmj and -bs-module-type es6 -o foo.mjs

Copy link
Member

@jchavarri jchavarri left a comment

Choose a reason for hiding this comment

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

A few more qs as i wrap my head around this 😬 thanks!

$TESTCASE_ROOT

$ cd output/app/
$ melc $BSPKG -bs-package-output commonjs:lol -nopervasives -I ../../lib ../../app/b.cmj -o b.js
Copy link
Member

Choose a reason for hiding this comment

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

lol is the path to the module inside the "group" or package, right? I understand this only matters if the modules inside app would be consumed somewhere else. But shouldn't it be app?

Copy link
Member

Choose a reason for hiding this comment

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

Actually, does the path in -bs-package-output matter at all when generating .js artifacts? I understand the "package paths" only matter for .cmj step.

Copy link
Member Author

Choose a reason for hiding this comment

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

this was an oversight. it should be -bs-module-type instead.

$ cd -
$TESTCASE_ROOT

$ cd app/
$ melc $PKG_NAME $DUMMY_SPECS -I ../lib b.ml -nopervasives -bs-stop-after-cmj
$ melc $PKG_NAME -bs-package-output commonjs:./app:.js -I ../lib b.ml -nopervasives -bs-stop-after-cmj
Copy link
Member

Choose a reason for hiding this comment

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

Is it required to pass the .js extension to the cmjs? On the other test set-package-name-in-js, I see it's been removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's required for "batch compilation", i.e. output .js at same time as .cmj.

But not for "separate compilation" mode.

jscomp/main/melc.ml Outdated Show resolved Hide resolved
@anmonteiro anmonteiro merged commit 2293d9a into main Oct 28, 2022
@anmonteiro anmonteiro deleted the anmonteiro/no-bs-package-name branch October 28, 2022 04:34
anmonteiro added a commit to anmonteiro/opam-repository that referenced this pull request Nov 6, 2022
CHANGES:

- [melange] Introduce 2 explicit modes of JavaScript compilation:
  - "Batch compilation": produces `.cmj` and `.js` files at the same time (this
    is the previous behavior -- using `--bs-package-output
    MODULE_SYSTEM:REL_PATH:JS_EXTENSION`)
  - "Separate emission": produces _only_ `.cmj` files with `--bs-stop-after-cmj
    --bs-package-output REL_PATH_ONLY`, and allows emitting JavaScript files
    separately, with `--bs-module-type MODULE_SYSTEM -o
    TARGET_FILE.JS_EXTENSION`
  ([melange-re/melange#384](melange-re/melange#384))
- [mel]: Fix `mel build --watch` exiting after the first change
  ([melange-re/melange#401](melange-re/melange#401))
- [melange]: Remove dependency on `reason`. Reason syntax users should install`
  reason` from their preferred package manager instead, and Melange / Dune will
  find it in `$PATH` ([melange-re/melange#409](melange-re/melange#409))
- [melange]: Remove dependency on `napkin` (the ReScript syntax parser). Users
  that depend on libraries written in ReScript syntax should install the `mel`
  package and Melange / Dune will find the `rescript_syntax` binary in `$PATH`
  ([melange-re/melange#411](melange-re/melange#411))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants