Commit Graph

59 Commits

Author SHA1 Message Date
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
d3575adcb8 fix(typings): Restore inadvertently-deleted typings/msg/msg.d.ts; add TS import test (#7955)
* test(typings): Add langfile (msg) import + typings test

* fix(typings): Restore inadvertently-deleted typings/msg/msg.d.ts

  Fixes #7952.

  The main typings file for langfiles, typings/msg/msg.d.ts, was
  inadvertently deleted in PR #7822.

  This was part of a well intentioned attempt to remove spurious
  files from typings/msg/ that do not correspond to published
  langfiles, but this file should have been retained because
  msg.d.ts is reexported by all the other *.d.ts files in this
  directory.
2024-03-21 15:01:22 +00: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
Christopher Allen
4cc4bd573c fix(generators): Fix generator type declarations (#7750)
* test(generators): Add generator TS import/use tests

* fix(generators): Fix generator type declarations

  Add a missing ./ prefix to the imports in the generator wrapper
  .d.ts files.

  Fixes: #7741
2024-01-08 17:10:47 +00:00
Christopher Allen
4dcf4064f2 fix(generators): Fix generator typings (#7727) 2023-12-19 21:20:04 +00:00
Christopher Allen
d503fbb409 fix(generators): Changes to exports and access controls for TypeScript compatibility (#7295)
* fix(generators): Add missing declarations for Order enums

* chore(generators): Remove spurious whitespace

* fix(generators): Make provideFunction_ etc. public

  Remove the protected declaration on provideFunction_ and
  FUNCTION_NAME_PLACEHOLDER_ so they can be used from generator
  functions written in TypeScript.

  Not strictly part of #7283, but closely related and required to
  fixing the related issue google/blockly-samples#1785.

* chore(generators): format
2023-07-17 20:40:27 +01:00
Beka Westberg
42b8c6e3ab fix: return annotations (#7118)
* chore: remove suppress annotations

* chore: remove fileoverview annotation

* chore: remove other unused annotations

* chore: change return to returns

* chore: enable tag linting
2023-05-24 13:01:33 -07:00
Beka Westberg
73cdc7410f chore: update typings docs (#6704) 2022-12-14 17:07:37 -08:00
Beka Westberg
9c81e7591a fix: message types being incorrect (#6414)
* 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
2022-09-26 14:02:57 -07:00
Neil Fraser
e5dcb766bd chore: Remove radix from parseInt, simplify Blockly.utils.dom methods, use Unicode characters. (#6441)
* chore: remove radix from parseInt

Previously any number starting with '0' would be parsed as octal if the radix was left blank.  But this was changed years ago.  It is no longer needed to specify a radix.

* chore: 'ID' is identification

'id' is a part of Freud's brain.

* Use Unicode characters instead of codes

This is in line with the current style guide.

* Simplify Blockly.utils.dom methods.

classList add/remove/has supports SVG elements in all browsers Blockly supports (i.e. not IE).
2022-09-22 06:59:24 -07:00
Beka Westberg
b2fa356c60 fix: generator type declarations (#6412)
* fix: generator type declarations

* chore: remove accidental file overview
2022-09-17 15:49:06 -07:00
Maribeth Bottorff
ec72e8bb4d chore: add api extractor configuration and fix some associated problems (#6388)
* chore: add configuration for api extractor

* fix: remove extra param names

* chore: private to internal

* remove unrestricted

* chore: remove double backticks

* chore: remove fileoverview and export * as

* chore: return to returns

* chore: fix backslashes and angle brackets in tsdoc

* chore: final to sealed

* chore: ignore to internal

* chore: fix link tags

* chore: add api-extractor configuration

* chore: add unrecognized tag names

* chore: remove tsdoc-metadata

* fix: correct index.d.ts

* chore: fix connection link
2022-09-01 11:39:05 -07:00
Beka Westberg
c8dd01ac87 fix: packaging .d.ts files (#6327)
* fix: dts files not being properly included

* fix: hand crafted declaration files pointing to the wrong things
2022-08-08 14:32:03 -07: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
Berke Anday Baloglu
233cce8883 Fix: inject function options dictionary has wrong type definition (#6231) 2022-06-23 18:14:50 +01:00
Maribeth Bottorff
2ff4f88f24 fix: Make generator types and BlockDefinition less restrictive (#6185) 2022-06-03 12:20:06 -07:00
Maribeth Bottorff
87aa4c0f62 fix: Update typescript definition files for core, blocks, and generators (#6174)
* fix: update definitions for core and blocks

* fix: update javascript definition

* fix: update JS definition to work with both import types

* fix: update typings for blocks
2022-06-01 15:20:23 -07:00
Neil Fraser
63ca83b545 chore: Make startsWith faster (#6118)
by using built-in function (polyfill will handle IE).
2022-04-27 15:25:07 -07:00
Maribeth Bottorff
69f3d4ae89 fix: Update typings for q1 2022 release (#6051)
* fix: initial commit for typings for q1 2022 release

* fix: update interface declarations

* fix: remove spurious override

* fix: add explicit any type

* fix: remove spurious Array type

* fix: CopyData declaration

* fix: fix extra-state
2022-03-30 18:37:51 -07:00
alschmiedt
10d9cc45d2 Merge branch 'develop' into master_into_develop 2022-03-29 15:25:39 -07:00
Andrew Wyer
5d7c890243 fix: TypeScript exporting of the serialization functions (#5890)
* Relocates serialization typing to be adjacent
* Gathers serialization imports and exports from Blockly
2022-01-25 16:35:47 +00:00
Rachel Fenichel
07a75dee8d fix: msg imports in type definitions (#5858)
This is a copy of https://github.com/google/blockly/pull/5846/files against master, which will fix https://github.com/google/blockly/issues/5841 in the next patch release.

When we released v7 we committed to making patch releases for typescript definition errors, since our pipeline for typings was convoluted this quarter.
2022-01-07 10:11:13 -08:00
Maribeth Bottorff
1fb204e36b fix: Upload new TypeScript typings for Q4 release (#5802)
* fix: Run intial typings script for q4 release

* fix: manually fix errors with types

* fix: update core module
2021-12-09 10:43:43 -08:00
Neil Fraser
90b3f75d82 Remove @author tags (#5601)
Our files are up to a decade old, and have churned so much, that the initial author of the file no longer has much meaning.

Furthermore, this will encourage developers to post to the developer group, rather than emailing Googlers (usually me) directly.
2021-10-15 09:50:46 -07:00
alschmiedt
1c1918ebb2 chore: rebuild for release (#5573) 2021-10-01 08:04:20 -07:00
Sam El-Husseini
6136d93cdf Fix msg typings script and move to typings build directory 2021-07-10 13:02:47 +01:00
Beka Westberg
30d7f0914e Rebuild (#4975) 2021-07-01 08:17:08 -07:00
叶伟伟
978b1b83c4 fix: Fix typing error of generators (#4753) 2021-04-12 16:00:16 -07:00
Maribeth Bottorff
aed9ba13a9 Rebuild (#4733) 2021-03-25 09:37:19 -07:00
alschmiedt
ee99aec820 Fix toolbox typings (#4588) 2021-01-25 09:48:05 -08:00
alschmiedt
92f2ab0258 Rebuild (#4547) 2020-12-17 12:19:28 -08:00
alschmiedt
ebd9d51f3d Revert "Allow .js script files to refer to Blockly global from blockly.d.ts (#4434)" (#4543)
This reverts commit 9a2f288dd4.
2020-12-17 10:08:16 -08:00
Sam El-Husseini
7ebb53968c Update typings script and fix two typing issues: (#4542) 2020-12-16 19:29:20 -08:00
David Foster
9a2f288dd4 Allow .js script files to refer to Blockly global from blockly.d.ts (#4434) 2020-11-16 14:12:10 -08:00
Monica Kozbial
bdee690ab2 Rebuild (#4318) 2020-09-24 12:14:11 -07:00
Sam El-Husseini
d70d896a9f Fix field registry typings (#4281)
* Fix field registry types
2020-09-16 09:10:41 -07:00
Sam El-Husseini
ba68081d8f Rebuild 2020-07-06 11:11:05 -07:00
alschmiedt
a1727b1717 Rebuild (#4001) 2020-06-25 16:11:32 -07:00
Sam El-Husseini
e3babee1f3 Add Blockly.utils.Metrics @record (#3913)
* Add Blockly.utils.Metrics
2020-05-21 15:03:17 -07:00
Sam El-Husseini
888e348c69 Clean out the date field (#3876) 2020-05-06 09:42:24 -07:00
Sam El-Husseini
12c8a50a0f Update the options object to reflect its properties, update the public option interface to include keymap and other little things (#3826) 2020-04-15 17:51:57 -07:00
Sam El-Husseini
7e4e6c7286 Add typings modules to match UMD modules. (#3821)
* Add typings modules to match UMD modules.
2020-04-15 09:44:25 -07:00
alschmiedt
66a47025b7 Update build files in preparation for release (#3786) 2020-04-02 13:10:19 -07:00
Neil Fraser
4e2f8e6e02 Use SPDX licences.
This is a followup to #3127.
At the time, SPDX licenses were pending approval by Google.
2020-02-11 13:27:20 -08:00
Sam El-Husseini
639218e883 Add renderer into typings options (#3631) 2020-01-22 11:07:28 -08:00
Sam El-Husseini
92a19d8340 Rebuild (#3622) 2020-01-21 14:15:35 -08:00
Sam El-Husseini
b87d23b976 Rebuild for release with options parsing fix. (#3618) 2020-01-21 13:40:17 -08:00
Sam El-Husseini
2f3716a022 Update Typings in preparation for release (#3603) 2020-01-16 11:36:51 -08:00
Sam El-Husseini
0f659b25fa Support workspace theme option as JSON (#3379)
* Allow passing in a theme as JSON
2019-10-31 15:49:48 -07:00
Sam El-Husseini
a782645851 Add setLocale to the Blockly typescript definition file. (#3197) 2019-10-08 11:12:29 -07:00