@codepress/codepress-engine 0.7.2 → 0.7.3
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/webpack-plugin.d.ts
CHANGED
|
@@ -48,9 +48,13 @@ export default class CodePressWebpackPlugin {
|
|
|
48
48
|
*/
|
|
49
49
|
private processAssets;
|
|
50
50
|
/**
|
|
51
|
-
* Build a mapping of module IDs to normalized paths
|
|
51
|
+
* Build a mapping of module IDs to normalized paths and export names
|
|
52
52
|
*/
|
|
53
53
|
private buildModuleMap;
|
|
54
|
+
/**
|
|
55
|
+
* Capture export name mappings for a module (original -> minified)
|
|
56
|
+
*/
|
|
57
|
+
private captureExportMappings;
|
|
54
58
|
/**
|
|
55
59
|
* Normalize a module path to a human-readable format
|
|
56
60
|
*
|
package/dist/webpack-plugin.js
CHANGED
|
@@ -71,7 +71,7 @@ class CodePressWebpackPlugin {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* Build a mapping of module IDs to normalized paths
|
|
74
|
+
* Build a mapping of module IDs to normalized paths and export names
|
|
75
75
|
*/
|
|
76
76
|
buildModuleMap(compilation, compiler) {
|
|
77
77
|
const moduleMap = {};
|
|
@@ -89,11 +89,100 @@ class CodePressWebpackPlugin {
|
|
|
89
89
|
const id = String(moduleId);
|
|
90
90
|
const normalizedPath = this.normalizePath(moduleWithResource.resource, compiler.context);
|
|
91
91
|
if (normalizedPath) {
|
|
92
|
-
|
|
92
|
+
// Skip export mapping for Next.js internal modules and font loaders
|
|
93
|
+
// These have special handling by Next.js and we shouldn't interfere
|
|
94
|
+
const shouldSkipExportMapping = moduleWithResource.resource.includes('next/font') ||
|
|
95
|
+
moduleWithResource.resource.includes('next/dist') ||
|
|
96
|
+
moduleWithResource.resource.includes('@next/font');
|
|
97
|
+
if (shouldSkipExportMapping) {
|
|
98
|
+
// Just store the path without export mappings
|
|
99
|
+
moduleMap[id] = normalizedPath;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Try to capture export mappings for regular modules
|
|
103
|
+
const exportMappings = this.captureExportMappings(module, compilation);
|
|
104
|
+
if (exportMappings && Object.keys(exportMappings).length > 0) {
|
|
105
|
+
moduleMap[id] = {
|
|
106
|
+
path: normalizedPath,
|
|
107
|
+
exports: exportMappings,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// Fallback to simple string format if no exports found
|
|
112
|
+
moduleMap[id] = normalizedPath;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
93
115
|
}
|
|
94
116
|
});
|
|
95
117
|
return moduleMap;
|
|
96
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Capture export name mappings for a module (original -> minified)
|
|
121
|
+
*/
|
|
122
|
+
captureExportMappings(module, compilation) {
|
|
123
|
+
try {
|
|
124
|
+
// Get exports info from module graph
|
|
125
|
+
const exportsInfo = compilation.moduleGraph.getExportsInfo(module);
|
|
126
|
+
if (!exportsInfo) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
// Get the generated code for this module
|
|
130
|
+
if (!compilation.codeGenerationResults) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
const codeGenResult = compilation.codeGenerationResults.get(module, undefined);
|
|
134
|
+
if (!codeGenResult) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
// Get the source code
|
|
138
|
+
const sources = codeGenResult.sources;
|
|
139
|
+
const sourceMap = sources.get('javascript');
|
|
140
|
+
if (!sourceMap) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const sourceCode = sourceMap.source().toString();
|
|
144
|
+
// Extract export names from the module
|
|
145
|
+
const exportMappings = {};
|
|
146
|
+
// Get all exports from the module (convert iterable to array)
|
|
147
|
+
const orderedExports = Array.from(exportsInfo.orderedExports || []);
|
|
148
|
+
if (orderedExports.length === 0) {
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
// Parse the generated code to find export assignments
|
|
152
|
+
// Look for patterns like: exports.X = ..., __webpack_exports__.X = ..., etc.
|
|
153
|
+
for (const exportInfo of orderedExports) {
|
|
154
|
+
const originalName = exportInfo.name;
|
|
155
|
+
if (!originalName || originalName === '__esModule') {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
// Try to find the mangled name in the source code
|
|
159
|
+
// Pattern: look for export assignments
|
|
160
|
+
const patterns = [
|
|
161
|
+
new RegExp(`exports\\.([a-zA-Z_$][a-zA-Z0-9_$]*)\\s*=.*(?://.*)?(?:${originalName}|"${originalName}")`, 'g'),
|
|
162
|
+
new RegExp(`\\["([^"]+)"\\]\\s*=.*(?://.*)?(?:${originalName}|"${originalName}")`, 'g'),
|
|
163
|
+
new RegExp(`\\.([a-zA-Z])\\s*=.*(?://.*)?(?:${originalName}|function ${originalName})`, 'g'),
|
|
164
|
+
];
|
|
165
|
+
for (const pattern of patterns) {
|
|
166
|
+
const matches = sourceCode.matchAll(pattern);
|
|
167
|
+
for (const match of matches) {
|
|
168
|
+
const minifiedName = match[1];
|
|
169
|
+
if (minifiedName && minifiedName !== originalName) {
|
|
170
|
+
exportMappings[originalName] = minifiedName;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (exportMappings[originalName]) {
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return Object.keys(exportMappings).length > 0 ? exportMappings : null;
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
// Silently fail - export mapping is optional
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
97
186
|
/**
|
|
98
187
|
* Normalize a module path to a human-readable format
|
|
99
188
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-plugin.js","sourceRoot":"","sources":["../src/webpack-plugin.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;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