Skip to content

Commit

Permalink
Use less restrictive license, docs, test action
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed Aug 27, 2022
1 parent 07e97f2 commit f571fab
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 540 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: update-dependencies

on:
workflow_dispatch:
schedule:
- cron: "42 19 * * *"

jobs:
update-dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: denoland/setup-deno@v1
with:
deno-version: vx.x.x
- name: Update dependencies
run: |
export DATA=deno task update | tail -n 1 | tr -dc '0-9'
echo "::set-env name=DATA::$DATA"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
id: pr
with:
commit-message: "Update dependencies"
title: Update dependencies
body: >
Updated $DATA dependencies
Generated by [deno-outdated](https://github.com/LeoDog896/deno-outdated).
branch: deno-dependency-updates
author: GitHub <[email protected]>
delete-branch: true
- name: Retrieve commit sha
id: commit
run: |
echo "::set-output name=sha::$(git rev-parse HEAD)"
- name: Set commit status with pending
uses: Sibz/github-status-action@v1
with:
authToken: ${{ secrets.GITHUB_TOKEN }}
context: "Basic tests"
state: "pending"
sha: ${{ steps.commit.outputs.sha }}
- name: Basic tests
id: test
continue-on-error: true
run: |
deno task test
- name: Set commit status with outcome
uses: Sibz/github-status-action@v1
with:
authToken: ${{ secrets.GITHUB_TOKEN }}
context: "Basic tests"
description: "To run other CI actions close/reopen this PR"
state: ${{ steps.test.outcome }}
sha: ${{ steps.commit.outputs.sha }}
524 changes: 21 additions & 503 deletions LICENSE

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

Pins your dependencies to the latest version & updates existing ones.

Also check out: [uud](https://github.com/hayd/deno-udd)

```bash
deno install --allow-read=./ --allow-net --allow-write=./ -f -n=deno-outdated https://deno.land/x/deno_outdated/cli.ts
```
Expand Down Expand Up @@ -39,13 +37,18 @@ const x = 'https://deno.land/[email protected]/testing/asserts.ts' // i-deno-outdated

Currently works with:

- https://deno.land/x
- https://deno.land/
- https://esm.sh/
- https://cdn.jsdelivr.net
- https://unpkg.com

(Want to add more? Contribute to `regex.ts`)

## What's the difference between this and [UDD](https://github.com/hayd/deno-udd)?

This tool aims to be similar to deno native tools such as `deno fmt` and
`deno lint`, or aka shellable

## Internal layout

Updating works by finding URLs in a source file, removing their version
Expand Down
48 changes: 22 additions & 26 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts";
import { basename, join } from "https://deno.land/std@0.152.0/path/mod.ts";
import { basename, join } from "https://deno.land/std@0.153.0/path/mod.ts";
import { findAndReplace } from "./change.ts";

/**
* Recursively find all files in a directory
* @param path The starting parent path
* @param ignore The files to ignore
*/
export async function* recursiveReaddir(
path: string,
path = Deno.cwd(),
ignore: string[] = [],
): AsyncGenerator<string, void> {
for await (const dirEntry of Deno.readDir(path)) {
Expand All @@ -18,17 +23,15 @@ export async function* recursiveReaddir(
}

async function update(
quiet: boolean,
check: boolean,
quiet = false,
check = false,
ignore: string[] = [],
lineIgnore: string,
lineIgnore = "i-deno-outdated",
debug = false,
) {
let count = 0;
// TODO .gitignore
for await (const file of recursiveReaddir(Deno.cwd(), [...ignore, ".git"])) {
if (debug) console.log(`Scanning ${file}`);

if (ignore.includes(basename(file))) {
if (debug) console.log(`Ignoring ${file}`);
continue;
Expand Down Expand Up @@ -59,32 +62,25 @@ async function update(

await new Command()
.name("deno-outdated")
.version("0.0.1")
.option("-d --debug", "Show all scanned files", {
default: false,
})
.option("-q --quiet", "Silence any output", {
default: false,
})
.option("-i --ignore [ignore...:string]]", "list of files to ignore", {
separator: " ",
})
.version("0.3.0")
.option("-d, --debug", "Show all scanned files")
.option("-q, --quiet", "Silence any output")
.option(
"-c, --check",
"Check files without updating them",
)
.option(
"-l --line-ignore [line-ignore:string]",
"The text of the comment to ignore",
{
default: "i-deno-outdated",
},
)
.option(
"-c --check",
"True if the editor shouldn't change files and tell you about outdated dependencies.",
{
default: false,
},
)
.option("-i --ignore [ignore...:string]]", "list of files to ignore", {
separator: " ",
})
.description(
"Check for outdated dependencies for deno.land/x and other various 3rd party vendors",
"Check and update outdated dependencies for various 3rd party vendors",
)
.action(async ({ quiet, ignore, lineIgnore, debug, check }) => {
const count = await update(
Expand All @@ -94,6 +90,6 @@ await new Command()
typeof lineIgnore === "string" ? lineIgnore : "i-deno-outdated",
debug,
);
if (!quiet) console.log(`Updated ${count} file${count === 1 ? "" : "s"}`);
if (!quiet) console.log(`${check ? "Checked" : "Updated"} ${count} file${count === 1 ? "" : "s"}`);
})
.parse(Deno.args);
2 changes: 1 addition & 1 deletion redirect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Find the redirect of a URL, or `null` if no redirect exists.
* Find the redirect of a URL, or `undefined` if no redirect exists.
* @param url the URL
*/
export async function checkRedirect(url: string): Promise<string | undefined> {
Expand Down
8 changes: 8 additions & 0 deletions regex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ export interface Regex {
removal: RegExp;
}

/*
TODO all of the regexes currently follow:
Match: /https\?:\\\/\\\/([\w.]+)\\\/\[\^ "'`\]\+\/g
Replace: "$1"
All cases follow similar of not exactly the same removal case. When more regexes are added, if they all follow this pattern, it may be possible to easily update new registries that follow this.
*/
export const regexes: Regex[] = [
{
validate: /https?:\/\/deno.land\/[^ "'`]+/g,
Expand Down
7 changes: 5 additions & 2 deletions test/change.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
assert,
assertEquals,
assertNotEquals,
} from "https://deno.land/std@0.152.0/testing/asserts.ts";
} from "https://deno.land/std@0.153.0/testing/asserts.ts";

Deno.test("Source code translation works", async () => {
const source = "const x = 'https://deno.land/[email protected]/testing/asserts.ts'"; // i-deno-outdated
Expand All @@ -27,7 +27,10 @@ const x = 'https://deno.land/[email protected]/testing/asserts.ts' // i-deno-outdated
// ensure that the escape character bug does not exist
assert(!lines[0].includes("%22"));

assert(!lines[0].includes("i-deno-outdated"), "i-deno-outdated exists in the first line of the source string")
assert(
!lines[0].includes("i-deno-outdated"),
"i-deno-outdated exists in the first line of the source string",
);
assertNotEquals(lines[0], sourceLines[0]); // the deno-outdated line exists only exists in the code and not the string (as proven above)
assertEquals(lines[1], sourceLines[1]);

Expand Down
2 changes: 1 addition & 1 deletion test/redirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { checkRedirect } from "../redirect.ts";
import {
assertEquals,
assertNotEquals,
} from "https://deno.land/std@0.152.0/testing/asserts.ts";
} from "https://deno.land/std@0.153.0/testing/asserts.ts";

Deno.test("Redirects redirect to another URL (against deno.land/x)", async () => {
const redirect = await checkRedirect("https://deno.land/x/cliffy/mod.ts"); // i-deno-outdated
Expand Down
18 changes: 14 additions & 4 deletions update.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import { apply } from "./regex.ts";
import { checkRedirect } from "./redirect.ts";

export async function updateOrSelf(url: string): Promise<string> {
return (await checkRedirect(apply(url) ?? url)) ?? url;
/**
* Removes any versioning from a URL and finds the latest redirect for it
* @param url The URL to check against
* @returns The updated URL or undefined if it wasn't updated.
*/
export async function update(url: string): Promise<string | undefined> {
return (await checkRedirect(apply(url) ?? url));
}

export async function update(url: string): Promise<string | undefined> {
return (await checkRedirect(apply(url) ?? url)) ?? undefined;
/**
* Removes any versioning from a URL and finds the latest redirect for it
* @param url The URL to check against
* @returns The url whether it was updated or not.
*/
export async function updateOrSelf(url: string): Promise<string> {
return await update(url) ?? url;
}

0 comments on commit f571fab

Please sign in to comment.