refactor(build): Remove closure-make-deps and closure-calculate-chunks (#7473)

* refactor(build): Don't use closure-calculate-chunks

  Rewrite the getChunkOptions function to not use
  closure-calculate-chunks, but instead just chunk the input files
  (more or less) by subdirectory: first chunk is core/, second is
  blocks/, etc.

  This does make a material change to blockly_compressed.js,
  because we end up feeding several empty modules that contain
  only typescript interface declarations and which tsc
  compiles to "export {};" in the input to Closure Compiler
  (closure-calculate-chunks is smart enough to notice that
  no other module depends on these), which results in ~1.7KiB of
  superflous

      var module$build$src$core$interfaces$i_ast_node_location_svg={};

  declarations.  This can be avoided by filtering such empty modules
  out but that has been left for a future commit.

  This adds the glob NPM package as a dev dependency, but gulp
  and several other existing dev dependencies already depend on
  it.

  Build time is sped up by about a factor of 3x, due to removal
  of the buildDeps step that was really slow:

  $ time npm run build

  before:
  real    0m24.410s
  user    0m16.010s
  sys     0m1.140s

  after:
  real    0m8.397s
  user    0m11.976s
  sys     0m0.694s

* chore(build): Remove buildDeps task

* refactor: Remove $build$src infix from munged paths

  Closure Compiler renames module globals so that they do not
  clash when multiple modules are bundled together.  It does so
  by adding a "$$module$build$src$path$to$module" suffix (with
  the module object istelf being named simply
  "$module$build$src$path$to$module").

  By changing the gulp.src base option to be build/src/ instead
  of ./ (referring to the repostiory root), Closure Compiler
  obligingly shortens all of these munged named by removing the
  "$build$src" infix, reducing the size of the compressed chunks
  by about 10%; blockly_compressed.js goes from 900595 to 816667
  bytes.

* chore(build): Compute module object munged name from entrypoint

  - Add modulePath to compute the munged name of the entrypoint
    module from the entrypoint module filename, and use this
    instead of hard-coded chunk.exports paths.
  - Be more careful about when we are using poxix vs. OS-specific
    paths, especially TSC_OUTPUT_PATH which is regularly passed
    to gulp.src, which is documented as taking only posix paths.
  - Rename one existing variable modulePath -> entryPath to try
    to avoid confusion with new modulePath function.
This commit is contained in:
Christopher Allen
2023-09-12 18:13:52 +02:00
committed by GitHub
parent 07fec204bf
commit e7030a18a6
3 changed files with 375 additions and 839 deletions

View File

@@ -76,14 +76,13 @@
"@wdio/selenium-standalone-service": "^8.0.2",
"async-done": "^2.0.0",
"chai": "^4.2.0",
"closure-calculate-chunks": "^3.0.2",
"concurrently": "^8.0.1",
"eslint": "^8.4.1",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-jsdoc": "^46.2.6",
"glob": "^10.3.4",
"google-closure-compiler": "^20230802.0.0",
"google-closure-deps": "^20230502.0.0",
"gulp": "^4.0.2",
"gulp-concat": "^2.6.1",
"gulp-gzip": "^1.4.2",