@domain-first/project-structure 2.16.0 → 2.16.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.
- package/README.md +3 -2
- package/dist/index.cjs +35 -7
- package/dist/index.js +35 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -209,8 +209,9 @@ folders. A widget moves with its whole folder (assets included), and a page with
|
|
|
209
209
|
the files next to it that share its name, such as `<name>-page.module.css`. File
|
|
210
210
|
names, `<Name>Page`, `<Name>Widget…` and `use<Name>UIModel` follow the new name,
|
|
211
211
|
and so does a generated story title. Imports of the module are updated across
|
|
212
|
-
the project, both relative ones and `tsconfig.json` `paths` aliases such as
|
|
213
|
-
|
|
212
|
+
the project, both relative ones and `tsconfig.json` `paths` aliases such as `@/`;
|
|
213
|
+
files importing it through barrels (`export * from` / `export { … } from`) get
|
|
214
|
+
the renamed classes too, and relative imports inside the module are adjusted to its new location. The CLI
|
|
214
215
|
lists the files to move and to update and asks before writing; emptied folders
|
|
215
216
|
are removed. Entering the same name renames files made before file names used
|
|
216
217
|
the whole path, for example `pages/admin/users-page.tsx` to
|
package/dist/index.cjs
CHANGED
|
@@ -1217,6 +1217,16 @@ const readAliases = (projectRoot)=>{
|
|
|
1217
1217
|
}
|
|
1218
1218
|
};
|
|
1219
1219
|
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
1220
|
+
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
1221
|
+
const importPaths = (file)=>{
|
|
1222
|
+
const withoutExtension = file.replace(codeExtension, '');
|
|
1223
|
+
return 'index' === external_node_path_default().basename(withoutExtension) ? [
|
|
1224
|
+
withoutExtension,
|
|
1225
|
+
external_node_path_default().dirname(withoutExtension)
|
|
1226
|
+
] : [
|
|
1227
|
+
withoutExtension
|
|
1228
|
+
];
|
|
1229
|
+
};
|
|
1220
1230
|
const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
1221
1231
|
const newName = new NestedName(rawName);
|
|
1222
1232
|
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
@@ -1263,13 +1273,35 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
1263
1273
|
'Widgets',
|
|
1264
1274
|
...newName.classNameSegments
|
|
1265
1275
|
].join('/');
|
|
1276
|
+
const codeFiles = new Map(react_module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
1277
|
+
file,
|
|
1278
|
+
external_node_fs_default().readFileSync(file, 'utf8')
|
|
1279
|
+
]));
|
|
1280
|
+
const barrels = new Set();
|
|
1281
|
+
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
1282
|
+
for(let found = true; found;){
|
|
1283
|
+
found = false;
|
|
1284
|
+
for (const [file, content] of codeFiles){
|
|
1285
|
+
if (moves.has(file) || isBarrel(file)) continue;
|
|
1286
|
+
const reExportsModule = [
|
|
1287
|
+
...content.matchAll(reExportPattern)
|
|
1288
|
+
].some(([, , specifier])=>{
|
|
1289
|
+
const resolution = resolve(specifier, file);
|
|
1290
|
+
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
1291
|
+
});
|
|
1292
|
+
if (reExportsModule) {
|
|
1293
|
+
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
1294
|
+
found = true;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1266
1298
|
const rewrite = (content, oldFile, newFile)=>{
|
|
1267
1299
|
let referencesModule = false;
|
|
1268
1300
|
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
1269
1301
|
const resolution = resolve(specifier, oldFile);
|
|
1270
1302
|
if (!resolution) return match;
|
|
1271
1303
|
const moved = movedPath(resolution.resolved);
|
|
1272
|
-
if (moved) referencesModule = true;
|
|
1304
|
+
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
1273
1305
|
if (!moved && oldFile === newFile) return match;
|
|
1274
1306
|
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
1275
1307
|
return `${keyword}${quote}${next}${quote}`;
|
|
@@ -1278,14 +1310,10 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
1278
1310
|
const renamed = rewritten.replace(classPattern, (_, use = '')=>`${use}${newClassName}`);
|
|
1279
1311
|
return moves.has(oldFile) && 'widget' === module.kind ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
1280
1312
|
};
|
|
1313
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, reactFolder);
|
|
1281
1314
|
const updated = [];
|
|
1282
|
-
for (const file of
|
|
1315
|
+
for (const [file, content] of codeFiles){
|
|
1283
1316
|
const newFile = moves.get(file);
|
|
1284
|
-
if (!codeExtension.test(file)) {
|
|
1285
|
-
if (newFile && newFile !== file) new File(file).moveTo(newFile, reactFolder);
|
|
1286
|
-
continue;
|
|
1287
|
-
}
|
|
1288
|
-
const content = external_node_fs_default().readFileSync(file, 'utf8');
|
|
1289
1317
|
const next = rewrite(content, file, newFile ?? file);
|
|
1290
1318
|
if (newFile && newFile !== file) {
|
|
1291
1319
|
new File(newFile).data = next;
|
package/dist/index.js
CHANGED
|
@@ -1187,6 +1187,16 @@ const readAliases = (projectRoot)=>{
|
|
|
1187
1187
|
}
|
|
1188
1188
|
};
|
|
1189
1189
|
const specifierPattern = /(\bfrom\s*|\bimport\s*\(\s*|\bimport\s+|\brequire\s*\(\s*|\bmock\s*\(\s*)(['"])([^'"\n]+)\2/g;
|
|
1190
|
+
const reExportPattern = /\bexport\s+(?:type\s+)?(?:\*(?:\s+as\s+[\w$]+)?|\{[^}]*\})\s*from\s*(['"])([^'"\n]+)\1/g;
|
|
1191
|
+
const importPaths = (file)=>{
|
|
1192
|
+
const withoutExtension = file.replace(codeExtension, '');
|
|
1193
|
+
return 'index' === node_path.basename(withoutExtension) ? [
|
|
1194
|
+
withoutExtension,
|
|
1195
|
+
node_path.dirname(withoutExtension)
|
|
1196
|
+
] : [
|
|
1197
|
+
withoutExtension
|
|
1198
|
+
];
|
|
1199
|
+
};
|
|
1190
1200
|
const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
1191
1201
|
const newName = new NestedName(rawName);
|
|
1192
1202
|
const target = react_module_move_targetPath(reactFolder, module, rawName);
|
|
@@ -1233,13 +1243,35 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
1233
1243
|
'Widgets',
|
|
1234
1244
|
...newName.classNameSegments
|
|
1235
1245
|
].join('/');
|
|
1246
|
+
const codeFiles = new Map(react_module_move_walk(projectRoot).filter((file)=>codeExtension.test(file)).map((file)=>[
|
|
1247
|
+
file,
|
|
1248
|
+
node_fs.readFileSync(file, 'utf8')
|
|
1249
|
+
]));
|
|
1250
|
+
const barrels = new Set();
|
|
1251
|
+
const isBarrel = (resolved)=>barrels.has(resolved.replace(codeExtension, ''));
|
|
1252
|
+
for(let found = true; found;){
|
|
1253
|
+
found = false;
|
|
1254
|
+
for (const [file, content] of codeFiles){
|
|
1255
|
+
if (moves.has(file) || isBarrel(file)) continue;
|
|
1256
|
+
const reExportsModule = [
|
|
1257
|
+
...content.matchAll(reExportPattern)
|
|
1258
|
+
].some(([, , specifier])=>{
|
|
1259
|
+
const resolution = resolve(specifier, file);
|
|
1260
|
+
return !!resolution && (!!movedPath(resolution.resolved) || isBarrel(resolution.resolved));
|
|
1261
|
+
});
|
|
1262
|
+
if (reExportsModule) {
|
|
1263
|
+
for (const importPath of importPaths(file))barrels.add(importPath);
|
|
1264
|
+
found = true;
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1236
1268
|
const rewrite = (content, oldFile, newFile)=>{
|
|
1237
1269
|
let referencesModule = false;
|
|
1238
1270
|
const rewritten = content.replace(specifierPattern, (match, keyword, quote, specifier)=>{
|
|
1239
1271
|
const resolution = resolve(specifier, oldFile);
|
|
1240
1272
|
if (!resolution) return match;
|
|
1241
1273
|
const moved = movedPath(resolution.resolved);
|
|
1242
|
-
if (moved) referencesModule = true;
|
|
1274
|
+
if (moved || isBarrel(resolution.resolved)) referencesModule = true;
|
|
1243
1275
|
if (!moved && oldFile === newFile) return match;
|
|
1244
1276
|
const next = specifierFor(newFile, moved ?? resolution.resolved, resolution.alias);
|
|
1245
1277
|
return `${keyword}${quote}${next}${quote}`;
|
|
@@ -1248,14 +1280,10 @@ const moveReactModule = (projectRoot, reactFolder, module, rawName)=>{
|
|
|
1248
1280
|
const renamed = rewritten.replace(classPattern, (_, use = '')=>`${use}${newClassName}`);
|
|
1249
1281
|
return moves.has(oldFile) && 'widget' === module.kind ? renamed.replace(titlePattern, (_, quote)=>`${quote}${newTitle}${quote}`) : renamed;
|
|
1250
1282
|
};
|
|
1283
|
+
for (const [file, newFile] of moves)if (!codeFiles.has(file) && newFile !== file) new File(file).moveTo(newFile, reactFolder);
|
|
1251
1284
|
const updated = [];
|
|
1252
|
-
for (const file of
|
|
1285
|
+
for (const [file, content] of codeFiles){
|
|
1253
1286
|
const newFile = moves.get(file);
|
|
1254
|
-
if (!codeExtension.test(file)) {
|
|
1255
|
-
if (newFile && newFile !== file) new File(file).moveTo(newFile, reactFolder);
|
|
1256
|
-
continue;
|
|
1257
|
-
}
|
|
1258
|
-
const content = node_fs.readFileSync(file, 'utf8');
|
|
1259
1287
|
const next = rewrite(content, file, newFile ?? file);
|
|
1260
1288
|
if (newFile && newFile !== file) {
|
|
1261
1289
|
new File(newFile).data = next;
|