'use strict'; var path = require('node:path'); var fs = require('node:fs'); var esbuild = require('esbuild'); function _interopNamespaceDefault(e) { var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path); var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs); var esbuild__namespace = /*#__PURE__*/_interopNamespaceDefault(esbuild); async function doesFileExist(location) { let resolver; let exists = new Promise((resolve) => (resolver = resolve)); fs__namespace.lstat(location, (err, stats) => { if (err || (stats && !stats.isFile())) { resolver(false); return; } resolver(true); }); return (await exists); } function discoverFiles(basePath, clean = true) { let files = []; for (const discovery of fs__namespace.readdirSync(basePath)) { const fullFilePath = path__namespace.join(basePath, discovery); const discoveryStats = fs__namespace.lstatSync(fullFilePath); if (discoveryStats.isDirectory()) { files = files.concat(discoverFiles(fullFilePath, false)); } else { files.push(path__namespace.posix.join(basePath.replace(/\\/g, '/'), discovery)); } } if (clean) files = files.map((file) => file.substring(basePath.length)); return files; } function staticRouter(assets) { let routes = []; for (let asset of assets) { if (asset.endsWith('/index.html') || asset.endsWith('/index.htm') || asset.endsWith('/index.xhtml')) { let assetPath = asset.split('/'); assetPath[assetPath.length - 1] = ''; routes.push({ status: 308, path: assetPath.join('/'), location: asset }); } } return routes; } let entryServer; path__namespace.resolve(undefined); const __filename$1 = path__namespace.resolve(undefined); function zugriff(options = {}) { return { name: 'zugriff', remixConfigResolved: async (config) => { if (process.env.NODE_ENV == 'production') { try { fs__namespace.rmSync(path__namespace.join('.zugriff', 'functions'), { recursive: true }); } catch (_) { } try { fs__namespace.rmSync(path__namespace.join('.zugriff', 'assets'), { recursive: true }); } catch (_) { } try { fs__namespace.rmSync(path__namespace.join('.zugriff', 'config.json')); } catch (_) { } } if (config.remixConfig.ssr) { entryServer = path__namespace.join(config.remixConfig.appDirectory, 'entry.server.tsx'); let entryClientJSX = path__namespace.join(config.remixConfig.appDirectory, 'entry.server.jsx'); let source = path__namespace.join(path__namespace.dirname(__filename$1), 'entry.server.tsx'); if (await doesFileExist(entryClientJSX)) { source = path__namespace.join(path__namespace.dirname(__filename$1), 'entry.server.jsx'); entryServer = path__namespace.join(config.remixConfig.appDirectory, 'entry.server.jsx'); } if (!(await doesFileExist(entryServer)) && !options.disableEntryServerCreation) { fs__namespace.copyFileSync(source, entryServer); } else if (!options.disableEntryServerReplacement && !options.disableEntryServerCreation) { let suffix = 'tsx'; if (entryServer.endsWith('jsx')) { suffix = 'jsx'; } let nodeEntryServer = path__namespace.join(config.remixConfig.appDirectory, 'entry.server.node.' + suffix); if (!(await doesFileExist(nodeEntryServer))) { let contents = fs__namespace.readFileSync(entryServer).toString(); if (contents.match(/(?:from\s(?:"|')@remix-run\/node(?:"|'))|(?:from\s(?:"|')react-dom\/server(?:"|'))/gm).length > 0) { fs__namespace.renameSync(entryServer, nodeEntryServer); fs__namespace.copyFileSync(source, entryServer); } } } } }, remixConfig: () => ({ buildDirectory: path__namespace.join('.zugriff', 'tmp'), manifest: true, buildEnd: (config) => { fs__namespace.renameSync(path__namespace.join('.zugriff', 'tmp', 'client'), path__namespace.join('.zugriff', 'assets')); if (config.remixConfig.ssr) { let handler = path__namespace.join(config.remixConfig.buildDirectory, 'server', 'handler.js'); fs__namespace.copyFileSync(path__namespace.join(path__namespace.dirname(__filename$1), 'handler.js'), handler); esbuild__namespace.buildSync({ bundle: true, target: 'esnext', minify: true, platform: 'browser', logLevel: 'error', format: 'esm', external: ['postgres', 'ioredis', 'nodemailer', 'dotenv'], banner: { js: 'globalThis.global = globalThis;' }, entryPoints: [handler], outfile: path__namespace.join('.zugriff', 'functions', 'index.js'), }); fs__namespace.writeFileSync(path__namespace.join('.zugriff', 'config.json'), JSON.stringify({ version: 1, meta: { technology: 'Remix', }, functions: [{ path: '/index.js', pattern: '*' }], puppets: {}, redirects: [], assets: discoverFiles(path__namespace.join('.zugriff', 'assets')), })); } else { // create route handler try { fs__namespace.mkdirSync(path__namespace.join('.zugriff', 'functions')); } catch (_) { } let assets = discoverFiles(path__namespace.join('.zugriff', 'assets')); fs__namespace.writeFileSync(path__namespace.join('.zugriff', 'config.json'), JSON.stringify({ version: 1, meta: { technology: 'Remix', }, functions: [], puppets: {}, redirects: options && options.disableDefaultIndexHTMLRedirect && options.disableDefaultIndexHTMLRedirect == true ? [] : staticRouter(assets), assets, })); } }, }), }; } module.exports = zugriff; //# sourceMappingURL=index.cjs.map