@faapi/faapi 2.0.0 → 2.0.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.
package/dist/cli/index.js CHANGED
@@ -5995,6 +5995,16 @@ var init_loadPlugins = __esm({
5995
5995
  import fs13 from "fs";
5996
5996
  import path15 from "path";
5997
5997
  import { PassThrough, Readable as Readable4 } from "stream";
5998
+ function getCurrentApp() {
5999
+ return globalThis[APP_INSTANCE_KEY] ?? null;
6000
+ }
6001
+ function setCurrentApp(app) {
6002
+ if (app === null) {
6003
+ delete globalThis[APP_INSTANCE_KEY];
6004
+ } else {
6005
+ globalThis[APP_INSTANCE_KEY] = app;
6006
+ }
6007
+ }
5998
6008
  function isFaapiConfigKey(key) {
5999
6009
  return FAAPI_CONFIG_KEYS.has(key);
6000
6010
  }
@@ -6169,20 +6179,20 @@ async function createAppBase(options) {
6169
6179
  }
6170
6180
  if (!server.listening) {
6171
6181
  app.server = null;
6172
- if (currentApp === app) currentApp = null;
6182
+ if (getCurrentApp() === app) setCurrentApp(null);
6173
6183
  return;
6174
6184
  }
6175
6185
  return new Promise((resolve3) => {
6176
6186
  server.close((err) => {
6177
6187
  if (err) console.error("Error closing server:", err);
6178
6188
  app.server = null;
6179
- if (currentApp === app) currentApp = null;
6189
+ if (getCurrentApp() === app) setCurrentApp(null);
6180
6190
  resolve3();
6181
6191
  });
6182
6192
  });
6183
6193
  }
6184
6194
  };
6185
- currentApp = app;
6195
+ setCurrentApp(app);
6186
6196
  const ctx = {
6187
6197
  rootDir,
6188
6198
  dist,
@@ -6201,7 +6211,7 @@ async function createAppBase(options) {
6201
6211
  };
6202
6212
  return { app, ctx };
6203
6213
  }
6204
- var DEFAULT_DIST, DEFAULT_PORT, ROUTES_FILE, PATTERNS, currentApp, FAAPI_CONFIG_KEYS;
6214
+ var DEFAULT_DIST, DEFAULT_PORT, ROUTES_FILE, PATTERNS, APP_INSTANCE_KEY, FAAPI_CONFIG_KEYS;
6205
6215
  var init_createAppCore = __esm({
6206
6216
  "src/cli/createAppCore.ts"() {
6207
6217
  "use strict";
@@ -6217,7 +6227,7 @@ var init_createAppCore = __esm({
6217
6227
  DEFAULT_PORT = 3e3;
6218
6228
  ROUTES_FILE = "faapi-routes.js";
6219
6229
  PATTERNS = ["src/api/**/*.ts"];
6220
- currentApp = null;
6230
+ APP_INSTANCE_KEY = /* @__PURE__ */ Symbol.for("faapi.app.instance");
6221
6231
  FAAPI_CONFIG_KEYS = /* @__PURE__ */ new Set([
6222
6232
  "cors",
6223
6233
  "lifecycle",