Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(rosetta): _fingerprint() does not attempt to generate new fingerprint #3146

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions packages/jsii-rosetta/lib/jsii/assemblies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as spec from '@jsii/spec';
import * as crypto from 'crypto';
import * as fs from 'fs-extra';
import * as path from 'path';

Expand All @@ -18,9 +17,6 @@ import { enforcesStrictMode } from '../strict';
import { LanguageTablet, DEFAULT_TABLET_NAME } from '../tablets/tablets';
import { fmap, mkDict, sortBy } from '../util';

// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const sortJson = require('sort-json');

/**
* The JSDoc tag users can use to associate non-visible metadata with an example
*
Expand Down Expand Up @@ -216,14 +212,16 @@ export async function replaceAssembly(assembly: spec.Assembly, directory: string
}

/**
* This function is copied from `packages/jsii/lib/assembler.ts`.
* We should make sure not to change one without changing the other as well.
* Replaces the old fingerprint with '***********'.
*
* @rmuller says fingerprinting is useless, as we do not actually check
* if an assembly is changed. Instead of keeping the old (wrong) fingerprint
* or spending extra time calculating a new fingerprint, we replace with '**********'
* that demonstrates the fingerprint has changed.
*/
function _fingerprint(assembly: spec.Assembly): spec.Assembly {
delete (assembly as any).fingerprint;
assembly = sortJson(assembly);
const fingerprint = crypto.createHash('sha256').update(JSON.stringify(assembly)).digest('base64');
return { ...assembly, fingerprint };
assembly.fingerprint = '*'.repeat(10);
return assembly;
}

export interface TypeLookupAssembly {
Expand Down
21 changes: 10 additions & 11 deletions packages/jsii/lib/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as spec from '@jsii/spec';
import { PackageJson } from '@jsii/spec';
import * as Case from 'case';
import * as chalk from 'chalk';
import * as crypto from 'crypto';
// eslint-disable-next-line @typescript-eslint/no-require-imports
import deepEqual = require('deep-equal');
import * as fs from 'fs-extra';
Expand Down Expand Up @@ -32,9 +31,6 @@ import { Validator } from './validator';
import { SHORT_VERSION, VERSION } from './version';
import { enabledWarnings } from './warnings';

// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports
const sortJson = require('sort-json');

const LOG = log4js.getLogger('jsii/assembler');

/**
Expand Down Expand Up @@ -2865,14 +2861,17 @@ interface SubmoduleSpec {
readonly readme?: spec.ReadMe;
}

/**
* Replaces the old fingerprint with '***********'.
*
* @rmuller says fingerprinting is useless, as we do not actually check
* if an assembly is changed. Instead of keeping the old (wrong) fingerprint
* or spending extra time calculating a new fingerprint, we replace with '**********'
* that demonstrates the fingerprint has changed.
*/
function _fingerprint(assembly: spec.Assembly): spec.Assembly {
delete assembly.fingerprint;
assembly = sortJson(assembly);
const fingerprint = crypto
.createHash('sha256')
.update(JSON.stringify(assembly))
.digest('base64');
return { ...assembly, fingerprint };
assembly.fingerprint = '*'.repeat(10);
return assembly;
}

function _isAbstract(
Expand Down