monorepo-next 8.4.0 → 8.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monorepo-next",
3
- "version": "8.4.0",
3
+ "version": "8.5.1",
4
4
  "description": "Detach monorepo packages from normal linking",
5
5
  "bin": {
6
6
  "next": "bin/next.js"
@@ -62,7 +62,6 @@
62
62
  "conventional-recommended-bump": "6.1.0",
63
63
  "debug": "^4.3.1",
64
64
  "execa": "^5.0.0",
65
- "glob": "^8.0.0",
66
65
  "inquirer": "^8.0.0",
67
66
  "minimatch": "^5.0.0",
68
67
  "npm-packlist": "^5.0.0",
@@ -4,7 +4,7 @@ const path = require('path');
4
4
  const semver = require('semver');
5
5
  const dependencyTypes = require('./dependency-types');
6
6
  const readJson = require('./json').read;
7
- const getWorkspacesPaths = require('./get-workspaces-paths');
7
+ const { getWorkspacesPaths } = require('./get-workspaces-paths');
8
8
 
9
9
  function copyDeps(left, right) {
10
10
  for (let dependencyType of dependencyTypes) {
@@ -1,10 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  const execa = require('execa');
4
- const { promisify } = require('util');
5
- const glob = promisify(require('glob'));
6
4
  const path = require('path');
7
5
  const readJson = require('./json').read;
6
+ const readJsonSync = require('./json').readSync;
8
7
 
9
8
  async function getWorkspacesPaths({
10
9
  workspaceCwd,
@@ -13,28 +12,51 @@ async function getWorkspacesPaths({
13
12
 
14
13
  let { workspaces } = workspacePackageJson;
15
14
 
16
- let _1dFilesArray;
17
-
18
15
  if (!workspaces) {
19
- _1dFilesArray = (await execa('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], { cwd: workspaceCwd })).stdout
16
+ workspaces = (await execa('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], { cwd: workspaceCwd })).stdout
20
17
  .split(/\r?\n/)
21
18
  .map(workspace => path.relative(workspaceCwd, workspace));
22
-
23
19
  } else {
24
- let packagesGlobs = workspaces.packages || workspaces;
25
-
26
- let _2dFilesArray = await Promise.all(packagesGlobs.map(packagesGlob => {
27
- return glob(packagesGlob, {
20
+ let jsonString = (
21
+ await execa('yarn', ['--silent', 'workspaces', 'info'], {
28
22
  cwd: workspaceCwd,
29
- });
30
- }));
23
+ })
24
+ ).stdout;
25
+
26
+ let workspacesJson = JSON.parse(jsonString);
31
27
 
32
- _1dFilesArray = Array.prototype.concat.apply([], _2dFilesArray);
28
+ workspaces = Object.values(workspacesJson).map(({ location }) => location);
33
29
  }
30
+
31
+ return workspaces;
32
+ }
33
+
34
+ function getWorkspacesPathsSync({
35
+ workspaceCwd,
36
+ }) {
37
+ let workspacePackageJson = readJsonSync(path.join(workspaceCwd, 'package.json'));
38
+
39
+ let { workspaces } = workspacePackageJson;
40
+
41
+ if (!workspaces) {
42
+ workspaces = (execa.sync('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], { cwd: workspaceCwd })).stdout
43
+ .split(/\r?\n/)
44
+ .map(workspace => path.relative(workspaceCwd, workspace));
45
+ } else {
46
+ let jsonString = (
47
+ execa.sync('yarn', ['--silent', 'workspaces', 'info'], {
48
+ cwd: workspaceCwd,
49
+ })
50
+ ).stdout;
51
+
52
+ let workspacesJson = JSON.parse(jsonString);
34
53
 
35
- workspaces = [...new Set(_1dFilesArray)];
36
-
54
+ workspaces = Object.values(workspacesJson).map(({ location }) => location);
55
+ }
37
56
  return workspaces;
38
57
  }
39
58
 
40
- module.exports = getWorkspacesPaths;
59
+ module.exports = {
60
+ getWorkspacesPaths,
61
+ getWorkspacesPathsSync,
62
+ };
package/src/json.js CHANGED
@@ -11,6 +11,10 @@ async function read(path) {
11
11
  return JSON.parse(await fs.readFile(path, 'utf8'));
12
12
  }
13
13
 
14
+ function readSync(path) {
15
+ return JSON.parse(fs.readFileSync(path, 'utf8'));
16
+ }
17
+
14
18
  async function write(path, json) {
15
19
  await fs.writeFile(path, stringify(json));
16
20
  }
@@ -18,5 +22,6 @@ async function write(path, json) {
18
22
  module.exports = {
19
23
  stringify,
20
24
  read,
25
+ readSync,
21
26
  write,
22
27
  };
package/src/releasable.js CHANGED
@@ -18,6 +18,32 @@ const filesContributingToReleasability = new Set([
18
18
 
19
19
  const packageJsonDevChangeRegex = /^\/(?:devDependencies|publishConfig)(?:\/|$)/m;
20
20
 
21
+ const relativePathRegex = /^\.{2}(?:\/|\\|$)/;
22
+
23
+ function removeSubDirs(files) {
24
+ let remainingFiles = new Set(files);
25
+
26
+ for (let file of remainingFiles) {
27
+ let isSubDir = remainingFiles.some(nextFile => {
28
+ if (file === nextFile) {
29
+ return false;
30
+ }
31
+
32
+ let relative = path.relative(file, nextFile);
33
+
34
+ let isSubDir = !relativePathRegex.test(relative);
35
+
36
+ return isSubDir;
37
+ });
38
+
39
+ if (isSubDir) {
40
+ remainingFiles.delete(file);
41
+ }
42
+ }
43
+
44
+ return remainingFiles;
45
+ }
46
+
21
47
  async function prepareTmpPackage({
22
48
  cwd,
23
49
  tmpDir,
@@ -38,11 +64,11 @@ async function prepareTmpPackage({
38
64
  }
39
65
  }
40
66
 
41
- for (let file of changedFiles) {
42
- if (filesContributingToReleasability.has(file)) {
43
- continue;
44
- }
67
+ let remainingFiles = changedFiles.diff(filesContributingToReleasability);
68
+
69
+ remainingFiles = removeSubDirs(remainingFiles);
45
70
 
71
+ for (let file of remainingFiles) {
46
72
  let filePath = path.join(tmpDir, file);
47
73
 
48
74
  await fs.mkdir(path.dirname(filePath), { recursive: true });
@@ -161,4 +187,6 @@ async function getChangedReleasableFiles({
161
187
  module.exports = {
162
188
  getChangedReleasableFiles,
163
189
  packageJsonDevChangeRegex,
190
+ removeSubDirs,
191
+ relativePathRegex,
164
192
  };