@selfchecks/selfchecks 0.1.49 → 0.1.51

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.
@@ -72,10 +72,15 @@ async function run(options) {
72
72
  const projectName = readRequiredString(config.projectName, "projectName");
73
73
  const logicalId = readRequiredString(config.logicalId, "logicalId");
74
74
  const collector = [];
75
+ const constructFilePaths = new Map();
75
76
  globalThis[constructCollectorSymbol] = collector;
76
77
  try {
77
78
  for (const filePath of await findCheckFiles(options.rootDir)) {
79
+ const collectorStartIndex = collector.length;
78
80
  await import(pathToFileURL(filePath).href);
81
+ for (const construct of collector.slice(collectorStartIndex)) {
82
+ constructFilePaths.set(construct, filePath);
83
+ }
79
84
  }
80
85
  }
81
86
  finally {
@@ -99,7 +104,13 @@ async function run(options) {
99
104
  assertSupportedConfigDefaults(config);
100
105
  const checks = collector
101
106
  .filter((item) => item.kind === "ApiCheck" || item.kind === "BrowserCheck")
102
- .map((item) => compileCheck(item, config, groups, channels));
107
+ .map((item) => {
108
+ const checkFilePath = constructFilePaths.get(item);
109
+ if (!checkFilePath) {
110
+ throw new Error(`Unable to resolve the source file for ${item.logicalId}.`);
111
+ }
112
+ return compileCheck(item, config, groups, channels, options.rootDir, checkFilePath);
113
+ });
103
114
  if (checks.length === 0) {
104
115
  throw new Error(`No Selfchecks definitions were found in ${options.rootDir}.`);
105
116
  }
@@ -133,7 +144,7 @@ async function findCheckFiles(rootDir) {
133
144
  await visit(rootDir);
134
145
  return files.sort();
135
146
  }
136
- function compileCheck(construct, config, groups, channels) {
147
+ function compileCheck(construct, config, groups, channels, rootDir, checkFilePath) {
137
148
  const type = construct.kind === "ApiCheck" ? "api" : "browser";
138
149
  const ownProps = asRecord(construct.props);
139
150
  const groupLogicalId = getLogicalId(ownProps.group);
@@ -200,10 +211,20 @@ function compileCheck(construct, config, groups, channels) {
200
211
  if (typeof entrypoint !== "string" || !entrypoint.trim()) {
201
212
  throw new Error(`BrowserCheck ${construct.logicalId} requires code.entrypoint.`);
202
213
  }
203
- base.entrypoint = entrypoint;
214
+ base.entrypoint = normalizeEntrypoint(rootDir, checkFilePath, entrypoint);
204
215
  }
205
216
  return base;
206
217
  }
218
+ function normalizeEntrypoint(rootDir, checkFilePath, entrypoint) {
219
+ if (!entrypoint.startsWith(".")) {
220
+ return entrypoint;
221
+ }
222
+ const absoluteEntrypoint = path.resolve(path.dirname(checkFilePath), entrypoint);
223
+ return path
224
+ .relative(rootDir, absoluteEntrypoint)
225
+ .split(path.sep)
226
+ .join(path.posix.sep);
227
+ }
207
228
  function pickGroupCheckDefaults(props) {
208
229
  return Object.fromEntries(["activated", "frequency", "muted", "retryStrategy", "shouldFail", "tags"].flatMap((key) => (key in props ? [[key, props[key]]] : [])));
209
230
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@selfchecks/selfchecks",
3
- "version": "0.1.49",
3
+ "version": "0.1.51",
4
4
  "description": "Checkly-compatible constructs supported by Selfchecks",
5
5
  "license": "Elastic-2.0",
6
6
  "type": "module",