@wp-typia/project-tools 0.15.3 → 0.15.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/cli-add.js +5 -1
- package/package.json +1 -1
package/dist/runtime/cli-add.js
CHANGED
|
@@ -648,6 +648,7 @@ const LEGACY_ASSERT_PATTERN = /assert:\s*typia\.createAssert</u;
|
|
|
648
648
|
const LEGACY_MANIFEST_PATTERN = /\r?\n[ \t]*manifest:\s*currentManifest,/u;
|
|
649
649
|
const LEGACY_TOOLKIT_CALL_PATTERN = /createTemplateValidatorToolkit<\s*(?<typeName>[A-Za-z0-9_]+)\s*>\s*\(\s*\{/u;
|
|
650
650
|
const LEGACY_VALIDATOR_TOOLKIT_IMPORT_PATTERN = /from\s*["']\.\.\/\.\.\/validator-toolkit["']/u;
|
|
651
|
+
const TYPIA_IMPORT_PATTERN = /^[\uFEFF \t]*import\s+typia\s+from\s*["']typia["'];?/mu;
|
|
651
652
|
const COMPATIBLE_COMPOUND_TOOLKIT_PATTERNS = [
|
|
652
653
|
/interface\s+TemplateValidatorFunctions\s*<\s*T\s+extends\s+object\s*>\s*\{/u,
|
|
653
654
|
/\bassert\s*:\s*ScaffoldValidatorToolkitOptions\s*<\s*T\s*>\s*\[\s*["']assert["']\s*\]/u,
|
|
@@ -667,6 +668,9 @@ function isLegacyCompoundValidatorSource(source) {
|
|
|
667
668
|
LEGACY_VALIDATOR_TOOLKIT_IMPORT_PATTERN.test(source) &&
|
|
668
669
|
!LEGACY_ASSERT_PATTERN.test(source));
|
|
669
670
|
}
|
|
671
|
+
function hasTypiaImport(source) {
|
|
672
|
+
return TYPIA_IMPORT_PATTERN.test(source.replace(/\/\*[\s\S]*?\*\//gu, ""));
|
|
673
|
+
}
|
|
670
674
|
function upgradeLegacyCompoundValidatorSource(source) {
|
|
671
675
|
const typeNameMatch = source.match(LEGACY_TOOLKIT_CALL_PATTERN);
|
|
672
676
|
const typeName = typeNameMatch?.groups?.typeName;
|
|
@@ -674,7 +678,7 @@ function upgradeLegacyCompoundValidatorSource(source) {
|
|
|
674
678
|
throw new Error("Unable to upgrade a legacy compound validator without a generated type import.");
|
|
675
679
|
}
|
|
676
680
|
let nextSource = source;
|
|
677
|
-
if (!nextSource
|
|
681
|
+
if (!hasTypiaImport(nextSource)) {
|
|
678
682
|
nextSource = `import typia from 'typia';\n${nextSource}`;
|
|
679
683
|
}
|
|
680
684
|
nextSource = nextSource.replace(LEGACY_TOOLKIT_CALL_PATTERN, [
|