get from url, fix logic
All checks were successful
Unit tests / Unit tests (lts/*) (push) Successful in -2m0s
Unit tests / Unit tests (lts/hydrogen) (push) Successful in -1m59s
Distribution check / Generated files check (push) Successful in -1m58s
NPM Audit Check / Check NPM audit (push) Successful in -2m10s
Unit tests / Unit tests (latest) (push) Successful in -1m59s

This commit is contained in:
2025-11-07 17:23:26 -05:00
parent 6c27b5d0d6
commit 4a8498f975
4 changed files with 42 additions and 15 deletions

25
dist/index.js vendored
View File

@@ -41379,11 +41379,15 @@ const ky = createInstance();
//# sourceMappingURL=index.js.map //# sourceMappingURL=index.js.map
;// CONCATENATED MODULE: external "fs/promises" ;// CONCATENATED MODULE: external "fs/promises"
const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("fs/promises"); const promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("fs/promises");
// EXTERNAL MODULE: external "url"
var external_url_ = __nccwpck_require__(7016);
// EXTERNAL MODULE: ./node_modules/yaml/dist/index.js // EXTERNAL MODULE: ./node_modules/yaml/dist/index.js
var dist = __nccwpck_require__(8815); var dist = __nccwpck_require__(8815);
;// CONCATENATED MODULE: ./lib/src/pkgbase.js ;// CONCATENATED MODULE: ./lib/src/pkgbase.js
async function parse(previous, current) { async function parse(previous, current) {
const prev = await tryRead(previous); const prev = await tryRead(previous);
const curr = await tryRead(current); const curr = await tryRead(current);
@@ -41394,13 +41398,14 @@ async function parse(previous, current) {
delete: [], delete: [],
actions, actions,
}; };
if (isDelete(actions)) { // can't delete if there's nothing to delete/no previous success
if (prev && isDelete(actions)) {
const repo = prev.repos[actions.removeRepo]; const repo = prev.repos[actions.removeRepo];
result.delete.push(...parseRepoContents(repo, actions.removeRepo)); result.delete.push(...parseRepoContents(repo, actions.removeRepo));
} }
else if (prev && isMove(actions)) { else if (isMove(actions)) {
const moving = result.move = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo); const moving = result.move = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo);
result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving)); prev && result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving));
} }
else if ((result.build = isAdd(actions)) && prev) { else if ((result.build = isAdd(actions)) && prev) {
result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo))); result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo)));
@@ -41429,15 +41434,25 @@ function isAdd(actions) {
function isMove(actions) { function isMove(actions) {
return !!(actions.removeRepo && actions.addRepo); return !!(actions.removeRepo && actions.addRepo);
} }
async function tryRead(file) { async function tryRead(location) {
try { try {
const contents = await promises_namespaceObject.readFile(file, { encoding: 'utf-8' }); const contents = isUrl(location) ? await (await distribution.get(location)).text() : await promises_namespaceObject.readFile(location, { encoding: 'utf-8' });
return dist/* parse */.qg(contents); return dist/* parse */.qg(contents);
} }
catch { catch {
return null; return null;
} }
} }
function isUrl(s) {
try {
new external_url_.URL(s);
return true;
}
catch (err) {
return false;
}
}
;
//# sourceMappingURL=pkgbase.js.map //# sourceMappingURL=pkgbase.js.map
;// CONCATENATED MODULE: ./lib/src/router.js ;// CONCATENATED MODULE: ./lib/src/router.js

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,7 @@
import { type PathLike } from 'fs'; import { type PathLike } from 'fs';
import fsp from 'fs/promises'; import fsp from 'fs/promises';
import { URL } from 'url';
import ky from 'ky';
import * as YAML from 'yaml'; import * as YAML from 'yaml';
export interface PackageInfo { export interface PackageInfo {
@@ -51,9 +53,9 @@ export interface PkgBase {
} }
} }
export async function parse(previous: PathLike, current: PathLike): Promise<Result> { export async function parse(previous: string, current: string): Promise<Result> {
const prev = await tryRead(previous); const prev: PkgBase | null = await tryRead(previous);
const curr = await tryRead(current); const curr: PkgBase | null = await tryRead(current);
const actions = curr?.actions; const actions = curr?.actions;
const result: Result = { const result: Result = {
build: false, build: false,
@@ -62,13 +64,14 @@ export async function parse(previous: PathLike, current: PathLike): Promise<Resu
actions, actions,
}; };
if (isDelete(actions)) { // can't delete if there's nothing to delete/no previous success
if (prev && isDelete(actions)) {
const repo: RepoContents = prev.repos[actions.removeRepo]; const repo: RepoContents = prev.repos[actions.removeRepo];
result.delete.push(...parseRepoContents(repo, actions.removeRepo)); result.delete.push(...parseRepoContents(repo, actions.removeRepo));
} }
else if (prev && isMove(actions)) { else if (isMove(actions)) {
const moving = result.move = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo); const moving = result.move = parseRepoContents(curr.repos[actions.addRepo], actions.removeRepo);
result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving)); prev && result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), moving));
} }
else if ((result.build = isAdd(actions)) && prev) { else if ((result.build = isAdd(actions)) && prev) {
result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo))); result.delete.push(...getDropped(parseRepoContents(prev.repos[actions.addRepo], actions.addRepo), parseRepoContents(curr.repos[actions.addRepo], actions.addRepo)));
@@ -104,12 +107,21 @@ function isMove(actions: Actions): boolean {
return !!(actions.removeRepo && actions.addRepo); return !!(actions.removeRepo && actions.addRepo);
} }
export async function tryRead(file: PathLike): Promise<PkgBase | null> { export async function tryRead(location: string): Promise<PkgBase | null> {
try { try {
const contents = await fsp.readFile(file, { encoding: 'utf-8' }); const contents = isUrl(location) ? await (await ky.get(location)).text() : await fsp.readFile(location, { encoding: 'utf-8' });
return YAML.parse(contents); return YAML.parse(contents);
} }
catch { catch {
return null; return null;
} }
} }
function isUrl(s: string) {
try {
new URL(s);
return true;
} catch (err) {
return false;
}
};

View File

@@ -129,7 +129,7 @@ describe('pkgbase parser', () => {
} }
}; };
const rDir = 'move-with-dropped'; const rDir = 'move-with-dropped';
await expect(parse(path.join('test', 'resources', rDir, 'pkgbase.old.yaml'), path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected); await expect(parse(`https://git.sanin.dev/packages_test/pkgbase-yaml-parser/raw/branch/master/test/resources/${rDir}/pkgbase.old.yaml`, path.join('test', 'resources', rDir, 'pkgbase.new.yaml'))).resolves.toEqual(expected);
}); });
it('can detect a delete operation', async () => { it('can detect a delete operation', async () => {