Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Update dependencies, require Node.js 10.13 #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [8, 10, 12, 13]
node-version: [10, 12, 14, 15]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
Expand Down
23 changes: 11 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
const fs = require('fs');
const path = require('path');
const hasha = require('hasha');
const makeDir = require('make-dir');
const writeFileAtomic = require('write-file-atomic');
const packageHash = require('package-hash');

Expand All @@ -12,34 +11,34 @@ function getOwnHash() {
return ownHash;
}

function wrap(opts) {
if (!(opts.factory || opts.transform) || (opts.factory && opts.transform)) {
function wrap(options) {
if (!(options.factory || options.transform) || (options.factory && options.transform)) {
throw new Error('Specify factory or transform but not both');
}

if (typeof opts.cacheDir !== 'string' && !opts.disableCache) {
if (typeof options.cacheDir !== 'string' && !options.disableCache) {
throw new Error('cacheDir must be a string');
}

opts = {
options = {
ext: '',
salt: '',
hashData: () => [],
filenamePrefix: () => '',
onHash: () => {},
...opts
...options
};

let transformFn = opts.transform;
const {factory, cacheDir, shouldTransform, disableCache, hashData, onHash, filenamePrefix, ext, salt} = opts;
const cacheDirCreated = opts.createCacheDir === false;
let transformFn = options.transform;
const {factory, cacheDir, shouldTransform, disableCache, hashData, onHash, filenamePrefix, ext, salt} = options;
const cacheDirCreated = options.createCacheDir === false;
let created = transformFn && cacheDirCreated;
const encoding = opts.encoding === 'buffer' ? undefined : opts.encoding || 'utf8';
const encoding = options.encoding === 'buffer' ? undefined : options.encoding || 'utf8';

function transform(input, metadata, hash) {
if (!created) {
if (!cacheDirCreated && !disableCache) {
makeDir.sync(cacheDir);
fs.mkdirSync(cacheDir, {recursive: true});
}

if (!transformFn) {
Expand Down Expand Up @@ -78,7 +77,7 @@ function wrap(opts) {
while (true) {
try {
return fs.readFileSync(cachedPath, encoding);
} catch (_) {
} catch {
if (!result) {
result = transform(input, metadata, hash);
}
Expand Down
Loading