@openrewrite/rewrite 8.92.15 → 8.92.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/javascript/add-import.d.ts.map +1 -1
  2. package/dist/javascript/add-import.js +3 -2
  3. package/dist/javascript/add-import.js.map +1 -1
  4. package/dist/javascript/amd.d.ts.map +1 -1
  5. package/dist/javascript/amd.js +3 -2
  6. package/dist/javascript/amd.js.map +1 -1
  7. package/dist/javascript/binding.js +3 -3
  8. package/dist/javascript/binding.js.map +1 -1
  9. package/dist/javascript/index.d.ts +3 -0
  10. package/dist/javascript/index.d.ts.map +1 -1
  11. package/dist/javascript/index.js +3 -0
  12. package/dist/javascript/index.js.map +1 -1
  13. package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.d.ts.map +1 -1
  14. package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js +28 -32
  15. package/dist/javascript/migrate/es6/modernize-octal-escape-sequences.js.map +1 -1
  16. package/dist/javascript/preconditions.d.ts +11 -0
  17. package/dist/javascript/preconditions.d.ts.map +1 -1
  18. package/dist/javascript/preconditions.js +14 -0
  19. package/dist/javascript/preconditions.js.map +1 -1
  20. package/dist/javascript/search/index.d.ts +1 -0
  21. package/dist/javascript/search/index.d.ts.map +1 -1
  22. package/dist/javascript/search/index.js +1 -0
  23. package/dist/javascript/search/index.js.map +1 -1
  24. package/dist/javascript/search/is-vendored-or-bundled.d.ts +13 -0
  25. package/dist/javascript/search/is-vendored-or-bundled.d.ts.map +1 -0
  26. package/dist/javascript/search/is-vendored-or-bundled.js +93 -0
  27. package/dist/javascript/search/is-vendored-or-bundled.js.map +1 -0
  28. package/dist/rewrite-javascript-version.txt +1 -1
  29. package/package.json +1 -1
  30. package/src/javascript/add-import.ts +3 -2
  31. package/src/javascript/amd.ts +3 -2
  32. package/src/javascript/binding.ts +3 -3
  33. package/src/javascript/index.ts +3 -0
  34. package/src/javascript/migrate/es6/modernize-octal-escape-sequences.ts +28 -36
  35. package/src/javascript/preconditions.ts +19 -1
  36. package/src/javascript/search/index.ts +1 -0
  37. package/src/javascript/search/is-vendored-or-bundled.ts +59 -0
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import {RecipeRef} from "../preconditions";
17
17
  import {IsSourceFile} from "../search";
18
- import {UsesMethod, UsesType} from "./search";
18
+ import {IsVendoredOrBundled, UsesMethod, UsesType} from "./search";
19
19
 
20
20
  /**
21
21
  * Match source files by path glob.
@@ -40,6 +40,24 @@ export function hasSourcePath(filePattern: string): RecipeRef {
40
40
  );
41
41
  }
42
42
 
43
+ /**
44
+ * Match vendored, bundled and build-output JavaScript and TypeScript sources,
45
+ * typically negated with {@link not} so that a recipe leaves them alone.
46
+ *
47
+ * Returns a {@link RecipeRef} placeholder bundled with a native
48
+ * {@link IsVendoredOrBundled} visitor for in-process evaluation; see
49
+ * {@link hasSourcePath} for the introspection / lazy-evaluation pattern.
50
+ *
51
+ * Delegates to {@code org.openrewrite.javascript.search.FindVendoredOrBundled}.
52
+ */
53
+ export function isVendoredOrBundled(): RecipeRef {
54
+ return new RecipeRef(
55
+ "org.openrewrite.javascript.search.FindVendoredOrBundled",
56
+ {},
57
+ new IsVendoredOrBundled(),
58
+ );
59
+ }
60
+
43
61
  /**
44
62
  * Match files using a specific method.
45
63
  *
@@ -1,6 +1,7 @@
1
1
  import {CategoryDescriptor, JavaScript} from "../../marketplace";
2
2
 
3
3
  export * from './find-dependency';
4
+ export * from './is-vendored-or-bundled';
4
5
  export * from './uses-method';
5
6
  export * from './uses-type';
6
7
 
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Copyright 2026 the original author or authors.
3
+ * <p>
4
+ * Licensed under the Moderne Source Available License (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ * <p>
8
+ * https://docs.moderne.io/licensing/moderne-source-available-license
9
+ * <p>
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import * as picomatch from "picomatch";
17
+ import {ExecutionContext} from "../../execution";
18
+ import {TreeVisitor} from "../../visitor";
19
+ import {foundSearchResult} from "../../markers";
20
+ import {J, TextComment} from "../../java";
21
+ import {JS} from "../tree";
22
+
23
+ const PATH_PATTERNS = [
24
+ "**/node_modules/**",
25
+ "**/bower_components/**",
26
+ "**/vendor/**",
27
+ "**/dist/**",
28
+ "**/*.min.*",
29
+ "**/*.bundle.*"
30
+ ];
31
+
32
+ const SOURCE_MAPPING_URL = /^[#@] sourceMappingURL=/;
33
+
34
+ /**
35
+ * Marks JavaScript and TypeScript sources that are vendored, bundled or build output.
36
+ * In-process counterpart of {@code org.openrewrite.javascript.search.FindVendoredOrBundled};
37
+ * keep the two in sync.
38
+ */
39
+ export class IsVendoredOrBundled extends TreeVisitor<any, ExecutionContext> {
40
+ private readonly matcher: picomatch.Matcher =
41
+ picomatch.default ? picomatch.default(PATH_PATTERNS) : (picomatch as any)(PATH_PATTERNS);
42
+
43
+ protected async preVisit(tree: any, _: ExecutionContext): Promise<any> {
44
+ this.stopAfterPreVisit();
45
+ if (tree.kind === JS.Kind.CompilationUnit && this.isVendoredOrBundled(tree as JS.CompilationUnit)) {
46
+ return foundSearchResult(tree);
47
+ }
48
+ return tree;
49
+ }
50
+
51
+ private isVendoredOrBundled(cu: JS.CompilationUnit): boolean {
52
+ if (this.matcher(cu.sourcePath.replace(/\\/g, '/'))) {
53
+ return true;
54
+ }
55
+ const comments = cu.eof.comments;
56
+ const last = comments[comments.length - 1];
57
+ return last?.kind === J.Kind.TextComment && SOURCE_MAPPING_URL.test((last as TextComment).text.trim());
58
+ }
59
+ }