@deessejs/collections 0.0.46 → 0.0.47
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/config/index.js +9 -4
- package/dist/next/index.js +30 -15
- package/dist/worker/index.js +26 -22
- package/package.json +1 -1
package/dist/config/index.js
CHANGED
|
@@ -5,10 +5,15 @@ exports.defineConfig = void 0;
|
|
|
5
5
|
const node_postgres_1 = require("drizzle-orm/node-postgres");
|
|
6
6
|
const defineConfig = (config) => {
|
|
7
7
|
const db = (0, node_postgres_1.drizzle)(config.databaseUrl);
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
// Attacher la config cachée pour que le worker puisse la lire
|
|
9
|
+
// sans avoir besoin de parser l'AST manuellement
|
|
10
|
+
Object.defineProperty(db, '_config', {
|
|
11
|
+
value: config,
|
|
12
|
+
enumerable: false, // Pour ne pas polluer les logs de console.log(db)
|
|
13
|
+
writable: false
|
|
14
|
+
});
|
|
15
|
+
// Optionnel : Génération initiale synchrone si on veut bloquer le démarrage
|
|
16
|
+
// generateShadowSchema(config.collections);
|
|
12
17
|
return db;
|
|
13
18
|
};
|
|
14
19
|
exports.defineConfig = defineConfig;
|
package/dist/next/index.js
CHANGED
|
@@ -4,40 +4,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.withCollections = void 0;
|
|
7
|
-
// src/next/index.ts (votre withCollections)
|
|
8
7
|
const child_process_1 = require("child_process");
|
|
9
8
|
const constants_1 = require("next/constants");
|
|
10
9
|
const path_1 = __importDefault(require("path"));
|
|
11
10
|
const withCollections = (phase, config) => {
|
|
12
11
|
const isDev = phase === constants_1.PHASE_DEVELOPMENT_SERVER;
|
|
12
|
+
// 1. Lancer le worker en arrière-plan (votre code actuel)
|
|
13
13
|
if (isDev && !global.__collections_worker_started) {
|
|
14
14
|
global.__collections_worker_started = true;
|
|
15
|
-
//
|
|
16
|
-
// Si vous êtes en monorepo/dev local sur la lib, pointez vers le TS avec ts-node ou bun
|
|
15
|
+
// Assurez-vous que ce chemin pointe vers le JS compilé de votre lib
|
|
17
16
|
const workerPath = path_1.default.resolve(__dirname, "../worker/index.js");
|
|
18
17
|
console.log("[Deesse] Spawning background worker:", workerPath);
|
|
19
18
|
(0, child_process_1.spawn)("node", [workerPath], {
|
|
20
19
|
stdio: "inherit",
|
|
21
|
-
env: {
|
|
22
|
-
...process.env,
|
|
23
|
-
// Variables d'env utiles pour le worker
|
|
24
|
-
NODE_ENV: "development",
|
|
25
|
-
}
|
|
20
|
+
env: { ...process.env },
|
|
26
21
|
});
|
|
27
22
|
}
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
// ou pour que Drizzle trouve le fichier généré.
|
|
23
|
+
// Chemin absolu vers le schéma généré
|
|
24
|
+
const shadowSchemaPath = path_1.default.join(process.cwd(), ".deesse", "shadow", "schema.ts");
|
|
31
25
|
return {
|
|
32
26
|
...config,
|
|
27
|
+
// 2. Configuration pour Turbopack (Next.js 16+)
|
|
28
|
+
turbopack: {
|
|
29
|
+
...(config.turbopack || {}),
|
|
30
|
+
resolveAlias: {
|
|
31
|
+
...(config.turbopack?.resolveAlias || {}),
|
|
32
|
+
// Création de l'alias pour Turbopack
|
|
33
|
+
"@deesse/schema": shadowSchemaPath,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
// 3. Configuration pour Webpack (Next.js < 16 ou --webpack)
|
|
33
37
|
webpack: (webpackConfig, options) => {
|
|
34
|
-
|
|
38
|
+
// Appliquer la config utilisateur existante s'il y en a une
|
|
39
|
+
if (typeof config.webpack === "function") {
|
|
35
40
|
webpackConfig = config.webpack(webpackConfig, options);
|
|
36
41
|
}
|
|
37
|
-
//
|
|
38
|
-
webpackConfig.resolve.alias["@deesse/schema"] =
|
|
42
|
+
// Création de l'alias pour Webpack
|
|
43
|
+
webpackConfig.resolve.alias["@deesse/schema"] = shadowSchemaPath;
|
|
39
44
|
return webpackConfig;
|
|
40
|
-
}
|
|
45
|
+
},
|
|
46
|
+
// 4. Empêcher le bundling des paquets serveur (Drizzle, PG, etc.)
|
|
47
|
+
// C'est crucial pour éviter les erreurs de compilation côté Next
|
|
48
|
+
serverExternalPackages: [
|
|
49
|
+
...(config.serverExternalPackages || []),
|
|
50
|
+
"drizzle-orm",
|
|
51
|
+
"drizzle-kit",
|
|
52
|
+
"pg",
|
|
53
|
+
"jiti", // Important pour que Jiti ne soit pas bundlé si utilisé côté serveur
|
|
54
|
+
"@deessejs/collections", // Votre lib
|
|
55
|
+
],
|
|
41
56
|
};
|
|
42
57
|
};
|
|
43
58
|
exports.withCollections = withCollections;
|
package/dist/worker/index.js
CHANGED
|
@@ -3,52 +3,56 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
// src/worker/index.ts
|
|
7
6
|
const jiti_1 = require("jiti");
|
|
8
7
|
const path_1 = __importDefault(require("path"));
|
|
9
8
|
const chokidar_1 = __importDefault(require("chokidar"));
|
|
10
|
-
const
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const generate_1 = require("../drizzle/generate");
|
|
11
|
+
// Chemins relatifs au projet de l'utilisateur (process.cwd())
|
|
11
12
|
const PROJECT_ROOT = process.cwd();
|
|
12
13
|
const CONFIG_PATH = path_1.default.join(PROJECT_ROOT, "src", "api", "index.ts");
|
|
13
14
|
const COLLECTIONS_DIR = path_1.default.join(PROJECT_ROOT, "src", "collections");
|
|
14
|
-
// Initialiser Jiti pour
|
|
15
|
+
// Initialiser Jiti pour charger du TS à la volée
|
|
15
16
|
const jiti = (0, jiti_1.createJiti)(PROJECT_ROOT, {
|
|
16
17
|
interopDefault: true,
|
|
17
|
-
requireCache: false, //
|
|
18
|
+
requireCache: false, // Désactiver le cache pour le hot-reload
|
|
18
19
|
});
|
|
19
20
|
async function runGenerator() {
|
|
20
21
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
// Vérifier si le fichier existe avant
|
|
23
|
+
if (!fs_1.default.existsSync(CONFIG_PATH)) {
|
|
24
|
+
console.warn(`[Deesse] Config file not found at ${CONFIG_PATH}`);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
// 1. Importer la config utilisateur via Jiti
|
|
28
|
+
// Jiti compile le TS en JS à la volée, indépendamment de Next.js
|
|
26
29
|
const mod = await jiti.import(CONFIG_PATH);
|
|
27
|
-
//
|
|
28
|
-
// Note : Si l'utilisateur fait "export const db = ...", mod.db sera l'instance
|
|
29
|
-
// Si l'utilisateur fait "export default ...", ce sera mod.default
|
|
30
|
+
// 2. Récupérer l'instance db exportée
|
|
30
31
|
const dbInstance = mod.db || mod.default;
|
|
32
|
+
// Note : Vous devrez modifier votre `defineConfig` pour qu'il attache la config brute à l'objet retourné
|
|
33
|
+
// Exemple dans src/api/index.ts : (db as any)._config = config;
|
|
31
34
|
if (!dbInstance || !dbInstance._config) {
|
|
32
|
-
|
|
35
|
+
// Si c'est le premier run, on ne spam pas l'erreur, l'utilisateur est peut-être en train d'écrire
|
|
36
|
+
return;
|
|
33
37
|
}
|
|
34
38
|
const collections = dbInstance._config.collections;
|
|
35
|
-
//
|
|
39
|
+
// 3. Générer le fichier de schéma
|
|
40
|
+
console.log("[Deesse] ⚡ Updating Drizzle schema...");
|
|
36
41
|
(0, generate_1.generateShadowSchema)(collections);
|
|
37
|
-
console.log("[Deesse] ✅ Schema updated");
|
|
38
42
|
}
|
|
39
43
|
catch (error) {
|
|
40
|
-
console.error("[Deesse] ❌ Error
|
|
44
|
+
console.error("[Deesse] ❌ Error in schema generation worker:", error);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
|
-
//
|
|
47
|
+
// --- Démarrage ---
|
|
48
|
+
// 1. Génération initiale
|
|
44
49
|
runGenerator();
|
|
45
|
-
// Mode Watch
|
|
46
|
-
console.log(`[Deesse] 👀 Watching
|
|
50
|
+
// 2. Mode Watch
|
|
51
|
+
console.log(`[Deesse] 👀 Watching changes in: src/collections`);
|
|
47
52
|
const watcher = chokidar_1.default.watch([CONFIG_PATH, COLLECTIONS_DIR], {
|
|
48
53
|
ignoreInitial: true,
|
|
49
|
-
ignored: /(^|[\/\\])\../,
|
|
54
|
+
ignored: /(^|[\/\\])\../,
|
|
50
55
|
});
|
|
51
|
-
watcher.on("all", (
|
|
52
|
-
// On debounce légèrement pour éviter de générer 2 fois si l'éditeur sauvegarde en plusieurs étapes
|
|
56
|
+
watcher.on("all", () => {
|
|
53
57
|
runGenerator();
|
|
54
58
|
});
|