@reliverse/dler 1.7.24 → 1.7.25
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/check/cmd.js +11 -0
- package/bin/app/magic/cmd.js +1 -1
- package/bin/app/pub/impl.js +1 -1
- package/bin/app/transform/cmd.d.ts +0 -0
- package/bin/app/transform/cmd.js +0 -0
- package/bin/libs/cfg/rse/rse-impl/rse-define.d.ts +9 -9
- package/bin/libs/sdk/sdk-impl/cmds/inject/inject-impl-mod.d.ts +99 -50
- package/bin/libs/sdk/sdk-impl/cmds/inject/inject-impl-mod.js +703 -216
- package/bin/libs/sdk/sdk-impl/cmds/transform/transform-impl-mod.d.ts +117 -0
- package/bin/libs/sdk/sdk-impl/cmds/transform/transform-impl-mod.js +178 -0
- package/bin/libs/sdk/sdk-impl/config/info.js +1 -1
- package/bin/libs/sdk/sdk-impl/magic/{apply.d.ts → ms-apply.d.ts} +1 -0
- package/bin/libs/sdk/sdk-impl/magic/{apply.js → ms-apply.js} +18 -10
- package/bin/libs/sdk/sdk-impl/magic/{spells.d.ts → ms-spells.d.ts} +1 -1
- package/bin/libs/sdk/sdk-impl/magic/{spells.js → ms-spells.js} +27 -9
- package/bin/libs/sdk/sdk-impl/rules/reliverse/no-dynamic-imports/no-dynamic-imports.d.ts +2 -0
- package/bin/libs/sdk/sdk-impl/rules/reliverse/no-dynamic-imports/no-dynamic-imports.js +41 -0
- package/bin/libs/sdk/sdk-mod.d.ts +4 -4
- package/bin/libs/sdk/sdk-mod.js +2 -2
- package/package.json +2 -2
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { SourceMapOptions } from "magic-string";
|
|
2
|
+
import MagicString from "magic-string";
|
|
3
|
+
export interface MagicStringOptions {
|
|
4
|
+
filename?: string;
|
|
5
|
+
indentExclusionRanges?: [number, number][];
|
|
6
|
+
ignoreList?: boolean;
|
|
7
|
+
offset?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface UpdateOptions {
|
|
10
|
+
storeName?: boolean;
|
|
11
|
+
overwrite?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface OverwriteOptions {
|
|
14
|
+
storeName?: boolean;
|
|
15
|
+
contentOnly?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface IndentOptions {
|
|
18
|
+
exclude?: [number, number][];
|
|
19
|
+
}
|
|
20
|
+
export interface StringTransformer {
|
|
21
|
+
readonly original: string;
|
|
22
|
+
readonly current: () => string;
|
|
23
|
+
readonly hasChanged: () => boolean;
|
|
24
|
+
readonly isEmpty: () => boolean;
|
|
25
|
+
readonly clone: () => StringTransformer;
|
|
26
|
+
readonly generateMap: (options?: SourceMapOptions) => any;
|
|
27
|
+
readonly generateDecodedMap: (options?: SourceMapOptions) => any;
|
|
28
|
+
}
|
|
29
|
+
export interface TransformResult {
|
|
30
|
+
code: string;
|
|
31
|
+
map?: any;
|
|
32
|
+
hasChanged: boolean;
|
|
33
|
+
transformer: StringTransformer;
|
|
34
|
+
}
|
|
35
|
+
export declare const createTransformerFromMagicString: (ms: MagicString, original: string) => StringTransformer;
|
|
36
|
+
export declare const createTransformer: (source: string, options?: MagicStringOptions) => StringTransformer;
|
|
37
|
+
export declare const update: (transformer: StringTransformer, start: number, end: number, content: string, options?: UpdateOptions) => StringTransformer;
|
|
38
|
+
export declare const overwrite: (transformer: StringTransformer, start: number, end: number, content: string, options?: OverwriteOptions) => StringTransformer;
|
|
39
|
+
export declare const append: (transformer: StringTransformer, content: string) => StringTransformer;
|
|
40
|
+
export declare const prepend: (transformer: StringTransformer, content: string) => StringTransformer;
|
|
41
|
+
export declare const remove: (transformer: StringTransformer, start: number, end: number) => StringTransformer;
|
|
42
|
+
export declare const replace: (transformer: StringTransformer, searchValue: string | RegExp, replaceValue: string | ((match: string, ...args: any[]) => string)) => StringTransformer;
|
|
43
|
+
export declare const replaceAll: (transformer: StringTransformer, searchValue: string | RegExp, replaceValue: string | ((match: string, ...args: any[]) => string)) => StringTransformer;
|
|
44
|
+
export declare const indent: (transformer: StringTransformer, prefix?: string, options?: IndentOptions) => StringTransformer;
|
|
45
|
+
export declare const trim: (transformer: StringTransformer, charType?: string) => StringTransformer;
|
|
46
|
+
export declare const pipe: <T>(value: T, ...operations: ((input: T) => T)[]) => T;
|
|
47
|
+
export declare const wrapWith: (transformer: StringTransformer, prefix: string, suffix: string) => StringTransformer;
|
|
48
|
+
export declare const insertAt: (transformer: StringTransformer, index: number, content: string) => StringTransformer;
|
|
49
|
+
export declare const slice: (transformer: StringTransformer, start?: number, end?: number) => string;
|
|
50
|
+
export declare const template: (strings: TemplateStringsArray, ...values: any[]) => StringTransformer;
|
|
51
|
+
export declare const readAndTransform: (filePath: string, transformer: (content: StringTransformer) => StringTransformer) => Promise<TransformResult>;
|
|
52
|
+
export declare const transformAndWrite: (inputPath: string, outputPath: string, transformer: (content: StringTransformer) => StringTransformer, options?: {
|
|
53
|
+
generateSourceMap?: boolean;
|
|
54
|
+
sourceMapPath?: string;
|
|
55
|
+
}) => Promise<void>;
|
|
56
|
+
export declare const transformMultiple: (transformations: {
|
|
57
|
+
input: string;
|
|
58
|
+
output: string;
|
|
59
|
+
transformer: (content: StringTransformer) => StringTransformer;
|
|
60
|
+
}[]) => Promise<void>;
|
|
61
|
+
export interface BundleSource {
|
|
62
|
+
filename: string;
|
|
63
|
+
content: StringTransformer;
|
|
64
|
+
ignoreList?: boolean;
|
|
65
|
+
indentExclusionRanges?: [number, number][];
|
|
66
|
+
}
|
|
67
|
+
export declare const createBundle: (sources?: BundleSource[]) => {
|
|
68
|
+
addSource: (source: BundleSource) => /*elided*/ any;
|
|
69
|
+
indent: (prefix?: string) => /*elided*/ any;
|
|
70
|
+
prepend: (content: string) => /*elided*/ any;
|
|
71
|
+
append: (content: string) => /*elided*/ any;
|
|
72
|
+
toString: () => string;
|
|
73
|
+
generateMap: (options?: SourceMapOptions) => Omit<import("magic-string").SourceMap, "sourcesContent"> & {
|
|
74
|
+
sourcesContent: Array<string | null>;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export declare const compose: <T>(...transformers: ((input: T) => T)[]) => ((input: T) => T);
|
|
78
|
+
export * from "magic-string";
|
|
79
|
+
declare const _default: {
|
|
80
|
+
createTransformer: (source: string, options?: MagicStringOptions) => StringTransformer;
|
|
81
|
+
update: (transformer: StringTransformer, start: number, end: number, content: string, options?: UpdateOptions) => StringTransformer;
|
|
82
|
+
overwrite: (transformer: StringTransformer, start: number, end: number, content: string, options?: OverwriteOptions) => StringTransformer;
|
|
83
|
+
append: (transformer: StringTransformer, content: string) => StringTransformer;
|
|
84
|
+
prepend: (transformer: StringTransformer, content: string) => StringTransformer;
|
|
85
|
+
remove: (transformer: StringTransformer, start: number, end: number) => StringTransformer;
|
|
86
|
+
replace: (transformer: StringTransformer, searchValue: string | RegExp, replaceValue: string | ((match: string, ...args: any[]) => string)) => StringTransformer;
|
|
87
|
+
replaceAll: (transformer: StringTransformer, searchValue: string | RegExp, replaceValue: string | ((match: string, ...args: any[]) => string)) => StringTransformer;
|
|
88
|
+
indent: (transformer: StringTransformer, prefix?: string, options?: IndentOptions) => StringTransformer;
|
|
89
|
+
trim: (transformer: StringTransformer, charType?: string) => StringTransformer;
|
|
90
|
+
pipe: <T>(value: T, ...operations: ((input: T) => T)[]) => T;
|
|
91
|
+
wrapWith: (transformer: StringTransformer, prefix: string, suffix: string) => StringTransformer;
|
|
92
|
+
insertAt: (transformer: StringTransformer, index: number, content: string) => StringTransformer;
|
|
93
|
+
slice: (transformer: StringTransformer, start?: number, end?: number) => string;
|
|
94
|
+
template: (strings: TemplateStringsArray, ...values: any[]) => StringTransformer;
|
|
95
|
+
readAndTransform: (filePath: string, transformer: (content: StringTransformer) => StringTransformer) => Promise<TransformResult>;
|
|
96
|
+
transformAndWrite: (inputPath: string, outputPath: string, transformer: (content: StringTransformer) => StringTransformer, options?: {
|
|
97
|
+
generateSourceMap?: boolean;
|
|
98
|
+
sourceMapPath?: string;
|
|
99
|
+
}) => Promise<void>;
|
|
100
|
+
transformMultiple: (transformations: {
|
|
101
|
+
input: string;
|
|
102
|
+
output: string;
|
|
103
|
+
transformer: (content: StringTransformer) => StringTransformer;
|
|
104
|
+
}[]) => Promise<void>;
|
|
105
|
+
createBundle: (sources?: BundleSource[]) => {
|
|
106
|
+
addSource: (source: BundleSource) => /*elided*/ any;
|
|
107
|
+
indent: (prefix?: string) => /*elided*/ any;
|
|
108
|
+
prepend: (content: string) => /*elided*/ any;
|
|
109
|
+
append: (content: string) => /*elided*/ any;
|
|
110
|
+
toString: () => string;
|
|
111
|
+
generateMap: (options?: SourceMapOptions) => Omit<import("magic-string").SourceMap, "sourcesContent"> & {
|
|
112
|
+
sourcesContent: Array<string | null>;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
compose: <T>(...transformers: ((input: T) => T)[]) => ((input: T) => T);
|
|
116
|
+
};
|
|
117
|
+
export default _default;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import MagicString, { Bundle } from "magic-string";
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
export const createTransformerFromMagicString = (ms, original) => {
|
|
4
|
+
const transformer = {
|
|
5
|
+
original,
|
|
6
|
+
_ms: ms,
|
|
7
|
+
current: () => ms.toString(),
|
|
8
|
+
hasChanged: () => ms.hasChanged(),
|
|
9
|
+
isEmpty: () => ms.isEmpty(),
|
|
10
|
+
clone: () => createTransformerFromMagicString(ms.clone(), original),
|
|
11
|
+
generateMap: (mapOptions) => ms.generateMap(mapOptions),
|
|
12
|
+
generateDecodedMap: (mapOptions) => ms.generateDecodedMap(mapOptions)
|
|
13
|
+
};
|
|
14
|
+
return transformer;
|
|
15
|
+
};
|
|
16
|
+
export const createTransformer = (source, options) => {
|
|
17
|
+
const ms = new MagicString(source, options);
|
|
18
|
+
return createTransformerFromMagicString(ms, source);
|
|
19
|
+
};
|
|
20
|
+
export const update = (transformer, start, end, content, options) => {
|
|
21
|
+
const ms = transformer._ms.clone();
|
|
22
|
+
ms.update(start, end, content, options);
|
|
23
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
24
|
+
};
|
|
25
|
+
export const overwrite = (transformer, start, end, content, options) => {
|
|
26
|
+
const ms = transformer._ms.clone();
|
|
27
|
+
ms.overwrite(start, end, content, options);
|
|
28
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
29
|
+
};
|
|
30
|
+
export const append = (transformer, content) => {
|
|
31
|
+
const ms = transformer._ms.clone();
|
|
32
|
+
ms.append(content);
|
|
33
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
34
|
+
};
|
|
35
|
+
export const prepend = (transformer, content) => {
|
|
36
|
+
const ms = transformer._ms.clone();
|
|
37
|
+
ms.prepend(content);
|
|
38
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
39
|
+
};
|
|
40
|
+
export const remove = (transformer, start, end) => {
|
|
41
|
+
const ms = transformer._ms.clone();
|
|
42
|
+
ms.remove(start, end);
|
|
43
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
44
|
+
};
|
|
45
|
+
export const replace = (transformer, searchValue, replaceValue) => {
|
|
46
|
+
const ms = transformer._ms.clone();
|
|
47
|
+
ms.replace(searchValue, replaceValue);
|
|
48
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
49
|
+
};
|
|
50
|
+
export const replaceAll = (transformer, searchValue, replaceValue) => {
|
|
51
|
+
const ms = transformer._ms.clone();
|
|
52
|
+
ms.replaceAll(searchValue, replaceValue);
|
|
53
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
54
|
+
};
|
|
55
|
+
export const indent = (transformer, prefix, options) => {
|
|
56
|
+
const ms = transformer._ms.clone();
|
|
57
|
+
ms.indent(prefix, options);
|
|
58
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
59
|
+
};
|
|
60
|
+
export const trim = (transformer, charType) => {
|
|
61
|
+
const ms = transformer._ms.clone();
|
|
62
|
+
ms.trim(charType);
|
|
63
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
64
|
+
};
|
|
65
|
+
export const pipe = (value, ...operations) => {
|
|
66
|
+
return operations.reduce((acc, operation) => operation(acc), value);
|
|
67
|
+
};
|
|
68
|
+
export const wrapWith = (transformer, prefix, suffix) => {
|
|
69
|
+
return pipe(
|
|
70
|
+
transformer,
|
|
71
|
+
(t) => prepend(t, prefix),
|
|
72
|
+
(t) => append(t, suffix)
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
export const insertAt = (transformer, index, content) => {
|
|
76
|
+
const ms = transformer._ms.clone();
|
|
77
|
+
ms.appendLeft(index, content);
|
|
78
|
+
return createTransformerFromMagicString(ms, transformer.original);
|
|
79
|
+
};
|
|
80
|
+
export const slice = (transformer, start = 0, end) => {
|
|
81
|
+
const currentString = transformer.current();
|
|
82
|
+
return currentString.slice(start, end ?? currentString.length);
|
|
83
|
+
};
|
|
84
|
+
export const template = (strings, ...values) => {
|
|
85
|
+
const source = strings.reduce((result, string, i) => result + string + (values[i] || ""), "");
|
|
86
|
+
return createTransformer(source);
|
|
87
|
+
};
|
|
88
|
+
export const readAndTransform = async (filePath, transformer) => {
|
|
89
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
90
|
+
const original = createTransformer(content);
|
|
91
|
+
const transformed = transformer(original);
|
|
92
|
+
return {
|
|
93
|
+
code: transformed.current(),
|
|
94
|
+
hasChanged: transformed.hasChanged(),
|
|
95
|
+
transformer: transformed
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export const transformAndWrite = async (inputPath, outputPath, transformer, options) => {
|
|
99
|
+
const result = await readAndTransform(inputPath, transformer);
|
|
100
|
+
await fs.writeFile(outputPath, result.code);
|
|
101
|
+
if (options?.generateSourceMap && options.sourceMapPath) {
|
|
102
|
+
const map = result.transformer.generateMap({
|
|
103
|
+
source: inputPath,
|
|
104
|
+
file: options.sourceMapPath,
|
|
105
|
+
includeContent: true
|
|
106
|
+
});
|
|
107
|
+
await fs.writeFile(options.sourceMapPath, map.toString());
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
export const transformMultiple = async (transformations) => {
|
|
111
|
+
await Promise.all(
|
|
112
|
+
transformations.map(
|
|
113
|
+
({ input, output, transformer }) => transformAndWrite(input, output, transformer)
|
|
114
|
+
)
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
export const createBundle = (sources = []) => {
|
|
118
|
+
const bundle = new Bundle();
|
|
119
|
+
for (const source of sources) {
|
|
120
|
+
bundle.addSource({
|
|
121
|
+
filename: source.filename,
|
|
122
|
+
content: new MagicString(source.content.current()),
|
|
123
|
+
ignoreList: source.ignoreList,
|
|
124
|
+
indentExclusionRanges: source.indentExclusionRanges
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
addSource: (source) => {
|
|
129
|
+
bundle.addSource({
|
|
130
|
+
filename: source.filename,
|
|
131
|
+
content: new MagicString(source.content.current()),
|
|
132
|
+
ignoreList: source.ignoreList,
|
|
133
|
+
indentExclusionRanges: source.indentExclusionRanges
|
|
134
|
+
});
|
|
135
|
+
return createBundle([]);
|
|
136
|
+
},
|
|
137
|
+
indent: (prefix) => {
|
|
138
|
+
bundle.indent(prefix);
|
|
139
|
+
return createBundle([]);
|
|
140
|
+
},
|
|
141
|
+
prepend: (content) => {
|
|
142
|
+
bundle.prepend(content);
|
|
143
|
+
return createBundle([]);
|
|
144
|
+
},
|
|
145
|
+
append: (content) => {
|
|
146
|
+
bundle.append(content);
|
|
147
|
+
return createBundle([]);
|
|
148
|
+
},
|
|
149
|
+
toString: () => bundle.toString(),
|
|
150
|
+
generateMap: (options) => bundle.generateMap(options)
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
export const compose = (...transformers) => {
|
|
154
|
+
return (input) => transformers.reduceRight((acc, transformer) => transformer(acc), input);
|
|
155
|
+
};
|
|
156
|
+
export * from "magic-string";
|
|
157
|
+
export default {
|
|
158
|
+
createTransformer,
|
|
159
|
+
update,
|
|
160
|
+
overwrite,
|
|
161
|
+
append,
|
|
162
|
+
prepend,
|
|
163
|
+
remove,
|
|
164
|
+
replace,
|
|
165
|
+
replaceAll,
|
|
166
|
+
indent,
|
|
167
|
+
trim,
|
|
168
|
+
pipe,
|
|
169
|
+
wrapWith,
|
|
170
|
+
insertAt,
|
|
171
|
+
slice,
|
|
172
|
+
template,
|
|
173
|
+
readAndTransform,
|
|
174
|
+
transformAndWrite,
|
|
175
|
+
transformMultiple,
|
|
176
|
+
createBundle,
|
|
177
|
+
compose
|
|
178
|
+
};
|
|
@@ -35,6 +35,7 @@ export interface ApplyMagicSpellsResult {
|
|
|
35
35
|
* @returns Object containing arrays of processed files and processed .d.ts files
|
|
36
36
|
*/
|
|
37
37
|
export declare function applyMagicSpells(targets: string[], options?: Partial<ApplyMagicSpellsOptions>): Promise<ApplyMagicSpellsResult>;
|
|
38
|
+
export declare function processSingleOutputFile(filePath: string, options?: Partial<ApplyMagicSpellsOptions>): Promise<boolean>;
|
|
38
39
|
/**
|
|
39
40
|
* Gets all available registries across all libraries
|
|
40
41
|
* @returns Array of unique registry names found across all libraries
|
|
@@ -4,7 +4,9 @@ import { relinka } from "@reliverse/relinka";
|
|
|
4
4
|
import pMap from "p-map";
|
|
5
5
|
import { isBinaryExt } from "../utils/binary.js";
|
|
6
6
|
import { formatError } from "../utils/utils-error-cwd.js";
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
evaluateMagicDirective
|
|
9
|
+
} from "./ms-spells.js";
|
|
8
10
|
const DEBUG_MODE = true;
|
|
9
11
|
const PROCESS_DTS_FILES = true;
|
|
10
12
|
const DEFAULT_OPTIONS = {
|
|
@@ -29,7 +31,7 @@ function validateTargets(targets, customOutputPaths) {
|
|
|
29
31
|
throw new Error(`Invalid output target: ${target}`);
|
|
30
32
|
}
|
|
31
33
|
const outputPath = allOutputPaths[outputDir] || outputDir;
|
|
32
|
-
const fullPath = path.join(process.cwd(), outputPath);
|
|
34
|
+
const fullPath = path.isAbsolute(outputPath) ? outputPath : path.join(process.cwd(), outputPath);
|
|
33
35
|
if (!fs.existsSync(fullPath)) {
|
|
34
36
|
throw new Error(`Output directory does not exist: ${outputPath}`);
|
|
35
37
|
}
|
|
@@ -149,7 +151,7 @@ async function processCustomTarget(outputDir, options = {}) {
|
|
|
149
151
|
}
|
|
150
152
|
const outputFilesToProcess = [];
|
|
151
153
|
const outputPath = options.customOutputPaths?.[outputDir] || outputDir;
|
|
152
|
-
const fullOutputPath = path.join(process.cwd(), outputPath);
|
|
154
|
+
const fullOutputPath = path.isAbsolute(outputPath) ? outputPath : path.join(process.cwd(), outputPath);
|
|
153
155
|
for await (const filePath of walkDirectoryTree(fullOutputPath)) {
|
|
154
156
|
if (await isBinaryExt(filePath)) {
|
|
155
157
|
continue;
|
|
@@ -340,7 +342,7 @@ async function findSourceFile(distFilePath) {
|
|
|
340
342
|
}
|
|
341
343
|
return null;
|
|
342
344
|
}
|
|
343
|
-
async function processSingleOutputFile(filePath, options = {}) {
|
|
345
|
+
export async function processSingleOutputFile(filePath, options = {}) {
|
|
344
346
|
const projectRel = path.relative(process.cwd(), filePath).replaceAll(path.sep, "/");
|
|
345
347
|
if (await isBinaryExt(filePath)) {
|
|
346
348
|
if (DEBUG_MODE) relinka("log", `[spells] \u2298 binary ${projectRel}`);
|
|
@@ -349,7 +351,7 @@ async function processSingleOutputFile(filePath, options = {}) {
|
|
|
349
351
|
let copiedFromSource = false;
|
|
350
352
|
if (options.copyFileWithDirectivesFromSrcBeforeProcessing ?? DEFAULT_OPTIONS.copyFileWithDirectivesFromSrcBeforeProcessing) {
|
|
351
353
|
const sourceFile = await findSourceFile(filePath);
|
|
352
|
-
if (sourceFile) {
|
|
354
|
+
if (sourceFile && sourceFile !== filePath) {
|
|
353
355
|
try {
|
|
354
356
|
await fs.copyFile(sourceFile, filePath);
|
|
355
357
|
copiedFromSource = true;
|
|
@@ -364,15 +366,17 @@ async function processSingleOutputFile(filePath, options = {}) {
|
|
|
364
366
|
const source = await fs.readFile(filePath, "utf8");
|
|
365
367
|
const ctx = { filePath: projectRel };
|
|
366
368
|
let removeFile = false;
|
|
369
|
+
const allLines = source.split(/\r?\n/);
|
|
367
370
|
const processedLines = [];
|
|
368
|
-
for (
|
|
371
|
+
for (let i = allLines.length - 1; i >= 0; i--) {
|
|
372
|
+
const line = allLines[i];
|
|
369
373
|
const outcome = evaluateMagicDirective(line, ctx);
|
|
370
374
|
if (outcome.removeFile) {
|
|
371
375
|
removeFile = true;
|
|
372
376
|
break;
|
|
373
377
|
}
|
|
374
378
|
if (!outcome.removeLine) {
|
|
375
|
-
processedLines.
|
|
379
|
+
processedLines.unshift(outcome.replacement ?? line);
|
|
376
380
|
}
|
|
377
381
|
}
|
|
378
382
|
if (removeFile) {
|
|
@@ -411,7 +415,7 @@ async function findOutputFiles(sourceFilePath, outputDir, libName, customOutputP
|
|
|
411
415
|
extensions = [ext];
|
|
412
416
|
}
|
|
413
417
|
for (const outputExt of extensions) {
|
|
414
|
-
const outputFile = path.join(process.cwd(), outputPath, `${baseName}${outputExt}`);
|
|
418
|
+
const outputFile = path.isAbsolute(outputPath) ? path.join(outputPath, `${baseName}${outputExt}`) : path.join(process.cwd(), outputPath, `${baseName}${outputExt}`);
|
|
415
419
|
if (await fs.pathExists(outputFile)) {
|
|
416
420
|
outputFiles.push(outputFile);
|
|
417
421
|
}
|
|
@@ -429,7 +433,7 @@ async function findOutputFiles(sourceFilePath, outputDir, libName, customOutputP
|
|
|
429
433
|
extensions = [ext];
|
|
430
434
|
}
|
|
431
435
|
for (const outputExt of extensions) {
|
|
432
|
-
const outputFile = path.join(process.cwd(), outputPath, `${baseName}${outputExt}`);
|
|
436
|
+
const outputFile = path.isAbsolute(basePath) ? path.join(basePath, dirPath === "." ? "" : dirPath, `${baseName}${outputExt}`) : path.join(process.cwd(), outputPath, `${baseName}${outputExt}`);
|
|
433
437
|
if (await fs.pathExists(outputFile)) {
|
|
434
438
|
outputFiles.push(outputFile);
|
|
435
439
|
}
|
|
@@ -483,6 +487,10 @@ async function getSpellImplementationPaths() {
|
|
|
483
487
|
return paths;
|
|
484
488
|
}
|
|
485
489
|
async function isSpellImplementationFile(projectRelPath) {
|
|
490
|
+
const fileName = path.basename(projectRelPath);
|
|
491
|
+
if (fileName === "ms-apply.ts" || fileName === "ms-apply.js" || fileName === "ms-apply.d.ts" || fileName === "ms-spells.ts" || fileName === "ms-spells.js" || fileName === "ms-spells.d.ts") {
|
|
492
|
+
return true;
|
|
493
|
+
}
|
|
486
494
|
const spellPaths = await getSpellImplementationPaths();
|
|
487
495
|
return spellPaths.some((spellPath) => projectRelPath.includes(spellPath));
|
|
488
496
|
}
|
|
@@ -573,7 +581,7 @@ export async function getFilesWithMagicSpells(dirs, options = {}) {
|
|
|
573
581
|
await pMap(
|
|
574
582
|
dirs,
|
|
575
583
|
async (dir) => {
|
|
576
|
-
const fullPath = path.join(process.cwd(), dir);
|
|
584
|
+
const fullPath = path.isAbsolute(dir) ? dir : path.join(process.cwd(), dir);
|
|
577
585
|
if (!await fs.pathExists(fullPath)) {
|
|
578
586
|
const error = `Directory does not exist: ${dir}`;
|
|
579
587
|
if (stopOnError) {
|
|
@@ -24,7 +24,7 @@ export interface SpellOutcome {
|
|
|
24
24
|
removeLine: boolean;
|
|
25
25
|
removeFile: boolean;
|
|
26
26
|
}
|
|
27
|
-
export type SpellDirective = "dler-replace-line-to" | "dler-remove-line" | "dler-remove-file" | "dler-remove-comment";
|
|
27
|
+
export type SpellDirective = "dler-replace-line-to" | "dler-remove-line" | "dler-remove-file" | "dler-remove-comment" | "dler-ignore-this-line";
|
|
28
28
|
export interface SpellInfo {
|
|
29
29
|
/** The name of the spell directive */
|
|
30
30
|
name: SpellDirective;
|
|
@@ -10,7 +10,7 @@ export function getAvailableSpells() {
|
|
|
10
10
|
name: "dler-replace-line-to",
|
|
11
11
|
description: "Replaces the current line with new content, optionally based on a condition",
|
|
12
12
|
example: "// <dler-replace-line-to `export const version = \"1.0.0\";` if 'current file path starts with dist-npm'>",
|
|
13
|
-
notes: "If condition is not met and else content is provided, uses else content. Otherwise keeps original line. Also supports @ts-expect-error prefix."
|
|
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
14
|
},
|
|
15
15
|
{
|
|
16
16
|
name: "dler-remove-line",
|
|
@@ -26,13 +26,22 @@ export function getAvailableSpells() {
|
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
name: "dler-remove-comment",
|
|
29
|
-
description: "Removes the
|
|
30
|
-
example: "// <dler-remove-comment>",
|
|
31
|
-
notes: "
|
|
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."
|
|
32
38
|
}
|
|
33
39
|
];
|
|
34
40
|
}
|
|
35
41
|
export function evaluateMagicDirective(line, ctx) {
|
|
42
|
+
if (line.includes("<dler-ignore-this-line>")) {
|
|
43
|
+
return NO_OP;
|
|
44
|
+
}
|
|
36
45
|
const match = line.match(SPELL_REGEX);
|
|
37
46
|
if (!match) return NO_OP;
|
|
38
47
|
const [, directive = "", body] = match;
|
|
@@ -57,8 +66,12 @@ export function evaluateMagicDirective(line, ctx) {
|
|
|
57
66
|
/* dler-remove-comment */
|
|
58
67
|
/* -------------------------------------------------------------- */
|
|
59
68
|
case "dler-remove-comment": {
|
|
60
|
-
const
|
|
61
|
-
|
|
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;
|
|
62
75
|
}
|
|
63
76
|
/* -------------------------------------------------------------- */
|
|
64
77
|
/* dler-replace-line-to */
|
|
@@ -78,6 +91,12 @@ export function evaluateMagicDirective(line, ctx) {
|
|
|
78
91
|
}
|
|
79
92
|
return NO_OP;
|
|
80
93
|
}
|
|
94
|
+
/* -------------------------------------------------------------- */
|
|
95
|
+
/* dler-ignore-this-line */
|
|
96
|
+
/* -------------------------------------------------------------- */
|
|
97
|
+
case "dler-ignore-this-line": {
|
|
98
|
+
return NO_OP;
|
|
99
|
+
}
|
|
81
100
|
default:
|
|
82
101
|
return NO_OP;
|
|
83
102
|
}
|
|
@@ -88,7 +107,8 @@ function isValidMagicDirective(directive) {
|
|
|
88
107
|
"dler-replace-line-to",
|
|
89
108
|
"dler-remove-line",
|
|
90
109
|
"dler-remove-file",
|
|
91
|
-
"dler-remove-comment"
|
|
110
|
+
"dler-remove-comment",
|
|
111
|
+
"dler-ignore-this-line"
|
|
92
112
|
].includes(directive);
|
|
93
113
|
}
|
|
94
114
|
function parseReplacementDirective(body) {
|
|
@@ -100,8 +120,6 @@ function parseReplacementDirective(body) {
|
|
|
100
120
|
const ifMatch = body.match(IF_CONDITION_REGEX);
|
|
101
121
|
if (ifMatch?.[1]) {
|
|
102
122
|
parts.condition = ifMatch[1].trim();
|
|
103
|
-
} else {
|
|
104
|
-
parts.condition = "current file path starts with dist-jsr or dist-npm";
|
|
105
123
|
}
|
|
106
124
|
const elseMatch = body.match(ELSE_CONTENT_REGEX);
|
|
107
125
|
if (elseMatch?.[1]) parts.elseContent = elseMatch[1].trim();
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import path from "@reliverse/pathkit";
|
|
2
|
+
import { promises as fs } from "node:fs";
|
|
3
|
+
import { glob } from "tinyglobby";
|
|
4
|
+
export async function checkNoDynamicImports(directory) {
|
|
5
|
+
const startTime = Date.now();
|
|
6
|
+
const issues = [];
|
|
7
|
+
const files = await glob("**/*.{ts,tsx,js,jsx}", {
|
|
8
|
+
cwd: directory,
|
|
9
|
+
ignore: ["**/node_modules/**", "**/dist/**"]
|
|
10
|
+
});
|
|
11
|
+
for (const file of files) {
|
|
12
|
+
const filePath = path.join(directory, file);
|
|
13
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
14
|
+
const lines = content.split("\n");
|
|
15
|
+
const dynamicImportRegex = /await\s+import\s*\(/g;
|
|
16
|
+
let match;
|
|
17
|
+
while (true) {
|
|
18
|
+
match = dynamicImportRegex.exec(content);
|
|
19
|
+
if (!match) break;
|
|
20
|
+
const lineNumber = content.substring(0, match.index).split("\n").length;
|
|
21
|
+
const lineContent = lines[lineNumber - 1] ?? "";
|
|
22
|
+
const column = match.index - content.lastIndexOf("\n", match.index);
|
|
23
|
+
issues.push({
|
|
24
|
+
type: "file-extension",
|
|
25
|
+
file,
|
|
26
|
+
line: lineNumber,
|
|
27
|
+
column,
|
|
28
|
+
message: `Dynamic import found: ${lineContent.trim()}. Consider using static imports for better tree-shaking, type inference, and performance.`
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
success: issues.length === 0,
|
|
34
|
+
issues,
|
|
35
|
+
stats: {
|
|
36
|
+
filesChecked: files.length,
|
|
37
|
+
importsChecked: 0,
|
|
38
|
+
timeElapsed: Date.now() - startTime
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -59,10 +59,10 @@ export type { AllowedFileExtensionsType } from "./sdk-impl/rules/rules-consts.js
|
|
|
59
59
|
export { ALLOWED_FILE_EXTENSIONS, STRICT_FILE_EXTENSIONS, ALLOWED_IMPORT_EXTENSIONS, STRICT_IMPORT_EXTENSIONS, } from "./sdk-impl/rules/rules-consts.js";
|
|
60
60
|
export { displayCheckResults } from "./sdk-impl/rules/rules-mod.js";
|
|
61
61
|
export { shouldIgnoreFile, getAllFiles, getLineNumber } from "./sdk-impl/rules/rules-utils.js";
|
|
62
|
-
export type { ApplyMagicSpellsOptions, ApplyMagicSpellsResult, } from "./sdk-impl/magic/apply.js";
|
|
63
|
-
export { applyMagicSpells, getAllAvailableRegistries } from "./sdk-impl/magic/apply.js";
|
|
64
|
-
export type { SpellEvaluationContext, SpellOutcome, SpellDirective, } from "./sdk-impl/magic/spells.js";
|
|
65
|
-
export { evaluateMagicDirective } from "./sdk-impl/magic/spells.js";
|
|
62
|
+
export type { ApplyMagicSpellsOptions, ApplyMagicSpellsResult, } from "./sdk-impl/magic/ms-apply.js";
|
|
63
|
+
export { applyMagicSpells, getAllAvailableRegistries } from "./sdk-impl/magic/ms-apply.js";
|
|
64
|
+
export type { SpellEvaluationContext, SpellOutcome, SpellDirective, } from "./sdk-impl/magic/ms-spells.js";
|
|
65
|
+
export { evaluateMagicDirective } from "./sdk-impl/magic/ms-spells.js";
|
|
66
66
|
export { BINARY_EXTS, BINARY_SET } from "./sdk-impl/utils/b-exts.js";
|
|
67
67
|
export { isBinaryExt } from "./sdk-impl/utils/binary.js";
|
|
68
68
|
export type { CommentStyle, FileExtension, CommentMapping } from "./sdk-impl/utils/comments.js";
|
package/bin/libs/sdk/sdk-mod.js
CHANGED
|
@@ -106,8 +106,8 @@ export {
|
|
|
106
106
|
} from "./sdk-impl/rules/rules-consts.js";
|
|
107
107
|
export { displayCheckResults } from "./sdk-impl/rules/rules-mod.js";
|
|
108
108
|
export { shouldIgnoreFile, getAllFiles, getLineNumber } from "./sdk-impl/rules/rules-utils.js";
|
|
109
|
-
export { applyMagicSpells, getAllAvailableRegistries } from "./sdk-impl/magic/apply.js";
|
|
110
|
-
export { evaluateMagicDirective } from "./sdk-impl/magic/spells.js";
|
|
109
|
+
export { applyMagicSpells, getAllAvailableRegistries } from "./sdk-impl/magic/ms-apply.js";
|
|
110
|
+
export { evaluateMagicDirective } from "./sdk-impl/magic/ms-spells.js";
|
|
111
111
|
export { BINARY_EXTS, BINARY_SET } from "./sdk-impl/utils/b-exts.js";
|
|
112
112
|
export { isBinaryExt } from "./sdk-impl/utils/binary.js";
|
|
113
113
|
export { DEFAULT_COMMENT, COMMENT_MAP, getCommentPrefix } from "./sdk-impl/utils/comments.js";
|
package/package.json
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"p-all": "^5.0.0",
|
|
36
36
|
"p-map": "^7.0.3",
|
|
37
37
|
"pkg-types": "^2.1.0",
|
|
38
|
-
"postcss": "^8.5.
|
|
38
|
+
"postcss": "^8.5.5",
|
|
39
39
|
"postcss-nested": "^7.0.2",
|
|
40
40
|
"pretty-bytes": "^7.0.0",
|
|
41
41
|
"pretty-ms": "^9.2.0",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"license": "MIT",
|
|
53
53
|
"name": "@reliverse/dler",
|
|
54
54
|
"type": "module",
|
|
55
|
-
"version": "1.7.
|
|
55
|
+
"version": "1.7.25",
|
|
56
56
|
"keywords": [
|
|
57
57
|
"reliverse",
|
|
58
58
|
"cli",
|