How to use the @yarnpkg/core.miscUtils.releaseAfterUseAsync function in @yarnpkg/core

To help you get started, we’ve selected a few @yarnpkg/core 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-file / sources / TarballFileFetcher.ts View on Github external
// If the package fs publicized its "original location" (for example like
    // in the case of "file:" packages), we use it to derive the real location.
    const effectiveParentFetch = parentFetch.localPath
      ? {packageFs: new NodeFS(), prefixPath: parentFetch.localPath}
      : parentFetch;

    // Discard the parent fs unless we really need it to access the files
    if (parentFetch !== effectiveParentFetch && parentFetch.releaseFs)
      parentFetch.releaseFs();

    const sourceFs = effectiveParentFetch.packageFs;
    const sourcePath = ppath.resolve(effectiveParentFetch.prefixPath, path);
    const sourceBuffer = await sourceFs.readFilePromise(sourcePath);

    return await miscUtils.releaseAfterUseAsync(async () => {
      return await tgzUtils.convertToZip(sourceBuffer, {
        stripComponents: 1,
        prefixPath: structUtils.getIdentVendorPath(locator),
      });
    }, effectiveParentFetch.releaseFs);
  }
}
github yarnpkg / berry / packages / plugin-file / sources / FileFetcher.ts View on Github external
: await opts.fetcher.fetch(parentLocator, opts);

    // If the package fs publicized its "original location" (for example like
    // in the case of "file:" packages), we use it to derive the real location.
    const effectiveParentFetch = parentFetch.localPath
      ? {packageFs: new NodeFS(), prefixPath: parentFetch.localPath}
      : parentFetch;

    // Discard the parent fs unless we really need it to access the files
    if (parentFetch !== effectiveParentFetch && parentFetch.releaseFs)
      parentFetch.releaseFs();

    const sourceFs = effectiveParentFetch.packageFs;
    const sourcePath = ppath.resolve(effectiveParentFetch.prefixPath, path);

    return await miscUtils.releaseAfterUseAsync(async () => {
      return await tgzUtils.makeArchiveFromDirectory(sourcePath, {
        baseFs: sourceFs,
        prefixPath: structUtils.getIdentVendorPath(locator),
      });
    }, effectiveParentFetch.releaseFs);
  }
}
github yarnpkg / berry / packages / plugin-patch / sources / patchUtils.ts View on Github external
? await opts.fetcher.fetch(parentLocator, opts)
    : null;

  // If the package fs publicized its "original location" (for example like
  // in the case of "file:" packages), we use it to derive the real location.
  const effectiveParentFetch = parentFetch && parentFetch.localPath
    ? {packageFs: new NodeFS(), prefixPath: parentFetch.localPath, releaseFs: undefined}
    : parentFetch;

  // Discard the parent fs unless we really need it to access the files
  if (parentFetch && parentFetch !== effectiveParentFetch && parentFetch.releaseFs)
    parentFetch.releaseFs();

  // First we obtain the specification for all the patches that we'll have to
  // apply to the original package.
  return await miscUtils.releaseAfterUseAsync(async () => {
    return await Promise.all(patchPaths.map(async patchPath => visitPatchPath({
      onAbsolute: async () => {
        return await xfs.readFilePromise(patchPath, `utf8`);
      },

      onRelative: async () => {
        if (parentFetch === null)
          throw new Error(`Assertion failed: The parent locator should have been fetched`);

        return await parentFetch.packageFs.readFilePromise(patchPath, `utf8`);
      },

      onBuiltin: async name => {
        return await opts.project.configuration.firstHook((hooks: PatchHooks) => {
          return hooks.getBuiltinPatch;
        }, opts.project, name);
github yarnpkg / berry / packages / plugin-git / sources / GitResolver.ts View on Github external
async resolve(locator: Locator, opts: ResolveOptions) {
    if (!opts.fetchOptions)
      throw new Error(`Assertion failed: This resolver cannot be used unless a fetcher is configured`);

    const packageFetch = await opts.fetchOptions.fetcher.fetch(locator, opts.fetchOptions);

    const manifest = await miscUtils.releaseAfterUseAsync(async () => {
      return await Manifest.find(packageFetch.prefixPath, {baseFs: packageFetch.packageFs});
    }, packageFetch.releaseFs);

    return {
      ...locator,

      version: manifest.version || `0.0.0`,

      languageName: opts.project.configuration.get(`defaultLanguageName`),
      linkType: LinkType.HARD,

      dependencies: manifest.dependencies,
      peerDependencies: manifest.peerDependencies,

      dependenciesMeta: manifest.dependenciesMeta,
      peerDependenciesMeta: manifest.peerDependenciesMeta,
github yarnpkg / berry / packages / plugin-file / sources / FileResolver.ts View on Github external
async resolve(locator: Locator, opts: ResolveOptions) {
    if (!opts.fetchOptions)
      throw new Error(`Assertion failed: This resolver cannot be used unless a fetcher is configured`);

    const packageFetch = await opts.fetchOptions.fetcher.fetch(locator, opts.fetchOptions);

    const manifest = await miscUtils.releaseAfterUseAsync(async () => {
      return await Manifest.find(packageFetch.prefixPath, {baseFs: packageFetch.packageFs});
    }, packageFetch.releaseFs);

    return {
      ...locator,

      version: manifest.version || `0.0.0`,

      languageName: opts.project.configuration.get(`defaultLanguageName`),
      linkType: LinkType.HARD,

      dependencies: manifest.dependencies,
      peerDependencies: manifest.peerDependencies,

      dependenciesMeta: manifest.dependenciesMeta,
      peerDependenciesMeta: manifest.peerDependenciesMeta,
github yarnpkg / berry / packages / plugin-link / sources / LinkResolver.ts View on Github external
async resolve(locator: Locator, opts: ResolveOptions): Promise {
    if (!opts.fetchOptions)
      throw new Error(`Assertion failed: This resolver cannot be used unless a fetcher is configured`);

    const packageFetch = await opts.fetchOptions.fetcher.fetch(locator, opts.fetchOptions);

    const manifest = await miscUtils.releaseAfterUseAsync(async () => {
      return await Manifest.find(packageFetch.prefixPath, {baseFs: packageFetch.packageFs});
    }, packageFetch.releaseFs);

    return {
      ...locator,

      version: manifest.version || `0.0.0`,

      languageName: opts.project.configuration.get(`defaultLanguageName`),
      linkType: LinkType.SOFT,

      dependencies: new Map([...manifest.dependencies, ...manifest.devDependencies]),
      peerDependencies: manifest.peerDependencies,

      dependenciesMeta: manifest.dependenciesMeta,
      peerDependenciesMeta: manifest.peerDependenciesMeta,
github yarnpkg / berry / packages / plugin-git / sources / GitFetcher.ts View on Github external
async cloneFromRemote(locator: Locator, opts: FetchOptions) {
    const cloneTarget = await gitUtils.clone(locator.reference, opts.project.configuration);

    const packagePath = ppath.join(cloneTarget, `package.tgz` as PortablePath);
    await scriptUtils.prepareExternalProject(cloneTarget, packagePath, {
      configuration: opts.project.configuration,
      report: opts.report,
    });

    const sourceBuffer = await xfs.readFilePromise(packagePath);

    return await miscUtils.releaseAfterUseAsync(async () => {
      return await tgzUtils.convertToZip(sourceBuffer, {
        stripComponents: 1,
        prefixPath: structUtils.getIdentVendorPath(locator),
      });
    });
  }
}
github yarnpkg / berry / packages / plugin-patch / sources / PatchFetcher.ts View on Github external
private async patchPackage(locator: Locator, opts: FetchOptions) {
    const {parentLocator, sourceLocator, patchPaths} = patchUtils.parseLocator(locator);
    const patchFiles = await patchUtils.loadPatchFiles(parentLocator, patchPaths, opts);

    const tmpDir = await xfs.mktempPromise();
    const tmpFile = ppath.join(tmpDir, `patched.zip` as Filename);

    const sourceFetch = await opts.fetcher.fetch(sourceLocator, opts);
    const prefixPath = structUtils.getIdentVendorPath(locator);

    const copiedPackage = new ZipFS(tmpFile, {create: true});
    await copiedPackage.mkdirpPromise(prefixPath);

    await miscUtils.releaseAfterUseAsync(async () => {
      await copiedPackage.copyPromise(prefixPath, sourceFetch.prefixPath, {baseFs: sourceFetch.packageFs});
    }, sourceFetch.releaseFs);

    copiedPackage.saveAndClose();

    const patchedPackage = new ZipFS(tmpFile);
    const patchFs = new CwdFS(prefixPath, {baseFs: patchedPackage});

    for (const patchFile of patchFiles) {
      if (patchFile !== null) {
        await patchUtils.applyPatchFile(patchUtils.parsePatchFile(patchFile), {
          baseFs: patchFs,
        });
      }
    }
github yarnpkg / berry / packages / plugin-file / sources / TarballFileResolver.ts View on Github external
async resolve(locator: Locator, opts: ResolveOptions) {
    if (!opts.fetchOptions)
      throw new Error(`Assertion failed: This resolver cannot be used unless a fetcher is configured`);

    const packageFetch = await opts.fetchOptions.fetcher.fetch(locator, opts.fetchOptions);

    const manifest = await miscUtils.releaseAfterUseAsync(async () => {
      return await Manifest.find(packageFetch.prefixPath, {baseFs: packageFetch.packageFs});
    }, packageFetch.releaseFs);

    return {
      ...locator,

      version: manifest.version || `0.0.0`,

      languageName: opts.project.configuration.get(`defaultLanguageName`),
      linkType: LinkType.HARD,

      dependencies: manifest.dependencies,
      peerDependencies: manifest.peerDependencies,

      dependenciesMeta: manifest.dependenciesMeta,
      peerDependenciesMeta: manifest.peerDependenciesMeta,