Skip to content

Commit 78591b0

Browse files
committed
fix: @putout/plugin-filesystem: convert to ESM
1 parent 419b652 commit 78591b0

Some content is hidden

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

63 files changed

+315
-322
lines changed

packages/plugin-filesystem/.putout.json

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
{
2+
"rules": {
3+
"putout/apply-exports": ["on", {
4+
"renameFileByMask": [
5+
"report",
6+
"fix",
7+
"scan"
8+
],
9+
"createRemoveFiles": [
10+
"report",
11+
"fix",
12+
"scan"
13+
]
14+
}]
15+
},
216
"match": {
317
"*.md": {
418
"putout-config/remove-empty": "off"

packages/plugin-filesystem/lib/bundle/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
'use strict';
1+
import {basename} from 'node:path';
2+
import {operator} from 'putout';
23

3-
const {basename} = require('node:path');
4-
const {operator} = require('putout');
54
const id = (a) => a;
65

76
const {
@@ -18,8 +17,8 @@ const maybeArray = (a) => isArray(a) ? a : [a];
1817
const {entries} = Object;
1918
const {isArray} = Array;
2019

21-
module.exports.report = () => `Minify css`;
22-
module.exports.fix = (rootPath, {dist, fileGroups}) => {
20+
export const report = () => `Minify css`;
21+
export const fix = (rootPath, {dist, fileGroups}) => {
2322
const distDirectory = createDirectory(rootPath, dist);
2423

2524
for (const [name, content] of entries(fileGroups)) {
@@ -46,7 +45,7 @@ const mark = (a) => a.__putout_filesystem_processed = true;
4645
const isMarked = (a) => a.__putout_filesystem_processed;
4746
const process = (file, transform, config) => transform(readFileContent(file), config);
4847

49-
module.exports.scan = (rootPath, {push, options}) => {
48+
export const scan = (rootPath, {push, options}) => {
5049
const {
5150
transform = id,
5251
groups = [],

packages/plugin-filesystem/lib/bundle/index.spec.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
'use strict';
1+
import tryCatch from 'try-catch';
2+
import {createTest} from '@putout/test';
3+
import {minify} from './minify.spec.js';
4+
import * as plugin from './index.js';
25

3-
const tryCatch = require('try-catch');
4-
const {createTest} = require('@putout/test');
5-
6-
const {minify} = require('./minify.spec');
7-
const plugin = require('.');
8-
9-
const test = createTest(__dirname, {
6+
const test = createTest(import.meta.url, {
107
plugins: [
118
['bundle-css', plugin],
129
],

packages/plugin-filesystem/lib/bundle/minify.spec.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
1+
import Clean from 'clean-css';
22

3-
const Clean = require('clean-css');
4-
5-
module.exports.minify = (data, config) => {
3+
export const minify = (data, config) => {
64
const {
75
styles,
86
errors,

packages/plugin-filesystem/lib/convert-filesystem-to-simple-filesystem/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.cjs';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-filesystem-to-simple-filesystem', plugin],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {__json} = operator;
54

6-
module.exports.report = () => `Convert '*.js' to '*.json'`;
5+
export const report = () => `Convert '*.js' to '*.json'`;
76

8-
module.exports.replace = () => ({
7+
export const replace = () => ({
98
'export default __object': __json,
109
'module.exports = __object': __json,
1110
});

packages/plugin-filesystem/lib/convert-js-to-json/convert/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert', plugin],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
'use strict';
1+
import {operator} from 'putout';
2+
import * as convert from './convert/index.js';
23

3-
const {matchFiles} = require('putout').operator;
4-
const convert = require('./convert');
5-
6-
module.exports = matchFiles({
4+
const {matchFiles} = operator;
5+
const {
6+
report,
7+
fix,
8+
scan,
9+
} = matchFiles({
710
'__name.js -> __name.json': convert,
811
});
12+
13+
export {
14+
report,
15+
fix,
16+
scan,
17+
};

packages/plugin-filesystem/lib/convert-js-to-json/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-js-to-json', plugin],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {__json} = operator;
54

6-
module.exports.report = () => `Convert '*.json' to '*.js'`;
5+
export const report = () => `Convert '*.json' to '*.js'`;
76

8-
module.exports.replace = () => ({
7+
export const replace = () => ({
98
[__json]: 'export default __object',
109
});

packages/plugin-filesystem/lib/convert-json-to-js/convert/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert', plugin],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
'use strict';
1+
import {operator} from 'putout';
2+
import * as convert from './convert/index.js';
23

3-
const {matchFiles} = require('putout').operator;
4-
const convert = require('./convert');
5-
6-
module.exports = matchFiles({
4+
const {matchFiles} = operator;
5+
const {
6+
report,
7+
fix,
8+
scan,
9+
} = matchFiles({
710
'__name.json -> __name.js': convert,
811
});
12+
13+
export {
14+
report,
15+
fix,
16+
scan,
17+
};

packages/plugin-filesystem/lib/convert-json-to-js/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-json-to-js', plugin],
97
],

packages/plugin-filesystem/lib/convert-simple-filesystem-to-filesystem/index.spec.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
'use strict';
2-
3-
const tryCatch = require('try-catch');
4-
const {createTest} = require('@putout/test');
5-
const plugin = require('.');
1+
import tryCatch from 'try-catch';
2+
import {createTest} from '@putout/test';
3+
import * as plugin from './index.cjs';
64

75
const CHECK_ASSERTIONS_COUNT = {
86
checkAssertionsCount: false,
97
};
108

11-
const test = createTest(__dirname, {
9+
const test = createTest(import.meta.url, {
1210
plugins: [
1311
['convert-simple-filesystem-to-filesystem', plugin],
1412
],

packages/plugin-filesystem/lib/create-remove-files.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {isArray} = Array;
54
const maybeArray = (a) => isArray(a) ? a : [a];
65
const {removeFile, getFilename} = operator;
@@ -11,7 +10,7 @@ const fix = (file) => {
1110
removeFile(file);
1211
};
1312

14-
module.exports.createRemoveFiles = (defaultNames) => ({
13+
export const createRemoveFiles = (defaultNames) => ({
1514
report,
1615
fix,
1716
scan: createScan(defaultNames),

packages/plugin-filesystem/lib/index.js

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
'use strict';
1+
import * as renameFile from './rename-file/index.js';
2+
import * as removeFiles from './remove-files/index.js';
3+
import * as removeVimSwapFile from './remove-vim-swap-file/index.js';
4+
import * as renameSpecToTest from './rename-spec-to-test/index.js';
5+
import * as renameTestToSpec from './rename-test-to-spec/index.js';
6+
import * as renameReferencedFile from './rename-referenced-file/index.js';
7+
import * as moveReferencedFile from './move-referenced-file/index.js';
8+
import * as convertSimpleFilesystemToFilesystem from './convert-simple-filesystem-to-filesystem/index.cjs';
9+
import * as convertFilesystemToSimpleFilesystem from './convert-filesystem-to-simple-filesystem/index.cjs';
10+
import * as convertJsonToJs from './convert-json-to-js/index.js';
11+
import * as bundle from './bundle/index.js';
12+
import * as replaceCwd from './replace-cwd/index.js';
13+
import * as readAllFiles from './read-all-files/index.js';
14+
import * as writeAllFiles from './write-all-files/index.js';
15+
import * as convertJsToJson from './convert-js-to-json/index.js';
16+
import * as removeNycOutputFiles from './remove-nyc-output-files/index.js';
17+
import * as removeTravisYmlFile from './remove-travis-yml-file/index.js';
18+
import * as removeEmptyDirectory from './remove-empty-directory/index.js';
219

3-
const renameFile = require('./rename-file');
4-
const removeFiles = require('./remove-files');
5-
const removeVimSwapFile = require('./remove-vim-swap-file');
6-
const renameSpecToTest = require('./rename-spec-to-test');
7-
const renameTestToSpec = require('./rename-test-to-spec');
8-
const renameReferencedFile = require('./rename-referenced-file');
9-
const moveReferencedFile = require('./move-referenced-file');
10-
const convertSimpleFilesystemToFilesystem = require('./convert-simple-filesystem-to-filesystem');
11-
const convertFilesystemToSimpleFilesystem = require('./convert-filesystem-to-simple-filesystem');
12-
const convertJsonToJs = require('./convert-json-to-js');
13-
const bundle = require('./bundle');
14-
const replaceCwd = require('./replace-cwd');
15-
const readAllFiles = require('./read-all-files');
16-
const writeAllFiles = require('./write-all-files');
17-
const convertJsToJson = require('./convert-js-to-json');
18-
const removeNycOutputFiles = require('./remove-nyc-output-files');
19-
const removeTravisYmlFile = require('./remove-travis-yml-file');
20-
const removeEmptyDirectory = require('./remove-empty-directory');
21-
22-
module.exports.rules = {
20+
export const rules = {
2321
'remove-vim-swap-file': removeVimSwapFile,
2422
'remove-files': ['off', removeFiles],
2523
'rename-file': ['off', renameFile],

packages/plugin-filesystem/lib/move-referenced-file/index.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
'use strict';
2-
3-
const {
1+
import {
42
join,
53
dirname,
64
relative,
75
basename,
8-
} = require('node:path');
9-
10-
const {
6+
} from 'node:path';
7+
import {
118
operator,
129
parse,
1310
transform,
1411
print,
15-
} = require('putout');
12+
} from 'putout';
1613

1714
const {
1815
readFileContent,
@@ -52,9 +49,9 @@ const getImportsPlugin = {
5249
}),
5350
};
5451

55-
module.exports.report = (file, {mainFilename, nextName}) => `Move '${mainFilename}' to '${nextName}'`;
52+
export const report = (file, {mainFilename, nextName}) => `Move '${mainFilename}' to '${nextName}'`;
5653

57-
module.exports.fix = (file, {cwd, nextName, mainFile, mainDirectory, mainFilename, ast, content}) => {
54+
export const fix = (file, {cwd, nextName, mainFile, mainDirectory, mainFilename, ast, content}) => {
5855
moveFile(mainFile, mainDirectory);
5956

6057
transform(ast, content, {
@@ -74,7 +71,7 @@ module.exports.fix = (file, {cwd, nextName, mainFile, mainDirectory, mainFilenam
7471
writeFileContent(file, code);
7572
};
7673

77-
module.exports.scan = (path, {push, options}) => {
74+
export const scan = (path, {push, options}) => {
7875
const {name, directory} = options;
7976

8077
if (!name || !directory)

packages/plugin-filesystem/lib/move-referenced-file/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['move-referenced-file', plugin],
97
],

packages/plugin-filesystem/lib/read-all-files/index.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {readFileContent} = operator;
54

6-
module.exports.report = () => `Read all files`;
5+
export const report = () => `Read all files`;
76

8-
module.exports.fix = (file) => {
7+
export const fix = (file) => {
98
readFileContent(file);
109
};
1110

12-
module.exports.scan = (root, {push, options, trackFile}) => {
11+
export const scan = (root, {push, options, trackFile}) => {
1312
const {mask = '*'} = options;
1413

1514
for (const file of trackFile(root, mask)) {

packages/plugin-filesystem/lib/read-all-files/index.spec.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['read-all-files', plugin],
97
],

0 commit comments

Comments
 (0)