UNPKG

@shopify/react-server

Version:
35 lines (30 loc) 905 B
import { existsSync, readdirSync } from 'fs'; import { resolve, join } from 'path'; let Entrypoint; (function (Entrypoint) { Entrypoint["Client"] = "client"; Entrypoint["Server"] = "server"; Entrypoint["Error"] = "error"; })(Entrypoint || (Entrypoint = {})); const HEADER = ` // Generated by @shopify/react-server/webpack-plugin `; function noSourceExists(entry, options, { options: { context = '' } }) { const { basePath: path } = options; const basePath = resolve(context, path); // if there is a folder we assume it has an index file if (existsSync(join(basePath, entry))) { return false; } // otherwise we look for explicit files in the folder const dirFiles = readdirSync(basePath); const filenameRegex = new RegExp(`^${entry}.[jt]sx?$`); return dirFiles.find(file => filenameRegex.test(file)) == null; } export { Entrypoint, HEADER, noSourceExists };