pepr 0.13.3 → 0.13.4

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/cli.js CHANGED
@@ -106,7 +106,7 @@ var banner = `\x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[38;2;96;96;96m \x1B[0m\x1B[
106
106
  // src/cli/build.ts
107
107
  var import_child_process2 = require("child_process");
108
108
  var import_esbuild = require("esbuild");
109
- var import_fs4 = require("fs");
109
+ var import_fs5 = require("fs");
110
110
  var import_path = require("path");
111
111
 
112
112
  // src/lib/assets/index.ts
@@ -775,8 +775,8 @@ var import_client_node3 = require("@kubernetes/client-node");
775
775
  var import_util = require("util");
776
776
  var import_uuid = require("uuid");
777
777
 
778
- // src/templates/.eslintrc.json
779
- var eslintrc_default = {
778
+ // src/templates/.eslintrc.template.json
779
+ var eslintrc_template_default = {
780
780
  env: {
781
781
  browser: false,
782
782
  es2021: true
@@ -784,11 +784,15 @@ var eslintrc_default = {
784
784
  extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
785
785
  parser: "@typescript-eslint/parser",
786
786
  parserOptions: {
787
+ project: ["./tsconfig.json"],
787
788
  ecmaVersion: 2022
788
789
  },
789
790
  plugins: ["@typescript-eslint"],
790
- ignorePatterns: ["node_modules", "dist", "hack"],
791
- root: true
791
+ ignorePatterns: ["node_modules", "dist"],
792
+ root: true,
793
+ rules: {
794
+ "@typescript-eslint/no-floating-promises": ["error"]
795
+ }
792
796
  };
793
797
 
794
798
  // src/templates/.prettierrc.json
@@ -973,7 +977,7 @@ var gitIgnore = "# Ignore node_modules and Pepr build artifacts\nnode_modules\nd
973
977
  var readmeMd = '# Pepr Module\n\nThis is a Pepr Module. [Pepr](https://github.com/defenseunicorns/pepr) is a type-safe Kubernetes middleware system.\n\nThe `capabilities` directory contains all the capabilities for this module. By default,\na capability is a single typescript file in the format of `capability-name.ts` that is\nimported in the root `pepr.ts` file as `import { HelloPepr } from "./capabilities/hello-pepr";`.\nBecause this is typescript, you can organize this however you choose, e.g. creating a sub-folder\nper-capability or common logic in shared files or folders.\n\nExample Structure:\n\n```\nModule Root\n\u251C\u2500\u2500 package.json\n\u251C\u2500\u2500 pepr.ts\n\u2514\u2500\u2500 capabilities\n \u251C\u2500\u2500 example-one.ts\n \u251C\u2500\u2500 example-three.ts\n \u2514\u2500\u2500 example-two.ts\n```\n';
974
978
  var peprTS = 'import { PeprModule } from "pepr";\n// cfg loads your pepr configuration from package.json\nimport cfg from "./package.json";\n\n// HelloPepr is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\nimport { HelloPepr } from "./capabilities/hello-pepr";\n\n/**\n * This is the main entrypoint for this Pepr module. It is run when the module is started.\n * This is where you register your Pepr configurations and capabilities.\n */\nnew PeprModule(cfg, [\n // "HelloPepr" is a demo capability that is included with Pepr. Comment or delete the line below to remove it.\n HelloPepr,\n\n // Your additional capabilities go here\n]);\n';
975
979
  var helloPeprTS = 'import {\n Capability,\n Log,\n PeprMutateRequest,\n RegisterKind,\n a,\n fetch,\n fetchStatus,\n} from "pepr";\n\n/**\n * The HelloPepr Capability is an example capability to demonstrate some general concepts of Pepr.\n * To test this capability you run `pepr dev`and then run the following command:\n * `kubectl apply -f capabilities/hello-pepr.samples.yaml`\n */\nexport const HelloPepr = new Capability({\n name: "hello-pepr",\n description: "A simple example capability to show how things work.",\n namespaces: ["pepr-demo", "pepr-demo-2"],\n});\n\n// Use the \'When\' function to create a new Action\nconst { When } = HelloPepr;\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Namespace) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action removes the label `remove-me` when a Namespace is created.\n * Note we don\'t need to specify the namespace here, because we\'ve already specified\n * it in the Capability definition above.\n */\nWhen(a.Namespace)\n .IsCreated()\n .Mutate(ns => ns.RemoveLabel("remove-me"));\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 1) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is a single action. They can be in the same file or put imported from other files.\n * In this example, when a ConfigMap is created with the name `example-1`, then add a label and annotation.\n *\n * Equivalent to manually running:\n * `kubectl label configmap example-1 pepr=was-here`\n * `kubectl annotate configmap example-1 pepr.dev=annotations-work-too`\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request\n .SetLabel("pepr", "was-here")\n .SetAnnotation("pepr.dev", "annotations-work-too");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate & Validate Actions (CM Example 2) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This combines 2 different types of actions: \'Mutate\', and \'Validate\'. The order\n * of the actions is required, but each action is optional. In this example, when a ConfigMap is created\n * with the name `example-2`, then add a label and annotation and finally validate that the ConfigMap has the label\n * `pepr`.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n // This Mutate Action will mutate the request before it is persisted to the cluster\n\n // Use `request.Merge()` to merge the new data with the existing data\n request.Merge({\n metadata: {\n labels: {\n pepr: "was-here",\n },\n annotations: {\n "pepr.dev": "annotations-work-too",\n },\n },\n });\n })\n .Validate(request => {\n // This Validate Action will validate the request before it is persisted to the cluster\n\n // Approve the request if the ConfigMap has the label \'pepr\'\n if (request.HasLabel("pepr")) {\n return request.Approve();\n }\n\n // Otherwise, deny the request with an error message (optional)\n return request.Deny("ConfigMap must have label \'pepr\'");\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 2a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action shows a simple validation that will deny any ConfigMap that has the\n * annotation `evil`. Note that the `Deny()` function takes an optional second parameter that is a\n * user-defined status code to return.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .Validate(request => {\n if (request.HasAnnotation("evil")) {\n return request.Deny("No evil CM annotations allowed.", 400);\n }\n\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 3) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action combines different styles. Unlike the previous actions, this one will look\n * for any ConfigMap in the `pepr-demo` namespace that has the label `change=by-label` during either\n * CREATE or UPDATE. Note that all conditions added such as `WithName()`, `WithLabel()`, `InNamespace()`,\n * are ANDs so all conditions must be true for the request to be processed.\n */\nWhen(a.ConfigMap)\n .IsCreatedOrUpdated()\n .WithLabel("change", "by-label")\n .Mutate(request => {\n // The K8s object e are going to mutate\n const cm = request.Raw;\n\n // Get the username and uid of the K8s request\n const { username, uid } = request.Request.userInfo;\n\n // Store some data about the request in the configmap\n cm.data["username"] = username;\n cm.data["uid"] = uid;\n\n // You can still mix other ways of making changes too\n request.SetAnnotation("pepr.dev", "making-waves");\n });\n\n// This action validates the label `change=by-label` is deleted\nWhen(a.ConfigMap)\n .IsDeleted()\n .WithLabel("change", "by-label")\n .Validate(request => {\n // Log and then always approve the request\n Log.info("CM with label \'change=by-label\' was deleted.");\n return request.Approve();\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action show how you can use the `Mutate()` function without an inline function.\n * This is useful if you want to keep your actions small and focused on a single task,\n * or if you want to reuse the same function in multiple actions.\n */\nWhen(a.ConfigMap).IsCreated().WithName("example-4").Mutate(example4Cb);\n\n// This function uses the complete type definition, but is not required.\nfunction example4Cb(cm: PeprMutateRequest<a.ConfigMap>) {\n cm.SetLabel("pepr.dev/first", "true");\n cm.SetLabel("pepr.dev/second", "true");\n cm.SetLabel("pepr.dev/third", "true");\n}\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 4a) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This is the same as Example 4, except this only operates on a CM in the `pepr-demo-2` namespace.\n * Note because the Capability defines namespaces, the namespace specified here must be one of those.\n * Alternatively, you can remove the namespace from the Capability definition and specify it here.\n */\nWhen(a.ConfigMap)\n .IsCreated()\n .InNamespace("pepr-demo-2")\n .WithName("example-4a")\n .Mutate(example4Cb);\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (CM Example 5) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This action is a bit more complex. It will look for any ConfigMap in the `pepr-demo`\n * namespace that has the label `chuck-norris` during CREATE. When it finds one, it will fetch a\n * random Chuck Norris joke from the API and add it to the ConfigMap. This is a great example of how\n * you can use Pepr to make changes to your K8s objects based on external data.\n *\n * Note the use of the `async` keyword. This is required for any action that uses `await` or `fetch()`.\n *\n * Also note we are passing a type to the `fetch()` function. This is optional, but it will help you\n * avoid mistakes when working with the data returned from the API. You can also use the `as` keyword to\n * cast the data returned from the API.\n *\n * These are equivalent:\n * ```ts\n * const joke = await fetch<TheChuckNorrisJoke>("https://api.chucknorris.io/jokes/random?category=dev");\n * const joke = await fetch("https://api.chucknorris.io/jokes/random?category=dev") as TheChuckNorrisJoke;\n * ```\n *\n * Alternatively, you can drop the type completely:\n *\n * ```ts\n * fetch("https://api.chucknorris.io/jokes/random?category=dev")\n * ```\n */\ninterface TheChuckNorrisJoke {\n icon_url: string;\n id: string;\n url: string;\n value: string;\n}\n\nWhen(a.ConfigMap)\n .IsCreated()\n .WithLabel("chuck-norris")\n .Mutate(async change => {\n // Try/catch is not needed as a response object will always be returned\n const response = await fetch<TheChuckNorrisJoke>(\n "https://api.chucknorris.io/jokes/random?category=dev",\n );\n\n // Instead, check the `response.ok` field\n if (response.ok) {\n // Add the Chuck Norris joke to the configmap\n change.Raw.data["chuck-says"] = response.data.value;\n return;\n }\n\n // You can also assert on different HTTP response codes\n if (response.status === fetchStatus.NOT_FOUND) {\n // Do something else\n return;\n }\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Secret Base64 Handling) *\n * ---------------------------------------------------------------------------------------------------\n *\n * The K8s JS client provides incomplete support for base64 encoding/decoding handling for secrets,\n * unlike the GO client. To make this less painful, Pepr automatically handles base64 encoding/decoding\n * secret data before and after the action is executed.\n */\nWhen(a.Secret)\n .IsCreated()\n .WithName("secret-1")\n .Mutate(request => {\n const secret = request.Raw;\n\n // This will be encoded at the end of all processing back to base64: "Y2hhbmdlLXdpdGhvdXQtZW5jb2Rpbmc="\n secret.data.magic = "change-without-encoding";\n\n // You can modify the data directly, and it will be encoded at the end of all processing\n secret.data.example += " - modified by Pepr";\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Untyped Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * Out of the box, Pepr supports all the standard Kubernetes objects. However, you can also create\n * your own types. This is useful if you are working with an Operator that creates custom resources.\n * There are two ways to do this, the first is to use the `When()` function with a `GenericKind`,\n * the second is to create a new class that extends `GenericKind` and use the `RegisterKind()` function.\n *\n * This example shows how to use the `When()` function with a `GenericKind`. Note that you\n * must specify the `group`, `version`, and `kind` of the object (if applicable). This is how Pepr knows\n * if the action should be triggered or not. Since we are using a `GenericKind`,\n * Pepr will not be able to provide any intellisense for the object, so you will need to refer to the\n * Kubernetes API documentation for the object you are working with.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-1\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```\n */\nWhen(a.GenericKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n})\n .IsCreated()\n .WithName("example-1")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr without type data!",\n counter: Math.random(),\n },\n });\n });\n\n/**\n * ---------------------------------------------------------------------------------------------------\n * Mutate Action (Typed Custom Resource) *\n * ---------------------------------------------------------------------------------------------------\n *\n * This example shows how to use the `RegisterKind()` function to create a new type. This is useful\n * if you are working with an Operator that creates custom resources and you want to have intellisense\n * for the object. Note that you must specify the `group`, `version`, and `kind` of the object (if applicable)\n * as this is how Pepr knows if the action should be triggered or not.\n *\n * Once you register a new Kind with Pepr, you can use the `When()` function with the new Kind. Ideally,\n * you should register custom Kinds at the top of your Capability file or Pepr Module so they are available\n * to all actions, but we are putting it here for demonstration purposes.\n *\n * You will need to wait for the CRD in `hello-pepr.samples.yaml` to be created, then you can apply\n *\n * ```yaml\n * apiVersion: pepr.dev/v1\n * kind: Unicorn\n * metadata:\n * name: example-2\n * namespace: pepr-demo\n * spec:\n * message: replace-me\n * counter: 0\n * ```*\n */\nclass UnicornKind extends a.GenericKind {\n spec: {\n /**\n * JSDoc comments can be added to explain more details about the field.\n *\n * @example\n * ```ts\n * request.Raw.spec.message = "Hello Pepr!";\n * ```\n * */\n message: string;\n counter: number;\n };\n}\n\nRegisterKind(UnicornKind, {\n group: "pepr.dev",\n version: "v1",\n kind: "Unicorn",\n});\n\nWhen(UnicornKind)\n .IsCreated()\n .WithName("example-2")\n .Mutate(request => {\n request.Merge({\n spec: {\n message: "Hello Pepr with type data!",\n counter: Math.random(),\n },\n });\n });\n';
976
- var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.13.3", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest journey/entrypoint.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@kubernetes/client-node": "0.18.1", express: "4.18.2", "fast-json-patch": "3.1.1", "http-status-codes": "2.2.0", "node-fetch": "2.7.0", pino: "8.15.1", "pino-pretty": "10.2.0", "prom-client": "14.2.0", ramda: "0.29.0" }, devDependencies: { "@jest/globals": "29.6.4", "@types/eslint": "8.44.2", "@types/express": "4.17.17", "@types/node": "18.x.x", "@types/node-fetch": "2.6.4", "@types/node-forge": "1.3.4", "@types/prettier": "3.0.0", "@types/prompts": "2.4.4", "@types/ramda": "0.29.3", "@types/uuid": "9.0.3", jest: "29.6.4", nock: "13.3.3", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.5.0", "@typescript-eslint/parser": "6.5.0", commander: "11.0.0", esbuild: "0.19.2", eslint: "8.48.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.0" } };
980
+ var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.13.4", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest journey/entrypoint.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@kubernetes/client-node": "0.19.0", express: "4.18.2", "fast-json-patch": "3.1.1", "http-status-codes": "2.2.0", "node-fetch": "2.7.0", pino: "8.15.1", "pino-pretty": "10.2.0", "prom-client": "14.2.0", ramda: "0.29.0" }, devDependencies: { "@jest/globals": "29.7.0", "@types/eslint": "8.44.2", "@types/express": "4.17.17", "@types/node": "18.x.x", "@types/node-fetch": "2.6.4", "@types/node-forge": "1.3.5", "@types/prettier": "3.0.0", "@types/prompts": "2.4.4", "@types/ramda": "0.29.4", "@types/uuid": "9.0.4", jest: "29.7.0", nock: "13.3.3", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.5.0", "@typescript-eslint/parser": "6.5.0", commander: "11.0.0", esbuild: "0.19.2", eslint: "8.48.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.0" } };
977
981
 
978
982
  // src/templates/pepr.code-snippets.json
979
983
  var pepr_code_snippets_default = {
@@ -1135,9 +1139,64 @@ var prettier = {
1135
1139
  };
1136
1140
  var eslint = {
1137
1141
  path: ".eslintrc.json",
1138
- data: eslintrc_default
1142
+ data: eslintrc_template_default
1139
1143
  };
1140
1144
 
1145
+ // src/cli/format.ts
1146
+ var import_eslint = require("eslint");
1147
+ var import_fs4 = require("fs");
1148
+ var import_prettier = require("prettier");
1149
+ function format_default(program2) {
1150
+ program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
1151
+ const success = await peprFormat(opts.validateOnly);
1152
+ if (success) {
1153
+ console.info("\u2705 Module formatted");
1154
+ } else {
1155
+ process.exit(1);
1156
+ }
1157
+ });
1158
+ }
1159
+ async function peprFormat(validateOnly) {
1160
+ {
1161
+ try {
1162
+ const eslint2 = new import_eslint.ESLint();
1163
+ const results = await eslint2.lintFiles(["./**/*.ts"]);
1164
+ let hasFailure = false;
1165
+ results.forEach(async (result) => {
1166
+ const errorCount = result.fatalErrorCount + result.errorCount;
1167
+ if (errorCount > 0) {
1168
+ hasFailure = true;
1169
+ }
1170
+ });
1171
+ const formatter = await eslint2.loadFormatter("stylish");
1172
+ const resultText = await formatter.format(results);
1173
+ if (resultText) {
1174
+ console.log(resultText);
1175
+ }
1176
+ if (!validateOnly) {
1177
+ await import_eslint.ESLint.outputFixes(results);
1178
+ }
1179
+ for (const { filePath } of results) {
1180
+ const content = await import_fs4.promises.readFile(filePath, "utf8");
1181
+ const cfg = await (0, import_prettier.resolveConfig)(filePath);
1182
+ const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
1183
+ if (validateOnly) {
1184
+ if (formatted !== content) {
1185
+ hasFailure = true;
1186
+ console.error(`File ${filePath} is not formatted correctly`);
1187
+ }
1188
+ } else {
1189
+ await import_fs4.promises.writeFile(filePath, formatted);
1190
+ }
1191
+ }
1192
+ return !hasFailure;
1193
+ } catch (e) {
1194
+ console.error(e.message);
1195
+ return false;
1196
+ }
1197
+ }
1198
+ }
1199
+
1141
1200
  // src/cli/build.ts
1142
1201
  var peprTS2 = "pepr.ts";
1143
1202
  function build_default(program2) {
@@ -1164,8 +1223,8 @@ function build_default(program2) {
1164
1223
  const yaml = await assets.allYaml();
1165
1224
  const zarfPath = (0, import_path.resolve)("dist", "zarf.yaml");
1166
1225
  const zarf = assets.zarfYaml(yamlFile);
1167
- await import_fs4.promises.writeFile(yamlPath, yaml);
1168
- await import_fs4.promises.writeFile(zarfPath, zarf);
1226
+ await import_fs5.promises.writeFile(yamlPath, yaml);
1227
+ await import_fs5.promises.writeFile(zarfPath, zarf);
1169
1228
  console.info(`\u2705 K8s resource for the module saved to ${yamlPath}`);
1170
1229
  });
1171
1230
  }
@@ -1175,15 +1234,15 @@ async function loadModule(entryPoint = peprTS2) {
1175
1234
  const cfgPath = (0, import_path.resolve)(".", "package.json");
1176
1235
  const input = (0, import_path.resolve)(".", entryPoint);
1177
1236
  try {
1178
- await import_fs4.promises.access(cfgPath);
1179
- await import_fs4.promises.access(input);
1237
+ await import_fs5.promises.access(cfgPath);
1238
+ await import_fs5.promises.access(input);
1180
1239
  } catch (e) {
1181
1240
  console.error(
1182
1241
  `Could not find ${cfgPath} or ${input} in the current directory. Please run this command from the root of your module's directory.`
1183
1242
  );
1184
1243
  process.exit(1);
1185
1244
  }
1186
- const moduleText = await import_fs4.promises.readFile(cfgPath, { encoding: "utf-8" });
1245
+ const moduleText = await import_fs5.promises.readFile(cfgPath, { encoding: "utf-8" });
1187
1246
  const cfg = JSON.parse(moduleText);
1188
1247
  const { uuid } = cfg.pepr;
1189
1248
  const name = `pepr-${uuid}.js`;
@@ -1202,6 +1261,13 @@ async function loadModule(entryPoint = peprTS2) {
1202
1261
  async function buildModule(reloader, entryPoint = peprTS2) {
1203
1262
  try {
1204
1263
  const { cfg, path, uuid } = await loadModule(entryPoint);
1264
+ const validFormat = await peprFormat(true);
1265
+ if (!validFormat) {
1266
+ console.log(
1267
+ "\x1B[33m%s\x1B[0m",
1268
+ "Formatting errors were found. The build will continue, but you may want to run `npx pepr format` to address any issues."
1269
+ );
1270
+ }
1205
1271
  (0, import_child_process2.execSync)("./node_modules/.bin/tsc", { stdio: "pipe" });
1206
1272
  const ctxCfg = {
1207
1273
  bundle: true,
@@ -1319,7 +1385,7 @@ function deploy_default(program2) {
1319
1385
 
1320
1386
  // src/cli/dev.ts
1321
1387
  var import_child_process3 = require("child_process");
1322
- var import_fs5 = require("fs");
1388
+ var import_fs6 = require("fs");
1323
1389
  var import_prompts2 = __toESM(require("prompts"));
1324
1390
  function dev_default(program2) {
1325
1391
  program2.command("dev").description("Setup a local webhook development environment").option("-h, --host [host]", "Host to listen on", "host.k3d.internal").option("--confirm", "Skip confirmation prompt").action(async (opts) => {
@@ -1342,8 +1408,8 @@ function dev_default(program2) {
1342
1408
  path,
1343
1409
  opts.host
1344
1410
  );
1345
- await import_fs5.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
1346
- await import_fs5.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
1411
+ await import_fs6.promises.writeFile("insecure-tls.crt", webhook.tls.pem.crt);
1412
+ await import_fs6.promises.writeFile("insecure-tls.key", webhook.tls.pem.key);
1347
1413
  try {
1348
1414
  let program3;
1349
1415
  const runFork = async () => {
@@ -1380,54 +1446,6 @@ function dev_default(program2) {
1380
1446
  });
1381
1447
  }
1382
1448
 
1383
- // src/cli/format.ts
1384
- var import_eslint = require("eslint");
1385
- var import_fs6 = require("fs");
1386
- var import_prettier = require("prettier");
1387
- function format_default(program2) {
1388
- program2.command("format").description("Lint and format this Pepr module").option("-v, --validate-only", "Do not modify files, only validate formatting").action(async (opts) => {
1389
- try {
1390
- const eslint2 = new import_eslint.ESLint();
1391
- const results = await eslint2.lintFiles(["./**/*.ts"]);
1392
- let hasFailure = false;
1393
- results.forEach(async (result) => {
1394
- const errorCount = result.fatalErrorCount + result.errorCount;
1395
- if (errorCount > 0) {
1396
- hasFailure = true;
1397
- }
1398
- });
1399
- const formatter = await eslint2.loadFormatter("stylish");
1400
- const resultText = await formatter.format(results);
1401
- if (resultText) {
1402
- console.log(resultText);
1403
- }
1404
- if (!opts.validateOnly) {
1405
- await import_eslint.ESLint.outputFixes(results);
1406
- }
1407
- for (const { filePath } of results) {
1408
- const content = await import_fs6.promises.readFile(filePath, "utf8");
1409
- const cfg = await (0, import_prettier.resolveConfig)(filePath);
1410
- const formatted = await (0, import_prettier.format)(content, { filepath: filePath, ...cfg });
1411
- if (opts.validateOnly) {
1412
- if (formatted !== content) {
1413
- hasFailure = true;
1414
- console.error(`File ${filePath} is not formatted correctly`);
1415
- }
1416
- } else {
1417
- await import_fs6.promises.writeFile(filePath, formatted);
1418
- }
1419
- }
1420
- if (opts.validateOnly && hasFailure) {
1421
- process.exit(1);
1422
- }
1423
- console.info("\u2705 Module formatted");
1424
- } catch (e) {
1425
- console.error(e.message);
1426
- process.exit(1);
1427
- }
1428
- });
1429
- }
1430
-
1431
1449
  // src/cli/init/index.ts
1432
1450
  var import_child_process4 = require("child_process");
1433
1451
  var import_path2 = require("path");
@@ -48,7 +48,7 @@ if (process.env.LOG_LEVEL) {
48
48
  var logger_default = Log;
49
49
 
50
50
  // src/templates/data.json
51
- var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.13.3", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest journey/entrypoint.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@kubernetes/client-node": "0.18.1", express: "4.18.2", "fast-json-patch": "3.1.1", "http-status-codes": "2.2.0", "node-fetch": "2.7.0", pino: "8.15.1", "pino-pretty": "10.2.0", "prom-client": "14.2.0", ramda: "0.29.0" }, devDependencies: { "@jest/globals": "29.6.4", "@types/eslint": "8.44.2", "@types/express": "4.17.17", "@types/node": "18.x.x", "@types/node-fetch": "2.6.4", "@types/node-forge": "1.3.4", "@types/prettier": "3.0.0", "@types/prompts": "2.4.4", "@types/ramda": "0.29.3", "@types/uuid": "9.0.3", jest: "29.6.4", nock: "13.3.3", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.5.0", "@typescript-eslint/parser": "6.5.0", commander: "11.0.0", esbuild: "0.19.2", eslint: "8.48.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.0" } };
51
+ var packageJSON = { name: "pepr", description: "Kubernetes application engine", author: "Defense Unicorns", homepage: "https://github.com/defenseunicorns/pepr", license: "Apache-2.0", bin: "dist/cli.js", repository: "defenseunicorns/pepr", engines: { node: ">=18.0.0" }, version: "0.13.4", main: "dist/lib.js", types: "dist/lib.d.ts", scripts: { "gen-data-json": "node hack/build-template-data.js", prebuild: "rm -fr dist/* && npm run gen-data-json", build: "tsc && node build.mjs", test: "npm run test:unit && npm run test:journey", "test:unit": "npm run gen-data-json && jest src --coverage", "test:journey": "npm run test:journey:k3d && npm run test:journey:build && npm run test:journey:image && npm run test:journey:run", "test:journey:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'", "test:journey:build": "npm run build && npm pack", "test:journey:image": "docker buildx build --tag pepr:dev . && k3d image import pepr:dev -c pepr-dev", "test:journey:run": "jest journey/entrypoint.test.ts", "format:check": "eslint src && prettier src --check", "format:fix": "eslint src --fix && prettier src --write" }, dependencies: { "@kubernetes/client-node": "0.19.0", express: "4.18.2", "fast-json-patch": "3.1.1", "http-status-codes": "2.2.0", "node-fetch": "2.7.0", pino: "8.15.1", "pino-pretty": "10.2.0", "prom-client": "14.2.0", ramda: "0.29.0" }, devDependencies: { "@jest/globals": "29.7.0", "@types/eslint": "8.44.2", "@types/express": "4.17.17", "@types/node": "18.x.x", "@types/node-fetch": "2.6.4", "@types/node-forge": "1.3.5", "@types/prettier": "3.0.0", "@types/prompts": "2.4.4", "@types/ramda": "0.29.4", "@types/uuid": "9.0.4", jest: "29.7.0", nock: "13.3.3", "ts-jest": "29.1.1" }, peerDependencies: { "@typescript-eslint/eslint-plugin": "6.5.0", "@typescript-eslint/parser": "6.5.0", commander: "11.0.0", esbuild: "0.19.2", eslint: "8.48.0", "node-forge": "1.3.1", prettier: "3.0.3", prompts: "2.4.2", typescript: "5.2.2", uuid: "9.0.0" } };
52
52
 
53
53
  // src/runtime/controller.ts
54
54
  var { version } = packageJSON;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "engines": {
10
10
  "node": ">=18.0.0"
11
11
  },
12
- "version": "0.13.3",
12
+ "version": "0.13.4",
13
13
  "main": "dist/lib.js",
14
14
  "types": "dist/lib.d.ts",
15
15
  "scripts": {
@@ -27,7 +27,7 @@
27
27
  "format:fix": "eslint src --fix && prettier src --write"
28
28
  },
29
29
  "dependencies": {
30
- "@kubernetes/client-node": "0.18.1",
30
+ "@kubernetes/client-node": "0.19.0",
31
31
  "express": "4.18.2",
32
32
  "fast-json-patch": "3.1.1",
33
33
  "http-status-codes": "2.2.0",
@@ -38,17 +38,17 @@
38
38
  "ramda": "0.29.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@jest/globals": "29.6.4",
41
+ "@jest/globals": "29.7.0",
42
42
  "@types/eslint": "8.44.2",
43
43
  "@types/express": "4.17.17",
44
44
  "@types/node": "18.x.x",
45
45
  "@types/node-fetch": "2.6.4",
46
- "@types/node-forge": "1.3.4",
46
+ "@types/node-forge": "1.3.5",
47
47
  "@types/prettier": "3.0.0",
48
48
  "@types/prompts": "2.4.4",
49
- "@types/ramda": "0.29.3",
50
- "@types/uuid": "9.0.3",
51
- "jest": "29.6.4",
49
+ "@types/ramda": "0.29.4",
50
+ "@types/uuid": "9.0.4",
51
+ "jest": "29.7.0",
52
52
  "nock": "13.3.3",
53
53
  "ts-jest": "29.1.1"
54
54
  },
@@ -0,0 +1,18 @@
1
+ {
2
+ "env": {
3
+ "browser": false,
4
+ "es2021": true
5
+ },
6
+ "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
7
+ "parser": "@typescript-eslint/parser",
8
+ "parserOptions": {
9
+ "project": ["./tsconfig.json"],
10
+ "ecmaVersion": 2022
11
+ },
12
+ "plugins": ["@typescript-eslint"],
13
+ "ignorePatterns": ["node_modules", "dist"],
14
+ "root": true,
15
+ "rules": {
16
+ "@typescript-eslint/no-floating-promises": ["error"]
17
+ }
18
+ }