From 49b7bcb154dfae9434674ee0367e455e3c01f6ad Mon Sep 17 00:00:00 2001 From: Daniel Del Core Date: Fri, 28 Jan 2022 22:39:51 +1100 Subject: [PATCH] moved to path.join --- .changeset/happy-bulldogs-refuse.md | 5 ++++ packages/initializer/src/index.ts | 39 ++++++++++++++++++----------- 2 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 .changeset/happy-bulldogs-refuse.md diff --git a/.changeset/happy-bulldogs-refuse.md b/.changeset/happy-bulldogs-refuse.md new file mode 100644 index 000000000..ee3a1c5b0 --- /dev/null +++ b/.changeset/happy-bulldogs-refuse.md @@ -0,0 +1,5 @@ +--- +'@codeshift/initializer': patch +--- + +Usage path module over string concatinations for better cross OS support diff --git a/packages/initializer/src/index.ts b/packages/initializer/src/index.ts index 4760c5322..a66b64d62 100644 --- a/packages/initializer/src/index.ts +++ b/packages/initializer/src/index.ts @@ -103,14 +103,20 @@ export function initDirectory( targetPath: string = './', isReduced: boolean = false, ) { - const basePath = `${targetPath}/${packageName.replace('/', '__')}`; - const configPath = `${basePath}${ - !isReduced ? '/src' : '' - }/codeshift.config.js`; + const basePath = path.join(targetPath, packageName.replace('/', '__')); + const configPath = path.join( + basePath, + !isReduced ? 'src' : '', + 'codeshift.config.js', + ); - fs.copySync(`${__dirname}/../template${isReduced ? '/src' : ''}`, basePath, { - filter: src => !src.includes('src/codemod'), - }); + fs.copySync( + path.join(__dirname, '..', 'template', isReduced ? 'src' : ''), + basePath, + { + filter: src => !src.includes('src/codemod'), + }, + ); if (!isReduced) { fs.writeFileSync( @@ -135,19 +141,24 @@ export function initTransform( throw new Error(`Provided version ${id} is not a valid semver version`); } - const basePath = `${targetPath}/${packageName.replace('/', '__')}`; - const transformPath = `${basePath}${!isReduced ? '/src' : ''}/${id}`; - const configPath = `${basePath}${ - !isReduced ? '/src' : '' - }/codeshift.config.js`; + const basePath = path.join(targetPath, packageName.replace('/', '__')); + const transformPath = path.join(basePath, !isReduced ? 'src' : '', id); + const configPath = path.join( + basePath, + !isReduced ? 'src' : '', + 'codeshift.config.js', + ); if (fs.existsSync(transformPath)) { throw new Error(`Codemod for ${type} "${id}" already exists`); } - fs.copySync(`${__dirname}/../template${isReduced ? '/src' : ''}`, basePath); + fs.copySync( + path.join(__dirname, '..', 'template', isReduced ? 'src' : ''), + basePath, + ); fs.renameSync( - `${basePath}${!isReduced ? '/src' : ''}/codemod`, + path.join(basePath, !isReduced ? 'src' : '', 'codemod'), transformPath, );