@intlayer/config 6.1.6 → 7.0.0-canary.0
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/cjs/_virtual/rolldown_runtime.cjs +34 -0
- package/dist/cjs/alias.cjs +27 -100
- package/dist/cjs/alias.cjs.map +1 -1
- package/dist/cjs/built.cjs +7 -25
- package/dist/cjs/built.cjs.map +1 -1
- package/dist/cjs/bundleJSFile.cjs +30 -51
- package/dist/cjs/bundleJSFile.cjs.map +1 -1
- package/dist/cjs/client.cjs +19 -52
- package/dist/cjs/configFile/buildConfigurationFields.cjs +100 -657
- package/dist/cjs/configFile/buildConfigurationFields.cjs.map +1 -1
- package/dist/cjs/configFile/getConfiguration.cjs +60 -114
- package/dist/cjs/configFile/getConfiguration.cjs.map +1 -1
- package/dist/cjs/configFile/index.cjs +8 -25
- package/dist/cjs/configFile/loadConfigurationFile.cjs +22 -47
- package/dist/cjs/configFile/loadConfigurationFile.cjs.map +1 -1
- package/dist/cjs/configFile/searchConfigurationFile.cjs +49 -55
- package/dist/cjs/configFile/searchConfigurationFile.cjs.map +1 -1
- package/dist/cjs/defaultValues/build.cjs +23 -35
- package/dist/cjs/defaultValues/build.cjs.map +1 -1
- package/dist/cjs/defaultValues/content.cjs +68 -70
- package/dist/cjs/defaultValues/content.cjs.map +1 -1
- package/dist/cjs/defaultValues/editor.cjs +29 -41
- package/dist/cjs/defaultValues/editor.cjs.map +1 -1
- package/dist/cjs/defaultValues/index.cjs +62 -0
- package/dist/cjs/defaultValues/index.cjs.map +1 -0
- package/dist/cjs/defaultValues/internationalization.cjs +23 -34
- package/dist/cjs/defaultValues/internationalization.cjs.map +1 -1
- package/dist/cjs/defaultValues/log.cjs +17 -29
- package/dist/cjs/defaultValues/log.cjs.map +1 -1
- package/dist/cjs/defaultValues/routing.cjs +38 -0
- package/dist/cjs/defaultValues/routing.cjs.map +1 -0
- package/dist/cjs/extractErrorMessage.cjs +95 -0
- package/dist/cjs/extractErrorMessage.cjs.map +1 -0
- package/dist/cjs/index.cjs +67 -98
- package/dist/cjs/loadEnvFile.cjs +30 -51
- package/dist/cjs/loadEnvFile.cjs.map +1 -1
- package/dist/cjs/loadExternalFile/bundleFile.cjs +74 -0
- package/dist/cjs/loadExternalFile/bundleFile.cjs.map +1 -0
- package/dist/cjs/loadExternalFile/loadExternalFile.cjs +86 -0
- package/dist/cjs/loadExternalFile/loadExternalFile.cjs.map +1 -0
- package/dist/cjs/loadExternalFile/parseFileContent.cjs +67 -0
- package/dist/cjs/loadExternalFile/parseFileContent.cjs.map +1 -0
- package/dist/cjs/loadExternalFile/transpileTSToMJS.cjs +60 -0
- package/dist/cjs/loadExternalFile/transpileTSToMJS.cjs.map +1 -0
- package/dist/cjs/logger.cjs +124 -152
- package/dist/cjs/logger.cjs.map +1 -1
- package/dist/cjs/package.cjs +12 -0
- package/dist/cjs/package.cjs.map +1 -0
- package/dist/cjs/retryManager.cjs +42 -49
- package/dist/cjs/retryManager.cjs.map +1 -1
- package/dist/cjs/utils/ESMxCJSHelpers.cjs +24 -33
- package/dist/cjs/utils/ESMxCJSHelpers.cjs.map +1 -1
- package/dist/cjs/utils/cache.cjs +426 -0
- package/dist/cjs/utils/cache.cjs.map +1 -0
- package/dist/cjs/utils/clearModuleCache.cjs +23 -46
- package/dist/cjs/utils/clearModuleCache.cjs.map +1 -1
- package/dist/cjs/utils/extractErrorMessage.cjs +95 -0
- package/dist/cjs/utils/extractErrorMessage.cjs.map +1 -0
- package/dist/cjs/utils/getExtension.cjs +12 -35
- package/dist/cjs/utils/getExtension.cjs.map +1 -1
- package/dist/cjs/utils/getPackageJsonPath.cjs +37 -0
- package/dist/cjs/utils/getPackageJsonPath.cjs.map +1 -0
- package/dist/cjs/utils/logStack.cjs +16 -0
- package/dist/cjs/utils/logStack.cjs.map +1 -0
- package/dist/cjs/utils/normalizePath.cjs +15 -27
- package/dist/cjs/utils/normalizePath.cjs.map +1 -1
- package/dist/esm/_virtual/rolldown_runtime.mjs +17 -0
- package/dist/esm/alias.mjs +23 -74
- package/dist/esm/alias.mjs.map +1 -1
- package/dist/esm/built.mjs +5 -3
- package/dist/esm/built.mjs.map +1 -1
- package/dist/esm/bundleJSFile.mjs +26 -25
- package/dist/esm/bundleJSFile.mjs.map +1 -1
- package/dist/esm/client.mjs +4 -31
- package/dist/esm/configFile/buildConfigurationFields.mjs +97 -674
- package/dist/esm/configFile/buildConfigurationFields.mjs.map +1 -1
- package/dist/esm/configFile/getConfiguration.mjs +52 -75
- package/dist/esm/configFile/getConfiguration.mjs.map +1 -1
- package/dist/esm/configFile/index.mjs +5 -3
- package/dist/esm/configFile/loadConfigurationFile.mjs +22 -23
- package/dist/esm/configFile/loadConfigurationFile.mjs.map +1 -1
- package/dist/esm/configFile/searchConfigurationFile.mjs +45 -30
- package/dist/esm/configFile/searchConfigurationFile.mjs.map +1 -1
- package/dist/esm/defaultValues/build.mjs +16 -11
- package/dist/esm/defaultValues/build.mjs.map +1 -1
- package/dist/esm/defaultValues/content.mjs +48 -34
- package/dist/esm/defaultValues/content.mjs.map +1 -1
- package/dist/esm/defaultValues/editor.mjs +17 -11
- package/dist/esm/defaultValues/editor.mjs.map +1 -1
- package/dist/esm/defaultValues/index.mjs +21 -0
- package/dist/esm/defaultValues/index.mjs.map +1 -0
- package/dist/esm/defaultValues/internationalization.mjs +13 -7
- package/dist/esm/defaultValues/internationalization.mjs.map +1 -1
- package/dist/esm/defaultValues/log.mjs +10 -4
- package/dist/esm/defaultValues/log.mjs.map +1 -1
- package/dist/esm/defaultValues/routing.mjs +25 -0
- package/dist/esm/defaultValues/routing.mjs.map +1 -0
- package/dist/esm/extractErrorMessage.mjs +94 -0
- package/dist/esm/extractErrorMessage.mjs.map +1 -0
- package/dist/esm/index.mjs +18 -61
- package/dist/esm/loadEnvFile.mjs +27 -17
- package/dist/esm/loadEnvFile.mjs.map +1 -1
- package/dist/esm/loadExternalFile/bundleFile.mjs +68 -0
- package/dist/esm/loadExternalFile/bundleFile.mjs.map +1 -0
- package/dist/esm/loadExternalFile/loadExternalFile.mjs +81 -0
- package/dist/esm/loadExternalFile/loadExternalFile.mjs.map +1 -0
- package/dist/esm/loadExternalFile/parseFileContent.mjs +63 -0
- package/dist/esm/loadExternalFile/parseFileContent.mjs.map +1 -0
- package/dist/esm/loadExternalFile/transpileTSToMJS.mjs +55 -0
- package/dist/esm/loadExternalFile/transpileTSToMJS.mjs.map +1 -0
- package/dist/esm/logger.mjs +110 -115
- package/dist/esm/logger.mjs.map +1 -1
- package/dist/esm/package.mjs +6 -0
- package/dist/esm/package.mjs.map +1 -0
- package/dist/esm/retryManager.mjs +40 -23
- package/dist/esm/retryManager.mjs.map +1 -1
- package/dist/esm/utils/ESMxCJSHelpers.mjs +20 -6
- package/dist/esm/utils/ESMxCJSHelpers.mjs.map +1 -1
- package/dist/esm/utils/cache.mjs +414 -0
- package/dist/esm/utils/cache.mjs.map +1 -0
- package/dist/esm/utils/clearModuleCache.mjs +22 -21
- package/dist/esm/utils/clearModuleCache.mjs.map +1 -1
- package/dist/esm/utils/extractErrorMessage.mjs +94 -0
- package/dist/esm/utils/extractErrorMessage.mjs.map +1 -0
- package/dist/esm/utils/getExtension.mjs +11 -11
- package/dist/esm/utils/getExtension.mjs.map +1 -1
- package/dist/esm/utils/getPackageJsonPath.mjs +33 -0
- package/dist/esm/utils/getPackageJsonPath.mjs.map +1 -0
- package/dist/esm/utils/logStack.mjs +16 -0
- package/dist/esm/utils/logStack.mjs.map +1 -0
- package/dist/esm/utils/normalizePath.mjs +14 -3
- package/dist/esm/utils/normalizePath.mjs.map +1 -1
- package/dist/types/alias.d.ts +20 -12
- package/dist/types/alias.d.ts.map +1 -1
- package/dist/types/built.d.ts +7 -6
- package/dist/types/built.d.ts.map +1 -1
- package/dist/types/bundleJSFile.d.ts +97 -93
- package/dist/types/bundleJSFile.d.ts.map +1 -1
- package/dist/types/client.d.ts +3 -5
- package/dist/types/configFile/buildConfigurationFields.d.ts +7 -2
- package/dist/types/configFile/buildConfigurationFields.d.ts.map +1 -1
- package/dist/types/configFile/getConfiguration.d.ts +19 -15
- package/dist/types/configFile/getConfiguration.d.ts.map +1 -1
- package/dist/types/configFile/index.d.ts +4 -3
- package/dist/types/configFile/loadConfigurationFile.d.ts +8 -3
- package/dist/types/configFile/loadConfigurationFile.d.ts.map +1 -1
- package/dist/types/configFile/searchConfigurationFile.d.ts +6 -4
- package/dist/types/configFile/searchConfigurationFile.d.ts.map +1 -1
- package/dist/types/defaultValues/build.d.ts +10 -4
- package/dist/types/defaultValues/build.d.ts.map +1 -1
- package/dist/types/defaultValues/content.d.ts +23 -16
- package/dist/types/defaultValues/content.d.ts.map +1 -1
- package/dist/types/defaultValues/editor.d.ts +14 -9
- package/dist/types/defaultValues/editor.d.ts.map +1 -1
- package/dist/types/defaultValues/index.d.ts +14 -0
- package/dist/types/defaultValues/index.d.ts.map +1 -0
- package/dist/types/defaultValues/internationalization.d.ts +12 -6
- package/dist/types/defaultValues/internationalization.d.ts.map +1 -1
- package/dist/types/defaultValues/log.d.ts +7 -2
- package/dist/types/defaultValues/log.d.ts.map +1 -1
- package/dist/types/defaultValues/routing.d.ts +14 -0
- package/dist/types/defaultValues/routing.d.ts.map +1 -0
- package/dist/types/extractErrorMessage.d.ts +5 -0
- package/dist/types/extractErrorMessage.d.ts.map +1 -0
- package/dist/types/index.d.ts +21 -17
- package/dist/types/loadEnvFile.d.ts +8 -5
- package/dist/types/loadEnvFile.d.ts.map +1 -1
- package/dist/types/loadExternalFile/bundleFile.d.ts +10 -0
- package/dist/types/loadExternalFile/bundleFile.d.ts.map +1 -0
- package/dist/types/loadExternalFile/loadExternalFile.d.ts +25 -0
- package/dist/types/loadExternalFile/loadExternalFile.d.ts.map +1 -0
- package/dist/types/loadExternalFile/parseFileContent.d.ts +29 -0
- package/dist/types/loadExternalFile/parseFileContent.d.ts.map +1 -0
- package/dist/types/loadExternalFile/transpileTSToMJS.d.ts +9 -0
- package/dist/types/loadExternalFile/transpileTSToMJS.d.ts.map +1 -0
- package/dist/types/logger.d.ts +41 -37
- package/dist/types/logger.d.ts.map +1 -1
- package/dist/types/retryManager.d.ts +26 -8
- package/dist/types/retryManager.d.ts.map +1 -1
- package/dist/types/utils/ESMxCJSHelpers.d.ts +16 -2
- package/dist/types/utils/ESMxCJSHelpers.d.ts.map +1 -1
- package/dist/types/utils/cache.d.ts +50 -0
- package/dist/types/utils/cache.d.ts.map +1 -0
- package/dist/types/utils/clearModuleCache.d.ts +4 -1
- package/dist/types/utils/clearModuleCache.d.ts.map +1 -1
- package/dist/types/utils/extractErrorMessage.d.ts +5 -0
- package/dist/types/utils/extractErrorMessage.d.ts.map +1 -0
- package/dist/types/utils/getExtension.d.ts +6 -2
- package/dist/types/utils/getExtension.d.ts.map +1 -1
- package/dist/types/utils/getPackageJsonPath.d.ts +10 -0
- package/dist/types/utils/getPackageJsonPath.d.ts.map +1 -0
- package/dist/types/utils/logStack.d.ts +7 -0
- package/dist/types/utils/logStack.d.ts.map +1 -0
- package/dist/types/utils/normalizePath.d.ts +4 -1
- package/dist/types/utils/normalizePath.d.ts.map +1 -1
- package/package.json +40 -35
- package/LICENSE +0 -202
- package/dist/cjs/client.cjs.map +0 -1
- package/dist/cjs/configFile/index.cjs.map +0 -1
- package/dist/cjs/defaultValues/middleware.cjs +0 -47
- package/dist/cjs/defaultValues/middleware.cjs.map +0 -1
- package/dist/cjs/getSandboxContext.cjs +0 -64
- package/dist/cjs/getSandboxContext.cjs.map +0 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/loadExternalFile.cjs +0 -105
- package/dist/cjs/loadExternalFile.cjs.map +0 -1
- package/dist/cjs/types/config.cjs +0 -17
- package/dist/cjs/types/config.cjs.map +0 -1
- package/dist/cjs/types/locales.cjs +0 -310
- package/dist/cjs/types/locales.cjs.map +0 -1
- package/dist/esm/client.mjs.map +0 -1
- package/dist/esm/configFile/index.mjs.map +0 -1
- package/dist/esm/defaultValues/middleware.mjs +0 -17
- package/dist/esm/defaultValues/middleware.mjs.map +0 -1
- package/dist/esm/getSandboxContext.mjs +0 -40
- package/dist/esm/getSandboxContext.mjs.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/loadExternalFile.mjs +0 -81
- package/dist/esm/loadExternalFile.mjs.map +0 -1
- package/dist/esm/types/config.mjs +0 -1
- package/dist/esm/types/config.mjs.map +0 -1
- package/dist/esm/types/locales.mjs +0 -286
- package/dist/esm/types/locales.mjs.map +0 -1
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/configFile/index.d.ts.map +0 -1
- package/dist/types/defaultValues/middleware.d.ts +0 -8
- package/dist/types/defaultValues/middleware.d.ts.map +0 -1
- package/dist/types/getSandboxContext.d.ts +0 -4
- package/dist/types/getSandboxContext.d.ts.map +0 -1
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/loadExternalFile.d.ts +0 -8
- package/dist/types/loadExternalFile.d.ts.map +0 -1
- package/dist/types/types/config.d.ts +0 -659
- package/dist/types/types/config.d.ts.map +0 -1
- package/dist/types/types/locales.d.ts +0 -564
- package/dist/types/types/locales.d.ts.map +0 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/extractErrorMessage.ts
|
|
3
|
+
const extractErrorMessage = (error) => {
|
|
4
|
+
const trimToSingleLine = (text) => text.split(/\r?\n/).map((s) => s.trim()).filter(Boolean)[0] ?? text.trim();
|
|
5
|
+
const looksLikeJson = (value) => {
|
|
6
|
+
const s = value.trim();
|
|
7
|
+
if (!s) return false;
|
|
8
|
+
const first = s[0];
|
|
9
|
+
return first === "{" || first === "[" || first === "\"";
|
|
10
|
+
};
|
|
11
|
+
const sanitizeUnexpectedTokenMessage = (text) => {
|
|
12
|
+
const t = text.trim();
|
|
13
|
+
if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {
|
|
14
|
+
const quoted = t.match(/"([^"]+)"/);
|
|
15
|
+
if (quoted?.[1]) return quoted[1];
|
|
16
|
+
const afterColon = t.split(":").slice(1).join(":").trim();
|
|
17
|
+
if (afterColon) return afterColon;
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
const pickFieldsFromObject = (value, seen) => {
|
|
22
|
+
if (!value || typeof value !== "object") return void 0;
|
|
23
|
+
if (seen.has(value)) return void 0;
|
|
24
|
+
seen.add(value);
|
|
25
|
+
const obj = value;
|
|
26
|
+
if (typeof obj.message === "string" && obj.message.trim()) return obj.message;
|
|
27
|
+
if (typeof obj.error_description === "string" && obj.error_description.trim()) return obj.error_description;
|
|
28
|
+
if (typeof obj.error === "string" && obj.error.trim()) return obj.error;
|
|
29
|
+
const title = typeof obj.title === "string" ? obj.title.trim() : "";
|
|
30
|
+
const code = typeof obj.code === "string" ? obj.code.trim() : "";
|
|
31
|
+
if (title && code) return `${title} (${code})`;
|
|
32
|
+
if (title) return title;
|
|
33
|
+
if (code) return code;
|
|
34
|
+
if (typeof obj.statusText === "string" && obj.statusText.trim()) return obj.statusText;
|
|
35
|
+
const response = obj.response;
|
|
36
|
+
if (response && typeof response === "object") {
|
|
37
|
+
const data$1 = response.data;
|
|
38
|
+
const fromData$1 = pickFieldsFromObject(data$1, seen);
|
|
39
|
+
if (fromData$1) return fromData$1;
|
|
40
|
+
}
|
|
41
|
+
const data = obj.data;
|
|
42
|
+
const fromData = pickFieldsFromObject(data, seen);
|
|
43
|
+
if (fromData) return fromData;
|
|
44
|
+
const cause = obj.cause;
|
|
45
|
+
const fromCause = pickFieldsFromObject(cause, seen) ?? (typeof cause?.message === "string" ? cause.message : void 0);
|
|
46
|
+
if (fromCause) return fromCause;
|
|
47
|
+
const errors = obj.errors;
|
|
48
|
+
if (Array.isArray(errors)) for (const item of errors) {
|
|
49
|
+
const fromItem = pickFieldsFromObject(item, seen);
|
|
50
|
+
if (fromItem) return fromItem;
|
|
51
|
+
if (typeof item?.message === "string") return item.message;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const tryParseJsonString = (maybeJson) => {
|
|
55
|
+
if (!looksLikeJson(maybeJson)) return void 0;
|
|
56
|
+
try {
|
|
57
|
+
const parsed = JSON.parse(maybeJson);
|
|
58
|
+
const picked = pickFieldsFromObject(parsed, /* @__PURE__ */ new Set());
|
|
59
|
+
if (picked) return picked;
|
|
60
|
+
if (typeof parsed === "string") return parsed;
|
|
61
|
+
return;
|
|
62
|
+
} catch {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
if (typeof error === "string") {
|
|
67
|
+
const cleaned = sanitizeUnexpectedTokenMessage(error);
|
|
68
|
+
return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);
|
|
69
|
+
}
|
|
70
|
+
if (error && typeof error === "object") {
|
|
71
|
+
if (error instanceof Error) {
|
|
72
|
+
const cleaned = sanitizeUnexpectedTokenMessage(error.message);
|
|
73
|
+
const fromMessage = tryParseJsonString(cleaned);
|
|
74
|
+
if (fromMessage) return trimToSingleLine(fromMessage);
|
|
75
|
+
const fromCause = extractErrorMessage(error.cause);
|
|
76
|
+
if (fromCause && fromCause !== "An unknown error occurred") return trimToSingleLine(fromCause);
|
|
77
|
+
return trimToSingleLine(cleaned);
|
|
78
|
+
}
|
|
79
|
+
const fromObject = pickFieldsFromObject(error, /* @__PURE__ */ new Set());
|
|
80
|
+
if (fromObject) {
|
|
81
|
+
const cleaned = sanitizeUnexpectedTokenMessage(fromObject);
|
|
82
|
+
return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
return trimToSingleLine(JSON.stringify(error));
|
|
86
|
+
} catch {
|
|
87
|
+
return trimToSingleLine(String(error));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return "An unknown error occurred";
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
exports.extractErrorMessage = extractErrorMessage;
|
|
95
|
+
//# sourceMappingURL=extractErrorMessage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extractErrorMessage.cjs","names":["data","fromData"],"sources":["../../src/extractErrorMessage.ts"],"sourcesContent":["export const extractErrorMessage = (error: unknown): string => {\n const trimToSingleLine = (text: string): string =>\n text\n .split(/\\r?\\n/)\n .map((s) => s.trim())\n .filter(Boolean)[0] ?? text.trim();\n\n const looksLikeJson = (value: string): boolean => {\n const s = value.trim();\n if (!s) return false;\n const first = s[0];\n return first === '{' || first === '[' || first === '\"';\n };\n\n const sanitizeUnexpectedTokenMessage = (text: string): string => {\n // If the text mentions an invalid JSON parse, try to extract the meaningful part\n const t = text.trim();\n if (/Unexpected token/i.test(t) && /not valid JSON/i.test(t)) {\n const quoted = t.match(/\"([^\"]+)\"/);\n if (quoted?.[1]) return quoted[1];\n // Fallback: drop the leading parser error description\n const afterColon = t.split(':').slice(1).join(':').trim();\n if (afterColon) return afterColon;\n }\n return t;\n };\n\n const pickFieldsFromObject = (\n value: unknown,\n seen: Set<unknown>\n ): string | undefined => {\n if (!value || typeof value !== 'object') return undefined;\n if (seen.has(value)) return undefined;\n seen.add(value);\n\n const obj = value as Record<string, unknown>;\n\n // Check for message first (highest priority)\n if (typeof obj.message === 'string' && obj.message.trim()) {\n return obj.message;\n }\n\n // Check for error_description\n if (\n typeof obj.error_description === 'string' &&\n obj.error_description.trim()\n ) {\n return obj.error_description;\n }\n\n // Check for error\n if (typeof obj.error === 'string' && obj.error.trim()) {\n return obj.error;\n }\n\n // Handle title and code combination\n const title = typeof obj.title === 'string' ? obj.title.trim() : '';\n const code = typeof obj.code === 'string' ? obj.code.trim() : '';\n\n if (title && code) {\n return `${title} (${code})`;\n }\n\n if (title) {\n return title;\n }\n\n if (code) {\n return code;\n }\n\n // Check for statusText\n if (typeof obj.statusText === 'string' && obj.statusText.trim()) {\n return obj.statusText;\n }\n\n // Common nested structures (Axios/Fetch-like)\n const response = obj.response as Record<string, unknown> | undefined;\n if (response && typeof response === 'object') {\n const data = response.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n if (fromData) return fromData;\n }\n\n const data = obj.data as unknown;\n const fromData = pickFieldsFromObject(data, seen);\n if (fromData) return fromData;\n\n // Nested cause chain\n const cause = (obj as { cause?: unknown }).cause;\n const fromCause =\n pickFieldsFromObject(cause, seen) ??\n (typeof (cause as any)?.message === 'string'\n ? (cause as any).message\n : undefined);\n if (fromCause) return fromCause;\n\n // Arrays of errors\n const errors = obj.errors as unknown;\n if (Array.isArray(errors)) {\n for (const item of errors) {\n const fromItem = pickFieldsFromObject(item, seen);\n if (fromItem) return fromItem;\n if (typeof (item as any)?.message === 'string')\n return (item as any).message;\n }\n }\n\n return undefined;\n };\n\n const tryParseJsonString = (maybeJson: string): string | undefined => {\n if (!looksLikeJson(maybeJson)) return undefined;\n try {\n const parsed = JSON.parse(maybeJson);\n const picked = pickFieldsFromObject(parsed, new Set());\n if (picked) return picked;\n if (typeof parsed === 'string') return parsed;\n return undefined;\n } catch {\n return undefined;\n }\n };\n\n if (typeof error === 'string') {\n const cleaned = sanitizeUnexpectedTokenMessage(error);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n if (error && typeof error === 'object') {\n // Native Error instance\n if (error instanceof Error) {\n const cleaned = sanitizeUnexpectedTokenMessage(error.message);\n const fromMessage = tryParseJsonString(cleaned);\n if (fromMessage) return trimToSingleLine(fromMessage);\n // Dive into cause when present\n const fromCause = extractErrorMessage(error.cause as unknown);\n if (fromCause && fromCause !== 'An unknown error occurred')\n return trimToSingleLine(fromCause);\n return trimToSingleLine(cleaned);\n }\n\n // Generic object\n const seen = new Set<unknown>();\n const fromObject = pickFieldsFromObject(error, seen);\n if (fromObject) {\n const cleaned = sanitizeUnexpectedTokenMessage(fromObject);\n return tryParseJsonString(cleaned) ?? trimToSingleLine(cleaned);\n }\n\n try {\n const serialized = JSON.stringify(error);\n return trimToSingleLine(serialized);\n } catch {\n return trimToSingleLine(String(error));\n }\n }\n\n return 'An unknown error occurred';\n};\n"],"mappings":"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"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,100 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
const require_utils_getExtension = require('./utils/getExtension.cjs');
|
|
2
|
+
const require_utils_normalizePath = require('./utils/normalizePath.cjs');
|
|
3
|
+
const require_alias = require('./alias.cjs');
|
|
4
|
+
const require_logger = require('./logger.cjs');
|
|
5
|
+
const require_utils_cache = require('./utils/cache.cjs');
|
|
6
|
+
const require_utils_getPackageJsonPath = require('./utils/getPackageJsonPath.cjs');
|
|
7
|
+
const require_utils_ESMxCJSHelpers = require('./utils/ESMxCJSHelpers.cjs');
|
|
8
|
+
const require_configFile_buildConfigurationFields = require('./configFile/buildConfigurationFields.cjs');
|
|
9
|
+
const require_loadEnvFile = require('./loadEnvFile.cjs');
|
|
10
|
+
const require_loadExternalFile_parseFileContent = require('./loadExternalFile/parseFileContent.cjs');
|
|
11
|
+
const require_loadExternalFile_bundleFile = require('./loadExternalFile/bundleFile.cjs');
|
|
12
|
+
const require_loadExternalFile_loadExternalFile = require('./loadExternalFile/loadExternalFile.cjs');
|
|
13
|
+
const require_configFile_searchConfigurationFile = require('./configFile/searchConfigurationFile.cjs');
|
|
14
|
+
const require_configFile_getConfiguration = require('./configFile/getConfiguration.cjs');
|
|
15
|
+
const require_bundleJSFile = require('./bundleJSFile.cjs');
|
|
16
|
+
const require_defaultValues_index = require('./defaultValues/index.cjs');
|
|
17
|
+
const require_utils_extractErrorMessage = require('./utils/extractErrorMessage.cjs');
|
|
18
|
+
const require_retryManager = require('./retryManager.cjs');
|
|
19
|
+
const require_utils_clearModuleCache = require('./utils/clearModuleCache.cjs');
|
|
20
|
+
const require_utils_logStack = require('./utils/logStack.cjs');
|
|
21
|
+
|
|
22
|
+
exports.ANSIColors = require_logger.ANSIColors;
|
|
23
|
+
Object.defineProperty(exports, 'DefaultValues', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return require_defaultValues_index.defaultValues_exports;
|
|
15
27
|
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var index_exports = {};
|
|
20
|
-
__export(index_exports, {
|
|
21
|
-
ANSIColors: () => import_logger.ANSIColors,
|
|
22
|
-
ESMxCJSRequire: () => import_ESMxCJSHelpers.ESMxCJSRequire,
|
|
23
|
-
Locales: () => import_locales.Locales,
|
|
24
|
-
bundleJSFile: () => import_bundleJSFile.bundleJSFile,
|
|
25
|
-
clearModuleCache: () => import_clearModuleCache.clearModuleCache,
|
|
26
|
-
clock: () => import_logger.clock,
|
|
27
|
-
colon: () => import_logger.colon,
|
|
28
|
-
colorize: () => import_logger.colorize,
|
|
29
|
-
colorizeKey: () => import_logger.colorizeKey,
|
|
30
|
-
colorizeLocales: () => import_logger.colorizeLocales,
|
|
31
|
-
colorizeNumber: () => import_logger.colorizeNumber,
|
|
32
|
-
colorizePath: () => import_logger.colorizePath,
|
|
33
|
-
getAlias: () => import_alias.getAlias,
|
|
34
|
-
getAppLogger: () => import_logger.getAppLogger,
|
|
35
|
-
getConfiguration: () => import_getConfiguration.getConfiguration,
|
|
36
|
-
getConfigurationAndFilePath: () => import_getConfiguration.getConfigurationAndFilePath,
|
|
37
|
-
getEnvFilePath: () => import_loadEnvFile.getEnvFilePath,
|
|
38
|
-
getExtension: () => import_getExtension.getExtension,
|
|
39
|
-
getSandBoxContext: () => import_getSandboxContext.getSandBoxContext,
|
|
40
|
-
isESModule: () => import_ESMxCJSHelpers.isESModule,
|
|
41
|
-
loadEnvFile: () => import_loadEnvFile.loadEnvFile,
|
|
42
|
-
loadExternalFile: () => import_loadExternalFile.loadExternalFile,
|
|
43
|
-
logger: () => import_logger.logger,
|
|
44
|
-
normalizePath: () => import_normalizePath.normalizePath,
|
|
45
|
-
removeColor: () => import_logger.removeColor,
|
|
46
|
-
retryManager: () => import_retryManager.retryManager,
|
|
47
|
-
searchConfigurationFile: () => import_searchConfigurationFile.searchConfigurationFile,
|
|
48
|
-
spinnerFrames: () => import_logger.spinnerFrames,
|
|
49
|
-
v: () => import_logger.v,
|
|
50
|
-
x: () => import_logger.x
|
|
51
28
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
removeColor,
|
|
94
|
-
retryManager,
|
|
95
|
-
searchConfigurationFile,
|
|
96
|
-
spinnerFrames,
|
|
97
|
-
v,
|
|
98
|
-
x
|
|
99
|
-
});
|
|
100
|
-
//# sourceMappingURL=index.cjs.map
|
|
29
|
+
exports.ESMxCJSRequire = require_utils_ESMxCJSHelpers.ESMxCJSRequire;
|
|
30
|
+
exports.buildConfigurationFields = require_configFile_buildConfigurationFields.buildConfigurationFields;
|
|
31
|
+
exports.bundleFile = require_loadExternalFile_bundleFile.bundleFile;
|
|
32
|
+
exports.bundleFileSync = require_loadExternalFile_bundleFile.bundleFileSync;
|
|
33
|
+
exports.bundleJSFile = require_bundleJSFile.bundleJSFile;
|
|
34
|
+
exports.cache = require_utils_cache.cache;
|
|
35
|
+
exports.clearCache = require_utils_cache.clearCache;
|
|
36
|
+
exports.clearModuleCache = require_utils_clearModuleCache.clearModuleCache;
|
|
37
|
+
exports.clock = require_logger.clock;
|
|
38
|
+
exports.colon = require_logger.colon;
|
|
39
|
+
exports.colorize = require_logger.colorize;
|
|
40
|
+
exports.colorizeKey = require_logger.colorizeKey;
|
|
41
|
+
exports.colorizeLocales = require_logger.colorizeLocales;
|
|
42
|
+
exports.colorizeNumber = require_logger.colorizeNumber;
|
|
43
|
+
exports.colorizePath = require_logger.colorizePath;
|
|
44
|
+
exports.configESMxCJSRequire = require_utils_ESMxCJSHelpers.configESMxCJSRequire;
|
|
45
|
+
exports.extractErrorMessage = require_utils_extractErrorMessage.extractErrorMessage;
|
|
46
|
+
exports.getAlias = require_alias.getAlias;
|
|
47
|
+
exports.getAppLogger = require_logger.getAppLogger;
|
|
48
|
+
exports.getCache = require_utils_cache.getCache;
|
|
49
|
+
exports.getConfiguration = require_configFile_getConfiguration.getConfiguration;
|
|
50
|
+
exports.getConfigurationAndFilePath = require_configFile_getConfiguration.getConfigurationAndFilePath;
|
|
51
|
+
exports.getEnvFilePath = require_loadEnvFile.getEnvFilePath;
|
|
52
|
+
exports.getExtension = require_utils_getExtension.getExtension;
|
|
53
|
+
exports.getPackageJsonPath = require_utils_getPackageJsonPath.getPackageJsonPath;
|
|
54
|
+
exports.isESModule = require_utils_ESMxCJSHelpers.isESModule;
|
|
55
|
+
exports.loadEnvFile = require_loadEnvFile.loadEnvFile;
|
|
56
|
+
exports.loadExternalFile = require_loadExternalFile_loadExternalFile.loadExternalFile;
|
|
57
|
+
exports.loadExternalFileSync = require_loadExternalFile_loadExternalFile.loadExternalFileSync;
|
|
58
|
+
exports.localCache = require_utils_cache.localCache;
|
|
59
|
+
exports.logStack = require_utils_logStack.logStack;
|
|
60
|
+
exports.logger = require_logger.logger;
|
|
61
|
+
exports.normalizePath = require_utils_normalizePath.normalizePath;
|
|
62
|
+
exports.parseFileContent = require_loadExternalFile_parseFileContent.parseFileContent;
|
|
63
|
+
exports.removeColor = require_logger.removeColor;
|
|
64
|
+
exports.retryManager = require_retryManager.retryManager;
|
|
65
|
+
exports.searchConfigurationFile = require_configFile_searchConfigurationFile.searchConfigurationFile;
|
|
66
|
+
exports.setCache = require_utils_cache.setCache;
|
|
67
|
+
exports.spinnerFrames = require_logger.spinnerFrames;
|
|
68
|
+
exports.v = require_logger.v;
|
|
69
|
+
exports.x = require_logger.x;
|
package/dist/cjs/loadEnvFile.cjs
CHANGED
|
@@ -1,57 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var loadEnvFile_exports = {};
|
|
30
|
-
__export(loadEnvFile_exports, {
|
|
31
|
-
getEnvFilePath: () => getEnvFilePath,
|
|
32
|
-
loadEnvFile: () => loadEnvFile
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(loadEnvFile_exports);
|
|
35
|
-
var import_dotenv = __toESM(require("dotenv"));
|
|
36
|
-
var import_fs = require("fs");
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_fs = require("node:fs");
|
|
3
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
4
|
+
let dotenv = require("dotenv");
|
|
5
|
+
dotenv = require_rolldown_runtime.__toESM(dotenv);
|
|
6
|
+
|
|
7
|
+
//#region src/loadEnvFile.ts
|
|
37
8
|
const DEFAULT_ENV = process.env.NODE_ENV ?? "development";
|
|
38
9
|
const getEnvFilePath = (env = process.env.NODE_ENV ?? "development", envFile) => {
|
|
39
|
-
|
|
40
|
-
|
|
10
|
+
return (envFile ? [envFile] : [
|
|
11
|
+
`.env.${env}.local`,
|
|
12
|
+
`.env.${env}`,
|
|
13
|
+
".env.local",
|
|
14
|
+
".env"
|
|
15
|
+
]).find(node_fs.existsSync);
|
|
41
16
|
};
|
|
42
17
|
const loadEnvFile = (options) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
18
|
+
const env = options?.env ?? DEFAULT_ENV;
|
|
19
|
+
const envFiles = options?.envFile ? [options.envFile] : [
|
|
20
|
+
`.env.${env}.local`,
|
|
21
|
+
`.env.${env}`,
|
|
22
|
+
".env.local",
|
|
23
|
+
".env"
|
|
24
|
+
];
|
|
25
|
+
const result = {};
|
|
26
|
+
dotenv.default.config({
|
|
27
|
+
path: envFiles,
|
|
28
|
+
processEnv: result
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
51
31
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
});
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.getEnvFilePath = getEnvFilePath;
|
|
35
|
+
exports.loadEnvFile = loadEnvFile;
|
|
57
36
|
//# sourceMappingURL=loadEnvFile.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/loadEnvFile.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"loadEnvFile.cjs","names":["existsSync"],"sources":["../../src/loadEnvFile.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport dotenv from 'dotenv';\n\nconst DEFAULT_ENV = process.env.NODE_ENV ?? 'development';\n\nexport type LoadEnvFileOptions = {\n env?: string;\n envFile?: string;\n};\n\nexport const getEnvFilePath = (\n env: string = process.env.NODE_ENV ?? 'development',\n envFile?: string\n): string | undefined => {\n const envFiles = envFile\n ? [envFile]\n : [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env'];\n\n return envFiles.find(existsSync); // Returns the first existing env file\n};\n\nexport const loadEnvFile = (options?: Partial<LoadEnvFileOptions>) => {\n const env = options?.env ?? DEFAULT_ENV;\n\n const envFiles = options?.envFile\n ? [options.envFile]\n : [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env'];\n\n const result = {};\n\n dotenv.config({\n path: envFiles,\n processEnv: result,\n });\n\n return result; // Return the parsed env object\n};\n"],"mappings":";;;;;;;AAGA,MAAM,cAAc,QAAQ,IAAI,YAAY;AAO5C,MAAa,kBACX,MAAc,QAAQ,IAAI,YAAY,eACtC,YACuB;AAKvB,SAJiB,UACb,CAAC,QAAQ,GACT;EAAC,QAAQ,IAAI;EAAS,QAAQ;EAAO;EAAc;EAAO,EAE9C,KAAKA,mBAAW;;AAGlC,MAAa,eAAe,YAA0C;CACpE,MAAM,MAAM,SAAS,OAAO;CAE5B,MAAM,WAAW,SAAS,UACtB,CAAC,QAAQ,QAAQ,GACjB;EAAC,QAAQ,IAAI;EAAS,QAAQ;EAAO;EAAc;EAAO;CAE9D,MAAM,SAAS,EAAE;AAEjB,gBAAO,OAAO;EACZ,MAAM;EACN,YAAY;EACb,CAAC;AAEF,QAAO"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
4
|
+
let esbuild = require("esbuild");
|
|
5
|
+
esbuild = require_rolldown_runtime.__toESM(esbuild);
|
|
6
|
+
let node_url = require("node:url");
|
|
7
|
+
node_url = require_rolldown_runtime.__toESM(node_url);
|
|
8
|
+
|
|
9
|
+
//#region src/loadExternalFile/bundleFile.ts
|
|
10
|
+
const getLoader = (extension) => {
|
|
11
|
+
switch (extension) {
|
|
12
|
+
case ".js": return "js";
|
|
13
|
+
case ".jsx": return "jsx";
|
|
14
|
+
case ".mjs": return "js";
|
|
15
|
+
case ".ts": return "ts";
|
|
16
|
+
case ".tsx": return "tsx";
|
|
17
|
+
case ".cjs": return "js";
|
|
18
|
+
case ".json": return "json";
|
|
19
|
+
case ".md": return "text";
|
|
20
|
+
case ".mdx": return "text";
|
|
21
|
+
default: return "js";
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const getTransformationOptions = (filePath) => ({
|
|
25
|
+
loader: {
|
|
26
|
+
".js": "js",
|
|
27
|
+
".jsx": "jsx",
|
|
28
|
+
".mjs": "js",
|
|
29
|
+
".ts": "ts",
|
|
30
|
+
".tsx": "tsx",
|
|
31
|
+
".cjs": "js",
|
|
32
|
+
".json": "json",
|
|
33
|
+
".md": "text",
|
|
34
|
+
".mdx": "text"
|
|
35
|
+
},
|
|
36
|
+
format: "cjs",
|
|
37
|
+
target: "node16",
|
|
38
|
+
platform: "neutral",
|
|
39
|
+
write: false,
|
|
40
|
+
packages: "bundle",
|
|
41
|
+
external: ["esbuild"],
|
|
42
|
+
bundle: true,
|
|
43
|
+
define: { "import.meta.url": JSON.stringify((0, node_url.pathToFileURL)(filePath).href) }
|
|
44
|
+
});
|
|
45
|
+
const bundleFileSync = (code, filePath, options) => {
|
|
46
|
+
return (0, esbuild.buildSync)({
|
|
47
|
+
stdin: {
|
|
48
|
+
contents: code,
|
|
49
|
+
loader: getLoader((0, node_path.extname)(filePath)),
|
|
50
|
+
resolveDir: (0, node_path.dirname)(filePath),
|
|
51
|
+
sourcefile: filePath
|
|
52
|
+
},
|
|
53
|
+
...getTransformationOptions(filePath),
|
|
54
|
+
...options
|
|
55
|
+
}).outputFiles?.[0].text;
|
|
56
|
+
};
|
|
57
|
+
const bundleFile = async (code, filePath, options) => {
|
|
58
|
+
return (await (0, esbuild.build)({
|
|
59
|
+
stdin: {
|
|
60
|
+
contents: code,
|
|
61
|
+
loader: getLoader((0, node_path.extname)(filePath)),
|
|
62
|
+
resolveDir: (0, node_path.dirname)(filePath),
|
|
63
|
+
sourcefile: filePath
|
|
64
|
+
},
|
|
65
|
+
...getTransformationOptions(filePath),
|
|
66
|
+
...options
|
|
67
|
+
})).outputFiles?.[0].text;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.bundleFile = bundleFile;
|
|
72
|
+
exports.bundleFileSync = bundleFileSync;
|
|
73
|
+
exports.getLoader = getLoader;
|
|
74
|
+
//# sourceMappingURL=bundleFile.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleFile.cjs","names":[],"sources":["../../../src/loadExternalFile/bundleFile.ts"],"sourcesContent":["import { dirname, extname } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport {\n type BuildOptions,\n type BuildResult,\n build,\n buildSync,\n type Loader,\n type Plugin,\n} from 'esbuild';\n\nexport type ESBuildPlugin = Plugin;\n\nexport const getLoader = (extension: string): Loader => {\n switch (extension) {\n case '.js':\n return 'js';\n case '.jsx':\n return 'jsx';\n case '.mjs':\n return 'js';\n case '.ts':\n return 'ts';\n case '.tsx':\n return 'tsx';\n case '.cjs':\n return 'js';\n case '.json':\n return 'json';\n case '.md':\n return 'text';\n case '.mdx':\n return 'text';\n default:\n return 'js';\n }\n};\n\nconst getTransformationOptions = (filePath: string): BuildOptions => ({\n loader: {\n '.js': 'js',\n '.jsx': 'jsx',\n '.mjs': 'js',\n '.ts': 'ts',\n '.tsx': 'tsx',\n '.cjs': 'js',\n '.json': 'json',\n '.md': 'text',\n '.mdx': 'text',\n },\n format: 'cjs',\n target: 'node16',\n platform: 'neutral',\n write: false,\n packages: 'bundle',\n external: ['esbuild'],\n bundle: true,\n define: {\n 'import.meta.url': JSON.stringify(pathToFileURL(filePath).href),\n },\n});\n\nexport const bundleFileSync = (\n code: string,\n filePath: string,\n options?: BuildOptions\n): string | undefined => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = buildSync({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n\nexport const bundleFile = async (\n code: string,\n filePath: string,\n options?: BuildOptions\n): Promise<string | undefined> => {\n const extension = extname(filePath);\n const loader = getLoader(extension);\n\n const moduleResult: BuildResult = await build({\n stdin: {\n contents: code,\n loader,\n resolveDir: dirname(filePath), // Add resolveDir to resolve imports relative to the file's location\n sourcefile: filePath, // Add sourcefile for better error messages\n },\n ...getTransformationOptions(filePath),\n ...options,\n });\n\n const moduleResultString = moduleResult.outputFiles?.[0].text;\n\n return moduleResultString;\n};\n"],"mappings":";;;;;;;;;AAaA,MAAa,aAAa,cAA8B;AACtD,SAAQ,WAAR;EACE,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,KAAK,QACH,QAAO;EACT,KAAK,MACH,QAAO;EACT,KAAK,OACH,QAAO;EACT,QACE,QAAO;;;AAIb,MAAM,4BAA4B,cAAoC;CACpE,QAAQ;EACN,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,OAAO;EACP,QAAQ;EACR,QAAQ;EACR,SAAS;EACT,OAAO;EACP,QAAQ;EACT;CACD,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,OAAO;CACP,UAAU;CACV,UAAU,CAAC,UAAU;CACrB,QAAQ;CACR,QAAQ,EACN,mBAAmB,KAAK,sCAAwB,SAAS,CAAC,KAAK,EAChE;CACF;AAED,MAAa,kBACX,MACA,UACA,YACuB;AAiBvB,+BAb4C;EAC1C,OAAO;GACL,UAAU;GACV,QALW,iCADW,SAAS,CACA;GAM/B,mCAAoB,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,CAEsC,cAAc,GAAG;;AAK3D,MAAa,aAAa,OACxB,MACA,UACA,YACgC;AAiBhC,SAbkC,yBAAY;EAC5C,OAAO;GACL,UAAU;GACV,QALW,iCADW,SAAS,CACA;GAM/B,mCAAoB,SAAS;GAC7B,YAAY;GACb;EACD,GAAG,yBAAyB,SAAS;EACrC,GAAG;EACJ,CAAC,EAEsC,cAAc,GAAG"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_logger = require('../logger.cjs');
|
|
3
|
+
const require_utils_ESMxCJSHelpers = require('../utils/ESMxCJSHelpers.cjs');
|
|
4
|
+
const require_loadExternalFile_parseFileContent = require('./parseFileContent.cjs');
|
|
5
|
+
const require_loadExternalFile_transpileTSToMJS = require('./transpileTSToMJS.cjs');
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
8
|
+
let node_fs_promises = require("node:fs/promises");
|
|
9
|
+
node_fs_promises = require_rolldown_runtime.__toESM(node_fs_promises);
|
|
10
|
+
let node_fs = require("node:fs");
|
|
11
|
+
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
12
|
+
|
|
13
|
+
//#region src/loadExternalFile/loadExternalFile.ts
|
|
14
|
+
/**
|
|
15
|
+
* Load the content declaration from the given path
|
|
16
|
+
*
|
|
17
|
+
* Accepts JSON, JS, MJS and TS files as configuration
|
|
18
|
+
*/
|
|
19
|
+
const loadExternalFileSync = (filePath, options) => {
|
|
20
|
+
const fileExtension = (0, node_path.extname)(filePath);
|
|
21
|
+
const safeProjectRequire = options?.projectRequire ?? require_utils_ESMxCJSHelpers.ESMxCJSRequire;
|
|
22
|
+
try {
|
|
23
|
+
if (fileExtension === "json") {
|
|
24
|
+
delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];
|
|
25
|
+
return safeProjectRequire(filePath);
|
|
26
|
+
}
|
|
27
|
+
const moduleResultString = require_loadExternalFile_transpileTSToMJS.transpileTSToMJSSync((0, node_fs.readFileSync)(filePath, "utf-8"), filePath);
|
|
28
|
+
if (!moduleResultString) {
|
|
29
|
+
require_logger.logger("File could not be loaded.", { level: "error" });
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const fileContent = require_loadExternalFile_parseFileContent.parseFileContent(moduleResultString, {
|
|
33
|
+
projectRequire: options?.projectRequire,
|
|
34
|
+
envVarOptions: options?.envVarOptions,
|
|
35
|
+
additionalEnvVars: options?.additionalEnvVars,
|
|
36
|
+
mocks: options?.mocks,
|
|
37
|
+
aliases: options?.aliases
|
|
38
|
+
});
|
|
39
|
+
if (typeof fileContent === "undefined") {
|
|
40
|
+
require_logger.logger(`File file could not be loaded. Path : ${filePath}`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
return fileContent;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
require_logger.logger([`Error: ${error.message} - `, JSON.stringify(error.stack, null, 2)], { level: "error" });
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Load the content declaration from the given path
|
|
50
|
+
*
|
|
51
|
+
* Accepts JSON, JS, MJS and TS files as configuration
|
|
52
|
+
*/
|
|
53
|
+
const loadExternalFile = async (filePath, options) => {
|
|
54
|
+
const fileExtension = (0, node_path.extname)(filePath);
|
|
55
|
+
const safeProjectRequire = options?.projectRequire ?? require_utils_ESMxCJSHelpers.ESMxCJSRequire;
|
|
56
|
+
try {
|
|
57
|
+
if (fileExtension === "json") {
|
|
58
|
+
delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];
|
|
59
|
+
return safeProjectRequire(filePath);
|
|
60
|
+
}
|
|
61
|
+
const moduleResultString = await require_loadExternalFile_transpileTSToMJS.transpileTSToMJS(await (0, node_fs_promises.readFile)(filePath, "utf-8"), filePath, options?.buildOptions);
|
|
62
|
+
if (!moduleResultString) {
|
|
63
|
+
require_logger.logger("File could not be loaded.", { level: "error" });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const fileContent = require_loadExternalFile_parseFileContent.parseFileContent(moduleResultString, {
|
|
67
|
+
projectRequire: options?.projectRequire,
|
|
68
|
+
envVarOptions: options?.envVarOptions,
|
|
69
|
+
additionalEnvVars: options?.additionalEnvVars,
|
|
70
|
+
mocks: options?.mocks,
|
|
71
|
+
aliases: options?.aliases
|
|
72
|
+
});
|
|
73
|
+
if (typeof fileContent === "undefined") {
|
|
74
|
+
require_logger.logger(`File file could not be loaded. Path : ${require_logger.colorizePath(filePath)}`);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
return fileContent;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
require_logger.logger([`Error: ${error.message} - `, JSON.stringify(error.stack, null, 2)], { level: "error" });
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.loadExternalFile = loadExternalFile;
|
|
85
|
+
exports.loadExternalFileSync = loadExternalFileSync;
|
|
86
|
+
//# sourceMappingURL=loadExternalFile.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadExternalFile.cjs","names":["ESMxCJSRequire","moduleResultString: string | undefined","transpileTSToMJSSync","parseFileContent","transpileTSToMJS","colorizePath"],"sources":["../../../src/loadExternalFile/loadExternalFile.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { readFile } from 'node:fs/promises';\nimport { extname } from 'node:path';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport type { BuildOptions, Plugin } from 'esbuild';\nimport { colorizePath, logger } from '../logger';\nimport { ESMxCJSRequire } from '../utils/ESMxCJSHelpers';\nimport {\n parseFileContent,\n type SandBoxContextOptions,\n} from './parseFileContent';\nimport { transpileTSToMJS, transpileTSToMJSSync } from './transpileTSToMJS';\n\nexport type ESBuildPlugin = Plugin;\n\nexport type LoadExternalFileOptions = {\n configuration?: IntlayerConfig;\n buildOptions?: BuildOptions;\n} & SandBoxContextOptions;\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadExternalFileSync = (\n filePath: string,\n options?: LoadExternalFileOptions\n): any | undefined => {\n const fileExtension = extname(filePath);\n const safeProjectRequire = options?.projectRequire ?? ESMxCJSRequire;\n\n try {\n if (fileExtension === 'json') {\n // Remove cache to force getting fresh content\n delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];\n // Assume JSON\n return safeProjectRequire(filePath);\n }\n\n // Rest is JS, MJS or TS\n const code = readFileSync(filePath, 'utf-8');\n\n const moduleResultString: string | undefined = transpileTSToMJSSync(\n code,\n filePath\n );\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const fileContent = parseFileContent(moduleResultString, {\n projectRequire: options?.projectRequire,\n envVarOptions: options?.envVarOptions,\n additionalEnvVars: options?.additionalEnvVars,\n mocks: options?.mocks,\n aliases: options?.aliases,\n });\n\n if (typeof fileContent === 'undefined') {\n logger(`File file could not be loaded. Path : ${filePath}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n [\n `Error: ${(error as Error).message} - `,\n JSON.stringify((error as Error).stack, null, 2),\n ],\n {\n level: 'error',\n }\n );\n }\n};\n\n/**\n * Load the content declaration from the given path\n *\n * Accepts JSON, JS, MJS and TS files as configuration\n */\nexport const loadExternalFile = async (\n filePath: string,\n options?: LoadExternalFileOptions\n): Promise<any | undefined> => {\n const fileExtension = extname(filePath);\n const safeProjectRequire = options?.projectRequire ?? ESMxCJSRequire;\n\n try {\n if (fileExtension === 'json') {\n // Remove cache to force getting fresh content\n delete safeProjectRequire.cache[safeProjectRequire.resolve(filePath)];\n // Assume JSON\n return safeProjectRequire(filePath);\n }\n\n // Rest is JS, MJS or TS\n const code = await readFile(filePath, 'utf-8');\n\n const moduleResultString: string | undefined = await transpileTSToMJS(\n code,\n filePath,\n options?.buildOptions\n );\n\n if (!moduleResultString) {\n logger('File could not be loaded.', { level: 'error' });\n return undefined;\n }\n\n const fileContent = parseFileContent(moduleResultString, {\n projectRequire: options?.projectRequire,\n envVarOptions: options?.envVarOptions,\n additionalEnvVars: options?.additionalEnvVars,\n mocks: options?.mocks,\n aliases: options?.aliases,\n });\n\n if (typeof fileContent === 'undefined') {\n logger(`File file could not be loaded. Path : ${colorizePath(filePath)}`);\n return undefined;\n }\n\n return fileContent;\n } catch (error) {\n logger(\n [\n `Error: ${(error as Error).message} - `,\n JSON.stringify((error as Error).stack, null, 2),\n ],\n {\n level: 'error',\n }\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,MAAa,wBACX,UACA,YACoB;CACpB,MAAM,uCAAwB,SAAS;CACvC,MAAM,qBAAqB,SAAS,kBAAkBA;AAEtD,KAAI;AACF,MAAI,kBAAkB,QAAQ;AAE5B,UAAO,mBAAmB,MAAM,mBAAmB,QAAQ,SAAS;AAEpE,UAAO,mBAAmB,SAAS;;EAMrC,MAAMC,qBAAyCC,yFAFrB,UAAU,QAAQ,EAI1C,SACD;AAED,MAAI,CAAC,oBAAoB;AACvB,yBAAO,6BAA6B,EAAE,OAAO,SAAS,CAAC;AACvD;;EAGF,MAAM,cAAcC,2DAAiB,oBAAoB;GACvD,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,mBAAmB,SAAS;GAC5B,OAAO,SAAS;GAChB,SAAS,SAAS;GACnB,CAAC;AAEF,MAAI,OAAO,gBAAgB,aAAa;AACtC,yBAAO,yCAAyC,WAAW;AAC3D;;AAGF,SAAO;UACA,OAAO;AACd,wBACE,CACE,UAAW,MAAgB,QAAQ,MACnC,KAAK,UAAW,MAAgB,OAAO,MAAM,EAAE,CAChD,EACD,EACE,OAAO,SACR,CACF;;;;;;;;AASL,MAAa,mBAAmB,OAC9B,UACA,YAC6B;CAC7B,MAAM,uCAAwB,SAAS;CACvC,MAAM,qBAAqB,SAAS,kBAAkBH;AAEtD,KAAI;AACF,MAAI,kBAAkB,QAAQ;AAE5B,UAAO,mBAAmB,MAAM,mBAAmB,QAAQ,SAAS;AAEpE,UAAO,mBAAmB,SAAS;;EAMrC,MAAMC,qBAAyC,MAAMG,2DAFxC,qCAAe,UAAU,QAAQ,EAI5C,UACA,SAAS,aACV;AAED,MAAI,CAAC,oBAAoB;AACvB,yBAAO,6BAA6B,EAAE,OAAO,SAAS,CAAC;AACvD;;EAGF,MAAM,cAAcD,2DAAiB,oBAAoB;GACvD,gBAAgB,SAAS;GACzB,eAAe,SAAS;GACxB,mBAAmB,SAAS;GAC5B,OAAO,SAAS;GAChB,SAAS,SAAS;GACnB,CAAC;AAEF,MAAI,OAAO,gBAAgB,aAAa;AACtC,yBAAO,yCAAyCE,4BAAa,SAAS,GAAG;AACzE;;AAGF,SAAO;UACA,OAAO;AACd,wBACE,CACE,UAAW,MAAgB,QAAQ,MACnC,KAAK,UAAW,MAAgB,OAAO,MAAM,EAAE,CAChD,EACD,EACE,OAAO,SACR,CACF"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils_ESMxCJSHelpers = require('../utils/ESMxCJSHelpers.cjs');
|
|
3
|
+
const require_loadEnvFile = require('../loadEnvFile.cjs');
|
|
4
|
+
let node_vm = require("node:vm");
|
|
5
|
+
node_vm = require_rolldown_runtime.__toESM(node_vm);
|
|
6
|
+
let esbuild = require("esbuild");
|
|
7
|
+
esbuild = require_rolldown_runtime.__toESM(esbuild);
|
|
8
|
+
|
|
9
|
+
//#region src/loadExternalFile/parseFileContent.ts
|
|
10
|
+
const getSandBoxContext = (options) => {
|
|
11
|
+
const { envVarOptions, projectRequire, additionalEnvVars, mocks, aliases } = options ?? {};
|
|
12
|
+
let additionalGlobalVar = {};
|
|
13
|
+
const baseRequire = typeof projectRequire === "function" ? projectRequire : require_utils_ESMxCJSHelpers.ESMxCJSRequire;
|
|
14
|
+
const mockedRequire = (() => {
|
|
15
|
+
const mockTable = Object.assign({ esbuild }, mocks);
|
|
16
|
+
const aliasTable = Object.assign({}, aliases);
|
|
17
|
+
const wrappedRequire = function mockableRequire(id) {
|
|
18
|
+
const target = aliasTable?.[id] ? aliasTable[id] : id;
|
|
19
|
+
if (mockTable && Object.hasOwn(mockTable, target)) return mockTable[target];
|
|
20
|
+
if (target !== id && mockTable && Object.hasOwn(mockTable, id)) return mockTable[id];
|
|
21
|
+
return baseRequire(target);
|
|
22
|
+
};
|
|
23
|
+
wrappedRequire.resolve = baseRequire.resolve.bind(baseRequire);
|
|
24
|
+
wrappedRequire.main = baseRequire.main;
|
|
25
|
+
wrappedRequire.extensions = baseRequire.extensions;
|
|
26
|
+
wrappedRequire.cache = baseRequire.cache;
|
|
27
|
+
return wrappedRequire;
|
|
28
|
+
})();
|
|
29
|
+
try {
|
|
30
|
+
additionalGlobalVar = { React: baseRequire("react") };
|
|
31
|
+
} catch (_err) {}
|
|
32
|
+
const sandboxContext = {
|
|
33
|
+
exports: { default: {} },
|
|
34
|
+
module: { exports: {} },
|
|
35
|
+
process: {
|
|
36
|
+
...process,
|
|
37
|
+
env: {
|
|
38
|
+
...process.env,
|
|
39
|
+
...require_loadEnvFile.loadEnvFile(envVarOptions),
|
|
40
|
+
...additionalEnvVars
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
console,
|
|
44
|
+
require: mockedRequire,
|
|
45
|
+
...additionalGlobalVar
|
|
46
|
+
};
|
|
47
|
+
Object.getOwnPropertyNames(globalThis).forEach((key) => {
|
|
48
|
+
if (!(key in sandboxContext)) sandboxContext[key] = globalThis[key];
|
|
49
|
+
});
|
|
50
|
+
return sandboxContext;
|
|
51
|
+
};
|
|
52
|
+
const parseFileContent = (fileContentString, options) => {
|
|
53
|
+
const sandboxContext = getSandBoxContext(options);
|
|
54
|
+
(0, node_vm.runInNewContext)(`"use strict";\n${fileContentString}`, sandboxContext);
|
|
55
|
+
const candidates = [
|
|
56
|
+
sandboxContext.exports?.default,
|
|
57
|
+
sandboxContext.module?.exports?.defaults,
|
|
58
|
+
sandboxContext.module?.exports?.default,
|
|
59
|
+
sandboxContext.module?.exports
|
|
60
|
+
];
|
|
61
|
+
for (const candidate of candidates) if (candidate && typeof candidate === "object" && Object.keys(candidate).length > 0) return candidate;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.getSandBoxContext = getSandBoxContext;
|
|
66
|
+
exports.parseFileContent = parseFileContent;
|
|
67
|
+
//# sourceMappingURL=parseFileContent.cjs.map
|