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

Projectionist is not working as expected #192

Open
jiz4oh opened this issue Jul 25, 2024 · 6 comments
Open

Projectionist is not working as expected #192

jiz4oh opened this issue Jul 25, 2024 · 6 comments

Comments

@jiz4oh
Copy link

jiz4oh commented Jul 25, 2024

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
Copy link

bfrg commented Nov 29, 2024

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
Copy link
Author

jiz4oh commented Nov 29, 2024

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
Copy link

bfrg commented Nov 29, 2024

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
Copy link
Author

jiz4oh commented Nov 29, 2024

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
Copy link
Owner

tpope commented Nov 29, 2024

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.

@jiz4oh
Copy link
Author

jiz4oh commented Dec 8, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants