0

I have a lib package that has (following AWS guidance)

"devDependencies": {
    "aws-cdk-lib": "2.1.0"
  },
"peerDependencies": {
    "aws-cdk-lib": "^2.1.0"
  },

It is checked out in parallel with my app package and depended via relative path.

"dependencies": {
    "lib": "../../lib",
    "aws-cdk-lib": "2.39.0"
  },

Current behaviour:

  1. npm install in lib
  2. npm install in app creates a symblink to lib in node_module. "aws-cdk-lib": "2.1.0" is used.

Desired behaviour:

  1. npm install in lib
  2. npm install in app clones the src of lib, and builds lib in node_module with "aws-cdk-lib": "2.39.0"

How do I achieve this?

I don't want to use other workarounds like depending via git repo because I don't have an easy way to get git credentials during deployment.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
shawn
  • 1
  • 1

1 Answers1

0

I really don't recommend this, but if all you want is the source to be compiled, just import it directly:

import { X } from '../../lib'

But you'll have to install the lib's dependencies in your project as well.

Alternatively, you can alias the import path in your tsconfig.json by adding:

"compilerOptions": {
    "baseUrl": "src",
    "paths": {
        "@lib": ["../../lib/*"]
    }
}

And import it as:

import { X } from '@lib'

But again, you have to add the libs dependencies to you project's package.json.

At that stage, you're better off just copy/pasting the code into your project, that's much less brittle, but still not a great way of managing it.

It's a much better idea to just install the lib via npm. If you don't own the lib, but you do own the pipeline, there are workarounds that might work. For example, it could be easier to clone the repo to codecommit and install it from there, it all depends on what the problem is exactly.

Bottom line is, I wouldn't make a brittle codebase just because your deployment pipeline is tricky, the pipeline is supposed to help, not make your life harder.

Richard Dunn
  • 6,165
  • 1
  • 25
  • 36
  • Thanks Richard, I'll bite the bullet and use git module import following [this guide](https://stackoverflow.com/a/40312033). This brittle way causes more problem when there are breaking changes and the consuming package need to depend on a previous major version, since the latest src is always pulled down. – shawn Sep 06 '22 at 01:00
  • That's only if you don't specify a commit. You can add the commit id or tag to the end of the URL with a hash, I do it all the time. `"lib": "git+ssh://my.lib.url#"` – Richard Dunn Sep 06 '22 at 20:06