I'm developing a vs-code extension, I wrote a code for cron-jobs (runs extension at a certain time) and it works well. the problem is my extension doesn't lunch at startup I've read the docs and I did what I must do like I saw in docs and still doesn't work at startup.
extension.ts:
import * as vscode from "vscode";
import axios from "axios";
// dotenv
import "dotenv/config";
export async function activate(context: vscode.ExtensionContext) {
var cron = require("node-cron");
// API Call Goes Here...
// *** Visual Studio Code ***
let disposable = vscode.commands.registerCommand(
"myExtenstionIdAndNameNotForPublicXD",
async () => {
if (Content || Reference) {
vscode.window.showInformationMessage(
`"${Content}" - ${Reference} π₯`
);
} else {
vscode.window.showInformationMessage(
`Network Error! π₯`
);
}
// *** Autostart ***
{
/*
# βββββββββββββββ second (optional)
# β βββββββββββββ minute
# β β βββββββββββ hour
# β β β βββββββββ day of month
# β β β β βββββββ month
# β β β β β βββββ day of week
# β β β β β β
# β β β β β β
# * * * * * *
*/
}
cron.schedule(
// S M H D M W
"5 * * * * *",
async () => {
if (Content || Reference) {
vscode.window.showInformationMessage(
`"${Content}" - ${Reference} π₯`
);
} else {
vscode.window.showInformationMessage(
`Network Error! π₯`
);
}
},
{
scheduled: true,
}
);
}
);
context.subscriptions.push(disposable);
}
// this method is called when your extension is deactivated
export function deactivate() {}
and here is my package.json
{
"name": "name",
"displayName": "name",
"description": "name",
"version": "0.0.1",
"engines": {
"vscode": "^1.70.0"
},
"categories": [
"Other"
],
"activationEvents": ["*"],
"main": "./dist/extension.js",
"contributes": {
"commands": [
{
"command": "name.name",
"title": "name.name"
}
]
},
"scripts": {
"vscode:prepublish": "npm run package",
"compile": "webpack",
"watch": "webpack --watch",
"package": "webpack --mode production --devtool hidden-source-map",
"compile-tests": "tsc -p . --outDir out",
"watch-tests": "tsc -p . -w --outDir out",
"pretest": "npm run compile-tests && npm run compile && npm run lint",
"lint": "eslint src --ext ts",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"#types/glob": "^7.2.0",
"#types/mocha": "^9.1.1",
"#types/node": "^16.11.56",
"#types/vscode": "^1.70.0",
"#typescript-eslint/eslint-plugin": "^5.31.0",
"#typescript-eslint/parser": "^5.31.0",
"#vscode/test-electron": "^2.1.5",
"eslint": "^8.20.0",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"ts-loader": "^9.3.1",
"typescript": "^4.7.4",
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
},
"dependencies": {
"axios": "^0.27.2",
"cron": "^2.1.0",
"dotenv": "^16.0.1",
"node-cron": "^3.0.2"
}
}
I need to auto-lunch the extension when the user opens vs code.
then it shows a notification
last, the cron-job code work well and push notifications daily (i know it will push every 15 sec .. just for test)
note: I get this error on my debug console
Error: Unexpected SIGPIPE at process.<anonymous> (/usr/share/code/resources/app/out/out-vscode/bootstrap.js:35:18) at process.emit (/home/kareem/Desktop/VerseOfTheDay-vscode/lib/events.js:390:28) at Signal.callbackTrampoline (node:internal/async_hooks:130:17) {stack: 'Error: Unexpected SIGPIPE at process.<anoβ¦Trampoline (node:internal/async_hooks:130:17)', message: 'Unexpected SIGPIPE'}
that's it! im sorry for hiding the extension name and details :)
I found a solution that was not mentioned on DOCS,
You must do this next like this:
extension.ts or extension.js
context.subscriptions.push(disposable);
// Solution is the next line after your context
vscode.commands.executeCommand("identifier.yourExtensionName");
Also, make sure you have one of the following options on your Package.json
"activationEvents": ["onStartupFinished"], // or "*"
Ref: https://medium.com/secarmalabs/using-visual-studio-code-extensions-for-persistence-a65c940b7ea6
and
https://code.visualstudio.com/api/references/activation-events
I hope it helps you ^-^
Related
I am using:
Terraform v1.2.9
on windows_amd64
provider registry.terraform.io/snowflake-labs/snowflake v0.42.1
My main.tf file is:
terraform {
required_version = ">= 1.1.7"
backend "http" {
}
required_providers {
snowflake = {
source = "Snowflake-Labs/snowflake"
version = "~> 0.42"
}
}
}
provider "snowflake" {
username = "xxxxxx"
account = "yyyyyy"
region = "canada-central.azure"
}
When I add the following tags to a Snowflake role, I have an error. Can you help?
resource "snowflake_role" "operations_manager" {
name = "OPERATIONS_MANAGER"
comment = "A comment"
tag = {
managed-with = "Terraform",
owner = "Joe Smith"
}
}
Error: Unsupported argument
β
β on functional_roles.tf line 35, in resource "snowflake_role" "operations_manager":
β 35: tag = {
β
β An argument named "tag" is not expected here. Did you mean to define a block of type "tag"?
Is it possible to pipe the output of an executor to a CLI command.
In package.json I would do this:
"dev": "node index.js | pino-pretty"
I cannot figure out how to apply this to the project.json
"dev": {
"executor": "#nrwl/node:node",
"options": {
"buildTarget": "api:build"
}
}
I managed to get it to work by creating a custom task:
"pretty": {
"command":"npx nx serve | pino-pretty"
},
"serve" ...
So now I use npx nx pretty myproject and that runs nx serve and pipes it to pino-pretty
I'm working on a Typescript/nodeJS personal project. I want to create a connection to my postgres database using typeOrm but I ran into this issue:
here is the full error:
$ ts-node src/index.ts
Version 9 of Highlight.js has reached EOL and is no longer supported. Please upgrade to version 10.
Server listening at http://localhost:3002
(node:36885) UnhandledPromiseRejectionWarning: Error: No connection options were found in any orm configuration files.
at connexion_1.createConnection.error (/home/maxime/Dev/JeuxDuPlacard/packages/server/src/index.ts:7:36)
at typeorm_1.getConnectionOptions.then.catch.error (/home/maxime/Dev/JeuxDuPlacard/packages/server/src/technical/typeorm/connexion.ts:17:5)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at Object.<anonymous> (/home/maxime/Dev/JeuxDuPlacard/packages/server/node_modules/ts-node/src/_bin.ts:182:12)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
(node:36885) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:36885) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code
my project structure
.
βββ docker
βΒ Β βββ database.env
βΒ Β βββ docker-compose.yml
βββ ormconfig.ts
βββ package.json
βββ package-lock.json
βββ src
βΒ Β βββ app.ts
βΒ Β βββ business
βΒ Β βββ index.ts
βΒ Β βββ technical
βΒ Β βββ controller
βΒ Β βββ typeorm
βΒ Β βΒ Β βββ connexion.ts
βΒ Β βΒ Β βββ repository
βΒ Β βββ user
βΒ Β βββ validation
βββ tsconfig.json
βββ yarn-error.log
βββ yarn.lock
./package.json
{
"name": "server",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"type": "commonjs",
"workspaces": [
"packages/*"
],
"private": true,
"scripts": {
"dev": "tsc --watch",
"test": "echo testing server",
"start": "ts-node src/index.ts"
},
"dependencies": {
"#types/jsonwebtoken": "^8.5.0",
"bcrypt": "^5.0.0",
"body-parser": "^1.19.0",
"express": "^4.17.1",
"jsonwebtoken": "^8.5.1",
"pg": "^8.4.0",
"reflect-metadata": "^0.1.10",
"typeorm": "0.2.29",
"validate.js": "^0.13.1"
},
"devDependencies": {
"#types/bcrypt": "^3.0.0",
"#types/express": "^4.17.9",
"#types/node": "^14.14.8",
"ts-node": "3.3.0",
"ts-node-dev": "^1.0.0",
"typescript": "^4.0.5"
}
}
src/index.ts
import "reflect-metadata";
import { createConnection } from "./technical/typeorm/connexion";
import app from './app';
const port = 3002;
createConnection( error => { throw new Error(error.message) });
app.listen(port, () => console.log(`Server listening at http://localhost:${port}`))
src/technical/typeorm/connection.ts
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
import { getConnectionOptions, createConnection as TypeOrmCreateConnexion, Connection } from 'typeorm';
export async function createConnection(handleError: (error: Error) => unknown): Promise<Connection>{
return getConnectionOptions()
.then(connectionOptions => {
console.log(connectionOptions)
return TypeOrmCreateConnexion({
...(connectionOptions as PostgresConnectionOptions),
poolErrorHandler: handleError,
extra: {
max: 1
},
})
})
.catch(error => {
handleError(error);
throw error;
})
}
ormConfig.ts
import {ConnectionOptions} from "typeorm";
import path from "path";
const isCompiled = path.extname(__filename).includes('js');
const fileExtension = isCompiled ? "js" : "ts";
export default {
type: "postgres",
host: process.env.DB_HOST || "localhost",
port: Number(process.env.DB_PORT) || 5432,
username: process.env.DB_USERNAME || "test",
password: process.env.DB_PASSWORD || "test",
database: process.env.DB_NAME || "test",
synchronize: true,
logging: false,
entities: [
`src/business/**/*.entity.${fileExtension}`
],
migrations: [
`src/migration/**/*.${fileExtension}`
],
subscribers: [
`src/subscriber/**/*.${fileExtension}`
]
} as ConnectionOptions;
Apparently, typeOrm cannot find the ormConfig.ts file. This project is part of a larger monorepo which also contains the front-end connected with workspaces and lerna (I can provide more information if needed)
Any help coming from someone who can help me to find the solution about why typeORM can't find this ormConfig file will be greatly appreciated.
If you would like to use TypeORM configuration file from the root of the project, then it should be one of the next formats: .js, .json, .xml, .env, .yml, .xml (doc) (also suggest to use ormconfig without capital C).
The problem that i am having is that when i run vsce package i still get the This extension consists of 3587 separate files. For performance reasons, you should bundle your extension: warning, i followed the Bundling Extension steps, debugging works as expected.
package.json
{
"main": "./out/extension",
"scripts": {
"vscode:prepublish": "webpack --mode production",
"webpack": "webpack --mode development",
"webpack-dev": "webpack --mode development --watch",
"compile": "npm run webpack",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
}
The webpack config is an exact copy of the Bundling Extension example.
This sounds like you might've forgotten to add the source directories to .vscodeignore, so they're still being packaged into the release. The ignore file should probably contain at least the following, plus anything else not needed at runtime:
src/**
node_modules/**
If you are working with a Language Server extension which has both client and server folders, If you exclude the node_modules of the client and server from the bundle the extension would fail when installed and launch for the first time
.vscodeignore contains
.vscode
**/*.ts
**/*.map
out/**
node_modules/**
test_files/**
client/src/**
server/src/**
tsconfig.json
webpack.config.js
.gitignore
Also the documentation is a bit obsolete regarding the webpack.config.js, you have to wrap the 'use strict' into a function with all the settings.
The entry setting was changed according to my needs
//#ts-check
(function () {
'use strict';
const path = require('path');
/**#type {import('webpack').Configuration}*/
const config = {
target: 'node', // vscode extensions run in a Node.js-context π -> https://webpack.js.org/configuration/node/
entry: './client/src/extension.ts', // the entry point of this extension, π -> https://webpack.js.org/configuration/entry-context/
output: {
// the bundle is stored in the 'dist' folder (check package.json), π -> https://webpack.js.org/configuration/output/
path: path.resolve(__dirname, 'dist'),
filename: 'extension.js',
clean: true, //clean the dist folder for each time webpack is run
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]'
},
devtool: 'source-map',
externals: {
vscode: 'commonjs vscode' // the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, π -> https://webpack.js.org/configuration/externals/
},
resolve: {
// support reading TypeScript and JavaScript files, π -> https://github.com/TypeStrong/ts-loader
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
}
]
}
};
module.exports = config;
}());
I have the following shell script which creates a Debian base aci container for rkt / appC:
#!/bin/sh
set -e
# $ zcat debian.aci | tree | head
# $ rkt run debian.aci --insecure-options=image
export MY_CHROOT=/var/lib/container/aci/debian
mkdir -p $MY_CHROOT
debootstrap --verbose --arch=amd64 --include=iputils-ping,iproute --variant=minbase stable $MY_CHROOT/rootfs http://httpredir.debian.org/debian
cat > $MY_CHROOT/manifest <<EOF
{
"acKind": "ImageManifest",
"acVersion": "0.8.9",
"name": "debian",
"labels": [
{"name": "arch", "value": "amd64"},
{"name": "os", "value": "linux"},
{"name": "version", "value": "1.0.0"}
],
"app": {
"exec": [
"/bin/sh",
"echo",
"Hello, World from $MY_ENV_VAR!"
],
"user": "0",
"group": "0",
"environment": [
{
"name": "MY_ENV_VAR",
"value": "$(whoami)"
}
],
},
"annotations": {
"authors": "Istvan Lantos <email#addess.com>"
}
}
EOF
# use gpg to create a sig, but we'll skip that for now
tar cvvf - $MY_CHROOT/manifest $MY_CHROOT/rootfs | gzip -c > $MY_CHROOT/debian.aci
To verify that manifest file is present:
root#debian:/var/lib/container/aci/debian# zcat debian.aci | tree | head
.
βββ debian.aci
βββ manifest
βββ rootfs
βββ bin
βΒ Β βββ bash
βΒ Β βββ cat
βΒ Β βββ chacl
βΒ Β βββ chgrp
βΒ Β βββ chmod
When I try to run this container with $ rkt run debian.aci --insecure-options=image command, I got the following error:
run: missing manifest
I followed these guides for file structure:
https://github.com/appc/spec
https://github.com/appc/spec/blob/master/spec/aci.md#image-layout
https://github.com/appc/spec/blob/master/examples/image.json
Why not working?
Thank You for your help!
Actually, the error is caused by tar which includes absolute paths in the archive.
So solution is to cd in the directory and not use absolute paths prefixed by $MY_CHROOT.
Source: https://unix.stackexchange.com/a/59246/120771