vim-projectionist icon indicating copy to clipboard operation
vim-projectionist copied to clipboard

Projectionist is not working as expected

Open jiz4oh opened this issue 1 year ago • 6 comments

image Hi @tpope, I have a project built by node and it has many microapps, and each apps has the same structure like app-demo with node_modules and package.json

node_modules/
packages/
    apps/
        app-case/
        app-root/
        app-freight/
        app-demo/
              node_modules/
              package.json

I would like to set something on package.json under each app and exclude anything in node_modules, but it's not working even if I set .projections.json as below

{
  "packages/apps/*/package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  },
  "package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  }
}

and this will scan all the node_modules, it's too slow for me

{
  "!packages/apps/*/node_modules&packages/apps/*/package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  },
  "package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  }
}

could you help resolve this issue or is there any other way to ignore the node_modules?

jiz4oh avatar Jul 25 '24 07:07 jiz4oh

I would like to set something on package.json under each app and exclude anything in node_modules, but it's not working even if I set .projections.json as below

What exactly doesn't work? I just tried it with your .projections.json and the following directory structure and it seems to work:

.
├── node_modules
├── packages
│   └── apps
│       ├── app-one
│       │   ├── node-modules
│       │   └── package.json
│       ├── app-three
│       │   ├── node-modules
│       │   └── package.json
│       └── app-two
│           ├── node-modules
│           └── package.json
└── package.json

bfrg avatar Nov 29 '24 00:11 bfrg

Hi @bfrg, mostly of node modules has the package.json and all of them will be set as a lib due to

  "package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  }

but I would like only set the app-one app-two app-three except others which under node_modules as the lib

jiz4oh avatar Nov 29 '24 02:11 jiz4oh

If you know the prefix of each app, you can do this:

{
  "packages/apps/app-*/package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  },
  "package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  }
}

Alternatively, you can also specify a projection for each app:

{
  "packages/apps/foo/package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  },
  "packages/apps/bar/package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  },
  "package.json": {
    "type": "lib",
    "alternate": [
      "pnpm-lock.yaml"
    ]
  }
}

This is certainly more cumbersome.

bfrg avatar Nov 29 '24 14:11 bfrg

thank you for your advise, agreed with This is certainly more cumbersome, so I expected the !packages/apps/*/node_modules&packages/apps/*/package.json works that ignore the package.json which under node_modules

jiz4oh avatar Nov 29 '24 15:11 jiz4oh

It took me a while to figure out what the question actually was. I think the issue is that packages/apps/*/package.json is treated by Projectionist as packages/apps/**/*/package.json, and there's no way around this. And there's not really a good way to fix this without breaking backwards compatibility. You could maybe trick it by using package/**/apps/*/package.json, which will make it recursive in a direction that probably won't match anything.

Note that ! and & are for g:projectionist_heuristics and can't be used here.

tpope avatar Nov 29 '24 20:11 tpope

Hi @tpope, thanks for your suggestion, sorry for the late reply. the package/**/apps/*/package.json works for me, but there is still a performance issue, the vim is blocked when I type :Elib a, which seems like the complete function is searching each node_modules recursively. is there any solution like .gitignore that lets us ignore some big directories?

jiz4oh avatar Dec 08 '24 14:12 jiz4oh