Skip to content

Commit ce3084c

Browse files
committed
npm/node updates
Signed-off-by: Ryan Swanson <ryan.swanson@loft.sh>
1 parent 42028f9 commit ce3084c

File tree

20 files changed

+815
-1033
lines changed

20 files changed

+815
-1033
lines changed

.github/workflows/npm.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v1
1616
- uses: actions/setup-node@v1
1717
with:
18-
node-version: 12
18+
node-version: 20
1919
registry-url: https://registry.npmjs.org/
2020
- run: |
2121
npm install -g
@@ -38,7 +38,7 @@ jobs:
3838
- uses: actions/checkout@v1
3939
- uses: actions/setup-node@v1
4040
with:
41-
node-version: 12
41+
node-version: 20
4242
registry-url: https://registry.npmjs.org/
4343
- run: |
4444
npm install -g

assets/assets.go

Lines changed: 124 additions & 46 deletions
Large diffs are not rendered by default.

dist/npm/index.js

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#!/usr/bin/env node
22
const fs = require("fs");
33
const path = require("path");
4+
const http = require("http");
5+
const https = require("https");
46
const execSync = require("child_process").execSync;
5-
const fetch = require("node-fetch");
6-
const Spinner = require("cli-spinner").Spinner;
7-
const inquirer = require('inquirer');
8-
const findProcess = require('find-process');
97

108
const downloadPathTemplate =
119
"https://github.com/devspace-sh/devspace/releases/download/v{{version}}/devspace-{{platform}}-{{arch}}";
@@ -62,6 +60,70 @@ const requestHeaders = {
6260
};
6361
let packageJson = JSON.parse(fs.readFileSync(packageJsonPath));
6462

63+
const request = function (requestUrl, options) {
64+
const requestOptions = options || {};
65+
const headers = requestOptions.headers || {};
66+
const maxRedirects = requestOptions.maxRedirects == null ? 10 : requestOptions.maxRedirects;
67+
68+
return new Promise(function (resolve, reject) {
69+
const makeRequest = function (currentUrl, redirectsRemaining) {
70+
const parsedUrl = new URL(currentUrl);
71+
const client = parsedUrl.protocol === "https:" ? https : http;
72+
const req = client.request(parsedUrl, { headers }, function (res) {
73+
const statusCode = res.statusCode || 0;
74+
75+
if (
76+
statusCode >= 300 &&
77+
statusCode < 400 &&
78+
res.headers.location &&
79+
redirectsRemaining > 0
80+
) {
81+
const redirectUrl = new URL(res.headers.location, currentUrl).toString();
82+
res.resume();
83+
makeRequest(redirectUrl, redirectsRemaining - 1);
84+
return;
85+
}
86+
87+
resolve({
88+
ok: statusCode >= 200 && statusCode < 300,
89+
status: statusCode,
90+
statusText: res.statusMessage || "",
91+
url: currentUrl,
92+
body: res,
93+
});
94+
});
95+
96+
req.on("error", reject);
97+
req.end();
98+
};
99+
100+
makeRequest(requestUrl, maxRedirects);
101+
});
102+
};
103+
104+
const getSpinner = function () {
105+
try {
106+
return require("cli-spinner").Spinner;
107+
} catch (err) {
108+
return function Spinner() {
109+
this.setSpinnerString = function () { };
110+
this.start = function () { };
111+
this.stop = function () { };
112+
};
113+
}
114+
};
115+
116+
const getInquirer = function () {
117+
return require("inquirer");
118+
};
119+
120+
const getFindProcess = function () {
121+
const findProcessModule = require("find-process");
122+
return typeof findProcessModule === "function"
123+
? findProcessModule
124+
: findProcessModule.default;
125+
};
126+
65127
const sanitizeVersion = function(version) {
66128
if (version == null) {
67129
return "latest"
@@ -81,9 +143,10 @@ const sanitizeVersion = function(version) {
81143
const getLatestVersion = function (callback) {
82144
const releasesURL = "https://github.com/devspace-sh/devspace/releases/latest";
83145

84-
fetch(releasesURL, { headers: requestHeaders, redirect: false })
146+
request(releasesURL, { headers: requestHeaders })
85147
.then(function (res) {
86148
if (!res.ok) {
149+
res.body.resume();
87150
console.error(
88151
"Error requesting URL " +
89152
releasesURL +
@@ -106,8 +169,10 @@ const getLatestVersion = function (callback) {
106169

107170
const latestVersion = matches[1].replace('v', '')
108171
if (latestVersion) {
172+
res.body.resume();
109173
callback(latestVersion);
110174
} else {
175+
res.body.resume();
111176
console.error("Unable to identify latest devspace version");
112177
process.exit(2);
113178
}
@@ -320,6 +385,7 @@ let continueProcess = function (askRemoveGlobalFolder) {
320385
}
321386
};
322387

388+
const inquirer = getInquirer();
323389
inquirer
324390
.prompt([
325391
{
@@ -377,6 +443,7 @@ let continueProcess = function (askRemoveGlobalFolder) {
377443

378444
console.log("Download DevSpace CLI release: " + downloadPath + "\n");
379445

446+
const Spinner = getSpinner();
380447
const spinner = new Spinner(
381448
"%s Downloading DevSpace CLI... (this may take a minute)"
382449
);
@@ -391,15 +458,10 @@ let continueProcess = function (askRemoveGlobalFolder) {
391458
showRootError(version);
392459
});
393460

394-
fetch(downloadPath, { headers: requestHeaders, encoding: null })
395-
.catch(function (err) {
396-
writeStream.end();
397-
spinner.stop(true);
398-
console.error("Error requesting URL: " + downloadPath);
399-
process.exit(6);
400-
})
461+
request(downloadPath, { headers: requestHeaders })
401462
.then(function (res) {
402463
if (!res.ok) {
464+
res.body.resume();
403465
writeStream.end();
404466
spinner.stop(true);
405467

@@ -457,6 +519,12 @@ let continueProcess = function (askRemoveGlobalFolder) {
457519
showRootError(version);
458520
}
459521
}
522+
})
523+
.catch(function (err) {
524+
writeStream.end();
525+
spinner.stop(true);
526+
console.error("Error requesting URL: " + downloadPath);
527+
process.exit(6);
460528
});
461529
};
462530

@@ -466,6 +534,15 @@ let continueProcess = function (askRemoveGlobalFolder) {
466534
}
467535

468536
if (process.ppid > 1) {
537+
let findProcess;
538+
539+
try {
540+
findProcess = getFindProcess();
541+
} catch (err) {
542+
continueProcess(true);
543+
return;
544+
}
545+
469546
findProcess('pid', process.ppid)
470547
.then(function (list) {
471548
if (list.length === 1 && list[0].ppid > 1) {

hack/build-ui.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -e
55
DEVSPACE_ROOT=$(git rev-parse --show-toplevel)
66

77
# Install dependencies
8-
cd ui && npm install && npm run build
8+
cd ui && npm install --legacy-peer-deps && npm run build
99

1010
# Pack ui
1111
echo "Packing ui"

ui/config/webpack.config.dev.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ module.exports = {
8888
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
8989
'react-native': 'react-native-web',
9090
},
91+
fallback: {
92+
dgram: false,
93+
fs: false,
94+
net: false,
95+
tls: false,
96+
child_process: false,
97+
},
9198
plugins: [
9299
// Prevents users from importing files from outside of src/ (or node_modules/).
93100
// This often causes confusion because we only process files within src/ with babel.
@@ -150,7 +157,7 @@ module.exports = {
150157
},
151158
{
152159
test: /\.module\.s(a|c)ss$/,
153-
loader: [
160+
use: [
154161
require.resolve('style-loader'),
155162
// isDevelopment ? 'style-loader' : MiniCssExtractPlugin.loader,
156163
{
@@ -266,7 +273,10 @@ module.exports = {
266273
// solution that requires the user to opt into importing specific locales.
267274
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
268275
// You can remove this if you don't use Moment.js:
269-
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
276+
new webpack.IgnorePlugin({
277+
resourceRegExp: /^\.\/locale$/,
278+
contextRegExp: /moment$/,
279+
}),
270280
// Perform type checking and linting in a separate process to speed up compilation
271281
new ForkTsCheckerWebpackPlugin({
272282
async: false,
@@ -275,15 +285,6 @@ module.exports = {
275285
tslint: paths.appTsLint,
276286
}),
277287
],
278-
// Some libraries import Node modules but don't use them in the browser.
279-
// Tell Webpack to provide empty mocks for them so importing them works.
280-
node: {
281-
dgram: 'empty',
282-
fs: 'empty',
283-
net: 'empty',
284-
tls: 'empty',
285-
child_process: 'empty',
286-
},
287288
// Turn off performance hints during development because we don't do any
288289
// splitting or minification in interest of speed. These warnings become
289290
// cumbersome.

0 commit comments

Comments
 (0)