How to use the proper-lockfile.check function in proper-lockfile

To help you get started, we’ve selected a few proper-lockfile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elastic / kibana / x-pack / legacy / plugins / code / server / lsp / workspace_command.ts View on Github external
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);
github elastic / kibana / kibana-extra / code / server / lsp / workspace_command.ts View on Github external
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}`);
github elastic / kibana / x-pack / plugins / code / server / lsp / workspace_command.ts View on Github external
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}`);
github mjackson / unpkg / server / utils / getPackage.js View on Github external
fetchPackage(tarballURL, outputDir).then(
          () => {
            release();
            callback(null, outputDir);
          },
          error => {
            release();
            callback(error);
          }
        );
      } else {
        callback(error);
      }
    } else {
      lockfile.check(outputDir).then(locked => {
        if (locked) {
          // Another process on this same machine has locked the
          // directory. We need to wait for it to be unlocked
          // before we callback.
          const timer = setInterval(() => {
            lockfile.check(outputDir).then(
              locked => {
                if (!locked) {
                  clearInterval(timer);
                  callback(null, outputDir);
                }
              },
              error => {
                clearInterval(timer);
                callback(error);
              }
github jspm / jspm-cli / lib / utils / cache.js View on Github external
            const locked = await new Promise((resolve, reject) => lockfile.check(resolved, { realpath: false }, (err, locked) => err ? reject(err) : resolve(locked)));
            if (locked)
github laurent22 / joplin / CliClient / app / command-sync.js View on Github external
return new Promise((resolve, reject) => {
			locker.check(filePath, (error, isLocked) => {
				if (error) {
					reject(error);
					return;
				}

				resolve(isLocked);
			});
		});
	}
github nuxt / nuxt.js / packages / utils / src / locking.js View on Github external
export async function lock ({ id, dir, root, options }) {
  const lockPath = await getLockPath({ id, dir, root })

  try {
    const locked = await properlock.check(lockPath)
    if (locked) {
      consola.fatal(`A lock with id '${id}' already exists on ${dir}`)
    }
  } catch (e) {
    consola.debug(`Check for an existing lock with id '${id}' on ${dir} failed`, e)
  }

  let lockWasCompromised = false
  let release

  try {
    options = getLockOptions(options)

    const onCompromised = options.onCompromised
    options.onCompromised = (err) => {
      onCompromised(err)
github mjackson / unpkg / server / utils / getPackage.js View on Github external
const timer = setInterval(() => {
            lockfile.check(outputDir).then(
              locked => {
                if (!locked) {
                  clearInterval(timer);
                  callback(null, outputDir);
                }
              },
              error => {
                clearInterval(timer);
                callback(error);
              }
            );
          }, 10);

proper-lockfile

A inter-process and inter-machine lockfile utility that works on a local or network file system

MIT
Latest version published 4 years ago

Package Health Score

74 / 100
Full package analysis