@deessejs/collections 0.0.46 → 0.0.48
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 +54 -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,84 @@ 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
11
|
const PROJECT_ROOT = process.cwd();
|
|
12
12
|
const CONFIG_PATH = path_1.default.join(PROJECT_ROOT, "src", "api", "index.ts");
|
|
13
13
|
const COLLECTIONS_DIR = path_1.default.join(PROJECT_ROOT, "src", "collections");
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Lit le tsconfig.json pour extraire les paths (alias)
|
|
16
|
+
* et les convertir au format attendu par Jiti/Node.
|
|
17
|
+
*/
|
|
18
|
+
function getTsConfigAliases(root) {
|
|
19
|
+
const tsConfigPath = path_1.default.join(root, "tsconfig.json");
|
|
20
|
+
if (!fs_1.default.existsSync(tsConfigPath)) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
// Lecture brute + nettoyage des commentaires (JSON standard ne supporte pas les commentaires)
|
|
25
|
+
const content = fs_1.default.readFileSync(tsConfigPath, "utf-8");
|
|
26
|
+
// Regex simple pour retirer les commentaires // et /* */
|
|
27
|
+
const jsonContent = content.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
28
|
+
const tsConfig = JSON.parse(jsonContent);
|
|
29
|
+
const paths = tsConfig?.compilerOptions?.paths;
|
|
30
|
+
if (!paths)
|
|
31
|
+
return {};
|
|
32
|
+
const aliases = {};
|
|
33
|
+
for (const [key, values] of Object.entries(paths)) {
|
|
34
|
+
const value = Array.isArray(values) ? values[0] : values;
|
|
35
|
+
// Conversion de la syntaxe TS ("@/*": ["./src/*"]) vers syntaxe alias simple ("@": "/abs/src")
|
|
36
|
+
const aliasKey = key.replace("/*", "");
|
|
37
|
+
const aliasValue = String(value).replace("/*", "");
|
|
38
|
+
// Jiti a besoin de chemins absolus pour les alias
|
|
39
|
+
aliases[aliasKey] = path_1.default.resolve(root, aliasValue);
|
|
40
|
+
}
|
|
41
|
+
return aliases;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.warn("[Deesse] ⚠️ Failed to parse tsconfig.json for aliases", error);
|
|
45
|
+
return {};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// 1. Charger les alias (ex: { "@": "C:/.../src" })
|
|
49
|
+
const aliases = getTsConfigAliases(PROJECT_ROOT);
|
|
50
|
+
// 2. Initialiser Jiti avec les alias injectés
|
|
15
51
|
const jiti = (0, jiti_1.createJiti)(PROJECT_ROOT, {
|
|
16
52
|
interopDefault: true,
|
|
17
|
-
requireCache: false,
|
|
53
|
+
requireCache: false,
|
|
54
|
+
alias: aliases, // <--- C'est ici que la magie opère
|
|
18
55
|
});
|
|
19
56
|
async function runGenerator() {
|
|
20
57
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
// Jiti va compiler le TS à la volée.
|
|
58
|
+
if (!fs_1.default.existsSync(CONFIG_PATH)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Importation de la config
|
|
26
62
|
const mod = await jiti.import(CONFIG_PATH);
|
|
27
|
-
// 3. On récupère la config
|
|
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
63
|
const dbInstance = mod.db || mod.default;
|
|
31
64
|
if (!dbInstance || !dbInstance._config) {
|
|
32
|
-
|
|
65
|
+
return;
|
|
33
66
|
}
|
|
34
67
|
const collections = dbInstance._config.collections;
|
|
35
|
-
//
|
|
68
|
+
// Génération
|
|
36
69
|
(0, generate_1.generateShadowSchema)(collections);
|
|
37
|
-
|
|
70
|
+
// Feedback visuel discret (optionnel)
|
|
71
|
+
// console.log("[Deesse] Schema synced");
|
|
38
72
|
}
|
|
39
73
|
catch (error) {
|
|
40
|
-
console.error("[Deesse] ❌ Error
|
|
74
|
+
console.error("[Deesse] ❌ Worker Error:", error);
|
|
41
75
|
}
|
|
42
76
|
}
|
|
43
|
-
// Lancement
|
|
77
|
+
// --- Lancement ---
|
|
44
78
|
runGenerator();
|
|
45
|
-
|
|
46
|
-
console.log(`[Deesse] 👀 Watching for changes in ${COLLECTIONS_DIR}...`);
|
|
79
|
+
console.log(`[Deesse] 👀 Watching collections...`);
|
|
47
80
|
const watcher = chokidar_1.default.watch([CONFIG_PATH, COLLECTIONS_DIR], {
|
|
48
81
|
ignoreInitial: true,
|
|
49
|
-
ignored: /(^|[\/\\])\../,
|
|
82
|
+
ignored: /(^|[\/\\])\../,
|
|
50
83
|
});
|
|
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
|
|
84
|
+
watcher.on("all", () => {
|
|
53
85
|
runGenerator();
|
|
54
86
|
});
|