Skip to content

Commit

Permalink
chore: buffer instead of utf8 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed May 24, 2024
1 parent aed5038 commit 10a9c73
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"dependencies": {
"@oclif/core": "^3.26.6",
"@salesforce/core": "^7.3.9",
"@salesforce/kit": "^3.1.1",
"@salesforce/kit": "^3.1.2",
"@salesforce/source-deploy-retrieve": "^11.6.2",
"@salesforce/ts-types": "^2.0.9",
"fast-xml-parser": "^4.3.6",
Expand Down
2 changes: 1 addition & 1 deletion src/shared/local/moveDetection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ const getHashForAddedFile =
async (filepath: string): Promise<FilenameBasenameHash> => ({
filename: filepath,
basename: path.basename(filepath),
hash: (await git.hashBlob({ object: await fs.promises.readFile(path.join(projectPath, filepath), 'utf8') })).oid,
hash: (await git.hashBlob({ object: await fs.promises.readFile(path.join(projectPath, filepath)) })).oid,
});

const resolveType = (resolver: MetadataResolver, filenames: string[]): SourceComponent[] =>
Expand Down
61 changes: 34 additions & 27 deletions test/nuts/local/localTrackingFileMovesDecomposedChild.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import { ShadowRepo } from '../../../src/shared/local/localShadowRepo';
/* eslint-disable no-unused-expressions */

describe('ignores moved files that are children of a decomposed metadata type', () => {
const FIELD = path.join('fields', 'Account__c.field-meta.xml');
let session: TestSession;
let repo: ShadowRepo;
let filesToSync: string[];
let objectsDir: string;

before(async () => {
session = await TestSession.create({
Expand All @@ -26,12 +27,17 @@ describe('ignores moved files that are children of a decomposed metadata type',
},
devhubAuthStrategy: 'NONE',
});
objectsDir = path.join(session.project.dir, 'force-app', 'main', 'default', 'objects');
});

after(async () => {
await session?.clean();
});

afterEach(() => {
delete process.env.SF_BETA_TRACK_FILE_MOVES;
});

it('initialize the local tracking', async () => {
repo = await ShadowRepo.getInstance({
orgId: 'fakeOrgId',
Expand All @@ -44,32 +50,12 @@ describe('ignores moved files that are children of a decomposed metadata type',
it('should ignore moved child metadata', async () => {
expect(process.env.SF_BETA_TRACK_FILE_MOVES).to.be.undefined;
process.env.SF_BETA_TRACK_FILE_MOVES = 'true';
// Commit the existing class files
filesToSync = await repo.getChangedFilenames();
// Commit the existing files
const filesToSync = await repo.getChangedFilenames();
await repo.commitChanges({ deployedFiles: filesToSync });

// move all the classes to the new folder
const objectFieldOld = path.join(
session.project.dir,
'force-app',
'main',
'default',
'objects',
'Order__c',
'fields',
'Account__c.field-meta.xml'
);
const objectFieldNew = path.join(
session.project.dir,
'force-app',
'main',
'default',
'objects',
'Product__c',
'fields',
'Account__c.field-meta.xml'
);
// fs.mkdirSync(path.join(session.project.dir, 'force-app', 'main', 'foo'), { recursive: true });
// move the field from one object to another
const objectFieldOld = path.join(objectsDir, 'Order__c', FIELD);
const objectFieldNew = path.join(objectsDir, 'Product__c', FIELD);
fs.renameSync(objectFieldOld, objectFieldNew);

await repo.getStatus(true);
Expand All @@ -78,6 +64,27 @@ describe('ignores moved files that are children of a decomposed metadata type',
.to.be.an('array')
.with.lengthOf(2);

delete process.env.SF_BETA_TRACK_FILE_MOVES;
// put it back how it was and verify the tracking
fs.renameSync(objectFieldNew, objectFieldOld);
await repo.getStatus(true);

expect(await repo.getChangedFilenames())
.to.be.an('array')
.with.lengthOf(0);
});

it('should clear tracking when the field is moved to another dir', async () => {
const newDir = path.join(session.project.dir, 'force-app', 'other', 'objects', 'Order__c', 'fields');
await fs.promises.mkdir(newDir, {
recursive: true,
});
const objectFieldOld = path.join(objectsDir, 'Order__c', FIELD);
const objectFieldNew = path.join(objectsDir, 'Order__c', FIELD);
fs.renameSync(objectFieldOld, objectFieldNew);
await repo.getStatus(true);

expect(await repo.getChangedFilenames())
.to.be.an('array')
.with.lengthOf(0);
});
});
24 changes: 5 additions & 19 deletions test/nuts/local/localTrackingFileMovesImage.nut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('it detects image file moves ', () => {
let session: TestSession;
let repo: ShadowRepo;
let filesToSync: string[];
let staticDir: string;

before(async () => {
session = await TestSession.create({
Expand All @@ -27,6 +28,7 @@ describe('it detects image file moves ', () => {
},
devhubAuthStrategy: 'NONE',
});
staticDir = path.join(session.project.dir, 'force-app', 'main', 'default', 'staticresources');
});

after(async () => {
Expand All @@ -50,28 +52,12 @@ describe('it detects image file moves ', () => {
await repo.commitChanges({ deployedFiles: filesToSync });

// move all the classes to the new folder
fs.mkdirSync(path.join(session.project.dir, 'force-app', 'main', 'default', 'staticresources', 'bike_assets_new'), {
fs.mkdirSync(path.join(staticDir, 'bike_assets_new'), {
recursive: true,
});
fs.renameSync(
path.join(
session.project.dir,
'force-app',
'main',
'default',
'staticresources',
'bike_assets',
'CyclingGrass.jpg'
),
path.join(
session.project.dir,
'force-app',
'main',
'default',
'staticresources',
'bike_assets_new',
'CyclingGrass.jpg'
)
path.join(staticDir, 'bike_assets', 'CyclingGrass.jpg'),
path.join(staticDir, 'bike_assets_new', 'CyclingGrass.jpg')
);

await repo.getStatus(true);
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,14 @@
"@salesforce/ts-types" "^2.0.9"
tslib "^2.6.2"

"@salesforce/kit@^3.1.2":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@salesforce/kit/-/kit-3.1.2.tgz#270741c54c70969df19ef17f8979b4ef1fa664b2"
integrity sha512-si+ddvZDgx9q5czxAANuK5xhz3pv+KGspQy1wyia/7HDPKadA0QZkLTzUnO1Ju4Mux32CNHEb2y9lw9jj+eVTA==
dependencies:
"@salesforce/ts-types" "^2.0.9"
tslib "^2.6.2"

"@salesforce/prettier-config@^0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@salesforce/prettier-config/-/prettier-config-0.0.3.tgz#ba648d4886bb38adabe073dbea0b3a91b3753bb0"
Expand Down

0 comments on commit 10a9c73

Please sign in to comment.