ph-cmd 0.42.0 → 0.43.0-dev.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.
- package/dist/src/commands/__tests__/update.test.d.ts +2 -0
- package/dist/src/commands/__tests__/update.test.d.ts.map +1 -0
- package/dist/src/commands/__tests__/update.test.js +150 -0
- package/dist/src/commands/__tests__/use.test.d.ts +2 -0
- package/dist/src/commands/__tests__/use.test.d.ts.map +1 -0
- package/dist/src/commands/__tests__/use.test.js +128 -0
- package/dist/src/commands/index.d.ts +3 -1
- package/dist/src/commands/index.d.ts.map +1 -1
- package/dist/src/commands/index.js +12 -3
- package/dist/src/commands/update.d.ts +11 -0
- package/dist/src/commands/update.d.ts.map +1 -0
- package/dist/src/commands/update.js +88 -0
- package/dist/src/commands/use.d.ts +27 -0
- package/dist/src/commands/use.d.ts.map +1 -0
- package/dist/src/commands/use.js +81 -0
- package/dist/src/utils.d.ts +34 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +59 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -2
package/dist/src/utils.js
CHANGED
|
@@ -28,27 +28,43 @@ export const PH_GLOBAL_PROJECT_NAME = ".ph";
|
|
|
28
28
|
export const POWERHOUSE_GLOBAL_DIR = path.join(HOME_DIR, PH_GLOBAL_PROJECT_NAME);
|
|
29
29
|
export const packageManagers = {
|
|
30
30
|
bun: {
|
|
31
|
+
installCommand: "bun add {{dependency}}",
|
|
31
32
|
execCommand: `bun ${PH_BIN} {{arguments}}`,
|
|
32
33
|
execScript: `bun {{arguments}}`,
|
|
33
34
|
lockfile: "bun.lock",
|
|
34
35
|
globalPathRegexp: /[\\/].bun[\\/]/,
|
|
36
|
+
updateCommand: "bun update {{dependency}}",
|
|
37
|
+
buildAffected: "bun run build:affected",
|
|
38
|
+
workspaceOption: "",
|
|
35
39
|
},
|
|
36
40
|
pnpm: {
|
|
41
|
+
installCommand: "pnpm add {{dependency}}",
|
|
37
42
|
execCommand: `pnpm exec ${PH_BIN} {{arguments}}`,
|
|
38
43
|
execScript: `pnpm {{arguments}}`,
|
|
39
44
|
lockfile: "pnpm-lock.yaml",
|
|
40
45
|
globalPathRegexp: /[\\/]pnpm[\\/]/,
|
|
46
|
+
updateCommand: "pnpm update {{dependency}}",
|
|
47
|
+
buildAffected: "pnpm run build:affected",
|
|
48
|
+
workspaceOption: "--workspace-root",
|
|
41
49
|
},
|
|
42
50
|
yarn: {
|
|
51
|
+
installCommand: "yarn add {{dependency}}",
|
|
43
52
|
execCommand: `yarn ${PH_BIN} {{arguments}}`,
|
|
44
53
|
execScript: `yarn {{arguments}}`,
|
|
45
54
|
lockfile: "yarn.lock",
|
|
46
55
|
globalPathRegexp: /[\\/]yarn[\\/]/,
|
|
56
|
+
updateCommand: "yarn upgrade {{dependency}}",
|
|
57
|
+
buildAffected: "yarn run build:affected",
|
|
58
|
+
workspaceOption: "-W",
|
|
47
59
|
},
|
|
48
60
|
npm: {
|
|
61
|
+
installCommand: "npm install {{dependency}}",
|
|
49
62
|
execCommand: `npx ${PH_BIN} {{arguments}}`,
|
|
50
63
|
execScript: `npm run {{arguments}}`,
|
|
51
64
|
lockfile: "package-lock.json",
|
|
65
|
+
updateCommand: "npm update {{dependency}} --save",
|
|
66
|
+
buildAffected: "npm run build:affected",
|
|
67
|
+
workspaceOption: "",
|
|
52
68
|
},
|
|
53
69
|
};
|
|
54
70
|
export function defaultPathValidation() {
|
|
@@ -127,3 +143,46 @@ export function forwardPHCommand(packageManager, projectPath, args, debug) {
|
|
|
127
143
|
...commandOptions,
|
|
128
144
|
});
|
|
129
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Recursively searches for a specific file by traversing up the directory tree.
|
|
148
|
+
* Starting from the given path, it checks each parent directory until it finds
|
|
149
|
+
* the target file or reaches the root directory.
|
|
150
|
+
*
|
|
151
|
+
* @param startPath - The absolute path of the directory to start searching from
|
|
152
|
+
* @param targetFile - The name of the file to search for (e.g., 'package.json', 'pnpm-workspace.yaml')
|
|
153
|
+
* @returns The absolute path of the directory containing the target file, or null if not found
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // Find the workspace root directory
|
|
157
|
+
* const workspaceRoot = findContainerDirectory('/path/to/project/src', 'pnpm-workspace.yaml');
|
|
158
|
+
*
|
|
159
|
+
* // Find the nearest package.json
|
|
160
|
+
* const packageDir = findContainerDirectory('/path/to/project/src/components', 'package.json');
|
|
161
|
+
*/
|
|
162
|
+
export const findContainerDirectory = (startPath, targetFile) => {
|
|
163
|
+
const filePath = path.join(startPath, targetFile);
|
|
164
|
+
if (fs.existsSync(filePath)) {
|
|
165
|
+
return startPath;
|
|
166
|
+
}
|
|
167
|
+
const parentDir = path.dirname(startPath);
|
|
168
|
+
//reached the root directory and haven't found the file
|
|
169
|
+
if (parentDir === startPath) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
return findContainerDirectory(parentDir, targetFile);
|
|
173
|
+
};
|
|
174
|
+
export function installDependency(packageManager, dependencies, projectPath, workspace) {
|
|
175
|
+
if (!fs.existsSync(projectPath)) {
|
|
176
|
+
throw new Error(`Project path not found: ${projectPath}`);
|
|
177
|
+
}
|
|
178
|
+
const manager = packageManagers[packageManager];
|
|
179
|
+
let installCommand = manager.installCommand.replace("{{dependency}}", dependencies.join(" "));
|
|
180
|
+
if (workspace) {
|
|
181
|
+
installCommand += ` ${manager.workspaceOption}`;
|
|
182
|
+
}
|
|
183
|
+
const commandOptions = { cwd: projectPath };
|
|
184
|
+
execSync(installCommand, {
|
|
185
|
+
stdio: "inherit",
|
|
186
|
+
...commandOptions,
|
|
187
|
+
});
|
|
188
|
+
}
|