@nx/js
Version:
29 lines (28 loc) • 1.22 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolveVersionSpec = resolveVersionSpec;
const npa = require("npm-package-arg");
const devkit_1 = require("@nx/devkit");
function resolveVersionSpec(name, version, spec, location) {
// yarn classic uses link instead of file, normalize to match what npm expects
spec = spec.replace(/^link:/, 'file:');
// Support workspace: protocol for pnpm and yarn 2+ (https://pnpm.io/workspaces#workspace-protocol-workspace)
const isWorkspaceSpec = /^workspace:/.test(spec);
if (isWorkspaceSpec) {
spec = spec.replace(/^workspace:/, '');
// replace aliases (https://pnpm.io/workspaces#referencing-workspace-packages-through-aliases)
if (spec === '*' || spec === '^' || spec === '~') {
if (version) {
const prefix = spec === '*' ? '' : spec;
spec = `${prefix}${version}`;
}
else {
spec = '*';
}
}
}
const npaResult = npa.resolve(name, spec, location);
return npaResult.fetchSpec.includes('\\')
? (0, devkit_1.normalizePath)(npaResult.fetchSpec)
: npaResult.fetchSpec;
}
;