@oliasoft-open-source/node-json-migrator 5.6.2 → 5.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +32 -10
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -15,6 +15,16 @@ import os from "node:os";
15
15
  import tty from "node:tty";
16
16
  import process$2 from "process";
17
17
  import { execSync, spawn } from "child_process";
18
+ //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/compact.mjs
19
+ function compact(arr) {
20
+ const result = [];
21
+ for (let i = 0; i < arr.length; i++) {
22
+ const item = arr[i];
23
+ if (item) result.push(item);
24
+ }
25
+ return result;
26
+ }
27
+ //#endregion
18
28
  //#region node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/array/difference.mjs
19
29
  function difference(firstArr, secondArr) {
20
30
  const secondSet = new Set(secondArr);
@@ -4731,25 +4741,37 @@ const getPlanRevisionsFromGit = async (planFilePath, terminal) => {
4731
4741
  const getPlanFromGit = async (planFilePath, revision, terminal) => {
4732
4742
  return exec(`git show ${revision}:${planFilePath}`, terminal);
4733
4743
  };
4744
+ const parseHistoricalPlan = (rawPlan, revision) => {
4745
+ try {
4746
+ const plan = formatJSON(rawPlan);
4747
+ return {
4748
+ revision,
4749
+ version: hash(plan),
4750
+ plan
4751
+ };
4752
+ } catch {
4753
+ console.warn(`Skipping invalid historical plan.json at commit ${revision.version}`);
4754
+ return null;
4755
+ }
4756
+ };
4734
4757
  const getHistoricalPlansFromGit = async (planFilePath) => {
4735
4758
  try {
4736
4759
  if (!gitAvailable()) throw new Error("git must be installed and in PATH");
4737
4760
  const terminal = getTerminal();
4738
- const revisions = await getPlanRevisionsFromGit(planFilePath, terminal);
4739
- return { historicalPlans: await Promise.all(revisions.map(async (revision) => {
4740
- const plan = await getPlanFromGit(planFilePath, revision.version, terminal);
4741
- return {
4742
- revision,
4743
- version: hash(plan),
4744
- plan
4745
- };
4746
- })) };
4761
+ const revisions = await GitModule.getPlanRevisionsFromGit(planFilePath, terminal);
4762
+ return { historicalPlans: compact(await Promise.all(revisions.map(async (revision) => {
4763
+ return parseHistoricalPlan(await GitModule.getPlanFromGit(planFilePath, revision.version, terminal), revision);
4764
+ }))) };
4747
4765
  } catch (error) {
4748
4766
  console.error(chalk.red(error));
4749
4767
  throw new Error("Unable to fetch plan.json history from git");
4750
4768
  }
4751
4769
  };
4752
- const GitModule = { getHistoricalPlansFromGit };
4770
+ const GitModule = {
4771
+ getHistoricalPlansFromGit,
4772
+ getPlanRevisionsFromGit,
4773
+ getPlanFromGit
4774
+ };
4753
4775
  //#endregion
4754
4776
  //#region src/executed/executed.ts
4755
4777
  const readPlanFromDatabase = async ({ database, entity, version }) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/node-json-migrator",
3
- "version": "5.6.2",
3
+ "version": "5.6.3",
4
4
  "description": "A library for JSON migrations",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/node-json-migrator",
6
6
  "bugs": {