Skip to content

Commit f3e18fc

Browse files
committed
Fixes #444 do not proceed with build if dir is a parent of appDir or baseUrl
1 parent bebecf8 commit f3e18fc

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

build/jslib/build.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,21 @@ define(function (require) {
10971097
' for optimization, and "dir" if you want the appDir' +
10981098
' or baseUrl directories optimized.');
10991099
}
1100-
if (config.dir && config.appDir && config.dir === config.appDir) {
1101-
throw new Error('"dir" and "appDir" set to the same directory.' +
1102-
' This could result in the deletion of appDir.' +
1103-
' Stopping.');
1100+
1101+
if (config.dir) {
1102+
// Make sure the output dir is not set to a parent of the
1103+
// source dir or the same dir, as it will result in source
1104+
// code deletion.
1105+
if (config.dir === config.baseUrl ||
1106+
config.dir === config.appDir ||
1107+
(config.baseUrl && build.makeRelativeFilePath(config.dir,
1108+
config.baseUrl).indexOf('..') !== 0) ||
1109+
(config.appDir &&
1110+
build.makeRelativeFilePath(config.dir, config.appDir).indexOf('..') !== 0)) {
1111+
throw new Error('"dir" is set to a parent or same directory as' +
1112+
' "appDir" or "baseUrl". This can result in' +
1113+
' the deletion of source code. Stopping.');
1114+
}
11041115
}
11051116

11061117
if (config.insertRequire && !lang.isArray(config.insertRequire)) {

0 commit comments

Comments
 (0)