@datacamp/learn-vm-scripts 1.8.4 → 1.8.5

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 (2) hide show
  1. package/dist/index.cjs +36 -6
  2. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -367074,9 +367074,10 @@ var handleInput = async ({ line, page }) => {
367074
367074
  default:
367075
367075
  return unreachable(input);
367076
367076
  }
367077
- log("Script ran successfully");
367077
+ return true;
367078
367078
  } catch (error) {
367079
367079
  console.error(`Error: "${error.message}" on input ${line}`);
367080
+ return false;
367080
367081
  }
367081
367082
  };
367082
367083
  var createFileIfNotExists = async (filePath) => {
@@ -367095,6 +367096,9 @@ var startInputWatcher = async ({
367095
367096
  }) => {
367096
367097
  const outputFileHandle = await fs.open(outputFilePath, "a");
367097
367098
  let lastInput = void 0;
367099
+ let lastInputSucceeded = void 0;
367100
+ let processingPromise = void 0;
367101
+ let numberOfRuns = 0;
367098
367102
  await createFileIfNotExists(inputFilePath);
367099
367103
  let page = await setupPuppeteerPage({
367100
367104
  executablePath,
@@ -367108,8 +367112,9 @@ var startInputWatcher = async ({
367108
367112
  log("No input");
367109
367113
  return;
367110
367114
  }
367111
- if (lastInput != null && newInput === lastInput) {
367115
+ if (lastInput != null && newInput === lastInput && lastInputSucceeded === true) {
367112
367116
  log("Input already processed");
367117
+ log("Script ran successfully");
367113
367118
  await outputFileHandle.appendFile(`Done: ${newInput}`);
367114
367119
  return;
367115
367120
  }
@@ -367122,19 +367127,44 @@ var startInputWatcher = async ({
367122
367127
  });
367123
367128
  }
367124
367129
  log("New input, processing");
367125
- await handleInput({ line: newInput, page });
367130
+ const success = await handleInput({ line: newInput, page });
367131
+ lastInput = newInput;
367132
+ if (success) {
367133
+ log("Script ran successfully");
367134
+ lastInputSucceeded = true;
367135
+ } else {
367136
+ log("Script ran unsuccessfully");
367137
+ lastInputSucceeded = false;
367138
+ }
367126
367139
  await outputFileHandle.appendFile(`Done: ${newInput}`);
367127
367140
  log("Done processing input");
367128
- lastInput = newInput;
367129
367141
  };
367130
- await checkInputFile();
367142
+ const run = async () => {
367143
+ numberOfRuns++;
367144
+ const runId = numberOfRuns;
367145
+ if (processingPromise != null) {
367146
+ log(`WARNING: Parallel execution detected!`);
367147
+ await processingPromise;
367148
+ if (runId !== numberOfRuns) {
367149
+ log(`WARNING: Run ${runId} was cancelled`);
367150
+ return;
367151
+ }
367152
+ }
367153
+ try {
367154
+ processingPromise = checkInputFile();
367155
+ await processingPromise;
367156
+ } finally {
367157
+ processingPromise = void 0;
367158
+ }
367159
+ };
367160
+ await run();
367131
367161
  log("Waiting for input");
367132
367162
  for await (const event of fs.watch(inputFilePath)) {
367133
367163
  if (event.eventType !== "change") {
367134
367164
  continue;
367135
367165
  }
367136
367166
  log("Input file changed");
367137
- await checkInputFile();
367167
+ await run();
367138
367168
  }
367139
367169
  };
367140
367170
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datacamp/learn-vm-scripts",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "repository": "git@github.com:datacamp-engineering/learn-vm-scripts.git",
5
5
  "description": "Scripts used by VMs in learn.",
6
6
  "main": "./dist/index.cjs",