feat: check for outdated packages #270
feat: check for outdated packages #270kaf-lamed-beyt wants to merge 14 commits intotriggerdotdev:mainfrom
Conversation
🦋 Changeset detectedLatest commit: d38b54f The changes in this PR will be included in the next version bump. This PR includes changesets to release 25 packages
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 |
|
While trying to test, I'm stuck at the point where I have to do 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.
``` |
|
@kaf-lamed-beyt it looks like Docker isn't running. You probably just need to run It's step 6 in the setup in the Contributing guide: https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md |
|
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. |
|
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 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 0I think it is sort of related to my Postgres version. What would you advice @ericallam? |
|
@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. |
| 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}`); | ||
| } | ||
| } |
There was a problem hiding this comment.
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}`);
}There was a problem hiding this comment.
Ha! This looks better. I'll include it.
|
|
||
| const packageJSONSchema = z.object({ | ||
| dependencies: z.record(z.string()), | ||
| devDependencies: z.record(z.string()), |
There was a problem hiding this comment.
devDependencies should be optional. The default with a new nextjs app is none
| 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."); |
There was a problem hiding this comment.
For now, this should be commented out, as it'll be a different PR to do this.
| } | ||
| console.warn("Run 'npx @trigger.dev/cli update' to update the packages."); | ||
| } else { | ||
| console.log("All @trigger.dev packages are up-to-date."); |
There was a problem hiding this comment.
If they're up to date I think it'd be better to log nothing
There was a problem hiding this comment.
Oh! Cool! I'll fix this now
Oh! I'd have to download the docker app? Or will the vscode extension work in this case? |
|
@matt-aitken I pushed some changes a moment ago. Kindly review. I'm currently downloading the docker desktop app. But, aside from that. I've also done 👇🏼 to remove unused volumes sudo docker system pruneCurrently, when I run 👇🏼 and try to delete it with the sudo docker volume lsFor now, I'm still looking for a workaround. When I find one, I'll let you know. |
…into outdated-packages
|
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. |
|
So awesome!! 🚀 cc: @matt-aitken One more thing. When i tried adding the changeset, I noticed that |
|
Hi @ericallam, @matt-aitken. In case you missed this. |
|
Okay, I'll check again now. |
…package versions instead of using strings
…into outdated-packages
|
@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. 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. |
|
@ericallam, I've included the changeset for this PR, kindly review. |
|
@matt-aitken, whenever you get the chance, please help me review this. |
| const formtattedInstalledVersion = semver.clean(installedVersion); | ||
| const formattedLatestVersion = semver.clean(latestVersion); |
There was a problem hiding this comment.
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:
- That it doesn't initially identify any outdated packages (i.e. does nothing).
- Modify one of the versions to be older, then check if identifies it and logs it out
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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\/.+$/"
When you're back if you can make this change we'll tip you generously because we've messed you around a bit here.
There was a problem hiding this comment.
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!
|
@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 |
|
Sure thing @ericallam! I'll do so. Thank you. ✊🏽 |
|
@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 |






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
examplesdir/claim #167