Wakamai-Fondue / wakamai-fondue-engine

The engine that powers Wakamai Fondue
Apache License 2.0
46 stars 9 forks source link

Add lib-font dependency #38

Closed RoelN closed 3 years ago

RoelN commented 3 years ago

⚠️ This ~doesn't work yet~ didn't work at first.

Two problems I could identify:

  1. When installing:
    
    $ npm i
    npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
    npm WARN deprecated har-validator@5.1.5: this library is no longer supported
    npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
    npm WARN deprecated request-promise-native@1.0.9: request-promise-native has been deprecated because it extends the now deprecated request package, see https://github.com/request
    /request/issues/3142
    npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142

@wakamai-fondue/engine@1.0.0 prepare npm run --silent build

./index.js → lib/index.js... (!) Unresolved dependencies https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency lib-font (imported by index.js) created lib/index.js in 2s

added 901 packages, and audited 901 packages in 21s

44 packages are looking for funding run npm fund for details


2. Running tests fails
```bash
$ npm test

> @wakamai-fondue/engine@1.0.0 test
> jest

 FAIL  test/Fondue.test.js
  ● Test suite failed to run

    Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /Users/roel/code/WakamaiFondue/wakamai-fondue-engine/node_modules/lib-font/lib-font.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import "./src/utils/shim-fetch.js";
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 |
    > 2 | import { Font } from "lib-font";
        | ^
      3 | import Fondue from "./src/fondue/Fondue.js";
      4 |
      5 | export function fromPath(fontPath) {

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (index.js:2:1)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files |       0 |        0 |       0 |       0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.887 s
Ran all test suites.
npm ERR! code 1
npm ERR! path /Users/roel/code/WakamaiFondue/wakamai-fondue-engine
npm ERR! command failed
npm ERR! command sh -c jest

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/roel/.npm/_logs/2020-12-14T09_58_15_673Z-debug.log
pascalw commented 3 years ago

@RoelN things are working again. One remaining issue is the following: We can no longer import inflate and unbrotli from https://github.com/Pomax/lib-font/tree/master/lib, as these are not exported from the NPM package. I've included these modules from NPM now, but it seems treeshaking is less efficient this way as the bundle size grew from 2.9M to 3.6M (unminified). We could request Pomax to export these modules from lib-font, or vendor these in our own repo in third_party/. WDYT?

pascalw commented 3 years ago

@RoelN I replaced the NPM dependencies for brotli and pako with vendored, optimized builds. Bundle size is now back to normal.

  1. Unbrotli doesn't ship a browser-optimized build in their NPM package
  2. Treeshaking was not working when importing only deflate from pako NPM package