securenow 7.7.12 → 7.7.13
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/cli/init.js +33 -4
- package/package.json +1 -1
package/cli/init.js
CHANGED
|
@@ -137,6 +137,9 @@ async function initNextJs(dir, project, flags) {
|
|
|
137
137
|
fs.writeFileSync(newConfigPath, `/** @type {import('next').NextConfig} */
|
|
138
138
|
const nextConfig = {
|
|
139
139
|
serverExternalPackages: ['securenow'],
|
|
140
|
+
outputFileTracingIncludes: {
|
|
141
|
+
'/*': ['./node_modules/securenow/**/*'],
|
|
142
|
+
},
|
|
140
143
|
};
|
|
141
144
|
|
|
142
145
|
export default nextConfig;
|
|
@@ -149,21 +152,47 @@ function patchNextConfig(configPath, major) {
|
|
|
149
152
|
const content = fs.readFileSync(configPath, 'utf8');
|
|
150
153
|
const serverExternalWithSecureNow = /serverExternalPackages\s*:\s*\[[\s\S]*?['"]securenow['"][\s\S]*?\]/m.test(content);
|
|
151
154
|
const serverComponentsWithSecureNow = /serverComponentsExternalPackages\s*:\s*\[[\s\S]*?['"]securenow['"][\s\S]*?\]/m.test(content);
|
|
152
|
-
|
|
155
|
+
const traceIncludeWithSecureNow = /outputFileTracingIncludes\s*:\s*{[\s\S]*?node_modules\/securenow\/\*\*/m.test(content);
|
|
156
|
+
if ((serverExternalWithSecureNow || serverComponentsWithSecureNow || content.includes('withSecureNow(')) && traceIncludeWithSecureNow) {
|
|
153
157
|
return 'already';
|
|
154
158
|
}
|
|
155
159
|
|
|
156
160
|
if (major < 15) return 'manual';
|
|
157
161
|
|
|
162
|
+
function addTraceInclude(nextContent) {
|
|
163
|
+
if (traceIncludeWithSecureNow || /outputFileTracingIncludes\s*:/.test(nextContent)) return nextContent;
|
|
164
|
+
const insert = ` outputFileTracingIncludes: {\n '/*': ['./node_modules/securenow/**/*'],\n },\n`;
|
|
165
|
+
const patterns = [
|
|
166
|
+
/(const\s+nextConfig\s*=\s*{\s*\r?\n)/,
|
|
167
|
+
/(export\s+default\s+{\s*\r?\n)/,
|
|
168
|
+
/(module\.exports\s*=\s*{\s*\r?\n)/,
|
|
169
|
+
];
|
|
170
|
+
for (const pattern of patterns) {
|
|
171
|
+
if (pattern.test(nextContent)) return nextContent.replace(pattern, `$1${insert}`);
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (serverExternalWithSecureNow || serverComponentsWithSecureNow || content.includes('withSecureNow(')) {
|
|
177
|
+
const withTraceInclude = addTraceInclude(content);
|
|
178
|
+
if (withTraceInclude && withTraceInclude !== content) {
|
|
179
|
+
fs.writeFileSync(configPath, withTraceInclude, 'utf8');
|
|
180
|
+
return 'patched';
|
|
181
|
+
}
|
|
182
|
+
return 'manual';
|
|
183
|
+
}
|
|
184
|
+
|
|
158
185
|
const existingServerExternal = content.match(/serverExternalPackages\s*:\s*\[([\s\S]*?)\]/m);
|
|
159
186
|
if (existingServerExternal) {
|
|
160
187
|
const current = existingServerExternal[1].trim().replace(/,\s*$/, '');
|
|
161
188
|
const replacement = `serverExternalPackages: [${current ? `${current}, ` : ''}'securenow']`;
|
|
162
|
-
|
|
189
|
+
let nextContent = content.replace(existingServerExternal[0], replacement);
|
|
190
|
+
nextContent = addTraceInclude(nextContent) || nextContent;
|
|
191
|
+
fs.writeFileSync(configPath, nextContent, 'utf8');
|
|
163
192
|
return 'patched';
|
|
164
193
|
}
|
|
165
194
|
|
|
166
|
-
const insert = ` serverExternalPackages: ['securenow'],\n`;
|
|
195
|
+
const insert = ` serverExternalPackages: ['securenow'],\n outputFileTracingIncludes: {\n '/*': ['./node_modules/securenow/**/*'],\n },\n`;
|
|
167
196
|
const patterns = [
|
|
168
197
|
/(const\s+nextConfig\s*=\s*{\s*\r?\n)/,
|
|
169
198
|
/(export\s+default\s+{\s*\r?\n)/,
|
|
@@ -212,7 +241,7 @@ function printAgentPrompt(kind, filename, major, project) {
|
|
|
212
241
|
? `Merge this into ${filename}: in register(), return unless process.env.NEXT_RUNTIME === "nodejs"; then dynamically import "securenow/nextjs" and "securenow/nextjs-auto-capture" with /* webpackIgnore: true */ so Next does not bundle OpenTelemetry internals. Preserve all existing instrumentation.`
|
|
213
242
|
: null,
|
|
214
243
|
kind === 'next-config' && major >= 15
|
|
215
|
-
? `Update ${filename} while preserving existing config: add securenow to serverExternalPackages, e.g. serverExternalPackages: [...(existing || []), "securenow"].`
|
|
244
|
+
? `Update ${filename} while preserving existing config: add securenow to serverExternalPackages, e.g. serverExternalPackages: [...(existing || []), "securenow"], and include SecureNow runtime files for standalone output with outputFileTracingIncludes: { "/*": ["./node_modules/securenow/**/*"] }.`
|
|
216
245
|
: null,
|
|
217
246
|
kind === 'next-config' && major < 15
|
|
218
247
|
? `Update ${filename} while preserving existing config: enable experimental.instrumentationHook and add securenow to experimental.serverComponentsExternalPackages.`
|
package/package.json
CHANGED