diff --git a/packages/plugin-commands-patching/src/patch.ts b/packages/plugin-commands-patching/src/patch.ts index 03689fb7c22..b52f8f64df4 100644 --- a/packages/plugin-commands-patching/src/patch.ts +++ b/packages/plugin-commands-patching/src/patch.ts @@ -19,11 +19,11 @@ export function rcOptionsTypes () { } export function cliOptionsTypes () { - return { ...rcOptionsTypes(), 'user-dir': String } + return { ...rcOptionsTypes(), 'edit-dir': String } } export const shorthands = { - d: '--user-dir', + d: '--edit-dir', } export const commandNames = ['patch'] @@ -36,13 +36,13 @@ export function help () { list: [ { description: 'Directory path that patch files will be stored. If not set, the files is stored in temporary directory.', - name: '--user-dir', + name: '--edit-dir', shortAlias: '-d', }, ], }], url: docsUrl('patch'), - usages: ['pnpm patch [--user-dir ]'], + usages: ['pnpm patch [--edit-dir ]'], }) } @@ -51,7 +51,7 @@ Config, 'dir' | 'registries' | 'tag' | 'storeDir' > & CreateStoreControllerOptions & { - userDir?: string + editDir?: string reporter?: (logObj: LogBase) => void } @@ -73,7 +73,7 @@ export async function handler (opts: PatchCommandOptions, params: string[]) { const filesResponse = await pkgResponse.files!() const tempDir = tempy.directory() - const patchPackageDir = createPackageDirectory(opts.userDir) ?? tempDir + const patchPackageDir = createPackageDirectory(opts.editDir) ?? tempDir const userChangesDir = path.join(patchPackageDir, 'user') await Promise.all([ store.ctrl.importPackage(path.join(tempDir, 'source'), { @@ -88,15 +88,15 @@ export async function handler (opts: PatchCommandOptions, params: string[]) { return `You can now edit the following folder: ${userChangesDir}` } -function createPackageDirectory (userDir?: string) { - if (!userDir) { +function createPackageDirectory (editDir?: string) { + if (!editDir) { return } - if (fs.existsSync(userDir)) { - throw new PnpmError('DIR_ALREADY_EXISTS', `The package directory already exists: '${userDir}'`) + if (fs.existsSync(editDir)) { + throw new PnpmError('DIR_ALREADY_EXISTS', `The package directory already exists: '${editDir}'`) } - fs.mkdirSync(userDir, { recursive: true }) - return userDir + fs.mkdirSync(editDir, { recursive: true }) + return editDir } \ No newline at end of file diff --git a/packages/plugin-commands-patching/test/patch.test.ts b/packages/plugin-commands-patching/test/patch.test.ts index 53bead1344c..5738fc71b32 100644 --- a/packages/plugin-commands-patching/test/patch.test.ts +++ b/packages/plugin-commands-patching/test/patch.test.ts @@ -40,7 +40,7 @@ describe('patch and commit', () => { const userPatchDir = output.substring(output.indexOf(':') + 1).trim() const tempDir = os.tmpdir() // temp dir depends on the operating system (@see tempy) - // store patch files(user, source) in temporary directory when not given userDir option + // store patch files(user, source) in temporary directory when not given editDir option expect(userPatchDir).toContain(tempDir) expect(fs.existsSync(userPatchDir)).toBe(true) expect(fs.existsSync(userPatchDir.replace('/user', '/source'))).toBe(true) @@ -69,18 +69,18 @@ describe('patch and commit', () => { expect(fs.existsSync('node_modules/is-positive/license')).toBe(false) }) - test('store source files in temporary directory and user files in user directory, when given userDir option', async () => { - const userDir = 'test/user/is-positive' + test('store source files in temporary directory and user files in user directory, when given editDir option', async () => { + const editDir = 'test/user/is-positive' - const patchFn = async () => patch.handler({ ...defaultPatchOption, userDir }, ['is-positive@1.0.0']) + const patchFn = async () => patch.handler({ ...defaultPatchOption, editDir }, ['is-positive@1.0.0']) const output = await patchFn() const userPatchDir = output.substring(output.indexOf(':') + 1).trim() - expect(userPatchDir).toBe(path.join(userDir, '/user')) + expect(userPatchDir).toBe(path.join(editDir, '/user')) expect(fs.existsSync(userPatchDir)).toBe(true) expect(fs.existsSync(path.join(tempySpy.mock.results[0].value, '/source'))).toBe(true) - // If userDir already exists, it should throw an error - await expect(patchFn()).rejects.toThrow(`The package directory already exists: '${userDir}'`) + // If editDir already exists, it should throw an error + await expect(patchFn()).rejects.toThrow(`The package directory already exists: '${editDir}'`) }) })