watskeburt 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016-2022 Sander Verweij
3
+ Copyright (c) 2022-2022 Sander Verweij
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -24,20 +24,20 @@ but for just this simple usage they're a bit overkill.
24
24
  ### :scroll: API
25
25
 
26
26
  ```javascript
27
- // const { list } = require('watskeburt'); // will work in commonjs contexts as well
28
- import { list, getSHA } from "watskeburt";
27
+ // const { listSync, getSHASync } = require("watskeburt"); // in commonjs contexts you can also require it
28
+ import { listSync, getSHASync } from "watskeburt";
29
29
 
30
30
  // print the SHA1 of the current HEAD
31
- console.log(getSHA());
31
+ console.log(getSHASync());
32
32
 
33
33
  // list all files that differ between 'main' and the current revision (including
34
34
  // files not staged for commit and files not under revision control)
35
35
  /** @type {import('watskeburt').IChange[]} */
36
- const lChangedFiles = list("main");
36
+ const lChangedFiles = listSync("main");
37
37
 
38
38
  // As a second parameter you can pass some options:
39
39
  /** @type {import('watskeburt').IChange[]|string} */
40
- const lChangedFiles = list("main", {
40
+ const lChangedFiles = listSync("main", {
41
41
  trackedOnly: false, // when set to true leaves out files not under revision control
42
42
  outputType: "object", // other options: "json" and "regex" (as used in the CLI)
43
43
  });
@@ -1 +1 @@
1
- "use strict";var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},_=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of y(t))!A.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(o=x(t,r))||o.enumerable});return e};var D=e=>_(a({},"__esModule",{value:!0}),e);var I={};C(I,{getSHA:()=>E,list:()=>F});module.exports=D(I);var u=require("os"),L=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,R=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,U={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function i(e){return U[e]||"unknown"}function O(e){let t=e.match(R),n={};if(t){let o=i(t.groups.stagedChangeType),r=i(t.groups.unStagedChangeType);n.changeType=o==="unmodified"?r:o,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function v(e){let t=e.match(L),n={};return t&&(n.changeType=i(t.groups.changeType),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function m(e){return e.split(u.EOL).filter(Boolean).map(O).filter(({changeType:t})=>Boolean(t))}function g(e){return e.split(u.EOL).filter(Boolean).map(v).filter(({changeType:t})=>Boolean(t))}var s=require("child_process");function d(e){return e instanceof Buffer?e.toString("utf8"):e}function j(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function c(e,t,n){let o=n("git",e,{cwd:process.cwd(),env:process.env});if(o.error&&j(o.error),o.status===0)return d(o.stdout);throw new Error(t[o.status]||`internal git error: ${o.status} (${d(o.stderr)})`)}function T(e=s.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return c(["status","--porcelain"],t,e)}function h(e,t=s.spawnSync){let n={128:`revision '${e}' unknown `,129:`'${process.cwd()}' does not seem to be a git repository`};return c(["diff",e,"--name-status"],n,t)}function S(e=s.spawnSync){return c(["rev-parse","HEAD"],{},e).slice(0,40)}var N=require("path"),$=new Set([".cjs",".cjsx",".coffee",".csx",".js",".json",".jsx",".litcoffee",".ls",".mjs",".svelte",".ts",".tsx",".vue",".vuex"]),B=new Set(["modified","added","renamed","copied","untracked"]);function f(e,t=$,n=B){return`^(${e.filter(r=>n.has(r.changeType)).map(({name:r})=>r).filter(r=>t.has((0,N.extname)(r))).join("|")})$`}function p(e){return JSON.stringify(e,null,2)}var H={regex:f,json:p,object:e=>e},M="object";function l(e,t){return H[t||M](e)}function E(){return S()}function F(e,t){let n=e||E(),o=g(h(n)),r=t||{};return r.trackedOnly||(o=o.concat(m(T()).filter(({changeType:w})=>w==="untracked"))),l(o,r.outputType)}0&&(module.exports={getSHA,list});
1
+ "use strict";var a=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var A=(e,t)=>{for(var n in t)a(e,n,{get:t[n],enumerable:!0})},C=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of y(t))!x.call(e,r)&&r!==n&&a(e,r,{get:()=>t[r],enumerable:!(o=w(t,r))||o.enumerable});return e};var _=e=>C(a({},"__esModule",{value:!0}),e);var I={};A(I,{getSHASync:()=>M,listSync:()=>F});module.exports=_(I);var u=require("os"),D=/^(?<changeType>[ACDMRTUXB])(?<similarity>[0-9]{3})?[ \t]+(?<name>[^ \t]+)[ \t]*(?<newName>[^ \t]+)?$/,L=/^(?<stagedChangeType>[ ACDMRTUXB?!])(?<unStagedChangeType>[ ACDMRTUXB?!])[ \t]+(?<name>[^ \t]+)(( -> )(?<newName>[^ \t]+))?$/,R={A:"added",C:"copied",D:"deleted",M:"modified",R:"renamed",T:"type changed",U:"unmerged",B:"pairing broken"," ":"unmodified","?":"untracked","!":"ignored"};function i(e){return R[e]||"unknown"}function U(e){let t=e.match(L),n={};if(t){let o=i(t.groups.stagedChangeType),r=i(t.groups.unStagedChangeType);n.changeType=o==="unmodified"?r:o,t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name}return n}function O(e){let t=e.match(D),n={};return t&&(n.changeType=i(t.groups.changeType),t.groups.newName?(n.name=t.groups.newName,n.oldName=t.groups.name):n.name=t.groups.name),n}function g(e){return e.split(u.EOL).filter(Boolean).map(U).filter(({changeType:t})=>Boolean(t))}function d(e){return e.split(u.EOL).filter(Boolean).map(O).filter(({changeType:t})=>Boolean(t))}var s=require("child_process");function T(e){return e instanceof Buffer?e.toString("utf8"):e}function v(e){throw e.code==="ENOENT"?new Error("git executable not found"):new Error(`internal spawn error: ${e}`)}function c(e,t,n){let o=n("git",e,{cwd:process.cwd(),env:process.env});if(o.error&&v(o.error),o.status===0)return T(o.stdout);throw new Error(t[o.status]||`internal git error: ${o.status} (${T(o.stderr)})`)}function S(e=s.spawnSync){let t={129:`'${process.cwd()}' does not seem to be a git repository`};return c(["status","--porcelain"],t,e)}function h(e,t=s.spawnSync){let n={128:`revision '${e}' unknown `,129:`'${process.cwd()}' does not seem to be a git repository`};return c(["diff",e,"--name-status"],n,t)}function f(e=s.spawnSync){return c(["rev-parse","HEAD"],{},e).slice(0,40)}var N=require("path"),j=new Set([".cjs",".cjsx",".coffee",".csx",".js",".json",".jsx",".litcoffee",".ls",".mjs",".svelte",".ts",".tsx",".vue",".vuex"]),$=new Set(["modified","added","renamed","copied","untracked"]);function p(e,t=j,n=$){return`^(${e.filter(r=>n.has(r.changeType)).map(({name:r})=>r).filter(r=>t.has((0,N.extname)(r))).join("|")})$`}function l(e){return JSON.stringify(e,null,2)}var B={regex:p,json:l,object:e=>e},H="object";function m(e,t){return B[t||H](e)}function M(){return f()}function F(e,t){let n=e||f(),o=d(h(n)),r=t||{};return r.trackedOnly||(o=o.concat(g(S()).filter(({changeType:E})=>E==="untracked"))),m(o,r.outputType)}0&&(module.exports={getSHASync,listSync});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watskeburt",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "List files changed since a git revision",
5
5
  "keywords": [
6
6
  "git",
package/src/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable no-console */
3
3
 
4
4
  import { program } from "commander";
5
- import { list } from "./main.mjs";
5
+ import { listSync } from "./main.mjs";
6
6
  import { VERSION } from "./version.mjs";
7
7
 
8
8
  program
@@ -17,7 +17,7 @@ program
17
17
  .parse(process.argv);
18
18
 
19
19
  try {
20
- console.log(list(program.args[0], program.opts()));
20
+ console.log(listSync(program.args[0], program.opts()));
21
21
  } catch (pError) {
22
22
  console.error(`ERROR: ${pError.message}`);
23
23
  }
package/src/main.mjs CHANGED
@@ -5,14 +5,14 @@ import {
5
5
  import { getDiffLines, getSHA1, getStatusShort } from "./git-primitives.mjs";
6
6
  import format from "./formatters/format.mjs";
7
7
 
8
- /** @type {import("../types/watskeburt.js").getSHA} */
9
- export function getSHA() {
8
+ /** @type {import("../types/watskeburt").getSHASync} */
9
+ export function getSHASync() {
10
10
  return getSHA1();
11
11
  }
12
12
 
13
- /** @type {import("../types/watskeburt.js").list} */
14
- export function list(pOldRevision, pOptions) {
15
- const lOldRevision = pOldRevision || getSHA();
13
+ /** @type {import("../types/watskeburt").listSync} */
14
+ export function listSync(pOldRevision, pOptions) {
15
+ const lOldRevision = pOldRevision || getSHA1();
16
16
  let lChanges = convertDiffLines(getDiffLines(lOldRevision));
17
17
  const lOptions = pOptions || {};
18
18
 
package/src/version.mjs CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.5.1";
1
+ export const VERSION = "0.6.0";
@@ -32,7 +32,7 @@ export type outputTypeType = "regex" | "json" | "object";
32
32
  export interface IOptions {
33
33
  /**
34
34
  * The type of output to deliver. Defaults to "object" - in which case
35
- * the list function returns an IChange[] object
35
+ * the listSync function returns an IChange[] object
36
36
  */
37
37
  outputType: outputTypeType;
38
38
  /**
@@ -54,14 +54,14 @@ export interface IOptions {
54
54
  * filter what is returned and
55
55
  * @throws {Error}
56
56
  */
57
- export function list(
57
+ export type listSync = (
58
58
  pOldRevision?: string,
59
59
  pOptions?: IOptions
60
- ): IChange[] | string;
60
+ ) => IChange[] | string;
61
61
 
62
62
  /**
63
63
  * Returns the SHA1 of the current HEAD
64
64
  *
65
65
  * @throws {Error}
66
66
  */
67
- export function getSHA(): string;
67
+ export type getSHASync = () => string;