Skip to content

Commit 4aab128

Browse files
committed
Better options path resolution
1 parent eb02b48 commit 4aab128

File tree

6 files changed

+31
-7
lines changed

6 files changed

+31
-7
lines changed

lib/bundle.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const BbPromise = require('bluebird');
4+
const relative = require('./utils/relative-path');
45

56
module.exports = (args) => new BbPromise((resolve, reject) => {
67
const colors = require('colors/safe');
@@ -11,12 +12,14 @@ module.exports = (args) => new BbPromise((resolve, reject) => {
1112

1213
const options = Object.assign(
1314
{
14-
config: path.join(process.cwd(), './webpack.config.js'),
15+
config: './webpack.config.js',
1516
watch: false,
1617
},
1718
args || {}
1819
);
1920

21+
options.config = relative(options.config);
22+
2023
if (args.help) {
2124
console.log(' Use Webpack to create the output bundle.');
2225
console.log(` ${colors.gray('config')}: The Webpack configuration file (${options.config})`);
@@ -26,7 +29,7 @@ module.exports = (args) => new BbPromise((resolve, reject) => {
2629

2730
console.log(` Using Webpack config at ${colors.gray(options.config)}`);
2831

29-
const config = require(options.config);
32+
const config = require(path.join(process.cwd(), options.config));
3033
const bundler = webpack(config);
3134
let bundlerRunCount = 0;
3235

lib/clean.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const BbPromise = require('bluebird');
4+
const relative = require('./utils/relative-path');
45

56
module.exports = (args) => BbPromise.resolve(args).then(args => {
67
const colors = require('colors/safe');
@@ -11,12 +12,15 @@ module.exports = (args) => BbPromise.resolve(args).then(args => {
1112

1213
const options = Object.assign(
1314
{
14-
package: path.join(process.cwd(), './package.json'),
15-
outDir: path.join(process.cwd(), './dist'),
15+
package: './package.json',
16+
outDir: './dist',
1617
},
1718
args || {}
1819
);
1920

21+
options.package = relative(options.package);
22+
options.outDir = relative(options.outDir);
23+
2024
if (args.help) {
2125
console.log(' Removes dist files.');
2226
console.log(` ${colors.gray('package')}: The npm package.json (${options.package})`);

lib/copy.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const BbPromise = require('bluebird');
4+
const relative = require('./utils/relative-path');
45

56
module.exports = (args) => BbPromise.resolve(args).then(args => {
67
const colors = require('colors/safe');
@@ -11,12 +12,15 @@ module.exports = (args) => BbPromise.resolve(args).then(args => {
1112

1213
const options = Object.assign(
1314
{
14-
package: path.join(process.cwd(), './package.json'),
15-
outDir: path.join(process.cwd(), './dist'),
15+
package: './package.json',
16+
outDir: './dist',
1617
},
1718
args || {}
1819
);
1920

21+
options.package = relative(options.package);
22+
options.outDir = relative(options.outDir);
23+
2024
if (args.help) {
2125
console.log(' Copy package json in dist directory as well as static files.');
2226
console.log(` ${colors.gray('package')}: The npm package.json (${options.package})`);

lib/image.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = (args) => BbPromise.resolve(args)
1111
const tar = require('tar-fs');
1212
const Docker = require('dockerode');
1313
const JSONStream = require('JSONStream');
14+
const relative = require('./utils/relative-path');
1415

1516
console.log(colors.yellow('Image...'));
1617

@@ -23,6 +24,9 @@ module.exports = (args) => BbPromise.resolve(args)
2324
args || {}
2425
);
2526

27+
options.package = relative(options.package);
28+
options.outDir = relative(options.outDir);
29+
2630
const pkg = fse.readJsonSync(options.package);
2731
if (!options.repo) {
2832
options.repo = pkg.name.replace('-', '/');

lib/serve.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const BbPromise = require('bluebird');
4+
const relative = require('./utils/relative-path');
45

56
module.exports = (args) => BbPromise.resolve(args)
67
.then(require('./build'))
@@ -23,6 +24,9 @@ module.exports = (args) => BbPromise.resolve(args)
2324
args || {}
2425
);
2526

27+
options.package = relative(options.package);
28+
options.config = relative(options.config);
29+
2630
if (options.devProxy === true) {
2731
options.devProxy = 5000;
2832
}
@@ -78,7 +82,7 @@ module.exports = (args) => BbPromise.resolve(args)
7882
// TODO a way to select a subconfig is needed
7983
const webpack = require('webpack');
8084
const webpackDevServer = require('webpack-dev-server');
81-
const config = require(options.config);
85+
const config = require(path.join(process.cwd(), options.config));
8286
const bundler = webpack(config);
8387
const proxyUrl = `http://localhost:${options.devProxy}`;
8488

lib/utils/relative-path.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const path = require('path');
2+
3+
module.exports = function (p) {
4+
return path.relative(process.cwd(), p);
5+
};

0 commit comments

Comments
 (0)