@abcnews/aunty 12.1.1 → 12.2.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.
- package/package.json +1 -1
- package/src/cli/release/constants.js +1 -1
- package/src/cli/release/index.js +6 -1
- package/src/cli/serve/constants.js +1 -0
- package/src/cli/serve/index.js +2 -2
- package/src/config/deploy.js +3 -1
- package/src/config/serve.js +55 -6
- package/src/config/webpackDevServer.js +2 -2
- package/src/generators/project/templates/basic/src/index.ts +1 -1
- package/src/generators/project/templates/react/src/index.tsx +7 -7
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const { cmd, hvy, ok, opt, sec } = require('../../utils/color');
|
|
3
3
|
|
|
4
4
|
const FORCE_REMINDER = `Use the ${opt('--force')} option to ignore warnings or release without tagging.`;
|
|
5
|
-
const VALID_BUMPS = (module.exports.VALID_BUMPS = new Set(['major', 'minor', 'patch']));
|
|
5
|
+
const VALID_BUMPS = (module.exports.VALID_BUMPS = new Set(['major', 'minor', 'patch','prerelease']));
|
|
6
6
|
|
|
7
7
|
const OPTIONS = (module.exports.OPTIONS = {
|
|
8
8
|
string: ['bump', 'git-remote'],
|
package/src/cli/release/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Native
|
|
2
|
+
const { existsSync } = require('fs');
|
|
2
3
|
const { join } = require('path');
|
|
3
4
|
|
|
4
5
|
// External
|
|
@@ -154,4 +155,8 @@ module.exports = command(
|
|
|
154
155
|
}
|
|
155
156
|
);
|
|
156
157
|
|
|
157
|
-
const updateJsonFile = (path, source) =>
|
|
158
|
+
const updateJsonFile = (path, source) => {
|
|
159
|
+
if (existsSync(path)) {
|
|
160
|
+
writeJsonFile.sync(path, combine(loadJsonFile.sync(path), source));
|
|
161
|
+
}
|
|
162
|
+
};
|
|
@@ -8,6 +8,7 @@ const BUNDLE_ANALYZER_CONFIG = (module.exports.BUNDLE_ANALYZER_CONFIG = {
|
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
module.exports.MESSAGES = {
|
|
11
|
+
port: port => `Port ${port} already in use attempting to use port ${port + 1}`,
|
|
11
12
|
analysis: ({ analyzerHost, analyzerPort }) => `http://${analyzerHost}:${analyzerPort}`,
|
|
12
13
|
serve: ({ bundleAnalysisPath, hot, publicPath }) => `Serve (${hvy(process.env.NODE_ENV)}):${
|
|
13
14
|
bundleAnalysisPath
|
package/src/cli/serve/index.js
CHANGED
|
@@ -23,9 +23,9 @@ module.exports = command(
|
|
|
23
23
|
usage: MESSAGES.usage
|
|
24
24
|
},
|
|
25
25
|
async argv => {
|
|
26
|
-
const { hasBundleAnalysis, port } = getServeConfig();
|
|
26
|
+
const { hasBundleAnalysis, port } = await getServeConfig();
|
|
27
27
|
const webpackConfig = getWebpackConfig();
|
|
28
|
-
const webpackDevServerConfig = getWebpackDevServerConfig();
|
|
28
|
+
const webpackDevServerConfig = await getWebpackDevServerConfig();
|
|
29
29
|
const { hot, devMiddleware } = webpackDevServerConfig;
|
|
30
30
|
const { publicPath } = devMiddleware;
|
|
31
31
|
const bundleAnalyzerConfig = hasBundleAnalysis
|
package/src/config/deploy.js
CHANGED
|
@@ -95,9 +95,11 @@ const addKnownProfileProperties = config => {
|
|
|
95
95
|
function resolveProperties(config) {
|
|
96
96
|
const { pkg, root } = getProjectConfig();
|
|
97
97
|
const { name } = pkg;
|
|
98
|
+
// Package name may be in `@scope/name` format
|
|
99
|
+
const unscopedName = name.split('/').reverse()[0];
|
|
98
100
|
|
|
99
101
|
config.from = join(root, config.from);
|
|
100
|
-
config.to = config.to.replace('<name>',
|
|
102
|
+
config.to = config.to.replace('<name>', unscopedName).replace('<id>', config.id);
|
|
101
103
|
config.publicPath = typeof config.resolvePublicPath === 'function' ? config.resolvePublicPath(config) : '/';
|
|
102
104
|
|
|
103
105
|
return config;
|
package/src/config/serve.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { homedir, hostname } = require('os');
|
|
3
3
|
const { readFileSync } = require('fs');
|
|
4
4
|
const { join } = require('path');
|
|
5
|
+
const { Socket } = require('net');
|
|
5
6
|
|
|
6
7
|
// External
|
|
7
8
|
const { probe } = require('tcp-ping-sync');
|
|
@@ -9,6 +10,8 @@ const { probe } = require('tcp-ping-sync');
|
|
|
9
10
|
// Ours
|
|
10
11
|
const { combine } = require('../utils/structures');
|
|
11
12
|
const { getProjectConfig } = require('./project');
|
|
13
|
+
const { info } = require('../utils/logging');
|
|
14
|
+
const { MESSAGES } = require('../cli/serve/constants');
|
|
12
15
|
|
|
13
16
|
const HOME_DIR = homedir();
|
|
14
17
|
const SSL_DIR = '.aunty/ssl';
|
|
@@ -20,10 +23,14 @@ const DEFAULT_HOST = (module.exports.DEFAULT_HOST = probe(`nucwed${INTERNAL_SUFF
|
|
|
20
23
|
: 'localhost');
|
|
21
24
|
const DEFAULT_PORT = 8000;
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
const serveConfigPromise = getServeConfigPromise();
|
|
27
|
+
|
|
28
|
+
module.exports.getServeConfig = () => serveConfigPromise;
|
|
29
|
+
|
|
30
|
+
async function getServeConfigPromise() {
|
|
24
31
|
const { serve } = getProjectConfig();
|
|
25
32
|
|
|
26
|
-
|
|
33
|
+
const config = combine(
|
|
27
34
|
{
|
|
28
35
|
hasBundleAnalysis: false,
|
|
29
36
|
host: DEFAULT_HOST,
|
|
@@ -35,9 +42,13 @@ module.exports.getServeConfig = () => {
|
|
|
35
42
|
addEnvironmentVariables,
|
|
36
43
|
addUserSSLConfig
|
|
37
44
|
);
|
|
38
|
-
|
|
45
|
+
const port = await findPort(config.port, config.port + 100, config.host);
|
|
46
|
+
config.port = port;
|
|
39
47
|
|
|
40
|
-
|
|
48
|
+
return config;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function addEnvironmentVariables(config) {
|
|
41
52
|
if (process.env.AUNTY_HOST) {
|
|
42
53
|
config.host = process.env.AUNTY_HOST;
|
|
43
54
|
}
|
|
@@ -47,12 +58,12 @@ const addEnvironmentVariables = config => {
|
|
|
47
58
|
}
|
|
48
59
|
|
|
49
60
|
return config;
|
|
50
|
-
}
|
|
61
|
+
}
|
|
51
62
|
|
|
52
63
|
const getSSLPath = (module.exports.getSSLPath = (host, name) => join(HOME_DIR, SSL_DIR, host, name || '.'));
|
|
53
64
|
|
|
54
65
|
/*
|
|
55
|
-
Set config.https to cert & key generated with `aunty sign-cert` (if they both exist)
|
|
66
|
+
Set config.https to cert & key generated with `aunty sign-cert` (if they both exist)
|
|
56
67
|
We expect them to be in: ~/.aunty/ssl/<host>/server.{cert|key}
|
|
57
68
|
*/
|
|
58
69
|
function addUserSSLConfig(config) {
|
|
@@ -67,3 +78,41 @@ function addUserSSLConfig(config) {
|
|
|
67
78
|
|
|
68
79
|
return config;
|
|
69
80
|
}
|
|
81
|
+
|
|
82
|
+
async function findPort(port, max = port + 100, host = '0.0.0.0') {
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
const socket = new Socket();
|
|
85
|
+
|
|
86
|
+
const next = () => {
|
|
87
|
+
socket.destroy();
|
|
88
|
+
info(MESSAGES.port(port));
|
|
89
|
+
if (port <= max) resolve(findPort(port + 1, max, host));
|
|
90
|
+
else reject(new Error('Could not find an available port'));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const found = () => {
|
|
94
|
+
socket.destroy();
|
|
95
|
+
resolve(port);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// Port is taken if connection can be made
|
|
99
|
+
socket.once('connect', next);
|
|
100
|
+
|
|
101
|
+
// Port is open if connection attempt times out
|
|
102
|
+
socket.setTimeout(500);
|
|
103
|
+
socket.once('timeout', found);
|
|
104
|
+
|
|
105
|
+
// If an error occurs, it's assumed the port is available.
|
|
106
|
+
socket.once('error', e => {
|
|
107
|
+
// If the connection is refused, it's assumed nothing is listening and the port is available.
|
|
108
|
+
if (e.code === 'ECONNREFUSED') {
|
|
109
|
+
found();
|
|
110
|
+
} else {
|
|
111
|
+
// Not sure what to do with other errors, so keep seeking a free port.
|
|
112
|
+
next();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
socket.connect(port, host);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
@@ -7,10 +7,10 @@ const { getBuildConfig } = require('./build');
|
|
|
7
7
|
const { getProjectConfig } = require('./project');
|
|
8
8
|
const { getServeConfig } = require('./serve');
|
|
9
9
|
|
|
10
|
-
module.exports.getWebpackDevServerConfig = () => {
|
|
10
|
+
module.exports.getWebpackDevServerConfig = async () => {
|
|
11
11
|
const { root, webpackDevServer: projectWebpackDevServerConfig } = getProjectConfig();
|
|
12
12
|
const { staticDir } = getBuildConfig();
|
|
13
|
-
const { host, hot, https, port } = getServeConfig();
|
|
13
|
+
const { host, hot, https, port } = await getServeConfig();
|
|
14
14
|
|
|
15
15
|
return combine(
|
|
16
16
|
{
|
|
@@ -27,7 +27,7 @@ if (module.hot) {
|
|
|
27
27
|
renderApp();
|
|
28
28
|
} catch (err) {
|
|
29
29
|
import('./components/ErrorBox').then(({ default: ErrorBox }) => {
|
|
30
|
-
render(new ErrorBox({ error: err }).el, appMountEl);
|
|
30
|
+
render(new ErrorBox({ error: err<% if (isTS) { %> as Error<% } %> }).el, appMountEl);
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
});
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import acto from '@abcnews/alternating-case-to-object';
|
|
2
2
|
import { <% if (isOdyssey) { %>whenOdysseyLoaded<% } else { %>whenDOMReady<% } %> } from '@abcnews/env-utils';
|
|
3
|
-
import { getMountValue, selectMounts } from '@abcnews/mount-utils'
|
|
4
|
-
import type { Mount } from '@abcnews/mount-utils';<% } %>
|
|
3
|
+
import { getMountValue, selectMounts } from '@abcnews/mount-utils';
|
|
5
4
|
import React from 'react';
|
|
6
|
-
import {
|
|
5
|
+
import { createRoot<% if (isTS) { %>, Root<% } %> } from 'react-dom/client';
|
|
7
6
|
import App from './components/App';<% if (isTS) { %>
|
|
8
7
|
import type { AppProps } from './components/App';<% } %>
|
|
9
8
|
|
|
10
|
-
let
|
|
9
|
+
let root<% if (isTS) { %>: Root<% } %>;
|
|
11
10
|
let appProps<% if (isTS) { %>: AppProps<% } %>;
|
|
12
11
|
|
|
13
12
|
function renderApp() {
|
|
14
|
-
render(<App {...appProps}
|
|
13
|
+
root.render(<App {...appProps} />);
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
<% if (isOdyssey) { %>whenOdysseyLoaded<% } else { %>whenDOMReady<% } %>.then(() => {
|
|
18
|
-
[appMountEl] = selectMounts('<%= projectNameFlat %>');
|
|
17
|
+
const [appMountEl] = selectMounts('<%= projectNameFlat %>');
|
|
19
18
|
|
|
20
19
|
if (appMountEl) {
|
|
20
|
+
root = createRoot(appMountEl);
|
|
21
21
|
appProps = acto(getMountValue(appMountEl))<% if (isTS) { %> as AppProps<% } %>;
|
|
22
22
|
renderApp();
|
|
23
23
|
}
|
|
@@ -29,7 +29,7 @@ if (module.hot) {
|
|
|
29
29
|
renderApp();
|
|
30
30
|
} catch (err) {
|
|
31
31
|
import('./components/ErrorBox').then(({ default: ErrorBox }) => {
|
|
32
|
-
render(<ErrorBox error={err}
|
|
32
|
+
root.render(<ErrorBox error={err} />);
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
});
|