@polylith/builder 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/App.js +72 -27
  2. package/package.json +1 -1
package/App.js CHANGED
@@ -156,18 +156,28 @@ export default class App {
156
156
  * If no manual chunk specifiers are added, then this will be used as the
157
157
  * default.
158
158
  *
159
- * @param {String} id the filename being processed.
159
+ * @param {String} id this is the filename of the current file being
160
+ * processed by rollup
160
161
  *
161
162
  * @returns {String} the chunk name if there is a match
162
163
  */
163
- defaultManualChunkCallback(id) {
164
+ defaultManualChunks(id) {
164
165
  if (id.includes('node_modules')) {
165
166
  return 'vendor';
166
167
  }
167
168
  }
168
169
 
169
- manualChunksArray(id) {
170
- var fixId = this.fixPath(id);
170
+ /**
171
+ * This is called when manual chunk specifications have been added as an
172
+ * array.
173
+ *
174
+ * @param {String} id this is the filename of the current file being
175
+ * processed by rollup
176
+ * @returns {String} the name fo the chunk if there is a matching chunk
177
+ * name specifier
178
+ */
179
+ handleManualChunksArray(id) {
180
+ var fixId = App.fixPath(id);
171
181
  var result = this.manualChunks.find(function(spec) {
172
182
  return fixId.includes(spec.includes);
173
183
  })
@@ -175,22 +185,38 @@ export default class App {
175
185
  if (result) return result.name;
176
186
  }
177
187
 
178
- manualChunksCallback(id) {
179
- var fixId = this.fixPath(fixId);
188
+ /**
189
+ * This is called when the manual chunk specifiers are functions. Each
190
+ * registered function is called in the reverse order to how they were
191
+ * added.
192
+ *
193
+ * @param {String} id this is the filename of the current file being
194
+ * processed by rollup
195
+ * @returns the chunk name if any of the callbacks return one
196
+ */
197
+ handleManualChunksCallbacks(id) {
198
+ var fixId = App.fixPath(id);
180
199
  if (this.manualChunks.length === 0) {
181
200
  return this.defaultManualChunks(fixId);
182
201
  } else {
183
202
  for (let idx = 0; idx < this.manualChunks.length; idx++) {
184
- var result = this.manualChunks[id](fixId);
203
+ var result = this.manualChunks[idx](fixId);
185
204
  if (result) return result;
186
205
  }
187
206
  }
188
207
  }
189
208
 
209
+ /**
210
+ * This is called by the builder to get the method to handle manual chunks
211
+ * based on how they have been setup. The value returned from this funtion
212
+ * will be the value set in the rollup options object.
213
+ *
214
+ * @returns {Object|Function} the value to assign to the manualChunk field.
215
+ */
190
216
  getManualChunks() {
191
- if (this.manualChunksType === 'object') return this.manualChunks;
192
- if (this.manualChunksType === 'array') return this.manualChunksArray.bind(this);
193
- if (this.manualChunksType === 'function') return this.manualChunksCallback.bind(this);
217
+ if (this.manualChunkType === 'object') return this.manualChunks;
218
+ if (this.manualChunkType === 'array') return this.handleManualChunksArray.bind(this);
219
+ if (this.manualChunkType === 'function') return this.handleManualChunksCallbacks.bind(this);
194
220
  }
195
221
 
196
222
  /**
@@ -245,18 +271,18 @@ export default class App {
245
271
  }
246
272
  }
247
273
 
248
- /* features will call this method if they want to add loadables
249
-
250
- name - name of the loadable that we be passed to the load method
251
- main - the relative path from the source folder to the entry point of the
252
- loadable.
253
- prefix - if given, the prefix on services created in this loadable.
254
- The start and ready methods will be called on these services
255
- */
274
+ /**
275
+ *
276
+ * @param {String} name unique name of the loadable that will be passed to
277
+ * the load method
278
+ * @param {String} main the relative path from the source folder to the entry
279
+ * point of the loadable.
280
+ * @param {String} [prefix] if given, the prefix on services created in
281
+ * this loadable. When the loadable has been loaded, the start and ready
282
+ * methods will be called on all services starting with this prefix.
283
+ */
256
284
  addLoadable(name, main, prefix) {
257
285
  var dest = path.posix.join(this.sourcePath, main);
258
-
259
- console.log('addLoadable', {name, path: dest, prefix})
260
286
  this.loadables.push({name, path: dest, prefix});
261
287
  }
262
288
 
@@ -326,10 +352,13 @@ export default class App {
326
352
  return '[name].js';
327
353
  }.bind(this),
328
354
  manualChunks: manualChunks,
329
- treeshake: {
330
- moduleSideEffects: true
331
- }
332
355
  },
356
+ },
357
+ watch : {
358
+ watch: {
359
+ buildDelay: 250,
360
+ exclude: 'node_modules/**',
361
+ }
333
362
  }
334
363
  };
335
364
 
@@ -338,11 +367,27 @@ export default class App {
338
367
 
339
368
  async build() {
340
369
  await this.buildFeatures();
341
- var config = this.buildConfiguration();
370
+ this.config = this.buildConfiguration();
342
371
 
343
- const bundle = await rollup.rollup(config.input);
344
- await bundle.generate(config.output);
345
- await bundle.write(config.output);
372
+ const bundle = await rollup.rollup(this.config.input);
373
+ await bundle.generate(this.config.output);
374
+ await bundle.write(this.config.output);
346
375
  await bundle.close();
347
376
  }
377
+
378
+ watch() {
379
+ var watchConfig = {
380
+ input: this.config.input,
381
+ output: this.config.output,
382
+ watch: this.config.watch,
383
+ }
384
+
385
+ const watcher = rollup.watch(watchConfig);
386
+
387
+ watcher.on('event', function({result}) {
388
+ if (result) {
389
+ result.close();
390
+ }
391
+ }.bind(this));
392
+ }
348
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polylith/builder",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "The polylith builder",
5
5
  "main": "index.js",
6
6
  "type": "module",