Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@akryum/cpx

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@akryum/cpx - npm Package Compare versions

Comparing version 1.5.2 to 1.5.3

83

lib/utils/copy-file.js

@@ -0,1 +1,3 @@

/* eslint-disable no-process-env */
/**

@@ -9,5 +11,8 @@ * @author Toru Nagashima

const path = require("path")
const co = require("co")
const fs = require("fs-extra")
const excludeReg = process.env.CPX_EXCLUDE
? new RegExp(process.env.CPX_EXCLUDE)
: null
/**

@@ -22,49 +27,19 @@ * Copy the content of the given file.

*/
function copyFileContent(source, output, transforms) {
return new Promise((resolve, reject) => {
const reader = fs.createReadStream(source)
const writer = fs.createWriteStream(output)
const streams = [reader]
async function copyFileContent(source, output, transforms) {
if (excludeReg && excludeReg.test(source)) {
return
}
/**
* Clean up.
* @param {Error} err - An error or undefined.
* @returns {void}
*/
function cleanup(err) {
try {
for (const s of streams) {
s.removeListener("error", cleanup)
if (typeof s.destroy === "function") {
s.destroy()
}
}
writer.removeListener("error", cleanup)
writer.removeListener("finish", resolve)
} catch (_err) {
reject(err)
return
}
reject(err)
// Skip change if content is equal
let sourceContent = fs.readFileSync(source)
if (fs.existsSync(output)) {
const outputContent = fs.readFileSync(output)
if (Buffer.compare(sourceContent, outputContent) === 0) {
return
}
}
reader.on("error", cleanup)
writer.on("error", cleanup)
writer.on("finish", resolve)
sourceContent = transforms.reduce((content, t) => t(content), sourceContent)
try {
transforms
.reduce((input, factory) => {
const t = factory(source, { outfile: output })
t.on("error", cleanup)
streams.push(t)
return input.pipe(t)
}, reader)
.pipe(writer)
} catch (err) {
cleanup(err)
}
})
await fs.writeFile(output, sourceContent)
}

@@ -85,8 +60,8 @@

*/
module.exports = co.wrap(function* copyFile(source, output, options) {
const stat = yield fs.stat(source)
module.exports = async function copyFile(source, output, options) {
const stat = await fs.stat(source)
if (options.update) {
try {
const dstStat = yield fs.stat(output)
const dstStat = await fs.stat(output)
if (dstStat.mtime.getTime() > stat.mtime.getTime()) {

@@ -105,13 +80,13 @@ // Don't overwrite because the file on destination is newer than

if (stat.isDirectory()) {
yield fs.ensureDir(output)
await fs.ensureDir(output)
} else {
yield fs.ensureDir(path.dirname(output))
yield copyFileContent(source, output, options.transform)
await fs.ensureDir(path.dirname(output))
await copyFileContent(source, output, options.transform)
}
yield fs.chmod(output, stat.mode)
await fs.chmod(output, stat.mode)
if (options.preserve) {
yield fs.chown(output, stat.uid, stat.gid)
yield fs.utimes(output, stat.atime, stat.mtime)
await fs.chown(output, stat.uid, stat.gid)
await fs.utimes(output, stat.atime, stat.mtime)
}
})
}

@@ -389,12 +389,2 @@ /**

onChanged(sourcePath) {
// Skip change if content is equal
const outputPath = this.toDestination(sourcePath)
const sourceContent = fs.readFileSync(sourcePath)
if (fs.existsSync(outputPath)) {
const outputContent = fs.readFileSync(outputPath)
if (Buffer.compare(sourceContent, outputContent) === 0) {
return
}
}
debug("Watcher#onChanged", sourcePath)

@@ -401,0 +391,0 @@ const normalizedPath = normalizePath(sourcePath)

{
"name": "@akryum/cpx",
"version": "1.5.2",
"version": "1.5.3",
"description": "Copy file globs, watching for changes.",
"engines": {
"node": ">=6.5"
"node": ">=12.0"
},

@@ -8,0 +8,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc