@onruntime/next-sitemap 0.6.0 → 0.6.2

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.
@@ -2,9 +2,12 @@
2
2
 
3
3
  var fs = require('fs');
4
4
  var path = require('path');
5
- var jiti$1 = require('jiti');
5
+ var jiti = require('jiti');
6
+ var stripJsonComments = require('strip-json-comments');
6
7
 
7
8
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
8
11
  function _interopNamespace(e) {
9
12
  if (e && e.__esModule) return e;
10
13
  var n = Object.create(null);
@@ -25,6 +28,7 @@ function _interopNamespace(e) {
25
28
 
26
29
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
27
30
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
31
+ var stripJsonComments__default = /*#__PURE__*/_interopDefault(stripJsonComments);
28
32
 
29
33
  // src/app/index.ts
30
34
 
@@ -129,6 +133,7 @@ ${allEntries}
129
133
  }
130
134
 
131
135
  // src/app/index.ts
136
+ var joinPath = (...segments) => path__namespace.join(...segments);
132
137
  function findPageFiles(dir, baseDir = dir) {
133
138
  const files = [];
134
139
  try {
@@ -137,7 +142,7 @@ function findPageFiles(dir, baseDir = dir) {
137
142
  const fullPath = path__namespace.join(dir, entry.name);
138
143
  if (entry.isDirectory()) {
139
144
  files.push(...findPageFiles(fullPath, baseDir));
140
- } else if (entry.name === "page.tsx" || entry.name === "page.ts") {
145
+ } else if (/^page\.(tsx?|jsx?)$/.test(entry.name)) {
141
146
  const relativePath = "./" + path__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
142
147
  files.push(relativePath);
143
148
  }
@@ -162,17 +167,73 @@ function resolveAppDirectory(options) {
162
167
  function getPageKeys(options) {
163
168
  return findPageFiles(resolveAppDirectory(options));
164
169
  }
165
- var jiti = jiti$1.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)), { jsx: true });
166
- async function importPage(appDirectory, key) {
170
+ var jitiCache = /* @__PURE__ */ new Map();
171
+ function getTsconfigPaths(projectRoot, debug = false) {
172
+ const alias = {};
173
+ try {
174
+ const tsconfigPath = path__namespace.join(projectRoot, "tsconfig.json");
175
+ if (debug) {
176
+ console.log("[next-sitemap] Looking for tsconfig at:", tsconfigPath);
177
+ console.log("[next-sitemap] tsconfig exists:", fs__namespace.existsSync(tsconfigPath));
178
+ }
179
+ if (fs__namespace.existsSync(tsconfigPath)) {
180
+ const content = fs__namespace.readFileSync(tsconfigPath, "utf-8");
181
+ const withoutComments = stripJsonComments__default.default(content);
182
+ const cleaned = withoutComments.replace(/,(\s*[}\]])/g, "$1");
183
+ if (debug) {
184
+ console.log("[next-sitemap] Cleaned tsconfig (first 500 chars):", cleaned.slice(0, 500));
185
+ }
186
+ const tsconfig = JSON.parse(cleaned);
187
+ if (debug) {
188
+ console.log("[next-sitemap] Parsed tsconfig paths:", tsconfig.compilerOptions?.paths);
189
+ }
190
+ const baseUrl = tsconfig.compilerOptions?.baseUrl || ".";
191
+ const paths = tsconfig.compilerOptions?.paths || {};
192
+ for (const [key, values] of Object.entries(paths)) {
193
+ if (values.length > 0) {
194
+ const aliasKey = key.replace(/\*$/, "");
195
+ const aliasValue = joinPath(projectRoot, baseUrl, values[0].replace(/\*$/, ""));
196
+ alias[aliasKey] = aliasValue;
197
+ }
198
+ }
199
+ }
200
+ } catch (error) {
201
+ if (debug) {
202
+ console.error("[next-sitemap] Error parsing tsconfig:", error);
203
+ }
204
+ }
205
+ return alias;
206
+ }
207
+ function getJiti(projectRoot, debug = false) {
208
+ if (jitiCache.has(projectRoot)) {
209
+ return jitiCache.get(projectRoot);
210
+ }
211
+ const alias = getTsconfigPaths(projectRoot, debug);
212
+ if (debug) {
213
+ console.log("[next-sitemap] Final alias config:", JSON.stringify(alias));
214
+ }
215
+ const jiti$1 = jiti.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)), {
216
+ moduleCache: false,
217
+ interopDefault: true,
218
+ jsx: true,
219
+ alias
220
+ });
221
+ jitiCache.set(projectRoot, jiti$1);
222
+ return jiti$1;
223
+ }
224
+ async function importPage(appDirectory, key, debug = false) {
167
225
  const relativePath = key.replace("./", "");
168
226
  const absolutePath = path__namespace.join(appDirectory, relativePath);
169
- return jiti.import(absolutePath);
227
+ const projectRoot = process.cwd();
228
+ const jiti = getJiti(projectRoot, debug);
229
+ const module = await jiti.import(absolutePath);
230
+ return module.default || module;
170
231
  }
171
232
  function extractRoutes(pageKeys, localeSegment) {
172
233
  const routes = [];
173
234
  for (const key of pageKeys) {
174
235
  if (key.includes("[...")) continue;
175
- let pathname = key.replace("./", "/").replace("/page.tsx", "");
236
+ let pathname = key.replace("./", "/").replace(/\/page\.(tsx?|jsx?)$/, "");
176
237
  if (localeSegment) {
177
238
  pathname = pathname.replace(
178
239
  new RegExp(`^/${localeSegment.replace(/[[\]]/g, "\\$&")}`),
@@ -210,7 +271,7 @@ async function getAllPaths(routes, appDirectory, debug = false) {
210
271
  if (debug) {
211
272
  console.log(`[next-sitemap] ${route.pathname}: importing ${route.key}`);
212
273
  }
213
- const module = await importPage(appDirectory, route.key);
274
+ const module = await importPage(appDirectory, route.key, debug);
214
275
  getParams = module.generateStaticParams || null;
215
276
  } catch (error) {
216
277
  if (debug) {
package/dist/app/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { createJiti } from 'jiti';
4
+ import stripJsonComments from 'strip-json-comments';
4
5
 
5
6
  // src/app/index.ts
6
7
 
@@ -105,6 +106,7 @@ ${allEntries}
105
106
  }
106
107
 
107
108
  // src/app/index.ts
109
+ var joinPath = (...segments) => path.join(...segments);
108
110
  function findPageFiles(dir, baseDir = dir) {
109
111
  const files = [];
110
112
  try {
@@ -113,7 +115,7 @@ function findPageFiles(dir, baseDir = dir) {
113
115
  const fullPath = path.join(dir, entry.name);
114
116
  if (entry.isDirectory()) {
115
117
  files.push(...findPageFiles(fullPath, baseDir));
116
- } else if (entry.name === "page.tsx" || entry.name === "page.ts") {
118
+ } else if (/^page\.(tsx?|jsx?)$/.test(entry.name)) {
117
119
  const relativePath = "./" + path.relative(baseDir, fullPath).replace(/\\/g, "/");
118
120
  files.push(relativePath);
119
121
  }
@@ -138,17 +140,73 @@ function resolveAppDirectory(options) {
138
140
  function getPageKeys(options) {
139
141
  return findPageFiles(resolveAppDirectory(options));
140
142
  }
141
- var jiti = createJiti(import.meta.url, { jsx: true });
142
- async function importPage(appDirectory, key) {
143
+ var jitiCache = /* @__PURE__ */ new Map();
144
+ function getTsconfigPaths(projectRoot, debug = false) {
145
+ const alias = {};
146
+ try {
147
+ const tsconfigPath = path.join(projectRoot, "tsconfig.json");
148
+ if (debug) {
149
+ console.log("[next-sitemap] Looking for tsconfig at:", tsconfigPath);
150
+ console.log("[next-sitemap] tsconfig exists:", fs.existsSync(tsconfigPath));
151
+ }
152
+ if (fs.existsSync(tsconfigPath)) {
153
+ const content = fs.readFileSync(tsconfigPath, "utf-8");
154
+ const withoutComments = stripJsonComments(content);
155
+ const cleaned = withoutComments.replace(/,(\s*[}\]])/g, "$1");
156
+ if (debug) {
157
+ console.log("[next-sitemap] Cleaned tsconfig (first 500 chars):", cleaned.slice(0, 500));
158
+ }
159
+ const tsconfig = JSON.parse(cleaned);
160
+ if (debug) {
161
+ console.log("[next-sitemap] Parsed tsconfig paths:", tsconfig.compilerOptions?.paths);
162
+ }
163
+ const baseUrl = tsconfig.compilerOptions?.baseUrl || ".";
164
+ const paths = tsconfig.compilerOptions?.paths || {};
165
+ for (const [key, values] of Object.entries(paths)) {
166
+ if (values.length > 0) {
167
+ const aliasKey = key.replace(/\*$/, "");
168
+ const aliasValue = joinPath(projectRoot, baseUrl, values[0].replace(/\*$/, ""));
169
+ alias[aliasKey] = aliasValue;
170
+ }
171
+ }
172
+ }
173
+ } catch (error) {
174
+ if (debug) {
175
+ console.error("[next-sitemap] Error parsing tsconfig:", error);
176
+ }
177
+ }
178
+ return alias;
179
+ }
180
+ function getJiti(projectRoot, debug = false) {
181
+ if (jitiCache.has(projectRoot)) {
182
+ return jitiCache.get(projectRoot);
183
+ }
184
+ const alias = getTsconfigPaths(projectRoot, debug);
185
+ if (debug) {
186
+ console.log("[next-sitemap] Final alias config:", JSON.stringify(alias));
187
+ }
188
+ const jiti = createJiti(import.meta.url, {
189
+ moduleCache: false,
190
+ interopDefault: true,
191
+ jsx: true,
192
+ alias
193
+ });
194
+ jitiCache.set(projectRoot, jiti);
195
+ return jiti;
196
+ }
197
+ async function importPage(appDirectory, key, debug = false) {
143
198
  const relativePath = key.replace("./", "");
144
199
  const absolutePath = path.join(appDirectory, relativePath);
145
- return jiti.import(absolutePath);
200
+ const projectRoot = process.cwd();
201
+ const jiti = getJiti(projectRoot, debug);
202
+ const module = await jiti.import(absolutePath);
203
+ return module.default || module;
146
204
  }
147
205
  function extractRoutes(pageKeys, localeSegment) {
148
206
  const routes = [];
149
207
  for (const key of pageKeys) {
150
208
  if (key.includes("[...")) continue;
151
- let pathname = key.replace("./", "/").replace("/page.tsx", "");
209
+ let pathname = key.replace("./", "/").replace(/\/page\.(tsx?|jsx?)$/, "");
152
210
  if (localeSegment) {
153
211
  pathname = pathname.replace(
154
212
  new RegExp(`^/${localeSegment.replace(/[[\]]/g, "\\$&")}`),
@@ -186,7 +244,7 @@ async function getAllPaths(routes, appDirectory, debug = false) {
186
244
  if (debug) {
187
245
  console.log(`[next-sitemap] ${route.pathname}: importing ${route.key}`);
188
246
  }
189
- const module = await importPage(appDirectory, route.key);
247
+ const module = await importPage(appDirectory, route.key, debug);
190
248
  getParams = module.generateStaticParams || null;
191
249
  } catch (error) {
192
250
  if (debug) {
@@ -2,9 +2,12 @@
2
2
 
3
3
  var fs = require('fs');
4
4
  var path = require('path');
5
- var jiti$1 = require('jiti');
5
+ var jiti = require('jiti');
6
+ var stripJsonComments = require('strip-json-comments');
6
7
 
7
8
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
8
11
  function _interopNamespace(e) {
9
12
  if (e && e.__esModule) return e;
10
13
  var n = Object.create(null);
@@ -25,6 +28,7 @@ function _interopNamespace(e) {
25
28
 
26
29
  var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
27
30
  var path__namespace = /*#__PURE__*/_interopNamespace(path);
31
+ var stripJsonComments__default = /*#__PURE__*/_interopDefault(stripJsonComments);
28
32
 
29
33
  // src/pages/index.ts
30
34
 
@@ -167,6 +171,7 @@ function generateRobotsTxt(config) {
167
171
  }
168
172
 
169
173
  // src/pages/index.ts
174
+ var joinPath = (...segments) => path__namespace.join(...segments);
170
175
  function findPageFiles(dir, baseDir = dir) {
171
176
  const files = [];
172
177
  try {
@@ -176,7 +181,7 @@ function findPageFiles(dir, baseDir = dir) {
176
181
  if (entry.isDirectory()) {
177
182
  if (entry.name === "api") continue;
178
183
  files.push(...findPageFiles(fullPath, baseDir));
179
- } else if ((entry.name.endsWith(".tsx") || entry.name.endsWith(".ts")) && !entry.name.startsWith("_")) {
184
+ } else if (/\.(tsx?|jsx?)$/.test(entry.name) && !entry.name.startsWith("_")) {
180
185
  const relativePath = "./" + path__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
181
186
  files.push(relativePath);
182
187
  }
@@ -201,17 +206,57 @@ function resolvePagesDirectory(options) {
201
206
  function getPageKeys(options) {
202
207
  return findPageFiles(resolvePagesDirectory(options));
203
208
  }
204
- var jiti = jiti$1.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)), { jsx: true });
209
+ var jitiCache = /* @__PURE__ */ new Map();
210
+ function getTsconfigPaths(projectRoot) {
211
+ const alias = {};
212
+ try {
213
+ const tsconfigPath = path__namespace.join(projectRoot, "tsconfig.json");
214
+ if (fs__namespace.existsSync(tsconfigPath)) {
215
+ const content = fs__namespace.readFileSync(tsconfigPath, "utf-8");
216
+ const withoutComments = stripJsonComments__default.default(content);
217
+ const cleaned = withoutComments.replace(/,(\s*[}\]])/g, "$1");
218
+ const tsconfig = JSON.parse(cleaned);
219
+ const baseUrl = tsconfig.compilerOptions?.baseUrl || ".";
220
+ const paths = tsconfig.compilerOptions?.paths || {};
221
+ for (const [key, values] of Object.entries(paths)) {
222
+ if (values.length > 0) {
223
+ const aliasKey = key.replace(/\*$/, "");
224
+ const aliasValue = joinPath(projectRoot, baseUrl, values[0].replace(/\*$/, ""));
225
+ alias[aliasKey] = aliasValue;
226
+ }
227
+ }
228
+ }
229
+ } catch {
230
+ }
231
+ return alias;
232
+ }
233
+ function getJiti(projectRoot) {
234
+ if (jitiCache.has(projectRoot)) {
235
+ return jitiCache.get(projectRoot);
236
+ }
237
+ const alias = getTsconfigPaths(projectRoot);
238
+ const jiti$1 = jiti.createJiti((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)), {
239
+ moduleCache: false,
240
+ interopDefault: true,
241
+ jsx: true,
242
+ alias
243
+ });
244
+ jitiCache.set(projectRoot, jiti$1);
245
+ return jiti$1;
246
+ }
205
247
  async function importPage(pagesDirectory, key) {
206
248
  const relativePath = key.replace("./", "");
207
249
  const absolutePath = path__namespace.join(pagesDirectory, relativePath);
208
- return jiti.import(absolutePath);
250
+ const projectRoot = process.cwd();
251
+ const jiti = getJiti(projectRoot);
252
+ const module = await jiti.import(absolutePath);
253
+ return module.default || module;
209
254
  }
210
255
  function extractRoutes(pageKeys, localeSegment) {
211
256
  const routes = [];
212
257
  for (const key of pageKeys) {
213
258
  if (key.includes("[...")) continue;
214
- let pathname = key.replace(/^\.\//, "/").replace(/\.tsx?$/, "").replace(/\/index$/, "/");
259
+ let pathname = key.replace(/^\.\//, "/").replace(/\.(tsx?|jsx?)$/, "").replace(/\/index$/, "/");
215
260
  if (pathname === "") pathname = "/";
216
261
  if (localeSegment) {
217
262
  pathname = pathname.replace(
@@ -1,6 +1,7 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
3
  import { createJiti } from 'jiti';
4
+ import stripJsonComments from 'strip-json-comments';
4
5
 
5
6
  // src/pages/index.ts
6
7
 
@@ -143,6 +144,7 @@ function generateRobotsTxt(config) {
143
144
  }
144
145
 
145
146
  // src/pages/index.ts
147
+ var joinPath = (...segments) => path.join(...segments);
146
148
  function findPageFiles(dir, baseDir = dir) {
147
149
  const files = [];
148
150
  try {
@@ -152,7 +154,7 @@ function findPageFiles(dir, baseDir = dir) {
152
154
  if (entry.isDirectory()) {
153
155
  if (entry.name === "api") continue;
154
156
  files.push(...findPageFiles(fullPath, baseDir));
155
- } else if ((entry.name.endsWith(".tsx") || entry.name.endsWith(".ts")) && !entry.name.startsWith("_")) {
157
+ } else if (/\.(tsx?|jsx?)$/.test(entry.name) && !entry.name.startsWith("_")) {
156
158
  const relativePath = "./" + path.relative(baseDir, fullPath).replace(/\\/g, "/");
157
159
  files.push(relativePath);
158
160
  }
@@ -177,17 +179,57 @@ function resolvePagesDirectory(options) {
177
179
  function getPageKeys(options) {
178
180
  return findPageFiles(resolvePagesDirectory(options));
179
181
  }
180
- var jiti = createJiti(import.meta.url, { jsx: true });
182
+ var jitiCache = /* @__PURE__ */ new Map();
183
+ function getTsconfigPaths(projectRoot) {
184
+ const alias = {};
185
+ try {
186
+ const tsconfigPath = path.join(projectRoot, "tsconfig.json");
187
+ if (fs.existsSync(tsconfigPath)) {
188
+ const content = fs.readFileSync(tsconfigPath, "utf-8");
189
+ const withoutComments = stripJsonComments(content);
190
+ const cleaned = withoutComments.replace(/,(\s*[}\]])/g, "$1");
191
+ const tsconfig = JSON.parse(cleaned);
192
+ const baseUrl = tsconfig.compilerOptions?.baseUrl || ".";
193
+ const paths = tsconfig.compilerOptions?.paths || {};
194
+ for (const [key, values] of Object.entries(paths)) {
195
+ if (values.length > 0) {
196
+ const aliasKey = key.replace(/\*$/, "");
197
+ const aliasValue = joinPath(projectRoot, baseUrl, values[0].replace(/\*$/, ""));
198
+ alias[aliasKey] = aliasValue;
199
+ }
200
+ }
201
+ }
202
+ } catch {
203
+ }
204
+ return alias;
205
+ }
206
+ function getJiti(projectRoot) {
207
+ if (jitiCache.has(projectRoot)) {
208
+ return jitiCache.get(projectRoot);
209
+ }
210
+ const alias = getTsconfigPaths(projectRoot);
211
+ const jiti = createJiti(import.meta.url, {
212
+ moduleCache: false,
213
+ interopDefault: true,
214
+ jsx: true,
215
+ alias
216
+ });
217
+ jitiCache.set(projectRoot, jiti);
218
+ return jiti;
219
+ }
181
220
  async function importPage(pagesDirectory, key) {
182
221
  const relativePath = key.replace("./", "");
183
222
  const absolutePath = path.join(pagesDirectory, relativePath);
184
- return jiti.import(absolutePath);
223
+ const projectRoot = process.cwd();
224
+ const jiti = getJiti(projectRoot);
225
+ const module = await jiti.import(absolutePath);
226
+ return module.default || module;
185
227
  }
186
228
  function extractRoutes(pageKeys, localeSegment) {
187
229
  const routes = [];
188
230
  for (const key of pageKeys) {
189
231
  if (key.includes("[...")) continue;
190
- let pathname = key.replace(/^\.\//, "/").replace(/\.tsx?$/, "").replace(/\/index$/, "/");
232
+ let pathname = key.replace(/^\.\//, "/").replace(/\.(tsx?|jsx?)$/, "").replace(/\/index$/, "/");
191
233
  if (pathname === "") pathname = "/";
192
234
  if (localeSegment) {
193
235
  pathname = pathname.replace(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onruntime/next-sitemap",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Dynamic sitemap generation for Next.js with automatic route discovery",
5
5
  "author": "onRuntime Studio <contact@onruntime.com>",
6
6
  "repository": {
@@ -39,7 +39,8 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "jiti": "^2.6.1"
42
+ "jiti": "^2",
43
+ "strip-json-comments": "^5"
43
44
  },
44
45
  "peerDependencies": {
45
46
  "next": ">=14.0.0"