Skip to content

Commit aebd5f1

Browse files
authored
Merge pull request #823 from NativeScript/pete/ignore-parsing-webpacked-workers
Filter out webpacked workers before parsing the scripts in the ASBG
2 parents ccb8ace + ab356c8 commit aebd5f1

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

android-static-binding-generator/project/build.gradle

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ def cachedJarsFilePath = "$projectDir/cached.txt"
1414
def jsParserP = "$projectDir/parser/js_parser.js"
1515
def jsFilesParametersP = "$projectDir/jsFilesParameters.txt"
1616

17-
18-
19-
//def absoluteOutDir = new File("./outDir")//project.outDir
17+
def webpackWorkersExcludePath = "$projectDir/../../src/main/assets/app/__worker-chunks.json"
18+
def webpackWorkersExcludesList = [];
19+
20+
def workersExcludeFile = file(webpackWorkersExcludePath);
21+
if (workersExcludeFile.exists()) {
22+
// in case the file exists but is malformed
23+
try {
24+
webpackWorkersExcludesList = new JsonSlurper().parseText(workersExcludeFile.text)
25+
} catch (all) {
26+
println "Malformed workers exclude file at ${webpackWorkersExcludePath}"
27+
}
28+
}
2029

2130
def absoluteOutDir;
2231
if (project.hasProperty("outDir")) {
@@ -113,10 +122,9 @@ traverseDirectory = { dir, traverseExplicitly ->
113122
}
114123

115124
currentDir.eachFile(FileType.FILES) { File f ->
116-
def file = f.getAbsolutePath();
117-
if (file.substring(file.length() - 3, file.length()).equals(".js")) {
118-
logger.info("Task: traverseDirectory: Visiting JavaScript file: " + f.getName())
119-
inputJsFiles.add(f.getAbsolutePath())
125+
def currFile = f.getAbsolutePath();
126+
if (isJsFile(currFile) && !isWorkerScript(currFile)) {
127+
inputJsFiles.add(currFile)
120128
}
121129
}
122130

@@ -125,6 +133,15 @@ traverseDirectory = { dir, traverseExplicitly ->
125133
}
126134
}
127135

136+
def isJsFile = { fileName -> return fileName.substring(fileName.length() - 3, fileName.length()).equals(".js")
137+
}
138+
139+
def isWorkerScript = { fileName ->
140+
// Read __worker-chunks.json file containing a list of webpacked workers
141+
// ignore worker scripts, so as to not attempt to generate bindings for them
142+
return webpackWorkersExcludesList.any{element -> file(element).getAbsolutePath() == fileName}
143+
}
144+
128145
task traverseJsFilesArgs << { //(jsCodeDir, bindingsFilePath, interfaceNamesFilePath, jsParserPath, jsFilesParameter) {
129146
jsCodeAbsolutePath = jsCodeDir;
130147
inputJsFiles = new LinkedList<String>();

0 commit comments

Comments
 (0)