@onruntime/next-sitemap 0.6.0 → 0.6.1

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
 
@@ -137,7 +141,7 @@ function findPageFiles(dir, baseDir = dir) {
137
141
  const fullPath = path__namespace.join(dir, entry.name);
138
142
  if (entry.isDirectory()) {
139
143
  files.push(...findPageFiles(fullPath, baseDir));
140
- } else if (entry.name === "page.tsx" || entry.name === "page.ts") {
144
+ } else if (/^page\.(tsx?|jsx?)$/.test(entry.name)) {
141
145
  const relativePath = "./" + path__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
142
146
  files.push(relativePath);
143
147
  }
@@ -162,17 +166,73 @@ function resolveAppDirectory(options) {
162
166
  function getPageKeys(options) {
163
167
  return findPageFiles(resolveAppDirectory(options));
164
168
  }
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) {
169
+ var jitiCache = /* @__PURE__ */ new Map();
170
+ function getTsconfigPaths(projectRoot, debug = false) {
171
+ const alias = {};
172
+ try {
173
+ const tsconfigPath = path__namespace.join(projectRoot, "tsconfig.json");
174
+ if (debug) {
175
+ console.log("[next-sitemap] Looking for tsconfig at:", tsconfigPath);
176
+ console.log("[next-sitemap] tsconfig exists:", fs__namespace.existsSync(tsconfigPath));
177
+ }
178
+ if (fs__namespace.existsSync(tsconfigPath)) {
179
+ const content = fs__namespace.readFileSync(tsconfigPath, "utf-8");
180
+ const withoutComments = stripJsonComments__default.default(content);
181
+ const cleaned = withoutComments.replace(/,(\s*[}\]])/g, "$1");
182
+ if (debug) {
183
+ console.log("[next-sitemap] Cleaned tsconfig (first 500 chars):", cleaned.slice(0, 500));
184
+ }
185
+ const tsconfig = JSON.parse(cleaned);
186
+ if (debug) {
187
+ console.log("[next-sitemap] Parsed tsconfig paths:", tsconfig.compilerOptions?.paths);
188
+ }
189
+ const baseUrl = tsconfig.compilerOptions?.baseUrl || ".";
190
+ const paths = tsconfig.compilerOptions?.paths || {};
191
+ for (const [key, values] of Object.entries(paths)) {
192
+ if (values.length > 0) {
193
+ const aliasKey = key.replace(/\*$/, "");
194
+ const aliasValue = path__namespace.join(projectRoot, baseUrl, values[0].replace(/\*$/, ""));
195
+ alias[aliasKey] = aliasValue;
196
+ }
197
+ }
198
+ }
199
+ } catch (error) {
200
+ if (debug) {
201
+ console.error("[next-sitemap] Error parsing tsconfig:", error);
202
+ }
203
+ }
204
+ return alias;
205
+ }
206
+ function getJiti(projectRoot, debug = false) {
207
+ if (jitiCache.has(projectRoot)) {
208
+ return jitiCache.get(projectRoot);
209
+ }
210
+ const alias = getTsconfigPaths(projectRoot, debug);
211
+ if (debug) {
212
+ console.log("[next-sitemap] Final alias config:", JSON.stringify(alias));
213
+ }
214
+ 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)), {
215
+ moduleCache: false,
216
+ interopDefault: true,
217
+ jsx: true,
218
+ alias
219
+ });
220
+ jitiCache.set(projectRoot, jiti$1);
221
+ return jiti$1;
222
+ }
223
+ async function importPage(appDirectory, key, debug = false) {
167
224
  const relativePath = key.replace("./", "");
168
225
  const absolutePath = path__namespace.join(appDirectory, relativePath);
169
- return jiti.import(absolutePath);
226
+ const projectRoot = process.cwd();
227
+ const jiti = getJiti(projectRoot, debug);
228
+ const module = await jiti.import(absolutePath);
229
+ return module.default || module;
170
230
  }
171
231
  function extractRoutes(pageKeys, localeSegment) {
172
232
  const routes = [];
173
233
  for (const key of pageKeys) {
174
234
  if (key.includes("[...")) continue;
175
- let pathname = key.replace("./", "/").replace("/page.tsx", "");
235
+ let pathname = key.replace("./", "/").replace(/\/page\.(tsx?|jsx?)$/, "");
176
236
  if (localeSegment) {
177
237
  pathname = pathname.replace(
178
238
  new RegExp(`^/${localeSegment.replace(/[[\]]/g, "\\$&")}`),
@@ -210,7 +270,7 @@ async function getAllPaths(routes, appDirectory, debug = false) {
210
270
  if (debug) {
211
271
  console.log(`[next-sitemap] ${route.pathname}: importing ${route.key}`);
212
272
  }
213
- const module = await importPage(appDirectory, route.key);
273
+ const module = await importPage(appDirectory, route.key, debug);
214
274
  getParams = module.generateStaticParams || null;
215
275
  } catch (error) {
216
276
  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
 
@@ -113,7 +114,7 @@ function findPageFiles(dir, baseDir = dir) {
113
114
  const fullPath = path.join(dir, entry.name);
114
115
  if (entry.isDirectory()) {
115
116
  files.push(...findPageFiles(fullPath, baseDir));
116
- } else if (entry.name === "page.tsx" || entry.name === "page.ts") {
117
+ } else if (/^page\.(tsx?|jsx?)$/.test(entry.name)) {
117
118
  const relativePath = "./" + path.relative(baseDir, fullPath).replace(/\\/g, "/");
118
119
  files.push(relativePath);
119
120
  }
@@ -138,17 +139,73 @@ function resolveAppDirectory(options) {
138
139
  function getPageKeys(options) {
139
140
  return findPageFiles(resolveAppDirectory(options));
140
141
  }
141
- var jiti = createJiti(import.meta.url, { jsx: true });
142
- async function importPage(appDirectory, key) {
142
+ var jitiCache = /* @__PURE__ */ new Map();
143
+ function getTsconfigPaths(projectRoot, debug = false) {
144
+ const alias = {};
145
+ try {
146
+ const tsconfigPath = path.join(projectRoot, "tsconfig.json");
147
+ if (debug) {
148
+ console.log("[next-sitemap] Looking for tsconfig at:", tsconfigPath);
149
+ console.log("[next-sitemap] tsconfig exists:", fs.existsSync(tsconfigPath));
150
+ }
151
+ if (fs.existsSync(tsconfigPath)) {
152
+ const content = fs.readFileSync(tsconfigPath, "utf-8");
153
+ const withoutComments = stripJsonComments(content);
154
+ const cleaned = withoutComments.replace(/,(\s*[}\]])/g, "$1");
155
+ if (debug) {
156
+ console.log("[next-sitemap] Cleaned tsconfig (first 500 chars):", cleaned.slice(0, 500));
157
+ }
158
+ const tsconfig = JSON.parse(cleaned);
159
+ if (debug) {
160
+ console.log("[next-sitemap] Parsed tsconfig paths:", tsconfig.compilerOptions?.paths);
161
+ }
162
+ const baseUrl = tsconfig.compilerOptions?.baseUrl || ".";
163
+ const paths = tsconfig.compilerOptions?.paths || {};
164
+ for (const [key, values] of Object.entries(paths)) {
165
+ if (values.length > 0) {
166
+ const aliasKey = key.replace(/\*$/, "");
167
+ const aliasValue = path.join(projectRoot, baseUrl, values[0].replace(/\*$/, ""));
168
+ alias[aliasKey] = aliasValue;
169
+ }
170
+ }
171
+ }
172
+ } catch (error) {
173
+ if (debug) {
174
+ console.error("[next-sitemap] Error parsing tsconfig:", error);
175
+ }
176
+ }
177
+ return alias;
178
+ }
179
+ function getJiti(projectRoot, debug = false) {
180
+ if (jitiCache.has(projectRoot)) {
181
+ return jitiCache.get(projectRoot);
182
+ }
183
+ const alias = getTsconfigPaths(projectRoot, debug);
184
+ if (debug) {
185
+ console.log("[next-sitemap] Final alias config:", JSON.stringify(alias));
186
+ }
187
+ const jiti = createJiti(import.meta.url, {
188
+ moduleCache: false,
189
+ interopDefault: true,
190
+ jsx: true,
191
+ alias
192
+ });
193
+ jitiCache.set(projectRoot, jiti);
194
+ return jiti;
195
+ }
196
+ async function importPage(appDirectory, key, debug = false) {
143
197
  const relativePath = key.replace("./", "");
144
198
  const absolutePath = path.join(appDirectory, relativePath);
145
- return jiti.import(absolutePath);
199
+ const projectRoot = process.cwd();
200
+ const jiti = getJiti(projectRoot, debug);
201
+ const module = await jiti.import(absolutePath);
202
+ return module.default || module;
146
203
  }
147
204
  function extractRoutes(pageKeys, localeSegment) {
148
205
  const routes = [];
149
206
  for (const key of pageKeys) {
150
207
  if (key.includes("[...")) continue;
151
- let pathname = key.replace("./", "/").replace("/page.tsx", "");
208
+ let pathname = key.replace("./", "/").replace(/\/page\.(tsx?|jsx?)$/, "");
152
209
  if (localeSegment) {
153
210
  pathname = pathname.replace(
154
211
  new RegExp(`^/${localeSegment.replace(/[[\]]/g, "\\$&")}`),
@@ -186,7 +243,7 @@ async function getAllPaths(routes, appDirectory, debug = false) {
186
243
  if (debug) {
187
244
  console.log(`[next-sitemap] ${route.pathname}: importing ${route.key}`);
188
245
  }
189
- const module = await importPage(appDirectory, route.key);
246
+ const module = await importPage(appDirectory, route.key, debug);
190
247
  getParams = module.generateStaticParams || null;
191
248
  } catch (error) {
192
249
  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
 
@@ -176,7 +180,7 @@ function findPageFiles(dir, baseDir = dir) {
176
180
  if (entry.isDirectory()) {
177
181
  if (entry.name === "api") continue;
178
182
  files.push(...findPageFiles(fullPath, baseDir));
179
- } else if ((entry.name.endsWith(".tsx") || entry.name.endsWith(".ts")) && !entry.name.startsWith("_")) {
183
+ } else if (/\.(tsx?|jsx?)$/.test(entry.name) && !entry.name.startsWith("_")) {
180
184
  const relativePath = "./" + path__namespace.relative(baseDir, fullPath).replace(/\\/g, "/");
181
185
  files.push(relativePath);
182
186
  }
@@ -201,17 +205,57 @@ function resolvePagesDirectory(options) {
201
205
  function getPageKeys(options) {
202
206
  return findPageFiles(resolvePagesDirectory(options));
203
207
  }
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 });
208
+ var jitiCache = /* @__PURE__ */ new Map();
209
+ function getTsconfigPaths(projectRoot) {
210
+ const alias = {};
211
+ try {
212
+ const tsconfigPath = path__namespace.join(projectRoot, "tsconfig.json");
213
+ if (fs__namespace.existsSync(tsconfigPath)) {
214
+ const content = fs__namespace.readFileSync(tsconfigPath, "utf-8");
215
+ const withoutComments = stripJsonComments__default.default(content);
216
+ const cleaned = withoutComments.replace(/,(\s*[}\]])/g, "$1");
217
+ const tsconfig = JSON.parse(cleaned);
218
+ const baseUrl = tsconfig.compilerOptions?.baseUrl || ".";
219
+ const paths = tsconfig.compilerOptions?.paths || {};
220
+ for (const [key, values] of Object.entries(paths)) {
221
+ if (values.length > 0) {
222
+ const aliasKey = key.replace(/\*$/, "");
223
+ const aliasValue = path__namespace.join(projectRoot, baseUrl, values[0].replace(/\*$/, ""));
224
+ alias[aliasKey] = aliasValue;
225
+ }
226
+ }
227
+ }
228
+ } catch {
229
+ }
230
+ return alias;
231
+ }
232
+ function getJiti(projectRoot) {
233
+ if (jitiCache.has(projectRoot)) {
234
+ return jitiCache.get(projectRoot);
235
+ }
236
+ const alias = getTsconfigPaths(projectRoot);
237
+ 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)), {
238
+ moduleCache: false,
239
+ interopDefault: true,
240
+ jsx: true,
241
+ alias
242
+ });
243
+ jitiCache.set(projectRoot, jiti$1);
244
+ return jiti$1;
245
+ }
205
246
  async function importPage(pagesDirectory, key) {
206
247
  const relativePath = key.replace("./", "");
207
248
  const absolutePath = path__namespace.join(pagesDirectory, relativePath);
208
- return jiti.import(absolutePath);
249
+ const projectRoot = process.cwd();
250
+ const jiti = getJiti(projectRoot);
251
+ const module = await jiti.import(absolutePath);
252
+ return module.default || module;
209
253
  }
210
254
  function extractRoutes(pageKeys, localeSegment) {
211
255
  const routes = [];
212
256
  for (const key of pageKeys) {
213
257
  if (key.includes("[...")) continue;
214
- let pathname = key.replace(/^\.\//, "/").replace(/\.tsx?$/, "").replace(/\/index$/, "/");
258
+ let pathname = key.replace(/^\.\//, "/").replace(/\.(tsx?|jsx?)$/, "").replace(/\/index$/, "/");
215
259
  if (pathname === "") pathname = "/";
216
260
  if (localeSegment) {
217
261
  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
 
@@ -152,7 +153,7 @@ function findPageFiles(dir, baseDir = dir) {
152
153
  if (entry.isDirectory()) {
153
154
  if (entry.name === "api") continue;
154
155
  files.push(...findPageFiles(fullPath, baseDir));
155
- } else if ((entry.name.endsWith(".tsx") || entry.name.endsWith(".ts")) && !entry.name.startsWith("_")) {
156
+ } else if (/\.(tsx?|jsx?)$/.test(entry.name) && !entry.name.startsWith("_")) {
156
157
  const relativePath = "./" + path.relative(baseDir, fullPath).replace(/\\/g, "/");
157
158
  files.push(relativePath);
158
159
  }
@@ -177,17 +178,57 @@ function resolvePagesDirectory(options) {
177
178
  function getPageKeys(options) {
178
179
  return findPageFiles(resolvePagesDirectory(options));
179
180
  }
180
- var jiti = createJiti(import.meta.url, { jsx: true });
181
+ var jitiCache = /* @__PURE__ */ new Map();
182
+ function getTsconfigPaths(projectRoot) {
183
+ const alias = {};
184
+ try {
185
+ const tsconfigPath = path.join(projectRoot, "tsconfig.json");
186
+ if (fs.existsSync(tsconfigPath)) {
187
+ const content = fs.readFileSync(tsconfigPath, "utf-8");
188
+ const withoutComments = stripJsonComments(content);
189
+ const cleaned = withoutComments.replace(/,(\s*[}\]])/g, "$1");
190
+ const tsconfig = JSON.parse(cleaned);
191
+ const baseUrl = tsconfig.compilerOptions?.baseUrl || ".";
192
+ const paths = tsconfig.compilerOptions?.paths || {};
193
+ for (const [key, values] of Object.entries(paths)) {
194
+ if (values.length > 0) {
195
+ const aliasKey = key.replace(/\*$/, "");
196
+ const aliasValue = path.join(projectRoot, baseUrl, values[0].replace(/\*$/, ""));
197
+ alias[aliasKey] = aliasValue;
198
+ }
199
+ }
200
+ }
201
+ } catch {
202
+ }
203
+ return alias;
204
+ }
205
+ function getJiti(projectRoot) {
206
+ if (jitiCache.has(projectRoot)) {
207
+ return jitiCache.get(projectRoot);
208
+ }
209
+ const alias = getTsconfigPaths(projectRoot);
210
+ const jiti = createJiti(import.meta.url, {
211
+ moduleCache: false,
212
+ interopDefault: true,
213
+ jsx: true,
214
+ alias
215
+ });
216
+ jitiCache.set(projectRoot, jiti);
217
+ return jiti;
218
+ }
181
219
  async function importPage(pagesDirectory, key) {
182
220
  const relativePath = key.replace("./", "");
183
221
  const absolutePath = path.join(pagesDirectory, relativePath);
184
- return jiti.import(absolutePath);
222
+ const projectRoot = process.cwd();
223
+ const jiti = getJiti(projectRoot);
224
+ const module = await jiti.import(absolutePath);
225
+ return module.default || module;
185
226
  }
186
227
  function extractRoutes(pageKeys, localeSegment) {
187
228
  const routes = [];
188
229
  for (const key of pageKeys) {
189
230
  if (key.includes("[...")) continue;
190
- let pathname = key.replace(/^\.\//, "/").replace(/\.tsx?$/, "").replace(/\/index$/, "/");
231
+ let pathname = key.replace(/^\.\//, "/").replace(/\.(tsx?|jsx?)$/, "").replace(/\/index$/, "/");
191
232
  if (pathname === "") pathname = "/";
192
233
  if (localeSegment) {
193
234
  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.1",
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"