UNPKG

@emahuni/directus

Version:

A wrapper around the Directus CLI to enhance its module resolution capabilities, allowing for more flexible and efficient management of dependencies in the Directus API/server.

51 lines (43 loc) 1.68 kB
import { pathToFileURL } from 'node:url'; import { createRequire } from 'node:module'; import { register } from 'node:module'; import { init } from '@emahuni/rolldown-wrapper'; import commonjs from '@rollup/plugin-commonjs'; import resolveFromApiNodeModules from '../plugins/rollup-plugin-resolve-from-api-node-modules.js'; const require = createRequire(import.meta.url); /** * Initializes the environment and runs the Directus CLI. */ export async function runDirectusCli () { // Dynamically resolve loader package const loaderPackage = '@emahuni/rolldown-wrapper'; const loaderPath = pathToFileURL(new URL(loaderPackage, import.meta.url).pathname); init({ rollupOptions: { plugins: [ resolveFromApiNodeModules(process.cwd()), commonjs(), ], onwarn (warning, warn) { // Ignore circular dependencies in zod or other known safe packages if (warning.code === 'CIRCULAR_DEPENDENCY' && /zod/.test(warning.message)) { return; } // Print all other warnings normally warn(warning); }, }, debug : false, }); // Register loader register(loaderPackage, loaderPath); // Dynamically resolve Directus CLI try { const cliPath = require.resolve('directus/package.json') .replace('package.json', 'cli.js'); await import(pathToFileURL(cliPath).href); console.debug('Starting Directus CLI...'); } catch (err) { console.error('Failed to start Directus CLI:', err); } }