diff --git a/packages/translations/plugin.ts b/packages/translations/plugin.ts index 4c5de8ee..67dde227 100644 --- a/packages/translations/plugin.ts +++ b/packages/translations/plugin.ts @@ -1 +1 @@ -export { createNodes, createDependencies, TranslationPluginOptions } from './src/plugins/plugin' +export * from './src/plugins/plugin' diff --git a/packages/translations/src/plugins/plugin.ts b/packages/translations/src/plugins/plugin.ts index c8da0fc2..9713e3a7 100644 --- a/packages/translations/src/plugins/plugin.ts +++ b/packages/translations/src/plugins/plugin.ts @@ -1,19 +1,11 @@ -import { - CreateDependencies, - CreateNodes, - CreateNodesContext, - detectPackageManager, - readJsonFile, - TargetConfiguration, - writeJsonFile -} from '@nx/devkit' -import { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes' +import { createNodesFromFiles } from '@nx/devkit' import { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs' -import { existsSync, readdirSync } from 'fs' -import { getLockFileName } from 'nx/src/plugins/js/lock-file/lock-file' -import { workspaceDataDirectory } from 'nx/src/utils/cache-directory' +import { readdirSync } from 'fs' import { dirname, join } from 'path' +import type { CreateNodesResultV2, CreateNodesV2, TargetConfiguration } from '@nx/devkit' +import type { CreateNodesContext, CreateNodesResult } from '@nx/devkit' + import { BaseConfigFile, getConfigFileInRoot } from '../utils/config-file' export interface TranslationPluginOptions { @@ -23,71 +15,46 @@ export interface TranslationPluginOptions { translateTargetName?: string } -const cachePath = join(workspaceDataDirectory, 'nx-extend.translations.hash') -const targetsCache = existsSync(cachePath) ? readTargetsCache() : {} - -const calculatedTargets: Record< - string, - Record -> = {} - -function readTargetsCache(): Record< - string, - Record -> { - return readJsonFile(cachePath) -} - -function writeTargetsToCache( - targets: Record> -) { - writeJsonFile(cachePath, targets) -} - -export const createDependencies: CreateDependencies = () => { - writeTargetsToCache(calculatedTargets) - - return [] -} - -export const createNodes: CreateNodes = [ +export const createNodesV2: CreateNodesV2 = [ '**/.translationsrc.json', - async (configFilePath, options, context) => { - const projectRoot = dirname(configFilePath) - const fullyQualifiedProjectRoot = join(context.workspaceRoot, projectRoot) - - // Do not create a project if package.json and project.json isn't there - const siblingFiles = readdirSync(fullyQualifiedProjectRoot) - if (!siblingFiles.includes('project.json') || siblingFiles.includes('nx.json')) { - return {} - } + async (configFiles, options: TranslationPluginOptions, context): Promise => { - const config = getConfigFileInRoot(projectRoot) - options = normalizeOptions(options) + return createNodesFromFiles( + createTargets, + configFiles, + options, + context + ) + } +] - const hash = await calculateHashForCreateNodes(projectRoot, options, context, [ - getLockFileName(detectPackageManager(context.workspaceRoot)) - ]) +function createTargets(projectConfigurationFile: string, options: TranslationPluginOptions, context: CreateNodesContext): CreateNodesResult { + const projectRoot = dirname(projectConfigurationFile) + const fullyQualifiedProjectRoot = join(context.workspaceRoot, projectRoot) - const targets = targetsCache[hash] ?? buildTranslationTargets( - projectRoot, - context, - config, - options - ) + // Do not create a project if package.json and project.json isn't there + const siblingFiles = readdirSync(fullyQualifiedProjectRoot) + if (!siblingFiles.includes('project.json') || siblingFiles.includes('nx.json')) { + return {} + } - calculatedTargets[hash] = targets + const config = getConfigFileInRoot(projectRoot) + options = normalizeOptions(options) - return { - projects: { - [projectRoot]: { - root: projectRoot, - targets: targets - } + return { + projects: { + [projectRoot]: { + root: projectRoot, + targets: buildTranslationTargets( + projectRoot, + context, + config, + options + ) } } } -] +} function buildTranslationTargets( projectRoot: string, diff --git a/packages/translations/src/utils/config-file.ts b/packages/translations/src/utils/config-file.ts index 3c9d234f..5af5a73c 100644 --- a/packages/translations/src/utils/config-file.ts +++ b/packages/translations/src/utils/config-file.ts @@ -88,7 +88,7 @@ export const getConfigFileInRoot = ( return configFile as Config } -export const updateConfigFile = (context: ExecutorContext, update): void => { +export const updateConfigFile = (context: ExecutorContext, update: object): void => { const fileLocation = resolve(getProjectRoot(context), '.translationsrc.json') writeJsonFile(fileLocation, Object.assign(readJsonFile(fileLocation), update)) diff --git a/packages/vercel/src/executors/build/build.impl.ts b/packages/vercel/src/executors/build/build.impl.ts index 0b2b70cb..07bc51fc 100644 --- a/packages/vercel/src/executors/build/build.impl.ts +++ b/packages/vercel/src/executors/build/build.impl.ts @@ -71,11 +71,12 @@ export function buildExecutor( settings: {} }) + const vercelCommand = 'npx vercel@33.0.2' const vercelEnvironment = context.configurationName === 'production' ? 'production' : 'preview' // Pull latest const { success: pullSuccess } = execCommand(buildCommand([ - 'npx vercel pull --yes', + `${vercelCommand} pull --yes`, `--environment=${vercelEnvironment}`, vercelToken && `--token=${vercelToken}`, @@ -110,12 +111,12 @@ export function buildExecutor( outputDirectory: getOutputDirectory(framework, outputDirectory), rootDirectory: null, directoryListing: false, - nodeVersion: options.nodeVersion || '18.x' + nodeVersion: options.nodeVersion || '20.x' } }) const { success } = execCommand(buildCommand([ - 'npx vercel build', + `${vercelCommand} build`, `--output ${outputDirectory}/.vercel/output`, context.configurationName === 'production' && '--prod', options.config && `--local-config=${join(workspaceRoot, options.config)}`,