Skip to content

Commit 50a17d8

Browse files
authored
chore!: Normalize repository, dropping node <10.13 support (#8)
feat: Support non-extensible functions by removing WeakMap shim feat: Remove default-resolution dependency since platform has consistent resolution
1 parent 436e29e commit 50a17d8

15 files changed

+214
-176
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage/

.github/workflows/dev.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: dev
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
env:
9+
CI: true
10+
11+
jobs:
12+
prettier:
13+
name: Format code
14+
runs-on: ubuntu-latest
15+
if: ${{ github.event_name == 'push' }}
16+
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
21+
- name: Prettier
22+
uses: gulpjs/prettier_action@v3.0
23+
with:
24+
commit_message: 'chore: Run prettier'
25+
prettier_options: '--write .'
26+
27+
test:
28+
name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }}
29+
runs-on: ${{ matrix.os }}
30+
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
node: [10, 12, 14, 16]
35+
os: [ubuntu-latest, windows-latest, macos-latest]
36+
37+
steps:
38+
- name: Clone repository
39+
uses: actions/checkout@v2
40+
41+
- name: Set Node.js version
42+
uses: actions/setup-node@v2
43+
with:
44+
node-version: ${{ matrix.node }}
45+
46+
- run: node --version
47+
- run: npm --version
48+
49+
- name: Install npm dependencies
50+
run: npm install
51+
52+
- name: Run lint
53+
run: npm run lint
54+
55+
- name: Run tests
56+
run: npm test
57+
58+
- name: Coveralls
59+
uses: coverallsapp/github-action@v1.1.2
60+
with:
61+
github-token: ${{ secrets.GITHUB_TOKEN }}
62+
flag-name: ${{matrix.os}}-node-${{ matrix.node }}
63+
parallel: true
64+
65+
coveralls:
66+
needs: test
67+
name: Finish up
68+
69+
runs-on: ubuntu-latest
70+
steps:
71+
- name: Coveralls Finished
72+
uses: coverallsapp/github-action@v1.1.2
73+
with:
74+
github-token: ${{ secrets.GITHUB_TOKEN }}
75+
parallel-finished: true

.github/workflows/release.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
8+
jobs:
9+
release-please:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: GoogleCloudPlatform/release-please-action@v2
13+
with:
14+
token: ${{ secrets.GITHUB_TOKEN }}
15+
release-type: node
16+
package-name: release-please-action
17+
bump-minor-pre-major: true

.gitignore

+44-8
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,67 @@
11
# Logs
22
logs
33
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
47

58
# Runtime data
69
pids
710
*.pid
811
*.seed
12+
*.pid.lock
913

1014
# Directory for instrumented libs generated by jscoverage/JSCover
1115
lib-cov
1216

1317
# Coverage directory used by tools like istanbul
1418
coverage
1519

16-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
1724
.grunt
1825

19-
# Compiled binary addons (http://nodejs.org/api/addons.html)
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
2033
build/Release
2134

22-
# Dependency directory
23-
# Commenting this out is preferred by some people, see
24-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25-
node_modules
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
2638

27-
# Users Environment Variables
28-
.lock-wscript
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# next.js build output
61+
.next
2962

3063
# Garbage files
3164
.DS_Store
65+
66+
# Test results
67+
test.xunit

.jscsrc

-3
This file was deleted.

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
.nyc_output/
3+
CHANGELOG.md

.travis.yml

-10
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Blaine Bublitz, Eric Schoffstall and other contributors
3+
Copyright (c) 2015-2017, 2021 Blaine Bublitz <blaine.bublitz@gmail.com> and Eric Schoffstall <yo@contra.io>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+10-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<p align="center">
2-
<a href="http://gulpjs.com">
2+
<a href="https://gulpjs.com">
33
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
44
</a>
55
</p>
66

77
# last-run
88

9-
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
9+
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]
1010

1111
Capture and retrieve the last time a function was run.
1212

@@ -28,9 +28,6 @@ lastRun(myFunc);
2828

2929
## API
3030

31-
__Note: this module uses a WeakMap shim, and throws on non-extensible functions on platforms that
32-
don't have a native WeakMap implementation__
33-
3431
### lastRun(fn, [timeResolution]) => [Timestamp]
3532

3633
Takes a function (`fn`) and returns a timestamp of the last time the function was captured.
@@ -39,13 +36,7 @@ Returns undefined if the function has not been captured.
3936

4037
The timestamp is always given in millisecond but the time resolution can be reduced (rounded down).
4138
The use case is to be able to compare a build time to a file time attribute.
42-
On node v0.10 or with file system like HFS or FAT, `fs.stat` time attributes like `mtime` precision is one second.
43-
44-
Assuming `lastRun(fn)` returns 1426000001111, `lastRun(fn, 1000)` returns 1426000001000.
45-
46-
The default time resolution is 1000 on node v0.10, 0 on node 0.11+ and iojs.
47-
More information at [`default-resolution`][default-resolution] and
48-
[undertaker PR #17][undertaker-17].
39+
On some file systems, `fs.stat` time attributes like `mtime` might have one second precision.
4940

5041
### lastRun.capture(fn, [timestamp])
5142

@@ -61,21 +52,15 @@ Takes a function (`fn`) and removes the last run timestamp for it.
6152

6253
MIT
6354

64-
[default-resolution]: https://github.com/gulpjs/default-resolution
65-
[undertaker-17]: https://github.com/gulpjs/undertaker/pull/17#issuecomment-82374512
6655

67-
[downloads-image]: http://img.shields.io/npm/dm/last-run.svg
56+
<!-- prettier-ignore-start -->
57+
[downloads-image]: https://img.shields.io/npm/dm/last-run.svg?style=flat-square
6858
[npm-url]: https://www.npmjs.com/package/last-run
69-
[npm-image]: http://img.shields.io/npm/v/last-run.svg
59+
[npm-image]: https://img.shields.io/npm/v/last-run.svg?style=flat-square
7060

71-
[travis-url]: https://travis-ci.org/gulpjs/last-run
72-
[travis-image]: http://img.shields.io/travis/gulpjs/last-run.svg?label=travis-ci
73-
74-
[appveyor-url]: https://ci.appveyor.com/project/gulpjs/last-run
75-
[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/last-run.svg?label=appveyor
61+
[ci-url]: https://github.com/gulpjs/last-run/actions?query=workflow:dev
62+
[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/last-run/dev?style=flat-square
7663

7764
[coveralls-url]: https://coveralls.io/r/gulpjs/last-run
78-
[coveralls-image]: http://img.shields.io/coveralls/gulpjs/last-run/master.svg
79-
80-
[gitter-url]: https://gitter.im/gulpjs/gulp
81-
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg
65+
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/last-run/master.svg?style=flat-square
66+
<!-- prettier-ignore-end -->

appveyor.yml

-25
This file was deleted.

index.js

+2-18
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,28 @@
22

33
var assert = require('assert');
44

5-
var WM = require('es6-weak-map');
6-
var hasNativeWeakMap = require('es6-weak-map/is-native-implemented');
7-
var defaultResolution = require('default-resolution');
8-
9-
var runtimes = new WM();
5+
var runtimes = new WeakMap();
106

117
function isFunction(fn) {
128
return (typeof fn === 'function');
139
}
1410

15-
function isExtensible(fn) {
16-
if (hasNativeWeakMap) {
17-
// Native weakmap doesn't care about extensible
18-
return true;
19-
}
20-
21-
return Object.isExtensible(fn);
22-
}
23-
2411
function lastRun(fn, timeResolution) {
2512
assert(isFunction(fn), 'Only functions can check lastRun');
26-
assert(isExtensible(fn), 'Only extensible functions can check lastRun');
2713

2814
var time = runtimes.get(fn);
2915

3016
if (time == null) {
3117
return;
3218
}
3319

34-
var resolution = defaultResolution(timeResolution);
20+
var resolution = parseInt(timeResolution, 10) || 1;
3521

3622
return time - (time % resolution);
3723
}
3824

3925
function capture(fn, timestamp) {
4026
assert(isFunction(fn), 'Only functions can be captured');
41-
assert(isExtensible(fn), 'Only extensible functions can be captured');
4227

4328
timestamp = timestamp || Date.now();
4429

@@ -47,7 +32,6 @@ function capture(fn, timestamp) {
4732

4833
function release(fn) {
4934
assert(isFunction(fn), 'Only functions can be captured');
50-
assert(isExtensible(fn), 'Only extensible functions can be captured');
5135

5236
runtimes.delete(fn);
5337
}

0 commit comments

Comments
 (0)