@eldrin-project/eldrin-app-core 0.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/LICENSE +21 -0
- package/README.md +248 -0
- package/dist/cli/release.d.ts +35 -0
- package/dist/cli/release.js +592 -0
- package/dist/cli/release.js.map +1 -0
- package/dist/cli/submit.d.ts +37 -0
- package/dist/cli/submit.js +261 -0
- package/dist/cli/submit.js.map +1 -0
- package/dist/index.cjs +582 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +485 -0
- package/dist/index.d.ts +485 -0
- package/dist/index.js +562 -0
- package/dist/index.js.map +1 -0
- package/dist/vite.cjs +91 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +41 -0
- package/dist/vite.d.ts +41 -0
- package/dist/vite.js +89 -0
- package/dist/vite.js.map +1 -0
- package/package.json +102 -0
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var promises = require('fs/promises');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
|
|
7
|
+
// src/vite.ts
|
|
8
|
+
var MIGRATIONS_MODULE_ID = "virtual:eldrin/migrations";
|
|
9
|
+
var SEEDS_MODULE_ID = "virtual:eldrin/seeds";
|
|
10
|
+
var RESOLVED_MIGRATIONS_ID = "\0" + MIGRATIONS_MODULE_ID;
|
|
11
|
+
var RESOLVED_SEEDS_ID = "\0" + SEEDS_MODULE_ID;
|
|
12
|
+
async function readSQLFiles(dir) {
|
|
13
|
+
if (!fs.existsSync(dir)) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const files = await promises.readdir(dir);
|
|
17
|
+
const sqlFiles = files.filter((f) => f.endsWith(".sql"));
|
|
18
|
+
const migrations = [];
|
|
19
|
+
for (const file of sqlFiles) {
|
|
20
|
+
const content = await promises.readFile(path.resolve(dir, file), "utf-8");
|
|
21
|
+
migrations.push({
|
|
22
|
+
name: path.basename(file),
|
|
23
|
+
content
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return migrations;
|
|
27
|
+
}
|
|
28
|
+
function eldrinPlugin(options = {}) {
|
|
29
|
+
const { migrationsDir = "./migrations", seedsDir = "./seeds" } = options;
|
|
30
|
+
let projectRoot;
|
|
31
|
+
return {
|
|
32
|
+
name: "eldrin-app-core",
|
|
33
|
+
configResolved(config) {
|
|
34
|
+
projectRoot = config.root;
|
|
35
|
+
},
|
|
36
|
+
resolveId(id) {
|
|
37
|
+
if (id === MIGRATIONS_MODULE_ID) {
|
|
38
|
+
return RESOLVED_MIGRATIONS_ID;
|
|
39
|
+
}
|
|
40
|
+
if (id === SEEDS_MODULE_ID) {
|
|
41
|
+
return RESOLVED_SEEDS_ID;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
},
|
|
45
|
+
async load(id) {
|
|
46
|
+
if (id === RESOLVED_MIGRATIONS_ID) {
|
|
47
|
+
const dir = path.resolve(projectRoot, migrationsDir);
|
|
48
|
+
const migrations = await readSQLFiles(dir);
|
|
49
|
+
const migrationFiles = migrations.filter(
|
|
50
|
+
(m) => !m.name.endsWith(".rollback.sql")
|
|
51
|
+
);
|
|
52
|
+
return `export default ${JSON.stringify(migrationFiles)};`;
|
|
53
|
+
}
|
|
54
|
+
if (id === RESOLVED_SEEDS_ID) {
|
|
55
|
+
const dir = path.resolve(projectRoot, seedsDir);
|
|
56
|
+
const seeds = await readSQLFiles(dir);
|
|
57
|
+
return `export default ${JSON.stringify(seeds)};`;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
},
|
|
61
|
+
// Watch migration files for HMR
|
|
62
|
+
configureServer(server) {
|
|
63
|
+
const migrationsPath = path.resolve(projectRoot, migrationsDir);
|
|
64
|
+
const seedsPath = path.resolve(projectRoot, seedsDir);
|
|
65
|
+
if (fs.existsSync(migrationsPath)) {
|
|
66
|
+
server.watcher.add(migrationsPath);
|
|
67
|
+
}
|
|
68
|
+
if (fs.existsSync(seedsPath)) {
|
|
69
|
+
server.watcher.add(seedsPath);
|
|
70
|
+
}
|
|
71
|
+
server.watcher.on("change", (file) => {
|
|
72
|
+
if (file.startsWith(migrationsPath) && file.endsWith(".sql")) {
|
|
73
|
+
const module = server.moduleGraph.getModuleById(RESOLVED_MIGRATIONS_ID);
|
|
74
|
+
if (module) {
|
|
75
|
+
server.moduleGraph.invalidateModule(module);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (file.startsWith(seedsPath) && file.endsWith(".sql")) {
|
|
79
|
+
const module = server.moduleGraph.getModuleById(RESOLVED_SEEDS_ID);
|
|
80
|
+
if (module) {
|
|
81
|
+
server.moduleGraph.invalidateModule(module);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.eldrinPlugin = eldrinPlugin;
|
|
90
|
+
//# sourceMappingURL=vite.cjs.map
|
|
91
|
+
//# sourceMappingURL=vite.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vite.ts"],"names":["existsSync","readdir","readFile","resolve","basename"],"mappings":";;;;;;;AA6CA,IAAM,oBAAA,GAAuB,2BAAA;AAC7B,IAAM,eAAA,GAAkB,sBAAA;AACxB,IAAM,yBAAyB,IAAA,GAAO,oBAAA;AACtC,IAAM,oBAAoB,IAAA,GAAO,eAAA;AAKjC,eAAe,aAAa,GAAA,EAAuC;AACjE,EAAA,IAAI,CAACA,aAAA,CAAW,GAAG,CAAA,EAAG;AACpB,IAAA,OAAO,EAAC;AAAA,EACV;AAEA,EAAA,MAAM,KAAA,GAAQ,MAAMC,gBAAA,CAAQ,GAAG,CAAA;AAC/B,EAAA,MAAM,QAAA,GAAW,MAAM,MAAA,CAAO,CAAC,MAAM,CAAA,CAAE,QAAA,CAAS,MAAM,CAAC,CAA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AAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,aAAA,CAAc,iBAAiB,CAAA;AACjE,UAAA,IAAI,MAAA,EAAQ;AACV,YAAA,MAAA,CAAO,WAAA,CAAY,iBAAiB,MAAM,CAAA;AAAA,UAC5C;AAAA,QACF;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"vite.cjs","sourcesContent":["/**\n * Vite plugin for @eldrin-project/eldrin-app-core\n *\n * Loads migration and seed files at build time since\n * Cloudflare Workers don't have filesystem access at runtime.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { eldrinPlugin } from '@eldrin-project/eldrin-app-core/vite';\n *\n * export default defineConfig({\n * plugins: [\n * eldrinPlugin({\n * migrationsDir: './migrations',\n * seedsDir: './seeds',\n * }),\n * ],\n * });\n * ```\n */\n\nimport { resolve, basename } from 'path';\nimport { readdir, readFile } from 'fs/promises';\nimport { existsSync } from 'fs';\nimport type { MigrationFile } from './types';\n\n// Use generic type to avoid version conflicts between different vite installations\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype VitePlugin = any;\n\n/**\n * Plugin options\n */\nexport interface EldrinPluginOptions {\n /** Directory containing migration SQL files (default: './migrations') */\n migrationsDir?: string;\n /** Directory containing seed SQL files (default: './seeds') */\n seedsDir?: string;\n}\n\n/**\n * Virtual module IDs\n */\nconst MIGRATIONS_MODULE_ID = 'virtual:eldrin/migrations';\nconst SEEDS_MODULE_ID = 'virtual:eldrin/seeds';\nconst RESOLVED_MIGRATIONS_ID = '\\0' + MIGRATIONS_MODULE_ID;\nconst RESOLVED_SEEDS_ID = '\\0' + SEEDS_MODULE_ID;\n\n/**\n * Read SQL files from a directory\n */\nasync function readSQLFiles(dir: string): Promise<MigrationFile[]> {\n if (!existsSync(dir)) {\n return [];\n }\n\n const files = await readdir(dir);\n const sqlFiles = files.filter((f) => f.endsWith('.sql'));\n\n const migrations: MigrationFile[] = [];\n\n for (const file of sqlFiles) {\n const content = await readFile(resolve(dir, file), 'utf-8');\n migrations.push({\n name: basename(file),\n content,\n });\n }\n\n return migrations;\n}\n\n/**\n * Vite plugin for Eldrin apps\n *\n * Provides virtual modules for migrations and seeds that are\n * loaded at build time.\n */\nexport function eldrinPlugin(options: EldrinPluginOptions = {}): VitePlugin {\n const { migrationsDir = './migrations', seedsDir = './seeds' } = options;\n\n let projectRoot: string;\n\n return {\n name: 'eldrin-app-core',\n\n configResolved(config: { root: string }) {\n projectRoot = config.root;\n },\n\n resolveId(id: string) {\n if (id === MIGRATIONS_MODULE_ID) {\n return RESOLVED_MIGRATIONS_ID;\n }\n if (id === SEEDS_MODULE_ID) {\n return RESOLVED_SEEDS_ID;\n }\n return null;\n },\n\n async load(id: string) {\n if (id === RESOLVED_MIGRATIONS_ID) {\n const dir = resolve(projectRoot, migrationsDir);\n const migrations = await readSQLFiles(dir);\n\n // Filter to only migration files (not rollback files)\n const migrationFiles = migrations.filter(\n (m) => !m.name.endsWith('.rollback.sql')\n );\n\n return `export default ${JSON.stringify(migrationFiles)};`;\n }\n\n if (id === RESOLVED_SEEDS_ID) {\n const dir = resolve(projectRoot, seedsDir);\n const seeds = await readSQLFiles(dir);\n\n return `export default ${JSON.stringify(seeds)};`;\n }\n\n return null;\n },\n\n // Watch migration files for HMR\n configureServer(server: {\n watcher: {\n add: (path: string) => void;\n on: (event: string, handler: (file: string) => void) => void;\n };\n moduleGraph: {\n getModuleById: (id: string) => { invalidate?: () => void } | null;\n invalidateModule: (module: { invalidate?: () => void }) => void;\n };\n }) {\n const migrationsPath = resolve(projectRoot, migrationsDir);\n const seedsPath = resolve(projectRoot, seedsDir);\n\n // Add directories to watch list\n if (existsSync(migrationsPath)) {\n server.watcher.add(migrationsPath);\n }\n if (existsSync(seedsPath)) {\n server.watcher.add(seedsPath);\n }\n\n // Invalidate virtual modules when files change\n server.watcher.on('change', (file: string) => {\n if (file.startsWith(migrationsPath) && file.endsWith('.sql')) {\n const module = server.moduleGraph.getModuleById(RESOLVED_MIGRATIONS_ID);\n if (module) {\n server.moduleGraph.invalidateModule(module);\n }\n }\n if (file.startsWith(seedsPath) && file.endsWith('.sql')) {\n const module = server.moduleGraph.getModuleById(RESOLVED_SEEDS_ID);\n if (module) {\n server.moduleGraph.invalidateModule(module);\n }\n }\n });\n },\n };\n}\n\n// Type declarations are in vite-env.d.ts\n"]}
|
package/dist/vite.d.cts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin for @eldrin-project/eldrin-app-core
|
|
3
|
+
*
|
|
4
|
+
* Loads migration and seed files at build time since
|
|
5
|
+
* Cloudflare Workers don't have filesystem access at runtime.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // vite.config.ts
|
|
10
|
+
* import { defineConfig } from 'vite';
|
|
11
|
+
* import { eldrinPlugin } from '@eldrin-project/eldrin-app-core/vite';
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* plugins: [
|
|
15
|
+
* eldrinPlugin({
|
|
16
|
+
* migrationsDir: './migrations',
|
|
17
|
+
* seedsDir: './seeds',
|
|
18
|
+
* }),
|
|
19
|
+
* ],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
type VitePlugin = any;
|
|
24
|
+
/**
|
|
25
|
+
* Plugin options
|
|
26
|
+
*/
|
|
27
|
+
interface EldrinPluginOptions {
|
|
28
|
+
/** Directory containing migration SQL files (default: './migrations') */
|
|
29
|
+
migrationsDir?: string;
|
|
30
|
+
/** Directory containing seed SQL files (default: './seeds') */
|
|
31
|
+
seedsDir?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Vite plugin for Eldrin apps
|
|
35
|
+
*
|
|
36
|
+
* Provides virtual modules for migrations and seeds that are
|
|
37
|
+
* loaded at build time.
|
|
38
|
+
*/
|
|
39
|
+
declare function eldrinPlugin(options?: EldrinPluginOptions): VitePlugin;
|
|
40
|
+
|
|
41
|
+
export { type EldrinPluginOptions, eldrinPlugin };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin for @eldrin-project/eldrin-app-core
|
|
3
|
+
*
|
|
4
|
+
* Loads migration and seed files at build time since
|
|
5
|
+
* Cloudflare Workers don't have filesystem access at runtime.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* // vite.config.ts
|
|
10
|
+
* import { defineConfig } from 'vite';
|
|
11
|
+
* import { eldrinPlugin } from '@eldrin-project/eldrin-app-core/vite';
|
|
12
|
+
*
|
|
13
|
+
* export default defineConfig({
|
|
14
|
+
* plugins: [
|
|
15
|
+
* eldrinPlugin({
|
|
16
|
+
* migrationsDir: './migrations',
|
|
17
|
+
* seedsDir: './seeds',
|
|
18
|
+
* }),
|
|
19
|
+
* ],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
type VitePlugin = any;
|
|
24
|
+
/**
|
|
25
|
+
* Plugin options
|
|
26
|
+
*/
|
|
27
|
+
interface EldrinPluginOptions {
|
|
28
|
+
/** Directory containing migration SQL files (default: './migrations') */
|
|
29
|
+
migrationsDir?: string;
|
|
30
|
+
/** Directory containing seed SQL files (default: './seeds') */
|
|
31
|
+
seedsDir?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Vite plugin for Eldrin apps
|
|
35
|
+
*
|
|
36
|
+
* Provides virtual modules for migrations and seeds that are
|
|
37
|
+
* loaded at build time.
|
|
38
|
+
*/
|
|
39
|
+
declare function eldrinPlugin(options?: EldrinPluginOptions): VitePlugin;
|
|
40
|
+
|
|
41
|
+
export { type EldrinPluginOptions, eldrinPlugin };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { resolve, basename } from 'path';
|
|
2
|
+
import { readdir, readFile } from 'fs/promises';
|
|
3
|
+
import { existsSync } from 'fs';
|
|
4
|
+
|
|
5
|
+
// src/vite.ts
|
|
6
|
+
var MIGRATIONS_MODULE_ID = "virtual:eldrin/migrations";
|
|
7
|
+
var SEEDS_MODULE_ID = "virtual:eldrin/seeds";
|
|
8
|
+
var RESOLVED_MIGRATIONS_ID = "\0" + MIGRATIONS_MODULE_ID;
|
|
9
|
+
var RESOLVED_SEEDS_ID = "\0" + SEEDS_MODULE_ID;
|
|
10
|
+
async function readSQLFiles(dir) {
|
|
11
|
+
if (!existsSync(dir)) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const files = await readdir(dir);
|
|
15
|
+
const sqlFiles = files.filter((f) => f.endsWith(".sql"));
|
|
16
|
+
const migrations = [];
|
|
17
|
+
for (const file of sqlFiles) {
|
|
18
|
+
const content = await readFile(resolve(dir, file), "utf-8");
|
|
19
|
+
migrations.push({
|
|
20
|
+
name: basename(file),
|
|
21
|
+
content
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return migrations;
|
|
25
|
+
}
|
|
26
|
+
function eldrinPlugin(options = {}) {
|
|
27
|
+
const { migrationsDir = "./migrations", seedsDir = "./seeds" } = options;
|
|
28
|
+
let projectRoot;
|
|
29
|
+
return {
|
|
30
|
+
name: "eldrin-app-core",
|
|
31
|
+
configResolved(config) {
|
|
32
|
+
projectRoot = config.root;
|
|
33
|
+
},
|
|
34
|
+
resolveId(id) {
|
|
35
|
+
if (id === MIGRATIONS_MODULE_ID) {
|
|
36
|
+
return RESOLVED_MIGRATIONS_ID;
|
|
37
|
+
}
|
|
38
|
+
if (id === SEEDS_MODULE_ID) {
|
|
39
|
+
return RESOLVED_SEEDS_ID;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
},
|
|
43
|
+
async load(id) {
|
|
44
|
+
if (id === RESOLVED_MIGRATIONS_ID) {
|
|
45
|
+
const dir = resolve(projectRoot, migrationsDir);
|
|
46
|
+
const migrations = await readSQLFiles(dir);
|
|
47
|
+
const migrationFiles = migrations.filter(
|
|
48
|
+
(m) => !m.name.endsWith(".rollback.sql")
|
|
49
|
+
);
|
|
50
|
+
return `export default ${JSON.stringify(migrationFiles)};`;
|
|
51
|
+
}
|
|
52
|
+
if (id === RESOLVED_SEEDS_ID) {
|
|
53
|
+
const dir = resolve(projectRoot, seedsDir);
|
|
54
|
+
const seeds = await readSQLFiles(dir);
|
|
55
|
+
return `export default ${JSON.stringify(seeds)};`;
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
},
|
|
59
|
+
// Watch migration files for HMR
|
|
60
|
+
configureServer(server) {
|
|
61
|
+
const migrationsPath = resolve(projectRoot, migrationsDir);
|
|
62
|
+
const seedsPath = resolve(projectRoot, seedsDir);
|
|
63
|
+
if (existsSync(migrationsPath)) {
|
|
64
|
+
server.watcher.add(migrationsPath);
|
|
65
|
+
}
|
|
66
|
+
if (existsSync(seedsPath)) {
|
|
67
|
+
server.watcher.add(seedsPath);
|
|
68
|
+
}
|
|
69
|
+
server.watcher.on("change", (file) => {
|
|
70
|
+
if (file.startsWith(migrationsPath) && file.endsWith(".sql")) {
|
|
71
|
+
const module = server.moduleGraph.getModuleById(RESOLVED_MIGRATIONS_ID);
|
|
72
|
+
if (module) {
|
|
73
|
+
server.moduleGraph.invalidateModule(module);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (file.startsWith(seedsPath) && file.endsWith(".sql")) {
|
|
77
|
+
const module = server.moduleGraph.getModuleById(RESOLVED_SEEDS_ID);
|
|
78
|
+
if (module) {
|
|
79
|
+
server.moduleGraph.invalidateModule(module);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { eldrinPlugin };
|
|
88
|
+
//# sourceMappingURL=vite.js.map
|
|
89
|
+
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
ADDED
|
@@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SAAS,CAAA;AAAA,MAC9B;AAGA,MAAA,MAAA,CAAO,OAAA,CAAQ,EAAA,CAAG,QAAA,EAAU,CAAC,IAAA,KAAiB;AAC5C,QAAA,IAAI,KAAK,UAAA,CAAW,cAAc,KAAK,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA,EAAG;AAC5D,UAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,aAAA,CAAc,sBAAsB,CAAA;AACtE,UAAA,IAAI,MAAA,EAAQ;AACV,YAAA,MAAA,CAAO,WAAA,CAAY,iBAAiB,MAAM,CAAA;AAAA,UAC5C;AAAA,QACF;AACA,QAAA,IAAI,KAAK,UAAA,CAAW,SAAS,KAAK,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA,EAAG;AACvD,UAAA,MAAM,MAAA,GAAS,MAAA,CAAO,WAAA,CAAY,aAAA,CAAc,iBAAiB,CAAA;AACjE,UAAA,IAAI,MAAA,EAAQ;AACV,YAAA,MAAA,CAAO,WAAA,CAAY,iBAAiB,MAAM,CAAA;AAAA,UAC5C;AAAA,QACF;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF","file":"vite.js","sourcesContent":["/**\n * Vite plugin for @eldrin-project/eldrin-app-core\n *\n * Loads migration and seed files at build time since\n * Cloudflare Workers don't have filesystem access at runtime.\n *\n * @example\n * ```ts\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { eldrinPlugin } from '@eldrin-project/eldrin-app-core/vite';\n *\n * export default defineConfig({\n * plugins: [\n * eldrinPlugin({\n * migrationsDir: './migrations',\n * seedsDir: './seeds',\n * }),\n * ],\n * });\n * ```\n */\n\nimport { resolve, basename } from 'path';\nimport { readdir, readFile } from 'fs/promises';\nimport { existsSync } from 'fs';\nimport type { MigrationFile } from './types';\n\n// Use generic type to avoid version conflicts between different vite installations\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype VitePlugin = any;\n\n/**\n * Plugin options\n */\nexport interface EldrinPluginOptions {\n /** Directory containing migration SQL files (default: './migrations') */\n migrationsDir?: string;\n /** Directory containing seed SQL files (default: './seeds') */\n seedsDir?: string;\n}\n\n/**\n * Virtual module IDs\n */\nconst MIGRATIONS_MODULE_ID = 'virtual:eldrin/migrations';\nconst SEEDS_MODULE_ID = 'virtual:eldrin/seeds';\nconst RESOLVED_MIGRATIONS_ID = '\\0' + MIGRATIONS_MODULE_ID;\nconst RESOLVED_SEEDS_ID = '\\0' + SEEDS_MODULE_ID;\n\n/**\n * Read SQL files from a directory\n */\nasync function readSQLFiles(dir: string): Promise<MigrationFile[]> {\n if (!existsSync(dir)) {\n return [];\n }\n\n const files = await readdir(dir);\n const sqlFiles = files.filter((f) => f.endsWith('.sql'));\n\n const migrations: MigrationFile[] = [];\n\n for (const file of sqlFiles) {\n const content = await readFile(resolve(dir, file), 'utf-8');\n migrations.push({\n name: basename(file),\n content,\n });\n }\n\n return migrations;\n}\n\n/**\n * Vite plugin for Eldrin apps\n *\n * Provides virtual modules for migrations and seeds that are\n * loaded at build time.\n */\nexport function eldrinPlugin(options: EldrinPluginOptions = {}): VitePlugin {\n const { migrationsDir = './migrations', seedsDir = './seeds' } = options;\n\n let projectRoot: string;\n\n return {\n name: 'eldrin-app-core',\n\n configResolved(config: { root: string }) {\n projectRoot = config.root;\n },\n\n resolveId(id: string) {\n if (id === MIGRATIONS_MODULE_ID) {\n return RESOLVED_MIGRATIONS_ID;\n }\n if (id === SEEDS_MODULE_ID) {\n return RESOLVED_SEEDS_ID;\n }\n return null;\n },\n\n async load(id: string) {\n if (id === RESOLVED_MIGRATIONS_ID) {\n const dir = resolve(projectRoot, migrationsDir);\n const migrations = await readSQLFiles(dir);\n\n // Filter to only migration files (not rollback files)\n const migrationFiles = migrations.filter(\n (m) => !m.name.endsWith('.rollback.sql')\n );\n\n return `export default ${JSON.stringify(migrationFiles)};`;\n }\n\n if (id === RESOLVED_SEEDS_ID) {\n const dir = resolve(projectRoot, seedsDir);\n const seeds = await readSQLFiles(dir);\n\n return `export default ${JSON.stringify(seeds)};`;\n }\n\n return null;\n },\n\n // Watch migration files for HMR\n configureServer(server: {\n watcher: {\n add: (path: string) => void;\n on: (event: string, handler: (file: string) => void) => void;\n };\n moduleGraph: {\n getModuleById: (id: string) => { invalidate?: () => void } | null;\n invalidateModule: (module: { invalidate?: () => void }) => void;\n };\n }) {\n const migrationsPath = resolve(projectRoot, migrationsDir);\n const seedsPath = resolve(projectRoot, seedsDir);\n\n // Add directories to watch list\n if (existsSync(migrationsPath)) {\n server.watcher.add(migrationsPath);\n }\n if (existsSync(seedsPath)) {\n server.watcher.add(seedsPath);\n }\n\n // Invalidate virtual modules when files change\n server.watcher.on('change', (file: string) => {\n if (file.startsWith(migrationsPath) && file.endsWith('.sql')) {\n const module = server.moduleGraph.getModuleById(RESOLVED_MIGRATIONS_ID);\n if (module) {\n server.moduleGraph.invalidateModule(module);\n }\n }\n if (file.startsWith(seedsPath) && file.endsWith('.sql')) {\n const module = server.moduleGraph.getModuleById(RESOLVED_SEEDS_ID);\n if (module) {\n server.moduleGraph.invalidateModule(module);\n }\n }\n });\n },\n };\n}\n\n// Type declarations are in vite-env.d.ts\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eldrin-project/eldrin-app-core",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Standard library for Eldrin apps providing database migrations, storage isolation, event communication, and common utilities",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"bin": {
|
|
13
|
+
"eldrin-submit": "./dist/cli/submit.js",
|
|
14
|
+
"eldrin-release": "./dist/cli/release.js"
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./dist/index.d.cts",
|
|
24
|
+
"default": "./dist/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"./vite": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/vite.d.ts",
|
|
30
|
+
"default": "./dist/vite.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/vite.d.cts",
|
|
34
|
+
"default": "./dist/vite.cjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./vite-env": {
|
|
38
|
+
"types": "./dist/vite-env.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./submit": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/cli/submit.d.ts",
|
|
43
|
+
"default": "./dist/cli/submit.js"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"dev": "tsup --watch",
|
|
53
|
+
"test": "vitest",
|
|
54
|
+
"test:run": "vitest run",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"lint": "eslint src",
|
|
57
|
+
"prepublishOnly": "npm run build"
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"eldrin",
|
|
61
|
+
"cloudflare",
|
|
62
|
+
"d1",
|
|
63
|
+
"migrations",
|
|
64
|
+
"single-spa"
|
|
65
|
+
],
|
|
66
|
+
"author": "Eldrin Team",
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"peerDependencies": {
|
|
69
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
70
|
+
"vite": "^6.0.0 || ^7.0.0"
|
|
71
|
+
},
|
|
72
|
+
"devDependencies": {
|
|
73
|
+
"@cloudflare/workers-types": "^4.20251216.0",
|
|
74
|
+
"@eslint/js": "^9.39.2",
|
|
75
|
+
"@types/node": "^22.0.0",
|
|
76
|
+
"@types/react": "^19.0.0",
|
|
77
|
+
"@types/react-dom": "^19.0.0",
|
|
78
|
+
"eslint": "^9.39.2",
|
|
79
|
+
"globals": "^16.5.0",
|
|
80
|
+
"react": "^19.0.0",
|
|
81
|
+
"react-dom": "^19.0.0",
|
|
82
|
+
"tsup": "^8.0.0",
|
|
83
|
+
"typescript": "^5.8.0",
|
|
84
|
+
"typescript-eslint": "^8.50.1",
|
|
85
|
+
"vite": "^7.1.2",
|
|
86
|
+
"vitest": "^2.0.0"
|
|
87
|
+
},
|
|
88
|
+
"repository": {
|
|
89
|
+
"type": "git",
|
|
90
|
+
"url": "git+https://github.com/eldrin-project/eldrin-app-core.git"
|
|
91
|
+
},
|
|
92
|
+
"bugs": {
|
|
93
|
+
"url": "https://github.com/eldrin-project/eldrin-app-core/issues"
|
|
94
|
+
},
|
|
95
|
+
"homepage": "https://github.com/eldrin-project/eldrin-app-core#readme",
|
|
96
|
+
"engines": {
|
|
97
|
+
"node": ">=18.0.0"
|
|
98
|
+
},
|
|
99
|
+
"dependencies": {
|
|
100
|
+
"dotenv": "^17.2.3"
|
|
101
|
+
}
|
|
102
|
+
}
|