MCPcopy
hub / github.com/FredKSchott/snowpack / run

Function run

plugins/plugin-typescript/plugin.js:7–37  ·  view source on GitHub ↗
({isDev, log})

Source from the content-addressed store, hash-verified

5 return {
6 name: '@snowpack/plugin-typescript',
7 async run({isDev, log}) {
8 const workerPromise = execa.command(
9 `${tsc ? tsc : 'tsc'} ${args ? args : ''} --noEmit ${isDev ? '--watch' : ''}`,
10 {
11 env: npmRunPath.env(),
12 extendEnv: true,
13 windowsHide: false,
14 cwd: snowpackConfig.root || process.cwd(),
15 },
16 );
17 const {stdout, stderr} = workerPromise;
18 function dataListener(chunk) {
19 let stdOutput = chunk.toString();
20 // In --watch mode, handle the "clear" character
21 if (stdOutput.includes('\u001bc') || stdOutput.includes('\x1Bc')) {
22 log('WORKER_RESET', {});
23 stdOutput = stdOutput.replace(/\x1Bc/, '').replace(/\u001bc/, '');
24 }
25 log('WORKER_MSG', {msg: stdOutput});
26 }
27 stdout && stdout.on('data', dataListener);
28 stderr && stderr.on('data', dataListener);
29 return workerPromise.catch((err) => {
30 if (/ENOENT/.test(err.message)) {
31 log('WORKER_MSG', {
32 msg: 'WARN: "tsc" run failed. Is typescript installed in your project?',
33 });
34 }
35 throw err;
36 });
37 },
38 };
39}
40

Callers 1

index.bin.jsFile · 0.50

Calls 2

onMethod · 0.80
logFunction · 0.50

Tested by

no test coverage detected