immosquare-cleaner 0.1.43 β 0.1.44
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/immosquare-cleaner/version.rb +1 -1
- data/node_modules/@eslint/js/package.json +1 -1
- data/node_modules/eslint/README.md +1 -1
- data/node_modules/eslint/lib/cli.js +4 -3
- data/node_modules/eslint/lib/eslint/eslint.js +93 -17
- data/node_modules/eslint/lib/languages/js/source-code/source-code.js +1 -1
- data/node_modules/eslint/lib/rules/require-await.js +37 -3
- data/node_modules/eslint/lib/rules/utils/ast-utils.js +4 -3
- data/node_modules/eslint/lib/shared/flags.js +2 -1
- data/node_modules/eslint/package.json +17 -8
- data/node_modules/jscodeshift/CHANGELOG.md +17 -0
- data/node_modules/jscodeshift/CONTRIBUTING.md +7 -6
- data/node_modules/jscodeshift/README.md +3 -2
- data/node_modules/jscodeshift/dist/Runner.js +15 -15
- data/node_modules/jscodeshift/dist/collections/ImportDeclaration.js +113 -0
- data/node_modules/jscodeshift/dist/collections/index.js +1 -0
- data/node_modules/jscodeshift/dist/src/Runner.js +15 -15
- data/node_modules/jscodeshift/dist/src/collections/ImportDeclaration.js +113 -0
- data/node_modules/jscodeshift/dist/src/collections/index.js +1 -0
- data/node_modules/jscodeshift/package.json +9 -7
- data/node_modules/jscodeshift/parser/tsOptions.js +2 -0
- data/node_modules/jscodeshift/src/Runner.js +15 -15
- data/node_modules/jscodeshift/src/collections/ImportDeclaration.js +113 -0
- data/node_modules/jscodeshift/src/collections/index.js +1 -0
- data/node_modules/jscodeshift/utils/testUtils.js +1 -2
- data/node_modules/jscodeshift/website/README.md +44 -0
- data/node_modules/jscodeshift/website/astro.config.mjs +36 -0
- data/node_modules/jscodeshift/website/package.json +17 -0
- data/node_modules/jscodeshift/website/public/favicon.svg +1 -0
- data/node_modules/jscodeshift/website/src/assets/houston.webp +0 -0
- data/node_modules/jscodeshift/website/src/content/config.ts +6 -0
- data/node_modules/jscodeshift/website/src/content/docs/build/api-reference.mdx +406 -0
- data/node_modules/jscodeshift/website/src/content/docs/build/ast-grammar.mdx +3086 -0
- data/node_modules/jscodeshift/website/src/content/docs/index.mdx +15 -0
- data/node_modules/jscodeshift/website/src/content/docs/overview/introduction.mdx +45 -0
- data/node_modules/jscodeshift/website/src/content/docs/run/cli.mdx +161 -0
- data/node_modules/jscodeshift/website/src/env.d.ts +2 -0
- data/node_modules/jscodeshift/website/tsconfig.json +3 -0
- data/node_modules/npm-check-updates/README.md +34 -21
- data/node_modules/npm-check-updates/build/index.js +136 -136
- data/node_modules/npm-check-updates/build/index.js.map +1 -1
- data/node_modules/npm-check-updates/package.json +1 -1
- data/package.json +4 -4
- metadata +18 -10
- data/node_modules/jscodeshift/node_modules/chalk/index.d.ts +0 -415
- data/node_modules/jscodeshift/node_modules/chalk/license +0 -9
- data/node_modules/jscodeshift/node_modules/chalk/package.json +0 -68
- data/node_modules/jscodeshift/node_modules/chalk/readme.md +0 -341
- data/node_modules/jscodeshift/node_modules/chalk/source/index.js +0 -229
- data/node_modules/jscodeshift/node_modules/chalk/source/templates.js +0 -134
- data/node_modules/jscodeshift/node_modules/chalk/source/util.js +0 -39
- data/node_modules/jscodeshift/website/index.htm +0 -9
@@ -0,0 +1,113 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
"use strict";
|
9
|
+
|
10
|
+
const Collection = require("../Collection");
|
11
|
+
const NodeCollection = require("./Node");
|
12
|
+
|
13
|
+
const assert = require("assert");
|
14
|
+
const once = require("../utils/once");
|
15
|
+
const recast = require("recast");
|
16
|
+
|
17
|
+
const types = recast.types.namedTypes;
|
18
|
+
|
19
|
+
const globalMethods = {
|
20
|
+
/**
|
21
|
+
* Inserts an ImportDeclaration at the top of the AST
|
22
|
+
*
|
23
|
+
* @param {string} sourcePath
|
24
|
+
* @param {Array} specifiers
|
25
|
+
*/
|
26
|
+
insertImportDeclaration: function (sourcePath, specifiers) {
|
27
|
+
assert.ok(
|
28
|
+
sourcePath && typeof sourcePath === "string",
|
29
|
+
"insertImportDeclaration(...) needs a source path"
|
30
|
+
);
|
31
|
+
|
32
|
+
assert.ok(
|
33
|
+
specifiers && Array.isArray(specifiers),
|
34
|
+
"insertImportDeclaration(...) needs an array of specifiers"
|
35
|
+
);
|
36
|
+
|
37
|
+
if (this.hasImportDeclaration(sourcePath)) {
|
38
|
+
return this;
|
39
|
+
}
|
40
|
+
|
41
|
+
const importDeclaration = recast.types.builders.importDeclaration(
|
42
|
+
specifiers,
|
43
|
+
recast.types.builders.stringLiteral(sourcePath)
|
44
|
+
);
|
45
|
+
|
46
|
+
return this.forEach((path) => {
|
47
|
+
if (path.value.type === "Program") {
|
48
|
+
path.value.body.unshift(importDeclaration);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
},
|
52
|
+
/**
|
53
|
+
* Finds all ImportDeclarations optionally filtered by name
|
54
|
+
*
|
55
|
+
* @param {string} sourcePath
|
56
|
+
* @return {Collection}
|
57
|
+
*/
|
58
|
+
findImportDeclarations: function (sourcePath) {
|
59
|
+
assert.ok(
|
60
|
+
sourcePath && typeof sourcePath === "string",
|
61
|
+
"findImportDeclarations(...) needs a source path"
|
62
|
+
);
|
63
|
+
|
64
|
+
return this.find(types.ImportDeclaration, {
|
65
|
+
source: { value: sourcePath },
|
66
|
+
});
|
67
|
+
},
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Determines if the collection has an ImportDeclaration with the given sourcePath
|
71
|
+
*
|
72
|
+
* @param {string} sourcePath
|
73
|
+
* @returns {boolean}
|
74
|
+
*/
|
75
|
+
hasImportDeclaration: function (sourcePath) {
|
76
|
+
assert.ok(
|
77
|
+
sourcePath && typeof sourcePath === "string",
|
78
|
+
"findImportDeclarations(...) needs a source path"
|
79
|
+
);
|
80
|
+
|
81
|
+
return this.findImportDeclarations(sourcePath).length > 0;
|
82
|
+
},
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Renames all ImportDeclarations with the given name
|
86
|
+
*
|
87
|
+
* @param {string} sourcePath
|
88
|
+
* @param {string} newSourcePath
|
89
|
+
* @return {Collection}
|
90
|
+
*/
|
91
|
+
renameImportDeclaration: function (sourcePath, newSourcePath) {
|
92
|
+
assert.ok(
|
93
|
+
sourcePath && typeof sourcePath === "string",
|
94
|
+
"renameImportDeclaration(...) needs a name to look for"
|
95
|
+
);
|
96
|
+
|
97
|
+
assert.ok(
|
98
|
+
newSourcePath && typeof newSourcePath === "string",
|
99
|
+
"renameImportDeclaration(...) needs a new name to rename to"
|
100
|
+
);
|
101
|
+
|
102
|
+
return this.findImportDeclarations(sourcePath).forEach((path) => {
|
103
|
+
path.value.source.value = newSourcePath;
|
104
|
+
});
|
105
|
+
},
|
106
|
+
};
|
107
|
+
|
108
|
+
function register() {
|
109
|
+
NodeCollection.register();
|
110
|
+
Collection.registerMethods(globalMethods, types.Node);
|
111
|
+
}
|
112
|
+
|
113
|
+
exports.register = once(register);
|
@@ -9,7 +9,7 @@
|
|
9
9
|
'use strict';
|
10
10
|
|
11
11
|
const child_process = require('child_process');
|
12
|
-
const
|
12
|
+
const pc = require('picocolors');
|
13
13
|
const fs = require('graceful-fs');
|
14
14
|
const path = require('path');
|
15
15
|
const http = require('http');
|
@@ -47,21 +47,21 @@ const bufferedWrite = (function() {
|
|
47
47
|
|
48
48
|
const log = {
|
49
49
|
ok(msg, verbose) {
|
50
|
-
verbose >= 2 && bufferedWrite(
|
50
|
+
verbose >= 2 && bufferedWrite(pc.bgGreen(pc.white(' OKK ')) + msg);
|
51
51
|
},
|
52
52
|
nochange(msg, verbose) {
|
53
|
-
verbose >= 1 && bufferedWrite(
|
53
|
+
verbose >= 1 && bufferedWrite(pc.bgYellow(pc.white(' NOC ')) + msg);
|
54
54
|
},
|
55
55
|
skip(msg, verbose) {
|
56
|
-
verbose >= 1 && bufferedWrite(
|
56
|
+
verbose >= 1 && bufferedWrite(pc.bgYellow(pc.white(' SKIP ')) + msg);
|
57
57
|
},
|
58
58
|
error(msg, verbose) {
|
59
|
-
verbose >= 0 && bufferedWrite(
|
59
|
+
verbose >= 0 && bufferedWrite(pc.bgRed(pc.white(' ERR ')) + msg);
|
60
60
|
},
|
61
61
|
};
|
62
62
|
|
63
63
|
function report({file, msg}) {
|
64
|
-
bufferedWrite(lineBreak(`${
|
64
|
+
bufferedWrite(lineBreak(`${pc.bgBlue(pc.white(' REP '))}${file} ${msg}`));
|
65
65
|
}
|
66
66
|
|
67
67
|
function concatAll(arrays) {
|
@@ -77,17 +77,17 @@ function concatAll(arrays) {
|
|
77
77
|
function showFileStats(fileStats) {
|
78
78
|
process.stdout.write(
|
79
79
|
'Results: \n'+
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
pc.red(fileStats.error + ' errors\n')+
|
81
|
+
pc.yellow(fileStats.nochange + ' unmodified\n')+
|
82
|
+
pc.yellow(fileStats.skip + ' skipped\n')+
|
83
|
+
pc.green(fileStats.ok + ' ok\n')
|
84
84
|
);
|
85
85
|
}
|
86
86
|
|
87
87
|
function showStats(stats) {
|
88
88
|
const names = Object.keys(stats).sort();
|
89
89
|
if (names.length) {
|
90
|
-
process.stdout.write(
|
90
|
+
process.stdout.write(pc.blue('Stats: \n'));
|
91
91
|
}
|
92
92
|
names.forEach(name => process.stdout.write(name + ': ' + stats[name] + '\n'));
|
93
93
|
}
|
@@ -177,7 +177,7 @@ function run(transformFile, paths, options) {
|
|
177
177
|
let gitIgnorePath = path.join(currDirectory, '.gitignore');
|
178
178
|
ignores.addFromFile(gitIgnorePath);
|
179
179
|
}
|
180
|
-
|
180
|
+
|
181
181
|
if (/^http/.test(transformFile)) {
|
182
182
|
usedRemoteScript = true;
|
183
183
|
return new Promise((resolve, reject) => {
|
@@ -208,7 +208,7 @@ function run(transformFile, paths, options) {
|
|
208
208
|
});
|
209
209
|
} else if (!fs.existsSync(transformFile)) {
|
210
210
|
process.stderr.write(
|
211
|
-
|
211
|
+
pc.bgRed(pc.white('ERROR')) + ' Transform file ' + transformFile + ' does not exist \n'
|
212
212
|
);
|
213
213
|
return;
|
214
214
|
} else {
|
@@ -254,7 +254,7 @@ function run(transformFile, paths, options) {
|
|
254
254
|
}
|
255
255
|
if (options.dry) {
|
256
256
|
process.stdout.write(
|
257
|
-
|
257
|
+
pc.green('Running in dry mode, no files will be written! \n')
|
258
258
|
);
|
259
259
|
}
|
260
260
|
}
|
@@ -305,7 +305,7 @@ function run(transformFile, paths, options) {
|
|
305
305
|
process.stdout.write(
|
306
306
|
'Time elapsed: ' + timeElapsed + 'seconds \n'
|
307
307
|
);
|
308
|
-
|
308
|
+
|
309
309
|
if (options.failOnError && fileCounters.error > 0) {
|
310
310
|
process.exit(1);
|
311
311
|
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
"use strict";
|
9
|
+
|
10
|
+
const Collection = require("../Collection");
|
11
|
+
const NodeCollection = require("./Node");
|
12
|
+
|
13
|
+
const assert = require("assert");
|
14
|
+
const once = require("../utils/once");
|
15
|
+
const recast = require("recast");
|
16
|
+
|
17
|
+
const types = recast.types.namedTypes;
|
18
|
+
|
19
|
+
const globalMethods = {
|
20
|
+
/**
|
21
|
+
* Inserts an ImportDeclaration at the top of the AST
|
22
|
+
*
|
23
|
+
* @param {string} sourcePath
|
24
|
+
* @param {Array} specifiers
|
25
|
+
*/
|
26
|
+
insertImportDeclaration: function (sourcePath, specifiers) {
|
27
|
+
assert.ok(
|
28
|
+
sourcePath && typeof sourcePath === "string",
|
29
|
+
"insertImportDeclaration(...) needs a source path"
|
30
|
+
);
|
31
|
+
|
32
|
+
assert.ok(
|
33
|
+
specifiers && Array.isArray(specifiers),
|
34
|
+
"insertImportDeclaration(...) needs an array of specifiers"
|
35
|
+
);
|
36
|
+
|
37
|
+
if (this.hasImportDeclaration(sourcePath)) {
|
38
|
+
return this;
|
39
|
+
}
|
40
|
+
|
41
|
+
const importDeclaration = recast.types.builders.importDeclaration(
|
42
|
+
specifiers,
|
43
|
+
recast.types.builders.stringLiteral(sourcePath)
|
44
|
+
);
|
45
|
+
|
46
|
+
return this.forEach((path) => {
|
47
|
+
if (path.value.type === "Program") {
|
48
|
+
path.value.body.unshift(importDeclaration);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
},
|
52
|
+
/**
|
53
|
+
* Finds all ImportDeclarations optionally filtered by name
|
54
|
+
*
|
55
|
+
* @param {string} sourcePath
|
56
|
+
* @return {Collection}
|
57
|
+
*/
|
58
|
+
findImportDeclarations: function (sourcePath) {
|
59
|
+
assert.ok(
|
60
|
+
sourcePath && typeof sourcePath === "string",
|
61
|
+
"findImportDeclarations(...) needs a source path"
|
62
|
+
);
|
63
|
+
|
64
|
+
return this.find(types.ImportDeclaration, {
|
65
|
+
source: { value: sourcePath },
|
66
|
+
});
|
67
|
+
},
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Determines if the collection has an ImportDeclaration with the given sourcePath
|
71
|
+
*
|
72
|
+
* @param {string} sourcePath
|
73
|
+
* @returns {boolean}
|
74
|
+
*/
|
75
|
+
hasImportDeclaration: function (sourcePath) {
|
76
|
+
assert.ok(
|
77
|
+
sourcePath && typeof sourcePath === "string",
|
78
|
+
"findImportDeclarations(...) needs a source path"
|
79
|
+
);
|
80
|
+
|
81
|
+
return this.findImportDeclarations(sourcePath).length > 0;
|
82
|
+
},
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Renames all ImportDeclarations with the given name
|
86
|
+
*
|
87
|
+
* @param {string} sourcePath
|
88
|
+
* @param {string} newSourcePath
|
89
|
+
* @return {Collection}
|
90
|
+
*/
|
91
|
+
renameImportDeclaration: function (sourcePath, newSourcePath) {
|
92
|
+
assert.ok(
|
93
|
+
sourcePath && typeof sourcePath === "string",
|
94
|
+
"renameImportDeclaration(...) needs a name to look for"
|
95
|
+
);
|
96
|
+
|
97
|
+
assert.ok(
|
98
|
+
newSourcePath && typeof newSourcePath === "string",
|
99
|
+
"renameImportDeclaration(...) needs a new name to rename to"
|
100
|
+
);
|
101
|
+
|
102
|
+
return this.findImportDeclarations(sourcePath).forEach((path) => {
|
103
|
+
path.value.source.value = newSourcePath;
|
104
|
+
});
|
105
|
+
},
|
106
|
+
};
|
107
|
+
|
108
|
+
function register() {
|
109
|
+
NodeCollection.register();
|
110
|
+
Collection.registerMethods(globalMethods, types.Node);
|
111
|
+
}
|
112
|
+
|
113
|
+
exports.register = once(register);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jscodeshift",
|
3
|
-
"version": "0.
|
3
|
+
"version": "17.0.0",
|
4
4
|
"description": "A toolkit for JavaScript codemods",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -34,12 +34,11 @@
|
|
34
34
|
"@babel/preset-flow": "^7.24.7",
|
35
35
|
"@babel/preset-typescript": "^7.24.7",
|
36
36
|
"@babel/register": "^7.24.6",
|
37
|
-
"
|
37
|
+
"picocolors": "^1.0.1",
|
38
38
|
"flow-parser": "0.*",
|
39
39
|
"graceful-fs": "^4.2.4",
|
40
40
|
"micromatch": "^4.0.7",
|
41
41
|
"neo-async": "^2.5.0",
|
42
|
-
"node-dir": "^0.1.17",
|
43
42
|
"recast": "^0.23.9",
|
44
43
|
"temp": "^0.9.4",
|
45
44
|
"write-file-atomic": "^5.0.1"
|
@@ -53,11 +52,10 @@
|
|
53
52
|
}
|
54
53
|
},
|
55
54
|
"devDependencies": {
|
56
|
-
"babel-
|
55
|
+
"@babel/eslint-parser": "^7.24.7",
|
57
56
|
"eslint": "8.56.0",
|
58
57
|
"jest": "^29.7.0",
|
59
|
-
"jsdoc": "^4.0.3"
|
60
|
-
"mkdirp": "^3.0.1"
|
58
|
+
"jsdoc": "^4.0.3"
|
61
59
|
},
|
62
60
|
"jest": {
|
63
61
|
"roots": [
|
@@ -66,5 +64,9 @@
|
|
66
64
|
"parser",
|
67
65
|
"sample"
|
68
66
|
]
|
69
|
-
}
|
67
|
+
},
|
68
|
+
"engines": {
|
69
|
+
"node": ">=16"
|
70
|
+
},
|
71
|
+
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
70
72
|
}
|
@@ -19,6 +19,7 @@ module.exports = {
|
|
19
19
|
tokens: true,
|
20
20
|
plugins: [
|
21
21
|
'asyncGenerators',
|
22
|
+
'decoratorAutoAccessors',
|
22
23
|
'bigInt',
|
23
24
|
'classPrivateMethods',
|
24
25
|
'classPrivateProperties',
|
@@ -31,6 +32,7 @@ module.exports = {
|
|
31
32
|
'exportNamespaceFrom',
|
32
33
|
'functionBind',
|
33
34
|
'functionSent',
|
35
|
+
'importAttributes',
|
34
36
|
'importMeta',
|
35
37
|
'nullishCoalescingOperator',
|
36
38
|
'numericSeparator',
|
@@ -9,7 +9,7 @@
|
|
9
9
|
'use strict';
|
10
10
|
|
11
11
|
const child_process = require('child_process');
|
12
|
-
const
|
12
|
+
const pc = require('picocolors');
|
13
13
|
const fs = require('graceful-fs');
|
14
14
|
const path = require('path');
|
15
15
|
const http = require('http');
|
@@ -47,21 +47,21 @@ const bufferedWrite = (function() {
|
|
47
47
|
|
48
48
|
const log = {
|
49
49
|
ok(msg, verbose) {
|
50
|
-
verbose >= 2 && bufferedWrite(
|
50
|
+
verbose >= 2 && bufferedWrite(pc.bgGreen(pc.white(' OKK ')) + msg);
|
51
51
|
},
|
52
52
|
nochange(msg, verbose) {
|
53
|
-
verbose >= 1 && bufferedWrite(
|
53
|
+
verbose >= 1 && bufferedWrite(pc.bgYellow(pc.white(' NOC ')) + msg);
|
54
54
|
},
|
55
55
|
skip(msg, verbose) {
|
56
|
-
verbose >= 1 && bufferedWrite(
|
56
|
+
verbose >= 1 && bufferedWrite(pc.bgYellow(pc.white(' SKIP ')) + msg);
|
57
57
|
},
|
58
58
|
error(msg, verbose) {
|
59
|
-
verbose >= 0 && bufferedWrite(
|
59
|
+
verbose >= 0 && bufferedWrite(pc.bgRed(pc.white(' ERR ')) + msg);
|
60
60
|
},
|
61
61
|
};
|
62
62
|
|
63
63
|
function report({file, msg}) {
|
64
|
-
bufferedWrite(lineBreak(`${
|
64
|
+
bufferedWrite(lineBreak(`${pc.bgBlue(pc.white(' REP '))}${file} ${msg}`));
|
65
65
|
}
|
66
66
|
|
67
67
|
function concatAll(arrays) {
|
@@ -77,17 +77,17 @@ function concatAll(arrays) {
|
|
77
77
|
function showFileStats(fileStats) {
|
78
78
|
process.stdout.write(
|
79
79
|
'Results: \n'+
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
pc.red(fileStats.error + ' errors\n')+
|
81
|
+
pc.yellow(fileStats.nochange + ' unmodified\n')+
|
82
|
+
pc.yellow(fileStats.skip + ' skipped\n')+
|
83
|
+
pc.green(fileStats.ok + ' ok\n')
|
84
84
|
);
|
85
85
|
}
|
86
86
|
|
87
87
|
function showStats(stats) {
|
88
88
|
const names = Object.keys(stats).sort();
|
89
89
|
if (names.length) {
|
90
|
-
process.stdout.write(
|
90
|
+
process.stdout.write(pc.blue('Stats: \n'));
|
91
91
|
}
|
92
92
|
names.forEach(name => process.stdout.write(name + ': ' + stats[name] + '\n'));
|
93
93
|
}
|
@@ -177,7 +177,7 @@ function run(transformFile, paths, options) {
|
|
177
177
|
let gitIgnorePath = path.join(currDirectory, '.gitignore');
|
178
178
|
ignores.addFromFile(gitIgnorePath);
|
179
179
|
}
|
180
|
-
|
180
|
+
|
181
181
|
if (/^http/.test(transformFile)) {
|
182
182
|
usedRemoteScript = true;
|
183
183
|
return new Promise((resolve, reject) => {
|
@@ -208,7 +208,7 @@ function run(transformFile, paths, options) {
|
|
208
208
|
});
|
209
209
|
} else if (!fs.existsSync(transformFile)) {
|
210
210
|
process.stderr.write(
|
211
|
-
|
211
|
+
pc.bgRed(pc.white('ERROR')) + ' Transform file ' + transformFile + ' does not exist \n'
|
212
212
|
);
|
213
213
|
return;
|
214
214
|
} else {
|
@@ -254,7 +254,7 @@ function run(transformFile, paths, options) {
|
|
254
254
|
}
|
255
255
|
if (options.dry) {
|
256
256
|
process.stdout.write(
|
257
|
-
|
257
|
+
pc.green('Running in dry mode, no files will be written! \n')
|
258
258
|
);
|
259
259
|
}
|
260
260
|
}
|
@@ -305,7 +305,7 @@ function run(transformFile, paths, options) {
|
|
305
305
|
process.stdout.write(
|
306
306
|
'Time elapsed: ' + timeElapsed + 'seconds \n'
|
307
307
|
);
|
308
|
-
|
308
|
+
|
309
309
|
if (options.failOnError && fileCounters.error > 0) {
|
310
310
|
process.exit(1);
|
311
311
|
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*/
|
7
|
+
|
8
|
+
"use strict";
|
9
|
+
|
10
|
+
const Collection = require("../Collection");
|
11
|
+
const NodeCollection = require("./Node");
|
12
|
+
|
13
|
+
const assert = require("assert");
|
14
|
+
const once = require("../utils/once");
|
15
|
+
const recast = require("recast");
|
16
|
+
|
17
|
+
const types = recast.types.namedTypes;
|
18
|
+
|
19
|
+
const globalMethods = {
|
20
|
+
/**
|
21
|
+
* Inserts an ImportDeclaration at the top of the AST
|
22
|
+
*
|
23
|
+
* @param {string} sourcePath
|
24
|
+
* @param {Array} specifiers
|
25
|
+
*/
|
26
|
+
insertImportDeclaration: function (sourcePath, specifiers) {
|
27
|
+
assert.ok(
|
28
|
+
sourcePath && typeof sourcePath === "string",
|
29
|
+
"insertImportDeclaration(...) needs a source path"
|
30
|
+
);
|
31
|
+
|
32
|
+
assert.ok(
|
33
|
+
specifiers && Array.isArray(specifiers),
|
34
|
+
"insertImportDeclaration(...) needs an array of specifiers"
|
35
|
+
);
|
36
|
+
|
37
|
+
if (this.hasImportDeclaration(sourcePath)) {
|
38
|
+
return this;
|
39
|
+
}
|
40
|
+
|
41
|
+
const importDeclaration = recast.types.builders.importDeclaration(
|
42
|
+
specifiers,
|
43
|
+
recast.types.builders.stringLiteral(sourcePath)
|
44
|
+
);
|
45
|
+
|
46
|
+
return this.forEach((path) => {
|
47
|
+
if (path.value.type === "Program") {
|
48
|
+
path.value.body.unshift(importDeclaration);
|
49
|
+
}
|
50
|
+
});
|
51
|
+
},
|
52
|
+
/**
|
53
|
+
* Finds all ImportDeclarations optionally filtered by name
|
54
|
+
*
|
55
|
+
* @param {string} sourcePath
|
56
|
+
* @return {Collection}
|
57
|
+
*/
|
58
|
+
findImportDeclarations: function (sourcePath) {
|
59
|
+
assert.ok(
|
60
|
+
sourcePath && typeof sourcePath === "string",
|
61
|
+
"findImportDeclarations(...) needs a source path"
|
62
|
+
);
|
63
|
+
|
64
|
+
return this.find(types.ImportDeclaration, {
|
65
|
+
source: { value: sourcePath },
|
66
|
+
});
|
67
|
+
},
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Determines if the collection has an ImportDeclaration with the given sourcePath
|
71
|
+
*
|
72
|
+
* @param {string} sourcePath
|
73
|
+
* @returns {boolean}
|
74
|
+
*/
|
75
|
+
hasImportDeclaration: function (sourcePath) {
|
76
|
+
assert.ok(
|
77
|
+
sourcePath && typeof sourcePath === "string",
|
78
|
+
"findImportDeclarations(...) needs a source path"
|
79
|
+
);
|
80
|
+
|
81
|
+
return this.findImportDeclarations(sourcePath).length > 0;
|
82
|
+
},
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Renames all ImportDeclarations with the given name
|
86
|
+
*
|
87
|
+
* @param {string} sourcePath
|
88
|
+
* @param {string} newSourcePath
|
89
|
+
* @return {Collection}
|
90
|
+
*/
|
91
|
+
renameImportDeclaration: function (sourcePath, newSourcePath) {
|
92
|
+
assert.ok(
|
93
|
+
sourcePath && typeof sourcePath === "string",
|
94
|
+
"renameImportDeclaration(...) needs a name to look for"
|
95
|
+
);
|
96
|
+
|
97
|
+
assert.ok(
|
98
|
+
newSourcePath && typeof newSourcePath === "string",
|
99
|
+
"renameImportDeclaration(...) needs a new name to rename to"
|
100
|
+
);
|
101
|
+
|
102
|
+
return this.findImportDeclarations(sourcePath).forEach((path) => {
|
103
|
+
path.value.source.value = newSourcePath;
|
104
|
+
});
|
105
|
+
},
|
106
|
+
};
|
107
|
+
|
108
|
+
function register() {
|
109
|
+
NodeCollection.register();
|
110
|
+
Collection.registerMethods(globalMethods, types.Node);
|
111
|
+
}
|
112
|
+
|
113
|
+
exports.register = once(register);
|
@@ -9,14 +9,13 @@
|
|
9
9
|
'use strict';
|
10
10
|
|
11
11
|
const fs = require('fs');
|
12
|
-
const mkdirp = require('mkdirp');
|
13
12
|
const path = require('path');
|
14
13
|
const temp = require('temp');
|
15
14
|
|
16
15
|
function renameFileTo(oldPath, newFilename, extension = '') {
|
17
16
|
const projectPath = path.dirname(oldPath);
|
18
17
|
const newPath = path.join(projectPath, newFilename + extension);
|
19
|
-
|
18
|
+
fs.mkdirSync(path.dirname(newPath), { recursive: true });
|
20
19
|
fs.renameSync(oldPath, newPath);
|
21
20
|
return newPath;
|
22
21
|
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# jscodeshift docs
|
2
|
+
|
3
|
+
[![Built with Starlight](https://astro.badg.es/v2/built-with-starlight/tiny.svg)](https://starlight.astro.build)
|
4
|
+
|
5
|
+
## π Project Structure
|
6
|
+
|
7
|
+
```
|
8
|
+
.
|
9
|
+
βββ public/
|
10
|
+
βββ src/
|
11
|
+
β βββ assets/
|
12
|
+
β βββ content/
|
13
|
+
β β βββ docs/
|
14
|
+
β β βββ config.ts
|
15
|
+
β βββ env.d.ts
|
16
|
+
βββ astro.config.mjs
|
17
|
+
βββ package.json
|
18
|
+
βββ tsconfig.json
|
19
|
+
```
|
20
|
+
|
21
|
+
Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on
|
22
|
+
its file name.
|
23
|
+
|
24
|
+
Images can be added to `src/assets/` and embedded in Markdown with a relative link.
|
25
|
+
|
26
|
+
Static assets, like favicons, can be placed in the `public/` directory.
|
27
|
+
|
28
|
+
## π§ Commands
|
29
|
+
|
30
|
+
All commands are run from the root of the project, from a terminal:
|
31
|
+
|
32
|
+
| Command | Action |
|
33
|
+
|:-----------------------|:-------------------------------------------------|
|
34
|
+
| `yarn install` | Installs dependencies |
|
35
|
+
| `yarn dev` | Starts local dev server at `localhost:4321` |
|
36
|
+
| `yarn build` | Build your production site to `./dist/` |
|
37
|
+
| `yarn preview` | Preview your build locally, before deploying |
|
38
|
+
| `yarn astro ...` | Run CLI commands like `astro add`, `astro check` |
|
39
|
+
| `yarn astro -- --help` | Get help using the Astro CLI |
|
40
|
+
|
41
|
+
## π Want to learn more?
|
42
|
+
|
43
|
+
Check out [Starlightβs docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build),
|
44
|
+
or jump into the [Astro Discord server](https://astro.build/chat).
|