@putout/operator-filesystem 10.0.1 → 10.0.2

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/lib/filesystem.js CHANGED
@@ -1,28 +1,22 @@
1
- 'use strict';
2
-
3
- const {
1
+ import {
4
2
  join,
5
3
  basename,
6
4
  dirname,
7
- } = require('node:path');
8
-
9
- const {types} = require('@putout/babel');
10
- const tryCatch = require('try-catch');
11
-
12
- const {
5
+ } from 'node:path';
6
+ import {types} from '@putout/babel';
7
+ import {tryCatch} from 'try-catch';
8
+ import {
13
9
  setLiteralValue,
14
10
  getProperty,
15
11
  traverseProperties,
16
- } = require('@putout/operate');
17
-
18
- const maybeFS = require('./maybe-fs');
19
-
20
- const {
12
+ } from '@putout/operate';
13
+ import * as maybeFS from './maybe-fs.js';
14
+ import {
21
15
  createTypeProperty,
22
16
  createFilesProperty,
23
17
  createFilenameProperty,
24
18
  createContentProperty,
25
- } = require('./property');
19
+ } from './property.js';
26
20
 
27
21
  const {
28
22
  isProgram,
@@ -63,9 +57,7 @@ const getRegExp = (wildcard) => {
63
57
  return RegExp(`^${escaped}$`);
64
58
  };
65
59
 
66
- module.exports.getParentDirectory = getParentDirectory;
67
-
68
- function getParentDirectory(filePath) {
60
+ export function getParentDirectory(filePath) {
69
61
  if (!filePath.parentPath)
70
62
  return null;
71
63
 
@@ -77,8 +69,6 @@ function getParentDirectory(filePath) {
77
69
  return parentPath;
78
70
  }
79
71
 
80
- module.exports.findFile = findFile;
81
-
82
72
  function isExcluded({name, base, exclude}) {
83
73
  for (const currentExclude of exclude) {
84
74
  if (name === currentExclude || getRegExp(currentExclude).test(base))
@@ -88,7 +78,7 @@ function isExcluded({name, base, exclude}) {
88
78
  return false;
89
79
  }
90
80
 
91
- function findFile(node, name, exclude = []) {
81
+ export function findFile(node, name, exclude = []) {
92
82
  checkName(name);
93
83
 
94
84
  const filePaths = [];
@@ -128,21 +118,17 @@ function getFilenamePath(filePath) {
128
118
  return filenamePath.get('value');
129
119
  }
130
120
 
131
- function getFilename(filePath) {
121
+ export function getFilename(filePath) {
132
122
  const {value} = getFilenamePath(filePath).node;
133
123
  return value;
134
124
  }
135
125
 
136
- module.exports.getFileType = getFileType;
137
-
138
- function getFileType(filePath) {
126
+ export function getFileType(filePath) {
139
127
  const typePath = getProperty(filePath, 'type');
140
128
  return typePath.node.value.value;
141
129
  }
142
130
 
143
- module.exports.getFileContent = getFileContent;
144
-
145
- function getFileContent(filePath) {
131
+ export function getFileContent(filePath) {
146
132
  const content = getProperty(filePath, 'content');
147
133
 
148
134
  return [
@@ -151,9 +137,7 @@ function getFileContent(filePath) {
151
137
  ];
152
138
  }
153
139
 
154
- module.exports.getFilename = getFilename;
155
-
156
- module.exports.renameFile = (filePath, name) => {
140
+ export const renameFile = (filePath, name) => {
157
141
  const oldName = getFilename(filePath);
158
142
  const valuePath = getFilenamePath(filePath);
159
143
  const baseName = oldName
@@ -170,8 +154,7 @@ module.exports.renameFile = (filePath, name) => {
170
154
  maybeFS.renameFile(oldName, newFilename);
171
155
  };
172
156
 
173
- module.exports.removeFile = removeFile;
174
- function removeFile(filePath) {
157
+ export function removeFile(filePath) {
175
158
  const filename = getFilename(filePath);
176
159
 
177
160
  if (!getParentDirectory(filePath))
@@ -181,7 +164,7 @@ function removeFile(filePath) {
181
164
  maybeFS.removeFile(filename);
182
165
  }
183
166
 
184
- module.exports.removeEmptyDirectory = (dirPath) => {
167
+ export const removeEmptyDirectory = (dirPath) => {
185
168
  const type = getFileType(dirPath);
186
169
 
187
170
  if (type !== 'directory')
@@ -205,7 +188,7 @@ module.exports.removeEmptyDirectory = (dirPath) => {
205
188
  }
206
189
  };
207
190
 
208
- module.exports.moveFile = (filePath, dirPath) => {
191
+ export const moveFile = (filePath, dirPath) => {
209
192
  if (filePath === dirPath)
210
193
  return;
211
194
 
@@ -229,7 +212,7 @@ module.exports.moveFile = (filePath, dirPath) => {
229
212
  maybeFS.renameFile(filename, newFilename);
230
213
  };
231
214
 
232
- module.exports.copyFile = (filePath, dirPath) => {
215
+ export const copyFile = (filePath, dirPath) => {
233
216
  const dirname = getFilename(dirPath);
234
217
  const filename = getFilename(filePath);
235
218
 
@@ -272,7 +255,7 @@ function maybeRemoveFile(dirPath, filename) {
272
255
  fileToOverwrite.remove();
273
256
  }
274
257
 
275
- module.exports.createFile = (dirPath, name, content) => {
258
+ export const createFile = (dirPath, name, content) => {
276
259
  maybeRemoveFile(dirPath, name);
277
260
 
278
261
  const dirPathFiles = getFiles(dirPath);
@@ -300,8 +283,7 @@ module.exports.createFile = (dirPath, name, content) => {
300
283
 
301
284
  const getFiles = (dirPath) => getProperty(dirPath, 'files');
302
285
 
303
- module.exports.readDirectory = readDirectory;
304
- function readDirectory(dirPath) {
286
+ export function readDirectory(dirPath) {
305
287
  const fileType = getFileType(dirPath);
306
288
 
307
289
  if (fileType !== 'directory')
@@ -310,9 +292,7 @@ function readDirectory(dirPath) {
310
292
  return getFiles(dirPath).get('value.elements');
311
293
  }
312
294
 
313
- module.exports.createDirectory = createDirectory;
314
-
315
- function createDirectory(dirPath, name) {
295
+ export function createDirectory(dirPath, name) {
316
296
  const dirPathFiles = getFiles(dirPath);
317
297
  const parentFilename = getFilename(dirPath);
318
298
  const filename = join(parentFilename, name);
@@ -332,7 +312,7 @@ function createDirectory(dirPath, name) {
332
312
  return dirPathFiles.get('value.elements').at(-1);
333
313
  }
334
314
 
335
- module.exports.readFileContent = (filePath) => {
315
+ export const readFileContent = (filePath) => {
336
316
  const fileType = getFileType(filePath);
337
317
 
338
318
  if (fileType === 'directory')
@@ -353,9 +333,7 @@ module.exports.readFileContent = (filePath) => {
353
333
  return fileContent;
354
334
  };
355
335
 
356
- module.exports.writeFileContent = writeFileContent;
357
-
358
- function writeFileContent(filePath, content) {
336
+ export function writeFileContent(filePath, content) {
359
337
  const fileType = getFileType(filePath);
360
338
 
361
339
  if (fileType === 'directory')
@@ -376,7 +354,7 @@ function writeFileContent(filePath, content) {
376
354
  filePath.node.properties.push(property);
377
355
  }
378
356
 
379
- module.exports.createNestedDirectory = (path, name) => {
357
+ export const createNestedDirectory = (path, name) => {
380
358
  const rootPath = getRootDirectory(path);
381
359
  const dir = dirname(name);
382
360
 
@@ -421,8 +399,7 @@ module.exports.createNestedDirectory = (path, name) => {
421
399
  return lastDirectoryPath;
422
400
  };
423
401
 
424
- module.exports.getRootDirectory = getRootDirectory;
425
- function getRootDirectory(path) {
402
+ export function getRootDirectory(path) {
426
403
  let currentDirPath = getParentDirectory(path);
427
404
 
428
405
  if (!currentDirPath)
@@ -437,8 +414,9 @@ function getRootDirectory(path) {
437
414
  return prevPath;
438
415
  }
439
416
 
440
- module.exports.init = maybeFS.init;
441
- module.exports.deinit = maybeFS.deinit;
442
-
443
- module.exports.pause = maybeFS.pause;
444
- module.exports.start = maybeFS.start;
417
+ export const {
418
+ init,
419
+ deinit,
420
+ pause,
421
+ start,
422
+ } = maybeFS;
package/lib/maybe-fs.js CHANGED
@@ -1,6 +1,5 @@
1
- 'use strict';
1
+ import fullstore from 'fullstore';
2
2
 
3
- const fullstore = require('fullstore');
4
3
  const driverStore = fullstore();
5
4
 
6
5
  const {assign} = Object;
@@ -18,47 +17,43 @@ const defaultFS = {
18
17
 
19
18
  const maybeFS = assign({}, defaultFS);
20
19
 
21
- module.exports.renameFile = (oldName, newName) => {
20
+ export const renameFile = (oldName, newName) => {
22
21
  maybeFS.renameFile(oldName, newName);
23
22
  };
24
23
 
25
- module.exports.removeFile = (name) => {
24
+ export const removeFile = (name) => {
26
25
  maybeFS.removeFile(name);
27
26
  };
28
27
 
29
- module.exports.copyFile = (from, to) => {
28
+ export const copyFile = (from, to) => {
30
29
  maybeFS.copyFile(from, to);
31
30
  };
32
31
 
33
- module.exports.createDirectory = (name) => {
32
+ export const createDirectory = (name) => {
34
33
  maybeFS.createDirectory(name);
35
34
  };
36
35
 
37
- module.exports.readFileContent = (name) => {
36
+ export const readFileContent = (name) => {
38
37
  return maybeFS.readFileContent(name);
39
38
  };
40
39
 
41
- module.exports.writeFileContent = (name, content) => {
40
+ export const writeFileContent = (name, content) => {
42
41
  maybeFS.writeFileContent(name, content);
43
42
  };
44
43
 
45
- module.exports.init = init;
46
-
47
- function init(fsDriver) {
44
+ export function init(fsDriver) {
48
45
  assign(maybeFS, fsDriver);
49
46
  }
50
47
 
51
- module.exports.pause = () => {
48
+ export const pause = () => {
52
49
  driverStore(maybeFS);
53
50
  deinit();
54
51
  };
55
52
 
56
- module.exports.start = () => {
53
+ export const start = () => {
57
54
  init(driverStore());
58
55
  };
59
56
 
60
- module.exports.deinit = deinit;
61
-
62
- function deinit() {
57
+ export function deinit() {
63
58
  assign(maybeFS, defaultFS);
64
59
  }
package/lib/property.js CHANGED
@@ -1,28 +1,27 @@
1
- 'use strict';
1
+ import {types} from '@putout/babel';
2
2
 
3
- const {types} = require('@putout/babel');
4
3
  const {
5
4
  arrayExpression,
6
5
  stringLiteral,
7
6
  objectProperty,
8
7
  } = types;
9
8
 
10
- module.exports.createTypeProperty = (type) => {
9
+ export const createTypeProperty = (type) => {
11
10
  const value = stringLiteral(type);
12
11
  return createProperty('type', value);
13
12
  };
14
13
 
15
- module.exports.createFilesProperty = (files) => {
14
+ export const createFilesProperty = (files) => {
16
15
  const value = arrayExpression(files);
17
16
  return createProperty('files', value);
18
17
  };
19
18
 
20
- module.exports.createFilenameProperty = (filename) => {
19
+ export const createFilenameProperty = (filename) => {
21
20
  const value = stringLiteral(filename);
22
21
  return createProperty('filename', value);
23
22
  };
24
23
 
25
- module.exports.createContentProperty = (content) => {
24
+ export const createContentProperty = (content) => {
26
25
  const value = stringLiteral(content);
27
26
  return createProperty('content', value);
28
27
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/operator-filesystem",
3
- "version": "10.0.1",
4
- "type": "commonjs",
3
+ "version": "10.0.2",
4
+ "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout operator adds ability to filesystem referenced variables that was not defined",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/operator-filesystem#readme",
@@ -39,22 +39,22 @@
39
39
  "@putout/engine-parser": "^15.0.1",
40
40
  "@putout/eslint-flat": "^3.0.0",
41
41
  "@putout/operator-json": "^2.0.0",
42
- "@putout/test": "^14.0.0",
42
+ "@putout/test": "^15.0.0",
43
43
  "c8": "^10.0.0",
44
44
  "eslint": "^10.0.0-alpha.0",
45
45
  "eslint-plugin-n": "^17.0.0",
46
46
  "eslint-plugin-putout": "^29.0.0",
47
- "madrun": "^11.0.0",
47
+ "madrun": "^12.0.0",
48
48
  "montag": "^1.2.1",
49
49
  "nodemon": "^3.0.1",
50
- "supertape": "^11.0.3"
50
+ "supertape": "^12.0.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "putout": ">=41"
54
54
  },
55
55
  "license": "MIT",
56
56
  "engines": {
57
- "node": ">=20"
57
+ "node": ">=22"
58
58
  },
59
59
  "publishConfig": {
60
60
  "access": "public"