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

Update Dependencies & move to full ES Modules #432

Merged
merged 33 commits into from
Dec 13, 2021

Conversation

Booksbaum
Copy link
Contributor

  • Use dotnet sdk 6.0.100 (from 3.1.404)
    • to new? is LTS (unlike 5), but was released not too long ago
  • Update .Net dependencies
    • new Fable works better with ES Modules -> move project to ES Module (see somewhere below)
  • Move projects to net5.0
    • net6.0 isn't supported by FAKE yet. But shouldn't make really a different -- after all we are compiling to JS with Fable
  • Update JS dependencies
    • Move packages used in test-compiles to test-compiles/package.json (otherwise: dependency resolution issues)
      • are VERY outdated. But they are used in tests, and a lot are even removed from F# compilation again because of failures. And most are probably not used any more -> need cleanup and update (not in this PR)
    • Use (Dart) sass instead of node-sass
      • node-sass is deprecated, and only maintained to "work". It breaks with every new node version until an update. Additional doesn't yet work with just VS 2022 installed. Dart sass doesn't rely on external tools -> Works better with new node versions.
    • Use @monaco-react/react instead of react-monaco-editor
      • react-monaco-editor doesn't work with new monaco version, while @monaco-react/react does. Additional react-monaco-editor removed support for a custom loader (to load monaco from ./libs/vs/...)
    • Remove several unused packages
    • typescript still (very) old version: errors with new versions (even with newer 3.X) -> requires more rework (not in this PR)
  • Use ES Module
    • -> type=module in package.json
    • ESM in ./build/ and ./dist
      • running cli & tests don't need --require esm any more
      • Includes published npm package ts2fable
      • needs current_ish node version (all current LTS versions are supported)
    • WebApp not ESM (not that well supported by webpack (yet))
  • Update appveyor.yml to use matching dotnet and new node

Update paket & fake
Note: There are some changes in `3.4` which result in an error:
```
[...]\ts2fable\build\test\functionTests.js:1
Error [ERR_REQUIRE_ESM]: require() of ES Module [...]\ts2fable\build\test\fable_modules\fable-library.3.4.0\Util.js not supported.
Instead change the require of Util.js in null to a dynamic import() which is available in all CommonJS modules.
```
-> not yet updated to `3.4.x`
Because of dependency conflicts:
Move packages used to test ts2fable to their own `package.json` in `./test-modules/`. These are only packages that are used in unit tests or test compile as input for ts2fable. Packages used inside ts2fable, test and web-app are still in `package.json` in the root folder.

Note: root `package.json` isn't cleaned up yet. Only `ReactXP` was removed because of conflicts.

**Note**: `node-sass` currently doesn't work with `Node 17`
New Fable version doesn't work without `"type"="module"` in package.json (or transforming the generated code).
-> Update all code to use ES Modules instead of commonjs & `--require esm`.
But this doesn't work with too old node versions (requires `^12.20.0 || ^14.13.1 || >=16.0.0`).

Notes:
* Published Program (`./dist/ts2fable.js`, with `dotnet fake --target Cli.BuildRelease`) uses ES Modules too!
  Though it can be transformed so it works without ES Modules (`--format UMD`, like it was before). It would require a `package.json` without `type=module`. Which means: either custom `package.json` in `./dist/` or removing `type=module` from `package.json` in `build-update.package.js` (`dotnet fake --target Cli.Publish`). But this would complicate testing while development because it now doesn't work with `type=module`.
  -> Easiest to publish program in ESM format.
* web-app isn't updated yet!
* `--require esm` isn't necessary any more (and in fact erroneous)
* typescript MUST be imported with `import ts from "typescript"` instead of `import * as ts from "typescript"`
  Reason: (source: [node docs](https://nodejs.org/api/esm.html#import-statements))
  > When importing CommonJS modules, the module.exports object is provided as the default export.

  -> `import * as ts from ...` -> api is available via `ts.default`, but with `import ts from ...` it can be directly used with just `ts`
* `__dirname` [isn't supported any more in ESM](https://nodejs.org/dist/latest-v17.x/docs/api/all.html#esm_no-__filename-or-__dirname)
* [`require`](https://nodejs.org/dist/latest-v17.x/docs/api/all.html#esm_no-require-exports-or-moduleexports) cannot (easily) be used to load json.
* Because of `"type"="module"`: cannot use `require`, but instead `import`
`Shell.copyDir` copies files recursively
Note: `web-app` still doesn't run -- this just updates webpack
But still issue: Editor function don't work (like highlighting;
tranforming to F# works)
Note: dev build doesn't work:
`module.hot` is not defined in ESM. Requires `import.meta.webpackHot`.
But several modules use `module.hot` -> error when running wep-app.
This is only an issue in dev build. Production build removes
`module.hot` -> works
Empty `web-app/package.json`: override root `package.json` with
`type=module` -> use "default" with webpack

Note: Currently something is wrong with webpack processing:
* very slow (2x compared to current master)
* very large output: `ts.worker.js` is `4.7MB`, `vender.js` is `5.1MB`
Loader with `react-monaco-editor` didn't work any more.
`@monaco-react/react` works even with default settings (and without
requirejs)
-> for monaco only small parts are loaded and loaded `tsWorker.js` is
way smaller (`1MB`)

BUT: `ts.worker.js` is still published in `./output`. Why? Isn't loaded
runtime.

Additional: other bundles (`app` and especially `vendor` are still huge)
-> small files instead of HUGE bundle

Positive sideeffect: Remove `monaco-editor-webpack-plugin`. Was Reason
for very slow webpack builds

Remove requirejs

Move `Copy Monaco files` from Fake build script to webpack
Note: projects aren't moved to `net6.0`: not yet supported by FAKE
@Booksbaum Booksbaum merged commit 3a3f5aa into fable-compiler:master Dec 13, 2021
@Booksbaum Booksbaum deleted the update-deps-esm branch December 13, 2021 19:32
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.

1 participant