Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

btsm

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

btsm - npm Package Compare versions

Comparing version 2.2.1 to 2.2.2

45

bin.js
#!/usr/bin/env node
let argv=process.argv.slice(2);if(argv.includes("-h")||argv.includes("--help")){let e="";e+=`
Usage
$ tsm [options] -- <command>
`,e+=`
Options`,e+=`
--tsmconfig Configuration file path (default: tsm.js)`,e+=`
--quiet Silence all terminal messages`,e+=`
--version Displays current version`,e+=`
--help Displays this message
`,e+=`
Examples`,e+=`
$ tsm server.ts`,e+=`
$ node -r tsm input.jsx`,e+=`
$ node --loader tsm input.jsx`,e+=`
$ NO_COLOR=1 tsm input.jsx --trace-warnings`,e+=`
$ tsm server.tsx --tsmconfig tsm.mjs
`,console.log(e),process.exit(0)}(argv.includes("-v")||argv.includes("--version"))&&(console.log("tsm, v2.2.1"),process.exit(0));let{URL,pathToFileURL}=require("url");argv=["--loader",new URL("loader.mjs",pathToFileURL(__filename)).href,...argv],require("child_process").spawn("node",argv,{stdio:"inherit"}).on("exit",process.exit);
let argv = process.argv.slice(2);
if (argv.includes("-h") || argv.includes("--help")) {
let msg = "";
msg += "\n Usage\n $ tsm [options] -- <command>\n";
msg += "\n Options";
msg += `
--tsmconfig Configuration file path (default: tsm.js)`;
msg += `
--quiet Silence all terminal messages`;
msg += `
--version Displays current version`;
msg += "\n --help Displays this message\n";
msg += "\n Examples";
msg += "\n $ tsm server.ts";
msg += "\n $ node -r tsm input.jsx";
msg += "\n $ node --loader tsm input.jsx";
msg += "\n $ NO_COLOR=1 tsm input.jsx --trace-warnings";
msg += "\n $ tsm server.tsx --tsmconfig tsm.mjs\n";
console.log(msg);
process.exit(0);
}
if (argv.includes("-v") || argv.includes("--version")) {
console.log(`tsm, v${"2.2.1"}`);
process.exit(0);
}
let { URL, pathToFileURL } = require("url");
argv = ["--loader", new URL("loader.mjs", pathToFileURL(__filename)).href, ...argv];
require("child_process").spawn("node", argv, { stdio: "inherit" }).on("exit", process.exit);
{
"name": "btsm",
"version": "2.2.1",
"version": "2.2.2",
"repository": "lukeed/tsm",

@@ -5,0 +5,0 @@ "description": "TypeScript Module Loader",

@@ -1,1 +0,65 @@

const{extname}=require("path"),{readFileSync}=require("fs"),tsm=require("./utils"),loadJS=require.extensions[".js"];let esbuild,env=tsm.$defaults("cjs"),uconf=env.file&&require(env.file),config=tsm.$finalize(env,uconf);const tsrequire='var $$req=require("module").createRequire(__filename);require=('+function(){let{existsSync:r}=$$req("fs"),t=$$req("url");return new Proxy(require,{apply(s,n,o){let[e]=o;if(!e)return s.apply(n||$$req,o);if(/^\w+\:?/.test(e))return $$req(e);let l=/\.([mc])?js(?=\?|$)/.exec(e);if(l==null)return $$req(e);let u=t.pathToFileURL(__filename),i=t.fileURLToPath(new t.URL(e,u));return r(i)?$$req(e):(i=i.replace(new RegExp(l[0]+"$"),l[0].replace("js","ts")),r(i)?$$req(i):$$req(e))}})}+")();";function transform(r,t){return esbuild=esbuild||require("esbuild"),esbuild.transformSync(r,t).code}function loader(r,t){let s=extname(t),n=config[s]||{},o=r._compile.bind(r);n.sourcefile=t,/\.[mc]?tsx?$/.test(s)&&(n.banner=tsrequire+(n.banner||"")),config[s]!=null&&(r._compile=e=>{let l=transform(e,n);return o(l,t)});try{return loadJS(r,t)}catch(e){if((e&&e.code)!=="ERR_REQUIRE_ESM")throw e;let u=readFileSync(t,"utf8"),i=transform(u,{...n,format:"cjs"});return o(i,t)}}for(let r in config)require.extensions[r]=loader;config[".js"]==null&&(require.extensions[".js"]=loader);
const { extname } = require("path");
const { readFileSync } = require("fs");
const tsm = require("./utils");
const loadJS = require.extensions[".js"];
let esbuild;
let env = tsm.$defaults("cjs");
let uconf = env.file && require(env.file);
let config = tsm.$finalize(env, uconf);
const tsrequire = 'var $$req=require("module").createRequire(__filename);require=(' + function() {
let { existsSync } = $$req("fs");
let $url = $$req("url");
return new Proxy(require, {
apply(req, ctx, args) {
let [ident] = args;
if (!ident)
return req.apply(ctx || $$req, args);
if (/^\w+\:?/.test(ident))
return $$req(ident);
let match = /\.([mc])?js(?=\?|$)/.exec(ident);
if (match == null)
return $$req(ident);
let base = $url.pathToFileURL(__filename);
let file = $url.fileURLToPath(new $url.URL(ident, base));
if (existsSync(file))
return $$req(ident);
file = file.replace(new RegExp(match[0] + "$"), match[0].replace("js", "ts"));
return existsSync(file) ? $$req(file) : $$req(ident);
}
});
} + ")();";
function transform(source, options) {
esbuild = esbuild || require("esbuild");
return esbuild.transformSync(source, options).code;
}
function loader(Module, sourcefile) {
let extn = extname(sourcefile);
let options = config[extn] || {};
let pitch = Module._compile.bind(Module);
options.sourcefile = sourcefile;
if (/\.[mc]?tsx?$/.test(extn)) {
options.banner = tsrequire + (options.banner || "");
}
if (config[extn] != null) {
Module._compile = (source) => {
let result = transform(source, options);
return pitch(result, sourcefile);
};
}
try {
return loadJS(Module, sourcefile);
} catch (err) {
let ec = err && err.code;
if (ec !== "ERR_REQUIRE_ESM")
throw err;
let input = readFileSync(sourcefile, "utf8");
let result = transform(input, { ...options, format: "cjs" });
return pitch(result, sourcefile);
}
}
for (let extn in config) {
require.extensions[extn] = loader;
}
if (config[".js"] == null) {
require.extensions[".js"] = loader;
}

@@ -1,1 +0,55 @@

const{resolve}=require("path"),{existsSync}=require("fs");exports.$defaults=function(i){let{FORCE_COLOR:e,NO_COLOR:s,NODE_DISABLE_COLORS:o,TERM:t}=process.env,l=process.argv.slice(2),n=new Set(l),f=n.has("-q")||n.has("--quiet"),d=!o&&s==null&&t!=="dumb"&&(e!=null&&e!=="0"||process.stdout.isTTY),r=n.has("--tsmconfig")?l.indexOf("--tsmconfig"):-1,a=resolve(".",!!~r&&l[++r]||"tsm.js");return{file:existsSync(a)&&a,isESM:i==="esm",options:{format:i,charset:"utf8",sourcemap:"inline",target:i==="esm"?"node"+process.versions.node:"node12",logLevel:f?"silent":"warning",color:d}}},exports.$finalize=function(i,e){let s=i.options;e&&e.common&&(Object.assign(s,e.common),delete e.common);let o={".mts":{...s,loader:"ts"},".jsx":{...s,loader:"jsx"},".tsx":{...s,loader:"tsx"},".cts":{...s,loader:"ts"},".ts":{...s,loader:"ts"}};i.isESM?o[".json"]={...s,loader:"json"}:o[".mjs"]={...s,loader:"js"};let t;if(e&&e.loaders)for(t in e.loaders)o[t]={...s,loader:e.loaders[t]};else if(e){let l=e.config||e;for(t in l)o[t]={...s,...l[t]}}return o};
const { resolve } = require("path");
const { existsSync } = require("fs");
exports.$defaults = function(format) {
let { FORCE_COLOR, NO_COLOR, NODE_DISABLE_COLORS, TERM } = process.env;
let argv = process.argv.slice(2);
let flags = new Set(argv);
let isQuiet = flags.has("-q") || flags.has("--quiet");
let enabled = !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || process.stdout.isTTY);
let idx = flags.has("--tsmconfig") ? argv.indexOf("--tsmconfig") : -1;
let file = resolve(".", !!~idx && argv[++idx] || "tsm.js");
return {
file: existsSync(file) && file,
isESM: format === "esm",
options: {
format,
charset: "utf8",
sourcemap: "inline",
target: format === "esm" ? "node" + process.versions.node : "node12",
logLevel: isQuiet ? "silent" : "warning",
color: enabled
}
};
};
exports.$finalize = function(env, custom) {
let base = env.options;
if (custom && custom.common) {
Object.assign(base, custom.common);
delete custom.common;
}
let config = {
".mts": { ...base, loader: "ts" },
".jsx": { ...base, loader: "jsx" },
".tsx": { ...base, loader: "tsx" },
".cts": { ...base, loader: "ts" },
".ts": { ...base, loader: "ts" }
};
if (env.isESM) {
config[".json"] = { ...base, loader: "json" };
} else {
config[".mjs"] = { ...base, loader: "js" };
}
let extn;
if (custom && custom.loaders) {
for (extn in custom.loaders)
config[extn] = {
...base,
loader: custom.loaders[extn]
};
} else if (custom) {
let conf = custom.config || custom;
for (extn in conf)
config[extn] = { ...base, ...conf[extn] };
}
return config;
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc