@abcnews/aunty 13.2.2 → 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 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 ([gourlay.colin@abc.net.au](mailto:gourlay.colin@abc.net.au))
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abcnews/aunty",
3
- "version": "13.2.2",
3
+ "version": "14.0.1",
4
4
  "description": "A toolkit for working with ABC News projects",
5
5
  "repository": "abcnews/aunty",
6
6
  "license": "MIT",
@@ -70,8 +70,6 @@
70
70
  "node-fetch": "^2.6.0",
71
71
  "ora": "^5.0.0",
72
72
  "pify": "^5.0.0",
73
- "postcss": "^8.3.6",
74
- "postcss-loader": "^6.1.1",
75
73
  "prettier": "^2.0.5",
76
74
  "requireg": "^0.2.2",
77
75
  "rsyncwrapper": "^3.0.1",
@@ -92,9 +90,6 @@
92
90
  "yeoman-environment": "^3.2.0",
93
91
  "yeoman-generator": "^5.2.0"
94
92
  },
95
- "optionalDependencies": {
96
- "@abcaustralia/postcss-config": "^11.2.5"
97
- },
98
93
  "devDependencies": {
99
94
  "babel-eslint": "^10.1.0",
100
95
  "eslint": "^7.7.0",
@@ -8,7 +8,7 @@ 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
+ 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
@@ -9,7 +9,7 @@ const mem = require('mem');
9
9
 
10
10
  // Ours
11
11
  const { hvy } = require('../utils/color');
12
- const { pretty, warn } = require('../utils/logging');
12
+ const { pretty } = require('../utils/logging');
13
13
  const { combine } = require('../utils/structures');
14
14
  const { PROJECT_CONFIG_FILE_NAME } = require('../constants');
15
15
 
@@ -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, so keep seeking a free port.
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
 
@@ -4,7 +4,6 @@ const { join, resolve } = require('path');
4
4
 
5
5
  // External
6
6
  const importLazy = require('import-lazy')(require);
7
- const getContext = importLazy('@abcaustralia/postcss-config/getContext'); // optional dependency
8
7
  const CopyPlugin = importLazy('copy-webpack-plugin');
9
8
  const Dotenv = importLazy('dotenv-webpack');
10
9
  const ForkTsCheckerWebpackPlugin = importLazy('fork-ts-checker-webpack-plugin');
@@ -19,6 +18,10 @@ const { getBuildConfig } = require('./build');
19
18
  const { getProjectConfig } = require('./project');
20
19
 
21
20
  const JSX_RESOLVE_EXTENSIONS = ['.jsx', '.tsx'];
21
+
22
+ /**
23
+ * Project types to override the Webpack config.
24
+ */
22
25
  const PROJECT_TYPES_CONFIG = {
23
26
  preact: {
24
27
  resolve: {
@@ -35,6 +38,11 @@ const PROJECT_TYPES_CONFIG = {
35
38
  extensions: JSX_RESOLVE_EXTENSIONS
36
39
  }
37
40
  },
41
+
42
+ /**
43
+ * Svelte uses a function to modify the existing config, rather than just merging in.
44
+ * @see combine
45
+ */
38
46
  svelte: config => {
39
47
  config.resolve = {
40
48
  // Make sure that only one copy of the Svelte runtime is bundled in the app
@@ -45,7 +53,8 @@ const PROJECT_TYPES_CONFIG = {
45
53
  extensions: [...config.resolve.extensions, '.svelte'],
46
54
  // When using Svelte components installed from npm, use the original component
47
55
  // source code, rather than consuming the already-compiled version
48
- mainFields: ['svelte', 'browser', 'module', 'main']
56
+ mainFields: ['svelte', 'browser', 'module', 'main'],
57
+ conditionNames: ['svelte', 'browser', 'import']
49
58
  };
50
59
 
51
60
  const { include, loader, options } = getHintedRule(config, 'scripts');
@@ -168,6 +177,10 @@ function createWebpackConfig({ isModernJS } = {}) {
168
177
  module: {
169
178
  rules: [
170
179
  {
180
+ /**
181
+ * hints are used by PROJECT_TYPES_CONFIGs to quickly select the right config.
182
+ * @see PROJECT_TYPES_CONFIG
183
+ */
171
184
  __hint__: 'scripts',
172
185
  test: hasTS ? /\.m?[jt]sx?$/ : /\.m?jsx?$/,
173
186
  include: [resolve(root, from)].concat(resolveIncludedDependencies(includedDependencies, root)),
@@ -265,7 +278,6 @@ function createWebpackConfig({ isModernJS } = {}) {
265
278
  moduleIds: isProd ? 'deterministic' : 'named'
266
279
  }
267
280
  },
268
- conditionallyEnableABCAustraliaStyles,
269
281
  PROJECT_TYPES_CONFIG[type],
270
282
  projectWebpackConfig
271
283
  );
@@ -287,74 +299,3 @@ function createWebpackConfig({ isModernJS } = {}) {
287
299
  function getHintedRule(config, hint) {
288
300
  return config.module.rules.find(rule => rule.__hint__ === hint);
289
301
  }
290
-
291
- const ABC_POSTCSS_CONTEXT_SUGGESTION = `
292
-
293
- To compile @abcaustralia/* styles, you need to add the following to your package.json:
294
-
295
- "abc": {
296
- "css": {
297
- "libraryDir": "./node_modules/@abcaustralia/nucleus/css",
298
- "logVariables": "false"
299
- }
300
- }
301
- `;
302
-
303
- function getABCAustraliaPostCSSContext(isDev) {
304
- try {
305
- return getContext(isDev);
306
- } catch (err) {
307
- if (err.message.indexOf('css') > -1) {
308
- err.message += ABC_POSTCSS_CONTEXT_SUGGESTION;
309
- }
310
-
311
- throw err;
312
- }
313
- }
314
-
315
- const ABC_PACKAGE_PATTERN = /(node_modules\/@abcaustralia\/*)/;
316
-
317
- function conditionallyEnableABCAustraliaStyles(config) {
318
- const { pkg } = getProjectConfig();
319
-
320
- // Only enable if we have an @abcaustralia/* dependency
321
- if (!Object.keys(pkg.dependencies || {}).find(x => x.indexOf('@abcaustralia/') === 0)) {
322
- return config;
323
- }
324
-
325
- const isProd = config.mode === 'production';
326
- const stylesRule = getHintedRule(config, 'styles');
327
-
328
- stylesRule.exclude = ABC_PACKAGE_PATTERN;
329
-
330
- config.module.rules.push({
331
- __hint__: 'styles/@abcaustralia',
332
- test: /\.css$/,
333
- include: ABC_PACKAGE_PATTERN,
334
- use: [
335
- stylesRule.use[0],
336
- {
337
- loader: require.resolve('css-loader'),
338
- options: {
339
- importLoaders: 1,
340
- modules: {
341
- exportLocalsConvention: 'camelCase',
342
- localIdentName: `${isProd ? '' : '[name]__[local]--'}[contenthash:base64:5]`
343
- },
344
- url: false
345
- }
346
- },
347
- {
348
- loader: require.resolve('postcss-loader'),
349
- options: {
350
- postcssOptions: {
351
- config: require.resolve('@abcaustralia/postcss-config'),
352
- ...getABCAustraliaPostCSSContext(!isProd)
353
- }
354
- }
355
- }
356
- ]
357
- });
358
-
359
- return config;
360
- }
@@ -17,7 +17,8 @@ module.exports.getWebpackDevServerConfig = async () => {
17
17
  allowedHosts: 'all',
18
18
  client: {
19
19
  logging: 'warn',
20
- overlay: true
20
+ overlay: true,
21
+ webSocketURL: `ws${https ? 's' : ''}://${host}:${port}/ws`
21
22
  },
22
23
  devMiddleware: {
23
24
  publicPath: `http${https ? 's' : ''}://${host}:${port}/`
@@ -14,11 +14,5 @@
14
14
  "start": "aunty serve",
15
15
  "dev": "aunty serve",
16
16
  "test": "aunty test"
17
- }<% if (projectType === "react") { %>,
18
- "abc": {
19
- "css": {
20
- "libraryDir": "./node_modules/@abcaustralia/nucleus/css",
21
- "logVariables": "false"
22
- }
23
- }<% } %>
17
+ }
24
18
  }
@@ -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
  });
@@ -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]));