atomically 2.0.2 → 2.0.4

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.
Files changed (33) hide show
  1. package/.nyc_output/09ad542c-5435-4970-ae9c-d3aca17cc8e0.json +1 -0
  2. package/.nyc_output/5c74a299-649e-4bcb-894e-d3d7bc61ba96.json +1 -0
  3. package/.nyc_output/aec5ef7b-c224-4fa5-a830-b12bd1873072.json +1 -0
  4. package/.nyc_output/e5566b61-47b7-4c05-8e8b-36c7f809df3e.json +1 -0
  5. package/.nyc_output/f6bca65a-d147-4d4d-9fbf-a307181ea52f.json +1 -0
  6. package/.nyc_output/processinfo/09ad542c-5435-4970-ae9c-d3aca17cc8e0.json +1 -0
  7. package/.nyc_output/processinfo/5c74a299-649e-4bcb-894e-d3d7bc61ba96.json +1 -0
  8. package/.nyc_output/processinfo/aec5ef7b-c224-4fa5-a830-b12bd1873072.json +1 -0
  9. package/.nyc_output/processinfo/e5566b61-47b7-4c05-8e8b-36c7f809df3e.json +1 -0
  10. package/.nyc_output/processinfo/f6bca65a-d147-4d4d-9fbf-a307181ea52f.json +1 -0
  11. package/.nyc_output/processinfo/index.json +1 -0
  12. package/dist/constants.d.ts +2 -2
  13. package/dist/constants.js +2 -2
  14. package/dist/index.d.ts +2 -2
  15. package/dist/index.js +25 -21
  16. package/dist/types.d.ts +0 -1
  17. package/dist/utils/lang.d.ts +2 -2
  18. package/dist/utils/scheduler.d.ts +1 -1
  19. package/dist/utils/temp.d.ts +1 -1
  20. package/dist/utils/temp.js +1 -1
  21. package/package.json +10 -9
  22. package/.editorconfig +0 -10
  23. package/src/constants.ts +0 -39
  24. package/src/index.ts +0 -330
  25. package/src/types.ts +0 -37
  26. package/src/utils/lang.ts +0 -34
  27. package/src/utils/scheduler.ts +0 -62
  28. package/src/utils/temp.ts +0 -102
  29. package/tasks/benchmark.js +0 -76
  30. package/test/basic.cjs +0 -508
  31. package/test/concurrency.cjs +0 -151
  32. package/test/integration.cjs +0 -289
  33. package/tsconfig.json +0 -3
@@ -1,289 +0,0 @@
1
- process.setMaxListeners(1000000);
2
-
3
- const fs = require('fs')
4
- const path = require('path')
5
- const {test} = require('tap')
6
- const rimraf = require('rimraf')
7
- const requireInject = require('require-inject')
8
-
9
- const workdir = path.join(__dirname, path.basename(__filename, '.cjs'))
10
- let testfiles = 0
11
- function tmpFile () {
12
- return path.join(workdir, 'test-' + (++testfiles))
13
- }
14
-
15
- function readFile (path) {
16
- return fs.readFileSync(path).toString()
17
- }
18
-
19
- function didWriteFileAtomic (t, expected, filename, data, options, callback) {
20
- if (options instanceof Function) {
21
- callback = options
22
- options = null
23
- }
24
- if (!options) options = {}
25
- const actual = {}
26
- const {writeFile: writeFileAtomic} = requireInject('./atomically.cjs', {
27
- fs: Object.assign({}, fs, {
28
- chown (filename, uid, gid, cb) {
29
- actual.uid = uid
30
- actual.gid = gid
31
- process.nextTick(cb)
32
- },
33
- stat (filename, cb) {
34
- fs.stat(filename, (err, stats) => {
35
- if (err) return cb(err)
36
- cb(null, Object.assign(stats, expected || {}))
37
- })
38
- }
39
- })
40
- })
41
- return writeFileAtomic(filename, data, options, err => {
42
- t.ok(true); // t.strictSame(actual, expected, 'ownership is as expected') //TODO: Turned off as it's implemented unreliably, preventing us from doing a safe optimization
43
- callback(err)
44
- })
45
- }
46
-
47
- function didWriteFileAtomicSync (t, expected, filename, data, options) {
48
- const actual = {}
49
- const {writeFileSync} = requireInject('./atomically.cjs', {
50
- fs: Object.assign({}, fs, {
51
- chownSync (filename, uid, gid) {
52
- actual.uid = uid
53
- actual.gid = gid
54
- },
55
- statSync (filename) {
56
- const stats = fs.statSync(filename)
57
- return Object.assign(stats, expected || {})
58
- }
59
- })
60
- })
61
- writeFileSync(filename, data, options)
62
- t.ok(true); // t.strictSame(actual, expected) //TODO: Turned off as it's implemented unreliably, preventing us from doing a safe optimization
63
- }
64
-
65
- function currentUser () {
66
- return {
67
- uid: process.getuid(),
68
- gid: process.getgid()
69
- }
70
- }
71
-
72
- test('setup', t => {
73
- rimraf.sync(workdir)
74
- fs.mkdirSync(workdir, {recursive: true})
75
- t.end()
76
- })
77
-
78
- test('writes simple file (async)', t => {
79
- t.plan(3)
80
- const file = tmpFile()
81
- didWriteFileAtomic(t, {}, file, '42', err => {
82
- t.error(err, 'no error')
83
- t.equal(readFile(file), '42', 'content ok')
84
- })
85
- })
86
-
87
- test('writes simple file with encoding (async)', t => {
88
- t.plan(3)
89
- const file = tmpFile()
90
- didWriteFileAtomic(t, {}, file, 'foo', 'utf16le', err => {
91
- t.error(err, 'no error')
92
- t.equal(readFile(file), 'f\u0000o\u0000o\u0000', 'content ok')
93
- })
94
- })
95
-
96
- test('writes buffers to simple file (async)', t => {
97
- t.plan(3)
98
- const file = tmpFile()
99
- didWriteFileAtomic(t, {}, file, Buffer.from('42'), err => {
100
- t.error(err, 'no error')
101
- t.equal(readFile(file), '42', 'content ok')
102
- })
103
- })
104
-
105
- test('writes undefined to simple file (async)', t => {
106
- t.plan(3)
107
- const file = tmpFile()
108
- didWriteFileAtomic(t, {}, file, undefined, err => {
109
- t.error(err, 'no error')
110
- t.equal(readFile(file), '', 'content ok')
111
- })
112
- })
113
-
114
- test('writes to symlinks without clobbering (async)', t => {
115
- t.plan(5)
116
- const file = tmpFile()
117
- const link = tmpFile()
118
- fs.writeFileSync(file, '42')
119
- fs.symlinkSync(file, link)
120
- didWriteFileAtomic(t, currentUser(), link, '43', err => {
121
- t.error(err, 'no error')
122
- t.equal(readFile(file), '43', 'target content ok')
123
- t.equal(readFile(link), '43', 'link content ok')
124
- t.ok(fs.lstatSync(link).isSymbolicLink(), 'link is link')
125
- })
126
- })
127
-
128
- test('runs chown on given file (async)', t => {
129
- const file = tmpFile()
130
- didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '42', { chown: { uid: 42, gid: 43 } }, err => {
131
- t.error(err, 'no error')
132
- t.equal(readFile(file), '42', 'content ok')
133
- t.end()
134
- })
135
- })
136
-
137
- test('writes simple file with no chown (async)', t => {
138
- t.plan(3)
139
- const file = tmpFile()
140
- didWriteFileAtomic(t, {}, file, '42', { chown: false }, err => {
141
- t.error(err, 'no error')
142
- t.equal(readFile(file), '42', 'content ok')
143
- t.end()
144
- })
145
- })
146
-
147
- test('runs chmod on given file (async)', t => {
148
- t.plan(5)
149
- const file = tmpFile()
150
- didWriteFileAtomic(t, {}, file, '42', { mode: parseInt('741', 8) }, err => {
151
- t.error(err, 'no error')
152
- const stat = fs.statSync(file)
153
- t.equal(stat.mode, parseInt('100741', 8))
154
- didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '23', { chown: { uid: 42, gid: 43 } }, err => {
155
- t.error(err, 'no error')
156
- })
157
- })
158
- })
159
-
160
- test('run chmod AND chown (async)', t => {
161
- t.plan(3)
162
- const file = tmpFile()
163
- didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '42', { mode: parseInt('741', 8), chown: { uid: 42, gid: 43 } }, err => {
164
- t.error(err, 'no error')
165
- const stat = fs.statSync(file)
166
- t.equal(stat.mode, parseInt('100741', 8))
167
- })
168
- })
169
-
170
- test('does not change chmod by default (async)', t => {
171
- t.plan(5)
172
- const file = tmpFile()
173
- didWriteFileAtomic(t, {}, file, '42', { mode: parseInt('741', 8) }, err => {
174
- t.error(err, 'no error')
175
-
176
- didWriteFileAtomic(t, currentUser(), file, '43', err => {
177
- t.error(err, 'no error')
178
- const stat = fs.statSync(file)
179
- t.equal(stat.mode, parseInt('100741', 8))
180
- })
181
- })
182
- })
183
-
184
- test('does not change chown by default (async)', t => {
185
- t.plan(6)
186
- const file = tmpFile()
187
- didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '42', { chown: { uid: 42, gid: 43 } }, _setModeOnly)
188
-
189
- function _setModeOnly (err) {
190
- t.error(err, 'no error')
191
-
192
- didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '43', { mode: parseInt('741', 8) }, _allDefault)
193
- }
194
-
195
- function _allDefault (err) {
196
- t.error(err, 'no error')
197
-
198
- didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '43', _noError)
199
- }
200
-
201
- function _noError (err) {
202
- t.error(err, 'no error')
203
- }
204
- })
205
-
206
- test('writes simple file (sync)', t => {
207
- t.plan(2)
208
- const file = tmpFile()
209
- didWriteFileAtomicSync(t, {}, file, '42')
210
- t.equal(readFile(file), '42')
211
- })
212
-
213
- test('writes simple file with encoding (sync)', t => {
214
- t.plan(2)
215
- const file = tmpFile()
216
- didWriteFileAtomicSync(t, {}, file, 'foo', 'utf16le')
217
- t.equal(readFile(file), 'f\u0000o\u0000o\u0000')
218
- })
219
-
220
- test('writes simple buffer file (sync)', t => {
221
- t.plan(2)
222
- const file = tmpFile()
223
- didWriteFileAtomicSync(t, {}, file, Buffer.from('42'))
224
- t.equal(readFile(file), '42')
225
- })
226
-
227
- test('writes undefined file (sync)', t => {
228
- t.plan(2)
229
- const file = tmpFile()
230
- didWriteFileAtomicSync(t, {}, file, undefined)
231
- t.equal(readFile(file), '')
232
- })
233
-
234
- test('writes to symlinks without clobbering (sync)', t => {
235
- t.plan(4)
236
- const file = tmpFile()
237
- const link = tmpFile()
238
- fs.writeFileSync(file, '42')
239
- fs.symlinkSync(file, link)
240
- didWriteFileAtomicSync(t, currentUser(), link, '43')
241
- t.equal(readFile(file), '43', 'target content ok')
242
- t.equal(readFile(link), '43', 'link content ok')
243
- t.ok(fs.lstatSync(link).isSymbolicLink(), 'link is link')
244
- })
245
-
246
- test('runs chown on given file (sync)', t => {
247
- t.plan(1)
248
- const file = tmpFile()
249
- didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '42', { chown: { uid: 42, gid: 43 } })
250
- })
251
-
252
- test('runs chmod on given file (sync)', t => {
253
- t.plan(3)
254
- const file = tmpFile()
255
- didWriteFileAtomicSync(t, {}, file, '42', { mode: parseInt('741', 8) })
256
- const stat = fs.statSync(file)
257
- t.equal(stat.mode, parseInt('100741', 8))
258
- didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '23', { chown: { uid: 42, gid: 43 } })
259
- })
260
-
261
- test('runs chown and chmod (sync)', t => {
262
- t.plan(2)
263
- const file = tmpFile()
264
- didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '42', { mode: parseInt('741', 8), chown: { uid: 42, gid: 43 } })
265
- const stat = fs.statSync(file)
266
- t.equal(stat.mode, parseInt('100741', 8))
267
- })
268
-
269
- test('does not change chmod by default (sync)', t => {
270
- t.plan(3)
271
- const file = tmpFile()
272
- didWriteFileAtomicSync(t, {}, file, '42', { mode: parseInt('741', 8) })
273
- didWriteFileAtomicSync(t, currentUser(), file, '43')
274
- const stat = fs.statSync(file)
275
- t.equal(stat.mode, parseInt('100741', 8))
276
- })
277
-
278
- test('does not change chown by default (sync)', t => {
279
- t.plan(3)
280
- const file = tmpFile()
281
- didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '42', { chown: { uid: 42, gid: 43 } })
282
- didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '43', { mode: parseInt('741', 8) })
283
- didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '44')
284
- })
285
-
286
- test('cleanup', t => {
287
- rimraf.sync(workdir)
288
- t.end()
289
- })
package/tsconfig.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "tsex/tsconfig.json"
3
- }