Files
renovate/lib/modules/manager/deno/extract.ts
Hajime-san 0004fcf69b feat(managers): add Deno manager support (#37828)
* works

* fix ci

Base branch is: main
Base branch ref for this PR is: c3a9360ecd
❌ Error: Snapshots have been added in this PR. Use toMatch instead.

* fix ci

Base branch is: main
Base branch ref for this PR is: c3a9360ecd
✅ Snapshot code check passed.
Added files in '__fixtures__':
lib/modules/manager/deno/__fixtures__/.gitignore
lib/modules/manager/deno/__fixtures__/npm-compat-workspace/deno.lock
lib/modules/manager/deno/__fixtures__/npm-compat-workspace/package.json
lib/modules/manager/deno/__fixtures__/npm-compat-workspace/sub/package.json
lib/modules/manager/deno/__fixtures__/workspace-01/deno.json
lib/modules/manager/deno/__fixtures__/workspace-01/deno.lock
lib/modules/manager/deno/__fixtures__/workspace-01/docs/deno.json
lib/modules/manager/deno/__fixtures__/workspace-01/docs/deno.lock
lib/modules/manager/deno/__fixtures__/workspace-01/packages/pkg1/deno.jsonc
lib/modules/manager/deno/__fixtures__/workspace-01/packages/pkg1/deno.lock
lib/modules/manager/deno/__fixtures__/workspace-02/deno.json
lib/modules/manager/deno/__fixtures__/workspace-02/deno.lock
lib/modules/manager/deno/__fixtures__/workspace-02/docs/deno.json
lib/modules/manager/deno/__fixtures__/workspace-02/import_map.json
lib/modules/manager/deno/__fixtures__/workspace-03/deno.json
lib/modules/manager/deno/__fixtures__/workspace-03/deno.lock
lib/modules/manager/deno/__fixtures__/workspace-03/node/package.json
Total number of added files in '__fixtures__': 17
Deleted files in '__fixtures__':

Total number of deleted files in '__fixtures__': 0

Updated total number of added files in '__fixtures__': 17
Updated total number of deleted files in '__fixtures__': 0
❌ Error: More files have been added to '__fixtures__' directories than deleted.
Error: Process completed with exit code 1.

* nit fix

* fix import map

* remove unnecessary mock

* nested workspace is invalid

* cleanup to postExtract

* revert JSR datasource files

* move to schema

* move

* cleanup lock

* importMapReferrer

* cleanup artifact test

* comment

* remove support deno-cli detailed behaviour due to complexity

* cleanup

* fix schema

* cleanup

* schema for updateDependency

* nit

* lint

* update doc

* tmp-promise

* no need filter deno

* returns an error

* remove delete lockfile

* store the importMapReferrer result

* constraints

* use parseJson

* remove processDenoCompatiblePackageJson

* move to types.ts

* Update lib/modules/manager/deno/post.ts

Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com>

* Revert "Update lib/modules/manager/deno/post.ts"

This reverts commit 64bd57649c.

* Revert "remove delete lockfile"

This reverts commit e701333519.

* Reapply "remove delete lockfile"

This reverts commit 89c3d79a43.

* remove comment

* bump ci

* fix eslint

* Apply suggestion from @RahulGautamSingh

Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com>

* Update lib/modules/manager/deno/compat.spec.ts

Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com>

* Update lib/modules/manager/deno/post.ts

Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com>

* Update lib/modules/manager/deno/compat.spec.ts

Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com>

* prettier

* Revert "Reapply "remove delete lockfile""

This reverts commit 85af6a506e.

* falling back for lockFileMaintenance

* mock statically

* use mockExecAll

* avoid cloning

* avoid cloning

* add `.ts` extension

* fix versioning

* fix `.ts` extension

* c8

* c8 update

* c8 post

* c8 extract

* c8 versiong

* c8 schema

* c8 compat

* revert deno versioning

* pnpm lint-fix

* lockFileNames

* zod/v3

* comment

* Apply suggestions from code review

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* Apply suggestions from code review

review batch lib/modules/manager/deno/compat.ts

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* fix import

* fix

* Apply suggestions from code review

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* isObject

* Apply suggestions from code review

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* named import @sindresorhus/is

* Apply suggestions from code review

* review

* rm test

* Apply suggestions from code review

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* Redundant radix parameter.

* review

* review

* c8 lib/modules/manager/deno/update.ts

* fix

* named import

* clean up

* rm unnecessary

* named import

* Missing radix parameter.

* better

* move to beforeAll

* `lockFile` to `fileName`

https://github.com/renovatebot/renovate/pull/41631

* `lockFile` to `fileName`

https://github.com/renovatebot/renovate/pull/41631

* Update lib/modules/manager/deno/schema.ts

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* update containerbase

* oxlint

* refactor for

https://github.com/renovatebot/renovate/pull/42253

* Apply suggestions from code review

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* use `Record`

* use type `Upgrade`

* update README.md

---------

Co-authored-by: RahulGautamSingh <rahultesnik@gmail.com>
Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2026-04-29 14:36:41 +00:00

135 lines
3.4 KiB
TypeScript

import { isObject } from '@sindresorhus/is';
import upath from 'upath';
import { logger } from '../../../logger/index.ts';
import {
getSiblingFileName,
localPathIsFile,
readLocalFile,
} from '../../../util/fs/index.ts';
import type {
ExtractConfig,
PackageDependency,
PackageFile,
} from '../types.ts';
import { collectPackageJson } from './compat.ts';
import { postExtract } from './post.ts';
import { DenoExtract, ImportMapExtract } from './schema.ts';
import type { DenoManagerData } from './types.ts';
export async function extractAllPackageFiles(
config: ExtractConfig,
matchedFiles: string[],
): Promise<PackageFile<DenoManagerData>[]> {
const packageFiles: PackageFile<DenoManagerData>[] = [];
for (const matchedFile of matchedFiles) {
if (upath.basename(matchedFile) === 'deno.lock') {
// node-compat
const extracted = await collectPackageJson(matchedFile);
if (extracted) {
packageFiles.push(...extracted);
}
}
// deno.json or deno.jsonc
if (upath.basename(matchedFile).startsWith('deno.json')) {
const content = await readLocalFile(matchedFile, 'utf8');
const res = DenoExtract.safeParse({
content,
fileName: matchedFile,
});
if (!res.success) {
logger.debug({ matchedFile, err: res.error }, 'Deno: extract failed');
continue;
}
const result = await processDenoExtract(res.data);
packageFiles.push(...result);
}
}
await postExtract(packageFiles);
return packageFiles;
}
export async function getLockFiles(
lock: DenoExtract['content']['lock'],
fileName: string,
): Promise<string[]> {
let lockFile: string | undefined;
if (lock && (await localPathIsFile(lock))) {
lockFile = lock;
}
if (!lockFile) {
const siblingLockFile = getSiblingFileName(fileName, 'deno.lock');
if (await localPathIsFile(siblingLockFile)) {
lockFile = siblingLockFile;
}
}
return lockFile ? [lockFile] : [];
}
export async function processImportMap(
packageFile: string,
importMapReferrer: string,
lockFiles: string[],
): Promise<PackageFile<DenoManagerData> | null> {
// we can't handle remote import map
if (packageFile.startsWith('http')) {
return null;
}
const content = await readLocalFile(packageFile, 'utf8');
if (!content) {
return null;
}
const res = ImportMapExtract.safeParse(content);
if (!res.success) {
logger.debug({ packageFile, err: res.error }, 'Deno: extract failed');
return null;
}
const deps: PackageDependency<DenoManagerData>[] = [];
deps.push(...res.data.dependencies);
return {
deps,
packageFile,
managerData: {
importMapReferrer,
},
lockFiles,
};
}
export async function processDenoExtract(
data: DenoExtract,
): Promise<PackageFile<DenoManagerData>[]> {
const { content, fileName } = data;
const lockFiles = await getLockFiles(content.lock, fileName);
let importMapPackageFile: PackageFile<DenoManagerData> | null = null;
if (content.importMap) {
importMapPackageFile = await processImportMap(
content.importMap,
fileName,
lockFiles,
);
}
const packageFile: PackageFile<DenoManagerData> = {
deps: content.dependencies,
packageFile: fileName,
managerData: content.managerData,
lockFiles,
};
return [packageFile, importMapPackageFile].filter(
isObject,
) as PackageFile<DenoManagerData>[];
}