Skip to content

Commit

Permalink
Implements the enable-meta-folder (#3367)
Browse files Browse the repository at this point in the history
* Implements the enable-meta-folder

* Adds enable-meta-folder support to yarn-error.log
  • Loading branch information
arcanis authored and bestander committed May 10, 2017
1 parent 7d9acc6 commit 9809511
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 24 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ test/fixtures/**/.fbkpm
/__tests__/fixtures/**/_*
/__tests__/fixtures/request-cache/GET/localhost/.bin
.idea
.yarn-meta
8 changes: 8 additions & 0 deletions __tests__/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,11 @@ test.concurrent('--integrity should fail if integrity file have different linked
expect(getStdout()).toContain('Integrity check: Linked modules don\'t match');
});
});

test('--integrity should create the integrity file under the meta folder if enabled', async (): Promise<void> => {
await runInstall({}, path.join('..', 'check', 'integrity-meta-folder'),
async (config, reporter, install, getStdout): Promise<void> => {
await checkCmd.run(config, reporter, {integrity: true}, []);
expect(await fs.exists(path.join(config.cwd, '.yarn-meta', '.yarn-integrity'))).toEqual(true);
});
});
1 change: 1 addition & 0 deletions __tests__/fixtures/check/integrity-meta-folder/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enable-meta-folder true
4 changes: 4 additions & 0 deletions __tests__/fixtures/check/integrity-meta-folder/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "a",
"version": "1.0.0"
}
4 changes: 3 additions & 1 deletion src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ function onUnexpectedError(err: Error) {
}

function writeErrorReport(log) : ?string {
const errorReportLoc = path.join(config.cwd, 'yarn-error.log');
const errorReportLoc = config.enableMetaFolder
? path.join(config.cwd, constants.META_FOLDER, 'yarn-error.log')
: path.join(config.cwd, 'yarn-error.log');

try {
fs.writeFileSync(errorReportLoc, log.join('\n\n') + '\n');
Expand Down
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type ConfigOptions = {
offline?: boolean,
preferOffline?: boolean,
pruneOfflineMirror?: boolean,
enableMetaFolder?: boolean,
captureHar?: boolean,
ignoreScripts?: boolean,
ignorePlatform?: boolean,
Expand Down Expand Up @@ -89,6 +90,7 @@ export default class Config {
offline: boolean;
preferOffline: boolean;
pruneOfflineMirror: boolean;
enableMetaFolder: boolean;
disableLockfileVersions: boolean;
ignorePlatform: boolean;
binLinks: boolean;
Expand Down Expand Up @@ -266,6 +268,7 @@ export default class Config {
);

this.pruneOfflineMirror = Boolean(this.getOption('yarn-offline-mirror-pruning'));
this.enableMetaFolder = Boolean(this.getOption('enable-meta-folder'));
this.disableLockfileVersions = Boolean(this.getOption('yarn-disable-lockfile-versions'));

//init & create cacheFolder, tempFolder
Expand Down
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const CONFIG_DIRECTORY = getDirectory('config');
export const LINK_REGISTRY_DIRECTORY = path.join(CONFIG_DIRECTORY, 'link');
export const GLOBAL_MODULE_DIRECTORY = path.join(CONFIG_DIRECTORY, 'global');

export const META_FOLDER = '.yarn-meta';
export const INTEGRITY_FILENAME = '.yarn-integrity';
export const LOCKFILE_FILENAME = 'yarn.lock';
export const METADATA_FILENAME = '.yarn-metadata.json';
Expand Down
55 changes: 32 additions & 23 deletions src/integrity-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,46 @@ export default class InstallationIntegrityChecker {
*/

async _getIntegrityHashLocation(usedRegistries?: Set<RegistryNames>): Promise<IntegrityHashLocation> {
// build up possible folders
let registries = registryNames;
if (usedRegistries && usedRegistries.size > 0) {
registries = usedRegistries;
}
const possibleFolders = [];
if (this.config.modulesFolder) {
possibleFolders.push(this.config.modulesFolder);
}
let locationFolder;

if (this.config.enableMetaFolder) {
locationFolder = path.join(this.config.cwd, constants.META_FOLDER);
} else {
// build up possible folders
let registries = registryNames;
if (usedRegistries && usedRegistries.size > 0) {
registries = usedRegistries;
}
const possibleFolders = [];
if (this.config.modulesFolder) {
possibleFolders.push(this.config.modulesFolder);
}

// ensure we only write to a registry folder that was used
for (const name of registries) {
const loc = path.join(this.config.cwd, this.config.registries[name].folder);
possibleFolders.push(loc);
}
// ensure we only write to a registry folder that was used
for (const name of registries) {
const loc = path.join(this.config.cwd, this.config.registries[name].folder);
possibleFolders.push(loc);
}

// if we already have an integrity hash in one of these folders then use it's location otherwise use the
// first folder
let loc;
for (const possibleLoc of possibleFolders) {
if (await fs.exists(path.join(possibleLoc, constants.INTEGRITY_FILENAME))) {
loc = possibleLoc;
break;
// if we already have an integrity hash in one of these folders then use it's location otherwise use the
// first folder
let loc;
for (const possibleLoc of possibleFolders) {
if (await fs.exists(path.join(possibleLoc, constants.INTEGRITY_FILENAME))) {
loc = possibleLoc;
break;
}
}
locationFolder = loc || possibleFolders[0];
}
const locationFolder = loc || possibleFolders[0];

const locationPath = path.join(locationFolder, constants.INTEGRITY_FILENAME);
const exists = await fs.exists(locationPath);

return {
locationFolder,
locationPath,
exists: !!loc,
exists,
};
}

Expand Down

0 comments on commit 9809511

Please sign in to comment.