diff --git a/src/compiler.ts b/src/compiler.ts index 332ca52..a4b8a70 100644 --- a/src/compiler.ts +++ b/src/compiler.ts @@ -111,8 +111,10 @@ export class NexeCompiler { if (options.asset && options.asset.startsWith('http')) { this.remoteAsset = options.asset } else { - this.remoteAsset = - 'https://github.com/nexe/nexe/releases/download/v3.0.0/' + this.target.toString() + if (!options.remote.startsWith('http')) { + throw new NexeError(`Invalid remote URL (must be HTTP/HTTPS): ${options.remote}`) + } + this.remoteAsset = options.remote + this.target.toString() } this.src = join(this.options.temp, this.target.version) this.configureScript = configure + (semverGt(this.target.version, '10.10.0') ? '.py' : '') diff --git a/src/options.ts b/src/options.ts index 8b1393a..54a1e3b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -39,6 +39,7 @@ export interface NexeOptions { native: any mangle: boolean ghToken: string + remote: string sourceUrl?: string enableStdIn?: boolean python?: string @@ -71,6 +72,7 @@ const defaults = { bundle: true, patches: [], plugins: [], + remote: 'https://github.com/nexe/nexe/releases/download/v3.0.0/', } const alias = { i: 'input', @@ -87,6 +89,7 @@ const alias = { m: 'make', h: 'help', l: 'loglevel', + e: 'remote', 'fake-argv': 'fakeArgv', 'gh-token': 'ghToken', } @@ -103,6 +106,7 @@ ${c.bold('nexe [options]')} -r --resource -- *embed files (glob) within the binary -a --asset -- alternate asset path, file or url pointing to a base (nexe) binary --plugin -- extend nexe runtime behavior + -e --remote -- third-party remote location (URL) to download pre-built releases from ${c.underline.bold('Building from source:')} @@ -249,6 +253,10 @@ function normalizeOptions(input?: Partial): NexeOptions { options.configure = flatten(options.configure) options.resources = flatten(opts.resource, options.resources) + if (!options.remote.endsWith('/')) { + options.remote += '/' + } + options.downloadOptions = options.downloadOptions || {} options.downloadOptions.headers = options.downloadOptions.headers || {} options.downloadOptions.headers['User-Agent'] = 'nexe (https://www.npmjs.com/package/nexe)' diff --git a/test/options.spec.ts b/test/options.spec.ts index 5b0832d..01a85e2 100644 --- a/test/options.spec.ts +++ b/test/options.spec.ts @@ -39,6 +39,26 @@ describe('options', () => { expect(options.output).to.equal(path.resolve(cwd, `abc${ext}`)) }) }) + + describe('remote', () => { + it('should use default remote', () => { + const options = normalizeOptions({}) + expect(options.remote).to.equal('https://github.com/nexe/nexe/releases/download/v3.0.0/') + }) + it('should append trailing slash to third-party remote if necessary', () => { + const options = normalizeOptions({ + remote: 'https://sitejs.org/nexe' + }) + expect(options.remote).to.equal('https://sitejs.org/nexe/') + }) + it('should not append trailing slash to third-party remote that already has one', () => { + const options = normalizeOptions({ + remote: 'https://sitejs.org/nexe/' + }) + expect(options.remote).to.equal('https://sitejs.org/nexe/') + }) + }) + describe('output', () => { it('should work', () => { const options = normalizeOptions({