redlint 3.12.0 → 3.12.1
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/ChangeLog +8 -0
- package/bin/redlint.js +2 -2
- package/bundle.js +26 -0
- package/example/entry.js +3 -1
- package/example/one.js +3 -1
- package/package.json +3 -3
- package/example/bundle.js +0 -11
- package/lib/bundle/README.md +0 -68
- package/lib/bundle/bundle-files/index.js +0 -97
- package/lib/bundle/bundle.js +0 -67
- package/lib/bundle/parse-filenames/index.js +0 -57
- package/lib/bundle/parse-filenames/parse-require/index.js +0 -23
- package/lib/bundle/resolve-filenames/index.js +0 -35
- package/lib/bundle/resolve-filenames/resolve-require/index.js +0 -32
package/ChangeLog
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
2024.02.19, v3.12.1
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 8772c48 redlint: @putout/plugin-nodejs v11.0.0
|
|
5
|
+
- 7e558b7 redlint: rm unused mock-require
|
|
6
|
+
- 4e18645 redlint: add ability to create a bundle file
|
|
7
|
+
- e053ab9 redlint: bundle: resolve-filenames: integrate
|
|
8
|
+
|
|
1
9
|
2024.02.16, v3.12.0
|
|
2
10
|
|
|
3
11
|
feature:
|
package/bin/redlint.js
CHANGED
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
isExit,
|
|
49
49
|
isBundleDebug,
|
|
50
50
|
} from '../lib/menu.js';
|
|
51
|
-
import {bundle} from '
|
|
51
|
+
import {bundle} from '@putout/bundler';
|
|
52
52
|
|
|
53
53
|
const {log} = console;
|
|
54
54
|
const {exit} = process;
|
|
@@ -204,7 +204,7 @@ async function uiLoop(arg) {
|
|
|
204
204
|
await writeFile(join(CWD, 'bundle.js'), result);
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
done(`
|
|
207
|
+
done(`bundle 'bundle.js'`);
|
|
208
208
|
return;
|
|
209
209
|
}
|
|
210
210
|
|
package/bundle.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
const __filesystem = {
|
|
3
|
+
'/example/one.js': (exports, require, module) => {
|
|
4
|
+
module.exports = 'hello';
|
|
5
|
+
},
|
|
6
|
+
'/example/entry.js': (exports, require, module) => {
|
|
7
|
+
const one = require('/example/one.js');
|
|
8
|
+
console.log(one);
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
const __modules = {};
|
|
12
|
+
const require = (name) => {
|
|
13
|
+
const exports = {};
|
|
14
|
+
const module = {
|
|
15
|
+
exports,
|
|
16
|
+
};
|
|
17
|
+
if (__modules[name])
|
|
18
|
+
return __modules[name];
|
|
19
|
+
|
|
20
|
+
__filesystem[name](exports, require, module);
|
|
21
|
+
__modules[name] = module.exports;
|
|
22
|
+
return module.exports;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
require('/example/entry.js');
|
|
26
|
+
})();
|
package/example/entry.js
CHANGED
package/example/one.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redlint",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Lint Filesystem with 🐊Putout",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"report": "madrun report"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
+
"@putout/bundler": "^1.0.0",
|
|
33
34
|
"@putout/cli-choose": "^2.0.0",
|
|
34
35
|
"@putout/cli-filesystem": "^2.0.1",
|
|
35
36
|
"@putout/engine-runner": "^21.0.0",
|
|
@@ -38,7 +39,7 @@
|
|
|
38
39
|
"@putout/operator-filesystem": "^4.0.1",
|
|
39
40
|
"@putout/operator-json": "^2.0.0",
|
|
40
41
|
"@putout/plugin-filesystem": "^4.0.0",
|
|
41
|
-
"@putout/plugin-nodejs": "^
|
|
42
|
+
"@putout/plugin-nodejs": "^11.0.0",
|
|
42
43
|
"@putout/processor-filesystem": "^4.0.0",
|
|
43
44
|
"chalk": "^5.3.0",
|
|
44
45
|
"enquirer": "^2.4.1",
|
|
@@ -67,7 +68,6 @@
|
|
|
67
68
|
"estree-to-babel": "^9.0.0",
|
|
68
69
|
"just-kebab-case": "^4.2.0",
|
|
69
70
|
"madrun": "^10.0.0",
|
|
70
|
-
"mock-require": "^3.0.3",
|
|
71
71
|
"montag": "^1.0.0",
|
|
72
72
|
"nodemon": "^3.0.1",
|
|
73
73
|
"supertape": "^10.0.0",
|
package/example/bundle.js
DELETED
package/lib/bundle/README.md
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Bundle
|
|
2
|
-
|
|
3
|
-
## Convert ESM to CommonJS
|
|
4
|
-
|
|
5
|
-
To Simplify things up all files converted to CommonJS first.
|
|
6
|
-
Let's suppose none of them use top-level await to get things simpler.
|
|
7
|
-
|
|
8
|
-
## Parse filenames
|
|
9
|
-
|
|
10
|
-
Traverse all files starting from `entry` and get all filenames.
|
|
11
|
-
|
|
12
|
-
- [`parse-require`](https://putout.cloudcmd.io/#/gist/d973366be6b07ab705b5c9d793369904/ca8b6b15fa953d95f57b42e07136c65791f38ca1);
|
|
13
|
-
- [`parse-filenames`](https://putout.cloudcmd.io/#/gist/d973366be6b07ab705b5c9d793369904/3067150ad161029e75b95e9bfff290e03953ef41);
|
|
14
|
-
- [`resolve-filenames`](https://putout.cloudcmd.io/#/gist/8ca1ac9b5fb4d1a47d185836c3f0b393/edf99b8064fe0faf4545aa0cc66138a7fa34c557);
|
|
15
|
-
- [`resolve-require`](https://putout.cloudcmd.io/#/gist/833539f66cb238fcc3b6ca6cee61ef9e/79a068c96b686bb0eacdf3f570d532981499b114);
|
|
16
|
-
- [`bundle-files`](https://putout.cloudcmd.io/#/gist/7dd3bffa8e88f7542c84065f622b63d7/3b1e68e0babc3a72af947076ed9801c0034a096e);
|
|
17
|
-
|
|
18
|
-
## Bundle all files to object
|
|
19
|
-
|
|
20
|
-
Traverse filesystem and create object that contains filename and file content:
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
const __filesystem = {
|
|
24
|
-
'/entry.js': () => {
|
|
25
|
-
const client = require('/client.js');
|
|
26
|
-
console.log(client);
|
|
27
|
-
},
|
|
28
|
-
'/client.js': (exports, require, module) => {
|
|
29
|
-
module.exports = 'hello';
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## IIFE
|
|
35
|
-
|
|
36
|
-
Most likely we need IIFE so couple bundles can be loaded on page simultaneously.
|
|
37
|
-
|
|
38
|
-
## Result Example
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
const __modules = {};
|
|
42
|
-
const __filesystem = {
|
|
43
|
-
'/entry.js': () => {
|
|
44
|
-
const client = require('/client.js');
|
|
45
|
-
console.log(client);
|
|
46
|
-
},
|
|
47
|
-
'/client.js': (exports, require, module) => {
|
|
48
|
-
module.exports = 'hello';
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const require = (name) => {
|
|
53
|
-
const exports = {};
|
|
54
|
-
const module = {
|
|
55
|
-
exports,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
if (__modules[name])
|
|
59
|
-
return __modules[name];
|
|
60
|
-
|
|
61
|
-
__filesystem[name](exports, require, module);
|
|
62
|
-
__modules[name] = module.exports;
|
|
63
|
-
|
|
64
|
-
return module.exports;
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
require('/entry.js');
|
|
68
|
-
```
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
types,
|
|
3
|
-
operator,
|
|
4
|
-
template,
|
|
5
|
-
} from 'putout';
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
replaceWith,
|
|
9
|
-
getFilename,
|
|
10
|
-
readFileContent,
|
|
11
|
-
} = operator;
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
Identifier,
|
|
15
|
-
VariableDeclarator,
|
|
16
|
-
VariableDeclaration,
|
|
17
|
-
StringLiteral,
|
|
18
|
-
ObjectProperty,
|
|
19
|
-
ObjectExpression,
|
|
20
|
-
} = types;
|
|
21
|
-
|
|
22
|
-
const createFunction = template('(exports, require, module) => {BODY}');
|
|
23
|
-
|
|
24
|
-
const createIIFEE = template(`
|
|
25
|
-
(() => {
|
|
26
|
-
FILESYSTEM;
|
|
27
|
-
MODULES;
|
|
28
|
-
REQUIRE;
|
|
29
|
-
ENTRY;
|
|
30
|
-
})()
|
|
31
|
-
`);
|
|
32
|
-
|
|
33
|
-
export const report = () => '';
|
|
34
|
-
|
|
35
|
-
export const fix = (root, {entry, filenames, trackFile}) => {
|
|
36
|
-
const object = ObjectExpression([]);
|
|
37
|
-
|
|
38
|
-
for (const file of trackFile(root, filenames)) {
|
|
39
|
-
const content = readFileContent(file);
|
|
40
|
-
const filename = getFilename(file);
|
|
41
|
-
const property = ObjectProperty(StringLiteral(filename), createFunction({
|
|
42
|
-
BODY: template.ast(content),
|
|
43
|
-
}));
|
|
44
|
-
|
|
45
|
-
object.properties.push(property);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const filesystem = VariableDeclaration('const', [VariableDeclarator(Identifier('__filesystem'), object)]);
|
|
49
|
-
|
|
50
|
-
replaceWith(root.parentPath, createIIFEE({
|
|
51
|
-
FILESYSTEM: filesystem,
|
|
52
|
-
MODULES: createModules(),
|
|
53
|
-
REQUIRE: createRequire(),
|
|
54
|
-
ENTRY: requireEntry(entry),
|
|
55
|
-
}));
|
|
56
|
-
};
|
|
57
|
-
export const scan = (root, {push, trackFile}) => {
|
|
58
|
-
const filenames = [
|
|
59
|
-
'/index.js',
|
|
60
|
-
'/send.js',
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
const entry = '/index.js';
|
|
64
|
-
|
|
65
|
-
push(root, {
|
|
66
|
-
entry,
|
|
67
|
-
filenames,
|
|
68
|
-
trackFile,
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
function createModules() {
|
|
73
|
-
return template.ast(`const __modules = {}`);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function requireEntry(entry) {
|
|
77
|
-
return template.ast(`require("${entry}")`);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function createRequire() {
|
|
81
|
-
return template.ast(`
|
|
82
|
-
const require = (name) => {
|
|
83
|
-
const exports = {};
|
|
84
|
-
const module = {
|
|
85
|
-
exports,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
if (__modules[name])
|
|
89
|
-
return __modules[name];
|
|
90
|
-
|
|
91
|
-
__filesystem[name](exports, require, module);
|
|
92
|
-
__modules[name] = module.exports;
|
|
93
|
-
|
|
94
|
-
return module.exports;
|
|
95
|
-
};
|
|
96
|
-
`);
|
|
97
|
-
}
|
package/lib/bundle/bundle.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parse,
|
|
3
|
-
transform,
|
|
4
|
-
print,
|
|
5
|
-
findPlaces,
|
|
6
|
-
} from 'putout';
|
|
7
|
-
import {createProgress} from '@putout/engine-runner/progress';
|
|
8
|
-
import * as pluginFilesystem from '@putout/plugin-filesystem';
|
|
9
|
-
import * as pluginParseFilenames from './parse-filenames/index.js';
|
|
10
|
-
import {
|
|
11
|
-
branch as originalBranch,
|
|
12
|
-
merge as originalMerge,
|
|
13
|
-
} from '@putout/processor-filesystem';
|
|
14
|
-
|
|
15
|
-
const [, replaceCwd] = pluginFilesystem.rules['replace-cwd'];
|
|
16
|
-
const [, readAllFiles] = pluginFilesystem.rules['read-all-files'];
|
|
17
|
-
|
|
18
|
-
const getMessage = (a) => a.message;
|
|
19
|
-
|
|
20
|
-
export const bundle = (from, entry, filesystem, {
|
|
21
|
-
progress = createProgress(),
|
|
22
|
-
branch = originalBranch,
|
|
23
|
-
merge = originalMerge,
|
|
24
|
-
} = {}) => {
|
|
25
|
-
const [{source}] = branch(filesystem);
|
|
26
|
-
const ast = parse(source);
|
|
27
|
-
|
|
28
|
-
transform(ast, filesystem, {
|
|
29
|
-
fix: true,
|
|
30
|
-
fixCount: 1,
|
|
31
|
-
progress,
|
|
32
|
-
rules: {
|
|
33
|
-
'read-all-files': ['on', {
|
|
34
|
-
mask: '*.js',
|
|
35
|
-
}],
|
|
36
|
-
'replace-cwd': ['on', {
|
|
37
|
-
from,
|
|
38
|
-
to: '/',
|
|
39
|
-
}],
|
|
40
|
-
},
|
|
41
|
-
plugins: [
|
|
42
|
-
['read-all-files', readAllFiles],
|
|
43
|
-
['replace-cwd', replaceCwd],
|
|
44
|
-
],
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const places = findPlaces(ast, filesystem, {
|
|
48
|
-
fixCount: 1,
|
|
49
|
-
progress,
|
|
50
|
-
rules: {
|
|
51
|
-
'parse-filenames': ['on', {
|
|
52
|
-
entry,
|
|
53
|
-
}],
|
|
54
|
-
},
|
|
55
|
-
plugins: [
|
|
56
|
-
['parse-filenames', pluginParseFilenames],
|
|
57
|
-
],
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const filenames = places.map(getMessage);
|
|
61
|
-
|
|
62
|
-
console.log(filenames);
|
|
63
|
-
|
|
64
|
-
const code = print(ast);
|
|
65
|
-
|
|
66
|
-
return merge(filesystem, [code]);
|
|
67
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import putout from 'putout';
|
|
2
|
-
import {dirname} from 'node:path';
|
|
3
|
-
// parse-require
|
|
4
|
-
import * as parseRequire from './parse-require/index.js';
|
|
5
|
-
import * as convertEsmToCommonjs from '@putout/plugin-nodejs/convert-esm-to-commonjs';
|
|
6
|
-
|
|
7
|
-
// parse-require
|
|
8
|
-
const {operator} = putout;
|
|
9
|
-
const {
|
|
10
|
-
readFileContent,
|
|
11
|
-
getFilename,
|
|
12
|
-
findFile,
|
|
13
|
-
} = operator;
|
|
14
|
-
|
|
15
|
-
const getMessage = ({message}) => message;
|
|
16
|
-
|
|
17
|
-
export const report = (root, {file}) => file;
|
|
18
|
-
export const fix = () => {};
|
|
19
|
-
export const scan = (root, {push, options}) => {
|
|
20
|
-
const {entry = '/index.js'} = options;
|
|
21
|
-
const files = new Set();
|
|
22
|
-
const processingNames = new Set([entry]);
|
|
23
|
-
|
|
24
|
-
for (const currentName of processingNames) {
|
|
25
|
-
const [file] = findFile(root, currentName);
|
|
26
|
-
|
|
27
|
-
if (!file)
|
|
28
|
-
throw Error(`file '${currentName}' not found`);
|
|
29
|
-
|
|
30
|
-
const filename = getFilename(file);
|
|
31
|
-
const dir = dirname(filename);
|
|
32
|
-
|
|
33
|
-
files.add(filename);
|
|
34
|
-
|
|
35
|
-
const {places} = putout(readFileContent(file), {
|
|
36
|
-
rules: {
|
|
37
|
-
'parse-require': ['on', {
|
|
38
|
-
dir,
|
|
39
|
-
}],
|
|
40
|
-
},
|
|
41
|
-
plugins: [
|
|
42
|
-
['convert-esm-to-commonjs', convertEsmToCommonjs],
|
|
43
|
-
['parse-require', parseRequire],
|
|
44
|
-
],
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
for (const name of places.map(getMessage))
|
|
48
|
-
processingNames.add(name);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
for (const file of files) {
|
|
52
|
-
push(root, {
|
|
53
|
-
file,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {operator} from 'putout';
|
|
2
|
-
import {resolve} from 'node:path';
|
|
3
|
-
|
|
4
|
-
const {getTemplateValues} = operator;
|
|
5
|
-
|
|
6
|
-
export const report = ({filename}) => maybeAddJs(filename);
|
|
7
|
-
export const fix = () => {};
|
|
8
|
-
|
|
9
|
-
const REQUIRE = 'require(__a)';
|
|
10
|
-
const maybeAddJs = (a) => a.endsWith('js') ? a : `${a}.js`;
|
|
11
|
-
|
|
12
|
-
export const traverse = ({push, options}) => ({
|
|
13
|
-
[REQUIRE]: (path) => {
|
|
14
|
-
const {dir = '/'} = options;
|
|
15
|
-
const {__a} = getTemplateValues(path, REQUIRE);
|
|
16
|
-
const filename = resolve(dir, __a.value);
|
|
17
|
-
|
|
18
|
-
push({
|
|
19
|
-
path,
|
|
20
|
-
filename,
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import putout, {operator} from 'putout';
|
|
2
|
-
import {dirname} from 'node:path';
|
|
3
|
-
import * as resolveRequire from './resolve-require/index.js';
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
writeFileContent,
|
|
7
|
-
getFilename,
|
|
8
|
-
readFileContent,
|
|
9
|
-
} = operator;
|
|
10
|
-
|
|
11
|
-
export const report = (file) => getFilename(file);
|
|
12
|
-
export const fix = (file) => {
|
|
13
|
-
const {code} = putout(readFileContent(file), {
|
|
14
|
-
rules: {
|
|
15
|
-
'resolve-require': ['on', {
|
|
16
|
-
dir: dirname(getFilename(file)),
|
|
17
|
-
}],
|
|
18
|
-
},
|
|
19
|
-
plugins: [
|
|
20
|
-
['resolve-require', resolveRequire],
|
|
21
|
-
],
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
writeFileContent(file, code);
|
|
25
|
-
};
|
|
26
|
-
export const scan = (root, {push, trackFile}) => {
|
|
27
|
-
const filenames = [
|
|
28
|
-
'/index.js',
|
|
29
|
-
'/send.js',
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
for (const file of trackFile(root, filenames)) {
|
|
33
|
-
push(file);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {operator} from 'putout';
|
|
2
|
-
import {resolve} from 'node:path';
|
|
3
|
-
|
|
4
|
-
const {
|
|
5
|
-
getTemplateValues,
|
|
6
|
-
setLiteralValue,
|
|
7
|
-
} = operator;
|
|
8
|
-
|
|
9
|
-
export const report = ({filename}) => filename;
|
|
10
|
-
export const fix = ({path, filename}) => {
|
|
11
|
-
const [arg] = path.node.arguments;
|
|
12
|
-
setLiteralValue(arg, `${filename}.js`);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const REQUIRE = 'require(__a)';
|
|
16
|
-
|
|
17
|
-
export const traverse = ({push, options}) => ({
|
|
18
|
-
[REQUIRE]: (path) => {
|
|
19
|
-
const {dir = '/'} = options;
|
|
20
|
-
const {__a} = getTemplateValues(path, REQUIRE);
|
|
21
|
-
|
|
22
|
-
if (__a.value.startsWith('/'))
|
|
23
|
-
return;
|
|
24
|
-
|
|
25
|
-
const filename = resolve(dir, __a.value);
|
|
26
|
-
|
|
27
|
-
push({
|
|
28
|
-
path,
|
|
29
|
-
filename,
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
});
|