@autter/runtime-cli 0.0.0-stage → 1.1.0

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.
@@ -0,0 +1,24 @@
1
+ import { A as AutterSourceMapsOptions } from './build-CPXR9Xd3.cjs';
2
+
3
+ type NextConfigObject = Record<string, any>;
4
+ type NextConfigFunction = (phase: string, context: {
5
+ defaultConfig: NextConfigObject;
6
+ }) => NextConfigObject | Promise<NextConfigObject>;
7
+ /** The project's installed Next.js version, or null. */
8
+ declare function installedNextVersion(cwd?: string): string | null;
9
+ /**
10
+ * Next.js config wrapper: hidden source maps for client production builds,
11
+ * debug ids injected into every client chunk, maps uploaded after the build
12
+ * when AUTTER_RUNTIME_KEY (or `key`) is set, then deleted whatever the
13
+ * upload's outcome (without a key, no maps are turned on at all). Works with webpack builds, and
14
+ * with Turbopack builds on Next.js 15.4.1+ (`compiler.runAfterProductionCompile`).
15
+ *
16
+ * ```js
17
+ * // next.config.mjs
18
+ * import { withAutterSourceMaps } from "@autter/runtime-cli/next";
19
+ * export default withAutterSourceMaps({ reactStrictMode: true });
20
+ * ```
21
+ */
22
+ declare function withAutterSourceMaps<C extends NextConfigObject | NextConfigFunction>(nextConfig?: C, options?: AutterSourceMapsOptions): C;
23
+
24
+ export { AutterSourceMapsOptions, withAutterSourceMaps as default, installedNextVersion, withAutterSourceMaps };
package/dist/next.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { A as AutterSourceMapsOptions } from './build-CPXR9Xd3.js';
2
+
3
+ type NextConfigObject = Record<string, any>;
4
+ type NextConfigFunction = (phase: string, context: {
5
+ defaultConfig: NextConfigObject;
6
+ }) => NextConfigObject | Promise<NextConfigObject>;
7
+ /** The project's installed Next.js version, or null. */
8
+ declare function installedNextVersion(cwd?: string): string | null;
9
+ /**
10
+ * Next.js config wrapper: hidden source maps for client production builds,
11
+ * debug ids injected into every client chunk, maps uploaded after the build
12
+ * when AUTTER_RUNTIME_KEY (or `key`) is set, then deleted whatever the
13
+ * upload's outcome (without a key, no maps are turned on at all). Works with webpack builds, and
14
+ * with Turbopack builds on Next.js 15.4.1+ (`compiler.runAfterProductionCompile`).
15
+ *
16
+ * ```js
17
+ * // next.config.mjs
18
+ * import { withAutterSourceMaps } from "@autter/runtime-cli/next";
19
+ * export default withAutterSourceMaps({ reactStrictMode: true });
20
+ * ```
21
+ */
22
+ declare function withAutterSourceMaps<C extends NextConfigObject | NextConfigFunction>(nextConfig?: C, options?: AutterSourceMapsOptions): C;
23
+
24
+ export { AutterSourceMapsOptions, withAutterSourceMaps as default, installedNextVersion, withAutterSourceMaps };
package/dist/next.js ADDED
@@ -0,0 +1,103 @@
1
+ import {
2
+ AutterSourceMapsWebpackPlugin
3
+ } from "./chunk-I2743JCN.js";
4
+ import {
5
+ findMapFiles,
6
+ logMapsNotGenerated,
7
+ processBuildOutput,
8
+ shouldGenerateMaps
9
+ } from "./chunk-DQLLM2NT.js";
10
+
11
+ // src/next.ts
12
+ import { createRequire } from "module";
13
+ import { join, resolve } from "path";
14
+ var AFTER_COMPILE_HOOK_SINCE = [15, 4, 1];
15
+ function installedNextVersion(cwd = process.cwd()) {
16
+ try {
17
+ const version = createRequire(join(cwd, "package.json"))("next/package.json").version;
18
+ return typeof version === "string" ? version : null;
19
+ } catch {
20
+ return null;
21
+ }
22
+ }
23
+ function hasAfterCompileHook(version) {
24
+ const match = version ? /^(\d+)\.(\d+)\.(\d+)/.exec(version) : null;
25
+ if (!match) return false;
26
+ const parts = [Number(match[1]), Number(match[2]), Number(match[3])];
27
+ for (let i = 0; i < 3; i++) {
28
+ if (parts[i] !== AFTER_COMPILE_HOOK_SINCE[i]) return parts[i] > AFTER_COMPILE_HOOK_SINCE[i];
29
+ }
30
+ return true;
31
+ }
32
+ function wrapConfig(config, options) {
33
+ const publicMaps = config.productionBrowserSourceMaps === true;
34
+ const ownMaps = !publicMaps && shouldGenerateMaps(options);
35
+ const deleteAfterUpload = options.deleteAfterUpload ?? !publicMaps;
36
+ let notified = false;
37
+ const notifyNoMaps = () => {
38
+ if (!publicMaps && !ownMaps && !notified) {
39
+ notified = true;
40
+ logMapsNotGenerated(options);
41
+ }
42
+ };
43
+ const base = String(config.assetPrefix || config.basePath || "").replace(/\/+$/, "");
44
+ const nextPrefix = `${base}/_next/`;
45
+ const useHook = hasAfterCompileHook(installedNextVersion());
46
+ const userWebpack = config.webpack;
47
+ const wrapped = {
48
+ ...config,
49
+ webpack(webpackConfig, context) {
50
+ const result = typeof userWebpack === "function" ? userWebpack(webpackConfig, context) : webpackConfig;
51
+ if (!context.isServer && !context.dev) {
52
+ if (ownMaps) result.devtool = "hidden-source-map";
53
+ if (!useHook) {
54
+ result.plugins = [
55
+ ...result.plugins ?? [],
56
+ new AutterSourceMapsWebpackPlugin(
57
+ { ...options, urlPrefix: options.urlPrefix ?? nextPrefix, deleteAfterUpload },
58
+ { ownMaps }
59
+ )
60
+ ];
61
+ }
62
+ }
63
+ return result;
64
+ }
65
+ };
66
+ if (useHook) {
67
+ if (ownMaps) wrapped.productionBrowserSourceMaps = true;
68
+ const userHook = config.compiler?.runAfterProductionCompile;
69
+ wrapped.compiler = {
70
+ ...config.compiler,
71
+ async runAfterProductionCompile(ctx = {}) {
72
+ if (typeof userHook === "function") await userHook(ctx);
73
+ const distDir = ctx.distDir ?? resolve(ctx.projectDir ?? process.cwd(), String(config.distDir ?? ".next"));
74
+ const staticDir = join(distDir, "static");
75
+ notifyNoMaps();
76
+ await processBuildOutput({
77
+ dir: staticDir,
78
+ urlPrefix: options.urlPrefix ?? `${nextPrefix}static/`,
79
+ options: { ...options, deleteAfterUpload },
80
+ deleteAfterUpload,
81
+ stripSourceMappingUrl: !publicMaps,
82
+ ownMaps,
83
+ // Every client map (JS and CSS): .next/static is deployed as is.
84
+ maps: ownMaps ? await findMapFiles(staticDir) : void 0
85
+ });
86
+ }
87
+ };
88
+ }
89
+ return wrapped;
90
+ }
91
+ function withAutterSourceMaps(nextConfig = {}, options = {}) {
92
+ if (typeof nextConfig === "function") {
93
+ const fn = async (phase, context) => wrapConfig(await nextConfig(phase, context), options);
94
+ return fn;
95
+ }
96
+ return wrapConfig(nextConfig, options);
97
+ }
98
+ var next_default = withAutterSourceMaps;
99
+ export {
100
+ next_default as default,
101
+ installedNextVersion,
102
+ withAutterSourceMaps
103
+ };