@cloudbase/cloudbase-mcp 2.4.0-alpha.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/dist/cli.cjs +426 -18
  2. package/dist/index.cjs +426 -18
  3. package/dist/index.js +7721 -7632
  4. package/package.json +2 -1
package/dist/index.cjs CHANGED
@@ -100572,6 +100572,9 @@ async function createCloudBaseMcpServer(options) {
100572
100572
  if (logger) {
100573
100573
  server.logger = logger;
100574
100574
  }
100575
+ server.setLogger = (logger) => {
100576
+ server.logger = logger;
100577
+ };
100575
100578
  // Enable telemetry if requested
100576
100579
  if (enableTelemetry) {
100577
100580
  (0, tool_wrapper_js_1.wrapServerWithTelemetry)(server);
@@ -135023,7 +135026,7 @@ class TelemetryReporter {
135023
135026
  const nodeVersion = process.version; // Node.js版本
135024
135027
  const arch = os_1.default.arch(); // 系统架构
135025
135028
  // 从构建时注入的版本号获取MCP版本信息
135026
- const mcpVersion = process.env.npm_package_version || "2.4.0-alpha.0" || 0;
135029
+ const mcpVersion = process.env.npm_package_version || "2.5.0" || 0;
135027
135030
  return {
135028
135031
  userAgent: `${osType} ${osRelease} ${arch} ${nodeVersion} CloudBase-MCP/${mcpVersion}`,
135029
135032
  deviceId: this.deviceId,
@@ -185505,6 +185508,7 @@ exports.getClaudePrompt = getClaudePrompt;
185505
185508
  exports.registerRagTools = registerRagTools;
185506
185509
  const adm_zip_1 = __importDefault(__webpack_require__(30283));
185507
185510
  const fs = __importStar(__webpack_require__(79748));
185511
+ const lockfile_1 = __importDefault(__webpack_require__(80127));
185508
185512
  const os = __importStar(__webpack_require__(21820));
185509
185513
  const path = __importStar(__webpack_require__(39902));
185510
185514
  const zod_1 = __webpack_require__(21614);
@@ -185521,7 +185525,39 @@ const KnowledgeBaseIdMap = {
185521
185525
  // ============ 缓存配置 ============
185522
185526
  const CACHE_BASE_DIR = path.join(os.homedir(), ".cloudbase-mcp");
185523
185527
  const CACHE_META_FILE = path.join(CACHE_BASE_DIR, "cache-meta.json");
185528
+ const LOCK_FILE = path.join(CACHE_BASE_DIR, ".download.lock");
185524
185529
  const DEFAULT_CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 默认 24 小时
185530
+ // Promise wrapper for lockfile methods
185531
+ function acquireLock(lockPath, options) {
185532
+ return new Promise((resolve, reject) => {
185533
+ if (options) {
185534
+ lockfile_1.default.lock(lockPath, options, (err) => {
185535
+ if (err)
185536
+ reject(err);
185537
+ else
185538
+ resolve();
185539
+ });
185540
+ }
185541
+ else {
185542
+ lockfile_1.default.lock(lockPath, (err) => {
185543
+ if (err)
185544
+ reject(err);
185545
+ else
185546
+ resolve();
185547
+ });
185548
+ }
185549
+ });
185550
+ }
185551
+ function releaseLock(lockPath) {
185552
+ return new Promise((resolve, reject) => {
185553
+ lockfile_1.default.unlock(lockPath, (err) => {
185554
+ if (err)
185555
+ reject(err);
185556
+ else
185557
+ resolve();
185558
+ });
185559
+ });
185560
+ }
185525
185561
  // 支持环境变量 CLOUDBASE_MCP_CACHE_TTL_MS 控制缓存过期时间(毫秒)
185526
185562
  const parsedCacheTTL = process.env.CLOUDBASE_MCP_CACHE_TTL_MS
185527
185563
  ? parseInt(process.env.CLOUDBASE_MCP_CACHE_TTL_MS, 10)
@@ -185691,14 +185727,19 @@ async function _doDownloadResources() {
185691
185727
  async function downloadResources() {
185692
185728
  const webTemplateDir = path.join(CACHE_BASE_DIR, "web-template");
185693
185729
  const openAPIDir = path.join(CACHE_BASE_DIR, "openapi");
185694
- // 检查缓存是否有效
185730
+ // 如果已有下载任务在进行中,共享该 Promise
185731
+ if (resourceDownloadPromise) {
185732
+ (0, logger_js_1.debug)("[downloadResources] 共享已有下载任务");
185733
+ return resourceDownloadPromise;
185734
+ }
185735
+ // 先快速检查缓存(不需要锁,因为只是读取)
185695
185736
  if (await canUseCache()) {
185696
185737
  try {
185697
185738
  // 检查两个目录都存在
185698
185739
  await Promise.all([fs.access(webTemplateDir), fs.access(openAPIDir)]);
185699
185740
  const files = await fs.readdir(openAPIDir);
185700
185741
  if (files.length > 0) {
185701
- (0, logger_js_1.debug)("[downloadResources] 使用缓存");
185742
+ (0, logger_js_1.debug)("[downloadResources] 使用缓存(快速路径)");
185702
185743
  return {
185703
185744
  webTemplateDir,
185704
185745
  openAPIDocs: OPENAPI_SOURCES.map((source) => ({
@@ -185713,21 +185754,61 @@ async function downloadResources() {
185713
185754
  // 缓存无效,需要重新下载
185714
185755
  }
185715
185756
  }
185716
- // 如果已有下载任务在进行中,共享该 Promise
185717
- if (resourceDownloadPromise) {
185718
- (0, logger_js_1.debug)("[downloadResources] 共享已有下载任务");
185719
- return resourceDownloadPromise;
185720
- }
185721
- // 创建新的下载任务
185757
+ // 创建新的下载任务,使用文件锁保护
185722
185758
  (0, logger_js_1.debug)("[downloadResources] 开始新下载任务");
185723
185759
  await fs.mkdir(CACHE_BASE_DIR, { recursive: true });
185724
- resourceDownloadPromise = _doDownloadResources()
185725
- .then(async (result) => {
185726
- await updateCache();
185727
- (0, logger_js_1.debug)("[downloadResources] 缓存已更新");
185728
- return result;
185729
- })
185730
- .finally(() => {
185760
+ resourceDownloadPromise = (async () => {
185761
+ // 尝试获取文件锁,最多等待 6 秒(30 次 × 200ms),每 200ms 轮询一次
185762
+ let lockAcquired = false;
185763
+ try {
185764
+ await acquireLock(LOCK_FILE, {
185765
+ wait: 30 * 200, // 总等待时间:6000ms (6 秒)
185766
+ pollPeriod: 200, // 轮询间隔:200ms
185767
+ stale: 5 * 60 * 1000, // 5 分钟,如果锁文件超过这个时间认为是过期的
185768
+ });
185769
+ lockAcquired = true;
185770
+ (0, logger_js_1.debug)("[downloadResources] 文件锁已获取");
185771
+ // 在持有锁的情况下再次检查缓存(可能其他进程已经下载完成)
185772
+ if (await canUseCache()) {
185773
+ try {
185774
+ // 检查两个目录都存在
185775
+ await Promise.all([fs.access(webTemplateDir), fs.access(openAPIDir)]);
185776
+ const files = await fs.readdir(openAPIDir);
185777
+ if (files.length > 0) {
185778
+ (0, logger_js_1.debug)("[downloadResources] 使用缓存(在锁保护下检查)");
185779
+ return {
185780
+ webTemplateDir,
185781
+ openAPIDocs: OPENAPI_SOURCES.map((source) => ({
185782
+ name: source.name,
185783
+ description: source.description,
185784
+ absolutePath: path.join(openAPIDir, `${source.name}.openapi.yaml`),
185785
+ })).filter((item) => files.includes(`${item.name}.openapi.yaml`)),
185786
+ };
185787
+ }
185788
+ }
185789
+ catch {
185790
+ // 缓存无效,需要重新下载
185791
+ }
185792
+ }
185793
+ // 执行下载
185794
+ const result = await _doDownloadResources();
185795
+ await updateCache();
185796
+ (0, logger_js_1.debug)("[downloadResources] 缓存已更新");
185797
+ return result;
185798
+ }
185799
+ finally {
185800
+ // 释放文件锁
185801
+ if (lockAcquired) {
185802
+ try {
185803
+ await releaseLock(LOCK_FILE);
185804
+ (0, logger_js_1.debug)("[downloadResources] 文件锁已释放");
185805
+ }
185806
+ catch (error) {
185807
+ (0, logger_js_1.warn)("[downloadResources] 释放文件锁失败", { error });
185808
+ }
185809
+ }
185810
+ }
185811
+ })().finally(() => {
185731
185812
  resourceDownloadPromise = null;
185732
185813
  });
185733
185814
  return resourceDownloadPromise;
@@ -200871,7 +200952,7 @@ ${envIdSection}
200871
200952
  ## 环境信息
200872
200953
  - 操作系统: ${os_1.default.type()} ${os_1.default.release()}
200873
200954
  - Node.js版本: ${process.version}
200874
- - MCP 版本:${process.env.npm_package_version || "2.4.0-alpha.0" || 0}
200955
+ - MCP 版本:${process.env.npm_package_version || "2.5.0" || 0}
200875
200956
  - 系统架构: ${os_1.default.arch()}
200876
200957
  - 时间: ${new Date().toISOString()}
200877
200958
  - 请求ID: ${requestId}
@@ -215540,7 +215621,7 @@ function registerSetupTools(server) {
215540
215621
  title: "下载项目模板",
215541
215622
  description: `自动下载并部署CloudBase项目模板。⚠️ **MANDATORY FOR NEW PROJECTS** ⚠️
215542
215623
 
215543
- **CRITICAL**: This tool MUST be called FIRST when starting a new project.\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置(默认)\n- cursor: Cursor AI编辑器\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.4.0-alpha.0" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
215624
+ **CRITICAL**: This tool MUST be called FIRST when starting a new project.\n\n支持的模板:\n- react: React + CloudBase 全栈应用模板\n- vue: Vue + CloudBase 全栈应用模板\n- miniprogram: 微信小程序 + 云开发模板 \n- uniapp: UniApp + CloudBase 跨端应用模板\n- rules: 只包含AI编辑器配置文件(包含Cursor、WindSurf、CodeBuddy等所有主流编辑器配置),适合在已有项目中补充AI编辑器配置\n\n支持的IDE类型:\n- all: 下载所有IDE配置(默认)\n- cursor: Cursor AI编辑器\n- windsurf: WindSurf AI编辑器\n- codebuddy: CodeBuddy AI编辑器\n- claude-code: Claude Code AI编辑器\n- cline: Cline AI编辑器\n- gemini-cli: Gemini CLI\n- opencode: OpenCode AI编辑器\n- qwen-code: 通义灵码\n- baidu-comate: 百度Comate\n- openai-codex-cli: OpenAI Codex CLI\n- augment-code: Augment Code\n- github-copilot: GitHub Copilot\n- roocode: RooCode AI编辑器\n- tongyi-lingma: 通义灵码\n- trae: Trae AI编辑器\n- qoder: Qoder AI编辑器\n- antigravity: Google Antigravity AI编辑器\n- vscode: Visual Studio Code\n\n特别说明:\n- rules 模板会自动包含当前 mcp 版本号信息(版本号:${ true ? "2.5.0" : 0}),便于后续维护和版本追踪\n- 下载 rules 模板时,如果项目中已存在 README.md 文件,系统会自动保护该文件不被覆盖(除非设置 overwrite=true)`,
215544
215625
  inputSchema: {
215545
215626
  template: zod_1.z
215546
215627
  .enum(["react", "vue", "miniprogram", "uniapp", "rules"])
@@ -224631,6 +224712,333 @@ function resolveIds(schema) {
224631
224712
  }
224632
224713
 
224633
224714
 
224715
+ /***/ }),
224716
+
224717
+ /***/ 80127:
224718
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
224719
+
224720
+ var fs = __webpack_require__(29021)
224721
+
224722
+ var wx = 'wx'
224723
+ if (process.version.match(/^v0\.[0-6]/)) {
224724
+ var c = __webpack_require__(81115)
224725
+ wx = c.O_TRUNC | c.O_CREAT | c.O_WRONLY | c.O_EXCL
224726
+ }
224727
+
224728
+ var os = __webpack_require__(21820)
224729
+ exports.filetime = 'ctime'
224730
+ if (os.platform() == "win32") {
224731
+ exports.filetime = 'mtime'
224732
+ }
224733
+
224734
+ var debug
224735
+ var util = __webpack_require__(28354)
224736
+ if (util.debuglog)
224737
+ debug = util.debuglog('LOCKFILE')
224738
+ else if (/\blockfile\b/i.test(process.env.NODE_DEBUG))
224739
+ debug = function() {
224740
+ var msg = util.format.apply(util, arguments)
224741
+ console.error('LOCKFILE %d %s', process.pid, msg)
224742
+ }
224743
+ else
224744
+ debug = function() {}
224745
+
224746
+ var locks = {}
224747
+
224748
+ function hasOwnProperty (obj, prop) {
224749
+ return Object.prototype.hasOwnProperty.call(obj, prop)
224750
+ }
224751
+
224752
+ var onExit = __webpack_require__(29468)
224753
+ onExit(function () {
224754
+ debug('exit listener')
224755
+ // cleanup
224756
+ Object.keys(locks).forEach(exports.unlockSync)
224757
+ })
224758
+
224759
+ // XXX https://github.com/joyent/node/issues/3555
224760
+ // Remove when node 0.8 is deprecated.
224761
+ if (/^v0\.[0-8]\./.test(process.version)) {
224762
+ debug('uncaughtException, version = %s', process.version)
224763
+ process.on('uncaughtException', function H (er) {
224764
+ debug('uncaughtException')
224765
+ var l = process.listeners('uncaughtException').filter(function (h) {
224766
+ return h !== H
224767
+ })
224768
+ if (!l.length) {
224769
+ // cleanup
224770
+ try { Object.keys(locks).forEach(exports.unlockSync) } catch (e) {}
224771
+ process.removeListener('uncaughtException', H)
224772
+ throw er
224773
+ }
224774
+ })
224775
+ }
224776
+
224777
+ exports.unlock = function (path, cb) {
224778
+ debug('unlock', path)
224779
+ // best-effort. unlocking an already-unlocked lock is a noop
224780
+ delete locks[path]
224781
+ fs.unlink(path, function (unlinkEr) { cb && cb() })
224782
+ }
224783
+
224784
+ exports.unlockSync = function (path) {
224785
+ debug('unlockSync', path)
224786
+ // best-effort. unlocking an already-unlocked lock is a noop
224787
+ try { fs.unlinkSync(path) } catch (er) {}
224788
+ delete locks[path]
224789
+ }
224790
+
224791
+
224792
+ // if the file can be opened in readonly mode, then it's there.
224793
+ // if the error is something other than ENOENT, then it's not.
224794
+ exports.check = function (path, opts, cb) {
224795
+ if (typeof opts === 'function') cb = opts, opts = {}
224796
+ debug('check', path, opts)
224797
+ fs.open(path, 'r', function (er, fd) {
224798
+ if (er) {
224799
+ if (er.code !== 'ENOENT') return cb(er)
224800
+ return cb(null, false)
224801
+ }
224802
+
224803
+ if (!opts.stale) {
224804
+ return fs.close(fd, function (er) {
224805
+ return cb(er, true)
224806
+ })
224807
+ }
224808
+
224809
+ fs.fstat(fd, function (er, st) {
224810
+ if (er) return fs.close(fd, function (er2) {
224811
+ return cb(er)
224812
+ })
224813
+
224814
+ fs.close(fd, function (er) {
224815
+ var age = Date.now() - st[exports.filetime].getTime()
224816
+ return cb(er, age <= opts.stale)
224817
+ })
224818
+ })
224819
+ })
224820
+ }
224821
+
224822
+ exports.checkSync = function (path, opts) {
224823
+ opts = opts || {}
224824
+ debug('checkSync', path, opts)
224825
+ if (opts.wait) {
224826
+ throw new Error('opts.wait not supported sync for obvious reasons')
224827
+ }
224828
+
224829
+ try {
224830
+ var fd = fs.openSync(path, 'r')
224831
+ } catch (er) {
224832
+ if (er.code !== 'ENOENT') throw er
224833
+ return false
224834
+ }
224835
+
224836
+ if (!opts.stale) {
224837
+ try { fs.closeSync(fd) } catch (er) {}
224838
+ return true
224839
+ }
224840
+
224841
+ // file exists. however, might be stale
224842
+ if (opts.stale) {
224843
+ try {
224844
+ var st = fs.fstatSync(fd)
224845
+ } finally {
224846
+ fs.closeSync(fd)
224847
+ }
224848
+ var age = Date.now() - st[exports.filetime].getTime()
224849
+ return (age <= opts.stale)
224850
+ }
224851
+ }
224852
+
224853
+
224854
+
224855
+ var req = 1
224856
+ exports.lock = function (path, opts, cb) {
224857
+ if (typeof opts === 'function') cb = opts, opts = {}
224858
+ opts.req = opts.req || req++
224859
+ debug('lock', path, opts)
224860
+ opts.start = opts.start || Date.now()
224861
+
224862
+ if (typeof opts.retries === 'number' && opts.retries > 0) {
224863
+ debug('has retries', opts.retries)
224864
+ var retries = opts.retries
224865
+ opts.retries = 0
224866
+ cb = (function (orig) { return function cb (er, fd) {
224867
+ debug('retry-mutated callback')
224868
+ retries -= 1
224869
+ if (!er || retries < 0) return orig(er, fd)
224870
+
224871
+ debug('lock retry', path, opts)
224872
+
224873
+ if (opts.retryWait) setTimeout(retry, opts.retryWait)
224874
+ else retry()
224875
+
224876
+ function retry () {
224877
+ opts.start = Date.now()
224878
+ debug('retrying', opts.start)
224879
+ exports.lock(path, opts, cb)
224880
+ }
224881
+ }})(cb)
224882
+ }
224883
+
224884
+ // try to engage the lock.
224885
+ // if this succeeds, then we're in business.
224886
+ fs.open(path, wx, function (er, fd) {
224887
+ if (!er) {
224888
+ debug('locked', path, fd)
224889
+ locks[path] = fd
224890
+ return fs.close(fd, function () {
224891
+ return cb()
224892
+ })
224893
+ }
224894
+
224895
+ debug('failed to acquire lock', er)
224896
+
224897
+ // something other than "currently locked"
224898
+ // maybe eperm or something.
224899
+ if (er.code !== 'EEXIST') {
224900
+ debug('not EEXIST error', er)
224901
+ return cb(er)
224902
+ }
224903
+
224904
+ // someone's got this one. see if it's valid.
224905
+ if (!opts.stale) return notStale(er, path, opts, cb)
224906
+
224907
+ return maybeStale(er, path, opts, false, cb)
224908
+ })
224909
+ debug('lock return')
224910
+ }
224911
+
224912
+
224913
+ // Staleness checking algorithm
224914
+ // 1. acquire $lock, fail
224915
+ // 2. stat $lock, find that it is stale
224916
+ // 3. acquire $lock.STALE
224917
+ // 4. stat $lock, assert that it is still stale
224918
+ // 5. unlink $lock
224919
+ // 6. link $lock.STALE $lock
224920
+ // 7. unlink $lock.STALE
224921
+ // On any failure, clean up whatever we've done, and raise the error.
224922
+ function maybeStale (originalEr, path, opts, hasStaleLock, cb) {
224923
+ fs.stat(path, function (statEr, st) {
224924
+ if (statEr) {
224925
+ if (statEr.code === 'ENOENT') {
224926
+ // expired already!
224927
+ opts.stale = false
224928
+ debug('lock stale enoent retry', path, opts)
224929
+ exports.lock(path, opts, cb)
224930
+ return
224931
+ }
224932
+ return cb(statEr)
224933
+ }
224934
+
224935
+ var age = Date.now() - st[exports.filetime].getTime()
224936
+ if (age <= opts.stale) return notStale(originalEr, path, opts, cb)
224937
+
224938
+ debug('lock stale', path, opts)
224939
+ if (hasStaleLock) {
224940
+ exports.unlock(path, function (er) {
224941
+ if (er) return cb(er)
224942
+ debug('lock stale retry', path, opts)
224943
+ fs.link(path + '.STALE', path, function (er) {
224944
+ fs.unlink(path + '.STALE', function () {
224945
+ // best effort. if the unlink fails, oh well.
224946
+ cb(er)
224947
+ })
224948
+ })
224949
+ })
224950
+ } else {
224951
+ debug('acquire .STALE file lock', opts)
224952
+ exports.lock(path + '.STALE', opts, function (er) {
224953
+ if (er) return cb(er)
224954
+ maybeStale(originalEr, path, opts, true, cb)
224955
+ })
224956
+ }
224957
+ })
224958
+ }
224959
+
224960
+ function notStale (er, path, opts, cb) {
224961
+ debug('notStale', path, opts)
224962
+
224963
+ // if we can't wait, then just call it a failure
224964
+ if (typeof opts.wait !== 'number' || opts.wait <= 0) {
224965
+ debug('notStale, wait is not a number')
224966
+ return cb(er)
224967
+ }
224968
+
224969
+ // poll for some ms for the lock to clear
224970
+ var now = Date.now()
224971
+ var start = opts.start || now
224972
+ var end = start + opts.wait
224973
+
224974
+ if (end <= now)
224975
+ return cb(er)
224976
+
224977
+ debug('now=%d, wait until %d (delta=%d)', start, end, end-start)
224978
+ var wait = Math.min(end - start, opts.pollPeriod || 100)
224979
+ var timer = setTimeout(poll, wait)
224980
+
224981
+ function poll () {
224982
+ debug('notStale, polling', path, opts)
224983
+ exports.lock(path, opts, cb)
224984
+ }
224985
+ }
224986
+
224987
+ exports.lockSync = function (path, opts) {
224988
+ opts = opts || {}
224989
+ opts.req = opts.req || req++
224990
+ debug('lockSync', path, opts)
224991
+ if (opts.wait || opts.retryWait) {
224992
+ throw new Error('opts.wait not supported sync for obvious reasons')
224993
+ }
224994
+
224995
+ try {
224996
+ var fd = fs.openSync(path, wx)
224997
+ locks[path] = fd
224998
+ try { fs.closeSync(fd) } catch (er) {}
224999
+ debug('locked sync!', path, fd)
225000
+ return
225001
+ } catch (er) {
225002
+ if (er.code !== 'EEXIST') return retryThrow(path, opts, er)
225003
+
225004
+ if (opts.stale) {
225005
+ var st = fs.statSync(path)
225006
+ var ct = st[exports.filetime].getTime()
225007
+ if (!(ct % 1000) && (opts.stale % 1000)) {
225008
+ // probably don't have subsecond resolution.
225009
+ // round up the staleness indicator.
225010
+ // Yes, this will be wrong 1/1000 times on platforms
225011
+ // with subsecond stat precision, but that's acceptable
225012
+ // in exchange for not mistakenly removing locks on
225013
+ // most other systems.
225014
+ opts.stale = 1000 * Math.ceil(opts.stale / 1000)
225015
+ }
225016
+ var age = Date.now() - ct
225017
+ if (age > opts.stale) {
225018
+ debug('lockSync stale', path, opts, age)
225019
+ exports.unlockSync(path)
225020
+ return exports.lockSync(path, opts)
225021
+ }
225022
+ }
225023
+
225024
+ // failed to lock!
225025
+ debug('failed to lock', path, opts, er)
225026
+ return retryThrow(path, opts, er)
225027
+ }
225028
+ }
225029
+
225030
+ function retryThrow (path, opts, er) {
225031
+ if (typeof opts.retries === 'number' && opts.retries > 0) {
225032
+ var newRT = opts.retries - 1
225033
+ debug('retryThrow', path, opts, newRT)
225034
+ opts.retries = newRT
225035
+ return exports.lockSync(path, opts)
225036
+ }
225037
+ throw er
225038
+ }
225039
+
225040
+
225041
+
224634
225042
  /***/ }),
224635
225043
 
224636
225044
  /***/ 80280: