From 85601e5e8aefe4964d50fc52077fd67da03e1d2e Mon Sep 17 00:00:00 2001 From: Konstantin Komelin Date: Sat, 30 Mar 2024 10:53:47 +0900 Subject: [PATCH 1/6] Added pnpm support. --- README.md | 2 +- package.json | 1 + src/package-manager.ts | 2 +- src/pnpm.ts | 48 ++++++++++++++++++++++++++++++ src/types.ts | 2 +- src/utils/package-manager-utils.ts | 20 +++++++++++-- typedoc.json | 2 +- 7 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 src/pnpm.ts diff --git a/README.md b/README.md index 7b1c26e..f6296f0 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Full documentation of available functions and configuration can be found on: ### 1. Disparity in supported flags -At the current moment `yarn` has no equivalent flags for `--save-bundle` or `--no-save`. These will be ignored when `yarn` has been detected as package manager. +At the current moment `yarn` and `pnpm` have no equivalent flags for `--save-bundle` or `--no-save`. These will be ignored when `yarn` or `pnpm` has been detected as package manager. The flags that were ignored in the run are returned as the `ignoredFlags` property. diff --git a/package.json b/package.json index 55c0f7d..2e3529f 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "keywords": [ "npm", "yarn", + "pnpm", "install", "cli", "script" diff --git a/src/package-manager.ts b/src/package-manager.ts index 9e502dd..37bf75e 100644 --- a/src/package-manager.ts +++ b/src/package-manager.ts @@ -12,7 +12,7 @@ import { /** * Determine what package manager to use based on what preference is set, - * and whether it's currently running in a yarn/npm script + * and whether it's currently running in a yarn/npm/pnpm script * * @export * @param {InstallConfig} config diff --git a/src/pnpm.ts b/src/pnpm.ts new file mode 100644 index 0000000..5b7b394 --- /dev/null +++ b/src/pnpm.ts @@ -0,0 +1,48 @@ +import { InstallConfig, PackageManagerFlag } from "./config"; +import { getFlagsToSet } from "./flags"; +import { UnreachableCaseError } from "./helpers"; +import { ConstructArgumentsResult, PackageList } from "./types"; + +export function constructPnpmArguments( + packageList: PackageList, + config: InstallConfig +): ConstructArgumentsResult { + const flagsToSet = getFlagsToSet(config); + const globalCommand = config.global ? ["--global"] : []; + const cwdCommand = config.forceCwd ? ["--pnpm-prefix", config.cwd] : []; + const args: string[] = [ + "install", + ...globalCommand, + ...cwdCommand, + "add", + ...packageList, + ]; + + const ignoredFlags: PackageManagerFlag[] = []; + flagsToSet.forEach((flag) => { + switch (flag) { + case "dev": + if (!config.global) { + args.push("--save-dev"); + } else { + ignoredFlags.push(flag); + } + break; + case "exact": + args.push("--save-exact"); + break; + case "verbose": + case "bundle": + case "noSave": + ignoredFlags.push(flag); + break; + /* istanbul ignore next */ + default: + throw new UnreachableCaseError(flag); + } + }); + + return { args, ignoredFlags }; +} + +export const pnpmProjectInstallArgs = ["install"]; diff --git a/src/types.ts b/src/types.ts index 409a1ba..d4ce277 100644 --- a/src/types.ts +++ b/src/types.ts @@ -8,7 +8,7 @@ export type PackageMap = { export type PackageList = string[]; export type Packages = PackageMap | PackageList; -export type SupportedPackageManagers = 'yarn' | 'npm'; +export type SupportedPackageManagers = 'yarn' | 'npm' | 'pnpm'; /** * What to do with I/O. This is passed to `execa` diff --git a/src/utils/package-manager-utils.ts b/src/utils/package-manager-utils.ts index 9d707e2..25bc9fc 100644 --- a/src/utils/package-manager-utils.ts +++ b/src/utils/package-manager-utils.ts @@ -62,6 +62,10 @@ export function getCurrentPackageManager(): SupportedPackageManagers | null { return 'yarn'; } + if (userAgent.startsWith('pnpm')) { + return 'pnpm'; + } + return null; } @@ -77,6 +81,7 @@ export async function getPackageManagerFromLockfile( ): Promise { const pkgLockPath = path.join(config.cwd, 'package-lock.json'); const yarnLockPath = path.join(config.cwd, 'yarn.lock'); + const pnpmLockPath = path.join(config.cwd, 'pnpm-lock.yaml'); try { await access(pkgLockPath); return 'npm'; @@ -85,7 +90,12 @@ export async function getPackageManagerFromLockfile( await access(yarnLockPath); return 'yarn'; } catch (err) { - return null; + try { + await access(pnpmLockPath); + return 'pnpm'; + } catch (err) { + return null; + } } } } @@ -102,6 +112,7 @@ export function getPackageManagerFromLockfileSync( ): SupportedPackageManagers | null { const pkgLockPath = path.join(config.cwd, 'package-lock.json'); const yarnLockPath = path.join(config.cwd, 'yarn.lock'); + const pnpmLockPath = path.join(config.cwd, 'pnpm-lock.yaml'); try { accessSync(pkgLockPath); return 'npm'; @@ -110,7 +121,12 @@ export function getPackageManagerFromLockfileSync( accessSync(yarnLockPath); return 'yarn'; } catch (err) { - return null; + try { + accessSync(pnpmLockPath); + return 'pnpm'; + } catch (err) { + return null; + } } } } diff --git a/typedoc.json b/typedoc.json index 9a57dfd..3ee1d4d 100644 --- a/typedoc.json +++ b/typedoc.json @@ -4,6 +4,6 @@ "mode": "modules", "out": "docs", "theme": "default", - "exclude": ["**/__tests__/*.ts", "**/helpers.ts", "**/npm.ts", "**/yarn.ts"], + "exclude": ["**/__tests__/*.ts", "**/helpers.ts", "**/npm.ts", "**/yarn.ts", "**/pnpm.ts"], "gaID": "UA-40008341-3" } From f8c376ba18a3c6ec02fe775542269448895b9fa3 Mon Sep 17 00:00:00 2001 From: Konstantin Komelin Date: Sat, 30 Mar 2024 14:11:42 +0900 Subject: [PATCH 2/6] Commiting /lib folder as a quick workaround for the lack of build process. --- .gitignore | 4 +- lib/__mocks__/execa.d.ts | 3 + lib/__mocks__/execa.js | 17 ++ lib/__mocks__/execa.js.map | 1 + lib/__tests__/helpers.d.ts | 1 + lib/__tests__/helpers.js | 48 ++++ lib/__tests__/helpers.js.map | 1 + lib/__tests__/index.d.ts | 1 + lib/__tests__/index.js | 31 ++ lib/__tests__/index.js.map | 1 + lib/__tests__/install.d.ts | 1 + lib/__tests__/install.js | 270 ++++++++++++++++++ lib/__tests__/install.js.map | 1 + lib/__tests__/npm.d.ts | 1 + lib/__tests__/npm.js | 82 ++++++ lib/__tests__/npm.js.map | 1 + lib/__tests__/package-manager.d.ts | 1 + lib/__tests__/package-manager.js | 262 +++++++++++++++++ lib/__tests__/package-manager.js.map | 1 + lib/__tests__/yarn.d.ts | 1 + lib/__tests__/yarn.js | 82 ++++++ lib/__tests__/yarn.js.map | 1 + lib/config.d.ts | 43 +++ lib/config.js | 37 +++ lib/config.js.map | 1 + lib/flags.d.ts | 2 + lib/flags.js | 19 ++ lib/flags.js.map | 1 + lib/helpers.d.ts | 11 + lib/helpers.js | 53 ++++ lib/helpers.js.map | 1 + lib/index.d.ts | 9 + lib/index.js | 22 ++ lib/index.js.map | 1 + lib/install.d.ts | 59 ++++ lib/install.js | 169 +++++++++++ lib/install.js.map | 1 + lib/npm.d.ts | 4 + lib/npm.js | 50 ++++ lib/npm.js.map | 1 + lib/package-manager.d.ts | 21 ++ lib/package-manager.js | 107 +++++++ lib/package-manager.js.map | 1 + lib/pnpm.d.ts | 4 + lib/pnpm.js | 50 ++++ lib/pnpm.js.map | 1 + lib/types.d.ts | 16 ++ lib/types.js | 3 + lib/types.js.map | 1 + .../__tests__/package-manager-utils.d.ts | 1 + lib/utils/__tests__/package-manager-utils.js | 223 +++++++++++++++ .../__tests__/package-manager-utils.js.map | 1 + lib/utils/package-manager-utils.d.ts | 47 +++ lib/utils/package-manager-utils.js | 194 +++++++++++++ lib/utils/package-manager-utils.js.map | 1 + lib/yarn.d.ts | 4 + lib/yarn.js | 48 ++++ lib/yarn.js.map | 1 + 58 files changed, 2018 insertions(+), 2 deletions(-) create mode 100644 lib/__mocks__/execa.d.ts create mode 100644 lib/__mocks__/execa.js create mode 100644 lib/__mocks__/execa.js.map create mode 100644 lib/__tests__/helpers.d.ts create mode 100644 lib/__tests__/helpers.js create mode 100644 lib/__tests__/helpers.js.map create mode 100644 lib/__tests__/index.d.ts create mode 100644 lib/__tests__/index.js create mode 100644 lib/__tests__/index.js.map create mode 100644 lib/__tests__/install.d.ts create mode 100644 lib/__tests__/install.js create mode 100644 lib/__tests__/install.js.map create mode 100644 lib/__tests__/npm.d.ts create mode 100644 lib/__tests__/npm.js create mode 100644 lib/__tests__/npm.js.map create mode 100644 lib/__tests__/package-manager.d.ts create mode 100644 lib/__tests__/package-manager.js create mode 100644 lib/__tests__/package-manager.js.map create mode 100644 lib/__tests__/yarn.d.ts create mode 100644 lib/__tests__/yarn.js create mode 100644 lib/__tests__/yarn.js.map create mode 100644 lib/config.d.ts create mode 100644 lib/config.js create mode 100644 lib/config.js.map create mode 100644 lib/flags.d.ts create mode 100644 lib/flags.js create mode 100644 lib/flags.js.map create mode 100644 lib/helpers.d.ts create mode 100644 lib/helpers.js create mode 100644 lib/helpers.js.map create mode 100644 lib/index.d.ts create mode 100644 lib/index.js create mode 100644 lib/index.js.map create mode 100644 lib/install.d.ts create mode 100644 lib/install.js create mode 100644 lib/install.js.map create mode 100644 lib/npm.d.ts create mode 100644 lib/npm.js create mode 100644 lib/npm.js.map create mode 100644 lib/package-manager.d.ts create mode 100644 lib/package-manager.js create mode 100644 lib/package-manager.js.map create mode 100644 lib/pnpm.d.ts create mode 100644 lib/pnpm.js create mode 100644 lib/pnpm.js.map create mode 100644 lib/types.d.ts create mode 100644 lib/types.js create mode 100644 lib/types.js.map create mode 100644 lib/utils/__tests__/package-manager-utils.d.ts create mode 100644 lib/utils/__tests__/package-manager-utils.js create mode 100644 lib/utils/__tests__/package-manager-utils.js.map create mode 100644 lib/utils/package-manager-utils.d.ts create mode 100644 lib/utils/package-manager-utils.js create mode 100644 lib/utils/package-manager-utils.js.map create mode 100644 lib/yarn.d.ts create mode 100644 lib/yarn.js create mode 100644 lib/yarn.js.map diff --git a/.gitignore b/.gitignore index 1265784..9b47c63 100644 --- a/.gitignore +++ b/.gitignore @@ -80,6 +80,6 @@ typings/ .dynamodb/ # Compile Output -lib/ +#lib/ coverage/ -docs/ \ No newline at end of file +docs/ diff --git a/lib/__mocks__/execa.d.ts b/lib/__mocks__/execa.d.ts new file mode 100644 index 0000000..e4b0ce8 --- /dev/null +++ b/lib/__mocks__/execa.d.ts @@ -0,0 +1,3 @@ +/// +declare const execa: jest.Mock; +export default execa; diff --git a/lib/__mocks__/execa.js b/lib/__mocks__/execa.js new file mode 100644 index 0000000..be1ab8b --- /dev/null +++ b/lib/__mocks__/execa.js @@ -0,0 +1,17 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var execa = jest.fn().mockImplementation(function () { + return Promise.resolve({ + failed: false + }); +}); +var execaSync = jest.fn().mockImplementation(function () { + return { + failed: false + }; +}); +Object.defineProperty(execa, 'sync', { + value: execaSync +}); +exports.default = execa; +//# sourceMappingURL=execa.js.map \ No newline at end of file diff --git a/lib/__mocks__/execa.js.map b/lib/__mocks__/execa.js.map new file mode 100644 index 0000000..f752a87 --- /dev/null +++ b/lib/__mocks__/execa.js.map @@ -0,0 +1 @@ +{"version":3,"file":"execa.js","sourceRoot":"","sources":["../../src/__mocks__/execa.ts"],"names":[],"mappings":";;AAAA,IAAM,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC;IACzC,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC;IAC7C,OAAO;QACL,MAAM,EAAE,KAAK;KACd,CAAA;AACH,CAAC,CAAC,CAAA;AACF,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE;IACnC,KAAK,EAAE,SAAS;CACjB,CAAC,CAAA;AAGF,kBAAe,KAAK,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/helpers.d.ts b/lib/__tests__/helpers.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/__tests__/helpers.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/__tests__/helpers.js b/lib/__tests__/helpers.js new file mode 100644 index 0000000..f7b8795 --- /dev/null +++ b/lib/__tests__/helpers.js @@ -0,0 +1,48 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var config_1 = require("../config"); +var helpers_1 = require("../helpers"); +describe('getPackageList', function () { + it('should handle arrays', function () { + var input = ['twilio', 'node-env-run@1', 'twilio-run@1']; + var output = helpers_1.getPackageList(input); + expect(output).toEqual(input); + }); + it('should filter out empty or invalid values', function () { + var input = ['twilio', undefined, 1.23, 'node-env-run@1']; + // @ts-ignore + var output = helpers_1.getPackageList(input); + expect(output).toEqual(['twilio', 'node-env-run@1']); + }); + it('should turn objects into arrays', function () { + var input = { + twilio: '^3', + 'node-env-run': '1', + 'twilio-run': undefined, + }; + var output = helpers_1.getPackageList(input); + expect(output).toEqual(['twilio@^3', 'node-env-run@1', 'twilio-run']); + }); +}); +describe('getExecaConfig', function () { + it('should extract the right config parameters', function () { + var config = __assign(__assign({}, config_1.defaultInstallConfig), { stdio: 'inherit', cwd: '/some/user/path' }); + var output = helpers_1.getExecaConfig(config); + expect(output).toEqual({ + stdio: 'inherit', + cwd: '/some/user/path', + }); + }); +}); +//# sourceMappingURL=helpers.js.map \ No newline at end of file diff --git a/lib/__tests__/helpers.js.map b/lib/__tests__/helpers.js.map new file mode 100644 index 0000000..0e53dc2 --- /dev/null +++ b/lib/__tests__/helpers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/__tests__/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oCAAiD;AACjD,sCAA4D;AAE5D,QAAQ,CAAC,gBAAgB,EAAE;IACzB,EAAE,CAAC,sBAAsB,EAAE;QACzB,IAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAC3D,IAAM,MAAM,GAAG,wBAAc,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE;QAC9C,IAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;QAC5D,aAAa;QACb,IAAM,MAAM,GAAG,wBAAc,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE;QACpC,IAAM,KAAK,GAAG;YACZ,MAAM,EAAE,IAAI;YACZ,cAAc,EAAE,GAAG;YACnB,YAAY,EAAE,SAAS;SACxB,CAAC;QACF,IAAM,MAAM,GAAG,wBAAc,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,gBAAgB,EAAE;IACzB,EAAE,CAAC,4CAA4C,EAAE;QAC/C,IAAM,MAAM,yBACP,6BAAoB,KACvB,KAAK,EAAE,SAAsB,EAC7B,GAAG,EAAE,iBAAiB,GACvB,CAAC;QAEF,IAAM,MAAM,GAAG,wBAAc,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,iBAAiB;SACvB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/index.d.ts b/lib/__tests__/index.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/__tests__/index.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/__tests__/index.js b/lib/__tests__/index.js new file mode 100644 index 0000000..422369b --- /dev/null +++ b/lib/__tests__/index.js @@ -0,0 +1,31 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var pkgInstall = __importStar(require("../index")); +describe('index export', function () { + it('exports the right things', function () { + expect(typeof pkgInstall.install).toBe('function'); + expect(typeof pkgInstall.installSync).toBe('function'); + expect(typeof pkgInstall.projectInstall).toBe('function'); + expect(typeof pkgInstall.projectInstallSync).toBe('function'); + }); +}); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/__tests__/index.js.map b/lib/__tests__/index.js.map new file mode 100644 index 0000000..c8cdc90 --- /dev/null +++ b/lib/__tests__/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/__tests__/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AAEvC,QAAQ,CAAC,cAAc,EAAE;IACvB,EAAE,CAAC,0BAA0B,EAAE;QAC7B,MAAM,CAAC,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnD,MAAM,CAAC,OAAO,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACvD,MAAM,CAAC,OAAO,UAAU,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,CAAC,OAAO,UAAU,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/install.d.ts b/lib/__tests__/install.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/__tests__/install.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/__tests__/install.js b/lib/__tests__/install.js new file mode 100644 index 0000000..2d538e7 --- /dev/null +++ b/lib/__tests__/install.js @@ -0,0 +1,270 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +jest.mock('execa'); +jest.mock('../package-manager', function () { + var getPackageManager = jest.fn().mockImplementation(function () { + return Promise.resolve('npm'); + }); + var getPackageManagerSync = jest.fn().mockReturnValue('npm'); + return { + getPackageManager: getPackageManager, + getPackageManagerSync: getPackageManagerSync, + }; +}); +jest.mock('../npm', function () { + return { + npmProjectInstallArgs: ['install'], + constructNpmArguments: jest.fn().mockImplementation(function (pkgList) { + return __spreadArrays(['install'], pkgList); + }), + }; +}); +jest.mock('../yarn', function () { + return { + yarnProjectInstallArgs: ['install'], + constructYarnArguments: jest.fn().mockImplementation(function (pkgList) { + return __spreadArrays(['add'], pkgList); + }), + }; +}); +var execa_1 = __importDefault(require("execa")); +var config_1 = require("../config"); +var install_1 = require("../install"); +var npm_1 = require("../npm"); +var package_manager_1 = require("../package-manager"); +var yarn_1 = require("../yarn"); +beforeEach(function () { + execa_1.default.mockClear(); + execa_1.default.sync.mockClear(); +}); +describe('install', function () { + beforeEach(function () { + npm_1.constructNpmArguments.mockClear(); + yarn_1.constructYarnArguments.mockClear(); + }); + it('should execute execa', function () { return __awaiter(void 0, void 0, void 0, function () { + var result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, install_1.install(['twilio'])]; + case 1: + result = _a.sent(); + expect(execa_1.default).toHaveBeenCalledTimes(1); + return [2 /*return*/]; + } + }); + }); }); + it('should merge settings correctly', function () { return __awaiter(void 0, void 0, void 0, function () { + var result, expectedConfig; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, install_1.install(['twilio'], { + noSave: true, + global: true, + forceCwd: true, + })]; + case 1: + result = _a.sent(); + expectedConfig = __assign(__assign({}, config_1.defaultInstallConfig), { noSave: true, global: true, forceCwd: true }); + expect(package_manager_1.getPackageManager).toHaveBeenCalledWith(expectedConfig); + return [2 /*return*/]; + } + }); + }); }); + it('should call the right argument constructor (npm)', function () { return __awaiter(void 0, void 0, void 0, function () { + var result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + package_manager_1.getPackageManager.mockReturnValueOnce(Promise.resolve('npm')); + return [4 /*yield*/, install_1.install(['twilio'])]; + case 1: + result = _a.sent(); + expect(npm_1.constructNpmArguments).toHaveBeenCalledTimes(1); + expect(npm_1.constructNpmArguments).toHaveBeenCalledWith(['twilio'], config_1.defaultInstallConfig); + expect(yarn_1.constructYarnArguments).toHaveBeenCalledTimes(0); + return [2 /*return*/]; + } + }); + }); }); + it('should call the right argument constructor (yarn)', function () { return __awaiter(void 0, void 0, void 0, function () { + var result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + package_manager_1.getPackageManager.mockReturnValueOnce(Promise.resolve('yarn')); + return [4 /*yield*/, install_1.install(['twilio'])]; + case 1: + result = _a.sent(); + expect(yarn_1.constructYarnArguments).toHaveBeenCalledTimes(1); + expect(yarn_1.constructYarnArguments).toHaveBeenCalledWith(['twilio'], config_1.defaultInstallConfig); + expect(npm_1.constructNpmArguments).toHaveBeenCalledTimes(0); + return [2 /*return*/]; + } + }); + }); }); +}); +describe('installSync', function () { + beforeEach(function () { + npm_1.constructNpmArguments.mockClear(); + yarn_1.constructYarnArguments.mockClear(); + }); + it('should execute execa.sync', function () { + var result = install_1.installSync(['twilio']); + expect(execa_1.default.sync).toHaveBeenCalledTimes(1); + }); + it('should merge settings correctly', function () { + var result = install_1.installSync(['twilio'], { + noSave: true, + global: true, + forceCwd: true, + }); + var expectedConfig = __assign(__assign({}, config_1.defaultInstallConfig), { noSave: true, global: true, forceCwd: true }); + expect(package_manager_1.getPackageManager).toHaveBeenCalledWith(expectedConfig); + }); + it('should call the right argument constructor (npm)', function () { + package_manager_1.getPackageManagerSync.mockReturnValueOnce('npm'); + var result = install_1.installSync(['twilio']); + expect(npm_1.constructNpmArguments).toHaveBeenCalledTimes(1); + expect(npm_1.constructNpmArguments).toHaveBeenCalledWith(['twilio'], config_1.defaultInstallConfig); + expect(yarn_1.constructYarnArguments).toHaveBeenCalledTimes(0); + }); + it('should call the right argument constructor (yarn)', function () { + package_manager_1.getPackageManagerSync.mockReturnValueOnce('yarn'); + var result = install_1.installSync(['twilio']); + expect(yarn_1.constructYarnArguments).toHaveBeenCalledTimes(1); + expect(yarn_1.constructYarnArguments).toHaveBeenCalledWith(['twilio'], config_1.defaultInstallConfig); + expect(npm_1.constructNpmArguments).toHaveBeenCalledTimes(0); + }); +}); +describe('projectInstall', function () { + it('should call execa with the right arguments (npm)', function () { return __awaiter(void 0, void 0, void 0, function () { + var result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + package_manager_1.getPackageManager.mockResolvedValueOnce('npm'); + return [4 /*yield*/, install_1.projectInstall()]; + case 1: + result = _a.sent(); + expect(execa_1.default).toHaveBeenCalledWith('npm', ['install'], { + stdio: 'pipe', + cwd: process.cwd(), + }); + return [2 /*return*/]; + } + }); + }); }); + it('should call execa with the right arguments (yarn)', function () { return __awaiter(void 0, void 0, void 0, function () { + var result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + package_manager_1.getPackageManager.mockResolvedValueOnce('yarn'); + return [4 /*yield*/, install_1.projectInstall()]; + case 1: + result = _a.sent(); + expect(execa_1.default).toHaveBeenCalledWith('yarn', ['install'], { + stdio: 'pipe', + cwd: process.cwd(), + }); + return [2 /*return*/]; + } + }); + }); }); + it('merges config correctly', function () { return __awaiter(void 0, void 0, void 0, function () { + var expectedConfig, result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + expectedConfig = __assign(__assign({}, config_1.defaultInstallConfig), { stdio: 'inherit' }); + return [4 /*yield*/, install_1.projectInstall({ stdio: 'inherit' })]; + case 1: + result = _a.sent(); + expect(package_manager_1.getPackageManager).toHaveBeenLastCalledWith(expectedConfig); + return [2 /*return*/]; + } + }); + }); }); +}); +describe('projectInstallSync', function () { + it('should call execa.sync with the right arguments (npm)', function () { + package_manager_1.getPackageManagerSync.mockReturnValueOnce('npm'); + var result = install_1.projectInstallSync(); + expect(execa_1.default.sync).toHaveBeenCalledWith('npm', ['install'], { + stdio: 'pipe', + cwd: process.cwd(), + }); + }); + it('should call execa.sync with the right arguments (yarn)', function () { + package_manager_1.getPackageManagerSync.mockReturnValueOnce('yarn'); + var result = install_1.projectInstallSync(); + expect(execa_1.default.sync).toHaveBeenCalledWith('yarn', ['install'], { + stdio: 'pipe', + cwd: process.cwd(), + }); + }); + it('merges config correctly', function () { + var expectedConfig = __assign(__assign({}, config_1.defaultInstallConfig), { stdio: 'inherit' }); + var result = install_1.projectInstallSync({ stdio: 'inherit' }); + expect(package_manager_1.getPackageManagerSync).toHaveBeenLastCalledWith(expectedConfig); + }); +}); +//# sourceMappingURL=install.js.map \ No newline at end of file diff --git a/lib/__tests__/install.js.map b/lib/__tests__/install.js.map new file mode 100644 index 0000000..60e39e1 --- /dev/null +++ b/lib/__tests__/install.js.map @@ -0,0 +1 @@ +{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/__tests__/install.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACnB,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;IAC9B,IAAM,iBAAiB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC;QACrD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IACH,IAAM,qBAAqB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC/D,OAAO;QACL,iBAAiB,mBAAA;QACjB,qBAAqB,uBAAA;KACtB,CAAC;AACJ,CAAC,CAAC,CAAC;AACH,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;IAClB,OAAO;QACL,qBAAqB,EAAE,CAAC,SAAS,CAAC;QAClC,qBAAqB,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAA,OAAO;YACzD,uBAAQ,SAAS,GAAK,OAAO,EAAE;QACjC,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;IACnB,OAAO;QACL,sBAAsB,EAAE,CAAC,SAAS,CAAC;QACnC,sBAAsB,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAA,OAAO;YAC1D,uBAAQ,KAAK,GAAK,OAAO,EAAE;QAC7B,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,gDAA0B;AAC1B,oCAAiD;AACjD,sCAKoB;AACpB,8BAA+C;AAC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AC;IAEH,EAAE,CAAC,wDAAwD,EAAE;QAC1D,uCAAmC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QACjE,IAAM,MAAM,GAAG,4BAAkB,EAAE,CAAC;QACpC,MAAM,CAAC,eAAK,CAAC,IAAI,CAAC,CAAC,oBAAoB,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,EAAE;YAC3D,KAAK,EAAE,MAAM;YACb,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;SACnB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE;QAC5B,IAAM,cAAc,yBACf,6BAAoB,KACvB,KAAK,EAAE,SAAS,GACjB,CAAC;QAEF,IAAM,MAAM,GAAG,4BAAkB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QACxD,MAAM,CAAC,uCAAqB,CAAC,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/npm.d.ts b/lib/__tests__/npm.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/__tests__/npm.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/__tests__/npm.js b/lib/__tests__/npm.js new file mode 100644 index 0000000..74ccdfb --- /dev/null +++ b/lib/__tests__/npm.js @@ -0,0 +1,82 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var config_1 = require("../config"); +var npm_1 = require("../npm"); +describe('constructNpmArguments', function () { + var packageList = ['twilio', 'twilio-run@1']; + it('should handle default config', function () { + var _a = npm_1.constructNpmArguments(packageList, config_1.defaultInstallConfig), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install'], packageList)); + expect(ignoredFlags.length).toBe(0); + }); + it('should add dev flag', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install'], packageList, ['--save-dev'])); + expect(ignoredFlags.length).toBe(0); + }); + it('should ignore dev flag when global', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true, global: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install', '-g'], packageList)); + expect(ignoredFlags).toEqual(['dev']); + }); + it('should add exact flag', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { exact: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install'], packageList, ['--save-exact'])); + expect(ignoredFlags.length).toBe(0); + }); + it('should add verbose flag', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { verbose: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install'], packageList, ['--verbose'])); + expect(ignoredFlags.length).toBe(0); + }); + it('should add bundle flag', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { bundle: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install'], packageList, ['--save-bundle'])); + expect(ignoredFlags.length).toBe(0); + }); + it('should handle noSave flag', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { noSave: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install'], packageList, ['--no-save'])); + expect(ignoredFlags.length).toBe(0); + }); + it('should handle global flag', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { global: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install', '-g'], packageList)); + expect(ignoredFlags.length).toBe(0); + }); + it('should handle forceCwd flag', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { forceCwd: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['install', '--prefix', process.cwd()], packageList)); + expect(ignoredFlags.length).toBe(0); + }); + it('should handle all flags', function () { + var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true, exact: true, verbose: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays([ + 'install' + ], packageList, [ + '--save-dev', + '--save-exact', + '--verbose', + ])); + expect(ignoredFlags.length).toBe(0); + }); +}); +//# sourceMappingURL=npm.js.map \ No newline at end of file diff --git a/lib/__tests__/npm.js.map b/lib/__tests__/npm.js.map new file mode 100644 index 0000000..31ecc5e --- /dev/null +++ b/lib/__tests__/npm.js.map @@ -0,0 +1 @@ +{"version":3,"file":"npm.js","sourceRoot":"","sources":["../../src/__tests__/npm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,oCAAiD;AACjD,8BAA+C;AAE/C,QAAQ,CAAC,uBAAuB,EAAE;IAChC,IAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAE/C,EAAE,CAAC,8BAA8B,EAAE;QAC3B,IAAA,KAAiC,2BAAqB,CAC1D,WAAW,EACX,6BAAoB,CACrB,EAHa,M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AM,EAAE,IAAI,IACZ,EAHY,MAAM,UAAA,EAAE,YAAY,kBAGhC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,iBAAE,SAAS,EAAE,IAAI,GAAK,WAAW,EAAE,CAAC;QAC1D,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE;QAC1B,IAAA,KAAiC,2BAAqB,CAAC,WAAW,wBACnE,6BAAoB,KACvB,QAAQ,EAAE,IAAI,IACd,EAHY,MAAM,UAAA,EAAE,YAAY,kBAGhC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,iBAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE,GAAK,WAAW,EAAE,CAAC;QAC/E,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE;QACtB,IAAA,KAAiC,2BAAqB,CAAC,WAAW,wBACnE,6BAAoB,KACvB,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,IAAI,EACX,OAAO,EAAE,IAAI,IACb,EALY,MAAM,UAAA,EAAE,YAAY,kBAKhC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO;YACpB,SAAS;WACN,WAAW;YACd,YAAY;YACZ,cAAc;YACd,WAAW;WACX,CAAC;QACH,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/package-manager.d.ts b/lib/__tests__/package-manager.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/__tests__/package-manager.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/__tests__/package-manager.js b/lib/__tests__/package-manager.js new file mode 100644 index 0000000..0aa4051 --- /dev/null +++ b/lib/__tests__/package-manager.js @@ -0,0 +1,262 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var mockGetCurrentPm = jest.fn(); +var mockGetPmFromLock = jest.fn(); +var mockIsManagerInstalled = jest.fn(); +var mockGetPmFromLockSync = jest.fn(); +var mockIsManagerInstalledSync = jest.fn(); +jest.mock('../utils/package-manager-utils', function () { + return { + getCurrentPackageManager: mockGetCurrentPm, + getPackageManagerFromLockfile: mockGetPmFromLock, + isManagerInstalled: mockIsManagerInstalled, + isManagerInstalledSync: mockIsManagerInstalledSync, + getPackageManagerFromLockfileSync: mockGetPmFromLockSync, + }; +}); +var config_1 = require("../config"); +var package_manager_1 = require("../package-manager"); +describe('getPackageManager', function () { + var config = __assign(__assign({}, config_1.defaultInstallConfig), { cwd: '/' }); + beforeEach(function () { + mockGetCurrentPm.mockRestore(); + mockGetCurrentPm.mockImplementation(function () { return null; }); + mockGetPmFromLock.mockRestore(); + mockGetPmFromLock.mockImplementation(function () { return null; }); + mockIsManagerInstalled.mockRestore(); + mockIsManagerInstalled.mockImplementation(function () { return Promise.resolve(true); }); + }); + it('should respect the prefer flag', function () { return __awaiter(void 0, void 0, void 0, function () { + var preferYarnConfig, _a, preferNpmConfig, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + preferYarnConfig = __assign(__assign({}, config), { prefer: 'yarn' }); + _a = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(preferYarnConfig)]; + case 1: + _a.apply(void 0, [_c.sent()]).toBe('yarn'); + preferNpmConfig = __assign(__assign({}, config), { prefer: 'npm' }); + _b = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(preferNpmConfig)]; + case 2: + _b.apply(void 0, [_c.sent()]).toBe('npm'); + return [2 /*return*/]; + } + }); + }); }); + it('should fallback to getCurrentPackageManager', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + mockGetCurrentPm.mockImplementationOnce(function () { return 'npm'; }); + _a = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(config)]; + case 1: + _a.apply(void 0, [_c.sent()]).toBe('npm'); + mockGetCurrentPm.mockImplementationOnce(function () { return 'yarn'; }); + _b = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(config)]; + case 2: + _b.apply(void 0, [_c.sent()]).toBe('yarn'); + return [2 /*return*/]; + } + }); + }); }); + it('should try to read from lockfile', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + mockGetPmFromLock.mockImplementationOnce(function () { return 'npm'; }); + _a = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(config)]; + case 1: + _a.apply(void 0, [_c.sent()]).toBe('npm'); + mockGetPmFromLock.mockImplementationOnce(function () { return 'yarn'; }); + _b = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(config)]; + case 2: + _b.apply(void 0, [_c.sent()]).toBe('yarn'); + return [2 /*return*/]; + } + }); + }); }); + it('should always fallback to npm', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(config)]; + case 1: + _a.apply(void 0, [_b.sent()]).toBe('npm'); + return [2 /*return*/]; + } + }); + }); }); + it('should try the other package manager if one is missing', function () { return __awaiter(void 0, void 0, void 0, function () { + var c, _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + mockIsManagerInstalled.mockImplementation(function (manager) { + return Promise.resolve(manager === 'yarn' ? false : true); + }); + c = __assign(__assign({}, config), { prefer: 'yarn' }); + _a = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(c)]; + case 1: + _a.apply(void 0, [_c.sent()]).toBe('npm'); + expect(mockIsManagerInstalled).toHaveBeenCalledTimes(2); + expect(mockIsManagerInstalled).toHaveBeenCalledWith('yarn'); + expect(mockIsManagerInstalled).toHaveBeenLastCalledWith('npm'); + mockIsManagerInstalled.mockClear(); + mockIsManagerInstalled.mockImplementation(function (manager) { + return Promise.resolve(manager === 'npm' ? false : true); + }); + c = __assign(__assign({}, config), { prefer: 'npm' }); + _b = expect; + return [4 /*yield*/, package_manager_1.getPackageManager(c)]; + case 2: + _b.apply(void 0, [_c.sent()]).toBe('yarn'); + expect(mockIsManagerInstalled).toHaveBeenCalledTimes(2); + expect(mockIsManagerInstalled).toHaveBeenCalledWith('npm'); + expect(mockIsManagerInstalled).toHaveBeenLastCalledWith('yarn'); + return [2 /*return*/]; + } + }); + }); }); + it('should throw an error if no manager is installed', function () { return __awaiter(void 0, void 0, void 0, function () { + var c, err_1; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + c = __assign(__assign({}, config), { prefer: 'yarn' }); + mockIsManagerInstalled.mockImplementation(function () { return Promise.resolve(false); }); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 4]); + return [4 /*yield*/, package_manager_1.getPackageManager(c)]; + case 2: + _a.sent(); + return [3 /*break*/, 4]; + case 3: + err_1 = _a.sent(); + expect(err_1.message).toBe('No supported package manager found'); + return [3 /*break*/, 4]; + case 4: return [2 /*return*/]; + } + }); + }); }); +}); +describe('getPackageManagerSync', function () { + var config = __assign(__assign({}, config_1.defaultInstallConfig), { cwd: '/' }); + beforeEach(function () { + mockGetCurrentPm.mockRestore(); + mockGetCurrentPm.mockImplementation(function () { return null; }); + mockGetPmFromLockSync.mockRestore(); + mockGetPmFromLockSync.mockImplementation(function () { return null; }); + mockIsManagerInstalledSync.mockRestore(); + mockIsManagerInstalledSync.mockImplementation(function () { return true; }); + }); + it('should respect the prefer flag', function () { + var preferYarnConfig = __assign(__assign({}, config), { prefer: 'yarn' }); + expect(package_manager_1.getPackageManagerSync(preferYarnConfig)).toBe('yarn'); + var preferNpmConfig = __assign(__assign({}, config), { prefer: 'npm' }); + expect(package_manager_1.getPackageManagerSync(preferNpmConfig)).toBe('npm'); + }); + it('should fallback to getCurrentPackageManager', function () { + mockGetCurrentPm.mockImplementationOnce(function () { return 'npm'; }); + expect(package_manager_1.getPackageManagerSync(config)).toBe('npm'); + mockGetCurrentPm.mockImplementationOnce(function () { return 'yarn'; }); + expect(package_manager_1.getPackageManagerSync(config)).toBe('yarn'); + }); + it('should try to read from lockfile', function () { + mockGetPmFromLockSync.mockImplementationOnce(function () { return 'npm'; }); + expect(package_manager_1.getPackageManagerSync(config)).toBe('npm'); + mockGetPmFromLockSync.mockImplementationOnce(function () { return 'yarn'; }); + expect(package_manager_1.getPackageManagerSync(config)).toBe('yarn'); + }); + it('should always fallback to npm', function () { + expect(package_manager_1.getPackageManagerSync(config)).toBe('npm'); + }); + it('should try the other package manager if one is missing', function () { + mockIsManagerInstalledSync.mockImplementation(function (manager) { + return manager === 'yarn' ? false : true; + }); + var c = __assign(__assign({}, config), { prefer: 'yarn' }); + expect(package_manager_1.getPackageManagerSync(c)).toBe('npm'); + expect(mockIsManagerInstalledSync).toHaveBeenCalledTimes(2); + expect(mockIsManagerInstalledSync).toHaveBeenCalledWith('yarn'); + expect(mockIsManagerInstalledSync).toHaveBeenLastCalledWith('npm'); + mockIsManagerInstalledSync.mockClear(); + mockIsManagerInstalledSync.mockImplementation(function (manager) { + return manager === 'npm' ? false : true; + }); + c = __assign(__assign({}, config), { prefer: 'npm' }); + expect(package_manager_1.getPackageManagerSync(c)).toBe('yarn'); + expect(mockIsManagerInstalledSync).toHaveBeenCalledTimes(2); + expect(mockIsManagerInstalledSync).toHaveBeenCalledWith('npm'); + expect(mockIsManagerInstalledSync).toHaveBeenLastCalledWith('yarn'); + }); + it('should throw an error if no manager is installed', function () { + var c = __assign(__assign({}, config), { prefer: 'yarn' }); + mockIsManagerInstalledSync.mockImplementation(function () { return false; }); + try { + package_manager_1.getPackageManagerSync(c); + } + catch (err) { + expect(err.message).toBe('No supported package manager found'); + } + }); +}); +//# sourceMappingURL=package-manager.js.map \ No newline at end of file diff --git a/lib/__tests__/package-manager.js.map b/lib/__tests__/package-manager.js.map new file mode 100644 index 0000000..44f4810 --- /dev/null +++ b/lib/__tests__/package-manager.js.map @@ -0,0 +1 @@ +{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../../src/__tests__/package-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAM,gBAAgB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACnC,IAAM,iBAAiB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACpC,IAAM,sBAAsB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACzC,IAAM,qBAAqB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACxC,IAAM,0BAA0B,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE7C,IAAI,CAAC,IAAI,CAAC,gCAAgC,EAAE;IAC1C,OAAO;QACL,wBAAwB,EAAE,gBAAgB;QAC1C,6BAA6B,EAAE,iBAAiB;QAChD,kBAAkB,EAAE,sBAAsB;QAC1C,sBAAsB,EAAE,0BAA0B;QAClD,iCAAiC,EAAE,qBAAqB;KACzD,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,oCAAgE;AAChE,sDAA8E;AAE9E,QAAQ,CAAC,mBAAmB,EAAE;IAC5B,IAAM,MAAM,yBACP,6BAAoB,KACvB,GAAG,EAAE,GAAG,GACT,CAAC;IAEF,UAAU,CAAC;QACT,gBAAgB,CAAC,WAAW,EAAE,CAAC;QAC/B,gBAAgB,CAAC,kBAAkB,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC,CAAC;QAChD,iBAAiB,CAAC,WAAW,EAAE,CAAC;QAChC,iBA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AK,CAAC,CAAC,CAAC,IAAI,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,CAAC,GAAG,sBAAK,MAAM,KAAE,MAAM,EAAE,KAAK,GAAmB,CAAC;QAClD,MAAM,CAAC,uCAAqB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9C,MAAM,CAAC,0BAA0B,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,0BAA0B,CAAC,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;QAC/D,MAAM,CAAC,0BAA0B,CAAC,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE;QACrD,IAAM,CAAC,GAAG,sBAAK,MAAM,KAAE,MAAM,EAAE,MAAM,GAAmB,CAAC;QACzD,0BAA0B,CAAC,kBAAkB,CAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC,CAAC;QAC3D,IAAI;YACF,uCAAqB,CAAC,CAAC,CAAC,CAAC;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;SAChE;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/yarn.d.ts b/lib/__tests__/yarn.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/__tests__/yarn.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/__tests__/yarn.js b/lib/__tests__/yarn.js new file mode 100644 index 0000000..2acea71 --- /dev/null +++ b/lib/__tests__/yarn.js @@ -0,0 +1,82 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var config_1 = require("../config"); +var yarn_1 = require("../yarn"); +describe('constructYarnArguments', function () { + var packageList = ['twilio', 'twilio-run@1']; + it('should handle default config', function () { + var _a = yarn_1.constructYarnArguments(packageList, config_1.defaultInstallConfig), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['add'], packageList)); + expect(ignoredFlags.length).toBe(0); + }); + it('should add dev flag', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['add'], packageList, ['--dev'])); + expect(ignoredFlags.length).toBe(0); + }); + it('should ignore dev flag when global', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true, global: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['global', 'add'], packageList)); + expect(ignoredFlags).toEqual(['dev']); + }); + it('should add exact flag', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { exact: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['add'], packageList, ['--exact'])); + expect(ignoredFlags.length).toBe(0); + }); + it('should add verbose flag', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { verbose: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['add'], packageList, ['--verbose'])); + expect(ignoredFlags.length).toBe(0); + }); + it('should ignore noSave option', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { noSave: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['add'], packageList)); + expect(ignoredFlags).toEqual(['noSave']); + }); + it('should ignore bundle option', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { bundle: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['add'], packageList)); + expect(ignoredFlags).toEqual(['bundle']); + }); + it('should handle global option', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { global: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['global', 'add'], packageList)); + expect(ignoredFlags.length).toBe(0); + }); + it('should handle forceCwd flag', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { forceCwd: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays(['--cwd', process.cwd(), 'add'], packageList)); + expect(ignoredFlags.length).toBe(0); + }); + it('should handle all flags', function () { + var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true, exact: true, verbose: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; + expect(output).toEqual(__spreadArrays([ + 'add' + ], packageList, [ + '--dev', + '--exact', + '--verbose', + ])); + expect(ignoredFlags.length).toBe(0); + }); +}); +//# sourceMappingURL=yarn.js.map \ No newline at end of file diff --git a/lib/__tests__/yarn.js.map b/lib/__tests__/yarn.js.map new file mode 100644 index 0000000..a271dde --- /dev/null +++ b/lib/__tests__/yarn.js.map @@ -0,0 +1 @@ +{"version":3,"file":"yarn.js","sourceRoot":"","sources":["../../src/__tests__/yarn.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,oCAAi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C,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/config.d.ts b/lib/config.d.ts new file mode 100644 index 0000000..75f3401 --- /dev/null +++ b/lib/config.d.ts @@ -0,0 +1,43 @@ +import { StdioOption, SupportedPackageManagers } from './types'; +export declare type PackageManagerFlagConfig = { + /** Installs the passed dependencies as dev dependencies */ + dev: boolean; + /** Uses the save exact functionality of pkg manager */ + exact: boolean; + /** Does not write the dependency to package.json (*only available for npm*) */ + noSave: boolean; + /** Saves dependency as bundled dependency (*only available for npm*) */ + bundle: boolean; + /** Runs package manager in verbose mode */ + verbose: boolean; +}; +export declare type PackageManagerFlag = keyof PackageManagerFlagConfig; +export declare const ValidPackageFlags: Set; +export declare type ProjectInstallFlagConfig = { + dryRun: boolean; + verbose: boolean; +}; +export declare type ProjectInstallFlag = keyof ProjectInstallFlagConfig; +export declare const ValidProjectInstallFlags: Set; +export declare type GenericInstallConfig = { + /** Allows you to "force" package manager if available */ + prefer: SupportedPackageManagers | null; + /** Passes to execa in which way the I/O should be passed */ + stdio: StdioOption | StdioOption[]; + /** Working directory in which to run the package manager */ + cwd: string; +}; +/** + * Available options to modify the behavior of `install` and `installSync` + */ +export declare type InstallConfig = PackageManagerFlagConfig & GenericInstallConfig & { + /** Installs packages globally */ + global: boolean; + /** Passes cwd value within the parameters */ + forceCwd: boolean; +}; +export declare type ProjectInstallConfig = GenericInstallConfig & ProjectInstallFlagConfig & {}; +/** + * Default options for `install` and `installSync` + */ +export declare const defaultInstallConfig: InstallConfig; diff --git a/lib/config.js b/lib/config.js new file mode 100644 index 0000000..08d1fae --- /dev/null +++ b/lib/config.js @@ -0,0 +1,37 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.defaultInstallConfig = exports.ValidProjectInstallFlags = exports.ValidPackageFlags = void 0; +exports.ValidPackageFlags = new Set([ + 'dev', + 'exact', + 'noSave', + 'bundle', + 'verbose', +]); +exports.ValidProjectInstallFlags = new Set(['dryRun', 'verbose']); +/** + * Default options for `install` and `installSync` + */ +exports.defaultInstallConfig = { + /** Installs the passed dependencies as dev dependencies */ + dev: false, + /** Allows you to "force" package manager if available */ + prefer: null, + /** Uses the save exact functionality of pkg manager */ + exact: false, + /** Does not write the dependency to package.json (*only available for npm*) */ + noSave: false, + /** Saves dependency as bundled dependency (*only available for npm*) */ + bundle: false, + /** Runs package manager in verbose mode */ + verbose: false, + /** Installs packages globally */ + global: false, + /** Passes to execa in which way the I/O should be passed */ + stdio: 'pipe', + /** Working directory in which to run the package manager */ + cwd: process.cwd(), + /** Passes cwd value within the parameters */ + forceCwd: false +}; +//# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/lib/config.js.map b/lib/config.js.map new file mode 100644 index 0000000..d5ffef6 --- /dev/null +++ b/lib/config.js.map @@ -0,0 +1 @@ +{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAgBa,QAAA,iBAAiB,GAAG,IAAI,GAAG,CAAS;IAC/C,KAAK;IACL,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,SAAS;CACV,CAAC,CAAC;AAOU,QAAA,wBAAwB,GAAG,IAAI,GAAG,CAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAyB/E;;GAEG;AACU,QAAA,oBAAoB,GAAkB;IACjD,2DAA2D;IAC3D,GAAG,EAAE,KAAK;IACV,yDAAyD;IACzD,MAAM,EAAE,IAAI;IACZ,uDAAuD;IACvD,KAAK,EAAE,KAAK;IACZ,+EAA+E;IAC/E,MAAM,EAAE,KAAK;IACb,wEAAwE;IACxE,MAAM,EAAE,KAAK;IACb,2CAA2C;IAC3C,OAAO,EAAE,KAAK;IACd,iCAAiC;IACjC,MAAM,EAAE,KAAK;IACb,4DAA4D;IAC5D,KAAK,EAAE,MAAqB;IAC5B,4DAA4D;IAC5D,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAClB,6CAA6C;IAC7C,QAAQ,EAAE,KAAK;CAChB,CAAC"} \ No newline at end of file diff --git a/lib/flags.d.ts b/lib/flags.d.ts new file mode 100644 index 0000000..8e534eb --- /dev/null +++ b/lib/flags.d.ts @@ -0,0 +1,2 @@ +import { PackageManagerFlag, PackageManagerFlagConfig } from './config'; +export declare function getFlagsToSet(config: PackageManagerFlagConfig): PackageManagerFlag[]; diff --git a/lib/flags.js b/lib/flags.js new file mode 100644 index 0000000..eab6ff6 --- /dev/null +++ b/lib/flags.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getFlagsToSet = void 0; +var config_1 = require("./config"); +function getFlagsToSet(config) { + return Object.entries(config) + .filter(function (entry) { + var flag = entry[0], value = entry[1]; + if (!value) { + return false; + } + return config_1.ValidPackageFlags.has(flag); + }) + .map(function (entry) { + return entry[0]; + }); +} +exports.getFlagsToSet = getFlagsToSet; +//# sourceMappingURL=flags.js.map \ No newline at end of file diff --git a/lib/flags.js.map b/lib/flags.js.map new file mode 100644 index 0000000..de2b3f8 --- /dev/null +++ b/lib/flags.js.map @@ -0,0 +1 @@ +{"version":3,"file":"flags.js","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":";;;AAAA,mCAIkB;AAElB,SAAgB,aAAa,CAC3B,MAAgC;IAEhC,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;SAC1B,MAAM,CAAC,UAAA,KAAK;QACJ,IAAA,IAAI,GAAW,KAAK,GAAhB,EAAE,KAAK,GAAI,KAAK,GAAT,CAAU;QAC5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,KAAK,CAAC;SACd;QACD,OAAO,0BAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC;SACD,GAAG,CAAC,UAAA,KAAK;QACR,OAAO,KAAK,CAAC,CAAC,CAAuB,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC;AAdD,sCAcC"} \ No newline at end of file diff --git a/lib/helpers.d.ts b/lib/helpers.d.ts new file mode 100644 index 0000000..6316843 --- /dev/null +++ b/lib/helpers.d.ts @@ -0,0 +1,11 @@ +import execa from 'execa'; +import { InstallConfig } from './config'; +import { PackageList, Packages } from './types'; +export declare function getPackageList(packages: Packages): PackageList; +export declare function getExecaConfig(config: InstallConfig): execa.CommonOptions; +/** + * Error class used for cases that can't be reached. It's a helper for TypeScript + */ +export declare class UnreachableCaseError extends Error { + constructor(val: never); +} diff --git a/lib/helpers.js b/lib/helpers.js new file mode 100644 index 0000000..9518e7b --- /dev/null +++ b/lib/helpers.js @@ -0,0 +1,53 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UnreachableCaseError = exports.getExecaConfig = exports.getPackageList = void 0; +function getPackageList(packages) { + if (Array.isArray(packages)) { + return packages.filter(function (pkg) { return typeof pkg === 'string'; }); + } + var entries = Object.entries(packages); + return entries + .filter(function (_a) { + var name = _a[0], version = _a[1]; + return ((typeof name === 'string' && typeof version === 'string') || + typeof version === 'undefined'); + }) + .map(function (_a) { + var name = _a[0], version = _a[1]; + return version ? name + "@" + version : name; + }); +} +exports.getPackageList = getPackageList; +function getExecaConfig(config) { + return { + stdio: config.stdio, + cwd: config.cwd, + }; +} +exports.getExecaConfig = getExecaConfig; +/** + * Error class used for cases that can't be reached. It's a helper for TypeScript + */ +var UnreachableCaseError = /** @class */ (function (_super) { + __extends(UnreachableCaseError, _super); + /* istanbul ignore next */ + function UnreachableCaseError(val) { + return _super.call(this, "Unreachable case: " + val) || this; + } + return UnreachableCaseError; +}(Error)); +exports.UnreachableCaseError = UnreachableCaseError; +//# sourceMappingURL=helpers.js.map \ No newline at end of file diff --git a/lib/helpers.js.map b/lib/helpers.js.map new file mode 100644 index 0000000..4fbd84a --- /dev/null +++ b/lib/helpers.js.map @@ -0,0 +1 @@ +{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAIA,SAAgB,cAAc,CAAC,QAAkB;IAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,OAAO,QAAQ,CAAC,MAAM,CAAC,UAAA,GAAG,IAAI,OAAA,OAAO,GAAG,KAAK,QAAQ,EAAvB,CAAuB,CAAC,CAAC;KACxD;IAED,IAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEzC,OAAO,OAAO;SACX,MAAM,CAAC,UAAC,EAAe;YAAd,IAAI,QAAA,EAAE,OAAO,QAAA;QACrB,OAAO,CACL,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;YACzD,OAAO,OAAO,KAAK,WAAW,CAC/B,CAAC;IACJ,CAAC,CAAC;SACD,GAAG,CAAC,UAAC,EAAe;YAAd,IAAI,QAAA,EAAE,OAAO,QAAA;QAClB,OAAO,OAAO,CAAC,CAAC,CAAI,IAAI,SAAI,OAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC;AAjBD,wCAiBC;AAED,SAAgB,cAAc,CAAC,MAAqB;IAClD,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,GAAG,EAAE,MAAM,CAAC,GAAG;KAChB,CAAC;AACJ,CAAC;AALD,wCAKC;AAED;;GAEG;AACH;IAA0C,wCAAK;IAC7C,0BAA0B;IAC1B,8BAAY,GAAU;eACpB,kBAAM,uBAAqB,GAAK,CAAC;IACnC,CAAC;IACH,2BAAC;AAAD,CAAC,AALD,CAA0C,KAAK,GAK9C;AALY,oDAAoB"} \ No newline at end of file diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..745627a --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,9 @@ +/** + * @module pkg-install + * @preferred + * + * Main entry point of the project + */ +export * from './install'; +export * from './package-manager'; +export * from './types'; diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..c857c23 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,22 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * @module pkg-install + * @preferred + * + * Main entry point of the project + */ +__exportStar(require("./install"), exports); +__exportStar(require("./package-manager"), exports); +__exportStar(require("./types"), exports); +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/index.js.map b/lib/index.js.map new file mode 100644 index 0000000..b19734f --- /dev/null +++ b/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;GAKG;AACH,4CAA0B;AAC1B,oDAAkC;AAClC,0CAAwB"} \ No newline at end of file diff --git a/lib/install.d.ts b/lib/install.d.ts new file mode 100644 index 0000000..50ccbb3 --- /dev/null +++ b/lib/install.d.ts @@ -0,0 +1,59 @@ +/** @module pkg-install */ +import execa from 'execa'; +import { InstallConfig, PackageManagerFlag } from './config'; +import { PackageList, Packages } from './types'; +export declare type InstallResult = execa.ExecaReturns & { + ignoredFlags: PackageManagerFlag[]; +}; +/** + * Installs a passed set of packages using either npm or yarn. Depending on: + * 1) If you specify a preferred package manager + * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) + * 3) What package manager is available + * + * @export + * @param {Packages} packages List or object of packages to be installed + * @param {Partial} [options={}] Options to modify behavior + * @returns {Promise} + */ +export declare function install(packages: Packages, options?: Partial): Promise; +/** + * SYNC VERSION. Installs a passed set of packages using either npm or yarn. Depending on: + * + * 1) If you specify a preferred package manager + * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) + * 3) If there is a yarn.lock or package-lock.json available + * 4) What package manager is available + * + * @export + * @param {Packages} packages List or object of packages to be installed + * @param {Partial} [options={}] Options to modify behavior + * @returns {InstallResult} + */ +export declare function installSync(packages: PackageList, options?: Partial): InstallResult; +/** + * Runs `npm install` or `yarn install` for the project. Depending on: + * + * 1) If you specify a preferred package manager + * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) + * 3) If there is a yarn.lock or package-lock.json available + * 4) What package manager is available + * + * @export + * @param {Partial} [options={}] Options to modify behavior + * @returns {Promise} + */ +export declare function projectInstall(options?: Partial): Promise; +/** + * SYNC VERSION. Runs `npm install` or `yarn install` for the project. Depending on: + * + * 1) If you specify a preferred package manager + * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) + * 3) If there is a yarn.lock or package-lock.json available + * 4) What package manager is available + * + * @export + * @param {Partial} [options={}] Options to modify behavior + * @returns {execa.ExecaReturns} + */ +export declare function projectInstallSync(options?: Partial): execa.ExecaReturns; diff --git a/lib/install.js b/lib/install.js new file mode 100644 index 0000000..b697b0a --- /dev/null +++ b/lib/install.js @@ -0,0 +1,169 @@ +"use strict"; +/** @module pkg-install */ +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.projectInstallSync = exports.projectInstall = exports.installSync = exports.install = void 0; +var execa_1 = __importDefault(require("execa")); +var config_1 = require("./config"); +var helpers_1 = require("./helpers"); +var npm_1 = require("./npm"); +var package_manager_1 = require("./package-manager"); +var yarn_1 = require("./yarn"); +/** + * Installs a passed set of packages using either npm or yarn. Depending on: + * 1) If you specify a preferred package manager + * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) + * 3) What package manager is available + * + * @export + * @param {Packages} packages List or object of packages to be installed + * @param {Partial} [options={}] Options to modify behavior + * @returns {Promise} + */ +function install(packages, options) { + if (options === void 0) { options = config_1.defaultInstallConfig; } + return __awaiter(this, void 0, void 0, function () { + var config, pkgManager, packageList, getArguments, _a, args, ignoredFlags, result; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + config = __assign(__assign({}, config_1.defaultInstallConfig), options); + return [4 /*yield*/, package_manager_1.getPackageManager(config)]; + case 1: + pkgManager = _b.sent(); + packageList = helpers_1.getPackageList(packages); + getArguments = pkgManager === 'npm' ? npm_1.constructNpmArguments : yarn_1.constructYarnArguments; + _a = getArguments(packageList, config), args = _a.args, ignoredFlags = _a.ignoredFlags; + return [4 /*yield*/, execa_1.default(pkgManager, args, helpers_1.getExecaConfig(config))]; + case 2: + result = _b.sent(); + return [2 /*return*/, __assign(__assign({}, result), { ignoredFlags: ignoredFlags })]; + } + }); + }); +} +exports.install = install; +/** + * SYNC VERSION. Installs a passed set of packages using either npm or yarn. Depending on: + * + * 1) If you specify a preferred package manager + * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) + * 3) If there is a yarn.lock or package-lock.json available + * 4) What package manager is available + * + * @export + * @param {Packages} packages List or object of packages to be installed + * @param {Partial} [options={}] Options to modify behavior + * @returns {InstallResult} + */ +function installSync(packages, options) { + if (options === void 0) { options = config_1.defaultInstallConfig; } + var config = __assign(__assign({}, config_1.defaultInstallConfig), options); + var pkgManager = package_manager_1.getPackageManagerSync(config); + var packageList = helpers_1.getPackageList(packages); + var getArguments = pkgManager === 'npm' ? npm_1.constructNpmArguments : yarn_1.constructYarnArguments; + var _a = getArguments(packageList, config), args = _a.args, ignoredFlags = _a.ignoredFlags; + var result = execa_1.default.sync(pkgManager, args, helpers_1.getExecaConfig(config)); + return __assign(__assign({}, result), { ignoredFlags: ignoredFlags }); +} +exports.installSync = installSync; +/** + * Runs `npm install` or `yarn install` for the project. Depending on: + * + * 1) If you specify a preferred package manager + * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) + * 3) If there is a yarn.lock or package-lock.json available + * 4) What package manager is available + * + * @export + * @param {Partial} [options={}] Options to modify behavior + * @returns {Promise} + */ +function projectInstall(options) { + if (options === void 0) { options = config_1.defaultInstallConfig; } + return __awaiter(this, void 0, void 0, function () { + var config, pkgManager, args; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + config = __assign(__assign({}, config_1.defaultInstallConfig), options); + return [4 /*yield*/, package_manager_1.getPackageManager(config)]; + case 1: + pkgManager = _a.sent(); + args = pkgManager === 'npm' ? npm_1.npmProjectInstallArgs : yarn_1.yarnProjectInstallArgs; + return [2 /*return*/, execa_1.default(pkgManager, args, helpers_1.getExecaConfig(config))]; + } + }); + }); +} +exports.projectInstall = projectInstall; +/** + * SYNC VERSION. Runs `npm install` or `yarn install` for the project. Depending on: + * + * 1) If you specify a preferred package manager + * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) + * 3) If there is a yarn.lock or package-lock.json available + * 4) What package manager is available + * + * @export + * @param {Partial} [options={}] Options to modify behavior + * @returns {execa.ExecaReturns} + */ +function projectInstallSync(options) { + if (options === void 0) { options = config_1.defaultInstallConfig; } + var config = __assign(__assign({}, config_1.defaultInstallConfig), options); + var pkgManager = package_manager_1.getPackageManagerSync(config); + var args = pkgManager === 'npm' ? npm_1.npmProjectInstallArgs : yarn_1.yarnProjectInstallArgs; + return execa_1.default.sync(pkgManager, args, helpers_1.getExecaConfig(config)); +} +exports.projectInstallSync = projectInstallSync; +//# sourceMappingURL=install.js.map \ No newline at end of file diff --git a/lib/install.js.map b/lib/install.js.map new file mode 100644 index 0000000..1c0c3cb --- /dev/null +++ b/lib/install.js.map @@ -0,0 +1 @@ +{"version":3,"file":"install.js","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,gDAA0B;AAC1B,mCAIkB;AAClB,qCAA2D;AAC3D,6BAAqE;AACrE,qDAA6E;AAE7E,+BAAwE;AAMxE;;;;;;;;;;GAUG;AACH,SAAsB,OAAO,CAC3B,QAAkB,EAClB,OAAsD;IAAtD,wBAAA,EAAA,UAAkC,6BAAoB;;;;;;oBAEhD,MAAM,yBAAuB,6BAAoB,GAAK,OAAO,CAAE,CAAC;oBACnD,qBAAM,mCAAiB,CAAC,MAAM,CAAC,EAAA;;oBAA5C,UAAU,GAAG,SAA+B;oBAE5C,WAAW,GAAG,wBAAc,CAAC,QAAQ,CAAC,CAAC;oBACvC,YAAY,GAChB,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,2BAAqB,CAAC,CAAC,CAAC,6BAAsB,CAAC;oBAClE,KAAyB,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,EAAxD,IAAI,UAAA,EAAE,YAAY,kBAAA,CAAuC;oBAElD,qBAAM,eAAK,CAAC,UAAU,EAAE,IAAI,EAAE,wBAAc,CAAC,MAAM,CAAC,CAAC,EAAA;;oBAA9D,MAAM,GAAG,SAAqD;oBACpE,4CACK,MAAM,KACT,YAAY,cAAA,KACZ;;;;CACH;AAjBD,0BAiBC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,WAAW,CACzB,QAAqB,EACrB,OAAsD;IAAtD,wBAAA,EAAA,UAAkC,6BAAoB;IAEtD,IAAM,MAAM,yBAAuB,6BAAoB,GAAK,OAAO,CAAE,CAAC;IACtE,IAAM,UAAU,GA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,eAAK,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,wBAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC;AAVD,gDAUC"} \ No newline at end of file diff --git a/lib/npm.d.ts b/lib/npm.d.ts new file mode 100644 index 0000000..f562c55 --- /dev/null +++ b/lib/npm.d.ts @@ -0,0 +1,4 @@ +import { InstallConfig } from './config'; +import { ConstructArgumentsResult, PackageList } from './types'; +export declare function constructNpmArguments(packageList: PackageList, config: InstallConfig): ConstructArgumentsResult; +export declare const npmProjectInstallArgs: string[]; diff --git a/lib/npm.js b/lib/npm.js new file mode 100644 index 0000000..00787da --- /dev/null +++ b/lib/npm.js @@ -0,0 +1,50 @@ +"use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.npmProjectInstallArgs = exports.constructNpmArguments = void 0; +var flags_1 = require("./flags"); +var helpers_1 = require("./helpers"); +function constructNpmArguments(packageList, config) { + var flagsToSet = flags_1.getFlagsToSet(config); + var globalCommand = config.global ? ['-g'] : []; + var cwdCommand = config.forceCwd ? ['--prefix', config.cwd] : []; + var args = __spreadArrays(['install'], globalCommand, cwdCommand, packageList); + var ignoredFlags = []; + flagsToSet.forEach(function (flag) { + switch (flag) { + case 'dev': + if (!config.global) { + args.push('--save-dev'); + } + else { + ignoredFlags.push(flag); + } + break; + case 'exact': + args.push('--save-exact'); + break; + case 'verbose': + args.push('--verbose'); + break; + case 'bundle': + args.push('--save-bundle'); + break; + case 'noSave': + args.push('--no-save'); + break; + /* istanbul ignore next */ + default: + throw new helpers_1.UnreachableCaseError(flag); + } + }); + return { args: args, ignoredFlags: ignoredFlags }; +} +exports.constructNpmArguments = constructNpmArguments; +exports.npmProjectInstallArgs = ['install']; +//# sourceMappingURL=npm.js.map \ No newline at end of file diff --git a/lib/npm.js.map b/lib/npm.js.map new file mode 100644 index 0000000..2c04481 --- /dev/null +++ b/lib/npm.js.map @@ -0,0 +1 @@ +{"version":3,"file":"npm.js","sourceRoot":"","sources":["../src/npm.ts"],"names":[],"mappings":";;;;;;;;;;AACA,iCAAwC;AACxC,qCAAiD;AAGjD,SAAgB,qBAAqB,CACnC,WAAwB,EACxB,MAAqB;IAErB,IAAM,UAAU,GAAG,qBAAa,CAAC,MAAM,CAAC,CAAC;IACzC,IAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,IAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,IAAM,IAAI,mBAAc,SAAS,GAAK,aAAa,EAAK,UAAU,EAAK,WAAW,CAAC,CAAC;IAEpF,IAAM,YAAY,GAAyB,EAAE,CAAC;IAC9C,UAAU,CAAC,OAAO,CAAC,UAAA,IAAI;QACrB,QAAQ,IAAI,EAAE;YACZ,KAAK,KAAK;gBACR,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;oBAClB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACzB;qBAAM;oBACL,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACzB;gBACD,MAAM;YACR,KAAK,OAAO;gBACV,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAC1B,MAAM;YACR,KAAK,SAAS;gBACZ,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBACvB,MAAM;YACR,KAAK,QAAQ;gBACX,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;gBAC3B,MAAM;YACR,KAAK,QAAQ;gBACX,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBACvB,MAAM;YACR,0BAA0B;YAC1B;gBACE,MAAM,IAAI,8BAAoB,CAAC,IAAI,CAAC,CAAC;SACxC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,IAAI,MAAA,EAAE,YAAY,cAAA,EAAE,CAAC;AAChC,CAAC;AAtCD,sDAsCC;AAEY,QAAA,qBAAqB,GAAG,CAAC,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/package-manager.d.ts b/lib/package-manager.d.ts new file mode 100644 index 0000000..ef4c5f8 --- /dev/null +++ b/lib/package-manager.d.ts @@ -0,0 +1,21 @@ +/** @module pkg-install */ +import { InstallConfig } from './config'; +import { SupportedPackageManagers } from './types'; +/** + * Determine what package manager to use based on what preference is set, + * and whether it's currently running in a yarn/npm/pnpm script + * + * @export + * @param {InstallConfig} config + * @returns {Promise} + */ +export declare function getPackageManager(config: InstallConfig): Promise; +/** + * SYNC: Determine what package manager to use based on what preference is set, + * and whether it's currently running in a yarn/npm script + * + * @export + * @param {InstallConfig} config + * @returns {SupportedPackageManagers} + */ +export declare function getPackageManagerSync(config: InstallConfig): SupportedPackageManagers; diff --git a/lib/package-manager.js b/lib/package-manager.js new file mode 100644 index 0000000..0171b2e --- /dev/null +++ b/lib/package-manager.js @@ -0,0 +1,107 @@ +"use strict"; +/** @module pkg-install */ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getPackageManagerSync = exports.getPackageManager = void 0; +var package_manager_utils_1 = require("./utils/package-manager-utils"); +/** + * Determine what package manager to use based on what preference is set, + * and whether it's currently running in a yarn/npm/pnpm script + * + * @export + * @param {InstallConfig} config + * @returns {Promise} + */ +function getPackageManager(config) { + return __awaiter(this, void 0, void 0, function () { + var pkgManager; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + pkgManager = config.prefer || package_manager_utils_1.getCurrentPackageManager(); + if (!!pkgManager) return [3 /*break*/, 2]; + return [4 /*yield*/, package_manager_utils_1.getPackageManagerFromLockfile(config)]; + case 1: + pkgManager = _a.sent(); + _a.label = 2; + case 2: + if (!pkgManager) { + pkgManager = 'npm'; + } + return [4 /*yield*/, package_manager_utils_1.isManagerInstalled(pkgManager)]; + case 3: + if (!!(_a.sent())) return [3 /*break*/, 5]; + pkgManager = pkgManager === 'npm' ? 'yarn' : 'npm'; + return [4 /*yield*/, package_manager_utils_1.isManagerInstalled(pkgManager)]; + case 4: + if (!(_a.sent())) { + throw new Error('No supported package manager found'); + } + _a.label = 5; + case 5: return [2 /*return*/, pkgManager]; + } + }); + }); +} +exports.getPackageManager = getPackageManager; +/** + * SYNC: Determine what package manager to use based on what preference is set, + * and whether it's currently running in a yarn/npm script + * + * @export + * @param {InstallConfig} config + * @returns {SupportedPackageManagers} + */ +function getPackageManagerSync(config) { + var pkgManager = config.prefer || package_manager_utils_1.getCurrentPackageManager(); + if (!pkgManager) { + pkgManager = package_manager_utils_1.getPackageManagerFromLockfileSync(config); + } + if (!pkgManager) { + pkgManager = 'npm'; + } + if (!package_manager_utils_1.isManagerInstalledSync(pkgManager)) { + pkgManager = pkgManager === 'npm' ? 'yarn' : 'npm'; + if (!package_manager_utils_1.isManagerInstalledSync(pkgManager)) { + throw new Error('No supported package manager found'); + } + } + return pkgManager; +} +exports.getPackageManagerSync = getPackageManagerSync; +//# sourceMappingURL=package-manager.js.map \ No newline at end of file diff --git a/lib/package-manager.js.map b/lib/package-manager.js.map new file mode 100644 index 0000000..4566ebb --- /dev/null +++ b/lib/package-manager.js.map @@ -0,0 +1 @@ +{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../src/package-manager.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI1B,uEAMuC;AAEvC;;;;;;;GAOG;AACH,SAAsB,iBAAiB,CACrC,MAAqB;;;;;;oBAEjB,UAAU,GAAG,MAAM,CAAC,MAAM,IAAI,gDAAwB,EAAE,CAAC;yBAEzD,CAAC,UAAU,EAAX,wBAAW;oBACA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,4 @@ +import { InstallConfig } from "./config"; +import { ConstructArgumentsResult, PackageList } from "./types"; +export declare function constructPnpmArguments(packageList: PackageList, config: InstallConfig): ConstructArgumentsResult; +export declare const pnpmProjectInstallArgs: string[]; diff --git a/lib/pnpm.js b/lib/pnpm.js new file mode 100644 index 0000000..0290ace --- /dev/null +++ b/lib/pnpm.js @@ -0,0 +1,50 @@ +"use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.pnpmProjectInstallArgs = exports.constructPnpmArguments = void 0; +var flags_1 = require("./flags"); +var helpers_1 = require("./helpers"); +function constructPnpmArguments(packageList, config) { + var flagsToSet = flags_1.getFlagsToSet(config); + var globalCommand = config.global ? ["--global"] : []; + var cwdCommand = config.forceCwd ? ["--pnpm-prefix", config.cwd] : []; + var args = __spreadArrays([ + "install" + ], globalCommand, cwdCommand, [ + "add" + ], packageList); + var ignoredFlags = []; + flagsToSet.forEach(function (flag) { + switch (flag) { + case "dev": + if (!config.global) { + args.push("--save-dev"); + } + else { + ignoredFlags.push(flag); + } + break; + case "exact": + args.push("--save-exact"); + break; + case "verbose": + case "bundle": + case "noSave": + ignoredFlags.push(flag); + break; + /* istanbul ignore next */ + default: + throw new helpers_1.UnreachableCaseError(flag); + } + }); + return { args: args, ignoredFlags: ignoredFlags }; +} +exports.constructPnpmArguments = constructPnpmArguments; +exports.pnpmProjectInstallArgs = ["install"]; +//# sourceMappingURL=pnpm.js.map \ No newline at end of file diff --git a/lib/pnpm.js.map b/lib/pnpm.js.map new file mode 100644 index 0000000..a9fa584 --- /dev/null +++ b/lib/pnpm.js.map @@ -0,0 +1 @@ +{"version":3,"file":"pnpm.js","sourceRoot":"","sources":["../src/pnpm.ts"],"names":[],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git a/lib/types.d.ts b/lib/types.d.ts new file mode 100644 index 0000000..f86cb4e --- /dev/null +++ b/lib/types.d.ts @@ -0,0 +1,16 @@ +import { PackageManagerFlag } from './config'; +/** @module pkg-install */ +export declare type PackageMap = { + [packageName: string]: string | undefined; +}; +export declare type PackageList = string[]; +export declare type Packages = PackageMap | PackageList; +export declare type SupportedPackageManagers = 'yarn' | 'npm' | 'pnpm'; +/** + * What to do with I/O. This is passed to `execa` + */ +export declare type StdioOption = 'pipe' | 'ignore' | 'inherit'; +export declare type ConstructArgumentsResult = { + args: string[]; + ignoredFlags: PackageManagerFlag[]; +}; diff --git a/lib/types.js b/lib/types.js new file mode 100644 index 0000000..11e638d --- /dev/null +++ b/lib/types.js @@ -0,0 +1,3 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/lib/types.js.map b/lib/types.js.map new file mode 100644 index 0000000..c768b79 --- /dev/null +++ b/lib/types.js.map @@ -0,0 +1 @@ +{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib/utils/__tests__/package-manager-utils.d.ts b/lib/utils/__tests__/package-manager-utils.d.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/lib/utils/__tests__/package-manager-utils.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/utils/__tests__/package-manager-utils.js b/lib/utils/__tests__/package-manager-utils.js new file mode 100644 index 0000000..2325ad8 --- /dev/null +++ b/lib/utils/__tests__/package-manager-utils.js @@ -0,0 +1,223 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var shouldFailExeca = false; +var mockExeca = function () { + return { + failed: shouldFailExeca, + }; +}; +var asyncExeca = jest + .fn() + .mockImplementation(function () { return Promise.resolve(mockExeca()); }); +var syncExeca = jest.fn().mockImplementation(mockExeca); +Object.defineProperty(asyncExeca, 'sync', { + value: syncExeca, +}); +jest.mock('execa', function () { + return asyncExeca; +}); +var accessShouldFailOn = []; +var mockAccess = jest.fn().mockImplementation(function (path, callback) { + if (!accessShouldFailOn.includes(path)) { + return callback(null); + } + else { + return callback(new Error('Unit test failure message')); + } +}); +var mockAccessSync = jest.fn().mockImplementation(function (path) { + if (!accessShouldFailOn.includes(path)) { + return {}; + } + else { + throw new Error('Unit test failure message'); + } +}); +jest.mock('fs', function () { + return { + access: mockAccess, + accessSync: mockAccessSync, + }; +}); +var config_1 = require("../../config"); +var package_manager_utils_1 = require("../package-manager-utils"); +describe('isManagerInstalled', function () { + it('should call execa with the right paramters', function () { + package_manager_utils_1.isManagerInstalled('npm'); + expect(asyncExeca).toHaveBeenLastCalledWith('npm', ['--version']); + package_manager_utils_1.isManagerInstalled('yarn'); + expect(asyncExeca).toHaveBeenLastCalledWith('yarn', ['--version']); + }); + it('should forward the result', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a, _b; + return __generator(this, function (_c) { + switch (_c.label) { + case 0: + shouldFailExeca = false; + _a = expect; + return [4 /*yield*/, package_manager_utils_1.isManagerInstalled('npm')]; + case 1: + _a.apply(void 0, [_c.sent()]).toBe(true); + shouldFailExeca = true; + _b = expect; + return [4 /*yield*/, package_manager_utils_1.isManagerInstalled('npm')]; + case 2: + _b.apply(void 0, [_c.sent()]).toBe(false); + return [2 /*return*/]; + } + }); + }); }); +}); +describe('isManagerInstalledSync', function () { + it('should call execa with the right paramters', function () { + package_manager_utils_1.isManagerInstalledSync('npm'); + expect(syncExeca).toHaveBeenLastCalledWith('npm', ['--version']); + package_manager_utils_1.isManagerInstalledSync('yarn'); + expect(syncExeca).toHaveBeenLastCalledWith('yarn', ['--version']); + }); + it('should forward the result', function () { + shouldFailExeca = false; + expect(package_manager_utils_1.isManagerInstalledSync('npm')).toBe(true); + shouldFailExeca = true; + expect(package_manager_utils_1.isManagerInstalledSync('npm')).toBe(false); + }); +}); +describe('getCurrentPackageManager', function () { + var envBackup; + beforeEach(function () { + envBackup = __assign({}, process.env); + }); + afterEach(function () { + process.env = __assign({}, envBackup); + }); + it('should handle yarn user agents', function () { + process.env = { + npm_config_user_agent: 'yarn/1.13.0 npm/? node/v11.6.0 darwin x64', + }; + expect(package_manager_utils_1.getCurrentPackageManager()).toBe('yarn'); + }); + it('should handle npm user agents', function () { + process.env = { + npm_config_user_agent: 'npm/6.5.0 node/v11.6.0 darwin x64', + }; + expect(package_manager_utils_1.getCurrentPackageManager()).toBe('npm'); + }); + it('should handle missing user agents', function () { + process.env = {}; + expect(package_manager_utils_1.getCurrentPackageManager()).toBe(null); + }); + it('should handle invalid user agents', function () { + process.env = { + npm_config_user_agent: 'some-invalid-value', + }; + expect(package_manager_utils_1.getCurrentPackageManager()).toBe(null); + }); +}); +describe('getPackageManagerFromLockfile', function () { + var config = __assign(__assign({}, config_1.defaultInstallConfig), { cwd: '/' }); + it('should check for npm', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + accessShouldFailOn = []; + _a = expect; + return [4 /*yield*/, package_manager_utils_1.getPackageManagerFromLockfile(config)]; + case 1: + _a.apply(void 0, [_b.sent()]).toBe('npm'); + return [2 /*return*/]; + } + }); + }); }); + it('should check for yarn if npm does not exist', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + accessShouldFailOn = ['/package-lock.json']; + _a = expect; + return [4 /*yield*/, package_manager_utils_1.getPackageManagerFromLockfile(config)]; + case 1: + _a.apply(void 0, [_b.sent()]).toBe('yarn'); + return [2 /*return*/]; + } + }); + }); }); + it('should return null if no lock file exists', function () { return __awaiter(void 0, void 0, void 0, function () { + var _a; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + accessShouldFailOn = ['/package-lock.json', '/yarn.lock']; + _a = expect; + return [4 /*yield*/, package_manager_utils_1.getPackageManagerFromLockfile(config)]; + case 1: + _a.apply(void 0, [_b.sent()]).toBe(null); + return [2 /*return*/]; + } + }); + }); }); +}); +describe('getPackageManagerFromLockfileSync', function () { + var config = __assign(__assign({}, config_1.defaultInstallConfig), { cwd: '/' }); + it('should check for npm', function () { + accessShouldFailOn = []; + expect(package_manager_utils_1.getPackageManagerFromLockfileSync(config)).toBe('npm'); + }); + it('should check for yarn if npm does not exist', function () { + accessShouldFailOn = ['/package-lock.json']; + expect(package_manager_utils_1.getPackageManagerFromLockfileSync(config)).toBe('yarn'); + }); + it('should return null if no lock file exists', function () { + accessShouldFailOn = ['/package-lock.json', '/yarn.lock']; + expect(package_manager_utils_1.getPackageManagerFromLockfileSync(config)).toBe(null); + }); +}); +//# sourceMappingURL=package-manager-utils.js.map \ No newline at end of file diff --git a/lib/utils/__tests__/package-manager-utils.js.map b/lib/utils/__tests__/package-manager-utils.js.map new file mode 100644 index 0000000..490e66b --- /dev/null +++ b/lib/utils/__tests__/package-manager-utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"package-manager-utils.js","sourceRoot":"","sources":["../../../src/utils/__tests__/package-manager-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,eAAe,GAAG,KAAK,CAAC;AAC5B,IAAI,SAAS,GAAG;IACd,OAAO;QACL,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC,CAAC;AAEF,IAAM,UAAU,GAAG,IAAI;KACpB,EAAE,EAAE;KACJ,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,EAA5B,CAA4B,CAAC,CAAC;AAC1D,IAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAC1D,MAAM,CAAC,cAAc,CAAC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,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/utils/package-manager-utils.d.ts b/lib/utils/package-manager-utils.d.ts new file mode 100644 index 0000000..b037748 --- /dev/null +++ b/lib/utils/package-manager-utils.d.ts @@ -0,0 +1,47 @@ +/** @module pkg-install */ +import { InstallConfig } from '../config'; +import { SupportedPackageManagers } from '../types'; +/** + * Checks if a given package manager is currently installed by checking its version + * + * @export + * @param {SupportedPackageManagers} manager + * @returns {Promise} + */ +export declare function isManagerInstalled(manager: SupportedPackageManagers): Promise; +/** + * SYNC: Checks if a given package manager is currently installed by checking its version + * + * @export + * @param {SupportedPackageManagers} manager + * @returns {boolean} + */ +export declare function isManagerInstalledSync(manager: SupportedPackageManagers): boolean; +/** + * Returns the package manager currently active if the program is executed + * through an npm or yarn script like: + * ```bash + * yarn run example + * npm run example + * ``` + * + * @export + * @returns {(SupportedPackageManagers | null)} + */ +export declare function getCurrentPackageManager(): SupportedPackageManagers | null; +/** + * Checks for the presence of package-lock.json or yarn.lock to determine which package manager is being used + * + * @export + * @param {InstallConfig} config Config specifying current working directory + * @returns + */ +export declare function getPackageManagerFromLockfile(config: InstallConfig): Promise; +/** + * SYNC: Checks for the presence of package-lock.json or yarn.lock to determine which package manager is being used + * + * @export + * @param {InstallConfig} config Config specifying current working directory + * @returns + */ +export declare function getPackageManagerFromLockfileSync(config: InstallConfig): SupportedPackageManagers | null; diff --git a/lib/utils/package-manager-utils.js b/lib/utils/package-manager-utils.js new file mode 100644 index 0000000..bdf0425 --- /dev/null +++ b/lib/utils/package-manager-utils.js @@ -0,0 +1,194 @@ +"use strict"; +/** @module pkg-install */ +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getPackageManagerFromLockfileSync = exports.getPackageManagerFromLockfile = exports.getCurrentPackageManager = exports.isManagerInstalledSync = exports.isManagerInstalled = void 0; +var execa_1 = __importDefault(require("execa")); +var fs_1 = require("fs"); +var path_1 = __importDefault(require("path")); +var util_1 = require("util"); +var access = util_1.promisify(fs_1.access); +/** + * Checks if a given package manager is currently installed by checking its version + * + * @export + * @param {SupportedPackageManagers} manager + * @returns {Promise} + */ +function isManagerInstalled(manager) { + return __awaiter(this, void 0, void 0, function () { + var result; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, execa_1.default(manager, ['--version'])]; + case 1: + result = _a.sent(); + return [2 /*return*/, !result.failed]; + } + }); + }); +} +exports.isManagerInstalled = isManagerInstalled; +/** + * SYNC: Checks if a given package manager is currently installed by checking its version + * + * @export + * @param {SupportedPackageManagers} manager + * @returns {boolean} + */ +function isManagerInstalledSync(manager) { + var result = execa_1.default.sync(manager, ['--version']); + return !result.failed; +} +exports.isManagerInstalledSync = isManagerInstalledSync; +/** + * Returns the package manager currently active if the program is executed + * through an npm or yarn script like: + * ```bash + * yarn run example + * npm run example + * ``` + * + * @export + * @returns {(SupportedPackageManagers | null)} + */ +function getCurrentPackageManager() { + var userAgent = process.env.npm_config_user_agent; + if (!userAgent) { + return null; + } + if (userAgent.startsWith('npm')) { + return 'npm'; + } + if (userAgent.startsWith('yarn')) { + return 'yarn'; + } + if (userAgent.startsWith('pnpm')) { + return 'pnpm'; + } + return null; +} +exports.getCurrentPackageManager = getCurrentPackageManager; +/** + * Checks for the presence of package-lock.json or yarn.lock to determine which package manager is being used + * + * @export + * @param {InstallConfig} config Config specifying current working directory + * @returns + */ +function getPackageManagerFromLockfile(config) { + return __awaiter(this, void 0, void 0, function () { + var pkgLockPath, yarnLockPath, pnpmLockPath, err_1, err_2, err_3; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + pkgLockPath = path_1.default.join(config.cwd, 'package-lock.json'); + yarnLockPath = path_1.default.join(config.cwd, 'yarn.lock'); + pnpmLockPath = path_1.default.join(config.cwd, 'pnpm-lock.yaml'); + _a.label = 1; + case 1: + _a.trys.push([1, 3, , 12]); + return [4 /*yield*/, access(pkgLockPath)]; + case 2: + _a.sent(); + return [2 /*return*/, 'npm']; + case 3: + err_1 = _a.sent(); + _a.label = 4; + case 4: + _a.trys.push([4, 6, , 11]); + return [4 /*yield*/, access(yarnLockPath)]; + case 5: + _a.sent(); + return [2 /*return*/, 'yarn']; + case 6: + err_2 = _a.sent(); + _a.label = 7; + case 7: + _a.trys.push([7, 9, , 10]); + return [4 /*yield*/, access(pnpmLockPath)]; + case 8: + _a.sent(); + return [2 /*return*/, 'pnpm']; + case 9: + err_3 = _a.sent(); + return [2 /*return*/, null]; + case 10: return [3 /*break*/, 11]; + case 11: return [3 /*break*/, 12]; + case 12: return [2 /*return*/]; + } + }); + }); +} +exports.getPackageManagerFromLockfile = getPackageManagerFromLockfile; +/** + * SYNC: Checks for the presence of package-lock.json or yarn.lock to determine which package manager is being used + * + * @export + * @param {InstallConfig} config Config specifying current working directory + * @returns + */ +function getPackageManagerFromLockfileSync(config) { + var pkgLockPath = path_1.default.join(config.cwd, 'package-lock.json'); + var yarnLockPath = path_1.default.join(config.cwd, 'yarn.lock'); + var pnpmLockPath = path_1.default.join(config.cwd, 'pnpm-lock.yaml'); + try { + fs_1.accessSync(pkgLockPath); + return 'npm'; + } + catch (err) { + try { + fs_1.accessSync(yarnLockPath); + return 'yarn'; + } + catch (err) { + try { + fs_1.accessSync(pnpmLockPath); + return 'pnpm'; + } + catch (err) { + return null; + } + } + } +} +exports.getPackageManagerFromLockfileSync = getPackageManagerFromLockfileSync; +//# sourceMappingURL=package-manager-utils.js.map \ No newline at end of file diff --git a/lib/utils/package-manager-utils.js.map b/lib/utils/package-manager-utils.js.map new file mode 100644 index 0000000..607ed71 --- /dev/null +++ b/lib/utils/package-manager-utils.js.map @@ -0,0 +1 @@ +{"version":3,"file":"package-manager-utils.js","sourceRoot":"","sources":["../../src/utils/package-manager-utils.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,gDAA0B;AAC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@ -0,0 +1,4 @@ +import { InstallConfig } from './config'; +import { ConstructArgumentsResult, PackageList } from './types'; +export declare function constructYarnArguments(packageList: PackageList, config: InstallConfig): ConstructArgumentsResult; +export declare const yarnProjectInstallArgs: string[]; diff --git a/lib/yarn.js b/lib/yarn.js new file mode 100644 index 0000000..c3cc76b --- /dev/null +++ b/lib/yarn.js @@ -0,0 +1,48 @@ +"use strict"; +var __spreadArrays = (this && this.__spreadArrays) || function () { + for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; + for (var r = Array(s), k = 0, i = 0; i < il; i++) + for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) + r[k] = a[j]; + return r; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.yarnProjectInstallArgs = exports.constructYarnArguments = void 0; +var flags_1 = require("./flags"); +var helpers_1 = require("./helpers"); +function constructYarnArguments(packageList, config) { + var flagsToSet = flags_1.getFlagsToSet(config); + var globalCommand = config.global ? ['global'] : []; + var cwdCommand = config.forceCwd ? ['--cwd', config.cwd] : []; + var args = __spreadArrays(cwdCommand, globalCommand, ['add'], packageList); + var ignoredFlags = []; + flagsToSet.forEach(function (flag) { + switch (flag) { + case 'dev': + if (!config.global) { + args.push('--dev'); + } + else { + ignoredFlags.push(flag); + } + break; + case 'exact': + args.push('--exact'); + break; + case 'verbose': + args.push('--verbose'); + break; + case 'bundle': + case 'noSave': + ignoredFlags.push(flag); + break; + /* istanbul ignore next */ + default: + throw new helpers_1.UnreachableCaseError(flag); + } + }); + return { args: args, ignoredFlags: ignoredFlags }; +} +exports.constructYarnArguments = constructYarnArguments; +exports.yarnProjectInstallArgs = ['install']; +//# sourceMappingURL=yarn.js.map \ No newline at end of file diff --git a/lib/yarn.js.map b/lib/yarn.js.map new file mode 100644 index 0000000..a41c75e --- /dev/null +++ b/lib/yarn.js.map @@ -0,0 +1 @@ +{"version":3,"file":"yarn.js","sourceRoot":"","sources":["../src/yarn.ts"],"names":[],"mappings":";;;;;;;;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AAC,SAAS,CAAC,CAAC"} \ No newline at end of file From 3256344b157a931554b09918b04782bccd84d68f Mon Sep 17 00:00:00 2001 From: Konstantin Komelin Date: Sat, 30 Mar 2024 14:34:00 +0900 Subject: [PATCH 3/6] Removed /lib from Git because the projects is built on install. Upgraded TypeScript and useUnknownInCatchVariables=false to get rid of TS errors in third-party dependencies. --- .gitignore | 2 +- lib/__mocks__/execa.d.ts | 3 - lib/__mocks__/execa.js | 17 -- lib/__mocks__/execa.js.map | 1 - lib/__tests__/helpers.d.ts | 1 - lib/__tests__/helpers.js | 48 ---- lib/__tests__/helpers.js.map | 1 - lib/__tests__/index.d.ts | 1 - lib/__tests__/index.js | 31 -- lib/__tests__/index.js.map | 1 - lib/__tests__/install.d.ts | 1 - lib/__tests__/install.js | 270 ------------------ lib/__tests__/install.js.map | 1 - lib/__tests__/npm.d.ts | 1 - lib/__tests__/npm.js | 82 ------ lib/__tests__/npm.js.map | 1 - lib/__tests__/package-manager.d.ts | 1 - lib/__tests__/package-manager.js | 262 ----------------- lib/__tests__/package-manager.js.map | 1 - lib/__tests__/yarn.d.ts | 1 - lib/__tests__/yarn.js | 82 ------ lib/__tests__/yarn.js.map | 1 - lib/config.d.ts | 43 --- lib/config.js | 37 --- lib/config.js.map | 1 - lib/flags.d.ts | 2 - lib/flags.js | 19 -- lib/flags.js.map | 1 - lib/helpers.d.ts | 11 - lib/helpers.js | 53 ---- lib/helpers.js.map | 1 - lib/index.d.ts | 9 - lib/index.js | 22 -- lib/index.js.map | 1 - lib/install.d.ts | 59 ---- lib/install.js | 169 ----------- lib/install.js.map | 1 - lib/npm.d.ts | 4 - lib/npm.js | 50 ---- lib/npm.js.map | 1 - lib/package-manager.d.ts | 21 -- lib/package-manager.js | 107 ------- lib/package-manager.js.map | 1 - lib/pnpm.d.ts | 4 - lib/pnpm.js | 50 ---- lib/pnpm.js.map | 1 - lib/types.d.ts | 16 -- lib/types.js | 3 - lib/types.js.map | 1 - .../__tests__/package-manager-utils.d.ts | 1 - lib/utils/__tests__/package-manager-utils.js | 223 --------------- .../__tests__/package-manager-utils.js.map | 1 - lib/utils/package-manager-utils.d.ts | 47 --- lib/utils/package-manager-utils.js | 194 ------------- lib/utils/package-manager-utils.js.map | 1 - lib/yarn.d.ts | 4 - lib/yarn.js | 48 ---- lib/yarn.js.map | 1 - package.json | 2 +- tsconfig.json | 4 +- 60 files changed, 5 insertions(+), 2019 deletions(-) delete mode 100644 lib/__mocks__/execa.d.ts delete mode 100644 lib/__mocks__/execa.js delete mode 100644 lib/__mocks__/execa.js.map delete mode 100644 lib/__tests__/helpers.d.ts delete mode 100644 lib/__tests__/helpers.js delete mode 100644 lib/__tests__/helpers.js.map delete mode 100644 lib/__tests__/index.d.ts delete mode 100644 lib/__tests__/index.js delete mode 100644 lib/__tests__/index.js.map delete mode 100644 lib/__tests__/install.d.ts delete mode 100644 lib/__tests__/install.js delete mode 100644 lib/__tests__/install.js.map delete mode 100644 lib/__tests__/npm.d.ts delete mode 100644 lib/__tests__/npm.js delete mode 100644 lib/__tests__/npm.js.map delete mode 100644 lib/__tests__/package-manager.d.ts delete mode 100644 lib/__tests__/package-manager.js delete mode 100644 lib/__tests__/package-manager.js.map delete mode 100644 lib/__tests__/yarn.d.ts delete mode 100644 lib/__tests__/yarn.js delete mode 100644 lib/__tests__/yarn.js.map delete mode 100644 lib/config.d.ts delete mode 100644 lib/config.js delete mode 100644 lib/config.js.map delete mode 100644 lib/flags.d.ts delete mode 100644 lib/flags.js delete mode 100644 lib/flags.js.map delete mode 100644 lib/helpers.d.ts delete mode 100644 lib/helpers.js delete mode 100644 lib/helpers.js.map delete mode 100644 lib/index.d.ts delete mode 100644 lib/index.js delete mode 100644 lib/index.js.map delete mode 100644 lib/install.d.ts delete mode 100644 lib/install.js delete mode 100644 lib/install.js.map delete mode 100644 lib/npm.d.ts delete mode 100644 lib/npm.js delete mode 100644 lib/npm.js.map delete mode 100644 lib/package-manager.d.ts delete mode 100644 lib/package-manager.js delete mode 100644 lib/package-manager.js.map delete mode 100644 lib/pnpm.d.ts delete mode 100644 lib/pnpm.js delete mode 100644 lib/pnpm.js.map delete mode 100644 lib/types.d.ts delete mode 100644 lib/types.js delete mode 100644 lib/types.js.map delete mode 100644 lib/utils/__tests__/package-manager-utils.d.ts delete mode 100644 lib/utils/__tests__/package-manager-utils.js delete mode 100644 lib/utils/__tests__/package-manager-utils.js.map delete mode 100644 lib/utils/package-manager-utils.d.ts delete mode 100644 lib/utils/package-manager-utils.js delete mode 100644 lib/utils/package-manager-utils.js.map delete mode 100644 lib/yarn.d.ts delete mode 100644 lib/yarn.js delete mode 100644 lib/yarn.js.map diff --git a/.gitignore b/.gitignore index 9b47c63..da6853c 100644 --- a/.gitignore +++ b/.gitignore @@ -80,6 +80,6 @@ typings/ .dynamodb/ # Compile Output -#lib/ +lib/ coverage/ docs/ diff --git a/lib/__mocks__/execa.d.ts b/lib/__mocks__/execa.d.ts deleted file mode 100644 index e4b0ce8..0000000 --- a/lib/__mocks__/execa.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -declare const execa: jest.Mock; -export default execa; diff --git a/lib/__mocks__/execa.js b/lib/__mocks__/execa.js deleted file mode 100644 index be1ab8b..0000000 --- a/lib/__mocks__/execa.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var execa = jest.fn().mockImplementation(function () { - return Promise.resolve({ - failed: false - }); -}); -var execaSync = jest.fn().mockImplementation(function () { - return { - failed: false - }; -}); -Object.defineProperty(execa, 'sync', { - value: execaSync -}); -exports.default = execa; -//# sourceMappingURL=execa.js.map \ No newline at end of file diff --git a/lib/__mocks__/execa.js.map b/lib/__mocks__/execa.js.map deleted file mode 100644 index f752a87..0000000 --- a/lib/__mocks__/execa.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"execa.js","sourceRoot":"","sources":["../../src/__mocks__/execa.ts"],"names":[],"mappings":";;AAAA,IAAM,KAAK,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC;IACzC,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,KAAK;KACd,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,IAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC;IAC7C,OAAO;QACL,MAAM,EAAE,KAAK;KACd,CAAA;AACH,CAAC,CAAC,CAAA;AACF,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE;IACnC,KAAK,EAAE,SAAS;CACjB,CAAC,CAAA;AAGF,kBAAe,KAAK,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/helpers.d.ts b/lib/__tests__/helpers.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/lib/__tests__/helpers.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/__tests__/helpers.js b/lib/__tests__/helpers.js deleted file mode 100644 index f7b8795..0000000 --- a/lib/__tests__/helpers.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var config_1 = require("../config"); -var helpers_1 = require("../helpers"); -describe('getPackageList', function () { - it('should handle arrays', function () { - var input = ['twilio', 'node-env-run@1', 'twilio-run@1']; - var output = helpers_1.getPackageList(input); - expect(output).toEqual(input); - }); - it('should filter out empty or invalid values', function () { - var input = ['twilio', undefined, 1.23, 'node-env-run@1']; - // @ts-ignore - var output = helpers_1.getPackageList(input); - expect(output).toEqual(['twilio', 'node-env-run@1']); - }); - it('should turn objects into arrays', function () { - var input = { - twilio: '^3', - 'node-env-run': '1', - 'twilio-run': undefined, - }; - var output = helpers_1.getPackageList(input); - expect(output).toEqual(['twilio@^3', 'node-env-run@1', 'twilio-run']); - }); -}); -describe('getExecaConfig', function () { - it('should extract the right config parameters', function () { - var config = __assign(__assign({}, config_1.defaultInstallConfig), { stdio: 'inherit', cwd: '/some/user/path' }); - var output = helpers_1.getExecaConfig(config); - expect(output).toEqual({ - stdio: 'inherit', - cwd: '/some/user/path', - }); - }); -}); -//# sourceMappingURL=helpers.js.map \ No newline at end of file diff --git a/lib/__tests__/helpers.js.map b/lib/__tests__/helpers.js.map deleted file mode 100644 index 0e53dc2..0000000 --- a/lib/__tests__/helpers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/__tests__/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oCAAiD;AACjD,sCAA4D;AAE5D,QAAQ,CAAC,gBAAgB,EAAE;IACzB,EAAE,CAAC,sBAAsB,EAAE;QACzB,IAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;QAC3D,IAAM,MAAM,GAAG,wBAAc,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE;QAC9C,IAAM,KAAK,GAAG,CAAC,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;QAC5D,aAAa;QACb,IAAM,MAAM,GAAG,wBAAc,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iCAAiC,EAAE;QACpC,IAAM,KAAK,GAAG;YACZ,MAAM,EAAE,IAAI;YACZ,cAAc,EAAE,GAAG;YACnB,YAAY,EAAE,SAAS;SACxB,CAAC;QACF,IAAM,MAAM,GAAG,wBAAc,CAAC,KAAK,CAAC,CAAC;QACrC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,gBAAgB,EAAE;IACzB,EAAE,CAAC,4CAA4C,EAAE;QAC/C,IAAM,MAAM,yBACP,6BAAoB,KACvB,KAAK,EAAE,SAAsB,EAC7B,GAAG,EAAE,iBAAiB,GACvB,CAAC;QAEF,IAAM,MAAM,GAAG,wBAAc,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,iBAAiB;SACvB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/index.d.ts b/lib/__tests__/index.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/lib/__tests__/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/__tests__/index.js b/lib/__tests__/index.js deleted file mode 100644 index 422369b..0000000 --- a/lib/__tests__/index.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var pkgInstall = __importStar(require("../index")); -describe('index export', function () { - it('exports the right things', function () { - expect(typeof pkgInstall.install).toBe('function'); - expect(typeof pkgInstall.installSync).toBe('function'); - expect(typeof pkgInstall.projectInstall).toBe('function'); - expect(typeof pkgInstall.projectInstallSync).toBe('function'); - }); -}); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/__tests__/index.js.map b/lib/__tests__/index.js.map deleted file mode 100644 index c8cdc90..0000000 --- a/lib/__tests__/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/__tests__/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,mDAAuC;AAEvC,QAAQ,CAAC,cAAc,EAAE;IACvB,EAAE,CAAC,0BAA0B,EAAE;QAC7B,MAAM,CAAC,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnD,MAAM,CAAC,OAAO,UAAU,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACvD,MAAM,CAAC,OAAO,UAAU,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC1D,MAAM,CAAC,OAAO,UAAU,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/install.d.ts b/lib/__tests__/install.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/lib/__tests__/install.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/__tests__/install.js b/lib/__tests__/install.js deleted file mode 100644 index 2d538e7..0000000 --- a/lib/__tests__/install.js +++ /dev/null @@ -1,270 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __spreadArrays = (this && this.__spreadArrays) || function () { - for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; - for (var r = Array(s), k = 0, i = 0; i < il; i++) - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) - r[k] = a[j]; - return r; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -jest.mock('execa'); -jest.mock('../package-manager', function () { - var getPackageManager = jest.fn().mockImplementation(function () { - return Promise.resolve('npm'); - }); - var getPackageManagerSync = jest.fn().mockReturnValue('npm'); - return { - getPackageManager: getPackageManager, - getPackageManagerSync: getPackageManagerSync, - }; -}); -jest.mock('../npm', function () { - return { - npmProjectInstallArgs: ['install'], - constructNpmArguments: jest.fn().mockImplementation(function (pkgList) { - return __spreadArrays(['install'], pkgList); - }), - }; -}); -jest.mock('../yarn', function () { - return { - yarnProjectInstallArgs: ['install'], - constructYarnArguments: jest.fn().mockImplementation(function (pkgList) { - return __spreadArrays(['add'], pkgList); - }), - }; -}); -var execa_1 = __importDefault(require("execa")); -var config_1 = require("../config"); -var install_1 = require("../install"); -var npm_1 = require("../npm"); -var package_manager_1 = require("../package-manager"); -var yarn_1 = require("../yarn"); -beforeEach(function () { - execa_1.default.mockClear(); - execa_1.default.sync.mockClear(); -}); -describe('install', function () { - beforeEach(function () { - npm_1.constructNpmArguments.mockClear(); - yarn_1.constructYarnArguments.mockClear(); - }); - it('should execute execa', function () { return __awaiter(void 0, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, install_1.install(['twilio'])]; - case 1: - result = _a.sent(); - expect(execa_1.default).toHaveBeenCalledTimes(1); - return [2 /*return*/]; - } - }); - }); }); - it('should merge settings correctly', function () { return __awaiter(void 0, void 0, void 0, function () { - var result, expectedConfig; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, install_1.install(['twilio'], { - noSave: true, - global: true, - forceCwd: true, - })]; - case 1: - result = _a.sent(); - expectedConfig = __assign(__assign({}, config_1.defaultInstallConfig), { noSave: true, global: true, forceCwd: true }); - expect(package_manager_1.getPackageManager).toHaveBeenCalledWith(expectedConfig); - return [2 /*return*/]; - } - }); - }); }); - it('should call the right argument constructor (npm)', function () { return __awaiter(void 0, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - package_manager_1.getPackageManager.mockReturnValueOnce(Promise.resolve('npm')); - return [4 /*yield*/, install_1.install(['twilio'])]; - case 1: - result = _a.sent(); - expect(npm_1.constructNpmArguments).toHaveBeenCalledTimes(1); - expect(npm_1.constructNpmArguments).toHaveBeenCalledWith(['twilio'], config_1.defaultInstallConfig); - expect(yarn_1.constructYarnArguments).toHaveBeenCalledTimes(0); - return [2 /*return*/]; - } - }); - }); }); - it('should call the right argument constructor (yarn)', function () { return __awaiter(void 0, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - package_manager_1.getPackageManager.mockReturnValueOnce(Promise.resolve('yarn')); - return [4 /*yield*/, install_1.install(['twilio'])]; - case 1: - result = _a.sent(); - expect(yarn_1.constructYarnArguments).toHaveBeenCalledTimes(1); - expect(yarn_1.constructYarnArguments).toHaveBeenCalledWith(['twilio'], config_1.defaultInstallConfig); - expect(npm_1.constructNpmArguments).toHaveBeenCalledTimes(0); - return [2 /*return*/]; - } - }); - }); }); -}); -describe('installSync', function () { - beforeEach(function () { - npm_1.constructNpmArguments.mockClear(); - yarn_1.constructYarnArguments.mockClear(); - }); - it('should execute execa.sync', function () { - var result = install_1.installSync(['twilio']); - expect(execa_1.default.sync).toHaveBeenCalledTimes(1); - }); - it('should merge settings correctly', function () { - var result = install_1.installSync(['twilio'], { - noSave: true, - global: true, - forceCwd: true, - }); - var expectedConfig = __assign(__assign({}, config_1.defaultInstallConfig), { noSave: true, global: true, forceCwd: true }); - expect(package_manager_1.getPackageManager).toHaveBeenCalledWith(expectedConfig); - }); - it('should call the right argument constructor (npm)', function () { - package_manager_1.getPackageManagerSync.mockReturnValueOnce('npm'); - var result = install_1.installSync(['twilio']); - expect(npm_1.constructNpmArguments).toHaveBeenCalledTimes(1); - expect(npm_1.constructNpmArguments).toHaveBeenCalledWith(['twilio'], config_1.defaultInstallConfig); - expect(yarn_1.constructYarnArguments).toHaveBeenCalledTimes(0); - }); - it('should call the right argument constructor (yarn)', function () { - package_manager_1.getPackageManagerSync.mockReturnValueOnce('yarn'); - var result = install_1.installSync(['twilio']); - expect(yarn_1.constructYarnArguments).toHaveBeenCalledTimes(1); - expect(yarn_1.constructYarnArguments).toHaveBeenCalledWith(['twilio'], config_1.defaultInstallConfig); - expect(npm_1.constructNpmArguments).toHaveBeenCalledTimes(0); - }); -}); -describe('projectInstall', function () { - it('should call execa with the right arguments (npm)', function () { return __awaiter(void 0, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - package_manager_1.getPackageManager.mockResolvedValueOnce('npm'); - return [4 /*yield*/, install_1.projectInstall()]; - case 1: - result = _a.sent(); - expect(execa_1.default).toHaveBeenCalledWith('npm', ['install'], { - stdio: 'pipe', - cwd: process.cwd(), - }); - return [2 /*return*/]; - } - }); - }); }); - it('should call execa with the right arguments (yarn)', function () { return __awaiter(void 0, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - package_manager_1.getPackageManager.mockResolvedValueOnce('yarn'); - return [4 /*yield*/, install_1.projectInstall()]; - case 1: - result = _a.sent(); - expect(execa_1.default).toHaveBeenCalledWith('yarn', ['install'], { - stdio: 'pipe', - cwd: process.cwd(), - }); - return [2 /*return*/]; - } - }); - }); }); - it('merges config correctly', function () { return __awaiter(void 0, void 0, void 0, function () { - var expectedConfig, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - expectedConfig = __assign(__assign({}, config_1.defaultInstallConfig), { stdio: 'inherit' }); - return [4 /*yield*/, install_1.projectInstall({ stdio: 'inherit' })]; - case 1: - result = _a.sent(); - expect(package_manager_1.getPackageManager).toHaveBeenLastCalledWith(expectedConfig); - return [2 /*return*/]; - } - }); - }); }); -}); -describe('projectInstallSync', function () { - it('should call execa.sync with the right arguments (npm)', function () { - package_manager_1.getPackageManagerSync.mockReturnValueOnce('npm'); - var result = install_1.projectInstallSync(); - expect(execa_1.default.sync).toHaveBeenCalledWith('npm', ['install'], { - stdio: 'pipe', - cwd: process.cwd(), - }); - }); - it('should call execa.sync with the right arguments (yarn)', function () { - package_manager_1.getPackageManagerSync.mockReturnValueOnce('yarn'); - var result = install_1.projectInstallSync(); - expect(execa_1.default.sync).toHaveBeenCalledWith('yarn', ['install'], { - stdio: 'pipe', - cwd: process.cwd(), - }); - }); - it('merges config correctly', function () { - var expectedConfig = __assign(__assign({}, config_1.defaultInstallConfig), { stdio: 'inherit' }); - var result = install_1.projectInstallSync({ stdio: 'inherit' }); - expect(package_manager_1.getPackageManagerSync).toHaveBeenLastCalledWith(expectedConfig); - }); -}); -//# sourceMappingURL=install.js.map \ No newline at end of file diff --git a/lib/__tests__/install.js.map b/lib/__tests__/install.js.map deleted file mode 100644 index 60e39e1..0000000 --- a/lib/__tests__/install.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/__tests__/install.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACnB,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE;IAC9B,IAAM,iBAAiB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC;QACrD,OAAO,OAAO,CAAC,OAAO,C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,SAAS,GACjB,CAAC;QAEF,IAAM,MAAM,GAAG,4BAAkB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QACxD,MAAM,CAAC,uCAAqB,CAAC,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/npm.d.ts b/lib/__tests__/npm.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/lib/__tests__/npm.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/__tests__/npm.js b/lib/__tests__/npm.js deleted file mode 100644 index 74ccdfb..0000000 --- a/lib/__tests__/npm.js +++ /dev/null @@ -1,82 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __spreadArrays = (this && this.__spreadArrays) || function () { - for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; - for (var r = Array(s), k = 0, i = 0; i < il; i++) - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) - r[k] = a[j]; - return r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var config_1 = require("../config"); -var npm_1 = require("../npm"); -describe('constructNpmArguments', function () { - var packageList = ['twilio', 'twilio-run@1']; - it('should handle default config', function () { - var _a = npm_1.constructNpmArguments(packageList, config_1.defaultInstallConfig), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install'], packageList)); - expect(ignoredFlags.length).toBe(0); - }); - it('should add dev flag', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install'], packageList, ['--save-dev'])); - expect(ignoredFlags.length).toBe(0); - }); - it('should ignore dev flag when global', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true, global: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install', '-g'], packageList)); - expect(ignoredFlags).toEqual(['dev']); - }); - it('should add exact flag', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { exact: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install'], packageList, ['--save-exact'])); - expect(ignoredFlags.length).toBe(0); - }); - it('should add verbose flag', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { verbose: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install'], packageList, ['--verbose'])); - expect(ignoredFlags.length).toBe(0); - }); - it('should add bundle flag', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { bundle: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install'], packageList, ['--save-bundle'])); - expect(ignoredFlags.length).toBe(0); - }); - it('should handle noSave flag', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { noSave: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install'], packageList, ['--no-save'])); - expect(ignoredFlags.length).toBe(0); - }); - it('should handle global flag', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { global: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install', '-g'], packageList)); - expect(ignoredFlags.length).toBe(0); - }); - it('should handle forceCwd flag', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { forceCwd: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['install', '--prefix', process.cwd()], packageList)); - expect(ignoredFlags.length).toBe(0); - }); - it('should handle all flags', function () { - var _a = npm_1.constructNpmArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true, exact: true, verbose: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays([ - 'install' - ], packageList, [ - '--save-dev', - '--save-exact', - '--verbose', - ])); - expect(ignoredFlags.length).toBe(0); - }); -}); -//# sourceMappingURL=npm.js.map \ No newline at end of file diff --git a/lib/__tests__/npm.js.map b/lib/__tests__/npm.js.map deleted file mode 100644 index 31ecc5e..0000000 --- a/lib/__tests__/npm.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"npm.js","sourceRoot":"","sources":["../../src/__tests__/npm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,oCAAiD;AACjD,8BAA+C;AAE/C,QAAQ,CAAC,uBAAuB,EAAE;IAChC,IAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAE/C,EAAE,CAAC,8BAA8B,EAAE;QAC3B,IAAA,KAAiC,2BAAqB,CAC1D,WAAW,EACX,6BAAoB,CACrB,EAHa,MAAM,UAAA,EAAE,YAAY,kBAGjC,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,iBAAE,SAAS,GAAK,WAAW,EAAE,CAAC;QACpD,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qBAAqB,EAAE;QAClB,IAAA,KAAiC,2BAAqB,CAAC,WAAW,wBACnE,6BAAoB,KACvB,GAAG,EAAE,IAAI,IACT,EAHY,MAAM,UAAA,EAAE,YAAY,kBAGhC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,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hC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,iBAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE,GAAK,WAAW,EAAE,CAAC;QAC/E,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE;QACtB,IAAA,KAAiC,2BAAqB,CAAC,WAAW,wBACnE,6BAAoB,KACvB,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,IAAI,EACX,OAAO,EAAE,IAAI,IACb,EALY,MAAM,UAAA,EAAE,YAAY,kBAKhC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO;YACpB,SAAS;WACN,WAAW;YACd,YAAY;YACZ,cAAc;YACd,WAAW;WACX,CAAC;QACH,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/package-manager.d.ts b/lib/__tests__/package-manager.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/lib/__tests__/package-manager.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/__tests__/package-manager.js b/lib/__tests__/package-manager.js deleted file mode 100644 index 0aa4051..0000000 --- a/lib/__tests__/package-manager.js +++ /dev/null @@ -1,262 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var mockGetCurrentPm = jest.fn(); -var mockGetPmFromLock = jest.fn(); -var mockIsManagerInstalled = jest.fn(); -var mockGetPmFromLockSync = jest.fn(); -var mockIsManagerInstalledSync = jest.fn(); -jest.mock('../utils/package-manager-utils', function () { - return { - getCurrentPackageManager: mockGetCurrentPm, - getPackageManagerFromLockfile: mockGetPmFromLock, - isManagerInstalled: mockIsManagerInstalled, - isManagerInstalledSync: mockIsManagerInstalledSync, - getPackageManagerFromLockfileSync: mockGetPmFromLockSync, - }; -}); -var config_1 = require("../config"); -var package_manager_1 = require("../package-manager"); -describe('getPackageManager', function () { - var config = __assign(__assign({}, config_1.defaultInstallConfig), { cwd: '/' }); - beforeEach(function () { - mockGetCurrentPm.mockRestore(); - mockGetCurrentPm.mockImplementation(function () { return null; }); - mockGetPmFromLock.mockRestore(); - mockGetPmFromLock.mockImplementation(function () { return null; }); - mockIsManagerInstalled.mockRestore(); - mockIsManagerInstalled.mockImplementation(function () { return Promise.resolve(true); }); - }); - it('should respect the prefer flag', function () { return __awaiter(void 0, void 0, void 0, function () { - var preferYarnConfig, _a, preferNpmConfig, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - preferYarnConfig = __assign(__assign({}, config), { prefer: 'yarn' }); - _a = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(preferYarnConfig)]; - case 1: - _a.apply(void 0, [_c.sent()]).toBe('yarn'); - preferNpmConfig = __assign(__assign({}, config), { prefer: 'npm' }); - _b = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(preferNpmConfig)]; - case 2: - _b.apply(void 0, [_c.sent()]).toBe('npm'); - return [2 /*return*/]; - } - }); - }); }); - it('should fallback to getCurrentPackageManager', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - mockGetCurrentPm.mockImplementationOnce(function () { return 'npm'; }); - _a = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(config)]; - case 1: - _a.apply(void 0, [_c.sent()]).toBe('npm'); - mockGetCurrentPm.mockImplementationOnce(function () { return 'yarn'; }); - _b = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(config)]; - case 2: - _b.apply(void 0, [_c.sent()]).toBe('yarn'); - return [2 /*return*/]; - } - }); - }); }); - it('should try to read from lockfile', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - mockGetPmFromLock.mockImplementationOnce(function () { return 'npm'; }); - _a = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(config)]; - case 1: - _a.apply(void 0, [_c.sent()]).toBe('npm'); - mockGetPmFromLock.mockImplementationOnce(function () { return 'yarn'; }); - _b = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(config)]; - case 2: - _b.apply(void 0, [_c.sent()]).toBe('yarn'); - return [2 /*return*/]; - } - }); - }); }); - it('should always fallback to npm', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _a = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(config)]; - case 1: - _a.apply(void 0, [_b.sent()]).toBe('npm'); - return [2 /*return*/]; - } - }); - }); }); - it('should try the other package manager if one is missing', function () { return __awaiter(void 0, void 0, void 0, function () { - var c, _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - mockIsManagerInstalled.mockImplementation(function (manager) { - return Promise.resolve(manager === 'yarn' ? false : true); - }); - c = __assign(__assign({}, config), { prefer: 'yarn' }); - _a = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(c)]; - case 1: - _a.apply(void 0, [_c.sent()]).toBe('npm'); - expect(mockIsManagerInstalled).toHaveBeenCalledTimes(2); - expect(mockIsManagerInstalled).toHaveBeenCalledWith('yarn'); - expect(mockIsManagerInstalled).toHaveBeenLastCalledWith('npm'); - mockIsManagerInstalled.mockClear(); - mockIsManagerInstalled.mockImplementation(function (manager) { - return Promise.resolve(manager === 'npm' ? false : true); - }); - c = __assign(__assign({}, config), { prefer: 'npm' }); - _b = expect; - return [4 /*yield*/, package_manager_1.getPackageManager(c)]; - case 2: - _b.apply(void 0, [_c.sent()]).toBe('yarn'); - expect(mockIsManagerInstalled).toHaveBeenCalledTimes(2); - expect(mockIsManagerInstalled).toHaveBeenCalledWith('npm'); - expect(mockIsManagerInstalled).toHaveBeenLastCalledWith('yarn'); - return [2 /*return*/]; - } - }); - }); }); - it('should throw an error if no manager is installed', function () { return __awaiter(void 0, void 0, void 0, function () { - var c, err_1; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - c = __assign(__assign({}, config), { prefer: 'yarn' }); - mockIsManagerInstalled.mockImplementation(function () { return Promise.resolve(false); }); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, package_manager_1.getPackageManager(c)]; - case 2: - _a.sent(); - return [3 /*break*/, 4]; - case 3: - err_1 = _a.sent(); - expect(err_1.message).toBe('No supported package manager found'); - return [3 /*break*/, 4]; - case 4: return [2 /*return*/]; - } - }); - }); }); -}); -describe('getPackageManagerSync', function () { - var config = __assign(__assign({}, config_1.defaultInstallConfig), { cwd: '/' }); - beforeEach(function () { - mockGetCurrentPm.mockRestore(); - mockGetCurrentPm.mockImplementation(function () { return null; }); - mockGetPmFromLockSync.mockRestore(); - mockGetPmFromLockSync.mockImplementation(function () { return null; }); - mockIsManagerInstalledSync.mockRestore(); - mockIsManagerInstalledSync.mockImplementation(function () { return true; }); - }); - it('should respect the prefer flag', function () { - var preferYarnConfig = __assign(__assign({}, config), { prefer: 'yarn' }); - expect(package_manager_1.getPackageManagerSync(preferYarnConfig)).toBe('yarn'); - var preferNpmConfig = __assign(__assign({}, config), { prefer: 'npm' }); - expect(package_manager_1.getPackageManagerSync(preferNpmConfig)).toBe('npm'); - }); - it('should fallback to getCurrentPackageManager', function () { - mockGetCurrentPm.mockImplementationOnce(function () { return 'npm'; }); - expect(package_manager_1.getPackageManagerSync(config)).toBe('npm'); - mockGetCurrentPm.mockImplementationOnce(function () { return 'yarn'; }); - expect(package_manager_1.getPackageManagerSync(config)).toBe('yarn'); - }); - it('should try to read from lockfile', function () { - mockGetPmFromLockSync.mockImplementationOnce(function () { return 'npm'; }); - expect(package_manager_1.getPackageManagerSync(config)).toBe('npm'); - mockGetPmFromLockSync.mockImplementationOnce(function () { return 'yarn'; }); - expect(package_manager_1.getPackageManagerSync(config)).toBe('yarn'); - }); - it('should always fallback to npm', function () { - expect(package_manager_1.getPackageManagerSync(config)).toBe('npm'); - }); - it('should try the other package manager if one is missing', function () { - mockIsManagerInstalledSync.mockImplementation(function (manager) { - return manager === 'yarn' ? false : true; - }); - var c = __assign(__assign({}, config), { prefer: 'yarn' }); - expect(package_manager_1.getPackageManagerSync(c)).toBe('npm'); - expect(mockIsManagerInstalledSync).toHaveBeenCalledTimes(2); - expect(mockIsManagerInstalledSync).toHaveBeenCalledWith('yarn'); - expect(mockIsManagerInstalledSync).toHaveBeenLastCalledWith('npm'); - mockIsManagerInstalledSync.mockClear(); - mockIsManagerInstalledSync.mockImplementation(function (manager) { - return manager === 'npm' ? false : true; - }); - c = __assign(__assign({}, config), { prefer: 'npm' }); - expect(package_manager_1.getPackageManagerSync(c)).toBe('yarn'); - expect(mockIsManagerInstalledSync).toHaveBeenCalledTimes(2); - expect(mockIsManagerInstalledSync).toHaveBeenCalledWith('npm'); - expect(mockIsManagerInstalledSync).toHaveBeenLastCalledWith('yarn'); - }); - it('should throw an error if no manager is installed', function () { - var c = __assign(__assign({}, config), { prefer: 'yarn' }); - mockIsManagerInstalledSync.mockImplementation(function () { return false; }); - try { - package_manager_1.getPackageManagerSync(c); - } - catch (err) { - expect(err.message).toBe('No supported package manager found'); - } - }); -}); -//# sourceMappingURL=package-manager.js.map \ No newline at end of file diff --git a/lib/__tests__/package-manager.js.map b/lib/__tests__/package-manager.js.map deleted file mode 100644 index 44f4810..0000000 --- a/lib/__tests__/package-manager.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../../src/__tests__/package-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAM,g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CAAC,MAAM,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kDAAkD,EAAE;QACrD,IAAM,CAAC,GAAG,sBAAK,MAAM,KAAE,MAAM,EAAE,MAAM,GAAmB,CAAC;QACzD,0BAA0B,CAAC,kBAAkB,CAAC,cAAM,OAAA,KAAK,EAAL,CAAK,CAAC,CAAC;QAC3D,IAAI;YACF,uCAAqB,CAAC,CAAC,CAAC,CAAC;SAC1B;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;SAChE;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/__tests__/yarn.d.ts b/lib/__tests__/yarn.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/lib/__tests__/yarn.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/__tests__/yarn.js b/lib/__tests__/yarn.js deleted file mode 100644 index 2acea71..0000000 --- a/lib/__tests__/yarn.js +++ /dev/null @@ -1,82 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __spreadArrays = (this && this.__spreadArrays) || function () { - for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; - for (var r = Array(s), k = 0, i = 0; i < il; i++) - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) - r[k] = a[j]; - return r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var config_1 = require("../config"); -var yarn_1 = require("../yarn"); -describe('constructYarnArguments', function () { - var packageList = ['twilio', 'twilio-run@1']; - it('should handle default config', function () { - var _a = yarn_1.constructYarnArguments(packageList, config_1.defaultInstallConfig), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['add'], packageList)); - expect(ignoredFlags.length).toBe(0); - }); - it('should add dev flag', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['add'], packageList, ['--dev'])); - expect(ignoredFlags.length).toBe(0); - }); - it('should ignore dev flag when global', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true, global: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['global', 'add'], packageList)); - expect(ignoredFlags).toEqual(['dev']); - }); - it('should add exact flag', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { exact: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['add'], packageList, ['--exact'])); - expect(ignoredFlags.length).toBe(0); - }); - it('should add verbose flag', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { verbose: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['add'], packageList, ['--verbose'])); - expect(ignoredFlags.length).toBe(0); - }); - it('should ignore noSave option', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { noSave: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['add'], packageList)); - expect(ignoredFlags).toEqual(['noSave']); - }); - it('should ignore bundle option', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { bundle: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['add'], packageList)); - expect(ignoredFlags).toEqual(['bundle']); - }); - it('should handle global option', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { global: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['global', 'add'], packageList)); - expect(ignoredFlags.length).toBe(0); - }); - it('should handle forceCwd flag', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { forceCwd: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays(['--cwd', process.cwd(), 'add'], packageList)); - expect(ignoredFlags.length).toBe(0); - }); - it('should handle all flags', function () { - var _a = yarn_1.constructYarnArguments(packageList, __assign(__assign({}, config_1.defaultInstallConfig), { dev: true, exact: true, verbose: true })), output = _a.args, ignoredFlags = _a.ignoredFlags; - expect(output).toEqual(__spreadArrays([ - 'add' - ], packageList, [ - '--dev', - '--exact', - '--verbose', - ])); - expect(ignoredFlags.length).toBe(0); - }); -}); -//# sourceMappingURL=yarn.js.map \ No newline at end of file diff --git a/lib/__tests__/yarn.js.map b/lib/__tests__/yarn.js.map deleted file mode 100644 index a271dde..0000000 --- a/lib/__tests__/yarn.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"yarn.js","sourceRoot":"","sources":["../../src/__tests__/yarn.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,oCAAiD;AACjD,gCAAiD;AAEjD,QAAQ,CAAC,wBAAwB,EAAE;IACjC,IAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAE/C,EAAE,CAAC,8BAA8B,EAAE;QAC3B,IAAA,KAAiC,6BAAsB,CAC3D,WAAW,EACX,6BAAoB,CACrB,EAHa,MAAM,UAAA,EAAE,YAAY,kBAGjC,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,iBAAE,KAAK,GAAK,WAAW,EAAE,CAAC;QAChD,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CA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AAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6BAA6B,EAAE;QAC1B,IAAA,KAAiC,6BAAsB,CAAC,WAAW,wBACpE,6BAAoB,KACvB,QAAQ,EAAE,IAAI,IACd,EAHY,MAAM,UAAA,EAAE,YAAY,kBAGhC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,iBAAE,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,KAAK,GAAK,WAAW,EAAE,CAAC;QACxE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE;QACtB,IAAA,KAAiC,6BAAsB,CAAC,WAAW,wBACpE,6BAAoB,KACvB,GAAG,EAAE,IAAI,EACT,KAAK,EAAE,IAAI,EACX,OAAO,EAAE,IAAI,IACb,EALY,MAAM,UAAA,EAAE,YAAY,kBAKhC,CAAC;QACH,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO;YACpB,KAAK;WACF,WAAW;YACd,OAAO;YACP,SAAS;YACT,WAAW;WACX,CAAC;QACH,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/config.d.ts b/lib/config.d.ts deleted file mode 100644 index 75f3401..0000000 --- a/lib/config.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { StdioOption, SupportedPackageManagers } from './types'; -export declare type PackageManagerFlagConfig = { - /** Installs the passed dependencies as dev dependencies */ - dev: boolean; - /** Uses the save exact functionality of pkg manager */ - exact: boolean; - /** Does not write the dependency to package.json (*only available for npm*) */ - noSave: boolean; - /** Saves dependency as bundled dependency (*only available for npm*) */ - bundle: boolean; - /** Runs package manager in verbose mode */ - verbose: boolean; -}; -export declare type PackageManagerFlag = keyof PackageManagerFlagConfig; -export declare const ValidPackageFlags: Set; -export declare type ProjectInstallFlagConfig = { - dryRun: boolean; - verbose: boolean; -}; -export declare type ProjectInstallFlag = keyof ProjectInstallFlagConfig; -export declare const ValidProjectInstallFlags: Set; -export declare type GenericInstallConfig = { - /** Allows you to "force" package manager if available */ - prefer: SupportedPackageManagers | null; - /** Passes to execa in which way the I/O should be passed */ - stdio: StdioOption | StdioOption[]; - /** Working directory in which to run the package manager */ - cwd: string; -}; -/** - * Available options to modify the behavior of `install` and `installSync` - */ -export declare type InstallConfig = PackageManagerFlagConfig & GenericInstallConfig & { - /** Installs packages globally */ - global: boolean; - /** Passes cwd value within the parameters */ - forceCwd: boolean; -}; -export declare type ProjectInstallConfig = GenericInstallConfig & ProjectInstallFlagConfig & {}; -/** - * Default options for `install` and `installSync` - */ -export declare const defaultInstallConfig: InstallConfig; diff --git a/lib/config.js b/lib/config.js deleted file mode 100644 index 08d1fae..0000000 --- a/lib/config.js +++ /dev/null @@ -1,37 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.defaultInstallConfig = exports.ValidProjectInstallFlags = exports.ValidPackageFlags = void 0; -exports.ValidPackageFlags = new Set([ - 'dev', - 'exact', - 'noSave', - 'bundle', - 'verbose', -]); -exports.ValidProjectInstallFlags = new Set(['dryRun', 'verbose']); -/** - * Default options for `install` and `installSync` - */ -exports.defaultInstallConfig = { - /** Installs the passed dependencies as dev dependencies */ - dev: false, - /** Allows you to "force" package manager if available */ - prefer: null, - /** Uses the save exact functionality of pkg manager */ - exact: false, - /** Does not write the dependency to package.json (*only available for npm*) */ - noSave: false, - /** Saves dependency as bundled dependency (*only available for npm*) */ - bundle: false, - /** Runs package manager in verbose mode */ - verbose: false, - /** Installs packages globally */ - global: false, - /** Passes to execa in which way the I/O should be passed */ - stdio: 'pipe', - /** Working directory in which to run the package manager */ - cwd: process.cwd(), - /** Passes cwd value within the parameters */ - forceCwd: false -}; -//# sourceMappingURL=config.js.map \ No newline at end of file diff --git a/lib/config.js.map b/lib/config.js.map deleted file mode 100644 index d5ffef6..0000000 --- a/lib/config.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;AAgBa,QAAA,iBAAiB,GAAG,IAAI,GAAG,CAAS;IAC/C,KAAK;IACL,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,SAAS;CACV,CAAC,CAAC;AAOU,QAAA,wBAAwB,GAAG,IAAI,GAAG,CAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC;AAyB/E;;GAEG;AACU,QAAA,oBAAoB,GAAkB;IACjD,2DAA2D;IAC3D,GAAG,EAAE,KAAK;IACV,yDAAyD;IACzD,MAAM,EAAE,IAAI;IACZ,uDAAuD;IACvD,KAAK,EAAE,KAAK;IACZ,+EAA+E;IAC/E,MAAM,EAAE,KAAK;IACb,wEAAwE;IACxE,MAAM,EAAE,KAAK;IACb,2CAA2C;IAC3C,OAAO,EAAE,KAAK;IACd,iCAAiC;IACjC,MAAM,EAAE,KAAK;IACb,4DAA4D;IAC5D,KAAK,EAAE,MAAqB;IAC5B,4DAA4D;IAC5D,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;IAClB,6CAA6C;IAC7C,QAAQ,EAAE,KAAK;CAChB,CAAC"} \ No newline at end of file diff --git a/lib/flags.d.ts b/lib/flags.d.ts deleted file mode 100644 index 8e534eb..0000000 --- a/lib/flags.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { PackageManagerFlag, PackageManagerFlagConfig } from './config'; -export declare function getFlagsToSet(config: PackageManagerFlagConfig): PackageManagerFlag[]; diff --git a/lib/flags.js b/lib/flags.js deleted file mode 100644 index eab6ff6..0000000 --- a/lib/flags.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getFlagsToSet = void 0; -var config_1 = require("./config"); -function getFlagsToSet(config) { - return Object.entries(config) - .filter(function (entry) { - var flag = entry[0], value = entry[1]; - if (!value) { - return false; - } - return config_1.ValidPackageFlags.has(flag); - }) - .map(function (entry) { - return entry[0]; - }); -} -exports.getFlagsToSet = getFlagsToSet; -//# sourceMappingURL=flags.js.map \ No newline at end of file diff --git a/lib/flags.js.map b/lib/flags.js.map deleted file mode 100644 index de2b3f8..0000000 --- a/lib/flags.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"flags.js","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":";;;AAAA,mCAIkB;AAElB,SAAgB,aAAa,CAC3B,MAAgC;IAEhC,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;SAC1B,MAAM,CAAC,UAAA,KAAK;QACJ,IAAA,IAAI,GAAW,KAAK,GAAhB,EAAE,KAAK,GAAI,KAAK,GAAT,CAAU;QAC5B,IAAI,CAAC,KAAK,EAAE;YACV,OAAO,KAAK,CAAC;SACd;QACD,OAAO,0BAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC,CAAC;SACD,GAAG,CAAC,UAAA,KAAK;QACR,OAAO,KAAK,CAAC,CAAC,CAAuB,CAAC;IACxC,CAAC,CAAC,CAAC;AACP,CAAC;AAdD,sCAcC"} \ No newline at end of file diff --git a/lib/helpers.d.ts b/lib/helpers.d.ts deleted file mode 100644 index 6316843..0000000 --- a/lib/helpers.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import execa from 'execa'; -import { InstallConfig } from './config'; -import { PackageList, Packages } from './types'; -export declare function getPackageList(packages: Packages): PackageList; -export declare function getExecaConfig(config: InstallConfig): execa.CommonOptions; -/** - * Error class used for cases that can't be reached. It's a helper for TypeScript - */ -export declare class UnreachableCaseError extends Error { - constructor(val: never); -} diff --git a/lib/helpers.js b/lib/helpers.js deleted file mode 100644 index 9518e7b..0000000 --- a/lib/helpers.js +++ /dev/null @@ -1,53 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -Object.defineProperty(exports, "__esModule", { value: true }); -exports.UnreachableCaseError = exports.getExecaConfig = exports.getPackageList = void 0; -function getPackageList(packages) { - if (Array.isArray(packages)) { - return packages.filter(function (pkg) { return typeof pkg === 'string'; }); - } - var entries = Object.entries(packages); - return entries - .filter(function (_a) { - var name = _a[0], version = _a[1]; - return ((typeof name === 'string' && typeof version === 'string') || - typeof version === 'undefined'); - }) - .map(function (_a) { - var name = _a[0], version = _a[1]; - return version ? name + "@" + version : name; - }); -} -exports.getPackageList = getPackageList; -function getExecaConfig(config) { - return { - stdio: config.stdio, - cwd: config.cwd, - }; -} -exports.getExecaConfig = getExecaConfig; -/** - * Error class used for cases that can't be reached. It's a helper for TypeScript - */ -var UnreachableCaseError = /** @class */ (function (_super) { - __extends(UnreachableCaseError, _super); - /* istanbul ignore next */ - function UnreachableCaseError(val) { - return _super.call(this, "Unreachable case: " + val) || this; - } - return UnreachableCaseError; -}(Error)); -exports.UnreachableCaseError = UnreachableCaseError; -//# sourceMappingURL=helpers.js.map \ No newline at end of file diff --git a/lib/helpers.js.map b/lib/helpers.js.map deleted file mode 100644 index 4fbd84a..0000000 --- a/lib/helpers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAIA,SAAgB,cAAc,CAAC,QAAkB;IAC/C,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAC3B,OAAO,QAAQ,CAAC,MAAM,CAAC,UAAA,GAAG,IAAI,OAAA,OAAO,GAAG,KAAK,QAAQ,EAAvB,CAAuB,CAAC,CAAC;KACxD;IAED,IAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEzC,OAAO,OAAO;SACX,MAAM,CAAC,UAAC,EAAe;YAAd,IAAI,QAAA,EAAE,OAAO,QAAA;QACrB,OAAO,CACL,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;YACzD,OAAO,OAAO,KAAK,WAAW,CAC/B,CAAC;IACJ,CAAC,CAAC;SACD,GAAG,CAAC,UAAC,EAAe;YAAd,IAAI,QAAA,EAAE,OAAO,QAAA;QAClB,OAAO,OAAO,CAAC,CAAC,CAAI,IAAI,SAAI,OAAS,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/C,CAAC,CAAC,CAAC;AACP,CAAC;AAjBD,wCAiBC;AAED,SAAgB,cAAc,CAAC,MAAqB;IAClD,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,GAAG,EAAE,MAAM,CAAC,GAAG;KAChB,CAAC;AACJ,CAAC;AALD,wCAKC;AAED;;GAEG;AACH;IAA0C,wCAAK;IAC7C,0BAA0B;IAC1B,8BAAY,GAAU;eACpB,kBAAM,uBAAqB,GAAK,CAAC;IACnC,CAAC;IACH,2BAAC;AAAD,CAAC,AALD,CAA0C,KAAK,GAK9C;AALY,oDAAoB"} \ No newline at end of file diff --git a/lib/index.d.ts b/lib/index.d.ts deleted file mode 100644 index 745627a..0000000 --- a/lib/index.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * @module pkg-install - * @preferred - * - * Main entry point of the project - */ -export * from './install'; -export * from './package-manager'; -export * from './types'; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index c857c23..0000000 --- a/lib/index.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __exportStar = (this && this.__exportStar) || function(m, exports) { - for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/** - * @module pkg-install - * @preferred - * - * Main entry point of the project - */ -__exportStar(require("./install"), exports); -__exportStar(require("./package-manager"), exports); -__exportStar(require("./types"), exports); -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/index.js.map b/lib/index.js.map deleted file mode 100644 index b19734f..0000000 --- a/lib/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;GAKG;AACH,4CAA0B;AAC1B,oDAAkC;AAClC,0CAAwB"} \ No newline at end of file diff --git a/lib/install.d.ts b/lib/install.d.ts deleted file mode 100644 index 50ccbb3..0000000 --- a/lib/install.d.ts +++ /dev/null @@ -1,59 +0,0 @@ -/** @module pkg-install */ -import execa from 'execa'; -import { InstallConfig, PackageManagerFlag } from './config'; -import { PackageList, Packages } from './types'; -export declare type InstallResult = execa.ExecaReturns & { - ignoredFlags: PackageManagerFlag[]; -}; -/** - * Installs a passed set of packages using either npm or yarn. Depending on: - * 1) If you specify a preferred package manager - * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) - * 3) What package manager is available - * - * @export - * @param {Packages} packages List or object of packages to be installed - * @param {Partial} [options={}] Options to modify behavior - * @returns {Promise} - */ -export declare function install(packages: Packages, options?: Partial): Promise; -/** - * SYNC VERSION. Installs a passed set of packages using either npm or yarn. Depending on: - * - * 1) If you specify a preferred package manager - * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) - * 3) If there is a yarn.lock or package-lock.json available - * 4) What package manager is available - * - * @export - * @param {Packages} packages List or object of packages to be installed - * @param {Partial} [options={}] Options to modify behavior - * @returns {InstallResult} - */ -export declare function installSync(packages: PackageList, options?: Partial): InstallResult; -/** - * Runs `npm install` or `yarn install` for the project. Depending on: - * - * 1) If you specify a preferred package manager - * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) - * 3) If there is a yarn.lock or package-lock.json available - * 4) What package manager is available - * - * @export - * @param {Partial} [options={}] Options to modify behavior - * @returns {Promise} - */ -export declare function projectInstall(options?: Partial): Promise; -/** - * SYNC VERSION. Runs `npm install` or `yarn install` for the project. Depending on: - * - * 1) If you specify a preferred package manager - * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) - * 3) If there is a yarn.lock or package-lock.json available - * 4) What package manager is available - * - * @export - * @param {Partial} [options={}] Options to modify behavior - * @returns {execa.ExecaReturns} - */ -export declare function projectInstallSync(options?: Partial): execa.ExecaReturns; diff --git a/lib/install.js b/lib/install.js deleted file mode 100644 index b697b0a..0000000 --- a/lib/install.js +++ /dev/null @@ -1,169 +0,0 @@ -"use strict"; -/** @module pkg-install */ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.projectInstallSync = exports.projectInstall = exports.installSync = exports.install = void 0; -var execa_1 = __importDefault(require("execa")); -var config_1 = require("./config"); -var helpers_1 = require("./helpers"); -var npm_1 = require("./npm"); -var package_manager_1 = require("./package-manager"); -var yarn_1 = require("./yarn"); -/** - * Installs a passed set of packages using either npm or yarn. Depending on: - * 1) If you specify a preferred package manager - * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) - * 3) What package manager is available - * - * @export - * @param {Packages} packages List or object of packages to be installed - * @param {Partial} [options={}] Options to modify behavior - * @returns {Promise} - */ -function install(packages, options) { - if (options === void 0) { options = config_1.defaultInstallConfig; } - return __awaiter(this, void 0, void 0, function () { - var config, pkgManager, packageList, getArguments, _a, args, ignoredFlags, result; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - config = __assign(__assign({}, config_1.defaultInstallConfig), options); - return [4 /*yield*/, package_manager_1.getPackageManager(config)]; - case 1: - pkgManager = _b.sent(); - packageList = helpers_1.getPackageList(packages); - getArguments = pkgManager === 'npm' ? npm_1.constructNpmArguments : yarn_1.constructYarnArguments; - _a = getArguments(packageList, config), args = _a.args, ignoredFlags = _a.ignoredFlags; - return [4 /*yield*/, execa_1.default(pkgManager, args, helpers_1.getExecaConfig(config))]; - case 2: - result = _b.sent(); - return [2 /*return*/, __assign(__assign({}, result), { ignoredFlags: ignoredFlags })]; - } - }); - }); -} -exports.install = install; -/** - * SYNC VERSION. Installs a passed set of packages using either npm or yarn. Depending on: - * - * 1) If you specify a preferred package manager - * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) - * 3) If there is a yarn.lock or package-lock.json available - * 4) What package manager is available - * - * @export - * @param {Packages} packages List or object of packages to be installed - * @param {Partial} [options={}] Options to modify behavior - * @returns {InstallResult} - */ -function installSync(packages, options) { - if (options === void 0) { options = config_1.defaultInstallConfig; } - var config = __assign(__assign({}, config_1.defaultInstallConfig), options); - var pkgManager = package_manager_1.getPackageManagerSync(config); - var packageList = helpers_1.getPackageList(packages); - var getArguments = pkgManager === 'npm' ? npm_1.constructNpmArguments : yarn_1.constructYarnArguments; - var _a = getArguments(packageList, config), args = _a.args, ignoredFlags = _a.ignoredFlags; - var result = execa_1.default.sync(pkgManager, args, helpers_1.getExecaConfig(config)); - return __assign(__assign({}, result), { ignoredFlags: ignoredFlags }); -} -exports.installSync = installSync; -/** - * Runs `npm install` or `yarn install` for the project. Depending on: - * - * 1) If you specify a preferred package manager - * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) - * 3) If there is a yarn.lock or package-lock.json available - * 4) What package manager is available - * - * @export - * @param {Partial} [options={}] Options to modify behavior - * @returns {Promise} - */ -function projectInstall(options) { - if (options === void 0) { options = config_1.defaultInstallConfig; } - return __awaiter(this, void 0, void 0, function () { - var config, pkgManager, args; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - config = __assign(__assign({}, config_1.defaultInstallConfig), options); - return [4 /*yield*/, package_manager_1.getPackageManager(config)]; - case 1: - pkgManager = _a.sent(); - args = pkgManager === 'npm' ? npm_1.npmProjectInstallArgs : yarn_1.yarnProjectInstallArgs; - return [2 /*return*/, execa_1.default(pkgManager, args, helpers_1.getExecaConfig(config))]; - } - }); - }); -} -exports.projectInstall = projectInstall; -/** - * SYNC VERSION. Runs `npm install` or `yarn install` for the project. Depending on: - * - * 1) If you specify a preferred package manager - * 2) If the program is currently running in an npm or yarn script (using npm run or yarn run) - * 3) If there is a yarn.lock or package-lock.json available - * 4) What package manager is available - * - * @export - * @param {Partial} [options={}] Options to modify behavior - * @returns {execa.ExecaReturns} - */ -function projectInstallSync(options) { - if (options === void 0) { options = config_1.defaultInstallConfig; } - var config = __assign(__assign({}, config_1.defaultInstallConfig), options); - var pkgManager = package_manager_1.getPackageManagerSync(config); - var args = pkgManager === 'npm' ? npm_1.npmProjectInstallArgs : yarn_1.yarnProjectInstallArgs; - return execa_1.default.sync(pkgManager, args, helpers_1.getExecaConfig(config)); -} -exports.projectInstallSync = projectInstallSync; -//# sourceMappingURL=install.js.map \ No newline at end of file diff --git a/lib/install.js.map b/lib/install.js.map deleted file mode 100644 index 1c0c3cb..0000000 --- a/lib/install.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"install.js","sourceRoot":"","sources":["../src/install.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,gDAA0B;AAC1B,mCAIkB;AAClB,qCAA2D;AAC3D,6BAAqE;AACrE,qDAA6E;A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AI,EAAE,wBAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IACpE,6BACK,MAAM,KACT,YAAY,cAAA,IACZ;AACJ,CAAC;AAjBD,kCAiBC;AAED;;;;;;;;;;;GAWG;AACH,SAAsB,cAAc,CAClC,OAAsD;IAAtD,wBAAA,EAAA,UAAkC,6BAAoB;;;;;;oBAEhD,MAAM,yBAAuB,6BAAoB,GAAK,OAAO,CAAE,CAAC;oBACnD,qBAAM,mCAAiB,CAAC,MAAM,CAAC,EAAA;;oBAA5C,UAAU,GAAG,SAA+B;oBAE5C,IAAI,GACR,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,2BAAqB,CAAC,CAAC,CAAC,6BAAsB,CAAC;oBAExE,sBAAO,eAAK,CAAC,UAAU,EAAE,IAAI,EAAE,wBAAc,CAAC,MAAM,CAAC,CAAC,EAAC;;;;CACxD;AAVD,wCAUC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,kBAAkB,CAChC,OAAsD;IAAtD,wBAAA,EAAA,UAAkC,6BAAoB;IAEtD,IAAM,MAAM,yBAAuB,6BAAoB,GAAK,OAAO,CAAE,CAAC;IACtE,IAAM,UAAU,GAAG,uCAAqB,CAAC,MAAM,CAAC,CAAC;IAEjD,IAAM,IAAI,GACR,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,2BAAqB,CAAC,CAAC,CAAC,6BAAsB,CAAC;IAExE,OAAO,eAAK,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,wBAAc,CAAC,MAAM,CAAC,CAAC,CAAC;AAC9D,CAAC;AAVD,gDAUC"} \ No newline at end of file diff --git a/lib/npm.d.ts b/lib/npm.d.ts deleted file mode 100644 index f562c55..0000000 --- a/lib/npm.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { InstallConfig } from './config'; -import { ConstructArgumentsResult, PackageList } from './types'; -export declare function constructNpmArguments(packageList: PackageList, config: InstallConfig): ConstructArgumentsResult; -export declare const npmProjectInstallArgs: string[]; diff --git a/lib/npm.js b/lib/npm.js deleted file mode 100644 index 00787da..0000000 --- a/lib/npm.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; -var __spreadArrays = (this && this.__spreadArrays) || function () { - for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; - for (var r = Array(s), k = 0, i = 0; i < il; i++) - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) - r[k] = a[j]; - return r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.npmProjectInstallArgs = exports.constructNpmArguments = void 0; -var flags_1 = require("./flags"); -var helpers_1 = require("./helpers"); -function constructNpmArguments(packageList, config) { - var flagsToSet = flags_1.getFlagsToSet(config); - var globalCommand = config.global ? ['-g'] : []; - var cwdCommand = config.forceCwd ? ['--prefix', config.cwd] : []; - var args = __spreadArrays(['install'], globalCommand, cwdCommand, packageList); - var ignoredFlags = []; - flagsToSet.forEach(function (flag) { - switch (flag) { - case 'dev': - if (!config.global) { - args.push('--save-dev'); - } - else { - ignoredFlags.push(flag); - } - break; - case 'exact': - args.push('--save-exact'); - break; - case 'verbose': - args.push('--verbose'); - break; - case 'bundle': - args.push('--save-bundle'); - break; - case 'noSave': - args.push('--no-save'); - break; - /* istanbul ignore next */ - default: - throw new helpers_1.UnreachableCaseError(flag); - } - }); - return { args: args, ignoredFlags: ignoredFlags }; -} -exports.constructNpmArguments = constructNpmArguments; -exports.npmProjectInstallArgs = ['install']; -//# sourceMappingURL=npm.js.map \ No newline at end of file diff --git a/lib/npm.js.map b/lib/npm.js.map deleted file mode 100644 index 2c04481..0000000 --- a/lib/npm.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"npm.js","sourceRoot":"","sources":["../src/npm.ts"],"names":[],"mappings":";;;;;;;;;;AACA,iCAAwC;AACxC,qCAAiD;AAGjD,SAAgB,qBAAqB,CACnC,WAAwB,EACxB,MAAqB;IAErB,IAAM,UAAU,GAAG,qBAAa,CAAC,MAAM,CAAC,CAAC;IACzC,I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index ef4c5f8..0000000 --- a/lib/package-manager.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** @module pkg-install */ -import { InstallConfig } from './config'; -import { SupportedPackageManagers } from './types'; -/** - * Determine what package manager to use based on what preference is set, - * and whether it's currently running in a yarn/npm/pnpm script - * - * @export - * @param {InstallConfig} config - * @returns {Promise} - */ -export declare function getPackageManager(config: InstallConfig): Promise; -/** - * SYNC: Determine what package manager to use based on what preference is set, - * and whether it's currently running in a yarn/npm script - * - * @export - * @param {InstallConfig} config - * @returns {SupportedPackageManagers} - */ -export declare function getPackageManagerSync(config: InstallConfig): SupportedPackageManagers; diff --git a/lib/package-manager.js b/lib/package-manager.js deleted file mode 100644 index 0171b2e..0000000 --- a/lib/package-manager.js +++ /dev/null @@ -1,107 +0,0 @@ -"use strict"; -/** @module pkg-install */ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getPackageManagerSync = exports.getPackageManager = void 0; -var package_manager_utils_1 = require("./utils/package-manager-utils"); -/** - * Determine what package manager to use based on what preference is set, - * and whether it's currently running in a yarn/npm/pnpm script - * - * @export - * @param {InstallConfig} config - * @returns {Promise} - */ -function getPackageManager(config) { - return __awaiter(this, void 0, void 0, function () { - var pkgManager; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - pkgManager = config.prefer || package_manager_utils_1.getCurrentPackageManager(); - if (!!pkgManager) return [3 /*break*/, 2]; - return [4 /*yield*/, package_manager_utils_1.getPackageManagerFromLockfile(config)]; - case 1: - pkgManager = _a.sent(); - _a.label = 2; - case 2: - if (!pkgManager) { - pkgManager = 'npm'; - } - return [4 /*yield*/, package_manager_utils_1.isManagerInstalled(pkgManager)]; - case 3: - if (!!(_a.sent())) return [3 /*break*/, 5]; - pkgManager = pkgManager === 'npm' ? 'yarn' : 'npm'; - return [4 /*yield*/, package_manager_utils_1.isManagerInstalled(pkgManager)]; - case 4: - if (!(_a.sent())) { - throw new Error('No supported package manager found'); - } - _a.label = 5; - case 5: return [2 /*return*/, pkgManager]; - } - }); - }); -} -exports.getPackageManager = getPackageManager; -/** - * SYNC: Determine what package manager to use based on what preference is set, - * and whether it's currently running in a yarn/npm script - * - * @export - * @param {InstallConfig} config - * @returns {SupportedPackageManagers} - */ -function getPackageManagerSync(config) { - var pkgManager = config.prefer || package_manager_utils_1.getCurrentPackageManager(); - if (!pkgManager) { - pkgManager = package_manager_utils_1.getPackageManagerFromLockfileSync(config); - } - if (!pkgManager) { - pkgManager = 'npm'; - } - if (!package_manager_utils_1.isManagerInstalledSync(pkgManager)) { - pkgManager = pkgManager === 'npm' ? 'yarn' : 'npm'; - if (!package_manager_utils_1.isManagerInstalledSync(pkgManager)) { - throw new Error('No supported package manager found'); - } - } - return pkgManager; -} -exports.getPackageManagerSync = getPackageManagerSync; -//# sourceMappingURL=package-manager.js.map \ No newline at end of file diff --git a/lib/package-manager.js.map b/lib/package-manager.js.map deleted file mode 100644 index 4566ebb..0000000 --- a/lib/package-manager.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"package-manager.js","sourceRoot":"","sources":["../src/package-manager.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI1B,uEAMuC;AAEvC;;;;;;;GAOG;AACH,SAAsB,iBAAiB,CACrC,MAAqB;;;;;;oBAEjB,UAAU,GAAG,MAAM,CAAC,MAAM,IAAI,gDAAwB,EAAE,CAAC;yBAEzD,CAAC,UAAU,EAAX,wBAAW;oBACA,qBAAM,qDAA6B,CAAC,MAAM,CAAC,EAAA;;oBAAxD,UAAU,GAAG,SAA2C,CAAC;;;oBAG3D,IAAI,CAAC,UAAU,EAAE;wBACf,UAAU,GAAG,KAAK,CAAC;qBACpB;oBAEK,qBAAM,0CAAkB,CAAC,UAAU,CAAC,EAAA;;yBAAtC,CAAC,CAAC,SAAoC,CAAC,EAAvC,wBAAuC;oBACzC,UAAU,GAAG,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;oBAE7C,qBAAM,0CAAkB,CAAC,UAAU,CAAC,EAAA;;oBAA1C,IAAI,CAAC,CAAC,SAAoC,CAAC,EAAE;wBAC3C,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;qBACvD;;wBAGH,sBAAO,UAAU,EAAC;;;;CACnB;AAtBD,8CAsBC;AAED;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACnC,MAAqB;IAErB,IAAI,UAAU,GACZ,MAAM,CAAC,MAAM,IAAI,gDAAwB,EAAE,CAAC;IAE9C,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,yDAAiC,CAAC,MAAM,CAAC,CAAC;KACxD;IAED,IAAI,CAAC,UAAU,EAAE;QACf,UAAU,GAAG,KAAK,CAAC;KACpB;IAED,IAAI,CAAC,8CAAsB,CAAC,UAAU,CAAC,EAAE;QACvC,UAAU,GAAG,UAAU,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;QAEnD,IAAI,CAAC,8CAAsB,CAAC,UAAU,CAAC,EAAE;YACvC,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;KACF;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAtBD,sDAsBC"} \ No newline at end of file diff --git a/lib/pnpm.d.ts b/lib/pnpm.d.ts deleted file mode 100644 index e87148b..0000000 --- a/lib/pnpm.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { InstallConfig } from "./config"; -import { ConstructArgumentsResult, PackageList } from "./types"; -export declare function constructPnpmArguments(packageList: PackageList, config: InstallConfig): ConstructArgumentsResult; -export declare const pnpmProjectInstallArgs: string[]; diff --git a/lib/pnpm.js b/lib/pnpm.js deleted file mode 100644 index 0290ace..0000000 --- a/lib/pnpm.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; -var __spreadArrays = (this && this.__spreadArrays) || function () { - for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; - for (var r = Array(s), k = 0, i = 0; i < il; i++) - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) - r[k] = a[j]; - return r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.pnpmProjectInstallArgs = exports.constructPnpmArguments = void 0; -var flags_1 = require("./flags"); -var helpers_1 = require("./helpers"); -function constructPnpmArguments(packageList, config) { - var flagsToSet = flags_1.getFlagsToSet(config); - var globalCommand = config.global ? ["--global"] : []; - var cwdCommand = config.forceCwd ? ["--pnpm-prefix", config.cwd] : []; - var args = __spreadArrays([ - "install" - ], globalCommand, cwdCommand, [ - "add" - ], packageList); - var ignoredFlags = []; - flagsToSet.forEach(function (flag) { - switch (flag) { - case "dev": - if (!config.global) { - args.push("--save-dev"); - } - else { - ignoredFlags.push(flag); - } - break; - case "exact": - args.push("--save-exact"); - break; - case "verbose": - case "bundle": - case "noSave": - ignoredFlags.push(flag); - break; - /* istanbul ignore next */ - default: - throw new helpers_1.UnreachableCaseError(flag); - } - }); - return { args: args, ignoredFlags: ignoredFlags }; -} -exports.constructPnpmArguments = constructPnpmArguments; -exports.pnpmProjectInstallArgs = ["install"]; -//# sourceMappingURL=pnpm.js.map \ No newline at end of file diff --git a/lib/pnpm.js.map b/lib/pnpm.js.map deleted file mode 100644 index a9fa584..0000000 --- a/lib/pnpm.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"pnpm.js","sourceRoot":"","sources":["../src/pnpm.ts"],"names":[],"mappings":";;;;;;;;;;AACA,iCAAwC;AACxC,qCAAiD;AAGjD,SAAgB,sBAAsB,CACpC,WAAwB,EACxB,MAAqB;IAErB,IAAM,UAAU,GAAG,qBAAa,CAAC,MAAM,CAAC,CAAC;IACzC,IAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACxD,IAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACxE,IAAM,IAAI;QACR,SAAS;OACN,aAAa,EACb,UAAU;QACb,KAAK;OACF,WAAW,CACf,CAAC;IAEF,IAAM,YAAY,GAAyB,EAAE,CAAC;IAC9C,UAAU,CAAC,OAAO,CAAC,UAAC,IAAI;QACtB,QAAQ,IAAI,EAAE;YACZ,KAAK,KAAK;gBACR,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;oBAClB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;iBACzB;qBAAM;oBACL,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACzB;gBACD,MAAM;YACR,KAAK,OAAO;gBACV,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBAC1B,MAAM;YACR,KAAK,SAAS,CAAC;YACf,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ;gBACX,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACxB,MAAM;YACR,0BAA0B;YAC1B;gBACE,MAAM,IAAI,8BAAoB,CAAC,IAAI,CAAC,CAAC;SACxC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,IAAI,MAAA,EAAE,YAAY,cAAA,EAAE,CAAC;AAChC,CAAC;AAxCD,wDAwCC;AAEY,QAAA,sBAAsB,GAAG,CAAC,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/types.d.ts b/lib/types.d.ts deleted file mode 100644 index f86cb4e..0000000 --- a/lib/types.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { PackageManagerFlag } from './config'; -/** @module pkg-install */ -export declare type PackageMap = { - [packageName: string]: string | undefined; -}; -export declare type PackageList = string[]; -export declare type Packages = PackageMap | PackageList; -export declare type SupportedPackageManagers = 'yarn' | 'npm' | 'pnpm'; -/** - * What to do with I/O. This is passed to `execa` - */ -export declare type StdioOption = 'pipe' | 'ignore' | 'inherit'; -export declare type ConstructArgumentsResult = { - args: string[]; - ignoredFlags: PackageManagerFlag[]; -}; diff --git a/lib/types.js b/lib/types.js deleted file mode 100644 index 11e638d..0000000 --- a/lib/types.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/lib/types.js.map b/lib/types.js.map deleted file mode 100644 index c768b79..0000000 --- a/lib/types.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib/utils/__tests__/package-manager-utils.d.ts b/lib/utils/__tests__/package-manager-utils.d.ts deleted file mode 100644 index cb0ff5c..0000000 --- a/lib/utils/__tests__/package-manager-utils.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/utils/__tests__/package-manager-utils.js b/lib/utils/__tests__/package-manager-utils.js deleted file mode 100644 index 2325ad8..0000000 --- a/lib/utils/__tests__/package-manager-utils.js +++ /dev/null @@ -1,223 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var shouldFailExeca = false; -var mockExeca = function () { - return { - failed: shouldFailExeca, - }; -}; -var asyncExeca = jest - .fn() - .mockImplementation(function () { return Promise.resolve(mockExeca()); }); -var syncExeca = jest.fn().mockImplementation(mockExeca); -Object.defineProperty(asyncExeca, 'sync', { - value: syncExeca, -}); -jest.mock('execa', function () { - return asyncExeca; -}); -var accessShouldFailOn = []; -var mockAccess = jest.fn().mockImplementation(function (path, callback) { - if (!accessShouldFailOn.includes(path)) { - return callback(null); - } - else { - return callback(new Error('Unit test failure message')); - } -}); -var mockAccessSync = jest.fn().mockImplementation(function (path) { - if (!accessShouldFailOn.includes(path)) { - return {}; - } - else { - throw new Error('Unit test failure message'); - } -}); -jest.mock('fs', function () { - return { - access: mockAccess, - accessSync: mockAccessSync, - }; -}); -var config_1 = require("../../config"); -var package_manager_utils_1 = require("../package-manager-utils"); -describe('isManagerInstalled', function () { - it('should call execa with the right paramters', function () { - package_manager_utils_1.isManagerInstalled('npm'); - expect(asyncExeca).toHaveBeenLastCalledWith('npm', ['--version']); - package_manager_utils_1.isManagerInstalled('yarn'); - expect(asyncExeca).toHaveBeenLastCalledWith('yarn', ['--version']); - }); - it('should forward the result', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - shouldFailExeca = false; - _a = expect; - return [4 /*yield*/, package_manager_utils_1.isManagerInstalled('npm')]; - case 1: - _a.apply(void 0, [_c.sent()]).toBe(true); - shouldFailExeca = true; - _b = expect; - return [4 /*yield*/, package_manager_utils_1.isManagerInstalled('npm')]; - case 2: - _b.apply(void 0, [_c.sent()]).toBe(false); - return [2 /*return*/]; - } - }); - }); }); -}); -describe('isManagerInstalledSync', function () { - it('should call execa with the right paramters', function () { - package_manager_utils_1.isManagerInstalledSync('npm'); - expect(syncExeca).toHaveBeenLastCalledWith('npm', ['--version']); - package_manager_utils_1.isManagerInstalledSync('yarn'); - expect(syncExeca).toHaveBeenLastCalledWith('yarn', ['--version']); - }); - it('should forward the result', function () { - shouldFailExeca = false; - expect(package_manager_utils_1.isManagerInstalledSync('npm')).toBe(true); - shouldFailExeca = true; - expect(package_manager_utils_1.isManagerInstalledSync('npm')).toBe(false); - }); -}); -describe('getCurrentPackageManager', function () { - var envBackup; - beforeEach(function () { - envBackup = __assign({}, process.env); - }); - afterEach(function () { - process.env = __assign({}, envBackup); - }); - it('should handle yarn user agents', function () { - process.env = { - npm_config_user_agent: 'yarn/1.13.0 npm/? node/v11.6.0 darwin x64', - }; - expect(package_manager_utils_1.getCurrentPackageManager()).toBe('yarn'); - }); - it('should handle npm user agents', function () { - process.env = { - npm_config_user_agent: 'npm/6.5.0 node/v11.6.0 darwin x64', - }; - expect(package_manager_utils_1.getCurrentPackageManager()).toBe('npm'); - }); - it('should handle missing user agents', function () { - process.env = {}; - expect(package_manager_utils_1.getCurrentPackageManager()).toBe(null); - }); - it('should handle invalid user agents', function () { - process.env = { - npm_config_user_agent: 'some-invalid-value', - }; - expect(package_manager_utils_1.getCurrentPackageManager()).toBe(null); - }); -}); -describe('getPackageManagerFromLockfile', function () { - var config = __assign(__assign({}, config_1.defaultInstallConfig), { cwd: '/' }); - it('should check for npm', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - accessShouldFailOn = []; - _a = expect; - return [4 /*yield*/, package_manager_utils_1.getPackageManagerFromLockfile(config)]; - case 1: - _a.apply(void 0, [_b.sent()]).toBe('npm'); - return [2 /*return*/]; - } - }); - }); }); - it('should check for yarn if npm does not exist', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - accessShouldFailOn = ['/package-lock.json']; - _a = expect; - return [4 /*yield*/, package_manager_utils_1.getPackageManagerFromLockfile(config)]; - case 1: - _a.apply(void 0, [_b.sent()]).toBe('yarn'); - return [2 /*return*/]; - } - }); - }); }); - it('should return null if no lock file exists', function () { return __awaiter(void 0, void 0, void 0, function () { - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - accessShouldFailOn = ['/package-lock.json', '/yarn.lock']; - _a = expect; - return [4 /*yield*/, package_manager_utils_1.getPackageManagerFromLockfile(config)]; - case 1: - _a.apply(void 0, [_b.sent()]).toBe(null); - return [2 /*return*/]; - } - }); - }); }); -}); -describe('getPackageManagerFromLockfileSync', function () { - var config = __assign(__assign({}, config_1.defaultInstallConfig), { cwd: '/' }); - it('should check for npm', function () { - accessShouldFailOn = []; - expect(package_manager_utils_1.getPackageManagerFromLockfileSync(config)).toBe('npm'); - }); - it('should check for yarn if npm does not exist', function () { - accessShouldFailOn = ['/package-lock.json']; - expect(package_manager_utils_1.getPackageManagerFromLockfileSync(config)).toBe('yarn'); - }); - it('should return null if no lock file exists', function () { - accessShouldFailOn = ['/package-lock.json', '/yarn.lock']; - expect(package_manager_utils_1.getPackageManagerFromLockfileSync(config)).toBe(null); - }); -}); -//# sourceMappingURL=package-manager-utils.js.map \ No newline at end of file diff --git a/lib/utils/__tests__/package-manager-utils.js.map b/lib/utils/__tests__/package-manager-utils.js.map deleted file mode 100644 index 490e66b..0000000 --- a/lib/utils/__tests__/package-manager-utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"package-manager-utils.js","sourceRoot":"","sources":["../../../src/utils/__tests__/package-manager-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAI,eAAe,GAAG,KAAK,CAAC;AAC5B,IAAI,SAAS,GAAG;IACd,OAAO;QACL,MAAM,EAAE,eAAe;KACxB,CAAC;AACJ,CAAC,CAAC;AAEF,IAAM,UAAU,GAAG,IAAI;KACpB,EAAE,EAAE;KACJ,kBAAkB,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,EAA5B,CAA4B,CAAC,CAAC;AAC1D,IAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;AAC1D,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE;IACxC,KAAK,EAAE,SAAS;CACjB,CAAC,CAAC;AAEH,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;IACjB,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC,CAAC;AAEH,IAAI,kBAAkB,GAAa,EAAE,CAAC;AACtC,IAAI,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAC,IAAI,EAAE,QAAQ;IAC3D,IAAI,CAAC,kBAAkB,CAAC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C,2CAA2C,EAAE;;;;;oBAC9C,kBAAkB,GAAG,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;oBAC1D,KAAA,MAAM,CAAA;oBAAC,qBAAM,qDAA6B,CAAC,MAAM,CAAC,EAAA;;oBAAlD,kBAAO,SAA2C,EAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;;;SAChE,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,mCAAmC,EAAE;IAC5C,IAAM,MAAM,yBACP,6BAAoB,KACvB,GAAG,EAAE,GAAG,GACT,CAAC;IAEF,EAAE,CAAC,sBAAsB,EAAE;QACzB,kBAAkB,GAAG,EAAE,CAAC;QACxB,MAAM,CAAC,yDAAiC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,6CAA6C,EAAE;QAChD,kBAAkB,GAAG,CAAC,oBAAoB,CAAC,CAAC;QAC5C,MAAM,CAAC,yDAAiC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2CAA2C,EAAE;QAC9C,kBAAkB,GAAG,CAAC,oBAAoB,EAAE,YAAY,CAAC,CAAC;QAC1D,MAAM,CAAC,yDAAiC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"} \ No newline at end of file diff --git a/lib/utils/package-manager-utils.d.ts b/lib/utils/package-manager-utils.d.ts deleted file mode 100644 index b037748..0000000 --- a/lib/utils/package-manager-utils.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -/** @module pkg-install */ -import { InstallConfig } from '../config'; -import { SupportedPackageManagers } from '../types'; -/** - * Checks if a given package manager is currently installed by checking its version - * - * @export - * @param {SupportedPackageManagers} manager - * @returns {Promise} - */ -export declare function isManagerInstalled(manager: SupportedPackageManagers): Promise; -/** - * SYNC: Checks if a given package manager is currently installed by checking its version - * - * @export - * @param {SupportedPackageManagers} manager - * @returns {boolean} - */ -export declare function isManagerInstalledSync(manager: SupportedPackageManagers): boolean; -/** - * Returns the package manager currently active if the program is executed - * through an npm or yarn script like: - * ```bash - * yarn run example - * npm run example - * ``` - * - * @export - * @returns {(SupportedPackageManagers | null)} - */ -export declare function getCurrentPackageManager(): SupportedPackageManagers | null; -/** - * Checks for the presence of package-lock.json or yarn.lock to determine which package manager is being used - * - * @export - * @param {InstallConfig} config Config specifying current working directory - * @returns - */ -export declare function getPackageManagerFromLockfile(config: InstallConfig): Promise; -/** - * SYNC: Checks for the presence of package-lock.json or yarn.lock to determine which package manager is being used - * - * @export - * @param {InstallConfig} config Config specifying current working directory - * @returns - */ -export declare function getPackageManagerFromLockfileSync(config: InstallConfig): SupportedPackageManagers | null; diff --git a/lib/utils/package-manager-utils.js b/lib/utils/package-manager-utils.js deleted file mode 100644 index bdf0425..0000000 --- a/lib/utils/package-manager-utils.js +++ /dev/null @@ -1,194 +0,0 @@ -"use strict"; -/** @module pkg-install */ -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.getPackageManagerFromLockfileSync = exports.getPackageManagerFromLockfile = exports.getCurrentPackageManager = exports.isManagerInstalledSync = exports.isManagerInstalled = void 0; -var execa_1 = __importDefault(require("execa")); -var fs_1 = require("fs"); -var path_1 = __importDefault(require("path")); -var util_1 = require("util"); -var access = util_1.promisify(fs_1.access); -/** - * Checks if a given package manager is currently installed by checking its version - * - * @export - * @param {SupportedPackageManagers} manager - * @returns {Promise} - */ -function isManagerInstalled(manager) { - return __awaiter(this, void 0, void 0, function () { - var result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, execa_1.default(manager, ['--version'])]; - case 1: - result = _a.sent(); - return [2 /*return*/, !result.failed]; - } - }); - }); -} -exports.isManagerInstalled = isManagerInstalled; -/** - * SYNC: Checks if a given package manager is currently installed by checking its version - * - * @export - * @param {SupportedPackageManagers} manager - * @returns {boolean} - */ -function isManagerInstalledSync(manager) { - var result = execa_1.default.sync(manager, ['--version']); - return !result.failed; -} -exports.isManagerInstalledSync = isManagerInstalledSync; -/** - * Returns the package manager currently active if the program is executed - * through an npm or yarn script like: - * ```bash - * yarn run example - * npm run example - * ``` - * - * @export - * @returns {(SupportedPackageManagers | null)} - */ -function getCurrentPackageManager() { - var userAgent = process.env.npm_config_user_agent; - if (!userAgent) { - return null; - } - if (userAgent.startsWith('npm')) { - return 'npm'; - } - if (userAgent.startsWith('yarn')) { - return 'yarn'; - } - if (userAgent.startsWith('pnpm')) { - return 'pnpm'; - } - return null; -} -exports.getCurrentPackageManager = getCurrentPackageManager; -/** - * Checks for the presence of package-lock.json or yarn.lock to determine which package manager is being used - * - * @export - * @param {InstallConfig} config Config specifying current working directory - * @returns - */ -function getPackageManagerFromLockfile(config) { - return __awaiter(this, void 0, void 0, function () { - var pkgLockPath, yarnLockPath, pnpmLockPath, err_1, err_2, err_3; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - pkgLockPath = path_1.default.join(config.cwd, 'package-lock.json'); - yarnLockPath = path_1.default.join(config.cwd, 'yarn.lock'); - pnpmLockPath = path_1.default.join(config.cwd, 'pnpm-lock.yaml'); - _a.label = 1; - case 1: - _a.trys.push([1, 3, , 12]); - return [4 /*yield*/, access(pkgLockPath)]; - case 2: - _a.sent(); - return [2 /*return*/, 'npm']; - case 3: - err_1 = _a.sent(); - _a.label = 4; - case 4: - _a.trys.push([4, 6, , 11]); - return [4 /*yield*/, access(yarnLockPath)]; - case 5: - _a.sent(); - return [2 /*return*/, 'yarn']; - case 6: - err_2 = _a.sent(); - _a.label = 7; - case 7: - _a.trys.push([7, 9, , 10]); - return [4 /*yield*/, access(pnpmLockPath)]; - case 8: - _a.sent(); - return [2 /*return*/, 'pnpm']; - case 9: - err_3 = _a.sent(); - return [2 /*return*/, null]; - case 10: return [3 /*break*/, 11]; - case 11: return [3 /*break*/, 12]; - case 12: return [2 /*return*/]; - } - }); - }); -} -exports.getPackageManagerFromLockfile = getPackageManagerFromLockfile; -/** - * SYNC: Checks for the presence of package-lock.json or yarn.lock to determine which package manager is being used - * - * @export - * @param {InstallConfig} config Config specifying current working directory - * @returns - */ -function getPackageManagerFromLockfileSync(config) { - var pkgLockPath = path_1.default.join(config.cwd, 'package-lock.json'); - var yarnLockPath = path_1.default.join(config.cwd, 'yarn.lock'); - var pnpmLockPath = path_1.default.join(config.cwd, 'pnpm-lock.yaml'); - try { - fs_1.accessSync(pkgLockPath); - return 'npm'; - } - catch (err) { - try { - fs_1.accessSync(yarnLockPath); - return 'yarn'; - } - catch (err) { - try { - fs_1.accessSync(pnpmLockPath); - return 'pnpm'; - } - catch (err) { - return null; - } - } - } -} -exports.getPackageManagerFromLockfileSync = getPackageManagerFromLockfileSync; -//# sourceMappingURL=package-manager-utils.js.map \ No newline at end of file diff --git a/lib/utils/package-manager-utils.js.map b/lib/utils/package-manager-utils.js.map deleted file mode 100644 index 607ed71..0000000 --- a/lib/utils/package-manager-utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"package-manager-utils.js","sourceRoot":"","sources":["../../src/utils/package-manager-utils.ts"],"names":[],"mappings":";AAAA,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE1B,gDAA0B;AAC1B,yBAAoD;AACpD,8CAAwB;AACxB,6BAAiC;AAIjC,IAAM,MAAM,GAAG,gBAAS,CAAC,WAAQ,CAAC,CAAC;AAEnC;;;;;;GAMG;AACH,SAAsB,kBAAkB,CACtC,OAAiC;;;;;wBAElB,qBAAM,eAAK,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAC,EAAA;;oBAA5C,MAAM,GAAG,SAAmC;oBAClD,sBAAO,CAAC,MAAM,CAAC,MAAM,EAAC;;;;CACvB;AALD,gDAK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,EAAA;;oBAA1B,SAA0B,CAAC;oBAC3B,sBAAO,MAAM,EAAC;;;oBAEd,sBAAO,IAAI,EAAC;;;;;;;CAInB;AAtBD,sEAsBC;AAED;;;;;;GAMG;AACH,SAAgB,iCAAiC,CAC/C,MAAqB;IAErB,IAAM,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;IAC/D,IAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;IACxD,IAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IAC7D,IAAI;QACF,eAAU,CAAC,WAAW,CAAC,CAAC;QACxB,OAAO,KAAK,CAAC;KACd;IAAC,OAAO,GAAG,EAAE;QACZ,IAAI;YACF,eAAU,CAAC,YAAY,CAAC,CAAC;YACzB,OAAO,MAAM,CAAC;SACf;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI;gBACF,eAAU,CAAC,YAAY,CAAC,CAAC;gBACzB,OAAO,MAAM,CAAC;aACf;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO,IAAI,CAAC;aACb;SACF;KACF;AACH,CAAC;AAtBD,8EAsBC"} \ No newline at end of file diff --git a/lib/yarn.d.ts b/lib/yarn.d.ts deleted file mode 100644 index 79ccf4a..0000000 --- a/lib/yarn.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { InstallConfig } from './config'; -import { ConstructArgumentsResult, PackageList } from './types'; -export declare function constructYarnArguments(packageList: PackageList, config: InstallConfig): ConstructArgumentsResult; -export declare const yarnProjectInstallArgs: string[]; diff --git a/lib/yarn.js b/lib/yarn.js deleted file mode 100644 index c3cc76b..0000000 --- a/lib/yarn.js +++ /dev/null @@ -1,48 +0,0 @@ -"use strict"; -var __spreadArrays = (this && this.__spreadArrays) || function () { - for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; - for (var r = Array(s), k = 0, i = 0; i < il; i++) - for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) - r[k] = a[j]; - return r; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.yarnProjectInstallArgs = exports.constructYarnArguments = void 0; -var flags_1 = require("./flags"); -var helpers_1 = require("./helpers"); -function constructYarnArguments(packageList, config) { - var flagsToSet = flags_1.getFlagsToSet(config); - var globalCommand = config.global ? ['global'] : []; - var cwdCommand = config.forceCwd ? ['--cwd', config.cwd] : []; - var args = __spreadArrays(cwdCommand, globalCommand, ['add'], packageList); - var ignoredFlags = []; - flagsToSet.forEach(function (flag) { - switch (flag) { - case 'dev': - if (!config.global) { - args.push('--dev'); - } - else { - ignoredFlags.push(flag); - } - break; - case 'exact': - args.push('--exact'); - break; - case 'verbose': - args.push('--verbose'); - break; - case 'bundle': - case 'noSave': - ignoredFlags.push(flag); - break; - /* istanbul ignore next */ - default: - throw new helpers_1.UnreachableCaseError(flag); - } - }); - return { args: args, ignoredFlags: ignoredFlags }; -} -exports.constructYarnArguments = constructYarnArguments; -exports.yarnProjectInstallArgs = ['install']; -//# sourceMappingURL=yarn.js.map \ No newline at end of file diff --git a/lib/yarn.js.map b/lib/yarn.js.map deleted file mode 100644 index a41c75e..0000000 --- a/lib/yarn.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"yarn.js","sourceRoot":"","sources":["../src/yarn.ts"],"names":[],"mappings":";;;;;;;;;;AACA,iCAAwC;AACxC,qCAAiD;AAGjD,SAAgB,sBAAsB,CACpC,WAAwB,EACxB,MAAqB;IAErB,IAAM,UAAU,GAAG,qBAAa,CAAC,MAAM,CAAC,CAAC;IACzC,IAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACtD,IAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,IAAM,IAAI,kBAAiB,UAAU,EAAK,aAAa,GAAE,KAAK,GAAK,WAAW,CAAC,CAAC;IAEhF,IAAM,YAAY,GAAyB,EAAE,CAAC;IAC9C,UAAU,CAAC,OAAO,CAAC,UAAA,IAAI;QACrB,QAAQ,IAAI,EAAE;YACZ,KAAK,KAAK;gBACR,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE;oBAClB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;iBACpB;qBAAM;oBACL,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;iBACzB;gBACD,MAAM;YACR,KAAK,OAAO;gBACV,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACrB,MAAM;YACR,KAAK,SAAS;gBACZ,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;gBACvB,MAAM;YACR,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ;gBACX,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACxB,MAAM;YACR,0BAA0B;YAC1B;gBACE,MAAM,IAAI,8BAAoB,CAAC,IAAI,CAAC,CAAC;SACxC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,IAAI,MAAA,EAAE,YAAY,cAAA,EAAE,CAAC;AAChC,CAAC;AApCD,wDAoCC;AAEY,QAAA,sBAAsB,GAAG,CAAC,SAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 2e3529f..7268c7c 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "typedoc": "^0.14.2", "typedoc-plugin-external-module-name": "^2.0.0", "typedoc-plugin-internal-external": "^2.0.1", - "typescript": "^3.3.3" + "typescript": "^5.4.3" }, "bugs": { "url": "https://github.com/dkundel/pkg-install/issues", diff --git a/tsconfig.json b/tsconfig.json index 3607e31..d62a5bb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -44,7 +44,7 @@ // "typeRoots": [], /* List of folders to include type definitions from. */ // "types": [], /* Type declaration files to be included in compilation. */ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ /* Source Map Options */ @@ -56,5 +56,7 @@ /* Experimental Options */ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + "useUnknownInCatchVariables": false } } From cbedc21164f864472ff413c684df254d42c44562 Mon Sep 17 00:00:00 2001 From: Konstantin Komelin Date: Sat, 30 Mar 2024 14:54:10 +0900 Subject: [PATCH 4/6] Added pnpm support to the install functions. --- src/install.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/install.ts b/src/install.ts index 55749c9..b10418e 100644 --- a/src/install.ts +++ b/src/install.ts @@ -9,6 +9,7 @@ import { import { getExecaConfig, getPackageList } from './helpers'; import { constructNpmArguments, npmProjectInstallArgs } from './npm'; import { getPackageManager, getPackageManagerSync } from './package-manager'; +import { constructPnpmArguments, pnpmProjectInstallArgs } from "./pnpm"; import { PackageList, Packages } from './types'; import { constructYarnArguments, yarnProjectInstallArgs } from './yarn'; @@ -36,7 +37,11 @@ export async function install( const packageList = getPackageList(packages); const getArguments = - pkgManager === 'npm' ? constructNpmArguments : constructYarnArguments; + pkgManager === "npm" + ? constructNpmArguments + : pkgManager === "yarn" + ? constructYarnArguments + : constructPnpmArguments; const { args, ignoredFlags } = getArguments(packageList, config); const result = await execa(pkgManager, args, getExecaConfig(config)); @@ -68,7 +73,11 @@ export function installSync( const packageList = getPackageList(packages); const getArguments = - pkgManager === 'npm' ? constructNpmArguments : constructYarnArguments; + pkgManager === "npm" + ? constructNpmArguments + : pkgManager === "yarn" + ? constructYarnArguments + : constructPnpmArguments; const { args, ignoredFlags } = getArguments(packageList, config); const result = execa.sync(pkgManager, args, getExecaConfig(config)); @@ -97,7 +106,11 @@ export async function projectInstall( const pkgManager = await getPackageManager(config); const args = - pkgManager === 'npm' ? npmProjectInstallArgs : yarnProjectInstallArgs; + pkgManager === "npm" + ? npmProjectInstallArgs + : pkgManager === "yarn" + ? yarnProjectInstallArgs + : pnpmProjectInstallArgs; return execa(pkgManager, args, getExecaConfig(config)); } @@ -121,7 +134,11 @@ export function projectInstallSync( const pkgManager = getPackageManagerSync(config); const args = - pkgManager === 'npm' ? npmProjectInstallArgs : yarnProjectInstallArgs; + pkgManager === "npm" + ? npmProjectInstallArgs + : pkgManager === "yarn" + ? yarnProjectInstallArgs + : pnpmProjectInstallArgs; return execa.sync(pkgManager, args, getExecaConfig(config)); } From 8b462b7355441249aea65385a1326dce04aa8cae Mon Sep 17 00:00:00 2001 From: Konstantin Komelin Date: Sat, 30 Mar 2024 15:07:43 +0900 Subject: [PATCH 5/6] Added some debug console output. --- src/package-manager.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/package-manager.ts b/src/package-manager.ts index 37bf75e..440c889 100644 --- a/src/package-manager.ts +++ b/src/package-manager.ts @@ -22,7 +22,7 @@ export async function getPackageManager( config: InstallConfig ): Promise { let pkgManager = config.prefer || getCurrentPackageManager(); - +console.log(pkgManager) if (!pkgManager) { pkgManager = await getPackageManagerFromLockfile(config); } @@ -39,6 +39,8 @@ export async function getPackageManager( } } + console.log(pkgManager) + return pkgManager; } From 1ea141e5836a7b4dd78ca1c724fb6d8c4e6abaf2 Mon Sep 17 00:00:00 2001 From: Konstantin Komelin Date: Sat, 30 Mar 2024 15:17:14 +0900 Subject: [PATCH 6/6] Rolledback previous commit. --- src/package-manager.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/package-manager.ts b/src/package-manager.ts index 440c889..37bf75e 100644 --- a/src/package-manager.ts +++ b/src/package-manager.ts @@ -22,7 +22,7 @@ export async function getPackageManager( config: InstallConfig ): Promise { let pkgManager = config.prefer || getCurrentPackageManager(); -console.log(pkgManager) + if (!pkgManager) { pkgManager = await getPackageManagerFromLockfile(config); } @@ -39,8 +39,6 @@ console.log(pkgManager) } } - console.log(pkgManager) - return pkgManager; }