How to use the @tslab/typescript-for-tslab.FileWatcherEventKind function in @tslab/typescript-for-tslab

To help you get started, we’ve selected a few @tslab/typescript-for-tslab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yunabe / tslab / src / converter.spec.ts View on Github external
await runInTmpAsync("pkg", async dir => {
      const srcPath = pathlib.resolve(pathlib.join(dir, "a.ts"));
      fs.writeFileSync(srcPath, 'export const aVal: string = "ABC";');
      let output = conv.convert("", `import {aVal} from "./${dir}/a";`);
      expect(output.diagnostics).toEqual([]);
      expect(output.sideOutputs).toEqual([
        {
          path: pathlib.join(process.cwd(), `${dir}/a.js`),
          data: buildOutput(['exports.aVal = "ABC";'])
        }
      ]);

      fs.writeFileSync(srcPath, 'export const aVal: string = "XYZ";');
      await waitFileEvent(srcPath, ts.FileWatcherEventKind.Changed);
      // yield to TyeScript compiler just for safety.
      await sleep(0);
      output = conv.convert("", `import {aVal} from "./${dir}/a";`);
      expect(output.diagnostics).toEqual([]);
      expect(output.sideOutputs).toEqual([
        {
          path: pathlib.join(process.cwd(), `${dir}/a.js`),
          data: buildOutput(['exports.aVal = "XYZ";'])
        }
      ]);
    });
  });
github yunabe / tslab / src / converter.ts View on Github external
function updateContent(decls: string, src: string) {
    declContent = decls;
    srcContent = src;
    builder = null;
    // TODO: Notify updates only when src is really updated,
    // unless there is another cache layer in watcher API.
    notifyUpdateSrc(srcFilename, ts.FileWatcherEventKind.Changed);
    notifyUpdateDecls(declFilename, ts.FileWatcherEventKind.Changed);
    if (!rebuildTimer) {
      throw new Error("rebuildTimer is not set properly");
    }
    rebuildTimer.callback();
    rebuildTimer = null;
    if (!builder) {
      throw new Error("builder is not recreated");
    }
  }
github yunabe / tslab / src / executor.spec.ts View on Github external
await runInTmpAsync("pkg", async dir => {
      const srcPath = pathlib.resolve(pathlib.join(dir, "a.ts"));
      fs.writeFileSync(srcPath, 'export const aVal = "ABC";');
      let promise = ex.execute(`import {aVal} from "./${dir}/a";`);
      expect(await promise).toBe(true);
      expect(consoleLogCalls).toEqual([]);
      expect(consoleErrorCalls).toEqual([]);
      expect(ex.locals.aVal).toEqual("ABC");

      fs.writeFileSync(srcPath, 'export const aVal = "XYZ";');
      await waitFileEvent(srcPath, ts.FileWatcherEventKind.Changed);
      // yield to TyeScript compiler just for safety.
      await sleep(0);
      promise = ex.execute(`import {aVal} from "./${dir}/a";`);
      expect(await promise).toBe(true);
      expect(consoleLogCalls).toEqual([]);
      expect(consoleErrorCalls).toEqual([]);
      expect(ex.locals.aVal).toEqual("XYZ");
    });
  });