dev-cli icon indicating copy to clipboard operation
dev-cli copied to clipboard

Pack doesn't work with yarn workspace (with package inter-dependency)

Open kmannislands opened this issue 5 years ago • 8 comments

$ oclif-dev pack doesn't seem to work in a yarn workspace where the CLI depends on unpublished packages from the workspace.

  • First, I get a failure about 'can't find package-lock.json'. This seems to be because the yarn.lock is under the workspace root but pack checks for a yarn.lock in the CLI dir to determine if it should use yarn. Hacked past this by adding a symlink.
  • Next, you get an error from yarn that it can't find whatever the shared package is on the registry. This is reasonable because the shared package isn't published to any registry. Wondered why it isn't resolved to the workspace but looking at the implementation of pack, this is also expected as well because pack copies everything from say ./packages/cli to ./packages/cli/tmp where tmp in not part of the workspace technically.

Tried to hack past the last one by changing adding ./packages/cli/tmp/foo to my workspaces in the root package.json. This means that the dependency can be resolved since the tmp dir is now part of the workspace but now you get an error from yarn because there are two packages under the workspace with the same name. This also makes sense because both copies of package.json will have the same name

kmannislands avatar Apr 12 '19 23:04 kmannislands

Here's a minimal repro based on a fork of the most common workspace example. https://github.com/kmannislands/typescript-yarn-workspace-example

Steps were:

  • Added a cli package under the workspace using the oclif multi util
  • Packed it successfully on OSX
  • Added a dependency on the shared package (unpublished, named @cashew/common)
  • Verified that pack now fails for the reason above

kmannislands avatar Apr 12 '19 23:04 kmannislands

@kmannislands : Also ran into this issue, did you find any workaround?

akshetpandey avatar May 02 '19 19:05 akshetpandey

bump, also having this issue

mwebb33 avatar May 07 '20 21:05 mwebb33

The first problem ("can't find package-lock.json") seems to be fixed in https://github.com/oclif/dev-cli/pull/156.

fson avatar Aug 14 '20 13:08 fson

+1 does anyone have find a workaround for this issue ?

Here's the stack trace for the error :

$ oclif-dev pack -t linux-arm,linux-x64,darwin-x64
[...]
npm notice 
[1/5] Validating package.json...
[2/5] Resolving packages...
error An unexpected error occurred: "https://registry.yarnpkg.com/WORKSPACE_PACKAGE: Not found".
info If you think this is a bug, please open a bug report with the information provided in "/cli/tmp/project/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
    Error: Command failed: /bin/sh -c yarn --no-progress --production --non-interactive
    Code: 1
error Command failed with exit code 1.

Clebiez avatar Jun 16 '21 08:06 Clebiez

same issue, any work around?

judedaryl avatar Jul 08 '21 16:07 judedaryl

+1 for a workaround that doesn't involve a privately hosted npm registry for an unpublished CLI

deldrid1 avatar Nov 10 '21 20:11 deldrid1

I managed to work around by:

  1. add the tmp directory to your root yarn package.json workspaces array
  2. Change your build step to be as below:
cd packages/package-dir
sed -i 's#package-name-here#package-name-here-temp#g' package.json
mv "$(npm pack | tail -n 1)" dist/js/build-package-temp.tgz
sed -i 's#package-name-here-temp#package-name-temp#g' package.json
npx oclif pack:tarballs --targets linux-x64,win32-x86,darwin-x64 --tarball dist/js/build-package-temp.tgz
rm -rf dist/js/build-package-temp.tgz

This is possible due to the new --tarball flag you can pass to the pack command

danielblignaut avatar Mar 14 '22 16:03 danielblignaut