Skip to content
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
41 changes: 22 additions & 19 deletions commands/upgrade.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// @flow
const {minVersion, satisfies, valid} = require('../utils/cached-semver');
const {getManifest} = require('../utils/get-manifest.js');
const {findLocalDependency} = require('../utils/find-local-dependency.js');
const {read, write, spawn} = require('../utils/node-helpers.js');
const {node, yarn} = require('../utils/binary-paths.js');
const { minVersion, satisfies, valid } = require('../utils/cached-semver');
const { getManifest } = require('../utils/get-manifest.js');
const { findLocalDependency } = require('../utils/find-local-dependency.js');
const { read, write, spawn } = require('../utils/node-helpers.js');
const { node, yarn } = require('../utils/binary-paths.js');
const {
getTypesPackages,
checkBundledTypes,
findBestTypesVersion,
removeTypesPackage,
} = require('../utils/types-manager.js');
const {promptForTypesVersion} = require('../utils/upgrade-prompts.js');
const { promptForTypesVersion } = require('../utils/upgrade-prompts.js');

/*::
export type UpgradeArgs = {
Expand All @@ -27,26 +27,26 @@ type RemoveTypesPackage = (string, Array<string>) => Promise<void>;
type PromptForTypesVersion = (string, ?string, Array<string>, boolean) => Promise<?string>;
*/

const upgrade /*: Upgrade */ = async ({root, args, interactive = true}) => {
const {projects} = await getManifest({root});
const upgrade /*: Upgrade */ = async ({ root, args, interactive = true }) => {
const { projects } = await getManifest({ root });
const roots = projects.map(dir => `${root}/${dir}`);

// group by whether the dep is local (listed in manifest.json) or external (from registry)
const locals = [];
const externals = [];
for (const arg of args) {
let [, name, version] = arg.match(/(@?[^@]*)@?(.*)/) || [];
const local = await findLocalDependency({root, name});
if (local) locals.push({local, name, version});
else externals.push({name, range: version});
const local = await findLocalDependency({ root, name });
if (local) locals.push({ local, name, version });
else externals.push({ name, range: version });
}

if (locals.length > 0) {
await Promise.all(
roots.map(async cwd => {
const meta = JSON.parse(await read(`${cwd}/package.json`, 'utf8'));

for (const {local, name, version} of locals) {
for (const { local, name, version } of locals) {
if (version && version !== local.meta.version) {
const error = `You must use version ${name}@${local.meta.version}`;
throw new Error(error);
Expand All @@ -68,17 +68,20 @@ const upgrade /*: Upgrade */ = async ({root, args, interactive = true}) => {
}

if (externals.length > 0) {
const deps = externals.map(({name, range}) => {
const deps = externals.map(({ name, range }) => {
return name + (range ? `@${range}` : '');
});

// Add @types packages
const typesDeps = await getTypesPackages(
externals,
root,
roots,
promptForTypesVersion
);
// In non-interactive mode, skip prompting (return null to skip package)
const promptFn = interactive
? promptForTypesVersion
: async (name, range, versions, shouldPrompt) => {
console.log(`Skipping ${name} (non-interactive mode)`);
return null;
};

const typesDeps = await getTypesPackages(externals, root, roots, promptFn);

await spawn(
node,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jazelle",
"version": "0.0.0-standalone.102",
"version": "0.0.0-standalone.103",
"main": "index.js",
"bin": {
"barn": "bin/bootstrap.sh",
Expand Down
Loading
Loading