Skip to content

Commit

Permalink
Update dev-related tooling (TypeScript, Prettier, Babel) (#152)
Browse files Browse the repository at this point in the history
* Update dev-related tooling (TypeScript, Prettier, Babel)

* Fixed TS errors and snapshots

* Reformat files
  • Loading branch information
Andarist authored Dec 20, 2022
1 parent c2a367b commit bf2013e
Show file tree
Hide file tree
Showing 38 changed files with 1,333 additions and 366 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"test-gatsby"
],
"dependencies": {
"@babel/core": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/preset-typescript": "^7.3.3",
"@babel/core": "^7.20.5",
"@babel/preset-env": "^7.20.2",
"@babel/preset-typescript": "^7.18.6",
"@changesets/changelog-github": "^0.4.1",
"@changesets/cli": "^2.5.0",
"@types/fs-extra": "^8.0.1",
Expand All @@ -21,7 +21,8 @@
"jest": "^26.1.0",
"jest-watch-typeahead": "^0.6.0",
"preconstruct": "^0.0.89",
"typescript": "^3.5.3"
"prettier": "^2.8.1",
"typescript": "^4.9.4"
},
"jest": {
"watchPlugins": [
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"manypkg": "./bin.js"
},
"dependencies": {
"@babel/runtime": "^7.5.5",
"@babel/runtime": "^7.20.6",
"@manypkg/get-packages": "^1.1.3",
"chalk": "^2.4.2",
"detect-indent": "^6.0.0",
Expand Down
36 changes: 12 additions & 24 deletions packages/cli/src/__snapshots__/run.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Run command should execute "@manypkg/basic-fixture-pkg-two start" and exit with 0: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
warning package.json: No license field
"warning package.json: No license field
warning ../../package.json: No license field
"
`;
Expand All @@ -14,8 +13,7 @@ hello start
`;

exports[`Run command should execute "package start" and exit with 1: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
☔️ error an identifier must only match a single package but \\"package\\" matches the following packages:
"☔️ error an identifier must only match a single package but \\"package\\" matches the following packages:
☔️ error @manypkg/basic-fixture-pkg-one
☔️ error @manypkg/basic-fixture-pkg-two
☔️ error @manypkg/basic-fixture-pkg-two-one
Expand All @@ -25,8 +23,7 @@ exports[`Run command should execute "package start" and exit with 1: stderr 1`]
exports[`Run command should execute "package start" and exit with 1: stdout 1`] = `""`;

exports[`Run command should execute "package-one start" and exit with 0: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
warning package.json: No license field
"warning package.json: No license field
warning ../../package.json: No license field
"
`;
Expand All @@ -38,8 +35,7 @@ hello start
`;

exports[`Run command should execute "package-one test" and exit with 0: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
warning package.json: No license field
"warning package.json: No license field
warning ../../package.json: No license field
"
`;
Expand All @@ -51,16 +47,14 @@ testing
`;

exports[`Run command should execute "package-three start" and exit with 1: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
☔️ error No matching packages found
"☔️ error No matching packages found
"
`;

exports[`Run command should execute "package-three start" and exit with 1: stdout 1`] = `""`;

exports[`Run command should execute "package-two start" and exit with 1: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
☔️ error an identifier must only match a single package but \\"package-two\\" matches the following packages:
"☔️ error an identifier must only match a single package but \\"package-two\\" matches the following packages:
☔️ error @manypkg/basic-fixture-pkg-two
☔️ error @manypkg/basic-fixture-pkg-two-one
"
Expand All @@ -69,8 +63,7 @@ exports[`Run command should execute "package-two start" and exit with 1: stderr
exports[`Run command should execute "package-two start" and exit with 1: stdout 1`] = `""`;

exports[`Run command should execute "package-two-one something" and exit with 1: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
warning package.json: No license field
"warning package.json: No license field
warning ../../package.json: No license field
error Command \\"something\\" not found.
"
Expand All @@ -82,8 +75,7 @@ exports[`Run command should execute "package-two-one something" and exit with 1:
`;

exports[`Run command should execute "package-two-one start" and exit with 0: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
warning package.json: No license field
"warning package.json: No license field
warning ../../package.json: No license field
"
`;
Expand All @@ -95,8 +87,7 @@ hello start
`;

exports[`Run command should execute "packages/package-two start" and exit with 0: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
warning package.json: No license field
"warning package.json: No license field
warning ../../package.json: No license field
"
`;
Expand All @@ -108,8 +99,7 @@ hello start
`;

exports[`Run command should execute "pkg-one start" and exit with 0: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
warning package.json: No license field
"warning package.json: No license field
warning ../../package.json: No license field
"
`;
Expand All @@ -121,8 +111,7 @@ hello start
`;

exports[`Run command should execute "pkg-two start" and exit with 1: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
☔️ error an identifier must only match a single package but \\"pkg-two\\" matches the following packages:
"☔️ error an identifier must only match a single package but \\"pkg-two\\" matches the following packages:
☔️ error @manypkg/basic-fixture-pkg-two
☔️ error @manypkg/basic-fixture-pkg-two-one
"
Expand All @@ -131,8 +120,7 @@ exports[`Run command should execute "pkg-two start" and exit with 1: stderr 1`]
exports[`Run command should execute "pkg-two start" and exit with 1: stdout 1`] = `""`;

exports[`Run command should execute "pkg-two-one start" and exit with 0: stderr 1`] = `
"Browserslist: caniuse-lite is outdated. Please run next command \`yarn upgrade\`
warning package.json: No license field
"warning package.json: No license field
warning ../../package.json: No license field
"
`;
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/checks/EXTERNAL_MISMATCH.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
makeCheck,
getMostCommonRangeMap,
NORMAL_DEPENDENCY_TYPES
NORMAL_DEPENDENCY_TYPES,
} from "./utils";
import { Package } from "@manypkg/get-packages";
import { validRange } from "semver";
Expand Down Expand Up @@ -35,15 +35,15 @@ export default makeCheck<ErrorType>({
workspace,
dependencyName: depName,
dependencyRange: range,
mostCommonDependencyRange: mostCommonRange
mostCommonDependencyRange: mostCommonRange,
});
}
}
}
}
return errors;
},
fix: error => {
fix: (error) => {
for (let depType of NORMAL_DEPENDENCY_TYPES) {
let deps = error.workspace.packageJson[depType];
if (deps && deps[error.dependencyName]) {
Expand All @@ -52,7 +52,7 @@ export default makeCheck<ErrorType>({
}
return { requiresInstall: true };
},
print: error =>
print: (error) =>
`${error.workspace.packageJson.name} has a dependency on ${error.dependencyName}@${error.dependencyRange} but the most common range in the repo is ${error.mostCommonDependencyRange}, the range should be set to ${error.mostCommonDependencyRange}`,
type: "all"
type: "all",
});
12 changes: 6 additions & 6 deletions packages/cli/src/checks/INCORRECT_REPOSITORY_FIELD.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export default makeCheck<ErrorType>({
type: "INCORRECT_REPOSITORY_FIELD",
workspace,
currentRepositoryField: rootRepositoryField,
correctRepositoryField
}
correctRepositoryField,
},
];
}
} else {
Expand All @@ -65,8 +65,8 @@ export default makeCheck<ErrorType>({
type: "INCORRECT_REPOSITORY_FIELD",
workspace,
currentRepositoryField,
correctRepositoryField
}
correctRepositoryField,
},
];
}
}
Expand All @@ -78,7 +78,7 @@ export default makeCheck<ErrorType>({
(error.workspace.packageJson as any).repository =
error.correctRepositoryField;
},
print: error => {
print: (error) => {
if (error.currentRepositoryField === undefined) {
return `${
error.workspace.packageJson.name
Expand All @@ -91,5 +91,5 @@ export default makeCheck<ErrorType>({
} has a repository field of ${JSON.stringify(
error.currentRepositoryField
)} when it should be ${JSON.stringify(error.correctRepositoryField)}`;
}
},
});
10 changes: 5 additions & 5 deletions packages/cli/src/checks/INTERNAL_MISMATCH.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
makeCheck,
NORMAL_DEPENDENCY_TYPES,
versionRangeToRangeType
versionRangeToRangeType,
} from "./utils";
import semver from "semver";
import { Package } from "@manypkg/get-packages";
Expand Down Expand Up @@ -30,7 +30,7 @@ export default makeCheck<ErrorType>({
type: "INTERNAL_MISMATCH",
workspace,
dependencyWorkspace,
dependencyRange: range
dependencyRange: range,
});
}
}
Expand All @@ -39,7 +39,7 @@ export default makeCheck<ErrorType>({

return errors;
},
fix: error => {
fix: (error) => {
for (let depType of NORMAL_DEPENDENCY_TYPES) {
let deps = error.workspace.packageJson[depType];
if (deps && deps[error.dependencyWorkspace.packageJson.name]) {
Expand All @@ -51,7 +51,7 @@ export default makeCheck<ErrorType>({
}
return { requiresInstall: true };
},
print: error =>
print: (error) =>
`${error.workspace.packageJson.name} has a dependency on ${error.dependencyWorkspace.packageJson.name}@${error.dependencyRange} but the version of ${error.dependencyWorkspace.packageJson.name} in the repo is ${error.dependencyWorkspace.packageJson.version} which is not within range of the depended on version, please update the dependency version`,
type: "all"
type: "all",
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default makeCheck<ErrorType>({
peerVersion: peerDeps[depName],
dependencyName: depName,
devVersion: null,
idealDevVersion
idealDevVersion,
});
} else if (
semver.validRange(devDeps[depName]) &&
Expand All @@ -59,25 +59,25 @@ export default makeCheck<ErrorType>({
dependencyName: depName,
peerVersion: peerDeps[depName],
devVersion: devDeps[depName],
idealDevVersion
idealDevVersion,
});
}
}
}
return errors;
},
fix: error => {
fix: (error) => {
if (!error.workspace.packageJson.devDependencies) {
error.workspace.packageJson.devDependencies = {};
}
error.workspace.packageJson.devDependencies[error.dependencyName] =
error.idealDevVersion;
return { requiresInstall: true };
},
print: error => {
print: (error) => {
if (error.devVersion === null) {
return `${error.workspace.packageJson.name} has a peerDependency on ${error.dependencyName} but it is not also specified in devDependencies, please add it there.`;
}
return `${error.workspace.packageJson.name} has a peerDependency on ${error.dependencyName} but the range specified in devDependency is not greater than or equal to the range specified in peerDependencies`;
}
},
});
16 changes: 8 additions & 8 deletions packages/cli/src/checks/INVALID_PACKAGE_NAME.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ type ErrorType = {

export default makeCheck<ErrorType>({
type: "all",
validate: workspace => {
validate: (workspace) => {
if (!workspace.packageJson.name) {
return [
{
type: "INVALID_PACKAGE_NAME",
workspace,
errors: ["name cannot be undefined"]
}
errors: ["name cannot be undefined"],
},
];
}
let validationErrors = validateNpmPackageName(workspace.packageJson.name);
let errors = [
...(validationErrors.errors || []),
...(validationErrors.warnings || [])
...(validationErrors.warnings || []),
];
if (errors.length) {
return [
{
type: "INVALID_PACKAGE_NAME",
workspace,
errors
}
errors,
},
];
}
return [];
},
print: error => {
print: (error) => {
if (!error.workspace.packageJson.name) {
return `The package at ${JSON.stringify(
error.workspace.dir
Expand All @@ -48,5 +48,5 @@ export default makeCheck<ErrorType>({
} is an invalid package name for the following reasons:\n${error.errors.join(
"\n"
)}`;
}
},
});
8 changes: 4 additions & 4 deletions packages/cli/src/checks/MULTIPLE_DEPENDENCY_TYPES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default makeCheck<ErrorType>({
type: "MULTIPLE_DEPENDENCY_TYPES",
dependencyType: depType,
dependencyName: depName,
workspace
workspace,
});
}
}
Expand All @@ -35,7 +35,7 @@ export default makeCheck<ErrorType>({
return errors;
},
type: "all",
fix: error => {
fix: (error) => {
let deps = error.workspace.packageJson[error.dependencyType];
if (deps) {
delete deps[error.dependencyName];
Expand All @@ -45,12 +45,12 @@ export default makeCheck<ErrorType>({
}
return { requiresInstall: true };
},
print: error =>
print: (error) =>
`${error.workspace.packageJson.name} has a dependency and a ${
error.dependencyType === "devDependencies"
? "devDependency"
: "optionalDependency"
} on ${
error.dependencyName
}, this is unnecessary, it should be removed from ${error.dependencyType}`
}, this is unnecessary, it should be removed from ${error.dependencyType}`,
});
Loading

0 comments on commit bf2013e

Please sign in to comment.