@reliverse/dler 1.7.46 → 1.7.47
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/bin/app/build/impl.js +1 -1
- package/bin/libs/cfg/cfg-impl/cfg-consts.d.ts +1 -1
- package/bin/libs/cfg/cfg-impl/cfg-consts.js +1 -1
- package/bin/libs/cfg/cfg-impl/cfg-types.d.ts +1 -1
- package/bin/libs/cfg/cfg-impl/rse-config/rse-impl/rse-define.d.ts +3 -3
- package/bin/libs/sdk/sdk-impl/config/default.js +1 -1
- package/bin/libs/sdk/sdk-impl/config/info.js +1 -1
- package/bin/libs/sdk/sdk-impl/config/init.js +1 -1
- package/bin/libs/sdk/sdk-impl/config/types.d.ts +1 -1
- package/bin/libs/sdk/sdk-impl/magic/magic-apply.js +1 -1
- package/bin/libs/sdk/sdk-impl/magic/magic-spells.js +143 -0
- package/package.json +1 -1
package/bin/app/build/impl.js
CHANGED
|
@@ -53,7 +53,7 @@ export async function dlerBuild(isDev, config, debugOnlyCopyNonBuildFiles, debug
|
|
|
53
53
|
await regular_buildFlow(timer, isDev, tempConfig);
|
|
54
54
|
await library_buildFlow(timer, isDev, tempConfig);
|
|
55
55
|
await dlerPostBuild(isDev, debugDontCopyNonBuildFiles);
|
|
56
|
-
if (effectiveConfig.postBuildSettings?.
|
|
56
|
+
if (effectiveConfig.postBuildSettings?.deleteDistTmpAfterBuild) {
|
|
57
57
|
await fs.remove(path.join(PROJECT_ROOT, "dist-tmp"));
|
|
58
58
|
}
|
|
59
59
|
return { timer, effectiveConfig };
|
|
@@ -51,7 +51,7 @@ export declare const defineConfigDler: (userConfig?: Partial<DlerConfig>) => {
|
|
|
51
51
|
hooksBeforeBuild: (() => Promise<void>)[];
|
|
52
52
|
hooksAfterBuild: (() => Promise<void>)[];
|
|
53
53
|
postBuildSettings: {
|
|
54
|
-
|
|
54
|
+
deleteDistTmpAfterBuild: boolean;
|
|
55
55
|
};
|
|
56
56
|
transpileFailOnWarn: boolean;
|
|
57
57
|
transpileEsbuild: import("./cfg-types").Esbuild;
|
|
@@ -11,7 +11,7 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
11
11
|
projectGitService?: "none" | "github" | "gitlab" | "bitbucket" | undefined;
|
|
12
12
|
projectDeployService?: "none" | "vercel" | "netlify" | "railway" | "deno" | undefined;
|
|
13
13
|
projectPackageManager?: "npm" | "bun" | "yarn" | "pnpm" | undefined;
|
|
14
|
-
projectState?: "
|
|
14
|
+
projectState?: "created" | "creating" | undefined;
|
|
15
15
|
projectCategory?: "browser" | "cli" | "unknown" | "website" | "vscode" | "library" | "mobile" | undefined;
|
|
16
16
|
projectSubcategory?: "unknown" | "e-commerce" | "tool" | undefined;
|
|
17
17
|
projectFramework?: "rempts" | "npm-jsr" | "unknown" | "vscode" | "nextjs" | "vite" | "svelte" | "remix" | "astro" | "nuxt" | "solid" | "qwik" | "vue" | "wxt" | "lynx" | "react-native" | "expo" | "capacitor" | "ionic" | "electron" | "tauri" | "neutralino" | "citty" | "commander" | "cac" | "meow" | "yargs" | "webextension" | "browser-extension" | undefined;
|
|
@@ -33,8 +33,6 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
33
33
|
themes?: string[] | undefined;
|
|
34
34
|
} | undefined;
|
|
35
35
|
preferredLibraries?: {
|
|
36
|
-
search?: "unknown" | "algolia" | undefined;
|
|
37
|
-
cdn?: "unknown" | "cloudflare" | undefined;
|
|
38
36
|
i18n?: "unknown" | "next-intl" | undefined;
|
|
39
37
|
analytics?: "unknown" | "vercel" | undefined;
|
|
40
38
|
authentication?: "unknown" | "better-auth" | "clerk" | "next-auth" | "supabase-auth" | "auth0" | undefined;
|
|
@@ -53,6 +51,7 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
53
51
|
logging?: "unknown" | "axiom" | undefined;
|
|
54
52
|
forms?: "unknown" | "react-hook-form" | undefined;
|
|
55
53
|
notifications?: "unknown" | "sonner" | undefined;
|
|
54
|
+
search?: "unknown" | "algolia" | undefined;
|
|
56
55
|
uploads?: "unknown" | "uploadthing" | undefined;
|
|
57
56
|
validation?: "unknown" | "zod" | "typebox" | "valibot" | undefined;
|
|
58
57
|
documentation?: "unknown" | "starlight" | "nextra" | undefined;
|
|
@@ -60,6 +59,7 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
60
59
|
mail?: "unknown" | "resend" | undefined;
|
|
61
60
|
cache?: "unknown" | "redis" | undefined;
|
|
62
61
|
storage?: "unknown" | "cloudflare" | undefined;
|
|
62
|
+
cdn?: "unknown" | "cloudflare" | undefined;
|
|
63
63
|
cms?: "unknown" | "contentlayer" | undefined;
|
|
64
64
|
seo?: "unknown" | "next-seo" | undefined;
|
|
65
65
|
motion?: "unknown" | "framer" | undefined;
|
|
@@ -522,7 +522,7 @@ async function getSpellImplementationPaths() {
|
|
|
522
522
|
}
|
|
523
523
|
async function isSpellImplementationFile(projectRelPath) {
|
|
524
524
|
const fileName = path.basename(projectRelPath);
|
|
525
|
-
if (fileName === "
|
|
525
|
+
if (fileName === "magic-apply.ts" || fileName === "magic-apply.js" || fileName === "magic-apply.d.ts" || fileName === "magic-spells.ts" || fileName === "magic-spells.js" || fileName === "magic-spells.d.ts") {
|
|
526
526
|
return true;
|
|
527
527
|
}
|
|
528
528
|
const spellPaths = await getSpellImplementationPaths();
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
const SPELL_REGEX = /\/\/\s*(?:@ts-expect-error\s+.*?)?<\s*(dler-[^>\s]+)(.*?)>/i;
|
|
3
|
+
const REPLACEMENT_REGEX = /`([^`]+)`/;
|
|
4
|
+
const IF_CONDITION_REGEX = /\bif\s+['"`]([^'"`]+)['"`]/i;
|
|
5
|
+
const ELSE_CONTENT_REGEX = /\belse\s+['"`]([^'"`]+)['"`]/i;
|
|
6
|
+
const STARTS_WITH_REGEX = /current file path starts with\s+(.+)$/i;
|
|
7
|
+
export function getAvailableSpells() {
|
|
8
|
+
return [
|
|
9
|
+
{
|
|
10
|
+
name: "dler-replace-line-to",
|
|
11
|
+
description: "Replaces the current line with new content, optionally based on a condition",
|
|
12
|
+
example: "// <dler-replace-line-to `export const version = \"1.0.0\";` if 'current file path starts with dist-npm'>",
|
|
13
|
+
notes: "If no condition is specified, replacement always applies. If condition is not met and else content is provided, uses else content. Otherwise keeps original line. Also supports @ts-expect-error prefix."
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: "dler-remove-line",
|
|
17
|
+
description: "Removes the current line from the output",
|
|
18
|
+
example: "// <dler-remove-line>",
|
|
19
|
+
notes: "Also supports @ts-expect-error prefix."
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "dler-remove-file",
|
|
23
|
+
description: "Removes the entire file from the output",
|
|
24
|
+
example: "// <dler-remove-file>",
|
|
25
|
+
notes: "This directive should be placed at the top of the file for clarity. Also supports @ts-expect-error prefix."
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "dler-remove-comment",
|
|
29
|
+
description: "Removes only the comment portion containing this directive from the line",
|
|
30
|
+
example: "console.log('debug info'); // <dler-remove-comment>",
|
|
31
|
+
notes: "Removes everything from '//' to the end of the line when the comment contains this directive. The code portion before the comment is preserved. Also supports @ts-expect-error prefix."
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "dler-ignore-this-line",
|
|
35
|
+
description: "Prevents any magic directives on this line from being processed",
|
|
36
|
+
example: "// <dler-remove-line> // <dler-ignore-this-line>",
|
|
37
|
+
notes: "When present on a line, all magic directives on that line are ignored and the line is kept as-is. Useful for code that contains magic directive strings that shouldn't be executed."
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
export function evaluateMagicDirective(line, ctx) {
|
|
42
|
+
if (line.includes("<dler-ignore-this-line>")) {
|
|
43
|
+
return NO_OP;
|
|
44
|
+
}
|
|
45
|
+
const match = line.match(SPELL_REGEX);
|
|
46
|
+
if (!match) return NO_OP;
|
|
47
|
+
const [, directive = "", body] = match;
|
|
48
|
+
if (!isValidMagicDirective(directive)) {
|
|
49
|
+
relinka("warn", `[spells] unknown directive: ${directive}`);
|
|
50
|
+
return NO_OP;
|
|
51
|
+
}
|
|
52
|
+
switch (directive) {
|
|
53
|
+
/* -------------------------------------------------------------- */
|
|
54
|
+
/* dler-remove-file */
|
|
55
|
+
/* -------------------------------------------------------------- */
|
|
56
|
+
case "dler-remove-file": {
|
|
57
|
+
return { removeFile: true, removeLine: true };
|
|
58
|
+
}
|
|
59
|
+
/* -------------------------------------------------------------- */
|
|
60
|
+
/* dler-remove-line */
|
|
61
|
+
/* -------------------------------------------------------------- */
|
|
62
|
+
case "dler-remove-line": {
|
|
63
|
+
return { removeLine: true, removeFile: false };
|
|
64
|
+
}
|
|
65
|
+
/* -------------------------------------------------------------- */
|
|
66
|
+
/* dler-remove-comment */
|
|
67
|
+
/* -------------------------------------------------------------- */
|
|
68
|
+
case "dler-remove-comment": {
|
|
69
|
+
const commentIndex = line.indexOf("//");
|
|
70
|
+
if (commentIndex !== -1) {
|
|
71
|
+
const codeBeforeComment = line.substring(0, commentIndex).trimEnd();
|
|
72
|
+
return { replacement: codeBeforeComment, removeLine: false, removeFile: false };
|
|
73
|
+
}
|
|
74
|
+
return NO_OP;
|
|
75
|
+
}
|
|
76
|
+
/* -------------------------------------------------------------- */
|
|
77
|
+
/* dler-replace-line-to */
|
|
78
|
+
/* -------------------------------------------------------------- */
|
|
79
|
+
case "dler-replace-line-to": {
|
|
80
|
+
const { replacement, elseContent, condition } = parseReplacementDirective(body ?? "");
|
|
81
|
+
if (!replacement) {
|
|
82
|
+
relinka("warn", "[spells] dler-replace-line-to missing replacement content");
|
|
83
|
+
return NO_OP;
|
|
84
|
+
}
|
|
85
|
+
const condMet = condition === void 0 ? true : evaluatePathCondition(condition, ctx);
|
|
86
|
+
if (condMet) {
|
|
87
|
+
return { replacement, removeLine: false, removeFile: false };
|
|
88
|
+
}
|
|
89
|
+
if (elseContent !== void 0) {
|
|
90
|
+
return { replacement: elseContent, removeLine: false, removeFile: false };
|
|
91
|
+
}
|
|
92
|
+
return NO_OP;
|
|
93
|
+
}
|
|
94
|
+
/* -------------------------------------------------------------- */
|
|
95
|
+
/* dler-ignore-this-line */
|
|
96
|
+
/* -------------------------------------------------------------- */
|
|
97
|
+
case "dler-ignore-this-line": {
|
|
98
|
+
return NO_OP;
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
return NO_OP;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const NO_OP = { removeLine: false, removeFile: false };
|
|
105
|
+
function isValidMagicDirective(directive) {
|
|
106
|
+
return [
|
|
107
|
+
"dler-replace-line-to",
|
|
108
|
+
"dler-remove-line",
|
|
109
|
+
"dler-remove-file",
|
|
110
|
+
"dler-remove-comment",
|
|
111
|
+
"dler-ignore-this-line"
|
|
112
|
+
].includes(directive);
|
|
113
|
+
}
|
|
114
|
+
function parseReplacementDirective(body) {
|
|
115
|
+
const parts = {
|
|
116
|
+
replacement: ""
|
|
117
|
+
};
|
|
118
|
+
const replacementMatch = body.match(REPLACEMENT_REGEX);
|
|
119
|
+
if (replacementMatch?.[1]) parts.replacement = replacementMatch[1].trim();
|
|
120
|
+
const ifMatch = body.match(IF_CONDITION_REGEX);
|
|
121
|
+
if (ifMatch?.[1]) {
|
|
122
|
+
parts.condition = ifMatch[1].trim();
|
|
123
|
+
}
|
|
124
|
+
const elseMatch = body.match(ELSE_CONTENT_REGEX);
|
|
125
|
+
if (elseMatch?.[1]) parts.elseContent = elseMatch[1].trim();
|
|
126
|
+
return parts;
|
|
127
|
+
}
|
|
128
|
+
function evaluatePathCondition(condition, ctx) {
|
|
129
|
+
const STARTS_WITH = STARTS_WITH_REGEX.exec(condition)?.[1];
|
|
130
|
+
if (STARTS_WITH) {
|
|
131
|
+
const prefixes = STARTS_WITH.split(/\s+or\s+/i).map(
|
|
132
|
+
(p) => p.replace(/['"`]/g, "").trim().replaceAll("\\", "/")
|
|
133
|
+
);
|
|
134
|
+
return prefixes.some((p) => ctx.filePath.startsWith(p));
|
|
135
|
+
}
|
|
136
|
+
if (condition.trim()) {
|
|
137
|
+
relinka(
|
|
138
|
+
"warn",
|
|
139
|
+
`[spells] unsupported condition "${condition}" - only "current file path starts with <prefix> [or <prefix> ...]" is supported`
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return false;
|
|
143
|
+
}
|