• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

evolvedbinary / lwdita / cca6d7bf-7c00-4498-aeae-a3b9e82fd494

05 Jun 2024 11:13AM UTC coverage: 87.525% (+0.1%) from 87.386%
cca6d7bf-7c00-4498-aeae-a3b9e82fd494

push

circleci

web-flow
Merge pull request #192 from evolvedbinary/hotfix/mono-repo

Place source code in a 'src/' folder

499 of 604 branches covered (82.62%)

Branch coverage included in aggregate %.

3 of 6 new or added lines in 2 files covered. (50.0%)

1227 of 1368 relevant lines covered (89.69%)

22.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.63
/plugin-release.js
1
module.exports = {
1✔
2
    name: `plugin-addition`,
3
    factory: require => {
4
      const {BaseCommand, WorkspaceRequiredError} = require(`@yarnpkg/cli`);
2✔
5
      const {Configuration, Project} = require('@yarnpkg/core');
2✔
6
      const {execute} = require('@yarnpkg/shell');
2✔
7
      const {Command, Option} = require(`clipanion`);
2✔
8
      const {copyFile, rm} = require('fs/promises');
2✔
9
      const t = require(`typanion`);
2✔
10

11
      const semver2Regex = "(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:\\-([1-9A-Za-z-][0-9A-Za-z-]*(?:\\.[1-9A-Za-z-][0-9A-Za-z-]*)*))?(?:\\+([1-9A-Za-z-][0-9A-Za-z-]*(?:\\.[1-9A-Za-z-][0-9A-Za-z-]*)*))?";
2✔
12
      const yarnAutoVersionsRegex = "(major|minor|patch)";
2✔
13
  
14
      class ReleaseCommand extends BaseCommand {
15
        static paths = [[`release`]];
2✔
16
  
17
        // Show descriptive usage for a --help argument passed to this command
18
        static usage = Command.Usage({
2✔
19
          description: `Publish a new release`,
20
          details: `
21
            This command will create a new release for the project, which involves the following steps:
22
            1. Check project status - Requires no unstaged changes, and no un-pushed commits.
23
            2. Pre-release testing - Executes the \`lint\` and \`test\` scripts.
24
            3. Update the version numbers of all packages.
25
            4. git commit the version update.
26
            5. git tag and sign the release tag.
27
            6. git push the updates - Version commit and tag.
28
            7. Publish the packages to npm.js.
29
          `,
30
          examples: [
31
            [
32
                `Release the next major version`,
33
                `yarn release major`,
34
            ],
35
            [
36
                `Release the next version as 2.1.0`,
37
                `yarn release 2.1.0`,
38
            ]
39
        ],
40
        });
41
  
42
        version = Option.String({
1✔
43
            validator: t.matchesRegExp(new RegExp("^" + yarnAutoVersionsRegex + "|(?:" + semver2Regex + ")$"))
44
        });
45
        // b = Option.String({validator: t.isNumber()});
46
  
47
        async execute() {
48
          const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
×
49
          const {project, workspace} = await Project.find(configuration, this.context.cwd);
×
50

51
          if (!workspace) {
×
52
            throw new WorkspaceRequiredError(project.cwd, this.context.cwd);
×
53
          }
54

55
          this.context.stdout.write(`Preparing to release version: ${this.version}...\n`);
×
56

57
          let executeOptions = {"cwd": project.cwd};
×
58

59
          // Step 1 - Check project status - requires no unstaged changes, and no un-pushed commits
60
          // TODO(AR) figure out how to capture stdout from the git commands below and check the content
61
          this.context.stdout.write("1. Checking project status...\n");
×
62
          this.context.stdout.write("1.1. Checking for git 'main' branch...\n");
×
63
          //   await execute('git', ['branch', '--show-current'], executeOptions);
64
          this.context.stdout.write("1.2. Checking for unstaged changes...\n");
×
65
          //   await execute('git', ['status', '--porcelain', '--untracked-files=no'], executeOptions);
66
          this.context.stdout.write("1.3. Checking for un-pushed commits...\n");
×
67
          //   await execute('git', ['log', 'origin/main..HEAD'], [], executeOptions);
68

69
          // Step 2 - Pre-release testing - Executes the `lint` and `test` scripts
70
          this.context.stdout.write("2. Performing pre-release testing...\n");
×
NEW
71
          await this.cli.run(['build']);
×
NEW
72
          await this.cli.run(['lint']);
×
NEW
73
          await this.cli.run(['test']);
×
74
          // this.context.stdout.write("2.1. Performing lint...\n");
75
          // await this.cli.run(['clean'])
76
          // await this.cli.run(['lint'])
77
          // this.context.stdout.write("2.2. Performing build...\n");
78
          // await this.cli.run(['clean'])
79
          // await this.cli.run(['build'])
80
          // this.context.stdout.write("2.3. Running tests...\n");
81
          // await this.cli.run(['clean'])
82
          // await this.cli.run(['test'])
83

84
          // Cleanup after Step 2 - Pre-release testing
85
          await this.cli.run(['clean'])
×
86

87
          // Step 3 - Increment the versions of all packages (including the project root)
88
          let packageFiles = [];
×
89
          this.context.stdout.write(`3. Running \`yarn version\` to bump versions of all workspaces to ${this.version}...\n`);
×
90
          for (let i = 0; i < project.workspaces.length; i++) {
×
91
            let projectWorkspace = project.workspaces[i];
×
92

93
            if (projectWorkspace.cwd == project.cwd) {
×
94
              await this.cli.run(['version', this.version]);
×
95
            } else {
96
              let projectWorkspaceName = `@${projectWorkspace.manifest.name.scope}/${projectWorkspace.manifest.name.name}`;
×
97
              await this.cli.run(['workspace', projectWorkspaceName, 'version', this.version]);
×
98
            }
99
            packageFiles.push(`${projectWorkspace.cwd}/package.json`);
×
100
          }
101

102
          // Step 4 - git commit the version update.
103
          this.context.stdout.write(`4. git Committing the version update...\n`);
×
104
          await execute('git', ['commit', `--message=[release] Release version: ${this.version}`].concat(packageFiles), executeOptions);
×
105
        
106
          // Step 5 - git tag and sign the release tag.
107
          this.context.stdout.write(`5. git Committing the version update...\n`);
×
108
          await execute('git', ['tag', `--message=[release] Release version: ${this.version}`, '--sign', `v${this.version}`], executeOptions);
×
109
        
110
          // Step 6 - git push the updates.
111
          this.context.stdout.write(`6. git push the version update...\n`);
×
112
          this.context.stdout.write(`6.1. git pushing the branch...\n`);
×
113
          await execute('git', ['push'], executeOptions);
×
114
          this.context.stdout.write(`6.2. git pushing the tag...\n`);
×
115
          await execute('git', ['push', '--tags'], executeOptions);
×
116

117
          // Step 7 - Publish the packages to npm.js.
118
          this.context.stdout.write(`7. Running \`yarn npn publish\` to publish packages to npm.js...\n`);
×
119
          await this.cli.run(['npm', 'login']);
×
120
          for (let i = 0; i < project.workspaces.length; i++) {
×
121
            let projectWorkspace = project.workspaces[i];
×
122

123
            if (projectWorkspace.cwd == project.cwd) {
×
124
              this.context.stdout.write("NOTE: Skipping publish of project root workspace!\n")
×
125
            } else {
126
              // Make a copy of the LICENSE file to the workspace so that it is published as part of the package
127
              await copyFile(`${project.cwd}/LICENSE`, `${projectWorkspace.cwd}/LICENSE`);
×
128

129
              // Publish the workspace package
130
              let projectWorkspaceName = `@${projectWorkspace.manifest.name.scope}/${projectWorkspace.manifest.name.name}`;
×
131
              await this.cli.run(['workspace', projectWorkspaceName, 'npm', 'publish', '--access', 'public']);
×
132

133
              // Remove the copy of the LICENSE file from the workspace
134
              await rm(`${projectWorkspace.cwd}/LICENSE`);
×
135
            }
136
          }
137

138
          this.context.stdout.write(`Released version: ${this.version} OK!\n`);
×
139
        }
140
      }
141
  
142
      return {
2✔
143
        commands: [
144
          ReleaseCommand,
145
        ],
146
      };
147
    },
148
  };
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc