initial commit
This commit is contained in:
107
.gitignore
vendored
Normal file
107
.gitignore
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Microbundle cache
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# gatsby files
|
||||
.cache/
|
||||
public
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
|
||||
# custom .gitignore
|
||||
config/config.json5
|
||||
distribution/
|
||||
.env
|
||||
test/*.js*
|
||||
output.wav
|
||||
output.mp3
|
||||
22
.vscode/launch.json
vendored
Normal file
22
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"program": "${workspaceFolder}/src/index.ts",
|
||||
"preLaunchTask": "tsc: build - tsconfig.json",
|
||||
"outFiles": [
|
||||
"${workspaceFolder}/distribution/**/*.js"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
3
README.md
Normal file
3
README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# pkgbase-yaml-parser
|
||||
|
||||
compare Artix `pkgbase.yaml` files.
|
||||
1743
package-lock.json
generated
Normal file
1743
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
37
package.json
Normal file
37
package.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "pkgbase-yaml-parser",
|
||||
"version": "0.0.1",
|
||||
"description": "compare Artix `pkgbase.yaml` files",
|
||||
"keywords": [
|
||||
"artix",
|
||||
"artixlinux"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://git.sanin.dev/packages_test/pkgbase-yaml-parser.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Cory Sanin",
|
||||
"email": "corysanin@outlook.com",
|
||||
"url": "https://sanin.dev/"
|
||||
},
|
||||
"type": "module",
|
||||
"main": "distribution/index.js",
|
||||
"files": [
|
||||
"distribution"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"yaml": "2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "5.9.3",
|
||||
"@types/node": "24.10.0",
|
||||
"vitest": "4.0.7",
|
||||
"@vitest/coverage-v8": "4.0.7"
|
||||
}
|
||||
}
|
||||
100
src/pkgbase.ts
Normal file
100
src/pkgbase.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import { type PathLike } from 'fs';
|
||||
import fsp from 'fs/promises';
|
||||
import * as YAML from 'yaml';
|
||||
|
||||
interface Actions {
|
||||
addRepo: string | null;
|
||||
removeRepo: string | null;
|
||||
triggersBuild: boolean;
|
||||
triggersRebuild: boolean;
|
||||
triggersRepoAdd: boolean;
|
||||
triggersRepoRemove: boolean;
|
||||
triggersNoCheck: boolean;
|
||||
}
|
||||
|
||||
interface Result {
|
||||
build: boolean;
|
||||
move: boolean;
|
||||
delete: string[];
|
||||
actions: Actions;
|
||||
}
|
||||
|
||||
interface RepoContents {
|
||||
version: string | null;
|
||||
packages: string[];
|
||||
debug: string[];
|
||||
}
|
||||
|
||||
interface PkgBase {
|
||||
actions: Actions;
|
||||
team: string;
|
||||
repos: {
|
||||
"system-goblins": RepoContents;
|
||||
"system-gremlins": RepoContents;
|
||||
"system": RepoContents;
|
||||
"world-goblins": RepoContents;
|
||||
"world-gremlins": RepoContents;
|
||||
"world": RepoContents;
|
||||
"lib32-goblins": RepoContents;
|
||||
"lib32-gremlins": RepoContents;
|
||||
"lib32": RepoContents;
|
||||
"galaxy-goblins": RepoContents;
|
||||
"galaxy-gremlins": RepoContents;
|
||||
"galaxy": RepoContents;
|
||||
}
|
||||
}
|
||||
|
||||
async function parse(previous: PathLike, current: PathLike): Promise<Result> {
|
||||
const prev = await tryRead(previous);
|
||||
const curr = await tryRead(current);
|
||||
const actions = curr?.actions;
|
||||
const result: Result = {
|
||||
build: false,
|
||||
move: false,
|
||||
delete: [],
|
||||
actions,
|
||||
};
|
||||
|
||||
if (isDelete(actions)) {
|
||||
result.delete.push(...(prev.repos[actions.removeRepo] as RepoContents).packages);
|
||||
}
|
||||
else if (result.move = isMove(actions)) {
|
||||
result.delete.push(...getDropped(prev.repos[actions.removeRepo], curr.repos[actions.addRepo]));
|
||||
}
|
||||
else if (result.build = isAdd(actions)) {
|
||||
result.delete.push(...getDropped(prev.repos[actions.addRepo], curr.repos[actions.addRepo]));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function getDropped(oldRepoContents: RepoContents, newRepoContents: RepoContents): string[] {
|
||||
const oldPackages = oldRepoContents.packages.map(p => p.split(`-${oldRepoContents.version}`)[0]);
|
||||
const newPackages = newRepoContents.packages.map(p => p.split(`-${newRepoContents.version}`)[0]);
|
||||
return oldPackages.filter(p => newPackages.indexOf(p) === -1);
|
||||
}
|
||||
|
||||
function isDelete(actions: Actions): boolean {
|
||||
return !!(actions.removeRepo && actions.addRepo === null);
|
||||
}
|
||||
|
||||
function isAdd(actions: Actions): boolean {
|
||||
return !!(actions.addRepo && actions.removeRepo === null);
|
||||
}
|
||||
|
||||
function isMove(actions: Actions): boolean {
|
||||
return !!(actions.removeRepo && actions.addRepo);
|
||||
}
|
||||
|
||||
async function tryRead(file: PathLike): Promise<PkgBase | null> {
|
||||
try {
|
||||
const contents = await fsp.readFile(file, { encoding: 'utf-8' });
|
||||
return YAML.parse(contents);
|
||||
}
|
||||
catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export { parse };
|
||||
export type { Actions, Result, RepoContents, PkgBase };
|
||||
41
test/pkgbase.test.ts
Normal file
41
test/pkgbase.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import path from 'path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { parse, type Result } from '../src/pkgbase.js';
|
||||
|
||||
describe('pkgbase parser', () => {
|
||||
it('can detect an add operation', async () => {
|
||||
const expected: Result = {
|
||||
build: true,
|
||||
move: false,
|
||||
delete: [],
|
||||
actions: {
|
||||
addRepo: 'system-goblins',
|
||||
removeRepo: null,
|
||||
triggersBuild: false,
|
||||
triggersRebuild: true,
|
||||
triggersRepoAdd: true,
|
||||
triggersRepoRemove: false,
|
||||
triggersNoCheck: false
|
||||
}
|
||||
};
|
||||
await expect(parse(path.join('test', 'resources', 'add-clean', 'pkgbase.old.yaml'), path.join('test', 'resources', 'add-clean', 'pkgbase.new.yaml'))).resolves.toEqual(expected);
|
||||
});
|
||||
|
||||
it('can remove dangling packages in an add operation', async () => {
|
||||
const expected: Result = {
|
||||
build: true,
|
||||
move: false,
|
||||
delete: ['pidgin'],
|
||||
actions: {
|
||||
addRepo: 'world',
|
||||
removeRepo: null,
|
||||
triggersBuild: true,
|
||||
triggersRebuild: false,
|
||||
triggersRepoAdd: true,
|
||||
triggersRepoRemove: false,
|
||||
triggersNoCheck: false
|
||||
}
|
||||
};
|
||||
await expect(parse(path.join('test', 'resources', 'add-with-dropped', 'pkgbase.old.yaml'), path.join('test', 'resources', 'add-with-dropped', 'pkgbase.new.yaml'))).resolves.toEqual(expected);
|
||||
});
|
||||
});
|
||||
61
test/resources/add-clean/pkgbase.new.yaml
Normal file
61
test/resources/add-clean/pkgbase.new.yaml
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
actions:
|
||||
addRepo: system-goblins
|
||||
removeRepo: null
|
||||
triggersBuild: false
|
||||
triggersRebuild: true
|
||||
triggersRepoAdd: true
|
||||
triggersRepoRemove: false
|
||||
triggersNoCheck: false
|
||||
repos:
|
||||
system-goblins:
|
||||
version: 78.1-1
|
||||
packages:
|
||||
- icu-78.1-1-x86_64.pkg.tar.zst
|
||||
debug: []
|
||||
system-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
system:
|
||||
version: 76.1-1
|
||||
packages:
|
||||
- icu-76.1-1-x86_64.pkg.tar.zst
|
||||
debug: []
|
||||
world-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
world-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
world:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
lib32-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
lib32-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
lib32:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
team: system
|
||||
55
test/resources/add-clean/pkgbase.old.yaml
Normal file
55
test/resources/add-clean/pkgbase.old.yaml
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
pkgbase:
|
||||
name: icu
|
||||
version: 76.1-1
|
||||
arch:
|
||||
- x86_64
|
||||
pkgname:
|
||||
- icu
|
||||
actions:
|
||||
addRepo: system
|
||||
removeRepo: system-gremlins
|
||||
triggersBuild: false
|
||||
triggersRebuild: false
|
||||
triggersRepoAdd: true
|
||||
triggersRepoRemove: true
|
||||
triggersNoCheck: false
|
||||
repos:
|
||||
system-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
system-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
system:
|
||||
version: 76.1-1
|
||||
packages:
|
||||
- icu-76.1-1-x86_64.pkg.tar.zst
|
||||
world-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
world-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
world:
|
||||
version: null
|
||||
packages: []
|
||||
lib32-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
lib32-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
lib32:
|
||||
version: null
|
||||
packages: []
|
||||
galaxy-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
galaxy-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
galaxy:
|
||||
version: null
|
||||
packages: []
|
||||
team: system
|
||||
61
test/resources/add-with-dropped/pkgbase.new.yaml
Normal file
61
test/resources/add-with-dropped/pkgbase.new.yaml
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
actions:
|
||||
addRepo: world
|
||||
removeRepo: null
|
||||
triggersBuild: true
|
||||
triggersRebuild: false
|
||||
triggersRepoAdd: true
|
||||
triggersRepoRemove: false
|
||||
triggersNoCheck: false
|
||||
repos:
|
||||
system-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
system-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
system:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
world-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
world-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
world:
|
||||
version: 2.14.14-4
|
||||
packages:
|
||||
- libpurple-2.14.14-4-x86_64.pkg.tar.zst
|
||||
- finch-2.14.14-4-x86_64.pkg.tar.zst
|
||||
debug: []
|
||||
lib32-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
lib32-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
lib32:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
team: world
|
||||
62
test/resources/add-with-dropped/pkgbase.old.yaml
Normal file
62
test/resources/add-with-dropped/pkgbase.old.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
---
|
||||
actions:
|
||||
addRepo: world
|
||||
removeRepo: world-gremlins
|
||||
triggersBuild: false
|
||||
triggersRebuild: false
|
||||
triggersRepoAdd: true
|
||||
triggersRepoRemove: true
|
||||
triggersNoCheck: false
|
||||
repos:
|
||||
system-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
system-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
system:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
world-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
world-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
world:
|
||||
version: 2.14.14-3
|
||||
packages:
|
||||
- pidgin-2.14.14-3-x86_64.pkg.tar.zst
|
||||
- libpurple-2.14.14-3-x86_64.pkg.tar.zst
|
||||
- finch-2.14.14-3-x86_64.pkg.tar.zst
|
||||
debug: []
|
||||
lib32-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
lib32-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
lib32:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy-goblins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy-gremlins:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
galaxy:
|
||||
version: null
|
||||
packages: []
|
||||
debug: []
|
||||
team: world
|
||||
17
tsconfig.json
Normal file
17
tsconfig.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext"],
|
||||
"module": "NodeNext",
|
||||
"target": "ESNext",
|
||||
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "node16",
|
||||
"sourceMap": true,
|
||||
"inlineSources": true,
|
||||
"rootDir": "./",
|
||||
"outDir": "./distribution"
|
||||
},
|
||||
"include": ["src/**/*", "test/**/*"],
|
||||
"exclude": ["**/*.spec.ts"]
|
||||
}
|
||||
Reference in New Issue
Block a user