From 55c3bc6d049fd28fab87b5a76bc225075e818322 Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Thu, 9 Mar 2023 19:46:02 -0800 Subject: [PATCH 1/2] Revert to original copyInstructionsTask behavior of copying by default --- ...-e0d6790d-3823-4990-8bff-44914b63d4d3.json | 11 +++++++++ .../src/arrayUtils/uniqueValues.ts | 7 ------ .../just-scripts/src/copy/CopyInstruction.ts | 23 +++++++++---------- .../__tests__/executeCopyInstructions.spec.ts | 5 ++-- .../src/copy/executeCopyInstructions.ts | 22 +++++++----------- 5 files changed, 32 insertions(+), 36 deletions(-) create mode 100644 change/change-e0d6790d-3823-4990-8bff-44914b63d4d3.json delete mode 100644 packages/just-scripts/src/arrayUtils/uniqueValues.ts diff --git a/change/change-e0d6790d-3823-4990-8bff-44914b63d4d3.json b/change/change-e0d6790d-3823-4990-8bff-44914b63d4d3.json new file mode 100644 index 00000000..dec8bd7d --- /dev/null +++ b/change/change-e0d6790d-3823-4990-8bff-44914b63d4d3.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "type": "major", + "comment": "Revert to original copy instructions behavior of copying by default. To create symlinks instead, pass `symlink: true`.", + "packageName": "just-scripts", + "email": "elcraig@microsoft.com", + "dependentChangeType": "patch" + } + ] +} diff --git a/packages/just-scripts/src/arrayUtils/uniqueValues.ts b/packages/just-scripts/src/arrayUtils/uniqueValues.ts deleted file mode 100644 index c1f77bd1..00000000 --- a/packages/just-scripts/src/arrayUtils/uniqueValues.ts +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Removes duplicate numbers from an array - * @param array - The array possibly containing duplicate values - */ -export function uniqueValues(array: T[]): T[] { - return Array.from(new Set(array)); -} diff --git a/packages/just-scripts/src/copy/CopyInstruction.ts b/packages/just-scripts/src/copy/CopyInstruction.ts index 64a11d38..b1e17887 100644 --- a/packages/just-scripts/src/copy/CopyInstruction.ts +++ b/packages/just-scripts/src/copy/CopyInstruction.ts @@ -15,11 +15,10 @@ export interface CopyInstruction { destinationFilePath: string; /** - * Set to true if a copy or merge should be performed, false if a symlink should be created. - * If multiple source files are specified (i.e. a merge), this must be true or undefined. - * The default value of undefined is equivalent to true for a merge, false in all other cases. + * Set to true to create symlinks rather than copying. + * If multiple source files are specified (i.e. a merge), this must be false or unset. */ - noSymlink?: boolean; + symlink?: boolean; } export interface CopyConfig { @@ -34,12 +33,12 @@ export interface CopyConfig { export function copyFilesToDestinationDirectory( sourceFilePaths: string | string[], destinationDirectory: string, - noSymlinks?: boolean, + symlink?: boolean, ): CopyInstruction[] { return arrayify(sourceFilePaths).map(sourceName => ({ sourceFilePath: normalize(sourceName), destinationFilePath: join(destinationDirectory, basename(sourceName)), - noSymlink: noSymlinks, + symlink, })); } @@ -52,9 +51,9 @@ export function copyFileToDestinationDirectoryWithRename( sourceFilePath: string, destinationName: string, destinationDirectory: string, - noSymlink?: boolean, + symlink?: boolean, ): CopyInstruction[] { - return [{ sourceFilePath, destinationFilePath: join(destinationDirectory, destinationName), noSymlink }]; + return [{ sourceFilePath, destinationFilePath: join(destinationDirectory, destinationName), symlink }]; } /** @@ -65,12 +64,12 @@ export function copyFileToDestinationDirectoryWithRename( export function copyFilesToDestinationDirectoryWithRename( instrs: { sourceFilePath: string; destinationName: string }[], destinationDirectory: string, - noSymlinks?: boolean, + symlink?: boolean, ): CopyInstruction[] { return instrs.map(instr => ({ sourceFilePath: instr.sourceFilePath, destinationFilePath: join(destinationDirectory, instr.destinationName), - noSymlink: noSymlinks, + symlink, })); } @@ -82,7 +81,7 @@ export function copyFilesInDirectory( sourceDirectoryPath: string, outputDirectoryPath: string, filterFunction?: (file: string) => boolean, - noSymlinks?: boolean, + symlink?: boolean, ): CopyInstruction[] { let files = readdirSync(sourceDirectoryPath); @@ -92,7 +91,7 @@ export function copyFilesInDirectory( return files.map(file => ({ sourceFilePath: join(sourceDirectoryPath, file), destinationFilePath: join(outputDirectoryPath, file), - noSymlink: noSymlinks, + symlink, })); } diff --git a/packages/just-scripts/src/copy/__tests__/executeCopyInstructions.spec.ts b/packages/just-scripts/src/copy/__tests__/executeCopyInstructions.spec.ts index 1b685b83..42bc7754 100644 --- a/packages/just-scripts/src/copy/__tests__/executeCopyInstructions.spec.ts +++ b/packages/just-scripts/src/copy/__tests__/executeCopyInstructions.spec.ts @@ -1,7 +1,6 @@ import * as mockfs from 'mock-fs'; import * as path from 'path'; import * as fs from 'fs'; -// import { dirSync, fileSync, DirResult, FileResult } from 'tmp'; import { executeCopyInstructions } from '../executeCopyInstructions'; import { CopyInstruction } from '../CopyInstruction'; @@ -35,6 +34,7 @@ describe('executeCopyInstructions functional tests', () => { const copyInstruction: CopyInstruction = { sourceFilePath: sourceFilePath1, destinationFilePath: destFilePath, + symlink: true, }; expect(fs.existsSync(destFilePath)).toBeFalsy(); @@ -52,7 +52,6 @@ describe('executeCopyInstructions functional tests', () => { const copyInstruction: CopyInstruction = { sourceFilePath: [sourceFilePath1], destinationFilePath: destFilePath, - noSymlink: true, }; expect(fs.existsSync(destFilePath)).toBeFalsy(); @@ -89,7 +88,7 @@ describe('executeCopyInstructions functional tests', () => { const copyInstruction: CopyInstruction = { sourceFilePath: [sourceFilePath1, sourceFilePath2], destinationFilePath: destFilePath, - noSymlink: false, + symlink: true, }; const promise = executeCopyInstructions({ diff --git a/packages/just-scripts/src/copy/executeCopyInstructions.ts b/packages/just-scripts/src/copy/executeCopyInstructions.ts index e785e921..25d4f1ef 100644 --- a/packages/just-scripts/src/copy/executeCopyInstructions.ts +++ b/packages/just-scripts/src/copy/executeCopyInstructions.ts @@ -2,7 +2,6 @@ import { dirname, resolve } from 'path'; import { readFile, writeFile, copy, ensureDir, ensureSymlink } from 'fs-extra'; import { CopyInstruction, CopyConfig } from './CopyInstruction'; import { arrayify } from '../arrayUtils/arrayify'; -import { uniqueValues } from '../arrayUtils/uniqueValues'; /** * Function containing the core code for the copy task with a given config. @@ -17,34 +16,29 @@ export async function executeCopyInstructions(config: CopyConfig | undefined): P function validateConfig(copyInstructions: CopyInstruction[]) { copyInstructions.forEach(instr => { - if (instr.noSymlink === false && Array.isArray(instr.sourceFilePath) && instr.sourceFilePath.length > 1) { + if (instr.symlink && Array.isArray(instr.sourceFilePath) && instr.sourceFilePath.length > 1) { throw new Error('Multiple source files cannot be specified when making a symlink'); } }); } function createDirectories(copyInstructions: CopyInstruction[]) { - return Promise.all( - uniqueValues(copyInstructions.map(instruction => dirname(instruction.destinationFilePath))).map(dirname => - ensureDir(dirname), - ), - ); + const directories = new Set(copyInstructions.map(instruction => dirname(instruction.destinationFilePath))); + return Promise.all([...directories].map(dirname => ensureDir(dirname))); } -function executeSingleCopyInstruction(copyInstruction: CopyInstruction) { +async function executeSingleCopyInstruction(copyInstruction: CopyInstruction) { const sourceFileNames = arrayify(copyInstruction.sourceFilePath); // source and dest are 1-to-1? perform binary copy or symlink as desired. if (sourceFileNames.length === 1) { - if (copyInstruction.noSymlink) { - return copy(sourceFileNames[0], copyInstruction.destinationFilePath); - } else { + if (copyInstruction.symlink) { return ensureSymlink(resolve(sourceFileNames[0]), copyInstruction.destinationFilePath); } + return copy(sourceFileNames[0], copyInstruction.destinationFilePath); } // perform text merge operation. - return Promise.all(sourceFileNames.map(fileName => readFile(fileName))).then(fileContents => { - return writeFile(copyInstruction.destinationFilePath, fileContents.join('\n')); - }); + const sourceFiles = await Promise.all(sourceFileNames.map(fileName => readFile(fileName))); + return writeFile(copyInstruction.destinationFilePath, sourceFiles.join('\n')); } From c46c8dd615aa08dc7519bdab9f771b909de55715 Mon Sep 17 00:00:00 2001 From: Elizabeth Craig Date: Thu, 9 Mar 2023 19:50:00 -0800 Subject: [PATCH 2/2] disable scheduled release --- .github/workflows/release.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7c8c7604..514da645 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,10 +4,11 @@ name: Release on: + # Temporarily disabling scheduled releases to evaluate whether any other major changes are desired. # release daily at 8am UTC (midnight or 1am pacific) # https://crontab-generator.org/ - schedule: - - cron: '0 8 * * *' + # schedule: + # - cron: '0 8 * * *' # or manual trigger workflow_dispatch: