MCPcopy Create free account
hub / github.com/developit/microbundle / doWatch

Function doWatch

src/index.js:147–192  ·  view source on GitHub ↗
(options, cwd, steps)

Source from the content-addressed store, hash-verified

145}
146
147function doWatch(options, cwd, steps) {
148 const { onStart, onBuild, onError } = options;
149
150 return new Promise((resolve, reject) => {
151 const targetDir = relative(cwd, dirname(options.output));
152 stdout(blue(`Watching source, compiling to ${targetDir}:`));
153
154 const watchers = steps.reduce((acc, options) => {
155 acc[options.inputOptions.input] = watch(
156 Object.assign(
157 {
158 output: options.outputOptions,
159 watch: WATCH_OPTS,
160 },
161 options.inputOptions,
162 ),
163 ).on('event', e => {
164 if (e.code === 'START') {
165 if (typeof onStart === 'function') {
166 onStart(e);
167 }
168 }
169 if (e.code === 'ERROR') {
170 logError(e.error);
171 if (typeof onError === 'function') {
172 onError(e);
173 }
174 }
175 if (e.code === 'END') {
176 if (options._sizeInfo) {
177 options._sizeInfo.then(text => {
178 stdout(`Wrote ${text.trim()}`);
179 });
180 }
181 if (typeof onBuild === 'function') {
182 onBuild(e);
183 }
184 }
185 });
186
187 return acc;
188 }, {});
189
190 resolve({ watchers });
191 });
192}
193
194async function jsOrTs(cwd, filename) {
195 const extension = (await isFile(resolve(cwd, filename + '.ts')))

Callers 1

microbundleFunction · 0.85

Calls 1

logErrorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…