Skip to content

Dpisani/afp 215 pass webpack options fix build #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changeset/9619af8b/changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"releases": [{ "name": "@brisk-docs/website", "type": "patch" }],
"dependents": []
}
1 change: 1 addition & 0 deletions .changeset/9619af8b/changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- sodjfsdfds
18 changes: 0 additions & 18 deletions default.webpack.config.js

This file was deleted.

21 changes: 19 additions & 2 deletions docs.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
const defaultWebpackConfig = require('./default.webpack.config');
const test = file => {
const nextServerFiles = new RegExp(`^${__dirname}/packages/website/`);
const sourceFiles = /\.(ts|tsx|js|jsx)$/;
return file.match(sourceFiles) && !file.match(nextServerFiles);
};

const webpack = config => {
config.module.rules.push({
test,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
root: __dirname,
},
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
};

module.exports = () => ({
docs: './packages/website/docs',
packages: ['./packages/*'],
useManifests: false,
webpackConfiguration: defaultWebpackConfig,
webpack,
siteName: 'Brisk Docs Docs',
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"delete:dist": "bolt ws exec --parallel -- rm -rf dist",
"delete:modules": "bolt ws exec --parallel -- rm -rf node_modules && rm -rf node_modules",
"docs": "node packages/website/bin/index.js dev",
"start": "bolt w @brisk-docs/website run start -p 8080",
"start": "bolt w @brisk-docs/website run start",
"prettier": "prettier --write \"**/*.js\"",
"lint:prettier": "prettier --list-different \"**/*.js\"",
"lint:eslint": "yarn eslint .",
Expand Down Expand Up @@ -83,6 +83,7 @@
"lodash.capitalize": "^4.2.1",
"lodash.debounce": "^4.0.8",
"lodash.flatmap": "^4.5.0",
"lodash.identity": "^3.0.0",
"lodash.snakecase": "^4.1.1",
"next": "^7.0.2",
"outdent": "^0.7.0",
Expand Down
17 changes: 15 additions & 2 deletions packages/website/__fixtures__/custom-babel-project/docs.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
const path = require('path');
const webpackConfiguration = require('./webpack.config');

const webpack = config => {
config.module.rules.push({
test: new RegExp(`${__dirname}/.*\\.(js|jsx)$`),
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
root: __dirname,
},
},
});
return config;
};

module.exports = () => ({
packages: path.join(__dirname, 'weird-babel-package'),
docs: path.join(__dirname, 'docs'),
siteName: 'Babel/webpack Test Docs',
webpackConfiguration,
webpack,
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const path = require('path');
const webpackConfiguration = require('./webpack.config');

const webpack = config => {
config.resolve.modules.push(path.join(__dirname, 'packages'));

return config;
};

module.exports = () => ({
packages: path.join(__dirname, 'packages', '*'),
docs: path.join(__dirname, 'docs'),
siteName: 'Webpack Test Docs',
webpackConfiguration,
webpack,
});

This file was deleted.

5 changes: 5 additions & 0 deletions packages/website/__fixtures__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This utility is to reduce the need to litter usages
// of __dirname across our tests which make it hard to
// move files

module.exports.fixturesPath = __dirname;
12 changes: 10 additions & 2 deletions packages/website/__fixtures__/typescript-project/docs.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const path = require('path');
const webpackConfiguration = require('./webpack.config');

const webpack = config => {
config.module.rules.push({
test: /\.tsx?$/,
loader: 'babel-loader!ts-loader',
});

return config;
};

module.exports = () => ({
packages: path.join(__dirname, 'typescript-package'),
docs: path.join(__dirname, 'docs'),
siteName: 'Typescript/webpack Test Docs',
webpackConfiguration,
webpack,
});
19 changes: 0 additions & 19 deletions packages/website/__fixtures__/typescript-project/webpack.config.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/website/bin/generate-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ module.exports = async ({
packageRoot,
'./components/page-templates',
);
const bundlesPath = path.resolve(packageRoot, './bundles');

const pagesList = await generatePages(
packagesPaths,
docsPath,
pagesPath,
componentsPath,
bundlesPath,
{
useManifests,
webpackConfiguration,
Expand Down
25 changes: 4 additions & 21 deletions packages/website/bin/handle-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const fse = require('fs-extra');
const identity = require('lodash.identity');

/**
* Validates a config entry specifying a path or paths and normalises
Expand All @@ -20,29 +21,11 @@ const resolvePathsConfig = entry => {
throw new Error('entry must be an array or a string');
};

const defaultWebpackConfig = {
mode: 'development',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
},
},
},
],
},
};

const defaultConfig = {
docs: './docs',
packages: ['./packages/*'],
useManifests: false,
webpackConfiguration: defaultWebpackConfig,
webpack: identity,
};

/**
Expand All @@ -61,13 +44,13 @@ const processConfig = (cwd, providedConfig = {}) => {
path.resolve(cwd, packagesPath),
);

const { useManifests, webpackConfiguration } = config;
const { useManifests, webpack } = config;

return {
docsPath,
packagesPaths,
useManifests,
webpackConfiguration,
webpack,
};
};

Expand Down
9 changes: 8 additions & 1 deletion packages/website/bin/handle-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('website configuration processor', () => {
packagesPaths: ['/c/w/d/packages/*'],
docsPath: '/c/w/d/docs',
useManifests: false,
webpackConfiguration: expect.anything(),
webpack: expect.any(Function),
});
});

Expand Down Expand Up @@ -43,6 +43,13 @@ describe('website configuration processor', () => {

expect(config.useManifests).toEqual(true);
});

it('accepts a webpack function', () => {
const dummyWebpack = _ => _;

const config = processConfig(mockCwd, { webpack: dummyWebpack });
expect(config.webpack).toBe(dummyWebpack);
});
});

describe('loadConfig', () => {
Expand Down
35 changes: 10 additions & 25 deletions packages/website/bin/index.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,40 @@
#!/usr/bin/env node
const { spawnSync } = require('child_process');
const path = require('path');
const commandLineArgs = require('command-line-args');

const generatePages = require('./generate-pages');
const handleConfig = require('./handle-config');
const { dev, build, start } = require('./run-website');

const mainDefinitions = [{ name: 'command', defaultOption: true }];
const mainOptions = commandLineArgs(mainDefinitions, {
stopAtFirstUnknown: true,
});

const nextRoot = path.resolve(__dirname, '..');

// We have no control over this dangling underscore
// eslint-disable-next-line no-underscore-dangle
const argv = mainOptions._unknown || [];

const cliOptions = [{ name: 'config', type: String }];
const options = commandLineArgs(cliOptions, { argv, camelCase: true });
const cwd = process.cwd();

const spawnNextProcess = command => {
spawnSync(
`PATH=$(npm bin):$PATH; NODE_PATH=$NODE_PATH:$PWD/src next ${command}`,
[],
{
stdio: 'inherit',
shell: true,
env: { ...process.env, FORCE_EXTRACT_REACT_TYPES: true },
cwd: nextRoot,
},
);
};
if (mainOptions.command === undefined) {
throw new Error(`No command supplied`);
}

const preNextScripts = async () => {
const config = handleConfig(cwd, options.config);
await generatePages(config);
const handleError = err => {
console.error(err);
process.exit(1);
};

switch (mainOptions.command) {
case 'dev': {
preNextScripts().then(() => spawnNextProcess('dev'));
dev(options.config).catch(handleError);
break;
}
case 'build': {
preNextScripts().then(() => spawnNextProcess('build'));
build(options.config).catch(handleError);
break;
}
case 'start': {
spawnNextProcess('start');
start(options.config).catch(handleError);
break;
}
default:
Expand Down
Loading