* refactor(generators): Move lang.js -> lang/lang_gernator.js
Move the LangGenerator definitions into their respective
subdirectories and add a _generator suffix to their filenames,
i.e. generators/javascript.js becomes
generators/javascript/javascript_generator.js.
This is to keep related code together and allow the `lang/all.js`
entrypoints to be moved to the top level generators/ directory.
No goog module IDs were changed, so playground and test code
that accesses this modules by filename does not need to be modified.
* refactor(generators) Move lang/all.js -> lang.js
- Move the entrypoints in generators/*/all.js to correspondingly-named
files in generators/ instead—i.e., generators/javascript/all.js
becomes generators/javascript.js.
- Update build_tasks.js accordingly.
* fix(generators): Add missing exports for LuaGenerator, PhpGenerator
These were inadvertently omitted from #7161 and #7162, respectively.
* refactor(generators): Make block generator modules side-effect free
- Move declaration of <lang>Generator instance from
generators/<lang>/<lang>_generator.js to generators/<lang>.js.
- Move .addReservedWords() calls from generators/<lang>/*.js to
generators/<lang>.js
- Modify generators/<lang>/*.js to export block generator functions
individually, rather than installing on <lang>Generator instance.
- Modify generators/<lang>.js to import and install block generator
functions on <lang>Generator instance.
* fix(tests): Fix tests broken by restructuring of generators
Where these tests needed block generator functions preinstalled
they should have been importing the Blockly.<Lang>.all module.
Where they do not need the provided block generator functions
they can now create their own empty <Lang>Generator instances.
* chore: Update renamings file
- Fix a malformation in previous entries that was not detected by
the renaming file validator test.
- Add entries describing the work done in this and related recent
PRs.
* fix: Correct minor errors in PR #7173
- Fix a search-and-replace error in renamings.json5
- Fix an incorrect-but-usable import in generator_test.js
* fix(build): Include node_modules/@blockly/ in gh-pages branch
- Add node_modules/@blockly to the list of files added to the gh-pages
branch.
- Add a _config.yml file telling Jekyll (which is needed to produce
the homepage served at https://google.github.io/blockly/, and hence
can't be disabled with a .nojekyll file instead) not to exclude
node_modules (which it does by default).
* refactor(build): Modernise git_tasks.js
- Various style updates:
- Use CONSTANT_CASE.
- Use /** JSDoc comments */
- Use `template ${literals}`.
- Use git switch instead of git checkout.
- Try to avoid use of remote names; use URLs where possible.
* refactor(build): Look up upstream git remote
Since git reset can't take a URL but needs an actual remote name,
use git branch -v to look up the remote for
github.com/google/blockly and then use that remote name.
* chores(build): format
Due to errors in PRs #7171 and 7173 (and the author's failure to do
enough local testing before submitting those PRs), compressed mode
loading was broken in the playgrounds. Fix this by:
- Fix a typo in bootstrap.js ("Blocky" -> "Blockly").
- Updating the chunks definitions build_tasks.js to use the new
variables we expect to contain generator exports objects.
* fix: input exports
* chore: fix build
* chore: attempt to fix build
* chore: attempt to fix build
* chore: create new align enum to replace old one
* chore: format
* fix: Tweak renamings entries
It appears that the goal is to map:
Blockly.Input.Align -> Blockly.inputs.Align
Blockly.Align -> Blockly.inputs.Align
Blockly.ALIGN_* -> Blockly.inputs.Align.*
I believe this commit achieves that in a more minimal (and correct)
way—but if I have misunderstood the intention then this will not
be a useful correction.
---------
Co-authored-by: Christopher Allen <cpcallen+git@google.com>
Refactor bootstrap.js and bootstrap_helper.js to be able to deal
with generator chunks. In particular for each chunk, specify:
- The goog.module ID to goog.require() in uncompressed mode.
- The script filename to load in compressed mode.
- Where the chunk's UMD wrapper will save the export object when
loaded as a script.
- What global variable the chunk's export object should be saved in
(if desired).
- Any individual named exports to destructure to global variables.
This allows the bootstrap scripts to be slightly simpler while
also being more flexible.
Previously, when loading a generator chunk (e.g.,
javascript_compressed.js) as a script (e.g., in a browser using
a <SCRIPT> tag), only a single named export from that chunk would
be made available (e.g, javascriptGenerator would be made availabe
as Blockly.JavaScript).
Until recently, that was fine because each generator chunk had only
a single named export, but now each one additionally has a
<Lang>Generator class and Order enum export.
To allow these new exports to be accessed by script users, the
chunk wrappers are modified to provide the whole export object
at a correspondingly-named global variable—e.g., when loaded as
a script javascript_compressed.js creates a global variable named
javascript, so the named exports can be accessed as
javascript.javascriptGenerator, javascript.JavascriptGenerator
and javascript.Order, as if the user had imported them via
import * as javascript from 'blockly/javascript';
This PR includes a breaking change and a deprecation, both of
which are only applicable when loading generators as scripts
(e.g. via a <SCRIPT> tag):
BREAKING CHANGE: The generator chunks will, when loaded as scripts
(e.g. via a <SCRIPT> tag, now clobber any existing global variable
of the corresponding name:
- dart_compresed.js will set dart
- javascript_compresed.js will set javascript
- lua_compresed.js will set lua
- php_compresed.js will set php
- python_compresed.js will set python
DEPRECATION: Accessing the generator instances at their previous
locations (Blockly.Dart, Blockly.JavaScript, Blockly.Lua,
Blockly.PHP, and Blockly.Python) is deprecated and may cease
to work in a future version of Blockly.
* feat(j2ts): Add support for migrating renaming imports
Convert
const {foo: bar} = require(/*...*/);
into
import {foo as bar} from /*...*/;
^^^^^^^^^^
Also fix a bug that caused relative paths to ESM in the same
directory to be missing a leading "./".
* fix(build): Fix trivial error exports for generators
The UMD wrapper was inadvertently exporting the contents of (e.g.)
the Blockly.JavaScript closure module rather than the intended
export of Blockly.JavaScript.all module - which went unnoticed
because the latter just reexported the former - but we are
about to convert the former to ESM.
* chore(generators): Migrate language generators to ESM
Migrate the main language generators in generators/*.js to ESM.
This was done by running js2ts on the files, renaming them back
to .js, and commenting out "import type" statements, which are
legal TS but not needed in JS (at least if you are not actually
letting Closure Compiler do type checking, which we are not.)
* chore(generators): Migrate block generators to ESM
Migrate generators/*/*.js (except all.js) to ESM.
This was done by running js2ts on the files, renaming them back
to .js, and removing now-spurious @suppress {extraRequire}
directives.
* chores(generators): Migrate generator chunk entrypoints to ESM
This was done by running js2ts on the files, renaming them back
to .js, and manually fixing the export statements.
An additional change to the chunk exports configuration in
build_tasks.js was necessary in order for the UMD wrapper to
find the new module object, which is given a different name
than the old exports object.
* chore(deps): Bump @hyperjump/json-schema from 0.23.3 to 1.5.0
Bumps [@hyperjump/json-schema](https://github.com/hyperjump-io/json-schema) from 0.23.3 to 1.5.0.
- [Commits](https://github.com/hyperjump-io/json-schema/compare/v0.23.3...v1.5.0)
---
updated-dependencies:
- dependency-name: "@hyperjump/json-schema"
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <support@github.com>
* chore(tests): Compatibility updates to validate-renamings.js
A minimal set of updates to validate-renamings.js to make it
compatible with @hyperjump/json-schema v1.5. The main difference
is that that package now ships ESM rather than CJS modules,
forcing the script to use import rather than require, with
various knock-on effects (no __dirname variable, must be named
*.mjs, etc.)
* chore(tests) Remove unneeded IIFE
* chore(tests): Additional tidy-up of ESM version
Now that validate-renamings is an ES module, we can do some other
cleanup to it.
---------
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>
Temporarily exclude the generated .d.ts files for blocks/* and
generators/* from the package.
This will in due course replace the (very simplistic) hand-written
versions in typings/, but for now they are not referenced
anywhere a developer's tooling should be looking, and contain
in some cases actually incorrect typings (e.g., in unmigrated
blocks files, the blocks export is typed as ObjectConstructor,
which is wrong), so do not include them in the package least they
cause problems for the unwary.
* Reduce usage of obsolete .keyCode property.
* Rename private properties/methods which violate eslint rules.
* Use arrays of bound events rather than individual properties.
* Improve typing info.
* Also fix O(n^2) recursive performance issue in theme's getComponentStyle function.
* And replace String(...) with '${...}' (smaller, faster).
* .toString() is considered harmful.
There are small typos in:
- closure/goog/base.js
- demos/minimap/minimap.js
- gulpfile.js
- scripts/gulpfiles/build_tasks.js
- scripts/gulpfiles/cleanup_tasks.js
- scripts/gulpfiles/license_tasks.js
Fixes:
- Should read `prerequisites` rather than `prequisites`.
- Should read `satisfies` rather than `satisifies`.
- Should read `regenerates` rather than `regenrates`.
- Should read `minimap` rather than `mimimap`.
- Should read `diagnostic` rather than `disagnostic`.
Signed-off-by: Tim Gates <tim.gates@iress.com>
* feat: added `tests/typescript` to test supported TS examples
* fix: update the test name, description, and output
* chore: remove unused imports in `test_tasks.js`
* fix: wrap README line at 80 characters
* fix: implemented `different_user_input.ts` feedback
* fix: correct mistaken comments
* chore: rename `./eslintrc.json` to `./eslintrc.js`
* feat: added linting for tests/typescript
* chore: cleanup eslintrc lines over 80 characters
* fix: updated `.eslintrc.js` to provide an override for linting itself
* fix: updated tests to build to the `build` directory
* feat: updated `gulp format` to handle formatting `.eslintrc.js`
* fix: updated `.eslintrc.js` to align with both formatter and linter
* fix: updated config comment wording
* fix: removed quotes for valid identifiers
* Revert "fix: removed quotes for valid identifiers"
This reverts commit 03eff91aea1468e503bc79a90fb139914d3f39d2.
* fix(tests): Fix errors in event tests
- Fix actual syntax errors in imports in event_marker_move_test.js
and event_selected.test.js, which were preventing those tests from
being run.
- Remove suite.only directives in those tests that would prevent
all the other tests from running.
* refactor(build): Improve buildDeps
- Run closure-make-deps only once, instead of separately for core/
and tests/.
- Specify a larger exec maxBuffer size, to ensure output and
diagnostics are not truncated.
- Change stderr filtering in buildDeps to filter out bounded
generics messages and blank lines.
- Attempt to suppress warnings in stderr output when
closure-make-deps returns a non-zero exit code.
Unfortunately, there seems to be a race condition which usually
the stderr argument to the exec callback not to contain the
complete output, so in that case print a helpful message.
- Have buildDeps just return a Promise instead of using a callback.
* fix(docs): Typo fix in JSDoc for log helper
* docs(icon): Better description for Icon.prototype.setVisible
Also tweak description of getBlock.
* docs(blocks): Fix typo in description of BlockDefinition
* chore(tests): Factor out common goog:chromeOptions
* chore(build): Minor style fixes
To make `npm install` and `npm ci` faster, and to avoid redundant
work when doing either of these followed by `npm run build` (or
any other script which does a build), delete the `prepare`
script and instead add an invocation of `npm run deps` to the
beginning of the `start` script.
Modify the prepareDemos script to copy the messages and compressed
files to their previous locations in the deploy directory, to
fix 404 errors on devsite that we can't immediately fix by pushing
devsite.
* Add tsick.js to rewrite enums.
tsc generates JavaScript which is incompatible with the Closure Compiler's advanced optimizations.
* Remove unused 'outputCode' variable.
* Rename 'run_X_in_browser.js' to 'webdriver.js'
The Mocha and generator tests can both be run either manually or via our webdriver. In all cases they run in a browser. These two 'run_X_in_browser.js' files only apply to webdriver, thus they are confusingly named.
Also delete completely unused (and broken) `run_all_tests.sh`
* Linting improvements to mocha/webdriver.js
Still not at 100%. Complains about require/module/process/__dirname not being defined in multiple places.
* runTestBlock -> runTestFunction
'Block' means something very different in Blockly.
* Removal of `var` from scripts.
* Add webdriver test to verify compile test worked.
* Resolve conficts with 'develop'.
* Address PR comments.
* feat(tests): Make runTestBlock able to run any gulp task
Modify runTestBlock so that it can run any async task, not just
ones that return a Promise, by using the async-done package
(part of Gulp, and already an indirect dependency) to detect
task completion.
Celebrate by renaming it to runTestTask.
* refactor(tests): Create Tester class to encapsulate test infrastructure
- Create Tester class to encapsulate the runTestTask,
and reportTestResult and runAll functions.
- Remove the unnecessary id parameter from runTestTask (code was
already using the .name of the task function object).
- Remove --silent flag from npm scripts so as not to suppress
syntax error in gulpfiles.
* refactor(tests): Invoke buildAdvancedCompilationTest task directly
Have the test task invoke the buildAdvancedCompilationTest
(via onlyBuildAdvancedCompilationTest, to skip already-run
prerequisites) directly, rather than by running npm.
* chore: add command to generate reference docs
* chore: format
* chore: add comments and fix names
* chore: format
* chore:update patch for latest api documenter version
* chore: fix package-lock
* feat(build): Make build tasks invoke their prerequisites
- Divide gulp targets into three kinds: main sequence,
manually invokable, and script-only. The first two categories
automatically invoke their prerequisites.
- Give (most of) the affected gulp targets shorter and more memorable
names that could become their npm script names in future.
* feat(build): Make package tasks invoke their prerequisites
Have the package task invoke the cleanBuildDir (as well as
cleanPackageDir) and build tasks. Remove the checkBuildDir
task as it is now redundant since a fresh build is done every
time.
* feat(build): Make git tasks invoke their prerequisites
* feat(build): Make cleanup, license [sic] tasks invoke their prerequisites
Turns out they don't have any, so this commit just classifies
their gulp targets according to the established scheme.
* feat(build): Make appengine tasks invoke their prerequisites
In this case prepareDeployDir will eventually depend on package
but does not for now.
* feat(build): Have npm scripts run npm ci first where applicable
Have any npm script that have external effects (e.g. publishing an
npm package, pushing a new version to appengine, or updating GitHub
Pages) start by running npm ci to ensure that all dependencies are
up-to-date with respect to package-lock.json.
(This is done by npm and not a gulp script because gulp itself
might need updating. So might npm, but that is less likely to
make any difference to what gets published/pushed.)
* chore(build): have tests use package target
Have the tests just run the package target (with debug flags)
since that runs the the build target automatically.
* feat(tests): Write Closure Compiler output directly to dist/
Since they are already UMD-wrapped, have Closure Compiler write
output chunks directly to RELEASE_DIR, i.e. dist/.
* chore(tests): Use freshly-build files in compressed mode.
Use the freshly-built build/*_compresssed.js files when bootstrapping
in compressed mode, rather than using the checked-in files in the
repository root.
This helps ensure that compressed and uncompressed mode will be
testing (as closely as possible) the same code.
Obsoletes #6218 (though the issues discussed there have not actually
yet been addressed in this branch).
* chore(build): Write intermediate langfiles to build/msg
Write the results of create_messages.py to build/msg instead of
build/msg/js.
* fix(build): Use build/msg/en.js instead of msg/messages.js in tests
This has no direct effect but fixes a long-standing misdesign
where we are testing against the input to, rather than the output
of, the language file processing pipeline.
* feat(demos): Use freshly-built files
Use the freshly-built dist/*_compresssed.js and build/msg/* files
rather than using the checked-in files in the repository root.
This helps ensure that these demos are using the most recent
version of Blockly (even in the develop branch).
* fix(build): Update appengine deployment to include built files
Modify the prepareDemos task as follows:
- Use the git index instead of HEAD, so that most local changes
will be applied (without copying whatever .gitignored cruft
might be in the local directory).
- Run clean and build and then copy build/msg and
dist/*_compressed.js* to the deploy directory.
This fixes the problem created by the previous commit, wherein the
demos relied on built files that were not being deployed to
appengine.
* fix(build): Update GitHub Pages deployment to include built files
Modify the updateGithubPages task to run clean and build and
then git add build/msg dist/*_compressed.js*, so that they will
be included in the deployed pages.
This fixes the problem created by the previous^2 commit,
wherein the demos relied on built files that were not being
deployed to GitHub Pages.
* chore(build): Remove build products from repository
Remove *_compressed.js* and msg/js/* from the blockly repository.
Also remove the now-obsolete checkinBuilt gulp task.
* chore(build): Apply relevant changes to test_tasks.js
Apply changes made to run_all_tests.sh and check_metadata.sh to
the corresponding parts of their JS replacements in
test_tasks.js.
* chore(build): Make updates suggested in PR #6475
- Remove `clean:builddir` and `clean:releasedir` - `clean`
is sufficient.
- Remove duplicate `require` from `appengine_tasks.js`.
* feat(build): Use shorter npm script names
Since scripts that run build tasks now automatically run their
prerequisite tasks, the previous naming scheme of task `build`
running all the `build:subtask`s no longe really makes very
much sense.
Additionally, following a chat discussion, there seems to be a
rough consensus to use "messages" to refer to the .json input
files, and "langfiles" to the generated .js output files.
Consequently, simplify npm script names by renaming as follows:
- "generate:langfiles" -> "messages"
- "build:langfiles" -> "langfiles"
- "build:js" -> "tsc"
- "build:deps" -> "deps"
- "build:compiled" -> "minify"
- "build:compressed": delete this synonym for "build:compiled",
("minify" was chosen as agnostic to Closure Compiler vs. WebPack.)
* chores(build): Add deprecation notice for old scripts
To reduce potential confusion/frustration, restore the previous
npm scripts but have them display a deprecation notice instead
(note that npm prints the script contents before running it, so
echo is not needed).
* docs(build): Add comments distinguishing 'messages' from 'langfiles'
* build: build/test on windows
* chore(deps): bump @hyperjump/json-schema from 0.18.4 to 0.18.5
* chore(deps): add gulp-gzip 1.4.2
* build: migrate test scripts to gulp task (test_tasks.js)
* build: not to use the grep command
* build: normalize path
* fix: Modified based on review suggestions.
* Add JSDoc comment
* Line length <= 80 characters.
* Formatting test output as previously.
* Always continue even if a test unit fails.
* Suppress the gulp messages.
* Fix test_tasks.js to pass eslint.
* fix: Modified based on review suggestions.
* Change generator test output directory.
* Formatting test output as previously.
* fix: Formatting test output as previously.
* fix: Modified based on review suggestions.
* chore: regen msg dts files
* fix: package tasks not packaging msg.d.ts files
* fix: add setLocale to blockly.ts
* chore: format
* chore: move setLocale
* chore: add comment about setLocale not being useful when used with script tags
* chore: format
* chore(build): Add inline sources to sourcemaps
* chore(build): Don't package sources
Since the sources are now inline in the sourcemaps, they no longer
need to be package separately.
PR #6244 made a change to have the npm run prepare script
(automatically invoked by npm install after package installation)
not bother running the buildJavaScriptAndDeps gulp task when run
from a GitHub action (since our build action will do npm test
straight afterwards, which runs this task already).
Unfortunately, due my misunderstanding of how gulp tasks work
the revised version generated a "Did you forget to signal async
completion?" error from gulp.
Fix this by adding a done parameter and passing the provided
callback to buildJavaScriptAndDeps. This also allows a
simplification of the the don't-run case by simply calling
done and then returning.
Get sourcemaps working again.
- The change in tsconfig.json is sufficient to get functional,
per-.ts-file sourcemaps in build/src/** that work in
uncompiled mode (i.e. in the playground / tests).
- No further changes are required for these to be ingested by
gulp + Closure Compiler; the resulting files -
build/*_compressed.js.map - now point at files in
core/, blocks/, etc. This works correctly when packaged and
also when doing local testing in compiled mode of the checked-in
build products (i.e., after they are copied to the repository
root.)
- In order to get sourcemaps to work for local testing in
compiled mode of the build products directly from build/,
buildCompile now creates symlinks from build/ to core/,
blocks/ and generators/.