Components.js icon indicating copy to clipboard operation
Components.js copied to clipboard

Could not find a valid import path for src/lib/MyActor.jsonld. 'lsd:importPaths' in package.json may be invalid.

Open leorumma opened this issue 3 years ago • 12 comments

Issue type:

  • :bug: Bug

Description:

I'm following the tutorial. But I get this error when running the command npm run build I'm not able to generate MyActor.jsonld file automatically


Environment:

Crash log:

leorumma avatar Jul 19 '22 05:07 leorumma

Thanks for reporting!

github-actions[bot] avatar Jul 19 '22 05:07 github-actions[bot]

My package.json file

{
    "name":"tep-banco-dados-01-trabalho-final",
    "version":"1.0.0",
    "description":"",
    "main":"src/lib/index.js",
    "typings":"src/lib",
    "lsd:module":true,
    "scripts":{
        "test":"echo \"Error: no test specified\" && exit 1",
        "build":"npm run build:ts && npm run build:components",
        "build:ts":"tsc",
        "build:components":"componentsjs-generator",
        "prepare":"npm run build"
    },
    "files":[
        "components",
        "lib/**/*.d.ts",
        "lib/**/*.js"
    ],
    "keywords":[
        
    ],
    "author":"",
    "license":"ISC",
    "devDependencies":{
        "@types/node":"^18.0.6",
        "componentsjs-generator":"^3.0.5",
        "typescript":"^4.7.4"
    },
    "dependencies":{
        "componentsjs":"^5.2.0"
    }
}

leorumma avatar Jul 19 '22 05:07 leorumma

What tutorial are you following exactly (there are multiple)?

rubensworks avatar Jul 19 '22 06:07 rubensworks

the tutorial I'm following is in the repository readme https://github.com/LinkedSoftwareDependencies/Components-Generator.js

leorumma avatar Jul 19 '22 12:07 leorumma

Can you try moving your index file outside of the lib directory as a test? (and updating the references in your package.json)

rubensworks avatar Jul 19 '22 12:07 rubensworks

ok, I moved the index to the src folder and I changed my json.package

  "main": "src/index.js",
  "typings": "src",
  "lsd:module": true,

but the error continued

2022-07-19T12:38:29.052Z [Components.js] info: Generating components for 1 package
Could not find a valid import path for src/lib/MyActor.jsonld. 'lsd:importPaths' in package.json may be invalid.

image

MyActor class does not generate jsonld

components.jsonld

{
  "@context": [
    "https://linkedsoftwaredependencies.org/bundles/npm/tep-banco-dados-01-trabalho-final/^1.0.0/components/context.jsonld"
  ],
  "@id": "npmd:tep-banco-dados-01-trabalho-final",
  "@type": "Module",
  "requireName": "tep-banco-dados-01-trabalho-final",
  "import": []
}

context.jsonld

{
  "@context": [
    "https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^5.0.0/components/context.jsonld",
    {
      "npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
      "tbd0tf": "npmd:tep-banco-dados-01-trabalho-final/^1.0.0/"
    }
  ]
}

leorumma avatar Jul 19 '22 12:07 leorumma

Hmm, that doesn't seem to be the cause of the problem then.

Can you try setting your typings entry in package.json to refer to the actual index file, instead of the directory it exists within?

rubensworks avatar Jul 19 '22 12:07 rubensworks

I tried again another way.

I modified the package.json file with the information contained in the repository

Before (package.json)

{
  "name": "tep-banco-dados-01-trabalho-final",
  "version": "1.0.0",
  "description": "",
  "main": "src/lib/index.js",
  "typings": "src/lib",
  "lsd:module": true,
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "npm run build:ts && npm run build:components",
    "build:ts": "tsc",
    "build:components": "componentsjs-generator",
    "prepare": "npm run build"
  },
  "files": [
    "components",
    "lib/**/*.d.ts",
    "lib/**/*.js"
  ],
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^18.0.6",
    "componentsjs-generator": "^3.0.5",
    "typescript": "^4.7.4"
  },
  "dependencies": {
    "componentsjs": "^5.2.0"
  }
}

After (package.json)

{
  "name": "tep-banco-dados-01-trabalho-final",
  "version": "1.0.0",
  "description": "",
  "lsd:module": "testing_any_value",
  "lsd:components": "components/components.jsonld",
  "lsd:contexts": {
    "https://linkedsoftwaredependencies.org/bundles/npm/documentation-components/^1.0.0/components/context.jsonld": "components/context.jsonld"
  },
  "lsd:importPaths": {
    "https://linkedsoftwaredependencies.org/bundles/npm/documentation-components/^1.0.0/components/": "lib/"
  },
  "main": "index.js",
  "typings": "index",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "npm run build:ts && npm run build:components",
    "build:ts": "tsc",
    "build:components": "componentsjs-generator",
    "prepare": "npm run build"
  },
  "files": [
    "components",
    "lib/**/*.d.ts",
    "lib/**/*.js"
  ],
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/node": "^18.0.6",
    "componentsjs-generator": "^3.0.5",
    "typescript": "^4.7.4"
  },
  "dependencies": {
    "componentsjs": "^5.2.0"
  }
}

I added the following parameters

"lsd:module": "testing_any_value", "lsd:components": "components/components.jsonld", "lsd:contexts": { "https://linkedsoftwaredependencies.org/bundles/npm/documentation-components/^1.0.0/components/context.jsonld": "components/context.jsonld" }, "lsd:importPaths": { "https://linkedsoftwaredependencies.org/bundles/npm/documentation-components/^1.0.0/components/": "lib/" },

the npm build command worked and generated the jsonld of the MyActor.ts class

PS > npm run build                                                     

> [email protected] build
> npm run build:ts && npm run build:components 


> [email protected] build:ts
> tsc                                             


> [email protected] build:components
> componentsjs-generator                                  

2022-07-20T01:52:27.687Z [Components.js] info: Generating components for 1 package
PS > 

image

MyActor.jsonld

{
  "@context": [
    "https://linkedsoftwaredependencies.org/bundles/npm/documentation-components/^1.0.0/components/context.jsonld"
  ],
  "@id": "testing_any_value",
  "components": [
    {
      "@id": "testing_any_value/^1.0.0/lib/MyActor.jsonld#MyClass",
      "@type": "Class",
      "requireElement": "MyClass",
      "comment": "This is a great class!",
      "parameters": [
        {
          "@id": "testing_any_value/^1.0.0/lib/MyActor.jsonld#MyClass_paramA",
          "range": "xsd:boolean",
          "comment": "My parameter"
        },
        {
          "@id": "testing_any_value/^1.0.0/lib/MyActor.jsonld#MyClass_paramB",
          "range": "xsd:number"
        },
        {
          "@id": "testing_any_value/^1.0.0/lib/MyActor.jsonld#MyClass_paramC",
          "range": {
            "@type": "ParameterRangeArray",
            "parameterRangeValue": "xsd:string"
          }
        }
      ],
      "memberFields": [
        {
          "@id": "testing_any_value/^1.0.0/lib/MyActor.jsonld#MyClass__member_constructor",
          "memberFieldName": "constructor"
        }
      ],
      "constructorArguments": [
        {
          "@id": "testing_any_value/^1.0.0/lib/MyActor.jsonld#MyClass_paramA"
        },
        {
          "@id": "testing_any_value/^1.0.0/lib/MyActor.jsonld#MyClass_paramB"
        },
        {
          "@id": "testing_any_value/^1.0.0/lib/MyActor.jsonld#MyClass_paramC"
        }
      ]
    }
  ]
}

.componentsjs-generator-config.json

{
    "source": "lib",
    "destination": "components",
    "extension": "jsonld",
    "logLevel": "info",
    "ignorePackagePaths": [],
    "ignoreComponents": [],
    "modulePrefix": {}
}

however, I found three problems

  1. the option "lsd:module": true does not work, only with some text parameter "lsd:module": "testing_any_value".

  2. jsonld files are being generated in the lib folder. The correct one should be in the components folder

  3. in the example repository the option "lsd:importPaths": { "https://linkedsoftwaredependencies.org/bundles/npm/documentation-components/^1.0.0/components/": "components/" }, works. But, in my code I needed to change from components to lib to work and generate the jsonld from MyActor.ts

leorumma avatar Jul 20 '22 02:07 leorumma

Thanks for the findings @leorumma!

jsonld files are being generated in the lib folder. The correct one should be in the components folder

The lib folder is correct though, since that is that you've defined in your lsd:importPaths. If you want the components folder, then the following should work:

  "lsd:importPaths": {
    "https://linkedsoftwaredependencies.org/bundles/npm/documentation-components/^1.0.0/components/": "components/"
  }

(but this should be the default when using "lsd:module": true)

in the example repository the option "lsd:importPaths" works. But, in my code I needed to change from components to lib to work and generate the jsonld from MyActor.ts

So there must be some other difference between your package and the example package. Perhaps this function may help uncovering this difference: https://github.com/LinkedSoftwareDependencies/Components.js/blob/master/lib/loading/ModuleStateBuilder.ts#L175-L220

rubensworks avatar Jul 25 '22 10:07 rubensworks

I had a brief look at this, since I've also have experienced troubles when trying to set "lsd:module": true in my projects. Here are my findings so far.

Using: componentsjs: 5.2.0 componentsjs-generator: 3.0.5

I put a breakpoint at: https://github.com/LinkedSoftwareDependencies/Components-Generator.js/blob/master/lib/generate/Generator.ts#L139 and to inspect the components argument.

I find that the componentsjs-generator does not adhere to the configured paths in my package.json whenever the lsd:module is set to true.

See the following two examples:


Example 1

For a package.json configured like this (notice the lsd:module property is not a boolean):

  "lsd:module": "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock",
  "lsd:components": "dist/components/components.jsonld",
  "lsd:contexts": {
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/components/context.jsonld": "dist/components/context.jsonld"
  },
  "lsd:importPaths": {
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/components/": "dist/components/",
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/dist/": "dist/"
  },

The inspected components argument (at the breakpoint) looks like this:

{
  name: "@antwika/lock",
  version: "0.0.1",
  moduleIri: "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock",
  componentsPath: "E:\\Dev\\antwika\\lock\\dist\\components\\components.jsonld",
  contexts: {
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/components/context.jsonld": "dist/components/context.jsonld",
  },
  importPaths: {
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/components/": "dist/components/",
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/dist/": "dist/",
  },
  typesPath: "E:\\Dev\\antwika\\lock\\dist\\index",
  prefix: undefined,
}

This works as expected.


Example 2

For a package.json configured like this (notice the lsd:module property is a boolean):

  "lsd:module": true,
  "lsd:components": "dist/components/components.jsonld",
  "lsd:contexts": {
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/components/context.jsonld": "dist/components/context.jsonld"
  },
  "lsd:importPaths": {
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/components/": "dist/components/",
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/*/dist/": "dist/"
  },

The inspected components argument (at the breakpoint) looks like this:

{
  name: "@antwika/lock",
  version: "0.0.1",
  moduleIri: "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock",
  componentsPath: "E:\\Dev\\antwika\\lock\\components\\components.jsonld",
  contexts: {
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/^0.0.0/components/context.jsonld": "components/context.jsonld",
  },
  importPaths: {
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/^0.0.0/components/": "components/",
    "https://linkedsoftwaredependencies.org/bundles/npm/@antwika/lock/^0.0.0/config/": "config/",
  },
  typesPath: "E:\\Dev\\antwika\\lock\\dist\\index",
  prefix: undefined,
}

This does not work and throws an error here

Could not find a valid import path for ${sourcePath}. 'lsd:importPaths' in package.json may be invalid.


Notice the absence of dist/ in the paths in the Example 2 componentsjs argument. I've not put in enough time/effort to figure out exactly why the paths look so different. 🤔

ixuz avatar Jul 26 '22 19:07 ixuz

Thanks for the findings @ixuz!

I find that the componentsjs-generator does not adhere to the configured paths in my package.json whenever the lsd:module is set to true.

That is intentional (but perhaps shouldn't be). If lsd:module is set to true, then all other lsd: entries in the package.json will be overwritten: https://github.com/LinkedSoftwareDependencies/Components.js/blob/master/lib/loading/ModuleStateBuilder.ts#L175-L220

I'm definitely open to a change in this logic so that if lsd:module is true, only those lsd: entries that have not been explicitly defined will be generated.

rubensworks avatar Jul 27 '22 11:07 rubensworks

Do the findings in https://github.com/LinkedSoftwareDependencies/Components.js/issues/111#issuecomment-1368811736 help resolving any problems here?

rubensworks avatar Jan 02 '23 10:01 rubensworks