create-windowless-app 9.3.7 → 10.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/nodeUtils.js CHANGED
@@ -1,119 +1,119 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.checkThatNpmCanReadCwd = exports.checkNodeVersion = exports.getWindowsReleases = void 0;
16
- const chalk_1 = __importDefault(require("chalk"));
17
- const semver_compare_1 = __importDefault(require("semver-compare"));
18
- const cross_spawn_1 = __importDefault(require("cross-spawn"));
19
- const got_1 = __importDefault(require("got"));
20
- const WINDOWS_PREFIX = "windows-x64";
21
- let releases;
22
- const getWindowsReleases = () => __awaiter(void 0, void 0, void 0, function* () {
23
- var _a;
24
- if (!releases) {
25
- const options = {
26
- responseType: "json",
27
- headers: {
28
- "User-Agent": "request"
29
- }
30
- };
31
- const response = yield got_1.default.get("https://api.github.com/repos/nexe/nexe/releases/latest", options);
32
- releases = (response === null || response === void 0 ? void 0 : response.statusCode) === 200 && ((_a = response.body) === null || _a === void 0 ? void 0 : _a.assets.map((asset) => asset.name).filter((name) => name.startsWith(WINDOWS_PREFIX)));
33
- }
34
- return releases;
35
- });
36
- exports.getWindowsReleases = getWindowsReleases;
37
- const checkNodeVersion = (nodeVersion) => __awaiter(void 0, void 0, void 0, function* () {
38
- const windowsPrefixLength = WINDOWS_PREFIX.length + 1;
39
- const windowsVersions = yield (0, exports.getWindowsReleases)();
40
- let nexeNodeVersion;
41
- if (nodeVersion) {
42
- // Find exact
43
- const split = nodeVersion.split(".");
44
- const major = (split.length > 0 && (Number(split[0]) || 0)) || 0;
45
- const minor = (split.length > 1 && (Number(split[1]) || 0)) || 0;
46
- const patch = (split.length > 2 && (Number(split[2]) || 0)) || 0;
47
- const lookupVersion = `${WINDOWS_PREFIX}-${major}.${minor}.${patch}`;
48
- const windowsVersion = windowsVersions && windowsVersions.find((asset) => asset === lookupVersion);
49
- if (windowsVersion) {
50
- if (major <= 14) {
51
- nexeNodeVersion = windowsVersion;
52
- console.log(`Found version ${chalk_1.default.green(nodeVersion)} in nexe`);
53
- }
54
- else {
55
- console.log(`Version ${chalk_1.default.green(nodeVersion)} found in nexe, but known to have issues. Looking for latest working nexe release`);
56
- }
57
- }
58
- else {
59
- console.log(`Can't find node version ${chalk_1.default.red(nodeVersion)} in nexe. Looking for latest nexe release`);
60
- }
61
- }
62
- if (!nexeNodeVersion) {
63
- // Find latest
64
- const latestWindowsVersion = windowsVersions &&
65
- windowsVersions.reduce((acc, cur) => {
66
- const curSemVer = cur.substring(windowsPrefixLength);
67
- const accSemVer = acc.substring(windowsPrefixLength);
68
- if ((0, semver_compare_1.default)(curSemVer, accSemVer) > 0 && (0, semver_compare_1.default)(curSemVer, "15.0.0") < 0) {
69
- acc = cur;
70
- }
71
- return acc;
72
- }, `${WINDOWS_PREFIX}-0.0.0`);
73
- console.log(`Using latest nexe release: ${latestWindowsVersion}`);
74
- nexeNodeVersion = latestWindowsVersion;
75
- }
76
- return nexeNodeVersion;
77
- });
78
- exports.checkNodeVersion = checkNodeVersion;
79
- const checkThatNpmCanReadCwd = () => {
80
- const cwd = process.cwd();
81
- let childOutput = null;
82
- try {
83
- const spawnResult = cross_spawn_1.default.sync("npm", ["config", "list"]);
84
- if (spawnResult.status !== 0) {
85
- return false;
86
- }
87
- childOutput = spawnResult.output.toString();
88
- }
89
- catch (err) {
90
- return false;
91
- }
92
- const lines = childOutput.split("\n");
93
- // `npm config list` output includes the following line:
94
- // "; cwd = C:\path\to\current\dir" (unquoted)
95
- // I couldn't find an easier way to get it.
96
- const prefix = "; cwd = ";
97
- const line = lines.find((line) => line.indexOf(prefix) === 0);
98
- if (typeof line !== "string") {
99
- // Fail gracefully. They could remove it.
100
- return true;
101
- }
102
- const npmCWD = line.substring(prefix.length);
103
- if (npmCWD === cwd) {
104
- return true;
105
- }
106
- console.error(chalk_1.default.red("Could not start an npm process in the right directory.\n\n" +
107
- `The current directory is: ${chalk_1.default.bold(cwd)}\n` +
108
- `However, a newly started npm process runs in: ${chalk_1.default.bold(npmCWD)}\n\n` +
109
- "This is probably caused by a misconfigured system terminal shell."));
110
- if (process.platform === "win32") {
111
- console.error(chalk_1.default.red("On Windows, this can usually be fixed by running:\n\n") +
112
- ` ${chalk_1.default.cyan("reg")} delete "HKCU\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n` +
113
- ` ${chalk_1.default.cyan("reg")} delete "HKLM\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n\n` +
114
- chalk_1.default.red("Try to run the above two lines in the terminal.\n") +
115
- chalk_1.default.red("To learn more about this problem, read: https://blogs.msdn.microsoft.com/oldnewthing/20071121-00/?p=24433/"));
116
- }
117
- return false;
118
- };
119
- exports.checkThatNpmCanReadCwd = checkThatNpmCanReadCwd;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.checkThatNpmCanReadCwd = exports.checkNodeVersion = exports.getWindowsReleases = void 0;
16
+ const chalk_1 = __importDefault(require("chalk"));
17
+ const semver_compare_1 = __importDefault(require("semver-compare"));
18
+ const cross_spawn_1 = __importDefault(require("cross-spawn"));
19
+ const got_1 = __importDefault(require("got"));
20
+ const WINDOWS_PREFIX = "windows-x64";
21
+ let releases;
22
+ const getWindowsReleases = () => __awaiter(void 0, void 0, void 0, function* () {
23
+ var _a;
24
+ if (!releases) {
25
+ const options = {
26
+ responseType: "json",
27
+ headers: {
28
+ "User-Agent": "request"
29
+ }
30
+ };
31
+ const response = yield got_1.default.get("https://api.github.com/repos/nexe/nexe/releases/latest", options);
32
+ releases = (response === null || response === void 0 ? void 0 : response.statusCode) === 200 && ((_a = response.body) === null || _a === void 0 ? void 0 : _a.assets.map((asset) => asset.name).filter((name) => name.startsWith(WINDOWS_PREFIX)));
33
+ }
34
+ return releases;
35
+ });
36
+ exports.getWindowsReleases = getWindowsReleases;
37
+ const checkNodeVersion = (nodeVersion) => __awaiter(void 0, void 0, void 0, function* () {
38
+ const windowsPrefixLength = WINDOWS_PREFIX.length + 1;
39
+ const windowsVersions = yield (0, exports.getWindowsReleases)();
40
+ let nexeNodeVersion;
41
+ if (nodeVersion) {
42
+ // Find exact
43
+ const split = nodeVersion.split(".");
44
+ const major = (split.length > 0 && (Number(split[0]) || 0)) || 0;
45
+ const minor = (split.length > 1 && (Number(split[1]) || 0)) || 0;
46
+ const patch = (split.length > 2 && (Number(split[2]) || 0)) || 0;
47
+ const lookupVersion = `${WINDOWS_PREFIX}-${major}.${minor}.${patch}`;
48
+ const windowsVersion = windowsVersions && windowsVersions.find((asset) => asset === lookupVersion);
49
+ if (windowsVersion) {
50
+ if (major <= 14) {
51
+ nexeNodeVersion = windowsVersion;
52
+ console.log(`Found version ${chalk_1.default.green(nodeVersion)} in nexe`);
53
+ }
54
+ else {
55
+ console.log(`Version ${chalk_1.default.green(nodeVersion)} found in nexe, but known to have issues. Looking for latest working nexe release`);
56
+ }
57
+ }
58
+ else {
59
+ console.log(`Can't find node version ${chalk_1.default.red(nodeVersion)} in nexe. Looking for latest nexe release`);
60
+ }
61
+ }
62
+ if (!nexeNodeVersion) {
63
+ // Find latest
64
+ const latestWindowsVersion = windowsVersions &&
65
+ windowsVersions.reduce((acc, cur) => {
66
+ const curSemVer = cur.substring(windowsPrefixLength);
67
+ const accSemVer = acc.substring(windowsPrefixLength);
68
+ if ((0, semver_compare_1.default)(curSemVer, accSemVer) > 0 && (0, semver_compare_1.default)(curSemVer, "15.0.0") < 0) {
69
+ acc = cur;
70
+ }
71
+ return acc;
72
+ }, `${WINDOWS_PREFIX}-0.0.0`);
73
+ console.log(`Using latest nexe release: ${latestWindowsVersion}`);
74
+ nexeNodeVersion = latestWindowsVersion;
75
+ }
76
+ return nexeNodeVersion;
77
+ });
78
+ exports.checkNodeVersion = checkNodeVersion;
79
+ const checkThatNpmCanReadCwd = () => {
80
+ const cwd = process.cwd();
81
+ let childOutput = null;
82
+ try {
83
+ const spawnResult = cross_spawn_1.default.sync("npm", ["config", "list"]);
84
+ if (spawnResult.status !== 0) {
85
+ return false;
86
+ }
87
+ childOutput = spawnResult.output.toString();
88
+ }
89
+ catch (err) {
90
+ return false;
91
+ }
92
+ const lines = childOutput.split("\n");
93
+ // `npm config list` output includes the following line:
94
+ // "; cwd = C:\path\to\current\dir" (unquoted)
95
+ // I couldn't find an easier way to get it.
96
+ const prefix = "; cwd = ";
97
+ const line = lines.find((line) => line.indexOf(prefix) === 0);
98
+ if (typeof line !== "string") {
99
+ // Fail gracefully. They could remove it.
100
+ return true;
101
+ }
102
+ const npmCWD = line.substring(prefix.length);
103
+ if (npmCWD === cwd) {
104
+ return true;
105
+ }
106
+ console.error(chalk_1.default.red("Could not start an npm process in the right directory.\n\n" +
107
+ `The current directory is: ${chalk_1.default.bold(cwd)}\n` +
108
+ `However, a newly started npm process runs in: ${chalk_1.default.bold(npmCWD)}\n\n` +
109
+ "This is probably caused by a misconfigured system terminal shell."));
110
+ if (process.platform === "win32") {
111
+ console.error(chalk_1.default.red("On Windows, this can usually be fixed by running:\n\n") +
112
+ ` ${chalk_1.default.cyan("reg")} delete "HKCU\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n` +
113
+ ` ${chalk_1.default.cyan("reg")} delete "HKLM\\Software\\Microsoft\\Command Processor" /v AutoRun /f\n\n` +
114
+ chalk_1.default.red("Try to run the above two lines in the terminal.\n") +
115
+ chalk_1.default.red("To learn more about this problem, read: https://blogs.msdn.microsoft.com/oldnewthing/20071121-00/?p=24433/"));
116
+ }
117
+ return false;
118
+ };
119
+ exports.checkThatNpmCanReadCwd = checkThatNpmCanReadCwd;
@@ -1,18 +1,18 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.validateNodeVersion = exports.validateProjectNameInput = void 0;
7
- const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
8
- const semver_1 = __importDefault(require("semver"));
9
- const validateProjectNameInput = (value) => {
10
- var _a, _b;
11
- const result = (0, validate_npm_package_name_1.default)(value);
12
- return result.validForNewPackages || ((_a = result === null || result === void 0 ? void 0 : result.errors) === null || _a === void 0 ? void 0 : _a[0]) || ((_b = result === null || result === void 0 ? void 0 : result.warnings) === null || _b === void 0 ? void 0 : _b[0]) || "Invalid project name";
13
- };
14
- exports.validateProjectNameInput = validateProjectNameInput;
15
- const validateNodeVersion = (value) => {
16
- return !value || !!semver_1.default.valid(value) || "Invalid node version";
17
- };
18
- exports.validateNodeVersion = validateNodeVersion;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.validateNodeVersion = exports.validateProjectNameInput = void 0;
7
+ const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
8
+ const semver_1 = __importDefault(require("semver"));
9
+ const validateProjectNameInput = (value) => {
10
+ var _a, _b;
11
+ const result = (0, validate_npm_package_name_1.default)(value);
12
+ return result.validForNewPackages || ((_a = result === null || result === void 0 ? void 0 : result.errors) === null || _a === void 0 ? void 0 : _a[0]) || ((_b = result === null || result === void 0 ? void 0 : result.warnings) === null || _b === void 0 ? void 0 : _b[0]) || "Invalid project name";
13
+ };
14
+ exports.validateProjectNameInput = validateProjectNameInput;
15
+ const validateNodeVersion = (value) => {
16
+ return !value || !!semver_1.default.valid(value) || "Invalid node version";
17
+ };
18
+ exports.validateNodeVersion = validateNodeVersion;