Skip to content

Commit 62c70f9

Browse files
fix(output.path): do not check output.path for file existence (#103)
1 parent aa25bdc commit 62c70f9

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/properties/output/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import Joi from 'joi'
2-
import { notAbsolutePath, absolutePath, urlPart } from '../../types'
2+
import { notAbsolutePath, looksLikeAbsolutePath, urlPart } from '../../types'
33

44
export default Joi.object({
55
filename: notAbsolutePath,
6-
path: absolutePath,
6+
// don't check for existence here because it could be created in the build process
7+
path: looksLikeAbsolutePath,
78
publicPath: Joi.alternatives().try([
89
urlPart,
910
Joi.string().valid(''),

src/properties/output/index.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const validModuleConfigs = [
66
{ input: { filename: 'foo' } },
77
{ input: { chunkFilename: 'foo' } },
88
{ input: { path: 'exists' } },
9+
// Does not start with ./ or ../ so it "looks like an absolute path"
10+
{ input: { path: 'doesnt_actually' } },
911
{ input: { publicPath: '/assets/' } },
1012
{ input: { devtoolModuleFilenameTemplate: () => {} } },
1113
{ input: { hotUpdateChunkFilename: '[id].[hash].hot-update.js' } },

src/types/absolutePath.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ export const JoiWithPath = Joi.extend({
1414
{
1515
name: 'absolute',
1616

17+
params: {
18+
checkForExistence: Joi.bool(),
19+
},
20+
1721
validate(params, value, state, options) {
1822
const looksLikeAbsolutePath = /^(?!\.?\.\/).+$/.test(value)
19-
const directoryExists = shell.test('-d', value)
23+
const directoryExists = params.checkForExistence === false ? true : shell.test('-d', value)
2024
if (!looksLikeAbsolutePath || !directoryExists) {
2125
return this.createError('path.absolute', {
2226
path: value,
@@ -33,6 +37,7 @@ export const JoiWithPath = Joi.extend({
3337
],
3438
})
3539

36-
const absolutePath = JoiWithPath.path().absolute()
40+
const absolutePath = JoiWithPath.path().absolute(true)
3741
absolutePath.message = MESSAGE
3842
export default absolutePath
43+
export const looksLikeAbsolutePath = JoiWithPath.path().absolute(false)

src/types/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { default as absolutePath } from './absolutePath'
1+
export { default as absolutePath, looksLikeAbsolutePath } from './absolutePath'
22
export { default as notAbsolutePath } from './notAbsolutePath'
33
export { default as urlPart } from './urlPart'

0 commit comments

Comments
 (0)