From e5ffbf5abd3a607ed8b235390151c2249bc448de Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Fri, 21 Jun 2024 22:02:06 +0200 Subject: [PATCH 1/4] fix(vercel): Lock vercel version when building See vercel/vercel#11097 for more info --- packages/vercel/src/executors/build/build.impl.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/vercel/src/executors/build/build.impl.ts b/packages/vercel/src/executors/build/build.impl.ts index 0b2b70cb..0adbbe8b 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}`, @@ -115,7 +116,7 @@ export function buildExecutor( }) 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)}`, From 10542684c00f569c03453fa63bf08c007934320b Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Fri, 21 Jun 2024 22:24:43 +0200 Subject: [PATCH 2/4] feat(translations): Updated plugin to `CreateNodesV2` --- packages/translations/plugin.ts | 2 +- packages/translations/src/plugins/plugin.ts | 107 ++++++------------ .../translations/src/utils/config-file.ts | 2 +- 3 files changed, 39 insertions(+), 72 deletions(-) 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..9f0ceef2 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 {} - } - - const config = getConfigFileInRoot(projectRoot) - options = normalizeOptions(options) + async (configFiles, options: TranslationPluginOptions, context): Promise => { + console.log('context.workspaceRoot',context.workspaceRoot) + 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)) From 239bc1227dc9eccf53a9b01d4fc12330d4bca2da Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Thu, 27 Jun 2024 12:28:22 +0200 Subject: [PATCH 3/4] refactor(translations): Remove console.log --- packages/translations/src/plugins/plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/translations/src/plugins/plugin.ts b/packages/translations/src/plugins/plugin.ts index 9f0ceef2..9713e3a7 100644 --- a/packages/translations/src/plugins/plugin.ts +++ b/packages/translations/src/plugins/plugin.ts @@ -18,7 +18,7 @@ export interface TranslationPluginOptions { export const createNodesV2: CreateNodesV2 = [ '**/.translationsrc.json', async (configFiles, options: TranslationPluginOptions, context): Promise => { - console.log('context.workspaceRoot',context.workspaceRoot) + return createNodesFromFiles( createTargets, configFiles, From dc79b44d92495c2f7ee8e665b0b8b730280bf376 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Tue, 2 Jul 2024 17:50:51 +0200 Subject: [PATCH 4/4] feat(vercel): Update to node version 20.x BREAKING CHANGE: Default node version is now 20.x --- packages/vercel/src/executors/build/build.impl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vercel/src/executors/build/build.impl.ts b/packages/vercel/src/executors/build/build.impl.ts index 0adbbe8b..07bc51fc 100644 --- a/packages/vercel/src/executors/build/build.impl.ts +++ b/packages/vercel/src/executors/build/build.impl.ts @@ -111,7 +111,7 @@ export function buildExecutor( outputDirectory: getOutputDirectory(framework, outputDirectory), rootDirectory: null, directoryListing: false, - nodeVersion: options.nodeVersion || '18.x' + nodeVersion: options.nodeVersion || '20.x' } })