Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/extensions sdk cli validate #24269

Open
wants to merge 45 commits into
base: main
Choose a base branch
from

Conversation

ukmadlz
Copy link
Member

@ukmadlz ukmadlz commented Dec 20, 2024

Scope

What's changed:

  • The addition of a validate command for the extensions-sdk CLI
  • Basic checks for the existence of a /dist directory, README, license field, and a valid directus:extension object within the package.json

Potential Risks / Drawbacks

  • Drawbacks are it's naive and verbose

Review Notes / Questions

  • How do we want to test the CLI commands in general? Just the existing unit test suite or a more general integration set of tests?
    • Integration tests added ✅
  • What additional things should be validated for better DX? As well as improving the quality of extensions within the directus marketplace?

Closes #DX-547

@ukmadlz ukmadlz self-assigned this Dec 20, 2024
Copy link

changeset-bot bot commented Dec 20, 2024

🦋 Changeset detected

Latest commit: 5ff39df

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@directus/extensions-sdk Minor
@directus/api Patch
create-directus-extension Patch
directus Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ComfortablyCoding
Copy link
Contributor

ComfortablyCoding commented Dec 20, 2024

How do we want to test the CLI commands in general? Just the existing unit test suite or a more general integration set of tests?

Does not seem like we currently have tests for the cli commands. Might be worth adding if low complexity

Basic checks for the existence of a /dist directory, README, LICENSE, and a valid directus:extension object within the package.json

Note that /dist is not a required path, it is a controlled output via the path property

What additional things should be validated for better DX? As well as improving the quality of extensions within the directus marketplace?

  • As most extensions are intended to be distributed to the marketplace it should at minimum the required metadata
  • Check host is valid for the latest version of directus. Potential for option to override and check specific version

@ukmadlz ukmadlz marked this pull request as ready for review December 27, 2024 10:13
@phazonoverload
Copy link
Contributor

I'll check this out tomorrow, but we may also want to flag a warning if an extension cannot be published to the marketplace because it is a bundle or API extension and not sandboxed.

@ukmadlz
Copy link
Member Author

ukmadlz commented Dec 31, 2024

I'll check this out tomorrow, but we may also want to flag a warning if an extension cannot be published to the marketplace because it is a bundle or API extension and not sandboxed.

I've added the functionality to give a warning, as well as a specific test for appearing in the marketplace

ukmadlz and others added 3 commits January 7, 2025 10:22
…nse.ts

Co-authored-by: Hannes Küttner <kuettner.hannes@gmail.com>
Co-authored-by: Hannes Küttner <kuettner.hannes@gmail.com>
Copy link
Member

@paescuj paescuj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added basic integration tests in 29a311f.

In order for them to pass, the following changes are necessary:

  • in case of invalid checks, the process should exit with exit code 1
  • check the license field in package.json instead of license file
  • allow all readme file namings according to the official specs:

    README & LICENSE can have any case and extension.

  • the directus-config check is currently failing with initial extension state (which should of course be valid):
    reason: TypeError: string "interface" is not a function
      at Array.findIndex (<anonymous>)
      at Object.handler (file:///<...>/dist/cli/commands/validators/check-directus-config.js:68:76)
    

…from package.json & file, validate semver the same as marketplace frontend
…dlz/directus into feature/extensions-sdk-cli-validate
@ukmadlz ukmadlz requested a review from paescuj January 7, 2025 17:31
@ukmadlz ukmadlz requested a review from hanneskuettner January 8, 2025 15:05
const packageFile = await fse.readJson(packagePath);

if (packageFile[EXTENSION_PKG_KEY]) {
const { path } = packageFile[EXTENSION_PKG_KEY];
Copy link
Member

@licitdev licitdev Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path value could be an object that breaks subsequent checks.

path: { app: 'dist/app.js', api: 'dist/api.js' },

Eg: https://github.com/directus-labs/extensions/blob/70f71c801686e0cd6cf2391aa40bb34a4c5e6477/packages/flow-trigger-bundle/package.json#L17-L20

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've solved this on L36-L52 now

Comment on lines 37 to 42
const message = `No ${codePath} directory`;

reports.push({
level: 'error',
message: `${checkBuiltCode.name}: ${message}`,
});
Copy link
Contributor

@ComfortablyCoding ComfortablyCoding Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick and non-blocking but we do message + reports.push({...}) in quite a few places, might be worth to extract to a util?

Alternatively we can rework the validators to return back the level & message or throw an Error that we then process in the main thread instead of passing around a mutable reports array. The name can be extracted from the respective command.

Copy link
Contributor

@ComfortablyCoding ComfortablyCoding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! Mostly small nitpick non-blocking comments

packages/extensions-sdk/src/cli/run.ts Outdated Show resolved Hide resolved
packages/extensions-sdk/src/cli/run.ts Outdated Show resolved Hide resolved
packages/extensions-sdk/src/cli/run.ts Outdated Show resolved Hide resolved
ukmadlz and others added 8 commits January 10, 2025 16:43
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
…me.ts

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
…me.ts

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
…nse.ts

Co-authored-by: daedalus <44623501+ComfortablyCoding@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants