@take-out/scripts 0.0.35 → 0.0.37

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": "@take-out/scripts",
3
- "version": "0.0.35",
3
+ "version": "0.0.37",
4
4
  "type": "module",
5
5
  "main": "./src/index.ts",
6
6
  "sideEffects": false,
@@ -24,7 +24,7 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "@take-out/helpers": "0.0.35"
27
+ "@take-out/helpers": "0.0.37"
28
28
  },
29
29
  "devDependencies": {
30
30
  "vxrn": "*"
package/src/clean.ts CHANGED
@@ -4,12 +4,26 @@
4
4
  * @description Clean build artifacts and temporary files
5
5
  */
6
6
 
7
- import { execSync } from 'node:child_process'
8
-
9
- try {
10
- execSync('rm -rf dist types .tamagui .vite node_modules/.cache', { stdio: 'inherit' })
11
- console.info('Cleanup complete!')
12
- } catch (error) {
13
- console.error('Error cleaning up')
14
- throw error
7
+ import { $ } from 'bun'
8
+
9
+ const full = process.argv.includes('--full')
10
+ const modules = full || process.argv.includes('--modules')
11
+ const native = full || process.argv.includes('--native')
12
+
13
+ await $`rm -rf dist types .tamagui .vite node_modules/.cache`
14
+
15
+ if (modules) {
16
+ console.info('removing all node_modules...')
17
+ await $`find . -name 'node_modules' -type d -prune -exec rm -rf {} +`
18
+ }
19
+
20
+ if (native) {
21
+ console.info('removing ios and android folders...')
22
+ await $`rm -rf ios android`
23
+ }
24
+
25
+ console.info('cleanup complete!')
26
+
27
+ if (!full) {
28
+ console.info('use --modules, --native, or --full for deeper cleaning')
15
29
  }
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env bun
2
+
3
+ /**
4
+ * @description Ensure a port is available, exit with error if in use
5
+ * @args --auto-kill <prefix>
6
+ */
7
+
8
+ import { execSync } from 'node:child_process'
9
+ import { parseArgs } from 'node:util'
10
+
11
+ const { values, positionals } = parseArgs({
12
+ args: process.argv.slice(2),
13
+ options: {
14
+ 'auto-kill': {
15
+ type: 'string',
16
+ short: 'k',
17
+ },
18
+ },
19
+ allowPositionals: true,
20
+ })
21
+
22
+ const port = positionals[0]
23
+
24
+ if (!port) {
25
+ console.error('usage: bun tko ensure-port <port> [--auto-kill <prefix>]')
26
+ process.exit(1)
27
+ }
28
+
29
+ const portNum = Number.parseInt(port, 10)
30
+
31
+ if (Number.isNaN(portNum) || portNum < 1 || portNum > 65535) {
32
+ console.error(`invalid port: ${port}`)
33
+ process.exit(1)
34
+ }
35
+
36
+ function getListeningProcess(p: number): { pid?: number; command?: string } {
37
+ try {
38
+ // use -sTCP:LISTEN to only find processes LISTENING on the port (servers)
39
+ // not clients connected to it
40
+ const output = execSync(`lsof -i :${p} -sTCP:LISTEN -t`, {
41
+ encoding: 'utf-8',
42
+ stdio: ['pipe', 'pipe', 'ignore'],
43
+ }).trim()
44
+
45
+ if (!output) return {}
46
+
47
+ const pid = Number.parseInt(output.split('\n')[0] || '', 10)
48
+ if (Number.isNaN(pid)) return {}
49
+
50
+ // get command name
51
+ const ps = execSync(`ps -p ${pid} -o comm=`, {
52
+ encoding: 'utf-8',
53
+ stdio: ['pipe', 'pipe', 'ignore'],
54
+ }).trim()
55
+
56
+ return { pid, command: ps }
57
+ } catch {
58
+ return {}
59
+ }
60
+ }
61
+
62
+ function killProcess(pid: number): boolean {
63
+ try {
64
+ execSync(`kill ${pid}`, { stdio: 'ignore' })
65
+ return true
66
+ } catch {
67
+ return false
68
+ }
69
+ }
70
+
71
+ const { pid, command } = getListeningProcess(portNum)
72
+
73
+ if (pid) {
74
+ const autoKillPrefix = values['auto-kill']
75
+
76
+ // check if we should auto-kill this process
77
+ if (autoKillPrefix && command?.startsWith(autoKillPrefix)) {
78
+ console.info(`killing ${command} (pid ${pid}) on port ${portNum}`)
79
+ if (killProcess(pid)) {
80
+ // give it a moment to release the port
81
+ Bun.sleepSync(100)
82
+ // verify it's gone
83
+ const check = getListeningProcess(portNum)
84
+ if (!check.pid) {
85
+ process.exit(0)
86
+ }
87
+ console.error(`failed to free port ${portNum}`)
88
+ process.exit(1)
89
+ }
90
+ console.error(`failed to kill pid ${pid}`)
91
+ process.exit(1)
92
+ }
93
+
94
+ console.error(`port ${portNum} in use by ${command || 'unknown'} (pid ${pid})`)
95
+ console.error(`run: kill ${pid}`)
96
+ process.exit(1)
97
+ }
@@ -10,17 +10,26 @@ export async function getTestEnv() {
10
10
  const dockerHost = getDockerHost()
11
11
  const serverEnvFallback = await import(join(process.cwd(), 'src/server/env-server'))
12
12
 
13
+ // explicit URLs required since vxrn loadEnv doesn't override existing env vars
14
+ const dockerDbBase = `postgresql://user:password@127.0.0.1:5433`
15
+
13
16
  return {
14
17
  ...serverEnvFallback,
15
18
  ...devEnv,
16
- CI: 'true', // Ensure CI flag is set for test environment
19
+ CI: 'true',
17
20
  ...(!process.env.DEBUG_BACKEND && {
18
21
  ZERO_LOG_LEVEL: 'warn',
19
22
  }),
20
23
  DO_NOT_TRACK: '1',
21
24
  ZERO_VERSION: zeroVersion,
22
- ZERO_AUTH_JWKS_URL: `http://${dockerHost}:8081/api/auth/jwks`,
23
- ZERO_PUSH_URL: `http://${dockerHost}:8081/api/zero/push`,
24
- ZERO_GET_QUERIES_URL: `http://${dockerHost}:8081/api/zero/pull`,
25
+ ZERO_MUTATE_URL: `http://${dockerHost}:8081/api/zero/push`,
26
+ ZERO_QUERY_URL: `http://${dockerHost}:8081/api/zero/pull`,
27
+ ZERO_UPSTREAM_DB: `${dockerDbBase}/postgres`,
28
+ ZERO_CVR_DB: `${dockerDbBase}/zero_cvr`,
29
+ ZERO_CHANGE_DB: `${dockerDbBase}/zero_cdb`,
30
+ CLOUDFLARE_R2_ENDPOINT: 'http://127.0.0.1:9200',
31
+ CLOUDFLARE_R2_PUBLIC_URL: 'http://127.0.0.1:9200',
32
+ CLOUDFLARE_R2_ACCESS_KEY: 'minio',
33
+ CLOUDFLARE_R2_SECRET_KEY: 'minio_password',
25
34
  }
26
35
  }
package/src/run.ts CHANGED
@@ -137,8 +137,10 @@ async function findWorkspaceDirectories(): Promise<string[]> {
137
137
 
138
138
  const allPackageDirs = await findPackageJsonDirs('.')
139
139
 
140
- const normalizePattern = (pattern: string): string => {
141
- return pattern.startsWith('./') ? pattern.substring(2) : pattern
140
+ // normalize path separators to forward slashes for cross-platform support
141
+ const normalizePath = (path: string): string => {
142
+ let normalized = path.replace(/\\/g, '/')
143
+ return normalized.startsWith('./') ? normalized.substring(2) : normalized
142
144
  }
143
145
 
144
146
  const workspaceDirs = allPackageDirs.filter((dir) => {
@@ -146,8 +148,8 @@ async function findWorkspaceDirectories(): Promise<string[]> {
146
148
 
147
149
  const relativePath = relative('.', dir)
148
150
  return patterns.some((pattern) => {
149
- const normalizedPattern = normalizePattern(pattern)
150
- const normalizedPath = normalizePattern(relativePath)
151
+ const normalizedPattern = normalizePath(pattern)
152
+ const normalizedPath = normalizePath(relativePath)
151
153
 
152
154
  if (normalizedPattern.endsWith('/*')) {
153
155
  const prefix = normalizedPattern.slice(0, -1)
package/src/typecheck.ts CHANGED
@@ -18,5 +18,5 @@ if (process.env.LAZY_TYPECHECK) {
18
18
  if (useTsgo) {
19
19
  await run(`bun tsgo --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
20
20
  } else {
21
- await run(`bun x tsc --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
21
+ await run(`bun tsc --project ./tsconfig.json --noEmit --preserveWatchOutput ${args}`)
22
22
  }
package/tsconfig.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "extends": "../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "outDir": "./dist"
4
+ "outDir": "./dist",
5
+ "moduleDetection": "force"
5
6
  },
6
7
  "include": ["./src/**/*"],
7
8
  "exclude": ["**/test", "**/__tests__", "dist", "node_modules"]