Skip to content

Instantly share code, notes, and snippets.

@cspotcode
cspotcode / README.md
Last active April 6, 2022 13:59
P.S: Ran the cmd without nodemon as well, same error

To try this, run npm start

{
"name": "yaml-loader",
"exports": {
".": "./yaml-loader.mjs"
}
}

Understanding the flavors of .d.ts

We think of .d.ts as having two styles: the ambient declare module style (Ambient) and the named "DT" style. (Named)

declare module "some string" { tells the compiler that, from then forward, if it ever sees any import of "some string" then it need look no further. It will not attempt to find anything on the filesystem, it will not scan through directories, none of that at all. On the other hand, if you put export const foo... at the beginning of a .d.ts, then the .d.ts itself is essentially pretending to be a .js file (Named) and imports will pass through typescript's resolver, doing all sorts of path mapping and filesystem traversal to find the .d.ts file.

The .d.ts's filename only matters in the latter case, where the declaration is pretending to by a .js file. (Named) In the former case, (Ambient) where the .d.ts exists to declare global types or declare module, the .d.ts's filename does not matter. All that matters is that the compiler has

To reproduce:

❯ volta --version
1.0.4

❯ npm --version
7.14.0

❯ npm install -g https://gist.github.com/cspotcode/c07208f11ed73dc7f81a0200e5aeb797.git
console.log('hello world');
@cspotcode
cspotcode / bootstrap.cjs
Created February 23, 2021 18:13
yarn 2 bootstrap downloader, when you don't want to commit yarn's binary to git
const target = './releases/yarn-berry.cjs';
// Change URL to refer to specific commit if you want version to be locked
const url = 'https://github.com/yarnpkg/berry/raw/master/packages/berry-cli/bin/berry.js';
const Path = require('path')
const fs = require('fs')
const targetPath = Path.join(__dirname, target)
if(fs.existsSync(targetPath)) {
require(targetPath)
} else {
@cspotcode
cspotcode / exec-with-tagged-template-literals.js
Created June 17, 2019 18:55
exec with tagged template literals
// TODO also support quoting?
function execTmpl(tmpl: TemplateStringsArray, ...rest: Array<string | Array<string>>) {
const delim = {};
const acc = [];
for(let i = 0; i < tmpl.length; i++) {
if(tmpl[i].length !== 0) {
const bits = tmpl[i].split(/ +/);
for(let j = 0; j < bits.length; j++) {
// whitespace becomes a delim
#Thread-safe data structure to store prompt strings and communicate about state
$prompt = [Collections.Concurrent.ConcurrentDictionary[String,String]]@{}
$prompt.infix = ''
Set-PSReadlineOption -ExtraPromptLineCount 1 # For 2-line prompt
Register-EngineEvent -SourceIdentifier PowerShell.OnIdle -Action {
if($prompt.state -eq 'rerender') {
$prompt.isIdleRender = 'yes'
[Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
$prompt.isIdleRender = 'no'
@cspotcode
cspotcode / .npm-init.js
Last active July 21, 2018 08:33
Extending npm's built-in init behavior rather than replacing it
// $HOME/.npm-init.js
function main() {
// Put your customizations here
package.private = true;
}
// Helpers for getting access to modules that are either installed globally or available as dependencies of npm
function requireGlobal(name) {
return require(require('path').join(config.get('prefix'), 'node_modules', name));
}
@cspotcode
cspotcode / README.md
Created October 4, 2017 05:03
Transpiling async functions

foo