Commit Graph

109 Commits

Author SHA1 Message Date
Christopher Allen
2409123d66 refactor: Omit unused exception arguments from catch blocks (#8559)
Fixes #1770.
2024-09-03 15:27:40 +01:00
Beka Westberg
933e210037 fix: lang file imports (#8179) 2024-05-28 10:01:50 -07:00
Christopher Allen
2ebdc0b7f9 feat(build)!: Introduce ESM entrypoints (#8091)
* 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.
2024-05-10 22:42:35 +01:00
Christopher Allen
c97b13632c feat(build)!: Introduce exports section in package.json (#7822)
* 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.
2024-03-15 22:09:41 +00:00
Beka Westberg
abe4cf98f2 chore: fix v11 branch build (#7836)
* chore: fix render management lint

* fix: build
2024-02-07 09:30:44 -08:00
Beka Westberg
75007a064c chore!: delete deprecations for v11. (#7732)
* chore: delete basic deprecations

* chore: remove deprecated align enum

* chore: remove generator deprecation

* chore: format
2024-01-23 08:48:08 -08:00
Christopher Allen
cd6b14e994 fix(build): Fix sourcemaps, re-update metadata (#7550)
* fix(build): Revert "refactor: Remove $build$src infix from munged paths"

  This is a mostly-manual revert of commit
  06d78af6a4 to fix an issue where
  the generated sourcemaps are missing the inline copies of the
  original .ts source files.

* chore: Update metadata for 2020 Q3 release

  This is being done a second time as the revert of 06d78af causes a
  significant increase in the size of the build products.
2023-09-28 08:35:27 -07:00
Christopher Allen
e7030a18a6 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.
2023-09-12 17:13:52 +01:00
Christopher Allen
b0a7c004a9 refactor(build): Delete Closure Library (#7415)
* fix(build): Restore erroneously-deleted filter function

  This was deleted in PR #7406 as it was mainly being used to
  filter core/ vs. test/mocha/ deps into separate deps files -
  but it turns out also to be used for filtering error
  messages too.  Oops.

* refactor(tests): Migrate advanced compilation test to ES Modules

* refactor(build): Migrate main.js to TypeScript

  This turns out to be pretty straight forward, even if it would
  cause crashing if one actually tried to import this module
  instead of just feeding it to Closure Compiler.

* chore(build): Remove goog.declareModuleId calls

  Replace goog.declareModuleId calls with a comment recording the
  former module ID for posterity (or at least until we decide
  how to reformat the renamings file.

* chore(tests): Delete closure/goog/*

  For the moment we still need something to serve as base.js for
  the benefit of closure-make-deps, so we keep a vestigial
  base.js around, containing only the @provideGoog declaration.

* refactor(build): Remove vestigial base.js

  By changing slightly the command line arguments to
  closure-make-deps and closure-calculate-chunks the need to have
  any base.js is eliminated.

* chore: Typo fix for PR #7415
2023-08-31 00:24:47 +01:00
Christopher Allen
be809d9d98 refactor(tests): Migrate generator tests to import shims; delete bootstrap.js (#7414)
* refactor(tests): Use shims instead of bootstrap to load Blockly

  - Modify tests/generators/index.html to import the test shims
    instead of using bootstrap.js to load Blockly.

  - Modify test/generators/webdriver.js to have it wait for the
    workspace to exist before calling loadSelected().  There was
    previously a race which index.html had been winning, but
    now webdriver.js is winning (and the tests failing because
    there is no workspace yet when start() is called.

* chore(tests): Delete bootstrap.js etc.

  - Delete bootstrap.js, bootstrap_helper.js, and bootstrap_done.mjs.
  - Remove remaining references to bootstrap.js

* refactor(build): Remove deps npm script

  buildDeps is now only needed by buildCompiled, not ever for
  runnning in uncompressed mode, so:

  - Remove the deps gulp task (and the deps npm script.
  - Have the minify task run buildJavaScript and buildDeps directly.

  Additionally, the buildAdvanceCompilationTest target hasn't
  needed deps.js for some time (if ever), so skip having it run
  buildDeps entirely.

* refactor(build): Repatriate DEPS_FILE to build_tasks.js

  Since this is no longer used anywhere else it doesn't need to
  live in common.js.

* fix(scripts): Remove vestigial references to deps.mocha.js

* docs(tests): Add additional explanatory note
2023-08-31 00:02:58 +01:00
Christopher Allen
6f20ac290d refactor(tests): Use import instead of goog.bootstrap to load Blockly in mocha tests (#7406)
* fix(build): Have buildShims clean up up after itself

  We need to create a build/package.json file to allow node.js to
  load build/src/core/blockly.js and the other chunk entry points
  as ES modules (it forcibly assumes .js means CJS even if one is
  trying to import, unless package.json says {"type": "module"}),
  but this interferes with scripts/migration/js2ts doing a
  require('build/deps.js'), which is _not_ an ES module.

  Specific error message was:

  /Users/cpcallen/src/blockly/scripts/migration/js2ts:56
  require(path.resolve(__dirname, '../../build/deps.js'));
  ^

  Error [ERR_REQUIRE_ESM]: require() of ES Module
  /Users/cpcallen/src/blockly/build/deps.js from /Users/cpcallen/src/blockly/scripts/migration/js2ts
  not supported.
  deps.js is treated as an ES module file as it is a .js file whose
  nearest parent package.json contains "type": "module" which
  declares all .js files in that package scope as ES modules.
  Instead rename deps.js to end in .cjs, change the requiring code
  to use dynamic import() which is available in all CommonJS
  modules, or change "type": "module" to "type": "commonjs" in
  /Users/cpcallen/src/blockly/build/package.json to treat all .js
  files as CommonJS (using .mjs for all ES modules instead).

      at Object.<anonymous> (/Users/cpcallen/src/blockly/scripts/migration/js2ts:56:1) {
    code: 'ERR_REQUIRE_ESM'
  }

* chore(tests): Reorder to put interesting script nearer top of file

* chore(tests): Add missing imports of closure/goog/goog.js

  These modules were depending on being loaded via the
  debug module loader, which cannot be used without first loading
  base.js as a script, and thereby defining goog.declareModuleId
  as a side effect—but if they are to be loaded via direct import
  statements then they need to actually import their own
  dependencies.

  This is a temporary measure as soon the goog.declareMouleId
  calls can themselves be deleted.

* refactor(tests): Use import instead of bootstrap to load Blockly

* chores(build): Stop generating deps.mocha.js

  This file was only needed by tests/mocha/index.html's use of
  the debug module loader (via bootstrap.js), which has now been
  removed.

* chore(tests): Remove unneeded goog.declareModuleId calls

  These were only needed because these modules were previously
  being loaded by goog.require and/or goog.bootstrap.

* chores(tests): Remove dead code

  We are fully committed to proper modules now.
2023-08-18 18:06:52 +01:00
Christopher Allen
51be0760c3 fix(build): Fix import of parent chunk's shim (#7398)
In PR #7380 it was suggested[1] that the shims be renamed from
(e.g.) blockly.mjs to blockly.loader.mjs, and in commit 6f930f5
this was duly done, but alas one place was overlooked.

The problem was not spotted in local testing because the
blockly.mjs module that the blocks and generators chunks were
attempting to import did still exist on disk, left over from
before the change was made.

Running npm run clean would have revealed the issue but alas
that was not done.

[1] https://github.com/google/blockly/pull/7380#discussion_r1291667037
2023-08-16 08:29:48 -07:00
Christopher Allen
5b5a56586c refactor(tests): Introduce loading shims, use in playgrounds (#7380)
* refactor(build): Simplify implementation of posixPath

* fix(closure): Make safe to import in node.js

  Make the implementation declareModlueId safe to import and
  execute in node.js, which does not provide a window global.

  (N.B. because this is an ESM and therefore automatically
  strict, using window?.goog?.declareModuleId doesn't work
  because window being undefined is an early error.)

* feat(tests): Introduce chunk loading shims

  - Add a buildShims task to build_tasks.js that, for each chunk,
    creates a correspondingly-named build/<chunk>.mjs that will
    either (in uncompressed mode) import and reexport that chunk's
    entry point module (e.g. core/blockly.js) or (in compressed
    mode) load dist/<chunk>_compressed.js using a <script> tag
    and then export the corresponding properties on the chunk's
    exports object.

  - Provide helper methods used by these shims in
    tests/scripts/loading.mjs, including code to detect whether
    to load in compressed or uncompressed mode.

  - Add a quote() function to scripts/helpers.js, used by
    buildShims.  This is copied from tests/bootstrap_helper.js,
    which will be removed in a later commit.

* refactor(tests): Update playground.html to use new loading shims

* refactor(tests): Update advanced_playground.html to use new loading shims

* refactor(tests): Update multi_playground.html to use new loading shims

* chore(tests): Delete playgrounds/shared_procedures.html

  Shared procedure support was moved to a plugin and this should
  have been removed from core along with it.

* docs(tests): Typo corrections.

* chore(tests): Add ".loader" infix to shim filenames.

  Per suggestion on PR #7380, have buildShims name the shims
  ${chunk.name}.loader.mjs instead of just `${chunk.name}.mjs`.
2023-08-14 22:47:19 +01:00
Abdul Al-Hasany
5e0390b3ec fix(build): support running Blocky locally on Windows machines (#7281)
* fix: update build path for windows

  When using single quote on windows, e.g. 'build/src', the folder
  are created with a single quote at the beginning `'build` and end
  `src'`. This commit fixes this issue.

* fix: update python command and folder separator

  Ensure that when running on windows, python command is python and
  not python3. Also, separators are normalized to posix style `/` even on
  windows system

* fix: add global PYTHON constant to run python command

* fix: simplify `path.sep` to forwadslash since it is cross-platform

* fix(syntax): replace double quote with single quote
2023-08-02 16:27:04 +00:00
Christopher Allen
7771a6dbff fix(build): Correct typos in PR #7169 (#7197)
Three separate mistakes left only the Python and PHP chunks with
the correct code for the legacy script exports.
2023-06-22 20:35:19 +00:00
Christopher Allen
b6e084257e refactor(blocks): Migrate blocks/blocks.js to TypeScript (#7193)
* refactor(blocks): Auto-migration of blocks/blocks.js to ts

* fix(blocks): Manually migrate & fix types in blocks.ts

* fix(build): Update location of blocks/blocks.ts exports object

* fix(blocks): Remove lint

* chore(blocks): Format
2023-06-21 22:07:20 +01:00
Christopher Allen
130989763c refactor(generators): Restructure generator modules to contain side effects (#7173)
* 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
2023-06-20 23:22:44 +01:00
Christopher Allen
ace9c4a188 fix(tests): Fix compressed mode loading (#7178)
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.
2023-06-20 21:49:26 +01:00
Beka Westberg
d7ccf8a5ee fix: input exports (#7165)
* 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>
2023-06-16 11:27:46 -07:00
Christopher Allen
817ffab754 refactor(tests): Update bootstrap.js to better support generator chunks (#7171)
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.
2023-06-15 21:03:04 +01:00
Christopher Allen
2d97e5aaf1 refactor(build)!: Provide all generator exports when loaded as script (#7169)
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.
2023-06-15 16:52:51 +01:00
Christopher Allen
3ae4a61842 fix(build): Fix path issue on Windows (#7127)
Fixes #6864.
2023-06-01 13:27:38 +01:00
Christopher Allen
4d2201a427 chore(generators): Migrate generators to ES Modules (#7103)
* 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.
2023-05-19 23:09:37 +01:00
Rachel Fenichel
8b635ab43a chore: remove sortrequires task (#7074) 2023-05-11 11:35:45 -07:00
Maribeth Bottorff
88ff901a72 chore: use prettier instead of clang-format (#7014)
* chore: add and configure prettier

* chore: remove clang-format

* chore: remove clang-format config

* chore: lint additional ts files

* chore: fix lint errors in blocks

* chore: add prettier-ignore where needed

* chore: ignore js blocks when formatting

* chore: fix playground html syntax

* chore: fix yaml spacing from merge

* chore: convert text blocks to use arrow functions

* chore: format everything with prettier

* chore: fix lint unused imports in blocks
2023-05-10 16:01:39 -07:00
Tim Gates
0a1096262f docs: Fix a few typos (#6878)
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>
2023-03-14 05:15:37 -07:00
Christopher Allen
f90a2531a7 feat(build): Run tsc on blocks/ and generators/ (#6836) 2023-02-15 13:10:27 -08:00
Blake Thomas Williams
13fe6eeccf feat: added tests/typescript to test supported TS examples (#6775)
* 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.
2023-02-10 17:12:18 +00:00
Christopher Allen
a7f498a6a0 fix(build): Fix event tests, improve buildDeps (#6773)
* 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
2023-01-26 20:09:19 +00:00
dependabot[bot]
ee51c0f41c chore(deps): bump rimraf from 3.0.2 to 4.0.7 (#6778)
* chore(deps): bump rimraf from 3.0.2 to 4.0.7

Bumps [rimraf](https://github.com/isaacs/rimraf) from 3.0.2 to 4.0.7.
- [Release notes](https://github.com/isaacs/rimraf/releases)
- [Changelog](https://github.com/isaacs/rimraf/blob/main/CHANGELOG.md)
- [Commits](https://github.com/isaacs/rimraf/compare/v3.0.2...v4.0.7)

---
updated-dependencies:
- dependency-name: rimraf
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: fix use of rimraf

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Beka Westberg <bwestberg@google.com>
2023-01-18 13:16:40 +00:00
Christopher Allen
3be3d4a6ff chore: miscellaneous fixes to docs, style, and tests (#6705)
* 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
2022-12-14 23:48:12 +00:00
Christopher Allen
e3c04978f3 chore(build): Remove prepare script; run deps script from start script (#6653)
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.
2022-12-08 16:32:25 +00:00
Neil Fraser
5a64a9a7f7 fix: Fix the compiler test, and check if it worked. (#6638)
* 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.
2022-11-25 11:45:00 -08:00
Christopher Allen
52a0d525d7 chore(build): Remove build products from the Blockly repository (#6475)
* 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'
2022-11-03 13:15:10 +00:00
Neil Fraser
e90aba9273 fix: Rename Generator to CodeGenerator (#6585)
Stops collisions with ES6's Generator.
The old Blockly.Generator still exists as a name, but is now deprecated.
2022-10-28 01:59:00 +02:00
YAMADA Yutaka
52879dd953 fix(build): build/test on windows (#6431)
* 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.
2022-10-27 21:02:50 +01:00
Christopher Allen
bcd62f170b chore(build): use inline sources in sourcemaps; don't package sources separately (#6362)
* 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.
2022-08-22 19:12:55 -04:00
Christopher Allen
079699baff fix(build): Have prepare task signal async completion (#6356)
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.
2022-08-22 17:27:26 -04:00
Christopher Allen
883d78d5a0 chore(build): Only suppress expected warnings from closure-make-deps (#6350) 2022-08-18 15:27:09 +01:00
Christopher Allen
e10bf99936 fix(build): Fix sourcemaps (#6352)
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/.
2022-08-17 17:05:38 +01:00
Christopher Allen
e145102b84 chore(tests): Drop build/test support for node.js v12 (#6222)
* chore(tests): Stop testing on node.js v12
* chore(build): Remove obsolete workaround for closure-calculate-chunks
2022-08-11 18:01:45 +01:00
Rachel Fenichel
f032151cd9 chore(build)!: compile to ES2015 instead of ES5 (#6335) 2022-08-10 16:56:43 -04:00
Beka Westberg
8f0a5ae6a8 chore: properly package .ts and .d.ts files (#6257)
* fix: package .ts sources

* chore: add generating type defs

* chore: copy generated type defs into dist dir

* chore: fix adding generated def files

* chore: remove unnecessary imports

* chore: make handcrafted files reference generated

* chore: replace AnyDuringMigration with any

* chore: use replace instead of regex-replace

* chore: use value in config instead of magic strings

* chore: remove blockly.d.ts

* chore: update jsdocs

* chore: remove old references to typings
2022-08-05 08:25:41 -07:00
Beka Westberg
21d90696d1 chore: Migrate core/ to Typescript, actually (#6299)
* fix: convert files to typescript

* fix: add alias for AnyDuringMigration so that tsc will run

* chore: format

* chore: enable ts for the clang-format workflow (#6233)

* chore: Restore @fileoverview comment locations (#6237)

* chore: add declareModuleId (#6238)

* fix: Revert comment change to app_controller.js (#6241)

* fix: Add missing import goog statements (#6240)

I've added the import statement immediately before the
goog.declareModuleId calls that depend on it.

There is an argument to be made that we should put the import
statement in their normal place amongst any other imports, and
move the declareModuleId statement to below the double blank
line below the imports, but as these are so tightly coupled,
replace the previous goog.module calls, and will both be deleted
at the same time once the transition to TypeScript is fully complete
I think it's fine (and certainly much easier) to do it this way.

* chore: Fix whitespace (#6243)

* fix: Remove spurious blank lines

  Remove extraneous blank lines introduced by deletion of
  'use strict'; pragmas.

  Also fix the location of the goog.declareModuleId call in
  core/utils/array.ts.

* fix: Add missing double-blank-line before body of modules

  Our convention is to have two blank lines between the imports (or
  module ID, if there are no imports) and the beginning of the body
  of the module.  Enforce this.

* fix: one addition format error for PR #6243

* fix(build): Skip npm prepare when running in CI (#6244)

Have npm prepare do nothing when running in CI.

We don't need to do any building, because npm test will build
everything needed in the workflows in which it is run, and we
don't want to build anything in other workflows because a tsc
error would prevent those workflows from completing.

* fix: re-add `@package` annotations as `@internal` annotations (#6232)

* fix: add ~70% of internal attributes

* fix: work on manually adding more @internal annotations

* fix: add more manual internal annotations

* fix: rename package typos to internal

* fix: final manual fixes for internal annotations

* chore: format

* chore: make unnecessary multiline jsdoc a single line

* fix: fix internal tags in serialization exceptions

* fix: tsc errors picked up from develop (#6224)

* fix: relative path for deprecation utils

* fix: checking if properties exist in svg_math

* fix: set all timeout PIDs to AnyDuringMigration

* fix: make nullability errors explicity in block drag surface

* fix: make null check in events_block_change explicit

* fix: make getEventWorkspace_ internal so we can access it from CommentCreateDeleteHelper

* fix: rename DIV -> containerDiv in tooltip

* fix: ignore backwards compat check in category

* fix: set block styles to AnyDuringMigration

* fix: type typo in KeyboardShortcut

* fix: constants name in row measurables

* fix: typecast in mutator

* fix: populateProcedures type of flattened array

* fix: ignore errors related to workspace comment deserialization

* chore: format files

* fix: renaming imports missing file extensions

* fix: remove check for sound.play

* fix: temporarily remove bad requireType.

All `export type` statements are stripped when tsc is run. This means
that when we attempt to require BlockDefinition from the block files, we
get an error because it does not exist.

We decided to temporarily remove the require, because this will no
longer be a problem when we conver the blocks to typescript, and
everything gets compiled together.

* fix: bad jsdoc in array

* fix: silence missing property errors

Closure was complaining about inexistant properties, but they actually
do exist, they're just not being transpiled by tsc in a way that closure
understands.

I.E. if things are initialized in a function called by the constructor,
rather than in a class field or in the custructor itself, closure would
error.

It would also error on enums, because they are transpiled to a weird
IIFE.

* fix: context menu action handler not knowing the type of this.

this: TypeX information gets stripped when tsc is run, so closure could
not know that this was not global. Fixed this by reorganizing to use the
option object directly instead of passing it to onAction to be bound to
this.

* fix: readd getDeveloperVars checks (should not be part of migration)

This was found because ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE was no
longer being accessed.

* fix: silence closure errors about overriding supertype props

We propertly define the overrides in typescript, but these get removed
from the compiled output, so closure doesn't know they exist.

* fix: silence globalThis errors

this: TypeX annotations get stripped from the compiled output, so
closure can't know that we're accessing the correct things. However,
typescript makes sure that this always has the correct properties, so
silencing this should be fine.

* fix: bad jsdoc name

* chore: attempt compiling with blockly.js

* fix: attempt moving the import statement above the namespace line

* chore: add todo comments to block def files

* chore: remove todo from context menu

* chore: add comments abotu disabled errors

* chore: move comments back to their correct positions (#6249)

* fix: work on fixing comments

* chore: finish moving all comments

* chore: format

* chore: move some other messed up comments

* chore: format

* fix: Correct enum formatting, use merged `namespace`s for types that are class static members (#6246)

* fix: formatting of enum KeyCodes

* fix: Use merged namespace for ContextMenuRegistry static types

  - Create a namespace to be merged with the ContextMenuRegistry
    class containing the types that were formerly declared as static
    properties on that class.

  - Use type aliases to export them individually as well, for
    compatibility with the changes made by MigranTS (and/or
    @gonfunko) to how other modules in core/ now import these
    types.

  - Update renamings.json5 to reflect the availability of the
    direct exports for modules that import this module directly
    (though they are not available to, and will not be used by,
    code that imports only via blockly.js/blockly.ts.)

* fix: Use merged namespace for Input.Align

  - Create a merged namespace for the Input.Align enum.

  - Use type/const aliases to export it as Input too.

  - Update renamings.json5 to reflect the availability of the
    direct export.

* fix: Use merged namespace for Names.NameType

  - Create a merged namespace for the Names.NameType enum.

  - Use type/const aliases to export it as NameType too.

  - Update renamings.json5 to reflect the availability of the
    direct export.  (This ought to have happened in an earlier
    version as it was already available by both routes.)

* chore: Fix minor issues for PR #6246

  - Use `Align` instead of `Input.Align` where possible.

* fix(build): Suppress irrelevant JSC_UNUSED_LOCAL_ASSIGNMENT errors

  tsc generates code for merged namespaces that looks like:

      (function (ClassName) {
          let EnumName;
          (function (EnumName) {
              EnumName[EnumNameAlign["v1"] = 0] = "v1";
              // etc.
          })(EnumName = ClassName.EnumName || (ClassName.EnumName = {}));
      })(ClassName || (ClassName = {}));

  and Closure Compiler complains about the fact that the EnumName let
  binding is initialised but never used.  (It exists so that any other
  code that was in the namespace could see the enum.)

  Suppress this message, since it is not actionable and lint and/or tsc
  should tell us if we have actual unused variables in our .ts files.

* chore(build): Suppress spurious warnings from closure-make-deps (#6253)

A little bit of an ugly hack, but it works: pipe stderr through
grep -v to suppress error output starting with "WARNING in".

* fix: remaining enums that weren't properly exported (#6251)

* fix: remaining enums that weren't properly exported

* chore: format

* fix: add enum value exports

* chore: format

* fix: properly export interfaces that were typedefs (#6250)

* fix: properly export interfaces that were typedefs

* fix: allowCollsion -> allowCollision

* fix: convert unconverted enums

* fix: enums that were/are instance properties

* fix: revert changes to property enums

* fix: renamed protected parameter properties (#6252)

* fix: bad protected parameter properties

* chore:format

* fix: gesture constructor

* fix: overridden properties that were renamed

* refactor: Migrate `blockly.js` to TypeScript (#6261)

* chore: Apply changes to blockly.js to blockly.ts

* fix: Build using core/blockly.ts instead of .js

  Compiles and runs in compressed mode correctly!

* fix(build): Don't depend on execSync running bash (#6262)

For some reason on Github CI servers execSync uses /bin/sh, which
is (on Ubuntu) dash rather than bash, and does not understand
the pipefail option.

So remove the grep pipe on stderr and just discard all error output
at all.

This is not ideal as errors in test deps will go unreported AND
not even cause test failure, but it's not clear that it's worth
investing more time to fix this at the moment.

* chore: use `import type` where possible (#6279)

* chore: automatically change imports to import types

* chore: revert changes that actually need to be imports

* chore: format

* chore: add more import type statements based on importsNotUsedAsValues

* chore: fix tsconfig

* chore: add link to compiler issue

* fix: add type information to blockly options (#6283)

* fix: add type information to blockly options

* chore: format

* chore: remove erroneous comment

* fix: bugs revealed by getting the built output working (#6282)

* fix: types of compose and decompose in block

* fix: workspace naming in toolbox

* chore: add jsdoc

* chore: restore registry comments to better positions

* chore: pr comments'

* fix(variables): Revert inadvertent change to allDeveloperVariables (#6290)

It appears that a function call got modified incorrectly (probably
in an effort to fix a typing issue).  This fix trivially reverts
the line in question to match the original JS version from develop.

This causes the generator tests to pass.

* fix: circular dependencies (#6281)

* chore: fix circular dependencies w/ static workspace funcs

* remove preserved imports that aren't currently necessary (probably)

* fix circular dependency with workspaces and block using stub

* fix dependency between variables and xml by moving function to utils

* add stub for trashcan as well

* fix line endings from rebase

* fix goog/base order

* add trashcan patch

* fix: types of compose and decompose in block

* fix: workspace naming in toolbox

* chore: add jsdoc

* chore: restore registry comments to better positions

* chore: remove implementations in goog.js

* chore: fix types of stubs

* chore: remove added AnyDuringMigration casts

* chore: remove modifications to xml and variables

* chore: format

* chore: remove event requirements in workspace comments

* chore: fix circular dependency with xml and workspace comments

* fixup remove ContextMenu import

* chore: fix dependency between mutator and workspace

* chore: break circular dependency between names and procedures

* chore: get tests to run?

* chore: pr comments'

* chore: fix stubbing field registry fromJson

* chore: fix spying on fire

* chore: fix stubbing parts of connection checker

* chore: fix stubbing dialog

* chore: fix stubbing style

* chore: fix spying on duplicate

* chore: fix stubbing variables

* chore: fix stubbing copy

* chore: fix stubbing in workspace

* chore: remove unnecessary stubs

* chore: fix formatting

* chore: fix other formatting

* chore: add backwards compatible static properties to workspace

* chore: move static type properties

* chore: move and comment stubs

* chore: add newlines at EOF

* chore: improve errors for monkey patched functions

* chore: update comment with a pointer to the doc

* chore: update comment with a pointer to the doc

* chore: format

* chore: revert changes to playground used for testing (#6292)

* chore: get mocha tests to pass. (#6291)

* chore: fix undo and empty code blocks

* chore: skip IE test

* chore: fix gesture test

* chore: fix replace message references test

* chore: fix string table interpolation

* chore: skip getById tests

* chore: fix field tests

* chore: fix console errors by making workspace nullable

* chore: format

* chore: fix definition overwrite warning

* chore: update metadata

* chore: temporarily modify the the advanced compile test

* chore: fix gestures by fixing test instead

Co-authored-by: Neil Fraser <fraser@google.com>
Co-authored-by: Christopher Allen <cpcallen+git@google.com>
2022-08-02 10:30:13 -07:00
Christopher Allen
aaafbc2b6f fix!: Move backwards-compatibility hacks to main.js (#6260)
* fix!: Move backwards-compatibility hacks out of blockly.js

  Move accessor properties for Blockly.alert, .confirm,
  .mainWorkspace, .prompt, .selected, .HSV_SATURATION and
  .HSV_VALUE, as well as the hack to allow loading of messages
  via <script> tags, from core/blockly.js to core/main.js,
  which becomes the entrypoint for the first chunk when
  compiled.

  BREAKING CHANGE: The aforementioned properties / hack are no
  longer available in uncompiled mode (or when using advanced
  compilation, unless also compiling against main.js.)

* fix!: Move backwards-compatibility hacks out of contextmenu.js

  Move accessor property for ContextMenu.currentBlock from
  core/contextmenu.js to core/main.js.

* chore: Update deprecation date for Generator.variableDB_ accessors

  Bring the deprecation date forward from May 2026 to September 2022.

  Not technically a breaking change—just a warning that there will
  be a breaking change earlier than previously advertised.

* fix!: Move backwards-compatibility hacks out of tooltip.js

  Move accessor properties for Blockly.Tooltip.visible and .DIV
  from core/tooltip.js to core/main.js.

* fix!: Move backwards-compatibility hacks out of widgetdiv.js

  Move accessor property for Blockly.WidgetDiv.DIV
  from core/widgetdiv.js to core/main.js.
2022-07-05 16:27:16 +01:00
Christopher Allen
f947b3f4f6 refactor!: Remove remaining use of goog.module.declareLegacyNamespace. (#6254)
* fix(build): Minor corrections to build_tasks.js

  - Use TSC_OUTPUT_DIR to find goog/goog.js when suppressing warnings.
  - Remove unnecessary trailing semicolons.

* refactor(blocks): Remove declareLegacyNamespace

  Remove the call to goog.module.declareLegacyNamespace from
  Blockly.libraryBlocks.  This entails:

  - Changes to the UMD wrapper to be able to find the exports object.
  - Changes to tests/bootstrap_helper.js to save the exports object
    in the libraryBlocks global variable.
  - As a precaution, renaming the tests/compile/test_blocks.js module
    so that goog.provide does not touch Blockly or
    Blockly.libraryBlocks, which may not exist / be writable.

  * feat(build): Add support named exports from chunks

  We need to convert the generators to named exports.  For backwards
  compatibility we still want e.g. Blockly.JavaScript to point at
  the generator object when the chunk is loaded using a script tag.

  Modify chunkWrapper to honour a .reexportOnly property in the
  chunks table and generate suitable additional code in the UMD
  wrapper.

* refactor(generators): Migrate JavaScript generator to named export

  - Export the JavaScript generator object as javascriptGenerator
    from the Blockly.JavaScript module(generators/javascript.js).

  - Modify the Blockly.JavaScript.all module
    (generators/javascript/all.js) to reexport the exports from
    Blockly.JavaScript.

  - Update chunk configuration so the generator object remains
    available as Blockly.JavaScript when loading
    javascript_compressed.js via a <script> tag.

    (N.B. it is otherwise necessary to destructure the require
    / import.)

  - Modify bootstrap_helper.js to store that export as
    window.javascriptGenerator for use in test code.

  - Modify test code to use javascriptGenerator instead of
    Blockly.JavaScript.

  - Modify .eslintrc.json so that javascriptGenerator is allowed
    as a global in test/.  (Also restrict use of Blockly global
    to test/.)

  N.B. that demo code in demos/code/code.js uses <script> tag
  loading and so will continue to access Blockly.JavaScript.

* refactor(generators): Migrate Lua generator to named export

* refactor(generators): Migrate PHP generator to named export

* refactor(generators): Migrate Python generator to named export

* refactor(generators): Remove declareLegacyNamespace calls

  Remove the goog.module.declareLegacyNamespace calls from the
  generators.

  This turns out to have the unexpected side-effect of causing the
  compiler to rename the core/blockly.js exports object from
  $.Blockly to just Blockly in blockly_compressed.js - presumably
  because it no longer needs to be accessed in any subsequent chunk
  because they no longer add properties to it.  This requires
  some changes (mainly simplification) to the chunkWrapper function
  in build_tasks.js.

* refactor(core): Remove declareLegacyNamespace from blockly.js

  So easy to do _now_: just need to:

  - Make sure the UMD wrapper for the first chunk knows where the
    exports object is.
  - Use that same value to set the Blockly.VERSION @define.
  - Have bootstrap_helper.js set window.Blockly to the exports
    object.
  - Fix tests/compile/test_blocks.js to not assume a Blockly
    global variable, by converting it to a goog.module so we
    can use a named require.
2022-06-30 19:53:32 +01:00
Christopher Allen
4070ffc419 feat(build): Support TypeScript in core/ (#6220)
* fix(tests): Use tsc-compiled base.js to allow use of goog.js

The Closure Compiler complains if you try to feed it a file named
goog.js which is not in the same directory as the Closure Library's
base.js.  Since tsc will "compile" goog.js when it encounters an
"import ... from '.../goog.js'", it is necessary to also have tsc
"compile" base.js and base_minimal.js, so they will come from the
same directory.  This necessitates some updates to paths in

* docs(build): JSDoc update for JSCOMP_WARNING

* refactor(utils): Convert utils/deprecation.js to TypeScript

This was done manually for test/proving purposes and might need to
be corrected based on what MigranTS generated.

* chore(utils): Update utils/deprecation.ts from MigranTS output

This manually applies certain changes from BeksOmega's ts/migration2
branch, but notably:

- I did not apply the reordering of the doc comments at the top.
- I applied the deletion of types and @package from the JSDoc.
- I preserved the import goog and goog.declareModuleId lines.
- I have applied a whitespace change on line 37 which violates the
  styleguide; I want to figure out why clang-format is not fixing
  this.

* feat(build): clang-format .ts files

And fix formatting issues introduced by MigranTS in deprecation.ts.

* fix(build): Fix sources for advanced compilation test

I'm not sure why this didn't fail on my local machine previously;
perhaps it succeeded only because of leftover files and would have
failed if I'd run npm run clean.

* fix(build): Disable checkTypes diagnostic group

Unfortunately TSC doesn't output type information in a form
that Closure Compiler can understand, so the latter raises errors
for situations like omitting an optional parameter.

We may have to turn off more diagnostics in future, but for now
this is sufficient.

* chore(utils): Use @internal where we previously used @package

Per comments on PR #6220.

This requires that we disable the nonStandardJsDocs diagnostic.
2022-06-16 10:49:24 -07:00
Christopher Allen
e6a0b0cb4d chore(build): Delete flattenCorePaths (#6217)
We are no longer using flattenCorePaths and unflattenCorePaths, so
delete them.
2022-06-16 08:43:07 +01:00
Christopher Allen
46df7d132d refactor(tests): Revise tests/playgrounds/prepare.js as tests/bootstrap.js to improve support for ES modules and post-bootstrap scripts (#6214)
* refactor(tests): Move and rename prepare.js, blockly.mjs

  Since prepare.js and blockly.mjs are going to be needed for running
  all tests in uncompiled mode (not just the playgrounds), move them
  tests/.  Further, rename prepare.js to bootstrap.js to better reflect
  its purpose.

* feat(tests): Introduce BLOCKLY_BOOTSTRAP_OPTIONS

  Provide a mechanism for web pages that use bootstrap.js to control
  what is loaded and how.

* fix(tests): Use the blockly repository path for all script src= URLs

  Previously the (non-advanced) playground was only correctly loadging
  on localhost because you can put an arbitrary number of "../"s in front
  of a relative URL and it just takes you to the root directory.

* fix(tests): Don't use template literals in bootstrap.js

  This is necessary (but not necessarily sufficient) to be able to
  load the file in IE 11.

* fix(tests): Throw error if attempting to bootstrap in node.js

* feat(tests): Make bootstrap.js more configurable.

* Terminology change: use "compressed" and "uncompressed" to describe
  what Closure Compiler calls "compiled" and "uncompiled", to reduce
  confusion with the compilation that will be done by tsc.

* Get the list of modules to bootstrap (in compressed mode), or
  scripts to load (in compressed mode) from BLOCKLY_BOOTSTRAP_OPTIONS,
  to allow calling scripts to to specify exactly what to load.

* feat(tests): Use a proper quote function

  We need to generate string literals.  Best to use a quote function
  instead of concatenating on quote marks withou escaping.  Copy a
  well-tested one from Code City.

* feat(tests): Support an additionalScripts option

  This is a list of scripts to load (in order) once the required modules
  have been bootstrapped.

  We do this using goog.addDependency to make the first script depend
  on the required modules, then each subsequent script depend on the
  previous one, and then finally goog.bootstrapping the last such script.

* refactor(tests): Remove special handling of msg/messages.js

* refactor(tests): Use additionalScripts for all script loading

  Use additionalScripts option for all script loading in
  playground.html and advanced_playground.html.

* refactor(tests): Use bootstrap instead of uncompressed in Mocha tests

  Use tests/bootstrap.js instead of blockly_uncompressed.js to load
  blockly in uncompressed mode in the Mocha tests.

  This entails adding a new item, despFiles, to BLOCKLY_BOOTSTRAP_OPTIONS,
  to allow tests/deps.mocha.js to be loaded at the appropriate point.

  Mention of blockly_uncompressed.js is removed from
  tests/mocah/.mocharc.js; it's not clear to me what effect the "file:"
  directive in this file might have previously had and I was not able to
  find documentation for it on mochajs.org, but in any case removing it
  appears to have had no ill effect.

* refactor(tests): Use bootstrap instead of uncompressed in generator tests

  This entails adding an additional check in bootstrap so as to load
  uncompressed when loading from a file: URL, since these are not
  localhost URLs - though in fact the generator tests run equally well
  in compressed mode, albeit against (for now) the previously-check-in
  build products rather than the live code.

* refactor(test): Use bootstrap.js in multi_playground.html

  This removes the last use of load_all.js, so remove it.

* chore(tests): Delete blockly_uncompressed.js

  Its function has now been entirely subsumed by tests/bootstrap.js,
  so remove it and update any remaining mentions of it.

  Also fix formatting and positions of some comments in playground.html.

* fix(tests): Rewrite bootstrap sequencing code

  An earlier commit modified the generated <script> to use
  goog.addDependency to trick the debug module loader into loading
  .additionalScripts (via goog.bootstrap), but it turns out there is
  a small problem: scripts like msg/messages.js have undeclared
  dependencies on the Blockly module, and without a call to
  goog.require('Blockly') in them they can end up being run before
  the Blockly module is fully loaded.

  (This problem only occurs when there are ES Modules, rather than
  merely goog.modules, in the mix.)

  Fix this by adding a script, bootstrap_helper.js, to be loaded
  options.requires and any options.additionalScripts that makes an
  explicit call to goog.require for each of option.requires.

  Also refactor the code so that instead of generating a loop which
  calls goog.addDependency, we generate the addDependency calls
  directly.  This makes debugging a bit easer as we can use the browser's
  dev tools to inspect the generated calls in the DOM tree.

* fix(tests): Prevent spurious transpilation warnings

  For some reason when the debug module loader encounters ES modules
  it starts to complain about being unable to transpile some ES202x
  features in other (non-ESM) modules, even though it doesn't normally
  try to transpile those.

  Since uncompressed-mode testing is almost exclusively on modern
  browsers we don't care about transpiling these features, so suppress
  the warnings instead.

* refactor(tests): Rename blockly.mjs to bootstrap_done.mjs; simplify

  Since blockly.mjs is no longer returning just the exports object
  from core/blockly.js (see PR #5995), it might be better named after
  its actual purpose: to wait for bootstrapping to be done.

  Remove all the code that was used to pass the blockly.js exports
  object along from the bootstrap callback to the blockly.mjs export,
  since there's no reason to go to a lot of trouble to set a local
  variable named Blockly to the same value as a global variable named
  Blockly.

  (Something like this may be needed again in future, but certainly in
  a different form.)

* 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.

* chore(tests): Rename BlocklyLoader to blocklyLoader; record compressed

  - Rename the BlocklyLoader global to blocklyLoader (since it is not
    a class constructor).
  - Create it regardless of whether we are bootstrapping in
    uncompressed or loading compressed via <script> tags.
  - Record which we are doing as .compressed, and use this property
    to choose playground background colour.

* chore(tests): Resolve comments for PR #6214

  Mostly documentation changes, but notably renaming blocklyLoader to
  bootstrapInfo.

* Revert "chore(tests): Use freshly-build files in compressed mode."

  This reverts commit de8d356838.
2022-06-15 19:35:01 +01:00
Christopher Allen
307ff71c21 refactor(build): Preparation for building TypeScript (#6205)
* chore(deps): Update closure/goog/base.js, add goog.js

  - Update base.js from the latest version (20220502.0.0).
  - Also copy over goog.js, which provides access to a suitable subset
    of goog.* via an importable module).

* chore(build): Split gulpfiles/config.js exports object

  This makes it possible for entries to depend on each other.

* chore(build): build config consistency

  - Reorder entries in gulpfiles.config.js to better match order they
    are used.
  - Have update_metadata.sh reference config.js and vice versa.

* refactor(build): Move deps.js (+ deps.mocha.js) from test/ to build/

  Once we start using tsc, deps.js will be created based on the ouptut
  of tsc rather than the raw source in core/.  Since tsc will need to
  be run before running closure-make-deps and also before trying to
  load blockly_uncompressed.js, it doesn't really make sense to check
  in deps.js; it's better to re-create as needed.

  To reduce inconvenience, a new "prepare" script is added to
  package.json which will run the buildDeps gulp target automaticaly
  when one runs npm install.

* refactor(build): Always build from TypeScript sources

  - Add buildJavaScript gulp task to use tsc to compile any .ts files
    in core/ into build/src/core/ (and also copy any .js files that
    are not yet migrated to TypeScript, which for now is all of them.
  - Remove closure/goog from explicit inputs to tsc; it will find
    the files it needs (e.g., goog.js) automatically.
  - Have buildDeps, the playground, and all the tests that run in
    uncompiled mode use build/src/core/ instead of core/ as their
    input directory.

* feat(build): Add buildJavaScriptAndDeps gulp task

  Have npm run build:deps (and npm run prepare) use a new gulp task,
  buildJavaScriptAndDeps, to run tsc followed by closure-make-deps,
  ensuring that deps.js is calculated based on the most recent code
  in core/.

* fix(build): Fix implementation of flattenCorePaths

  Even though this function is going away I want to remove it in
  a separate PR so that we can revert easily if desired.  But the
  previous checked-in code was totally wrong.  This version works.

* fix(build): Don't let checkinBuilt copy build/src/**

  Now that we are putting a lot more stuff in build/ (specifically,
  all the tsc output in build/src/), modify checkinBuilt so that it
  only copies the specific things we want to check in (for now):

  - _compressed.js build artifacts and their accompanying .js.maps
  - the generated build/msg/js/*.js language files.

  Unrelatedly, also fix safety-quoting of arguments for one execSync
  call.
2022-06-14 22:20:42 +01:00