-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support isolated folder for monorepo
- Loading branch information
1 parent
b53ce7d
commit 677f1b4
Showing
12 changed files
with
277 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {detectClones} from "jscpd"; | ||
|
||
(async () => { | ||
const clones = await detectClones({ | ||
path: [ | ||
__dirname + '/../fixtures' | ||
], | ||
skipIsolated: [ | ||
['packages/businessA', 'packages/businessB', 'packages/businessC'], | ||
], | ||
silent: true | ||
}); | ||
console.log(clones); | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copy the size of snapshot frame "sn" to frame "fr". Do the same for all | ||
* following frames and children. | ||
* Returns a pointer to the old current window, or NULL. | ||
*/ | ||
static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr) | ||
{ | ||
win_T *wp = NULL; | ||
win_T *wp2; | ||
|
||
fr->fr_height = sn->fr_height; | ||
fr->fr_width = sn->fr_width; | ||
if (fr->fr_layout == FR_LEAF) { | ||
frame_new_height(fr, fr->fr_height, FALSE, FALSE); | ||
frame_new_width(fr, fr->fr_width, FALSE, FALSE); | ||
wp = sn->fr_win; | ||
} | ||
win_T *wp = NULL; | ||
win_T *wp2; | ||
|
||
fr->fr_height = sn->fr_height; | ||
fr->fr_width = sn->fr_width; | ||
if (fr->fr_layout == FR_LEAF) { | ||
frame_new_height(fr, fr->fr_height, FALSE, FALSE); | ||
frame_new_width(fr, fr->fr_width, FALSE, FALSE); | ||
wp = sn->fr_win; | ||
} | ||
return wp; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
*12312 | ||
*/ | ||
function utf8_encode ( str_data ) { | ||
// Encodes an ISO-8859-1 string to UTF-8 | ||
// | ||
// + original by: Webtoolkit.info (http://www.webtoolkit.info/) | ||
str_data = str_data.replace(/\r\n/g,"\n"); | ||
var utftext = ""; | ||
|
||
for (var n = 0; n < str_data.length; n++) { | ||
var c = str_data.charCodeAt(n); | ||
if (c < 128) { | ||
utftext += String.fromCharCode(c); | ||
} else if((c > 127) && (c < 2048)) { | ||
utftext += String.fromCharCode((c >> 6) | 192); | ||
utftext += String.fromCharCode((c & 63) | 128); | ||
} else { | ||
utftext += String.fromCharCode((c >> 12) | 224); | ||
utftext += String.fromCharCode(((c >> 6) & 63) | 128); | ||
utftext += String.fromCharCode((c & 63) | 128); | ||
} | ||
} | ||
|
||
return utftext; | ||
} | ||
|
||
module.exports = function (store) { | ||
function getset (name, value) { | ||
var node = vars.store; | ||
var keys = name.split('.'); | ||
keys.slice(0,-1).forEach(function (k) { | ||
if (node[k] === undefined) node[k] = {}; | ||
node = node[k] | ||
}); | ||
var key = keys[keys.length - 1]; | ||
if (arguments.length == 1) { | ||
return node[key]; | ||
} | ||
else { | ||
return node[key] = value; | ||
} | ||
} | ||
|
||
var vars = { | ||
get : function (name) { | ||
return getset(name); | ||
}, | ||
set : function (name, value) { | ||
return getset(name, value); | ||
}, | ||
store : store || {}, | ||
}; | ||
return vars; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module.exports = function (store) { | ||
function getset (name, value) { | ||
var node = vars.store; | ||
var keys = name.split('.'); | ||
keys.slice(0,-1).forEach(function (k) { | ||
if (node[k] === undefined) node[k] = {}; | ||
node = node[k] | ||
}); | ||
var key = keys[keys.length - 1]; | ||
if (arguments.length == 1) { | ||
return node[key]; | ||
} | ||
else { | ||
return node[key] = value; | ||
} | ||
} | ||
|
||
var vars = { | ||
get : function (name) { | ||
return getset(name); | ||
}, | ||
set : function (name, value) { | ||
return getset(name, value); | ||
}, | ||
store : store || {}, | ||
}; | ||
return vars; | ||
}; | ||
module.exports = function (store) { | ||
function getset (name, value) { | ||
var node = vars.store; | ||
var keys = name.split('.'); | ||
keys.slice(0,-1).forEach(function (k) { | ||
if (node[k] === undefined) node[k] = {}; | ||
node = node[k] | ||
}); | ||
var key = keys[keys.length - 1]; | ||
if (arguments.length == 1) { | ||
return node[key]; | ||
} | ||
else { | ||
return node[key] = value; | ||
} | ||
} | ||
|
||
var vars = { | ||
get : function (name) { | ||
return getset(name); | ||
}, | ||
set : function (name, value) { | ||
return getset(name, value); | ||
}, | ||
store : store || {}, | ||
}; | ||
return vars; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './skip-local.validator'; | ||
export * from './skip-isolated.validator'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {getOption, IClone, ICloneValidator, IOptions, IValidationResult} from '@jscpd/core'; | ||
import {isAbsolute, relative} from "path"; | ||
|
||
export class SkipIsolatedValidator implements ICloneValidator { | ||
isRelativeMemoMap = new Map(); | ||
|
||
|
||
validate(clone: IClone, options: IOptions): IValidationResult { | ||
const status = !this.shouldSkipClone(clone, options); | ||
return { | ||
status, | ||
clone, | ||
message: [ | ||
`Sources of duplication located in isolated folder (${clone.duplicationA.sourceId}, ${clone.duplicationB.sourceId})` | ||
] | ||
}; | ||
} | ||
|
||
public shouldSkipClone(clone: IClone, options: IOptions): boolean { | ||
const skipIsolatedPathList: string[][] = getOption('skipIsolated', options); | ||
return skipIsolatedPathList.some( | ||
(dirList) => { | ||
const relA = dirList.find(dir => this.isRelativeMemo(clone.duplicationA.sourceId, dir)); | ||
const relB = dirList.find(dir => this.isRelativeMemo(clone.duplicationB.sourceId, dir)); | ||
return relA && relB && relA !== relB | ||
} | ||
); | ||
} | ||
|
||
private isRelativeMemo(file: string, dir: string) { | ||
const memoKey = `${file},${dir}`; | ||
if (this.isRelativeMemoMap.has(memoKey)) return this.isRelativeMemoMap.get(memoKey); | ||
const isRel = SkipIsolatedValidator.isRelative(file, dir) | ||
this.isRelativeMemoMap.set(memoKey, isRel); | ||
return isRel; | ||
} | ||
|
||
private static isRelative(file: string, path: string): boolean { | ||
const rel = relative(path, file); | ||
return rel !== '' && !rel.startsWith('..') && !isAbsolute(rel); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters