Skip to content

feat: check for outdated packages #270

Closed
kaf-lamed-beyt wants to merge 14 commits intotriggerdotdev:mainfrom
kaf-lamed-beyt:outdated-packages
Closed

feat: check for outdated packages #270
kaf-lamed-beyt wants to merge 14 commits intotriggerdotdev:mainfrom
kaf-lamed-beyt:outdated-packages

Conversation

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor

Hi @ericallam, kindly review this.

Although, I haven't been able to test, because my PC went off. When it's back up I'll try testing it by creating an example Next.js app in the examples dir

/claim #167

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Aug 6, 2023

🦋 Changeset detected

Latest commit: d38b54f

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

This PR includes changesets to release 25 packages
Name Type
@trigger.dev/cli Major
@examples/job-catalog Patch
@examples/jobs-starter Patch
@examples/nextjs Patch
@examples/nextjs-test Patch
@examples/package-tester Patch
@trigger.dev/tailwind-config Major
@trigger.dev/tsconfig Major
@trigger.dev/core Major
@trigger.dev/express Major
@trigger.dev/integration-kit Major
@trigger.dev/nextjs Major
@trigger.dev/react Major
@trigger.dev/sdk Major
@trigger.dev/github Major
@trigger.dev/openai Major
@trigger.dev/plain Major
@trigger.dev/resend Major
@trigger.dev/sendgrid Major
@trigger.dev/slack Major
@trigger.dev/stripe Major
@trigger.dev/supabase Major
@trigger.dev/typeform Major
nextjs-12 Patch
outdated-packages 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

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

While trying to test, I'm stuck at the point where I have to do pnpm run db:migrate. Kindly take a look at the error I'm getting.

pnpm run db:migrate 

> triggerdotdev@0.0.1 db:migrate /home/seven/Documents/codes/oss/trigger.dev
> turbo run db:migrate:deploy generate

• Packages in scope: @examples/job-catalog, @examples/jobs-starter, @examples/nextjs, @examples/package-tester, @trigger.dev/cli, @trigger.dev/core, @trigger.dev/database, @trigger.dev/express, @trigger.dev/github, @trigger.dev/integration-kit, @trigger.dev/nextjs, @trigger.dev/openai, @trigger.dev/plain, @trigger.dev/react, @trigger.dev/resend, @trigger.dev/sdk, @trigger.dev/slack, @trigger.dev/stripe, @trigger.dev/supabase, @trigger.dev/tailwind-config, @trigger.dev/tsconfig, @trigger.dev/typeform, docs, emails, eslint-config-custom, nextjs-12, outdated-packages, webapp
• Running db:migrate:deploy, generate in 28 packages
• Remote caching disabled
@trigger.dev/database:db:migrate:deploy: cache bypass, force executing 909df10673c0b4f0
@trigger.dev/database:generate: cache miss, executing 147eb0d5f9a081ae
@trigger.dev/database:generate: 
@trigger.dev/database:generate: > @trigger.dev/database@0.0.0 generate /home/seven/Documents/codes/oss/trigger.dev/packages/database
@trigger.dev/database:generate: > prisma generate
@trigger.dev/database:generate: 
@trigger.dev/database:db:migrate:deploy: 
@trigger.dev/database:db:migrate:deploy: > @trigger.dev/database@0.0.0 db:migrate:deploy /home/seven/Documents/codes/oss/trigger.dev/packages/database
@trigger.dev/database:db:migrate:deploy: > prisma migrate deploy
@trigger.dev/database:db:migrate:deploy: 
@trigger.dev/database:generate: Environment variables loaded from .env
@trigger.dev/database:generate: Prisma schema loaded from prisma/schema.prisma
@trigger.dev/database:db:migrate:deploy: Environment variables loaded from .env
@trigger.dev/database:db:migrate:deploy: Prisma schema loaded from prisma/schema.prisma
@trigger.dev/database:db:migrate:deploy: Datasource "db": PostgreSQL database "postgres", schema "public" at "localhost:5432"
@trigger.dev/database:db:migrate:deploy: 
@trigger.dev/database:db:migrate:deploy: Error: P1001: Can't reach database server at `localhost`:`5432`
@trigger.dev/database:db:migrate:deploy: 
@trigger.dev/database:db:migrate:deploy: Please make sure your database server is running at `localhost`:`5432`.
@trigger.dev/database:db:migrate:deploy:  ELIFECYCLE  Command failed with exit code 1.
@trigger.dev/database:db:migrate:deploy: ERROR: command finished with error: command (/home/seven/Documents/codes/oss/trigger.dev/packages/database) pnpm run db:migrate:deploy exited (1)
@trigger.dev/database:generate:  ELIFECYCLE  Command failed.
command (/home/seven/Documents/codes/oss/trigger.dev/packages/database) pnpm run db:migrate:deploy exited (1)

 Tasks:    0 successful, 2 total
Cached:    0 cached, 2 total
  Time:    4.076s 
Failed:    @trigger.dev/database#db:migrate:deploy

 ERROR  run failed: command  exited (1)
 ELIFECYCLE  Command failed with exit code 1.
 ```

@matt-aitken
Copy link
Copy Markdown
Member

@kaf-lamed-beyt it looks like Docker isn't running.

You probably just need to run pnpm run docker

It's step 6 in the setup in the Contributing guide: https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

I actually ran docker the first time and it outputed a text similar to: "containers created" and exited.

But, I'll try doing it again, and share what I see.

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

kaf-lamed-beyt commented Aug 7, 2023

This is what I'm seeing @matt-aitken

sudo pnpm run docker

> triggerdotdev@0.0.1 docker /home/seven/Documents/codes/oss/trigger.dev
> docker-compose -p triggerdotdev-docker -f docker/docker-compose.yml up -d

[+] Running 1/0
 ✔ Container database  Started                       

Edit: runing the command as is without the -d flag... here's what I'm getting.

sudo docker-compose -p triggerdotdev-docker -f docker/docker-compose.yml up

[+] Running 1/0
 ✔ Container database  Created                                                                                                                                                        0.0s 
Attaching to database
database  | 
database  | PostgreSQL Database directory appears to contain a database; Skipping initialization
database  | 
database  | 
database  | 2023-08-07 12:56:16.049 UTC [1] FATAL:  database files are incompatible with server
database  | 2023-08-07 12:56:16.049 UTC [1] DETAIL:  The data directory was initialized by PostgreSQL version 15, which is not compatible with this version 14.8 (Debian 14.8-1.pgdg120+1).
database exited with code 0

I think it is sort of related to my Postgres version. What would you advice @ericallam?

@matt-aitken
Copy link
Copy Markdown
Member

@kaf-lamed-beyt it looks like you need to delete your docker volume that's clashing. In the Docker UI you can go to the volumes and delete them.

Comment on lines +360 to +372
async function getLatestPackageVersion(packageName: string) {
const npmRegistryURL = `https://registry.npmjs.org/${packageName}`;
const response = await fetch(npmRegistryURL);

if (response.ok) {
const data = await response.json();
// use array destructuring because of the `dist-tags` property
// @ts-ignore
return data["dist-tags"].latest;
} else {
console.log(`Failed to fetch the latest version of ${packageName}`);
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It'd be nice to add a bit more safety to this:

const packageRegisterSchema = z.object({
  "dist-tags": z.object({
    latest: z.string(),
  }),
});

async function getLatestPackageVersion(packageName: string) {
  const npmRegistryURL = `https://registry.npmjs.org/${packageName}`;
  try {
    const response = await fetch(npmRegistryURL);

    if (response.ok) {
      const data = await response.json();
      const parsedData = packageRegisterSchema.safeParse(data);

      if (parsedData.success) {
        return parsedData.data["dist-tags"].latest;
      }
    }
  } catch (e) {}

  console.log(`Failed to fetch the latest version of ${packageName}`);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ha! This looks better. I'll include it.

Comment thread packages/cli/src/commands/dev.ts Outdated

const packageJSONSchema = z.object({
dependencies: z.record(z.string()),
devDependencies: z.record(z.string()),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

devDependencies should be optional. The default with a new nextjs app is none

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Cool. Noted!

Comment thread packages/cli/src/commands/dev.ts Outdated
for (const pkg of outdatedPackages) {
console.warn(`${pkg.name}: installed ${pkg.installedVersion}, latest ${pkg.latestVersion}`);
}
console.warn("Run 'npx @trigger.dev/cli update' to update the packages.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For now, this should be commented out, as it'll be a different PR to do this.

Comment thread packages/cli/src/commands/dev.ts Outdated
}
console.warn("Run 'npx @trigger.dev/cli update' to update the packages.");
} else {
console.log("All @trigger.dev packages are up-to-date.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If they're up to date I think it'd be better to log nothing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh! Cool! I'll fix this now

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

@kaf-lamed-beyt it looks like you need to delete your docker volume that's clashing. In the Docker UI you can go to the volumes and delete them.

Oh! I'd have to download the docker app?

Or will the vscode extension work in this case?

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

kaf-lamed-beyt commented Aug 8, 2023

@matt-aitken I pushed some changes a moment ago. Kindly review.

I'm currently downloading the docker desktop app.
image

But, aside from that. I've also done 👇🏼 to remove unused volumes

sudo docker system prune

Currently, when I run 👇🏼 and try to delete it with the rm command like so: sudo docker volume rm triggerdotdev-docker_database-data I'd find out that it is still running.

sudo docker volume ls

For now, I'm still looking for a workaround. When I find one, I'll let you know.

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

I found a fix!

I think one other issue that caused it, was because I might have omitted the steps outlined in the CONTRIBUTING guidelines. The dangling docker containers were involved too.

I'll push an update soon.

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

kaf-lamed-beyt commented Aug 9, 2023

So awesome!! 🚀

cc: @matt-aitken

image

One more thing. When i tried adding the changeset, I noticed that trigger.dev/cli isn't included in the options.

image

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

Hi @ericallam, @matt-aitken.

In case you missed this.

@ericallam
Copy link
Copy Markdown
Member

Can you double check this works? The screenshot you linked above looks like it's picking up an outdated package that isn't actually outdated:
CleanShot 2023-08-11 at 10 18 18

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

Okay, I'll check again now.

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

kaf-lamed-beyt commented Aug 11, 2023

@ericallam, the reason why both versions kept on showing up was because I was comparing the version strings instead using the appropriate approach.

So I used semver instead.

image

Mind you, the array of outdated package object above was just me trying to debug. It isn't logged to the console in the final fix.

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

@ericallam, I've included the changeset for this PR, kindly review.

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

@matt-aitken, whenever you get the chance, please help me review this.

Comment on lines +427 to +428
const formtattedInstalledVersion = semver.clean(installedVersion);
const formattedLatestVersion = semver.clean(latestVersion);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This code doesn't work with ^.

"^2.0.8" is being turned into null which means that no packages are ever considered outdated.

Follow this guide on testing the CLI: https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md#testing-cli-changes

Test:

  1. That it doesn't initially identify any outdated packages (i.e. does nothing).
  2. Modify one of the versions to be older, then check if identifies it and logs it out

Copy link
Copy Markdown
Contributor Author

@kaf-lamed-beyt kaf-lamed-beyt Aug 18, 2023

Choose a reason for hiding this comment

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

@matt-aitken

First off... if we're to modify the package version by editing the string to include ^, with what I've observed it doesn't change the package version unless the developer does npm install again.

And that means we may just be comparing the string values, and sometimes, before doing npm install the dev command will return that the packages (outdated and latest) are outdated as seen in this comment

But, with semver, since that is what I used, all package with their key value pairs (i.e. the name and versions) are most times represented with the leading ^ and semver considers those strings as invalid package versions because I'm trying to compare them with their respective string values from the npm API response.

So to avoid this issue, of invalid package versions, semver provides a clean() method to remove the ^ so that it can be considered as a valid one.

You can try modifying the code to exclude the check (with the clean method) and see the error I talked about.

Secondly, I'm sort of away from my computer for the next three weeks, I won't be able to access my PC till September 6 or thereafter.

So, if that's okay, I'd still love to work on this issue by then, if my approach with semver doesn't quite fit the problem.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @kaf-lamed-beyt,

Thanks for this, that makes sense. Now I understand why more frameworks don't do what we're trying to do here, it's not as simple as I thought it would be…

I think a better approach is to use this package: https://www.npmjs.com/package/npm-check-updates

It has a lot of contributors and high usage and allows programmatic usage (see the bottom of the readme) with wildcards.

If run from the command line:

npx npm-check-updates "/trigger.dev\/.+$/"

It correctly outputs
CleanShot 2023-08-18 at 11 42 33

When you're back if you can make this change we'll tip you generously because we've messed you around a bit here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah! I've seen npm-check-updates in action – frequently in some of the projects I use.

I'll be happy to implement this when I'm back. Thank you!

@ericallam
Copy link
Copy Markdown
Member

@kaf-lamed-beyt when you get back to this, might be best to just close this PR and create a new one starting from the latest changes in the main branch

@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

Sure thing @ericallam! I'll do so.

Thank you. ✊🏽

@ericallam ericallam closed this Aug 28, 2023
@kaf-lamed-beyt
Copy link
Copy Markdown
Contributor Author

@ericallam, I noticed that @neo773 submitted a PR (#412) that was merged.

There won't be a need to work on this anymore, yeah? Per this comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants