@autter/runtime-cli 0.0.0-stage → 1.0.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,23 @@
1
+ import { A as AutterSourceMapsOptions } from './build-BXFh_jbP.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. Works with webpack builds, and
13
+ * with Turbopack builds on Next.js 15.4.1+ (`compiler.runAfterProductionCompile`).
14
+ *
15
+ * ```js
16
+ * // next.config.mjs
17
+ * import { withAutterSourceMaps } from "@autter/runtime-cli/next";
18
+ * export default withAutterSourceMaps({ reactStrictMode: true });
19
+ * ```
20
+ */
21
+ declare function withAutterSourceMaps<C extends NextConfigObject | NextConfigFunction>(nextConfig?: C, options?: AutterSourceMapsOptions): C;
22
+
23
+ export { AutterSourceMapsOptions, withAutterSourceMaps as default, installedNextVersion, withAutterSourceMaps };
package/dist/next.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { A as AutterSourceMapsOptions } from './build-BXFh_jbP.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. Works with webpack builds, and
13
+ * with Turbopack builds on Next.js 15.4.1+ (`compiler.runAfterProductionCompile`).
14
+ *
15
+ * ```js
16
+ * // next.config.mjs
17
+ * import { withAutterSourceMaps } from "@autter/runtime-cli/next";
18
+ * export default withAutterSourceMaps({ reactStrictMode: true });
19
+ * ```
20
+ */
21
+ declare function withAutterSourceMaps<C extends NextConfigObject | NextConfigFunction>(nextConfig?: C, options?: AutterSourceMapsOptions): C;
22
+
23
+ export { AutterSourceMapsOptions, withAutterSourceMaps as default, installedNextVersion, withAutterSourceMaps };
package/dist/next.js ADDED
@@ -0,0 +1,84 @@
1
+ import {
2
+ AutterSourceMapsWebpackPlugin
3
+ } from "./chunk-GGHHEUPQ.js";
4
+ import {
5
+ processBuildOutput
6
+ } from "./chunk-SIRFO2QU.js";
7
+
8
+ // src/next.ts
9
+ import { createRequire } from "module";
10
+ import { join, resolve } from "path";
11
+ var AFTER_COMPILE_HOOK_SINCE = [15, 4, 1];
12
+ function installedNextVersion(cwd = process.cwd()) {
13
+ try {
14
+ const version = createRequire(join(cwd, "package.json"))("next/package.json").version;
15
+ return typeof version === "string" ? version : null;
16
+ } catch {
17
+ return null;
18
+ }
19
+ }
20
+ function hasAfterCompileHook(version) {
21
+ const match = version ? /^(\d+)\.(\d+)\.(\d+)/.exec(version) : null;
22
+ if (!match) return false;
23
+ const parts = [Number(match[1]), Number(match[2]), Number(match[3])];
24
+ for (let i = 0; i < 3; i++) {
25
+ if (parts[i] !== AFTER_COMPILE_HOOK_SINCE[i]) return parts[i] > AFTER_COMPILE_HOOK_SINCE[i];
26
+ }
27
+ return true;
28
+ }
29
+ function wrapConfig(config, options) {
30
+ const publicMaps = config.productionBrowserSourceMaps === true;
31
+ const deleteAfterUpload = options.deleteAfterUpload ?? !publicMaps;
32
+ const base = String(config.assetPrefix || config.basePath || "").replace(/\/+$/, "");
33
+ const nextPrefix = `${base}/_next/`;
34
+ const useHook = hasAfterCompileHook(installedNextVersion());
35
+ const userWebpack = config.webpack;
36
+ const wrapped = {
37
+ ...config,
38
+ webpack(webpackConfig, context) {
39
+ const result = typeof userWebpack === "function" ? userWebpack(webpackConfig, context) : webpackConfig;
40
+ if (!context.isServer && !context.dev) {
41
+ if (!publicMaps) result.devtool = "hidden-source-map";
42
+ if (!useHook) {
43
+ result.plugins = [
44
+ ...result.plugins ?? [],
45
+ new AutterSourceMapsWebpackPlugin({ ...options, urlPrefix: options.urlPrefix ?? nextPrefix, deleteAfterUpload })
46
+ ];
47
+ }
48
+ }
49
+ return result;
50
+ }
51
+ };
52
+ if (useHook) {
53
+ wrapped.productionBrowserSourceMaps = true;
54
+ const userHook = config.compiler?.runAfterProductionCompile;
55
+ wrapped.compiler = {
56
+ ...config.compiler,
57
+ async runAfterProductionCompile(ctx = {}) {
58
+ if (typeof userHook === "function") await userHook(ctx);
59
+ const distDir = ctx.distDir ?? resolve(ctx.projectDir ?? process.cwd(), String(config.distDir ?? ".next"));
60
+ await processBuildOutput({
61
+ dir: join(distDir, "static"),
62
+ urlPrefix: options.urlPrefix ?? `${nextPrefix}static/`,
63
+ options: { ...options, deleteAfterUpload },
64
+ deleteAfterUpload,
65
+ stripSourceMappingUrl: !publicMaps
66
+ });
67
+ }
68
+ };
69
+ }
70
+ return wrapped;
71
+ }
72
+ function withAutterSourceMaps(nextConfig = {}, options = {}) {
73
+ if (typeof nextConfig === "function") {
74
+ const fn = async (phase, context) => wrapConfig(await nextConfig(phase, context), options);
75
+ return fn;
76
+ }
77
+ return wrapConfig(nextConfig, options);
78
+ }
79
+ var next_default = withAutterSourceMaps;
80
+ export {
81
+ next_default as default,
82
+ installedNextVersion,
83
+ withAutterSourceMaps
84
+ };