Skip to content

Commit

Permalink
feat: stabilize deps
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Aug 5, 2024
1 parent 8beff85 commit bc6dcad
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 92 deletions.
75 changes: 33 additions & 42 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { abortable, deadline, debounce, delay, retry } from 'jsr:@std/async@^1.0.1'
export { walk } from 'jsr:@std/fs@^1.0.0'
export { serveDir, type ServeDirOptions, STATUS_CODE, STATUS_TEXT, type StatusCode } from 'jsr:@std/http@^1.0.0-rc.6'
export { abortable, deadline, debounce, delay, retry } from 'jsr:@std/async@^1.0.2'
export { walk } from 'jsr:@std/fs@^1.0.1'
export { serveDir, type ServeDirOptions, STATUS_CODE, STATUS_TEXT, type StatusCode } from 'jsr:@std/http@^1.0.0'
export { joinGlobs, toFileUrl } from 'jsr:@std/path@^1.0.2'
export { normalize as posixNormalize } from 'jsr:@std/path@^1.0.2/posix/normalize'
export { escape } from 'jsr:@std/regexp@^1.0.0'
Expand Down
15 changes: 7 additions & 8 deletions dev_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ export {
Select,
type SelectOptions,
} from 'jsr:@cliffy/prompt@^1.0.0-rc.5'
export { ensure, is } from 'jsr:@core/unknownutil@^3.18.1'
export { as, ensure, is } from 'jsr:@core/unknownutil@^4.0.1'
export { createGraph, load as loadGraph } from 'jsr:@deno/graph@^0.81.0'
export type { DependencyJson, ResolvedDependency } from 'jsr:@deno/graph@^0.81.0/types'
export { Mutex } from 'jsr:@lambdalisue/async@^2.1.1'
export { assertEquals, assertExists } from 'jsr:@std/assert@^1.0.1'
export { parseArgs, Spinner } from 'jsr:@std/cli@^1.0.1'
export { assertEquals, assertExists } from 'jsr:@std/assert@^1.0.2'
export { parseArgs, Spinner } from 'jsr:@std/cli@^1.0.2'
export { filterEntries } from 'jsr:@std/collections@^1.0.5'
export { bold, cyan, dim, green, magenta } from 'jsr:@std/fmt@^1.0.0-rc.1/colors'
export { expandGlob } from 'jsr:@std/fs@^1.0.0'
export { getAvailablePort } from 'jsr:@std/net@^1.0.0-rc.2/get-available-port'
export { bold, cyan, dim, green, magenta } from 'jsr:@std/fmt@^1.0.0/colors'
export { expandGlob } from 'jsr:@std/fs@^1.0.1'
export { getAvailablePort } from 'jsr:@std/net@^1.0.0/get-available-port'
export { dirname, fromFileUrl, relative, resolve, toFileUrl } from 'jsr:@std/path@^1.0.2'
export { escape } from 'jsr:@std/regexp@^1.0.0'
export * as SemVer from 'jsr:@std/semver@^1.0.0-rc.3'
export * as SemVer from 'jsr:@std/semver@^1.0.0'

export const $ = new Proxy(_$, {
apply(target, thisArg, args: Parameters<$Type>) {
Expand Down
44 changes: 5 additions & 39 deletions scripts/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import {
$,
as,
assertExists,
createGraph,
type DependencyJson,
Expand All @@ -16,7 +17,6 @@ import {
fromFileUrl,
is,
loadGraph,
Mutex,
parseArgs,
parseFromJson,
resolve,
Expand All @@ -29,34 +29,10 @@ import {

const supportedProtocols = ['npm:', 'jsr:', 'http:', 'https:'] as const

class LatestVersionCache implements Disposable {
static #mutex = new Map<string, Mutex>()
static #cache = new Map<string, UpdatedDependency | null>()

constructor(readonly name: string) {
const mutex = LatestVersionCache.#mutex.get(name) ?? LatestVersionCache.#mutex.set(name, new Mutex()).get(name)!
mutex.acquire()
}

get(name: string): UpdatedDependency | null | undefined {
return LatestVersionCache.#cache.get(name)
}

set<T extends UpdatedDependency | null>(name: string, dependency: T): void {
LatestVersionCache.#cache.set(name, dependency)
}

[Symbol.dispose]() {
const mutex = LatestVersionCache.#mutex.get(this.name)
assertExists(mutex)
mutex.release()
}
}

const isNpmPackageMeta = is.ObjectOf({ 'dist-tags': is.ObjectOf({ latest: is.String }) })

const isJsrPackageMeta = is.ObjectOf({
versions: is.RecordOf(is.ObjectOf({ yanked: is.OptionalOf(is.Boolean) }), is.String),
versions: is.RecordOf(is.ObjectOf({ yanked: as.Optional(is.Boolean) }), is.String),
})

// #endregion
Expand Down Expand Up @@ -155,7 +131,7 @@ async function updateSpecifier(specifier: string) {
parsed.version = parsed.version.slice(1)
}

const resolved = await resolveLatestVersion(parsed, { cache: true, allowPreRelease: isPreRelease(parsed.version!) })
const resolved = await resolveLatestVersion(parsed, { allowPreRelease: isPreRelease(parsed.version!) })
if (!resolved) {
console.log(`Could not resolve latest version for ${specifier}`)
return specifier
Expand Down Expand Up @@ -316,21 +292,11 @@ function stringifyDependency(
*/
async function resolveLatestVersion(
dependency: Dependency,
options?: { cache?: boolean; allowPreRelease?: boolean },
options?: { allowPreRelease?: boolean },
): Promise<UpdatedDependency | undefined> {
const constraint = dependency.version ? SemVer.tryParseRange(dependency.version) : undefined
if (constraint && constraint.flat().length > 1) return
using cache = options?.cache ? new LatestVersionCache(dependency.name) : undefined
const cached = cache?.get(dependency.name)
if (cached) {
dependency.version === undefined
? { name: cached.name, path: dependency.name.slice(cached.name.length) }
: { ...cached, path: dependency.path }
}
if (cached === null) return
const result = await _resolveLatestVersion(dependency, options)
cache?.set(dependency.name, result ?? null)
return result
return await _resolveLatestVersion(dependency, options)
}

async function _resolveLatestVersion(
Expand Down

0 comments on commit bc6dcad

Please sign in to comment.