Skip to content

Commit bab646f

Browse files
committed
Build on top of @snowpack/plugin-run-script
1 parent 103d3d4 commit bab646f

File tree

2 files changed

+11
-43
lines changed

2 files changed

+11
-43
lines changed

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jihchi/plugin-rescript",
3-
"version": "0.0.0",
3+
"version": "1.0.0",
44
"main": "plugin.js",
55
"license": "MIT",
66
"homepage": "https://github.com/jihchi/plugin-rescript/#readme",
@@ -15,8 +15,9 @@
1515
"plugin.js"
1616
],
1717
"dependencies": {
18-
"execa": "^5.0.0",
19-
"npm-run-path": "^4.0.1",
18+
"@snowpack/plugin-run-script": "^2.3.0"
19+
},
20+
"peerDependencies": {
2021
"rescript": "^9.1.1"
2122
}
2223
}

plugin.js

+7-40
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,10 @@
1-
const execa = require('execa');
2-
const npmRunPath = require('npm-run-path');
1+
const runScript = require('@snowpack/plugin-run-script');
32

4-
module.exports = function plugin(snowpackConfig, _options) {
5-
return {
3+
module.exports = function plugin(snowpackConfig, { output }) {
4+
return runScript(snowpackConfig, {
65
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+
});
4310
};

0 commit comments

Comments
 (0)