@cosmology/utils
Advanced tools
Comparing version 1.4.3 to 1.5.0
@@ -29,3 +29,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getServiceImplement = exports.buildImports = exports.getTypeNameFromFieldName = exports.getPluginValue = exports.swapKeyValue = void 0; | ||
exports.duplicateImportPathsWithExt = exports.restoreExtension = exports.getServiceImplement = exports.buildImports = exports.getTypeNameFromFieldName = exports.getPluginValue = exports.swapKeyValue = void 0; | ||
const minimatch_1 = __importDefault(require("minimatch")); | ||
@@ -140,1 +140,38 @@ const dotty = __importStar(require("dotty")); | ||
exports.getServiceImplement = getServiceImplement; | ||
/** | ||
* Add extension to path | ||
*/ | ||
const restoreExtension = (path, ext) => { | ||
if (!ext) { | ||
return path; | ||
} | ||
const fixedExt = ext.startsWith(".") ? ext : `.${ext}`; | ||
if (path.startsWith(".") && | ||
!path.endsWith(".js") && | ||
!path.endsWith(fixedExt)) { | ||
return `${path}${fixedExt}`; | ||
} | ||
return path; | ||
}; | ||
exports.restoreExtension = restoreExtension; | ||
/** | ||
* To duplicate the import paths with the extension. | ||
* @param paths ImportDeclarations | ||
* @param ext extension | ||
* @returns duplicated import paths with the extension | ||
*/ | ||
const duplicateImportPathsWithExt = (paths, ext) => { | ||
if (!ext) { | ||
return paths; | ||
} | ||
return paths.map(path => { | ||
return { | ||
...path, | ||
source: { | ||
...path.source, | ||
value: (0, exports.restoreExtension)(path.source.value, ext) | ||
} | ||
}; | ||
}); | ||
}; | ||
exports.duplicateImportPathsWithExt = duplicateImportPathsWithExt; |
@@ -105,1 +105,36 @@ import minimatch from "minimatch"; | ||
}; | ||
/** | ||
* Add extension to path | ||
*/ | ||
export const restoreExtension = (path, ext) => { | ||
if (!ext) { | ||
return path; | ||
} | ||
const fixedExt = ext.startsWith(".") ? ext : `.${ext}`; | ||
if (path.startsWith(".") && | ||
!path.endsWith(".js") && | ||
!path.endsWith(fixedExt)) { | ||
return `${path}${fixedExt}`; | ||
} | ||
return path; | ||
}; | ||
/** | ||
* To duplicate the import paths with the extension. | ||
* @param paths ImportDeclarations | ||
* @param ext extension | ||
* @returns duplicated import paths with the extension | ||
*/ | ||
export const duplicateImportPathsWithExt = (paths, ext) => { | ||
if (!ext) { | ||
return paths; | ||
} | ||
return paths.map(path => { | ||
return { | ||
...path, | ||
source: { | ||
...path.source, | ||
value: restoreExtension(path.source.value, ext) | ||
} | ||
}; | ||
}); | ||
}; |
{ | ||
"name": "@cosmology/utils", | ||
"version": "1.4.3", | ||
"version": "1.5.0", | ||
"description": "Telescope utils", | ||
@@ -77,6 +77,6 @@ "author": "Dan Lynch <pyramation@gmail.com>", | ||
"dependencies": { | ||
"@cosmology/types": "^1.4.3", | ||
"@cosmology/types": "^1.5.0", | ||
"dotty": "0.1.2" | ||
}, | ||
"gitHead": "565c9267b5f7438b8ecfbdf54ade7374c2df4782" | ||
"gitHead": "8d975f29b54ef773af98ce65a851a4b35b14e07e" | ||
} |
@@ -8,2 +8,3 @@ import minimatch from "minimatch"; | ||
} from "@cosmology/types"; | ||
import { ImportDeclaration } from "@babel/types"; | ||
import * as dotty from "dotty"; | ||
@@ -163,1 +164,44 @@ | ||
}; | ||
/** | ||
* Add extension to path | ||
*/ | ||
export const restoreExtension = (path: string, ext?: string) => { | ||
if (!ext) { | ||
return path; | ||
} | ||
const fixedExt = ext.startsWith(".") ? ext : `.${ext}`; | ||
if ( | ||
path.startsWith(".") && | ||
!path.endsWith(".js") && | ||
!path.endsWith(fixedExt) | ||
) { | ||
return `${path}${fixedExt}`; | ||
} | ||
return path; | ||
}; | ||
/** | ||
* To duplicate the import paths with the extension. | ||
* @param paths ImportDeclarations | ||
* @param ext extension | ||
* @returns duplicated import paths with the extension | ||
*/ | ||
export const duplicateImportPathsWithExt = (paths: ImportDeclaration[], ext?: string) => { | ||
if(!ext){ | ||
return paths; | ||
} | ||
return paths.map(path => { | ||
return { | ||
...path, | ||
source: { | ||
...path.source, | ||
value: restoreExtension(path.source.value, ext) | ||
} | ||
} | ||
}) | ||
}; |
import { TelescopeOptions, TelescopeOption, ProtoRef, ImportUsage } from "@cosmology/types"; | ||
import { ImportDeclaration } from "@babel/types"; | ||
/** | ||
@@ -37,1 +38,12 @@ * swap the key and value of the input object | ||
}) => string; | ||
/** | ||
* Add extension to path | ||
*/ | ||
export declare const restoreExtension: (path: string, ext?: string) => string; | ||
/** | ||
* To duplicate the import paths with the extension. | ||
* @param paths ImportDeclarations | ||
* @param ext extension | ||
* @returns duplicated import paths with the extension | ||
*/ | ||
export declare const duplicateImportPathsWithExt: (paths: ImportDeclaration[], ext?: string) => ImportDeclaration[]; |
79752
2141
Updated@cosmology/types@^1.5.0