@nx/devkit
Advanced tools
Comparing version 20.2.1 to 20.3.0-beta.0
{ | ||
"name": "@nx/devkit", | ||
"version": "20.2.1", | ||
"version": "20.3.0-beta.0", | ||
"private": false, | ||
@@ -5,0 +5,0 @@ "description": "The Nx Devkit is used to customize Nx for different technologies and use cases. It contains many utility functions for reading and writing files, updating configuration, working with Abstract Syntax Trees(ASTs), and more. Learn more about [extending Nx by leveraging the Nx Devkit](https://nx.dev/extending-nx/intro/getting-started) on our docs.", |
@@ -5,6 +5,15 @@ import { type Tree } from 'nx/src/devkit-exports'; | ||
name?: string; | ||
fileExtension?: 'js' | 'jsx' | 'ts' | 'tsx' | 'vue'; | ||
fileName?: string; | ||
fileExtension?: string; | ||
suffix?: string; | ||
allowedFileExtensions?: string[]; | ||
/** | ||
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21. | ||
*/ | ||
js?: boolean; | ||
/** | ||
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21. | ||
*/ | ||
jsOptionName?: string; | ||
}; | ||
export type FileExtensionType = 'js' | 'ts' | 'other'; | ||
export type NameAndDirectoryOptions = { | ||
@@ -24,2 +33,10 @@ /** | ||
/** | ||
* Normalized file extension. | ||
*/ | ||
fileExtension: string; | ||
/** | ||
* Normalized file extension type. | ||
*/ | ||
fileExtensionType: FileExtensionType; | ||
/** | ||
* Normalized full file path of the artifact. | ||
@@ -26,0 +43,0 @@ */ |
@@ -9,2 +9,9 @@ "use strict"; | ||
const path_1 = require("path"); | ||
const DEFAULT_ALLOWED_JS_FILE_EXTENSIONS = ['js', 'cjs', 'mjs', 'jsx']; | ||
const DEFAULT_ALLOWED_TS_FILE_EXTENSIONS = ['ts', 'cts', 'mts', 'tsx']; | ||
const DEFAULT_ALLOWED_FILE_EXTENSIONS = [ | ||
...DEFAULT_ALLOWED_JS_FILE_EXTENSIONS, | ||
...DEFAULT_ALLOWED_TS_FILE_EXTENSIONS, | ||
'vue', | ||
]; | ||
async function determineArtifactNameAndDirectoryOptions(tree, options) { | ||
@@ -19,3 +26,2 @@ const normalizedOptions = getNameAndDirectoryOptions(tree, options); | ||
: undefined; | ||
const fileExtension = options.fileExtension ?? 'ts'; | ||
let { name: extractedName, directory } = extractNameAndDirectoryFromPath(path); | ||
@@ -28,11 +34,26 @@ const relativeCwd = getRelativeCwd(); | ||
const project = findProjectFromPath(tree, directory); | ||
const name = options.fileName ?? | ||
(options.suffix ? `${extractedName}.${options.suffix}` : extractedName); | ||
const filePath = (0, devkit_exports_1.joinPathFragments)(directory, `${name}.${fileExtension}`); | ||
let fileName = extractedName; | ||
let fileExtension = options.fileExtension ?? 'ts'; | ||
const allowedFileExtensions = options.allowedFileExtensions ?? DEFAULT_ALLOWED_FILE_EXTENSIONS; | ||
const fileExtensionRegex = new RegExp(`\\.(${allowedFileExtensions.join('|')})$`); | ||
const fileExtensionMatch = fileName.match(fileExtensionRegex); | ||
if (fileExtensionMatch) { | ||
fileExtension = fileExtensionMatch[1]; | ||
fileName = fileName.replace(fileExtensionRegex, ''); | ||
extractedName = fileName; | ||
} | ||
else if (options.suffix) { | ||
fileName = `${fileName}.${options.suffix}`; | ||
} | ||
const filePath = (0, devkit_exports_1.joinPathFragments)(directory, `${fileName}.${fileExtension}`); | ||
const fileExtensionType = getFileExtensionType(fileExtension); | ||
validateFileExtension(fileExtension, allowedFileExtensions, options.js, options.jsOptionName); | ||
return { | ||
artifactName: options.name ?? extractedName, | ||
directory: directory, | ||
fileName: name, | ||
filePath: filePath, | ||
project: project, | ||
directory, | ||
fileName, | ||
fileExtension, | ||
fileExtensionType, | ||
filePath, | ||
project, | ||
}; | ||
@@ -78,1 +99,29 @@ } | ||
} | ||
function getFileExtensionType(fileExtension) { | ||
if (DEFAULT_ALLOWED_JS_FILE_EXTENSIONS.includes(fileExtension)) { | ||
return 'js'; | ||
} | ||
if (DEFAULT_ALLOWED_TS_FILE_EXTENSIONS.includes(fileExtension)) { | ||
return 'ts'; | ||
} | ||
return 'other'; | ||
} | ||
function validateFileExtension(fileExtension, allowedFileExtensions, js, jsOptionName) { | ||
const fileExtensionType = getFileExtensionType(fileExtension); | ||
if (!allowedFileExtensions.includes(fileExtension)) { | ||
throw new Error(`The provided file path has an extension (.${fileExtension}) that is not supported by this generator. | ||
The supported extensions are: ${allowedFileExtensions | ||
.map((ext) => `.${ext}`) | ||
.join(', ')}.`); | ||
} | ||
if (js !== undefined) { | ||
jsOptionName = jsOptionName ?? 'js'; | ||
if (js && fileExtensionType === 'ts') { | ||
throw new Error(`The provided file path has an extension (.${fileExtension}) that conflicts with the provided "--${jsOptionName}" option.`); | ||
} | ||
if (!js && fileExtensionType === 'js') { | ||
throw new Error(`The provided file path has an extension (.${fileExtension}) that conflicts with the provided "--${jsOptionName}" option.`); | ||
} | ||
} | ||
return fileExtensionType; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
208015
5126
1