@henderea/static-site-builder 1.9.6 → 1.10.0

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.
@@ -14,9 +14,9 @@
14
14
  // This is quite hacky and hopefully won't be needed when Webpack fixes this.
15
15
  // https://github.com/webpack/webpack/issues/2878
16
16
 
17
- var chalk = require('chalk');
17
+ import chalk from 'chalk';
18
18
  var friendlySyntaxErrorLabel = 'Syntax error:';
19
- var _ = require('lodash');
19
+ import _ from 'lodash';
20
20
 
21
21
  function isLikelyASyntaxError(message) {
22
22
  return message.indexOf(friendlySyntaxErrorLabel) !== -1;
@@ -28,7 +28,7 @@ function formatMessage(message, isError) {
28
28
  if(_.isPlainObject(message)) { message = message.message || ''; }
29
29
  var lines = message.split('\n');
30
30
 
31
- if (lines.length > 2 && lines[1] === '') {
31
+ if(lines.length > 2 && lines[1] === '') {
32
32
  // Remove extra newline.
33
33
  lines.splice(1, 1);
34
34
  }
@@ -38,22 +38,22 @@ function formatMessage(message, isError) {
38
38
  // ./~/css-loader!./~/postcss-loader!./src/App.css
39
39
  // After:
40
40
  // ./src/App.css
41
- if (lines[0].lastIndexOf('!') !== -1) {
41
+ if(lines[0].lastIndexOf('!') !== -1) {
42
42
  lines[0] = lines[0].substr(lines[0].lastIndexOf('!') + 1);
43
43
  }
44
44
 
45
45
  // Remove unnecessary stack added by `thread-loader`
46
46
  var threadLoaderIndex = -1;
47
47
  lines.forEach(function(line, index) {
48
- if (threadLoaderIndex !== -1) {
48
+ if(threadLoaderIndex !== -1) {
49
49
  return;
50
50
  }
51
- if (line.indexOf('from thread-loader (worker') !== -1) {
51
+ if(line.indexOf('from thread-loader (worker') !== -1) {
52
52
  threadLoaderIndex = index;
53
53
  }
54
54
  });
55
55
 
56
- if (threadLoaderIndex !== -1) {
56
+ if(threadLoaderIndex !== -1) {
57
57
  lines = lines.slice(0, threadLoaderIndex);
58
58
  }
59
59
 
@@ -68,12 +68,12 @@ function formatMessage(message, isError) {
68
68
 
69
69
  // line #0 is filename
70
70
  // line #1 is the main error message
71
- if (!lines[0] || !lines[1]) {
71
+ if(!lines[0] || !lines[1]) {
72
72
  return lines.join('\n');
73
73
  }
74
74
 
75
75
  // Cleans up verbose "module not found" messages for files and packages.
76
- if (lines[1].indexOf('Module not found: ') === 0) {
76
+ if(lines[1].indexOf('Module not found: ') === 0) {
77
77
  lines = [
78
78
  lines[0],
79
79
  // Clean up message because "Module not found: " is descriptive enough.
@@ -86,7 +86,7 @@ function formatMessage(message, isError) {
86
86
  }
87
87
 
88
88
  // Cleans up syntax error messages.
89
- if (lines[1].indexOf('Module build failed: ') === 0) {
89
+ if(lines[1].indexOf('Module build failed: ') === 0) {
90
90
  lines[1] = lines[1].replace(
91
91
  'Module build failed: SyntaxError:',
92
92
  friendlySyntaxErrorLabel
@@ -96,7 +96,7 @@ function formatMessage(message, isError) {
96
96
  // Clean up export errors.
97
97
  // TODO: we should really send a PR to Webpack for this.
98
98
  var exportError = /\s*(.+?)\s*(")?export '(.+?)' was not found in '(.+?)'/;
99
- if (lines[1].match(exportError)) {
99
+ if(lines[1].match(exportError)) {
100
100
  lines[1] = lines[1].replace(
101
101
  exportError,
102
102
  "$1 '$4' does not contain an export named '$3'."
@@ -119,7 +119,7 @@ function formatMessage(message, isError) {
119
119
  return message.trim();
120
120
  }
121
121
 
122
- function formatWebpackMessages(json) {
122
+ export default function formatWebpackMessages(json) {
123
123
  var formattedErrors = json.errors.map(function(message) {
124
124
  return formatMessage(message, true);
125
125
  });
@@ -130,7 +130,7 @@ function formatWebpackMessages(json) {
130
130
  errors: formattedErrors,
131
131
  warnings: formattedWarnings,
132
132
  };
133
- if (result.errors.some(isLikelyASyntaxError)) {
133
+ if(result.errors.some(isLikelyASyntaxError)) {
134
134
  // If there are any syntax errors, show just them.
135
135
  // This prevents a confusing ESLint parsing error
136
136
  // preceding a much more useful Babel syntax error.
@@ -138,5 +138,3 @@ function formatWebpackMessages(json) {
138
138
  }
139
139
  return result;
140
140
  }
141
-
142
- module.exports = formatWebpackMessages;
@@ -7,21 +7,21 @@
7
7
 
8
8
  'use strict';
9
9
 
10
- const chalk = require('chalk');
10
+ import chalk from 'chalk';
11
11
 
12
- module.exports = function printBuildError(err) {
12
+ export default function printBuildError(err) {
13
13
  const message = err != null && err.message;
14
14
  const stack = err != null && err.stack;
15
15
 
16
16
  // Add more helpful message for UglifyJs error
17
- if (
17
+ if(
18
18
  stack &&
19
19
  typeof message === 'string' &&
20
20
  message.indexOf('from UglifyJs') !== -1
21
21
  ) {
22
22
  try {
23
23
  const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack);
24
- if (!matched) {
24
+ if(!matched) {
25
25
  throw new Error('Using errors for control flow is bad.');
26
26
  }
27
27
  const problemPath = matched[2];
@@ -42,4 +42,4 @@ module.exports = function printBuildError(err) {
42
42
  console.log((message || err) + '\n');
43
43
  }
44
44
  console.log();
45
- };
45
+ }
@@ -5,14 +5,16 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- 'use strict';
9
- const fs = require('fs');
10
- const path = require('path');
11
- const findPkg = require('find-pkg');
12
- const globby = require('globby');
8
+ import fs from 'fs';
9
+ import path from 'path';
10
+ import findPkg from 'find-pkg';
11
+ import { globbySync } from 'globby';
12
+ import { createRequire } from 'module';
13
+
14
+ const require = createRequire(import.meta.url);
13
15
 
14
16
  const findPkgs = (rootPath, globPatterns) => {
15
- if (!globPatterns) {
17
+ if(!globPatterns) {
16
18
  return [];
17
19
  }
18
20
  const globOpts = {
@@ -23,23 +25,23 @@ const findPkgs = (rootPath, globPatterns) => {
23
25
  return globPatterns
24
26
  .reduce(
25
27
  (pkgs, pattern) =>
26
- pkgs.concat(globby.sync(path.join(pattern, 'package.json'), globOpts)),
28
+ pkgs.concat(globbySync(path.join(pattern, 'package.json'), globOpts)),
27
29
  []
28
30
  )
29
- .map(f => path.dirname(path.normalize(f)));
31
+ .map((f) => path.dirname(path.normalize(f)));
30
32
  };
31
33
 
32
- const findMonorepo = appDir => {
34
+ const findMonorepo = (appDir) => {
33
35
  const monoPkgPath = findPkg.sync(path.resolve(appDir, '..'));
34
36
  const monoPkg = monoPkgPath && require(monoPkgPath);
35
37
  const workspaces = monoPkg && monoPkg.workspaces;
36
38
  const patterns = (workspaces && workspaces.packages) || workspaces;
37
39
  const isYarnWs = Boolean(patterns);
38
40
  const allPkgs = patterns && findPkgs(path.dirname(monoPkgPath), patterns);
39
- const isIncluded = dir => allPkgs && allPkgs.indexOf(dir) !== -1;
41
+ const isIncluded = (dir) => allPkgs && allPkgs.indexOf(dir) !== -1;
40
42
  const isAppIncluded = isIncluded(appDir);
41
43
  const pkgs = allPkgs
42
- ? allPkgs.filter(f => fs.realpathSync(f) !== appDir)
44
+ ? allPkgs.filter((f) => fs.realpathSync(f) !== appDir)
43
45
  : [];
44
46
 
45
47
  return {
@@ -49,6 +51,6 @@ const findMonorepo = appDir => {
49
51
  };
50
52
  };
51
53
 
52
- module.exports = {
53
- findMonorepo,
54
- };
54
+ export {
55
+ findMonorepo
56
+ };