@mnci/cli 4.1.0 → 4.1.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/dist/cli.js +46 -0
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1669,6 +1669,50 @@ function registerProjectCommands(workspaceRoot, name, commands) {
|
|
|
1669
1669
|
})
|
|
1670
1670
|
);
|
|
1671
1671
|
}
|
|
1672
|
+
var PROJECT_MANIFEST_ROOTS = ["apps", "packages", "libs"];
|
|
1673
|
+
function rootRuntimeDependencies(workspaceRoot) {
|
|
1674
|
+
try {
|
|
1675
|
+
return readJson((0, import_node_path3.join)(workspaceRoot, "package.json")).dependencies ?? {};
|
|
1676
|
+
} catch {
|
|
1677
|
+
return {};
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
function relocateRootRuntimeDependencies(workspaceRoot, projectName, before) {
|
|
1681
|
+
const after = rootRuntimeDependencies(workspaceRoot);
|
|
1682
|
+
const added = Object.keys(after).filter((name) => !Object.hasOwn(before, name));
|
|
1683
|
+
if (added.length === 0) {
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
const manifestPath = PROJECT_MANIFEST_ROOTS.map(
|
|
1687
|
+
(root) => (0, import_node_path3.join)(workspaceRoot, root, projectName, "package.json")
|
|
1688
|
+
).find((candidate) => fileExists(candidate));
|
|
1689
|
+
if (manifestPath === void 0) {
|
|
1690
|
+
return;
|
|
1691
|
+
}
|
|
1692
|
+
const manifest = readJson(manifestPath);
|
|
1693
|
+
const owned = manifest.dependencies ?? {};
|
|
1694
|
+
const moved = Object.fromEntries(added.map((name) => [name, after[name]]));
|
|
1695
|
+
writeFileEnsured(manifestPath, toJson({ ...manifest, dependencies: { ...moved, ...owned } }));
|
|
1696
|
+
const remaining = Object.fromEntries(
|
|
1697
|
+
Object.entries(after).filter(([name]) => !added.includes(name))
|
|
1698
|
+
);
|
|
1699
|
+
const rootManifest = readJson((0, import_node_path3.join)(workspaceRoot, "package.json"));
|
|
1700
|
+
const { dependencies: _dropped, ...rest } = rootManifest;
|
|
1701
|
+
writeFileEnsured(
|
|
1702
|
+
(0, import_node_path3.join)(workspaceRoot, "package.json"),
|
|
1703
|
+
toJson(Object.keys(remaining).length > 0 ? { ...rest, dependencies: remaining } : rest)
|
|
1704
|
+
);
|
|
1705
|
+
logger.step(`Moved ${added.join(", ")} into ${projectName}'s own manifest`);
|
|
1706
|
+
if (runShell(
|
|
1707
|
+
"npm",
|
|
1708
|
+
["install", "--package-lock-only", "--no-audit", "--no-fund"],
|
|
1709
|
+
workspaceRoot
|
|
1710
|
+
) !== 0) {
|
|
1711
|
+
logger.warn(
|
|
1712
|
+
`Could not refresh package-lock.json after moving ${added.join(", ")}. Run 'npm install'.`
|
|
1713
|
+
);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1672
1716
|
|
|
1673
1717
|
// src/commands/add/flutter.ts
|
|
1674
1718
|
function addProjectJsonTargets(projectJsonPath, newTargets) {
|
|
@@ -3076,6 +3120,7 @@ async function runAdd(kind, name, options) {
|
|
|
3076
3120
|
});
|
|
3077
3121
|
const resolvedName = name ?? await promptText("Project name");
|
|
3078
3122
|
assertValidProjectName(resolvedName, "Project name");
|
|
3123
|
+
const rootDependenciesBefore = rootRuntimeDependencies(workspaceRoot);
|
|
3079
3124
|
switch (resolvedKind) {
|
|
3080
3125
|
case "react-app": {
|
|
3081
3126
|
addReactApp(workspaceRoot, resolvedName, stack);
|
|
@@ -3176,6 +3221,7 @@ async function runAdd(kind, name, options) {
|
|
|
3176
3221
|
);
|
|
3177
3222
|
}
|
|
3178
3223
|
}
|
|
3224
|
+
relocateRootRuntimeDependencies(workspaceRoot, resolvedName, rootDependenciesBefore);
|
|
3179
3225
|
syncProjectReferences(workspaceRoot);
|
|
3180
3226
|
runFormatter(workspaceRoot);
|
|
3181
3227
|
logger.success(`Added ${resolvedKind} '${resolvedName}'.`);
|