monorepo-next 8.2.0 → 8.4.0

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.4.0",
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
  }
@@ -1,12 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const path = require('path');
4
- const { promisify } = require('util');
5
- const glob = promisify(require('glob'));
6
4
  const semver = require('semver');
7
5
  const dependencyTypes = require('./dependency-types');
8
- const execa = require('execa');
9
6
  const readJson = require('./json').read;
7
+ const getWorkspacesPaths = require('./get-workspaces-paths');
10
8
 
11
9
  function copyDeps(left, right) {
12
10
  for (let dependencyType of dependencyTypes) {
@@ -79,36 +77,12 @@ async function buildDepGraph({
79
77
  }) {
80
78
  let workspacePackageJson = await readJson(path.join(workspaceCwd, 'package.json'));
81
79
 
82
- let { workspaces } = workspacePackageJson;
80
+ let workspaces = await getWorkspacesPaths({ workspaceCwd });
83
81
 
84
- let packagesGlobs;
85
-
86
- let _1dFilesArray;
87
- if (!workspaces) {
88
- _1dFilesArray = (await execa('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], { cwd: workspaceCwd })).stdout
89
- .split(/\r?\n/)
90
- .map(workspace => path.relative(workspaceCwd, workspace));
91
-
92
- packagesGlobs = [];
93
- } else {
94
- packagesGlobs = workspaces.packages || workspaces;
95
-
96
- let _2dFilesArray = await Promise.all(packagesGlobs.map(packagesGlob => {
97
- return glob(packagesGlob, {
98
- cwd: workspaceCwd,
99
- });
100
- }));
101
-
102
- _1dFilesArray = Array.prototype.concat.apply([], _2dFilesArray);
103
- }
104
-
105
- let uniqueFiles = [...new Set(_1dFilesArray)];
106
-
107
- let packageDirs = uniqueFiles.map(file => path.join(workspaceCwd, file));
82
+ let packageDirs = workspaces.map(dir => path.join(workspaceCwd, dir));
108
83
 
109
84
  let workspaceMeta = {
110
85
  cwd: workspaceCwd,
111
- packagesGlobs,
112
86
  };
113
87
 
114
88
  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
+ };
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ const execa = require('execa');
4
+ const { promisify } = require('util');
5
+ const glob = promisify(require('glob'));
6
+ const path = require('path');
7
+ const readJson = require('./json').read;
8
+
9
+ async function getWorkspacesPaths({
10
+ workspaceCwd,
11
+ }) {
12
+ let workspacePackageJson = await readJson(path.join(workspaceCwd, 'package.json'));
13
+
14
+ let { workspaces } = workspacePackageJson;
15
+
16
+ let _1dFilesArray;
17
+
18
+ if (!workspaces) {
19
+ _1dFilesArray = (await execa('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], { cwd: workspaceCwd })).stdout
20
+ .split(/\r?\n/)
21
+ .map(workspace => path.relative(workspaceCwd, workspace));
22
+
23
+ } else {
24
+ let packagesGlobs = workspaces.packages || workspaces;
25
+
26
+ let _2dFilesArray = await Promise.all(packagesGlobs.map(packagesGlob => {
27
+ return glob(packagesGlob, {
28
+ cwd: workspaceCwd,
29
+ });
30
+ }));
31
+
32
+ _1dFilesArray = Array.prototype.concat.apply([], _2dFilesArray);
33
+ }
34
+
35
+ workspaces = [...new Set(_1dFilesArray)];
36
+
37
+ return workspaces;
38
+ }
39
+
40
+ module.exports = getWorkspacesPaths;
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
+ };