Skip to content
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

[BUG] npm i -g @swc/cli removed my git repository #3457

Closed
1 task done
kdy1 opened this issue Jun 23, 2021 · 5 comments
Closed
1 task done

[BUG] npm i -g @swc/cli removed my git repository #3457

kdy1 opened this issue Jun 23, 2021 · 5 comments
Assignees
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release

Comments

@kdy1
Copy link

kdy1 commented Jun 23, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Deletes git repository.
(Removed .git and tracked files)

Expected Behavior

Install without error

Steps To Reproduce

  1. Clone https://github.com/kdy1/swc.git
  2. Checkout resolver branch
  3. npm i
  4. npm run build:dev
  5. npm link
  6. npm i -g @swc/cli

Environment

  • OS: macOS Big Sur
  • Node:
➜  swc-bugs node -v
v14.16.1

Note: I installed latest version of node js because of stack trace issue on github actions.

➜  swc-bugs brew info node
node: stable 16.3.0 (bottled), HEAD
Platform built on V8 to build network applications
https://nodejs.org/
/usr/local/Cellar/node/14.4.0 (107 files, 650KB)
  Built from source
/usr/local/Cellar/node/15.12.0 (3,268 files, 55.5MB)
  Poured from bottle on 2021-03-31 at 15:11:58
/usr/local/Cellar/node/16.2.0 (2,784 files, 49MB) *
  Poured from bottle on 2021-05-30 at 20:06:55
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/node.rb
License: MIT
==> Dependencies
Build: pkg-config ✔, python@3.9 ✔
Required: brotli ✔, c-ares ✔, icu4c ✔, libuv ✔, nghttp2 ✔, openssl@1.1 ✔
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 323,426 (30 days), 1,082,930 (90 days), 4,400,808 (365 days)
install-on-request: 254,200 (30 days), 847,506 (90 days), 3,304,651 (365 days)
build-error: 0 (30 days)
  • npm:
npm@7.14.0 /Users/kdy1/.nvm/versions/node/v14.16.1/lib/node_modules/npm
@kdy1 kdy1 added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Jun 23, 2021
@kdy1 kdy1 changed the title [BUG] npm i -g @swc/cli removed my directory gBUG] npm i -g @swc/cli removed my git repository Jun 23, 2021
@darcyclarke darcyclarke changed the title gBUG] npm i -g @swc/cli removed my git repository [BUG] npm i -g @swc/cli removed my git repository Jun 23, 2021
@ljharb
Copy link
Contributor

ljharb commented Jun 23, 2021

Duplicate of #2104?

@kdy1
Copy link
Author

kdy1 commented Jun 24, 2021

@ljharb npm link was successful. Before getting this issue, my folder was removed when I canceled npm i -g @swc/cli

I get this issue even though @swc/cli installation was successful.

@isaacs
Copy link
Contributor

isaacs commented Aug 18, 2021

I can reproduce this.

Simplest reproduction I've whittled it down to so far:

#!/usr/bin/env bash
rm -rf prefix swc
mkdir -p prefix/lib
mkdir swc

# just a dummy file
cat >swc/package.json <<PJ
{
  "name": "@swc/core",
  "version": "1.2.23-alpha.1"
}
PJ

cat >swc/donotdelete <<DATA
please do not delete this file
DATA

args=(--quiet --audit=false --ignoreScripts --global)
arborist reify prefix/lib --add=file:swc "${args[@]}"

arborist reify prefix/lib "${args[@]}" --update # '--add=@swc/cli' also works

if ! [ -d swc/donotdelete ]; then
  echo 'DAMAGED'
  exit 1
else
  echo 'PASS'
fi

This seems related to a few different subtle issues combining. I can't seem to get it to reproduce in a simpler tree, so there's definitely something very interesting here relating (i think?) to a peer dep of both a top-level global package and one of its dependencies, which is not satisfied by the thing being linked, and where the peer dep itself has dependencies as well.

@isaacs isaacs self-assigned this Aug 18, 2021
@isaacs
Copy link
Contributor

isaacs commented Aug 19, 2021

Ok, I have a fix for this. It'll be in the next npm release. Thanks @nlf for pairing through it with me.

isaacs added a commit to npm/arborist that referenced this issue Aug 19, 2021
We should never be doing this.  Any time we're extracting contents, it
should be into an honest to goodness directory, and not any other kind
of thing.

Commits to follow will make it impossible to reach this condition
without some very deep hacking, but the check is here to make it easier
to debug if anything like this is reported again.

Related-to: npm/cli#3457
isaacs added a commit to npm/arborist that referenced this issue Aug 19, 2021
When working with the global install space, such as
/usr/local/lib/node_modules, we create a "project root" at the parent of
the node_modules directory, and then more or less proceed normally, with
the globalStyle install strategy.

The main difference, of course, is that in such a case, we should not
ever place *peers* of a top-level global dependency in that same global
space.  This is part of the root cause of npm/cli#3457, where a peer
dependency of the globally installed package was placed as a top-level
globally installed package, instead of being nested under its dependent.

Note that this _also_ could result in an `ERESOLVE` if multiple
globally-installed packages depended upon conflicting versions of a peer
dep, or worse yet, quietly replacing that peerDep in such a way that it
breaks a previously-installed globally installed package.

With this change, peer dependencies of a global top-level package will
always be nested under their dependent, removing any chance that they
might collide with anything else in the top level of the global install
space.

Fix: npm/cli#3457
@isaacs
Copy link
Contributor

isaacs commented Aug 19, 2021

This is fixed in npm 7.21.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

3 participants