* chore(deps): Bump chai from 4.3.10 to 5.1.1
Bumps [chai](https://github.com/chaijs/chai) from 4.3.10 to 5.1.1.
- [Release notes](https://github.com/chaijs/chai/releases)
- [Changelog](https://github.com/chaijs/chai/blob/main/History.md)
- [Commits](https://github.com/chaijs/chai/compare/v4.3.10...v5.1.1)
---
updated-dependencies:
- dependency-name: chai
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* fix(tests): Migrate all usage of chai to ESM (#8216)
* fix(tests): Migrate node tests from CJS to ESM
This allows us to import (rather than require) chai, fixing failures
caused by that package dropping suppport for CJS in chai v5.0.0.
* fix(tests): Have mocha tests directly import chai
Previously they relied on obtaining it from the global scope, but it's
better if imports are explicit.
* fix(tests): Remove broken load of chai as script
Chai v5.0.0 no longer supports being loaded as a script, so this did
nothing but emit an syntax error message on the console.
* fix(tests): Migrate browser tests from CJS to ESM
This allows us to import (rather than require) chai, fixing failures
caused by chai no longer supporting CJS.
* chore(tests): format
---------
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Christopher Allen <cpcallen+git@google.com>
* feat(build)!: Introduce ESM entrypoints for chunks
Introduce an "import" conditional export for each of the chunk
entrypoints (blockly/core, blockly/blocks, blockly/javascript
etc.), and point these at wrappers created by build_tasks.js
that import the corresponding <chunk>_compressed.js file and
export its named exports.
BREAKING CHANGE:
Importing Blockly via
import Blockly from 'blockly/core';
(and similarly for the other chunk entrypoints) has worked until
now because most build tools (including Webpack in particular)
fuilfil the request for the default export of a CJS module by
providing the module.exports object, rather than an
explicitly-named default export as they would for an ES module.
Since core/blockly.ts (the notional entrypoint for blockly/core)
does not provide a default export, the wrappers created by this
PR do not either.
Code of the above form will therefore break, and should be updated
to use a wildcard:
import * as Blockly from 'blockly/core';
* feat(build)!: Introduce main package ESM entrypoint
Introduce an "import" conditional export for the top-level
package entrypoint (blockly), and point it at a wrappers
created by build_tasks.js that imports the existing index.js
file.
BREAKING CHANGE:
Importing Blockly via
import Blockly from 'blockly';
has worked until now because most build tools (including Webpack
in particular) fuilfil the request for the default export of a
CJS module by providing the module.exports object, rather than an
explicitly-named default export as they would for an ES module.
Since core/blockly.ts does not provide a default export, the
wrapper created by this PR does not either.
Code of the above form will therefore break, and should be updated
to use a wildcard:
import * as Blockly from 'blockly';
* feat(build)!: Introduce ESM entrypoints for langfiles
Introduce an "import" conditional export for each of the
langfile entrypoints (msg/en, msg/fr, etc.),, and point them
at wrappers created by build_tasks.js that import the
existing <lang>.js file.
BREAKING CHANGE:
Importing languages via
import en from 'blockly/msg/en';
has worked until now because most build tools (including Webpack
in particular) fuilfil the request for the default export of a
CJS module by providing the module.exports object, rather than an
explicitly-named default export as they would for an ES module.
Code of the above form will therefore break, and should be updated
to use a wildcard:
import * as en from 'blockly/msg/en';
* fix(typings): Remove bogus .d.ts file.
For some reason we had a typings/msg/yue.d.ts that did not
correxpond to any msg/json/yue.json. Delete it.
* fix(typings): Remove bogus .d.ts files; add new languages
PR #3821 added .d.ts files for every file in msg/json/, but several
of these are internal utility files rather than translations, and
do not result in a langfile being output by create_messages.py
when building langfiles.
In the meantime we have added a few new languages that are being
published but which have (until now) not had the corresponding
type declarations.
* feat(build)!: Add exports section to package.json
Add an exports stanza to package.json, enumerating existing
entrypoints in a new format.
- The original main entrypoint, index.js, is removed since the
exports section can point directly at node.js or browser.js.
- No change made (yet) to other entrypoints (core, blocks,
generators); these will be dealt with in a subsequent PR.
- The msg/en entrypoint is included in the top-level package.json
as an example; entries for all other languages created as part
of the packageJSON package task.
BREAKING CHANGE: The introduction of an exports stanza means that
correctly-behaved tools (node.js, bundlers like webpack, etc.)
will only allow importing of the specified entrypoints. Here
is the full list of permitted entrypoints that can be imported
or required:
- blockly
- blockly/core
- blockly/blocks
- blockly/dart
- blockly/lua
- blockly/javascript
- blockly/php
- blockly/python
- blockly/msg/<lang>, for all supported language codes <lang>
(e.g blockly/msg/en, blockly/msg/fr, blockly/msg/de, etc.)
If you previously impored any other paths from the blockly package
you will need to update your imports. Here are the most common
paths that may have been used, and their correct replacements:
| If you previously imported: | Import instead: |
| -------------------------------- | -------------------------- |
| blockly/index.js | blockly |
| blockly/node.js | blockly |
| blockly/browser.js | blockly |
| blockly/blockly.min | This file should only be loaded as a <script>. |
| blockly/core.js | blockly/core |
| blockly/core-browser.js | blockly/core |
| blockly/blockly_compressed.js | blockly/core |
| blockly/blocks.js | blockly/blocks |
| blockly/blocks_compressed.js | blockly/blocks |
| blockly/dart.js | blockly/dart |
| blockly/dart_compressed.js | blockly/dart |
| blockly/lua.js | blockly/lua |
| blockly/lua_compressed.js | blockly/lua |
| blockly/javascript.js | blockly/javascript |
| blockly/javascript_compressed.js | blockly/javascript |
| blockly/php.js | blockly/php |
| blockly/php_compressed.js | blockly/php |
| blockly/python.js | blockly/python |
| blockly/python_compressed.js | blockly/python |
| blockly/msg/en.js | blockly/msg/en |
* fix(build): Use package-paths (blockly/*) in wrapper imports
Use 'blockly/core' instead of './core' when importing core into
other wrappers (and similarly for other entries in package.json
exports stanza), so that (e.g.) dist/javascript.js won't
import dist/core.js (the node.js version that loads jsdom) when
being loaded in a browser environment.
This fixes an issue where blockly attempts to load jsdom even
in browser environments because the browser stanza in
package.json, which caused attempts to load core.js to load
core-browser.js instead in browser environments, was removed
in a previous commit.
* refactor(build): Remove unnecessray wrappers
Remove pointless wrapper modules that no longer server any
purpose; use exports stanza in package.json to point directly to
compiled chunks where possible.
* refactor(build)!: Eliminate separate browser and node entrypoints
Combine scripts/package/browser/index.js (becomes dist/browser.js)
and scripts/package/node/index.js (becomes dist/node.js) into
a single environment-agnostic index.js.
BREAKING CHANGE: Historically, importing the main 'blockly' package
would import 'blockly/core', 'blockly/blocks', 'blockly/en' and
'blockly/javascript' - and additionally, in node.js, also import
'blockly/dart', 'blockly/lua', 'blockly/php' and 'blockly/python'.
Now the main 'blockly' package entrypoint never loads any of the
generator modules.
This change has been made because of changes to generator exports
made in blockly v9.0.0 that make necessary to always separately
import generator modules.
Note that this change does not affect loading the blockly package
via <script src="https://unpkg.com/blockly"; that continues to
load to blockly.min.js, which includes javascript_compressed.js
and (due to being loaded as a script) makes it available via
Blockly.JavaScript.
* refactor(build): Simplify core entrypoint wrapper for node.js
Move scripts/package/node/core.js to scripts/package/core-node.js,
and have it packaged as dist/core-node.js rather than dist/core.js
- without a UMD wrapper, since it will always be loaded as a CJS
module.
* chore(build): Remove disused packageCommonJS helper
* refactor(build): Use subpath pattern (wildcard) for msg/* exports
Use a subpath pattern (wildcard) for the msg/* entrypoints,
obviating the need for special handling in packageJSON.
* fix(tests): Fix node tests
run_node_test.js previously directly require()d the dist/blockly.js
and dist/javascript.js wrapper module, which no longer exist.
Change it to require('blockly-test') (and …blockly-test/javascript)
and create a symlink ./node_modules/blocky-test -> dist/ to satisfy
this.
* fix(build): Add types: and default: entries to exports['./core']
In the 'blockly/core' export:
- Replace the browser: entrypoint with a default: one.
- Add a types: entrypoint for core.
* fix: updated field_dropdown to properly infer its Field type with TS 5.3.3
* fix: removed undefined as an option as its not needed for the type fix
* fix: updated field_dropdown to allow |undefined class validation
* 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.