Skip to content

Commit 8cf9a4b

Browse files
author
Daniel Del Core
committed
fix config path parsing
1 parent 7355558 commit 8cf9a4b

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
lines changed

.changeset/witty-cherries-cross.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@codeshift/core': patch
3+
'@codeshift/cli': patch
4+
---
5+
6+
Fixes config path parsing

packages/cli/src/main.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default async function main(
2626
}
2727

2828
const pluginManagerConfig: Partial<PluginManagerOptions> = {
29-
pluginsPath: path.join(__dirname, 'node_modules'),
29+
pluginsPath: path.join(__dirname, '..', 'node_modules'),
3030
};
3131

3232
// If a registry is provided in the CLI flags, use it for the pluginManagers configuration.
@@ -277,6 +277,4 @@ export default async function main(
277277
failOnError: false,
278278
});
279279
}
280-
281-
await packageManager.uninstallAll();
282280
}

packages/core/lib/Worker.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ function prepareJscodeshift(options) {
4545
return jscodeshift.withParser(parser);
4646
}
4747

48-
function getTransform(entryPath) {
49-
const transform = entryPath.split('@');
50-
if (transform[1]) return transform[1];
48+
function retrieveTransformId(str) {
49+
return (str.match(/[^@]*(?:[@](?!.*[@]))(.*)$/) || [, ''])[1];
50+
}
51+
function retrievePresetId(str) {
52+
return (str.match(/[^#]*(?:[#](?!.*[#]))(.*)$/) || [, ''])[1];
5153
}
5254

53-
function getPreset(entryPath) {
54-
const preset = entryPath.split('#');
55-
if (preset[1]) return preset[1];
55+
function retrievePath(str) {
56+
return str.replace(/[@#][^@#]*$/, '');
5657
}
5758

5859
function setup(entryPath, id, babel) {
@@ -91,27 +92,24 @@ function setup(entryPath, id, babel) {
9192
});
9293
}
9394

94-
const transformId = getTransform(entryPath);
95-
const presetId = getPreset(entryPath);
95+
const transformId = retrieveTransformId(entryPath);
96+
const presetId = retrievePresetId(entryPath);
9697

97-
let cleanEntryPath = entryPath;
9898
let transformPkg;
9999
let transformModule;
100100

101101
if (transformId) {
102-
cleanEntryPath = entryPath.split('@')[0];
103-
transformPkg = require(cleanEntryPath);
102+
transformPkg = require(retrievePath(entryPath));
104103
transformModule = transformPkg.transforms[transformId];
105104
}
106105

107106
if (presetId) {
108-
cleanEntryPath = entryPath.split('#')[0];
109-
transformPkg = require(cleanEntryPath);
107+
transformPkg = require(retrievePath(entryPath));
110108
transformModule = transformPkg.presets[presetId];
111109
}
112110

113111
if (!transformId && !presetId) {
114-
transformModule = require(cleanEntryPath);
112+
transformModule = require(entryPath);
115113
}
116114

117115
transform =

packages/core/src/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export function run(entrypointPath: string, paths: string[], options: Flags) {
166166
ignores.add(options.ignorePattern);
167167
ignores.addFromFile(options.ignoreConfig);
168168

169-
if (!fs.existsSync(entrypointPath)) {
169+
if (!fs.existsSync(entrypointPath.replace(/[@#][^@#]*$/, ''))) {
170170
process.stderr.write(
171171
chalk.white.bgRed('ERROR') +
172172
' Transform file ' +

0 commit comments

Comments
 (0)