diff --git a/src/index.ts b/src/index.ts index 08f54e6..aaef8be 100644 --- a/src/index.ts +++ b/src/index.ts @@ -55,10 +55,18 @@ interface PluginConfig { refresh?: boolean|string|string[]|RefreshConfig|RefreshConfig[] /** - * Utilise the valet TLS certificates. + * Utilise the Herd or Valet TLS certificates. * * @default false */ + detectTls?: string|boolean, + + /** + * Utilise the Herd or Valet TLS certificates. + * + * @default false + * @deprecated use "detectTls" instead + */ valetTls?: string|boolean, /** @@ -121,7 +129,7 @@ function resolveLaravelPlugin(pluginConfig: Required): LaravelPlug const env = loadEnv(mode, userConfig.envDir || process.cwd(), '') const assetUrl = env.ASSET_URL ?? '' const serverConfig = command === 'serve' - ? (resolveValetServerConfig(pluginConfig.valetTls) ?? resolveEnvironmentServerConfig(env)) + ? (resolveDevelopmentEnvironmentServerConfig(pluginConfig.detectTls) ?? resolveEnvironmentServerConfig(env)) : undefined ensureCommandShouldRunInEnvironment(command, env) @@ -333,6 +341,7 @@ function resolvePluginConfig(config: string|string[]|PluginConfig): Required code), } } @@ -492,11 +501,10 @@ function resolveHostFromEnv(env: Record): string|undefined } } - /** - * Resolve the valet server config for the given host. + * Resolve the Herd or Valet server config for the given host. */ -function resolveValetServerConfig(host: string|boolean): { +function resolveDevelopmentEnvironmentServerConfig(host: string|boolean): { hmr?: { host: string } host?: string, https?: { cert: Buffer, key: Buffer } @@ -505,13 +513,15 @@ function resolveValetServerConfig(host: string|boolean): { return } - host = host === true ? resolveValetHost() : host + const configPath = determineDevelopmentEnvironmentConfigPath(); + + host = host === true ? resolveDevelopmentEnvironmentHost(configPath) : host - const keyPath = path.resolve(os.homedir(), `.config/valet/Certificates/${host}.key`) - const certPath = path.resolve(os.homedir(), `.config/valet/Certificates/${host}.crt`) + const keyPath = path.resolve(configPath, 'Certificates', `${host}.key`) + const certPath = path.resolve(configPath, 'Certificates', `${host}.crt`) if (! fs.existsSync(keyPath) || ! fs.existsSync(certPath)) { - throw Error(`Unable to find Valet certificate files for your host [${host}]. Ensure you have run "valet secure".`) + throw Error(`Unable to find certificate files for your host [${host}] in the [${configPath}/Certificates] directory. Ensure you have secured the site via the Herd UI or run \`valet secure\`.`) } return { @@ -525,16 +535,29 @@ function resolveValetServerConfig(host: string|boolean): { } /** - * Resolve the valet valet host for the current directory. + * Resolve the path to the Herd or Valet configuration directory. + */ +function determineDevelopmentEnvironmentConfigPath(): string { + const herdConfigPath = path.resolve(os.homedir(), 'Library', 'Application Support', 'Herd', 'config', 'valet') + + if (fs.existsSync(herdConfigPath)) { + return herdConfigPath + } + + return path.resolve(os.homedir(), '.config', 'valet'); +} + +/** + * Resolve the Herd or Valet host for the current directory. */ -function resolveValetHost(): string { - const configPath = os.homedir() + `/.config/valet/config.json` +function resolveDevelopmentEnvironmentHost(configPath: string): string { + const configFile = path.resolve(configPath, 'config.json') - if (! fs.existsSync(configPath)) { - throw Error('Unable to find the Valet configuration file. You will need to manually specify the host in the `valetTls` configuration option.') + if (! fs.existsSync(configFile)) { + throw Error(`Unable to find the configuration file [${configFile}]. You will need to manually specify the host in the \`detectTls\` configuration option.`) } - const config: { tld: string } = JSON.parse(fs.readFileSync(configPath, 'utf-8')) + const config: { tld: string } = JSON.parse(fs.readFileSync(configFile, 'utf-8')) return path.basename(process.cwd()) + '.' + config.tld }