Skip to content

Commit

Permalink
Merge pull request #91 from arcanis/offline-cache
Browse files Browse the repository at this point in the history
Implements a super basic offline cache integration
  • Loading branch information
arcanis authored Aug 23, 2018
2 parents df61b90 + f46a763 commit 304f4ea
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type ConfigOptions = {
enablePnp?: boolean,
disablePnp?: boolean,
scriptsPrependNodePath?: boolean,
offlineCacheFolder?: string,

enableDefaultRc?: boolean,
extraneousYarnrcFiles?: Array<string>,
Expand Down Expand Up @@ -179,6 +180,8 @@ export default class Config {
workspacesEnabled: boolean;
workspacesNohoistEnabled: boolean;

offlineCacheFolder: ?string;

//
cwd: string;
workspaceRootFolder: ?string;
Expand Down Expand Up @@ -390,18 +393,20 @@ export default class Config {
}

this.plugnplayShebang = String(this.getOption('plugnplay-shebang')) || '/usr/bin/env node';
this.plugnplayBlacklist = String(this.getOption('plugnplay-blacklist')) || null;
this.plugnplayBlacklist = String(this.getOption('plugnplay-blacklist') || '') || null;

this.workspacesEnabled = this.getOption('workspaces-experimental') !== false;
this.workspacesNohoistEnabled = this.getOption('workspaces-nohoist-experimental') !== false;

this.offlineCacheFolder = String(this.getOption('offline-cache-folder') || '') || null;

this.pruneOfflineMirror = Boolean(this.getOption('yarn-offline-mirror-pruning'));
this.enableMetaFolder = Boolean(this.getOption('enable-meta-folder'));
this.enableLockfileVersions = Boolean(this.getOption('yarn-enable-lockfile-versions'));
this.linkFileDependencies = Boolean(this.getOption('yarn-link-file-dependencies'));
this.packBuiltPackages = Boolean(this.getOption('experimental-pack-script-packages-in-mirror'));

this.autoAddIntegrity = !Boolean(this.getOption('unsafe-disable-integrity-migration'));
this.autoAddIntegrity = !this.getOption('unsafe-disable-integrity-migration');

//init & create cacheFolder, tempFolder
this.cacheFolder = path.join(this._cacheRootFolder, 'v' + String(constants.CACHE_VERSION));
Expand Down
9 changes: 8 additions & 1 deletion src/rc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import {parse} from './lockfile';
import * as rcUtil from './util/rc.js';

// Keys that will get resolved relative to the path of the rc file they belong to
const PATH_KEYS = new Set(['yarn-path', 'cache-folder', 'global-folder', 'modules-folder', 'cwd']);
const PATH_KEYS = new Set([
'yarn-path',
'cache-folder',
'global-folder',
'modules-folder',
'cwd',
'offline-cache-folder',
]);

// given a cwd, load all .yarnrc files relative to it
export function getRcConfigForCwd(cwd: string, args: Array<string>): {[key: string]: string} {
Expand Down
2 changes: 1 addition & 1 deletion src/registries/yarn-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const DEFAULTS = {
'user-agent': [`yarn/${version}`, 'npm/?', `node/${process.version}`, process.platform, process.arch].join(' '),
};

const RELATIVE_KEYS = ['yarn-offline-mirror', 'cache-folder'];
const RELATIVE_KEYS = ['yarn-offline-mirror', 'cache-folder', 'offline-cache-folder'];

const npmMap = {
'version-git-sign': 'sign-git-tag',
Expand Down
15 changes: 15 additions & 0 deletions src/util/generate-pnp-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,26 @@ async function getPackageInformationStores(
{resolver, targetPath, workspaceLayout}: GeneratePnpMapOptions,
): Promise<[PackageInformationStores, Set<string>]> {
const targetDirectory = path.dirname(targetPath);
const offlineCacheFolder = config.offlineCacheFolder;

const packageInformationStores: PackageInformationStores = new Map();
const blacklistedLocations: Set<string> = new Set();

const normalizeDirectoryPath = (fsPath: string) => {
if (offlineCacheFolder) {
const cacheRelativePath = path.relative(config.cacheFolder, fsPath);

// if fsPath is inside cacheRelativePath
if (!cacheRelativePath.match(/^\.\.\//)) {
const components = cacheRelativePath.split(/\//g);

// eslint-disable-next-line no-unused-vars
const [cacheEntry, nodeModules, ...internalPath] = components;

fsPath = path.resolve(offlineCacheFolder, `${cacheEntry}.zip`, internalPath.join('/'));
}
}

let relativePath = path.relative(targetDirectory, fsPath);

if (!relativePath.match(/^\.{0,2}\//)) {
Expand Down

0 comments on commit 304f4ea

Please sign in to comment.