How to use the @microsoft/rush-lib.Package function in @microsoft/rush-lib

To help you get started, we’ve selected a few @microsoft/rush-lib 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 microsoft / rushstack / rush / rush / src / actions / LinkAction.ts View on Github external
localLinks = [];
              rushLinkJson.localLinks[localPackage.name] = localLinks;
            }
            localLinks.push(dependency.name);
          }

          // Is the dependency already resolved?
          const resolution: IResolveOrCreateResult = localPackage.resolveOrCreate(dependency.name);

          if (!resolution.found || resolution.found.version !== matchedVersion) {
            // We did not find a suitable match, so place a new local package that
            // symlinks to the Rush project
            const newLocalFolderPath: string = path.join(
              resolution.parentForCreate.folderPath, 'node_modules', dependency.name);

            const newLocalPackage: Package = new Package(
              dependency.name,
              matchedVersion,
              // Since matchingRushProject does not have a parent, its dependencies are
              // guaranteed to be already fully resolved inside its node_modules folder.
              [],
              newLocalFolderPath
            );

            newLocalPackage.symlinkTargetFolderPath = matchedRushPackage.projectFolder;

            resolution.parentForCreate.addChild(newLocalPackage);

            // (There are no dependencies, so we do not need to push it onto the queue.)
          }

          continue;
github microsoft / rushstack / rush / rush / src / actions / LinkAction.ts View on Github external
function linkProject(
  project: RushConfigurationProject,
  commonRootPackage: Package,
  commonPackageLookup: PackageLookup,
  rushConfiguration: RushConfiguration,
  rushLinkJson: IRushLinkJson): void {

  const commonProjectPackage: Package = commonRootPackage.getChildByName(project.tempProjectName);
  if (!commonProjectPackage) {
    throw new Error(`Unable to find a temp package for ${project.packageName} `
      + `-- you may need to run "rush generate" again`);
  }

  // TODO: Validate that the project's package.json still matches the common folder
  const localProjectPackage: Package = new Package(
    project.packageJson.name,
    commonProjectPackage.version,
    commonProjectPackage.dependencies,
    project.projectFolder
  );

  const queue: IQueueItem[] = [];
  queue.push({
    commonPackage: commonProjectPackage,
    localPackage: localProjectPackage,
    cyclicSubtreeRoot: undefined
  });

  // tslint:disable-next-line:no-constant-condition
  while (true) {
    const queueItem: IQueueItem = queue.shift();
github microsoft / rushstack / rush / rush / src / actions / LinkAction.ts View on Github external
resolution = localPackage.resolveOrCreate(dependency.name);
        } else {
          // We are inside a cyclicDependencyProjects subtree (i.e. cyclicSubtreeRoot != undefined),
          // and the dependency is a local project (i.e. matchedRushPackage != undefined), so
          // we use a special module resolution strategy that places everything under the
          // cyclicSubtreeRoot.
          resolution = localPackage.resolveOrCreate(dependency.name, cyclicSubtreeRoot);
        }

        if (!resolution.found || resolution.found.version !== effectiveDependencyVersion) {
          // We did not find a suitable match, so place a new local package

          const newLocalFolderPath: string = path.join(
            resolution.parentForCreate.folderPath, 'node_modules', commonDependencyPackage.name);

          const newLocalPackage: Package = new Package(
            commonDependencyPackage.name,
            commonDependencyPackage.version,
            commonDependencyPackage.dependencies,
            newLocalFolderPath
          );

          const commonPackage: Package = commonPackageLookup.getPackage(newLocalPackage.nameAndVersion);
          if (!commonPackage) {
            throw Error(`The ${localPackage.name}@${localPackage.version} package was not found`
              + ` in the ${rushConfiguration.commonFolderName} folder`);
          }
          newLocalPackage.symlinkTargetFolderPath = commonPackage.folderPath;

          let newCyclicSubtreeRoot: Package = cyclicSubtreeRoot;
          if (startingCyclicSubtree) {
            // If we are starting a new subtree, then newLocalPackage will be its root