vscode extension using execa returns EPERM - node.js

Currently writing a vscode extension and testing on mac osx. Need to automate some npm commands using execa. After the recent round of vscode updates we are no longer able to run our existing commands.
async runScript(script: string, cwd?: string) {
const scriptStdOut = execa.command(script, {
shell: true,
cwd: cwd,
windowsVerbatimArguments: true,
})
let out = await scriptStdOut
return out
}
Error: failed with exit code 1 (EPERM): npx ng update #angular/cli #angular/core

Related

How to execute an npm package from the code of another package without first installing it?

I created a command line package that has dynamically loaded packages in its code.
How can I install a dynamic package inside code?
Example:
hello-so package
export default async function() {
const ex = await import(process.argv[2]);
const raw = await ex.default(process.argv[3]);
}
hello-so-module package
export default async function(hello) {
console.log(hello);
return hello;
}
Run:
npx hello-so "hello-so-module" "Hello stackoverflow"
There will be an error because the hello-so-module package is not installed. But how to install it inside the code, or maybe there are other options?
I think that the user will have to install the dynamic module globally.

#aws-sdk/client-sts - TypeError: (0 , smithy_client_1.parseRfc3339DateTimeWithOffset) is not a function

I'm facing issue using sts client on lambdas.
The current code was working two days ago.
const {
STSClient,
AssumeRoleCommand,
} = require('#aws-sdk/client-sts')
const stsClient = new STSClient({
region: process.env.REGION || 'eu-west-1',
})
const params = new AssumeRoleCommand({
RoleArn: process.env.MARKETPLACE_RESOLVE_CUSTOMER_ROLE_ARN,
RoleSessionName: `${
process.env.AWS_LAMBDA_FUNCTION_NAME
}-${new Date().getTime()}`,
})
const assumedRoleOutput = await stsClient.send(params)
Now it always throws an exception as follow:
2023-02-08T08:07:18.684Z 1a7dd68d-da00-4b07-935c-2f6bc95f996f ERROR TypeError: (0 , smithy_client_1.parseRfc3339DateTimeWithOffset) is not a function
at deserializeAws_queryCredentials (/opt/nodejs/node_modules/#aws-sdk/client-sts/dist-cjs/protocols/Aws_query.js:860:117)
at deserializeAws_queryAssumeRoleResponse (/opt/nodejs/node_modules/#aws-sdk/client-sts/dist-cjs/protocols/Aws_query.js:756:32)
at deserializeAws_queryAssumeRoleCommand (/opt/nodejs/node_modules/#aws-sdk/client-sts/dist-cjs/protocols/Aws_query.js:119:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /opt/nodejs/node_modules/#aws-sdk/client-sts/node_modules/#aws-sdk/middleware-serde/dist-cjs/deserializerMiddleware.js:7:24
at async /opt/nodejs/node_modules/#aws-sdk/client-sts/node_modules/#aws-sdk/middleware-signing/dist-cjs/middleware.js:14:20
at async StandardRetryStrategy.retry (/opt/nodejs/node_modules/#aws-sdk/client-sts/node_modules/#aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js:51:46)
at async /opt/nodejs/node_modules/#aws-sdk/client-sts/node_modules/#aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:5:22
at async getMarketplaceResolveCustomerRoleCredentials (/var/task/utils/marketplaceUtils.js:27:29)
at async Object.resolveMarketplaceCustomer (/var/task/utils/marketplaceUtils.js:50:5) {
'$metadata': { attempts: 1, totalRetryDelay: 0 }
I've tried it with the #aws-sdk/client-sts at versions 3.266.0 and 3.224.0
The problem was the incorrect aws-sdk version installed during the creation of the layer.
I use a docker file to install all the dependencies used by my lambdas and was using the command like:
RUN npm i #aws-sdk/client-sts#3.224.0
RUN npm i #aws-sdk/client-marketplace-entitlement-service#3.266.0
So there was inconsistency between sdk versions probably?
So I tried to create the layer without including the aws sdk modules (removed by hand) and it worked (the sdk is included in lambda execution enviroment)
But I faced another error with aws-sdk/client-marketplace-entitlement-service that where fixed some times ago git issue
So I've changed the commands on the Dockerfile to install latest major release I wanted, as follow:
RUN npm i #aws-sdk/client-sts#3
RUN npm i #aws-sdk/client-marketplace-entitlement-service#3
and now it works!

Use node ssh into Runcloud gives a different version to what is actually installed/used by NVM on the server

I have a server on Runcloud on which I've used NVM and installed the version 16.14.2.
If I ssh via any SSH client and run node -v, I effectively get 16.14.2
Though when I wrote a script to ssh into the server and run the same command, I get 10.0
I was previously advised to create an alias, I tried to follow some steps I came across for that but it did not fix my issue. Further more, referencing the path to the desired version of npm inside nvm gives me an error that this version npm cannot run with node 10.0
npm does not support Node.js v10.0.0\n
Below is my code
import { NodeSSH } from 'node-ssh'
const ssh = new NodeSSH()
const { environment } = await inquirer.prompt([
{
name: 'environment',
message: `Environment?`,
type: 'input',
default: 'development'
}
])
if (build) {
const sshConfig = sshConfigs[environment]
console.log(chalk.yellow(`Connecting to ${sshConfig.host}...`))
await ssh.connect(sshConfig)
console.log(chalk.green('Connected'))
console.log(chalk.yellow('Executing release...'))
const nodePath = '~/.nvm/versions/node/v16.14.2/bin/node'
const npmPath = '~/.nvm/versions/node/v16.14.2/bin/npm'
console.log(await ssh.execCommand(`${npmPath} -v`))
ssh.dispose()
console.log(chalk.green('Release completed'))
}

Electron contextBridge works on desktop but not on web

My stack consist of Electron, React, FastAPI. I created a contextBridge in the preload.js file. Everything is working fine on the desktop application however when I am on the web, I get the following error below. If anyone knows what might be the cause of this please let me know where to start looking! I don't fully understand why it's a type error. Thank you!
preload.js
const { contextBridge, ipcRenderer } = require("electron");
contextBridge.exposeInMainWorld("api", {
rollDice: async () => {
return await ipcRenderer.invoke("roll-dice");
},
});
error in the browser console
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'rollDice')
You can recreate the bug by following this:
npx create-react-app my-app --template electron-python-fastapi
cd my-app
python -m pip install virtualenv
python -m virtualenv venv
.\venv\Scripts\activate
python -m pip install -r requirements.txt
npm start
Edit: in my App.js file window.api seems to be undefined. Any reason that might be the case for Web but not Desktop?
Edit: I added console.log("running preload"); at the end of my preload.js file and seems like it doesn't preload the file when running on the browser(web).
electron.js
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: false,
preload: path.join(__dirname, "preload.js"),
},
});

Gulp Command Run Never Finish

I have bought template MaterialPro from wrappixel website. After I got the template package already, I have followed getting started installation from document attached with template as the following:
Install Node.js From https://nodejs.org/en/download/
Open terminal navigating to material-pro/
Install npm: npm install --global npm#latest
Install yarn: npm install --global yarn
Install gulp: npm install --global gulp-cli
Copy gulp: gulp copy
The gulpfile.js inside root template is like this:
//gulpfile.js
console.time("Loading plugins"); //start measuring
const gulp = require('gulp'),
minifyCSS = require('gulp-clean-css'),
uglify = require('gulp-uglify'),
rename = require("gulp-rename"),
sass = require('gulp-sass'),
npmDist = require('gulp-npm-dist');
console.timeEnd('Loading plugins');
const sassFiles = 'src/assets/scss/*.scss',
cssDest = 'dist/css/';
//compile scss into css
function style() {
return gulp.src(sassFiles)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(cssDest));
}
//This is for the minify css
async function minifycss() {
return gulp.src(['dist/css/*.css', '!dist/css/**/*.min.css'])
.pipe(rename({
suffix: '.min'
}))
.pipe(minifyCSS())
.pipe(gulp.dest(cssDest));
}
// This is for the minifyjs
async function minifyjs() {
return gulp.src(['dist/js/custom.js','dist/js/app.js', '!dist/js/custom.min.js', '!dist/js/app.min.js'] )
.pipe(rename({
suffix: '.min'
}))
.pipe(uglify())
.pipe(gulp.dest('dist/js'));
}
// Copy dependencies to ./public/libs/
async function copy() {
gulp.src(npmDist(), {
base: './node_modules'
})
.pipe(gulp.dest('./src/assets/libs'));
};
async function watch() {
gulp.watch(['src/assets/scss/**/*.scss'], style);
gulp.watch(['dist/css/style.css'], minifycss);
gulp.watch(['dist/js/**/*.js', '!dist/js/**/*.min.js'], minifyjs);
}
gulp.task('default', watch);
exports.style = style;
exports.minifycss = minifycss;
exports.minifyjs = minifyjs;
exports.copy = copy;
exports.watch = watch;
After all, I made some changes to the template scss file, and run gulp command. At this point, the gulp command run never finished unitl now with output on terminal like this
Loading plugins: 539.410ms
[17:01:03] Using gulpfile ~/Documents/documentation/materialpro-bootstrap-latest/material-pro/gulpfile.js
[17:01:03] Starting 'default'...
[17:01:03] Finished 'default' after 18 ms
What was going wrong with this? Please kindly help, thanks.
P.S: Pls apologized if my question is incomplete or something, if I will try to add some more detail if suggested.
Your gulp code is fine. Made some change on your scss or js file it will show some changes.
Exaplantion
Your default command is gulp.task('default', watch);
when you run gulp it starts to watch your scss, css, js code. If there is new change it will execute the command.
Suggestion. Use like this.
async function watch() {
gulp.watch(['src/assets/scss/**/*.scss'], style, minifycss);
gulp.watch(['dist/js/**/*.js', '!dist/js/**/*.min.js'], minifyjs);
}

Resources