@epic-web/workshop-utils 4.6.6 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.server.d.ts","sourceRoot":"","sources":["../../src/utils.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.server.d.ts","sourceRoot":"","sources":["../../src/utils.server.ts"],"names":[],"mappings":"AAIA,wBAAsB,eAAe,qBASpC;AAID,wBAAsB,UAAU,CAAC,KAAK,EACrC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,KAAK,GAClB,OAAO,CAAC,KAAK,CAAC,CAyBhB"}
|
package/dist/esm/utils.server.js
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import { promises as dns } from 'node:dns';
|
|
2
1
|
import fs from 'node:fs';
|
|
3
2
|
import path from 'node:path';
|
|
4
3
|
import { z } from 'zod';
|
|
5
4
|
export async function checkConnection() {
|
|
6
|
-
|
|
5
|
+
try {
|
|
6
|
+
const response = await fetch('https://www.cloudflare.com', {
|
|
7
|
+
method: 'HEAD',
|
|
8
|
+
});
|
|
9
|
+
return response.ok;
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
7
14
|
}
|
|
8
15
|
const PkgSchema = z.object({}).passthrough();
|
|
9
16
|
export async function getPkgProp(fullPath, prop, defaultValue) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.server.js","sourceRoot":"","sources":["../../src/utils.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.server.js","sourceRoot":"","sources":["../../src/utils.server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,CA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IACF,CAAC;IACD,OAAO,KAAK,IAAI,YAAY,CAAA;AAC7B,CAAC","sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\nimport { z } from 'zod'\n\nexport async function checkConnection() {\n\ttry {\n\t\tconst response = await fetch('https://www.cloudflare.com', {\n\t\t\tmethod: 'HEAD',\n\t\t})\n\t\treturn response.ok\n\t} catch {\n\t\treturn false\n\t}\n}\n\nconst PkgSchema = z.object({}).passthrough()\n\nexport async function getPkgProp<Value>(\n\tfullPath: string,\n\tprop: string,\n\tdefaultValue?: Value,\n): Promise<Value> {\n\tlet pkg: z.infer<typeof PkgSchema>\n\ttry {\n\t\tpkg = PkgSchema.parse(\n\t\t\tJSON.parse(\n\t\t\t\tfs.readFileSync(path.join(fullPath, 'package.json')).toString(),\n\t\t\t),\n\t\t)\n\t} catch (error) {\n\t\tthrow new Error(`Could not parse package.json of ${fullPath}`, {\n\t\t\tcause: error,\n\t\t})\n\t}\n\tconst propPath = prop.split('.')\n\tlet value: any = pkg\n\tfor (const p of propPath) {\n\t\tvalue = value[p]\n\t\tif (value === undefined) break\n\t}\n\tif (value === undefined && defaultValue === undefined) {\n\t\tthrow new Error(\n\t\t\t`Could not find required property ${prop} in package.json of ${fullPath}`,\n\t\t)\n\t}\n\treturn value ?? defaultValue\n}\n"]}
|