蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

观察同名配置行与包入口

JAVASCRIPTNode.js 24.22.3、TypeScript 6.0.3、YAML 2.9.0、固定版本源码。patch-layer-order.mjs
patch-layer-order.mjs76 行
import { registerHooks, createRequire } from 'node:module'
import fs from 'node:fs'
import path from 'node:path'
import assert from 'node:assert/strict'
import { createHash } from 'node:crypto'
import { pathToFileURL, fileURLToPath } from 'node:url'

const repo = path.resolve(process.argv[2])
const base = pathToFileURL(repo + '/').href
const req = createRequire(import.meta.url)
const ts = req(path.join(repo, 'node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/typescript.js'))
const spec = path.join(repo, 'node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.js')
const aliases = {
  '@deepseek-ai/dsh-typert-protocol': 'packages/typert/protocol/src/index.ts',
  '@deepseek-ai/dsh-brand': 'packages/util/brand/src/index.ts',
  '@deepseek-ai/dsh-util-crypto': 'packages/util/crypto/src/index.ts',
  '@deepseek-ai/dsh-timeout': 'packages/util/timeout/src/index.ts',
  '@deepseek-ai/cordis': 'vendor/cordis/src/index.ts',
  '@deepseek-ai/cosmokit': 'vendor/cosmokit/src/index.ts',
  '@deepseek-ai/schemastery': 'vendor/schemastery/src/index.ts',
  '@deepseek-ai/dsh-scope': 'packages/core/scope/src/index.ts',
  '@deepseek-ai/dsh-util-values': 'packages/util/values/src/index.ts',
  '@deepseek-ai/dsh-error': 'packages/util/error/src/index.ts',
  '@deepseek-ai/dsh-llm': 'packages/llm/llm/src/error.ts',
}
registerHooks({
  resolve(s, c, n) {
    if (aliases[s]) return n(base + aliases[s], c)
    if (s === '@standard-schema/spec') return n(pathToFileURL(spec).href, c)
    return n(s, c)
  },
  load(u, c, n) {
    if (u.startsWith(base) && u.endsWith('.ts')) return { format: 'module', source: ts.transpile(fs.readFileSync(fileURLToPath(u), 'utf8'), { compilerOptions: { module: ts.ModuleKind.ESNext, target: ts.ScriptTarget.ES2022 } }), shortCircuit: true }
    return n(u, c)
  },
})
const { applyPatches } = await import(base + 'vendor/include/src/patch.ts')
const yaml = req(path.join(repo,'node_modules/.pnpm/yaml@2.9.0/node_modules/yaml/dist/index.js'))
const manifest = { name:'lesson-profile',dsh:{profile:{bundles:['lesson-base','lesson-labels']}} }
const packages = new Map([
  ['lesson-base',{ dsh:{bundle:{patch:'./base.yml'}}, contents:
    '- insert:\n  - id: labels\n    name: lesson-labels\n    config: { greeting: welcome, color: blue }\n' }],
  ['lesson-labels',{ dsh:{bundle:{patch:'./labels.yml'}}, contents:
    '- id: labels\n  config: { color: green }\n' }],
])
const patches = manifest.dsh.profile.bundles.map(name => yaml.parse(packages.get(name).contents))
const profile = yaml.parse('- id: labels\n  config: { color: yellow }\n')
const home = yaml.parse('- id: labels\n  config: { color: orange }\n')
const overlay = yaml.parse('- id: labels\n  config: { color: purple }\n')
const cases = []
function check(name,input,expected,actual) {
  assert.deepEqual(actual,expected,name)
  cases.push({name,input,expected,actual,passed:true})
}
const root = []
const combined = applyPatches(root,patches.flat()).data
check('bundle_list_order',manifest,{color:'green'},combined[0].config)
check('whole_config_replaced',patches,false,Object.hasOwn(combined[0].config,'greeting'))
check('package_reference_retained',patches,'lesson-labels',combined[0].name)
check('profile_patch_after_bundles',profile,'yellow',applyPatches(root,[...patches.flat(),...profile]).data[0].config.color)
check('home_patch_after_profile',home,'orange',applyPatches(root,[...patches.flat(),...profile,...home]).data[0].config.color)
check('explicit_overlay_after_home',overlay,'purple',applyPatches(root,[...patches.flat(),...profile,...home,...overlay]).data[0].config.color)
check('patcher_keeps_original_tree',root,[],root)
const warnings = []
const reverse = applyPatches(root,[...patches[1],...patches[0]],(...args)=>warnings.push(args)).data
check('override_before_insert_warns','reverse two bundle layers',{color:'blue',warnings:1},
  {color:reverse[0].config.color,warnings:warnings.length})
const hash = bytes => createHash('sha256').update(bytes).digest('hex')
const sources = ['vendor/include/src/patch.ts','vendor/include/src/journal.ts','vendor/cosmokit/src/index.ts',
  'docs/user/develop/basic/publish.zh.md','packages/boot/app-boot/src/profile.ts']
console.log(JSON.stringify({
  cases,node:process.version,typescript:ts.version,yaml:'2.9.0',code_sha256:hash(fs.readFileSync(fileURLToPath(import.meta.url))),
  source_hashes:Object.fromEntries(sources.map(name=>[name,hash(fs.readFileSync(path.join(repo,name)))])),
  actual_profile_cli_tested:false, pnpm_install_tested:false, modules_loaded_from_package:false, config_js_evaluated:false,
},null,2))
本例需在 Node.js 24.22.3、TypeScript 6.0.3、YAML 2.9.0、固定版本源码。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Node.js 24.22.3、TypeScript 6.0.3、YAML 2.9.0、固定版本源码。

入口文件:projects/deepseek-harness-bundle-profile/patch-layer-order.mjs

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 patch-layer-order.mjs,或下载右侧课程工程包。
  2. 确认本地已准备 Node.js 24.22.3、TypeScript 6.0.3、YAML 2.9.0、固定版本源码。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:DeepSeek Harness

课程关联工程包(登记关联33章) · 含当前章节或实例 · mbskycom202612a128.zip

下载课程关联工程包:DeepSeek Harness

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a130.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习