monorepo-next 8.5.1 → 8.6.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 +6 -3
- package/src/build-change-graph.js +7 -12
- package/src/build-dep-graph.js +1 -1
- package/src/get-workspaces-paths.js +147 -31
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "monorepo-next",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.6.0",
|
4
4
|
"description": "Detach monorepo packages from normal linking",
|
5
5
|
"bin": {
|
6
6
|
"next": "bin/next.js"
|
@@ -62,7 +62,9 @@
|
|
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",
|
65
66
|
"inquirer": "^8.0.0",
|
67
|
+
"js-yaml": "^4.0.0",
|
66
68
|
"minimatch": "^5.0.0",
|
67
69
|
"npm-packlist": "^5.0.0",
|
68
70
|
"rfc6902": "^5.0.0",
|
@@ -76,8 +78,9 @@
|
|
76
78
|
"@crowdstrike/commitlint": "^5.0.0",
|
77
79
|
"chai": "^4.2.0",
|
78
80
|
"chai-as-promised": "^7.1.1",
|
81
|
+
"common-tags": "^1.8.2",
|
79
82
|
"eslint": "^8.0.0",
|
80
|
-
"eslint-config-crowdstrike": "^
|
83
|
+
"eslint-config-crowdstrike": "^7.0.0",
|
81
84
|
"eslint-config-crowdstrike-node": "^3.0.0",
|
82
85
|
"eslint-plugin-json-files": "^1.0.0",
|
83
86
|
"eslint-plugin-mocha": "^10.0.0",
|
@@ -86,7 +89,7 @@
|
|
86
89
|
"git-fixtures": "^4.0.0",
|
87
90
|
"mocha": "^10.0.0",
|
88
91
|
"mocha-helpers": "^6.2.1",
|
89
|
-
"remark-cli": "^
|
92
|
+
"remark-cli": "^11.0.0",
|
90
93
|
"remark-preset-lint-crowdstrike": "^2.0.0",
|
91
94
|
"renovate-config-standard": "^2.0.0",
|
92
95
|
"sinon": "^14.0.0",
|
@@ -21,22 +21,17 @@ async function getPackageChangedFiles({
|
|
21
21
|
packageCwd,
|
22
22
|
options,
|
23
23
|
}) {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
let
|
28
|
-
if (isAncestor) {
|
29
|
-
olderCommit = fromCommit;
|
30
|
-
newerCommit = toCommit;
|
31
|
-
} else {
|
32
|
-
olderCommit = toCommit;
|
33
|
-
newerCommit = fromCommit;
|
34
|
-
}
|
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);
|
35
28
|
|
36
|
-
let committedChanges = await git(['diff', '--name-only', `${olderCommit}...${newerCommit}`, packageCwd], options);
|
37
29
|
committedChanges = getLinesFromOutput(committedChanges);
|
30
|
+
|
38
31
|
let dirtyChanges = await git(['status', '--porcelain', packageCwd, '-u'], options);
|
32
|
+
|
39
33
|
dirtyChanges = getLinesFromOutput(dirtyChanges).map(line => line.substr(3));
|
34
|
+
|
40
35
|
let changedFiles = Array.from(new Set(committedChanges).union(dirtyChanges));
|
41
36
|
|
42
37
|
return changedFiles;
|
package/src/build-dep-graph.js
CHANGED
@@ -77,7 +77,7 @@ async function buildDepGraph({
|
|
77
77
|
}) {
|
78
78
|
let workspacePackageJson = await readJson(path.join(workspaceCwd, 'package.json'));
|
79
79
|
|
80
|
-
let workspaces = await getWorkspacesPaths({ workspaceCwd });
|
80
|
+
let workspaces = await getWorkspacesPaths({ cwd: workspaceCwd });
|
81
81
|
|
82
82
|
let packageDirs = workspaces.map(dir => path.join(workspaceCwd, dir));
|
83
83
|
|
@@ -1,58 +1,174 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
const execa = require('execa');
|
4
|
+
const fs = { ...require('fs'), ...require('fs').promises };
|
5
|
+
const { promisify } = require('util');
|
6
|
+
const glob = promisify(require('glob'));
|
7
|
+
const jsYaml = require('js-yaml');
|
4
8
|
const path = require('path');
|
5
9
|
const readJson = require('./json').read;
|
6
10
|
const readJsonSync = require('./json').readSync;
|
7
11
|
|
12
|
+
function processPnpm({ stdout }, cwd) {
|
13
|
+
let workspaces = stdout.split(/\r?\n/).reduce((workspaces, workspace) => {
|
14
|
+
if (!workspace.startsWith('No projects matched the filters')) {
|
15
|
+
if (process.platform === 'darwin' && workspace.startsWith(`${path.sep}private${path.sep}`)) {
|
16
|
+
workspace = `${path.sep}${path.relative(`${path.sep}private`, workspace)}`;
|
17
|
+
}
|
18
|
+
|
19
|
+
let relative = path.relative(cwd, workspace);
|
20
|
+
|
21
|
+
workspaces.push(relative);
|
22
|
+
}
|
23
|
+
|
24
|
+
return workspaces;
|
25
|
+
}, []);
|
26
|
+
|
27
|
+
return workspaces;
|
28
|
+
}
|
29
|
+
|
30
|
+
function processYarn({ stdout }) {
|
31
|
+
let json = JSON.parse(stdout);
|
32
|
+
|
33
|
+
let workspaces = Object.values(json).map(({ location }) => location);
|
34
|
+
|
35
|
+
return workspaces;
|
36
|
+
}
|
37
|
+
|
38
|
+
function processPnpmYaml(buffer) {
|
39
|
+
// read packagesGlobs excluding packagesGLobs starting with !
|
40
|
+
// https://pnpm.io/pnpm-workspace_yaml
|
41
|
+
let packagesGlobs = jsYaml.load(buffer).packages.filter((packagesGlob) => !packagesGlob.startsWith('!'));
|
42
|
+
|
43
|
+
return packagesGlobs;
|
44
|
+
}
|
45
|
+
|
46
|
+
function processGlobs({ cwd, _2dFilesArray, isPnpm }) {
|
47
|
+
let _1dFilesArray = Array.prototype.concat.apply([], _2dFilesArray);
|
48
|
+
|
49
|
+
let packagePaths = [...new Set(_1dFilesArray)];
|
50
|
+
|
51
|
+
let neededYarnKeys = ['name', 'version'];
|
52
|
+
|
53
|
+
let workspaces = packagePaths.filter(packagePath => {
|
54
|
+
let packageJson;
|
55
|
+
|
56
|
+
try {
|
57
|
+
packageJson = readJsonSync(path.join(cwd, packagePath, 'package.json'));
|
58
|
+
} catch (err) {
|
59
|
+
if (err.code === 'ENOENT') {
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
|
63
|
+
throw err;
|
64
|
+
}
|
65
|
+
|
66
|
+
if (isPnpm) {
|
67
|
+
return true;
|
68
|
+
}
|
69
|
+
|
70
|
+
// for yarn, not a valid package if name and version are missing in package.json
|
71
|
+
if (neededYarnKeys.every(key => key in packageJson)) {
|
72
|
+
return true;
|
73
|
+
}
|
74
|
+
});
|
75
|
+
|
76
|
+
return workspaces;
|
77
|
+
}
|
78
|
+
|
8
79
|
async function getWorkspacesPaths({
|
9
|
-
|
80
|
+
cwd,
|
81
|
+
shouldSpawn = false,
|
10
82
|
}) {
|
11
|
-
let workspacePackageJson = await readJson(path.join(
|
83
|
+
let workspacePackageJson = await readJson(path.join(cwd, 'package.json'));
|
12
84
|
|
13
85
|
let { workspaces } = workspacePackageJson;
|
14
86
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
87
|
+
let isPnpm = !workspaces;
|
88
|
+
|
89
|
+
if (shouldSpawn) {
|
90
|
+
if (isPnpm) {
|
91
|
+
workspaces = processPnpm(
|
92
|
+
await execa('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], {
|
93
|
+
cwd,
|
94
|
+
}),
|
95
|
+
cwd,
|
96
|
+
);
|
97
|
+
} else {
|
98
|
+
workspaces = processYarn(
|
99
|
+
await execa('yarn', ['--silent', 'workspaces', 'info'], {
|
100
|
+
cwd,
|
101
|
+
}),
|
102
|
+
);
|
103
|
+
}
|
19
104
|
} else {
|
20
|
-
let
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
105
|
+
let packagesGlobs;
|
106
|
+
|
107
|
+
if (isPnpm) {
|
108
|
+
packagesGlobs = processPnpmYaml(
|
109
|
+
await fs.readFile(path.join(cwd, 'pnpm-workspace.yaml')),
|
110
|
+
);
|
111
|
+
} else {
|
112
|
+
packagesGlobs = workspaces.packages || workspaces;
|
113
|
+
}
|
114
|
+
|
115
|
+
let _2dFilesArray = await Promise.all(packagesGlobs.map(packagesGlob => {
|
116
|
+
return glob(packagesGlob, {
|
117
|
+
cwd,
|
118
|
+
});
|
119
|
+
}));
|
120
|
+
|
121
|
+
workspaces = processGlobs({ cwd, _2dFilesArray, isPnpm });
|
29
122
|
}
|
30
123
|
|
31
124
|
return workspaces;
|
32
125
|
}
|
33
126
|
|
34
127
|
function getWorkspacesPathsSync({
|
35
|
-
|
128
|
+
cwd,
|
129
|
+
shouldSpawn = false,
|
36
130
|
}) {
|
37
|
-
let workspacePackageJson = readJsonSync(path.join(
|
131
|
+
let workspacePackageJson = readJsonSync(path.join(cwd, 'package.json'));
|
38
132
|
|
39
133
|
let { workspaces } = workspacePackageJson;
|
40
134
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
135
|
+
let isPnpm = !workspaces;
|
136
|
+
|
137
|
+
if (shouldSpawn) {
|
138
|
+
if (isPnpm) {
|
139
|
+
workspaces = processPnpm(
|
140
|
+
execa.sync('pnpm', ['recursive', 'exec', '--', 'node', '-e', 'console.log(process.cwd())'], {
|
141
|
+
cwd,
|
142
|
+
}),
|
143
|
+
cwd,
|
144
|
+
);
|
145
|
+
} else {
|
146
|
+
workspaces = processYarn(
|
147
|
+
execa.sync('yarn', ['--silent', 'workspaces', 'info'], {
|
148
|
+
cwd,
|
149
|
+
}),
|
150
|
+
);
|
151
|
+
}
|
45
152
|
} else {
|
46
|
-
let
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
153
|
+
let packagesGlobs;
|
154
|
+
|
155
|
+
if (isPnpm) {
|
156
|
+
packagesGlobs = processPnpmYaml(
|
157
|
+
fs.readFileSync(path.join(cwd, 'pnpm-workspace.yaml')),
|
158
|
+
);
|
159
|
+
} else {
|
160
|
+
packagesGlobs = workspaces.packages || workspaces;
|
161
|
+
}
|
162
|
+
|
163
|
+
let _2dFilesArray = packagesGlobs.map(packagesGlob => {
|
164
|
+
return glob.sync(packagesGlob, {
|
165
|
+
cwd,
|
166
|
+
});
|
167
|
+
});
|
168
|
+
|
169
|
+
workspaces = processGlobs({ cwd, _2dFilesArray, isPnpm });
|
170
|
+
}
|
171
|
+
|
56
172
|
return workspaces;
|
57
173
|
}
|
58
174
|
|