0x80 / isolate-package

Isolate a monorepo package with its internal dependencies to form a self-contained directory with a pruned lockfile
MIT License
121 stars 13 forks source link

use within npm workspace #19

Closed npomfret closed 1 year ago

npomfret commented 1 year ago

I'm having trouble getting this working within a project that uses npm workspace. I have a workspace defined in a package.json file at the root:

  ...
  "workspaces": [
    "packages/*",
    "firebase/*"
  ],
  ...

And in the firebase directory I have a functions subdirectory (containing my firebase.json file). And inside packages there is a directory containing a typescript library called shared-code which is declared as a dependency in the package.json file in the functions.

root
  -- tsconfig.json
     package.json (defines workspaces "firebase" and "packages")
     node_modules

  -- firebase
    -- functions
      -- firebase.json
         package.json (with dependency file:../../shared-code)
         <-- no node_modules! -->

  -- packages
    -- shared-code
      -- package.json
         tsconfig.json
         node_modules

When I run npm install in the root of the entire project, the result is that a node_modules directory gets created at the root of the project, BUT there is no node_modules directory at all inside my functions workspace.

So when I run firebase deploy ... (inside firebase/functions) it fails immediately because there is no node_modules dir present. In my case with Cannot find local ESLint!.

@0x80 Is there a solution?

0x80 commented 1 year ago

AFAIK npm workspaces hoists al node modules to the root, so that would explain why there is no node_modules folder in your workspace packages, but it's been a while since I used it.

It seems to me like your problem is not related to isolate-package. What does your firebase.json file look like?

I also suggest creating a isolate.config.json and setting logLevel to "debug" as explained here

If you are still stuck you could send me a zip with your code to thijs@codecompose.com and I'll have a quick look.

0x80 commented 1 year ago

I'm going to close this for now, assuming that your issue is not directly caused by isolate-package. Feel free to re-open if you have more info.

npomfret commented 1 year ago

@0x80 I will add you to my repo if that's ok?

I've tried again, but was unable to get it work work. The 2nd attempt failed because the references in my tsconfig.json contained a relative path to the shared code, like this:

...
  "references": [
    {
      "path": "../path-to-shared-code"
    }
  ]

When the files get moved to the isolate dir, that path is no longer valid. Any help would be appreciated.