Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'proper-lockfile' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
if (!config.repository) {
console.log(
chalk.red('The "repository" option must be specified in the config file')
)
process.exit(1)
}
const fileLock = path.join(
osTmpdir(),
filenamify(config.repository, { replacement: '-' })
)
// ensure the dir exists, otherwise it's impossible to acquire the lock
if (!fs.existsSync(fileLock)) {
fs.mkdirSync(fileLock)
}
if (fs.existsSync(`${fileLock}.lock`)) {
if (lockfile.checkSync(fileLock)) {
console.log(
chalk.cyan(
`
There is probably another borgjs runnign process.
The look file seems to be locked.
${chalk.yellow(fileLock + '.lock')}
`
)
)
process.exit(1)
}
}
lockfile.lock(fileLock, err => {
if (err) {
console.log(chalk.red(err.message))
if (!config.repository) {
console.log(
chalk.red('The "repository" option must be specified in the config file')
)
process.exit(1)
}
const fileLock = path.join(
osTmpdir(),
filenamify(config.repository, { replacement: '-' })
)
// ensure the dir exists, otherwise it's impossible to acquire the lock
if (!fs.existsSync(fileLock)) {
fs.mkdirSync(fileLock)
}
if (fs.existsSync(`${fileLock}.lock`)) {
if (lockfile.checkSync(fileLock)) {
console.log(
chalk.cyan(
`
lockfile detected.
There is probably another borgjs runnign process.
${chalk.yellow(fileLock + '.lock')}
`
)
)
process.exit(1)
}
}
lockfile.lock(fileLock, err => {
if (err) {
console.log(chalk.red(err.message))
public async runInit(force: boolean) {
if (this.repoConfig.init) {
const versionFile = path.join(this.workspaceDir, 'init.version');
if (this.checkRevision(versionFile) && !force) {
this.log.info('a same revision exists, init cmd skipped.');
return;
}
const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');
const isLocked = await LockFile.check(lockFile);
if (isLocked) {
this.log.info('another process is running, please try again later');
return;
}
const release = await LockFile.lock(lockFile);
try {
const process = this.spawnProcess(this.repoConfig.init);
const logFile = path.join(this.workspaceDir, 'init.log');
const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
this.redirectOutput(process.stdout, logFileStream);
this.redirectOutput(process.stderr, logFileStream, true);
process.on('close', async (code, signal) => {
logFileStream.close();
await this.writeRevisionFile(versionFile);
this.log.info(`init process finished with code: ${code} signal: ${signal}`);
await release();
});
} catch (e) {
this.log.error(e);
release();
return new (_promise || _load_promise()).default(ok => {
const lockFilename = mutexFilename || path.join(config.cwd, (_constants || _load_constants()).SINGLE_INSTANCE_FILENAME);
lockfile.lock(lockFilename, { realpath: false }, (err, release) => {
if (err) {
if (isFirstTime) {
reporter.warn(reporter.lang('waitingInstance'));
}
setTimeout(() => {
ok(runEventuallyWithFile(mutexFilename, isFirstTime));
}, 200); // do not starve the CPU
} else {
onDeath(() => {
process.exit(1);
});
ok(run().then(release));
}
});
});
};
public async runInit(force: boolean) {
if (this.repoConfig.init) {
const versionFile = path.join(this.workspaceDir, 'init.version');
if (this.checkRevision(versionFile) && !force) {
this.log.info('a same revision exists, init cmd skipped.');
return;
}
const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');
const isLocked = await LockFile.check(lockFile);
if (isLocked) {
this.log.info('another process is running, please try again later');
return;
}
const release = await LockFile.lock(lockFile);
try {
if (!this.repoConfig.hasOwnProperty('init')) {
throw new Error(
`RepoConfig's init comes from a prototype, this is unexpected and unsupported`
);
}
const process = this.spawnProcess(this.repoConfig.init);
const logFile = path.join(this.workspaceDir, 'init.log');
const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
this.redirectOutput(process.stdout, logFileStream);
public async runInit(force: boolean) {
if (this.repoConfig.init) {
const versionFile = path.join(this.workspaceDir, 'init.version');
if (this.checkRevision(versionFile) && !force) {
this.log.info('a same revision exists, init cmd skipped.');
return;
}
const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');
const isLocked = await LockFile.check(lockFile);
if (isLocked) {
this.log.info('another process is running, please try again later');
return;
}
const release = await LockFile.lock(lockFile);
try {
const process = this.spawnProcess(this.repoConfig.init);
const logFile = path.join(this.workspaceDir, 'init.log');
const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
this.redirectOutput(process.stdout, logFileStream);
this.redirectOutput(process.stderr, logFileStream, true);
process.on('close', async (code, signal) => {
logFileStream.close();
await this.writeRevisionFile(versionFile);
this.log.info(`init process finished with code: ${code} signal: ${signal}`);
public async runInit(force: boolean) {
if (this.repoConfig.init) {
const versionFile = path.join(this.workspaceDir, 'init.version');
if (this.checkRevision(versionFile) && !force) {
this.log.info('a same revision exists, init cmd skipped.');
return;
}
const lockFile = this.workspaceDir; // path.join(this.workspaceDir, 'init.lock');
const isLocked = await LockFile.check(lockFile);
if (isLocked) {
this.log.info('another process is running, please try again later');
return;
}
const release = await LockFile.lock(lockFile);
try {
const process = this.spawnProcess(this.repoConfig.init);
const logFile = path.join(this.workspaceDir, 'init.log');
const logFileStream = fs.createWriteStream(logFile, { encoding: 'utf-8', flags: 'a+' });
this.redirectOutput(process.stdout, logFileStream);
this.redirectOutput(process.stderr, logFileStream, true);
process.on('close', async (code, signal) => {
logFileStream.close();
await this.writeRevisionFile(versionFile);
this.log.info(`init process finished with code: ${code} signal: ${signal}`);
return new Promise(resolve => {
const lockFilename =
mutexFilename || path.join(config.cwd, constants.SINGLE_INSTANCE_FILENAME);
lockfile.lock(
lockFilename,
{realpath: false},
(err: mixed, release: () => void) => {
if (err) {
if (isFirstTime) {
ctx.reporter.warn(ctx.reporter.lang('waitingInstance'));
}
setTimeout(() => {
resolve(runEventuallyWithFile(mutexFilename, false));
}, 200); // do not starve the CPU
} else {
onDeath(() => {
process.exitCode = 1;
});
resolve(run().then(release));
}
async function switchTheme (target) {
const lockfile = require('proper-lockfile')
let release
try {
release = await lockfile.lock('', { lockfilePath })
} catch (err) {
if (err.code === 'ELOCKED') {
// Another
return
}
throw err
}
try {
const colorTheme = workspace.getConfiguration('autoDarkMode').get(`${target}Theme`)
workspace.getConfiguration('workbench').update('colorTheme', colorTheme, ConfigurationTarget.Global)
const iconTheme = workspace.getConfiguration('autoDarkMode').get(`${target}IconTheme`)
if (iconTheme) {
workspace.getConfiguration('workbench').update('iconTheme', iconTheme, ConfigurationTarget.Global)
return new Promise(resolve => {
const lockFilename = mutexFilename || path.join(config.cwd, constants.SINGLE_INSTANCE_FILENAME);
lockfile.lock(lockFilename, {realpath: false}, (err: mixed, release: (() => void) => void) => {
if (err) {
if (isFirstTime) {
reporter.warn(reporter.lang('waitingInstance'));
}
setTimeout(() => {
resolve(runEventuallyWithFile(mutexFilename, false));
}, 200); // do not starve the CPU
} else {
onDeath(() => {
process.exitCode = 1;
});
resolve(run().then(() => new Promise(resolve => release(resolve))));
}
});
});
};