How to use the @yarnpkg/fslib.xfs.removePromise function in @yarnpkg/fslib

To help you get started, we’ve selected a few @yarnpkg/fslib 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 yarnpkg / berry / packages / plugin-node-modules / sources / NodeModulesLinker.ts View on Github external
fallbackExclusionList.push({name: structUtils.requirableIdent(pkg), reference: pkg.reference});

    const pnpSettings = {
      blacklistedLocations,
      dependencyTreeRoots,
      enableTopLevelFallback,
      fallbackExclusionList,
      ignorePattern,
      packageRegistry,
      shebang,
      virtualRoots,
    };

    const pnpUnpluggedFolder = this.opts.project.configuration.get(`pnpUnpluggedFolder`);
    if (this.unpluggedPaths.size === 0) {
      await xfs.removePromise(pnpUnpluggedFolder);
    } else {
      for (const entry of await xfs.readdirPromise(pnpUnpluggedFolder)) {
        const unpluggedPath = ppath.resolve(pnpUnpluggedFolder, entry);
        if (!this.unpluggedPaths.has(unpluggedPath)) {
          await xfs.removePromise(unpluggedPath);
        }
      }
    }

    const nodeFs = new NodeFS(fs);
    const baseFs = new ZipOpenFS({
      baseFs: nodeFs,
      maxOpenFiles: 80,
      readOnlyArchives: true,
    });
    const defaultFsLayer: FakeFS = new VirtualFS({baseFs});
github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
await xfs.removePromise(pnpDataPath);
    } else {
      const dataLocation = ppath.relative(ppath.dirname(pnpPath), pnpDataPath);
      const {dataFile, loaderFile} = generateSplitScript({...pnpSettings, dataLocation});

      await xfs.changeFilePromise(pnpPath, loaderFile);
      await xfs.chmodPromise(pnpPath, 0o755);

      await xfs.changeFilePromise(pnpDataPath, dataFile);
      await xfs.chmodPromise(pnpDataPath, 0o644);
    }

    const pnpUnpluggedFolder = this.opts.project.configuration.get(`pnpUnpluggedFolder`);
    if (this.unpluggedPaths.size === 0) {
      await xfs.removePromise(pnpUnpluggedFolder);
    } else {
      for (const entry of await xfs.readdirPromise(pnpUnpluggedFolder)) {
        const unpluggedPath = ppath.resolve(pnpUnpluggedFolder, entry);
        if (!this.unpluggedPaths.has(unpluggedPath)) {
          await xfs.removePromise(unpluggedPath);
        }
      }
    }
  }
github yarnpkg / berry / packages / plugin-node-modules / sources / NodeModulesLinker.ts View on Github external
enableTopLevelFallback,
      fallbackExclusionList,
      ignorePattern,
      packageRegistry,
      shebang,
      virtualRoots,
    };

    const pnpUnpluggedFolder = this.opts.project.configuration.get(`pnpUnpluggedFolder`);
    if (this.unpluggedPaths.size === 0) {
      await xfs.removePromise(pnpUnpluggedFolder);
    } else {
      for (const entry of await xfs.readdirPromise(pnpUnpluggedFolder)) {
        const unpluggedPath = ppath.resolve(pnpUnpluggedFolder, entry);
        if (!this.unpluggedPaths.has(unpluggedPath)) {
          await xfs.removePromise(unpluggedPath);
        }
      }
    }

    const nodeFs = new NodeFS(fs);
    const baseFs = new ZipOpenFS({
      baseFs: nodeFs,
      maxOpenFiles: 80,
      readOnlyArchives: true,
    });
    const defaultFsLayer: FakeFS = new VirtualFS({baseFs});

    const rootPath = this.opts.project.cwd;
    let prevLocatorMap: NodeModulesLocatorMap;
    try {
      prevLocatorMap = await readLocatorState(ppath.join(rootPath, NODE_MODULES, LOCATOR_STATE_FILE));
github yarnpkg / berry / packages / yarnpkg-core / sources / scriptUtils.ts View on Github external
const binary = packageAccessibleBinaries.get(binaryName);
  if (!binary)
    throw new Error(`Binary not found (${binaryName}) for ${structUtils.prettyLocator(project.configuration, locator)}`);

  const [, binaryPath] = binary;
  const env = await makeScriptEnv({project});

  for (const [binaryName, [, binaryPath]] of packageAccessibleBinaries)
    await makePathWrapper(env.BERRY_BIN_FOLDER as PortablePath, toFilename(binaryName), process.execPath, [binaryPath]);

  let result;
  try {
    result = await execUtils.pipevp(process.execPath, [binaryPath, ...args], {cwd, env, stdin, stdout, stderr});
  } finally {
    await xfs.removePromise(env.BERRY_BIN_FOLDER as PortablePath);
  }

  return result.code;
}
github yarnpkg / berry / packages / plugin-essentials / sources / commands / set / version / sources.ts View on Github external
report.reportSeparator();

        try {
          await runWorkflow(UPDATE_WORKFLOW(this));
          ready = true;
        } catch (error) {
          report.reportSeparator();
          report.reportWarning(MessageName.UNNAMED, `Repository update failed; we'll try to regenerate it`);
        }
      }

      if (!ready) {
        report.reportInfo(MessageName.UNNAMED, `Cloning the remote repository`);
        report.reportSeparator();

        await xfs.removePromise(target);
        await xfs.mkdirpPromise(target);

        await runWorkflow(CLONE_WORKFLOW(this, target));
      }

      report.reportSeparator();
      report.reportInfo(MessageName.UNNAMED, `Building a fresh bundle`);
      report.reportSeparator();

      await runWorkflow(BUILD_WORKFLOW(this));

      report.reportSeparator();

      const bundlePath = ppath.resolve(target, `packages/yarnpkg-cli/bundles/yarn.js` as PortablePath);
      const bundleBuffer = await xfs.readFilePromise(bundlePath);
github yarnpkg / berry / packages / yarnpkg-core / sources / scriptUtils.ts View on Github external
export async function executePackageShellcode(locator: Locator, command: string, args: Array, {cwd, project, stdin, stdout, stderr}: ExecutePackageScriptOptions) {
  const {binFolder, env, cwd: realCwd} = await initializePackageEnvironment(locator, {project, cwd});

  try {
    return await execute(command, args, {cwd: realCwd, env, stdin, stdout, stderr});
  } finally {
    await xfs.removePromise(binFolder);
  }
}
github yarnpkg / berry / packages / yarnpkg-core / sources / scriptUtils.ts View on Github external
return;

  const realExecutor = async () => {
    return await execute(script, args, {cwd: realCwd, env, stdin, stdout, stderr});
  };

  const executor = await project.configuration.reduceHook(hooks => {
    return hooks.wrapScriptExecution;
  }, realExecutor, project, locator, scriptName, {
    script, args, cwd: realCwd, env, stdin, stdout, stderr,
  });

  try {
    return await executor();
  } finally {
    await xfs.removePromise(binFolder);
  }
}
github yarnpkg / berry / packages / yarnpkg-core / sources / Project.ts View on Github external
});

    if (bstateData.length > 0) {
      let bstateFile = `# Warning: This file is automatically generated. Removing it is fine, but will\n# cause all your builds to become invalidated.\n`;

      for (const [locatorString, locatorHash, buildHash] of miscUtils.sortMap(bstateData, [d => d[0], d => d[1]])) {
        bstateFile += `\n`;
        bstateFile += `# ${locatorString}\n`;
        bstateFile += `${JSON.stringify(locatorHash)}:\n`;
        bstateFile += `  ${buildHash}\n`;
      }

      await xfs.mkdirpPromise(ppath.dirname(bstatePath));
      await xfs.changeFilePromise(bstatePath, bstateFile);
    } else {
      await xfs.removePromise(bstatePath);
    }
  }
github yarnpkg / berry / packages / plugin-dlx / sources / commands / dlx.ts View on Github external
this.context.stdout.write(`\n`);

      const configuration = await Configuration.find(tmpDir, this.context.plugins);
      const {workspace} = await Project.find(configuration, tmpDir);

      if (workspace === null)
        throw new WorkspaceRequiredError(tmpDir);

      return await scriptUtils.executeWorkspaceAccessibleBinary(workspace, command, this.args, {
        cwd: this.context.cwd,
        stdin: this.context.stdin,
        stdout: this.context.stdout,
        stderr: this.context.stderr,
      });
    } finally {
      await xfs.removePromise(tmpDir);
    }
  }
}
github yarnpkg / berry / packages / plugin-pnp / sources / PnpLinker.ts View on Github external
blacklistedLocations,
      dependencyTreeRoots,
      enableTopLevelFallback,
      fallbackExclusionList,
      ignorePattern,
      packageRegistry,
      shebang,
    };

    if (this.opts.project.configuration.get(`pnpEnableInlining`)) {
      const loaderFile = generateInlinedScript(pnpSettings);

      await xfs.changeFilePromise(pnpPath, loaderFile);
      await xfs.chmodPromise(pnpPath, 0o755);

      await xfs.removePromise(pnpDataPath);
    } else {
      const dataLocation = ppath.relative(ppath.dirname(pnpPath), pnpDataPath);
      const {dataFile, loaderFile} = generateSplitScript({...pnpSettings, dataLocation});

      await xfs.changeFilePromise(pnpPath, loaderFile);
      await xfs.chmodPromise(pnpPath, 0o755);

      await xfs.changeFilePromise(pnpDataPath, dataFile);
      await xfs.chmodPromise(pnpDataPath, 0o644);
    }

    const pnpUnpluggedFolder = this.opts.project.configuration.get(`pnpUnpluggedFolder`);
    if (this.unpluggedPaths.size === 0) {
      await xfs.removePromise(pnpUnpluggedFolder);
    } else {
      for (const entry of await xfs.readdirPromise(pnpUnpluggedFolder)) {