handsontable / hyperformula

HyperFormula is an open-source headless spreadsheet for business web apps. It comes with over 400 formulas, CRUD operations, undo-redo, clipboard support, and sorting.
https://hyperformula.handsontable.com/
GNU General Public License v3.0
1.88k stars 107 forks source link

[DO NOT MERGE!] Fix language files for Node+ESM #1377

Open sequba opened 4 months ago

sequba commented 4 months ago

Context

Breaking change

This will be a breaking change for devs that use Webpack 3 or Parcel. They need to adjust their config and/or update the bundler.

TODO

How did you test your changes?

Tested importing HF in scenarios:

Demo projects are available in the hyperformula-demos repo.

Tested by @budnix:

Vite ^5.1.4 - OK Parcel2 ^2.0.0 - Does not support "exports" so the language file has to be imported with /es/ or /commonjs/ prefixes; Webpack5 ^5.8.0 - OK Webpack4 ^4.42.0 - I getting an error. Seems the webpack has the problem with importing values from "chevrotain".

Types of changes

Related issues:

Fixes #1344

Checklist:

github-actions[bot] commented 4 months ago

Performance comparison of head (0cd4e056a5601c8aaae0c07a648de13332068897) vs base (e32e132ebcb2d51d5f5d9b4bfb1ae3d4c71a2aab)

                                     testName |   base |   head | change
------------------------------------------------------------------------
                                      Sheet A | 529.16 | 530.87 | +0.32%
                                      Sheet B | 171.97 |  170.4 | -0.91%
                                      Sheet T | 151.62 | 149.56 | -1.36%
                                Column ranges | 548.74 |  546.6 | -0.39%
Sheet A:  change value, add/remove row/column |  14.76 |  13.82 | -6.37%
 Sheet B: change value, add/remove row/column | 130.26 | 133.98 | +2.86%
                   Column ranges - add column | 157.07 | 153.52 | -2.26%
                Column ranges - without batch | 465.62 | 455.73 | -2.12%
                        Column ranges - batch |  121.1 | 119.48 | -1.34%
sequba commented 4 months ago
  • Webpack4 ^4.42.0 - I getting an error. Seems the webpack has the problem with importing values from "chevrotain".
// /node_modules/hyperformula/es/parser/FormulaParser.mjs
import { EmbeddedActionsParser, EMPTY_ALT, Lexer, tokenMatcher } from 'chevrotain';
// EmbeddedActionsParser, EMPTY_ALT and others are missing
ERROR in ./node_modules/hyperformula/es/parser/FormulaParser.mjs 689:125-137
Can't import the named export 'tokenMatcher' from non EcmaScript module (only default export is available)
 @ ./node_modules/hyperformula/es/parser/index.mjs
 @ ./node_modules/hyperformula/es/ArraySize.mjs
 @ ./node_modules/hyperformula/es/index.mjs
 @ ./src/index.js

ERROR in ./node_modules/hyperformula/es/parser/FormulaParser.mjs 708:29-41
Can't import the named export 'tokenMatcher' from non EcmaScript module (only default export is available)
 @ ./node_modules/hyperformula/es/parser/index.mjs
 @ ./node_modules/hyperformula/es/ArraySize.mjs
 @ ./node_modules/hyperformula/es/index.mjs
 @ ./src/index.js

I found out that webpack 4 does not support exports, and there seems to be no easy workaround for that. By tweaking the webpack configuration, I managed to make the project import HyperFormula correctly using the legacy paths. Working demo.

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.36%. Comparing base (e32e132) to head (0cd4e05).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/handsontable/hyperformula/pull/1377/graphs/tree.svg?width=650&height=150&src=pr&token=5k9ZQv8azO&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=handsontable)](https://app.codecov.io/gh/handsontable/hyperformula/pull/1377?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=handsontable) ```diff @@ Coverage Diff @@ ## develop #1377 +/- ## ======================================== Coverage 97.36% 97.36% ======================================== Files 169 169 Lines 14421 14421 Branches 3021 3021 ======================================== Hits 14041 14041 Misses 380 380 ```
magierg commented 3 months ago

I have retested all the demos available on https://github.com/handsontable/hyperformula-demos/tree/import-demos

image

plus the bundlers mentioned by @budnix getting the same results.

On top of the above I have tested:

sequba commented 2 months ago

TODO: verify it with the code example in issue https://github.com/handsontable/hyperformula/issues/1143

sequba commented 2 months ago

Svelte 3.5.4 + vite 4 - getting this error - might be user error - @sequba to investigate

It works correctly. The issue you reported was caused by running the setup code twice. I created a demo for svelte: https://github.com/handsontable/hyperformula-demos/tree/import-demos/import-demo-esm-svelte

Angular case is still to be verified.