Skip to content

[labs/cli] labs gen command fails to detect lit component when globally installed #3234

@augustjk

Description

@augustjk

Which package(s) are affected?

Other/unknown (please mention in description)

Description

$ lit labs gen --framework=react
file:///Users/augustinekim/.nvm/versions/node/v16.16.0/lib/node_modules/@lit-labs/cli/lib/generate/generate.js:83
            throw new Error(errors);
                  ^

Error: Error generating 'react' wrapper for package './': Error: No Lit components were found in this package.
    at generateReactWrapper (file:///Users/augustinekim/testing/cli-test2/node_modules/@lit-labs/gen-wrapper-react/index.js:40:15)
    at Object.generate (file:///Users/augustinekim/testing/cli-test2/node_modules/@lit-labs/gen-wrapper-react/index.js:20:26)
    at file:///Users/augustinekim/.nvm/versions/node/v16.16.0/lib/node_modules/@lit-labs/cli/lib/generate/generate.js:70:54
    at Array.map (<anonymous>)
    at Module.run (file:///Users/augustinekim/.nvm/versions/node/v16.16.0/lib/node_modules/@lit-labs/cli/lib/generate/generate.js:67:61)
    at async Object.run (file:///Users/augustinekim/.nvm/versions/node/v16.16.0/lib/node_modules/@lit-labs/cli/lib/commands/labs.js:36:21)
    at async file:///Users/augustinekim/.nvm/versions/node/v16.16.0/lib/node_modules/@lit-labs/cli/bin/lit.js:24:16
    at Module.run (file:///Users/augustinekim/.nvm/versions/node/v16.16.0/lib/node_modules/@lit-labs/cli/lib/generate/generate.js:83:19)
    at async Object.run (file:///Users/augustinekim/.nvm/versions/node/v16.16.0/lib/node_modules/@lit-labs/cli/lib/commands/labs.js:36:21)
    at async file:///Users/augustinekim/.nvm/versions/node/v16.16.0/lib/node_modules/@lit-labs/cli/bin/lit.js:24:16

This affects all frameworks though example above shows react.

The culprit is the instanceof check here.

dec instanceof ClassDeclaration &&

It ends up returning false there because the @lit-labs/analyzer module used by the CLI is different than the one used by @lit-labs/gen-wrapper-* packages.

Reproduction

TODO

Workaround

Installing the cli as dev dependency of the project and running the project instance of the cli makes it share the same @lit-labs/analyzer package.

If we want the cli to work globally we may need to either:

  • Remove the instanceof check
  • Move the analysis to each gen-wrapper-* code so we just use a single analzyer (That would be a single analyzer per gen-wrapper and this would cause unnecessary multiple analyses to happen if generating multiple wrappers so not good)

Is this a regression?

No or unsure. This never worked, or I haven't tried before.

Affected versions

0.1.0

Browser/OS/Node environment

Node version: 16.16.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions