dev-cli
dev-cli copied to clipboard
Pack doesn't work with yarn workspace (with package inter-dependency)
$ 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 theyarn.lock
is under the workspace root butpack
checks for ayarn.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 becausepack
copies everything from say./packages/cli
to./packages/cli/tmp
wheretmp
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
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 : Also ran into this issue, did you find any workaround?
bump, also having this issue
The first problem ("can't find package-lock.json") seems to be fixed in https://github.com/oclif/dev-cli/pull/156.
+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.
same issue, any work around?
+1 for a workaround that doesn't involve a privately hosted npm registry for an unpublished CLI
I managed to work around by:
- add the tmp directory to your root yarn package.json workspaces array
- 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