monorepo-next 8.1.1 → 8.3.1

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.1.1",
3
+ "version": "8.3.1",
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,
@@ -71,11 +73,21 @@ async function buildChangeGraph({
71
73
  let packagesWithChanges = {};
72
74
  let sinceBranchCommit;
73
75
 
76
+ let packagePaths = Object.values(workspaceMeta.packages).map(({ cwd }) => {
77
+ return path.relative(workspaceMeta.cwd, cwd);
78
+ });
79
+
74
80
  for (let _package of collectPackages(workspaceMeta)) {
75
81
  if (!_package.packageName || !_package.version) {
76
82
  continue;
77
83
  }
78
84
 
85
+ let nextConfig = loadPackageConfig(_package.cwd);
86
+
87
+ if (!nextConfig.shouldBumpVersion) {
88
+ continue;
89
+ }
90
+
79
91
  let _fromCommit;
80
92
  if (fromCommit) {
81
93
  _fromCommit = fromCommit;
@@ -129,8 +141,8 @@ async function buildChangeGraph({
129
141
  // remove package changes from the workspace root's changed files
130
142
  if (_package.cwd === workspaceMeta.cwd) {
131
143
  newFiles = newFiles.filter(file => {
132
- return !workspaceMeta.packagesGlobs.some(glob => {
133
- return minimatch(file, `${glob}/**`, { dot: true });
144
+ return !packagePaths.some((packagePath) => {
145
+ return isSubDir(packagePath, file);
134
146
  });
135
147
  });
136
148
  }
@@ -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
 
@@ -122,6 +123,8 @@ async function secondPass({
122
123
  shouldInheritGreaterReleaseType,
123
124
  shouldExcludeDevChanges,
124
125
  }) {
126
+ let visitedNodes = new Set();
127
+
125
128
  for (let { dag, changedReleasableFiles } of packagesWithChanges) {
126
129
  if (!changedReleasableFiles.length) {
127
130
  continue;
@@ -131,6 +134,18 @@ async function secondPass({
131
134
  dag,
132
135
  parent,
133
136
  }) {
137
+ if (visitedNodes.has(dag.node.packageName)) {
138
+ return;
139
+ }
140
+
141
+ visitedNodes.add(dag.node.packageName);
142
+
143
+ let nextConfig = loadPackageConfig(dag.node.cwd);
144
+
145
+ if (!nextConfig.shouldBumpVersion) {
146
+ return;
147
+ }
148
+
134
149
  let doesPackageHaveChanges = !!releaseTrees[dag.node.packageName];
135
150
  if (!doesPackageHaveChanges) {
136
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
+ };