UNPKG

768 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.detectNextJS = void 0;
7const regex = /[\s"\n]next.*?(\d+).*/;
8
9const detectNextJS = packageManager => {
10 try {
11 let out = '';
12
13 if (packageManager.type === 'npm') {
14 try {
15 // npm <= v7
16 out = packageManager.executeCommand('npm', ['ls', 'next']);
17 } catch (e2) {
18 // npm >= v8
19 out = packageManager.executeCommand('npm', ['why', 'next']);
20 }
21 } else {
22 out = packageManager.executeCommand('yarn', ['why', 'next']);
23 }
24
25 const [, version] = out.match(regex);
26 return version && parseInt(version, 10) ? parseInt(version, 10) : false;
27 } catch (err) {//
28 }
29
30 return false;
31};
32
33exports.detectNextJS = detectNextJS;
\No newline at end of file