climaybe 2.4.0 → 2.4.1
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/version.txt +1 -1
- package/package.json +1 -1
- package/src/workflows/build/build-scripts.js +35 -14
package/bin/version.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.4.
|
|
1
|
+
2.4.1
|
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const
|
|
3
|
+
const CLIMAYBE_DIR = process.cwd();
|
|
4
|
+
const SCRIPTS_DIR = path.join(CLIMAYBE_DIR, '_scripts');
|
|
4
5
|
|
|
5
6
|
function extractImports(content) {
|
|
6
7
|
const imports = [];
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
// Supports compact imports (import{a}from"./x"), multiline forms,
|
|
9
|
+
// and import attributes (with { type: "json" }).
|
|
10
|
+
const fromImportRegex =
|
|
11
|
+
/(^|\n)\s*import(?:\s+type)?\s*[\s\S]*?\s*\bfrom\b\s*['"]([^'"]+)['"](?:\s+with\s*\{[\s\S]*?\})?\s*;?/g;
|
|
12
|
+
const sideEffectImportRegex = /(^|\n)\s*import\s*['"]([^'"]+)['"](?:\s+with\s*\{[\s\S]*?\})?\s*;?/g;
|
|
9
13
|
let match;
|
|
10
14
|
|
|
11
15
|
while ((match = fromImportRegex.exec(content)) !== null) {
|
|
@@ -18,6 +22,27 @@ function extractImports(content) {
|
|
|
18
22
|
return imports;
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
function stripModuleSyntax(content) {
|
|
26
|
+
// Remove import statements (including multiline/compact forms and import attributes).
|
|
27
|
+
let cleaned = content.replace(
|
|
28
|
+
/(^|\n)\s*import(?:\s+type)?\s*[\s\S]*?\s*\bfrom\b\s*['"][^'"]+['"](?:\s+with\s*\{[\s\S]*?\})?\s*;?/g,
|
|
29
|
+
'$1'
|
|
30
|
+
);
|
|
31
|
+
cleaned = cleaned.replace(/(^|\n)\s*import\s*['"][^'"]+['"](?:\s+with\s*\{[\s\S]*?\})?\s*;?/g, '$1');
|
|
32
|
+
|
|
33
|
+
// Fallback: ensure no standalone import declarations leak into bundle output.
|
|
34
|
+
cleaned = cleaned.replace(/^[ \t]*import\s*['"][^'"]+['"][ \t]*;?[ \t]*$/gm, '');
|
|
35
|
+
cleaned = cleaned.replace(
|
|
36
|
+
/^[ \t]*import(?:\s+type)?[ \t]*[^;\n\r]*\bfrom\b[ \t]*['"][^'"]+['"][ \t]*(?:with[ \t]*\{[^}\n\r]*\})?[ \t]*;?[ \t]*$/gm,
|
|
37
|
+
''
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
cleaned = cleaned.replace(/^\s*export\s+default\s+/gm, '');
|
|
41
|
+
cleaned = cleaned.replace(/^\s*export\s+\{[^}]*\}\s*;?\s*$/gm, '');
|
|
42
|
+
cleaned = cleaned.replace(/^\s*export\s+(?=(const|let|var|function|class)\b)/gm, '');
|
|
43
|
+
return cleaned;
|
|
44
|
+
}
|
|
45
|
+
|
|
21
46
|
function processScriptFile(filePath, processedFiles = new Set()) {
|
|
22
47
|
if (processedFiles.has(filePath)) {
|
|
23
48
|
return '';
|
|
@@ -25,7 +50,7 @@ function processScriptFile(filePath, processedFiles = new Set()) {
|
|
|
25
50
|
|
|
26
51
|
processedFiles.add(filePath);
|
|
27
52
|
|
|
28
|
-
const fullPath = path.join(
|
|
53
|
+
const fullPath = path.join(SCRIPTS_DIR, filePath);
|
|
29
54
|
|
|
30
55
|
if (!fs.existsSync(fullPath)) {
|
|
31
56
|
console.warn(`Warning: File ${filePath} not found`);
|
|
@@ -40,12 +65,7 @@ function processScriptFile(filePath, processedFiles = new Set()) {
|
|
|
40
65
|
importedContent += processScriptFile(importPath, processedFiles);
|
|
41
66
|
}
|
|
42
67
|
|
|
43
|
-
|
|
44
|
-
content = content.replace(/(^|\n)\s*import\s+[\s\S]*?\s+from\s+['"][^'"]+['"]\s*;?/g, '$1');
|
|
45
|
-
content = content.replace(/(^|\n)\s*import\s+['"][^'"]+['"]\s*;?/g, '$1');
|
|
46
|
-
content = content.replace(/^\s*export\s+default\s+/gm, '');
|
|
47
|
-
content = content.replace(/^\s*export\s+\{[^}]*\}\s*;?\s*$/gm, '');
|
|
48
|
-
content = content.replace(/^\s*export\s+(?=(const|let|var|function|class)\b)/gm, '');
|
|
68
|
+
content = stripModuleSyntax(content);
|
|
49
69
|
|
|
50
70
|
if (process.env.NODE_ENV === 'production') {
|
|
51
71
|
content = content.replace(/\/\*\*[\s\S]*?\*\//g, '');
|
|
@@ -61,12 +81,13 @@ function buildScripts() {
|
|
|
61
81
|
try {
|
|
62
82
|
if (global.gc) global.gc();
|
|
63
83
|
|
|
64
|
-
const mainPath = path.join(
|
|
84
|
+
const mainPath = path.join(SCRIPTS_DIR, 'main.js');
|
|
65
85
|
fs.readFileSync(mainPath, 'utf8');
|
|
66
86
|
|
|
67
87
|
const processedFiles = new Set();
|
|
68
|
-
|
|
69
|
-
|
|
88
|
+
let finalContent = processScriptFile('main.js', processedFiles);
|
|
89
|
+
finalContent = stripModuleSyntax(finalContent);
|
|
90
|
+
const outputPath = path.join(CLIMAYBE_DIR, 'assets', 'index.js');
|
|
70
91
|
fs.writeFileSync(outputPath, finalContent.trim() + '\n');
|
|
71
92
|
|
|
72
93
|
const fileCount = processedFiles.size;
|
|
@@ -83,4 +104,4 @@ if (require.main === module) {
|
|
|
83
104
|
buildScripts();
|
|
84
105
|
}
|
|
85
106
|
|
|
86
|
-
module.exports = { buildScripts };
|
|
107
|
+
module.exports = { buildScripts };
|