@openrewrite/recipes-nodejs 0.60.0 → 0.62.0

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 (157) hide show
  1. package/dist/index.d.ts +7 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +70 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/migrate/config-object-support.d.ts +8 -0
  6. package/dist/migrate/config-object-support.d.ts.map +1 -0
  7. package/dist/migrate/config-object-support.js +46 -0
  8. package/dist/migrate/config-object-support.js.map +1 -0
  9. package/dist/migrate/cypress/cypress-13.d.ts +20 -0
  10. package/dist/migrate/cypress/cypress-13.d.ts.map +1 -0
  11. package/dist/migrate/cypress/cypress-13.js +108 -0
  12. package/dist/migrate/cypress/cypress-13.js.map +1 -0
  13. package/dist/migrate/cypress/cypress-14.d.ts +27 -0
  14. package/dist/migrate/cypress/cypress-14.d.ts.map +1 -0
  15. package/dist/migrate/cypress/cypress-14.js +203 -0
  16. package/dist/migrate/cypress/cypress-14.js.map +1 -0
  17. package/dist/migrate/cypress/cypress-15.d.ts +26 -0
  18. package/dist/migrate/cypress/cypress-15.d.ts.map +1 -0
  19. package/dist/migrate/cypress/cypress-15.js +151 -0
  20. package/dist/migrate/cypress/cypress-15.js.map +1 -0
  21. package/dist/migrate/cypress/cypress-support.d.ts +10 -0
  22. package/dist/migrate/cypress/cypress-support.d.ts.map +1 -0
  23. package/dist/migrate/cypress/cypress-support.js +115 -0
  24. package/dist/migrate/cypress/cypress-support.js.map +1 -0
  25. package/dist/migrate/express5/express-support.d.ts +6 -0
  26. package/dist/migrate/express5/express-support.d.ts.map +1 -0
  27. package/dist/migrate/express5/express-support.js +41 -0
  28. package/dist/migrate/express5/express-support.js.map +1 -0
  29. package/dist/migrate/express5/migrate-route-wildcards.d.ts +10 -0
  30. package/dist/migrate/express5/migrate-route-wildcards.d.ts.map +1 -0
  31. package/dist/migrate/express5/migrate-route-wildcards.js +146 -0
  32. package/dist/migrate/express5/migrate-route-wildcards.js.map +1 -0
  33. package/dist/migrate/express5/replace-removed-express-apis.d.ts +9 -0
  34. package/dist/migrate/express5/replace-removed-express-apis.d.ts.map +1 -0
  35. package/dist/migrate/express5/replace-removed-express-apis.js +105 -0
  36. package/dist/migrate/express5/replace-removed-express-apis.js.map +1 -0
  37. package/dist/migrate/fastify4/find-removed-fastify-4-options.d.ts +9 -0
  38. package/dist/migrate/fastify4/find-removed-fastify-4-options.d.ts.map +1 -0
  39. package/dist/migrate/fastify4/find-removed-fastify-4-options.js +60 -0
  40. package/dist/migrate/fastify4/find-removed-fastify-4-options.js.map +1 -0
  41. package/dist/migrate/fastify5/replace-removed-fastify-apis.d.ts +9 -0
  42. package/dist/migrate/fastify5/replace-removed-fastify-apis.d.ts.map +1 -0
  43. package/dist/migrate/fastify5/replace-removed-fastify-apis.js +107 -0
  44. package/dist/migrate/fastify5/replace-removed-fastify-apis.js.map +1 -0
  45. package/dist/migrate/handler-support.d.ts +10 -0
  46. package/dist/migrate/handler-support.d.ts.map +1 -0
  47. package/dist/migrate/handler-support.js +62 -0
  48. package/dist/migrate/handler-support.js.map +1 -0
  49. package/dist/migrate/storybook/migrate-storybook-9-addons.d.ts +8 -0
  50. package/dist/migrate/storybook/migrate-storybook-9-addons.d.ts.map +1 -0
  51. package/dist/migrate/storybook/migrate-storybook-9-addons.js +163 -0
  52. package/dist/migrate/storybook/migrate-storybook-9-addons.js.map +1 -0
  53. package/dist/migrate/storybook/migrate-storybook-9-imports.d.ts +14 -0
  54. package/dist/migrate/storybook/migrate-storybook-9-imports.d.ts.map +1 -0
  55. package/dist/migrate/storybook/migrate-storybook-9-imports.js +160 -0
  56. package/dist/migrate/storybook/migrate-storybook-9-imports.js.map +1 -0
  57. package/dist/migrate/storybook/storybook-10.d.ts +14 -0
  58. package/dist/migrate/storybook/storybook-10.d.ts.map +1 -0
  59. package/dist/migrate/storybook/storybook-10.js +242 -0
  60. package/dist/migrate/storybook/storybook-10.js.map +1 -0
  61. package/dist/migrate/storybook/storybook-7.d.ts +21 -0
  62. package/dist/migrate/storybook/storybook-7.d.ts.map +1 -0
  63. package/dist/migrate/storybook/storybook-7.js +217 -0
  64. package/dist/migrate/storybook/storybook-7.js.map +1 -0
  65. package/dist/migrate/storybook/storybook-9-packages.d.ts +5 -0
  66. package/dist/migrate/storybook/storybook-9-packages.d.ts.map +1 -0
  67. package/dist/migrate/storybook/storybook-9-packages.js +12 -0
  68. package/dist/migrate/storybook/storybook-9-packages.js.map +1 -0
  69. package/dist/migrate/vite/find-vite-changes.d.ts +42 -0
  70. package/dist/migrate/vite/find-vite-changes.d.ts.map +1 -0
  71. package/dist/migrate/vite/find-vite-changes.js +133 -0
  72. package/dist/migrate/vite/find-vite-changes.js.map +1 -0
  73. package/dist/migrate/vite/migrate-vite-config.d.ts +26 -0
  74. package/dist/migrate/vite/migrate-vite-config.d.ts.map +1 -0
  75. package/dist/migrate/vite/migrate-vite-config.js +165 -0
  76. package/dist/migrate/vite/migrate-vite-config.js.map +1 -0
  77. package/dist/migrate/vite/vite-config-support.d.ts +15 -0
  78. package/dist/migrate/vite/vite-config-support.d.ts.map +1 -0
  79. package/dist/migrate/vite/vite-config-support.js +78 -0
  80. package/dist/migrate/vite/vite-config-support.js.map +1 -0
  81. package/dist/migrate/vue/find-vue-3-removed-apis.d.ts +8 -0
  82. package/dist/migrate/vue/find-vue-3-removed-apis.d.ts.map +1 -0
  83. package/dist/migrate/vue/find-vue-3-removed-apis.js +90 -0
  84. package/dist/migrate/vue/find-vue-3-removed-apis.js.map +1 -0
  85. package/dist/migrate/vue/migrate-new-vue-to-create-app.d.ts +8 -0
  86. package/dist/migrate/vue/migrate-new-vue-to-create-app.d.ts.map +1 -0
  87. package/dist/migrate/vue/migrate-new-vue-to-create-app.js +167 -0
  88. package/dist/migrate/vue/migrate-new-vue-to-create-app.js.map +1 -0
  89. package/dist/migrate/vue/migrate-vue-router-catch-all-routes.d.ts +8 -0
  90. package/dist/migrate/vue/migrate-vue-router-catch-all-routes.d.ts.map +1 -0
  91. package/dist/migrate/vue/migrate-vue-router-catch-all-routes.js +65 -0
  92. package/dist/migrate/vue/migrate-vue-router-catch-all-routes.js.map +1 -0
  93. package/dist/migrate/vue/migrate-vue-router-constructor.d.ts +8 -0
  94. package/dist/migrate/vue/migrate-vue-router-constructor.d.ts.map +1 -0
  95. package/dist/migrate/vue/migrate-vue-router-constructor.js +144 -0
  96. package/dist/migrate/vue/migrate-vue-router-constructor.js.map +1 -0
  97. package/dist/migrate/vue/rename-vue-destroy-hooks.d.ts +8 -0
  98. package/dist/migrate/vue/rename-vue-destroy-hooks.d.ts.map +1 -0
  99. package/dist/migrate/vue/rename-vue-destroy-hooks.js +82 -0
  100. package/dist/migrate/vue/rename-vue-destroy-hooks.js.map +1 -0
  101. package/dist/migrate/vue/vue-support.d.ts +23 -0
  102. package/dist/migrate/vue/vue-support.d.ts.map +1 -0
  103. package/dist/migrate/vue/vue-support.js +97 -0
  104. package/dist/migrate/vue/vue-support.js.map +1 -0
  105. package/dist/migrate/webpack5/asset-modules.d.ts +10 -0
  106. package/dist/migrate/webpack5/asset-modules.d.ts.map +1 -0
  107. package/dist/migrate/webpack5/asset-modules.js +100 -0
  108. package/dist/migrate/webpack5/asset-modules.js.map +1 -0
  109. package/dist/migrate/webpack5/find-webpack-5-manual-migrations.d.ts +9 -0
  110. package/dist/migrate/webpack5/find-webpack-5-manual-migrations.d.ts.map +1 -0
  111. package/dist/migrate/webpack5/find-webpack-5-manual-migrations.js +107 -0
  112. package/dist/migrate/webpack5/find-webpack-5-manual-migrations.js.map +1 -0
  113. package/dist/migrate/webpack5/node-polyfills.d.ts +9 -0
  114. package/dist/migrate/webpack5/node-polyfills.d.ts.map +1 -0
  115. package/dist/migrate/webpack5/node-polyfills.js +85 -0
  116. package/dist/migrate/webpack5/node-polyfills.js.map +1 -0
  117. package/dist/migrate/webpack5/update-optimization-options.d.ts +9 -0
  118. package/dist/migrate/webpack5/update-optimization-options.d.ts.map +1 -0
  119. package/dist/migrate/webpack5/update-optimization-options.js +106 -0
  120. package/dist/migrate/webpack5/update-optimization-options.js.map +1 -0
  121. package/dist/migrate/webpack5/webpack-config-support.d.ts +13 -0
  122. package/dist/migrate/webpack5/webpack-config-support.d.ts.map +1 -0
  123. package/dist/migrate/webpack5/webpack-config-support.js +92 -0
  124. package/dist/migrate/webpack5/webpack-config-support.js.map +1 -0
  125. package/dist/resources/advisories-npm.csv +40 -26
  126. package/package.json +4 -3
  127. package/src/index.ts +69 -0
  128. package/src/migrate/config-object-support.ts +55 -0
  129. package/src/migrate/cypress/cypress-13.ts +70 -0
  130. package/src/migrate/cypress/cypress-14.ts +147 -0
  131. package/src/migrate/cypress/cypress-15.ts +98 -0
  132. package/src/migrate/cypress/cypress-support.ts +100 -0
  133. package/src/migrate/express5/express-support.ts +43 -0
  134. package/src/migrate/express5/migrate-route-wildcards.ts +111 -0
  135. package/src/migrate/express5/replace-removed-express-apis.ts +86 -0
  136. package/src/migrate/fastify4/find-removed-fastify-4-options.ts +39 -0
  137. package/src/migrate/fastify5/replace-removed-fastify-apis.ts +94 -0
  138. package/src/migrate/handler-support.ts +64 -0
  139. package/src/migrate/storybook/migrate-storybook-9-addons.ts +126 -0
  140. package/src/migrate/storybook/migrate-storybook-9-imports.ts +122 -0
  141. package/src/migrate/storybook/storybook-10.ts +180 -0
  142. package/src/migrate/storybook/storybook-7.ts +177 -0
  143. package/src/migrate/storybook/storybook-9-packages.ts +18 -0
  144. package/src/migrate/vite/find-vite-changes.ts +130 -0
  145. package/src/migrate/vite/migrate-vite-config.ts +123 -0
  146. package/src/migrate/vite/vite-config-support.ts +71 -0
  147. package/src/migrate/vue/find-vue-3-removed-apis.ts +63 -0
  148. package/src/migrate/vue/migrate-new-vue-to-create-app.ts +160 -0
  149. package/src/migrate/vue/migrate-vue-router-catch-all-routes.ts +50 -0
  150. package/src/migrate/vue/migrate-vue-router-constructor.ts +116 -0
  151. package/src/migrate/vue/rename-vue-destroy-hooks.ts +57 -0
  152. package/src/migrate/vue/vue-support.ts +115 -0
  153. package/src/migrate/webpack5/asset-modules.ts +77 -0
  154. package/src/migrate/webpack5/find-webpack-5-manual-migrations.ts +76 -0
  155. package/src/migrate/webpack5/node-polyfills.ts +73 -0
  156. package/src/migrate/webpack5/update-optimization-options.ts +84 -0
  157. package/src/migrate/webpack5/webpack-config-support.ts +98 -0
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MigrateVueRouterCatchAllRoutes = void 0;
13
+ const rewrite_1 = require("@openrewrite/rewrite");
14
+ const javascript_1 = require("@openrewrite/rewrite/javascript");
15
+ const java_1 = require("@openrewrite/rewrite/java");
16
+ const module_bindings_1 = require("../module-bindings");
17
+ const vue_support_1 = require("./vue-support");
18
+ const CATCH_ALL = ":pathMatch(.*)*";
19
+ const CATCH_ALL_PATHS = new Set(["*", "/*"]);
20
+ const PATH = new Set(["path"]);
21
+ const ROUTE_KEYS = new Set(["component", "components", "redirect", "children", "name", "beforeEnter", "meta"]);
22
+ class MigrateVueRouterCatchAllRoutes extends rewrite_1.Recipe {
23
+ constructor() {
24
+ super(...arguments);
25
+ this.name = "org.openrewrite.nodejs.migrate.vue.MigrateVueRouterCatchAllRoutes";
26
+ this.displayName = "Migrate `*` catch-all routes to `/:pathMatch(.*)*`";
27
+ this.description = "Vue Router 4 no longer accepts `*` as a path. Rewrites the route record paths `'*'` and `'/*'` " +
28
+ "to the custom regular expression parameter `'/:pathMatch(.*)*'` that the Vue Router 4 migration guide gives for them. Only an " +
29
+ "object literal that also has a route record property (`component`, `components`, `redirect`, `children`, `name`, " +
30
+ "`beforeEnter` or `meta`) is changed. A catch-all that is a child route (an entry of `children`) becomes the relative " +
31
+ "`':pathMatch(.*)*'`, which keeps matching under its parent as `*` did, because a leading slash would make it an absolute " +
32
+ "path; the guide does not cover children, so that follows from how Vue Router resolves child paths. Prefix wildcards such " +
33
+ "as `/user-*` are left as they are.";
34
+ }
35
+ editor() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return new class extends javascript_1.JavaScriptVisitor {
38
+ visitNewClass(newClass, p) {
39
+ const _super = Object.create(null, {
40
+ visitNewClass: { get: () => super.visitNewClass }
41
+ });
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const n = yield _super.visitNewClass.call(this, newClass, p);
44
+ if (!(0, vue_support_1.hasKey)(n, PATH))
45
+ return n;
46
+ const props = (0, vue_support_1.propertiesOf)(n);
47
+ const path = props === null || props === void 0 ? void 0 : props.find(prop => prop.key === "path");
48
+ const literal = (path === null || path === void 0 ? void 0 : path.tree.kind) === javascript_1.JS.Kind.PropertyAssignment ? path.value : undefined;
49
+ const value = (0, module_bindings_1.stringLiteral)(literal);
50
+ if (!props || !path || value === undefined || !CATCH_ALL_PATHS.has(value)
51
+ || !props.some(prop => ROUTE_KEYS.has(prop.key)))
52
+ return n;
53
+ const property = this.cursor.firstEnclosing((t) => (t === null || t === void 0 ? void 0 : t.kind) === javascript_1.JS.Kind.PropertyAssignment);
54
+ const key = property === null || property === void 0 ? void 0 : property.name.element;
55
+ const child = !!key && (0, java_1.isIdentifier)(key) ? key.simpleName === "children" : (0, module_bindings_1.stringLiteral)(key) === "children";
56
+ const replacement = (0, javascript_1.withStringValue)(literal, child ? CATCH_ALL : "/" + CATCH_ALL);
57
+ return (0, vue_support_1.replaceMember)(n, path.tree, Object.assign(Object.assign({}, path.tree), { initializer: replacement }));
58
+ });
59
+ }
60
+ };
61
+ });
62
+ }
63
+ }
64
+ exports.MigrateVueRouterCatchAllRoutes = MigrateVueRouterCatchAllRoutes;
65
+ //# sourceMappingURL=migrate-vue-router-catch-all-routes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-vue-router-catch-all-routes.js","sourceRoot":"","sources":["../../../src/migrate/vue/migrate-vue-router-catch-all-routes.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,kDAA2E;AAC3E,gEAAuF;AACvF,oDAA0D;AAC1D,wDAAiD;AACjD,+CAAkE;AAGlE,MAAM,SAAS,GAAG,iBAAiB,CAAC;AACpC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;AAE7C,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC;AAE/G,MAAa,8BAA+B,SAAQ,gBAAM;IAA1D;;QACa,SAAI,GAAG,mEAAmE,CAAC;QAC3E,gBAAW,GAAW,oDAAoD,CAAC;QAC3E,gBAAW,GAAW,iGAAiG;YAC5H,gIAAgI;YAChI,mHAAmH;YACnH,uHAAuH;YACvH,2HAA2H;YAC3H,2HAA2H;YAC3H,oCAAoC,CAAC;IAsB7C,CAAC;IApBS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACxC,aAAa,CAAC,QAAoB,EAAE,CAAmB;;;;;wBACnE,MAAM,CAAC,GAAG,MAAM,OAAM,aAAa,YAAC,QAAQ,EAAE,CAAC,CAAe,CAAC;wBAC/D,IAAI,CAAC,IAAA,oBAAM,EAAC,CAAC,EAAE,IAAI,CAAC;4BAAE,OAAO,CAAC,CA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AAA,4BAAe,EAAC,OAAoB,EAAE,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC;wBAC/F,OAAO,IAAA,2BAAa,EAAC,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,gCAAI,IAAI,CAAC,IAAI,KAAE,WAAW,EAAE,WAAW,GAA0B,CAAC,CAAC;oBAC1G,CAAC;iBAAA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AA/BD,wEA+BC"}
@@ -0,0 +1,8 @@
1
+ import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
2
+ export declare class MigrateVueRouterConstructor extends Recipe {
3
+ readonly name = "org.openrewrite.nodejs.migrate.vue.MigrateVueRouterConstructor";
4
+ readonly displayName: string;
5
+ readonly description: string;
6
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
7
+ }
8
+ //# sourceMappingURL=migrate-vue-router-constructor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-vue-router-constructor.d.ts","sourceRoot":"","sources":["../../../src/migrate/vue/migrate-vue-router-constructor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAS,gBAAgB,EAAqB,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAgBtG,qBAAa,2BAA4B,SAAQ,MAAM;IACnD,QAAQ,CAAC,IAAI,oEAAoE;IACjF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAmD;IAC/E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAK0N;IAEhP,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAoF9D"}
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MigrateVueRouterConstructor = void 0;
13
+ const rewrite_1 = require("@openrewrite/rewrite");
14
+ const javascript_1 = require("@openrewrite/rewrite/javascript");
15
+ const java_1 = require("@openrewrite/rewrite/java");
16
+ const handler_support_1 = require("../handler-support");
17
+ const module_bindings_1 = require("../module-bindings");
18
+ const vue_support_1 = require("./vue-support");
19
+ const HISTORY = {
20
+ history: "createWebHistory",
21
+ hash: "createWebHashHistory",
22
+ abstract: "createMemoryHistory",
23
+ };
24
+ const KEPT_OPTIONS = new Set(["routes", "scrollBehavior", "linkActiveClass", "linkExactActiveClass", "strict", "sensitive"]);
25
+ class MigrateVueRouterConstructor extends rewrite_1.Recipe {
26
+ constructor() {
27
+ super(...arguments);
28
+ this.name = "org.openrewrite.nodejs.migrate.vue.MigrateVueRouterConstructor";
29
+ this.displayName = "Migrate `new VueRouter()` to `createRouter()`";
30
+ this.description = "Vue Router 4 is no longer a class. Rewrites `new VueRouter({mode, base, routes})` to " +
31
+ "`createRouter({history: createWebHistory(base), routes})`, mapping `mode` `'history'`, `'hash'` and `'abstract'` to " +
32
+ "`createWebHistory`, `createWebHashHistory` and `createMemoryHistory` (no `mode` was the default `'hash'`) and passing `base` " +
33
+ "to it, and removes the `Vue.use(VueRouter)` call that Vue Router 4 replaces with `app.use(router)`. Only a file that " +
34
+ "imports `VueRouter` with an ES import is rewritten, and a `new VueRouter` with options other than `mode`, `base`, `routes`, " +
35
+ "`scrollBehavior`, `linkActiveClass`, `linkExactActiveClass`, `strict` and `sensitive` is left as it is. The `fallback` option, which Vue Router 4 removed, is dropped. Other uses of `VueRouter` such as `VueRouter.prototype.push` are marked.";
36
+ }
37
+ editor() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ return new class extends javascript_1.JavaScriptVisitor {
40
+ constructor() {
41
+ super(...arguments);
42
+ this.converted = false;
43
+ this.aliases = new Map();
44
+ }
45
+ localName(member) {
46
+ const { local, alias } = (0, vue_support_1.importName)(member, (0, javascript_1.compilationUnitOf)(this));
47
+ if (alias)
48
+ this.aliases.set(member, alias);
49
+ return local;
50
+ }
51
+ visitJsCompilationUnit(cu, p) {
52
+ const _super = Object.create(null, {
53
+ visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
54
+ });
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const isRouter = (m) => m === "vue-router";
57
+ if (!(0, handler_support_1.importsModule)(cu, isRouter) || (0, handler_support_1.requiresModule)(cu, isRouter))
58
+ return cu;
59
+ const names = (0, vue_support_1.wholeModuleBindings)(cu, "vue-router");
60
+ if (names.size !== 1)
61
+ return cu;
62
+ [this.router] = names;
63
+ this.converted = false;
64
+ this.aliases = new Map();
65
+ const result = yield _super.visitJsCompilationUnit.call(this, cu, p);
66
+ if (!this.converted)
67
+ return result;
68
+ const statements = result.statements.filter(s => !this.isUseOfRouter(s.element));
69
+ (0, javascript_1.maybeRemoveImport)(this, "vue-router", this.router);
70
+ for (const vue of (0, vue_support_1.wholeModuleBindings)(cu, "vue"))
71
+ (0, javascript_1.maybeRemoveImport)(this, "vue", vue);
72
+ return statements.length === result.statements.length ? result : Object.assign(Object.assign({}, result), { statements });
73
+ });
74
+ }
75
+ isUseOfRouter(e) {
76
+ return (e === null || e === void 0 ? void 0 : e.kind) === java_1.J.Kind.MethodInvocation && e.name.simpleName === "use" && !!e.select
77
+ && (0, java_1.isIdentifier)(e.select.element) && e.arguments.elements.length === 1
78
+ && (0, java_1.isIdentifier)(e.arguments.elements[0].element) && e.arguments.elements[0].element.simpleName === this.router;
79
+ }
80
+ visitFieldAccess(fieldAccess, p) {
81
+ const _super = Object.create(null, {
82
+ visitFieldAccess: { get: () => super.visitFieldAccess }
83
+ });
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ const f = yield _super.visitFieldAccess.call(this, fieldAccess, p);
86
+ return this.router && (0, java_1.isIdentifier)(f.target) && f.target.simpleName === this.router
87
+ ? (0, rewrite_1.foundSearchResult)(f, "Vue Router 4 exports no `VueRouter` class; patch `router.push` on the router instance instead, or use navigation guards.")
88
+ : f;
89
+ });
90
+ }
91
+ visitNewClass(newClass, p) {
92
+ const _super = Object.create(null, {
93
+ visitNewClass: { get: () => super.visitNewClass }
94
+ });
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ const n = yield _super.visitNewClass.call(this, newClass, p);
97
+ if (!this.router || !n.class || !(0, java_1.isIdentifier)(n.class) || n.class.simpleName !== this.router
98
+ || n.arguments.elements.length !== 1)
99
+ return n;
100
+ const props = (0, vue_support_1.propertiesOf)(n.arguments.elements[0].element);
101
+ if (!props)
102
+ return n;
103
+ let mode = "hash", base;
104
+ const kept = [];
105
+ for (const prop of props) {
106
+ if (prop.key === "mode" && prop.value) {
107
+ const value = (0, module_bindings_1.stringLiteral)(prop.value);
108
+ if (value === undefined || !HISTORY[value])
109
+ return n;
110
+ mode = value;
111
+ }
112
+ else if (prop.key === "fallback") {
113
+ continue;
114
+ }
115
+ else if (prop.key === "base" && prop.value) {
116
+ base = prop.value;
117
+ }
118
+ else if (KEPT_OPTIONS.has(prop.key)) {
119
+ kept.push(prop.tree);
120
+ }
121
+ else {
122
+ return n;
123
+ }
124
+ }
125
+ const historyMember = HISTORY[mode];
126
+ const history = this.localName(historyMember);
127
+ const create = this.localName("createRouter");
128
+ const cursor = new rewrite_1.Cursor(n, this.cursor);
129
+ const args = base ? [base] : [];
130
+ const result = yield (0, javascript_1.template) `${(0, javascript_1.raw)(create)}({history: ${(0, javascript_1.raw)(history)}(${args}), ${kept}})`.apply(n, cursor);
131
+ if (!result)
132
+ return n;
133
+ this.converted = true;
134
+ (0, javascript_1.maybeAddImport)(this, { module: "vue-router", member: "createRouter", alias: this.aliases.get("createRouter"), onlyIfReferenced: false });
135
+ (0, javascript_1.maybeAddImport)(this, { module: "vue-router", member: historyMember, alias: this.aliases.get(historyMember), onlyIfReferenced: false });
136
+ return result;
137
+ });
138
+ }
139
+ };
140
+ });
141
+ }
142
+ }
143
+ exports.MigrateVueRouterConstructor = MigrateVueRouterConstructor;
144
+ //# sourceMappingURL=migrate-vue-router-constructor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-vue-router-constructor.js","sourceRoot":"","sources":["../../../src/migrate/vue/migrate-vue-router-constructor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,kDAAsG;AACtG,gEAA2I;AAC3I,oDAAsE;AACtE,wDAAiE;AACjE,wDAAiD;AACjD,+CAA4E;AAG5E,MAAM,OAAO,GAAqC;IAC9C,OAAO,EAAE,kBAAkB;IAC3B,IAAI,EAAE,sBAAsB;IAC5B,QAAQ,EAAE,qBAAqB;CAClC,CAAC;AAEF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;AAE7H,MAAa,2BAA4B,SAAQ,gBAAM;IAAvD;;QACa,SAAI,GAAG,gEAAgE,CAAC;QACxE,gBAAW,GAAW,+CAA+C,CAAC;QACtE,gBAAW,GAAW,uFAAuF;YAClH,sHAAsH;YACtH,+HAA+H;YAC/H,uHAAuH;YACvH,8HAA8H;YAC9H,iPAAiP,CAAC;IAsF1P,CAAC;IApFS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBAAjD;;oBAEC,cAAS,GAAG,KAAK,CAAC;oBAClB,YAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;gBA8EhD,CAAC;gBA3EW,SAAS,CAAC,MAAc;oBAC5B,MAAM,EAAC,KAAK,EAAE,KAAK,EAAC,GAAG,IAAA,wBAAU,EAAC,MAAM,E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AA;aACJ,CAAC;QACN,CAAC;KAAA;CACJ;AA9FD,kEA8FC"}
@@ -0,0 +1,8 @@
1
+ import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
2
+ export declare class RenameVueDestroyHooks extends Recipe {
3
+ readonly name = "org.openrewrite.nodejs.migrate.vue.RenameVueDestroyHooks";
4
+ readonly displayName: string;
5
+ readonly description: string;
6
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
7
+ }
8
+ //# sourceMappingURL=rename-vue-destroy-hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rename-vue-destroy-hooks.d.ts","sourceRoot":"","sources":["../../../src/migrate/vue/rename-vue-destroy-hooks.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,gBAAgB,EAAqB,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAS9F,qBAAa,qBAAsB,SAAQ,MAAM;IAC7C,QAAQ,CAAC,IAAI,8DAA8D;IAC3E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA0D;IACtF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAG8F;IAEpH,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAkC9D"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RenameVueDestroyHooks = void 0;
13
+ const rewrite_1 = require("@openrewrite/rewrite");
14
+ const javascript_1 = require("@openrewrite/rewrite/javascript");
15
+ const java_1 = require("@openrewrite/rewrite/java");
16
+ const vue_support_1 = require("./vue-support");
17
+ const RENAMES = { beforeDestroy: "beforeUnmount", destroyed: "unmounted" };
18
+ const HOOKS = new Set(Object.keys(RENAMES));
19
+ class RenameVueDestroyHooks extends rewrite_1.Recipe {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.name = "org.openrewrite.nodejs.migrate.vue.RenameVueDestroyHooks";
23
+ this.displayName = "Rename the `beforeDestroy` and `destroyed` Vue hooks";
24
+ this.description = "Vue 3 renamed the `beforeDestroy` lifecycle option to `beforeUnmount` and `destroyed` to " +
25
+ "`unmounted`. Renames them in an object literal that also has a Vue component option such as `data`, `methods`, `computed`, " +
26
+ "`props`, `components`, `created` or `mounted`, in a file that imports `vue` or in the object that a file exports by default; " +
27
+ "any other object is left as it is. A shorthand hook (`{data, destroyed}`) cannot be renamed in place and is marked.";
28
+ }
29
+ editor() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return new class extends javascript_1.JavaScriptVisitor {
32
+ constructor() {
33
+ super(...arguments);
34
+ this.vueFile = false;
35
+ }
36
+ visitJsCompilationUnit(cu, p) {
37
+ const _super = Object.create(null, {
38
+ visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
39
+ });
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ this.vueFile = (0, vue_support_1.mentionsVue)(cu);
42
+ return this.vueFile || (0, vue_support_1.hasDefaultExport)(cu) ? _super.visitJsCompilationUnit.call(this, cu, p) : cu;
43
+ });
44
+ }
45
+ visitNewClass(newClass, p) {
46
+ const _super = Object.create(null, {
47
+ visitNewClass: { get: () => super.visitNewClass }
48
+ });
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const n = yield _super.visitNewClass.call(this, newClass, p);
51
+ if (!(0, vue_support_1.hasKey)(n, HOOKS) || !(this.vueFile || (0, vue_support_1.isDefaultExported)(this.cursor, newClass)))
52
+ return n;
53
+ const props = (0, vue_support_1.propertiesOf)(n, true);
54
+ if (!(0, vue_support_1.isComponentOptions)(props))
55
+ return n;
56
+ let result = n;
57
+ for (const prop of props) {
58
+ if (!RENAMES[prop.key])
59
+ continue;
60
+ const e = prop.tree;
61
+ if (e.kind === java_1.J.Kind.MethodDeclaration) {
62
+ result = (0, vue_support_1.replaceMember)(result, e, Object.assign(Object.assign({}, e), { name: Object.assign(Object.assign({}, e.name), { simpleName: RENAMES[prop.key] }) }));
63
+ }
64
+ else if (e.initializer && (0, java_1.isIdentifier)(e.name.element)) {
65
+ const key = e.name.element;
66
+ result = (0, vue_support_1.replaceMember)(result, e, Object.assign(Object.assign({}, e), { name: Object.assign(Object.assign({}, e.name), { element: Object.assign(Object.assign({}, key), { simpleName: RENAMES[prop.key] }) }) }));
67
+ }
68
+ else if (!e.initializer) {
69
+ const marked = (0, rewrite_1.foundSearchResult)(e, `Rename the \`${prop.key}\` shorthand to \`${RENAMES[prop.key]}: ${prop.key}\`: Vue 3 renamed the hook.`);
70
+ if (marked !== e)
71
+ result = (0, vue_support_1.replaceMember)(result, e, marked);
72
+ }
73
+ }
74
+ return result;
75
+ });
76
+ }
77
+ };
78
+ });
79
+ }
80
+ }
81
+ exports.RenameVueDestroyHooks = RenameVueDestroyHooks;
82
+ //# sourceMappingURL=rename-vue-destroy-hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rename-vue-destroy-hooks.js","sourceRoot":"","sources":["../../../src/migrate/vue/rename-vue-destroy-hooks.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,kDAA8F;AAC9F,gEAAsE;AACtE,oDAA0D;AAC1D,+CAAwI;AAGxI,MAAM,OAAO,GAAqC,EAAC,aAAa,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,EAAC,CAAC;AAC3G,MAAM,KAAK,GAAwB,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;AAEjE,MAA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rite/java";
3
+ import { JS } from "@openrewrite/rewrite/javascript";
4
+ export declare function wholeModuleBindings(cu: JS.CompilationUnit, module: string): Set<string>;
5
+ export declare function mentionsVue(cu: JS.CompilationUnit): boolean;
6
+ export declare function importsEsModule(cu: JS.CompilationUnit, module: string): boolean;
7
+ export declare function hasDefaultExport(cu: JS.CompilationUnit): boolean;
8
+ export declare function isDefaultExported(cursor: Cursor, object: J): boolean;
9
+ export declare function hasKey(e: J, keys: ReadonlySet<string>): boolean;
10
+ export declare function replaceMember(object: J.NewClass, old: J, replacement: J): J.NewClass;
11
+ export interface Property {
12
+ readonly key: string;
13
+ readonly tree: JS.PropertyAssignment | J.MethodDeclaration;
14
+ readonly value?: Expression;
15
+ }
16
+ export declare function propertiesOf(e: J | undefined, skipSpread?: boolean): Property[] | undefined;
17
+ export declare const COMPONENT_OPTIONS: ReadonlySet<string>;
18
+ export declare function isComponentOptions(properties: readonly Property[] | undefined): boolean;
19
+ export declare function importName(member: string, cu: JS.CompilationUnit): {
20
+ local: string;
21
+ alias?: string;
22
+ };
23
+ //# sourceMappingURL=vue-support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue-support.d.ts","sourceRoot":"","sources":["../../../src/migrate/vue/vue-support.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAC,UAAU,EAAgB,CAAC,EAAC,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAA8B,EAAE,EAAkB,MAAM,iCAAiC,CAAC;AAYjG,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAMvF;AAGD,wBAAgB,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,GAAG,OAAO,CAE3D;AAGD,wBAAgB,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,MAA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mentionsVue;
6
+ exports.importsEsModule = importsEsModule;
7
+ exports.hasDefaultExport = hasDefaultExport;
8
+ exports.isDefaultExported = isDefaultExported;
9
+ exports.hasKey = hasKey;
10
+ exports.replaceMember = replaceMember;
11
+ exports.propertiesOf = propertiesOf;
12
+ exports.isComponentOptions = isComponentOptions;
13
+ exports.importName = importName;
14
+ const java_1 = require("@openrewrite/rewrite/java");
15
+ const javascript_1 = require("@openrewrite/rewrite/javascript");
16
+ const handler_support_1 = require("../handler-support");
17
+ const module_bindings_1 = require("../module-bindings");
18
+ const MODULE_SETS = new Map();
19
+ function moduleSet(module) {
20
+ let set = MODULE_SETS.get(module);
21
+ if (!set)
22
+ MODULE_SETS.set(module, set = new Set([module]));
23
+ return set;
24
+ }
25
+ function wholeModuleBindings(cu, module) {
26
+ const names = new Set();
27
+ for (const [name, member] of (0, module_bindings_1.bindingsOf)(cu, moduleSet(module))) {
28
+ if (member === undefined)
29
+ names.add(name);
30
+ }
31
+ return names;
32
+ }
33
+ function mentionsVue(cu) {
34
+ return (0, handler_support_1.mentionsModule)(cu, m => m === "vue");
35
+ }
36
+ function importsEsModule(cu, module) {
37
+ return (0, handler_support_1.importsModule)(cu, m => m === module);
38
+ }
39
+ function hasDefaultExport(cu) {
40
+ return cu.statements.some(s => { var _a; return ((_a = s.element) === null || _a === void 0 ? void 0 : _a.kind) === javascript_1.JS.Kind.ExportAssignment; });
41
+ }
42
+ function isDefaultExported(cursor, object) {
43
+ const exported = cursor.firstEnclosing((t) => (t === null || t === void 0 ? void 0 : t.kind) === javascript_1.JS.Kind.ExportAssignment);
44
+ return (exported === null || exported === void 0 ? void 0 : exported.expression.element) === object;
45
+ }
46
+ function nameOf(e) {
47
+ return e && (0, java_1.isIdentifier)(e) ? e.simpleName : (0, module_bindings_1.stringLiteral)(e);
48
+ }
49
+ function hasKey(e, keys) {
50
+ var _a, _b;
51
+ if (!(0, javascript_1.isObjectLiteral)(e))
52
+ return false;
53
+ return ((_b = (_a = e.body) === null || _a === void 0 ? void 0 : _a.statements) !== null && _b !== void 0 ? _b : []).some(padded => {
54
+ const s = padded.element;
55
+ const key = s.kind === javascript_1.JS.Kind.PropertyAssignment ? nameOf(s.name.element)
56
+ : s.kind === java_1.J.Kind.MethodDeclaration ? s.name.simpleName : undefined;
57
+ return key !== undefined && keys.has(key);
58
+ });
59
+ }
60
+ function replaceMember(object, old, replacement) {
61
+ const statements = object.body.statements.map(s => s.element === old ? Object.assign(Object.assign({}, s), { element: replacement }) : s);
62
+ return Object.assign(Object.assign({}, object), { body: Object.assign(Object.assign({}, object.body), { statements }) });
63
+ }
64
+ function propertiesOf(e, skipSpread = false) {
65
+ var _a, _b, _c;
66
+ if (!e || !(0, javascript_1.isObjectLiteral)(e))
67
+ return undefined;
68
+ const out = [];
69
+ for (const padded of (_b = (_a = e.body) === null || _a === void 0 ? void 0 : _a.statements) !== null && _b !== void 0 ? _b : []) {
70
+ const s = padded.element;
71
+ if (s.kind === javascript_1.JS.Kind.PropertyAssignment) {
72
+ const key = nameOf(s.name.element);
73
+ if (key === undefined)
74
+ return undefined;
75
+ out.push({ key, tree: s, value: (_c = s.initializer) !== null && _c !== void 0 ? _c : s.name.element });
76
+ }
77
+ else if (s.kind === java_1.J.Kind.MethodDeclaration) {
78
+ out.push({ key: s.name.simpleName, tree: s });
79
+ }
80
+ else if (!(skipSpread && s.kind === javascript_1.JS.Kind.Spread)) {
81
+ return undefined;
82
+ }
83
+ }
84
+ return out;
85
+ }
86
+ exports.COMPONENT_OPTIONS = new Set(["name", "extends", "mixins", "setup", "directives", "data",
87
+ "methods", "computed", "props", "components", "watch", "template", "render", "created", "mounted", "beforeMount",
88
+ "updated", "beforeUpdate", "beforeDestroy", "destroyed"]);
89
+ function isComponentOptions(properties) {
90
+ return !!properties && properties.some(p => exports.COMPONENT_OPTIONS.has(p.key));
91
+ }
92
+ function importName(member, cu) {
93
+ const taken = (0, javascript_1.namesDeclaredIn)(cu);
94
+ const local = (0, javascript_1.deconflict)(member, n => taken.has(n));
95
+ return local === member ? { local } : { local, alias: local };
96
+ }
97
+ //# sourceMappingURL=vue-support.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vue-support.js","sourceRoot":"","sources":["../../../src/migrate/vue/vue-support.ts"],"names":[],"mappings":";;;AAmBA,kDAMC;AAGD,kCAEC;AAGD,0CAEC;AAGD,4CAEC;AAGD,8CAGC;AAOD,wBAQC;AAGD,sCAGC;AAcD,oCAgBC;AAQD,gDAEC;AAGD,gCAIC;AA5GD,oDAAsE;AACtE,gEAAiG;AACjG,wDAAiE;AACjE,wDAA6D;AAE7D,MAAM,WAAW,GAAG,IAAI,GAAG,EAA+B,CAAC;AAC3D,SAAS,SAAS,CAAC,MAAc;IAC7B,IAAI,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClC,IAAI,CAAC,GAAG;QAAE,WAAW,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC3D,OAAO,GAAG,CAAC;AACf,CAAC;AAGD,SAAgB,mBAAmB,CAAC,EAAsB,EAAE,MAAc;IACtE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,IAAA,4BAAU,EAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QAC7D,IAAI,MAAM,KAAK,SAAS;YAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAGD,SAAgB,WAAW,CAAC,EAAsB;IAC9C,OAAO,IAAA,gCAAc,EAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC;AAChD,CAAC;AAGD,SAAgB,eAAe,CAAC,EAAsB,EAAE,MAAc;IAClE,OAAO,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,uBAAU,EAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACpD,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,EAAC,KAAK,EAAC,CAAC,CAAC,CAAC,EAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
2
+ export declare const ASSET_TYPES: Readonly<Record<string, string>>;
3
+ export declare class ReplaceWebpackLoadersWithAssetModules extends Recipe {
4
+ readonly name = "org.openrewrite.nodejs.migrate.webpack.ReplaceWebpackLoadersWithAssetModules";
5
+ readonly displayName: string;
6
+ readonly description: string;
7
+ readonly tags: string[];
8
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
9
+ }
10
+ //# sourceMappingURL=asset-modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-modules.d.ts","sourceRoot":"","sources":["../../../src/migrate/webpack5/asset-modules.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAS3E,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIxD,CAAC;AAIF,qBAAa,qCAAsC,SAAQ,MAAM;IAC7D,QAAQ,CAAC,IAAI,kFAAkF;IAC/F,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA6F;IACzH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAG4F;IACxH,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAe;IAEhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA4B9D"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ReplaceWebpackLoadersWithAssetModules = exports.ASSET_TYPES = void 0;
13
+ const rewrite_1 = require("@openrewrite/rewrite");
14
+ const javascript_1 = require("@openrewrite/rewrite/javascript");
15
+ const java_1 = require("@openrewrite/rewrite/java");
16
+ const module_bindings_1 = require("../module-bindings");
17
+ const webpack_config_support_1 = require("./webpack-config-support");
18
+ exports.ASSET_TYPES = {
19
+ "file-loader": "asset/resource",
20
+ "url-loader": "asset/inline",
21
+ "raw-loader": "asset/source"
22
+ };
23
+ const RULE_MEMBERS_THAT_BLOCK = ["options", "type", "parser", "generator", "oneOf", "rules"];
24
+ class ReplaceWebpackLoadersWithAssetModules extends rewrite_1.Recipe {
25
+ constructor() {
26
+ super(...arguments);
27
+ this.name = "org.openrewrite.nodejs.migrate.webpack.ReplaceWebpackLoadersWithAssetModules";
28
+ this.displayName = "Replace `file-loader`, `url-loader` and `raw-loader` rules with webpack 5 asset modules";
29
+ this.description = "webpack 5 deprecates `file-loader`, `url-loader` and `raw-loader` in favour of asset modules. " +
30
+ "In a webpack configuration, a rule that applies one of them alone, with no options, gets `type: 'asset/resource'` " +
31
+ "(`file-loader`), `'asset/inline'` (`url-loader`, which inlines every file when it has no `limit`) or `'asset/source'` (`raw-loader`). " +
32
+ "Rules with `options`, other loaders in the chain or a `type` already are left for `FindWebpack5ManualMigrations`.";
33
+ this.tags = ["webpack"];
34
+ }
35
+ editor() {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ return new class extends javascript_1.JavaScriptVisitor {
38
+ constructor() {
39
+ super(...arguments);
40
+ this.config = false;
41
+ }
42
+ visitJsCompilationUnit(cu, p) {
43
+ const _super = Object.create(null, {
44
+ visitJsCompilationUnit: { get: () => super.visitJsCompilationUnit }
45
+ });
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ this.config = (0, webpack_config_support_1.isWebpackConfig)(cu);
48
+ return this.config ? _super.visitJsCompilationUnit.call(this, cu, p) : cu;
49
+ });
50
+ }
51
+ visitNewClass(newClass, p) {
52
+ const _super = Object.create(null, {
53
+ visitNewClass: { get: () => super.visitNewClass }
54
+ });
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ const n = yield _super.visitNewClass.call(this, newClass, p);
57
+ const rule = (0, webpack_config_support_1.objectOf)(n);
58
+ if (!rule || !(0, webpack_config_support_1.memberNamed)(rule, "test"))
59
+ return n;
60
+ if (RULE_MEMBERS_THAT_BLOCK.some(b => (0, webpack_config_support_1.memberNamed)(rule, b)))
61
+ return n;
62
+ const statements = (0, webpack_config_support_1.membersOf)(rule).map(m => {
63
+ const key = (0, webpack_config_support_1.keyOf)(m.element);
64
+ if (key !== "loader" && key !== "use")
65
+ return m;
66
+ const property = m.element;
67
+ const loader = loaderLiteral(property.initializer, key === "use");
68
+ const type = loader && exports.ASSET_TYPES[loader.value];
69
+ if (!type)
70
+ return m;
71
+ const initializer = Object.assign(Object.assign({}, (0, webpack_config_support_1.stringLike)(loader, type)), { prefix: property.initializer.prefix });
72
+ return Object.assign(Object.assign({}, m), { element: Object.assign(Object.assign({}, (0, webpack_config_support_1.renameKey)(property, "type")), { initializer }) });
73
+ });
74
+ return statements.some((m, i) => m !== (0, webpack_config_support_1.membersOf)(rule)[i]) ? (0, webpack_config_support_1.withMembers)(n, statements) : n;
75
+ });
76
+ }
77
+ };
78
+ });
79
+ }
80
+ }
81
+ exports.ReplaceWebpackLoadersWithAssetModules = ReplaceWebpackLoadersWithAssetModules;
82
+ function loaderLiteral(value, isUse) {
83
+ var _a;
84
+ if ((0, module_bindings_1.stringLiteral)(value) !== undefined)
85
+ return value;
86
+ if (!isUse || (value === null || value === void 0 ? void 0 : value.kind) !== java_1.J.Kind.NewArray)
87
+ return undefined;
88
+ const elements = (_a = value.initializer) === null || _a === void 0 ? void 0 : _a.elements;
89
+ if ((elements === null || elements === void 0 ? void 0 : elements.length) !== 1)
90
+ return undefined;
91
+ const only = elements[0].element;
92
+ if ((0, module_bindings_1.stringLiteral)(only) !== undefined)
93
+ return only;
94
+ const object = (0, webpack_config_support_1.objectOf)(only);
95
+ if (!object || (0, webpack_config_support_1.membersOf)(object).length !== 1)
96
+ return undefined;
97
+ const loader = (0, webpack_config_support_1.memberNamed)(object, "loader");
98
+ return (0, module_bindings_1.stringLiteral)(loader === null || loader === void 0 ? void 0 : loader.initializer) !== undefined ? loader.initializer : undefined;
99
+ }
100
+ //# sourceMappingURL=asset-modules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-modules.js","sourceRoot":"","sources":["../../../src/migrate/webpack5/asset-modules.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,kDAA2E;AAC3E,gEAAsE;AACtE,oDAA4C;AAC5C,wDAAiD;AACjD,qEAEkC;AAGrB,QAAA,WAAW,GAAqC;IACzD,aAAa,EAAE,gBAAgB;IAC/B,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,cAAc;CAC/B,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAE7F,MAAa,qCAAsC,SAAQ,gBAAM;IAAjE;;QACa,SAAI,GAAG,8EAA8E,CAAC;QACtF,gBAAW,GAAW,yFAAyF,CAAC;QAChH,gBAAW,GAAW,gGAAgG;YAC3H,oHAAoH;YACpH,wIAAwI;YACxI,mHAAmH,CAAC;QAC/G,SAAI,GAAa,CAAC,SAAS,CAAC,CAA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AK,SAAS;QAAE,OAAO,IAAiB,CAAC;IAChE,MAAM,MAAM,GAAG,IAAA,iCAAQ,EAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,MAAM,IAAI,IAAA,kCAAS,EAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAChE,MAAM,MAAM,GAAG,IAAA,oCAAW,EAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC7C,OAAO,IAAA,+BAAa,EAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,MAAO,CAAC,WAAwB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3G,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
2
+ export declare class FindWebpack5ManualMigrations extends Recipe {
3
+ readonly name = "org.openrewrite.nodejs.migrate.webpack.FindWebpack5ManualMigrations";
4
+ readonly displayName: string;
5
+ readonly description: string;
6
+ readonly tags: string[];
7
+ editor(): Promise<TreeVisitor<any, ExecutionContext>>;
8
+ }
9
+ //# sourceMappingURL=find-webpack-5-manual-migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-webpack-5-manual-migrations.d.ts","sourceRoot":"","sources":["../../../src/migrate/webpack5/find-webpack-5-manual-migrations.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,gBAAgB,EAAqB,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAgB9F,qBAAa,4BAA6B,SAAQ,MAAM;IACpD,QAAQ,CAAC,IAAI,yEAAyE;IACtF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAwE;IACpG,QAAQ,CAAC,WAAW,EAAE,MAAM,CAG2G;IACvI,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAe;IAEhC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAsC9D"}