@xylabs/toolchain 7.10.0 → 7.10.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/dist/index.d.ts +3 -1
- package/dist/index.mjs +879 -782
- package/dist/index.mjs.map +1 -1
- package/dist/lib/deprecationMigrate.mjs +99 -0
- package/dist/lib/deprecationMigrate.mjs.map +1 -0
- package/dist/lib/index.mjs +238 -141
- package/dist/lib/index.mjs.map +1 -1
- package/package.json +4 -3
package/dist/index.mjs
CHANGED
|
@@ -699,15 +699,111 @@ function printWorkspaceCycles(cycles) {
|
|
|
699
699
|
}
|
|
700
700
|
}
|
|
701
701
|
|
|
702
|
+
// src/lib/deprecationMigrate.ts
|
|
703
|
+
import {
|
|
704
|
+
existsSync as existsSync2,
|
|
705
|
+
readFileSync as readFileSync5,
|
|
706
|
+
writeFileSync
|
|
707
|
+
} from "fs";
|
|
708
|
+
import PATH4 from "path";
|
|
709
|
+
import { createInterface } from "readline";
|
|
710
|
+
import chalk5 from "chalk";
|
|
711
|
+
function findProjectRoot() {
|
|
712
|
+
return process.env.INIT_CWD ?? process.cwd();
|
|
713
|
+
}
|
|
714
|
+
function askYesNo(question) {
|
|
715
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
716
|
+
return new Promise((resolve) => {
|
|
717
|
+
rl.question(question, (answer) => {
|
|
718
|
+
rl.close();
|
|
719
|
+
resolve(answer.trim().toLowerCase().startsWith("y"));
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
function replaceInFile(filePath, oldStr, newStr) {
|
|
724
|
+
if (!existsSync2(filePath)) return false;
|
|
725
|
+
const content = readFileSync5(filePath, "utf8");
|
|
726
|
+
if (!content.includes(oldStr)) return false;
|
|
727
|
+
writeFileSync(filePath, content.replaceAll(oldStr, newStr), "utf8");
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
function migrateRootPackageJson(pkg, pkgPath, oldPackage, depField) {
|
|
731
|
+
const version = pkg[depField][oldPackage];
|
|
732
|
+
delete pkg[depField][oldPackage];
|
|
733
|
+
pkg[depField]["@xylabs/toolchain"] = version;
|
|
734
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
735
|
+
`, "utf8");
|
|
736
|
+
console.warn(chalk5.green(` \u2713 Replaced ${oldPackage} \u2192 @xylabs/toolchain in ${depField}`));
|
|
737
|
+
}
|
|
738
|
+
function migrateWorkspacePackageJson(wsPkgPath, dir, oldPackage) {
|
|
739
|
+
if (!existsSync2(wsPkgPath)) return;
|
|
740
|
+
const wsPkg = JSON.parse(readFileSync5(wsPkgPath, "utf8"));
|
|
741
|
+
let changed = false;
|
|
742
|
+
for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
|
|
743
|
+
if (wsPkg[field]?.[oldPackage]) {
|
|
744
|
+
const ver = wsPkg[field][oldPackage];
|
|
745
|
+
delete wsPkg[field][oldPackage];
|
|
746
|
+
wsPkg[field]["@xylabs/toolchain"] = ver;
|
|
747
|
+
changed = true;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (changed) {
|
|
751
|
+
writeFileSync(wsPkgPath, `${JSON.stringify(wsPkg, null, 2)}
|
|
752
|
+
`, "utf8");
|
|
753
|
+
console.warn(chalk5.green(` \u2713 Updated ${dir}/package.json`));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
async function migrateWorkspaces(root, workspacesGlob, oldPackage) {
|
|
757
|
+
if (!Array.isArray(workspacesGlob)) return;
|
|
758
|
+
const { globSync: globSync5 } = await import("glob");
|
|
759
|
+
for (const pattern of workspacesGlob) {
|
|
760
|
+
const dirs = globSync5(pattern, { cwd: root });
|
|
761
|
+
for (const dir of dirs) {
|
|
762
|
+
if (replaceInFile(PATH4.join(root, dir, "xy.config.ts"), oldPackage, "@xylabs/toolchain")) {
|
|
763
|
+
console.warn(chalk5.green(` \u2713 Updated ${dir}/xy.config.ts imports`));
|
|
764
|
+
}
|
|
765
|
+
migrateWorkspacePackageJson(PATH4.join(root, dir, "package.json"), dir, oldPackage);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
function printManualInstructions(oldPackage) {
|
|
770
|
+
console.warn(chalk5.gray(" Skipped. To migrate manually:\n"));
|
|
771
|
+
console.warn(chalk5.gray(` 1. Replace "${oldPackage}" with "@xylabs/toolchain" in package.json`));
|
|
772
|
+
console.warn(chalk5.gray(" 2. Update xy.config.ts imports"));
|
|
773
|
+
console.warn(chalk5.gray(" 3. Run your package manager install\n"));
|
|
774
|
+
}
|
|
775
|
+
async function deprecationMigrate(oldPackage) {
|
|
776
|
+
const root = findProjectRoot();
|
|
777
|
+
const pkgPath = PATH4.join(root, "package.json");
|
|
778
|
+
if (!existsSync2(pkgPath)) return;
|
|
779
|
+
const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
|
|
780
|
+
const depField = pkg.dependencies?.[oldPackage] ? "dependencies" : pkg.devDependencies?.[oldPackage] ? "devDependencies" : void 0;
|
|
781
|
+
if (!depField) return;
|
|
782
|
+
console.warn(chalk5.yellow(`
|
|
783
|
+
\u26A0 ${oldPackage} is deprecated. Use @xylabs/toolchain instead.
|
|
784
|
+
`));
|
|
785
|
+
const shouldMigrate = await askYesNo(chalk5.cyan(" Auto-migrate to @xylabs/toolchain? [y/N] "));
|
|
786
|
+
if (!shouldMigrate) {
|
|
787
|
+
printManualInstructions(oldPackage);
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
migrateRootPackageJson(pkg, pkgPath, oldPackage, depField);
|
|
791
|
+
if (replaceInFile(PATH4.join(root, "xy.config.ts"), oldPackage, "@xylabs/toolchain")) {
|
|
792
|
+
console.warn(chalk5.green(" \u2713 Updated xy.config.ts imports"));
|
|
793
|
+
}
|
|
794
|
+
await migrateWorkspaces(root, pkg.workspaces, oldPackage);
|
|
795
|
+
console.warn(chalk5.yellow("\n Run your package manager install to complete the migration.\n"));
|
|
796
|
+
}
|
|
797
|
+
|
|
702
798
|
// src/lib/file/constants.ts
|
|
703
799
|
var WINDOWS_NEWLINE_REGEX = /\r\n/g;
|
|
704
800
|
var CROSS_PLATFORM_NEWLINE = "\n";
|
|
705
801
|
|
|
706
802
|
// src/lib/file/fileLines.ts
|
|
707
803
|
import {
|
|
708
|
-
existsSync as
|
|
709
|
-
readFileSync as
|
|
710
|
-
writeFileSync
|
|
804
|
+
existsSync as existsSync3,
|
|
805
|
+
readFileSync as readFileSync6,
|
|
806
|
+
writeFileSync as writeFileSync2
|
|
711
807
|
} from "fs";
|
|
712
808
|
|
|
713
809
|
// src/lib/string/empty.ts
|
|
@@ -721,18 +817,18 @@ var union = (a, b) => /* @__PURE__ */ new Set([...new Set(a), ...new Set(b)]);
|
|
|
721
817
|
var defaultReadFileSyncOptions = { encoding: "utf8" };
|
|
722
818
|
|
|
723
819
|
// src/lib/file/fileLines.ts
|
|
724
|
-
var readLines = (uri, options = defaultReadFileSyncOptions) =>
|
|
820
|
+
var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync3(uri) ? readFileSync6(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
|
|
725
821
|
var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
|
|
726
822
|
var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
|
|
727
|
-
const existing =
|
|
823
|
+
const existing = existsSync3(uri) ? readFileSync6(uri, options) : void 0;
|
|
728
824
|
const desired = lines.join(CROSS_PLATFORM_NEWLINE);
|
|
729
|
-
if (existing !== desired)
|
|
825
|
+
if (existing !== desired) writeFileSync2(uri, desired, options);
|
|
730
826
|
};
|
|
731
827
|
|
|
732
828
|
// src/lib/file/tryReadFileSync.ts
|
|
733
|
-
import { existsSync as
|
|
829
|
+
import { existsSync as existsSync4, readFileSync as readFileSync7 } from "fs";
|
|
734
830
|
var tryReadFileSync = (uri, options = defaultReadFileSyncOptions) => {
|
|
735
|
-
return
|
|
831
|
+
return existsSync4(uri) ? readFileSync7(uri, options) : void 0;
|
|
736
832
|
};
|
|
737
833
|
|
|
738
834
|
// src/lib/fillTemplate.ts
|
|
@@ -741,7 +837,7 @@ function fillTemplate(template, data) {
|
|
|
741
837
|
}
|
|
742
838
|
|
|
743
839
|
// src/lib/generateIgnoreFiles.ts
|
|
744
|
-
import
|
|
840
|
+
import chalk6 from "chalk";
|
|
745
841
|
|
|
746
842
|
// src/lib/initCwd.ts
|
|
747
843
|
function INIT_CWD() {
|
|
@@ -752,7 +848,7 @@ function INIT_CWD() {
|
|
|
752
848
|
var localeCompare = (a, b) => a.localeCompare(b);
|
|
753
849
|
var mergeEntries = (a, b) => [...union(a, b)].toSorted(localeCompare);
|
|
754
850
|
var generateIgnoreFiles = (filename2, pkg) => {
|
|
755
|
-
console.log(
|
|
851
|
+
console.log(chalk6.green(`Generate ${filename2} Files`));
|
|
756
852
|
const cwd6 = INIT_CWD();
|
|
757
853
|
const pm = getPackageManager();
|
|
758
854
|
const singleWorkspace = pkg ? pm.findWorkspace(pkg) : void 0;
|
|
@@ -775,27 +871,27 @@ var generateIgnoreFiles = (filename2, pkg) => {
|
|
|
775
871
|
|
|
776
872
|
// src/lib/generateReadmeFiles.ts
|
|
777
873
|
import { execFile } from "child_process";
|
|
778
|
-
import FS, { readFileSync as
|
|
874
|
+
import FS, { readFileSync as readFileSync8 } from "fs";
|
|
779
875
|
import {
|
|
780
876
|
mkdir,
|
|
781
877
|
readFile,
|
|
782
878
|
writeFile
|
|
783
879
|
} from "fs/promises";
|
|
784
880
|
import { createRequire as createRequire2 } from "module";
|
|
785
|
-
import
|
|
786
|
-
import { createInterface } from "readline";
|
|
881
|
+
import PATH5 from "path";
|
|
882
|
+
import { createInterface as createInterface2 } from "readline";
|
|
787
883
|
import { promisify } from "util";
|
|
788
|
-
import
|
|
884
|
+
import chalk7 from "chalk";
|
|
789
885
|
var execFileAsync = promisify(execFile);
|
|
790
886
|
var require3 = createRequire2(import.meta.url);
|
|
791
|
-
var packageRoot2 =
|
|
792
|
-
var readmeTemplatesDir =
|
|
887
|
+
var packageRoot2 = PATH5.dirname(require3.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
888
|
+
var readmeTemplatesDir = PATH5.resolve(packageRoot2, "templates", "readme");
|
|
793
889
|
function fillReadmeTemplate(template, data) {
|
|
794
890
|
const additionalData = { ...data, safeName: data.name.replaceAll("/", "__").replaceAll("@", "") };
|
|
795
891
|
return fillTemplate(template, additionalData);
|
|
796
892
|
}
|
|
797
893
|
async function generateTypedoc(packageLocation, entryPoints) {
|
|
798
|
-
const tempDir =
|
|
894
|
+
const tempDir = PATH5.join(packageLocation, ".temp-typedoc");
|
|
799
895
|
try {
|
|
800
896
|
if (!FS.existsSync(tempDir)) {
|
|
801
897
|
FS.mkdirSync(tempDir, { recursive: true });
|
|
@@ -803,7 +899,7 @@ async function generateTypedoc(packageLocation, entryPoints) {
|
|
|
803
899
|
const typedocConfig = {
|
|
804
900
|
disableSources: true,
|
|
805
901
|
entryPointStrategy: "expand",
|
|
806
|
-
entryPoints: entryPoints.map((ep) =>
|
|
902
|
+
entryPoints: entryPoints.map((ep) => PATH5.resolve(packageLocation, ep)),
|
|
807
903
|
excludeExternals: true,
|
|
808
904
|
excludeInternal: true,
|
|
809
905
|
excludePrivate: true,
|
|
@@ -819,7 +915,7 @@ async function generateTypedoc(packageLocation, entryPoints) {
|
|
|
819
915
|
theme: "markdown",
|
|
820
916
|
useCodeBlocks: true
|
|
821
917
|
};
|
|
822
|
-
const typedocJsonPath =
|
|
918
|
+
const typedocJsonPath = PATH5.join(tempDir, "typedoc.json");
|
|
823
919
|
FS.writeFileSync(typedocJsonPath, JSON.stringify(typedocConfig, null, 2));
|
|
824
920
|
try {
|
|
825
921
|
await execFileAsync("npx", ["typedoc", "--options", typedocJsonPath], { cwd: process.cwd() });
|
|
@@ -838,7 +934,7 @@ async function generateTypedoc(packageLocation, entryPoints) {
|
|
|
838
934
|
}
|
|
839
935
|
function consolidateMarkdown(tempDir) {
|
|
840
936
|
let consolidated = "## Reference\n\n";
|
|
841
|
-
const mainReadmePath =
|
|
937
|
+
const mainReadmePath = PATH5.join(tempDir, "README.md");
|
|
842
938
|
if (FS.existsSync(mainReadmePath)) {
|
|
843
939
|
const mainContent = FS.readFileSync(mainReadmePath, "utf8").replace(/^---(.|\n)*?---\n/, "").replace(/^# .+\n/, "").replaceAll(/\]\((.+?)\.md\)/g, "](#$1)");
|
|
844
940
|
consolidated += mainContent + "\n\n";
|
|
@@ -854,7 +950,7 @@ function processDirectory(dir, level = 0) {
|
|
|
854
950
|
for (const item of items) {
|
|
855
951
|
if (item.isDirectory()) continue;
|
|
856
952
|
if (item.name === "README.md" || !item.name.endsWith(".md")) continue;
|
|
857
|
-
const fileContent = FS.readFileSync(
|
|
953
|
+
const fileContent = FS.readFileSync(PATH5.join(dir, item.name), "utf8").replace(/^---(.|\n)*?---\n/, "");
|
|
858
954
|
const moduleName = item.name.replace(".md", "");
|
|
859
955
|
content += `
|
|
860
956
|
|
|
@@ -870,14 +966,14 @@ ${indent}### <a id="${moduleName}"></a>${moduleName}
|
|
|
870
966
|
|
|
871
967
|
${indent}### ${item.name}
|
|
872
968
|
`;
|
|
873
|
-
content += processDirectory(
|
|
969
|
+
content += processDirectory(PATH5.join(dir, item.name), level + 1);
|
|
874
970
|
}
|
|
875
971
|
} catch {
|
|
876
972
|
}
|
|
877
973
|
return content;
|
|
878
974
|
}
|
|
879
975
|
function askConfirmation(question) {
|
|
880
|
-
const rl =
|
|
976
|
+
const rl = createInterface2({ input: process.stdin, output: process.stdout });
|
|
881
977
|
return new Promise((resolve) => {
|
|
882
978
|
rl.question(question, (answer) => {
|
|
883
979
|
rl.close();
|
|
@@ -885,8 +981,8 @@ function askConfirmation(question) {
|
|
|
885
981
|
});
|
|
886
982
|
});
|
|
887
983
|
}
|
|
888
|
-
var DEFAULT_README_TEMPLATE =
|
|
889
|
-
var DEFAULT_README_BODY =
|
|
984
|
+
var DEFAULT_README_TEMPLATE = readFileSync8(PATH5.resolve(readmeTemplatesDir, "README.template.md"), "utf8");
|
|
985
|
+
var DEFAULT_README_BODY = readFileSync8(PATH5.resolve(readmeTemplatesDir, "README.body.md"), "utf8");
|
|
890
986
|
function applyLogoConfig(template, logoUrl, logoLinkUrl) {
|
|
891
987
|
let result = template;
|
|
892
988
|
if (logoUrl) {
|
|
@@ -902,14 +998,14 @@ function applyLogoConfig(template, logoUrl, logoLinkUrl) {
|
|
|
902
998
|
}
|
|
903
999
|
function resolveTemplatePath(templatePath) {
|
|
904
1000
|
const cwd6 = INIT_CWD();
|
|
905
|
-
return templatePath ??
|
|
1001
|
+
return templatePath ?? PATH5.join(cwd6, ".xy", "README.template.md");
|
|
906
1002
|
}
|
|
907
1003
|
async function loadOrCreateTemplate(resolvedTemplatePath) {
|
|
908
1004
|
try {
|
|
909
1005
|
const template = await readFile(resolvedTemplatePath, "utf8");
|
|
910
1006
|
return { created: false, template };
|
|
911
1007
|
} catch {
|
|
912
|
-
console.log(
|
|
1008
|
+
console.log(chalk7.yellow(`Template not found: ${resolvedTemplatePath}`));
|
|
913
1009
|
const shouldCreate = await askConfirmation("Would you like to create a stock template? (y/N) ");
|
|
914
1010
|
if (!shouldCreate) {
|
|
915
1011
|
throw new Error("Template creation declined");
|
|
@@ -920,16 +1016,16 @@ async function loadOrCreateTemplate(resolvedTemplatePath) {
|
|
|
920
1016
|
}
|
|
921
1017
|
}
|
|
922
1018
|
async function scaffoldTemplate(resolvedTemplatePath, template) {
|
|
923
|
-
const xyDir =
|
|
1019
|
+
const xyDir = PATH5.dirname(resolvedTemplatePath);
|
|
924
1020
|
await mkdir(xyDir, { recursive: true });
|
|
925
1021
|
await writeFile(resolvedTemplatePath, template);
|
|
926
|
-
console.log(
|
|
927
|
-
const bodyPath =
|
|
1022
|
+
console.log(chalk7.green(`Created template: ${resolvedTemplatePath}`));
|
|
1023
|
+
const bodyPath = PATH5.join(xyDir, "README.body.md");
|
|
928
1024
|
await writeFile(bodyPath, DEFAULT_README_BODY);
|
|
929
|
-
console.log(
|
|
1025
|
+
console.log(chalk7.green(`Created body template: ${bodyPath}`));
|
|
930
1026
|
}
|
|
931
1027
|
async function resolveBody(location, defaultBody) {
|
|
932
|
-
const localBodyPath =
|
|
1028
|
+
const localBodyPath = PATH5.join(location, "README.body.md");
|
|
933
1029
|
try {
|
|
934
1030
|
return await readFile(localBodyPath, "utf8");
|
|
935
1031
|
} catch {
|
|
@@ -938,7 +1034,7 @@ async function resolveBody(location, defaultBody) {
|
|
|
938
1034
|
}
|
|
939
1035
|
async function generateReadmeForWorkspace(location, name, template, defaultBody, typedoc, verbose, pm) {
|
|
940
1036
|
try {
|
|
941
|
-
const pkgJsonPath =
|
|
1037
|
+
const pkgJsonPath = PATH5.join(location, "package.json");
|
|
942
1038
|
const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf8"));
|
|
943
1039
|
const body = await resolveBody(location, defaultBody);
|
|
944
1040
|
const typedocContent = typedoc ? await generateTypedoc(location, ["src/index*.ts"]) : "";
|
|
@@ -948,17 +1044,17 @@ async function generateReadmeForWorkspace(location, name, template, defaultBody,
|
|
|
948
1044
|
pm,
|
|
949
1045
|
typedoc: typedocContent
|
|
950
1046
|
});
|
|
951
|
-
await writeFile(
|
|
952
|
-
if (verbose) console.log(
|
|
1047
|
+
await writeFile(PATH5.join(location, "README.md"), readmeContent);
|
|
1048
|
+
if (verbose) console.log(chalk7.green(` ${name}`));
|
|
953
1049
|
return true;
|
|
954
1050
|
} catch (ex) {
|
|
955
1051
|
const error = ex;
|
|
956
|
-
console.warn(
|
|
1052
|
+
console.warn(chalk7.yellow(` Skipped ${location}: ${error.message}`));
|
|
957
1053
|
return false;
|
|
958
1054
|
}
|
|
959
1055
|
}
|
|
960
1056
|
async function loadDefaultBody(resolvedTemplatePath) {
|
|
961
|
-
const xyBodyPath =
|
|
1057
|
+
const xyBodyPath = PATH5.join(PATH5.dirname(resolvedTemplatePath), "README.body.md");
|
|
962
1058
|
try {
|
|
963
1059
|
return await readFile(xyBodyPath, "utf8");
|
|
964
1060
|
} catch {
|
|
@@ -984,7 +1080,7 @@ async function generateReadmeFiles({
|
|
|
984
1080
|
typedoc = false,
|
|
985
1081
|
verbose = false
|
|
986
1082
|
}) {
|
|
987
|
-
console.log(
|
|
1083
|
+
console.log(chalk7.green("Generate README Files"));
|
|
988
1084
|
const resolvedTemplatePath = resolveTemplatePath(templatePath);
|
|
989
1085
|
let template;
|
|
990
1086
|
let templateCreated;
|
|
@@ -995,7 +1091,7 @@ async function generateReadmeFiles({
|
|
|
995
1091
|
}
|
|
996
1092
|
template = applyLogoConfig(template, logoUrl, logoLinkUrl);
|
|
997
1093
|
if (templateCreated) {
|
|
998
|
-
console.log(
|
|
1094
|
+
console.log(chalk7.green("Generating README files for all packages..."));
|
|
999
1095
|
}
|
|
1000
1096
|
const defaultBody = await loadDefaultBody(resolvedTemplatePath);
|
|
1001
1097
|
const pmName = detectPackageManager();
|
|
@@ -1019,18 +1115,18 @@ async function generateReadmeFiles({
|
|
|
1019
1115
|
);
|
|
1020
1116
|
const failed = flushResults(results);
|
|
1021
1117
|
const ms = performance.now() - start2;
|
|
1022
|
-
console.log(
|
|
1118
|
+
console.log(chalk7.blue(`Generated ${workspaces.length} README(s) in ${ms.toFixed(0)}ms`));
|
|
1023
1119
|
return failed ? 1 : 0;
|
|
1024
1120
|
}
|
|
1025
1121
|
|
|
1026
1122
|
// src/lib/gitignoreTemplate.ts
|
|
1027
|
-
import { readFileSync as
|
|
1123
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
1028
1124
|
import { createRequire as createRequire3 } from "module";
|
|
1029
|
-
import
|
|
1125
|
+
import PATH6 from "path";
|
|
1030
1126
|
var require4 = createRequire3(import.meta.url);
|
|
1031
|
-
var packageRoot3 =
|
|
1032
|
-
var templatesDir2 =
|
|
1033
|
-
var gitignoreTemplate = () =>
|
|
1127
|
+
var packageRoot3 = PATH6.dirname(require4.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
1128
|
+
var templatesDir2 = PATH6.resolve(packageRoot3, "templates", "gitignore");
|
|
1129
|
+
var gitignoreTemplate = () => readFileSync9(PATH6.resolve(templatesDir2, "template.gitignore"), "utf8");
|
|
1034
1130
|
|
|
1035
1131
|
// src/lib/latestVersions.ts
|
|
1036
1132
|
var latestVersions = {
|
|
@@ -1042,7 +1138,7 @@ var latestVersions = {
|
|
|
1042
1138
|
};
|
|
1043
1139
|
|
|
1044
1140
|
// src/lib/loadConfig.ts
|
|
1045
|
-
import
|
|
1141
|
+
import chalk8 from "chalk";
|
|
1046
1142
|
import { cosmiconfig } from "cosmiconfig";
|
|
1047
1143
|
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
|
|
1048
1144
|
import deepmerge from "deepmerge";
|
|
@@ -1060,9 +1156,9 @@ var loadConfig = async (params) => {
|
|
|
1060
1156
|
rootConfigPath = cosmicConfigResult?.filepath;
|
|
1061
1157
|
const configFilePath = cosmicConfigResult?.filepath;
|
|
1062
1158
|
if (configFilePath !== void 0) {
|
|
1063
|
-
console.log(
|
|
1159
|
+
console.log(chalk8.green(`Loaded config from ${configFilePath}`));
|
|
1064
1160
|
if (config.verbose) {
|
|
1065
|
-
console.log(
|
|
1161
|
+
console.log(chalk8.gray(`${JSON.stringify(config, null, 2)}`));
|
|
1066
1162
|
}
|
|
1067
1163
|
}
|
|
1068
1164
|
}
|
|
@@ -1092,7 +1188,7 @@ function resolveCommandField(cfg, commandName, configPath) {
|
|
|
1092
1188
|
const key = `${configPath ?? "unknown"}:${commandName}`;
|
|
1093
1189
|
if (!deprecationWarned.has(key)) {
|
|
1094
1190
|
deprecationWarned.add(key);
|
|
1095
|
-
console.warn(
|
|
1191
|
+
console.warn(chalk8.yellow(
|
|
1096
1192
|
`[xy] Deprecated: top-level "${commandName}" in ${configPath ?? "xy.config"} \u2014 move to "commands.${commandName}"`
|
|
1097
1193
|
));
|
|
1098
1194
|
}
|
|
@@ -1110,7 +1206,7 @@ async function loadWorkspaceCommandConfig(workspaceDir, commandName) {
|
|
|
1110
1206
|
}
|
|
1111
1207
|
|
|
1112
1208
|
// src/lib/packageName.ts
|
|
1113
|
-
import { readFileSync as
|
|
1209
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
1114
1210
|
import path from "path";
|
|
1115
1211
|
function packageName() {
|
|
1116
1212
|
if (process.env.npm_package_name) {
|
|
@@ -1118,7 +1214,7 @@ function packageName() {
|
|
|
1118
1214
|
}
|
|
1119
1215
|
try {
|
|
1120
1216
|
const pkgPath = path.join(INIT_CWD(), "package.json");
|
|
1121
|
-
const pkg = JSON.parse(
|
|
1217
|
+
const pkg = JSON.parse(readFileSync10(pkgPath, "utf8"));
|
|
1122
1218
|
return pkg.name;
|
|
1123
1219
|
} catch {
|
|
1124
1220
|
return void 0;
|
|
@@ -1126,29 +1222,29 @@ function packageName() {
|
|
|
1126
1222
|
}
|
|
1127
1223
|
|
|
1128
1224
|
// src/lib/parsedPackageJSON.ts
|
|
1129
|
-
import { readFileSync as
|
|
1225
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
1130
1226
|
var parsedPackageJSON = (path19) => {
|
|
1131
1227
|
const pathToPackageJSON = path19 ?? process.env.npm_package_json ?? "";
|
|
1132
|
-
const packageJSON =
|
|
1228
|
+
const packageJSON = readFileSync11(pathToPackageJSON).toString();
|
|
1133
1229
|
return JSON.parse(packageJSON);
|
|
1134
1230
|
};
|
|
1135
1231
|
|
|
1136
1232
|
// src/lib/repoTemplates.ts
|
|
1137
|
-
import { readdirSync as readdirSync2, readFileSync as
|
|
1233
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync12 } from "fs";
|
|
1138
1234
|
import { createRequire as createRequire4 } from "module";
|
|
1139
|
-
import
|
|
1235
|
+
import PATH7 from "path";
|
|
1140
1236
|
var require5 = createRequire4(import.meta.url);
|
|
1141
|
-
var packageRoot4 =
|
|
1142
|
-
var repoTemplatesDir =
|
|
1237
|
+
var packageRoot4 = PATH7.dirname(require5.resolve("@xylabs/ts-scripts-common/package.json"));
|
|
1238
|
+
var repoTemplatesDir = PATH7.resolve(packageRoot4, "templates", "repo");
|
|
1143
1239
|
function collectFiles(dir, prefix) {
|
|
1144
1240
|
const results = [];
|
|
1145
1241
|
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
1146
1242
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
1147
1243
|
if (entry.isDirectory()) {
|
|
1148
|
-
results.push(...collectFiles(
|
|
1244
|
+
results.push(...collectFiles(PATH7.resolve(dir, entry.name), rel));
|
|
1149
1245
|
} else {
|
|
1150
1246
|
results.push({
|
|
1151
|
-
content:
|
|
1247
|
+
content: readFileSync12(PATH7.resolve(dir, entry.name), "utf8"),
|
|
1152
1248
|
relativePath: rel
|
|
1153
1249
|
});
|
|
1154
1250
|
}
|
|
@@ -1156,7 +1252,7 @@ function collectFiles(dir, prefix) {
|
|
|
1156
1252
|
return results;
|
|
1157
1253
|
}
|
|
1158
1254
|
function loadRepoTemplateFiles(template, section) {
|
|
1159
|
-
const dir =
|
|
1255
|
+
const dir = PATH7.resolve(repoTemplatesDir, template, section);
|
|
1160
1256
|
return collectFiles(dir, "");
|
|
1161
1257
|
}
|
|
1162
1258
|
function listRepoTemplates() {
|
|
@@ -1165,37 +1261,37 @@ function listRepoTemplates() {
|
|
|
1165
1261
|
|
|
1166
1262
|
// src/lib/runInstall.ts
|
|
1167
1263
|
import { spawnSync as spawnSync5 } from "child_process";
|
|
1168
|
-
import
|
|
1264
|
+
import chalk9 from "chalk";
|
|
1169
1265
|
function runInstall(cwd6) {
|
|
1170
1266
|
const pm = detectPackageManager();
|
|
1171
|
-
console.log(
|
|
1267
|
+
console.log(chalk9.gray(`Running ${pm} install...`));
|
|
1172
1268
|
const result = spawnSync5(pm, ["install"], {
|
|
1173
1269
|
cwd: cwd6,
|
|
1174
1270
|
stdio: "inherit"
|
|
1175
1271
|
});
|
|
1176
1272
|
if (result.status !== 0) {
|
|
1177
|
-
console.warn(
|
|
1273
|
+
console.warn(chalk9.yellow(`${pm} install failed`));
|
|
1178
1274
|
return false;
|
|
1179
1275
|
}
|
|
1180
|
-
console.log(
|
|
1276
|
+
console.log(chalk9.green("Dependencies installed"));
|
|
1181
1277
|
return true;
|
|
1182
1278
|
}
|
|
1183
1279
|
|
|
1184
1280
|
// src/lib/runSteps.ts
|
|
1185
1281
|
import { spawnSync as spawnSync6 } from "child_process";
|
|
1186
|
-
import { existsSync as
|
|
1187
|
-
import
|
|
1282
|
+
import { existsSync as existsSync5 } from "fs";
|
|
1283
|
+
import chalk10 from "chalk";
|
|
1188
1284
|
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
1189
1285
|
return safeExit(() => {
|
|
1190
1286
|
const pkgName = packageName();
|
|
1191
|
-
console.log(
|
|
1287
|
+
console.log(chalk10.green(`${name} [${pkgName}]`));
|
|
1192
1288
|
let totalStatus = 0;
|
|
1193
1289
|
for (const [i, [command, args, config2]] of steps.entries()) {
|
|
1194
1290
|
if (messages?.[i]) {
|
|
1195
|
-
console.log(
|
|
1291
|
+
console.log(chalk10.gray(messages?.[i]));
|
|
1196
1292
|
}
|
|
1197
1293
|
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
1198
|
-
if (command === "node" && !
|
|
1294
|
+
if (command === "node" && !existsSync5(argList[0])) {
|
|
1199
1295
|
throw new Error(`File not found [${argList[0]}]`);
|
|
1200
1296
|
}
|
|
1201
1297
|
const status = spawnSync6(command, Array.isArray(args) ? args : args.split(" "), {
|
|
@@ -1214,16 +1310,16 @@ var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
|
1214
1310
|
|
|
1215
1311
|
// src/lib/runStepsAsync.ts
|
|
1216
1312
|
import { spawn } from "child_process";
|
|
1217
|
-
import { existsSync as
|
|
1218
|
-
import
|
|
1313
|
+
import { existsSync as existsSync6 } from "fs";
|
|
1314
|
+
import chalk11 from "chalk";
|
|
1219
1315
|
var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
1220
1316
|
return new Promise((resolve) => {
|
|
1221
1317
|
const [command, args, config2] = step;
|
|
1222
1318
|
if (message) {
|
|
1223
|
-
console.log(
|
|
1319
|
+
console.log(chalk11.gray(message));
|
|
1224
1320
|
}
|
|
1225
1321
|
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
1226
|
-
if (command === "node" && !
|
|
1322
|
+
if (command === "node" && !existsSync6(argList[0])) {
|
|
1227
1323
|
throw new Error(`File not found [${argList[0]}]`);
|
|
1228
1324
|
}
|
|
1229
1325
|
spawn(command, Array.isArray(args) ? args : args.split(" "), {
|
|
@@ -1234,8 +1330,8 @@ var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
|
1234
1330
|
}).on("close", (code) => {
|
|
1235
1331
|
if (code) {
|
|
1236
1332
|
console.error(
|
|
1237
|
-
|
|
1238
|
-
`Command Exited With Non-Zero Result [${
|
|
1333
|
+
chalk11.red(
|
|
1334
|
+
`Command Exited With Non-Zero Result [${chalk11.gray(code)}] | ${chalk11.yellow(command)} ${chalk11.white(
|
|
1239
1335
|
Array.isArray(args) ? args.join(" ") : args
|
|
1240
1336
|
)}`
|
|
1241
1337
|
)
|
|
@@ -1251,7 +1347,7 @@ var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
|
1251
1347
|
var runStepsAsync = async (name, steps, exitOnFail = true, messages) => {
|
|
1252
1348
|
return await safeExitAsync(async () => {
|
|
1253
1349
|
const pkgName = packageName();
|
|
1254
|
-
console.log(
|
|
1350
|
+
console.log(chalk11.green(`${name} [${pkgName}]`));
|
|
1255
1351
|
let result = 0;
|
|
1256
1352
|
for (const [i, step] of steps.entries()) {
|
|
1257
1353
|
result += await runStepAsync(name, step, exitOnFail, messages?.[i]);
|
|
@@ -1270,33 +1366,33 @@ var runXy = (command) => {
|
|
|
1270
1366
|
};
|
|
1271
1367
|
|
|
1272
1368
|
// src/lib/runXyWithWarning.ts
|
|
1273
|
-
import
|
|
1369
|
+
import chalk12 from "chalk";
|
|
1274
1370
|
var runXyWithWarning = (command) => {
|
|
1275
1371
|
const pm = getPackageManager();
|
|
1276
1372
|
const commandString = `${pm.command} ${command}`;
|
|
1277
1373
|
const commandXyString = `${pm.command} xy ${command}`;
|
|
1278
|
-
console.warn(
|
|
1279
|
-
console.warn(
|
|
1374
|
+
console.warn(chalk12.yellow(`WARNING: [${chalk12.white(commandString)}] is deprecated for XY Labs Scripts.`));
|
|
1375
|
+
console.warn(chalk12.gray(`Did you mean [${chalk12.magenta(commandXyString)}]?`));
|
|
1280
1376
|
return 1;
|
|
1281
1377
|
};
|
|
1282
1378
|
|
|
1283
1379
|
// src/lib/tryRunLocalScript.ts
|
|
1284
1380
|
import { spawnSync as spawnSync7 } from "child_process";
|
|
1285
|
-
import { readFileSync as
|
|
1286
|
-
import
|
|
1287
|
-
import
|
|
1381
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
1382
|
+
import PATH8 from "path";
|
|
1383
|
+
import chalk13 from "chalk";
|
|
1288
1384
|
function tryRunLocalScript(commandName) {
|
|
1289
1385
|
if (process.env.XY_LOCAL_SCRIPT === "1") return void 0;
|
|
1290
|
-
const rootPkgPath =
|
|
1386
|
+
const rootPkgPath = PATH8.resolve(process.cwd(), "package.json");
|
|
1291
1387
|
let rootPkg;
|
|
1292
1388
|
try {
|
|
1293
|
-
rootPkg = JSON.parse(
|
|
1389
|
+
rootPkg = JSON.parse(readFileSync13(rootPkgPath, "utf8"));
|
|
1294
1390
|
} catch {
|
|
1295
1391
|
return void 0;
|
|
1296
1392
|
}
|
|
1297
1393
|
if (!rootPkg.scripts?.[commandName]) return void 0;
|
|
1298
1394
|
const extraArgs = process.argv.slice(process.argv.indexOf(commandName) + 1);
|
|
1299
|
-
console.log(
|
|
1395
|
+
console.log(chalk13.blue(`Delegating "${commandName}" to local script`));
|
|
1300
1396
|
const pm = getPackageManager();
|
|
1301
1397
|
const result = spawnSync7(pm.command, ["run", commandName, ...extraArgs], {
|
|
1302
1398
|
cwd: process.cwd(),
|
|
@@ -1313,17 +1409,17 @@ function tryRunLocalScript(commandName) {
|
|
|
1313
1409
|
}
|
|
1314
1410
|
|
|
1315
1411
|
// src/lib/updo/applyUpdates.ts
|
|
1316
|
-
import { readFileSync as
|
|
1317
|
-
import
|
|
1318
|
-
import
|
|
1412
|
+
import { readFileSync as readFileSync14, writeFileSync as writeFileSync3 } from "fs";
|
|
1413
|
+
import PATH9 from "path";
|
|
1414
|
+
import chalk14 from "chalk";
|
|
1319
1415
|
function applyUpdates(cwd6, workspaces, updates) {
|
|
1320
1416
|
const updateMap = new Map(updates.map((u) => [u.name, u]));
|
|
1321
1417
|
let modified = 0;
|
|
1322
1418
|
for (const ws of workspaces) {
|
|
1323
|
-
const pkgPath =
|
|
1419
|
+
const pkgPath = PATH9.resolve(cwd6, ws.location, "package.json");
|
|
1324
1420
|
let content;
|
|
1325
1421
|
try {
|
|
1326
|
-
content =
|
|
1422
|
+
content = readFileSync14(pkgPath, "utf8");
|
|
1327
1423
|
} catch {
|
|
1328
1424
|
continue;
|
|
1329
1425
|
}
|
|
@@ -1344,26 +1440,26 @@ function applyUpdates(cwd6, workspaces, updates) {
|
|
|
1344
1440
|
}
|
|
1345
1441
|
}
|
|
1346
1442
|
if (changed) {
|
|
1347
|
-
|
|
1443
|
+
writeFileSync3(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
1348
1444
|
`);
|
|
1349
1445
|
modified++;
|
|
1350
|
-
console.log(
|
|
1446
|
+
console.log(chalk14.gray(` Updated ${ws.name}`));
|
|
1351
1447
|
}
|
|
1352
1448
|
}
|
|
1353
1449
|
return modified;
|
|
1354
1450
|
}
|
|
1355
1451
|
|
|
1356
1452
|
// src/lib/updo/collectWorkspaceDeps.ts
|
|
1357
|
-
import { readFileSync as
|
|
1358
|
-
import
|
|
1453
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
1454
|
+
import PATH10 from "path";
|
|
1359
1455
|
var DEP_FIELDS = ["dependencies", "devDependencies", "peerDependencies"];
|
|
1360
1456
|
function collectWorkspaceDeps(cwd6, workspaces, workspaceNames) {
|
|
1361
1457
|
const depMap = /* @__PURE__ */ new Map();
|
|
1362
1458
|
for (const ws of workspaces) {
|
|
1363
|
-
const pkgPath =
|
|
1459
|
+
const pkgPath = PATH10.resolve(cwd6, ws.location, "package.json");
|
|
1364
1460
|
let pkg;
|
|
1365
1461
|
try {
|
|
1366
|
-
pkg = JSON.parse(
|
|
1462
|
+
pkg = JSON.parse(readFileSync15(pkgPath, "utf8"));
|
|
1367
1463
|
} catch {
|
|
1368
1464
|
continue;
|
|
1369
1465
|
}
|
|
@@ -1445,51 +1541,51 @@ import {
|
|
|
1445
1541
|
useRef,
|
|
1446
1542
|
useState
|
|
1447
1543
|
} from "@inquirer/core";
|
|
1448
|
-
import
|
|
1544
|
+
import chalk15 from "chalk";
|
|
1449
1545
|
import semver from "semver";
|
|
1450
1546
|
function versionColor(version, current) {
|
|
1451
|
-
if (!version || !current) return
|
|
1452
|
-
if (version === current) return
|
|
1547
|
+
if (!version || !current) return chalk15.gray;
|
|
1548
|
+
if (version === current) return chalk15.gray;
|
|
1453
1549
|
const diff = semver.diff(current, version);
|
|
1454
|
-
if (diff === "major" || diff === "premajor") return
|
|
1455
|
-
if (diff === "minor" || diff === "preminor") return
|
|
1456
|
-
return
|
|
1550
|
+
if (diff === "major" || diff === "premajor") return chalk15.red;
|
|
1551
|
+
if (diff === "minor" || diff === "preminor") return chalk15.yellow;
|
|
1552
|
+
return chalk15.green;
|
|
1457
1553
|
}
|
|
1458
1554
|
function pad(raw, colored, width) {
|
|
1459
1555
|
return colored + " ".repeat(Math.max(0, width - raw.length));
|
|
1460
1556
|
}
|
|
1461
1557
|
function dot(selected) {
|
|
1462
|
-
return selected ?
|
|
1558
|
+
return selected ? chalk15.green("\u25CF") : chalk15.dim("\u25CB");
|
|
1463
1559
|
}
|
|
1464
1560
|
function renderHeader(w) {
|
|
1465
1561
|
const header = [
|
|
1466
1562
|
" ",
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1563
|
+
chalk15.bold("Package".padEnd(w.name)),
|
|
1564
|
+
chalk15.bold("Current".padEnd(w.current)),
|
|
1565
|
+
chalk15.bold(" Wanted".padEnd(w.wanted + 2)),
|
|
1566
|
+
chalk15.bold(" Latest".padEnd(w.latest + 2)),
|
|
1567
|
+
chalk15.bold(" Next/RC".padEnd(w.next + 2))
|
|
1472
1568
|
].join(" ");
|
|
1473
1569
|
const totalWidth = w.name + w.current + w.wanted + w.latest + w.next + 24;
|
|
1474
1570
|
return `${header}
|
|
1475
|
-
${
|
|
1571
|
+
${chalk15.gray("\u2500".repeat(totalWidth))}`;
|
|
1476
1572
|
}
|
|
1477
1573
|
function renderRow(dep, selection, active, w) {
|
|
1478
|
-
const pointer = active ?
|
|
1574
|
+
const pointer = active ? chalk15.cyan("\u276F") : " ";
|
|
1479
1575
|
const rawName = dep.name;
|
|
1480
|
-
const name = active ?
|
|
1576
|
+
const name = active ? chalk15.white(rawName) : chalk15.gray(rawName);
|
|
1481
1577
|
const rawCurrent = dep.current ?? "-";
|
|
1482
|
-
const current =
|
|
1578
|
+
const current = chalk15.gray(rawCurrent);
|
|
1483
1579
|
const rawWanted = dep.wanted ?? "-";
|
|
1484
|
-
const wantedColorFn = dep.wanted ? versionColor(dep.wanted, dep.current) :
|
|
1580
|
+
const wantedColorFn = dep.wanted ? versionColor(dep.wanted, dep.current) : chalk15.gray;
|
|
1485
1581
|
const wantedDot = dep.wanted ? dot(selection === 0) : " ";
|
|
1486
1582
|
const wanted = `${wantedDot} ${pad(rawWanted, wantedColorFn(rawWanted), w.wanted)}`;
|
|
1487
1583
|
const rawLatest = dep.latest ?? "-";
|
|
1488
|
-
const latestColorFn = dep.latest ? versionColor(dep.latest, dep.current) :
|
|
1584
|
+
const latestColorFn = dep.latest ? versionColor(dep.latest, dep.current) : chalk15.gray;
|
|
1489
1585
|
const latestDot = dep.latest ? dot(selection === 1) : " ";
|
|
1490
1586
|
const latest = `${latestDot} ${pad(rawLatest, latestColorFn(rawLatest), w.latest)}`;
|
|
1491
1587
|
const rawNext = dep.next ?? "-";
|
|
1492
|
-
const nextColorFn = dep.next ? versionColor(dep.next, dep.current) :
|
|
1588
|
+
const nextColorFn = dep.next ? versionColor(dep.next, dep.current) : chalk15.gray;
|
|
1493
1589
|
const nextDot = dep.next ? dot(selection === 2) : " ";
|
|
1494
1590
|
const next = `${nextDot} ${pad(rawNext, nextColorFn(rawNext), w.next)}`;
|
|
1495
1591
|
return `${pointer} ${pad(rawName, name, w.name)} ${pad(rawCurrent, current, w.current)} ${wanted} ${latest} ${next}`;
|
|
@@ -1540,8 +1636,8 @@ function renderPage(rows, cursor, selections, w, pageSize) {
|
|
|
1540
1636
|
lines.push(renderRow(rows[i], selections[i], i === cursor, w));
|
|
1541
1637
|
}
|
|
1542
1638
|
if (total > pageSize) {
|
|
1543
|
-
if (start2 > 0) lines.unshift(
|
|
1544
|
-
if (end < total) lines.push(
|
|
1639
|
+
if (start2 > 0) lines.unshift(chalk15.dim(" \u2191 more"));
|
|
1640
|
+
if (end < total) lines.push(chalk15.dim(" \u2193 more"));
|
|
1545
1641
|
}
|
|
1546
1642
|
return lines.join("\n");
|
|
1547
1643
|
}
|
|
@@ -1590,7 +1686,7 @@ var updoPrompt = createPrompt((config2, done) => {
|
|
|
1590
1686
|
const header = renderHeader(w);
|
|
1591
1687
|
const page = renderPage(rows, cursor, selections.current, w, 20);
|
|
1592
1688
|
const selectedCount = selections.current.filter((s) => s >= 0).length;
|
|
1593
|
-
const status =
|
|
1689
|
+
const status = chalk15.gray(` ${selectedCount} selected \u2191/\u2193 navigate space cycle version enter confirm`);
|
|
1594
1690
|
return `${header}
|
|
1595
1691
|
${page}
|
|
1596
1692
|
${status}`;
|
|
@@ -1598,11 +1694,11 @@ ${status}`;
|
|
|
1598
1694
|
async function interactiveSelect(deps) {
|
|
1599
1695
|
const updatable = deps.filter((d) => d.updateAvailable);
|
|
1600
1696
|
if (updatable.length === 0) {
|
|
1601
|
-
console.log(
|
|
1697
|
+
console.log(chalk15.green("\nAll packages are up to date!"));
|
|
1602
1698
|
return [];
|
|
1603
1699
|
}
|
|
1604
1700
|
if (!process.stdout.isTTY) {
|
|
1605
|
-
console.log(
|
|
1701
|
+
console.log(chalk15.yellow("Non-interactive environment detected, skipping selection."));
|
|
1606
1702
|
return [];
|
|
1607
1703
|
}
|
|
1608
1704
|
try {
|
|
@@ -1616,24 +1712,24 @@ async function interactiveSelect(deps) {
|
|
|
1616
1712
|
}
|
|
1617
1713
|
|
|
1618
1714
|
// src/lib/updo/renderTable.ts
|
|
1619
|
-
import
|
|
1715
|
+
import chalk16 from "chalk";
|
|
1620
1716
|
import semver2 from "semver";
|
|
1621
1717
|
function versionColor2(version, current) {
|
|
1622
|
-
if (!version || !current) return
|
|
1623
|
-
if (version === current) return
|
|
1718
|
+
if (!version || !current) return chalk16.gray(version ?? "-");
|
|
1719
|
+
if (version === current) return chalk16.gray(version);
|
|
1624
1720
|
const diff = semver2.diff(current, version);
|
|
1625
|
-
if (diff === "major" || diff === "premajor") return
|
|
1626
|
-
if (diff === "minor" || diff === "preminor") return
|
|
1627
|
-
return
|
|
1721
|
+
if (diff === "major" || diff === "premajor") return chalk16.red(version);
|
|
1722
|
+
if (diff === "minor" || diff === "preminor") return chalk16.yellow(version);
|
|
1723
|
+
return chalk16.green(version);
|
|
1628
1724
|
}
|
|
1629
1725
|
var columns = [
|
|
1630
1726
|
{
|
|
1631
|
-
color: (_v, dep) => dep.updateAvailable ?
|
|
1727
|
+
color: (_v, dep) => dep.updateAvailable ? chalk16.white(dep.name) : chalk16.gray(dep.name),
|
|
1632
1728
|
header: "Package",
|
|
1633
1729
|
value: (dep) => dep.name
|
|
1634
1730
|
},
|
|
1635
1731
|
{
|
|
1636
|
-
color: (_v, dep) =>
|
|
1732
|
+
color: (_v, dep) => chalk16.gray(dep.current ?? "-"),
|
|
1637
1733
|
header: "Current",
|
|
1638
1734
|
value: (dep) => dep.current ?? "-"
|
|
1639
1735
|
},
|
|
@@ -1653,7 +1749,7 @@ var columns = [
|
|
|
1653
1749
|
value: (dep) => dep.next ?? "-"
|
|
1654
1750
|
},
|
|
1655
1751
|
{
|
|
1656
|
-
color: (_v, dep) =>
|
|
1752
|
+
color: (_v, dep) => chalk16.gray(dep.depTypes.join(", ")),
|
|
1657
1753
|
header: "Type",
|
|
1658
1754
|
value: (dep) => dep.depTypes.join(", ")
|
|
1659
1755
|
}
|
|
@@ -1661,7 +1757,7 @@ var columns = [
|
|
|
1661
1757
|
function renderTable(deps) {
|
|
1662
1758
|
const updatable = deps.filter((d) => d.updateAvailable);
|
|
1663
1759
|
if (updatable.length === 0) {
|
|
1664
|
-
console.log(
|
|
1760
|
+
console.log(chalk16.green("\nAll packages are up to date!"));
|
|
1665
1761
|
return;
|
|
1666
1762
|
}
|
|
1667
1763
|
const widths = columns.map((col) => {
|
|
@@ -1671,14 +1767,14 @@ function renderTable(deps) {
|
|
|
1671
1767
|
}
|
|
1672
1768
|
return Math.max(col.header.length, maxData);
|
|
1673
1769
|
});
|
|
1674
|
-
const header = columns.map((col, i) =>
|
|
1770
|
+
const header = columns.map((col, i) => chalk16.bold(col.header.padEnd(widths[i]))).join(" ");
|
|
1675
1771
|
console.log(`
|
|
1676
1772
|
${header}`);
|
|
1677
1773
|
let totalWidth = -2;
|
|
1678
1774
|
for (const w of widths) {
|
|
1679
1775
|
totalWidth += w + 2;
|
|
1680
1776
|
}
|
|
1681
|
-
console.log(
|
|
1777
|
+
console.log(chalk16.gray("\u2500".repeat(totalWidth)));
|
|
1682
1778
|
for (const dep of updatable) {
|
|
1683
1779
|
const row = columns.map((col, i) => {
|
|
1684
1780
|
const raw = col.value(dep);
|
|
@@ -1738,29 +1834,29 @@ function resolveVersions(deps, registry, installedVersions) {
|
|
|
1738
1834
|
}
|
|
1739
1835
|
|
|
1740
1836
|
// src/lib/updo/runUpdo.ts
|
|
1741
|
-
import
|
|
1837
|
+
import chalk17 from "chalk";
|
|
1742
1838
|
async function runUpdo(pm, _options = {}) {
|
|
1743
1839
|
const cwd6 = INIT_CWD();
|
|
1744
1840
|
const workspaces = pm.listWorkspaces();
|
|
1745
1841
|
const workspaceNames = new Set(workspaces.map((ws) => ws.name));
|
|
1746
|
-
console.log(
|
|
1842
|
+
console.log(chalk17.gray("Scanning workspace dependencies..."));
|
|
1747
1843
|
const declaredDeps = collectWorkspaceDeps(cwd6, workspaces, workspaceNames);
|
|
1748
|
-
console.log(
|
|
1749
|
-
console.log(
|
|
1844
|
+
console.log(chalk17.gray(` Found ${declaredDeps.size} unique dependencies across ${workspaces.length} workspaces`));
|
|
1845
|
+
console.log(chalk17.gray("Fetching registry info..."));
|
|
1750
1846
|
const registryInfo = await fetchAllRegistryInfo([...declaredDeps.keys()]);
|
|
1751
|
-
console.log(
|
|
1847
|
+
console.log(chalk17.gray("Reading installed versions..."));
|
|
1752
1848
|
const installedVersions = pm.listInstalledVersions();
|
|
1753
1849
|
const resolved = resolveVersions(declaredDeps, registryInfo, installedVersions);
|
|
1754
1850
|
const updates = await interactiveSelect(resolved);
|
|
1755
1851
|
if (updates.length === 0) {
|
|
1756
|
-
console.log(
|
|
1852
|
+
console.log(chalk17.gray("No updates selected."));
|
|
1757
1853
|
return 0;
|
|
1758
1854
|
}
|
|
1759
|
-
console.log(
|
|
1855
|
+
console.log(chalk17.gray(`
|
|
1760
1856
|
Applying ${updates.length} updates...`));
|
|
1761
1857
|
const modified = applyUpdates(cwd6, workspaces, updates);
|
|
1762
|
-
console.log(
|
|
1763
|
-
console.log(
|
|
1858
|
+
console.log(chalk17.gray(` Modified ${modified} package.json files`));
|
|
1859
|
+
console.log(chalk17.gray("Installing updated dependencies..."));
|
|
1764
1860
|
return runSteps("Updo", [
|
|
1765
1861
|
pm.install(),
|
|
1766
1862
|
pm.dedupe()
|
|
@@ -1797,13 +1893,13 @@ var build = async ({
|
|
|
1797
1893
|
|
|
1798
1894
|
// src/actions/claude-check.ts
|
|
1799
1895
|
import {
|
|
1800
|
-
existsSync as
|
|
1896
|
+
existsSync as existsSync7,
|
|
1801
1897
|
readdirSync as readdirSync3,
|
|
1802
|
-
readFileSync as
|
|
1898
|
+
readFileSync as readFileSync16,
|
|
1803
1899
|
statSync as statSync2
|
|
1804
1900
|
} from "fs";
|
|
1805
|
-
import
|
|
1806
|
-
import
|
|
1901
|
+
import PATH11 from "path";
|
|
1902
|
+
import chalk18 from "chalk";
|
|
1807
1903
|
var checkCommands = (commandsDir) => {
|
|
1808
1904
|
const pm = detectPackageManager();
|
|
1809
1905
|
const rawTemplates = claudeCommandTemplates();
|
|
@@ -1814,15 +1910,15 @@ var checkCommands = (commandsDir) => {
|
|
|
1814
1910
|
const missing = [];
|
|
1815
1911
|
const outdated = [];
|
|
1816
1912
|
for (const [filename2, content] of Object.entries(templates)) {
|
|
1817
|
-
const targetPath =
|
|
1818
|
-
if (!
|
|
1913
|
+
const targetPath = PATH11.resolve(commandsDir, filename2);
|
|
1914
|
+
if (!existsSync7(targetPath)) {
|
|
1819
1915
|
missing.push(filename2);
|
|
1820
|
-
} else if (
|
|
1916
|
+
} else if (readFileSync16(targetPath, "utf8") !== content) {
|
|
1821
1917
|
outdated.push(filename2);
|
|
1822
1918
|
}
|
|
1823
1919
|
}
|
|
1824
1920
|
const templateNames = new Set(Object.keys(templates));
|
|
1825
|
-
const stale =
|
|
1921
|
+
const stale = existsSync7(commandsDir) ? readdirSync3(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md") && !templateNames.has(f)) : [];
|
|
1826
1922
|
return {
|
|
1827
1923
|
missing,
|
|
1828
1924
|
outdated,
|
|
@@ -1839,15 +1935,15 @@ var checkRules = (rulesDir) => {
|
|
|
1839
1935
|
const missing = [];
|
|
1840
1936
|
const outdated = [];
|
|
1841
1937
|
for (const [filename2, content] of Object.entries(templates)) {
|
|
1842
|
-
const targetPath =
|
|
1843
|
-
if (!
|
|
1938
|
+
const targetPath = PATH11.resolve(rulesDir, filename2);
|
|
1939
|
+
if (!existsSync7(targetPath)) {
|
|
1844
1940
|
missing.push(filename2);
|
|
1845
|
-
} else if (
|
|
1941
|
+
} else if (readFileSync16(targetPath, "utf8") !== content) {
|
|
1846
1942
|
outdated.push(filename2);
|
|
1847
1943
|
}
|
|
1848
1944
|
}
|
|
1849
1945
|
const templateNames = new Set(Object.keys(templates));
|
|
1850
|
-
const stale =
|
|
1946
|
+
const stale = existsSync7(rulesDir) ? readdirSync3(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md") && !templateNames.has(f)) : [];
|
|
1851
1947
|
return {
|
|
1852
1948
|
missing,
|
|
1853
1949
|
outdated,
|
|
@@ -1860,24 +1956,24 @@ var checkSkills = (skillsDir) => {
|
|
|
1860
1956
|
const missing = [];
|
|
1861
1957
|
const outdated = [];
|
|
1862
1958
|
for (const [skillName, files] of Object.entries(rawTemplates)) {
|
|
1863
|
-
const skillDir =
|
|
1864
|
-
if (!
|
|
1959
|
+
const skillDir = PATH11.resolve(skillsDir, skillName);
|
|
1960
|
+
if (!existsSync7(skillDir)) {
|
|
1865
1961
|
missing.push(skillName);
|
|
1866
1962
|
continue;
|
|
1867
1963
|
}
|
|
1868
1964
|
for (const [filename2, rawContent] of Object.entries(files)) {
|
|
1869
1965
|
const content = applyPackageManager(rawContent, pm);
|
|
1870
|
-
const targetPath =
|
|
1871
|
-
if (!
|
|
1966
|
+
const targetPath = PATH11.resolve(skillDir, filename2);
|
|
1967
|
+
if (!existsSync7(targetPath)) {
|
|
1872
1968
|
missing.push(`${skillName}/${filename2}`);
|
|
1873
|
-
} else if (
|
|
1969
|
+
} else if (readFileSync16(targetPath, "utf8") !== content) {
|
|
1874
1970
|
outdated.push(`${skillName}/${filename2}`);
|
|
1875
1971
|
}
|
|
1876
1972
|
}
|
|
1877
1973
|
}
|
|
1878
1974
|
const templateNames = new Set(Object.keys(rawTemplates));
|
|
1879
|
-
const stale =
|
|
1880
|
-
(f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync2(
|
|
1975
|
+
const stale = existsSync7(skillsDir) ? readdirSync3(skillsDir).filter(
|
|
1976
|
+
(f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync2(PATH11.resolve(skillsDir, f)).isDirectory() && !templateNames.has(f)
|
|
1881
1977
|
) : [];
|
|
1882
1978
|
return {
|
|
1883
1979
|
missing,
|
|
@@ -1888,81 +1984,81 @@ var checkSkills = (skillsDir) => {
|
|
|
1888
1984
|
var logSection = (label, result) => {
|
|
1889
1985
|
const issues = [...result.missing, ...result.outdated, ...result.stale];
|
|
1890
1986
|
if (issues.length === 0) {
|
|
1891
|
-
console.log(
|
|
1987
|
+
console.log(chalk18.green(` \u2714 ${label}`));
|
|
1892
1988
|
return true;
|
|
1893
1989
|
}
|
|
1894
|
-
console.log(
|
|
1990
|
+
console.log(chalk18.red(` \u2718 ${label}`));
|
|
1895
1991
|
for (const file of result.missing) {
|
|
1896
|
-
console.log(
|
|
1992
|
+
console.log(chalk18.yellow(` missing: ${file}`));
|
|
1897
1993
|
}
|
|
1898
1994
|
for (const file of result.outdated) {
|
|
1899
|
-
console.log(
|
|
1995
|
+
console.log(chalk18.yellow(` outdated: ${file}`));
|
|
1900
1996
|
}
|
|
1901
1997
|
for (const file of result.stale) {
|
|
1902
|
-
console.log(
|
|
1998
|
+
console.log(chalk18.yellow(` stale: ${file}`));
|
|
1903
1999
|
}
|
|
1904
2000
|
return false;
|
|
1905
2001
|
};
|
|
1906
2002
|
function claudeCheck() {
|
|
1907
2003
|
const cwd6 = INIT_CWD();
|
|
1908
|
-
const claudeDir =
|
|
1909
|
-
console.log(
|
|
2004
|
+
const claudeDir = PATH11.resolve(cwd6, ".claude");
|
|
2005
|
+
console.log(chalk18.bold("Claude configuration check:"));
|
|
1910
2006
|
console.log();
|
|
1911
|
-
const commandsResult = checkCommands(
|
|
1912
|
-
const rulesResult = checkRules(
|
|
1913
|
-
const skillsResult = checkSkills(
|
|
2007
|
+
const commandsResult = checkCommands(PATH11.resolve(claudeDir, "commands"));
|
|
2008
|
+
const rulesResult = checkRules(PATH11.resolve(claudeDir, "rules"));
|
|
2009
|
+
const skillsResult = checkSkills(PATH11.resolve(claudeDir, "skills"));
|
|
1914
2010
|
const commandsOk = logSection("commands", commandsResult);
|
|
1915
2011
|
const rulesOk = logSection("rules", rulesResult);
|
|
1916
2012
|
const skillsOk = logSection("skills", skillsResult);
|
|
1917
2013
|
console.log();
|
|
1918
2014
|
if (commandsOk && rulesOk && skillsOk) {
|
|
1919
|
-
console.log(
|
|
2015
|
+
console.log(chalk18.green("All Claude configuration is up to date."));
|
|
1920
2016
|
} else {
|
|
1921
|
-
console.log(
|
|
2017
|
+
console.log(chalk18.yellow("Run `xy claude init` to sync all configuration."));
|
|
1922
2018
|
}
|
|
1923
2019
|
return 0;
|
|
1924
2020
|
}
|
|
1925
2021
|
|
|
1926
2022
|
// src/actions/claude-clean.ts
|
|
1927
2023
|
import {
|
|
1928
|
-
existsSync as
|
|
2024
|
+
existsSync as existsSync8,
|
|
1929
2025
|
readdirSync as readdirSync4,
|
|
1930
2026
|
rmSync,
|
|
1931
2027
|
unlinkSync
|
|
1932
2028
|
} from "fs";
|
|
1933
|
-
import
|
|
1934
|
-
import
|
|
2029
|
+
import PATH12 from "path";
|
|
2030
|
+
import chalk19 from "chalk";
|
|
1935
2031
|
function removeFile(filePath, label) {
|
|
1936
|
-
if (
|
|
2032
|
+
if (existsSync8(filePath)) {
|
|
1937
2033
|
unlinkSync(filePath);
|
|
1938
|
-
console.log(
|
|
2034
|
+
console.log(chalk19.yellow(` Removed ${label}`));
|
|
1939
2035
|
return true;
|
|
1940
2036
|
}
|
|
1941
2037
|
return false;
|
|
1942
2038
|
}
|
|
1943
2039
|
function removeDir(dirPath, label) {
|
|
1944
|
-
if (
|
|
2040
|
+
if (existsSync8(dirPath)) {
|
|
1945
2041
|
rmSync(dirPath, { recursive: true });
|
|
1946
|
-
console.log(
|
|
2042
|
+
console.log(chalk19.yellow(` Removed ${label}`));
|
|
1947
2043
|
return true;
|
|
1948
2044
|
}
|
|
1949
2045
|
return false;
|
|
1950
2046
|
}
|
|
1951
2047
|
function claudeClean() {
|
|
1952
|
-
console.log(
|
|
2048
|
+
console.log(chalk19.green("Clean Claude configuration"));
|
|
1953
2049
|
const cwd6 = INIT_CWD();
|
|
1954
2050
|
let removed = 0;
|
|
1955
2051
|
const rootFiles = ["CLAUDE.md", "CLAUDE.local.md"];
|
|
1956
2052
|
for (const file of rootFiles) {
|
|
1957
|
-
if (removeFile(
|
|
2053
|
+
if (removeFile(PATH12.resolve(cwd6, file), file)) removed++;
|
|
1958
2054
|
}
|
|
1959
|
-
if (removeDir(
|
|
1960
|
-
const packagesDir =
|
|
1961
|
-
if (
|
|
2055
|
+
if (removeDir(PATH12.resolve(cwd6, ".claude"), ".claude/")) removed++;
|
|
2056
|
+
const packagesDir = PATH12.resolve(cwd6, "packages");
|
|
2057
|
+
if (existsSync8(packagesDir)) {
|
|
1962
2058
|
const findClaudeFiles = (dir, prefix) => {
|
|
1963
2059
|
const entries = readdirSync4(dir, { withFileTypes: true });
|
|
1964
2060
|
for (const entry of entries) {
|
|
1965
|
-
const fullPath =
|
|
2061
|
+
const fullPath = PATH12.resolve(dir, entry.name);
|
|
1966
2062
|
const label = `${prefix}${entry.name}`;
|
|
1967
2063
|
if (entry.isFile() && (entry.name === "CLAUDE.md" || entry.name === "CLAUDE.local.md")) {
|
|
1968
2064
|
if (removeFile(fullPath, label)) removed++;
|
|
@@ -1976,24 +2072,24 @@ function claudeClean() {
|
|
|
1976
2072
|
findClaudeFiles(packagesDir, "packages/");
|
|
1977
2073
|
}
|
|
1978
2074
|
if (removed > 0) {
|
|
1979
|
-
console.log(
|
|
2075
|
+
console.log(chalk19.green(` Removed ${removed} item(s)`));
|
|
1980
2076
|
} else {
|
|
1981
|
-
console.log(
|
|
2077
|
+
console.log(chalk19.gray(" Nothing to clean"));
|
|
1982
2078
|
}
|
|
1983
2079
|
return 0;
|
|
1984
2080
|
}
|
|
1985
2081
|
|
|
1986
2082
|
// src/actions/claude-commands.ts
|
|
1987
2083
|
import {
|
|
1988
|
-
existsSync as
|
|
2084
|
+
existsSync as existsSync9,
|
|
1989
2085
|
mkdirSync,
|
|
1990
2086
|
readdirSync as readdirSync5,
|
|
1991
|
-
readFileSync as
|
|
2087
|
+
readFileSync as readFileSync17,
|
|
1992
2088
|
unlinkSync as unlinkSync2,
|
|
1993
|
-
writeFileSync as
|
|
2089
|
+
writeFileSync as writeFileSync4
|
|
1994
2090
|
} from "fs";
|
|
1995
|
-
import
|
|
1996
|
-
import
|
|
2091
|
+
import PATH13 from "path";
|
|
2092
|
+
import chalk20 from "chalk";
|
|
1997
2093
|
var syncCommandFiles = (commandsDir) => {
|
|
1998
2094
|
const pm = detectPackageManager();
|
|
1999
2095
|
const rawTemplates = claudeCommandTemplates();
|
|
@@ -2005,10 +2101,10 @@ var syncCommandFiles = (commandsDir) => {
|
|
|
2005
2101
|
let updated = 0;
|
|
2006
2102
|
let created = 0;
|
|
2007
2103
|
for (const [filename2, content] of Object.entries(templates)) {
|
|
2008
|
-
const targetPath =
|
|
2009
|
-
const existing =
|
|
2104
|
+
const targetPath = PATH13.resolve(commandsDir, filename2);
|
|
2105
|
+
const existing = existsSync9(targetPath) ? readFileSync17(targetPath, "utf8") : void 0;
|
|
2010
2106
|
if (existing === content) continue;
|
|
2011
|
-
|
|
2107
|
+
writeFileSync4(targetPath, content, "utf8");
|
|
2012
2108
|
if (existing) {
|
|
2013
2109
|
updated++;
|
|
2014
2110
|
} else {
|
|
@@ -2026,7 +2122,7 @@ var removeStaleCommands = (commandsDir, templateNames) => {
|
|
|
2026
2122
|
let removed = 0;
|
|
2027
2123
|
for (const file of existingCommands) {
|
|
2028
2124
|
if (!templateNames.has(file)) {
|
|
2029
|
-
unlinkSync2(
|
|
2125
|
+
unlinkSync2(PATH13.resolve(commandsDir, file));
|
|
2030
2126
|
removed++;
|
|
2031
2127
|
}
|
|
2032
2128
|
}
|
|
@@ -2035,7 +2131,7 @@ var removeStaleCommands = (commandsDir, templateNames) => {
|
|
|
2035
2131
|
var removeLegacyCommands = (commandsDir) => {
|
|
2036
2132
|
const legacyFiles = readdirSync5(commandsDir).filter((f) => f.startsWith(LEGACY_COMMANDS_PREFIX) && f.endsWith(".md"));
|
|
2037
2133
|
for (const file of legacyFiles) {
|
|
2038
|
-
unlinkSync2(
|
|
2134
|
+
unlinkSync2(PATH13.resolve(commandsDir, file));
|
|
2039
2135
|
}
|
|
2040
2136
|
return legacyFiles.length;
|
|
2041
2137
|
};
|
|
@@ -2046,14 +2142,14 @@ var logCommandsResult = (created, updated, removed) => {
|
|
|
2046
2142
|
updated ? `${updated} updated` : "",
|
|
2047
2143
|
removed ? `${removed} removed` : ""
|
|
2048
2144
|
].filter(Boolean);
|
|
2049
|
-
console.log(
|
|
2145
|
+
console.log(chalk20.green(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: ${parts.join(", ")}`));
|
|
2050
2146
|
} else {
|
|
2051
|
-
console.log(
|
|
2147
|
+
console.log(chalk20.gray(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: already up to date`));
|
|
2052
2148
|
}
|
|
2053
2149
|
};
|
|
2054
2150
|
var claudeCommands = () => {
|
|
2055
2151
|
const cwd6 = INIT_CWD();
|
|
2056
|
-
const commandsDir =
|
|
2152
|
+
const commandsDir = PATH13.resolve(cwd6, ".claude", "commands");
|
|
2057
2153
|
mkdirSync(commandsDir, { recursive: true });
|
|
2058
2154
|
const legacy = removeLegacyCommands(commandsDir);
|
|
2059
2155
|
const {
|
|
@@ -2069,15 +2165,15 @@ var claudeCommands = () => {
|
|
|
2069
2165
|
// src/actions/claude-rules.ts
|
|
2070
2166
|
import { spawnSync as spawnSync8 } from "child_process";
|
|
2071
2167
|
import {
|
|
2072
|
-
existsSync as
|
|
2168
|
+
existsSync as existsSync10,
|
|
2073
2169
|
mkdirSync as mkdirSync2,
|
|
2074
2170
|
readdirSync as readdirSync6,
|
|
2075
|
-
readFileSync as
|
|
2171
|
+
readFileSync as readFileSync18,
|
|
2076
2172
|
unlinkSync as unlinkSync3,
|
|
2077
|
-
writeFileSync as
|
|
2173
|
+
writeFileSync as writeFileSync5
|
|
2078
2174
|
} from "fs";
|
|
2079
|
-
import
|
|
2080
|
-
import
|
|
2175
|
+
import PATH14 from "path";
|
|
2176
|
+
import chalk21 from "chalk";
|
|
2081
2177
|
var syncRuleFiles = (rulesDir) => {
|
|
2082
2178
|
const pm = detectPackageManager();
|
|
2083
2179
|
const rawTemplates = claudeMdRuleTemplates();
|
|
@@ -2089,10 +2185,10 @@ var syncRuleFiles = (rulesDir) => {
|
|
|
2089
2185
|
let updated = 0;
|
|
2090
2186
|
let created = 0;
|
|
2091
2187
|
for (const [filename2, content] of Object.entries(templates)) {
|
|
2092
|
-
const targetPath =
|
|
2093
|
-
const existing =
|
|
2188
|
+
const targetPath = PATH14.resolve(rulesDir, filename2);
|
|
2189
|
+
const existing = existsSync10(targetPath) ? readFileSync18(targetPath, "utf8") : void 0;
|
|
2094
2190
|
if (existing === content) continue;
|
|
2095
|
-
|
|
2191
|
+
writeFileSync5(targetPath, content, "utf8");
|
|
2096
2192
|
if (existing) {
|
|
2097
2193
|
updated++;
|
|
2098
2194
|
} else {
|
|
@@ -2110,7 +2206,7 @@ var removeStaleRules = (rulesDir, templateNames) => {
|
|
|
2110
2206
|
let removed = 0;
|
|
2111
2207
|
for (const file of existingRules) {
|
|
2112
2208
|
if (!templateNames.has(file)) {
|
|
2113
|
-
unlinkSync3(
|
|
2209
|
+
unlinkSync3(PATH14.resolve(rulesDir, file));
|
|
2114
2210
|
removed++;
|
|
2115
2211
|
}
|
|
2116
2212
|
}
|
|
@@ -2123,44 +2219,44 @@ var logRulesResult = (created, updated, removed) => {
|
|
|
2123
2219
|
updated ? `${updated} updated` : "",
|
|
2124
2220
|
removed ? `${removed} removed` : ""
|
|
2125
2221
|
].filter(Boolean);
|
|
2126
|
-
console.log(
|
|
2222
|
+
console.log(chalk21.green(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: ${parts.join(", ")}`));
|
|
2127
2223
|
} else {
|
|
2128
|
-
console.log(
|
|
2224
|
+
console.log(chalk21.gray(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: already up to date`));
|
|
2129
2225
|
}
|
|
2130
2226
|
};
|
|
2131
2227
|
var ensureProjectClaudeMd = (cwd6, force) => {
|
|
2132
|
-
const projectPath =
|
|
2133
|
-
if (!
|
|
2134
|
-
if (force &&
|
|
2135
|
-
console.log(
|
|
2228
|
+
const projectPath = PATH14.resolve(cwd6, "CLAUDE.md");
|
|
2229
|
+
if (!existsSync10(projectPath) || force) {
|
|
2230
|
+
if (force && existsSync10(projectPath)) {
|
|
2231
|
+
console.log(chalk21.yellow("Regenerating CLAUDE.md"));
|
|
2136
2232
|
}
|
|
2137
|
-
console.log(
|
|
2233
|
+
console.log(chalk21.green("Generating CLAUDE.md via claude /init..."));
|
|
2138
2234
|
const result = spawnSync8("claude", ["-p", "/init", "--allowedTools", "Read", "Write", "Glob", "Grep"], {
|
|
2139
2235
|
cwd: cwd6,
|
|
2140
2236
|
shell: true,
|
|
2141
2237
|
stdio: "inherit"
|
|
2142
2238
|
});
|
|
2143
2239
|
if (result.status !== 0) {
|
|
2144
|
-
console.error(
|
|
2240
|
+
console.error(chalk21.red("claude /init failed \u2014 is Claude Code installed?"));
|
|
2145
2241
|
return 1;
|
|
2146
2242
|
}
|
|
2147
2243
|
} else {
|
|
2148
|
-
console.log(
|
|
2244
|
+
console.log(chalk21.gray("CLAUDE.md already exists (skipped, use --force to regenerate)"));
|
|
2149
2245
|
}
|
|
2150
2246
|
return 0;
|
|
2151
2247
|
};
|
|
2152
2248
|
var ensureLocalClaudeMd = (cwd6) => {
|
|
2153
|
-
const localPath =
|
|
2154
|
-
if (
|
|
2155
|
-
console.log(
|
|
2249
|
+
const localPath = PATH14.resolve(cwd6, "CLAUDE.local.md");
|
|
2250
|
+
if (existsSync10(localPath)) {
|
|
2251
|
+
console.log(chalk21.gray("CLAUDE.local.md already exists (skipped)"));
|
|
2156
2252
|
} else {
|
|
2157
|
-
|
|
2158
|
-
console.log(
|
|
2253
|
+
writeFileSync5(localPath, claudeMdLocalTemplate(), "utf8");
|
|
2254
|
+
console.log(chalk21.green("Generated CLAUDE.local.md"));
|
|
2159
2255
|
}
|
|
2160
2256
|
};
|
|
2161
2257
|
var claudeRules = ({ force } = {}) => {
|
|
2162
2258
|
const cwd6 = INIT_CWD();
|
|
2163
|
-
const rulesDir =
|
|
2259
|
+
const rulesDir = PATH14.resolve(cwd6, ".claude", "rules");
|
|
2164
2260
|
mkdirSync2(rulesDir, { recursive: true });
|
|
2165
2261
|
const {
|
|
2166
2262
|
created,
|
|
@@ -2176,13 +2272,13 @@ var claudeRules = ({ force } = {}) => {
|
|
|
2176
2272
|
|
|
2177
2273
|
// src/actions/claude-settings.ts
|
|
2178
2274
|
import {
|
|
2179
|
-
existsSync as
|
|
2275
|
+
existsSync as existsSync11,
|
|
2180
2276
|
mkdirSync as mkdirSync3,
|
|
2181
|
-
writeFileSync as
|
|
2277
|
+
writeFileSync as writeFileSync6
|
|
2182
2278
|
} from "fs";
|
|
2183
|
-
import
|
|
2184
|
-
import { createInterface as
|
|
2185
|
-
import
|
|
2279
|
+
import PATH15 from "path";
|
|
2280
|
+
import { createInterface as createInterface3 } from "readline";
|
|
2281
|
+
import chalk22 from "chalk";
|
|
2186
2282
|
var DENY_LIST = [
|
|
2187
2283
|
"Bash(git push --force *)",
|
|
2188
2284
|
"Bash(git reset --hard *)",
|
|
@@ -2234,7 +2330,7 @@ function buildSettings(level) {
|
|
|
2234
2330
|
};
|
|
2235
2331
|
}
|
|
2236
2332
|
function askConfirmation2(question) {
|
|
2237
|
-
const rl =
|
|
2333
|
+
const rl = createInterface3({ input: process.stdin, output: process.stdout });
|
|
2238
2334
|
return new Promise((resolve) => {
|
|
2239
2335
|
rl.question(question, (answer) => {
|
|
2240
2336
|
rl.close();
|
|
@@ -2244,37 +2340,37 @@ function askConfirmation2(question) {
|
|
|
2244
2340
|
}
|
|
2245
2341
|
async function claudeSettings({ level = "permissive" } = {}) {
|
|
2246
2342
|
const cwd6 = INIT_CWD();
|
|
2247
|
-
const claudeDir =
|
|
2248
|
-
const settingsPath =
|
|
2343
|
+
const claudeDir = PATH15.resolve(cwd6, ".claude");
|
|
2344
|
+
const settingsPath = PATH15.resolve(claudeDir, "settings.local.json");
|
|
2249
2345
|
mkdirSync3(claudeDir, { recursive: true });
|
|
2250
|
-
if (
|
|
2346
|
+
if (existsSync11(settingsPath)) {
|
|
2251
2347
|
const confirmed = await askConfirmation2(
|
|
2252
|
-
|
|
2348
|
+
chalk22.yellow(`${settingsPath} already exists. Replace it? (y/N) `)
|
|
2253
2349
|
);
|
|
2254
2350
|
if (!confirmed) {
|
|
2255
|
-
console.log(
|
|
2351
|
+
console.log(chalk22.gray("Skipped \u2014 existing settings.local.json preserved"));
|
|
2256
2352
|
return 0;
|
|
2257
2353
|
}
|
|
2258
2354
|
}
|
|
2259
2355
|
const settings = buildSettings(level);
|
|
2260
|
-
|
|
2356
|
+
writeFileSync6(settingsPath, `${JSON.stringify(settings, null, 2)}
|
|
2261
2357
|
`, "utf8");
|
|
2262
|
-
console.log(
|
|
2358
|
+
console.log(chalk22.green(`Generated .claude/settings.local.json (${level})`));
|
|
2263
2359
|
return 0;
|
|
2264
2360
|
}
|
|
2265
2361
|
|
|
2266
2362
|
// src/actions/claude-skills.ts
|
|
2267
2363
|
import {
|
|
2268
|
-
existsSync as
|
|
2364
|
+
existsSync as existsSync12,
|
|
2269
2365
|
mkdirSync as mkdirSync4,
|
|
2270
2366
|
readdirSync as readdirSync7,
|
|
2271
|
-
readFileSync as
|
|
2367
|
+
readFileSync as readFileSync19,
|
|
2272
2368
|
rmSync as rmSync2,
|
|
2273
2369
|
statSync as statSync3,
|
|
2274
|
-
writeFileSync as
|
|
2370
|
+
writeFileSync as writeFileSync7
|
|
2275
2371
|
} from "fs";
|
|
2276
|
-
import
|
|
2277
|
-
import
|
|
2372
|
+
import PATH16 from "path";
|
|
2373
|
+
import chalk23 from "chalk";
|
|
2278
2374
|
var syncSkillFiles = (skillsDir) => {
|
|
2279
2375
|
const pm = detectPackageManager();
|
|
2280
2376
|
const rawTemplates = claudeSkillTemplates();
|
|
@@ -2282,15 +2378,15 @@ var syncSkillFiles = (skillsDir) => {
|
|
|
2282
2378
|
let updated = 0;
|
|
2283
2379
|
let created = 0;
|
|
2284
2380
|
for (const [skillName, files] of Object.entries(rawTemplates)) {
|
|
2285
|
-
const skillDir =
|
|
2381
|
+
const skillDir = PATH16.resolve(skillsDir, skillName);
|
|
2286
2382
|
mkdirSync4(skillDir, { recursive: true });
|
|
2287
2383
|
for (const [filename2, rawContent] of Object.entries(files)) {
|
|
2288
2384
|
const content = applyPackageManager(rawContent, pm);
|
|
2289
|
-
const targetPath =
|
|
2290
|
-
mkdirSync4(
|
|
2291
|
-
const existing =
|
|
2385
|
+
const targetPath = PATH16.resolve(skillDir, filename2);
|
|
2386
|
+
mkdirSync4(PATH16.dirname(targetPath), { recursive: true });
|
|
2387
|
+
const existing = existsSync12(targetPath) ? readFileSync19(targetPath, "utf8") : void 0;
|
|
2292
2388
|
if (existing === content) continue;
|
|
2293
|
-
|
|
2389
|
+
writeFileSync7(targetPath, content, "utf8");
|
|
2294
2390
|
if (existing) {
|
|
2295
2391
|
updated++;
|
|
2296
2392
|
} else {
|
|
@@ -2306,12 +2402,12 @@ var syncSkillFiles = (skillsDir) => {
|
|
|
2306
2402
|
};
|
|
2307
2403
|
var removeStaleSkills = (skillsDir, templateNames) => {
|
|
2308
2404
|
const existingSkills = readdirSync7(skillsDir).filter(
|
|
2309
|
-
(f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync3(
|
|
2405
|
+
(f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync3(PATH16.resolve(skillsDir, f)).isDirectory()
|
|
2310
2406
|
);
|
|
2311
2407
|
let removed = 0;
|
|
2312
2408
|
for (const dir of existingSkills) {
|
|
2313
2409
|
if (!templateNames.has(dir)) {
|
|
2314
|
-
rmSync2(
|
|
2410
|
+
rmSync2(PATH16.resolve(skillsDir, dir), { recursive: true });
|
|
2315
2411
|
removed++;
|
|
2316
2412
|
}
|
|
2317
2413
|
}
|
|
@@ -2324,14 +2420,14 @@ var logSkillsResult = (created, updated, removed) => {
|
|
|
2324
2420
|
updated ? `${updated} updated` : "",
|
|
2325
2421
|
removed ? `${removed} removed` : ""
|
|
2326
2422
|
].filter(Boolean);
|
|
2327
|
-
console.log(
|
|
2423
|
+
console.log(chalk23.green(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: ${parts.join(", ")}`));
|
|
2328
2424
|
} else {
|
|
2329
|
-
console.log(
|
|
2425
|
+
console.log(chalk23.gray(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: already up to date`));
|
|
2330
2426
|
}
|
|
2331
2427
|
};
|
|
2332
2428
|
var claudeSkills = () => {
|
|
2333
2429
|
const cwd6 = INIT_CWD();
|
|
2334
|
-
const skillsDir =
|
|
2430
|
+
const skillsDir = PATH16.resolve(cwd6, ".claude", "skills");
|
|
2335
2431
|
mkdirSync4(skillsDir, { recursive: true });
|
|
2336
2432
|
const {
|
|
2337
2433
|
created,
|
|
@@ -2358,21 +2454,21 @@ var cleanAll = ({ verbose }) => {
|
|
|
2358
2454
|
|
|
2359
2455
|
// src/actions/clean-docs.ts
|
|
2360
2456
|
import path2 from "path";
|
|
2361
|
-
import
|
|
2457
|
+
import chalk24 from "chalk";
|
|
2362
2458
|
var cleanDocs = () => {
|
|
2363
2459
|
const pkgName = packageName();
|
|
2364
|
-
console.log(
|
|
2460
|
+
console.log(chalk24.green(`Cleaning Docs [${pkgName}]`));
|
|
2365
2461
|
for (const { location } of getPackageManager().listWorkspaces()) deleteGlob(path2.join(location, "docs"));
|
|
2366
2462
|
return 0;
|
|
2367
2463
|
};
|
|
2368
2464
|
|
|
2369
2465
|
// src/actions/clean-eslint.ts
|
|
2370
2466
|
import path3 from "path";
|
|
2371
|
-
import
|
|
2467
|
+
import chalk25 from "chalk";
|
|
2372
2468
|
var cleanESLint = () => {
|
|
2373
2469
|
const pkg = INIT_CWD();
|
|
2374
2470
|
const pkgName = packageName();
|
|
2375
|
-
console.log(
|
|
2471
|
+
console.log(chalk25.green(`Cleaning ESLint [${pkgName}]`));
|
|
2376
2472
|
deleteGlob(path3.join(pkg, ".eslintcache"));
|
|
2377
2473
|
return 0;
|
|
2378
2474
|
};
|
|
@@ -2427,7 +2523,7 @@ var compileAll = ({
|
|
|
2427
2523
|
|
|
2428
2524
|
// src/actions/copy-assets.ts
|
|
2429
2525
|
import path4 from "path/posix";
|
|
2430
|
-
import
|
|
2526
|
+
import chalk26 from "chalk";
|
|
2431
2527
|
import cpy from "cpy";
|
|
2432
2528
|
var copyPackageTargetAssets = async (target, name, location) => {
|
|
2433
2529
|
try {
|
|
@@ -2450,7 +2546,7 @@ var copyPackageTargetAssets = async (target, name, location) => {
|
|
|
2450
2546
|
};
|
|
2451
2547
|
var copyTargetAssets = async (target, pkg) => {
|
|
2452
2548
|
const workspaces = getPackageManager().listWorkspaces();
|
|
2453
|
-
console.log(
|
|
2549
|
+
console.log(chalk26.green(`Copying Assets [${target.toUpperCase()}]`));
|
|
2454
2550
|
const workspaceList = workspaces.filter(({ name }) => {
|
|
2455
2551
|
return pkg === void 0 || name === pkg;
|
|
2456
2552
|
});
|
|
@@ -2549,11 +2645,11 @@ var dead = () => {
|
|
|
2549
2645
|
};
|
|
2550
2646
|
|
|
2551
2647
|
// src/actions/deplint/deplint.ts
|
|
2552
|
-
import
|
|
2648
|
+
import chalk38 from "chalk";
|
|
2553
2649
|
|
|
2554
2650
|
// src/actions/deplint/packageJsonEditor.ts
|
|
2555
2651
|
import fs3 from "fs";
|
|
2556
|
-
import
|
|
2652
|
+
import chalk27 from "chalk";
|
|
2557
2653
|
import sortPackageJson from "sort-package-json";
|
|
2558
2654
|
|
|
2559
2655
|
// src/actions/deplint/getRequiredPeerDependencies.ts
|
|
@@ -2974,7 +3070,7 @@ function getExternalImportsFromFiles({
|
|
|
2974
3070
|
}
|
|
2975
3071
|
|
|
2976
3072
|
// src/actions/deplint/checkPackage/getMismatchedPeerDevVersions.ts
|
|
2977
|
-
import
|
|
3073
|
+
import chalk28 from "chalk";
|
|
2978
3074
|
import semver4 from "semver";
|
|
2979
3075
|
function findMismatchedPeerDevVersions({
|
|
2980
3076
|
peerDependencies,
|
|
@@ -3001,7 +3097,7 @@ function findMismatchedPeerDevVersions({
|
|
|
3001
3097
|
// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
|
|
3002
3098
|
import fs9 from "fs";
|
|
3003
3099
|
import { builtinModules } from "module";
|
|
3004
|
-
import
|
|
3100
|
+
import chalk29 from "chalk";
|
|
3005
3101
|
|
|
3006
3102
|
// src/actions/deplint/tsScriptsAliases.ts
|
|
3007
3103
|
var VARIANT_MAP = {
|
|
@@ -3058,7 +3154,7 @@ function findUnlistedDependencies(name, dependencies, devDependencies, peerDepen
|
|
|
3058
3154
|
|
|
3059
3155
|
// src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
|
|
3060
3156
|
import { builtinModules as builtinModules2 } from "module";
|
|
3061
|
-
import
|
|
3157
|
+
import chalk30 from "chalk";
|
|
3062
3158
|
function findUnlistedDevDeps(name, dependencies, devDependencies, peerDependencies, externalAllImports, distImports, externalDistTypeImports) {
|
|
3063
3159
|
const results = [];
|
|
3064
3160
|
for (const imp of externalAllImports) {
|
|
@@ -3071,11 +3167,11 @@ function findUnlistedDevDeps(name, dependencies, devDependencies, peerDependenci
|
|
|
3071
3167
|
|
|
3072
3168
|
// src/actions/deplint/checkPackage/getUnnecessaryPeerDependencies.ts
|
|
3073
3169
|
import fs11 from "fs";
|
|
3074
|
-
import
|
|
3170
|
+
import chalk32 from "chalk";
|
|
3075
3171
|
|
|
3076
3172
|
// src/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.ts
|
|
3077
3173
|
import fs10 from "fs";
|
|
3078
|
-
import
|
|
3174
|
+
import chalk31 from "chalk";
|
|
3079
3175
|
import semver5 from "semver";
|
|
3080
3176
|
import sortPackageJson2 from "sort-package-json";
|
|
3081
3177
|
function readDepPackageJson(location, dep) {
|
|
@@ -3272,7 +3368,7 @@ function findRedundantPeerDeps({ peerDependencies, dependencies }, exclude) {
|
|
|
3272
3368
|
}
|
|
3273
3369
|
|
|
3274
3370
|
// src/actions/deplint/checkPackage/getUnusedDependencies.ts
|
|
3275
|
-
import
|
|
3371
|
+
import chalk33 from "chalk";
|
|
3276
3372
|
function isDepImported(dep, distImports, distTypeImports) {
|
|
3277
3373
|
const baseName = dep.replace(/^@types\//, "");
|
|
3278
3374
|
return distImports.includes(dep) || distImports.includes(baseName) || distTypeImports.includes(dep) || distTypeImports.includes(baseName);
|
|
@@ -3302,7 +3398,7 @@ function findUnusedDependencies(location, dependencies, devDependencies, externa
|
|
|
3302
3398
|
}
|
|
3303
3399
|
|
|
3304
3400
|
// src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
|
|
3305
|
-
import
|
|
3401
|
+
import chalk34 from "chalk";
|
|
3306
3402
|
|
|
3307
3403
|
// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
|
|
3308
3404
|
import fs13 from "fs";
|
|
@@ -3584,7 +3680,7 @@ function findUnusedDevDeps(location, dependencies, devDependencies, peerDependen
|
|
|
3584
3680
|
}
|
|
3585
3681
|
|
|
3586
3682
|
// src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
|
|
3587
|
-
import
|
|
3683
|
+
import chalk35 from "chalk";
|
|
3588
3684
|
function isPeerUsed(dep, externalDistImports, externalDistTypeImports) {
|
|
3589
3685
|
const baseName = dep.replace(/^@types\//, "");
|
|
3590
3686
|
return externalDistImports.includes(dep) || externalDistImports.includes(baseName) || externalDistTypeImports.includes(dep) || externalDistTypeImports.includes(baseName);
|
|
@@ -3601,7 +3697,7 @@ function findUnusedPeerDeps(peerDependencies, externalDistImports, externalDistT
|
|
|
3601
3697
|
}
|
|
3602
3698
|
|
|
3603
3699
|
// src/actions/deplint/checkPackage/getWorkspaceVersionProblems.ts
|
|
3604
|
-
import
|
|
3700
|
+
import chalk36 from "chalk";
|
|
3605
3701
|
import semver6 from "semver";
|
|
3606
3702
|
function checkSection(deps, versions, section, workspaceNames, problems) {
|
|
3607
3703
|
for (const dep of deps) {
|
|
@@ -4210,25 +4306,25 @@ async function runDeplint(workspaces, options, workspaceNames) {
|
|
|
4210
4306
|
}
|
|
4211
4307
|
|
|
4212
4308
|
// src/actions/deplint/reporters.ts
|
|
4213
|
-
import
|
|
4309
|
+
import chalk37 from "chalk";
|
|
4214
4310
|
var humanDeplintReporter = {
|
|
4215
4311
|
render(result) {
|
|
4216
4312
|
for (const fix2 of result.appliedFixes) {
|
|
4217
|
-
console.log(`[${
|
|
4313
|
+
console.log(`[${chalk37.blue(fix2.workspace.name)}] Fixed: ${fix2.detail} ${chalk37.green(fix2.dependency)}`);
|
|
4218
4314
|
}
|
|
4219
4315
|
for (const diagnostic2 of result.diagnostics) {
|
|
4220
|
-
console.log(`[${
|
|
4316
|
+
console.log(`[${chalk37.blue(diagnostic2.workspace.name)}] ${diagnostic2.message}`);
|
|
4221
4317
|
for (const line of diagnostic2.evidence ?? []) {
|
|
4222
4318
|
console.log(` ${line}`);
|
|
4223
4319
|
}
|
|
4224
|
-
console.log(` ${
|
|
4320
|
+
console.log(` ${chalk37.yellow(diagnostic2.file)}
|
|
4225
4321
|
`);
|
|
4226
4322
|
}
|
|
4227
4323
|
if (result.summary.errorCount > 0) {
|
|
4228
|
-
console.warn(`Deplint: Found ${
|
|
4324
|
+
console.warn(`Deplint: Found ${chalk37.red(result.summary.errorCount)} dependency problems. ${chalk37.red("\u2716")}`);
|
|
4229
4325
|
return;
|
|
4230
4326
|
}
|
|
4231
|
-
console.info(`Deplint: Found no dependency problems. ${
|
|
4327
|
+
console.info(`Deplint: Found no dependency problems. ${chalk37.green("\u2714")}`);
|
|
4232
4328
|
}
|
|
4233
4329
|
};
|
|
4234
4330
|
var jsonDeplintReporter = {
|
|
@@ -4260,7 +4356,7 @@ var deplint = async ({
|
|
|
4260
4356
|
const targetWorkspace = pkg === void 0 ? void 0 : pm.findWorkspace(pkg);
|
|
4261
4357
|
const targetWorkspaces = pkg === void 0 ? workspaces : targetWorkspace ? [targetWorkspace] : [];
|
|
4262
4358
|
if (targetWorkspaces.length === 0) {
|
|
4263
|
-
console.error(
|
|
4359
|
+
console.error(chalk38.red(`Workspace not found: ${pkg}`));
|
|
4264
4360
|
return 1;
|
|
4265
4361
|
}
|
|
4266
4362
|
const result = await runDeplint(targetWorkspaces, {
|
|
@@ -4280,24 +4376,24 @@ var deplint = async ({
|
|
|
4280
4376
|
};
|
|
4281
4377
|
|
|
4282
4378
|
// src/actions/deploy.ts
|
|
4283
|
-
import { readFileSync as
|
|
4379
|
+
import { readFileSync as readFileSync21 } from "fs";
|
|
4284
4380
|
|
|
4285
4381
|
// src/actions/package-lint-deps.ts
|
|
4286
|
-
import { readFileSync as
|
|
4287
|
-
import
|
|
4288
|
-
import
|
|
4382
|
+
import { readFileSync as readFileSync20, writeFileSync as writeFileSync8 } from "fs";
|
|
4383
|
+
import PATH17 from "path";
|
|
4384
|
+
import chalk39 from "chalk";
|
|
4289
4385
|
import semver7 from "semver";
|
|
4290
4386
|
function readWorkspacePackageJson(cwd6, location) {
|
|
4291
|
-
const pkgPath =
|
|
4387
|
+
const pkgPath = PATH17.resolve(cwd6, location, "package.json");
|
|
4292
4388
|
try {
|
|
4293
|
-
return JSON.parse(
|
|
4389
|
+
return JSON.parse(readFileSync20(pkgPath, "utf8"));
|
|
4294
4390
|
} catch {
|
|
4295
4391
|
return void 0;
|
|
4296
4392
|
}
|
|
4297
4393
|
}
|
|
4298
4394
|
function writeWorkspacePackageJson(cwd6, location, pkg) {
|
|
4299
|
-
const pkgPath =
|
|
4300
|
-
|
|
4395
|
+
const pkgPath = PATH17.resolve(cwd6, location, "package.json");
|
|
4396
|
+
writeFileSync8(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
4301
4397
|
`, "utf8");
|
|
4302
4398
|
}
|
|
4303
4399
|
function buildWorkspaceVersionMap(cwd6, workspaces) {
|
|
@@ -4355,7 +4451,7 @@ function fixVersionConsistency(cwd6, rootPkg, writeRootPackageJson2, workspaces)
|
|
|
4355
4451
|
if (rootPkg.version !== void 0) {
|
|
4356
4452
|
delete rootPkg.version;
|
|
4357
4453
|
writeRootPackageJson2(cwd6, rootPkg);
|
|
4358
|
-
console.log(
|
|
4454
|
+
console.log(chalk39.green(' \u2714 Fixed: removed "version" from root package.json'));
|
|
4359
4455
|
}
|
|
4360
4456
|
const versions = [];
|
|
4361
4457
|
for (const { location } of workspaces) {
|
|
@@ -4376,7 +4472,7 @@ function fixVersionConsistency(cwd6, rootPkg, writeRootPackageJson2, workspaces)
|
|
|
4376
4472
|
if (pkg.version !== highest) {
|
|
4377
4473
|
pkg.version = highest;
|
|
4378
4474
|
writeWorkspacePackageJson(cwd6, location, pkg);
|
|
4379
|
-
console.log(
|
|
4475
|
+
console.log(chalk39.green(` \u2714 Fixed: set version to ${highest} in ${name} (${location})`));
|
|
4380
4476
|
}
|
|
4381
4477
|
}
|
|
4382
4478
|
}
|
|
@@ -4431,7 +4527,7 @@ function fixInternalDepVersions(cwd6, workspaces) {
|
|
|
4431
4527
|
const expected = expectedDepVersion(targetVersion);
|
|
4432
4528
|
if (version !== expected) {
|
|
4433
4529
|
deps[dep] = expected;
|
|
4434
|
-
console.log(
|
|
4530
|
+
console.log(chalk39.green(` \u2714 Fixed: set ${depField}.${dep} to "${expected}" in ${name} (${location})`));
|
|
4435
4531
|
modified = true;
|
|
4436
4532
|
}
|
|
4437
4533
|
}
|
|
@@ -4479,7 +4575,7 @@ function fixWorkspaceProtocol(cwd6, workspaces) {
|
|
|
4479
4575
|
if (!workspaceNames.has(dep)) continue;
|
|
4480
4576
|
if (!version.startsWith("workspace:")) {
|
|
4481
4577
|
deps[dep] = "workspace:~";
|
|
4482
|
-
console.log(
|
|
4578
|
+
console.log(chalk39.green(` \u2714 Fixed: set ${depField}.${dep} to "workspace:~" in ${name} (${location})`));
|
|
4483
4579
|
modified = true;
|
|
4484
4580
|
}
|
|
4485
4581
|
}
|
|
@@ -4537,7 +4633,7 @@ function fixInternalPeerVersions(cwd6, workspaces) {
|
|
|
4537
4633
|
const expected = expectedPeerRange(devDeps?.[dep], targetVersion);
|
|
4538
4634
|
if (version !== expected) {
|
|
4539
4635
|
peerDeps[dep] = expected;
|
|
4540
|
-
console.log(
|
|
4636
|
+
console.log(chalk39.green(` \u2714 Fixed: set peerDependencies.${dep} to "${expected}" in ${name} (${location})`));
|
|
4541
4637
|
modified = true;
|
|
4542
4638
|
}
|
|
4543
4639
|
}
|
|
@@ -4564,7 +4660,7 @@ function syncInternalPeerVersions() {
|
|
|
4564
4660
|
const expected = expectedPeerRange(devDeps?.[dep], targetVersion);
|
|
4565
4661
|
if (version !== expected) {
|
|
4566
4662
|
peerDeps[dep] = expected;
|
|
4567
|
-
console.log(
|
|
4663
|
+
console.log(chalk39.green(`Publish: updated ${name} peerDependencies.${dep} to "${expected}"`));
|
|
4568
4664
|
modified = true;
|
|
4569
4665
|
updated++;
|
|
4570
4666
|
}
|
|
@@ -4584,8 +4680,8 @@ function logMonorepoVersion() {
|
|
|
4584
4680
|
if (!pkg) continue;
|
|
4585
4681
|
const version = pkg.version;
|
|
4586
4682
|
if (version) {
|
|
4587
|
-
console.log(
|
|
4588
|
-
Deployed version: ${
|
|
4683
|
+
console.log(chalk39.green(`
|
|
4684
|
+
Deployed version: ${chalk39.bold(version)}`));
|
|
4589
4685
|
return;
|
|
4590
4686
|
}
|
|
4591
4687
|
}
|
|
@@ -4596,7 +4692,7 @@ var privatePackageExcludeList = () => {
|
|
|
4596
4692
|
const pm = getPackageManager();
|
|
4597
4693
|
const possibleDeployablePackages = pm.listWorkspaces().map((workspace) => [
|
|
4598
4694
|
workspace,
|
|
4599
|
-
JSON.parse(
|
|
4695
|
+
JSON.parse(readFileSync21(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
4600
4696
|
]);
|
|
4601
4697
|
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
4602
4698
|
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
@@ -4620,9 +4716,9 @@ function deploy(level = "patch") {
|
|
|
4620
4716
|
}
|
|
4621
4717
|
|
|
4622
4718
|
// src/actions/dupdeps.ts
|
|
4623
|
-
import
|
|
4719
|
+
import chalk40 from "chalk";
|
|
4624
4720
|
var dupdeps = () => {
|
|
4625
|
-
console.log(
|
|
4721
|
+
console.log(chalk40.green("Checking all Dependencies for Duplicates"));
|
|
4626
4722
|
const pkg = parsedPackageJSON();
|
|
4627
4723
|
const allDependencies = {
|
|
4628
4724
|
...pkg?.dependencies,
|
|
@@ -4640,21 +4736,21 @@ var eject = () => {
|
|
|
4640
4736
|
|
|
4641
4737
|
// src/actions/lintNext.ts
|
|
4642
4738
|
import path10 from "path";
|
|
4643
|
-
import
|
|
4739
|
+
import chalk41 from "chalk";
|
|
4644
4740
|
import { ESLint } from "eslint";
|
|
4645
4741
|
var dumpMessages = (lintResults) => {
|
|
4646
4742
|
const colors = ["white", "yellow", "red"];
|
|
4647
4743
|
const severity = ["none", "warning", "error"];
|
|
4648
4744
|
for (const lintResult of lintResults) {
|
|
4649
4745
|
if (lintResult.messages.length > 0) {
|
|
4650
|
-
console.log(
|
|
4746
|
+
console.log(chalk41.gray(`
|
|
4651
4747
|
${lintResult.filePath}`));
|
|
4652
4748
|
for (const message of lintResult.messages) {
|
|
4653
4749
|
console.log(
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4750
|
+
chalk41.gray(` ${message.line}:${message.column}`),
|
|
4751
|
+
chalk41[colors[message.severity]](` ${severity[message.severity]}`),
|
|
4752
|
+
chalk41.white(` ${message.message}`),
|
|
4753
|
+
chalk41.gray(` ${message.ruleId}`)
|
|
4658
4754
|
);
|
|
4659
4755
|
}
|
|
4660
4756
|
}
|
|
@@ -4684,7 +4780,7 @@ async function lintOnePackage({
|
|
|
4684
4780
|
const files = lintResults.length;
|
|
4685
4781
|
if (verbose) {
|
|
4686
4782
|
const filesColor = files < 100 ? "green" : files < 1e3 ? "yellow" : "red";
|
|
4687
|
-
console.log(
|
|
4783
|
+
console.log(chalk41.white(` ${chalk41[filesColor](files)} files linted`));
|
|
4688
4784
|
}
|
|
4689
4785
|
return {
|
|
4690
4786
|
errors,
|
|
@@ -4704,7 +4800,7 @@ async function lintNext({
|
|
|
4704
4800
|
const allWorkspaces = pm.listWorkspaces();
|
|
4705
4801
|
const workspaces = pkg ? allWorkspaces.filter((ws) => ws.name === pkg) : allWorkspaces;
|
|
4706
4802
|
if (workspaces.length === 0) {
|
|
4707
|
-
console.log(
|
|
4803
|
+
console.log(chalk41.red(pkg ? `Package "${pkg}" not found` : "No workspaces found"));
|
|
4708
4804
|
return 1;
|
|
4709
4805
|
}
|
|
4710
4806
|
const concurrency = jobs;
|
|
@@ -4729,7 +4825,7 @@ async function lintNext({
|
|
|
4729
4825
|
await outputStorage.run(output, async () => {
|
|
4730
4826
|
const pkgStart = Date.now();
|
|
4731
4827
|
const absCwd = path10.resolve(rootDir, ws.location);
|
|
4732
|
-
console.log(
|
|
4828
|
+
console.log(chalk41.green(`${label} [${ws.name}]`));
|
|
4733
4829
|
try {
|
|
4734
4830
|
const {
|
|
4735
4831
|
errors,
|
|
@@ -4751,7 +4847,7 @@ async function lintNext({
|
|
|
4751
4847
|
warnings
|
|
4752
4848
|
};
|
|
4753
4849
|
} catch (ex) {
|
|
4754
|
-
output.push(
|
|
4850
|
+
output.push(chalk41.red(`${label} failed for ${ws.name}: ${ex.message}
|
|
4755
4851
|
`));
|
|
4756
4852
|
results[i] = {
|
|
4757
4853
|
errors: 1,
|
|
@@ -4779,7 +4875,7 @@ async function lintNext({
|
|
|
4779
4875
|
const errColor = totalErrors > 0 ? "red" : "green";
|
|
4780
4876
|
const warnColor = totalWarnings > 0 ? "yellow" : "green";
|
|
4781
4877
|
console.log(
|
|
4782
|
-
|
|
4878
|
+
chalk41[errColor](`${totalErrors} errors`) + chalk41.gray(", ") + chalk41[warnColor](`${totalWarnings} warnings`) + chalk41.gray(` across ${totalFiles} files in ${workspaces.length} packages`)
|
|
4783
4879
|
);
|
|
4784
4880
|
return totalErrors;
|
|
4785
4881
|
}
|
|
@@ -4851,7 +4947,7 @@ var genDocsAll = ({ incremental, jobs }) => {
|
|
|
4851
4947
|
|
|
4852
4948
|
// src/actions/gitignore.ts
|
|
4853
4949
|
import { unlinkSync as unlinkSync4 } from "fs";
|
|
4854
|
-
import
|
|
4950
|
+
import chalk42 from "chalk";
|
|
4855
4951
|
var COMMENT_PREFIX = "#";
|
|
4856
4952
|
var isComment = (line) => line.startsWith(COMMENT_PREFIX);
|
|
4857
4953
|
var isNegation = (line) => line.startsWith("!");
|
|
@@ -4908,7 +5004,7 @@ function removePackageGitignores(cwd6) {
|
|
|
4908
5004
|
const filePath = `${cwd6}/${location}/.gitignore`;
|
|
4909
5005
|
try {
|
|
4910
5006
|
unlinkSync4(filePath);
|
|
4911
|
-
console.log(
|
|
5007
|
+
console.log(chalk42.yellow(` Removed ${location}/.gitignore`));
|
|
4912
5008
|
removed++;
|
|
4913
5009
|
} catch {
|
|
4914
5010
|
}
|
|
@@ -4917,7 +5013,7 @@ function removePackageGitignores(cwd6) {
|
|
|
4917
5013
|
}
|
|
4918
5014
|
var gitignoreGen = gitignore;
|
|
4919
5015
|
function gitignore() {
|
|
4920
|
-
console.log(
|
|
5016
|
+
console.log(chalk42.green("Generate .gitignore"));
|
|
4921
5017
|
const cwd6 = INIT_CWD();
|
|
4922
5018
|
const gitignorePath = `${cwd6}/.gitignore`;
|
|
4923
5019
|
try {
|
|
@@ -4925,21 +5021,21 @@ function gitignore() {
|
|
|
4925
5021
|
const existing = readNonEmptyLines(gitignorePath);
|
|
4926
5022
|
const merged = mergeWithTemplate(existing, templateContent);
|
|
4927
5023
|
writeLines(gitignorePath, merged);
|
|
4928
|
-
console.log(
|
|
5024
|
+
console.log(chalk42.green(" Root .gitignore updated"));
|
|
4929
5025
|
const removed = removePackageGitignores(cwd6);
|
|
4930
5026
|
if (removed > 0) {
|
|
4931
|
-
console.log(
|
|
5027
|
+
console.log(chalk42.green(` Removed ${removed} package .gitignore file(s)`));
|
|
4932
5028
|
}
|
|
4933
5029
|
return 0;
|
|
4934
5030
|
} catch (ex) {
|
|
4935
5031
|
const error = ex;
|
|
4936
|
-
console.error(
|
|
5032
|
+
console.error(chalk42.red(`Generate .gitignore failed: ${error.message}`));
|
|
4937
5033
|
return 1;
|
|
4938
5034
|
}
|
|
4939
5035
|
}
|
|
4940
5036
|
|
|
4941
5037
|
// src/actions/gitlint.ts
|
|
4942
|
-
import
|
|
5038
|
+
import chalk43 from "chalk";
|
|
4943
5039
|
import ParseGitConfig from "parse-git-config";
|
|
4944
5040
|
var gitlint = () => {
|
|
4945
5041
|
console.log(`
|
|
@@ -4950,7 +5046,7 @@ Gitlint Start [${process.cwd()}]
|
|
|
4950
5046
|
const errors = 0;
|
|
4951
5047
|
const gitConfig = ParseGitConfig.sync();
|
|
4952
5048
|
const warn = (message) => {
|
|
4953
|
-
console.warn(
|
|
5049
|
+
console.warn(chalk43.yellow(`Warning: ${message}`));
|
|
4954
5050
|
warnings++;
|
|
4955
5051
|
};
|
|
4956
5052
|
if (gitConfig.core.ignorecase) {
|
|
@@ -4970,13 +5066,13 @@ Gitlint Start [${process.cwd()}]
|
|
|
4970
5066
|
}
|
|
4971
5067
|
const resultMessages = [];
|
|
4972
5068
|
if (valid > 0) {
|
|
4973
|
-
resultMessages.push(
|
|
5069
|
+
resultMessages.push(chalk43.green(`Passed: ${valid}`));
|
|
4974
5070
|
}
|
|
4975
5071
|
if (warnings > 0) {
|
|
4976
|
-
resultMessages.push(
|
|
5072
|
+
resultMessages.push(chalk43.yellow(`Warnings: ${warnings}`));
|
|
4977
5073
|
}
|
|
4978
5074
|
if (errors > 0) {
|
|
4979
|
-
resultMessages.push(
|
|
5075
|
+
resultMessages.push(chalk43.red(` Errors: ${errors}`));
|
|
4980
5076
|
}
|
|
4981
5077
|
console.warn(`Gitlint Finish [ ${resultMessages.join(" | ")} ]
|
|
4982
5078
|
`);
|
|
@@ -4985,7 +5081,7 @@ Gitlint Start [${process.cwd()}]
|
|
|
4985
5081
|
|
|
4986
5082
|
// src/actions/gitlint-fix.ts
|
|
4987
5083
|
import { execSync as execSync2 } from "child_process";
|
|
4988
|
-
import
|
|
5084
|
+
import chalk44 from "chalk";
|
|
4989
5085
|
import ParseGitConfig2 from "parse-git-config";
|
|
4990
5086
|
var gitlintFix = () => {
|
|
4991
5087
|
console.log(`
|
|
@@ -4994,15 +5090,15 @@ Gitlint Fix Start [${process.cwd()}]
|
|
|
4994
5090
|
const gitConfig = ParseGitConfig2.sync();
|
|
4995
5091
|
if (gitConfig.core.ignorecase) {
|
|
4996
5092
|
execSync2("git config core.ignorecase false", { stdio: "inherit" });
|
|
4997
|
-
console.warn(
|
|
5093
|
+
console.warn(chalk44.yellow("\nGitlint Fix: Updated core.ignorecase to be false\n"));
|
|
4998
5094
|
}
|
|
4999
5095
|
if (gitConfig.core.autocrlf !== false) {
|
|
5000
5096
|
execSync2("git config core.autocrlf false", { stdio: "inherit" });
|
|
5001
|
-
console.warn(
|
|
5097
|
+
console.warn(chalk44.yellow("\nGitlint Fix: Updated core.autocrlf to be false\n"));
|
|
5002
5098
|
}
|
|
5003
5099
|
if (gitConfig.core.eol !== "lf") {
|
|
5004
5100
|
execSync2("git config core.eol lf", { stdio: "inherit" });
|
|
5005
|
-
console.warn(
|
|
5101
|
+
console.warn(chalk44.yellow('\nGitlint Fix: Updated core.eol to be "lf"\n'));
|
|
5006
5102
|
}
|
|
5007
5103
|
return 1;
|
|
5008
5104
|
};
|
|
@@ -5013,7 +5109,7 @@ var knip = () => {
|
|
|
5013
5109
|
};
|
|
5014
5110
|
|
|
5015
5111
|
// src/actions/license.ts
|
|
5016
|
-
import
|
|
5112
|
+
import chalk45 from "chalk";
|
|
5017
5113
|
import { init } from "license-checker";
|
|
5018
5114
|
var license = async (pkg) => {
|
|
5019
5115
|
const workspaces = getPackageManager().listWorkspaces();
|
|
@@ -5038,18 +5134,18 @@ var license = async (pkg) => {
|
|
|
5038
5134
|
"LGPL-3.0-or-later",
|
|
5039
5135
|
"Python-2.0"
|
|
5040
5136
|
]);
|
|
5041
|
-
console.log(
|
|
5137
|
+
console.log(chalk45.green("License Checker"));
|
|
5042
5138
|
return (await Promise.all(
|
|
5043
5139
|
workspaceList.map(({ location, name }) => {
|
|
5044
5140
|
return new Promise((resolve) => {
|
|
5045
5141
|
init({ production: true, start: location }, (error, packages) => {
|
|
5046
5142
|
if (error) {
|
|
5047
|
-
console.error(
|
|
5048
|
-
console.error(
|
|
5143
|
+
console.error(chalk45.red(`License Checker [${name}] Error`));
|
|
5144
|
+
console.error(chalk45.gray(error));
|
|
5049
5145
|
console.log("\n");
|
|
5050
5146
|
resolve(1);
|
|
5051
5147
|
} else {
|
|
5052
|
-
console.log(
|
|
5148
|
+
console.log(chalk45.green(`License Checker [${name}]`));
|
|
5053
5149
|
let count = 0;
|
|
5054
5150
|
for (const [name2, info] of Object.entries(packages)) {
|
|
5055
5151
|
const licenses = Array.isArray(info.licenses) ? info.licenses : [info.licenses];
|
|
@@ -5065,7 +5161,7 @@ var license = async (pkg) => {
|
|
|
5065
5161
|
}
|
|
5066
5162
|
if (!orLicenseFound) {
|
|
5067
5163
|
count++;
|
|
5068
|
-
console.warn(
|
|
5164
|
+
console.warn(chalk45.yellow(`${name2}: Package License not allowed [${license2}]`));
|
|
5069
5165
|
}
|
|
5070
5166
|
}
|
|
5071
5167
|
}
|
|
@@ -5081,17 +5177,17 @@ var license = async (pkg) => {
|
|
|
5081
5177
|
|
|
5082
5178
|
// src/actions/lint-init.ts
|
|
5083
5179
|
import {
|
|
5084
|
-
existsSync as
|
|
5085
|
-
readFileSync as
|
|
5180
|
+
existsSync as existsSync13,
|
|
5181
|
+
readFileSync as readFileSync22,
|
|
5086
5182
|
unlinkSync as unlinkSync5,
|
|
5087
|
-
writeFileSync as
|
|
5183
|
+
writeFileSync as writeFileSync9
|
|
5088
5184
|
} from "fs";
|
|
5089
|
-
import
|
|
5090
|
-
import { createInterface as
|
|
5091
|
-
import
|
|
5185
|
+
import PATH18 from "path";
|
|
5186
|
+
import { createInterface as createInterface4 } from "readline";
|
|
5187
|
+
import chalk46 from "chalk";
|
|
5092
5188
|
import { globSync as globSync3 } from "glob";
|
|
5093
5189
|
function askConfirmation3(question) {
|
|
5094
|
-
const rl =
|
|
5190
|
+
const rl = createInterface4({ input: process.stdin, output: process.stdout });
|
|
5095
5191
|
return new Promise((resolve) => {
|
|
5096
5192
|
rl.question(question, (answer) => {
|
|
5097
5193
|
rl.close();
|
|
@@ -5213,7 +5309,7 @@ function generateEslintConfig({
|
|
|
5213
5309
|
return lines.join("\n");
|
|
5214
5310
|
}
|
|
5215
5311
|
function addDevDependencies(packageJsonPath, requiredDeps, verbose) {
|
|
5216
|
-
const content =
|
|
5312
|
+
const content = readFileSync22(packageJsonPath, "utf8");
|
|
5217
5313
|
const pkg = JSON.parse(content);
|
|
5218
5314
|
const devDeps = pkg.devDependencies ?? {};
|
|
5219
5315
|
let changed = false;
|
|
@@ -5221,19 +5317,19 @@ function addDevDependencies(packageJsonPath, requiredDeps, verbose) {
|
|
|
5221
5317
|
if (!devDeps[name]) {
|
|
5222
5318
|
devDeps[name] = version;
|
|
5223
5319
|
changed = true;
|
|
5224
|
-
if (verbose) console.log(
|
|
5320
|
+
if (verbose) console.log(chalk46.gray(` Added ${name}@${version} to devDependencies`));
|
|
5225
5321
|
} else if (verbose) {
|
|
5226
|
-
console.log(
|
|
5322
|
+
console.log(chalk46.gray(` ${name} already in devDependencies`));
|
|
5227
5323
|
}
|
|
5228
5324
|
}
|
|
5229
5325
|
if (changed) {
|
|
5230
5326
|
const sorted = Object.fromEntries(Object.entries(devDeps).toSorted(([a], [b]) => a.localeCompare(b)));
|
|
5231
5327
|
pkg.devDependencies = sorted;
|
|
5232
|
-
|
|
5328
|
+
writeFileSync9(packageJsonPath, `${JSON.stringify(pkg, null, 2)}
|
|
5233
5329
|
`, "utf8");
|
|
5234
|
-
console.log(
|
|
5330
|
+
console.log(chalk46.green("Updated package.json devDependencies"));
|
|
5235
5331
|
} else {
|
|
5236
|
-
console.log(
|
|
5332
|
+
console.log(chalk46.gray("package.json devDependencies already up to date"));
|
|
5237
5333
|
}
|
|
5238
5334
|
return changed;
|
|
5239
5335
|
}
|
|
@@ -5243,14 +5339,14 @@ function detectReactInMonorepo(cwd6, verbose) {
|
|
|
5243
5339
|
ignore: ["**/node_modules/**"]
|
|
5244
5340
|
});
|
|
5245
5341
|
for (const relPath of packageJsonPaths) {
|
|
5246
|
-
const fullPath =
|
|
5342
|
+
const fullPath = PATH18.resolve(cwd6, relPath);
|
|
5247
5343
|
try {
|
|
5248
|
-
const content =
|
|
5344
|
+
const content = readFileSync22(fullPath, "utf8");
|
|
5249
5345
|
const pkg = JSON.parse(content);
|
|
5250
5346
|
const deps = pkg.dependencies;
|
|
5251
5347
|
const peerDeps = pkg.peerDependencies;
|
|
5252
5348
|
if (deps?.react || peerDeps?.react) {
|
|
5253
|
-
if (verbose) console.log(
|
|
5349
|
+
if (verbose) console.log(chalk46.gray(` React detected in ${relPath}`));
|
|
5254
5350
|
return true;
|
|
5255
5351
|
}
|
|
5256
5352
|
} catch {
|
|
@@ -5259,19 +5355,19 @@ function detectReactInMonorepo(cwd6, verbose) {
|
|
|
5259
5355
|
return false;
|
|
5260
5356
|
}
|
|
5261
5357
|
function findExistingConfig(configPath, legacyConfigPath) {
|
|
5262
|
-
if (
|
|
5263
|
-
if (
|
|
5358
|
+
if (existsSync13(configPath)) return configPath;
|
|
5359
|
+
if (existsSync13(legacyConfigPath)) return legacyConfigPath;
|
|
5264
5360
|
return void 0;
|
|
5265
5361
|
}
|
|
5266
5362
|
function removeLegacyConfig(legacyConfigPath) {
|
|
5267
|
-
if (
|
|
5363
|
+
if (existsSync13(legacyConfigPath)) {
|
|
5268
5364
|
unlinkSync5(legacyConfigPath);
|
|
5269
|
-
console.log(
|
|
5365
|
+
console.log(chalk46.gray("Removed legacy eslint.config.mjs"));
|
|
5270
5366
|
}
|
|
5271
5367
|
}
|
|
5272
5368
|
function updateDependencies(packageJsonPath, react, cwd6, verbose) {
|
|
5273
|
-
if (!
|
|
5274
|
-
console.log(
|
|
5369
|
+
if (!existsSync13(packageJsonPath)) {
|
|
5370
|
+
console.log(chalk46.yellow("No package.json found \u2014 skipping dependency updates"));
|
|
5275
5371
|
return;
|
|
5276
5372
|
}
|
|
5277
5373
|
const changed = addDevDependencies(packageJsonPath, getRequiredDevDependencies(react), verbose);
|
|
@@ -5281,52 +5377,52 @@ function updateDependencies(packageJsonPath, react, cwd6, verbose) {
|
|
|
5281
5377
|
}
|
|
5282
5378
|
async function lintInit({ verbose } = {}) {
|
|
5283
5379
|
const cwd6 = INIT_CWD();
|
|
5284
|
-
const configPath =
|
|
5285
|
-
const legacyConfigPath =
|
|
5380
|
+
const configPath = PATH18.resolve(cwd6, "eslint.config.ts");
|
|
5381
|
+
const legacyConfigPath = PATH18.resolve(cwd6, "eslint.config.mjs");
|
|
5286
5382
|
const existingPath = findExistingConfig(configPath, legacyConfigPath);
|
|
5287
5383
|
if (existingPath) {
|
|
5288
|
-
const filename2 =
|
|
5384
|
+
const filename2 = PATH18.basename(existingPath);
|
|
5289
5385
|
const confirmed = await askConfirmation3(
|
|
5290
|
-
|
|
5386
|
+
chalk46.yellow(`${filename2} already exists. Replace it with eslint.config.ts? (y/N) `)
|
|
5291
5387
|
);
|
|
5292
5388
|
if (!confirmed) {
|
|
5293
|
-
console.log(
|
|
5389
|
+
console.log(chalk46.gray(`Skipped \u2014 existing ${filename2} preserved`));
|
|
5294
5390
|
return 0;
|
|
5295
5391
|
}
|
|
5296
5392
|
}
|
|
5297
5393
|
const react = detectReactInMonorepo(cwd6, verbose);
|
|
5298
5394
|
if (react) {
|
|
5299
|
-
console.log(
|
|
5395
|
+
console.log(chalk46.cyan("Detected React packages \u2014 using @xylabs/eslint-config-react-flat"));
|
|
5300
5396
|
} else if (verbose) {
|
|
5301
|
-
console.log(
|
|
5397
|
+
console.log(chalk46.gray(" No React packages detected \u2014 using @xylabs/eslint-config-flat"));
|
|
5302
5398
|
}
|
|
5303
5399
|
const useXyLabsBarrel = await askConfirmation3(
|
|
5304
|
-
|
|
5400
|
+
chalk46.cyan("Disallow @xylabs/sdk-js barrel imports? (y/N) ")
|
|
5305
5401
|
);
|
|
5306
5402
|
const useXyoBarrel = await askConfirmation3(
|
|
5307
|
-
|
|
5403
|
+
chalk46.cyan("Disallow @xyo-network/sdk-js barrel imports? (y/N) ")
|
|
5308
5404
|
);
|
|
5309
5405
|
const config2 = generateEslintConfig({
|
|
5310
5406
|
react,
|
|
5311
5407
|
useXyLabsBarrel,
|
|
5312
5408
|
useXyoBarrel
|
|
5313
5409
|
});
|
|
5314
|
-
|
|
5315
|
-
console.log(
|
|
5410
|
+
writeFileSync9(configPath, config2, "utf8");
|
|
5411
|
+
console.log(chalk46.green("Generated eslint.config.ts"));
|
|
5316
5412
|
removeLegacyConfig(legacyConfigPath);
|
|
5317
|
-
updateDependencies(
|
|
5413
|
+
updateDependencies(PATH18.resolve(cwd6, "package.json"), react, cwd6, verbose);
|
|
5318
5414
|
return 0;
|
|
5319
5415
|
}
|
|
5320
5416
|
|
|
5321
5417
|
// src/actions/lintlint.ts
|
|
5322
5418
|
import { spawnSync as spawnSync9 } from "child_process";
|
|
5323
5419
|
import {
|
|
5324
|
-
existsSync as
|
|
5325
|
-
readFileSync as
|
|
5326
|
-
writeFileSync as
|
|
5420
|
+
existsSync as existsSync14,
|
|
5421
|
+
readFileSync as readFileSync23,
|
|
5422
|
+
writeFileSync as writeFileSync10
|
|
5327
5423
|
} from "fs";
|
|
5328
|
-
import
|
|
5329
|
-
import
|
|
5424
|
+
import PATH19 from "path";
|
|
5425
|
+
import chalk47 from "chalk";
|
|
5330
5426
|
import { findUp } from "find-up";
|
|
5331
5427
|
function parseRuleValue(value) {
|
|
5332
5428
|
if (typeof value === "string") {
|
|
@@ -5405,12 +5501,12 @@ async function resolveSharedConfig(configDir, sharedPkg) {
|
|
|
5405
5501
|
const sharedModule = await import(sharedPkg);
|
|
5406
5502
|
return extractConfigBlocks(sharedModule);
|
|
5407
5503
|
} catch {
|
|
5408
|
-
const distPath =
|
|
5504
|
+
const distPath = PATH19.resolve(configDir, "node_modules", sharedPkg, "dist", "node", "index.mjs");
|
|
5409
5505
|
try {
|
|
5410
5506
|
const sharedModule = await import(distPath);
|
|
5411
5507
|
return extractConfigBlocks(sharedModule);
|
|
5412
5508
|
} catch {
|
|
5413
|
-
const neutralPath =
|
|
5509
|
+
const neutralPath = PATH19.resolve(configDir, "node_modules", sharedPkg, "dist", "neutral", "index.mjs");
|
|
5414
5510
|
const sharedModule = await import(neutralPath);
|
|
5415
5511
|
return extractConfigBlocks(sharedModule);
|
|
5416
5512
|
}
|
|
@@ -5421,10 +5517,10 @@ async function loadSharedRules(configDir, sharedPkg, verbose) {
|
|
|
5421
5517
|
const sharedBlocks = await resolveSharedConfig(configDir, sharedPkg);
|
|
5422
5518
|
const sharedRules = mergeRulesFromBlocks(sharedBlocks);
|
|
5423
5519
|
if (verbose) {
|
|
5424
|
-
console.log(
|
|
5520
|
+
console.log(chalk47.gray(`Shared config defines ${sharedRules.size} rules`));
|
|
5425
5521
|
}
|
|
5426
5522
|
if (sharedRules.size === 0) {
|
|
5427
|
-
console.error(
|
|
5523
|
+
console.error(chalk47.red("Could not load rules from shared config. Is it installed and built?"));
|
|
5428
5524
|
return void 0;
|
|
5429
5525
|
}
|
|
5430
5526
|
return sharedRules;
|
|
@@ -5437,7 +5533,7 @@ async function loadLocalRules(eslintConfigPath, source, verbose) {
|
|
|
5437
5533
|
const localRuleBlocks = extractLocalRuleBlocks(source);
|
|
5438
5534
|
const explicit = extractRulesFromSourceBlocks(localRuleBlocks);
|
|
5439
5535
|
if (verbose) {
|
|
5440
|
-
console.log(
|
|
5536
|
+
console.log(chalk47.gray(`Local config has ${explicit.size} explicit rule setting(s)`));
|
|
5441
5537
|
}
|
|
5442
5538
|
return { explicit, resolved };
|
|
5443
5539
|
}
|
|
@@ -5477,38 +5573,38 @@ function reportResults({
|
|
|
5477
5573
|
redundant
|
|
5478
5574
|
}, verbose) {
|
|
5479
5575
|
if (redundant.length > 0) {
|
|
5480
|
-
console.log(
|
|
5576
|
+
console.log(chalk47.yellow(`
|
|
5481
5577
|
${redundant.length} redundant rule(s) (same as shared config \u2014 can be removed):`));
|
|
5482
5578
|
for (const { rule, local } of redundant) {
|
|
5483
|
-
console.log(
|
|
5579
|
+
console.log(chalk47.yellow(` ${rule}: ${formatRule(local)}`));
|
|
5484
5580
|
}
|
|
5485
5581
|
}
|
|
5486
5582
|
if (overrides.length > 0) {
|
|
5487
|
-
console.log(
|
|
5583
|
+
console.log(chalk47.cyan(`
|
|
5488
5584
|
${overrides.length} rule override(s) (different from shared config):`));
|
|
5489
5585
|
for (const {
|
|
5490
5586
|
rule,
|
|
5491
5587
|
local,
|
|
5492
5588
|
shared
|
|
5493
5589
|
} of overrides) {
|
|
5494
|
-
console.log(
|
|
5495
|
-
console.log(
|
|
5496
|
-
console.log(
|
|
5590
|
+
console.log(chalk47.cyan(` ${rule}:`));
|
|
5591
|
+
console.log(chalk47.gray(` shared: ${formatRule(shared)}`));
|
|
5592
|
+
console.log(chalk47.white(` local: ${formatRule(local)}`));
|
|
5497
5593
|
}
|
|
5498
5594
|
}
|
|
5499
5595
|
if (additions.length > 0 && verbose) {
|
|
5500
|
-
console.log(
|
|
5596
|
+
console.log(chalk47.gray(`
|
|
5501
5597
|
${additions.length} local addition(s) (not in shared config):`));
|
|
5502
5598
|
for (const { rule, local } of additions) {
|
|
5503
|
-
console.log(
|
|
5599
|
+
console.log(chalk47.gray(` ${rule}: ${formatRule(local)}`));
|
|
5504
5600
|
}
|
|
5505
5601
|
}
|
|
5506
5602
|
if (redundant.length === 0 && overrides.length === 0) {
|
|
5507
|
-
console.log(
|
|
5603
|
+
console.log(chalk47.green("No redundant or overridden rules found"));
|
|
5508
5604
|
}
|
|
5509
5605
|
}
|
|
5510
5606
|
function fixRedundantRules(eslintConfigPath, redundant) {
|
|
5511
|
-
let updated =
|
|
5607
|
+
let updated = readFileSync23(eslintConfigPath, "utf8");
|
|
5512
5608
|
const original = updated;
|
|
5513
5609
|
for (const { rule } of redundant) {
|
|
5514
5610
|
const escaped = rule.replaceAll("/", String.raw`\/`);
|
|
@@ -5518,8 +5614,8 @@ function fixRedundantRules(eslintConfigPath, redundant) {
|
|
|
5518
5614
|
updated = updated.replaceAll(/\{\s*rules\s*:\s*\{\s*\}\s*,?\s*\}\s*,?/g, "");
|
|
5519
5615
|
updated = updated.replaceAll(/\n{3,}/g, "\n\n");
|
|
5520
5616
|
if (updated !== original) {
|
|
5521
|
-
|
|
5522
|
-
console.log(
|
|
5617
|
+
writeFileSync10(eslintConfigPath, updated, "utf8");
|
|
5618
|
+
console.log(chalk47.green(`
|
|
5523
5619
|
Fixed: removed ${redundant.length} redundant rule(s)`));
|
|
5524
5620
|
}
|
|
5525
5621
|
}
|
|
@@ -5528,11 +5624,11 @@ function formatConfigFile(eslintConfigPath) {
|
|
|
5528
5624
|
}
|
|
5529
5625
|
function fixConfigMismatch(eslintConfigPath, configDir, source, sharedPkg, expectedPkg) {
|
|
5530
5626
|
const updated = source.replaceAll(sharedPkg, expectedPkg);
|
|
5531
|
-
|
|
5532
|
-
console.log(
|
|
5533
|
-
const packageJsonPath =
|
|
5534
|
-
if (!
|
|
5535
|
-
const content =
|
|
5627
|
+
writeFileSync10(eslintConfigPath, updated, "utf8");
|
|
5628
|
+
console.log(chalk47.green(`Fixed: replaced ${sharedPkg} with ${expectedPkg}`));
|
|
5629
|
+
const packageJsonPath = PATH19.resolve(configDir, "package.json");
|
|
5630
|
+
if (!existsSync14(packageJsonPath)) return;
|
|
5631
|
+
const content = readFileSync23(packageJsonPath, "utf8");
|
|
5536
5632
|
const pkg = JSON.parse(content);
|
|
5537
5633
|
const devDeps = pkg.devDependencies ?? {};
|
|
5538
5634
|
const oldVersion = devDeps[sharedPkg];
|
|
@@ -5541,18 +5637,18 @@ function fixConfigMismatch(eslintConfigPath, configDir, source, sharedPkg, expec
|
|
|
5541
5637
|
devDeps[expectedPkg] = oldVersion;
|
|
5542
5638
|
const sorted = Object.fromEntries(Object.entries(devDeps).toSorted(([a], [b]) => a.localeCompare(b)));
|
|
5543
5639
|
pkg.devDependencies = sorted;
|
|
5544
|
-
|
|
5640
|
+
writeFileSync10(packageJsonPath, `${JSON.stringify(pkg, null, 2)}
|
|
5545
5641
|
`, "utf8");
|
|
5546
|
-
console.log(
|
|
5642
|
+
console.log(chalk47.green(`Updated package.json: ${sharedPkg} \u2192 ${expectedPkg}`));
|
|
5547
5643
|
runInstall(configDir);
|
|
5548
5644
|
}
|
|
5549
5645
|
function checkConfigVariant(eslintConfigPath, configDir, source, sharedPkg, fix2, verbose) {
|
|
5550
5646
|
const hasReact = detectReactInMonorepo(configDir, verbose);
|
|
5551
5647
|
const expectedPkg = hasReact ? "@xylabs/eslint-config-react-flat" : "@xylabs/eslint-config-flat";
|
|
5552
5648
|
if (sharedPkg === expectedPkg) return false;
|
|
5553
|
-
console.log(
|
|
5649
|
+
console.log(chalk47.yellow(`
|
|
5554
5650
|
Config mismatch: using ${sharedPkg} but ${hasReact ? "React packages detected" : "no React packages found"}`));
|
|
5555
|
-
console.log(
|
|
5651
|
+
console.log(chalk47.yellow(` Expected: ${expectedPkg}`));
|
|
5556
5652
|
if (fix2) {
|
|
5557
5653
|
fixConfigMismatch(eslintConfigPath, configDir, source, sharedPkg, expectedPkg);
|
|
5558
5654
|
}
|
|
@@ -5561,24 +5657,24 @@ Config mismatch: using ${sharedPkg} but ${hasReact ? "React packages detected" :
|
|
|
5561
5657
|
async function lintlint({ fix: fix2, verbose } = {}) {
|
|
5562
5658
|
const eslintConfigPath = await findUp(["eslint.config.ts", "eslint.config.mjs"]);
|
|
5563
5659
|
if (!eslintConfigPath) {
|
|
5564
|
-
console.error(
|
|
5660
|
+
console.error(chalk47.red("No eslint.config.ts found"));
|
|
5565
5661
|
return 1;
|
|
5566
5662
|
}
|
|
5567
|
-
const configDir =
|
|
5663
|
+
const configDir = PATH19.dirname(eslintConfigPath);
|
|
5568
5664
|
if (verbose) {
|
|
5569
|
-
console.log(
|
|
5665
|
+
console.log(chalk47.gray(`Found config: ${eslintConfigPath}`));
|
|
5570
5666
|
}
|
|
5571
|
-
const source =
|
|
5667
|
+
const source = readFileSync23(eslintConfigPath, "utf8");
|
|
5572
5668
|
const sharedPkg = detectSharedPackage(source);
|
|
5573
5669
|
if (!sharedPkg) {
|
|
5574
|
-
console.log(
|
|
5670
|
+
console.log(chalk47.yellow("No @xylabs/eslint-config-flat or @xylabs/eslint-config-react-flat imports found"));
|
|
5575
5671
|
return 0;
|
|
5576
5672
|
}
|
|
5577
5673
|
if (verbose) {
|
|
5578
|
-
console.log(
|
|
5674
|
+
console.log(chalk47.gray(`Shared package: ${sharedPkg}`));
|
|
5579
5675
|
}
|
|
5580
5676
|
const hasMismatch = checkConfigVariant(eslintConfigPath, configDir, source, sharedPkg, !!fix2, !!verbose);
|
|
5581
|
-
const currentSource = hasMismatch && fix2 ?
|
|
5677
|
+
const currentSource = hasMismatch && fix2 ? readFileSync23(eslintConfigPath, "utf8") : source;
|
|
5582
5678
|
const sharedRules = await loadSharedRules(configDir, sharedPkg, !!verbose);
|
|
5583
5679
|
if (!sharedRules) return 1;
|
|
5584
5680
|
const { explicit, resolved } = await loadLocalRules(eslintConfigPath, currentSource, !!verbose);
|
|
@@ -5603,7 +5699,7 @@ var npmignoreGen = (pkg) => generateIgnoreFiles(filename, pkg);
|
|
|
5603
5699
|
// src/actions/orphan.ts
|
|
5604
5700
|
import fs16 from "fs";
|
|
5605
5701
|
import path11 from "path";
|
|
5606
|
-
import
|
|
5702
|
+
import chalk48 from "chalk";
|
|
5607
5703
|
import { glob as glob2 } from "glob";
|
|
5608
5704
|
function isAncestorOfWorkspace(dir, workspaceLocations) {
|
|
5609
5705
|
const dirWithSep = dir.endsWith(path11.sep) ? dir : dir + path11.sep;
|
|
@@ -5630,7 +5726,7 @@ function findOrphans(cwd6, verbose) {
|
|
|
5630
5726
|
if (workspaceLocations.has(parentAbs)) continue;
|
|
5631
5727
|
if (fs16.existsSync(path11.join(parentAbs, "package.json"))) continue;
|
|
5632
5728
|
if (verbose) {
|
|
5633
|
-
console.log(
|
|
5729
|
+
console.log(chalk48.gray(` Found orphan: ${parentRel}`));
|
|
5634
5730
|
}
|
|
5635
5731
|
let topOrphan = parentRel;
|
|
5636
5732
|
let current = path11.dirname(parentRel);
|
|
@@ -5648,45 +5744,45 @@ function findOrphans(cwd6, verbose) {
|
|
|
5648
5744
|
}
|
|
5649
5745
|
function orphanList({ verbose } = {}) {
|
|
5650
5746
|
const cwd6 = INIT_CWD();
|
|
5651
|
-
console.log(
|
|
5747
|
+
console.log(chalk48.green("Orphan List"));
|
|
5652
5748
|
const orphans = findOrphans(cwd6, verbose);
|
|
5653
5749
|
if (orphans.length === 0) {
|
|
5654
|
-
console.log(
|
|
5750
|
+
console.log(chalk48.green(" No orphaned directories found"));
|
|
5655
5751
|
return 0;
|
|
5656
5752
|
}
|
|
5657
5753
|
for (const orphan of orphans) {
|
|
5658
|
-
console.log(
|
|
5754
|
+
console.log(chalk48.yellow(` ${orphan}`));
|
|
5659
5755
|
}
|
|
5660
|
-
console.log(
|
|
5756
|
+
console.log(chalk48.yellow(`
|
|
5661
5757
|
Found ${orphans.length} orphaned director${orphans.length === 1 ? "y" : "ies"}`));
|
|
5662
5758
|
return 1;
|
|
5663
5759
|
}
|
|
5664
5760
|
function orphanClean({ verbose } = {}) {
|
|
5665
5761
|
const cwd6 = INIT_CWD();
|
|
5666
|
-
console.log(
|
|
5762
|
+
console.log(chalk48.green("Orphan Clean"));
|
|
5667
5763
|
const orphans = findOrphans(cwd6, verbose);
|
|
5668
5764
|
if (orphans.length === 0) {
|
|
5669
|
-
console.log(
|
|
5765
|
+
console.log(chalk48.green(" No orphaned directories found"));
|
|
5670
5766
|
return 0;
|
|
5671
5767
|
}
|
|
5672
5768
|
for (const orphan of orphans) {
|
|
5673
5769
|
const absPath = path11.resolve(cwd6, orphan);
|
|
5674
5770
|
fs16.rmSync(absPath, { force: true, recursive: true });
|
|
5675
|
-
console.log(
|
|
5771
|
+
console.log(chalk48.yellow(` Removed ${orphan}`));
|
|
5676
5772
|
}
|
|
5677
|
-
console.log(
|
|
5773
|
+
console.log(chalk48.green(`
|
|
5678
5774
|
Cleaned ${orphans.length} orphaned director${orphans.length === 1 ? "y" : "ies"}`));
|
|
5679
5775
|
return 0;
|
|
5680
5776
|
}
|
|
5681
5777
|
|
|
5682
5778
|
// src/actions/package/clean-outputs.ts
|
|
5683
5779
|
import path12 from "path";
|
|
5684
|
-
import
|
|
5780
|
+
import chalk49 from "chalk";
|
|
5685
5781
|
var packageCleanOutputs = () => {
|
|
5686
5782
|
const pkg = INIT_CWD();
|
|
5687
5783
|
const pkgName = packageName();
|
|
5688
5784
|
const folders = [path12.join(pkg, "dist"), path12.join(pkg, "build"), path12.join(pkg, "docs")];
|
|
5689
|
-
console.log(
|
|
5785
|
+
console.log(chalk49.green(`Cleaning Outputs [${pkgName}]`));
|
|
5690
5786
|
for (const folder of folders) {
|
|
5691
5787
|
deleteGlob(folder);
|
|
5692
5788
|
}
|
|
@@ -5695,11 +5791,11 @@ var packageCleanOutputs = () => {
|
|
|
5695
5791
|
|
|
5696
5792
|
// src/actions/package/clean-typescript.ts
|
|
5697
5793
|
import path13 from "path";
|
|
5698
|
-
import
|
|
5794
|
+
import chalk50 from "chalk";
|
|
5699
5795
|
var packageCleanTypescript = () => {
|
|
5700
5796
|
const pkg = INIT_CWD();
|
|
5701
5797
|
const pkgName = packageName();
|
|
5702
|
-
console.log(
|
|
5798
|
+
console.log(chalk50.green(`Cleaning Typescript [${pkgName}]`));
|
|
5703
5799
|
const files = [path13.join(pkg, "*.tsbuildinfo"), path13.join(pkg, ".tsconfig.*"), path13.join(pkg, ".eslintcache")];
|
|
5704
5800
|
for (const file of files) {
|
|
5705
5801
|
deleteGlob(file);
|
|
@@ -5714,26 +5810,26 @@ var packageClean = () => {
|
|
|
5714
5810
|
|
|
5715
5811
|
// src/actions/package/compile/compile.ts
|
|
5716
5812
|
import { cwd as cwd4 } from "process";
|
|
5717
|
-
import
|
|
5813
|
+
import chalk55 from "chalk";
|
|
5718
5814
|
|
|
5719
5815
|
// src/actions/package/compile/packageCompileTsup.ts
|
|
5720
|
-
import
|
|
5816
|
+
import chalk54 from "chalk";
|
|
5721
5817
|
import { build as build2, defineConfig } from "tsup";
|
|
5722
5818
|
|
|
5723
5819
|
// src/actions/package/compile/inputs.ts
|
|
5724
|
-
import
|
|
5820
|
+
import chalk51 from "chalk";
|
|
5725
5821
|
import { glob as glob3 } from "glob";
|
|
5726
5822
|
var getAllInputs = (srcDir, verbose = false) => {
|
|
5727
5823
|
return [...glob3.sync(`${srcDir}/**/*.ts`, { posix: true }).map((file) => {
|
|
5728
5824
|
const result = file.slice(Math.max(0, srcDir.length + 1));
|
|
5729
5825
|
if (verbose) {
|
|
5730
|
-
console.log(
|
|
5826
|
+
console.log(chalk51.gray(`getAllInputs: ${JSON.stringify(result, null, 2)}`));
|
|
5731
5827
|
}
|
|
5732
5828
|
return result;
|
|
5733
5829
|
}), ...glob3.sync(`${srcDir}/**/*.tsx`, { posix: true }).map((file) => {
|
|
5734
5830
|
const result = file.slice(Math.max(0, srcDir.length + 1));
|
|
5735
5831
|
if (verbose) {
|
|
5736
|
-
console.log(
|
|
5832
|
+
console.log(chalk51.gray(`getAllInputs: ${JSON.stringify(result, null, 2)}`));
|
|
5737
5833
|
}
|
|
5738
5834
|
return result;
|
|
5739
5835
|
})];
|
|
@@ -5796,7 +5892,7 @@ function deepMergeObjects(objects) {
|
|
|
5796
5892
|
|
|
5797
5893
|
// src/actions/package/compile/packageCompileTsc.ts
|
|
5798
5894
|
import { cwd as cwd2 } from "process";
|
|
5799
|
-
import
|
|
5895
|
+
import chalk52 from "chalk";
|
|
5800
5896
|
import { createProgramFromConfig } from "tsc-prog";
|
|
5801
5897
|
import ts3, {
|
|
5802
5898
|
DiagnosticCategory,
|
|
@@ -5818,7 +5914,7 @@ var getCompilerOptions = (options = {}, fileName = "tsconfig.json") => {
|
|
|
5818
5914
|
var packageCompileTsc = (platform, entries, srcDir = "src", outDir = "dist", compilerOptionsParam, verbose = false) => {
|
|
5819
5915
|
const pkg = cwd2();
|
|
5820
5916
|
if (verbose) {
|
|
5821
|
-
console.log(
|
|
5917
|
+
console.log(chalk52.cyan(`Validating code START: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
5822
5918
|
}
|
|
5823
5919
|
const configFilePath = ts3.findConfigFile(
|
|
5824
5920
|
pkg,
|
|
@@ -5840,10 +5936,10 @@ var packageCompileTsc = (platform, entries, srcDir = "src", outDir = "dist", com
|
|
|
5840
5936
|
emitDeclarationOnly: true,
|
|
5841
5937
|
noEmit: false
|
|
5842
5938
|
};
|
|
5843
|
-
console.log(
|
|
5939
|
+
console.log(chalk52.cyan(`Validating Files: ${entries.length}`));
|
|
5844
5940
|
if (verbose) {
|
|
5845
5941
|
for (const entry of entries) {
|
|
5846
|
-
console.log(
|
|
5942
|
+
console.log(chalk52.grey(`Validating: ${entry}`));
|
|
5847
5943
|
}
|
|
5848
5944
|
}
|
|
5849
5945
|
try {
|
|
@@ -5879,7 +5975,7 @@ var packageCompileTsc = (platform, entries, srcDir = "src", outDir = "dist", com
|
|
|
5879
5975
|
return 0;
|
|
5880
5976
|
} finally {
|
|
5881
5977
|
if (verbose) {
|
|
5882
|
-
console.log(
|
|
5978
|
+
console.log(chalk52.cyan(`Validating code FINISH: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
5883
5979
|
}
|
|
5884
5980
|
}
|
|
5885
5981
|
};
|
|
@@ -5887,7 +5983,7 @@ var packageCompileTsc = (platform, entries, srcDir = "src", outDir = "dist", com
|
|
|
5887
5983
|
// src/actions/package/compile/packageCompileTscTypes.ts
|
|
5888
5984
|
import path14 from "path";
|
|
5889
5985
|
import { cwd as cwd3 } from "process";
|
|
5890
|
-
import
|
|
5986
|
+
import chalk53 from "chalk";
|
|
5891
5987
|
import { rollup } from "rollup";
|
|
5892
5988
|
import dts from "rollup-plugin-dts";
|
|
5893
5989
|
import nodeExternals from "rollup-plugin-node-externals";
|
|
@@ -5912,8 +6008,8 @@ async function bundleDts(inputPath, outputPath, platform, options, verbose = fal
|
|
|
5912
6008
|
if (ignoredWarningCodes.has(warning.code ?? "")) {
|
|
5913
6009
|
return;
|
|
5914
6010
|
}
|
|
5915
|
-
console.warn(
|
|
5916
|
-
console.warn(
|
|
6011
|
+
console.warn(chalk53.yellow(`[${warning.code}] ${warning.message}`));
|
|
6012
|
+
console.warn(chalk53.gray(inputPath));
|
|
5917
6013
|
warn(warning);
|
|
5918
6014
|
}
|
|
5919
6015
|
});
|
|
@@ -5923,8 +6019,8 @@ async function bundleDts(inputPath, outputPath, platform, options, verbose = fal
|
|
|
5923
6019
|
});
|
|
5924
6020
|
} catch (ex) {
|
|
5925
6021
|
const error = ex;
|
|
5926
|
-
console.warn(
|
|
5927
|
-
console.warn(
|
|
6022
|
+
console.warn(chalk53.red(error));
|
|
6023
|
+
console.warn(chalk53.gray(inputPath));
|
|
5928
6024
|
}
|
|
5929
6025
|
if (verbose) {
|
|
5930
6026
|
console.log(`Bundled declarations written to ${outputPath}`);
|
|
@@ -5932,7 +6028,7 @@ async function bundleDts(inputPath, outputPath, platform, options, verbose = fal
|
|
|
5932
6028
|
}
|
|
5933
6029
|
var packageCompileTscTypes = async (entries, outDir, platform, srcDir = "build", verbose = false) => {
|
|
5934
6030
|
if (verbose) {
|
|
5935
|
-
console.log(
|
|
6031
|
+
console.log(chalk53.cyan(`Compiling Types START [${platform}]: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
5936
6032
|
console.log(`Entries: ${entries.join(", ")}`);
|
|
5937
6033
|
}
|
|
5938
6034
|
const pkg = cwd3();
|
|
@@ -5956,7 +6052,7 @@ var packageCompileTscTypes = async (entries, outDir, platform, srcDir = "build",
|
|
|
5956
6052
|
await bundleDts(`${srcRoot}/${entryTypeName}`, `${outDir}/${entryTypeName}`, platform, { compilerOptions }, verbose);
|
|
5957
6053
|
}));
|
|
5958
6054
|
if (verbose) {
|
|
5959
|
-
console.log(
|
|
6055
|
+
console.log(chalk53.cyan(`Compiling Types FINISH: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
5960
6056
|
}
|
|
5961
6057
|
return 0;
|
|
5962
6058
|
};
|
|
@@ -5968,15 +6064,15 @@ var compileFolder = async (srcDir, entries, buildDir, options, bundleTypes = fal
|
|
|
5968
6064
|
console.log(`compileFolder [${srcDir}, ${options?.outDir}]`);
|
|
5969
6065
|
}
|
|
5970
6066
|
if (entries.length === 0) {
|
|
5971
|
-
console.warn(
|
|
6067
|
+
console.warn(chalk54.yellow(`No entries found in ${srcDir} to compile`));
|
|
5972
6068
|
return 0;
|
|
5973
6069
|
}
|
|
5974
6070
|
if (verbose) {
|
|
5975
|
-
console.log(
|
|
6071
|
+
console.log(chalk54.gray(`buildDir [${buildDir}]`));
|
|
5976
6072
|
}
|
|
5977
6073
|
const validationResult = packageCompileTsc(options?.platform ?? "neutral", entries, srcDir, buildDir, void 0, verbose);
|
|
5978
6074
|
if (validationResult !== 0) {
|
|
5979
|
-
console.error(
|
|
6075
|
+
console.error(chalk54.red(`Compile:Validation had ${validationResult} errors`));
|
|
5980
6076
|
return validationResult;
|
|
5981
6077
|
}
|
|
5982
6078
|
const optionsParams = tsupOptions([{
|
|
@@ -6001,12 +6097,12 @@ var compileFolder = async (srcDir, entries, buildDir, options, bundleTypes = fal
|
|
|
6001
6097
|
})
|
|
6002
6098
|
)).flat();
|
|
6003
6099
|
if (verbose) {
|
|
6004
|
-
console.log(
|
|
6005
|
-
console.log(
|
|
6100
|
+
console.log(chalk54.cyan(`TSUP:build:start [${srcDir}]`));
|
|
6101
|
+
console.log(chalk54.gray(`TSUP:build:options [${JSON.stringify(optionsList, null, 2)}]`));
|
|
6006
6102
|
}
|
|
6007
6103
|
await Promise.all(optionsList.map((options2) => build2(options2)));
|
|
6008
6104
|
if (verbose) {
|
|
6009
|
-
console.log(
|
|
6105
|
+
console.log(chalk54.cyan(`TSUP:build:stop [${srcDir}]`));
|
|
6010
6106
|
}
|
|
6011
6107
|
if (bundleTypes) {
|
|
6012
6108
|
await packageCompileTscTypes(entries, outDir, options?.platform ?? "neutral", buildDir, verbose);
|
|
@@ -6117,7 +6213,7 @@ var packageCompileTsup = async (config2) => {
|
|
|
6117
6213
|
// src/actions/package/compile/compile.ts
|
|
6118
6214
|
var packageCompile = async (inConfig = {}) => {
|
|
6119
6215
|
const pkg = cwd4();
|
|
6120
|
-
console.log(
|
|
6216
|
+
console.log(chalk55.green(`Compiling ${pkg}`));
|
|
6121
6217
|
const config2 = await loadConfig(inConfig);
|
|
6122
6218
|
return await packageCompileTsup(config2);
|
|
6123
6219
|
};
|
|
@@ -6152,7 +6248,7 @@ var PUBLISH_ONLY_CHECKS = [
|
|
|
6152
6248
|
|
|
6153
6249
|
// src/actions/package/copy-assets.ts
|
|
6154
6250
|
import path15 from "path/posix";
|
|
6155
|
-
import
|
|
6251
|
+
import chalk56 from "chalk";
|
|
6156
6252
|
import cpy2 from "cpy";
|
|
6157
6253
|
var copyTargetAssets2 = async (target, name, location) => {
|
|
6158
6254
|
try {
|
|
@@ -6165,7 +6261,7 @@ var copyTargetAssets2 = async (target, name, location) => {
|
|
|
6165
6261
|
}
|
|
6166
6262
|
);
|
|
6167
6263
|
if (values.length > 0) {
|
|
6168
|
-
console.log(
|
|
6264
|
+
console.log(chalk56.green(`Copying Assets [${target.toUpperCase()}] - ${name} - ${location}`));
|
|
6169
6265
|
}
|
|
6170
6266
|
for (const value of values) {
|
|
6171
6267
|
console.log(`${value.split("/").pop()} => ./dist/${target}`);
|
|
@@ -6230,9 +6326,9 @@ var packageCycle = async () => {
|
|
|
6230
6326
|
};
|
|
6231
6327
|
|
|
6232
6328
|
// src/actions/package/gen-docs.ts
|
|
6233
|
-
import { existsSync as
|
|
6329
|
+
import { existsSync as existsSync15 } from "fs";
|
|
6234
6330
|
import path16 from "path";
|
|
6235
|
-
import
|
|
6331
|
+
import chalk57 from "chalk";
|
|
6236
6332
|
import {
|
|
6237
6333
|
Application,
|
|
6238
6334
|
ArgumentsReader,
|
|
@@ -6250,7 +6346,7 @@ var ExitCodes = {
|
|
|
6250
6346
|
};
|
|
6251
6347
|
var packageGenDocs = async () => {
|
|
6252
6348
|
const pkg = INIT_CWD();
|
|
6253
|
-
if (pkg !== void 0 && !
|
|
6349
|
+
if (pkg !== void 0 && !existsSync15(path16.join(pkg, "typedoc.json"))) {
|
|
6254
6350
|
return;
|
|
6255
6351
|
}
|
|
6256
6352
|
const app = await Application.bootstrap({
|
|
@@ -6336,7 +6432,7 @@ var runTypeDoc = async (app) => {
|
|
|
6336
6432
|
return ExitCodes.OutputError;
|
|
6337
6433
|
}
|
|
6338
6434
|
}
|
|
6339
|
-
console.log(
|
|
6435
|
+
console.log(chalk57.green(`${pkgName} - Ok`));
|
|
6340
6436
|
return ExitCodes.Ok;
|
|
6341
6437
|
};
|
|
6342
6438
|
|
|
@@ -6345,7 +6441,7 @@ import { readdirSync as readdirSync8 } from "fs";
|
|
|
6345
6441
|
import path17 from "path";
|
|
6346
6442
|
import { cwd as cwd5 } from "process";
|
|
6347
6443
|
import { pathToFileURL } from "url";
|
|
6348
|
-
import
|
|
6444
|
+
import chalk58 from "chalk";
|
|
6349
6445
|
import { ESLint as ESLint2 } from "eslint";
|
|
6350
6446
|
import { findUp as findUp2 } from "find-up";
|
|
6351
6447
|
import picomatch from "picomatch";
|
|
@@ -6354,14 +6450,14 @@ var dumpMessages2 = (lintResults) => {
|
|
|
6354
6450
|
const severity = ["none", "warning", "error"];
|
|
6355
6451
|
for (const lintResult of lintResults) {
|
|
6356
6452
|
if (lintResult.messages.length > 0) {
|
|
6357
|
-
console.log(
|
|
6453
|
+
console.log(chalk58.gray(`
|
|
6358
6454
|
${lintResult.filePath}`));
|
|
6359
6455
|
for (const message of lintResult.messages) {
|
|
6360
6456
|
console.log(
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6457
|
+
chalk58.gray(` ${message.line}:${message.column}`),
|
|
6458
|
+
chalk58[colors[message.severity]](` ${severity[message.severity]}`),
|
|
6459
|
+
chalk58.white(` ${message.message}`),
|
|
6460
|
+
chalk58.gray(` ${message.ruleId}`)
|
|
6365
6461
|
);
|
|
6366
6462
|
}
|
|
6367
6463
|
}
|
|
@@ -6399,10 +6495,10 @@ var packageLint = async (fix2 = false, verbose = false, cache = true) => {
|
|
|
6399
6495
|
cache
|
|
6400
6496
|
});
|
|
6401
6497
|
const files = getFiles(cwd5(), ignoreFolders);
|
|
6402
|
-
console.log(
|
|
6498
|
+
console.log(chalk58.green(`Linting ${pkg} [files = ${files.length}]`));
|
|
6403
6499
|
if (verbose) {
|
|
6404
6500
|
for (const file of files) {
|
|
6405
|
-
console.log(
|
|
6501
|
+
console.log(chalk58.gray(` ${file}`));
|
|
6406
6502
|
}
|
|
6407
6503
|
}
|
|
6408
6504
|
const lintResults = await engine.lintFiles(files);
|
|
@@ -6413,14 +6509,14 @@ var packageLint = async (fix2 = false, verbose = false, cache = true) => {
|
|
|
6413
6509
|
const filesCountColor = files.length < 100 ? "green" : files.length < 1e3 ? "yellow" : "red";
|
|
6414
6510
|
const lintTime = Date.now() - start2;
|
|
6415
6511
|
const lintTimeColor = lintTime < 1e3 ? "green" : lintTime < 3e3 ? "yellow" : "red";
|
|
6416
|
-
console.log(
|
|
6512
|
+
console.log(chalk58.white(`Linted ${chalk58[filesCountColor](files.length)} files in ${chalk58[lintTimeColor](lintTime)}ms`));
|
|
6417
6513
|
return lintResults.reduce((prev, lintResult) => prev + lintResult.errorCount, 0);
|
|
6418
6514
|
};
|
|
6419
6515
|
|
|
6420
6516
|
// src/actions/package/publint.ts
|
|
6421
6517
|
import { promises as fs17 } from "fs";
|
|
6422
6518
|
import path18 from "path";
|
|
6423
|
-
import
|
|
6519
|
+
import chalk59 from "chalk";
|
|
6424
6520
|
import { glob as glob4 } from "glob";
|
|
6425
6521
|
import sortPackageJson3 from "sort-package-json";
|
|
6426
6522
|
var removeSourceFromExports = (exports) => {
|
|
@@ -6490,22 +6586,22 @@ function checkFiles(pkg, fix2) {
|
|
|
6490
6586
|
const result = emptyCustomResult();
|
|
6491
6587
|
const files = pkg.files;
|
|
6492
6588
|
if (files === void 0) {
|
|
6493
|
-
console.warn(
|
|
6589
|
+
console.warn(chalk59.yellow('Publint [custom]: "files" field is missing'));
|
|
6494
6590
|
result.warnings++;
|
|
6495
6591
|
}
|
|
6496
6592
|
if (Array.isArray(files) && !files.includes("README.md")) {
|
|
6497
6593
|
files.push("README.md");
|
|
6498
|
-
console.warn(
|
|
6594
|
+
console.warn(chalk59.yellow('Publint [custom]: added "README.md" to "files"'));
|
|
6499
6595
|
result.modified = true;
|
|
6500
6596
|
result.warnings++;
|
|
6501
6597
|
}
|
|
6502
6598
|
if (Array.isArray(files) && files.includes("src")) {
|
|
6503
6599
|
if (fix2) {
|
|
6504
6600
|
pkg.files = files.filter((f) => f !== "src");
|
|
6505
|
-
console.warn(
|
|
6601
|
+
console.warn(chalk59.yellow('Publint [custom]: removed "src" from "files"'));
|
|
6506
6602
|
result.modified = true;
|
|
6507
6603
|
} else {
|
|
6508
|
-
console.warn(
|
|
6604
|
+
console.warn(chalk59.yellow('Publint [custom]: "src" should not be in "files" (use --fix to remove)'));
|
|
6509
6605
|
}
|
|
6510
6606
|
result.warnings++;
|
|
6511
6607
|
}
|
|
@@ -6517,10 +6613,10 @@ function checkExportsSource(pkg, fix2) {
|
|
|
6517
6613
|
if (exports && typeof exports === "object" && hasSourceInExports(exports)) {
|
|
6518
6614
|
if (fix2) {
|
|
6519
6615
|
removeSourceFromExports(exports);
|
|
6520
|
-
console.warn(
|
|
6616
|
+
console.warn(chalk59.yellow('Publint [custom]: removed "source" entries from "exports"'));
|
|
6521
6617
|
result.modified = true;
|
|
6522
6618
|
} else {
|
|
6523
|
-
console.warn(
|
|
6619
|
+
console.warn(chalk59.yellow('Publint [custom]: "source" entries should not be in "exports" (use --fix to remove)'));
|
|
6524
6620
|
}
|
|
6525
6621
|
result.warnings++;
|
|
6526
6622
|
}
|
|
@@ -6538,17 +6634,17 @@ function migrateFieldToExports(pkg, field, exportKey, fix2) {
|
|
|
6538
6634
|
const dot2 = exports["."];
|
|
6539
6635
|
if (dot2 && typeof dot2 === "object" && !dot2[exportKey]) {
|
|
6540
6636
|
dot2[exportKey] = exportValue;
|
|
6541
|
-
console.warn(
|
|
6637
|
+
console.warn(chalk59.yellow(`Publint [custom]: migrated "${field}" to "exports['.'].${exportKey}" (${fieldValue})`));
|
|
6542
6638
|
}
|
|
6543
6639
|
} else if (!pkg.exports) {
|
|
6544
6640
|
pkg.exports = { ".": { [exportKey]: exportValue } };
|
|
6545
|
-
console.warn(
|
|
6641
|
+
console.warn(chalk59.yellow(`Publint [custom]: migrated "${field}" to "exports" (.\u2192${fieldValue})`));
|
|
6546
6642
|
}
|
|
6547
6643
|
delete pkg[field];
|
|
6548
|
-
console.warn(
|
|
6644
|
+
console.warn(chalk59.yellow(`Publint [custom]: removed deprecated "${field}" field`));
|
|
6549
6645
|
result.modified = true;
|
|
6550
6646
|
} else {
|
|
6551
|
-
console.warn(
|
|
6647
|
+
console.warn(chalk59.yellow(`Publint [custom]: "${field}" field is deprecated, use "exports" instead (use --fix to remove)`));
|
|
6552
6648
|
}
|
|
6553
6649
|
result.warnings++;
|
|
6554
6650
|
return result;
|
|
@@ -6556,7 +6652,7 @@ function migrateFieldToExports(pkg, field, exportKey, fix2) {
|
|
|
6556
6652
|
function checkSideEffects(pkg) {
|
|
6557
6653
|
const result = emptyCustomResult();
|
|
6558
6654
|
if (pkg.sideEffects !== false) {
|
|
6559
|
-
console.warn(
|
|
6655
|
+
console.warn(chalk59.yellow('Publint [custom]: "sideEffects" field should be set to false'));
|
|
6560
6656
|
result.warnings++;
|
|
6561
6657
|
}
|
|
6562
6658
|
return result;
|
|
@@ -6567,10 +6663,10 @@ function checkRootSource(pkg, fix2) {
|
|
|
6567
6663
|
if (pkg[field] !== void 0) {
|
|
6568
6664
|
if (fix2) {
|
|
6569
6665
|
delete pkg[field];
|
|
6570
|
-
console.warn(
|
|
6666
|
+
console.warn(chalk59.yellow(`Publint [custom]: removed root-level "${field}" field`));
|
|
6571
6667
|
result.modified = true;
|
|
6572
6668
|
} else {
|
|
6573
|
-
console.warn(
|
|
6669
|
+
console.warn(chalk59.yellow(`Publint [custom]: root-level "${field}" field should not be in package.json (use --fix to remove)`));
|
|
6574
6670
|
}
|
|
6575
6671
|
result.warnings++;
|
|
6576
6672
|
}
|
|
@@ -6580,8 +6676,8 @@ function checkRootSource(pkg, fix2) {
|
|
|
6580
6676
|
function checkResolutions(pkg) {
|
|
6581
6677
|
const result = emptyCustomResult();
|
|
6582
6678
|
if (pkg.resolutions !== void 0) {
|
|
6583
|
-
console.warn(
|
|
6584
|
-
console.warn(
|
|
6679
|
+
console.warn(chalk59.yellow('Publint [custom]: "resolutions" in use'));
|
|
6680
|
+
console.warn(chalk59.gray(JSON.stringify(pkg.resolutions, null, 2)));
|
|
6585
6681
|
result.warnings++;
|
|
6586
6682
|
}
|
|
6587
6683
|
return result;
|
|
@@ -6593,10 +6689,10 @@ function checkImportToDefault(pkg, fix2) {
|
|
|
6593
6689
|
if (!hasImportKeyInExports(exports)) return result;
|
|
6594
6690
|
if (fix2) {
|
|
6595
6691
|
replaceImportWithDefault(exports);
|
|
6596
|
-
console.warn(
|
|
6692
|
+
console.warn(chalk59.yellow('Publint [custom]: renamed "import" to "default" in "exports" and ensured "types" siblings'));
|
|
6597
6693
|
result.modified = true;
|
|
6598
6694
|
} else {
|
|
6599
|
-
console.warn(
|
|
6695
|
+
console.warn(chalk59.yellow('Publint [custom]: "import" entries in "exports" should use "default" instead (use --fix to rename)'));
|
|
6600
6696
|
}
|
|
6601
6697
|
result.warnings++;
|
|
6602
6698
|
return result;
|
|
@@ -6608,10 +6704,10 @@ function checkRootTypes(pkg, fix2) {
|
|
|
6608
6704
|
if (!exports || typeof exports !== "object" || !hasTypesInExports(exports)) return result;
|
|
6609
6705
|
if (fix2) {
|
|
6610
6706
|
delete pkg.types;
|
|
6611
|
-
console.warn(
|
|
6707
|
+
console.warn(chalk59.yellow('Publint [custom]: removed redundant root "types" field (already defined in "exports")'));
|
|
6612
6708
|
result.modified = true;
|
|
6613
6709
|
} else {
|
|
6614
|
-
console.warn(
|
|
6710
|
+
console.warn(chalk59.yellow('Publint [custom]: root "types" field is redundant when "exports" defines types (use --fix to remove)'));
|
|
6615
6711
|
}
|
|
6616
6712
|
result.warnings++;
|
|
6617
6713
|
return result;
|
|
@@ -6683,15 +6779,15 @@ async function runPublintLibrary(pkgDir, pkg, strict, pack) {
|
|
|
6683
6779
|
for (const message of messages) {
|
|
6684
6780
|
switch (message.type) {
|
|
6685
6781
|
case "error": {
|
|
6686
|
-
console.error(
|
|
6782
|
+
console.error(chalk59.red(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
6687
6783
|
break;
|
|
6688
6784
|
}
|
|
6689
6785
|
case "warning": {
|
|
6690
|
-
console.warn(
|
|
6786
|
+
console.warn(chalk59.yellow(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
6691
6787
|
break;
|
|
6692
6788
|
}
|
|
6693
6789
|
default: {
|
|
6694
|
-
console.log(
|
|
6790
|
+
console.log(chalk59.white(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
6695
6791
|
break;
|
|
6696
6792
|
}
|
|
6697
6793
|
}
|
|
@@ -6714,8 +6810,8 @@ var packagePublint = async ({
|
|
|
6714
6810
|
await fs17.writeFile(`${pkgDir}/package.json`, sortedPkg);
|
|
6715
6811
|
const pkg = JSON.parse(await fs17.readFile(`${pkgDir}/package.json`, "utf8"));
|
|
6716
6812
|
const effectiveExclude = pkg.private ? /* @__PURE__ */ new Set([...exclude, ...PUBLISH_ONLY_CHECKS]) : exclude;
|
|
6717
|
-
console.log(
|
|
6718
|
-
console.log(
|
|
6813
|
+
console.log(chalk59.green(`Publint: ${String(pkg.name)}${pkg.private ? chalk59.gray(" (private)") : ""}`));
|
|
6814
|
+
console.log(chalk59.gray(pkgDir));
|
|
6719
6815
|
let libraryErrors = 0;
|
|
6720
6816
|
if (!effectiveExclude.has("publint")) {
|
|
6721
6817
|
const library = await runPublintLibrary(pkgDir, pkg, strict, pack);
|
|
@@ -6736,12 +6832,12 @@ var packageRecompile = async () => {
|
|
|
6736
6832
|
|
|
6737
6833
|
// src/actions/package-lint.ts
|
|
6738
6834
|
import {
|
|
6739
|
-
existsSync as
|
|
6740
|
-
readFileSync as
|
|
6741
|
-
writeFileSync as
|
|
6835
|
+
existsSync as existsSync16,
|
|
6836
|
+
readFileSync as readFileSync24,
|
|
6837
|
+
writeFileSync as writeFileSync11
|
|
6742
6838
|
} from "fs";
|
|
6743
|
-
import
|
|
6744
|
-
import
|
|
6839
|
+
import PATH20 from "path";
|
|
6840
|
+
import chalk60 from "chalk";
|
|
6745
6841
|
import picomatch2 from "picomatch";
|
|
6746
6842
|
import semver8 from "semver";
|
|
6747
6843
|
function emptyResult() {
|
|
@@ -6752,18 +6848,18 @@ function emptyResult() {
|
|
|
6752
6848
|
};
|
|
6753
6849
|
}
|
|
6754
6850
|
function readRootPackageJson(cwd6) {
|
|
6755
|
-
const raw =
|
|
6851
|
+
const raw = readFileSync24(PATH20.resolve(cwd6, "package.json"), "utf8");
|
|
6756
6852
|
return JSON.parse(raw);
|
|
6757
6853
|
}
|
|
6758
6854
|
function writeRootPackageJson(cwd6, pkg) {
|
|
6759
|
-
const path19 =
|
|
6760
|
-
|
|
6855
|
+
const path19 = PATH20.resolve(cwd6, "package.json");
|
|
6856
|
+
writeFileSync11(path19, `${JSON.stringify(pkg, null, 2)}
|
|
6761
6857
|
`, "utf8");
|
|
6762
6858
|
}
|
|
6763
6859
|
function readPnpmWorkspaceGlobs(cwd6) {
|
|
6764
|
-
const wsPath =
|
|
6765
|
-
if (!
|
|
6766
|
-
const raw =
|
|
6860
|
+
const wsPath = PATH20.resolve(cwd6, "pnpm-workspace.yaml");
|
|
6861
|
+
if (!existsSync16(wsPath)) return void 0;
|
|
6862
|
+
const raw = readFileSync24(wsPath, "utf8");
|
|
6767
6863
|
const globs = [];
|
|
6768
6864
|
let inPackages = false;
|
|
6769
6865
|
for (const line of raw.split("\n")) {
|
|
@@ -6807,7 +6903,7 @@ function checkRootPrivate(pkg) {
|
|
|
6807
6903
|
function fixRootPrivate(cwd6, pkg) {
|
|
6808
6904
|
pkg.private = true;
|
|
6809
6905
|
writeRootPackageJson(cwd6, pkg);
|
|
6810
|
-
console.log(
|
|
6906
|
+
console.log(chalk60.green(' \u2714 Fixed: set "private": true in root package.json'));
|
|
6811
6907
|
}
|
|
6812
6908
|
function checkNoPublishConfigOnPrivate(pkg) {
|
|
6813
6909
|
const result = emptyResult();
|
|
@@ -6819,15 +6915,15 @@ function checkNoPublishConfigOnPrivate(pkg) {
|
|
|
6819
6915
|
function fixNoPublishConfigOnPrivate(cwd6, pkg) {
|
|
6820
6916
|
delete pkg.publishConfig;
|
|
6821
6917
|
writeRootPackageJson(cwd6, pkg);
|
|
6822
|
-
console.log(
|
|
6918
|
+
console.log(chalk60.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
|
|
6823
6919
|
}
|
|
6824
6920
|
function checkNoPackageManagerInWorkspaces(cwd6, workspaces) {
|
|
6825
6921
|
const result = emptyResult();
|
|
6826
6922
|
for (const { location, name } of workspaces) {
|
|
6827
6923
|
if (location === ".") continue;
|
|
6828
|
-
const pkgPath =
|
|
6924
|
+
const pkgPath = PATH20.resolve(cwd6, location, "package.json");
|
|
6829
6925
|
try {
|
|
6830
|
-
const raw =
|
|
6926
|
+
const raw = readFileSync24(pkgPath, "utf8");
|
|
6831
6927
|
const pkg = JSON.parse(raw);
|
|
6832
6928
|
if (pkg.packageManager) {
|
|
6833
6929
|
result.fixable.push(`${name} (${location}) has a packageManager field \u2014 only the root should define this`);
|
|
@@ -6840,15 +6936,15 @@ function checkNoPackageManagerInWorkspaces(cwd6, workspaces) {
|
|
|
6840
6936
|
function fixNoPackageManagerInWorkspaces(cwd6, _pkg, workspaces) {
|
|
6841
6937
|
for (const { location } of workspaces) {
|
|
6842
6938
|
if (location === ".") continue;
|
|
6843
|
-
const pkgPath =
|
|
6939
|
+
const pkgPath = PATH20.resolve(cwd6, location, "package.json");
|
|
6844
6940
|
try {
|
|
6845
|
-
const raw =
|
|
6941
|
+
const raw = readFileSync24(pkgPath, "utf8");
|
|
6846
6942
|
const pkg = JSON.parse(raw);
|
|
6847
6943
|
if (pkg.packageManager) {
|
|
6848
6944
|
delete pkg.packageManager;
|
|
6849
|
-
|
|
6945
|
+
writeFileSync11(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
6850
6946
|
`, "utf8");
|
|
6851
|
-
console.log(
|
|
6947
|
+
console.log(chalk60.green(` \u2714 Fixed: removed packageManager from ${location}/package.json`));
|
|
6852
6948
|
}
|
|
6853
6949
|
} catch {
|
|
6854
6950
|
}
|
|
@@ -6858,9 +6954,9 @@ function checkWorkspacesFieldPlacement(cwd6, pm, workspaces) {
|
|
|
6858
6954
|
const result = emptyResult();
|
|
6859
6955
|
for (const { location, name } of workspaces) {
|
|
6860
6956
|
if (pm === "pnpm" ? true : location !== ".") {
|
|
6861
|
-
const pkgPath =
|
|
6957
|
+
const pkgPath = PATH20.resolve(cwd6, location, "package.json");
|
|
6862
6958
|
try {
|
|
6863
|
-
const pkg = JSON.parse(
|
|
6959
|
+
const pkg = JSON.parse(readFileSync24(pkgPath, "utf8"));
|
|
6864
6960
|
if (pkg.workspaces) {
|
|
6865
6961
|
const label = location === "." ? "Root" : `${name} (${location})`;
|
|
6866
6962
|
const reason = pm === "pnpm" ? "pnpm uses pnpm-workspace.yaml instead" : "only the root should define workspaces";
|
|
@@ -6875,15 +6971,15 @@ function checkWorkspacesFieldPlacement(cwd6, pm, workspaces) {
|
|
|
6875
6971
|
function fixWorkspacesFieldPlacement(cwd6, pm, workspaces) {
|
|
6876
6972
|
for (const { location } of workspaces) {
|
|
6877
6973
|
if (pm === "pnpm" ? true : location !== ".") {
|
|
6878
|
-
const pkgPath =
|
|
6974
|
+
const pkgPath = PATH20.resolve(cwd6, location, "package.json");
|
|
6879
6975
|
try {
|
|
6880
|
-
const pkg = JSON.parse(
|
|
6976
|
+
const pkg = JSON.parse(readFileSync24(pkgPath, "utf8"));
|
|
6881
6977
|
if (pkg.workspaces) {
|
|
6882
6978
|
delete pkg.workspaces;
|
|
6883
|
-
|
|
6979
|
+
writeFileSync11(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
6884
6980
|
`, "utf8");
|
|
6885
6981
|
const label = location === "." ? "root" : location;
|
|
6886
|
-
console.log(
|
|
6982
|
+
console.log(chalk60.green(` \u2714 Fixed: removed workspaces from ${label}/package.json`));
|
|
6887
6983
|
}
|
|
6888
6984
|
} catch {
|
|
6889
6985
|
}
|
|
@@ -6913,22 +7009,22 @@ function logResults(label, result, fix2) {
|
|
|
6913
7009
|
let errors = 0;
|
|
6914
7010
|
let fixed = 0;
|
|
6915
7011
|
for (const error of result.errors) {
|
|
6916
|
-
console.log(
|
|
7012
|
+
console.log(chalk60.red(` \u2717 ${error}`));
|
|
6917
7013
|
errors++;
|
|
6918
7014
|
}
|
|
6919
7015
|
for (const fixable of result.fixable) {
|
|
6920
7016
|
if (fix2) {
|
|
6921
7017
|
fixed++;
|
|
6922
7018
|
} else {
|
|
6923
|
-
console.log(
|
|
7019
|
+
console.log(chalk60.red(` \u2717 ${fixable} (fixable)`));
|
|
6924
7020
|
errors++;
|
|
6925
7021
|
}
|
|
6926
7022
|
}
|
|
6927
7023
|
for (const warning of result.warnings) {
|
|
6928
|
-
console.log(
|
|
7024
|
+
console.log(chalk60.yellow(` \u26A0 ${warning}`));
|
|
6929
7025
|
}
|
|
6930
7026
|
if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
|
|
6931
|
-
console.log(
|
|
7027
|
+
console.log(chalk60.green(` \u2713 ${label}`));
|
|
6932
7028
|
}
|
|
6933
7029
|
return { errors, fixed };
|
|
6934
7030
|
}
|
|
@@ -6950,9 +7046,9 @@ function checkVoltaOnlyInRoot(cwd6, workspaces) {
|
|
|
6950
7046
|
const result = emptyResult();
|
|
6951
7047
|
for (const { location, name } of workspaces) {
|
|
6952
7048
|
if (location === ".") continue;
|
|
6953
|
-
const pkgPath =
|
|
7049
|
+
const pkgPath = PATH20.resolve(cwd6, location, "package.json");
|
|
6954
7050
|
try {
|
|
6955
|
-
const pkg = JSON.parse(
|
|
7051
|
+
const pkg = JSON.parse(readFileSync24(pkgPath, "utf8"));
|
|
6956
7052
|
if (pkg.volta) {
|
|
6957
7053
|
result.fixable.push(`${name} (${location}) has a volta field \u2014 only the root should define this`);
|
|
6958
7054
|
}
|
|
@@ -6964,15 +7060,15 @@ function checkVoltaOnlyInRoot(cwd6, workspaces) {
|
|
|
6964
7060
|
function fixVoltaOnlyInRoot(cwd6, _pkg, workspaces) {
|
|
6965
7061
|
for (const { location } of workspaces) {
|
|
6966
7062
|
if (location === ".") continue;
|
|
6967
|
-
const pkgPath =
|
|
7063
|
+
const pkgPath = PATH20.resolve(cwd6, location, "package.json");
|
|
6968
7064
|
try {
|
|
6969
|
-
const raw =
|
|
7065
|
+
const raw = readFileSync24(pkgPath, "utf8");
|
|
6970
7066
|
const pkg = JSON.parse(raw);
|
|
6971
7067
|
if (pkg.volta) {
|
|
6972
7068
|
delete pkg.volta;
|
|
6973
|
-
|
|
7069
|
+
writeFileSync11(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
6974
7070
|
`, "utf8");
|
|
6975
|
-
console.log(
|
|
7071
|
+
console.log(chalk60.green(` \u2714 Fixed: removed volta from ${location}/package.json`));
|
|
6976
7072
|
}
|
|
6977
7073
|
} catch {
|
|
6978
7074
|
}
|
|
@@ -6983,15 +7079,15 @@ function isTerminalPackage2(pkg) {
|
|
|
6983
7079
|
}
|
|
6984
7080
|
function checkEnginesOnlyInNonTerminal(cwd6, workspaces) {
|
|
6985
7081
|
const result = emptyResult();
|
|
6986
|
-
const rootPkg = JSON.parse(
|
|
7082
|
+
const rootPkg = JSON.parse(readFileSync24(PATH20.resolve(cwd6, "package.json"), "utf8"));
|
|
6987
7083
|
if (rootPkg.engines) {
|
|
6988
7084
|
result.fixable.push("Root package.json has engines \u2014 terminal packages should not declare engines (use volta instead)");
|
|
6989
7085
|
}
|
|
6990
7086
|
for (const { location, name } of workspaces) {
|
|
6991
7087
|
if (location === ".") continue;
|
|
6992
|
-
const pkgPath =
|
|
7088
|
+
const pkgPath = PATH20.resolve(cwd6, location, "package.json");
|
|
6993
7089
|
try {
|
|
6994
|
-
const pkg = JSON.parse(
|
|
7090
|
+
const pkg = JSON.parse(readFileSync24(pkgPath, "utf8"));
|
|
6995
7091
|
if (isTerminalPackage2(pkg) && pkg.engines) {
|
|
6996
7092
|
result.fixable.push(`${name} (${location}) is terminal (private) but has engines \u2014 terminal packages should not declare engines`);
|
|
6997
7093
|
}
|
|
@@ -7004,33 +7100,33 @@ function checkEnginesOnlyInNonTerminal(cwd6, workspaces) {
|
|
|
7004
7100
|
return result;
|
|
7005
7101
|
}
|
|
7006
7102
|
function fixEnginesOnlyInNonTerminal(cwd6, _pkg, workspaces) {
|
|
7007
|
-
const rootPath =
|
|
7008
|
-
const rootRaw =
|
|
7103
|
+
const rootPath = PATH20.resolve(cwd6, "package.json");
|
|
7104
|
+
const rootRaw = readFileSync24(rootPath, "utf8");
|
|
7009
7105
|
const rootPkg = JSON.parse(rootRaw);
|
|
7010
7106
|
if (rootPkg.engines) {
|
|
7011
7107
|
delete rootPkg.engines;
|
|
7012
|
-
|
|
7108
|
+
writeFileSync11(rootPath, `${JSON.stringify(rootPkg, null, 2)}
|
|
7013
7109
|
`, "utf8");
|
|
7014
|
-
console.log(
|
|
7110
|
+
console.log(chalk60.green(" \u2714 Fixed: removed engines from root package.json"));
|
|
7015
7111
|
}
|
|
7016
7112
|
const enginesTemplate = resolveEnginesTemplate(cwd6, workspaces);
|
|
7017
7113
|
for (const { location } of workspaces) {
|
|
7018
7114
|
if (location === ".") continue;
|
|
7019
|
-
const pkgPath =
|
|
7115
|
+
const pkgPath = PATH20.resolve(cwd6, location, "package.json");
|
|
7020
7116
|
try {
|
|
7021
|
-
const raw =
|
|
7117
|
+
const raw = readFileSync24(pkgPath, "utf8");
|
|
7022
7118
|
const pkg = JSON.parse(raw);
|
|
7023
7119
|
if (isTerminalPackage2(pkg) && pkg.engines) {
|
|
7024
7120
|
delete pkg.engines;
|
|
7025
|
-
|
|
7121
|
+
writeFileSync11(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
7026
7122
|
`, "utf8");
|
|
7027
|
-
console.log(
|
|
7123
|
+
console.log(chalk60.green(` \u2714 Fixed: removed engines from ${location}/package.json`));
|
|
7028
7124
|
}
|
|
7029
7125
|
if (!isTerminalPackage2(pkg) && !pkg.engines && enginesTemplate) {
|
|
7030
7126
|
pkg.engines = enginesTemplate;
|
|
7031
|
-
|
|
7127
|
+
writeFileSync11(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
7032
7128
|
`, "utf8");
|
|
7033
|
-
console.log(
|
|
7129
|
+
console.log(chalk60.green(` \u2714 Fixed: added engines to ${location}/package.json`));
|
|
7034
7130
|
}
|
|
7035
7131
|
} catch {
|
|
7036
7132
|
}
|
|
@@ -7040,7 +7136,7 @@ function resolveEnginesTemplate(cwd6, workspaces) {
|
|
|
7040
7136
|
for (const { location } of workspaces) {
|
|
7041
7137
|
if (location === ".") continue;
|
|
7042
7138
|
try {
|
|
7043
|
-
const pkg = JSON.parse(
|
|
7139
|
+
const pkg = JSON.parse(readFileSync24(PATH20.resolve(cwd6, location, "package.json"), "utf8"));
|
|
7044
7140
|
if (!isTerminalPackage2(pkg) && pkg.engines) {
|
|
7045
7141
|
return pkg.engines;
|
|
7046
7142
|
}
|
|
@@ -7058,9 +7154,9 @@ function checkVersionsIncludeLts(cwd6, workspaces) {
|
|
|
7058
7154
|
yarn: latestVersions.yarn
|
|
7059
7155
|
};
|
|
7060
7156
|
for (const { location, name } of workspaces) {
|
|
7061
|
-
const pkgPath = location === "." ?
|
|
7157
|
+
const pkgPath = location === "." ? PATH20.resolve(cwd6, "package.json") : PATH20.resolve(cwd6, location, "package.json");
|
|
7062
7158
|
try {
|
|
7063
|
-
const pkg = JSON.parse(
|
|
7159
|
+
const pkg = JSON.parse(readFileSync24(pkgPath, "utf8"));
|
|
7064
7160
|
const label = location === "." ? "root" : `${name} (${location})`;
|
|
7065
7161
|
const engines = pkg.engines;
|
|
7066
7162
|
if (engines) {
|
|
@@ -7091,14 +7187,14 @@ function checkVersionsIncludeLts(cwd6, workspaces) {
|
|
|
7091
7187
|
}
|
|
7092
7188
|
function logSummary(errors, fixed) {
|
|
7093
7189
|
if (fixed > 0) {
|
|
7094
|
-
console.log(
|
|
7190
|
+
console.log(chalk60.green(`
|
|
7095
7191
|
Fixed ${fixed} issue(s)`));
|
|
7096
7192
|
}
|
|
7097
7193
|
if (errors > 0) {
|
|
7098
|
-
console.log(
|
|
7194
|
+
console.log(chalk60.red(`
|
|
7099
7195
|
${errors} error(s) found`));
|
|
7100
7196
|
} else if (fixed === 0) {
|
|
7101
|
-
console.log(
|
|
7197
|
+
console.log(chalk60.green("\n All checks passed"));
|
|
7102
7198
|
}
|
|
7103
7199
|
}
|
|
7104
7200
|
function packageLintMonorepo(fix2 = false) {
|
|
@@ -7107,14 +7203,14 @@ function packageLintMonorepo(fix2 = false) {
|
|
|
7107
7203
|
try {
|
|
7108
7204
|
pkg = readRootPackageJson(cwd6);
|
|
7109
7205
|
} catch {
|
|
7110
|
-
console.error(
|
|
7206
|
+
console.error(chalk60.red("Could not read package.json"));
|
|
7111
7207
|
return 1;
|
|
7112
7208
|
}
|
|
7113
7209
|
if (!isMonorepo(pkg, cwd6)) {
|
|
7114
|
-
console.log(
|
|
7210
|
+
console.log(chalk60.gray("Not a monorepo \u2014 skipping repo lint checks"));
|
|
7115
7211
|
return 0;
|
|
7116
7212
|
}
|
|
7117
|
-
console.log(
|
|
7213
|
+
console.log(chalk60.green("Repo Lint"));
|
|
7118
7214
|
const pm = detectPackageManager();
|
|
7119
7215
|
const workspaces = getPackageManager().listWorkspaces();
|
|
7120
7216
|
const internalDepCheck = pm === "pnpm" ? {
|
|
@@ -7188,34 +7284,34 @@ function packageLintMonorepo(fix2 = false) {
|
|
|
7188
7284
|
|
|
7189
7285
|
// src/actions/packman/clean.ts
|
|
7190
7286
|
import {
|
|
7191
|
-
existsSync as
|
|
7287
|
+
existsSync as existsSync22,
|
|
7192
7288
|
rmSync as rmSync5,
|
|
7193
|
-
writeFileSync as
|
|
7289
|
+
writeFileSync as writeFileSync16
|
|
7194
7290
|
} from "fs";
|
|
7195
|
-
import
|
|
7196
|
-
import
|
|
7291
|
+
import PATH25 from "path";
|
|
7292
|
+
import chalk66 from "chalk";
|
|
7197
7293
|
|
|
7198
7294
|
// src/actions/packman/convert.ts
|
|
7199
7295
|
import {
|
|
7200
|
-
existsSync as
|
|
7296
|
+
existsSync as existsSync21,
|
|
7201
7297
|
readdirSync as readdirSync9,
|
|
7202
|
-
readFileSync as
|
|
7298
|
+
readFileSync as readFileSync29,
|
|
7203
7299
|
statSync as statSync4
|
|
7204
7300
|
} from "fs";
|
|
7205
|
-
import
|
|
7206
|
-
import
|
|
7301
|
+
import PATH24 from "path";
|
|
7302
|
+
import chalk65 from "chalk";
|
|
7207
7303
|
|
|
7208
7304
|
// src/actions/packman/convertToPnpm.ts
|
|
7209
7305
|
import { spawnSync as spawnSync10 } from "child_process";
|
|
7210
7306
|
import {
|
|
7211
|
-
existsSync as
|
|
7307
|
+
existsSync as existsSync19,
|
|
7212
7308
|
mkdirSync as mkdirSync5,
|
|
7213
|
-
readFileSync as
|
|
7309
|
+
readFileSync as readFileSync27,
|
|
7214
7310
|
rmSync as rmSync3,
|
|
7215
|
-
writeFileSync as
|
|
7311
|
+
writeFileSync as writeFileSync14
|
|
7216
7312
|
} from "fs";
|
|
7217
|
-
import
|
|
7218
|
-
import
|
|
7313
|
+
import PATH22 from "path";
|
|
7314
|
+
import chalk63 from "chalk";
|
|
7219
7315
|
|
|
7220
7316
|
// src/actions/packman/rewriteScripts.ts
|
|
7221
7317
|
function rewriteYarnToPnpm(script) {
|
|
@@ -7267,11 +7363,11 @@ function rewriteScriptsInPackageJson(pkg, direction) {
|
|
|
7267
7363
|
|
|
7268
7364
|
// src/actions/packman/rewriteSourceImports.ts
|
|
7269
7365
|
import {
|
|
7270
|
-
existsSync as
|
|
7271
|
-
readFileSync as
|
|
7272
|
-
writeFileSync as
|
|
7366
|
+
existsSync as existsSync17,
|
|
7367
|
+
readFileSync as readFileSync25,
|
|
7368
|
+
writeFileSync as writeFileSync12
|
|
7273
7369
|
} from "fs";
|
|
7274
|
-
import
|
|
7370
|
+
import chalk61 from "chalk";
|
|
7275
7371
|
import { globSync as globSync4 } from "glob";
|
|
7276
7372
|
var IMPORT_SWAP_MAP = {
|
|
7277
7373
|
"yarn-to-pnpm": [
|
|
@@ -7306,30 +7402,30 @@ function rewriteSourceImports(cwd6, direction) {
|
|
|
7306
7402
|
});
|
|
7307
7403
|
let count = 0;
|
|
7308
7404
|
for (const file of files) {
|
|
7309
|
-
if (!
|
|
7310
|
-
const original =
|
|
7405
|
+
if (!existsSync17(file)) continue;
|
|
7406
|
+
const original = readFileSync25(file, "utf8");
|
|
7311
7407
|
let content = original;
|
|
7312
7408
|
for (const [from, to] of swaps) {
|
|
7313
7409
|
content = content.replaceAll(from, to);
|
|
7314
7410
|
}
|
|
7315
7411
|
if (content !== original) {
|
|
7316
|
-
|
|
7412
|
+
writeFileSync12(file, content, "utf8");
|
|
7317
7413
|
count++;
|
|
7318
7414
|
}
|
|
7319
7415
|
}
|
|
7320
7416
|
if (count > 0) {
|
|
7321
|
-
console.log(
|
|
7417
|
+
console.log(chalk61.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
7322
7418
|
}
|
|
7323
7419
|
}
|
|
7324
7420
|
|
|
7325
7421
|
// src/actions/packman/swapTsScriptsDependency.ts
|
|
7326
7422
|
import {
|
|
7327
|
-
existsSync as
|
|
7328
|
-
readFileSync as
|
|
7329
|
-
writeFileSync as
|
|
7423
|
+
existsSync as existsSync18,
|
|
7424
|
+
readFileSync as readFileSync26,
|
|
7425
|
+
writeFileSync as writeFileSync13
|
|
7330
7426
|
} from "fs";
|
|
7331
|
-
import
|
|
7332
|
-
import
|
|
7427
|
+
import PATH21 from "path";
|
|
7428
|
+
import chalk62 from "chalk";
|
|
7333
7429
|
var SWAP_MAP = {
|
|
7334
7430
|
"yarn-to-pnpm": [
|
|
7335
7431
|
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
@@ -7339,8 +7435,8 @@ var SWAP_MAP = {
|
|
|
7339
7435
|
]
|
|
7340
7436
|
};
|
|
7341
7437
|
function swapInPackageJson(pkgPath, direction) {
|
|
7342
|
-
if (!
|
|
7343
|
-
const raw =
|
|
7438
|
+
if (!existsSync18(pkgPath)) return false;
|
|
7439
|
+
const raw = readFileSync26(pkgPath, "utf8");
|
|
7344
7440
|
const pkg = JSON.parse(raw);
|
|
7345
7441
|
let changed = false;
|
|
7346
7442
|
for (const depField of ["dependencies", "devDependencies"]) {
|
|
@@ -7355,24 +7451,24 @@ function swapInPackageJson(pkgPath, direction) {
|
|
|
7355
7451
|
}
|
|
7356
7452
|
}
|
|
7357
7453
|
if (changed) {
|
|
7358
|
-
|
|
7454
|
+
writeFileSync13(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
7359
7455
|
}
|
|
7360
7456
|
return changed;
|
|
7361
7457
|
}
|
|
7362
7458
|
function swapTsScriptsDependency(cwd6, workspacePackageJsonPaths, direction) {
|
|
7363
7459
|
let count = 0;
|
|
7364
|
-
if (swapInPackageJson(
|
|
7460
|
+
if (swapInPackageJson(PATH21.join(cwd6, "package.json"), direction)) {
|
|
7365
7461
|
count++;
|
|
7366
7462
|
}
|
|
7367
7463
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
7368
|
-
const fullPath =
|
|
7464
|
+
const fullPath = PATH21.resolve(cwd6, pkgPath, "package.json");
|
|
7369
7465
|
if (swapInPackageJson(fullPath, direction)) {
|
|
7370
7466
|
count++;
|
|
7371
7467
|
}
|
|
7372
7468
|
}
|
|
7373
7469
|
if (count > 0) {
|
|
7374
7470
|
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
7375
|
-
console.log(
|
|
7471
|
+
console.log(chalk62.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
7376
7472
|
}
|
|
7377
7473
|
}
|
|
7378
7474
|
|
|
@@ -7383,13 +7479,13 @@ function createPnpmWorkspaceYaml(cwd6, workspacePatterns) {
|
|
|
7383
7479
|
for (const pattern of workspacePatterns) {
|
|
7384
7480
|
lines.push(` - '${pattern}'`);
|
|
7385
7481
|
}
|
|
7386
|
-
|
|
7387
|
-
console.log(
|
|
7482
|
+
writeFileSync14(PATH22.join(cwd6, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
7483
|
+
console.log(chalk63.green(" Created pnpm-workspace.yaml"));
|
|
7388
7484
|
}
|
|
7389
7485
|
function readPnpmWorkspacePatterns(cwd6) {
|
|
7390
|
-
const wsPath =
|
|
7391
|
-
if (!
|
|
7392
|
-
const content =
|
|
7486
|
+
const wsPath = PATH22.join(cwd6, "pnpm-workspace.yaml");
|
|
7487
|
+
if (!existsSync19(wsPath)) return [];
|
|
7488
|
+
const content = readFileSync27(wsPath, "utf8");
|
|
7393
7489
|
const patterns = [];
|
|
7394
7490
|
const lines = content.split("\n");
|
|
7395
7491
|
let inPackages = false;
|
|
@@ -7408,20 +7504,20 @@ function readPnpmWorkspacePatterns(cwd6) {
|
|
|
7408
7504
|
return patterns;
|
|
7409
7505
|
}
|
|
7410
7506
|
function updateRootPackageJson(cwd6) {
|
|
7411
|
-
const pkgPath =
|
|
7412
|
-
const pkg = JSON.parse(
|
|
7507
|
+
const pkgPath = PATH22.join(cwd6, "package.json");
|
|
7508
|
+
const pkg = JSON.parse(readFileSync27(pkgPath, "utf8"));
|
|
7413
7509
|
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd6);
|
|
7414
7510
|
delete pkg.workspaces;
|
|
7415
7511
|
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
7416
7512
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
7417
|
-
|
|
7418
|
-
console.log(
|
|
7513
|
+
writeFileSync14(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
7514
|
+
console.log(chalk63.green(" Updated root package.json"));
|
|
7419
7515
|
return workspacePatterns;
|
|
7420
7516
|
}
|
|
7421
7517
|
function updateGitignore(cwd6) {
|
|
7422
|
-
const gitignorePath =
|
|
7423
|
-
if (!
|
|
7424
|
-
let content =
|
|
7518
|
+
const gitignorePath = PATH22.join(cwd6, ".gitignore");
|
|
7519
|
+
if (!existsSync19(gitignorePath)) return;
|
|
7520
|
+
let content = readFileSync27(gitignorePath, "utf8");
|
|
7425
7521
|
const yarnLines = [
|
|
7426
7522
|
".pnp.*",
|
|
7427
7523
|
".pnp",
|
|
@@ -7436,53 +7532,53 @@ function updateGitignore(cwd6) {
|
|
|
7436
7532
|
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
7437
7533
|
}
|
|
7438
7534
|
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
7439
|
-
|
|
7440
|
-
console.log(
|
|
7535
|
+
writeFileSync14(gitignorePath, content, "utf8");
|
|
7536
|
+
console.log(chalk63.green(" Updated .gitignore"));
|
|
7441
7537
|
}
|
|
7442
7538
|
function deleteYarnArtifacts(cwd6) {
|
|
7443
|
-
const yarnLock =
|
|
7444
|
-
const yarnrc =
|
|
7445
|
-
const yarnDir =
|
|
7446
|
-
if (
|
|
7539
|
+
const yarnLock = PATH22.join(cwd6, "yarn.lock");
|
|
7540
|
+
const yarnrc = PATH22.join(cwd6, ".yarnrc.yml");
|
|
7541
|
+
const yarnDir = PATH22.join(cwd6, ".yarn");
|
|
7542
|
+
if (existsSync19(yarnLock)) {
|
|
7447
7543
|
rmSync3(yarnLock);
|
|
7448
|
-
console.log(
|
|
7544
|
+
console.log(chalk63.gray(" Deleted yarn.lock"));
|
|
7449
7545
|
}
|
|
7450
|
-
if (
|
|
7546
|
+
if (existsSync19(yarnrc)) {
|
|
7451
7547
|
rmSync3(yarnrc);
|
|
7452
|
-
console.log(
|
|
7548
|
+
console.log(chalk63.gray(" Deleted .yarnrc.yml"));
|
|
7453
7549
|
}
|
|
7454
|
-
if (
|
|
7550
|
+
if (existsSync19(yarnDir)) {
|
|
7455
7551
|
rmSync3(yarnDir, { force: true, recursive: true });
|
|
7456
|
-
console.log(
|
|
7552
|
+
console.log(chalk63.gray(" Deleted .yarn/"));
|
|
7457
7553
|
}
|
|
7458
7554
|
}
|
|
7459
7555
|
function createNpmrc(cwd6) {
|
|
7460
|
-
const npmrcPath =
|
|
7461
|
-
if (
|
|
7462
|
-
mkdirSync5(
|
|
7463
|
-
|
|
7464
|
-
console.log(
|
|
7556
|
+
const npmrcPath = PATH22.join(cwd6, ".npmrc");
|
|
7557
|
+
if (existsSync19(npmrcPath)) return;
|
|
7558
|
+
mkdirSync5(PATH22.dirname(npmrcPath), { recursive: true });
|
|
7559
|
+
writeFileSync14(npmrcPath, "", "utf8");
|
|
7560
|
+
console.log(chalk63.green(" Created .npmrc"));
|
|
7465
7561
|
}
|
|
7466
7562
|
function convertToPnpm(cwd6, workspacePackageJsonPaths) {
|
|
7467
|
-
console.log(
|
|
7563
|
+
console.log(chalk63.blue("\nConverting to pnpm...\n"));
|
|
7468
7564
|
const workspacePatterns = updateRootPackageJson(cwd6);
|
|
7469
7565
|
createPnpmWorkspaceYaml(cwd6, workspacePatterns);
|
|
7470
7566
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
7471
|
-
const fullPath =
|
|
7472
|
-
if (!
|
|
7473
|
-
const pkg = JSON.parse(
|
|
7567
|
+
const fullPath = PATH22.resolve(cwd6, pkgPath, "package.json");
|
|
7568
|
+
if (!existsSync19(fullPath)) continue;
|
|
7569
|
+
const pkg = JSON.parse(readFileSync27(fullPath, "utf8"));
|
|
7474
7570
|
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
7475
7571
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
7476
|
-
|
|
7572
|
+
writeFileSync14(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
7477
7573
|
}
|
|
7478
7574
|
}
|
|
7479
|
-
console.log(
|
|
7575
|
+
console.log(chalk63.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
7480
7576
|
updateGitignore(cwd6);
|
|
7481
7577
|
createNpmrc(cwd6);
|
|
7482
7578
|
swapTsScriptsDependency(cwd6, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
7483
7579
|
rewriteSourceImports(cwd6, "yarn-to-pnpm");
|
|
7484
7580
|
deleteYarnArtifacts(cwd6);
|
|
7485
|
-
console.log(
|
|
7581
|
+
console.log(chalk63.blue("\nRunning pnpm install..."));
|
|
7486
7582
|
const install = spawnSync10("pnpm", ["install"], {
|
|
7487
7583
|
cwd: cwd6,
|
|
7488
7584
|
encoding: "utf8",
|
|
@@ -7490,23 +7586,23 @@ function convertToPnpm(cwd6, workspacePackageJsonPaths) {
|
|
|
7490
7586
|
stdio: "inherit"
|
|
7491
7587
|
});
|
|
7492
7588
|
if (install.status !== 0) {
|
|
7493
|
-
console.error(
|
|
7589
|
+
console.error(chalk63.red("pnpm install failed"));
|
|
7494
7590
|
return 1;
|
|
7495
7591
|
}
|
|
7496
|
-
console.log(
|
|
7592
|
+
console.log(chalk63.blue("\nConversion complete.\n"));
|
|
7497
7593
|
return 0;
|
|
7498
7594
|
}
|
|
7499
7595
|
|
|
7500
7596
|
// src/actions/packman/convertToYarn.ts
|
|
7501
7597
|
import { spawnSync as spawnSync11 } from "child_process";
|
|
7502
7598
|
import {
|
|
7503
|
-
existsSync as
|
|
7504
|
-
readFileSync as
|
|
7599
|
+
existsSync as existsSync20,
|
|
7600
|
+
readFileSync as readFileSync28,
|
|
7505
7601
|
rmSync as rmSync4,
|
|
7506
|
-
writeFileSync as
|
|
7602
|
+
writeFileSync as writeFileSync15
|
|
7507
7603
|
} from "fs";
|
|
7508
|
-
import
|
|
7509
|
-
import
|
|
7604
|
+
import PATH23 from "path";
|
|
7605
|
+
import chalk64 from "chalk";
|
|
7510
7606
|
var YARN_VERSION = "4.13.0";
|
|
7511
7607
|
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
7512
7608
|
|
|
@@ -7528,9 +7624,9 @@ var YARN_GITIGNORE_ENTRIES = `
|
|
|
7528
7624
|
!.yarn/versions
|
|
7529
7625
|
`;
|
|
7530
7626
|
function readPnpmWorkspacePatterns2(cwd6) {
|
|
7531
|
-
const wsPath =
|
|
7532
|
-
if (!
|
|
7533
|
-
const content =
|
|
7627
|
+
const wsPath = PATH23.join(cwd6, "pnpm-workspace.yaml");
|
|
7628
|
+
if (!existsSync20(wsPath)) return [];
|
|
7629
|
+
const content = readFileSync28(wsPath, "utf8");
|
|
7534
7630
|
const patterns = [];
|
|
7535
7631
|
const lines = content.split("\n");
|
|
7536
7632
|
let inPackages = false;
|
|
@@ -7549,83 +7645,83 @@ function readPnpmWorkspacePatterns2(cwd6) {
|
|
|
7549
7645
|
return patterns;
|
|
7550
7646
|
}
|
|
7551
7647
|
function updateRootPackageJson2(cwd6, workspacePatterns) {
|
|
7552
|
-
const pkgPath =
|
|
7553
|
-
const pkg = JSON.parse(
|
|
7648
|
+
const pkgPath = PATH23.join(cwd6, "package.json");
|
|
7649
|
+
const pkg = JSON.parse(readFileSync28(pkgPath, "utf8"));
|
|
7554
7650
|
pkg.workspaces = workspacePatterns;
|
|
7555
7651
|
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
7556
7652
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
7557
|
-
|
|
7558
|
-
console.log(
|
|
7653
|
+
writeFileSync15(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
7654
|
+
console.log(chalk64.green(" Updated root package.json"));
|
|
7559
7655
|
}
|
|
7560
7656
|
function updateGitignore2(cwd6) {
|
|
7561
|
-
const gitignorePath =
|
|
7562
|
-
let content =
|
|
7657
|
+
const gitignorePath = PATH23.join(cwd6, ".gitignore");
|
|
7658
|
+
let content = existsSync20(gitignorePath) ? readFileSync28(gitignorePath, "utf8") : "";
|
|
7563
7659
|
if (!content.includes(".yarn/*")) {
|
|
7564
7660
|
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
7565
7661
|
}
|
|
7566
|
-
|
|
7567
|
-
console.log(
|
|
7662
|
+
writeFileSync15(gitignorePath, content, "utf8");
|
|
7663
|
+
console.log(chalk64.green(" Updated .gitignore"));
|
|
7568
7664
|
}
|
|
7569
7665
|
function deletePnpmArtifacts(cwd6) {
|
|
7570
|
-
const lockfile =
|
|
7571
|
-
const workspaceYaml =
|
|
7572
|
-
const npmrc =
|
|
7573
|
-
if (
|
|
7666
|
+
const lockfile = PATH23.join(cwd6, "pnpm-lock.yaml");
|
|
7667
|
+
const workspaceYaml = PATH23.join(cwd6, "pnpm-workspace.yaml");
|
|
7668
|
+
const npmrc = PATH23.join(cwd6, ".npmrc");
|
|
7669
|
+
if (existsSync20(lockfile)) {
|
|
7574
7670
|
rmSync4(lockfile);
|
|
7575
|
-
console.log(
|
|
7671
|
+
console.log(chalk64.gray(" Deleted pnpm-lock.yaml"));
|
|
7576
7672
|
}
|
|
7577
|
-
if (
|
|
7673
|
+
if (existsSync20(workspaceYaml)) {
|
|
7578
7674
|
rmSync4(workspaceYaml);
|
|
7579
|
-
console.log(
|
|
7675
|
+
console.log(chalk64.gray(" Deleted pnpm-workspace.yaml"));
|
|
7580
7676
|
}
|
|
7581
|
-
if (
|
|
7582
|
-
const content =
|
|
7677
|
+
if (existsSync20(npmrc)) {
|
|
7678
|
+
const content = readFileSync28(npmrc, "utf8");
|
|
7583
7679
|
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
7584
7680
|
rmSync4(npmrc);
|
|
7585
|
-
console.log(
|
|
7681
|
+
console.log(chalk64.gray(" Deleted .npmrc"));
|
|
7586
7682
|
}
|
|
7587
7683
|
}
|
|
7588
7684
|
}
|
|
7589
7685
|
function createYarnrc(cwd6) {
|
|
7590
|
-
const yarnrcPath =
|
|
7591
|
-
if (
|
|
7592
|
-
|
|
7593
|
-
console.log(
|
|
7686
|
+
const yarnrcPath = PATH23.join(cwd6, ".yarnrc.yml");
|
|
7687
|
+
if (existsSync20(yarnrcPath)) return;
|
|
7688
|
+
writeFileSync15(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
7689
|
+
console.log(chalk64.green(" Created .yarnrc.yml"));
|
|
7594
7690
|
}
|
|
7595
7691
|
function readWorkspacePatternsFromPackageJson(cwd6) {
|
|
7596
|
-
const pkgPath =
|
|
7597
|
-
if (!
|
|
7598
|
-
const pkg = JSON.parse(
|
|
7692
|
+
const pkgPath = PATH23.join(cwd6, "package.json");
|
|
7693
|
+
if (!existsSync20(pkgPath)) return [];
|
|
7694
|
+
const pkg = JSON.parse(readFileSync28(pkgPath, "utf8"));
|
|
7599
7695
|
return pkg.workspaces ?? [];
|
|
7600
7696
|
}
|
|
7601
7697
|
function convertToYarn(cwd6, workspacePackageJsonPaths) {
|
|
7602
|
-
console.log(
|
|
7698
|
+
console.log(chalk64.blue("\nConverting to yarn...\n"));
|
|
7603
7699
|
const workspacePatterns = readPnpmWorkspacePatterns2(cwd6);
|
|
7604
7700
|
if (workspacePatterns.length === 0) {
|
|
7605
7701
|
const fromPkg = readWorkspacePatternsFromPackageJson(cwd6);
|
|
7606
7702
|
if (fromPkg.length > 0) {
|
|
7607
7703
|
workspacePatterns.push(...fromPkg);
|
|
7608
7704
|
} else {
|
|
7609
|
-
console.warn(
|
|
7705
|
+
console.warn(chalk64.yellow(" No workspace patterns found"));
|
|
7610
7706
|
}
|
|
7611
7707
|
}
|
|
7612
7708
|
updateRootPackageJson2(cwd6, workspacePatterns);
|
|
7613
7709
|
for (const pkgPath of workspacePackageJsonPaths) {
|
|
7614
|
-
const fullPath =
|
|
7615
|
-
if (!
|
|
7616
|
-
const pkg = JSON.parse(
|
|
7710
|
+
const fullPath = PATH23.resolve(cwd6, pkgPath, "package.json");
|
|
7711
|
+
if (!existsSync20(fullPath)) continue;
|
|
7712
|
+
const pkg = JSON.parse(readFileSync28(fullPath, "utf8"));
|
|
7617
7713
|
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
7618
7714
|
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
7619
|
-
|
|
7715
|
+
writeFileSync15(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
7620
7716
|
}
|
|
7621
7717
|
}
|
|
7622
|
-
console.log(
|
|
7718
|
+
console.log(chalk64.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
7623
7719
|
updateGitignore2(cwd6);
|
|
7624
7720
|
createYarnrc(cwd6);
|
|
7625
7721
|
swapTsScriptsDependency(cwd6, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
7626
7722
|
rewriteSourceImports(cwd6, "pnpm-to-yarn");
|
|
7627
7723
|
deletePnpmArtifacts(cwd6);
|
|
7628
|
-
console.log(
|
|
7724
|
+
console.log(chalk64.blue("\nRunning yarn install..."));
|
|
7629
7725
|
const install = spawnSync11("yarn", ["install"], {
|
|
7630
7726
|
cwd: cwd6,
|
|
7631
7727
|
encoding: "utf8",
|
|
@@ -7633,31 +7729,31 @@ function convertToYarn(cwd6, workspacePackageJsonPaths) {
|
|
|
7633
7729
|
stdio: "inherit"
|
|
7634
7730
|
});
|
|
7635
7731
|
if (install.status !== 0) {
|
|
7636
|
-
console.error(
|
|
7732
|
+
console.error(chalk64.red("yarn install failed"));
|
|
7637
7733
|
return 1;
|
|
7638
7734
|
}
|
|
7639
|
-
console.log(
|
|
7735
|
+
console.log(chalk64.blue("\nConversion complete.\n"));
|
|
7640
7736
|
return 0;
|
|
7641
7737
|
}
|
|
7642
7738
|
|
|
7643
7739
|
// src/actions/packman/convert.ts
|
|
7644
7740
|
function detectCurrentPM(cwd6) {
|
|
7645
|
-
if (
|
|
7741
|
+
if (existsSync21(PATH24.join(cwd6, "pnpm-lock.yaml")) || existsSync21(PATH24.join(cwd6, "pnpm-workspace.yaml"))) {
|
|
7646
7742
|
return "pnpm";
|
|
7647
7743
|
}
|
|
7648
|
-
if (
|
|
7744
|
+
if (existsSync21(PATH24.join(cwd6, "yarn.lock")) || existsSync21(PATH24.join(cwd6, ".yarnrc.yml"))) {
|
|
7649
7745
|
return "yarn";
|
|
7650
7746
|
}
|
|
7651
7747
|
return "unknown";
|
|
7652
7748
|
}
|
|
7653
7749
|
function findWorkspacePackagePaths(cwd6) {
|
|
7654
|
-
const pkgPath =
|
|
7655
|
-
const pkg = JSON.parse(
|
|
7750
|
+
const pkgPath = PATH24.join(cwd6, "package.json");
|
|
7751
|
+
const pkg = JSON.parse(readFileSync29(pkgPath, "utf8"));
|
|
7656
7752
|
const patterns = pkg.workspaces ?? [];
|
|
7657
7753
|
if (patterns.length === 0) {
|
|
7658
|
-
const wsPath =
|
|
7659
|
-
if (
|
|
7660
|
-
const content =
|
|
7754
|
+
const wsPath = PATH24.join(cwd6, "pnpm-workspace.yaml");
|
|
7755
|
+
if (existsSync21(wsPath)) {
|
|
7756
|
+
const content = readFileSync29(wsPath, "utf8");
|
|
7661
7757
|
const lines = content.split("\n");
|
|
7662
7758
|
let inPackages = false;
|
|
7663
7759
|
for (const line of lines) {
|
|
@@ -7687,15 +7783,15 @@ function resolveWorkspaceGlob(cwd6, pattern) {
|
|
|
7687
7783
|
}
|
|
7688
7784
|
function walkGlob(basePath, parts, currentPath) {
|
|
7689
7785
|
if (parts.length === 0) {
|
|
7690
|
-
const fullPath =
|
|
7691
|
-
if (
|
|
7786
|
+
const fullPath = PATH24.join(basePath, currentPath);
|
|
7787
|
+
if (existsSync21(PATH24.join(fullPath, "package.json"))) {
|
|
7692
7788
|
return [currentPath];
|
|
7693
7789
|
}
|
|
7694
7790
|
return [];
|
|
7695
7791
|
}
|
|
7696
7792
|
const [part, ...rest] = parts;
|
|
7697
|
-
const dirPath =
|
|
7698
|
-
if (!
|
|
7793
|
+
const dirPath = PATH24.join(basePath, currentPath);
|
|
7794
|
+
if (!existsSync21(dirPath) || !statSync4(dirPath).isDirectory()) {
|
|
7699
7795
|
return [];
|
|
7700
7796
|
}
|
|
7701
7797
|
if (part === "*" || part === "**") {
|
|
@@ -7723,38 +7819,38 @@ function walkGlob(basePath, parts, currentPath) {
|
|
|
7723
7819
|
function convert({ target, verbose }) {
|
|
7724
7820
|
const validTargets = ["pnpm", "yarn"];
|
|
7725
7821
|
if (!validTargets.includes(target)) {
|
|
7726
|
-
console.error(
|
|
7822
|
+
console.error(chalk65.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
7727
7823
|
return 1;
|
|
7728
7824
|
}
|
|
7729
7825
|
const cwd6 = process.cwd();
|
|
7730
7826
|
const currentPM = detectCurrentPM(cwd6);
|
|
7731
7827
|
if (verbose) {
|
|
7732
|
-
console.log(
|
|
7733
|
-
console.log(
|
|
7828
|
+
console.log(chalk65.gray(`Current package manager: ${currentPM}`));
|
|
7829
|
+
console.log(chalk65.gray(`Target package manager: ${target}`));
|
|
7734
7830
|
}
|
|
7735
7831
|
if (currentPM === target) {
|
|
7736
|
-
console.log(
|
|
7832
|
+
console.log(chalk65.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
7737
7833
|
}
|
|
7738
7834
|
if (currentPM === "unknown") {
|
|
7739
|
-
console.error(
|
|
7835
|
+
console.error(chalk65.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
7740
7836
|
return 1;
|
|
7741
7837
|
}
|
|
7742
7838
|
const workspacePaths = findWorkspacePackagePaths(cwd6);
|
|
7743
7839
|
if (verbose) {
|
|
7744
|
-
console.log(
|
|
7840
|
+
console.log(chalk65.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
7745
7841
|
}
|
|
7746
7842
|
const result = target === "pnpm" ? convertToPnpm(cwd6, workspacePaths) : convertToYarn(cwd6, workspacePaths);
|
|
7747
7843
|
if (result !== 0) return result;
|
|
7748
|
-
console.log(
|
|
7844
|
+
console.log(chalk65.green("\nRunning repo lint --fix..."));
|
|
7749
7845
|
packageLintMonorepo(true);
|
|
7750
7846
|
return result;
|
|
7751
7847
|
}
|
|
7752
7848
|
|
|
7753
7849
|
// src/actions/packman/clean.ts
|
|
7754
7850
|
function removeNodeModules(dir, verbose) {
|
|
7755
|
-
const nmPath =
|
|
7756
|
-
if (
|
|
7757
|
-
if (verbose) console.log(
|
|
7851
|
+
const nmPath = PATH25.join(dir, "node_modules");
|
|
7852
|
+
if (existsSync22(nmPath)) {
|
|
7853
|
+
if (verbose) console.log(chalk66.gray(`Removing ${nmPath}`));
|
|
7758
7854
|
rmSync5(nmPath, { force: true, recursive: true });
|
|
7759
7855
|
return true;
|
|
7760
7856
|
}
|
|
@@ -7764,73 +7860,73 @@ function packmanClean({ verbose }) {
|
|
|
7764
7860
|
const cwd6 = process.cwd();
|
|
7765
7861
|
const pm = detectCurrentPM(cwd6);
|
|
7766
7862
|
if (pm === "unknown") {
|
|
7767
|
-
console.error(
|
|
7863
|
+
console.error(chalk66.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
7768
7864
|
return 1;
|
|
7769
7865
|
}
|
|
7770
|
-
console.log(
|
|
7866
|
+
console.log(chalk66.blue(`Detected package manager: ${pm}`));
|
|
7771
7867
|
let removedCount = 0;
|
|
7772
7868
|
if (removeNodeModules(cwd6, verbose)) removedCount++;
|
|
7773
7869
|
const workspacePaths = findWorkspacePackagePaths(cwd6);
|
|
7774
7870
|
for (const wsPath of workspacePaths) {
|
|
7775
|
-
const fullPath =
|
|
7871
|
+
const fullPath = PATH25.join(cwd6, wsPath);
|
|
7776
7872
|
if (removeNodeModules(fullPath, verbose)) removedCount++;
|
|
7777
7873
|
}
|
|
7778
|
-
console.log(
|
|
7874
|
+
console.log(chalk66.green(`Removed ${removedCount} node_modules folder${removedCount === 1 ? "" : "s"}`));
|
|
7779
7875
|
if (pm === "yarn") {
|
|
7780
|
-
const lockPath =
|
|
7781
|
-
if (
|
|
7782
|
-
|
|
7783
|
-
console.log(
|
|
7876
|
+
const lockPath = PATH25.join(cwd6, "yarn.lock");
|
|
7877
|
+
if (existsSync22(lockPath)) {
|
|
7878
|
+
writeFileSync16(lockPath, "");
|
|
7879
|
+
console.log(chalk66.green("Truncated yarn.lock"));
|
|
7784
7880
|
}
|
|
7785
7881
|
} else if (pm === "pnpm") {
|
|
7786
|
-
const lockPath =
|
|
7787
|
-
if (
|
|
7882
|
+
const lockPath = PATH25.join(cwd6, "pnpm-lock.yaml");
|
|
7883
|
+
if (existsSync22(lockPath)) {
|
|
7788
7884
|
rmSync5(lockPath);
|
|
7789
|
-
console.log(
|
|
7885
|
+
console.log(chalk66.green("Deleted pnpm-lock.yaml"));
|
|
7790
7886
|
}
|
|
7791
7887
|
}
|
|
7792
|
-
console.log(
|
|
7888
|
+
console.log(chalk66.green("Ready for a clean install"));
|
|
7793
7889
|
return 0;
|
|
7794
7890
|
}
|
|
7795
7891
|
|
|
7796
7892
|
// src/actions/packman/lint.ts
|
|
7797
7893
|
import {
|
|
7798
|
-
existsSync as
|
|
7799
|
-
readFileSync as
|
|
7800
|
-
writeFileSync as
|
|
7894
|
+
existsSync as existsSync23,
|
|
7895
|
+
readFileSync as readFileSync30,
|
|
7896
|
+
writeFileSync as writeFileSync17
|
|
7801
7897
|
} from "fs";
|
|
7802
|
-
import
|
|
7803
|
-
import
|
|
7898
|
+
import PATH26 from "path";
|
|
7899
|
+
import chalk67 from "chalk";
|
|
7804
7900
|
function checkEnableScripts(cwd6, verbose, silent) {
|
|
7805
|
-
const yarnrcPath =
|
|
7806
|
-
if (!
|
|
7807
|
-
if (verbose) console.log(
|
|
7901
|
+
const yarnrcPath = PATH26.join(cwd6, ".yarnrc.yml");
|
|
7902
|
+
if (!existsSync23(yarnrcPath)) {
|
|
7903
|
+
if (verbose) console.log(chalk67.gray(" No .yarnrc.yml found, skipping enableScripts check"));
|
|
7808
7904
|
return true;
|
|
7809
7905
|
}
|
|
7810
|
-
const content =
|
|
7906
|
+
const content = readFileSync30(yarnrcPath, "utf8");
|
|
7811
7907
|
const lines = content.split("\n");
|
|
7812
7908
|
for (const line of lines) {
|
|
7813
7909
|
const trimmed = line.trim();
|
|
7814
7910
|
if (/^enableScripts\s*:/.test(trimmed)) {
|
|
7815
7911
|
const value = trimmed.replace(/^enableScripts\s*:\s*/, "").trim();
|
|
7816
7912
|
if (value === "false") {
|
|
7817
|
-
if (verbose) console.log(
|
|
7913
|
+
if (verbose) console.log(chalk67.green(" enableScripts is correctly set to false"));
|
|
7818
7914
|
return true;
|
|
7819
7915
|
}
|
|
7820
|
-
if (!silent) console.log(
|
|
7916
|
+
if (!silent) console.log(chalk67.red(" enableScripts is set to", value, "(expected false)"));
|
|
7821
7917
|
return false;
|
|
7822
7918
|
}
|
|
7823
7919
|
}
|
|
7824
|
-
if (!silent) console.log(
|
|
7920
|
+
if (!silent) console.log(chalk67.red(" enableScripts is not set in .yarnrc.yml (expected false)"));
|
|
7825
7921
|
return false;
|
|
7826
7922
|
}
|
|
7827
7923
|
function fixEnableScripts(cwd6, verbose) {
|
|
7828
|
-
const yarnrcPath =
|
|
7829
|
-
if (!
|
|
7830
|
-
if (verbose) console.log(
|
|
7924
|
+
const yarnrcPath = PATH26.join(cwd6, ".yarnrc.yml");
|
|
7925
|
+
if (!existsSync23(yarnrcPath)) {
|
|
7926
|
+
if (verbose) console.log(chalk67.gray(" No .yarnrc.yml found, skipping enableScripts fix"));
|
|
7831
7927
|
return true;
|
|
7832
7928
|
}
|
|
7833
|
-
const content =
|
|
7929
|
+
const content = readFileSync30(yarnrcPath, "utf8");
|
|
7834
7930
|
const lines = content.split("\n");
|
|
7835
7931
|
let found = false;
|
|
7836
7932
|
const newLines = lines.map((line) => {
|
|
@@ -7859,8 +7955,8 @@ function fixEnableScripts(cwd6, verbose) {
|
|
|
7859
7955
|
}
|
|
7860
7956
|
}
|
|
7861
7957
|
}
|
|
7862
|
-
|
|
7863
|
-
console.log(
|
|
7958
|
+
writeFileSync17(yarnrcPath, newLines.join("\n"), "utf8");
|
|
7959
|
+
console.log(chalk67.green(" Fixed: enableScripts set to false"));
|
|
7864
7960
|
return true;
|
|
7865
7961
|
}
|
|
7866
7962
|
var checks = [
|
|
@@ -7874,7 +7970,7 @@ function packmanLint({ fix: fix2, verbose } = {}) {
|
|
|
7874
7970
|
const cwd6 = process.cwd();
|
|
7875
7971
|
let failures = 0;
|
|
7876
7972
|
for (const check of checks) {
|
|
7877
|
-
if (verbose) console.log(
|
|
7973
|
+
if (verbose) console.log(chalk67.gray(`Checking: ${check.name}`));
|
|
7878
7974
|
const passed = check.check(cwd6, verbose, fix2);
|
|
7879
7975
|
if (!passed) {
|
|
7880
7976
|
if (fix2) {
|
|
@@ -7888,24 +7984,24 @@ function packmanLint({ fix: fix2, verbose } = {}) {
|
|
|
7888
7984
|
}
|
|
7889
7985
|
}
|
|
7890
7986
|
if (failures > 0) {
|
|
7891
|
-
console.log(
|
|
7987
|
+
console.log(chalk67.red(`
|
|
7892
7988
|
packman lint: ${failures} check(s) failed`));
|
|
7893
7989
|
if (!fix2) {
|
|
7894
|
-
console.log(
|
|
7990
|
+
console.log(chalk67.yellow("Run with --fix to auto-fix issues"));
|
|
7895
7991
|
}
|
|
7896
7992
|
} else {
|
|
7897
|
-
console.log(
|
|
7993
|
+
console.log(chalk67.green("\npackman lint: all checks passed"));
|
|
7898
7994
|
}
|
|
7899
7995
|
return failures > 0 ? 1 : 0;
|
|
7900
7996
|
}
|
|
7901
7997
|
|
|
7902
7998
|
// src/actions/publint.ts
|
|
7903
|
-
import
|
|
7999
|
+
import chalk68 from "chalk";
|
|
7904
8000
|
function resolveExclude(publintConfig, cliExclude, cliInclude) {
|
|
7905
8001
|
const hasExclude = (publintConfig.exclude?.length ?? 0) > 0 || (cliExclude?.length ?? 0) > 0;
|
|
7906
8002
|
const hasInclude = (publintConfig.include?.length ?? 0) > 0 || (cliInclude?.length ?? 0) > 0;
|
|
7907
8003
|
if (hasExclude && hasInclude) {
|
|
7908
|
-
console.error(
|
|
8004
|
+
console.error(chalk68.red("Publint: --include and --exclude cannot be used together"));
|
|
7909
8005
|
return void 0;
|
|
7910
8006
|
}
|
|
7911
8007
|
if (hasInclude) {
|
|
@@ -7956,7 +8052,7 @@ var publint = async ({
|
|
|
7956
8052
|
});
|
|
7957
8053
|
};
|
|
7958
8054
|
function logPublintSummary(packages, errors, ms) {
|
|
7959
|
-
const color = errors > 0 ?
|
|
8055
|
+
const color = errors > 0 ? chalk68.red : chalk68.blue;
|
|
7960
8056
|
console.log(color(`Checked ${packages} package(s) in ${ms.toFixed(0)}ms with ${errors} issue(s) found.`));
|
|
7961
8057
|
}
|
|
7962
8058
|
var publintSingle = async ({
|
|
@@ -7971,7 +8067,7 @@ var publintSingle = async ({
|
|
|
7971
8067
|
const pm = getPackageManager();
|
|
7972
8068
|
const workspace = pm.findWorkspace(pkg);
|
|
7973
8069
|
if (!workspace) {
|
|
7974
|
-
console.error(
|
|
8070
|
+
console.error(chalk68.red(`Publint: workspace "${pkg}" not found`));
|
|
7975
8071
|
return 1;
|
|
7976
8072
|
}
|
|
7977
8073
|
const wsPublintConfig = normalizePublintConfig(
|
|
@@ -8025,7 +8121,7 @@ var publintAll = async ({
|
|
|
8025
8121
|
});
|
|
8026
8122
|
results[i] = { errors, output };
|
|
8027
8123
|
} catch (ex) {
|
|
8028
|
-
output.push(
|
|
8124
|
+
output.push(chalk68.red(`Publint failed for ${ws.name}: ${ex.message}
|
|
8029
8125
|
`));
|
|
8030
8126
|
results[i] = { errors: 1, output };
|
|
8031
8127
|
}
|
|
@@ -8049,7 +8145,7 @@ var publintAll = async ({
|
|
|
8049
8145
|
runInstall();
|
|
8050
8146
|
} else {
|
|
8051
8147
|
for (const msg of peerResult.fixable) {
|
|
8052
|
-
console.log(
|
|
8148
|
+
console.log(chalk68.red(` \u2717 ${msg} (fixable)`));
|
|
8053
8149
|
}
|
|
8054
8150
|
totalErrors += peerResult.fixable.length;
|
|
8055
8151
|
}
|
|
@@ -8103,25 +8199,25 @@ async function readmeInit({ templatePath }) {
|
|
|
8103
8199
|
}
|
|
8104
8200
|
|
|
8105
8201
|
// src/actions/readme-lint.ts
|
|
8106
|
-
import { existsSync as
|
|
8107
|
-
import
|
|
8108
|
-
import
|
|
8202
|
+
import { existsSync as existsSync24, readFileSync as readFileSync31 } from "fs";
|
|
8203
|
+
import PATH27 from "path";
|
|
8204
|
+
import chalk69 from "chalk";
|
|
8109
8205
|
function lintTemplate(cwd6) {
|
|
8110
8206
|
const result = { errors: [], warnings: [] };
|
|
8111
8207
|
const templatePath = resolveTemplatePath();
|
|
8112
|
-
if (!
|
|
8208
|
+
if (!existsSync24(templatePath)) {
|
|
8113
8209
|
result.errors.push('Missing .xy/README.template.md (run "xy readme init" to create)');
|
|
8114
8210
|
return result;
|
|
8115
8211
|
}
|
|
8116
|
-
const template =
|
|
8212
|
+
const template = readFileSync31(templatePath, "utf8");
|
|
8117
8213
|
if (!template.includes("{{body}}")) {
|
|
8118
8214
|
result.warnings.push(".xy/README.template.md does not contain a {{body}} placeholder");
|
|
8119
8215
|
}
|
|
8120
8216
|
if (!template.includes("{{description}}")) {
|
|
8121
8217
|
result.warnings.push(".xy/README.template.md does not contain a {{description}} placeholder");
|
|
8122
8218
|
}
|
|
8123
|
-
const bodyPath =
|
|
8124
|
-
if (!
|
|
8219
|
+
const bodyPath = PATH27.join(cwd6, ".xy", "README.body.md");
|
|
8220
|
+
if (!existsSync24(bodyPath)) {
|
|
8125
8221
|
result.errors.push('Missing .xy/README.body.md (run "xy readme init" to create)');
|
|
8126
8222
|
}
|
|
8127
8223
|
return result;
|
|
@@ -8129,8 +8225,8 @@ function lintTemplate(cwd6) {
|
|
|
8129
8225
|
function lintLogoConfig(cwd6, config2) {
|
|
8130
8226
|
const result = { errors: [], warnings: [] };
|
|
8131
8227
|
const templatePath = resolveTemplatePath();
|
|
8132
|
-
if (
|
|
8133
|
-
const template =
|
|
8228
|
+
if (existsSync24(templatePath)) {
|
|
8229
|
+
const template = readFileSync31(templatePath, "utf8");
|
|
8134
8230
|
const logoRef = /\[logo]: (.+)/.exec(template);
|
|
8135
8231
|
if (logoRef?.[1].includes("example.com")) {
|
|
8136
8232
|
result.warnings.push(".xy/README.template.md still has the example.com logo placeholder \u2014 update it or set readme.logoUrl in xy.config.ts");
|
|
@@ -8149,15 +8245,15 @@ function lintPackages(cwd6) {
|
|
|
8149
8245
|
const workspaces = pm.listWorkspaces();
|
|
8150
8246
|
for (const { location, name } of workspaces) {
|
|
8151
8247
|
if (location === ".") continue;
|
|
8152
|
-
const pkgPath =
|
|
8248
|
+
const pkgPath = PATH27.join(cwd6, location, "package.json");
|
|
8153
8249
|
try {
|
|
8154
|
-
const pkg = JSON.parse(
|
|
8250
|
+
const pkg = JSON.parse(readFileSync31(pkgPath, "utf8"));
|
|
8155
8251
|
if (pkg.private) continue;
|
|
8156
8252
|
if (!pkg.description) {
|
|
8157
8253
|
result.warnings.push(`${name} is missing a "description" in package.json`);
|
|
8158
8254
|
}
|
|
8159
|
-
const readmePath =
|
|
8160
|
-
if (!
|
|
8255
|
+
const readmePath = PATH27.join(cwd6, location, "README.md");
|
|
8256
|
+
if (!existsSync24(readmePath)) {
|
|
8161
8257
|
result.errors.push(`${name} is missing README.md`);
|
|
8162
8258
|
}
|
|
8163
8259
|
} catch {
|
|
@@ -8167,7 +8263,7 @@ function lintPackages(cwd6) {
|
|
|
8167
8263
|
}
|
|
8168
8264
|
function readmeLint({ config: config2, verbose }) {
|
|
8169
8265
|
const cwd6 = INIT_CWD();
|
|
8170
|
-
console.log(
|
|
8266
|
+
console.log(chalk69.green("Readme Lint"));
|
|
8171
8267
|
const checks2 = [
|
|
8172
8268
|
lintTemplate(cwd6),
|
|
8173
8269
|
lintLogoConfig(cwd6, config2),
|
|
@@ -8177,19 +8273,19 @@ function readmeLint({ config: config2, verbose }) {
|
|
|
8177
8273
|
let warningCount = 0;
|
|
8178
8274
|
for (const { errors, warnings } of checks2) {
|
|
8179
8275
|
for (const error of errors) {
|
|
8180
|
-
console.log(
|
|
8276
|
+
console.log(chalk69.red(` \u2717 ${error}`));
|
|
8181
8277
|
errorCount++;
|
|
8182
8278
|
}
|
|
8183
8279
|
for (const warning of warnings) {
|
|
8184
|
-
console.log(
|
|
8280
|
+
console.log(chalk69.yellow(` \u26A0 ${warning}`));
|
|
8185
8281
|
warningCount++;
|
|
8186
8282
|
}
|
|
8187
8283
|
}
|
|
8188
8284
|
if (errorCount === 0 && warningCount === 0) {
|
|
8189
|
-
console.log(
|
|
8285
|
+
console.log(chalk69.green(" All checks passed"));
|
|
8190
8286
|
} else {
|
|
8191
8287
|
if (verbose) {
|
|
8192
|
-
console.log(
|
|
8288
|
+
console.log(chalk69.gray(` ${errorCount} error(s), ${warningCount} warning(s)`));
|
|
8193
8289
|
}
|
|
8194
8290
|
}
|
|
8195
8291
|
return errorCount > 0 ? 1 : 0;
|
|
@@ -8298,18 +8394,18 @@ var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
|
8298
8394
|
// src/actions/repo-init.ts
|
|
8299
8395
|
import { spawnSync as spawnSync12 } from "child_process";
|
|
8300
8396
|
import {
|
|
8301
|
-
existsSync as
|
|
8397
|
+
existsSync as existsSync25,
|
|
8302
8398
|
mkdirSync as mkdirSync6,
|
|
8303
8399
|
readdirSync as readdirSync10,
|
|
8304
|
-
readFileSync as
|
|
8305
|
-
writeFileSync as
|
|
8400
|
+
readFileSync as readFileSync32,
|
|
8401
|
+
writeFileSync as writeFileSync18
|
|
8306
8402
|
} from "fs";
|
|
8307
8403
|
import { createRequire as createRequire5 } from "module";
|
|
8308
|
-
import
|
|
8309
|
-
import { createInterface as
|
|
8310
|
-
import
|
|
8404
|
+
import PATH28 from "path";
|
|
8405
|
+
import { createInterface as createInterface5 } from "readline";
|
|
8406
|
+
import chalk70 from "chalk";
|
|
8311
8407
|
function askQuestion(question) {
|
|
8312
|
-
const rl =
|
|
8408
|
+
const rl = createInterface5({ input: process.stdin, output: process.stdout });
|
|
8313
8409
|
return new Promise((resolve) => {
|
|
8314
8410
|
rl.question(question, (answer) => {
|
|
8315
8411
|
rl.close();
|
|
@@ -8320,7 +8416,7 @@ function askQuestion(question) {
|
|
|
8320
8416
|
function getConfigVersion() {
|
|
8321
8417
|
const require6 = createRequire5(import.meta.url);
|
|
8322
8418
|
const pkgPath = require6.resolve("@xylabs/ts-scripts-common/package.json");
|
|
8323
|
-
const pkg = JSON.parse(
|
|
8419
|
+
const pkg = JSON.parse(readFileSync32(pkgPath, "utf8"));
|
|
8324
8420
|
return pkg.version.replace(/\.\d+$/, "");
|
|
8325
8421
|
}
|
|
8326
8422
|
function mapOutputPath(relativePath, variables) {
|
|
@@ -8370,10 +8466,10 @@ function buildVariables(params) {
|
|
|
8370
8466
|
};
|
|
8371
8467
|
}
|
|
8372
8468
|
function ensureEmptyDir(projectDir, name) {
|
|
8373
|
-
if (
|
|
8469
|
+
if (existsSync25(projectDir)) {
|
|
8374
8470
|
const entries = readdirSync10(projectDir);
|
|
8375
8471
|
if (entries.length > 0) {
|
|
8376
|
-
console.error(
|
|
8472
|
+
console.error(chalk70.red(`Directory '${name}' already exists and is not empty`));
|
|
8377
8473
|
return false;
|
|
8378
8474
|
}
|
|
8379
8475
|
}
|
|
@@ -8389,37 +8485,37 @@ function scaffoldFiles(templateName, layer, outputDir, pm, variables, verbose) {
|
|
|
8389
8485
|
let outputPath = mapOutputPath(file.relativePath, variables);
|
|
8390
8486
|
if (!outputPath) continue;
|
|
8391
8487
|
if (layer === "root") outputPath = mapBuildWorkflowName(outputPath);
|
|
8392
|
-
const fullPath =
|
|
8393
|
-
mkdirSync6(
|
|
8394
|
-
|
|
8488
|
+
const fullPath = PATH28.resolve(outputDir, outputPath);
|
|
8489
|
+
mkdirSync6(PATH28.dirname(fullPath), { recursive: true });
|
|
8490
|
+
writeFileSync18(fullPath, content);
|
|
8395
8491
|
count++;
|
|
8396
|
-
if (verbose) console.log(
|
|
8492
|
+
if (verbose) console.log(chalk70.gray(` ${layer === "root" ? outputPath : `packages/${variables.packageName}/${outputPath}`}`));
|
|
8397
8493
|
}
|
|
8398
8494
|
return count;
|
|
8399
8495
|
}
|
|
8400
8496
|
function initGitRepo(projectDir, verbose) {
|
|
8401
|
-
if (verbose) console.log(
|
|
8497
|
+
if (verbose) console.log(chalk70.gray("Initializing git repository..."));
|
|
8402
8498
|
const result = spawnSync12("git", ["init", "-b", "main"], {
|
|
8403
8499
|
cwd: projectDir,
|
|
8404
8500
|
stdio: verbose ? "inherit" : "pipe"
|
|
8405
8501
|
});
|
|
8406
8502
|
if (result.status === 0) {
|
|
8407
|
-
console.log(
|
|
8503
|
+
console.log(chalk70.green("Initialized git repository"));
|
|
8408
8504
|
} else {
|
|
8409
|
-
console.warn(
|
|
8505
|
+
console.warn(chalk70.yellow("git init failed, skipping"));
|
|
8410
8506
|
}
|
|
8411
8507
|
}
|
|
8412
8508
|
function installDependencies(projectDir, pm) {
|
|
8413
|
-
console.log(
|
|
8509
|
+
console.log(chalk70.gray(`Running ${pm} install...`));
|
|
8414
8510
|
const result = spawnSync12(pm, ["install"], {
|
|
8415
8511
|
cwd: projectDir,
|
|
8416
8512
|
stdio: "inherit"
|
|
8417
8513
|
});
|
|
8418
8514
|
if (result.status !== 0) {
|
|
8419
|
-
console.warn(
|
|
8515
|
+
console.warn(chalk70.yellow(`${pm} install failed`));
|
|
8420
8516
|
return false;
|
|
8421
8517
|
}
|
|
8422
|
-
console.log(
|
|
8518
|
+
console.log(chalk70.green("Dependencies installed"));
|
|
8423
8519
|
return true;
|
|
8424
8520
|
}
|
|
8425
8521
|
async function repoInit(params) {
|
|
@@ -8434,13 +8530,13 @@ async function repoInit(params) {
|
|
|
8434
8530
|
} = params;
|
|
8435
8531
|
let name = params.name;
|
|
8436
8532
|
if (!name) {
|
|
8437
|
-
name = await askQuestion(
|
|
8533
|
+
name = await askQuestion(chalk70.cyan("Project name: "));
|
|
8438
8534
|
if (!name) {
|
|
8439
|
-
console.error(
|
|
8535
|
+
console.error(chalk70.red("Project name is required"));
|
|
8440
8536
|
return 1;
|
|
8441
8537
|
}
|
|
8442
8538
|
}
|
|
8443
|
-
const projectName =
|
|
8539
|
+
const projectName = PATH28.basename(name);
|
|
8444
8540
|
const packageName2 = params.packageName ?? projectName;
|
|
8445
8541
|
const githubOrg = params.githubOrg ?? scope.replace(/^@/, "");
|
|
8446
8542
|
const variables = buildVariables({
|
|
@@ -8452,26 +8548,26 @@ async function repoInit(params) {
|
|
|
8452
8548
|
scope
|
|
8453
8549
|
});
|
|
8454
8550
|
if (verbose) {
|
|
8455
|
-
console.log(
|
|
8551
|
+
console.log(chalk70.gray("Template variables:"));
|
|
8456
8552
|
for (const [key, value] of Object.entries(variables)) {
|
|
8457
|
-
console.log(
|
|
8553
|
+
console.log(chalk70.gray(` ${key}: ${value}`));
|
|
8458
8554
|
}
|
|
8459
8555
|
}
|
|
8460
|
-
const projectDir =
|
|
8556
|
+
const projectDir = PATH28.resolve(process.cwd(), name);
|
|
8461
8557
|
if (!ensureEmptyDir(projectDir, name)) return 1;
|
|
8462
8558
|
const rootCount = scaffoldFiles(template, "root", projectDir, pm, variables, verbose);
|
|
8463
|
-
const pkgDir =
|
|
8559
|
+
const pkgDir = PATH28.resolve(projectDir, "packages", packageName2);
|
|
8464
8560
|
const pkgCount = scaffoldFiles(template, "package", pkgDir, pm, variables, verbose);
|
|
8465
|
-
console.log(
|
|
8561
|
+
console.log(chalk70.green(`Scaffolded ${rootCount + pkgCount} files into ${name}/`));
|
|
8466
8562
|
if (!skipGit) initGitRepo(projectDir, verbose);
|
|
8467
8563
|
if (!skipInstall && !installDependencies(projectDir, pm)) return 1;
|
|
8468
8564
|
console.log("");
|
|
8469
|
-
console.log(
|
|
8565
|
+
console.log(chalk70.cyan(`Project ${name} created successfully!`));
|
|
8470
8566
|
console.log("");
|
|
8471
|
-
console.log(
|
|
8472
|
-
console.log(
|
|
8473
|
-
if (skipInstall) console.log(
|
|
8474
|
-
console.log(
|
|
8567
|
+
console.log(chalk70.gray("Next steps:"));
|
|
8568
|
+
console.log(chalk70.gray(` cd ${name}`));
|
|
8569
|
+
if (skipInstall) console.log(chalk70.gray(` ${pm} install`));
|
|
8570
|
+
console.log(chalk70.gray(` ${pm} xy build`));
|
|
8475
8571
|
return 0;
|
|
8476
8572
|
}
|
|
8477
8573
|
|
|
@@ -8508,10 +8604,10 @@ var start = () => {
|
|
|
8508
8604
|
};
|
|
8509
8605
|
|
|
8510
8606
|
// src/actions/statics.ts
|
|
8511
|
-
import
|
|
8607
|
+
import chalk71 from "chalk";
|
|
8512
8608
|
var DefaultDependencies = ["axios", "@xylabs/pixel", "react", "graphql", "react-router", "@mui/material", "@mui/system"];
|
|
8513
8609
|
var statics = () => {
|
|
8514
|
-
console.log(
|
|
8610
|
+
console.log(chalk71.green("Check Required Static Dependencies"));
|
|
8515
8611
|
const pkg = parsedPackageJSON();
|
|
8516
8612
|
const xy2 = pkg?.xy;
|
|
8517
8613
|
const deps = xy2?.deps;
|
|
@@ -8690,7 +8786,7 @@ var xyBuildCommands = (args) => {
|
|
|
8690
8786
|
};
|
|
8691
8787
|
|
|
8692
8788
|
// src/xy/common/checkCommand.ts
|
|
8693
|
-
import
|
|
8789
|
+
import chalk72 from "chalk";
|
|
8694
8790
|
var checkCommand = {
|
|
8695
8791
|
command: "check",
|
|
8696
8792
|
describe: "Check - Run gitlint, publint, repo lint, lintlint, and readme lint",
|
|
@@ -8707,25 +8803,25 @@ var checkCommand = {
|
|
|
8707
8803
|
const jobs = argv.jobs;
|
|
8708
8804
|
let errors = 0;
|
|
8709
8805
|
if (verbose) console.log("Check");
|
|
8710
|
-
console.log(
|
|
8806
|
+
console.log(chalk72.blue("\n\u2014 gitlint \u2014"));
|
|
8711
8807
|
errors += fix2 ? gitlintFix() : gitlint();
|
|
8712
|
-
console.log(
|
|
8808
|
+
console.log(chalk72.blue("\n\u2014 publint \u2014"));
|
|
8713
8809
|
errors += await publint({
|
|
8714
8810
|
fix: fix2,
|
|
8715
8811
|
jobs,
|
|
8716
8812
|
verbose
|
|
8717
8813
|
});
|
|
8718
|
-
console.log(
|
|
8814
|
+
console.log(chalk72.blue("\n\u2014 repo lint \u2014"));
|
|
8719
8815
|
errors += packageLintMonorepo(fix2);
|
|
8720
|
-
console.log(
|
|
8816
|
+
console.log(chalk72.blue("\n\u2014 lintlint \u2014"));
|
|
8721
8817
|
errors += await lintlint({ fix: fix2, verbose });
|
|
8722
|
-
console.log(
|
|
8818
|
+
console.log(chalk72.blue("\n\u2014 readme lint \u2014"));
|
|
8723
8819
|
const config2 = await loadConfig();
|
|
8724
8820
|
errors += readmeLint({ config: config2, verbose });
|
|
8725
8821
|
if (errors > 0) {
|
|
8726
|
-
console.log(
|
|
8822
|
+
console.log(chalk72.red(`${errors} issue(s) found`));
|
|
8727
8823
|
} else {
|
|
8728
|
-
console.log(
|
|
8824
|
+
console.log(chalk72.green("All checks passed"));
|
|
8729
8825
|
}
|
|
8730
8826
|
process.exitCode = errors > 0 ? 1 : 0;
|
|
8731
8827
|
}
|
|
@@ -9391,7 +9487,7 @@ var deplintCommand = {
|
|
|
9391
9487
|
};
|
|
9392
9488
|
|
|
9393
9489
|
// src/xy/lint/fixCommand.ts
|
|
9394
|
-
import
|
|
9490
|
+
import chalk73 from "chalk";
|
|
9395
9491
|
var fixCommand = {
|
|
9396
9492
|
builder: (yargs2) => {
|
|
9397
9493
|
return packagePositionalParam(yargs2).option("cache", {
|
|
@@ -9410,7 +9506,7 @@ var fixCommand = {
|
|
|
9410
9506
|
deprecated: 'Use "xy lint --fix" instead',
|
|
9411
9507
|
describe: "Fix - Run Eslint w/fix",
|
|
9412
9508
|
handler: async (argv) => {
|
|
9413
|
-
console.warn(
|
|
9509
|
+
console.warn(chalk73.yellow('Deprecated: use "xy lint --fix" instead of "xy fix"'));
|
|
9414
9510
|
if (argv.verbose) console.log("Fix");
|
|
9415
9511
|
process.exitCode = await fix({
|
|
9416
9512
|
cache: argv.cache,
|
|
@@ -9423,7 +9519,7 @@ var fixCommand = {
|
|
|
9423
9519
|
};
|
|
9424
9520
|
|
|
9425
9521
|
// src/xy/lint/knipCommand.ts
|
|
9426
|
-
import
|
|
9522
|
+
import chalk74 from "chalk";
|
|
9427
9523
|
var knipCommand = {
|
|
9428
9524
|
command: "knip",
|
|
9429
9525
|
describe: "Knip - Run Knip",
|
|
@@ -9434,12 +9530,12 @@ var knipCommand = {
|
|
|
9434
9530
|
if (argv.verbose) console.log("Knip");
|
|
9435
9531
|
const start2 = Date.now();
|
|
9436
9532
|
process.exitCode = knip();
|
|
9437
|
-
console.log(
|
|
9533
|
+
console.log(chalk74.blue(`Knip finished in ${Date.now() - start2}ms`));
|
|
9438
9534
|
}
|
|
9439
9535
|
};
|
|
9440
9536
|
|
|
9441
9537
|
// src/xy/lint/lint/index.ts
|
|
9442
|
-
import
|
|
9538
|
+
import chalk75 from "chalk";
|
|
9443
9539
|
|
|
9444
9540
|
// src/xy/lint/lint/initCommand.ts
|
|
9445
9541
|
var initCommand4 = {
|
|
@@ -9506,7 +9602,7 @@ var lintCommand4 = {
|
|
|
9506
9602
|
describe: "Lint - Run ESLint",
|
|
9507
9603
|
handler: async (argv) => {
|
|
9508
9604
|
if (argv.init) {
|
|
9509
|
-
console.warn(
|
|
9605
|
+
console.warn(chalk75.yellow('Deprecated: use "xy lint init" instead of "xy lint --init"'));
|
|
9510
9606
|
process.exitCode = await lintInit({ verbose: !!argv.verbose });
|
|
9511
9607
|
}
|
|
9512
9608
|
}
|
|
@@ -9655,11 +9751,11 @@ var xyReactCommands = (args) => {
|
|
|
9655
9751
|
};
|
|
9656
9752
|
|
|
9657
9753
|
// src/xy/xy.ts
|
|
9658
|
-
import
|
|
9754
|
+
import chalk77 from "chalk";
|
|
9659
9755
|
|
|
9660
9756
|
// src/xy/xyParseOptions.ts
|
|
9661
9757
|
import { availableParallelism } from "os";
|
|
9662
|
-
import
|
|
9758
|
+
import chalk76 from "chalk";
|
|
9663
9759
|
import yargs from "yargs";
|
|
9664
9760
|
import { hideBin } from "yargs/helpers";
|
|
9665
9761
|
function formatDuration(ms) {
|
|
@@ -9684,14 +9780,14 @@ var xyParseOptions = () => {
|
|
|
9684
9780
|
timerRegistered = true;
|
|
9685
9781
|
const commandName = argv._[0];
|
|
9686
9782
|
const jobs = argv.jobs;
|
|
9687
|
-
const label = commandName ? ` [${
|
|
9783
|
+
const label = commandName ? ` [${chalk76.white(commandName)}]` : "";
|
|
9688
9784
|
console.log(
|
|
9689
|
-
|
|
9785
|
+
chalk76.blue("\u2B21 XY") + label + chalk76.gray(` [threads: ${jobs}]`)
|
|
9690
9786
|
);
|
|
9691
9787
|
const start2 = Date.now();
|
|
9692
9788
|
process.on("exit", () => {
|
|
9693
|
-
const exitLabel = commandName ? ` [${
|
|
9694
|
-
console.log(
|
|
9789
|
+
const exitLabel = commandName ? ` [${chalk76.white(commandName)}]` : "";
|
|
9790
|
+
console.log(chalk76.blue(`Finished${exitLabel} in ${formatDuration(Date.now() - start2)}`));
|
|
9695
9791
|
});
|
|
9696
9792
|
}
|
|
9697
9793
|
}, true).option("jobs", {
|
|
@@ -9760,8 +9856,8 @@ var xyBase = async (plugins) => {
|
|
|
9760
9856
|
let args = xyBuildCommands(xyCommonCommands(xyLintCommands(options)));
|
|
9761
9857
|
if (plugins) args = plugins(args);
|
|
9762
9858
|
return await args.demandCommand(1).command("*", "", () => {
|
|
9763
|
-
console.error(
|
|
9764
|
-
console.log(
|
|
9859
|
+
console.error(chalk77.yellow(`Command not found [${chalk77.magenta(process.argv[2])}]`));
|
|
9860
|
+
console.log(chalk77.gray("Try 'xy --help' for list of commands"));
|
|
9765
9861
|
}).version().help().argv;
|
|
9766
9862
|
};
|
|
9767
9863
|
var xy = async () => {
|
|
@@ -9838,6 +9934,7 @@ export {
|
|
|
9838
9934
|
deplint,
|
|
9839
9935
|
deplintRules,
|
|
9840
9936
|
deploy,
|
|
9937
|
+
deprecationMigrate,
|
|
9841
9938
|
detectCurrentPM,
|
|
9842
9939
|
detectDuplicateDependencies,
|
|
9843
9940
|
detectPackageManager,
|