Skip to content

Commit

Permalink
A bit more tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
m-allanson committed Jul 2, 2020
1 parent 2ad2b5e commit 642bd32
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions scripts/bundle-esm.js
@@ -1,27 +1,26 @@
'use strict';

/* eslint-disable no-console */
/* eslint-disable guard-for-in */
/* eslint-disable node/no-extraneous-require */
/* eslint-disable node/no-extraneous-require -- these are all installed as part of `parcel` */

const bundleReport = require('@parcel/reporter-cli/lib/bundleReport').default;
const defaultConfigContents = require('@parcel/config-default');
const defaultConfigFilePath = require.resolve('@parcel/config-default');
const Parcel = require('@parcel/core').default;
const { createWorkerFarm } = require('@parcel/core');

/* eslint-enable node/no-extraneous-require */

// TODO: maybe it's worth verifying that all syntaxes are bundled?
// Though this is unlikely to change very often.

const config = {
browser: {
target: { distDir: 'dist' },
entry: 'lib/browser.js',
// dest: 'dist/stylelint-esm.js',
},
'syntax-css-in-js': {
target: { distDir: 'dist' },
entry: 'lib/syntaxes/syntax-css-in-js.js',
// dest: 'dist/syntax-css-in-js.js',
},
'syntax-html': {
target: { distDir: 'dist' },
Expand All @@ -30,44 +29,40 @@ const config = {
'syntax-less': {
target: { distDir: 'dist' },
entry: 'lib/syntaxes/syntax-less.js',
// dest: 'dist/syntax-less.js',
},
'syntax-markdown': {
target: { distDir: 'dist' },
entry: 'lib/syntaxes/syntax-markdown.js',
// dest: 'dist/syntax-markdown.js',
},
'syntax-sass': {
target: { distDir: 'dist' },
entry: 'lib/syntaxes/syntax-sass.js',
// dest: 'dist/syntax-sass.js',
},
'syntax-scss': {
target: { distDir: 'dist' },
entry: 'lib/syntaxes/syntax-scss.js',
// dest: 'dist/syntax-scss.js',
},
'syntax-sugarss': {
target: { distDir: 'dist' },
entry: 'lib/syntaxes/syntax-sugarss.js',
// dest: 'dist/syntax-sugarss.js',
},
};

let tasks = [];

// Workers have a startup cost. We can keep the workers around between runs,
// then shut them down when all bundles have been created.
let workerFarm = createWorkerFarm();

let tasks = [];

// eslint-disable-next-line guard-for-in -- meh
for (const module in config) {
let task = async () => {
let bundler = new Parcel({
entries: config[module].entry,
targets: { [module]: config[module].target },
defaultConfig: {
...defaultConfigContents,
filePath: require.resolve('@parcel/config-default'),
filePath: defaultConfigFilePath,
},
defaultEngines: {
browsers: ['> 0.25%'],
Expand All @@ -85,7 +80,7 @@ for (const module in config) {
const bundleGraph = await bundler.run();
const options = bundler._getResolvedParcelOptions(); // hackety hack. Not a public API

// log stats. This is similar to setting `logLevel: verbose`, but skips the progress spinner
// log stats to console. This is similar to setting `logLevel: verbose`, but skips the progress spinner to avoid unnecessary output
await bundleReport(bundleGraph, options.outputFS, options.projectRoot, options.detailedReport);

return bundleGraph;
Expand All @@ -100,23 +95,8 @@ for (const module in config) {
await task();
}
} catch (error) {
console.error(error);
console.error(error); // eslint-disable-line no-console
} finally {
await workerFarm.end(); // finished bundling, so we can shut the farm.
}
})();

/* eslint-enable no-console */
/* eslint-enable guard-for-in */
/* eslint-enable node/no-extraneous-require */

// tasks = [
// async () => {
// await new Promise((resolve) => setTimeout(resolve, 1000));
// console.log(`waited: 1000ms`);
// },
// async () => {
// await new Promise((resolve) => setTimeout(resolve, 500));
// console.log(`waited: 500ms`);
// },
// ];

0 comments on commit 642bd32

Please sign in to comment.