tpope / vim-projectionist

projectionist.vim: Granular project configuration
https://www.vim.org/scripts/script.php?script_id=4989
1.06k stars 65 forks source link

Projectionist is not working as expected #192

Open jiz4oh opened 4 months ago

jiz4oh commented 4 months ago

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?

bfrg commented 3 days ago

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
jiz4oh commented 3 days ago

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

bfrg commented 2 days ago

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.

jiz4oh commented 2 days ago

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

tpope commented 2 days ago

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.