@@ -3,17 +3,23 @@ import fs from 'node:fs';
33import https from 'node:https' ;
44import path from 'node:path' ;
55import process from 'node:process' ;
6+ import url from 'node:url' ;
67
78import * as GlobModule from 'glob' ;
89
910/**
1011 * Get manifest (array of NW release metadata) from URL.
11- * @param {string } manifestUrl Url to manifest
12- * @returns {Promise< string> } - Manifest object
12+ * @param {string } manifestUrl Versions manifest URI, https or file path
13+ * @returns {string } - Manifest object
1314 */
1415function getManifest ( manifestUrl ) {
1516 let chunks = '' ;
1617
18+ if ( manifestUrl . startsWith ( 'file://' ) ) {
19+ const filePath = url . fileURLToPath ( manifestUrl ) ;
20+ return fs . readFileSync ( filePath , 'utf-8' ) ;
21+ }
22+
1723 return new Promise ( ( resolve ) => {
1824 const req = https . get ( manifestUrl , ( response ) => {
1925 response . on ( 'data' , ( chunk ) => {
@@ -42,8 +48,8 @@ function getManifest(manifestUrl) {
4248 * @param {string } platform NW platform
4349 * @param {string } arch NW architecture
4450 * @param {string } cacheDir Directory to store NW binaries
45- * @param {string } manifestUrl Url to manifest
46- * @returns {object } Version specific release info
51+ * @param {string } manifestUrl Versions manifest URI, https or file path
52+ * @returns {Promise< object> } Version specific release info
4753 */
4854async function getReleaseInfo (
4955 version ,
@@ -343,8 +349,8 @@ export const validate = async (options, releaseInfo) => {
343349 if ( typeof options . downloadUrl === 'string' && ! options . downloadUrl . startsWith ( 'http' ) && ! options . downloadUrl . startsWith ( 'file' ) ) {
344350 throw new Error ( 'Expected options.downloadUrl to be a string and starts with `http` or `file`.' ) ;
345351 }
346- if ( typeof options . manifestUrl === 'string' && ! options . manifestUrl . startsWith ( 'http ' ) && ! options . manifestUrl . startsWith ( 'file' ) ) {
347- throw new Error ( 'Expected options.manifestUrl to be a string and starts with `http ` or `file`.' ) ;
352+ if ( typeof options . manifestUrl === 'string' && ! options . manifestUrl . startsWith ( 'https ' ) && ! options . manifestUrl . startsWith ( 'file' ) ) {
353+ throw new Error ( 'Expected options.manifestUrl to be a string and starts with `https ` or `file`.' ) ;
348354 }
349355 if ( typeof options . cacheDir !== 'string' ) {
350356 throw new Error ( 'Expected options.cacheDir to be a string. Got ' + typeof options . cacheDir ) ;
@@ -425,15 +431,15 @@ export const validate = async (options, releaseInfo) => {
425431 }
426432
427433 if ( typeof options . nativeAddon !== 'boolean' ) {
428- throw new Error ( 'Expected options.nativeAddon to be a boolean. Got ' + typeof options . nativeAddon ) ;
434+ throw new Error ( 'Expected options.nativeAddon to be a boolean. Got ' + typeof options . nativeAddon ) ;
429435 }
430436
431437 if ( typeof options . zip !== 'boolean' &
432- options . zip !== 'zip' &&
433- options . zip !== 'tar' &&
434- options . zip !== 'tgz' ) {
435- throw new Error ( 'Expected options.zip to be a boolean, `zip`, `tar` or `tgz`. Got ' + typeof options . zip ) ;
436- }
438+ options . zip !== 'zip' &&
439+ options . zip !== 'tar' &&
440+ options . zip !== 'tgz' ) {
441+ throw new Error ( 'Expected options.zip to be a boolean, `zip`, `tar` or `tgz`. Got ' + typeof options . zip ) ;
442+ }
437443
438444 if ( options . platform === 'linux' ) {
439445 if ( options . app . name && typeof options . app . name !== 'string' ) {
@@ -664,4 +670,4 @@ function log(severity, logLevel, message) {
664670 return stdout ;
665671}
666672
667- export default { fileExists, getReleaseInfo, getPath, PLATFORM_KV , ARCH_KV , EXE_NAME , globFiles, getNodeManifest, parse, validate, log } ;
673+ export default { fileExists, getReleaseInfo, getManifest , getPath, PLATFORM_KV , ARCH_KV , EXE_NAME , globFiles, getNodeManifest, parse, validate, log } ;
0 commit comments