@bigbinary/neeto-commons-frontend 4.13.42 → 4.13.44
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.
|
@@ -10,7 +10,7 @@ const babelParser = require("@babel/parser");
|
|
|
10
10
|
const traverse = require("@babel/traverse").default;
|
|
11
11
|
const { isNotEmpty, existsBy } = require("@bigbinary/neeto-cist");
|
|
12
12
|
const enhancedResolve = require("enhanced-resolve");
|
|
13
|
-
const { isEmpty, includes, __ } = require("ramda");
|
|
13
|
+
const { isEmpty, includes, __, mergeDeepLeft } = require("ramda");
|
|
14
14
|
|
|
15
15
|
const {
|
|
16
16
|
RAILS_MOUNTED_COMPONENTS_REGEX,
|
|
@@ -20,8 +20,14 @@ const {
|
|
|
20
20
|
} = require("./constants");
|
|
21
21
|
|
|
22
22
|
// @ts-ignore
|
|
23
|
-
|
|
24
|
-
const
|
|
23
|
+
const projectESBuildConfig = require("../../../../../../config/esbuild/config");
|
|
24
|
+
const baseESBuildAlias = require("../../esbuild/alias");
|
|
25
|
+
const baseESBuildExtensions = require("../../esbuild/index");
|
|
26
|
+
|
|
27
|
+
const mergedESBuildAlias = mergeDeepLeft(
|
|
28
|
+
projectESBuildConfig.alias,
|
|
29
|
+
baseESBuildAlias
|
|
30
|
+
);
|
|
25
31
|
|
|
26
32
|
let modifiedFiles = [];
|
|
27
33
|
let importedItems = [];
|
|
@@ -34,10 +40,8 @@ const javascriptDir = pathLib.resolve(
|
|
|
34
40
|
);
|
|
35
41
|
|
|
36
42
|
const resolver = enhancedResolve.create.sync({
|
|
37
|
-
alias:
|
|
38
|
-
|
|
39
|
-
extensions: webpackConfig.resolve.extensions,
|
|
40
|
-
fallback: webpackConfig.resolve.fallback,
|
|
43
|
+
alias: mergedESBuildAlias,
|
|
44
|
+
extensions: baseESBuildExtensions.config.resolveExtensions,
|
|
41
45
|
conditionNames: ["require", "import", "node", "default", "types"],
|
|
42
46
|
});
|
|
43
47
|
|
|
@@ -63,24 +67,98 @@ const findImports = filePath => {
|
|
|
63
67
|
const currentDir = pathLib.dirname(filePath);
|
|
64
68
|
const importSource = node.source.value;
|
|
65
69
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
try {
|
|
71
|
+
const resolvedPath = resolver(currentDir, importSource);
|
|
72
|
+
const isNodeModule = resolvedPath.includes("node_modules");
|
|
73
|
+
if (isNodeModule) return;
|
|
74
|
+
|
|
75
|
+
if (isEmpty(node.specifiers)) {
|
|
76
|
+
importedItems.push({ item: "*", filePath: resolvedPath });
|
|
77
|
+
}
|
|
69
78
|
|
|
70
|
-
|
|
71
|
-
|
|
79
|
+
node.specifiers.forEach(specifier => {
|
|
80
|
+
if (specifier.type === TYPES.IMPORT_NAMESPACE_SPECIFIER) {
|
|
81
|
+
importedItems.push({ item: "*", filePath: resolvedPath });
|
|
82
|
+
} else if (specifier.type === TYPES.IMPORT_DEFAULT_SPECIFIER) {
|
|
83
|
+
importedItems.push({ item: "default", filePath: resolvedPath });
|
|
84
|
+
} else {
|
|
85
|
+
const item = specifier.imported.name;
|
|
86
|
+
importedItems.push({ item, filePath: resolvedPath });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
} catch (err) {
|
|
90
|
+
// Skip resolution errors (e.g., malformed package exports in node_modules)
|
|
91
|
+
// This typically happens with external packages that have invalid exports(like BrowserPreview in neeto-molecules)
|
|
92
|
+
console.warn(
|
|
93
|
+
`Failed to resolve import "${importSource}" in ${filePath}: ${err.message}`
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return;
|
|
72
97
|
}
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// Handle React.lazy(() => import("...")) patterns and dynamic imports
|
|
101
|
+
CallExpression(path) {
|
|
102
|
+
const { node } = path;
|
|
103
|
+
|
|
104
|
+
// Check for React.lazy pattern
|
|
105
|
+
if (
|
|
106
|
+
node.callee.type === "MemberExpression" &&
|
|
107
|
+
node.callee.object.name === "React" &&
|
|
108
|
+
node.callee.property.name === "lazy" &&
|
|
109
|
+
node.arguments.length === 1 &&
|
|
110
|
+
node.arguments[0].type === "ArrowFunctionExpression"
|
|
111
|
+
) {
|
|
112
|
+
const arrowFunction = node.arguments[0];
|
|
113
|
+
if (
|
|
114
|
+
arrowFunction.body.type === "CallExpression" &&
|
|
115
|
+
arrowFunction.body.callee.type === "Import"
|
|
116
|
+
) {
|
|
117
|
+
const importArg = arrowFunction.body.arguments[0];
|
|
118
|
+
if (importArg && importArg.type === "StringLiteral") {
|
|
119
|
+
const currentDir = pathLib.dirname(filePath);
|
|
120
|
+
const importSource = importArg.value;
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
const resolvedPath = resolver(currentDir, importSource);
|
|
124
|
+
if (!resolvedPath || typeof resolvedPath !== "string") return;
|
|
125
|
+
|
|
126
|
+
const isNodeModule = resolvedPath.includes("node_modules");
|
|
127
|
+
if (isNodeModule) return;
|
|
128
|
+
|
|
129
|
+
importedItems.push({ item: "default", filePath: resolvedPath });
|
|
130
|
+
} catch (err) {
|
|
131
|
+
console.warn(
|
|
132
|
+
`⚠️ Failed to resolve React.lazy import "${importSource}" in ${filePath}: ${err.message}`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Handle direct dynamic imports: import("...")
|
|
140
|
+
if (
|
|
141
|
+
node.callee.type === "Import" &&
|
|
142
|
+
node.arguments.length === 1 &&
|
|
143
|
+
node.arguments[0].type === "StringLiteral"
|
|
144
|
+
) {
|
|
145
|
+
const currentDir = pathLib.dirname(filePath);
|
|
146
|
+
const importSource = node.arguments[0].value;
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const resolvedPath = resolver(currentDir, importSource);
|
|
150
|
+
if (!resolvedPath || typeof resolvedPath !== "string") return;
|
|
151
|
+
|
|
152
|
+
const isNodeModule = resolvedPath.includes("node_modules");
|
|
153
|
+
if (isNodeModule) return;
|
|
73
154
|
|
|
74
|
-
node.specifiers.forEach(specifier => {
|
|
75
|
-
if (specifier.type === TYPES.IMPORT_NAMESPACE_SPECIFIER) {
|
|
76
|
-
importedItems.push({ item: "*", filePath: resolvedPath });
|
|
77
|
-
} else if (specifier.type === TYPES.IMPORT_DEFAULT_SPECIFIER) {
|
|
78
155
|
importedItems.push({ item: "default", filePath: resolvedPath });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
156
|
+
} catch (err) {
|
|
157
|
+
console.warn(
|
|
158
|
+
`Failed to resolve dynamic import "${importSource}" in ${filePath}: ${err.message}`
|
|
159
|
+
);
|
|
82
160
|
}
|
|
83
|
-
}
|
|
161
|
+
}
|
|
84
162
|
},
|
|
85
163
|
});
|
|
86
164
|
};
|
|
@@ -233,7 +311,9 @@ const run = () => {
|
|
|
233
311
|
importedItems = [];
|
|
234
312
|
unusedFiles = [];
|
|
235
313
|
|
|
236
|
-
console.log(
|
|
314
|
+
console.log(
|
|
315
|
+
"* Collecting all the imports (including React.lazy and dynamic imports)."
|
|
316
|
+
);
|
|
237
317
|
traverseDirectoryAndExecuteFunc(javascriptDir, findImports);
|
|
238
318
|
|
|
239
319
|
console.log("* Removing exports which are not imported.");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-frontend",
|
|
3
|
-
"version": "4.13.
|
|
3
|
+
"version": "4.13.44",
|
|
4
4
|
"description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
|
|
6
6
|
"author": "Amaljith K <amaljith.k@bigbinary.com>",
|
|
@@ -143,6 +143,7 @@
|
|
|
143
143
|
"css-loader": "4.3.0",
|
|
144
144
|
"dayjs": "1.11.13",
|
|
145
145
|
"dompurify": "^3.2.4",
|
|
146
|
+
"enhanced-resolve": "^5.18.1",
|
|
146
147
|
"esbuild": "0.24.0",
|
|
147
148
|
"esbuild-plugin-svgr": "^3.1.0",
|
|
148
149
|
"esbuild-plugin-yaml": "^0.0.1",
|
|
@@ -238,6 +239,7 @@
|
|
|
238
239
|
"dayjs": "1.11.13",
|
|
239
240
|
"dompurify": "^3.2.4",
|
|
240
241
|
"dotenv-webpack": "^8.0.1",
|
|
242
|
+
"enhanced-resolve": "^5.18.1",
|
|
241
243
|
"esbuild": "0.24.0",
|
|
242
244
|
"esbuild-plugin-svgr": "^3.1.0",
|
|
243
245
|
"esbuild-plugins-node-modules-polyfill": "^1.6.8",
|