fix(core): do not replace legacy package mentions in binary files (#16547)
This commit is contained in:
parent
b374bd342c
commit
cba3c48e6c
@ -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 { isBinaryPath } 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 (isBinaryPath(filePath)) {
|
||||
newContent = readFileSync(filePath);
|
||||
} else {
|
||||
const template = readFileSync(filePath, 'utf-8');
|
||||
|
||||
48
packages/devkit/src/utils/binary-extensions.ts
Normal file
48
packages/devkit/src/utils/binary-extensions.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { extname } from 'path';
|
||||
|
||||
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',
|
||||
'.avif',
|
||||
'.dcm',
|
||||
|
||||
// Compressed files
|
||||
'.tgz',
|
||||
'.gz',
|
||||
'.zip',
|
||||
|
||||
// Documents
|
||||
'.pdf',
|
||||
|
||||
// Java files
|
||||
'.jar',
|
||||
'.keystore',
|
||||
|
||||
// Font files
|
||||
'.ttf',
|
||||
'.otf',
|
||||
'.woff',
|
||||
'.woff2',
|
||||
'.eot',
|
||||
]);
|
||||
|
||||
export function isBinaryPath(path: string): boolean {
|
||||
return binaryExtensions.has(extname(path));
|
||||
}
|
||||
@ -4,6 +4,7 @@ import { requireNx } from '../../nx';
|
||||
import { NX_VERSION } from './package-json';
|
||||
import { visitNotIgnoredFiles } from '../generators/visit-not-ignored-files';
|
||||
import { basename } from 'path';
|
||||
import { isBinaryPath } from './binary-extensions';
|
||||
|
||||
const {
|
||||
getProjects,
|
||||
@ -148,6 +149,10 @@ function replaceMentions(
|
||||
newPackageName: string
|
||||
) {
|
||||
visitNotIgnoredFiles(tree, '.', (path) => {
|
||||
if (isBinaryPath(path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const ignoredFiles = [
|
||||
'yarn.lock',
|
||||
'package-lock.json',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user