-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix scala.js deprecation warnings #222
Conversation
I need to check this once I'm on my computer, if it works as before or not. |
Hey! Let's finish this (and other PRs) before end of year! 😃 @GreyCat, @generalmimon, @dgelessus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you compare your and upstream version of the generated bundle js/npm/kaitai-struct-compiler.js
after running sbt compile fastOptJS buildNpmJsFile
, you find that the path to the object MainJs
has also changed:
diff --git "1/.\\kaitai-struct-compiler-upstream.js" "2/.\\kaitai-struct-compiler-Mingun-scala-js.js"
index 02dcd47..0f698e1 100644
--- "1/.\\kaitai-struct-compiler-upstream.js"
+++ "2/.\\kaitai-struct-compiler-Mingun-scala-js.js"
@@ -1,10 +1,10 @@
-(function (root, factory) {
+(function (root, compiler) {
if (typeof define === 'function' && define.amd) {
- define([], factory);
+ define([], function() { return compiler; });
} else if (typeof module === 'object' && module.exports) {
- module.exports = factory();
+ module.exports = compiler;
} else {
- root.KaitaiStructCompiler = factory();
+ root.KaitaiStructCompiler = compiler;
}
}(this, function () {
@@ -93251,10 +93251,7 @@ var $d_scm_ArrayBuffer = new $TypeData().initClass({
Ljava_io_Serializable: 1
});
$c_scm_ArrayBuffer.prototype.$classData = $d_scm_ArrayBuffer;
-$e.io = ($e.io || {});
-$e.io.kaitai = ($e.io.kaitai || {});
-$e.io.kaitai.struct = ($e.io.kaitai.struct || {});
-$e.io.kaitai.struct.MainJs = $m_Lio_kaitai_struct_MainJs$;
+$e.MainJs = $m_Lio_kaitai_struct_MainJs$();
}).call(this);
//# sourceMappingURL=kaitai-struct-compiler-js-fastopt.js.map
return exports.io.kaitai.struct.MainJs;
}));
So return exports.io.kaitai.struct.MainJs
here:
kaitai_struct_compiler/build.sbt
Lines 213 to 217 in d10b795
|$compiledFileContents | |
| | |
|return exports.io.kaitai.struct.MainJs; | |
| | |
|})); |
also needs to be changed into:
|$compiledFileContents
|
|return exports.MainJs;
|
|}));
I've found that probably changing
After upgrading scala-js and do not touching
Such a change seems reasonable and I think we shouldn't does anything with that. As I see, nobody in kaitai_struct repos using this generated file, but I've not checking web-IDE |
Well, I wholeheartedly agree, as the stuff like const KaitaiStructCompiler = require('kaitai-struct-compiler');
const compiler = new KaitaiStructCompiler();
// compiler.compile(...); that shows the common usage at the moment actually doesn't make any sense - But I'm reluctant to make such a daring BC break, because
Well, at the very least, GitHub shows so-called dependents by scanning the And yeah, the Web IDE is essentially based on the Scala.js bundle of KSC, I think that actually the Web IDE was the reason why the Scala.js target of the KSC was introduced in the first place :) So we've got a dilemma here of simplifying the usage but breaking the BC and just leaving it as it is for now (in the not-so-ideal state). I mean - the fix is incredibly simple (you just remove the calling brackets I see that you added an info to the README, that's great, but I wonder whether we can also automatically show a warning in the console right after a user updates the
console.warn(
'kaitai-struct-compiler: WARNING - you\'ve just installed the 0.10.0-SNAPSHOT20201217+ version. \
If you\'re coming from an older version, make sure to update your code - \
the usage changed from "(new KaitaiStructCompiler()).compile(...)" to "KaitaiStructCompiler.compile(...)".\n'
);
{
"version": "0.10.0-SNAPSHOT20201217-...",
"scripts": {
"postinstall": "node warn-about-constructor-bc-break.js"
}
} I think that this warning can be quite useful for the users. |
Well,
I definitely sure that we should do that. In any case when you upgrade your dependencies to next minor/major version you shouldn't expect that all will work as before 🙂
I've add this to the PR, but I think it will not be so useful, because it seems that this script will not run on |
js/README.md
Outdated
@@ -53,23 +53,24 @@ Our [examples repository](https://github.com/kaitai-io/kaitai_struct_examples) c | |||
|
|||
## Plugging in | |||
|
|||
> :information_source: Before the version 0.10.0 the `kaitai-struct-compiler` module returned a _compiler constructor_ (called `KaitaiStructCompiler`) and you used it as `new KaitaiStructCompiler()`, but since 0.10.0 release this is the _compiler object_ itself and using `new` is not required anymore (see [#222](https://github.com/kaitai-io/kaitai_struct_compiler/pull/222)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> :information_source: Before the version 0.10.0 the `kaitai-struct-compiler` module returned a _compiler constructor_ (called `KaitaiStructCompiler`) and you used it as `new KaitaiStructCompiler()`, but since 0.10.0 release this is the _compiler object_ itself and using `new` is not required anymore (see [#222](https://github.com/kaitai-io/kaitai_struct_compiler/pull/222)). | |
> :information_source: Before the version 0.10.0 the `kaitai-struct-compiler` module returned a _compiler constructor_ (called `KaitaiStructCompiler`) and you would use it as `(new KaitaiStructCompiler()).compile(...)`, but since 0.10.0 release it returns the _compiler object_ itself and you just need to do `KaitaiStructCompiler.compile(...)`. Make sure to adapt your code. |
I deleted the PR reference from my suggestion right away as I suggested in #222 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworded as you suggest
Ping |
`npm` since `v7` doesn't display the output of lifecycle scripts (see https://docs.npmjs.com/cli/v9/using-npm/logging?v=true#foreground-scripts), so the automatic notification no longer works. The note in README will have to suffice. This reverts commit 1be1580.
9aa3980
to
b3f2733
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mingun Thanks!
No description provided.