How to use the @yarnpkg/core.structUtils.stringifyIdent 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-stage / sources / drivers / GitDriver.ts View on Github external
} else if (currDep.range !== value.range) {
          actions.push([stageUtils.ActionType.MODIFY, `${pkgName} to ${currDep.range}`]);
        }
      }

      for (const [indentHash, value] of allCurrDeps) {
        if (!allPrevDeps.has(indentHash)) {
          actions.push([stageUtils.ActionType.ADD, structUtils.stringifyIdent(value)]);
        }
      }
    } else if (action === stageUtils.ActionType.CREATE) {
      // New package.json
      const manifest = await Manifest.fromFile(path)

      if (manifest.name) {
        actions.push([stageUtils.ActionType.CREATE, structUtils.stringifyIdent(manifest.name)])
      } else {
        actions.push([stageUtils.ActionType.CREATE, `a package`])
      }
    } else if (action === stageUtils.ActionType.DELETE) {
      const commitHash = await getLastCommitHash(cwd);
      const {stdout: prevSource} = await execUtils.execvp(`git`, [`show`, `${commitHash}:${relativePath}`], {cwd, strict: true});

      // Deleted package.json; we need to load it from its past sources
      const manifest = await Manifest.fromText(prevSource);

      if (manifest.name) {
        actions.push([stageUtils.ActionType.DELETE, structUtils.stringifyIdent(manifest.name)]);
      } else {
        actions.push([stageUtils.ActionType.DELETE, `a package`]);
      }
    } else {
github yarnpkg / berry / packages / plugin-stage / sources / drivers / GitDriver.ts View on Github external
for (const {action, path} of modifiedPkgJsonFiles) {
    const relativePath = ppath.relative(cwd, path);

    if (action === stageUtils.ActionType.MODIFY) {
      const commitHash = await getLastCommitHash(cwd)
      const {stdout: prevSource} = await execUtils.execvp(`git`, [`show`, `${commitHash}:${relativePath}`], {cwd, strict: true});

      const prevManifest = await Manifest.fromText(prevSource);
      const currManifest = await Manifest.fromFile(path);

      const allCurrDeps: Map = new Map([...currManifest.dependencies, ...currManifest.devDependencies]);
      const allPrevDeps: Map = new Map([...prevManifest.dependencies, ...prevManifest.devDependencies]);

      for (const [indentHash, value] of allPrevDeps) {
        const pkgName = structUtils.stringifyIdent(value);
        const currDep = allCurrDeps.get(indentHash);

        if (!currDep) {
          actions.push([stageUtils.ActionType.REMOVE, pkgName])
        } else if (currDep.range !== value.range) {
          actions.push([stageUtils.ActionType.MODIFY, `${pkgName} to ${currDep.range}`]);
        }
      }

      for (const [indentHash, value] of allCurrDeps) {
        if (!allPrevDeps.has(indentHash)) {
          actions.push([stageUtils.ActionType.ADD, structUtils.stringifyIdent(value)]);
        }
      }
    } else if (action === stageUtils.ActionType.CREATE) {
      // New package.json
github yarnpkg / berry / packages / plugin-stage / sources / drivers / GitDriver.ts View on Github external
const allPrevDeps: Map = new Map([...prevManifest.dependencies, ...prevManifest.devDependencies]);

      for (const [indentHash, value] of allPrevDeps) {
        const pkgName = structUtils.stringifyIdent(value);
        const currDep = allCurrDeps.get(indentHash);

        if (!currDep) {
          actions.push([stageUtils.ActionType.REMOVE, pkgName])
        } else if (currDep.range !== value.range) {
          actions.push([stageUtils.ActionType.MODIFY, `${pkgName} to ${currDep.range}`]);
        }
      }

      for (const [indentHash, value] of allCurrDeps) {
        if (!allPrevDeps.has(indentHash)) {
          actions.push([stageUtils.ActionType.ADD, structUtils.stringifyIdent(value)]);
        }
      }
    } else if (action === stageUtils.ActionType.CREATE) {
      // New package.json
      const manifest = await Manifest.fromFile(path)

      if (manifest.name) {
        actions.push([stageUtils.ActionType.CREATE, structUtils.stringifyIdent(manifest.name)])
      } else {
        actions.push([stageUtils.ActionType.CREATE, `a package`])
      }
    } else if (action === stageUtils.ActionType.DELETE) {
      const commitHash = await getLastCommitHash(cwd);
      const {stdout: prevSource} = await execUtils.execvp(`git`, [`show`, `${commitHash}:${relativePath}`], {cwd, strict: true});

      // Deleted package.json; we need to load it from its past sources
github yarnpkg / berry / packages / plugin-constraints / sources / Constraints.ts View on Github external
      ({dependencyIdent}) => structUtils.stringifyIdent(dependencyIdent),
    ]);
github yarnpkg / berry / packages / plugin-workspace-tools / sources / commands / foreach.ts View on Github external
function getPrefix(workspace: Workspace, {configuration, commandIndex, verbose}: GetPrefixOptions) {
  if (!verbose)
    return null;

  const ident = structUtils.convertToIdent(workspace.locator);
  const name = structUtils.stringifyIdent(ident);

  let prefix = `[${name}]:`;

  const colors = [`#2E86AB`, `#A23B72`, `#F18F01`, `#C73E1D`, `#CCE2A3`];
  const colorName = colors[commandIndex % colors.length];

  return configuration.format(prefix, colorName);
}
github yarnpkg / berry / packages / plugin-exec / sources / ExecFetcher.ts View on Github external
const cwd = npath.toPortablePath(dirSync().name);
    const env = await scriptUtils.makeScriptEnv({project: opts.project});

    const logFile = npath.toPortablePath(tmpNameSync({
      prefix: `buildfile-`,
      postfix: `.log`,
    }));

    const stdin = null;
    const stdout = xfs.createWriteStream(logFile);
    const stderr = stdout;

    stdout.write(`# This file contains the result of Yarn generating a package (${structUtils.stringifyLocator(locator)})\n`);
    stdout.write(`\n`);

    const {code} = await execUtils.pipevp(process.execPath, [npath.fromPortablePath(generatorPath), structUtils.stringifyIdent(locator)], {cwd, env, stdin, stdout, stderr});
    if (code !== 0)
      throw new Error(`Package generation failed (exit code ${code}, logs can be found here: ${logFile})`);

    return cwd;
  }
}
github yarnpkg / berry / packages / plugin-workspace-tools / sources / commands / workspace.ts View on Github external
(workspace): [string, Workspace] => {
          const ident = structUtils.convertToIdent(workspace.locator);
          return [structUtils.stringifyIdent(ident), workspace];
        }
      )
github yarnpkg / berry / packages / plugin-essentials / sources / commands / link.ts View on Github external
if (linkedWorkspaces.length === 0) {
        throw new UsageError(`No workspace found to be linked in the target project`);
      }
    } else {
      if (!workspace2.manifest.name)
        throw new UsageError(`The target workspace doesn't have a name and thus cannot be linked`);

      if (workspace2.manifest.private && !this.private)
        throw new UsageError(`The target workspace is marked private - use the --private flag to link it anyway`);

      linkedWorkspaces.push(workspace2);
    }

    for (const workspace of linkedWorkspaces) {
      const fullName = structUtils.stringifyIdent(workspace.locator);
      const target = this.relative
        ? ppath.relative(project.cwd, workspace.cwd)
        : workspace.cwd;

      topLevelWorkspace.manifest.resolutions.push({
        pattern: {descriptor: {fullName}},
        reference: `portal:${target}`,
      });
    }

    const report = await StreamReport.start({
      configuration,
      stdout: this.context.stdout,
    }, async (report: StreamReport) => {
      await project.install({cache, report});
    });