mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-09-08 11:25:09 -05:00
Allow reading remote config from file URLs
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as path from 'node:path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import fetch from 'node-fetch';
|
||||
import mkdirp from 'mkdirp';
|
||||
import { ErrorResponse, ResponseSymbol } from '../api/util.js';
|
||||
@@ -32,6 +33,34 @@ async function loadRemoteConfig() {
|
||||
const config_cache_path = path.resolve(paths.cache, 'config.json');
|
||||
|
||||
const url = process.env.NXAPI_CONFIG_URL ?? CONFIG_URL;
|
||||
const url_parsed = new URL(url);
|
||||
|
||||
if (url_parsed.protocol === 'file:') {
|
||||
const file = fileURLToPath(url_parsed);
|
||||
|
||||
const stats = await fs.stat(file);
|
||||
|
||||
const config: NxapiRemoteConfig = {
|
||||
...JSON.parse(await fs.readFile(file, 'utf-8')),
|
||||
[SourceSymbol]: url_parsed.toString(),
|
||||
};
|
||||
|
||||
const cache: RemoteConfigCacheData = {
|
||||
created_at: stats.ctimeMs,
|
||||
updated_at: stats.mtimeMs,
|
||||
etag: null,
|
||||
revalidated_at: Date.now(),
|
||||
stale_at: null,
|
||||
expires_at: Date.now(),
|
||||
version,
|
||||
revision: git?.revision ?? null,
|
||||
url: url_parsed.toString(),
|
||||
headers: {},
|
||||
data: config,
|
||||
};
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
let data: RemoteConfigCacheData | undefined = undefined;
|
||||
let must_revalidate = true;
|
||||
|
||||
Reference in New Issue
Block a user