-
-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(plugin-commands-script-runners): support --resume-from for pnpm exec command #5856
Changes from 1 commit
9f2ff6a
3feb8ee
2f091c3
807e53a
abed48d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@pnpm/plugin-commands-script-runners": minor | ||
"pnpm": minor | ||
--- | ||
|
||
the `pnpm exec` command support `--resume-from` option. When used, the command will executed from given package [#4690](https://github.com/pnpm/pnpm/issues/4690). |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,6 +16,7 @@ import { | |||||
PARALLEL_OPTION_HELP, | ||||||
shorthands as runShorthands, | ||||||
} from './run' | ||||||
import { PnpmError } from '@pnpm/error' | ||||||
|
||||||
export const shorthands = { | ||||||
parallel: runShorthands.parallel, | ||||||
|
@@ -34,6 +35,7 @@ export function rcOptionsTypes () { | |||||
'workspace-concurrency', | ||||||
], types), | ||||||
'shell-mode': Boolean, | ||||||
'resume-from': String, | ||||||
} | ||||||
} | ||||||
|
||||||
|
@@ -66,6 +68,10 @@ The shell should understand the -c switch on UNIX or /d /s /c on Windows.', | |||||
name: '--shell-mode', | ||||||
shortAlias: '-c', | ||||||
}, | ||||||
{ | ||||||
description: 'command executed from given package', | ||||||
name: '--resume-from', | ||||||
}, | ||||||
], | ||||||
}, | ||||||
], | ||||||
|
@@ -83,6 +89,7 @@ export async function handler ( | |||||
sort?: boolean | ||||||
workspaceConcurrency?: number | ||||||
shellMode?: boolean | ||||||
resumeFrom?: string | ||||||
} & Pick<Config, 'extraBinPaths' | 'extraEnv' | 'lockfileDir' | 'dir' | 'userAgent' | 'recursive' | 'workspaceDir'>, | ||||||
params: string[] | ||||||
) { | ||||||
|
@@ -120,6 +127,19 @@ export async function handler ( | |||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
if (opts.resumeFrom) { | ||||||
const resumeFromPackagePrefix = Object.keys(opts.selectedProjectsGraph) | ||||||
.find((prefix) => opts.selectedProjectsGraph?.[prefix]?.package.manifest.name === opts.resumeFrom) | ||||||
|
||||||
if (!resumeFromPackagePrefix) { | ||||||
throw new PnpmError('RECURSIVE_EXEC_FAIL', `Cannot find package ${opts.resumeFrom}. Could not determine where to resume from.`) | ||||||
} | ||||||
|
||||||
const chunkPosition = chunks.findIndex(chunk => chunk.includes(resumeFromPackagePrefix)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be an equal check?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
chunks = chunks.slice(chunkPosition) | ||||||
} | ||||||
|
||||||
const existsPnp = existsInDir.bind(null, '.pnp.cjs') | ||||||
const workspacePnpPath = opts.workspaceDir && await existsPnp(opts.workspaceDir) | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
opts.selectedProjectsGraph
is not defined, I think an error should be thrownThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not quite sure about this situation, can you help explain why it is not defined? thanks ~
I looked at the type definition and it doesn't seem to be
undefined
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but you do check if it is defined by using optional chaining (
opts.selectedProjectsGraph?
)Instead, you can check if it exists before line 132
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, I'm using the optional chain based on the usage in line 159.
I wonder if we can remove the optional chaining if it really won't be
undefined
, I don't see other examples of checkingopts.selectedProjectsGraph
elsewhere, like inrun
orrunRecursive
, Please let me know if there is something missing. Thanks a lot