Skip to content

Commit

Permalink
fix: bump cosmiconfig to v8 (#3701)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed May 31, 2023
1 parent f67288b commit 898923d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 55 deletions.
2 changes: 1 addition & 1 deletion e2e/info/src/info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expect.addSnapshotSerializer({
return normalizeEnvironment(
str
.replaceAll(/OS: .*\n/g, "OS: {OS}\n")
.replaceAll(/CPU: \(\d{1,2}\) x(64|32) .* CPU .*\n/g, "CPU: {CPU}\n")
.replaceAll(/CPU: \(\d{1,2}\) x(64|32) .* (CPU|Processor).*\n/g, "CPU: {CPU}\n")
.replaceAll(/CPU: \(\d{1,2}\) arm64 .*\n/g, "CPU: {CPU}\n")
.replaceAll(/Node: (\d{1,2})\.(\d{1,2})\.(\d{1,2}) - .*\n/g, "Node: XX.XX.XX - {Node}\n")
.replaceAll(/Yarn: (\d{1,2})\.(\d{1,2})\.(\d{1,2}) - .*\n/g, "Yarn: XX.XX.XX - {Yarn}\n")
Expand Down
84 changes: 42 additions & 42 deletions libs/core/src/lib/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,52 +227,52 @@ export class Project {
}

#resolveLernaConfig(cwd?: string) {
const explorer = cosmiconfigSync("lerna", {
loaders: {
...defaultLoaders,
".json": (filepath, content) => {
if (!filepath.endsWith("lerna.json")) {
return defaultLoaders[".json"](filepath, content);
}
/**
* This prevents lerna from blowing up on trailing commas and comments in lerna configs,
* however it should be noted that we will not be able to respect those things whenever
* we perform an automated config migration, e.g. via `lerna repair` and they will be lost.
* (Although that will be easy enough for the user to see and updated in their `git diff`)
*/
try {
return parseJson(content);
} catch (err: unknown) {
if (err instanceof Error) {
err.name = "JSONError";
err.message = `Error in: ${filepath}\n${err.message}`;
try {
const explorer = cosmiconfigSync("lerna", {
loaders: {
...defaultLoaders,
".json": (filepath, content) => {
if (!filepath.endsWith("lerna.json")) {
return defaultLoaders[".json"](filepath, content);
}
/**
* This prevents lerna from blowing up on trailing commas and comments in lerna configs,
* however it should be noted that we will not be able to respect those things whenever
* we perform an automated config migration, e.g. via `lerna repair` and they will be lost.
* (Although that will be easy enough for the user to see and updated in their `git diff`)
*/
try {
return parseJson(content);
} catch (err: unknown) {
if (err instanceof Error) {
err.name = "JSONError";
err.message = `Error in: ${filepath}\n${err.message}`;
}
throw err;
}
throw err;
},
},
searchPlaces: ["lerna.json", "package.json"],
transform(obj) {
// cosmiconfig returns null when nothing is found
if (!obj) {
const configNotFoundResult: CosmiconfigNotFoundResult = {
// No need to distinguish between missing and empty,
// saves a lot of noisy guards elsewhere
config: {},
configNotFound: true,
// path.resolve(".", ...) starts from process.cwd()
filepath: path.resolve(cwd || ".", "lerna.json"),
};
return configNotFoundResult;
}

obj.config = applyExtends(obj.config, path.dirname(obj.filepath));

return obj;
},
},
searchPlaces: ["lerna.json", "package.json"],
transform(obj) {
// cosmiconfig returns null when nothing is found
if (!obj) {
const configNotFoundResult: CosmiconfigNotFoundResult = {
// No need to distinguish between missing and empty,
// saves a lot of noisy guards elsewhere
config: {},
configNotFound: true,
// path.resolve(".", ...) starts from process.cwd()
filepath: path.resolve(cwd || ".", "lerna.json"),
};
return configNotFoundResult;
}

obj.config = applyExtends(obj.config, path.dirname(obj.filepath));

return obj;
},
});
});

try {
/**
* We explicitly handle the missing config case in the transform function above,
* so we can remove null from the types and replace it with the custom ConfigNotFoundResult.
Expand Down
23 changes: 14 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"conventional-changelog-angular": "^5.0.12",
"conventional-changelog-core": "^4.2.4",
"conventional-recommended-bump": "^6.1.0",
"cosmiconfig": "^7.0.0",
"cosmiconfig": "8.1.3",
"dedent": "^0.7.0",
"envinfo": "^7.7.4",
"execa": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy-package-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"config-chain": "1.1.12",
"conventional-changelog-core": "4.2.4",
"conventional-recommended-bump": "6.1.0",
"cosmiconfig": "7.0.0",
"cosmiconfig": "8.1.3",
"dedent": "0.7.0",
"execa": "5.0.0",
"file-url": "3.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/lerna/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"conventional-changelog-angular": "5.0.12",
"conventional-changelog-core": "4.2.4",
"conventional-recommended-bump": "6.1.0",
"cosmiconfig": "7.0.0",
"cosmiconfig": "8.1.3",
"dedent": "0.7.0",
"envinfo": "^7.7.4",
"execa": "5.0.0",
Expand Down

0 comments on commit 898923d

Please sign in to comment.