@titanpl/packet 7.0.6 → 7.0.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.
@@ -159,6 +159,22 @@ export async function bundleFile(options) {
159
159
  }
160
160
  }
161
161
 
162
+ function getFilesRecursively(dir, baseDir = dir) {
163
+ let results = [];
164
+ if (!fs.existsSync(dir)) return results;
165
+ const list = fs.readdirSync(dir);
166
+ for (const file of list) {
167
+ const filePath = path.join(dir, file);
168
+ const stat = fs.statSync(filePath);
169
+ if (stat && stat.isDirectory()) {
170
+ results = results.concat(getFilesRecursively(filePath, baseDir));
171
+ } else {
172
+ results.push(path.relative(baseDir, filePath));
173
+ }
174
+ }
175
+ return results;
176
+ }
177
+
162
178
  /**
163
179
  * Main JS Bundler
164
180
  */
@@ -175,12 +191,14 @@ export async function bundle(options = {}) {
175
191
 
176
192
  if (!fs.existsSync(actionsDir)) return;
177
193
 
178
- const files = fs.readdirSync(actionsDir).filter(f => f.endsWith('.js'));
194
+ const files = getFilesRecursively(actionsDir).filter(f => f.endsWith('.js'));
179
195
 
180
196
  for (const file of files) {
181
- const actionName = path.basename(file, path.extname(file));
197
+ const relativeNoExt = file.replace(/\.js$/, '');
198
+ const actionName = relativeNoExt.replace(/\\/g, '/');
199
+ const exportedName = path.basename(file, path.extname(file));
182
200
  const entryPoint = path.join(actionsDir, file);
183
- const outfile = path.join(bundleDir, actionName + ".jsbundle");
201
+ const outfile = path.join(bundleDir, relativeNoExt + ".jsbundle");
184
202
 
185
203
  try {
186
204
  await bundleFile({
@@ -190,7 +208,7 @@ export async function bundle(options = {}) {
190
208
  footer: {
191
209
  js: `
192
210
  (function () {
193
- const fn = __titan_exports["${actionName}"] || __titan_exports.default;
211
+ const fn = __titan_exports["${exportedName}"] || __titan_exports.default;
194
212
  if (typeof fn !== "function") throw new Error("[TitanPL] Action '${actionName}' not found or not a function");
195
213
  globalThis["${actionName}"] = globalThis.defineAction(fn);
196
214
  })();`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@titanpl/packet",
3
- "version": "7.0.6",
3
+ "version": "7.0.7",
4
4
  "description": "The bundler for TitanPl servers.",
5
5
  "keywords": [
6
6
  "bundler",
@@ -203,6 +203,22 @@ export async function bundleFile(options) {
203
203
  }
204
204
  }
205
205
 
206
+ function getFilesRecursively(dir, baseDir = dir) {
207
+ let results = [];
208
+ if (!fs.existsSync(dir)) return results;
209
+ const list = fs.readdirSync(dir);
210
+ for (const file of list) {
211
+ const filePath = path.join(dir, file);
212
+ const stat = fs.statSync(filePath);
213
+ if (stat && stat.isDirectory()) {
214
+ results = results.concat(getFilesRecursively(filePath, baseDir));
215
+ } else {
216
+ results.push(path.relative(baseDir, filePath));
217
+ }
218
+ }
219
+ return results;
220
+ }
221
+
206
222
  /**
207
223
  * Main TS Bundler
208
224
  */
@@ -238,12 +254,14 @@ export async function bundle(options = {}) {
238
254
 
239
255
  if (!fs.existsSync(actionsDir)) return;
240
256
 
241
- const files = fs.readdirSync(actionsDir).filter(f => (f.endsWith('.ts') || f.endsWith('.js')) && !f.endsWith('.d.ts'));
257
+ const files = getFilesRecursively(actionsDir).filter(f => (f.endsWith('.ts') || f.endsWith('.js')) && !f.endsWith('.d.ts'));
242
258
 
243
259
  for (const file of files) {
244
- const actionName = path.basename(file, path.extname(file));
260
+ const relativeNoExt = file.replace(/\.[jt]s$/, '');
261
+ const actionName = relativeNoExt.replace(/\\/g, '/');
262
+ const exportedName = path.basename(file, path.extname(file));
245
263
  const entryPoint = path.join(actionsDir, file);
246
- const outfile = path.join(bundleDir, actionName + ".jsbundle");
264
+ const outfile = path.join(bundleDir, relativeNoExt + ".jsbundle");
247
265
 
248
266
  try {
249
267
  await bundleFile({
@@ -253,7 +271,7 @@ export async function bundle(options = {}) {
253
271
  footer: {
254
272
  js: `
255
273
  (function () {
256
- const fn = __titan_exports["${actionName}"] || __titan_exports.default;
274
+ const fn = __titan_exports["${exportedName}"] || __titan_exports.default;
257
275
  if (typeof fn !== "function") throw new Error("[TitanPL] Action '${actionName}' not found or not a function");
258
276
  globalThis["${actionName}"] = globalThis.defineAction(fn);
259
277
  })();`