|
1 | | -const execa = require('execa'); |
2 | | -const npmRunPath = require('npm-run-path'); |
| 1 | +const runScript = require('@snowpack/plugin-run-script'); |
3 | 2 |
|
4 | | -module.exports = function plugin(snowpackConfig, _options) { |
5 | | - return { |
| 3 | +module.exports = function plugin(snowpackConfig, { output }) { |
| 4 | + return runScript(snowpackConfig, { |
6 | 5 | name: '@jihchi/plugin-rescript', |
7 | | - async run({ isDev, log }) { |
8 | | - const cmd = execa.command( |
9 | | - `rescript build -with-deps ${isDev ? '-w' : ''}`, |
10 | | - { |
11 | | - env: npmRunPath.env(), |
12 | | - extendEnv: true, |
13 | | - windowsHide: false, |
14 | | - cwd: snowpackConfig.root || process.cwd(), |
15 | | - } |
16 | | - ); |
17 | | - const { stdout, stderr } = cmd; |
18 | | - |
19 | | - const onData = (chunk) => { |
20 | | - let stdOut = chunk.toString(); |
21 | | - // In --watch mode, handle the "clear" character |
22 | | - if (stdOut.includes('\u001bc') || stdOut.includes('\x1Bc')) { |
23 | | - log('WORKER_RESET', {}); |
24 | | - stdOut = stdOut.replace(/\x1Bc/, '').replace(/\u001bc/, ''); |
25 | | - } |
26 | | - log('WORKER_MSG', { msg: stdOut }); |
27 | | - }; |
28 | | - |
29 | | - stdout && stdout.on('data', onData); |
30 | | - stderr && stderr.on('data', onData); |
31 | | - |
32 | | - return cmd.catch((err) => { |
33 | | - if (/ENOENT/.test(err.message)) { |
34 | | - log('WORKER_MSG', { |
35 | | - msg: |
36 | | - 'WARN: "rescript" run failed. Is package `rescript` installed in your project?', |
37 | | - }); |
38 | | - } |
39 | | - throw err; |
40 | | - }); |
41 | | - }, |
42 | | - }; |
| 6 | + cmd: 'rescript build -with-deps', |
| 7 | + watch: '$1 -w', |
| 8 | + output, |
| 9 | + }); |
43 | 10 | }; |
0 commit comments