Skip to content
This repository was archived by the owner on Jul 9, 2021. It is now read-only.

Commit 7c8ae19

Browse files
committed
[changed] created a new module util; made the webpack module private
1 parent e0e7a60 commit 7c8ae19

7 files changed

Lines changed: 90 additions & 72 deletions

File tree

src/Compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import mkdirp from 'mkdirp';
55
import {dirname} from 'path';
66
import {writeFile, readFile} from 'fs';
77
import {gzip, gunzip} from 'zlib';
8-
import {isProduction} from './webpack';
8+
import {isProduction} from './util';
99
import {logError, logSequentialSuccessMessage} from './logger';
1010

1111
/**

src/JSCompiler.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {readdir, stat, createReadStream, createWriteStream} from 'fs';
66
import {transformFile} from 'babel-core';
77
import forEach from 'lodash/forEach';
88
import noop from 'lodash/noop';
9-
import {getCompiler, babelBEOptions} from './webpack';
9+
import {getCompiler} from './webpack';
10+
import {babelBEOptions} from './util';
1011
import {logError, log, consoleStyles} from './logger';
1112

1213
/* eslint-disable no-sync */

src/highlight.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import noop from 'lodash/noop';
55
import constant from 'lodash/constant';
66
import {load} from 'cheerio';
77
import {transformElements, arrayToJSX} from './jsx';
8+
import {isNode} from './util';
89

910
/**
1011
* CodeMirror syntax highlighting that works in the browser and on Node.js
1112
*
1213
* @module highlight
1314
*/
1415

15-
// when not in the browser, polyfill specific DOM requirements of CodeMirror
16-
if ('undefined' === typeof navigator) {
16+
// on Node.js, polyfill specific DOM requirements of CodeMirror
17+
if (isNode) {
1718
global.window = jsdom().defaultView;
1819
global.navigator = window.navigator;
1920
window.document.createRange = constant({

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ export {Documentation} from './Documentation';
66
export {watch} from './watch';
77
export {yaml} from './yaml';
88
export {findBinary} from './findBinary';
9-
export {babelBEOptions, babelFEOptions} from './webpack';
109
export {consoleStyles, log, logError, logPostCSSWarnings, logSASSError, logLintingErrors,
1110
logSequentialSuccessMessage} from './logger';
11+
export {isNode, isProduction, babelBEOptions, babelFEOptions} from './util';
1212

1313
export {flatten, arrayToJSX, htmlToArray, htmlToJSX} from './jsx';
1414
export {markdownToArray, markdownToJSX, markdownToHTML} from './markdown';

src/logger.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import map from 'lodash/map';
66
import transform from 'lodash/transform';
77
import ErrorStackParser from 'error-stack-parser';
88
import cleanStack from 'clean-stack';
9+
import {isNode} from './util';
910

1011
/* eslint-disable no-console */
1112

@@ -51,16 +52,6 @@ let i = 0;
5152
*/
5253
export class Message {
5354

54-
/**
55-
* true on Node.js
56-
*
57-
* @member {boolean} isNode
58-
* @memberof module:logger.Message
59-
* @private
60-
* @static
61-
*/
62-
static isNode: boolean = 'undefined' !== typeof process && 'node' === process.release.name;
63-
6455
/**
6556
* a style config
6657
*
@@ -151,7 +142,7 @@ export class Message {
151142
* @param {string | number | module:logger.Message} msg - a message
152143
*/
153144
addMessage(msg: string | number | Message) {
154-
if (Message.isNode) {
145+
if (isNode) {
155146
this.addBEMessage(msg);
156147
} else if (msg instanceof Message) {
157148
this.addFEMessageInstance(msg);

src/util.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* @flow */
2+
3+
/* eslint-disable no-process-env */
4+
5+
/**
6+
* Generic utilities and configuration objects.
7+
*
8+
* @module util
9+
*/
10+
11+
/**
12+
* `true` on Node.js
13+
*
14+
* @memberof module:util
15+
* @constant {boolean} isNode
16+
* @example
17+
* import {isNode} from 'webcompiler';
18+
* // or - import {isNode} from 'webcompiler/lib/util';
19+
* // or - var isNode = require('webcompiler').isNode;
20+
* // or - var isNode = require('webcompiler/lib/util').isNode;
21+
*/
22+
export const isNode = 'undefined' !== typeof process && 'node' === process.release.name;
23+
24+
/**
25+
* `true` if the `NODE_ENV` environment variable is set to `"production"`
26+
*
27+
* @memberof module:util
28+
* @constant {boolean} isProduction
29+
* @example
30+
* import {isProduction} from 'webcompiler';
31+
* // or - import {isProduction} from 'webcompiler/lib/util';
32+
* // or - var isProduction = require('webcompiler').isProduction;
33+
* // or - var isProduction = require('webcompiler/lib/util').isProduction;
34+
*/
35+
export const isProduction = 'production' === process.env.NODE_ENV;
36+
37+
/**
38+
* Babel configuration for the Node.js.
39+
*
40+
* @memberof module:util
41+
* @member {Object} babelBEOptions
42+
* @example
43+
* import {babelBEOptions} from 'webcompiler';
44+
* // or - import {babelBEOptions} from 'webcompiler/lib/util';
45+
* // or - var babelBEOptions = require('webcompiler').babelBEOptions;
46+
* // or - var babelBEOptions = require('webcompiler/lib/util').babelBEOptions;
47+
*/
48+
export const babelBEOptions = {
49+
babelrc: false,
50+
presets: ['es2016', 'es2017', 'stage-2', 'react'],
51+
plugins: [
52+
['transform-es2015-modules-commonjs', {loose: true}]
53+
]
54+
};
55+
56+
/**
57+
* Babel configuration for the browser.
58+
*
59+
* @memberof module:util
60+
* @member {Object} babelFEOptions
61+
* @example
62+
* import {babelFEOptions} from 'webcompiler';
63+
* // or - import {babelFEOptions} from 'webcompiler/lib/util';
64+
* // or - var babelFEOptions = require('webcompiler').babelFEOptions;
65+
* // or - var babelFEOptions = require('webcompiler/lib/util').babelFEOptions;
66+
*/
67+
export const babelFEOptions = {
68+
cacheDirectory: true,
69+
babelrc: false,
70+
presets: [
71+
['es2015', {
72+
// temporarily disabled until `webpack` 2.3 and `webpack-hot-loader` 3.0 are available
73+
// modules: false,
74+
loose: true
75+
}],
76+
'es2016', 'es2017', 'stage-2', 'react'
77+
],
78+
plugins: ['transform-runtime']
79+
};

src/webpack.js

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {dirname, basename} from 'path';
55
import WebpackDevServer from 'webpack-dev-server';
66
import MemoryFS from 'memory-fs';
77
import serveStatic from 'serve-static';
8+
import {isProduction, babelFEOptions} from './util';
89

910
/* eslint-disable no-process-env */
1011

@@ -26,64 +27,9 @@ const cache = {},
2627
* You can use it to tweak the Babel options.
2728
*
2829
* @module webpack
30+
* @private
2931
*/
3032

31-
/**
32-
* `true` if the `NODE_ENV` environment variable is set to `'production'`
33-
*
34-
* @memberof module:webpack
35-
* @constant {boolean} isProduction
36-
*/
37-
export const isProduction = 'production' === process.env.NODE_ENV;
38-
39-
/**
40-
* Babel configuration for the Node.js.
41-
*
42-
* @memberof module:webpack
43-
* @member {Object} babelBEOptions
44-
* @example
45-
* import {babelBEOptions} from 'webcompiler';
46-
* // or - import {babelBEOptions} from 'webcompiler/lib/webpack';
47-
* // or - var babelBEOptions = require('webcompiler').babelBEOptions;
48-
* // or - var babelBEOptions = require('webcompiler/lib/webpack').babelBEOptions;
49-
*
50-
* babelFEOptions.presets.push('my-custom-preset');
51-
*/
52-
export const babelBEOptions = {
53-
babelrc: false,
54-
presets: ['es2016', 'es2017', 'stage-2', 'react'],
55-
plugins: [
56-
['transform-es2015-modules-commonjs', {loose: true}]
57-
]
58-
};
59-
60-
/**
61-
* Babel configuration for the browser.
62-
*
63-
* @memberof module:webpack
64-
* @member {Object} babelFEOptions
65-
* @example
66-
* import {babelFEOptions} from 'webcompiler';
67-
* // or - import {babelFEOptions} from 'webcompiler/lib/webpack';
68-
* // or - var babelFEOptions = require('webcompiler').babelFEOptions;
69-
* // or - var babelFEOptions = require('webcompiler/lib/webpack').babelFEOptions;
70-
*
71-
* babelFEOptions.presets.push('my-custom-preset');
72-
*/
73-
export const babelFEOptions = {
74-
cacheDirectory: true,
75-
babelrc: false,
76-
presets: [
77-
['es2015', {
78-
// temporarily disabled until `webpack` 2.3 and `webpack-hot-loader` 3.0 are available
79-
// modules: false,
80-
loose: true
81-
}],
82-
'es2016', 'es2017', 'stage-2', 'react'
83-
],
84-
plugins: ['transform-runtime']
85-
};
86-
8733
/**
8834
* Returns a webpack configuration object.
8935
*

0 commit comments

Comments
 (0)