CodeSampleX

示例

electron-updater 6.8.9: NsisUpdater

已验证示例 — npm electron-updater 6.8.9: NsisUpdater. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: NsisUpdater instantiates with publish options and…

sha256:a8ae95f7562be639ac037a54df782deaf1883b0de6a8bf317fbe872fb9439ec0

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-26

案例

HOW
目标
verify NsisUpdater in pkg:npm/electron-updater@6.8.9
包
符号
  • NsisUpdater
环境
node 22.23.2
创建时间
2026-08-26T10:53:55Z

契约

  1. NsisUpdater instantiates with publish options and custom AppAdapter
  2. NsisUpdater exposes default autoDownload and autoInstallOnAppQuit flags as true
  3. NsisUpdater allows setting update channel and updates allowDowngrade accordingly
  4. NsisUpdater supports custom installDirectory configuration
  5. NsisUpdater allows configuring custom verifyUpdateCodeSignature verifier
  6. NsisUpdater adds authorization header to requestHeaders via addAuthHeader

文件

  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.cjs

下载源代码构件 (tar.gz)

源代码

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify NsisUpdater in pkg:npm/electron-updater@6.8.9
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/electron-updater@6.8.9
Demonstrate these symbols/APIs:
  - NsisUpdater

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:d28be4936b4949256778c64ad8e291fd5eee46eac78d96165fcc1eae287f6c70","contract":["NsisUpdater instantiates with publish options and custom AppAdapter","NsisUpdater exposes default autoDownload and autoInstallOnAppQuit flags as true","NsisUpdater allows setting update channel and updates allowDowngrade accordingly","NsisUpdater supports custom installDirectory configuration","NsisUpdater allows configuring custom verifyUpdateCodeSignature verifier","NsisUpdater adds authorization header to requestHeaders via addAuthHeader"],"goal":"verify NsisUpdater in pkg:npm/electron-updater@6.8.9","kind":"HOW","packages":["pkg:npm/electron-updater@6.8.9"],"schemaVersion":1,"symbols":["NsisUpdater"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/electron-updater@6.8.9"],"schemaVersion":1,"subject":"pkg:npm/electron-updater@6.8.9","symbols":["NsisUpdater"],"verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const { NsisUpdater } = require('electron-updater');

/**
 * Creates an instance of NsisUpdater with optional publish options and custom AppAdapter.
 * @param {Object} [options] - Publish options or updater configuration.
 * @param {Object} [app] - Optional custom AppAdapter.
 * @returns {NsisUpdater}
 */
function createNsisUpdater(options, app) {
  return new NsisUpdater(options, app);
}

/**
 * Configures common NsisUpdater properties such as channel, installDirectory, and autoDownload.
 * @param {NsisUpdater} updater
 * @param {Object} config
 * @returns {NsisUpdater}
 */
function configureNsisUpdater(updater, config = {}) {
  if (config.channel !== undefined) {
    updater.channel = config.channel;
  }
  if (config.autoDownload !== undefined) {
    updater.autoDownload = config.autoDownload;
  }
  if (config.autoInstallOnAppQuit !== undefined) {
    updater.autoInstallOnAppQuit = config.autoInstallOnAppQuit;
  }
  if (config.installDirectory !== undefined) {
    updater.installDirectory = config.installDirectory;
  }
  if (config.authHeader !== undefined) {
    updater.addAuthHeader(config.authHeader);
  }
  return updater;
}

module.exports = {
  createNsisUpdater,
  configureNsisUpdater,
  NsisUpdater
};
package-lock.json
{
  "name": "sample-electron-updater-nsisupdater",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-electron-updater-nsisupdater",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "electron-updater": "6.8.9"
      }
    },
    "node_modules/argparse": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
      "license": "Python-2.0"
    },
    "node_modules/builder-util-runtime": {
      "version": "9.7.0",
      "resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-9.7.0.tgz",
      "integrity": "sha512-g/kR520giAFYkSXTzcmF3kqQq7wi8F6N6SzeDgZrqTBN+VHdmgWOyTdD1yD7AATDId/yXLvuP34CxW46/BwCdw==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.3.4",
        "sax": "^1.2.4"
      },
      "engines": {
        "node": ">=12.0.0"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/electron-updater": {
      "version": "6.8.9",
      "resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-6.8.9.tgz",
      "integrity": "sha512-ZhVxM9iGONUpZGI1FxdMRgJjUFXi7AYGVa5PwKlO1tV1/4zDxQmfKpXOHVztKrd6L9rLcFjERvi1Mf2vxyTkig==",
      "license": "MIT",
      "dependencies": {
        "builder-util-runtime": "9.7.0",
        "fs-extra": "^10.1.0",
        "js-yaml": "^4.1.0",
        "lazy-val": "^1.0.5",
        "lodash.escaperegexp": "^4.1.2",
        "lodash.isequal": "^4.5.0",
        "semver": "~7.7.3",
        "tiny-typed-emitter": "^2.1.0"
      }
    },
    "node_modules/fs-extra": {
      "version": "10.1.0",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz",
      "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==",
      "license": "MIT",
      "dependencies": {
        "graceful-fs": "^4.2.0",
        "jsonfile": "^6.0.1",
        "universalify": "^2.0.0"
      },
      "engines": {
        "node": ">=12"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/js-yaml": {
      "version": "4.3.1",
      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.1.tgz",
      "integrity": "sha512-CY6crGq313MX8GkwvB7tzgp99vjQxY1++5y10/BKN/GUfHqWaOGQMNZkBvqSzsZKWk/ijwHlWzzkLulsGHhjWQ==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/puzrin"
        },
        {
          "type": "github",
          "url": "https://github.com/sponsors/nodeca"
        }
      ],
      "license": "MIT",
      "dependencies": {
        "argparse": "^2.0.1"
      },
      "bin": {
        "js-yaml": "bin/js-yaml.js"
      }
    },
    "node_modules/jsonfile": {
      "version": "6.2.1",
      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
      "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
      "license": "MIT",
      "dependencies": {
        "universalify": "^2.0.0"
      },
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/lazy-val": {
      "version": "1.0.5",
      "resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.5.tgz",
      "integrity": "sha512-0/BnGCCfyUMkBpeDgWihanIAF9JmZhHBgUhEqzvf+adhNGLoP6TaiI5oF8oyb3I45P+PcnrqihSf01M0l0G5+Q==",
      "license": "MIT"
    },
    "node_modules/lodash.escaperegexp": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz",
      "integrity": "sha512-TM9YBvyC84ZxE3rgfefxUWiQKLilstD6k7PTGt6wfbtXF8ixIJLOL3VYyV/z+ZiPLsVxAsKAFVwWlWeb2Y8Yyw==",
      "license": "MIT"
    },
    "node_modules/lodash.isequal": {
      "version": "4.5.0",
      "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
      "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==",
      "deprecated": "This package is deprecated. Use require('node:util').isDeepStrictEqual instead.",
      "license": "MIT"
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/sax": {
      "version": "1.6.1",
      "resolved": "https://registry.npmjs.org/sax/-/sax-1.6.1.tgz",
      "integrity": "sha512-42tBVwLWnaQvW5zc4HbZrTuWccECCZfBi92FDuwtqxasH+JbPB3/FOKb1m222K42R4WxuxzzMsTswfzgtSu64Q==",
      "license": "BlueOak-1.0.0",
      "engines": {
        "node": ">=11.0.0"
      }
    },
    "node_modules/semver": {
      "version": "7.7.4",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.4.tgz",
      "integrity": "sha512-vFKC2IEtQnVhpT78h1Yp8wzwrf8CM+MzKMHGJZfBtzhZNycRFnXsHk6E5TxIkkMsgNS7mdX3AGB7x2QM2di4lA==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/tiny-typed-emitter": {
      "version": "2.1.0",
      "resolved": "https://registry.npmjs.org/tiny-typed-emitter/-/tiny-typed-emitter-2.1.0.tgz",
      "integrity": "sha512-qVtvMxeXbVej0cQWKqVSSAHmKZEHAvxdF8HEUBFWts8h+xEo5m/lEiPakuyZ3BnCBjOD8i24kzNOiOLLgsSxhA==",
      "license": "MIT"
    },
    "node_modules/universalify": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
      "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-electron-updater-nsisupdater",
  "version": "1.0.0",
  "private": true,
  "description": "verify NsisUpdater in pkg:npm/electron-updater@6.8.9",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "electron-updater": "6.8.9"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify NsisUpdater in pkg:npm/electron-updater@6.8.9",
  "kind": "HOW",
  "packages": [
    "pkg:npm/electron-updater@6.8.9"
  ],
  "symbols": [
    "NsisUpdater"
  ]
}
test/contract.cjs
'use strict';

const assert = require('assert');
const path = require('path');
const os = require('os');
const { EventEmitter } = require('events');
const { NsisUpdater, createNsisUpdater, configureNsisUpdater } = require('../index.js');

function createMockAppAdapter() {
  const tmpDir = os.tmpdir();
  return {
    version: '1.0.0',
    name: 'test-electron-app',
    isPackaged: true,
    appUpdateConfigPath: path.join(tmpDir, 'app-update.yml'),
    userDataPath: path.join(tmpDir, 'test-userData'),
    baseCachePath: path.join(tmpDir, 'test-cache'),
    whenReady: async () => {},
    relaunch: () => {},
    quit: () => {},
    onQuit: (handler) => {}
  };
}

async function run() {
  const mockApp = createMockAppAdapter();
  const publishOptions = {
    provider: 'generic',
    url: 'https://example.com/updates'
  };

  // 1. Instantiation and prototype hierarchy
  const updater = createNsisUpdater(publishOptions, mockApp);
  assert(updater instanceof NsisUpdater, 'updater must be an instance of NsisUpdater');
  assert(updater instanceof EventEmitter, 'updater must inherit from EventEmitter');

  // 2. Default property values
  assert.strictEqual(updater.autoDownload, true, 'autoDownload must default to true');
  assert.strictEqual(updater.autoInstallOnAppQuit, true, 'autoInstallOnAppQuit must default to true');
  assert.strictEqual(updater.allowDowngrade, false, 'allowDowngrade must default to false');
  assert.strictEqual(updater.allowPrerelease, false, 'allowPrerelease must default to false');
  assert.strictEqual(updater.channel, null, 'channel must default to null');

  // 3. Channel configuration and allowDowngrade side-effect
  updater.channel = 'beta';
  assert.strictEqual(updater.channel, 'beta', 'channel must reflect assigned string value');
  assert.strictEqual(updater.allowDowngrade, true, 'setting channel must automatically set allowDowngrade to true');

  // Setting invalid channel throws error
  assert.throws(
    () => {
      updater.channel = '';
    },
    (err) => err.code === 'ERR_UPDATER_INVALID_CHANNEL' || /Channel must be not an empty string/.test(err.message),
    'setting empty channel must throw ERR_UPDATER_INVALID_CHANNEL'
  );

  // 4. installDirectory property
  assert.strictEqual(updater.installDirectory, undefined, 'installDirectory must initially be undefined');
  updater.installDirectory = 'custom-install-dir';
  assert.strictEqual(updater.installDirectory, 'custom-install-dir', 'installDirectory must be configurable');

  // 5. Code signature verifier customization
  assert.strictEqual(typeof updater.verifyUpdateCodeSignature, 'function', 'verifyUpdateCodeSignature must be a function');
  let customVerifierCalled = false;
  const customVerifier = async (publisherNames, tempPath) => {
    customVerifierCalled = true;
    return null;
  };
  updater.verifyUpdateCodeSignature = customVerifier;
  assert.strictEqual(updater.verifyUpdateCodeSignature, customVerifier, 'custom verifyUpdateCodeSignature must be assignable');

  // 6. Request headers and auth header
  updater.addAuthHeader('Bearer test-token-xyz');
  assert.deepStrictEqual(updater.requestHeaders, { authorization: 'Bearer test-token-xyz' }, 'addAuthHeader must set authorization header');

  // 7. configureNsisUpdater helper function
  const anotherUpdater = new NsisUpdater(null, mockApp);
  configureNsisUpdater(anotherUpdater, {
    channel: 'alpha',
    autoDownload: false,
    autoInstallOnAppQuit: false,
    installDirectory: 'another-install-dir',
    authHeader: 'Basic dGVzdDp0ZXN0'
  });
  assert.strictEqual(anotherUpdater.channel, 'alpha', 'helper must configure channel');
  assert.strictEqual(anotherUpdater.autoDownload, false, 'helper must configure autoDownload');
  assert.strictEqual(anotherUpdater.autoInstallOnAppQuit, false, 'helper must configure autoInstallOnAppQuit');
  assert.strictEqual(anotherUpdater.installDirectory, 'another-install-dir', 'helper must configure installDirectory');
  assert.deepStrictEqual(anotherUpdater.requestHeaders, { authorization: 'Basic dGVzdDp0ZXN0' }, 'helper must configure authHeader');

  // 8. Event listener attachment
  let listenerAttached = false;
  updater.on('update-available', () => {
    listenerAttached = true;
  });
  assert.strictEqual(updater.listenerCount('update-available'), 1, 'event listeners can be registered on updater');

  console.log('Contract tests passed successfully.');
  process.exit(0);
}

run().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

原始种子者

匿名