CodeSampleX

示例

bare-module-resolve 1.12.4: resolve

已验证示例 — npm bare-module-resolve 1.12.4: resolve. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: resolve yields candidate URLs for relative paths and…

sha256:fbf384c14256eb5d992d14cde6fc44d99714aea20cb8013c91270eef2d2d1638

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

执行证据

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

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

验证运行环境

环境 契约 阶段 运行日期
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-27

案例

HOW
目标
verify pkg:npm/bare-module-resolve@1.12.4
包
符号
  • resolve
创建时间
2026-08-27T13:12:58Z

契约

  1. resolve yields candidate URLs for relative paths and appends configured file extensions and directory index files
  2. resolve queries package.json via readPackage and resolves package main entry point
  3. resolve handles package exports conditions and subpath patterns
  4. resolve supports async iteration when readPackage returns a promise
  5. resolve throws ModuleResolveError with INVALID_MODULE_SPECIFIER for invalid package specifiers
  6. resolve throws ModuleResolveError with PACKAGE_PATH_NOT_EXPORTED when subpath is not in exports

文件

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

下载源代码构件 (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 pkg:npm/bare-module-resolve@1.12.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/bare-module-resolve@1.12.4
Demonstrate these symbols/APIs:
  - resolve

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:1fafac81d27032e1582d7618a0e8ddc8340211a97f954729b226eb2f6e208657","contract":["resolve yields candidate URLs for relative paths and appends configured file extensions and directory index files","resolve queries package.json via readPackage and resolves package main entry point","resolve handles package exports conditions and subpath patterns","resolve supports async iteration when readPackage returns a promise","resolve throws ModuleResolveError with INVALID_MODULE_SPECIFIER for invalid package specifiers","resolve throws ModuleResolveError with PACKAGE_PATH_NOT_EXPORTED when subpath is not in exports"],"goal":"verify pkg:npm/bare-module-resolve@1.12.4","kind":"HOW","packages":["pkg:npm/bare-module-resolve@1.12.4"],"schemaVersion":1,"symbols":["resolve"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/bare-module-resolve@1.12.4"],"schemaVersion":1,"subject":"pkg:npm/bare-module-resolve@1.12.4","symbols":["resolve"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "bare-module-resolve-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "bare-module-resolve-sample",
      "version": "1.0.0",
      "dependencies": {
        "bare-module-resolve": "1.12.4"
      }
    },
    "node_modules/bare-module-resolve": {
      "version": "1.12.4",
      "resolved": "https://registry.npmjs.org/bare-module-resolve/-/bare-module-resolve-1.12.4.tgz",
      "integrity": "sha512-xcfgg2u7HqgJiBmah71O9vvdFAgHCvkqC/WSC2O7Bbgosoc1eC/BWe/6IDJ4OsfKlkxuvC/TDWXC+oH5yeW8mA==",
      "license": "Apache-2.0",
      "dependencies": {
        "bare-semver": "^1.0.0"
      },
      "peerDependencies": {
        "bare-url": "*"
      },
      "peerDependenciesMeta": {
        "bare-url": {
          "optional": true
        }
      }
    },
    "node_modules/bare-semver": {
      "version": "1.1.0",
      "resolved": "https://registry.npmjs.org/bare-semver/-/bare-semver-1.1.0.tgz",
      "integrity": "sha512-1Hw5qJ7hXdVt3uPUqjeFTuxyvBUJauvz5A1I2jk8gzjZMHp04n//6nV9MDbG9CMw78JHY2lGV0w6s//LrASm2w==",
      "license": "Apache-2.0"
    }
  }
}
package.json
{
  "name": "bare-module-resolve-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for bare-module-resolve",
  "dependencies": {
    "bare-module-resolve": "1.12.4"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/bare-module-resolve@1.12.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/bare-module-resolve@1.12.4"
  ],
  "symbols": [
    "resolve"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import resolve from 'bare-module-resolve';

// 1. resolve yields candidate URLs for relative paths and appends configured file extensions and directory index files
const parentURL = new URL('file:///workspace/project/src/app.js');
const relativeCandidates = [...resolve('./helpers', parentURL, { extensions: ['.js', '.json'] })];
assert.deepStrictEqual(relativeCandidates.map((u) => u.href), [
  'file:///workspace/project/src/helpers',
  'file:///workspace/project/src/helpers.js',
  'file:///workspace/project/src/helpers.json',
  'file:///workspace/project/src/helpers/index.js',
  'file:///workspace/project/src/helpers/index.json'
]);

// 2. resolve queries package.json via readPackage and resolves package main entry point
const packageCandidates = [
  ...resolve('example-lib', parentURL, { extensions: ['.js'] }, (packageURL) => {
    if (packageURL.href === 'file:///workspace/project/node_modules/example-lib/package.json') {
      return {
        name: 'example-lib',
        main: './lib/index.js'
      };
    }
    return null;
  })
];
assert.strictEqual(
  packageCandidates[0].href,
  'file:///workspace/project/node_modules/example-lib/lib/index.js'
);

// 3. resolve handles package exports conditions and subpath patterns
const exportCandidates = [
  ...resolve(
    'example-pkg/feature/sub',
    parentURL,
    { conditions: ['import', 'node', 'default'] },
    (packageURL) => {
      if (packageURL.href === 'file:///workspace/project/node_modules/example-pkg/package.json') {
        return {
          name: 'example-pkg',
          exports: {
            '.': {
              import: './esm/index.js',
              require: './cjs/index.cjs'
            },
            './feature/*': {
              import: './esm/features/*.js',
              default: './cjs/features/*.cjs'
            }
          }
        };
      }
      return null;
    }
  )
];
assert.strictEqual(
  exportCandidates[0].href,
  'file:///workspace/project/node_modules/example-pkg/esm/features/sub.js'
);

// 4. resolve supports async iteration when readPackage returns a promise
const asyncResults = [];
for await (const candidate of resolve('async-pkg', parentURL, {}, async (packageURL) => {
  if (packageURL.href === 'file:///workspace/project/node_modules/async-pkg/package.json') {
    return {
      name: 'async-pkg',
      main: './dist/bundle.js'
    };
  }
  return null;
})) {
  asyncResults.push(candidate);
}
assert.strictEqual(
  asyncResults[0].href,
  'file:///workspace/project/node_modules/async-pkg/dist/bundle.js'
);

// 5. resolve throws ModuleResolveError with INVALID_MODULE_SPECIFIER for invalid package specifiers
assert.throws(
  () => {
    [...resolve('', parentURL)];
  },
  (err) => {
    return err.name === 'ModuleResolveError' && err.code === 'INVALID_MODULE_SPECIFIER';
  }
);

// 6. resolve throws ModuleResolveError with PACKAGE_PATH_NOT_EXPORTED when subpath is not in exports
assert.throws(
  () => {
    [
      ...resolve('example-pkg/unexported', parentURL, {}, (packageURL) => {
        if (packageURL.href === 'file:///workspace/project/node_modules/example-pkg/package.json') {
          return {
            name: 'example-pkg',
            exports: {
              './valid': './dist/valid.js'
            }
          };
        }
        return null;
      })
    ];
  },
  (err) => {
    return err.name === 'ModuleResolveError' && err.code === 'PACKAGE_PATH_NOT_EXPORTED';
  }
);

console.log('Contract passed');

原始种子者

匿名