@react-spectrum/codemods 1.2.0 → 1.2.1

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.
@@ -80,6 +80,20 @@ function resolveTargetSource(candidates, uniqueSources, existingImports) {
80
80
  }
81
81
  return candidates[0];
82
82
  }
83
+ function moduleAugmentsRouterConfig(body) {
84
+ for (let stmt of body.body) {
85
+ if (stmt.type === 'TSInterfaceDeclaration' && stmt.id.type === 'Identifier' && stmt.id.name === 'RouterConfig') {
86
+ return true;
87
+ }
88
+ if (stmt.type === 'ExportNamedDeclaration' &&
89
+ stmt.declaration?.type === 'TSInterfaceDeclaration' &&
90
+ stmt.declaration.id.type === 'Identifier' &&
91
+ stmt.declaration.id.name === 'RouterConfig') {
92
+ return true;
93
+ }
94
+ }
95
+ return false;
96
+ }
83
97
  function transformer(file, api) {
84
98
  let specifiersByPackage = (0, specifiers_1.getSpecifiersByPackage)(file.path);
85
99
  let j = api.jscodeshift.withParser({
@@ -117,6 +131,7 @@ function transformer(file, api) {
117
131
  let program = root.get().node.program;
118
132
  let uniqueSources = new Set();
119
133
  let existingImports = new Map();
134
+ let didChange = false;
120
135
  for (let node of program.body) {
121
136
  if (node.type === 'ImportDeclaration') {
122
137
  let source = node.source.value;
@@ -139,8 +154,20 @@ function transformer(file, api) {
139
154
  }
140
155
  }
141
156
  }
157
+ if (node.type === 'TSModuleDeclaration' && node.declare && node.id.type === 'StringLiteral') {
158
+ let mod = node.id.value;
159
+ if (!specifiers_1.MONOPACKAGE_ROOTS.includes(mod) || node.body?.type !== 'TSModuleBlock' || !moduleAugmentsRouterConfig(node.body)) {
160
+ continue;
161
+ }
162
+ let target = `${mod}/Provider`;
163
+ let candidates = specifiersByPackage[mod]?.Provider;
164
+ if (!candidates?.includes(target)) {
165
+ continue;
166
+ }
167
+ node.id = t.stringLiteral(target);
168
+ didChange = true;
169
+ }
142
170
  }
143
- let didChange = false;
144
171
  program.body = program.body.flatMap(node => {
145
172
  if (node.type !== 'ImportDeclaration') {
146
173
  return [node];
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MONOPACKAGE_ROOTS = void 0;
6
7
  exports.getSpecifiersByPackage = getSpecifiersByPackage;
7
8
  /* eslint-disable max-depth */
8
9
  const fs_1 = __importDefault(require("fs"));
@@ -10,7 +11,7 @@ const module_1 = __importDefault(require("module"));
10
11
  const parser_1 = require("@babel/parser");
11
12
  const path_1 = __importDefault(require("path"));
12
13
  const url_1 = __importDefault(require("url"));
13
- const PACKAGES = [
14
+ exports.MONOPACKAGE_ROOTS = [
14
15
  '@adobe/react-spectrum',
15
16
  '@react-spectrum/s2',
16
17
  'react-aria-components',
@@ -20,7 +21,7 @@ const PACKAGES = [
20
21
  const specifiersByPackage = {};
21
22
  /** Builds a mapping of monopackage -> export -> subpaths that contain the export. */
22
23
  function getSpecifiersByPackage(from) {
23
- for (let pkg of PACKAGES) {
24
+ for (let pkg of exports.MONOPACKAGE_ROOTS) {
24
25
  if (specifiersByPackage[pkg]) {
25
26
  continue;
26
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-spectrum/codemods",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "main": "dist/index.js",
5
5
  "source": "src/index.ts",
6
6
  "bin": "dist/index.js",
@@ -53,5 +53,5 @@
53
53
  "publishConfig": {
54
54
  "access": "public"
55
55
  },
56
- "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
56
+ "gitHead": "36fdd8bca2df281fa955117d946e6dd9718241e4"
57
57
  }