@abcnews/aunty 14.0.0 → 14.0.1
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.
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/cli/serve/constants.js +1 -1
- package/src/config/project.js +1 -1
- package/src/config/serve.js +13 -10
- package/src/config/webpack.js +15 -1
- package/src/generators/project/templates/react/src/index.tsx +1 -1
- package/src/utils/structures.js +17 -3
package/README.md
CHANGED
|
@@ -120,7 +120,7 @@ If you don't need to override any of the project defaults, your entire aunty con
|
|
|
120
120
|
| `hasBundleAnalysis` | `false` | Setting this to true will spin up a second server on another port, allowing you to inspect your bundle. The address will be logged to the console when the dev server starts. |
|
|
121
121
|
| `host` | `"localhost"` | The hostname of your dev server. If you're on the ABC internal network, the default will change to your machine's hostname (`ws<number>.aus.aunty.abc.net.au`). The `AUNTY_HOST` environment variable, if present, will override this setting. |
|
|
122
122
|
| `hot` | `true` | Should the dev server enable hot reloading. If `NODE_ENV !== "development"`, the default will change to `false`. |
|
|
123
|
-
| `https` | `true` | Should the dev server use SSL (with a self-signed certificate matching the `host`). You can alternatively supply your own `{cert: string, key: string` object if you've generated your certificate some other way. |
|
|
123
|
+
| `https` | `true` | Should the dev server use SSL (with a self-signed certificate matching the `host`). You can alternatively supply your own `{cert: string, key: string}` object if you've generated your certificate some other way. |
|
|
124
124
|
| `port` | `8000` | The port number of your dev server. If the port specified is unavailable, **aunty** will try incrementing the port number until it finds an available one. The `AUNTY_PORT` environment variable, if present, will override this setting. |
|
|
125
125
|
|
|
126
126
|
#### `deploy` config properties
|
|
@@ -156,7 +156,7 @@ Note: You may also need a `Promise` polyfill for IE11.
|
|
|
156
156
|
|
|
157
157
|
## Authors
|
|
158
158
|
|
|
159
|
-
- Colin Gourlay
|
|
159
|
+
- Colin Gourlay
|
|
160
160
|
- Simon Elvery ([elvery.simon@abc.net.au](mailto:elvery.simon@abc.net.au))
|
|
161
161
|
- Joshua Byrd ([byrd.joshua@abc.net.au](mailto:byrd.joshua@abc.net.au))
|
|
162
162
|
- Nathan Hoad
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ module.exports.BUNDLE_ANALYZER_CONFIG = {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
module.exports.MESSAGES = {
|
|
11
|
-
port: port => `Port ${port}
|
|
11
|
+
port: ({ port, errorType }) => `Port ${port} could not be used (${errorType}). Attempting to use port ${port + 1}`,
|
|
12
12
|
analysis: ({ analyzerHost, analyzerPort }) => `http://${analyzerHost}:${analyzerPort}`,
|
|
13
13
|
serve: ({ bundleAnalysisPath, hot, publicPath }) => `Serve (${hvy(process.env.NODE_ENV)}):${
|
|
14
14
|
bundleAnalysisPath
|
package/src/config/project.js
CHANGED
|
@@ -9,7 +9,7 @@ const mem = require('mem');
|
|
|
9
9
|
|
|
10
10
|
// Ours
|
|
11
11
|
const { hvy } = require('../utils/color');
|
|
12
|
-
const { pretty
|
|
12
|
+
const { pretty } = require('../utils/logging');
|
|
13
13
|
const { combine } = require('../utils/structures');
|
|
14
14
|
const { PROJECT_CONFIG_FILE_NAME } = require('../constants');
|
|
15
15
|
|
package/src/config/serve.js
CHANGED
|
@@ -12,7 +12,7 @@ const { combine } = require('../utils/structures');
|
|
|
12
12
|
const { getProjectConfig } = require('./project');
|
|
13
13
|
const { info } = require('../utils/logging');
|
|
14
14
|
const { MESSAGES } = require('../cli/serve/constants');
|
|
15
|
-
const {INTERNAL_TEST_HOST} = require('../constants')
|
|
15
|
+
const { INTERNAL_TEST_HOST } = require('../constants');
|
|
16
16
|
|
|
17
17
|
const HOME_DIR = homedir();
|
|
18
18
|
const SSL_DIR = '.aunty/ssl';
|
|
@@ -38,10 +38,10 @@ const addEnvironmentVariables = config => {
|
|
|
38
38
|
|
|
39
39
|
const getSSLPath = (module.exports.getSSLPath = (host, name) => join(HOME_DIR, SSL_DIR, host, name || '.'));
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
Set config.https to cert & key generated with `aunty sign-cert` (if they both exist)
|
|
43
|
-
We expect them to be in: ~/.aunty/ssl/<host>/server.{cert|key}
|
|
44
|
-
*/
|
|
41
|
+
/**
|
|
42
|
+
* Set config.https to cert & key generated with `aunty sign-cert` (if they both exist)
|
|
43
|
+
* We expect them to be in: ~/.aunty/ssl/<host>/server.{cert|key}
|
|
44
|
+
*/
|
|
45
45
|
const addUserSSLConfig = config => {
|
|
46
46
|
if (config.https === true) {
|
|
47
47
|
try {
|
|
@@ -55,13 +55,16 @@ const addUserSSLConfig = config => {
|
|
|
55
55
|
return config;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Find an open port, or keep incrementing until we get one
|
|
60
|
+
*/
|
|
58
61
|
const findPort = async (port, max = port + 100, host = '0.0.0.0') => {
|
|
59
62
|
return new Promise((resolve, reject) => {
|
|
60
63
|
const socket = new Socket();
|
|
61
64
|
|
|
62
|
-
const next =
|
|
65
|
+
const next = errorType => {
|
|
63
66
|
socket.destroy();
|
|
64
|
-
info(MESSAGES.port(port));
|
|
67
|
+
info(MESSAGES.port({ port, errorType }));
|
|
65
68
|
if (port <= max) resolve(findPort(port + 1, max, host));
|
|
66
69
|
else reject(new Error('Could not find an available port'));
|
|
67
70
|
};
|
|
@@ -72,7 +75,7 @@ const findPort = async (port, max = port + 100, host = '0.0.0.0') => {
|
|
|
72
75
|
};
|
|
73
76
|
|
|
74
77
|
// Port is taken if connection can be made
|
|
75
|
-
socket.once('connect', next);
|
|
78
|
+
socket.once('connect', () => next('in use'));
|
|
76
79
|
|
|
77
80
|
// Port is open if connection attempt times out
|
|
78
81
|
socket.setTimeout(500);
|
|
@@ -84,8 +87,8 @@ const findPort = async (port, max = port + 100, host = '0.0.0.0') => {
|
|
|
84
87
|
if (e.code === 'ECONNREFUSED') {
|
|
85
88
|
found();
|
|
86
89
|
} else {
|
|
87
|
-
// Not sure what to do with other errors
|
|
88
|
-
next();
|
|
90
|
+
// Not sure what to do with other errors. Log the code & keep seeking a free port.
|
|
91
|
+
next(`error code ${e.code}`);
|
|
89
92
|
}
|
|
90
93
|
});
|
|
91
94
|
|
package/src/config/webpack.js
CHANGED
|
@@ -18,6 +18,10 @@ const { getBuildConfig } = require('./build');
|
|
|
18
18
|
const { getProjectConfig } = require('./project');
|
|
19
19
|
|
|
20
20
|
const JSX_RESOLVE_EXTENSIONS = ['.jsx', '.tsx'];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Project types to override the Webpack config.
|
|
24
|
+
*/
|
|
21
25
|
const PROJECT_TYPES_CONFIG = {
|
|
22
26
|
preact: {
|
|
23
27
|
resolve: {
|
|
@@ -34,6 +38,11 @@ const PROJECT_TYPES_CONFIG = {
|
|
|
34
38
|
extensions: JSX_RESOLVE_EXTENSIONS
|
|
35
39
|
}
|
|
36
40
|
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Svelte uses a function to modify the existing config, rather than just merging in.
|
|
44
|
+
* @see combine
|
|
45
|
+
*/
|
|
37
46
|
svelte: config => {
|
|
38
47
|
config.resolve = {
|
|
39
48
|
// Make sure that only one copy of the Svelte runtime is bundled in the app
|
|
@@ -44,7 +53,8 @@ const PROJECT_TYPES_CONFIG = {
|
|
|
44
53
|
extensions: [...config.resolve.extensions, '.svelte'],
|
|
45
54
|
// When using Svelte components installed from npm, use the original component
|
|
46
55
|
// source code, rather than consuming the already-compiled version
|
|
47
|
-
mainFields: ['svelte', 'browser', 'module', 'main']
|
|
56
|
+
mainFields: ['svelte', 'browser', 'module', 'main'],
|
|
57
|
+
conditionNames: ['svelte', 'browser', 'import']
|
|
48
58
|
};
|
|
49
59
|
|
|
50
60
|
const { include, loader, options } = getHintedRule(config, 'scripts');
|
|
@@ -167,6 +177,10 @@ function createWebpackConfig({ isModernJS } = {}) {
|
|
|
167
177
|
module: {
|
|
168
178
|
rules: [
|
|
169
179
|
{
|
|
180
|
+
/**
|
|
181
|
+
* hints are used by PROJECT_TYPES_CONFIGs to quickly select the right config.
|
|
182
|
+
* @see PROJECT_TYPES_CONFIG
|
|
183
|
+
*/
|
|
170
184
|
__hint__: 'scripts',
|
|
171
185
|
test: hasTS ? /\.m?[jt]sx?$/ : /\.m?jsx?$/,
|
|
172
186
|
include: [resolve(root, from)].concat(resolveIncludedDependencies(includedDependencies, root)),
|
|
@@ -27,7 +27,7 @@ if (module.hot) {
|
|
|
27
27
|
module.hot.accept('./components/App', () => {
|
|
28
28
|
try {
|
|
29
29
|
renderApp();
|
|
30
|
-
} catch (err
|
|
30
|
+
} catch (err<% if (isTS) { %>: any<% } %>) {
|
|
31
31
|
import('./components/ErrorBox').then(({ default: ErrorBox }) => {
|
|
32
32
|
root.render(<ErrorBox error={err} />);
|
|
33
33
|
});
|
package/src/utils/structures.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
const deepmerge = require('deepmerge');
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Merge a function or object into the target object
|
|
5
|
+
* @param target an object to merge into
|
|
6
|
+
* @param source an object to merge with `target`, or a function that takes `target` as an argument
|
|
7
|
+
* @param isDeep use deepmerge to merge
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
3
10
|
const combine = (target, source, isDeep) =>
|
|
4
11
|
typeof source === 'function'
|
|
5
12
|
? source(target)
|
|
@@ -11,11 +18,18 @@ const combine = (target, source, isDeep) =>
|
|
|
11
18
|
|
|
12
19
|
const combineDeep = (memo, source) => combine(memo, source, true);
|
|
13
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Shallow merge an array of objects. Earlier values overwritten by later values
|
|
23
|
+
* @param sources Array of objects and functions to be merged using `combine`
|
|
24
|
+
* @see combine
|
|
25
|
+
*/
|
|
14
26
|
module.exports.combine = (...sources) => sources.reduce(combine, {});
|
|
15
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Deep merge an array of objects. Earlier values overwritten by later values.
|
|
30
|
+
* @param sources Array of objects and functions to be merged using `combine`
|
|
31
|
+
* @see combine
|
|
32
|
+
*/
|
|
16
33
|
module.exports.merge = (...sources) => sources.reduce(combineDeep, {});
|
|
17
34
|
|
|
18
|
-
module.exports.setOfKeysAndValues = source =>
|
|
19
|
-
new Set([].concat(Object.keys(source).map(key => source[key])).concat(Object.keys(source)));
|
|
20
|
-
|
|
21
35
|
module.exports.setOfValues = source => new Set(Object.keys(source).map(key => source[key]));
|