jsii icon indicating copy to clipboard operation
jsii copied to clipboard

Missing support for npm local path dependencies

Open vktry-k-it opened this issue 2 years ago • 1 comments

Describe the issue

The following POSIX shell script generates 3 JSII projects (A,B,C), where 2 of the projects (B,C) are dependent upon the other project (A). Project B depends upon project A by version reference, project C depends upon project A by local path reference.


mkdir -p project-a/lib project-b/lib project-c/lib

touch project-a/README.md project-b/README.md project-c/README.md

PROJECT_A_PREFIX=$(tr -dc a-z0-9 </dev/urandom | head -c 5)

cat << EOF > project-a/package.json
{
  "name": "$PROJECT_A_PREFIX-project-a",
  "version": "0.0.0",
  "author": "Sample Author",
  "description": "Sample Description",
  "license": "GPL-3.0-only",
  "repository": {
    "type": "git",
    "url": "about:blank"
  },
  "type": "module",
  "main": "lib/index.js",
  "devDependencies": {
    "@types/node": "10.17.27",
    "constructs": "10.1.285",
    "jsii": "^1.71.0",
    "typescript": "~4.9.3",
    "jsii-pacmak": "^1.71.0"
  },
  "dependencies": {},
  "bundleDependencies": [],
  "peerDependencies": {
      "constructs": "10.1.285"
  },
  "types": "lib/index.d.ts",
  "stability": "experimental",
  "jsii": {
      "outdir": "dist",
      "targets": {}
  }
}
EOF

cat << EOF > project-b/package.json
{
  "name": "project-b",
  "version": "0.0.0",
  "author": "Sample Author",
  "description": "Sample Description",
  "license": "GPL-3.0-only",
  "repository": {
    "type": "git",
    "url": "about:blank"
  },
  "main": "lib/index.ts",
  "devDependencies": {
    "@types/node": "10.17.27",
    "jsii": "^1.71.0",
    "typescript": "~4.9.3",
    "constructs": "10.1.285",
    "$PROJECT_A_PREFIX-project-a": "0.0.0",
    "jsii-pacmak": "^1.71.0"
  },
  "dependencies": {
  },
  "peerDependencies": {
      "constructs": "^10.1.285",
      "$PROJECT_A_PREFIX-project-a": "0.0.0"
  },
  "bundleDependencies": [
  ],
  "types": "lib/index.d.ts",
  "stability": "experimental",
  "jsii": {
      "outdir": "dist",
      "targets": {}
  }
}
EOF

cat << EOF > project-c/package.json
{
  "name": "project-c",
  "version": "0.0.0",
  "author": "Sample Author",
  "description": "Sample Description",
  "license": "GPL-3.0-only",
  "repository": {
    "type": "git",
    "url": "about:blank"
  },
  "main": "lib/index.ts",
  "devDependencies": {
    "@types/node": "10.17.27",
    "jsii": "^1.71.0",
    "typescript": "~4.9.3",
    "constructs": "10.1.285",
    "$PROJECT_A_PREFIX-project-a": "file:../project-a",
    "jsii-pacmak": "^1.71.0"
  },
  "dependencies": {},
  "peerDependencies": {
      "constructs": "^10.1.285",
      "$PROJECT_A_PREFIX-project-a": "0.0.0"
  },
  "bundleDependencies": [
  ],
  "types": "lib/index.d.ts",
  "stability": "experimental",
  "jsii": {
      "outdir": "dist",
      "targets": {}
  }
}
EOF

cat << EOF > project-a/lib/index.ts
import {
    Construct,
    IConstruct,
} from 'constructs';

export interface ISampleConstruct extends IConstruct {}

export class SampleConstruct extends Construct implements ISampleConstruct {

    constructor(construct: Construct, id: string) {

        super(construct, id);
    };
}
EOF

cat << EOF > project-b/lib/index.ts
import {Construct} from 'constructs';
import {
    SampleConstruct,
    ISampleConstruct,
} from '$PROJECT_A_PREFIX-project-a';

export class ChildSampleConstruct extends SampleConstruct implements ISampleConstruct {

    constructor(construct: Construct, id: string) {

        super(construct, id);
    };
}

new ChildSampleConstruct(undefined as unknown as Construct, 'sample');
EOF

cp project-b/lib/index.ts project-c/lib/index.ts

sh -c "cd project-a && npm install && npx jsii && npx jsii-pacmak -v --target js && npm publish"

sh -c "cd project-b && npm install && npx jsii && npx jsii-pacmak -v --target js"

sh -c "cd project-c && npm install && npx jsii && npx jsii-pacmak -v --target js"

results in:

                                                                                                                                                             
                                                                                                                                                             
                                                                                                                                                             
up to date, audited 93 packages in 752ms                                                                                                                     
                                                                                                                                                             
12 packages are looking for funding                                                                                                                          
  run `npm fund` for details                                                                                                                                 
                                                                                                                                                             
found 0 vulnerabilities                                                                                                                                      
[jsii-pacmak] [INFO] Found 1 modules to package                                                                                                              
[jsii-pacmak] [INFO] Packaging NPM bundles                                                                                                                   
[jsii-pacmak] [INFO] Loading jsii assemblies and translations                                                                                                
[jsii-pacmak] [INFO] Packaging 'js' for 1413x-project-a                                                                                                      
[jsii-pacmak] [INFO] js finished                                                                                                                             
[jsii-pacmak] [INFO] Packaged. npm pack (0.7s) | js (0.0s) | load jsii (0.0s) | cleanup (0.0s)                                                               
npm notice                                                                                                                                                   
npm notice 📦  [email protected]                                                                                                                         
npm notice === Tarball Contents ===                                                                                                                          
npm notice 2.8kB  .jsii                                                                                                                                      
npm notice 0B     README.md                                                                                                                                  
npm notice 247B   lib/index.d.ts                                                                                                                             
npm notice 1.3kB  lib/index.js                                                                                                                               
npm notice 664B   package.json                                                                                                                               
npm notice 38.1kB tsconfig.tsbuildinfo                                                                                                                       
npm notice === Tarball Details ===                                                                                                                           
npm notice name:          1413x-project-a                                                                                                                    
npm notice version:       0.0.0                                    
npm notice filename:      1413x-project-a-0.0.0.tgz               
npm notice package size:  7.6 kB                                   
npm notice unpacked size: 43.1 kB                                  
npm notice shasum:        08ac78b1ee97f5b5fe5af6c669d518542fd1c1ca
npm notice integrity:     sha512-sw35CNjB/8VmT[...]KT99NTzjWIGMw==
npm notice total files:   6                                        
npm notice 
npm notice Publishing to https://registry.npmjs.org/ with tag latest and default access
+ [email protected]
+ [email protected]

added 36 packages, removed 1 package, and audited 94 packages in 3s

12 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[jsii-pacmak] [INFO] Found 1 modules to package
[jsii-pacmak] [INFO] Updated .npmignore
[jsii-pacmak] [INFO] Packaging NPM bundles
[jsii-pacmak] [INFO] Loading jsii assemblies and translations
[jsii-pacmak] [INFO] Packaging 'js' for project-b
[jsii-pacmak] [INFO] js finished
[jsii-pacmak] [INFO] Packaged. npm pack (0.7s) | js (0.0s) | load jsii (0.0s) | cleanup (0.0s)

added 36 packages, removed 1 package, and audited 94 packages in 2s

12 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
warning JSII6: A "peerDependency" on "1413x-project-a" at "0.0.0" means you should take a "devDependency" on "1413x-project-a" at "0.0.0" (found "file:../project-a")
[jsii-pacmak] [INFO] Found 1 modules to package
[jsii-pacmak] [INFO] Updated .npmignore
[jsii-pacmak] [INFO] Packaging NPM bundles
[jsii-pacmak] [INFO] Loading jsii assemblies and translations
[jsii-pacmak] [INFO] Packaging 'js' for project-b
[jsii-pacmak] [INFO] js finished
[jsii-pacmak] [INFO] Packaged. npm pack (0.7s) | js (0.0s) | load jsii (0.0s) | cleanup (0.0s)

The warning indicates, that local paths of dependencies inside package.json are currently not supported, whatever that implies.

This has been confusing to me, since i tried fixing it by following the suggestions, which lead upon many iterations of switching the dependency types and running into fatal errors.

It is nice to have the npm local path feature, since it speeds up development across multiple dependent JSII npm packages, but at least a notice about them not being supported, or a more thorough explanation on what is not expected to work would be nice.

Links

https://aws.github.io/jsii/user-guides/lib-author/configuration/#dependency-considerations https://docs.npmjs.com/cli/v7/configuring-npm/package-json#local-paths

vktry-k-it avatar Mar 21 '23 20:03 vktry-k-it

Related to https://github.com/aws/jsii/issues/4016

mrgrain avatar Apr 09 '24 11:04 mrgrain