Skip to content

Conversation

petekanev
Copy link
Contributor

Problem:
As explained in #778 - webpack will bundle essential code inside the worker chunks, and that will cause the static binding generator's parser to traverse and generate the same classes as many times as there are workers. The logic in the ASBG prevents a class with the same name from being generated more than once to guarantee predictable runtime behavior, and will crash build-time.

Proposed Solution:
Read a list of the worker scripts output by the webpack worker loader, and exclude the script chunks from being javascript-parsed. Should there be extending of classes the runtime binding generator will take care of handling it the first time per app installation.

Depends on a custom implementation of the worker-loader, and existing webpack user configurations importing the custom plugin.

Addresses: #778

@petekanev petekanev added this to the 3.2.0 milestone Aug 10, 2017
@petekanev petekanev requested review from Plamen5kov and sis0k0 August 10, 2017 14:23
@ns-bot
Copy link

ns-bot commented Aug 10, 2017

💔

@petekanev
Copy link
Contributor Author

run CI

@ns-bot
Copy link

ns-bot commented Aug 10, 2017

💔

@petekanev
Copy link
Contributor Author

run ci

@ns-bot
Copy link

ns-bot commented Aug 15, 2017

💚

if (currFile.substring(currFile.length() - 3, currFile.length()).equals(".js")) {
// Read __worker-chunks.json file containing a list of webpacked workers
// ignore worker scripts, so as to not attempt to generate bindings for them
if (filterWorkerFiles) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can skip this check. If we don't have a __worker-chunks.json file, the webpackWorkersExcludesList will be empty.

logger.info("Task: traverseDirectory: Visiting JavaScript file: " + f.getName())
inputJsFiles.add(f.getAbsolutePath())
def currFile = f.getAbsolutePath();
if (currFile.substring(currFile.length() - 3, currFile.length()).equals(".js")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can extract that logic to a function. Sth like - isJsFile(fullPath)

// Read __worker-chunks.json file containing a list of webpacked workers
// ignore worker scripts, so as to not attempt to generate bindings for them
if (filterWorkerFiles) {
if (webpackWorkersExcludesList.any{element -> file(element).getAbsolutePath() == currFile}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move that to a separate function - isWorkerScript(file)

logger.info("Task: traverseDirectory: Visiting JavaScript file: " + f.getName())
inputJsFiles.add(f.getAbsolutePath())
def currFile = f.getAbsolutePath();
if (currFile.substring(currFile.length() - 3, currFile.length()).equals(".js")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we can move the check that's below here -

if (isJsFile(currFile) && !isWorkerScript(currFile)) {
  // ...
}

if (workersExcludeFile.exists()) {
filterWorkerFiles = true;
webpackWorkersExcludesList = new JsonSlurper().parseText(workersExcludeFile.text)
}
Copy link
Contributor

@Plamen5kov Plamen5kov Aug 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the workersExcludeFile doesn't exist, please add some kind of warning or error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? The app may be built without webpack, or without the worker-loader if the user decided to remove it manually.

Copy link
Contributor

@Plamen5kov Plamen5kov Aug 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if it's an app with webpack and the file does not exist, a warning can go a long way towards debugging the problem. In cases, users are dealing with webpack. I'm sure there's a way to add a check if the project is a webpack one and I believe it's important.
If you believe we shouldn't do it, don't, that why I left a comment not a request for change.

@ns-bot
Copy link

ns-bot commented Aug 15, 2017

💚

Copy link
Contributor

@Plamen5kov Plamen5kov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look at the comments

def isWorkerScript = { fileName ->
// Read __worker-chunks.json file containing a list of webpacked workers
// ignore worker scripts, so as to not attempt to generate bindings for them
if (webpackWorkersExcludesList.any{element -> file(element).getAbsolutePath() == fileName}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that be just

return webpackWorkersExcludesList.any{element -> file(element).getAbsolutePath() == fileName}

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, I have unintentionally left the if statement!

@petekanev petekanev force-pushed the pete/ignore-parsing-webpacked-workers branch from 243ef35 to ab356c8 Compare August 16, 2017 07:39
@ns-bot
Copy link

ns-bot commented Aug 16, 2017

💚

@petekanev
Copy link
Contributor Author

@Plamen5kov thanks for your input. Please note that besides the list of workers to exclude from parsing, Gradle doesn't know if its building a webpacked, or a regular project, thus adding a warning message on every build which doesn't involve webpacking, I think will confuse users more than it would help others who webpack.

@petekanev petekanev merged commit aebd5f1 into master Aug 17, 2017
@petekanev petekanev deleted the pete/ignore-parsing-webpacked-workers branch August 17, 2017 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants