agent-neckbeard 1.1.12 → 1.1.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/README.md +2 -2
- package/dist/index.cjs +169 -13
- package/dist/index.d.cts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +169 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,13 +71,13 @@ const nextConfig = withNeckbeardNextConfig({
|
|
|
71
71
|
// your existing Next config
|
|
72
72
|
}, {
|
|
73
73
|
routeGlob: '/api/my-agent',
|
|
74
|
-
sourceFiles: ['./packages/my-agent/src
|
|
74
|
+
sourceFiles: ['./packages/my-agent/src/agent.ts'],
|
|
75
75
|
});
|
|
76
76
|
|
|
77
77
|
export default nextConfig;
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
For Next 13 configs that still use `experimental.serverComponentsExternalPackages`, the helper automatically uses the matching experimental tracing fields when it sees that shape. Set `outputFileTracingRoot` when the agent source is outside the app root.
|
|
80
|
+
The helper traces files imported by those source entries by default, including package entry metadata that `deploy()` needs when it rebundles the agent at runtime. For Next 13 configs that still use `experimental.serverComponentsExternalPackages`, the helper automatically uses the matching experimental tracing fields when it sees that shape. Set `outputFileTracingRoot` when the agent source is outside the app root.
|
|
81
81
|
|
|
82
82
|
This repo tests that shape locally with `npm run test:compat:next`, which builds and runs a Dockerized Next App Router fixture without pushing to Vercel. The fixture also checks the runtime env contract, Node major, and traced standalone files so source-level tests do not mask deployment artifact problems.
|
|
83
83
|
|
package/dist/index.cjs
CHANGED
|
@@ -266,6 +266,7 @@ var SERVER_HEALTH_TIMEOUT_MS = 12e4;
|
|
|
266
266
|
var SERVER_RECONNECT_HEALTH_TIMEOUT_MS = 3e3;
|
|
267
267
|
var SERVER_HEALTH_POLL_INTERVAL_MS = 1e3;
|
|
268
268
|
var NATIVE_EXT_RE = /\.(node|wasm|gyp|c|cc|cpp|cxx|h|hpp|hxx)$/i;
|
|
269
|
+
var TRACEABLE_SOURCE_EXT_RE = /\.(cjs|cts|js|jsx|mjs|mts|ts|tsx)$/i;
|
|
269
270
|
var E2B_SANDBOX_HOME = "/home/user";
|
|
270
271
|
var NeckbeardError = class extends Error {
|
|
271
272
|
constructor(message) {
|
|
@@ -319,6 +320,12 @@ function resolveAgentSourceFile(candidates, options = {}) {
|
|
|
319
320
|
function withNeckbeardNextConfig(nextConfig, options) {
|
|
320
321
|
const sourceFiles = normalizeNonEmptyStrings("sourceFiles", options.sourceFiles);
|
|
321
322
|
const routeGlobs = normalizeNonEmptyStrings("routeGlob", options.routeGlob ?? "/*");
|
|
323
|
+
const traceSourceDependencies = options.traceSourceDependencies ?? true;
|
|
324
|
+
const traceIncludeFiles = traceIncludeFilesForConfig(
|
|
325
|
+
process.cwd(),
|
|
326
|
+
sourceFiles,
|
|
327
|
+
traceSourceDependencies
|
|
328
|
+
);
|
|
322
329
|
const experimental = asRecord(nextConfig.experimental);
|
|
323
330
|
const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
|
|
324
331
|
if (useLegacyExperimental) {
|
|
@@ -331,7 +338,7 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
331
338
|
outputFileTracingIncludes: mergeTracingIncludes(
|
|
332
339
|
experimental.outputFileTracingIncludes,
|
|
333
340
|
routeGlobs,
|
|
334
|
-
|
|
341
|
+
traceIncludeFiles
|
|
335
342
|
)
|
|
336
343
|
};
|
|
337
344
|
if (options.outputFileTracingRoot !== void 0) {
|
|
@@ -340,7 +347,12 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
340
347
|
return {
|
|
341
348
|
...nextConfig,
|
|
342
349
|
experimental: nextExperimental,
|
|
343
|
-
webpack: withNextTraceIncludeWebpack(
|
|
350
|
+
webpack: withNextTraceIncludeWebpack(
|
|
351
|
+
nextConfig.webpack,
|
|
352
|
+
sourceFiles,
|
|
353
|
+
routeGlobs,
|
|
354
|
+
traceSourceDependencies
|
|
355
|
+
)
|
|
344
356
|
};
|
|
345
357
|
}
|
|
346
358
|
const result = {
|
|
@@ -351,19 +363,28 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
351
363
|
outputFileTracingIncludes: mergeTracingIncludes(
|
|
352
364
|
nextConfig.outputFileTracingIncludes,
|
|
353
365
|
routeGlobs,
|
|
354
|
-
|
|
366
|
+
traceIncludeFiles
|
|
355
367
|
)
|
|
356
368
|
};
|
|
369
|
+
if (nextConfig.webpack) {
|
|
370
|
+
result.webpack = withNextTraceIncludeWebpack(
|
|
371
|
+
nextConfig.webpack,
|
|
372
|
+
sourceFiles,
|
|
373
|
+
routeGlobs,
|
|
374
|
+
traceSourceDependencies
|
|
375
|
+
);
|
|
376
|
+
}
|
|
357
377
|
if (options.outputFileTracingRoot !== void 0) {
|
|
358
378
|
result.outputFileTracingRoot = options.outputFileTracingRoot;
|
|
359
379
|
}
|
|
360
380
|
return result;
|
|
361
381
|
}
|
|
362
382
|
var NextTraceIncludePlugin = class {
|
|
363
|
-
constructor(appDir, sourceFiles, routeGlobs) {
|
|
383
|
+
constructor(appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
364
384
|
this.appDir = appDir;
|
|
365
385
|
this.sourceFiles = sourceFiles;
|
|
366
386
|
this.routeGlobs = routeGlobs;
|
|
387
|
+
this.traceSourceDependencies = traceSourceDependencies;
|
|
367
388
|
}
|
|
368
389
|
apply(compiler) {
|
|
369
390
|
const compilationHook = compiler.hooks?.compilation;
|
|
@@ -384,6 +405,7 @@ var NextTraceIncludePlugin = class {
|
|
|
384
405
|
rawSource: compiler.webpack?.sources?.RawSource,
|
|
385
406
|
routeGlobs: this.routeGlobs,
|
|
386
407
|
sourceFiles: this.sourceFiles,
|
|
408
|
+
traceSourceDependencies: this.traceSourceDependencies,
|
|
387
409
|
updateAsset: compilation.updateAsset?.bind(compilation)
|
|
388
410
|
});
|
|
389
411
|
});
|
|
@@ -402,7 +424,8 @@ var NextTraceIncludePlugin = class {
|
|
|
402
424
|
compiler.outputPath ?? "",
|
|
403
425
|
this.appDir,
|
|
404
426
|
this.sourceFiles,
|
|
405
|
-
this.routeGlobs
|
|
427
|
+
this.routeGlobs,
|
|
428
|
+
this.traceSourceDependencies
|
|
406
429
|
);
|
|
407
430
|
};
|
|
408
431
|
if (typeof afterEmit?.tap === "function") {
|
|
@@ -420,9 +443,10 @@ function appendIncludesToTraceAssets({
|
|
|
420
443
|
rawSource,
|
|
421
444
|
routeGlobs,
|
|
422
445
|
sourceFiles,
|
|
446
|
+
traceSourceDependencies,
|
|
423
447
|
updateAsset
|
|
424
448
|
}) {
|
|
425
|
-
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
|
|
449
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
426
450
|
if (includedFiles.length === 0) {
|
|
427
451
|
return;
|
|
428
452
|
}
|
|
@@ -446,7 +470,7 @@ function appendIncludesToTraceAssets({
|
|
|
446
470
|
}
|
|
447
471
|
}
|
|
448
472
|
}
|
|
449
|
-
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
|
|
473
|
+
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
450
474
|
return (config, context) => {
|
|
451
475
|
const nextConfig = originalWebpack ? originalWebpack(config, context) : config;
|
|
452
476
|
if (!context.isServer || context.dev) {
|
|
@@ -455,7 +479,12 @@ function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
|
|
|
455
479
|
nextConfig.externals = withNeckbeardExternal(nextConfig.externals);
|
|
456
480
|
nextConfig.plugins = [
|
|
457
481
|
...Array.isArray(nextConfig.plugins) ? nextConfig.plugins : [],
|
|
458
|
-
new NextTraceIncludePlugin(
|
|
482
|
+
new NextTraceIncludePlugin(
|
|
483
|
+
context.dir ?? process.cwd(),
|
|
484
|
+
sourceFiles,
|
|
485
|
+
routeGlobs,
|
|
486
|
+
traceSourceDependencies
|
|
487
|
+
)
|
|
459
488
|
];
|
|
460
489
|
return nextConfig;
|
|
461
490
|
};
|
|
@@ -482,11 +511,11 @@ function neckbeardExternal(contextOrRequest, requestOrCallback) {
|
|
|
482
511
|
callback();
|
|
483
512
|
}
|
|
484
513
|
}
|
|
485
|
-
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs) {
|
|
514
|
+
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
486
515
|
if (!outputPath || !(0, import_node_fs.existsSync)(outputPath)) {
|
|
487
516
|
return;
|
|
488
517
|
}
|
|
489
|
-
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
|
|
518
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
490
519
|
if (includedFiles.length === 0) {
|
|
491
520
|
return;
|
|
492
521
|
}
|
|
@@ -518,15 +547,31 @@ function traceWithIncludedFiles(traceSource, traceDir, includedFiles) {
|
|
|
518
547
|
files: [...nextFiles]
|
|
519
548
|
});
|
|
520
549
|
}
|
|
521
|
-
function expandTraceIncludeFiles(appDir, sourceFiles) {
|
|
550
|
+
function expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies = true) {
|
|
522
551
|
const files = /* @__PURE__ */ new Set();
|
|
523
552
|
for (const sourceFile of sourceFiles) {
|
|
524
553
|
for (const file of expandTraceIncludePattern(appDir, sourceFile)) {
|
|
525
554
|
files.add(file);
|
|
526
555
|
}
|
|
527
556
|
}
|
|
557
|
+
if (traceSourceDependencies) {
|
|
558
|
+
for (const file of traceSourceDependencyFiles(appDir, [...files])) {
|
|
559
|
+
files.add(file);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
528
562
|
return [...files];
|
|
529
563
|
}
|
|
564
|
+
function traceIncludeFilesForConfig(appDir, sourceFiles, traceSourceDependencies) {
|
|
565
|
+
const tracedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies).map((file) => toNextTraceIncludePath(appDir, file));
|
|
566
|
+
return mergeStringArray(sourceFiles, tracedFiles);
|
|
567
|
+
}
|
|
568
|
+
function toNextTraceIncludePath(appDir, file) {
|
|
569
|
+
const relativePath = (0, import_node_path.relative)(appDir, file).replace(/\\/g, "/");
|
|
570
|
+
if (relativePath.startsWith("..")) {
|
|
571
|
+
return relativePath;
|
|
572
|
+
}
|
|
573
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
574
|
+
}
|
|
530
575
|
function expandTraceIncludePattern(appDir, sourceFile) {
|
|
531
576
|
const normalized = sourceFile.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
532
577
|
if (normalized.endsWith("/**/*")) {
|
|
@@ -540,6 +585,70 @@ function expandTraceIncludePattern(appDir, sourceFile) {
|
|
|
540
585
|
const file = (0, import_node_path.resolve)(appDir, normalized);
|
|
541
586
|
return (0, import_node_fs.existsSync)(file) && (0, import_node_fs.statSync)(file).isFile() ? [file] : [];
|
|
542
587
|
}
|
|
588
|
+
function traceSourceDependencyFiles(appDir, sourceFiles) {
|
|
589
|
+
const entryPoints = sourceFiles.filter((file) => TRACEABLE_SOURCE_EXT_RE.test(file));
|
|
590
|
+
if (entryPoints.length === 0) {
|
|
591
|
+
return [];
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
const esbuild = getEsbuildSync();
|
|
595
|
+
const result = esbuild.buildSync({
|
|
596
|
+
absWorkingDir: appDir,
|
|
597
|
+
bundle: true,
|
|
598
|
+
entryPoints,
|
|
599
|
+
external: [...DEFAULT_EXTERNALS, NECKBEARD_PACKAGE_NAME],
|
|
600
|
+
format: "esm",
|
|
601
|
+
logLevel: "silent",
|
|
602
|
+
metafile: true,
|
|
603
|
+
platform: "node",
|
|
604
|
+
preserveSymlinks: true,
|
|
605
|
+
target: NODE_TARGET,
|
|
606
|
+
treeShaking: false,
|
|
607
|
+
write: false
|
|
608
|
+
});
|
|
609
|
+
const metafile = result.metafile;
|
|
610
|
+
if (!metafile) {
|
|
611
|
+
return [];
|
|
612
|
+
}
|
|
613
|
+
const files = /* @__PURE__ */ new Set();
|
|
614
|
+
const addFile = (file) => {
|
|
615
|
+
if (file && (0, import_node_fs.existsSync)(file) && (0, import_node_fs.statSync)(file).isFile()) {
|
|
616
|
+
files.add(file);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
for (const [inputPath, input] of Object.entries(metafile.inputs)) {
|
|
620
|
+
const absoluteInput = resolveMetafileInput(appDir, inputPath);
|
|
621
|
+
addFile(absoluteInput);
|
|
622
|
+
for (const importRecord of input.imports ?? []) {
|
|
623
|
+
const importPath = importRecord.original ?? importRecord.path;
|
|
624
|
+
if (!isBareModuleImport(importPath) || isBuiltinModule(importPath)) {
|
|
625
|
+
continue;
|
|
626
|
+
}
|
|
627
|
+
if (importPath === NECKBEARD_PACKAGE_NAME) {
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
const resolvedImportPath = importRecord.external ? void 0 : resolveMetafileInput(appDir, importRecord.path);
|
|
631
|
+
const packageInfo = resolvedImportPath ? resolvePackageInfoFromResolvedPath(importPath, resolvedImportPath) : resolvePackageInfoSync(importPath, (0, import_node_path.dirname)(absoluteInput));
|
|
632
|
+
if (!packageInfo) {
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
addFile(packageInfo.resolvedPath);
|
|
636
|
+
addFile((0, import_node_path.join)(packageInfo.root, "package.json"));
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
return [...files];
|
|
640
|
+
} catch (error) {
|
|
641
|
+
throw new ConfigurationError(
|
|
642
|
+
`Failed to trace Neckbeard source dependencies for Next.js output tracing: ${errorMessage(error)}`
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
function getEsbuildSync() {
|
|
647
|
+
return packageRequire("esbuild");
|
|
648
|
+
}
|
|
649
|
+
function resolveMetafileInput(absWorkingDir, inputPath) {
|
|
650
|
+
return (0, import_node_path.resolve)(absWorkingDir, inputPath);
|
|
651
|
+
}
|
|
543
652
|
function findTraceFiles(root) {
|
|
544
653
|
return findFiles(root).filter((file) => file.endsWith(".nft.json"));
|
|
545
654
|
}
|
|
@@ -759,10 +868,28 @@ function shellEscape(str) {
|
|
|
759
868
|
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
760
869
|
}
|
|
761
870
|
var require2 = (0, import_node_module.createRequire)((0, import_node_path.join)(process.cwd(), "__agent_neckbeard__.cjs"));
|
|
871
|
+
var packageRequire = createPackageRequire();
|
|
872
|
+
function createPackageRequire() {
|
|
873
|
+
const cwdPackageJsonPath = (0, import_node_path.join)(process.cwd(), "package.json");
|
|
874
|
+
try {
|
|
875
|
+
if ((0, import_node_fs.existsSync)(cwdPackageJsonPath) && readPackageJson(cwdPackageJsonPath).name === NECKBEARD_PACKAGE_NAME) {
|
|
876
|
+
return (0, import_node_module.createRequire)(cwdPackageJsonPath);
|
|
877
|
+
}
|
|
878
|
+
} catch {
|
|
879
|
+
}
|
|
880
|
+
try {
|
|
881
|
+
return (0, import_node_module.createRequire)(require2.resolve(NECKBEARD_PACKAGE_NAME));
|
|
882
|
+
} catch {
|
|
883
|
+
return require2;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
762
886
|
function isBareModuleImport(path) {
|
|
763
887
|
const excludes = [".", "/", "~", "file:", "data:"];
|
|
764
888
|
return !excludes.some((exclude) => path.startsWith(exclude));
|
|
765
889
|
}
|
|
890
|
+
function isBuiltinModule(path) {
|
|
891
|
+
return import_node_module.builtinModules.includes(path.replace("node:", ""));
|
|
892
|
+
}
|
|
766
893
|
function packageNameForImportPath(importPath) {
|
|
767
894
|
if (importPath.startsWith("@")) {
|
|
768
895
|
return importPath.split("/").slice(0, 2).join("/");
|
|
@@ -777,6 +904,9 @@ function matchesExternal(matchers, pkgName) {
|
|
|
777
904
|
return matchers.some((re) => re.test(pkgName));
|
|
778
905
|
}
|
|
779
906
|
async function resolvePackageInfo(importPath, resolveDir) {
|
|
907
|
+
return resolvePackageInfoSync(importPath, resolveDir);
|
|
908
|
+
}
|
|
909
|
+
function resolvePackageInfoSync(importPath, resolveDir) {
|
|
780
910
|
try {
|
|
781
911
|
const resolvedPath = require2.resolve(importPath, { paths: [resolveDir] });
|
|
782
912
|
const packageName = packageNameForImportPath(importPath);
|
|
@@ -810,6 +940,29 @@ async function resolvePackageInfo(importPath, resolveDir) {
|
|
|
810
940
|
return null;
|
|
811
941
|
}
|
|
812
942
|
}
|
|
943
|
+
function resolvePackageInfoFromResolvedPath(importPath, resolvedPath) {
|
|
944
|
+
const packageName = packageNameForImportPath(importPath);
|
|
945
|
+
let root = (0, import_node_path.dirname)(resolvedPath);
|
|
946
|
+
while (true) {
|
|
947
|
+
const packageJsonPath = (0, import_node_path.join)(root, "package.json");
|
|
948
|
+
if ((0, import_node_fs.existsSync)(packageJsonPath)) {
|
|
949
|
+
const packageJson = readPackageJson(packageJsonPath);
|
|
950
|
+
if (packageJson.name === packageName) {
|
|
951
|
+
if (!packageJson.version) return null;
|
|
952
|
+
return {
|
|
953
|
+
name: packageJson.name,
|
|
954
|
+
version: packageJson.version,
|
|
955
|
+
root,
|
|
956
|
+
resolvedPath,
|
|
957
|
+
packageJson
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
const parent = (0, import_node_path.dirname)(root);
|
|
962
|
+
if (parent === root) return null;
|
|
963
|
+
root = parent;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
813
966
|
function hasNativeHints(info) {
|
|
814
967
|
const files = Array.isArray(info.packageJson.files) ? info.packageJson.files : [];
|
|
815
968
|
const fields = [info.packageJson.main, info.packageJson.module, info.packageJson.browser].filter(
|
|
@@ -884,6 +1037,9 @@ function timeoutMsToSeconds(timeoutMs) {
|
|
|
884
1037
|
function asError(error) {
|
|
885
1038
|
return error instanceof Error ? error : new Error(String(error));
|
|
886
1039
|
}
|
|
1040
|
+
function errorMessage(error) {
|
|
1041
|
+
return error instanceof Error ? error.message : String(error);
|
|
1042
|
+
}
|
|
887
1043
|
async function resolveDaytonaPaths(sandbox) {
|
|
888
1044
|
const workDir = await sandbox.getWorkDir() ?? await sandbox.getUserHomeDir();
|
|
889
1045
|
const homeDir = await sandbox.getUserHomeDir() ?? workDir;
|
|
@@ -915,11 +1071,11 @@ async function runE2bCommand(sandbox, cmd, options) {
|
|
|
915
1071
|
};
|
|
916
1072
|
} catch (error) {
|
|
917
1073
|
const exitCode = error.exitCode ?? 1;
|
|
918
|
-
const
|
|
1074
|
+
const errorMessage2 = error instanceof Error ? error.message : String(error);
|
|
919
1075
|
return {
|
|
920
1076
|
exitCode,
|
|
921
1077
|
stdout,
|
|
922
|
-
stderr: stderr ||
|
|
1078
|
+
stderr: stderr || errorMessage2
|
|
923
1079
|
};
|
|
924
1080
|
}
|
|
925
1081
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -93,6 +93,16 @@ interface NeckbeardNextConfigOptions {
|
|
|
93
93
|
* relative to the app root unless `outputFileTracingRoot` is also set.
|
|
94
94
|
*/
|
|
95
95
|
sourceFiles: string[];
|
|
96
|
+
/**
|
|
97
|
+
* Also include files that the source entries import.
|
|
98
|
+
*
|
|
99
|
+
* Neckbeard rebundles `sourceFile` during `deploy()`. Framework server
|
|
100
|
+
* artifacts therefore need the source entry plus the files and package entry
|
|
101
|
+
* metadata that esbuild will need to resolve its import graph at runtime.
|
|
102
|
+
*
|
|
103
|
+
* @default true
|
|
104
|
+
*/
|
|
105
|
+
traceSourceDependencies?: boolean;
|
|
96
106
|
/**
|
|
97
107
|
* Route glob or globs whose server traces should include `sourceFiles`.
|
|
98
108
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -93,6 +93,16 @@ interface NeckbeardNextConfigOptions {
|
|
|
93
93
|
* relative to the app root unless `outputFileTracingRoot` is also set.
|
|
94
94
|
*/
|
|
95
95
|
sourceFiles: string[];
|
|
96
|
+
/**
|
|
97
|
+
* Also include files that the source entries import.
|
|
98
|
+
*
|
|
99
|
+
* Neckbeard rebundles `sourceFile` during `deploy()`. Framework server
|
|
100
|
+
* artifacts therefore need the source entry plus the files and package entry
|
|
101
|
+
* metadata that esbuild will need to resolve its import graph at runtime.
|
|
102
|
+
*
|
|
103
|
+
* @default true
|
|
104
|
+
*/
|
|
105
|
+
traceSourceDependencies?: boolean;
|
|
96
106
|
/**
|
|
97
107
|
* Route glob or globs whose server traces should include `sourceFiles`.
|
|
98
108
|
*
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ var SERVER_HEALTH_TIMEOUT_MS = 12e4;
|
|
|
33
33
|
var SERVER_RECONNECT_HEALTH_TIMEOUT_MS = 3e3;
|
|
34
34
|
var SERVER_HEALTH_POLL_INTERVAL_MS = 1e3;
|
|
35
35
|
var NATIVE_EXT_RE = /\.(node|wasm|gyp|c|cc|cpp|cxx|h|hpp|hxx)$/i;
|
|
36
|
+
var TRACEABLE_SOURCE_EXT_RE = /\.(cjs|cts|js|jsx|mjs|mts|ts|tsx)$/i;
|
|
36
37
|
var E2B_SANDBOX_HOME = "/home/user";
|
|
37
38
|
var NeckbeardError = class extends Error {
|
|
38
39
|
constructor(message) {
|
|
@@ -86,6 +87,12 @@ function resolveAgentSourceFile(candidates, options = {}) {
|
|
|
86
87
|
function withNeckbeardNextConfig(nextConfig, options) {
|
|
87
88
|
const sourceFiles = normalizeNonEmptyStrings("sourceFiles", options.sourceFiles);
|
|
88
89
|
const routeGlobs = normalizeNonEmptyStrings("routeGlob", options.routeGlob ?? "/*");
|
|
90
|
+
const traceSourceDependencies = options.traceSourceDependencies ?? true;
|
|
91
|
+
const traceIncludeFiles = traceIncludeFilesForConfig(
|
|
92
|
+
process.cwd(),
|
|
93
|
+
sourceFiles,
|
|
94
|
+
traceSourceDependencies
|
|
95
|
+
);
|
|
89
96
|
const experimental = asRecord(nextConfig.experimental);
|
|
90
97
|
const useLegacyExperimental = options.legacyExperimental ?? ("serverComponentsExternalPackages" in experimental || "outputFileTracingIncludes" in experimental || "outputFileTracingRoot" in experimental);
|
|
91
98
|
if (useLegacyExperimental) {
|
|
@@ -98,7 +105,7 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
98
105
|
outputFileTracingIncludes: mergeTracingIncludes(
|
|
99
106
|
experimental.outputFileTracingIncludes,
|
|
100
107
|
routeGlobs,
|
|
101
|
-
|
|
108
|
+
traceIncludeFiles
|
|
102
109
|
)
|
|
103
110
|
};
|
|
104
111
|
if (options.outputFileTracingRoot !== void 0) {
|
|
@@ -107,7 +114,12 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
107
114
|
return {
|
|
108
115
|
...nextConfig,
|
|
109
116
|
experimental: nextExperimental,
|
|
110
|
-
webpack: withNextTraceIncludeWebpack(
|
|
117
|
+
webpack: withNextTraceIncludeWebpack(
|
|
118
|
+
nextConfig.webpack,
|
|
119
|
+
sourceFiles,
|
|
120
|
+
routeGlobs,
|
|
121
|
+
traceSourceDependencies
|
|
122
|
+
)
|
|
111
123
|
};
|
|
112
124
|
}
|
|
113
125
|
const result = {
|
|
@@ -118,19 +130,28 @@ function withNeckbeardNextConfig(nextConfig, options) {
|
|
|
118
130
|
outputFileTracingIncludes: mergeTracingIncludes(
|
|
119
131
|
nextConfig.outputFileTracingIncludes,
|
|
120
132
|
routeGlobs,
|
|
121
|
-
|
|
133
|
+
traceIncludeFiles
|
|
122
134
|
)
|
|
123
135
|
};
|
|
136
|
+
if (nextConfig.webpack) {
|
|
137
|
+
result.webpack = withNextTraceIncludeWebpack(
|
|
138
|
+
nextConfig.webpack,
|
|
139
|
+
sourceFiles,
|
|
140
|
+
routeGlobs,
|
|
141
|
+
traceSourceDependencies
|
|
142
|
+
);
|
|
143
|
+
}
|
|
124
144
|
if (options.outputFileTracingRoot !== void 0) {
|
|
125
145
|
result.outputFileTracingRoot = options.outputFileTracingRoot;
|
|
126
146
|
}
|
|
127
147
|
return result;
|
|
128
148
|
}
|
|
129
149
|
var NextTraceIncludePlugin = class {
|
|
130
|
-
constructor(appDir, sourceFiles, routeGlobs) {
|
|
150
|
+
constructor(appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
131
151
|
this.appDir = appDir;
|
|
132
152
|
this.sourceFiles = sourceFiles;
|
|
133
153
|
this.routeGlobs = routeGlobs;
|
|
154
|
+
this.traceSourceDependencies = traceSourceDependencies;
|
|
134
155
|
}
|
|
135
156
|
apply(compiler) {
|
|
136
157
|
const compilationHook = compiler.hooks?.compilation;
|
|
@@ -151,6 +172,7 @@ var NextTraceIncludePlugin = class {
|
|
|
151
172
|
rawSource: compiler.webpack?.sources?.RawSource,
|
|
152
173
|
routeGlobs: this.routeGlobs,
|
|
153
174
|
sourceFiles: this.sourceFiles,
|
|
175
|
+
traceSourceDependencies: this.traceSourceDependencies,
|
|
154
176
|
updateAsset: compilation.updateAsset?.bind(compilation)
|
|
155
177
|
});
|
|
156
178
|
});
|
|
@@ -169,7 +191,8 @@ var NextTraceIncludePlugin = class {
|
|
|
169
191
|
compiler.outputPath ?? "",
|
|
170
192
|
this.appDir,
|
|
171
193
|
this.sourceFiles,
|
|
172
|
-
this.routeGlobs
|
|
194
|
+
this.routeGlobs,
|
|
195
|
+
this.traceSourceDependencies
|
|
173
196
|
);
|
|
174
197
|
};
|
|
175
198
|
if (typeof afterEmit?.tap === "function") {
|
|
@@ -187,9 +210,10 @@ function appendIncludesToTraceAssets({
|
|
|
187
210
|
rawSource,
|
|
188
211
|
routeGlobs,
|
|
189
212
|
sourceFiles,
|
|
213
|
+
traceSourceDependencies,
|
|
190
214
|
updateAsset
|
|
191
215
|
}) {
|
|
192
|
-
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
|
|
216
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
193
217
|
if (includedFiles.length === 0) {
|
|
194
218
|
return;
|
|
195
219
|
}
|
|
@@ -213,7 +237,7 @@ function appendIncludesToTraceAssets({
|
|
|
213
237
|
}
|
|
214
238
|
}
|
|
215
239
|
}
|
|
216
|
-
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
|
|
240
|
+
function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
217
241
|
return (config, context) => {
|
|
218
242
|
const nextConfig = originalWebpack ? originalWebpack(config, context) : config;
|
|
219
243
|
if (!context.isServer || context.dev) {
|
|
@@ -222,7 +246,12 @@ function withNextTraceIncludeWebpack(originalWebpack, sourceFiles, routeGlobs) {
|
|
|
222
246
|
nextConfig.externals = withNeckbeardExternal(nextConfig.externals);
|
|
223
247
|
nextConfig.plugins = [
|
|
224
248
|
...Array.isArray(nextConfig.plugins) ? nextConfig.plugins : [],
|
|
225
|
-
new NextTraceIncludePlugin(
|
|
249
|
+
new NextTraceIncludePlugin(
|
|
250
|
+
context.dir ?? process.cwd(),
|
|
251
|
+
sourceFiles,
|
|
252
|
+
routeGlobs,
|
|
253
|
+
traceSourceDependencies
|
|
254
|
+
)
|
|
226
255
|
];
|
|
227
256
|
return nextConfig;
|
|
228
257
|
};
|
|
@@ -249,11 +278,11 @@ function neckbeardExternal(contextOrRequest, requestOrCallback) {
|
|
|
249
278
|
callback();
|
|
250
279
|
}
|
|
251
280
|
}
|
|
252
|
-
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs) {
|
|
281
|
+
function appendIncludesToTraceFiles(outputPath, appDir, sourceFiles, routeGlobs, traceSourceDependencies) {
|
|
253
282
|
if (!outputPath || !existsSync(outputPath)) {
|
|
254
283
|
return;
|
|
255
284
|
}
|
|
256
|
-
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles);
|
|
285
|
+
const includedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies);
|
|
257
286
|
if (includedFiles.length === 0) {
|
|
258
287
|
return;
|
|
259
288
|
}
|
|
@@ -285,15 +314,31 @@ function traceWithIncludedFiles(traceSource, traceDir, includedFiles) {
|
|
|
285
314
|
files: [...nextFiles]
|
|
286
315
|
});
|
|
287
316
|
}
|
|
288
|
-
function expandTraceIncludeFiles(appDir, sourceFiles) {
|
|
317
|
+
function expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies = true) {
|
|
289
318
|
const files = /* @__PURE__ */ new Set();
|
|
290
319
|
for (const sourceFile of sourceFiles) {
|
|
291
320
|
for (const file of expandTraceIncludePattern(appDir, sourceFile)) {
|
|
292
321
|
files.add(file);
|
|
293
322
|
}
|
|
294
323
|
}
|
|
324
|
+
if (traceSourceDependencies) {
|
|
325
|
+
for (const file of traceSourceDependencyFiles(appDir, [...files])) {
|
|
326
|
+
files.add(file);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
295
329
|
return [...files];
|
|
296
330
|
}
|
|
331
|
+
function traceIncludeFilesForConfig(appDir, sourceFiles, traceSourceDependencies) {
|
|
332
|
+
const tracedFiles = expandTraceIncludeFiles(appDir, sourceFiles, traceSourceDependencies).map((file) => toNextTraceIncludePath(appDir, file));
|
|
333
|
+
return mergeStringArray(sourceFiles, tracedFiles);
|
|
334
|
+
}
|
|
335
|
+
function toNextTraceIncludePath(appDir, file) {
|
|
336
|
+
const relativePath = relative(appDir, file).replace(/\\/g, "/");
|
|
337
|
+
if (relativePath.startsWith("..")) {
|
|
338
|
+
return relativePath;
|
|
339
|
+
}
|
|
340
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
341
|
+
}
|
|
297
342
|
function expandTraceIncludePattern(appDir, sourceFile) {
|
|
298
343
|
const normalized = sourceFile.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
299
344
|
if (normalized.endsWith("/**/*")) {
|
|
@@ -307,6 +352,70 @@ function expandTraceIncludePattern(appDir, sourceFile) {
|
|
|
307
352
|
const file = resolve(appDir, normalized);
|
|
308
353
|
return existsSync(file) && statSync(file).isFile() ? [file] : [];
|
|
309
354
|
}
|
|
355
|
+
function traceSourceDependencyFiles(appDir, sourceFiles) {
|
|
356
|
+
const entryPoints = sourceFiles.filter((file) => TRACEABLE_SOURCE_EXT_RE.test(file));
|
|
357
|
+
if (entryPoints.length === 0) {
|
|
358
|
+
return [];
|
|
359
|
+
}
|
|
360
|
+
try {
|
|
361
|
+
const esbuild = getEsbuildSync();
|
|
362
|
+
const result = esbuild.buildSync({
|
|
363
|
+
absWorkingDir: appDir,
|
|
364
|
+
bundle: true,
|
|
365
|
+
entryPoints,
|
|
366
|
+
external: [...DEFAULT_EXTERNALS, NECKBEARD_PACKAGE_NAME],
|
|
367
|
+
format: "esm",
|
|
368
|
+
logLevel: "silent",
|
|
369
|
+
metafile: true,
|
|
370
|
+
platform: "node",
|
|
371
|
+
preserveSymlinks: true,
|
|
372
|
+
target: NODE_TARGET,
|
|
373
|
+
treeShaking: false,
|
|
374
|
+
write: false
|
|
375
|
+
});
|
|
376
|
+
const metafile = result.metafile;
|
|
377
|
+
if (!metafile) {
|
|
378
|
+
return [];
|
|
379
|
+
}
|
|
380
|
+
const files = /* @__PURE__ */ new Set();
|
|
381
|
+
const addFile = (file) => {
|
|
382
|
+
if (file && existsSync(file) && statSync(file).isFile()) {
|
|
383
|
+
files.add(file);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
for (const [inputPath, input] of Object.entries(metafile.inputs)) {
|
|
387
|
+
const absoluteInput = resolveMetafileInput(appDir, inputPath);
|
|
388
|
+
addFile(absoluteInput);
|
|
389
|
+
for (const importRecord of input.imports ?? []) {
|
|
390
|
+
const importPath = importRecord.original ?? importRecord.path;
|
|
391
|
+
if (!isBareModuleImport(importPath) || isBuiltinModule(importPath)) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (importPath === NECKBEARD_PACKAGE_NAME) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
const resolvedImportPath = importRecord.external ? void 0 : resolveMetafileInput(appDir, importRecord.path);
|
|
398
|
+
const packageInfo = resolvedImportPath ? resolvePackageInfoFromResolvedPath(importPath, resolvedImportPath) : resolvePackageInfoSync(importPath, dirname(absoluteInput));
|
|
399
|
+
if (!packageInfo) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
addFile(packageInfo.resolvedPath);
|
|
403
|
+
addFile(join(packageInfo.root, "package.json"));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return [...files];
|
|
407
|
+
} catch (error) {
|
|
408
|
+
throw new ConfigurationError(
|
|
409
|
+
`Failed to trace Neckbeard source dependencies for Next.js output tracing: ${errorMessage(error)}`
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
function getEsbuildSync() {
|
|
414
|
+
return packageRequire("esbuild");
|
|
415
|
+
}
|
|
416
|
+
function resolveMetafileInput(absWorkingDir, inputPath) {
|
|
417
|
+
return resolve(absWorkingDir, inputPath);
|
|
418
|
+
}
|
|
310
419
|
function findTraceFiles(root) {
|
|
311
420
|
return findFiles(root).filter((file) => file.endsWith(".nft.json"));
|
|
312
421
|
}
|
|
@@ -526,10 +635,28 @@ function shellEscape(str) {
|
|
|
526
635
|
return `'${str.replace(/'/g, "'\\''")}'`;
|
|
527
636
|
}
|
|
528
637
|
var require2 = createRequire(join(process.cwd(), "__agent_neckbeard__.cjs"));
|
|
638
|
+
var packageRequire = createPackageRequire();
|
|
639
|
+
function createPackageRequire() {
|
|
640
|
+
const cwdPackageJsonPath = join(process.cwd(), "package.json");
|
|
641
|
+
try {
|
|
642
|
+
if (existsSync(cwdPackageJsonPath) && readPackageJson(cwdPackageJsonPath).name === NECKBEARD_PACKAGE_NAME) {
|
|
643
|
+
return createRequire(cwdPackageJsonPath);
|
|
644
|
+
}
|
|
645
|
+
} catch {
|
|
646
|
+
}
|
|
647
|
+
try {
|
|
648
|
+
return createRequire(require2.resolve(NECKBEARD_PACKAGE_NAME));
|
|
649
|
+
} catch {
|
|
650
|
+
return require2;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
529
653
|
function isBareModuleImport(path) {
|
|
530
654
|
const excludes = [".", "/", "~", "file:", "data:"];
|
|
531
655
|
return !excludes.some((exclude) => path.startsWith(exclude));
|
|
532
656
|
}
|
|
657
|
+
function isBuiltinModule(path) {
|
|
658
|
+
return builtinModules.includes(path.replace("node:", ""));
|
|
659
|
+
}
|
|
533
660
|
function packageNameForImportPath(importPath) {
|
|
534
661
|
if (importPath.startsWith("@")) {
|
|
535
662
|
return importPath.split("/").slice(0, 2).join("/");
|
|
@@ -544,6 +671,9 @@ function matchesExternal(matchers, pkgName) {
|
|
|
544
671
|
return matchers.some((re) => re.test(pkgName));
|
|
545
672
|
}
|
|
546
673
|
async function resolvePackageInfo(importPath, resolveDir) {
|
|
674
|
+
return resolvePackageInfoSync(importPath, resolveDir);
|
|
675
|
+
}
|
|
676
|
+
function resolvePackageInfoSync(importPath, resolveDir) {
|
|
547
677
|
try {
|
|
548
678
|
const resolvedPath = require2.resolve(importPath, { paths: [resolveDir] });
|
|
549
679
|
const packageName = packageNameForImportPath(importPath);
|
|
@@ -577,6 +707,29 @@ async function resolvePackageInfo(importPath, resolveDir) {
|
|
|
577
707
|
return null;
|
|
578
708
|
}
|
|
579
709
|
}
|
|
710
|
+
function resolvePackageInfoFromResolvedPath(importPath, resolvedPath) {
|
|
711
|
+
const packageName = packageNameForImportPath(importPath);
|
|
712
|
+
let root = dirname(resolvedPath);
|
|
713
|
+
while (true) {
|
|
714
|
+
const packageJsonPath = join(root, "package.json");
|
|
715
|
+
if (existsSync(packageJsonPath)) {
|
|
716
|
+
const packageJson = readPackageJson(packageJsonPath);
|
|
717
|
+
if (packageJson.name === packageName) {
|
|
718
|
+
if (!packageJson.version) return null;
|
|
719
|
+
return {
|
|
720
|
+
name: packageJson.name,
|
|
721
|
+
version: packageJson.version,
|
|
722
|
+
root,
|
|
723
|
+
resolvedPath,
|
|
724
|
+
packageJson
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
const parent = dirname(root);
|
|
729
|
+
if (parent === root) return null;
|
|
730
|
+
root = parent;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
580
733
|
function hasNativeHints(info) {
|
|
581
734
|
const files = Array.isArray(info.packageJson.files) ? info.packageJson.files : [];
|
|
582
735
|
const fields = [info.packageJson.main, info.packageJson.module, info.packageJson.browser].filter(
|
|
@@ -651,6 +804,9 @@ function timeoutMsToSeconds(timeoutMs) {
|
|
|
651
804
|
function asError(error) {
|
|
652
805
|
return error instanceof Error ? error : new Error(String(error));
|
|
653
806
|
}
|
|
807
|
+
function errorMessage(error) {
|
|
808
|
+
return error instanceof Error ? error.message : String(error);
|
|
809
|
+
}
|
|
654
810
|
async function resolveDaytonaPaths(sandbox) {
|
|
655
811
|
const workDir = await sandbox.getWorkDir() ?? await sandbox.getUserHomeDir();
|
|
656
812
|
const homeDir = await sandbox.getUserHomeDir() ?? workDir;
|
|
@@ -682,11 +838,11 @@ async function runE2bCommand(sandbox, cmd, options) {
|
|
|
682
838
|
};
|
|
683
839
|
} catch (error) {
|
|
684
840
|
const exitCode = error.exitCode ?? 1;
|
|
685
|
-
const
|
|
841
|
+
const errorMessage2 = error instanceof Error ? error.message : String(error);
|
|
686
842
|
return {
|
|
687
843
|
exitCode,
|
|
688
844
|
stdout,
|
|
689
|
-
stderr: stderr ||
|
|
845
|
+
stderr: stderr || errorMessage2
|
|
690
846
|
};
|
|
691
847
|
}
|
|
692
848
|
}
|