Skip to content

Commit a732469

Browse files
committed
Merge branch 'release/4.1.0'
2 parents 92dfd13 + 860c827 commit a732469

File tree

9 files changed

+4075
-6131
lines changed

9 files changed

+4075
-6131
lines changed

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run pre-commit

.husky/pre-push

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run pre-push

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dist/*.map
99
.git*
1010
.dockerignore
1111
.travis.yml
12+
.husky
1213
babel.config.js
1314
prettier.config.js
1415
appveyor.yml

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:12 as base
1+
FROM node:14 as base
22

33
WORKDIR /project
44
# Install app dependencies

package-lock.json

Lines changed: 4032 additions & 6108 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "build-revision",
3-
"version": "4.0.0",
3+
"version": "4.1.0",
44
"description": "Generate semver compatible version to uniquely identify project build using build metadata",
55
"main": "index.js",
66
"license": "MIT",
@@ -18,19 +18,15 @@
1818
"homepage": "https://github.com/abhishekdev/build-revision#readme",
1919
"scripts": {
2020
"build": "babel src -d dist --source-maps",
21-
"prepare": "npm run build",
21+
"prepare": "npm run build && husky install",
22+
"pre-commit": "pretty-quick --staged && npm run lint",
23+
"pre-push": "npm run build && npm test",
2224
"prepublishOnly": "npm run build && npm run test",
2325
"lint": "prettier --check \"src/**/*.js\" \"test/**/*.js\" index.js",
2426
"pretest": "npm run lint",
2527
"test": "nyc --reporter=html --reporter=text ava",
2628
"coverage": "nyc report --reporter=text-lcov | coveralls"
2729
},
28-
"husky": {
29-
"hooks": {
30-
"pre-commit": "pretty-quick --staged && npm run lint",
31-
"pre-push": "npm run build && npm test"
32-
}
33-
},
3430
"ava": {
3531
"babel": true
3632
},
@@ -42,21 +38,21 @@
4238
"SHA"
4339
],
4440
"dependencies": {
45-
"moment": "^2.28.0",
41+
"dayjs": "^1.10.4",
4642
"read-pkg-up": "^7.0.1",
47-
"semver": "^7.3.2",
43+
"semver": "^7.3.5",
4844
"username": "^5.1.0"
4945
},
5046
"devDependencies": {
5147
"@ava/babel": "^1.0.1",
52-
"@babel/cli": "^7.11.6",
53-
"@babel/core": "^7.11.6",
54-
"@babel/preset-env": "^7.11.5",
55-
"ava": "^3.12.1",
48+
"@babel/cli": "^7.13.14",
49+
"@babel/core": "^7.13.15",
50+
"@babel/preset-env": "^7.13.15",
51+
"ava": "^3.15.0",
5652
"coveralls": "^3.1.0",
57-
"husky": "^4.3.0",
53+
"husky": "^6.0.0",
5854
"nyc": "^15.1.0",
59-
"prettier": "^2.1.2",
60-
"pretty-quick": "^3.0.2"
55+
"prettier": "^2.2.1",
56+
"pretty-quick": "^3.1.0"
6157
}
6258
}

src/version.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
import path from 'path';
4-
import moment from 'moment';
4+
import dayjs from 'dayjs';
55
import semver from 'semver';
66
import username from 'username';
77
import readPkgUp from 'read-pkg-up';
@@ -20,7 +20,7 @@ const semverString = (str) => {
2020
// e.g. 2017-Jan-01, 15:00:01.100 => "20170130T1500Z"
2121
const semverMoment = () => {
2222
// Get ISO date after ignoring the millisecond precision
23-
const isoDate = moment().milliseconds(0).toISOString();
23+
const isoDate = dayjs().millisecond(0).toISOString();
2424

2525
// Replace millisecond information as the 'dot' notation for it is incompatible with semver
2626
return semverString(isoDate.replace(REGEX_ISODATE_MILLISECONDS, ''));

test/test.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import fs from 'fs';
22
import test from 'ava';
33
import semver from 'semver';
4-
import moment from 'moment';
4+
import dayjs from 'dayjs';
5+
import utc from 'dayjs/plugin/utc';
6+
import customParseFormat from 'dayjs/plugin/customParseFormat';
57

68
import buildRevision from '../index';
79

10+
dayjs.extend(utc);
11+
dayjs.extend(customParseFormat);
12+
13+
// Expect ISO 8601 compatible format which has no separators for semver compatibility
14+
const TIMESTAMP_FORMAT = 'YYYYMMDD[T]HHmmss[Z]';
15+
816
test('build revision is semver compatible', async (t) => {
917
const option = { cwd: 'test/fixture/package-valid/target' };
1018

@@ -69,7 +77,10 @@ test('generates ISO 8601 UTC timestamp for dirty builds', async (t) => {
6977

7078
const revision = await buildRevision(option);
7179
const timestamp = revision.split('.').pop();
72-
t.true(moment(timestamp).isValid(), 'could not parse a valid timestamp');
80+
t.true(
81+
dayjs.utc(timestamp, TIMESTAMP_FORMAT).isValid(),
82+
'could not parse a valid timestamp'
83+
);
7384

7485
// Test Teardown: Reset repository
7586
fs.unlink('test/fixture/package-valid/change.txt', (err) => {
@@ -97,7 +108,10 @@ test.serial('works when package is not a git repo', async (t) => {
97108
semver.valid(revision) && revision.includes(`+${PREFIX}`),
98109
'could not parse default buildinfo prefix for un-versioned repo'
99110
);
100-
t.true(moment(timestamp).isValid(), 'could not parse a valid timestamp');
111+
t.true(
112+
dayjs.utc(timestamp, TIMESTAMP_FORMAT).isValid(),
113+
'could not parse a valid timestamp'
114+
);
101115

102116
// Test Teardown: Re-instate .git directory
103117
if (fs.existsSync('backup.git')) {

0 commit comments

Comments
 (0)