From 34227d357475d5fe1b49374d1b8481e85a63b357 Mon Sep 17 00:00:00 2001 From: Thivi Date: Thu, 18 May 2023 16:49:04 +0530 Subject: [PATCH] Allow publishing from a specific folder using `publishPath` attribute --- __tests__/plugin-test.js | 56 ++++++++++++++++++++++++++++++++++++++++ index.js | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/__tests__/plugin-test.js b/__tests__/plugin-test.js index 05aeb7f..02f8bd2 100644 --- a/__tests__/plugin-test.js +++ b/__tests__/plugin-test.js @@ -260,6 +260,62 @@ describe('@release-it-plugins/workspaces', () => { expect(readWorkspacePackage('foo').version).toEqual('1.0.1'); }); + it('publishes from the publishPath attribute of the package.json', async () => { + setupProject({ packages: ['packages/*'] }); + + setupWorkspace({ name: 'foo' }); + setupWorkspace({ name: 'bar', publishPath: 'dist' }); + + let plugin = buildPlugin(); + + await runTasks(plugin); + + expect(plugin.operations).toMatchInlineSnapshot(` + Array [ + Object { + "command": "npm ping --registry https://registry.npmjs.org", + "operationType": "command", + "options": undefined, + }, + Object { + "command": "npm whoami --registry https://registry.npmjs.org", + "operationType": "command", + "options": undefined, + }, + Object { + "command": "npm publish ./packages/bar/dist --tag latest", + "operationType": "command", + "options": Object { + "write": false, + }, + }, + Object { + "command": "npm publish ./packages/foo --tag latest", + "operationType": "command", + "options": Object { + "write": false, + }, + }, + Object { + "messages": Array [ + "🔗 https://www.npmjs.com/package/bar", + ], + "operationType": "log", + }, + Object { + "messages": Array [ + "🔗 https://www.npmjs.com/package/foo", + ], + "operationType": "log", + }, + ] + `); + + expect(JSON.parse(dir.readText('package.json')).version).toEqual('1.0.1'); + expect(readWorkspacePackage('bar').version).toEqual('1.0.1'); + expect(readWorkspacePackage('foo').version).toEqual('1.0.1'); + }); + it('updates dependencies / devDependencies of packages', async () => { setupWorkspace({ name: 'derp' }); setupWorkspace({ name: 'qux' }); diff --git a/index.js b/index.js index e6bbba3..ecedb47 100644 --- a/index.js +++ b/index.js @@ -534,7 +534,7 @@ export default class WorkspacesPlugin extends Plugin { let absolutePath = path.join(root, file); let pkgInfo = JSONFile.for(absolutePath); - let relativeRoot = path.dirname(file); + let relativeRoot = path.join(path.dirname(file), pkgInfo.pkg.publishPath || ''); return { root: path.join(root, relativeRoot),