Mqx
Mqx
DDeno
Created by Mqx on 4/9/2024 in #help
`declare module` doesn’t work
I was trying to declare a module like so:
declare module "*.scss";
declare module "*.scss";
But this simply doesn’t have any effect whatsoever. I also tried this:
declare module "*.scss" {
const content: string;
export default content;
}
declare module "*.scss" {
const content: string;
export default content;
}
None of this worked. I don’t know if .d.ts file are simply ignored by Deno or if this is a bug, or I have done something wrong. This is the GitHub Issue: https://github.com/denoland/deno/issues/23007 I appreciate any help 👍🏻 Thanks
35 replies
DDeno
Created by Mqx on 3/11/2024 in #help
Import SCSS in TS files
Hey, I am currently building a template for web development and I want to use ESBuild as a bundler. I use lit in combination with SASS. For SASS files I use the esbuild-sass-plugin from npm in Deno. This works fine and ESBuild successfully resolves and bundles the .scss files imported into the .ts files. However deno-ts marks the default import as red because it is not valid js/ts how can I specify this in the config for Deno so that the files get recognized as SCSS files/plain text?
import style from „style.scss“
// ^ Works but is red because style.scss does not have a default export.
import style from „style.scss“
// ^ Works but is red because style.scss does not have a default export.
51 replies
DDeno
Created by Mqx on 1/30/2024 in #help
Creating custom GitHub Action using Deno
Hey, I am currently trying to develop my first own custom GitHub Action. I have some trouble setting up my environment. I really don't want to use Node and try to stick to Deno, but this is easier said than done. Can someone help me setting a basic action up? Thanks! This is my current repo where I try to set everything up: https://github.com/Datapack-Registry/minecraft-manifest
7 replies
DDeno
Created by Mqx on 1/22/2024 in #help
walk() include only last directory...
Hey, I'm currently trying to write a replacer for file names, file content and folder names. My goal is to crawl over a certain directory and then replace a certain pattern in file names, file content and folder names. Currently I use the walk() function from the std library. My problem now is that walk() returns every single directory and not just the last one. In other words, walk() does not just give me:
file/to/directory
file/to/directory
but:
file
file/to
file/to/directory
file
file/to
file/to/directory
What is the best way to filter this? There may also be a better method... This is what my current attempt looks like:
import { parseArgs } from 'https://deno.land/std@0.212.0/cli/mod.ts';
import { walkSync } from 'https://deno.land/std@0.212.0/fs/mod.ts';
import { parseString as parseRegExpString } from 'https://raw.githubusercontent.com/TypeScriptPlayground/std/main/src/regexp/mod.ts'

const args = parseArgs<{
path : string,
pattern : string,
replacer : string
}>(Deno.args);

if (!args.path || !args.pattern || !args.replacer) {
console.log('Missing arguments');
Deno.exit();
}

const pattern = parseRegExpString(args.pattern);

const pathsToUpdate: Array<{ oldPath: string, newPath: string, isFile: boolean }> = [];

Deno.chdir(args.path);
for (const entry of walkSync('.')) {
const path = entry.path;
const pathReplaced = path.replace(pattern, args.replacer);

if (path !== pathReplaced) {
pathsToUpdate.push({ oldPath: path, newPath: pathReplaced, isFile: entry.isFile });
}
}

for (const { oldPath, newPath, isFile } of pathsToUpdate) {
if (isFile) {
const content = Deno.readTextFileSync(oldPath);
const contentReplaced = content.replace(pattern, args.replacer);
Deno.writeTextFileSync(newPath, contentReplaced);
} else {
Deno.renameSync(oldPath, newPath); //<- Error: /path/{{pattern}}/{{pattern}}
}
console.log(`Updated: ${oldPath} -> ${newPath}`);
}
import { parseArgs } from 'https://deno.land/std@0.212.0/cli/mod.ts';
import { walkSync } from 'https://deno.land/std@0.212.0/fs/mod.ts';
import { parseString as parseRegExpString } from 'https://raw.githubusercontent.com/TypeScriptPlayground/std/main/src/regexp/mod.ts'

const args = parseArgs<{
path : string,
pattern : string,
replacer : string
}>(Deno.args);

if (!args.path || !args.pattern || !args.replacer) {
console.log('Missing arguments');
Deno.exit();
}

const pattern = parseRegExpString(args.pattern);

const pathsToUpdate: Array<{ oldPath: string, newPath: string, isFile: boolean }> = [];

Deno.chdir(args.path);
for (const entry of walkSync('.')) {
const path = entry.path;
const pathReplaced = path.replace(pattern, args.replacer);

if (path !== pathReplaced) {
pathsToUpdate.push({ oldPath: path, newPath: pathReplaced, isFile: entry.isFile });
}
}

for (const { oldPath, newPath, isFile } of pathsToUpdate) {
if (isFile) {
const content = Deno.readTextFileSync(oldPath);
const contentReplaced = content.replace(pattern, args.replacer);
Deno.writeTextFileSync(newPath, contentReplaced);
} else {
Deno.renameSync(oldPath, newPath); //<- Error: /path/{{pattern}}/{{pattern}}
}
console.log(`Updated: ${oldPath} -> ${newPath}`);
}
6 replies
DDeno
Created by Mqx on 1/11/2024 in #help
ESBuild SASS Plugin
Hey, I have developed this Plugin: https://github.com/DenoPlayground/esbuild-plugin-sass But I have some problems with the import paths from the SASS module. Maybe someone can help me to debug this, since ESBuild does not have an official community server. The problem at the moment is that when the SASS module tries to resolve an import it does that by assuming that the path is relative to the root directory and not the file that is currently processed. Maybe there is a way to account for this issue. For example if we would assume that this is our file structure and we import colors.scss into style.scss.
/src/client/style.scss
/src/client/colors.scss
/src/client/style.scss
/src/client/colors.scss
When the SASS module resolves the import it is trying to load the colors.scss from:
/colors.scss
/colors.scss
Because this is where the initial task gets started. But I can not simply set the new root to:
/src/client
/src/client
Because then all my other tasks would not work.
28 replies
DDeno
Created by Mqx on 11/15/2023 in #help
How to uploading images from frontend to Deno.serve()
Hey, can someone please give me a vanilla code example on how to upload files from my frontend application to the server that uses Deno.serve(). I know how to upload the image in the frontend and send it to the Deno backend using a POST request, but how can I work with this image on the server side? Currently my backend is set up without any framework. Thanks!
9 replies
DDeno
Created by Mqx on 11/7/2023 in #help
Deno lint custom rules
Hey is there currently a way to create custom rules for Deno lint? And if so how can I specify a custom rule? If there is no way to create custom rules, can I use ESLint with Deno without having to install Node? And I know I can install ESLint as a global „script“ but that still requires Node to be installed. Thanks ~Mqx
3 replies
DDeno
Created by Mqx on 10/26/2023 in #help
Using ESBuild with Deno
Hey, is anyone more familiar with ESBuild? I am currently trying to transpile my Deno TypeScript project with ESBuild in JavaScript. But I don't want to bundle the files. I just want to transpile them and put them under the same path instead of src in dist. I'm currently doing the whole thing like this:
deno run -A https://deno.land/x/esbuild@v0.19.4/mod.js —target=es2022 —outdir=dist ./src/client/**
deno run -A https://deno.land/x/esbuild@v0.19.4/mod.js —target=es2022 —outdir=dist ./src/client/**
Problem with this is that it does not resolve the import paths properly. At the end there is still the .ts extension in the import. Another problem is, for example, the ESBuild tries to convert the .d.ts files into .d.js which are then simply empty.
38 replies
DDeno
Created by Mqx on 9/30/2023 in #help
Deno + Lit
Hey how can use the Lit framework with Deno? Is there a guide or config on how to use it with this framework?
22 replies
DDeno
Created by Mqx on 9/12/2023 in #help
Using Deno in Frontend.
Hey, I was wandering if it is possible to use Deno for Vanilla Frontend development. I dont want to use a Framework like Oak or Fresh, I just want to use Vanilla TypeScript instead of JavaScript in my Frontend. As an example I just want types/typechecking for developing, build my Frontend and then transpile the whole thing to a JS-Bundle that I can then load in the Frontend. Now I have 2 problems. First is how to transpile my TypeScript to a JS-Bundle (I can do that with the emit module), and the second is how can I get the DOM in TypeScript. I have found this in the manual but I am not really sure how to use it. Can someone explain to me how to setup the DOM for TypeScript development in the Frontend. And also whats about Deno.* APIs? How does the emit module handle this? Thanks! ~Mqx
20 replies
DDeno
Created by Mqx on 9/4/2023 in #help
dlopen() from web url
Hey, is it possible to provide a url to the dll file from a cdn server? For example if I want to dlopen the dll from this url: „https://raw.githubusercontent.com/TypeScripPlayground/Serial/main/ts/bin/windows.dll “ I get an error: Could not open library, module not found
3 replies
DDeno
Created by Mqx on 8/23/2023 in #help
Deno console.log() all items of array
No description
7 replies
DDeno
Created by Mqx on 8/1/2023 in #help
Generate jUnit XML file from Deno Tests
Hey is it possible that the Deno Test suite generates a jUnit XML about the Test? So that I can display the results on GitLab/GitHub?
12 replies
DDeno
Created by Mqx on 7/12/2023 in #help
Deno type enforcement
Hey, I have a question about the type checking.
function logging(message : number) {
console.log(message);
}

logging(“Hello”);
function logging(message : number) {
console.log(message);
}

logging(“Hello”);
This should throw an error when trying to run it, but apparently it does not. But why? We tried using the tsc compiler from Node and it clearly throws an error, saying that the type string is not assignable to type number. Is there something I need to change in the config for Deno to get the same error result? Thanks ~Mqx
2 replies
DDeno
Created by Mqx on 6/10/2023 in #help
VS-Code auto import local modules
Hey is there a way to enable some sort of auto import for local modules/files in VS-Code? Currently it only works if the file is opened in an other tab. When I close the tab an try to use autocomplete an exported module from that file it does not auto import. Is there a fix to this? Or some settings? Thanks for any help!
3 replies
DDeno
Created by Mqx on 5/22/2023 in #help
Reclaim an already registered module?
Is it possible to reclaim an already registered third party module? For example if the module that is already registered doesn’t get any updates or is deprecated?
27 replies
DDeno
Created by Mqx on 5/1/2023 in #help
Pass string from TS to dll and return the passed string. (Like echo)
Hey I am currently trying to understand the communication between a dll and my TS program. Currently I am simply trying to pass a string to the dll and have the dll give me the string back. Similar to an echo. I have been trying to follow this guide for this: https://medium.com/deno-the-complete-reference/calling-c-functions-from-windows-dll-in-deno-part-2-buffers-131226acd3d2 only somehow I can't pass the buffer in my TS program. Can someone give me a simple example of how to pass a string from TS to dll and from dll to TS?
const dll = Deno.dlopen('./test.dll', {
'echo': {
parameters: ['pointer'],
result: 'pointer'
}
})

const buffer = new TextEncoder().encode('Hello World!')

console.log('echo:', dll.symbols.echo(buffer));

dll.close()
const dll = Deno.dlopen('./test.dll', {
'echo': {
parameters: ['pointer'],
result: 'pointer'
}
})

const buffer = new TextEncoder().encode('Hello World!')

console.log('echo:', dll.symbols.echo(buffer));

dll.close()
117 replies
DDeno
Created by Mqx on 2/9/2023 in #help
Deno stopps at file.read()
I am currently working on a way to communicate with a COM device. I can successfully open and read from the COM port. The only problem is, is there is no data on the COM port Deno pauses at that point in the code because the Promise gets neither resolved or rejected. Here is the link to the Stackoverflow problem. https://stackoverflow.com/questions/75400521/abort-promise-after-delay-in-deno
24 replies
DDeno
Created by Mqx on 1/21/2023 in #help
Use Deno.run() to communicate with Arduino
Hey I'm trying to communicate via USB serial with my Arduino. My goal is to have the result I get via USB serial available as a variable in Deno. I tried to do the whole thing with Deno.run(). This is my Arduino main file:
#define POTENTIOMETER_PIN_A A0

void setup() {
pinMode(POTENTIOMETER_PIN_A, INPUT);
Serial.begin(115200);
}

void loop() {
int potentiometerA = analogRead(POTENTIOMETER_PIN_A);

String data = map(potentiometerA, 0, 1023, 0, 100) + String('\n');

Serial.write(data.c_str());

delay(100);
}
#define POTENTIOMETER_PIN_A A0

void setup() {
pinMode(POTENTIOMETER_PIN_A, INPUT);
Serial.begin(115200);
}

void loop() {
int potentiometerA = analogRead(POTENTIOMETER_PIN_A);

String data = map(potentiometerA, 0, 1023, 0, 100) + String('\n');

Serial.write(data.c_str());

delay(100);
}
With this simple PowerShell script I can read the data from USB serial:
$port= new-Object System.IO.Ports.SerialPort COM4,115200,None,one
$port.Open()
do {
$line = $port.ReadLine()
Write-Host $line
}
while ($port.IsOpen)
$port= new-Object System.IO.Ports.SerialPort COM4,115200,None,one
$port.Open()
do {
$line = $port.ReadLine()
Write-Host $line
}
while ($port.IsOpen)
How can I run the whole thing in Deno now and get the output? I have tried the following which obviously does not work:
Deno.run({
cmd: [
'powershell',
'$port= new-Object System.IO.Ports.SerialPort COM4,115200,None,one',
'$port.Open()',
'do { $line = $port.ReadLine(); Write-Host $line }',
'while ($port.IsOpen)'
]
})
Deno.run({
cmd: [
'powershell',
'$port= new-Object System.IO.Ports.SerialPort COM4,115200,None,one',
'$port.Open()',
'do { $line = $port.ReadLine(); Write-Host $line }',
'while ($port.IsOpen)'
]
})
Can anyone help me with this? Or is there perhaps a better solution for that? Thanks!
103 replies