janniks / basetag

⚾️ A better way to import local NodeJS modules
MIT License
37 stars 3 forks source link

Add basetag bin for `npx basetag` #21

Closed coolaj86 closed 3 years ago

coolaj86 commented 3 years ago

This is important because npm install always destroys node_modules/$ and running npm ci can take minutes.

Usage

package.json:

{
  "scripts": {
    "postinstall": "npx basetag"
  }
}

Test my branch

npm install 'git+https://github.com/coolaj86/basetag.git#basetag-bin'
npx basetag
coolaj86 commented 3 years ago

@janniks I know you're busy, but I've giving this a bump just in a case you have some more time this week and have forgotten about it.

janniks commented 3 years ago

Thanks for the bump! And sorry for the delay — will do some coding on this now.

coolaj86 commented 3 years ago

@janniks You'd asked me to show you how this works, here's a go:

Working Example

Create a project using basetag (using my fork because I know my exact changes work):

mkdir -p /tmp/example
pushd /tmp/example/
npm init -y
npm install --save 'git+https://github.com/coolaj86/basetag.git#basetag-bin'

Check that the $ exists:

ls -laF /tmp/example/node_modules/\$

/tmp/example/node_modules/$@ ⇒ /private/tmp/example

Install something else (which will destroy $:

npm install --save @root/request

Check that the $ DOES NOT exist:

ls -laF /tmp/example/node_modules/\$

lsd: /tmp/example/node_modules/$: No such file or directory (os error 2).

Edit that project's package.json to include a basetag script:

vim /tmp/example/package.json
{
  // ...
  "scripts": {
    "postinstall": "npx basetag",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  // ...
}

Now run npm install again:

npm install

See that the basetag $ exists:

ls -laF /tmp/example/node_modules/\$

/tmp/example/node_modules/$@ ⇒ /private/tmp/example

Bad News

The bad news is that if we install a specific item, it breaks again until we re-run npm install, which I had not realized at first:

npm install --save @root/request

Check $:

ls -laF /tmp/example/node_modules/\$

lsd: /tmp/example/node_modules/$: No such file or directory (os error 2).

Run npm install again:

npm install

Check $:

ls -laF /tmp/example/node_modules/\$

/tmp/example/node_modules/$@ ⇒ /private/tmp/example
janniks commented 3 years ago

Got it! This is where my confusion came from — I thought you meant it also works after a specific package install (e.g. npm install --save x)

I'm working on a solution that could both be used as the postinstall script (as in your branch) but also sets up the .hooks file to work after a specific package install. Then we would cover all bases and avoid a lot of confusion for new users.