From 8d8bca8fdd1fe8db15d24e67ab7e7ea18762157c Mon Sep 17 00:00:00 2001 From: FrozenPandaz Date: Tue, 25 Apr 2023 12:20:11 -0400 Subject: [PATCH] chore(repo): do not replace legacy package mentions in binary files --- .../devkit/src/generators/generate-files.ts | 37 +------------------ .../devkit/src/utils/binary-extensions.ts | 33 +++++++++++++++++ packages/devkit/src/utils/replace-package.ts | 7 +++- 3 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 packages/devkit/src/utils/binary-extensions.ts diff --git a/packages/devkit/src/generators/generate-files.ts b/packages/devkit/src/generators/generate-files.ts index cfd3d28343ac54..a01e04c6c59f06 100644 --- a/packages/devkit/src/generators/generate-files.ts +++ b/packages/devkit/src/generators/generate-files.ts @@ -2,43 +2,10 @@ import { readFileSync, readdirSync, statSync } from 'fs'; import * as path from 'path'; import type { Tree } from 'nx/src/generators/tree'; import { requireNx } from '../../nx'; +import { binaryExtensions } from '../utils/binary-extensions'; const { logger } = requireNx(); -const binaryExts = new Set([ - // // Image types originally from https://github.com/sindresorhus/image-type/blob/5541b6a/index.js - '.jpg', - '.jpeg', - '.png', - '.gif', - '.webp', - '.flif', - '.cr2', - '.tif', - '.bmp', - '.jxr', - '.psd', - '.ico', - '.bpg', - '.jp2', - '.jpm', - '.jpx', - '.heic', - '.cur', - '.tgz', - - // Java files - '.jar', - '.keystore', - - // Font files - '.ttf', - '.otf', - '.woff', - '.woff2', - '.eot', -]); - /** * Generates a folder of files based on provided templates. * @@ -84,7 +51,7 @@ export function generateFiles( substitutions ); - if (binaryExts.has(path.extname(filePath))) { + if (binaryExtensions.has(path.extname(filePath))) { newContent = readFileSync(filePath); } else { const template = readFileSync(filePath, 'utf-8'); diff --git a/packages/devkit/src/utils/binary-extensions.ts b/packages/devkit/src/utils/binary-extensions.ts new file mode 100644 index 00000000000000..8bdcfbb874b535 --- /dev/null +++ b/packages/devkit/src/utils/binary-extensions.ts @@ -0,0 +1,33 @@ +export const binaryExtensions = new Set([ + // // Image types originally from https://github.com/sindresorhus/image-type/blob/5541b6a/index.js + '.jpg', + '.jpeg', + '.png', + '.gif', + '.webp', + '.flif', + '.cr2', + '.tif', + '.bmp', + '.jxr', + '.psd', + '.ico', + '.bpg', + '.jp2', + '.jpm', + '.jpx', + '.heic', + '.cur', + '.tgz', + + // Java files + '.jar', + '.keystore', + + // Font files + '.ttf', + '.otf', + '.woff', + '.woff2', + '.eot', +]); diff --git a/packages/devkit/src/utils/replace-package.ts b/packages/devkit/src/utils/replace-package.ts index e54cc77806319b..dc8d3f3eaa5e15 100644 --- a/packages/devkit/src/utils/replace-package.ts +++ b/packages/devkit/src/utils/replace-package.ts @@ -3,7 +3,8 @@ import type { PackageJson } from 'nx/src/utils/package-json'; import { requireNx } from '../../nx'; import { NX_VERSION } from './package-json'; import { visitNotIgnoredFiles } from '../generators/visit-not-ignored-files'; -import { basename } from 'path'; +import { basename, extname } from 'path'; +import { binaryExtensions } from './binary-extensions'; const { getProjects, @@ -148,6 +149,10 @@ function replaceMentions( newPackageName: string ) { visitNotIgnoredFiles(tree, '.', (path) => { + if (binaryExtensions.has(extname(path))) { + return; + } + const ignoredFiles = [ 'yarn.lock', 'package-lock.json',