@covector/files
Advanced tools
Comparing version 0.6.2 to 0.7.0
# Changelog | ||
## \[0.7.0] | ||
### Enhancements | ||
- [`7498ecc`](https://www.github.com/jbolda/covector/commit/7498ecc332efd10a1d6d4b6cd487d2817c9a853d)([#289](https://www.github.com/jbolda/covector/pull/289)) Implement zod for config file schema parsing and checking. It will throw an error if the `config.json` has entries that do not match the schema. | ||
### Dependencies | ||
- [`cb35f38`](https://www.github.com/jbolda/covector/commit/cb35f38287580597539f3c69d748ee330939cf84)([#291](https://www.github.com/jbolda/covector/pull/291)) Bumps `js-yaml` minor to sync on the same version. | ||
- [`cb35f38`](https://www.github.com/jbolda/covector/commit/cb35f38287580597539f3c69d748ee330939cf84)([#291](https://www.github.com/jbolda/covector/pull/291)) Bumps `semver` minor to latest. | ||
## \[0.6.2] | ||
@@ -4,0 +15,0 @@ |
/// <reference types="node" /> | ||
import { PathLike } from "fs"; | ||
import { Operation } from "effection"; | ||
import type { File, PackageFile, PreFile, ConfigFile, Pkg } from "@covector/types"; | ||
import { type Operation } from "effection"; | ||
import type { File, ConfigFile, PackageFile, PreFile, Pkg } from "@covector/types"; | ||
export declare function loadFile(file: PathLike, cwd: string): Operation<File | void>; | ||
@@ -50,7 +50,3 @@ export declare function saveFile(file: File, cwd: string): Operation<File>; | ||
changeFolder?: string; | ||
}): Operation<ConfigFile>; | ||
export declare const checkFileOrDirectory: ({ cwd, config, }: { | ||
cwd: string; | ||
config: ConfigFile; | ||
}) => ConfigFile["packages"]; | ||
}): Operation<ConfigFile & File>; | ||
export declare const changeFiles: ({ cwd, changeFolder, }: { | ||
@@ -57,0 +53,0 @@ cwd: string; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -38,7 +15,9 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.writeChangelog = exports.readChangelog = exports.changeFilesRemove = exports.loadChangeFiles = exports.changeFiles = exports.checkFileOrDirectory = exports.configFile = exports.testSerializePkgFile = exports.writePreFile = exports.setPackageFileVersion = exports.getPackageFileVersion = exports.readPreFile = exports.writePkgFile = exports.readPkgFile = exports.readAllPkgFiles = exports.saveFile = exports.loadFile = void 0; | ||
const fs_1 = __importStar(require("fs")); | ||
exports.writeChangelog = exports.readChangelog = exports.changeFilesRemove = exports.loadChangeFiles = exports.changeFiles = exports.configFile = exports.testSerializePkgFile = exports.writePreFile = exports.setPackageFileVersion = exports.getPackageFileVersion = exports.readPreFile = exports.writePkgFile = exports.readPkgFile = exports.readAllPkgFiles = exports.saveFile = exports.loadFile = void 0; | ||
const fs_1 = __importDefault(require("fs")); | ||
// this is compatible with node@12+ | ||
const fs = fs_1.default.promises; | ||
const effection_1 = require("effection"); | ||
const schema_1 = require("./schema"); | ||
const zod_validation_error_1 = require("zod-validation-error"); | ||
const globby_1 = __importDefault(require("globby")); | ||
@@ -397,26 +376,12 @@ const path_1 = __importDefault(require("path")); | ||
const inputFile = yield loadFile(path_1.default.join(changeFolder, "config.json"), cwd); | ||
const parsed = JSON.parse(inputFile.content); | ||
return Object.assign(Object.assign({ file: inputFile }, parsed), (0, exports.checkFileOrDirectory)({ cwd, config: parsed })); | ||
try { | ||
const parsed = (0, schema_1.configFileSchema)(cwd).parse(JSON.parse(inputFile.content)); | ||
return Object.assign({ file: inputFile }, parsed); | ||
} | ||
catch (error) { | ||
const validationError = (0, zod_validation_error_1.fromZodError)(error); | ||
throw new effection_1.MainError({ exitCode: 1, message: validationError.message }); | ||
} | ||
} | ||
exports.configFile = configFile; | ||
const checkFileOrDirectory = ({ cwd, config, }) => !config.packages | ||
? {} | ||
: { | ||
packages: Object.keys(config.packages).reduce((packages, pkg) => { | ||
const packagePath = config.packages[pkg].path; | ||
if (!packagePath || !cwd) | ||
return packages; | ||
const checkDir = (0, fs_1.statSync)(path_1.default.join(cwd, packagePath)); | ||
if (checkDir.isFile()) { | ||
const dirName = path_1.default.dirname(packagePath); | ||
const packageFileName = path_1.default.basename(packagePath); | ||
packages[pkg] = Object.assign(Object.assign({}, packages[pkg]), { path: dirName, packageFileName }); | ||
return packages; | ||
} | ||
else { | ||
return packages; | ||
} | ||
}, config === null || config === void 0 ? void 0 : config.packages), | ||
}; | ||
exports.checkFileOrDirectory = checkFileOrDirectory; | ||
const changeFiles = ({ cwd, changeFolder = ".changes", }) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -423,0 +388,0 @@ return yield (0, globby_1.default)([ |
{ | ||
"name": "@covector/files", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"license": "Apache-2.0", | ||
@@ -22,8 +22,10 @@ "homepage": "https://github.com/jbolda/covector#readme", | ||
"globby": "^11.1.0", | ||
"js-yaml": "^4.0.0", | ||
"semver": "^7.3.8" | ||
"js-yaml": "^4.1.0", | ||
"semver": "^7.5.4", | ||
"zod": "^3.21.4", | ||
"zod-validation-error": "^1.3.1" | ||
}, | ||
"devDependencies": { | ||
"@covector/types": "^0.0.0", | ||
"@types/js-yaml": "^4.0.0", | ||
"@covector/types": "0.0.0", | ||
"@types/js-yaml": "^4.0.5", | ||
"@types/node": "^16.18.12", | ||
@@ -30,0 +32,0 @@ "@types/semver": "^7.3.13", |
@@ -5,3 +5,5 @@ import { default as fsDefault, PathLike, statSync } from "fs"; | ||
import { all, Operation } from "effection"; | ||
import { all, MainError, type Operation } from "effection"; | ||
import { configFileSchema } from "./schema"; | ||
import { fromZodError } from "zod-validation-error"; | ||
import globby from "globby"; | ||
@@ -15,6 +17,6 @@ import path from "path"; | ||
File, | ||
ConfigFile, | ||
PkgMinimum, | ||
PackageFile, | ||
PreFile, | ||
ConfigFile, | ||
DepsKeyed, | ||
@@ -193,3 +195,3 @@ DepTypes, | ||
const readPkgs = pkgArray.map(([name, pkg]) => | ||
readPkgFile({ cwd, pkgConfig: pkg, nickname: name }) | ||
readPkgFile({ cwd, pkgConfig: pkg, nickname: name }), | ||
); | ||
@@ -205,3 +207,3 @@ const pkgFilesArray: PackageFile[] = yield all(readPkgs); | ||
}, | ||
{} | ||
{}, | ||
); | ||
@@ -345,3 +347,3 @@ } | ||
`This cannot be published. ` + | ||
`Please pin it to a MAJOR.MINOR.PATCH reference.` | ||
`Please pin it to a MAJOR.MINOR.PATCH reference.`, | ||
); | ||
@@ -399,4 +401,4 @@ } | ||
null, | ||
2 | ||
)}` | ||
2, | ||
)}`, | ||
); | ||
@@ -454,3 +456,3 @@ if (!dep) return pkg; | ||
console.error( | ||
"It appears that a dependency within this repo does not have a version specified." | ||
"It appears that a dependency within this repo does not have a version specified.", | ||
); | ||
@@ -468,42 +470,19 @@ } | ||
changeFolder?: string; | ||
}): Operation<ConfigFile> { | ||
const inputFile = yield loadFile(path.join(changeFolder, "config.json"), cwd); | ||
const parsed = JSON.parse(inputFile.content); | ||
return { | ||
file: inputFile, | ||
...parsed, | ||
...checkFileOrDirectory({ cwd, config: parsed }), | ||
}; | ||
}): Operation<ConfigFile & File> { | ||
const inputFile: File = yield loadFile( | ||
path.join(changeFolder, "config.json"), | ||
cwd, | ||
); | ||
try { | ||
const parsed = configFileSchema(cwd).parse(JSON.parse(inputFile.content)); | ||
return { | ||
file: inputFile, | ||
...parsed, | ||
}; | ||
} catch (error: any) { | ||
const validationError = fromZodError(error); | ||
throw new MainError({ exitCode: 1, message: validationError.message }); | ||
} | ||
} | ||
export const checkFileOrDirectory = ({ | ||
cwd, | ||
config, | ||
}: { | ||
cwd: string; | ||
config: ConfigFile; | ||
}): ConfigFile["packages"] => | ||
!config.packages | ||
? {} | ||
: { | ||
packages: Object.keys(config.packages).reduce((packages, pkg) => { | ||
const packagePath = config.packages[pkg].path; | ||
if (!packagePath || !cwd) return packages; | ||
const checkDir = statSync(path.join(cwd, packagePath)); | ||
if (checkDir.isFile()) { | ||
const dirName = path.dirname(packagePath); | ||
const packageFileName = path.basename(packagePath); | ||
packages[pkg] = { | ||
...packages[pkg], | ||
path: dirName, | ||
packageFileName, | ||
}; | ||
return packages; | ||
} else { | ||
return packages; | ||
} | ||
}, config?.packages), | ||
}; | ||
export const changeFiles = async ({ | ||
@@ -525,3 +504,3 @@ cwd, | ||
cwd, | ||
} | ||
}, | ||
); | ||
@@ -553,3 +532,3 @@ }; | ||
return changeFilePath; | ||
}) | ||
}), | ||
); | ||
@@ -556,0 +535,0 @@ } |
@@ -30,3 +30,5 @@ import { | ||
const configArray = yield configFile({ cwd: configFolder }); | ||
expect((configArray as any).stuff).toBe("here"); | ||
expect((configArray as any).gitSiteUrl).toBe( | ||
"https://github.com/jbolda/covector", | ||
); | ||
}); | ||
@@ -33,0 +35,0 @@ |
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"strict": true, | ||
"baseUrl": ".", | ||
@@ -5,0 +6,0 @@ "outDir": "dist", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
462488
19
11019
7
2
1
+ Addedzod@^3.21.4
+ Addedzod-validation-error@^1.3.1
+ Addedzod@3.23.8(transitive)
+ Addedzod-validation-error@1.5.0(transitive)
Updatedjs-yaml@^4.1.0
Updatedsemver@^7.5.4