monorepo-next 8.2.0 → 8.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,6 +4,15 @@
4
4
 
5
5
  Detach monorepo packages from normal linking. Work on breaking changes while gradually updating consumers.
6
6
 
7
+ Each package can have a `monorepo-next.config.js` with the following options:
8
+
9
+ ```js
10
+ module.exports = {
11
+ // Set this to false to opt-out of change detection and versioning.
12
+ shouldBumpVersion: true,
13
+ }
14
+ ```
15
+
7
16
  <!-- CODEGEN_CLI_HELP -->
8
17
 
9
18
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monorepo-next",
3
- "version": "8.2.0",
3
+ "version": "8.3.2",
4
4
  "description": "Detach monorepo packages from normal linking",
5
5
  "bin": {
6
6
  "next": "bin/next.js"
@@ -9,9 +9,11 @@ const {
9
9
  getCommitSinceLastRelease,
10
10
  } = require('./git');
11
11
  const { collectPackages } = require('./build-dep-graph');
12
- const minimatch = require('minimatch');
12
+ const { isSubDir } = require('./path');
13
13
  const { getChangedReleasableFiles } = require('./releasable');
14
14
  const Set = require('superset');
15
+ const { loadPackageConfig } = require('./config');
16
+ const path = require('path');
15
17
 
16
18
  async function getPackageChangedFiles({
17
19
  fromCommit,
@@ -19,22 +21,17 @@ async function getPackageChangedFiles({
19
21
  packageCwd,
20
22
  options,
21
23
  }) {
22
- let isAncestor = await isCommitAncestorOf(fromCommit, toCommit, options);
23
-
24
- let olderCommit;
25
- let newerCommit;
26
- if (isAncestor) {
27
- olderCommit = fromCommit;
28
- newerCommit = toCommit;
29
- } else {
30
- olderCommit = toCommit;
31
- newerCommit = fromCommit;
32
- }
24
+ // Be careful you don't accidentally use `...` instead of `..`.
25
+ // `...` finds the merge-base and uses that instead of `fromCommit`.
26
+ // https://stackoverflow.com/a/60496462
27
+ let committedChanges = await git(['diff', '--name-only', `${fromCommit}..${toCommit}`, packageCwd], options);
33
28
 
34
- let committedChanges = await git(['diff', '--name-only', `${olderCommit}...${newerCommit}`, packageCwd], options);
35
29
  committedChanges = getLinesFromOutput(committedChanges);
30
+
36
31
  let dirtyChanges = await git(['status', '--porcelain', packageCwd, '-u'], options);
32
+
37
33
  dirtyChanges = getLinesFromOutput(dirtyChanges).map(line => line.substr(3));
34
+
38
35
  let changedFiles = Array.from(new Set(committedChanges).union(dirtyChanges));
39
36
 
40
37
  return changedFiles;
@@ -71,11 +68,21 @@ async function buildChangeGraph({
71
68
  let packagesWithChanges = {};
72
69
  let sinceBranchCommit;
73
70
 
71
+ let packagePaths = Object.values(workspaceMeta.packages).map(({ cwd }) => {
72
+ return path.relative(workspaceMeta.cwd, cwd);
73
+ });
74
+
74
75
  for (let _package of collectPackages(workspaceMeta)) {
75
76
  if (!_package.packageName || !_package.version) {
76
77
  continue;
77
78
  }
78
79
 
80
+ let nextConfig = loadPackageConfig(_package.cwd);
81
+
82
+ if (!nextConfig.shouldBumpVersion) {
83
+ continue;
84
+ }
85
+
79
86
  let _fromCommit;
80
87
  if (fromCommit) {
81
88
  _fromCommit = fromCommit;
@@ -129,8 +136,8 @@ async function buildChangeGraph({
129
136
  // remove package changes from the workspace root's changed files
130
137
  if (_package.cwd === workspaceMeta.cwd) {
131
138
  newFiles = newFiles.filter(file => {
132
- return !workspaceMeta.packagesGlobs.some(glob => {
133
- return minimatch(file, `${glob}/**`, { dot: true });
139
+ return !packagePaths.some((packagePath) => {
140
+ return isSubDir(packagePath, file);
134
141
  });
135
142
  });
136
143
  }
@@ -81,17 +81,13 @@ async function buildDepGraph({
81
81
 
82
82
  let { workspaces } = workspacePackageJson;
83
83
 
84
- let packagesGlobs;
85
-
86
84
  let _1dFilesArray;
87
85
  if (!workspaces) {
88
86
  _1dFilesArray = (await execa('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], { cwd: workspaceCwd })).stdout
89
87
  .split(/\r?\n/)
90
88
  .map(workspace => path.relative(workspaceCwd, workspace));
91
-
92
- packagesGlobs = [];
93
89
  } else {
94
- packagesGlobs = workspaces.packages || workspaces;
90
+ let packagesGlobs = workspaces.packages || workspaces;
95
91
 
96
92
  let _2dFilesArray = await Promise.all(packagesGlobs.map(packagesGlob => {
97
93
  return glob(packagesGlob, {
@@ -108,7 +104,6 @@ async function buildDepGraph({
108
104
 
109
105
  let workspaceMeta = {
110
106
  cwd: workspaceCwd,
111
- packagesGlobs,
112
107
  };
113
108
 
114
109
  await firstPass(workspaceMeta, workspacePackageJson, packageDirs);
@@ -10,6 +10,7 @@ const { trackNewVersion } = require('./version');
10
10
  const semver = require('semver');
11
11
  const dependencyTypes = require('./dependency-types');
12
12
  const { isCycle } = require('./build-dag');
13
+ const { loadPackageConfig } = require('./config');
13
14
 
14
15
  const defaultReleaseType = 'patch';
15
16
 
@@ -139,6 +140,12 @@ async function secondPass({
139
140
 
140
141
  visitedNodes.add(dag.node.packageName);
141
142
 
143
+ let nextConfig = loadPackageConfig(dag.node.cwd);
144
+
145
+ if (!nextConfig.shouldBumpVersion) {
146
+ return;
147
+ }
148
+
142
149
  let doesPackageHaveChanges = !!releaseTrees[dag.node.packageName];
143
150
  if (!doesPackageHaveChanges) {
144
151
  let isDevDep = dag.dependencyType === 'devDependencies';
package/src/config.js ADDED
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+
5
+ function loadPackageConfig(cwd) {
6
+ let nextConfig;
7
+
8
+ try {
9
+ nextConfig = require(path.join(cwd, 'monorepo-next.config.js'));
10
+ } catch (err) {
11
+ if (err.code !== 'MODULE_NOT_FOUND') {
12
+ throw err;
13
+ }
14
+
15
+ nextConfig = {};
16
+ }
17
+
18
+ return {
19
+ shouldBumpVersion: true,
20
+ ...nextConfig,
21
+ };
22
+ }
23
+
24
+ module.exports = {
25
+ loadPackageConfig,
26
+ };
package/src/path.js ADDED
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+
5
+ function isSubDir(dir, subDir) {
6
+ let relative = path.relative(dir, subDir);
7
+
8
+ return !relative.startsWith(`..${path.sep}`);
9
+ }
10
+
11
+ module.exports = {
12
+ isSubDir,
13
+ };