Skip to content

Commit 16b7902

Browse files
author
snip-cli
committed
chore: fixed edit function in cli and Delete numerous miscellaneous files from the node_modules directory.
1 parent e834499 commit 16b7902

File tree

4,800 files changed

+396
-467079
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,800 files changed

+396
-467079
lines changed

STRATEGY.md

Lines changed: 370 additions & 0 deletions
Large diffs are not rendered by default.

__tests__/rm_edit.test.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1+
const fs = require('fs');
2+
const os = require('os');
3+
const path = require('path');
14
const storage = require('../lib/storage');
25
const cfg = require('../lib/config');
36
const editCmd = require('../lib/commands/edit');
47
const rmCmd = require('../lib/commands/rm');
58

69
describe('edit and rm', () => {
7-
test('edit updates updatedAt and rm removes snippet', () => {
10+
test('edit detects no-change with noop editor, and rm removes snippet', () => {
811
const s = storage.addSnippet({ name: 'editrm', content: 'before', language: 'txt', tags: [] });
9-
const before = s.updatedAt;
10-
cfg.saveConfig({ editor: 'true' }); // use shell `true` as noop editor
12+
cfg.saveConfig({ editor: 'true' }); // noop editor — file unchanged
1113
editCmd(s.id);
12-
const updated = storage.getSnippetByIdOrName(s.id);
13-
expect(updated.updatedAt).not.toBe(before);
14+
// Content unchanged → updatedAt should NOT change
15+
const unchanged = storage.getSnippetByIdOrName(s.id);
16+
expect(unchanged.updatedAt).toBe(s.updatedAt);
1417
rmCmd(s.id);
1518
const after = storage.getSnippetByIdOrName(s.id);
1619
expect(after).toBeNull();
1720
});
21+
22+
test('edit updates content when file changes', () => {
23+
const s = storage.addSnippet({ name: 'editchange', content: 'original', language: 'txt', tags: [] });
24+
// Directly update the content via storage to simulate an edit
25+
storage.updateSnippetContent(s.id, 'modified');
26+
const updated = storage.getSnippetByIdOrName(s.id);
27+
expect(updated.updatedAt).not.toBe(s.updatedAt);
28+
// Cleanup
29+
rmCmd(s.id);
30+
});
1831
});

lib/commands/edit.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ function edit(idOrName) {
99
const s = storage.getSnippetByIdOrName(idOrName);
1010
if (!s) return console.error('Snippet not found');
1111
const content = storage.readSnippetContent(s);
12-
const editor = (config.loadConfig().editor || 'vi').split(' ');
12+
const editor = (config.loadConfig().editor || process.env.EDITOR || 'vi').split(' ');
1313
const fileToEdit = s.path || path.join(os.tmpdir(), `snip-edit-${s.id}.tmp`);
1414
if (!s.path) fs.writeFileSync(fileToEdit, content, 'utf8');
1515
spawnSync(editor[0], editor.slice(1).concat([fileToEdit]), { stdio: 'inherit' });
1616
const newContent = fs.readFileSync(fileToEdit, 'utf8');
17-
if (!s.path) fs.unlinkSync(fileToEdit);
18-
storage.updateSnippetContent(s.id, newContent);
19-
console.log('Updated', s.id);
17+
if (!s.path) try { fs.unlinkSync(fileToEdit); } catch (e) { }
18+
if (newContent !== content) {
19+
storage.updateSnippetContent(s.id, newContent);
20+
console.log(`Updated "${s.name}"`);
21+
} else {
22+
console.log('No changes.');
23+
}
2024
}
2125

2226
module.exports = edit;

node_modules/.bin/baseline-browser-mapping

Lines changed: 0 additions & 1 deletion
This file was deleted.

node_modules/.bin/browserslist

Lines changed: 0 additions & 1 deletion
This file was deleted.

node_modules/.bin/create-jest

Lines changed: 0 additions & 1 deletion
This file was deleted.

node_modules/.bin/esparse

Lines changed: 0 additions & 1 deletion
This file was deleted.

node_modules/.bin/esvalidate

Lines changed: 0 additions & 1 deletion
This file was deleted.

node_modules/.bin/import-local-fixture

Lines changed: 0 additions & 1 deletion
This file was deleted.

node_modules/.bin/jest

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)