Skip to content

Commit d4b9beb

Browse files
author
Max Schaefer
committed
JavaScript: Teach autobuilder not to extract node_modules and bower_components folders.
1 parent bd61094 commit d4b9beb

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

change-notes/1.23/extractor-javascript.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55
## Changes to code extraction
66

77
* Asynchronous generator methods are now parsed correctly and no longer cause a spurious syntax error.
8+
* Files in `node_modules` and `bower_components` folders are no longer extracted by default. If you still want to extract files from these folders, you can add the following filters to your `lgtm.yml` file (or add them to existing filters):
9+
10+
```yaml
11+
extraction:
12+
javascript:
13+
index:
14+
filters:
15+
- include: "**/node_modules"
16+
- include: "**/bower_components"
17+
```
18+
819
* Recognition of CommonJS modules has improved. As a result, some files that were previously extracted as
920
global scripts are now extracted as modules.
1021
* Top-level `await` is now supported.

javascript/extractor/src/com/semmle/js/extractor/AutoBuild.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ private void setupFilters() {
387387
patterns.add("-**/*.min.js");
388388
patterns.add("-**/*-min.js");
389389

390+
// exclude `node_modules` and `bower_components`
391+
patterns.add("-**/node_modules");
392+
patterns.add("-**/bower_components");
393+
390394
String base = LGTM_SRC.toString().replace('\\', '/');
391395
// process `$LGTM_INDEX_FILTERS`
392396
for (String pattern : Main.NEWLINE.split(getEnvVar("LGTM_INDEX_FILTERS", ""))) {

javascript/extractor/src/com/semmle/js/extractor/test/AutoBuildTests.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,40 @@ public void minifiedFilesCanBeReIncluded() throws IOException {
483483
runTest();
484484
}
485485

486+
@Test
487+
public void nodeModulesAreExcluded() throws IOException {
488+
addFile(true, LGTM_SRC, "index.js");
489+
addFile(false, LGTM_SRC, "node_modules", "dep", "main.js");
490+
addFile(false, LGTM_SRC, "node_modules", "dep", "node_modules", "leftpad", "index.js");
491+
runTest();
492+
}
493+
494+
@Test
495+
public void nodeModulesCanBeReincluded() throws IOException {
496+
envVars.put("LGTM_INDEX_FILTERS", "include:**/node_modules");
497+
addFile(true, LGTM_SRC, "index.js");
498+
addFile(true, LGTM_SRC, "node_modules", "dep", "main.js");
499+
addFile(true, LGTM_SRC, "node_modules", "dep", "node_modules", "leftpad", "index.js");
500+
runTest();
501+
}
502+
503+
@Test
504+
public void bowerComponentsAreExcluded() throws IOException {
505+
addFile(true, LGTM_SRC, "index.js");
506+
addFile(false, LGTM_SRC, "bower_components", "dep", "main.js");
507+
addFile(false, LGTM_SRC, "bower_components", "dep", "bower_components", "leftpad", "index.js");
508+
runTest();
509+
}
510+
511+
@Test
512+
public void bowerComponentsCanBeReincluded() throws IOException {
513+
envVars.put("LGTM_INDEX_FILTERS", "include:**/bower_components");
514+
addFile(true, LGTM_SRC, "index.js");
515+
addFile(true, LGTM_SRC, "bower_components", "dep", "main.js");
516+
addFile(true, LGTM_SRC, "bower_components", "dep", "bower_components", "leftpad", "index.js");
517+
runTest();
518+
}
519+
486520
@Test
487521
public void customExtensions() throws IOException {
488522
envVars.put("LGTM_INDEX_FILETYPES", ".jsm:js\n.soy:html");

0 commit comments

Comments
 (0)