Skip to content

Commit

Permalink
explicitly search for node_modules, remove obsolete docs
Browse files Browse the repository at this point in the history
  • Loading branch information
salvatore-fxpig committed May 26, 2020
1 parent 2f30aa8 commit 6f716c5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
2 changes: 0 additions & 2 deletions docs-src/docs/customise-client/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ A useful reference may be the [customisation JSON file](https://github.com/nexts
* `googleAnalyticsKey` You can specify a Google Analytics key to enable (some) analytics functionality. More documentation to come.
* `serverAddress` Specify the address / prefix which the auspice client uses for API requests.

> For customisation code which uses [React](https://reactjs.org/) components, you must import these as `import React from "@libraries/react";` to ensure that the version of react is the same as what Auspice uses.
---

## Sidebar Theme
Expand Down
3 changes: 0 additions & 3 deletions docs/customise-client/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ <h2><a class="anchor" aria-hidden="true" id="available-customisations"></a><a hr
<li><code>googleAnalyticsKey</code> You can specify a Google Analytics key to enable (some) analytics functionality. More documentation to come.</li>
<li><code>serverAddress</code> Specify the address / prefix which the auspice client uses for API requests.</li>
</ul>
<blockquote>
<p>For customisation code which uses <a href="https://reactjs.org/">React</a> components, you must import these as <code>import React from &quot;@libraries/react&quot;;</code> to ensure that the version of react is the same as what Auspice uses.</p>
</blockquote>
<hr>
<h2><a class="anchor" aria-hidden="true" id="sidebar-theme"></a><a href="#sidebar-theme" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Sidebar Theme</h2>
<p>The appearence of the sidebar can be customised by specifing a theme in the config JSON used to build Auspice.
Expand Down
3 changes: 0 additions & 3 deletions docs/customise-client/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ <h2><a class="anchor" aria-hidden="true" id="available-customisations"></a><a hr
<li><code>googleAnalyticsKey</code> You can specify a Google Analytics key to enable (some) analytics functionality. More documentation to come.</li>
<li><code>serverAddress</code> Specify the address / prefix which the auspice client uses for API requests.</li>
</ul>
<blockquote>
<p>For customisation code which uses <a href="https://reactjs.org/">React</a> components, you must import these as <code>import React from &quot;@libraries/react&quot;;</code> to ensure that the version of react is the same as what Auspice uses.</p>
</blockquote>
<hr>
<h2><a class="anchor" aria-hidden="true" id="sidebar-theme"></a><a href="#sidebar-theme" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Sidebar Theme</h2>
<p>The appearence of the sidebar can be customised by specifing a theme in the config JSON used to build Auspice.
Expand Down
64 changes: 43 additions & 21 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,47 @@ const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');

/* Webpack config generator */

const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyzeBundle=false}) => {
const generateConfig = ({ extensionPath, devMode = false, customOutputPath, analyzeBundle = false }) => {
utils.verbose(`Generating webpack config. Extensions? ${!!extensionPath}. devMode: ${devMode}`);

/* which directories should be parsed by babel and other loaders? */
const directoriesToTransform = [path.join(__dirname, 'src')];

// Pins all react stuff, and uses hot loader's dom (can be used safely in production)
// Format is either "libName" or "libName:libPath"
const coreDeps = [
"react",
"react-hot-loader",
"react-dom:@hot-loader/react-dom",
"regenerator-runtime",
"core-js",
"styled-components"
];

// Actively searches for the "good" root starting from auspice dir and going backwards
// In 99.9% of practical cases these should all resolve wrt the node_modules in the root project,
// but if there are conflict they will preferentially resolve to auspice's node_modules
let baseDir = __dirname;
let foundNodeModules = false;
const resolvedCoreDeps = {};
while (!foundNodeModules) {
foundNodeModules = true;
for (const coreDep of coreDeps) {
const coreDepParts = coreDep.split(":");
if (!resolvedCoreDeps[coreDepParts[0] || coreDep]) {
const modulePath = path.join(baseDir, "node_modules", coreDepParts[1] || coreDep);
foundNodeModules = foundNodeModules && fs.existsSync(modulePath);
if (foundNodeModules) resolvedCoreDeps[coreDepParts[0] || coreDep] = modulePath;
}
}
baseDir = foundNodeModules ? baseDir : path.resolve(baseDir, "..");
}

/* webpack alias' used in code import / require statements */
const aliasesToResolve = {
"@extensions": path.join(__dirname, '.null'), /* must provide a default, else it won't compile */
"@auspice": path.join(__dirname, 'src'),
"@libraries": path.join(__dirname, 'node_modules'),
// Pins all react stuff to auspice dir, and uses hot loader's dom (can be used safely in production)
"react": path.join(__dirname, 'node_modules/react'), // eslint-disable-line quote-props
"react-hot-loader": path.join(__dirname, 'node_modules/react-hot-loader'),
'react-dom': path.join(__dirname, 'node_modules/@hot-loader/react-dom'),
'regenerator-runtime': path.join(__dirname, 'node_modules/regenerator-runtime'),
'core-js': path.join(__dirname, 'node_modules/core-js'),
'styled-components': path.join(__dirname, 'node_modules/styled-components')
...resolvedCoreDeps
};

let extensionData;
Expand Down Expand Up @@ -72,23 +95,21 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
pluginHtml,
cleanWebpackPlugin
] : [
new LodashModuleReplacementPlugin(),
pluginProcessEnvData,
new webpack.HashedModuleIdsPlugin({}),
new WebpackChunkHash({algorithm: 'md5'}),
pluginCompress,
pluginHtml,
cleanWebpackPlugin
];
new LodashModuleReplacementPlugin(),
pluginProcessEnvData,
new webpack.HashedModuleIdsPlugin({}),
new WebpackChunkHash({ algorithm: 'md5' }),
pluginCompress,
pluginHtml,
cleanWebpackPlugin
];

if (analyzeBundle) {
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // eslint-disable-line
plugins.push(new BundleAnalyzerPlugin());
}

const entry = devMode
? ["webpack-hot-middleware/client", "./src/index"]
: ["./src/index"];
const entry = devMode ? ["webpack-hot-middleware/client", "./src/index"] : ["./src/index"];

/* Where do we want the output to be saved?
* For development we use the (virtual) "devel" directory
Expand Down Expand Up @@ -168,6 +189,7 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
publicPath: "/dist/"
},
resolve: {
mainFields: ['browser', 'main', 'module'],
alias: aliasesToResolve
},
node: {
Expand Down Expand Up @@ -238,4 +260,4 @@ const generateConfig = ({extensionPath, devMode=false, customOutputPath, analyze
return config;
};

module.exports = {default: generateConfig};
module.exports = { default: generateConfig };

0 comments on commit 6f716c5

Please sign in to comment.