ezlogs-nextjs 0.4.4 → 0.4.7
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 +73 -13
- package/dist/actors/index.d.cts +1 -1
- package/dist/actors/index.d.ts +1 -1
- package/dist/{chunk-MMLQXSSD.cjs → chunk-2YCQFLXW.cjs} +21 -11
- package/dist/{chunk-YMIGZYFH.js → chunk-343ZGTMH.js} +1 -1
- package/dist/{chunk-Z2TM3LGG.js → chunk-5ZMOWEBY.js} +1 -1
- package/dist/{chunk-GI6BM4MR.js → chunk-7MFKEYDN.js} +21 -12
- package/dist/{chunk-NINIAL7M.js → chunk-AXIQTU52.js} +1 -1
- package/dist/chunk-BE3RCFNP.js +13 -0
- package/dist/chunk-CHVJ4WPM.cjs +16 -0
- package/dist/{chunk-MHBS5FEP.js → chunk-CYAFYBKF.js} +27 -4
- package/dist/chunk-DRE2VXFX.js +19 -0
- package/dist/{chunk-GMHOUAKD.cjs → chunk-EXGEA4KE.cjs} +37 -13
- package/dist/{chunk-PS4U2GFJ.cjs → chunk-JB4UYCZI.cjs} +5 -5
- package/dist/chunk-JWJKFZBW.js +52 -0
- package/dist/{chunk-R6IWVTX3.cjs → chunk-KOFR5OC3.cjs} +31 -21
- package/dist/chunk-NFZ5OKF3.cjs +22 -0
- package/dist/{chunk-U22T7QYY.js → chunk-Q3HRVWCS.js} +13 -3
- package/dist/{chunk-YXZZNZG6.cjs → chunk-UC2KS5EG.cjs} +9 -9
- package/dist/chunk-VJR4VB4B.cjs +56 -0
- package/dist/{chunk-NX4EL7BY.cjs → chunk-XWEBKN65.cjs} +4 -4
- package/dist/{configuration-CJ5yKVlP.d.cts → configuration-b9pImwFB.d.cts} +2 -2
- package/dist/{configuration-CJ5yKVlP.d.ts → configuration-b9pImwFB.d.ts} +2 -2
- package/dist/db/drizzle.cjs +3 -3
- package/dist/db/drizzle.js +2 -2
- package/dist/db/postgres-js.cjs +4 -4
- package/dist/db/postgres-js.js +2 -2
- package/dist/db/prisma.cjs +12 -12
- package/dist/db/prisma.js +2 -2
- package/dist/db/supabase.cjs +42 -17
- package/dist/db/supabase.d.cts +11 -5
- package/dist/db/supabase.d.ts +11 -5
- package/dist/db/supabase.js +33 -9
- package/dist/index.cjs +303 -142
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +213 -52
- package/dist/jobs/bullmq.cjs +44 -16
- package/dist/jobs/bullmq.d.cts +7 -1
- package/dist/jobs/bullmq.d.ts +7 -1
- package/dist/jobs/bullmq.js +33 -6
- package/dist/jobs/inngest.cjs +171 -48
- package/dist/jobs/inngest.d.cts +13 -7
- package/dist/jobs/inngest.d.ts +13 -7
- package/dist/jobs/inngest.js +162 -40
- package/dist/jobs/supabase-queues.cjs +9 -9
- package/dist/jobs/supabase-queues.js +4 -4
- package/dist/jobs/trigger.cjs +7 -7
- package/dist/jobs/trigger.js +4 -4
- package/dist/jobs/upstash-workflow.cjs +139 -23
- package/dist/jobs/upstash-workflow.d.cts +20 -2
- package/dist/jobs/upstash-workflow.d.ts +20 -2
- package/dist/jobs/upstash-workflow.js +129 -14
- package/dist/nextjs-plugin/index.cjs +46 -29
- package/dist/nextjs-plugin/index.js +46 -29
- package/dist/nextjs-plugin/loader.cjs +104 -65
- package/dist/nextjs-plugin/loader.d.cts +18 -1
- package/dist/nextjs-plugin/loader.d.ts +18 -1
- package/dist/nextjs-plugin/loader.js +104 -66
- package/dist/triggers/index.cjs +22 -16
- package/dist/triggers/index.d.cts +0 -10
- package/dist/triggers/index.d.ts +0 -10
- package/dist/triggers/index.js +11 -5
- package/package.json +1 -1
- package/sql/postgres/00_install.sql +20 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkNFZ5OKF3_cjs = require('../chunk-NFZ5OKF3.cjs');
|
|
3
4
|
require('../chunk-ZDSQYCYV.cjs');
|
|
4
5
|
var path = require('path');
|
|
5
6
|
var fs = require('fs');
|
|
@@ -78,7 +79,7 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
78
79
|
loaders: [
|
|
79
80
|
{
|
|
80
81
|
loader: loaderPath,
|
|
81
|
-
options: { kind: "middleware" }
|
|
82
|
+
options: { kind: "middleware", projectDir }
|
|
82
83
|
}
|
|
83
84
|
],
|
|
84
85
|
as: `*.${ext}`
|
|
@@ -88,7 +89,7 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
88
89
|
loaders: [
|
|
89
90
|
{
|
|
90
91
|
loader: loaderPath,
|
|
91
|
-
options: { kind: "middleware" }
|
|
92
|
+
options: { kind: "middleware", projectDir }
|
|
92
93
|
}
|
|
93
94
|
],
|
|
94
95
|
as: `*.${ext}`
|
|
@@ -121,21 +122,6 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
121
122
|
as: `*.${ext}`
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
|
-
const supabaseGlobs = [
|
|
125
|
-
`**/{lib,src/lib,utils,src/utils}/supabase/**/*.${ext}`
|
|
126
|
-
];
|
|
127
|
-
for (const glob of supabaseGlobs) {
|
|
128
|
-
ezlogsRules[glob] = {
|
|
129
|
-
condition: { not: "browser" },
|
|
130
|
-
loaders: [
|
|
131
|
-
{
|
|
132
|
-
loader: loaderPath,
|
|
133
|
-
options: { kind: "supabase-factory" }
|
|
134
|
-
}
|
|
135
|
-
],
|
|
136
|
-
as: `*.${ext}`
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
125
|
for (const inlineFilename of INLINE_ROUTE_FILENAMES) {
|
|
140
126
|
ezlogsRules[`**/{app,src/app}/**/${inlineFilename}.${ext}`] = {
|
|
141
127
|
condition: {
|
|
@@ -149,6 +135,22 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
149
135
|
]
|
|
150
136
|
};
|
|
151
137
|
}
|
|
138
|
+
ezlogsRules[`**/*.${ext}`] = {
|
|
139
|
+
condition: {
|
|
140
|
+
all: [
|
|
141
|
+
{ not: "browser" },
|
|
142
|
+
{ content: chunkNFZ5OKF3_cjs.INSTRUMENTED_IMPORT_CONTENT },
|
|
143
|
+
{ not: { path: /(^|[\\/])node_modules[\\/]/ } },
|
|
144
|
+
{ not: { any: ownedByOtherRules(wrapProxy) } }
|
|
145
|
+
]
|
|
146
|
+
},
|
|
147
|
+
loaders: [
|
|
148
|
+
{
|
|
149
|
+
loader: loaderPath,
|
|
150
|
+
options: { kind: "instrumented-imports" }
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
};
|
|
152
154
|
}
|
|
153
155
|
return {
|
|
154
156
|
...userTurbopack,
|
|
@@ -234,29 +236,25 @@ function installLoaders(config, context) {
|
|
|
234
236
|
}
|
|
235
237
|
]
|
|
236
238
|
});
|
|
237
|
-
const libSupabase = path.resolve(projectDir, "lib/supabase");
|
|
238
|
-
const srcLibSupabase = path.resolve(projectDir, "src/lib/supabase");
|
|
239
|
-
const utilsSupabase = path.resolve(projectDir, "utils/supabase");
|
|
240
|
-
const srcUtilsSupabase = path.resolve(projectDir, "src/utils/supabase");
|
|
241
239
|
newRules.push({
|
|
242
|
-
test: new RegExp(
|
|
243
|
-
|
|
240
|
+
test: new RegExp(
|
|
241
|
+
`[/\\\\](${INLINE_ROUTE_FILENAMES.join("|")})\\.(${extPattern})$`
|
|
242
|
+
),
|
|
243
|
+
include: [appDir, srcAppDir],
|
|
244
244
|
use: [
|
|
245
245
|
{
|
|
246
246
|
loader: loaderPath,
|
|
247
|
-
options: { kind: "
|
|
247
|
+
options: { kind: "inline-server-action", projectDir }
|
|
248
248
|
}
|
|
249
249
|
]
|
|
250
250
|
});
|
|
251
251
|
newRules.push({
|
|
252
|
-
test: new RegExp(
|
|
253
|
-
|
|
254
|
-
),
|
|
255
|
-
include: [appDir, srcAppDir],
|
|
252
|
+
test: new RegExp(`\\.(${extPattern})$`),
|
|
253
|
+
exclude: /[\\/]node_modules[\\/]/,
|
|
256
254
|
use: [
|
|
257
255
|
{
|
|
258
256
|
loader: loaderPath,
|
|
259
|
-
options: { kind: "
|
|
257
|
+
options: { kind: "instrumented-imports", projectDir }
|
|
260
258
|
}
|
|
261
259
|
]
|
|
262
260
|
});
|
|
@@ -279,6 +277,25 @@ function nextMajorVersion(projectDir) {
|
|
|
279
277
|
return 0;
|
|
280
278
|
}
|
|
281
279
|
}
|
|
280
|
+
function ownedByOtherRules(wrapProxy) {
|
|
281
|
+
const sep = "[\\\\/]";
|
|
282
|
+
const ext = "\\.(?:ts|tsx|js|jsx)$";
|
|
283
|
+
const owned = [
|
|
284
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?route${ext}`) },
|
|
285
|
+
{ path: new RegExp(`(^|${sep})pages${sep}api${sep}`) },
|
|
286
|
+
{ path: new RegExp(`(^|${sep})middleware${ext}`) },
|
|
287
|
+
{ path: new RegExp(`(^|${sep})actions${sep}`) },
|
|
288
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?actions${ext}`) },
|
|
289
|
+
{
|
|
290
|
+
all: [
|
|
291
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?(${INLINE_ROUTE_FILENAMES.join("|")})${ext}`) },
|
|
292
|
+
{ content: /"use server"|'use server'/ }
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
];
|
|
296
|
+
if (wrapProxy) owned.push({ path: new RegExp(`(^|${sep})proxy${ext}`) });
|
|
297
|
+
return owned;
|
|
298
|
+
}
|
|
282
299
|
function escapeRegex(input) {
|
|
283
300
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
284
301
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { INSTRUMENTED_IMPORT_CONTENT } from '../chunk-DRE2VXFX.js';
|
|
1
2
|
import '../chunk-SIAA4J6H.js';
|
|
2
3
|
import { resolve, dirname } from 'path';
|
|
3
4
|
import { readFileSync } from 'fs';
|
|
@@ -75,7 +76,7 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
75
76
|
loaders: [
|
|
76
77
|
{
|
|
77
78
|
loader: loaderPath,
|
|
78
|
-
options: { kind: "middleware" }
|
|
79
|
+
options: { kind: "middleware", projectDir }
|
|
79
80
|
}
|
|
80
81
|
],
|
|
81
82
|
as: `*.${ext}`
|
|
@@ -85,7 +86,7 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
85
86
|
loaders: [
|
|
86
87
|
{
|
|
87
88
|
loader: loaderPath,
|
|
88
|
-
options: { kind: "middleware" }
|
|
89
|
+
options: { kind: "middleware", projectDir }
|
|
89
90
|
}
|
|
90
91
|
],
|
|
91
92
|
as: `*.${ext}`
|
|
@@ -118,21 +119,6 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
118
119
|
as: `*.${ext}`
|
|
119
120
|
};
|
|
120
121
|
}
|
|
121
|
-
const supabaseGlobs = [
|
|
122
|
-
`**/{lib,src/lib,utils,src/utils}/supabase/**/*.${ext}`
|
|
123
|
-
];
|
|
124
|
-
for (const glob of supabaseGlobs) {
|
|
125
|
-
ezlogsRules[glob] = {
|
|
126
|
-
condition: { not: "browser" },
|
|
127
|
-
loaders: [
|
|
128
|
-
{
|
|
129
|
-
loader: loaderPath,
|
|
130
|
-
options: { kind: "supabase-factory" }
|
|
131
|
-
}
|
|
132
|
-
],
|
|
133
|
-
as: `*.${ext}`
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
122
|
for (const inlineFilename of INLINE_ROUTE_FILENAMES) {
|
|
137
123
|
ezlogsRules[`**/{app,src/app}/**/${inlineFilename}.${ext}`] = {
|
|
138
124
|
condition: {
|
|
@@ -146,6 +132,22 @@ function mergeTurbopackConfig(userTurbopack, loaderPath, projectDir) {
|
|
|
146
132
|
]
|
|
147
133
|
};
|
|
148
134
|
}
|
|
135
|
+
ezlogsRules[`**/*.${ext}`] = {
|
|
136
|
+
condition: {
|
|
137
|
+
all: [
|
|
138
|
+
{ not: "browser" },
|
|
139
|
+
{ content: INSTRUMENTED_IMPORT_CONTENT },
|
|
140
|
+
{ not: { path: /(^|[\\/])node_modules[\\/]/ } },
|
|
141
|
+
{ not: { any: ownedByOtherRules(wrapProxy) } }
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
loaders: [
|
|
145
|
+
{
|
|
146
|
+
loader: loaderPath,
|
|
147
|
+
options: { kind: "instrumented-imports" }
|
|
148
|
+
}
|
|
149
|
+
]
|
|
150
|
+
};
|
|
149
151
|
}
|
|
150
152
|
return {
|
|
151
153
|
...userTurbopack,
|
|
@@ -231,29 +233,25 @@ function installLoaders(config, context) {
|
|
|
231
233
|
}
|
|
232
234
|
]
|
|
233
235
|
});
|
|
234
|
-
const libSupabase = resolve(projectDir, "lib/supabase");
|
|
235
|
-
const srcLibSupabase = resolve(projectDir, "src/lib/supabase");
|
|
236
|
-
const utilsSupabase = resolve(projectDir, "utils/supabase");
|
|
237
|
-
const srcUtilsSupabase = resolve(projectDir, "src/utils/supabase");
|
|
238
236
|
newRules.push({
|
|
239
|
-
test: new RegExp(
|
|
240
|
-
|
|
237
|
+
test: new RegExp(
|
|
238
|
+
`[/\\\\](${INLINE_ROUTE_FILENAMES.join("|")})\\.(${extPattern})$`
|
|
239
|
+
),
|
|
240
|
+
include: [appDir, srcAppDir],
|
|
241
241
|
use: [
|
|
242
242
|
{
|
|
243
243
|
loader: loaderPath,
|
|
244
|
-
options: { kind: "
|
|
244
|
+
options: { kind: "inline-server-action", projectDir }
|
|
245
245
|
}
|
|
246
246
|
]
|
|
247
247
|
});
|
|
248
248
|
newRules.push({
|
|
249
|
-
test: new RegExp(
|
|
250
|
-
|
|
251
|
-
),
|
|
252
|
-
include: [appDir, srcAppDir],
|
|
249
|
+
test: new RegExp(`\\.(${extPattern})$`),
|
|
250
|
+
exclude: /[\\/]node_modules[\\/]/,
|
|
253
251
|
use: [
|
|
254
252
|
{
|
|
255
253
|
loader: loaderPath,
|
|
256
|
-
options: { kind: "
|
|
254
|
+
options: { kind: "instrumented-imports", projectDir }
|
|
257
255
|
}
|
|
258
256
|
]
|
|
259
257
|
});
|
|
@@ -276,6 +274,25 @@ function nextMajorVersion(projectDir) {
|
|
|
276
274
|
return 0;
|
|
277
275
|
}
|
|
278
276
|
}
|
|
277
|
+
function ownedByOtherRules(wrapProxy) {
|
|
278
|
+
const sep = "[\\\\/]";
|
|
279
|
+
const ext = "\\.(?:ts|tsx|js|jsx)$";
|
|
280
|
+
const owned = [
|
|
281
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?route${ext}`) },
|
|
282
|
+
{ path: new RegExp(`(^|${sep})pages${sep}api${sep}`) },
|
|
283
|
+
{ path: new RegExp(`(^|${sep})middleware${ext}`) },
|
|
284
|
+
{ path: new RegExp(`(^|${sep})actions${sep}`) },
|
|
285
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?actions${ext}`) },
|
|
286
|
+
{
|
|
287
|
+
all: [
|
|
288
|
+
{ path: new RegExp(`(^|${sep})app${sep}(.*${sep})?(${INLINE_ROUTE_FILENAMES.join("|")})${ext}`) },
|
|
289
|
+
{ content: /"use server"|'use server'/ }
|
|
290
|
+
]
|
|
291
|
+
}
|
|
292
|
+
];
|
|
293
|
+
if (wrapProxy) owned.push({ path: new RegExp(`(^|${sep})proxy${ext}`) });
|
|
294
|
+
return owned;
|
|
295
|
+
}
|
|
279
296
|
function escapeRegex(input) {
|
|
280
297
|
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
281
298
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var chunkNFZ5OKF3_cjs = require('../chunk-NFZ5OKF3.cjs');
|
|
5
6
|
var chunkZDSQYCYV_cjs = require('../chunk-ZDSQYCYV.cjs');
|
|
6
7
|
var path = require('path');
|
|
7
8
|
|
|
@@ -15760,6 +15761,10 @@ function loaderImpl(source) {
|
|
|
15760
15761
|
const options = readOptions(this);
|
|
15761
15762
|
const kind = options.kind ?? "app-route-handler";
|
|
15762
15763
|
const routeModulePath = computeRouteModulePath(this.resourcePath, kind);
|
|
15764
|
+
const root = options.projectDir ?? this.rootContext ?? process.cwd();
|
|
15765
|
+
const rootEntry = isRootEntryFile(this.resourcePath, root, "middleware") || isRootEntryFile(this.resourcePath, root, "proxy");
|
|
15766
|
+
if (!rootEntry) source = rewriteInstrumentedImports(source, this.resourcePath);
|
|
15767
|
+
if (kind === "instrumented-imports") return source;
|
|
15763
15768
|
if (kind === "pages-api") {
|
|
15764
15769
|
return rewritePagesApi(source, routeModulePath);
|
|
15765
15770
|
}
|
|
@@ -15767,15 +15772,10 @@ function loaderImpl(source) {
|
|
|
15767
15772
|
return rewriteMiddleware(source);
|
|
15768
15773
|
}
|
|
15769
15774
|
if (kind === "proxy") {
|
|
15770
|
-
|
|
15771
|
-
return isRootProxyFile(this.resourcePath, root) ? rewriteMiddleware(source, "proxy") : source;
|
|
15775
|
+
return rootEntry ? rewriteMiddleware(source, "proxy") : source;
|
|
15772
15776
|
}
|
|
15773
15777
|
if (kind === "server-action") {
|
|
15774
|
-
|
|
15775
|
-
return rewriteServerActionFile(withSupabase);
|
|
15776
|
-
}
|
|
15777
|
-
if (kind === "supabase-factory") {
|
|
15778
|
-
return rewriteSupabaseFactoryImports(source);
|
|
15778
|
+
return rewriteServerActionFile(source);
|
|
15779
15779
|
}
|
|
15780
15780
|
if (kind === "inline-server-action") {
|
|
15781
15781
|
return rewriteInlineServerActions(source, this.resourcePath);
|
|
@@ -15861,70 +15861,75 @@ function rewriteLocalAliasedRouteExports(source, routeModulePath) {
|
|
|
15861
15861
|
}
|
|
15862
15862
|
function renameDestructuredExports(source) {
|
|
15863
15863
|
const methodSet = new Set(HTTP_METHOD_NAMES);
|
|
15864
|
-
const workflowServe = upstashWorkflowServeNames(source);
|
|
15865
15864
|
const methods = [];
|
|
15866
15865
|
const out = source.replace(
|
|
15867
15866
|
/(^|\n)([ \t]*)export\s+const\s*\{([^}]+)\}\s*=/g,
|
|
15868
15867
|
(full, lead, indent, list, offset) => {
|
|
15869
15868
|
const names = list.split(",").map((n) => n.trim()).filter(Boolean);
|
|
15870
15869
|
if (names.length === 0 || !names.every((n) => methodSet.has(n))) return full;
|
|
15871
|
-
const callee = /^\s*([A-Za-z_$][\w$]*)\s*[<(]/.exec(source.slice(offset + full.length))?.[1];
|
|
15872
|
-
if (callee && workflowServe.has(callee)) return full;
|
|
15873
15870
|
methods.push(...names);
|
|
15874
15871
|
return `${lead}${indent}const { ${names.map((n) => `${n}: ${ALREADY_WRAPPED_MARKER}${n}`).join(", ")} } =`;
|
|
15875
15872
|
}
|
|
15876
15873
|
);
|
|
15877
15874
|
return { source: out, methods };
|
|
15878
15875
|
}
|
|
15879
|
-
|
|
15880
|
-
|
|
15881
|
-
|
|
15882
|
-
|
|
15883
|
-
|
|
15884
|
-
|
|
15876
|
+
var NEVER_WRAP_EXPORTS = /* @__PURE__ */ new Set(["config", "metadata", "generateMetadata"]);
|
|
15877
|
+
var IMPORT_MARKER = "__ezlogs_import_";
|
|
15878
|
+
var NAMED_IMPORT = /^(\uFEFF?[ \t]*)import\s+(?!type\b)((?:[A-Za-z_$][\w$]*\s*,\s*)?)\{([^}]*)\}(\s*from\s*)(["'])([^"'\n]+)\5([ \t]*;?)/gm;
|
|
15879
|
+
function rewriteInstrumentedImports(source, filename = "file.ts") {
|
|
15880
|
+
if (!chunkNFZ5OKF3_cjs.INSTRUMENTED_IMPORTS.some((entry) => source.includes(entry.module))) return source;
|
|
15881
|
+
if (hasFileLevelDirective(source, "use client")) return source;
|
|
15882
|
+
const tokens = tokenize(source, filename);
|
|
15883
|
+
if (!tokens) return source;
|
|
15884
|
+
const importStarts = new Set(tokens.filter((t) => t.type === TT_IMPORT).map((t) => t.start));
|
|
15885
|
+
const valueUses = (local, from, to) => tokens.some(
|
|
15886
|
+
(t) => t.type === TT_NAME && !t.isType && (t.start < from || t.start >= to) && source.slice(t.start, t.end) === local
|
|
15887
|
+
);
|
|
15888
|
+
const imported = /* @__PURE__ */ new Set();
|
|
15889
|
+
return source.replace(
|
|
15890
|
+
NAMED_IMPORT,
|
|
15891
|
+
(full, indent, defaultPart, list, from, quote, module, end, offset) => {
|
|
15892
|
+
const entry = chunkNFZ5OKF3_cjs.INSTRUMENTED_IMPORTS.find((e) => e.module === module);
|
|
15893
|
+
if (!entry || !importStarts.has(offset + indent.length)) return full;
|
|
15894
|
+
if (/^\s*(?:with|assert)\s*\{/.test(source.slice(offset + full.length))) return full;
|
|
15895
|
+
const replaced = [];
|
|
15896
|
+
const specifiers = list.split(",").map((piece) => {
|
|
15897
|
+
const spec = piece.trim();
|
|
15898
|
+
const match = /^([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?$/.exec(spec);
|
|
15899
|
+
if (!match) return piece;
|
|
15900
|
+
const name = match[1];
|
|
15901
|
+
const local = match[2] ?? name;
|
|
15902
|
+
if (!entry.names.includes(name) || local.startsWith(IMPORT_MARKER)) return piece;
|
|
15903
|
+
if (!valueUses(local, offset, offset + full.length)) return piece;
|
|
15904
|
+
replaced.push({ local, name });
|
|
15905
|
+
return piece.replace(spec, `${name} as ${IMPORT_MARKER}${local}`);
|
|
15906
|
+
});
|
|
15907
|
+
if (replaced.length === 0) return full;
|
|
15908
|
+
const instrument = `__ezlogs_instrument_${entry.via.replace(/[^A-Za-z0-9]/g, "_")}`;
|
|
15909
|
+
const added = [];
|
|
15910
|
+
if (!imported.has(instrument)) {
|
|
15911
|
+
imported.add(instrument);
|
|
15912
|
+
added.push(`import { __ezlogsInstrument as ${instrument} } from "${PACKAGE_NAME}/${entry.via}";`);
|
|
15913
|
+
}
|
|
15914
|
+
for (const { local, name } of replaced) {
|
|
15915
|
+
added.push(`const ${local} = ${instrument}("${module}#${name}", ${IMPORT_MARKER}${local});`);
|
|
15916
|
+
}
|
|
15917
|
+
const statement = `${indent}import ${defaultPart}{${specifiers.join(",")}}${from}${quote}${module}${quote}${end}`;
|
|
15918
|
+
return `${statement}${end.trim().endsWith(";") ? "" : ";"} ${added.join(" ")}`;
|
|
15885
15919
|
}
|
|
15886
|
-
|
|
15887
|
-
return names;
|
|
15920
|
+
);
|
|
15888
15921
|
}
|
|
15889
|
-
|
|
15890
|
-
|
|
15891
|
-
|
|
15892
|
-
{
|
|
15893
|
-
|
|
15894
|
-
|
|
15895
|
-
|
|
15896
|
-
|
|
15897
|
-
let changed = false;
|
|
15898
|
-
let needsWrapImport = false;
|
|
15899
|
-
for (const { module, exportName } of SUPABASE_FACTORY_IMPORTS) {
|
|
15900
|
-
const importPattern = new RegExp(
|
|
15901
|
-
`(import\\s*\\{[^}]*?)\\b(${exportName})\\b(\\s*(?:,[^}]*)?\\}\\s*from\\s*['"]${escapeRegexLiteral(module)}['"])`,
|
|
15902
|
-
"m"
|
|
15922
|
+
function tokenize(source, filename) {
|
|
15923
|
+
const sucraseParse = getSucraseParse();
|
|
15924
|
+
if (sucraseParse === null) return null;
|
|
15925
|
+
try {
|
|
15926
|
+
return sucraseParse(source, /\.(jsx|tsx|js|mjs|cjs)$/i.test(filename), /\.([cm]?ts|tsx)$/i.test(filename), false).tokens;
|
|
15927
|
+
} catch (e) {
|
|
15928
|
+
console.warn(
|
|
15929
|
+
`[ezlogs] sucrase parse failed for ${filename}; its library imports are not instrumented. ${e instanceof Error ? e.message : String(e)}`
|
|
15903
15930
|
);
|
|
15904
|
-
|
|
15905
|
-
if (!match) continue;
|
|
15906
|
-
const insertPoint = match.index + match[1].length + match[2].length;
|
|
15907
|
-
const after = rewritten.slice(insertPoint, insertPoint + 6);
|
|
15908
|
-
if (/^\s+as\b/.test(after)) continue;
|
|
15909
|
-
rewritten = rewritten.replace(importPattern, (_full, lead, name, tail) => {
|
|
15910
|
-
return `${lead}${name} as ${ALREADY_WRAPPED_MARKER}${name}${tail}`;
|
|
15911
|
-
});
|
|
15912
|
-
const wrapper = `const ${exportName} = (...__ezlogs_args) => ${ALREADY_WRAPPED_MARKER}wrap(${ALREADY_WRAPPED_MARKER}${exportName}(...__ezlogs_args));`;
|
|
15913
|
-
rewritten = `${rewritten}
|
|
15914
|
-
${wrapper}
|
|
15915
|
-
`;
|
|
15916
|
-
changed = true;
|
|
15917
|
-
needsWrapImport = true;
|
|
15918
|
-
}
|
|
15919
|
-
if (!changed) return source;
|
|
15920
|
-
if (needsWrapImport) {
|
|
15921
|
-
rewritten = `import { wrapSupabase as ${ALREADY_WRAPPED_MARKER}wrap } from "${PACKAGE_NAME}/supabase";
|
|
15922
|
-
${rewritten}`;
|
|
15931
|
+
return null;
|
|
15923
15932
|
}
|
|
15924
|
-
return rewritten;
|
|
15925
|
-
}
|
|
15926
|
-
function escapeRegexLiteral(input) {
|
|
15927
|
-
return input.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
15928
15933
|
}
|
|
15929
15934
|
function rewriteServerActionFile(source) {
|
|
15930
15935
|
if (!hasFileLevelUseServer(source)) return source;
|
|
@@ -15972,6 +15977,7 @@ var TT_ARROW = 22528;
|
|
|
15972
15977
|
var TT_CONST = 80912;
|
|
15973
15978
|
var TT_LET = 79888;
|
|
15974
15979
|
var TT_VAR = 78864;
|
|
15980
|
+
var TT_IMPORT = 90640;
|
|
15975
15981
|
var INLINE_HELPER_NAME = "__ezlogs_run_inline_server_action";
|
|
15976
15982
|
function rewriteInlineServerActions(source, filename) {
|
|
15977
15983
|
if (!source.includes("use server")) return source;
|
|
@@ -16127,11 +16133,14 @@ function skipMatchingParens(tokens, idx) {
|
|
|
16127
16133
|
return -1;
|
|
16128
16134
|
}
|
|
16129
16135
|
function hasFileLevelUseServer(source) {
|
|
16136
|
+
return hasFileLevelDirective(source, "use server");
|
|
16137
|
+
}
|
|
16138
|
+
function hasFileLevelDirective(source, directive) {
|
|
16130
16139
|
let i = 0;
|
|
16131
16140
|
const n = source.length;
|
|
16132
16141
|
while (i < n) {
|
|
16133
16142
|
const ch = source.charCodeAt(i);
|
|
16134
|
-
if (ch === 32 || ch === 9 || ch === 10 || ch === 13) {
|
|
16143
|
+
if (ch === 32 || ch === 9 || ch === 10 || ch === 13 || ch === 65279) {
|
|
16135
16144
|
i += 1;
|
|
16136
16145
|
continue;
|
|
16137
16146
|
}
|
|
@@ -16149,8 +16158,8 @@ function hasFileLevelUseServer(source) {
|
|
|
16149
16158
|
}
|
|
16150
16159
|
break;
|
|
16151
16160
|
}
|
|
16152
|
-
const head = source.slice(i, i +
|
|
16153
|
-
return
|
|
16161
|
+
const head = source.slice(i, i + directive.length + 2);
|
|
16162
|
+
return head === `"${directive}"` || head === `'${directive}'`;
|
|
16154
16163
|
}
|
|
16155
16164
|
function rewriteMiddleware(source, name = "middleware") {
|
|
16156
16165
|
const namedRenamed = renameExport(source, name);
|
|
@@ -16179,9 +16188,9 @@ function rewriteMiddleware(source, name = "middleware") {
|
|
|
16179
16188
|
}
|
|
16180
16189
|
return source;
|
|
16181
16190
|
}
|
|
16182
|
-
function
|
|
16191
|
+
function isRootEntryFile(resourcePath, root, name) {
|
|
16183
16192
|
const rel = path.relative(root, resourcePath).split(path.sep).join("/");
|
|
16184
|
-
return
|
|
16193
|
+
return new RegExp(`^(?:src/)?${name}\\.[cm]?[jt]sx?$`).test(rel);
|
|
16185
16194
|
}
|
|
16186
16195
|
function rewritePagesApi(source, routeModulePath) {
|
|
16187
16196
|
const renamed = renameDefaultExport(source);
|
|
@@ -16203,19 +16212,23 @@ function rewritePagesApi(source, routeModulePath) {
|
|
|
16203
16212
|
return renamed.source + wrapperBlock;
|
|
16204
16213
|
}
|
|
16205
16214
|
function renameExport(source, name) {
|
|
16215
|
+
const end = "(?![\\p{L}\\p{N}_$\\u200C\\u200D])";
|
|
16206
16216
|
const patterns = [
|
|
16207
|
-
// `export async function NAME(`
|
|
16208
|
-
new RegExp(`(^|\\s)export\\s+async\\s+function\\s
|
|
16217
|
+
// `export async function NAME(` / `export async function* NAME(`
|
|
16218
|
+
new RegExp(`(^|\\s)export\\s+async\\s+function\\s*\\*?\\s*${name}${end}`, "mu"),
|
|
16209
16219
|
// `export function NAME(`
|
|
16210
|
-
new RegExp(`(^|\\s)export\\s+function\\s
|
|
16220
|
+
new RegExp(`(^|\\s)export\\s+function\\s*\\*?\\s*${name}${end}`, "mu"),
|
|
16211
16221
|
// `export const NAME =` / `export let NAME =` / `export var NAME =`
|
|
16212
|
-
new RegExp(`(^|\\s)export\\s+(const|let|var)\\s+${name}
|
|
16222
|
+
new RegExp(`(^|\\s)export\\s+(const|let|var)\\s+${name}${end}`, "mu")
|
|
16213
16223
|
];
|
|
16214
16224
|
for (const pattern of patterns) {
|
|
16215
16225
|
const match = source.match(pattern);
|
|
16226
|
+
if (match && pattern === patterns[2] && declaresMoreThanOne(source, match.index + match[0].length)) {
|
|
16227
|
+
return { source, changed: false };
|
|
16228
|
+
}
|
|
16216
16229
|
if (match) {
|
|
16217
16230
|
const replaced = source.replace(pattern, (full, lead) => {
|
|
16218
|
-
const rest = full.replace(/^\s*export\s+/, "").replace(new RegExp(
|
|
16231
|
+
const rest = full.replace(/^\s*export\s+/, "").replace(new RegExp(`(?<![\\p{L}\\p{N}_$])${name}${end}`, "u"), `${ALREADY_WRAPPED_MARKER}${name}`);
|
|
16219
16232
|
return `${lead}${rest}`;
|
|
16220
16233
|
});
|
|
16221
16234
|
return { source: replaced, changed: true };
|
|
@@ -16223,6 +16236,31 @@ function renameExport(source, name) {
|
|
|
16223
16236
|
}
|
|
16224
16237
|
return { source, changed: false };
|
|
16225
16238
|
}
|
|
16239
|
+
var TT_JSX_TEXT = 56320;
|
|
16240
|
+
function declaresMoreThanOne(source, from) {
|
|
16241
|
+
const sucraseParse = getSucraseParse();
|
|
16242
|
+
if (sucraseParse === null) return true;
|
|
16243
|
+
let tokens;
|
|
16244
|
+
try {
|
|
16245
|
+
tokens = sucraseParse(source, false, true, false).tokens;
|
|
16246
|
+
} catch {
|
|
16247
|
+
try {
|
|
16248
|
+
tokens = sucraseParse(source, true, true, false).tokens;
|
|
16249
|
+
} catch {
|
|
16250
|
+
return true;
|
|
16251
|
+
}
|
|
16252
|
+
}
|
|
16253
|
+
let depth = 0;
|
|
16254
|
+
for (const t of tokens) {
|
|
16255
|
+
if (t.start < from || t.isType || t.type === TT_JSX_TEXT) continue;
|
|
16256
|
+
const text = source.slice(t.start, t.end);
|
|
16257
|
+
if (text === "(" || text === "[" || text === "{" || text === "${") depth++;
|
|
16258
|
+
else if (text === ")" || text === "]" || text === "}") depth--;
|
|
16259
|
+
else if (depth === 0 && text === ",") return true;
|
|
16260
|
+
else if (depth === 0 && text === ";") return false;
|
|
16261
|
+
}
|
|
16262
|
+
return false;
|
|
16263
|
+
}
|
|
16226
16264
|
function renameDefaultExport(source) {
|
|
16227
16265
|
const fnDefault = source.match(
|
|
16228
16266
|
/(^|\n)\s*export\s+default\s+(async\s+)?function\s*([A-Za-z_$][A-Za-z0-9_$]*)?\s*\(/
|
|
@@ -16290,3 +16328,4 @@ function basename(p) {
|
|
|
16290
16328
|
exports.default = loader;
|
|
16291
16329
|
exports.pitch = pitch;
|
|
16292
16330
|
exports.rewriteInlineServerActions = rewriteInlineServerActions;
|
|
16331
|
+
exports.rewriteInstrumentedImports = rewriteInstrumentedImports;
|
|
@@ -35,6 +35,23 @@ declare function loader(this: PitchContext, source: string): string;
|
|
|
35
35
|
* through the main loader function, which we transform inline.
|
|
36
36
|
*/
|
|
37
37
|
declare function pitch(this: PitchContext, _remainingRequest: string): undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Rewrites `import { X } from "<library>"` (aliases included) so the
|
|
40
|
+
* file's `X` is the agent's instrumented replacement:
|
|
41
|
+
*
|
|
42
|
+
* import { Queue as __ezlogs_import_Queue } from "bullmq"; import { __ezlogsInstrument as __ezlogs_instrument_bullmq } from "ezlogs-nextjs/bullmq"; const Queue = __ezlogs_instrument_bullmq("bullmq#Queue", __ezlogs_import_Queue);
|
|
43
|
+
*
|
|
44
|
+
* The added code stays on the import's own line (line numbers in stack
|
|
45
|
+
* traces are unchanged) and right after it (the binding exists before
|
|
46
|
+
* any top-level code uses it). Only real import statements are touched
|
|
47
|
+
* (the tokenizer tells them from text in comments and strings), and
|
|
48
|
+
* only bindings the file uses as values: a type-only import stays one,
|
|
49
|
+
* so TypeScript still drops it and the library is not pulled into a
|
|
50
|
+
* bundle that never needed it. Client components are left alone: they
|
|
51
|
+
* also render on the server, but their imports are browser code.
|
|
52
|
+
* Idempotent: renamed bindings are not renamed again.
|
|
53
|
+
*/
|
|
54
|
+
declare function rewriteInstrumentedImports(source: string, filename?: string): string;
|
|
38
55
|
/**
|
|
39
56
|
* Rewrite inline `"use server"` actions inside RSC components
|
|
40
57
|
* (page/layout/etc.) so each one runs through
|
|
@@ -69,4 +86,4 @@ declare function pitch(this: PitchContext, _remainingRequest: string): undefined
|
|
|
69
86
|
*/
|
|
70
87
|
declare function rewriteInlineServerActions(source: string, filename: string): string;
|
|
71
88
|
|
|
72
|
-
export { loader as default, pitch, rewriteInlineServerActions };
|
|
89
|
+
export { loader as default, pitch, rewriteInlineServerActions, rewriteInstrumentedImports };
|
|
@@ -35,6 +35,23 @@ declare function loader(this: PitchContext, source: string): string;
|
|
|
35
35
|
* through the main loader function, which we transform inline.
|
|
36
36
|
*/
|
|
37
37
|
declare function pitch(this: PitchContext, _remainingRequest: string): undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Rewrites `import { X } from "<library>"` (aliases included) so the
|
|
40
|
+
* file's `X` is the agent's instrumented replacement:
|
|
41
|
+
*
|
|
42
|
+
* import { Queue as __ezlogs_import_Queue } from "bullmq"; import { __ezlogsInstrument as __ezlogs_instrument_bullmq } from "ezlogs-nextjs/bullmq"; const Queue = __ezlogs_instrument_bullmq("bullmq#Queue", __ezlogs_import_Queue);
|
|
43
|
+
*
|
|
44
|
+
* The added code stays on the import's own line (line numbers in stack
|
|
45
|
+
* traces are unchanged) and right after it (the binding exists before
|
|
46
|
+
* any top-level code uses it). Only real import statements are touched
|
|
47
|
+
* (the tokenizer tells them from text in comments and strings), and
|
|
48
|
+
* only bindings the file uses as values: a type-only import stays one,
|
|
49
|
+
* so TypeScript still drops it and the library is not pulled into a
|
|
50
|
+
* bundle that never needed it. Client components are left alone: they
|
|
51
|
+
* also render on the server, but their imports are browser code.
|
|
52
|
+
* Idempotent: renamed bindings are not renamed again.
|
|
53
|
+
*/
|
|
54
|
+
declare function rewriteInstrumentedImports(source: string, filename?: string): string;
|
|
38
55
|
/**
|
|
39
56
|
* Rewrite inline `"use server"` actions inside RSC components
|
|
40
57
|
* (page/layout/etc.) so each one runs through
|
|
@@ -69,4 +86,4 @@ declare function pitch(this: PitchContext, _remainingRequest: string): undefined
|
|
|
69
86
|
*/
|
|
70
87
|
declare function rewriteInlineServerActions(source: string, filename: string): string;
|
|
71
88
|
|
|
72
|
-
export { loader as default, pitch, rewriteInlineServerActions };
|
|
89
|
+
export { loader as default, pitch, rewriteInlineServerActions, rewriteInstrumentedImports };
|