@onereach/billing-shared 30.7.4-beta.12083.0 → 30.7.4-beta.12084.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onereach/billing-shared",
3
- "version": "30.7.4-beta.12083.0",
3
+ "version": "30.7.4-beta.12084.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,5 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { resolve, dirname } from 'node:path';
4
4
  import { fileURLToPath } from 'node:url';
5
5
 
@@ -8,84 +8,32 @@ const __dirname = dirname(__filename);
8
8
 
9
9
  const lockDir = '/tmp/shared-esm-build.lock';
10
10
  const pidFile = resolve(lockDir, 'pid');
11
- let ownsLock = false;
12
- const startupDeadline = Date.now() + 1000;
13
11
 
14
12
  const isAlive = (pid) => { try { process.kill(pid, 0);return true; } catch { return false; } };
15
- const reclaimLock = () => {
16
- const staleLockDir = `${lockDir}.stale-${process.pid}-${Date.now()}`;
17
- try {
18
- renameSync(lockDir, staleLockDir);
19
- } catch (error) {
20
- if (error.code === 'ENOENT') return;
21
- throw error;
22
- }
23
- rmSync(staleLockDir, {
24
- recursive: true,
25
- force: true,
26
- });
27
- };
28
- while (!ownsLock) {
29
- try {
30
- mkdirSync(lockDir);
31
- ownsLock = true;
32
- } catch (error) {
33
- if (error.code !== 'EEXIST') throw error;
34
-
35
- let oldPid = NaN;
36
- // eslint-disable-next-line no-empty
37
- try { oldPid = Number(readFileSync(pidFile, 'utf8').trim()); } catch {}
38
- if (!Number.isNaN(oldPid) && isAlive(oldPid)) {
39
- // eslint-disable-next-line no-console
40
- console.log(`shared already running (pid=${oldPid})`);
41
- process.exit(0);
42
- }
43
-
44
- if (Number.isNaN(oldPid)) {
45
- if (Date.now() < startupDeadline) {
46
- await new Promise(resolve => { setTimeout(resolve, 25); });
47
- continue;
48
- }
49
-
50
- reclaimLock();
51
- continue;
52
- }
53
-
54
- reclaimLock();
55
- }
13
+ if (!existsSync(lockDir)) mkdirSync(lockDir, { recursive: true });
14
+
15
+ let oldPid = NaN;
16
+ // eslint-disable-next-line no-empty
17
+ try { oldPid = Number(readFileSync(pidFile, 'utf8').trim()); } catch {}
18
+ if (!Number.isNaN(oldPid) && isAlive(oldPid)) {
19
+ // eslint-disable-next-line no-console
20
+ console.log(`shared already run (pid=${oldPid})`);
21
+ process.exit(0);
56
22
  }
57
23
 
58
24
  writeFileSync(pidFile, String(process.pid), 'utf8');
59
- const cleanup = () => {
60
- if (!ownsLock) return;
61
- ownsLock = false;
62
- rmSync(lockDir, {
63
- recursive: true,
64
- force: true,
65
- });
66
- };
25
+ // eslint-disable-next-line no-empty
26
+ const cleanup = () => { try { rmSync(pidFile, { force: true }); } catch {} };
67
27
  process.on('exit', cleanup);
28
+ process.on('SIGINT', () => { cleanup();process.exit(130); });
29
+ process.on('SIGTERM', () => { cleanup();process.exit(143); });
68
30
 
69
31
  const child = spawn('pnpm', ['build:watch:esm'], {
70
32
  stdio: 'inherit',
71
33
  cwd: resolve(__dirname, '..'),
72
34
  });
73
-
74
- let shuttingDown = false;
75
- const shutdown = (signal) => {
76
- if (shuttingDown) return;
77
- shuttingDown = true;
78
- child.kill(signal);
79
- };
80
- process.on('SIGINT', () => shutdown('SIGINT'));
81
- process.on('SIGTERM', () => shutdown('SIGTERM'));
82
-
83
35
  child.on('exit', (code, signal) => {
84
36
  cleanup();
85
- if (signal) {
86
- process.removeAllListeners(signal);
87
- process.kill(process.pid, signal);
88
- return;
89
- }
37
+ if (signal) process.kill(process.pid, signal);
90
38
  process.exit(code ?? 0);
91
39
  });