pepr 0.2.10 → 0.3.0-rc0

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.
Files changed (81) hide show
  1. package/dist/fixtures/data/cm1.json +75 -0
  2. package/dist/fixtures/data/deployment1.json +170 -0
  3. package/dist/fixtures/data/ns1.json +72 -0
  4. package/dist/fixtures/data/pod1.json +271 -0
  5. package/dist/fixtures/data/pod2.json +257 -0
  6. package/dist/fixtures/data/svc1.json +100 -0
  7. package/dist/fixtures/loader.js +60 -0
  8. package/dist/package.json +21 -39
  9. package/dist/src/cli/build.js +3 -1
  10. package/dist/src/cli/dev.js +31 -19
  11. package/dist/src/cli/index.js +1 -0
  12. package/dist/src/cli/init/index.js +3 -1
  13. package/dist/src/cli/init/templates.js +3 -2
  14. package/dist/src/cli/init/utils.js +1 -1
  15. package/dist/src/cli/init/utils.test.js +29 -0
  16. package/dist/src/cli/init/walkthrough.js +1 -1
  17. package/dist/src/cli/init/walkthrough.test.js +21 -0
  18. package/dist/src/cli/run.js +17 -17
  19. package/dist/src/cli/update.js +3 -1
  20. package/dist/src/lib/capability.js +1 -1
  21. package/dist/src/lib/controller.js +9 -1
  22. package/dist/src/lib/fetch.js +39 -6
  23. package/dist/src/lib/fetch.test.js +98 -0
  24. package/dist/src/lib/filter.test.js +208 -0
  25. package/dist/src/lib/k8s/kinds.test.js +296 -0
  26. package/dist/src/lib/k8s/webhook.js +22 -22
  27. package/dist/src/lib/logger.test.js +64 -0
  28. package/dist/src/lib/processor.js +4 -1
  29. package/{dist/index.d.ts → index.ts} +21 -3
  30. package/package.json +21 -39
  31. package/src/lib/capability.ts +158 -0
  32. package/src/lib/controller.ts +127 -0
  33. package/src/lib/fetch.test.ts +115 -0
  34. package/src/lib/fetch.ts +75 -0
  35. package/src/lib/filter.test.ts +231 -0
  36. package/src/lib/filter.ts +87 -0
  37. package/{dist/src/lib/k8s/index.d.ts → src/lib/k8s/index.ts} +6 -0
  38. package/src/lib/k8s/kinds.test.ts +333 -0
  39. package/src/lib/k8s/kinds.ts +489 -0
  40. package/src/lib/k8s/tls.ts +90 -0
  41. package/src/lib/k8s/types.ts +183 -0
  42. package/src/lib/k8s/upstream.ts +49 -0
  43. package/src/lib/k8s/webhook.ts +547 -0
  44. package/src/lib/logger.test.ts +80 -0
  45. package/src/lib/logger.ts +136 -0
  46. package/src/lib/module.ts +63 -0
  47. package/src/lib/processor.ts +98 -0
  48. package/src/lib/request.ts +140 -0
  49. package/src/lib/types.ts +211 -0
  50. package/dist/cli.d.ts +0 -2
  51. package/dist/cli.js +0 -4
  52. package/dist/run.d.ts +0 -2
  53. package/dist/run.js +0 -4
  54. package/dist/src/cli/banner.d.ts +0 -1
  55. package/dist/src/cli/build.d.ts +0 -7
  56. package/dist/src/cli/capability.d.ts +0 -2
  57. package/dist/src/cli/deploy.d.ts +0 -2
  58. package/dist/src/cli/dev.d.ts +0 -2
  59. package/dist/src/cli/index.d.ts +0 -1
  60. package/dist/src/cli/init/index.d.ts +0 -2
  61. package/dist/src/cli/init/templates.d.ts +0 -94
  62. package/dist/src/cli/init/utils.d.ts +0 -20
  63. package/dist/src/cli/init/walkthrough.d.ts +0 -7
  64. package/dist/src/cli/root.d.ts +0 -4
  65. package/dist/src/cli/run.d.ts +0 -1
  66. package/dist/src/cli/test.d.ts +0 -2
  67. package/dist/src/cli/update.d.ts +0 -2
  68. package/dist/src/lib/capability.d.ts +0 -28
  69. package/dist/src/lib/controller.d.ts +0 -17
  70. package/dist/src/lib/fetch.d.ts +0 -23
  71. package/dist/src/lib/filter.d.ts +0 -10
  72. package/dist/src/lib/k8s/kinds.d.ts +0 -11
  73. package/dist/src/lib/k8s/tls.d.ts +0 -17
  74. package/dist/src/lib/k8s/types.d.ts +0 -147
  75. package/dist/src/lib/k8s/upstream.d.ts +0 -3
  76. package/dist/src/lib/k8s/webhook.d.ts +0 -34
  77. package/dist/src/lib/logger.d.ts +0 -55
  78. package/dist/src/lib/module.d.ts +0 -32
  79. package/dist/src/lib/processor.d.ts +0 -4
  80. package/dist/src/lib/request.d.ts +0 -77
  81. package/dist/src/lib/types.d.ts +0 -187
@@ -0,0 +1,257 @@
1
+ {
2
+ "uid": "e40aafc4-db17-4368-89e9-e7bda15b814d",
3
+ "kind": {
4
+ "group": "",
5
+ "version": "v1",
6
+ "kind": "Pod"
7
+ },
8
+ "resource": {
9
+ "group": "",
10
+ "version": "v1",
11
+ "resource": "pods"
12
+ },
13
+ "requestKind": {
14
+ "group": "",
15
+ "version": "v1",
16
+ "kind": "Pod"
17
+ },
18
+ "requestResource": {
19
+ "group": "",
20
+ "version": "v1",
21
+ "resource": "pods"
22
+ },
23
+ "name": "lifespan-seven",
24
+ "namespace": "apps",
25
+ "operation": "CREATE",
26
+ "userInfo": {
27
+ "username": "kubernetes-admin",
28
+ "groups": ["system:masters", "system:authenticated"]
29
+ },
30
+ "object": {
31
+ "kind": "Pod",
32
+ "apiVersion": "v1",
33
+ "metadata": {
34
+ "name": "lifespan-seven",
35
+ "namespace": "apps",
36
+ "uid": "6cc7f934-7054-4387-9a69-84fb3dc9fd87",
37
+ "creationTimestamp": "2023-03-31T18:15:31Z",
38
+ "labels": {
39
+ "acme.com/lifespan-requested": "7"
40
+ },
41
+ "annotations": {
42
+ "kubectl.kubernetes.io/last-applied-configuration": {
43
+ "apiVersion": "v1",
44
+ "kind": "Pod",
45
+ "metadata": {
46
+ "annotations": {},
47
+ "labels": {
48
+ "acme.com/lifespan-requested": "7"
49
+ },
50
+ "name": "lifespan-seven",
51
+ "namespace": "apps"
52
+ },
53
+ "spec": {
54
+ "containers": [
55
+ {
56
+ "args": ["sleep", "3600"],
57
+ "image": "busybox",
58
+ "name": "lifespan-seven"
59
+ }
60
+ ],
61
+ "restartPolicy": "Always"
62
+ }
63
+ }
64
+ },
65
+ "managedFields": [
66
+ {
67
+ "manager": "kubectl-client-side-apply",
68
+ "operation": "Update",
69
+ "apiVersion": "v1",
70
+ "time": "2023-03-31T18:15:31Z",
71
+ "fieldsType": "FieldsV1",
72
+ "fieldsV1": {
73
+ "f:metadata": {
74
+ "f:annotations": {
75
+ ".": {},
76
+ "f:kubectl.kubernetes.io/last-applied-configuration": {}
77
+ },
78
+ "f:labels": {
79
+ ".": {},
80
+ "f:acme.com/lifespan-requested": {}
81
+ }
82
+ },
83
+ "f:spec": {
84
+ "f:containers": {
85
+ "k:{\"name\":\"lifespan-seven\"}": {
86
+ ".": {},
87
+ "f:args": {},
88
+ "f:image": {},
89
+ "f:imagePullPolicy": {},
90
+ "f:name": {},
91
+ "f:resources": {},
92
+ "f:terminationMessagePath": {},
93
+ "f:terminationMessagePolicy": {}
94
+ }
95
+ },
96
+ "f:dnsPolicy": {},
97
+ "f:enableServiceLinks": {},
98
+ "f:restartPolicy": {},
99
+ "f:schedulerName": {},
100
+ "f:securityContext": {},
101
+ "f:terminationGracePeriodSeconds": {}
102
+ }
103
+ }
104
+ }
105
+ ]
106
+ },
107
+ "spec": {
108
+ "volumes": [
109
+ {
110
+ "name": "kube-api-access-65g4k",
111
+ "projected": {
112
+ "sources": [
113
+ {
114
+ "serviceAccountToken": {
115
+ "expirationSeconds": 3607,
116
+ "path": "token"
117
+ }
118
+ },
119
+ {
120
+ "configMap": {
121
+ "name": "kube-root-ca.crt",
122
+ "items": [
123
+ {
124
+ "key": "ca.crt",
125
+ "path": "ca.crt"
126
+ }
127
+ ]
128
+ }
129
+ },
130
+ {
131
+ "downwardAPI": {
132
+ "items": [
133
+ {
134
+ "path": "namespace",
135
+ "fieldRef": {
136
+ "apiVersion": "v1",
137
+ "fieldPath": "metadata.namespace"
138
+ }
139
+ }
140
+ ]
141
+ }
142
+ }
143
+ ],
144
+ "defaultMode": 420
145
+ }
146
+ }
147
+ ],
148
+ "containers": [
149
+ {
150
+ "name": "lifespan-seven",
151
+ "image": "busybox",
152
+ "args": ["sleep", "3600"],
153
+ "env": [
154
+ {
155
+ "name": "KUBE",
156
+ "value": "true"
157
+ }
158
+ ],
159
+ "resources": {},
160
+ "volumeMounts": [
161
+ {
162
+ "name": "kube-api-access-65g4k",
163
+ "readOnly": true,
164
+ "mountPath": "/var/run/secrets/kubernetes.io/serviceaccount"
165
+ }
166
+ ],
167
+ "terminationMessagePath": "/dev/termination-log",
168
+ "terminationMessagePolicy": "File",
169
+ "imagePullPolicy": "Always"
170
+ }
171
+ ],
172
+ "restartPolicy": "Always",
173
+ "terminationGracePeriodSeconds": 30,
174
+ "dnsPolicy": "ClusterFirst",
175
+ "serviceAccountName": "default",
176
+ "serviceAccount": "default",
177
+ "securityContext": {},
178
+ "schedulerName": "default-scheduler",
179
+ "tolerations": [
180
+ {
181
+ "key": "node.kubernetes.io/not-ready",
182
+ "operator": "Exists",
183
+ "effect": "NoExecute",
184
+ "tolerationSeconds": 300
185
+ },
186
+ {
187
+ "key": "node.kubernetes.io/unreachable",
188
+ "operator": "Exists",
189
+ "effect": "NoExecute",
190
+ "tolerationSeconds": 300
191
+ },
192
+ {
193
+ "key": "acme.com/lifespan-remaining",
194
+ "operator": "Equal",
195
+ "value": "14",
196
+ "effect": "NoSchedule"
197
+ },
198
+ {
199
+ "key": "acme.com/lifespan-remaining",
200
+ "operator": "Equal",
201
+ "value": "13",
202
+ "effect": "NoSchedule"
203
+ },
204
+ {
205
+ "key": "acme.com/lifespan-remaining",
206
+ "operator": "Equal",
207
+ "value": "12",
208
+ "effect": "NoSchedule"
209
+ },
210
+ {
211
+ "key": "acme.com/lifespan-remaining",
212
+ "operator": "Equal",
213
+ "value": "11",
214
+ "effect": "NoSchedule"
215
+ },
216
+ {
217
+ "key": "acme.com/lifespan-remaining",
218
+ "operator": "Equal",
219
+ "value": "10",
220
+ "effect": "NoSchedule"
221
+ },
222
+ {
223
+ "key": "acme.com/lifespan-remaining",
224
+ "operator": "Equal",
225
+ "value": "9",
226
+ "effect": "NoSchedule"
227
+ },
228
+ {
229
+ "key": "acme.com/lifespan-remaining",
230
+ "operator": "Equal",
231
+ "value": "8",
232
+ "effect": "NoSchedule"
233
+ },
234
+ {
235
+ "key": "acme.com/lifespan-remaining",
236
+ "operator": "Equal",
237
+ "value": "7",
238
+ "effect": "NoSchedule"
239
+ }
240
+ ],
241
+ "priority": 0,
242
+ "enableServiceLinks": true,
243
+ "preemptionPolicy": "PreemptLowerPriority"
244
+ },
245
+ "status": {
246
+ "phase": "Pending",
247
+ "qosClass": "BestEffort"
248
+ }
249
+ },
250
+ "oldObject": null,
251
+ "dryRun": false,
252
+ "options": {
253
+ "kind": "CreateOptions",
254
+ "apiVersion": "meta.k8s.io/v1",
255
+ "fieldManager": "kubectl-client-side-apply"
256
+ }
257
+ }
@@ -0,0 +1,100 @@
1
+ {
2
+ "uid": "f7b55ff2-18ef-403c-87fe-bac8435e0ed7",
3
+ "kind": {
4
+ "group": "",
5
+ "version": "v1",
6
+ "kind": "Service"
7
+ },
8
+ "resource": {
9
+ "group": "",
10
+ "version": "v1",
11
+ "resource": "services"
12
+ },
13
+ "requestKind": {
14
+ "group": "",
15
+ "version": "v1",
16
+ "kind": "Service"
17
+ },
18
+ "requestResource": {
19
+ "group": "",
20
+ "version": "v1",
21
+ "resource": "services"
22
+ },
23
+ "name": "my-service",
24
+ "namespace": "apps",
25
+ "operation": "CREATE",
26
+ "userInfo": {
27
+ "username": "kubernetes-admin",
28
+ "groups": ["system:masters", "system:authenticated"]
29
+ },
30
+ "object": {
31
+ "kind": "Service",
32
+ "apiVersion": "v1",
33
+ "metadata": {
34
+ "name": "my-service",
35
+ "namespace": "apps",
36
+ "creationTimestamp": null,
37
+ "annotations": {
38
+ "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"v1\",\"kind\":\"Service\",\"metadata\":{\"annotations\":{},\"name\":\"my-service\",\"namespace\":\"apps\"},\"spec\":{\"ports\":[{\"port\":80,\"protocol\":\"TCP\",\"targetPort\":9376}],\"selector\":{\"app.kubernetes.io/name\":\"MyApp\"}}}\n"
39
+ },
40
+ "managedFields": [
41
+ {
42
+ "manager": "kubectl-client-side-apply",
43
+ "operation": "Update",
44
+ "apiVersion": "v1",
45
+ "time": "2023-03-31T19:08:48Z",
46
+ "fieldsType": "FieldsV1",
47
+ "fieldsV1": {
48
+ "f:metadata": {
49
+ "f:annotations": {
50
+ ".": {},
51
+ "f:kubectl.kubernetes.io/last-applied-configuration": {}
52
+ }
53
+ },
54
+ "f:spec": {
55
+ "f:ports": {
56
+ ".": {},
57
+ "k:{\"port\":80,\"protocol\":\"TCP\"}": {
58
+ ".": {},
59
+ "f:port": {},
60
+ "f:protocol": {},
61
+ "f:targetPort": {}
62
+ }
63
+ },
64
+ "f:selector": {
65
+ ".": {},
66
+ "f:app.kubernetes.io/name": {}
67
+ },
68
+ "f:sessionAffinity": {},
69
+ "f:type": {}
70
+ }
71
+ }
72
+ }
73
+ ]
74
+ },
75
+ "spec": {
76
+ "ports": [
77
+ {
78
+ "protocol": "TCP",
79
+ "port": 80,
80
+ "targetPort": 9376
81
+ }
82
+ ],
83
+ "selector": {
84
+ "app.kubernetes.io/name": "MyApp"
85
+ },
86
+ "type": "ClusterIP",
87
+ "sessionAffinity": "None"
88
+ },
89
+ "status": {
90
+ "loadBalancer": {}
91
+ }
92
+ },
93
+ "oldObject": null,
94
+ "dryRun": false,
95
+ "options": {
96
+ "kind": "CreateOptions",
97
+ "apiVersion": "meta.k8s.io/v1",
98
+ "fieldManager": "kubectl-client-side-apply"
99
+ }
100
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.NS1 = exports.CM1 = exports.DEPLOYMENT1 = exports.SVC1 = exports.POD2 = exports.POD1 = void 0;
27
+ const cm1 = __importStar(require("./data/cm1.json"));
28
+ const deployment1 = __importStar(require("./data/deployment1.json"));
29
+ const ns1 = __importStar(require("./data/ns1.json"));
30
+ const pod1 = __importStar(require("./data/pod1.json"));
31
+ const pod2 = __importStar(require("./data/pod2.json"));
32
+ const svc1 = __importStar(require("./data/svc1.json"));
33
+ function POD1() {
34
+ return cloneObject(pod1);
35
+ }
36
+ exports.POD1 = POD1;
37
+ function POD2() {
38
+ return cloneObject(pod2);
39
+ }
40
+ exports.POD2 = POD2;
41
+ function SVC1() {
42
+ return cloneObject(svc1);
43
+ }
44
+ exports.SVC1 = SVC1;
45
+ function DEPLOYMENT1() {
46
+ return cloneObject(deployment1);
47
+ }
48
+ exports.DEPLOYMENT1 = DEPLOYMENT1;
49
+ function CM1() {
50
+ return cloneObject(cm1);
51
+ }
52
+ exports.CM1 = CM1;
53
+ function NS1() {
54
+ return cloneObject(ns1);
55
+ }
56
+ exports.NS1 = NS1;
57
+ function cloneObject(obj) {
58
+ // JSON to avoid funky typescript silliness on jsonmodules
59
+ return JSON.parse(JSON.stringify(obj));
60
+ }
package/dist/package.json CHANGED
@@ -4,29 +4,17 @@
4
4
  "author": "Defense Unicorns",
5
5
  "homepage": "https://github.com/defenseunicorns/pepr",
6
6
  "license": "Apache-2.0",
7
- "bin": "dist/cli.js",
7
+ "bin": "dist/src/cli/index.js",
8
8
  "repository": "defenseunicorns/pepr",
9
9
  "engines": {
10
10
  "node": ">=18.0.0"
11
11
  },
12
- "version": "0.2.10",
12
+ "version": "0.3.0-rc0",
13
13
  "main": "dist/index.js",
14
- "types": "dist/index.d.ts",
15
- "pepr": {
16
- "name": "Development Module",
17
- "uuid": "20e17cf6-a2e4-46b2-b626-75d88d96c88b",
18
- "description": "Development module for pepr",
19
- "version": "dev",
20
- "onError": "ignore",
21
- "alwaysIgnore": {
22
- "namespaces": [],
23
- "labels": []
24
- }
25
- },
26
14
  "scripts": {
27
15
  "prebuild": "rm -fr dist/* && node hack/build-template-data.js",
28
- "build": "tsc -p tsconfig.build.json",
29
- "test:unit": "npm run build && ava",
16
+ "build": "tsc",
17
+ "test:unit": "npm run build && ava dist/**/*.test.js",
30
18
  "test:e2e": "npm run test:e2e:k3d && npm run test:e2e:build && npm run test:e2e:image && npm run test:e2e:run",
31
19
  "test:e2e:k3d": "k3d cluster delete pepr-dev && k3d cluster create pepr-dev --k3s-arg '--debug@server:0'",
32
20
  "test:e2e:build": "npm run build && npm uninstall pepr -g && npm install -g . && pepr",
@@ -37,45 +25,39 @@
37
25
  },
38
26
  "dependencies": {
39
27
  "@kubernetes/client-node": "0.18.1",
40
- "@rollup/plugin-json": "6.0.0",
41
- "@rollup/plugin-node-resolve": "15.0.2",
42
- "@rollup/plugin-typescript": "11.1.0",
43
- "@types/ramda": "0.29.1",
44
- "chokidar": "3.5.3",
45
- "commander": "10.0.1",
46
28
  "express": "4.18.2",
47
29
  "fast-json-patch": "3.1.1",
48
30
  "http-status-codes": "2.2.0",
49
31
  "node-fetch": "2.6.9",
50
- "node-forge": "1.3.1",
51
- "prettier": "2.8.8",
52
- "prompts": "2.4.2",
53
- "ramda": "0.29.0",
54
- "rollup": "3.21.4",
55
- "ts-node": "10.9.1",
56
- "tslib": "2.5.0",
57
- "typescript": "5.0.4",
58
- "uuid": "9.0.0"
32
+ "ramda": "0.29.0"
59
33
  },
60
34
  "devDependencies": {
61
35
  "@types/express": "4.17.17",
62
36
  "@types/node-fetch": "2.6.3",
63
37
  "@types/node-forge": "1.3.2",
64
38
  "@types/prompts": "2.4.4",
39
+ "@types/ramda": "0.29.1",
65
40
  "@types/uuid": "9.0.1",
66
41
  "@typescript-eslint/eslint-plugin": "5.59.2",
67
42
  "@typescript-eslint/parser": "5.59.2",
68
43
  "ava": "5.2.0",
69
- "eslint": "8.39.0",
70
- "nock": "13.3.1"
44
+ "eslint": "8.40.0",
45
+ "nock": "13.3.1",
46
+ "prettier": "2.8.8"
47
+ },
48
+ "peerDependencies": {
49
+ "@rollup/plugin-json": "6.0.0",
50
+ "@rollup/plugin-node-resolve": "15.0.2",
51
+ "@rollup/plugin-typescript": "11.1.0",
52
+ "chokidar": "3.5.3",
53
+ "commander": "10.0.1",
54
+ "node-forge": "1.3.1",
55
+ "prompts": "2.4.2",
56
+ "rollup": "3.21.5",
57
+ "typescript": "5.0.4",
58
+ "uuid": "9.0.0"
71
59
  },
72
60
  "ava": {
73
- "extensions": [
74
- "ts"
75
- ],
76
- "require": [
77
- "ts-node/register"
78
- ],
79
61
  "failFast": true,
80
62
  "verbose": true
81
63
  }
@@ -111,7 +111,9 @@ async function buildModule() {
111
111
  catch (e) {
112
112
  // On any other error, exit with a non-zero exit code
113
113
  logger_1.default.debug(e);
114
- logger_1.default.error(e.message);
114
+ if (e instanceof Error) {
115
+ logger_1.default.error(e.message);
116
+ }
115
117
  process.exit(1);
116
118
  }
117
119
  }
@@ -47,23 +47,38 @@ function default_1(program) {
47
47
  try {
48
48
  await webhook.deploy(code);
49
49
  logger_1.default.info(`Module deployed successfully`);
50
- const moduleFiles = (0, path_1.resolve)(".", "**", "*.ts");
51
- const watcher = (0, chokidar_1.watch)(moduleFiles);
52
- const peprTS = (0, path_1.resolve)(".", "pepr.ts");
53
- let program;
54
- // Run the module once to start the server
55
- runDev(peprTS);
50
+ const moduleFiles = [
51
+ (0, path_1.resolve)(".", "pepr.ts"),
52
+ (0, path_1.resolve)(".", "capabilities", "*.ts"),
53
+ (0, path_1.resolve)(".", "capabilities", "**", "*.ts"),
54
+ ];
55
+ const watcher = (0, chokidar_1.watch)(moduleFiles, {
56
+ awaitWriteFinish: {
57
+ stabilityThreshold: 3000,
58
+ pollInterval: 500,
59
+ },
60
+ });
56
61
  // Watch for changes
57
- watcher.on("ready", () => {
62
+ watcher.on("ready", async () => {
63
+ let building = false;
64
+ // Run the module once to start the server
65
+ let program = await runDev();
58
66
  logger_1.default.info(`Watching for changes in ${moduleFiles}`);
59
67
  watcher.on("all", async (event, path) => {
60
68
  logger_1.default.debug({ event, path }, "File changed");
61
- // Kill the running process
62
- if (program) {
63
- program.kill("SIGKILL");
69
+ // If we're already building, skip this event
70
+ if (building) {
71
+ return;
64
72
  }
65
- // Start the process again
66
- program = runDev(peprTS);
73
+ // Set building to true
74
+ building = true;
75
+ // Don't start a new process until the old one exits
76
+ program.once("exit", async () => {
77
+ program = await runDev();
78
+ building = false;
79
+ });
80
+ // Kill the running process
81
+ program.kill();
67
82
  });
68
83
  });
69
84
  }
@@ -74,9 +89,11 @@ function default_1(program) {
74
89
  });
75
90
  }
76
91
  exports.default = default_1;
77
- function runDev(path) {
92
+ async function runDev() {
78
93
  try {
79
- const program = (0, child_process_1.spawn)("./node_modules/.bin/ts-node", [path], {
94
+ const { path } = await (0, build_1.buildModule)();
95
+ logger_1.default.info(`Running module ${path}`);
96
+ const program = (0, child_process_1.fork)(path, {
80
97
  env: {
81
98
  ...process.env,
82
99
  LOG_LEVEL: "debug",
@@ -84,11 +101,6 @@ function runDev(path) {
84
101
  SSL_CERT_PATH: "insecure-tls.crt",
85
102
  },
86
103
  });
87
- program.stdout.on("data", data => console.log(data.toString()));
88
- program.stderr.on("data", data => console.error(data.toString()));
89
- program.on("close", code => {
90
- logger_1.default.info(`Process exited with code ${code}`);
91
- });
92
104
  return program;
93
105
  }
94
106
  catch (e) {
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  // SPDX-License-Identifier: Apache-2.0
3
4
  // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
@@ -70,7 +70,9 @@ function default_1(program) {
70
70
  }
71
71
  catch (e) {
72
72
  logger_1.default.debug(e);
73
- logger_1.default.error(e.message);
73
+ if (e instanceof Error) {
74
+ logger_1.default.error(e.message);
75
+ }
74
76
  process.exit(1);
75
77
  }
76
78
  }
@@ -22,7 +22,8 @@ function genPkgJSON(opts, pgkVerOverride) {
22
22
  // Generate a name for the module based on the module name
23
23
  const name = (0, utils_1.sanitizeName)(opts.name);
24
24
  // Make typescript a dev dependency
25
- const { typescript, "ts-node": tsNode } = package_json_1.dependencies;
25
+ const { typescript } = package_json_1.peerDependencies;
26
+ const { prettier } = package_json_1.devDependencies;
26
27
  const data = {
27
28
  name,
28
29
  version: "0.0.1",
@@ -47,8 +48,8 @@ function genPkgJSON(opts, pgkVerOverride) {
47
48
  pepr: pgkVerOverride || `${package_json_1.version}`,
48
49
  },
49
50
  devDependencies: {
51
+ prettier,
50
52
  typescript,
51
- "ts-node": tsNode,
52
53
  },
53
54
  };
54
55
  return {
@@ -31,7 +31,7 @@ async function createDir(dir) {
31
31
  }
32
32
  catch (err) {
33
33
  // The directory already exists
34
- if (err.code === "EEXIST") {
34
+ if (err && err.code === "EEXIST") {
35
35
  throw new Error(`Directory ${dir} already exists`);
36
36
  }
37
37
  else {