Skip to content

Commit

Permalink
chore!: Normalize repository, dropping node <10.13 support (#8)
Browse files Browse the repository at this point in the history
feat: Support non-extensible functions by removing WeakMap shim
feat: Remove default-resolution dependency since platform has consistent resolution
  • Loading branch information
sttk committed Jan 9, 2022
1 parent 436e29e commit 50a17d8
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 176 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
coverage/
75 changes: 75 additions & 0 deletions .github/workflows/dev.yml
@@ -0,0 +1,75 @@
name: dev
on:
pull_request:
push:
branches:
- master
- main
env:
CI: true

jobs:
prettier:
name: Format code
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Prettier
uses: gulpjs/prettier_action@v3.0
with:
commit_message: 'chore: Run prettier'
prettier_options: '--write .'

test:
name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node: [10, 12, 14, 16]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Clone repository
uses: actions/checkout@v2

- name: Set Node.js version
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}

- run: node --version
- run: npm --version

- name: Install npm dependencies
run: npm install

- name: Run lint
run: npm run lint

- name: Run tests
run: npm test

- name: Coveralls
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: ${{matrix.os}}-node-${{ matrix.node }}
parallel: true

coveralls:
needs: test
name: Finish up

runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v1.1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,17 @@
name: release
on:
push:
branches:
- master
- main

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
package-name: release-please-action
bump-minor-pre-major: true
52 changes: 44 additions & 8 deletions .gitignore
@@ -1,31 +1,67 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

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

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

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

# Users Environment Variables
.lock-wscript
# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# Garbage files
.DS_Store

# Test results
test.xunit
3 changes: 0 additions & 3 deletions .jscsrc

This file was deleted.

1 change: 1 addition & 0 deletions .npmrc
@@ -0,0 +1 @@
package-lock=false
3 changes: 3 additions & 0 deletions .prettierignore
@@ -0,0 +1,3 @@
coverage/
.nyc_output/
CHANGELOG.md
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
35 changes: 10 additions & 25 deletions README.md
@@ -1,12 +1,12 @@
<p align="center">
<a href="http://gulpjs.com">
<a href="https://gulpjs.com">
<img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
</a>
</p>

# last-run

[![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]
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url]

Capture and retrieve the last time a function was run.

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

## API

__Note: this module uses a WeakMap shim, and throws on non-extensible functions on platforms that
don't have a native WeakMap implementation__

### lastRun(fn, [timeResolution]) => [Timestamp]

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

The timestamp is always given in millisecond but the time resolution can be reduced (rounded down).
The use case is to be able to compare a build time to a file time attribute.
On node v0.10 or with file system like HFS or FAT, `fs.stat` time attributes like `mtime` precision is one second.

Assuming `lastRun(fn)` returns 1426000001111, `lastRun(fn, 1000)` returns 1426000001000.

The default time resolution is 1000 on node v0.10, 0 on node 0.11+ and iojs.
More information at [`default-resolution`][default-resolution] and
[undertaker PR #17][undertaker-17].
On some file systems, `fs.stat` time attributes like `mtime` might have one second precision.

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

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

MIT

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

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

[travis-url]: https://travis-ci.org/gulpjs/last-run
[travis-image]: http://img.shields.io/travis/gulpjs/last-run.svg?label=travis-ci

[appveyor-url]: https://ci.appveyor.com/project/gulpjs/last-run
[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/last-run.svg?label=appveyor
[ci-url]: https://github.com/gulpjs/last-run/actions?query=workflow:dev
[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/last-run/dev?style=flat-square

[coveralls-url]: https://coveralls.io/r/gulpjs/last-run
[coveralls-image]: http://img.shields.io/coveralls/gulpjs/last-run/master.svg

[gitter-url]: https://gitter.im/gulpjs/gulp
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/last-run/master.svg?style=flat-square
<!-- prettier-ignore-end -->
25 changes: 0 additions & 25 deletions appveyor.yml

This file was deleted.

20 changes: 2 additions & 18 deletions index.js
Expand Up @@ -2,43 +2,28 @@

var assert = require('assert');

var WM = require('es6-weak-map');
var hasNativeWeakMap = require('es6-weak-map/is-native-implemented');
var defaultResolution = require('default-resolution');

var runtimes = new WM();
var runtimes = new WeakMap();

function isFunction(fn) {
return (typeof fn === 'function');
}

function isExtensible(fn) {
if (hasNativeWeakMap) {
// Native weakmap doesn't care about extensible
return true;
}

return Object.isExtensible(fn);
}

function lastRun(fn, timeResolution) {
assert(isFunction(fn), 'Only functions can check lastRun');
assert(isExtensible(fn), 'Only extensible functions can check lastRun');

var time = runtimes.get(fn);

if (time == null) {
return;
}

var resolution = defaultResolution(timeResolution);
var resolution = parseInt(timeResolution, 10) || 1;

return time - (time % resolution);
}

function capture(fn, timestamp) {
assert(isFunction(fn), 'Only functions can be captured');
assert(isExtensible(fn), 'Only extensible functions can be captured');

timestamp = timestamp || Date.now();

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

function release(fn) {
assert(isFunction(fn), 'Only functions can be captured');
assert(isExtensible(fn), 'Only extensible functions can be captured');

runtimes.delete(fn);
}
Expand Down

0 comments on commit 50a17d8

Please sign in to comment.