@netlify/git-utils 3.0.0 → 4.0.0

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.
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "@netlify/git-utils",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "Utility for dealing with modified, created, deleted files since a git commit",
5
- "main": "src/main.js",
5
+ "type": "module",
6
+ "exports": "./src/main.js",
7
+ "main": "./src/main.js",
6
8
  "files": [
7
9
  "src/**/*.js"
8
10
  ],
package/src/commits.js CHANGED
@@ -1,10 +1,8 @@
1
- 'use strict'
2
-
3
- const { git } = require('./exec')
1
+ import { git } from './exec.js'
4
2
 
5
3
  // Return information on each commit since the `base` commit, such as SHA,
6
4
  // parent commits, author, committer and commit message
7
- const getCommits = function (base, head, cwd) {
5
+ export const getCommits = function (base, head, cwd) {
8
6
  const stdout = git(['log', `--pretty=${GIT_PRETTY_FORMAT}`, `${base}...${head}`], cwd)
9
7
  const commits = stdout.split('\n').map(getCommit)
10
8
  return commits
@@ -33,5 +31,3 @@ const getCommit = function (line) {
33
31
  const GIT_PRETTY_SEPARATOR = '\u001E'
34
32
  // List of commit fields we want to retrieve
35
33
  const GIT_PRETTY_FORMAT = ['%H', '%p', '%an', '%ae', '%ai', '%cn', '%ce', '%ci', '%f'].join(GIT_PRETTY_SEPARATOR)
36
-
37
- module.exports = { getCommits }
package/src/diff.js CHANGED
@@ -1,10 +1,8 @@
1
- 'use strict'
2
-
3
- const { git } = require('./exec')
1
+ import { git } from './exec.js'
4
2
 
5
3
  // Return the list of modified|created|deleted files according to git, between
6
4
  // the `base` commit and the `HEAD`
7
- const getDiffFiles = function (base, head, cwd) {
5
+ export const getDiffFiles = function (base, head, cwd) {
8
6
  const stdout = git(['diff', '--name-status', '--no-renames', `${base}...${head}`], cwd)
9
7
  const files = stdout.split('\n').map(getDiffFile).filter(Boolean)
10
8
 
@@ -36,5 +34,3 @@ const getFilesByType = function (files, type) {
36
34
  const getFilepath = function ({ filepath }) {
37
35
  return filepath
38
36
  }
39
-
40
- module.exports = { getDiffFiles }
package/src/exec.js CHANGED
@@ -1,10 +1,8 @@
1
- 'use strict'
1
+ import process from 'process'
2
2
 
3
- const process = require('process')
4
-
5
- const execa = require('execa')
6
- const moize = require('moize')
7
- const pathExists = require('path-exists')
3
+ import execa from 'execa'
4
+ import moize from 'moize'
5
+ import pathExists from 'path-exists'
8
6
 
9
7
  // Fires the `git` binary. Memoized.
10
8
  const mGit = function (args, cwd) {
@@ -21,7 +19,7 @@ const mGit = function (args, cwd) {
21
19
  }
22
20
 
23
21
  // eslint-disable-next-line no-magic-numbers
24
- const git = moize(mGit, { isDeepEqual: true, maxSize: 1e3 })
22
+ export const git = moize(mGit, { isDeepEqual: true, maxSize: 1e3 })
25
23
 
26
24
  const safeGetCwd = function (cwd) {
27
25
  const cwdA = getCwdValue(cwd)
@@ -44,5 +42,3 @@ const getCwdValue = function (cwd) {
44
42
  throw new Error('Current directory does not exist')
45
43
  }
46
44
  }
47
-
48
- module.exports = { git }
package/src/main.js CHANGED
@@ -1,13 +1,11 @@
1
- 'use strict'
2
-
3
- const { getCommits } = require('./commits')
4
- const { getDiffFiles } = require('./diff')
5
- const { fileMatch } = require('./match')
6
- const { getBase, getHead } = require('./refs')
7
- const { getLinesOfCode } = require('./stats')
1
+ import { getCommits } from './commits.js'
2
+ import { getDiffFiles } from './diff.js'
3
+ import { fileMatch } from './match.js'
4
+ import { getBase, getHead } from './refs.js'
5
+ import { getLinesOfCode } from './stats.js'
8
6
 
9
7
  // Main entry point to the git utilities
10
- const getGitUtils = function ({ base, head, cwd } = {}) {
8
+ export const getGitUtils = function ({ base, head, cwd } = {}) {
11
9
  const headA = getHead(cwd, head)
12
10
  const baseA = getBase(base, headA, cwd)
13
11
  const { modifiedFiles, createdFiles, deletedFiles } = getDiffFiles(baseA, headA, cwd)
@@ -16,5 +14,3 @@ const getGitUtils = function ({ base, head, cwd } = {}) {
16
14
  const fileMatchA = fileMatch.bind(null, { modifiedFiles, createdFiles, deletedFiles })
17
15
  return { modifiedFiles, createdFiles, deletedFiles, commits, linesOfCode, fileMatch: fileMatchA }
18
16
  }
19
-
20
- module.exports = getGitUtils
package/src/match.js CHANGED
@@ -1,11 +1,9 @@
1
- 'use strict'
2
-
3
- const mapObj = require('map-obj')
4
- const micromatch = require('micromatch')
1
+ import mapObj from 'map-obj'
2
+ import micromatch from 'micromatch'
5
3
 
6
4
  // Return functions that return modified|created|deleted files filtered by a
7
5
  // globbing pattern
8
- const fileMatch = function ({ modifiedFiles, createdFiles, deletedFiles }, ...patterns) {
6
+ export const fileMatch = function ({ modifiedFiles, createdFiles, deletedFiles }, ...patterns) {
9
7
  const matchFiles = {
10
8
  modified: modifiedFiles,
11
9
  created: createdFiles,
@@ -14,5 +12,3 @@ const fileMatch = function ({ modifiedFiles, createdFiles, deletedFiles }, ...pa
14
12
  }
15
13
  return mapObj(matchFiles, (key, paths) => [key, micromatch(paths, patterns)])
16
14
  }
17
-
18
- module.exports = { fileMatch }
package/src/refs.js CHANGED
@@ -1,11 +1,9 @@
1
- 'use strict'
1
+ import { env } from 'process'
2
2
 
3
- const { env } = require('process')
4
-
5
- const { git } = require('./exec')
3
+ import { git } from './exec.js'
6
4
 
7
5
  // Retrieve the `head` commit
8
- const getHead = function (cwd, head = 'HEAD') {
6
+ export const getHead = function (cwd, head = 'HEAD') {
9
7
  const result = checkRef(head, cwd)
10
8
  if (result.error !== undefined) {
11
9
  throwError('head', result)
@@ -14,7 +12,7 @@ const getHead = function (cwd, head = 'HEAD') {
14
12
  }
15
13
 
16
14
  // Retrieve the `base` commit
17
- const getBase = function (base, head, cwd) {
15
+ export const getBase = function (base, head, cwd) {
18
16
  const refs = getBaseRefs(base, head)
19
17
  const { ref } = findRef(refs, cwd)
20
18
  return ref
@@ -63,5 +61,3 @@ const throwError = function (name, { ref, error: { message, stderr } }) {
63
61
  const messageA = `Invalid ${name} commit ${ref}\n${messages}`
64
62
  throw new Error(messageA)
65
63
  }
66
-
67
- module.exports = { getBase, getHead }
package/src/stats.js CHANGED
@@ -1,10 +1,8 @@
1
- 'use strict'
2
-
3
- const { git } = require('./exec')
1
+ import { git } from './exec.js'
4
2
 
5
3
  // Returns the number of lines of code added, removed or modified since the
6
4
  // `base` commit
7
- const getLinesOfCode = function (base, head, cwd) {
5
+ export const getLinesOfCode = function (base, head, cwd) {
8
6
  const stdout = git(['diff', '--shortstat', `${base}...${head}`], cwd)
9
7
  const insertions = parseStdout(stdout, INSERTION_REGEXP)
10
8
  const deletions = parseStdout(stdout, DELETION_REGEXP)
@@ -23,5 +21,3 @@ const parseStdout = function (stdout, regexp) {
23
21
 
24
22
  const INSERTION_REGEXP = /(\d+) insertion/
25
23
  const DELETION_REGEXP = /(\d+) deletion/
26
-
27
- module.exports = { getLinesOfCode }