-
Notifications
You must be signed in to change notification settings - Fork 0
fix: ajuste no workflow para dist no npm #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { describe, it, expect, afterEach } from 'vitest'; | ||
| import { getCriticalSystemPaths, isCriticalSystemDirectory, isUserHomeDirectory } from '../safe-paths.js'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
|
|
||
| describe('safe-paths', () => { | ||
| const originalPlatform = process.platform; | ||
|
|
||
| afterEach(() => { | ||
| Object.defineProperty(process, 'platform', { | ||
| value: originalPlatform | ||
| }); | ||
| }); | ||
|
|
||
| describe('getCriticalSystemPaths', () => { | ||
| it('returns Windows paths on win32', () => { | ||
| Object.defineProperty(process, 'platform', { | ||
| value: 'win32' | ||
| }); | ||
|
|
||
| const paths = getCriticalSystemPaths(); | ||
|
|
||
| expect(paths).toContain('C:\\'); | ||
| expect(paths.some(p => p.includes('Windows'))).toBe(true); | ||
| expect(paths.some(p => p.includes('Program Files'))).toBe(true); | ||
| }); | ||
|
|
||
| it('returns macOS paths on darwin', () => { | ||
| Object.defineProperty(process, 'platform', { | ||
| value: 'darwin' | ||
| }); | ||
|
|
||
| const paths = getCriticalSystemPaths(); | ||
|
|
||
| expect(paths).toContain('/'); | ||
| expect(paths).toContain('/System'); | ||
| expect(paths).toContain('/Library'); | ||
| expect(paths).toContain('/Applications'); | ||
| }); | ||
|
|
||
| it('returns Linux paths on linux', () => { | ||
| Object.defineProperty(process, 'platform', { | ||
| value: 'linux' | ||
| }); | ||
|
|
||
| const paths = getCriticalSystemPaths(); | ||
|
|
||
| expect(paths).toContain('/'); | ||
| expect(paths).toContain('/usr'); | ||
| expect(paths).toContain('/etc'); | ||
| expect(paths).toContain('/var'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('isCriticalSystemDirectory', () => { | ||
| it('detects root directory as critical', () => { | ||
| const isRootCritical = isCriticalSystemDirectory('/'); | ||
| expect(isRootCritical).toBe(true); | ||
| }); | ||
|
|
||
| it('detects subdirectories of critical paths', () => { | ||
| if (process.platform === 'darwin' || process.platform === 'linux') { | ||
| expect(isCriticalSystemDirectory('/usr/local')).toBe(true); | ||
| expect(isCriticalSystemDirectory('/etc/config')).toBe(true); | ||
| } | ||
| }); | ||
|
|
||
| it('allows safe project directories', () => { | ||
| const homeDir = os.homedir(); | ||
| const projectDir = path.join(homeDir, 'projects', 'my-app'); | ||
|
|
||
| expect(isCriticalSystemDirectory(projectDir)).toBe(false); | ||
| }); | ||
|
|
||
| it('normalizes paths correctly', () => { | ||
| if (process.platform === 'darwin' || process.platform === 'linux') { | ||
| expect(isCriticalSystemDirectory('/usr/../usr')).toBe(true); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('isUserHomeDirectory', () => { | ||
| it('detects user home directory', () => { | ||
| const homeDir = os.homedir(); | ||
| expect(isUserHomeDirectory(homeDir)).toBe(true); | ||
| }); | ||
|
|
||
| it('allows subdirectories of home', () => { | ||
| const homeDir = os.homedir(); | ||
| const subDir = path.join(homeDir, 'projects'); | ||
|
|
||
| expect(isUserHomeDirectory(subDir)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('cross-platform compatibility', () => { | ||
| it('handles paths with different separators', () => { | ||
| const userDir = path.join(os.homedir(), 'projects', 'app'); | ||
|
|
||
| const result = isCriticalSystemDirectory(userDir); | ||
|
|
||
| expect(typeof result).toBe('boolean'); | ||
| }); | ||
|
|
||
| it('resolves relative paths', () => { | ||
| const relativePath = './some/project'; | ||
| const resolvedCheck = isCriticalSystemDirectory(relativePath); | ||
|
|
||
| expect(typeof resolvedCheck).toBe('boolean'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import path from 'node:path'; | ||
| import os from 'node:os'; | ||
|
|
||
| export function getCriticalSystemPaths(): string[] { | ||
| const platform = process.platform; | ||
|
|
||
| if (platform === 'win32') { | ||
| const systemRoot = process.env.SystemRoot || 'C:\\Windows'; | ||
| const programFiles = process.env['ProgramFiles'] || 'C:\\Program Files'; | ||
| const programFilesX86 = process.env['ProgramFiles(x86)'] || 'C:\\Program Files (x86)'; | ||
| const drives = ['C:\\', 'D:\\', 'E:\\']; | ||
|
|
||
| return [ | ||
| ...drives, | ||
| systemRoot, | ||
| path.join(systemRoot, 'System32'), | ||
| programFiles, | ||
| programFilesX86, | ||
| 'C:\\Windows', | ||
| 'C:\\Program Files', | ||
| 'C:\\Program Files (x86)' | ||
| ]; | ||
| } | ||
|
|
||
| if (platform === 'darwin') { | ||
| return [ | ||
| '/', | ||
| '/usr', | ||
| '/etc', | ||
| '/var', | ||
| '/System', | ||
| '/Library', | ||
| '/bin', | ||
| '/sbin', | ||
| '/opt', | ||
| '/private/etc', | ||
| '/private/var', | ||
| '/private/tmp', | ||
| '/Applications' | ||
| ]; | ||
| } | ||
|
|
||
| return [ | ||
| '/', | ||
| '/usr', | ||
| '/etc', | ||
| '/var', | ||
| '/bin', | ||
| '/sbin', | ||
| '/opt', | ||
| '/boot', | ||
| '/lib', | ||
| '/lib64', | ||
| '/sys', | ||
| '/proc', | ||
| '/dev', | ||
| '/root' | ||
| ]; | ||
| } | ||
|
|
||
| export function isCriticalSystemDirectory(targetPath: string): boolean { | ||
| const resolved = path.resolve(targetPath); | ||
| const criticalPaths = getCriticalSystemPaths(); | ||
|
|
||
| return criticalPaths.some(critical => { | ||
| const resolvedCritical = path.resolve(critical); | ||
|
|
||
| if (resolved === resolvedCritical) { | ||
| return true; | ||
| } | ||
|
|
||
| const normalizedResolved = resolved + path.sep; | ||
| const normalizedCritical = resolvedCritical + path.sep; | ||
|
|
||
| return normalizedResolved.startsWith(normalizedCritical); | ||
| }); | ||
| } | ||
|
|
||
| export function isUserHomeDirectory(targetPath: string): boolean { | ||
| const resolved = path.resolve(targetPath); | ||
| const homeDir = os.homedir(); | ||
|
|
||
| return resolved === homeDir; | ||
| } | ||
|
|
||
| export function getSafeInstallMessage(targetPath: string): string { | ||
| if (isUserHomeDirectory(targetPath)) { | ||
| return 'Installing in home directory is not recommended. Please run from a project directory.'; | ||
| } | ||
|
|
||
| if (isCriticalSystemDirectory(targetPath)) { | ||
| return 'Cannot install in critical system directory. Please run from a safe project directory.'; | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: POSIX Path Handling Fails on Windows
The critical system directory protection, which uses hardcoded POSIX paths, is ineffective on Windows. On Windows,
path.resolve('/')resolves to the current drive root, not the POSIX root, causing the check to fail and leaving critical Windows directories unprotected.Additional Locations (1)
apps/cli/src/commands/update.ts#L65-L81