Skip to content

Commit caa53bf

Browse files
committed
feature: @putout/operator-declare: migrate to ESM
1 parent f959d33 commit caa53bf

File tree

7 files changed

+32
-31
lines changed

7 files changed

+32
-31
lines changed

packages/operator-declare/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ npm i putout @putout/operator-declare
1616
If you want to create 🐊[**Putout**](https://github.com/coderaiser/putout) `plugin` that will declare variables according to your needs just:
1717

1818
```js
19-
const {operator} = require('putout');
19+
import {operator} from 'putout';
20+
2021
const {declare} = operator;
2122

22-
module.exports = declare({
23+
export const {
24+
report,
25+
include,
26+
fix,
27+
filter,
28+
} = declare({
2329
fs: `import fs from 'fs/promises'`,
2430
});
2531
```
@@ -32,7 +38,12 @@ When you need different declarations for `ESM` and `CommonJS` you can use:
3238
const {operator} = require('putout');
3339
const {declare} = operator;
3440

35-
module.exports = declare({
41+
export const {
42+
report,
43+
include,
44+
fix,
45+
filter,
46+
} = declare({
3647
fs: {
3748
esm: `import fs from 'fs/promises'`,
3849
comomnjs: `const fs = require('fs')`, // drop when not needed
File renamed without changes.

packages/operator-declare/lib/declare.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
'use strict';
2-
3-
const {template} = require('@putout/engine-parser');
4-
const {isESM, insertAfter} = require('@putout/operate');
5-
6-
const {compare} = require('@putout/compare');
7-
8-
const {types} = require('@putout/babel');
9-
10-
const {
1+
import {template} from '@putout/engine-parser';
2+
import {isESM, insertAfter} from '@putout/operate';
3+
import {compare} from '@putout/compare';
4+
import {types} from '@putout/babel';
5+
import {
116
addDeclarationForESLint,
127
checkDeclarationForESLint,
138
getModuleType,
149
setModuleType,
15-
} = require('./record');
10+
} from './record.js';
1611

1712
const {
1813
isImportDeclaration,
@@ -45,7 +40,7 @@ const TS_EXCLUDE = [
4540
'TSQualifiedName',
4641
];
4742

48-
module.exports.declare = (declarations) => ({
43+
export const declare = (declarations) => ({
4944
report,
5045
include,
5146
fix: fix(declarations),

packages/operator-declare/lib/declare.spec.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
'use strict';
2-
3-
const test = require('supertape');
4-
const putout = require('putout');
5-
const montag = require('montag');
6-
const nodejs = require('@putout/plugin-nodejs');
7-
8-
const {declare} = require('./declare.js');
1+
import test from 'supertape';
2+
import putout from 'putout';
3+
import montag from 'montag';
4+
import * as nodejs from '@putout/plugin-nodejs';
5+
import {declare} from './declare.js';
96

107
test('putout: operator: declare: declare', (t) => {
118
const declarations = {

packages/operator-declare/lib/record.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
'use strict';
2-
31
const prefix = '__putout_declare';
42
const getProgramParentPath = (path) => path.scope.getProgramParent().path;
53

64
const maybeInit = (a, b) => b[a] = b[a] || {};
75

8-
module.exports.checkDeclarationForESLint = (name, path) => {
6+
export const checkDeclarationForESLint = (name, path) => {
97
const programPath = getProgramParentPath(path);
108
maybeInit(prefix, programPath);
119

1210
return programPath[prefix][name];
1311
};
1412

15-
module.exports.addDeclarationForESLint = (name, path) => {
13+
export const addDeclarationForESLint = (name, path) => {
1614
const programPath = getProgramParentPath(path);
1715
maybeInit(prefix, programPath);
1816

1917
programPath[prefix][name] = true;
2018
};
2119

22-
module.exports.setModuleType = (type, path) => {
20+
export const setModuleType = (type, path) => {
2321
const programPath = getProgramParentPath(path);
2422
maybeInit(prefix, programPath);
2523

@@ -28,7 +26,7 @@ module.exports.setModuleType = (type, path) => {
2826
return type;
2927
};
3028

31-
module.exports.getModuleType = (path) => {
29+
export const getModuleType = (path) => {
3230
const programPath = getProgramParentPath(path);
3331
maybeInit(prefix, programPath);
3432

packages/operator-declare/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@putout/operator-declare",
33
"version": "15.0.1",
4-
"type": "commonjs",
4+
"type": "module",
55
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
66
"description": "🐊Putout operator adds ability to declare referenced variables that was not defined",
77
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/operator-declare#readme",
@@ -52,7 +52,7 @@
5252
},
5353
"license": "MIT",
5454
"engines": {
55-
"node": ">=20"
55+
"node": ">=22"
5656
},
5757
"publishConfig": {
5858
"access": "public"

0 commit comments

Comments
 (0)