monorepo-next 8.3.1 → 8.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monorepo-next",
3
- "version": "8.3.1",
3
+ "version": "8.5.0",
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",
@@ -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,28 +77,9 @@ 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 _1dFilesArray;
85
- if (!workspaces) {
86
- _1dFilesArray = (await execa('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], { cwd: workspaceCwd })).stdout
87
- .split(/\r?\n/)
88
- .map(workspace => path.relative(workspaceCwd, workspace));
89
- } else {
90
- let packagesGlobs = workspaces.packages || workspaces;
91
-
92
- let _2dFilesArray = await Promise.all(packagesGlobs.map(packagesGlob => {
93
- return glob(packagesGlob, {
94
- cwd: workspaceCwd,
95
- });
96
- }));
97
-
98
- _1dFilesArray = Array.prototype.concat.apply([], _2dFilesArray);
99
- }
100
-
101
- let uniqueFiles = [...new Set(_1dFilesArray)];
102
-
103
- let packageDirs = uniqueFiles.map(file => path.join(workspaceCwd, file));
82
+ let packageDirs = workspaces.map(dir => path.join(workspaceCwd, dir));
104
83
 
105
84
  let workspaceMeta = {
106
85
  cwd: workspaceCwd,
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ const execa = require('execa');
4
+ const path = require('path');
5
+ const readJson = require('./json').read;
6
+ const readJsonSync = require('./json').readSync;
7
+
8
+ async function getWorkspacesPaths({
9
+ workspaceCwd,
10
+ }) {
11
+ let workspacePackageJson = await readJson(path.join(workspaceCwd, 'package.json'));
12
+
13
+ let { workspaces } = workspacePackageJson;
14
+
15
+ if (!workspaces) {
16
+ workspaces = (await execa('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], { cwd: workspaceCwd })).stdout
17
+ .split(/\r?\n/)
18
+ .map(workspace => path.relative(workspaceCwd, workspace));
19
+ } else {
20
+ let jsonString = (
21
+ await execa('yarn', ['--silent', 'workspaces', 'info'], {
22
+ cwd: workspaceCwd,
23
+ })
24
+ ).stdout;
25
+
26
+ let workspacesJson = JSON.parse(jsonString);
27
+
28
+ workspaces = Object.values(workspacesJson).map(({ location }) => location);
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);
53
+
54
+ workspaces = Object.values(workspacesJson).map(({ location }) => location);
55
+ }
56
+ return workspaces;
57
+ }
58
+
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
  };