Socket
Socket
Sign inDemoInstall

@hyrious/dts

Package Overview
Dependencies
Maintainers
0
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hyrious/dts - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7

224

cli.js
#!/usr/bin/env node
// src/cli.ts
import sade from "sade";
// node_modules/mri/lib/index.mjs
function toArr(any) {
return any == null ? [] : Array.isArray(any) ? any : [any];
}
function toVal(out, key, val, opts) {
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
}
function lib_default(args, opts) {
args = args || [];
opts = opts || {};
var k, arr, arg, name2, val, out = { _: [] };
var i2 = 0, j = 0, idx = 0, len = args.length;
const alibi = opts.alias !== void 0;
const strict = opts.unknown !== void 0;
const defaults = opts.default !== void 0;
opts.alias = opts.alias || {};
opts.string = toArr(opts.string);
opts.boolean = toArr(opts.boolean);
if (alibi) {
for (k in opts.alias) {
arr = opts.alias[k] = toArr(opts.alias[k]);
for (i2 = 0; i2 < arr.length; i2++) {
(opts.alias[arr[i2]] = arr.concat(k)).splice(i2, 1);
}
}
}
for (i2 = opts.boolean.length; i2-- > 0; ) {
arr = opts.alias[opts.boolean[i2]] || [];
for (j = arr.length; j-- > 0; ) opts.boolean.push(arr[j]);
}
for (i2 = opts.string.length; i2-- > 0; ) {
arr = opts.alias[opts.string[i2]] || [];
for (j = arr.length; j-- > 0; ) opts.string.push(arr[j]);
}
if (defaults) {
for (k in opts.default) {
name2 = typeof opts.default[k];
arr = opts.alias[k] = opts.alias[k] || [];
if (opts[name2] !== void 0) {
opts[name2].push(k);
for (i2 = 0; i2 < arr.length; i2++) {
opts[name2].push(arr[i2]);
}
}
}
}
const keys = strict ? Object.keys(opts.alias) : [];
for (i2 = 0; i2 < len; i2++) {
arg = args[i2];
if (arg === "--") {
out._ = out._.concat(args.slice(++i2));
break;
}
for (j = 0; j < arg.length; j++) {
if (arg.charCodeAt(j) !== 45) break;
}
if (j === 0) {
out._.push(arg);
} else if (arg.substring(j, j + 3) === "no-") {
name2 = arg.substring(j + 3);
if (strict && !~keys.indexOf(name2)) {
return opts.unknown(arg);
}
out[name2] = false;
} else {
for (idx = j + 1; idx < arg.length; idx++) {
if (arg.charCodeAt(idx) === 61) break;
}
name2 = arg.substring(j, idx);
val = arg.substring(++idx) || (i2 + 1 === len || ("" + args[i2 + 1]).charCodeAt(0) === 45 || args[++i2]);
arr = j === 2 ? [name2] : name2;
for (idx = 0; idx < arr.length; idx++) {
name2 = arr[idx];
if (strict && !~keys.indexOf(name2)) return opts.unknown("-".repeat(j) + name2);
toVal(out, name2, idx + 1 < arr.length || val, opts);
}
}
}
if (defaults) {
for (k in opts.default) {
if (out[k] === void 0) {
out[k] = opts.default[k];
}
}
}
if (alibi) {
for (k in out) {
arr = opts.alias[k] || [];
while (arr.length > 0) {
out[arr.shift()] = out[k];
}
}
}
return out;
}
// node_modules/sade/lib/index.mjs
var t = "__all__";
var i = "__default__";
var s = "\n";
function r(e) {
if (!e.length) return "";
let t2 = function(e2) {
let t3 = 0, i2 = 0, s2 = 0, r2 = e2.length;
if (r2) for (; r2--; ) i2 = e2[r2].length, i2 > t3 && (s2 = r2, t3 = i2);
return e2[s2].length;
}(e.map((e2) => e2[0])) + 4;
return e.map((e2) => e2[0] + " ".repeat(t2 - e2[0].length) + e2[1] + (null == e2[2] ? "" : ` (default ${e2[2]})`));
}
function n(e) {
return e;
}
function l(e, t2, i2) {
if (!t2 || !t2.length) return "";
let r2 = 0, n2 = "";
for (n2 += "\n " + e; r2 < t2.length; r2++) n2 += "\n " + i2(t2[r2]);
return n2 + s;
}
function a(e, t2, i2 = 1) {
let s2 = l("ERROR", [t2], n);
s2 += `
Run \`$ ${e} --help\` for more info.
`, console.error(s2), process.exit(i2);
}
var o = class {
constructor(e, s2) {
let [r2, ...n2] = e.split(/\s+/);
s2 = s2 || n2.length > 0, this.bin = r2, this.ver = "0.0.0", this.default = "", this.tree = {}, this.command(t), this.command([i].concat(s2 ? n2 : "<command>").join(" ")), this.single = s2, this.curr = "";
}
command(e, t2, i2 = {}) {
if (this.single) throw new Error('Disable "single" mode to add commands');
let s2 = [], r2 = [], n2 = /(\[|<)/;
if (e.split(/\s+/).forEach((e2) => {
(n2.test(e2.charAt(0)) ? r2 : s2).push(e2);
}), s2 = s2.join(" "), s2 in this.tree) throw new Error("Command already exists: " + s2);
return s2.includes("__") || r2.unshift(s2), r2 = r2.join(" "), this.curr = s2, i2.default && (this.default = s2), this.tree[s2] = { usage: r2, alibi: [], options: [], alias: {}, default: {}, examples: [] }, i2.alias && this.alias(i2.alias), t2 && this.describe(t2), this;
}
describe(e) {
return this.tree[this.curr || i].describe = Array.isArray(e) ? e : function(e2) {
return (e2 || "").replace(/([.?!])\s*(?=[A-Z])/g, "$1|").split("|");
}(e), this;
}
alias(...e) {
if (this.single) throw new Error('Cannot call `alias()` in "single" mode');
if (!this.curr) throw new Error("Cannot call `alias()` before defining a command");
return (this.tree[this.curr].alibi = this.tree[this.curr].alibi.concat(...e)).forEach((e2) => this.tree[e2] = this.curr), this;
}
option(e, i2, s2) {
let r2 = this.tree[this.curr || t], [n2, l2] = function(e2) {
return (e2 || "").split(/^-{1,2}|,|\s+-{1,2}|\s+/).filter(Boolean);
}(e);
if (l2 && l2.length > 1 && ([n2, l2] = [l2, n2]), e = "--" + n2, l2 && l2.length > 0) {
e = `-${l2}, ${e}`;
let t2 = r2.alias[l2];
r2.alias[l2] = (t2 || []).concat(n2);
}
let a2 = [e, i2 || ""];
return void 0 !== s2 ? (a2.push(s2), r2.default[n2] = s2) : l2 || (r2.default[n2] = void 0), r2.options.push(a2), this;
}
action(e) {
return this.tree[this.curr || i].handler = e, this;
}
example(e) {
return this.tree[this.curr || i].examples.push(e), this;
}
version(e) {
return this.ver = e, this;
}
parse(s2, r2 = {}) {
s2 = s2.slice();
let n2, l2, o2, h, u = 2, f = lib_default(s2.slice(u), { alias: { h: "help", v: "version" } }), c = this.single, p = this.bin, d = "";
if (c) h = this.tree[i];
else {
let e, t2 = 1, i2 = f._.length + 1;
for (; t2 < i2; t2++) if (n2 = f._.slice(0, t2).join(" "), e = this.tree[n2], "string" == typeof e) l2 = (d = e).split(" "), s2.splice(s2.indexOf(f._[0]), t2, ...l2), t2 += l2.length - t2;
else if (e) d = n2;
else if (d) break;
if (h = this.tree[d], o2 = void 0 === h, o2) {
if (this.default) d = this.default, h = this.tree[d], s2.unshift(d), u++;
else if (n2) return a(p, "Invalid command: " + n2);
}
}
if (f.help) return this.help(!c && !o2 && d);
if (f.version) return this._version();
if (!c && void 0 === h) return a(p, "No command specified.");
let g = this.tree[t];
r2.alias = Object.assign(g.alias, h.alias, r2.alias), r2.default = Object.assign(g.default, h.default, r2.default), n2 = d.split(" "), l2 = s2.indexOf(n2[0], 2), ~l2 && s2.splice(l2, n2.length);
let m = lib_default(s2.slice(u), r2);
if (!m || "string" == typeof m) return a(p, m || "Parsed unknown option flag(s)!");
let b = h.usage.split(/\s+/), _ = b.filter((e) => "<" === e.charAt(0)), v = m._.splice(0, _.length);
if (v.length < _.length) return d && (p += " " + d), a(p, "Insufficient arguments!");
b.filter((e) => "[" === e.charAt(0)).forEach((e) => {
v.push(m._.shift());
}), v.push(m);
let $ = h.handler;
return r2.lazy ? { args: v, name: d, handler: $ } : $.apply(null, v);
}
help(e) {
console.log(function(e2, a2, o2, h) {
let u = "", f = a2[o2], c = "$ " + e2, p = a2[t], d = (e3) => `${c} ${e3}`.replace(/\s+/g, " "), g = [["-h, --help", "Displays this message"]];
if (o2 === i && g.unshift(["-v, --version", "Displays current version"]), f.options = (f.options || []).concat(p.options, g), f.options.length > 0 && (f.usage += " [options]"), u += l("Description", f.describe, n), u += l("Usage", [f.usage], d), h || o2 !== i) h || o2 === i || (u += l("Aliases", f.alibi, d));
else {
let e3, t2 = /^__/, i2 = "", o3 = [];
for (e3 in a2) "string" == typeof a2[e3] || t2.test(e3) || o3.push([e3, (a2[e3].describe || [""])[0]]) < 3 && (i2 += `
${c} ${e3} --help`);
u += l("Available Commands", r(o3), n), u += "\n For more info, run any command with the `--help` flag" + i2 + s;
}
return u += l("Options", r(f.options), n), u += l("Examples", f.examples.map(d), n), u;
}(this.bin, this.tree, e || i, this.single));
}
_version() {
console.log(`${this.bin}, ${this.ver}`);
}
};
var lib_default2 = (e, t2) => new o(e, t2);
// node_modules/yoctocolors/base.js

@@ -43,3 +257,3 @@ import tty from "node:tty";

var name = "@hyrious/dts";
var version = "0.2.6";
var version = "0.2.7";
var description = "Invoke rollup-plugin-dts to generate bundled .d.ts file";

@@ -81,3 +295,3 @@

}
sade(name).version(version).describe(description).command("build [index.ts]", "Build a .d.ts file from a .ts file", { default: true }).option("-o, --outfile", "Output file").option("-i, --include", "Force include a module in the bundle").option("-e, --exclude", "Force exclude a module from the bundle").option("-p, --patch", "Patch rollup-plugin-dts to handle `/// doc comments`").option("-a, --alias", "Rename an external path to something else").example("src/index.ts -o dist/index.d.ts").action(async (entry, options) => {
lib_default2(name).version(version).describe(description).command("build [index.ts]", "Build a .d.ts file from a .ts file", { default: true }).option("-o, --outfile", "Output file").option("-i, --include", "Force include a module in the bundle").option("-e, --exclude", "Force exclude a module from the bundle").option("-m, --empty", "Force ignore a module (treat as empty) in the bundle").option("-p, --patch", "Patch rollup-plugin-dts to handle `/// doc comments`").option("-a, --alias", "Rename an external path to something else").example("src/index.ts -o dist/index.d.ts").action(async (entry, options) => {
if (process.env.NO_DTS) {

@@ -92,2 +306,3 @@ console.log(`${bgGray(black(" DTS "))} Skipping build due to env NO_DTS`);

const exclude = to_array(options.exclude);
const empty = to_array(options.empty);
const alias = to_dict(to_array(options.alias));

@@ -105,2 +320,3 @@ try {

exclude,
empty,
alias

@@ -107,0 +323,0 @@ });

4

index.d.ts
import { RollupOutput } from 'rollup';
import { Options } from 'rollup-plugin-dts';
declare const version = "0.2.6";
declare const version = "0.2.7";

@@ -13,2 +13,4 @@ interface BuildOptions {

exclude?: string[];
/** Force ignore a module (treat as empty) in the types bundle. */
empty?: string[];
/** Rename external paths to something else. */

@@ -15,0 +17,0 @@ alias?: Record<string, string>;

@@ -27,5 +27,6 @@ // src/index.ts

import dts from "rollup-plugin-dts";
import { build as esbuild } from "esbuild";
// package.json
var version = "0.2.6";
var version = "0.2.7";

@@ -80,3 +81,32 @@ // src/index.ts

skipLibCheck: true,
stripInternal: true
stripInternal: true,
// Turn off all strict type checking options so that it can probably pass the type-check.
// The dts plugin will compile type definitions for .ts files, and it will search for
// the tsconfig.json from user's code base. This should be fine, however, in some cases
// it cannot infer some types correctly. Example:
//
// emitter.on('event', (data) => {})
// ^^^^ This type is infered, otherwise it will be `any`.
// However, an `any` type without `noImplicitAny` will cause an error.
//
// I honestly don't know why. But I can turn off all strict options to avoid this.
// This also means that this package should not be used as a type-checking linter.
strict: false,
alwaysStrict: false,
noImplicitAny: false,
noImplicitThis: false,
strictBindCallApply: false,
strictFunctionTypes: false,
strictNullChecks: false,
strictPropertyInitialization: false,
useUnknownInCatchVariables: false,
exactOptionalPropertyTypes: false,
noFallthroughCasesInSwitch: false,
noImplicitOverride: false,
noImplicitReturns: false,
noPropertyAccessFromIndexSignature: false,
noUncheckedIndexedAccess: false,
noUnusedLocals: false,
noUnusedParameters: false
// Maybe I will be missing some options here, please let me know if you find one.
};

@@ -87,2 +117,3 @@ async function build(entry, outfile, options = {}) {

const exclude = options.exclude || [];
const empty = options.empty || [];
const start = Date.now();

@@ -106,2 +137,6 @@ const pwd = process.cwd();

options.alias && alias(options.alias),
// ignore some modules
empty.length > 0 && ignore(new RegExp(`^(${empty.join("|")})(\\/|\\\\|$)`)),
// resolve tsconfig paths with esbuild
resolve2(),
// import "./style.css" = nothing

@@ -153,2 +188,33 @@ ignore(CSS_LANGS_RE),

}
function resolve2() {
return {
name: "resolve",
async resolveId(id, importer, options) {
if (options.isEntry || id[0] === "\0" || id.includes("virtual:")) return;
let result;
await esbuild({
stdin: {
contents: `import ${JSON.stringify(id)}`,
resolveDir: importer ? join(importer, "..") : process.cwd()
},
write: false,
bundle: true,
platform: "node",
logLevel: "silent",
plugins: [
{
name: "resolve",
setup({ onLoad }) {
onLoad({ filter: /()/ }, (args) => {
result = args.path;
return { contents: "" };
});
}
}
]
}).catch(() => void 0);
return result;
}
};
}
function ignore(re) {

@@ -155,0 +221,0 @@ return {

{
"name": "@hyrious/dts",
"type": "module",
"version": "0.2.6",
"version": "0.2.7",
"description": "Invoke rollup-plugin-dts to generate bundled .d.ts file",

@@ -30,5 +30,5 @@ "author": "hyrious <hyrious@outlook.com>",

"@rollup/plugin-json": "^6.1.0",
"esbuild": "^0.23.1",
"rollup": "^4.21.0",
"rollup-plugin-dts": "^6.1.1",
"sade": "^1.8.1",
"typescript": "^5.5.4"

@@ -39,7 +39,8 @@ },

"@hyrious/esbuild-dev": "^0.10.8",
"@hyrious/esbuild-plugin-external": "^0.1.4",
"@types/node": "^20.16.1",
"esbuild": "^0.23.1",
"escalade": "^3.1.2",
"sade": "^1.8.1",
"yoctocolors": "^2.1.1"
}
}

@@ -11,2 +11,9 @@ # @hyrious/dts

> [!IMPORTANT]
> Do not use this package as a type-checking linter. It intentionally turns off all strict type-checking options to make it work with any codebase. My goal is to generate `.d.ts` files instead of checking types.
### Bonus
Add `-p` to enable tripple-slash doc comments (will be transformed to `/** comments */`).
## Changelog

@@ -13,0 +20,0 @@

@@ -60,6 +60,10 @@ import sade from 'sade'

.option('-e, --exclude', 'Force exclude a module from the bundle')
.option('-m, --empty', 'Force ignore a module (treat as empty) in the bundle')
.option('-p, --patch', 'Patch rollup-plugin-dts to handle `/// doc comments`')
.option('-a, --alias', 'Rename an external path to something else')
.example('src/index.ts -o dist/index.d.ts')
.action(<SadeHandler1<'outfile' | 'include' | 'exclude' | 'patch' | 'alias'>>(async (entry, options) => {
.action(<SadeHandler1<'outfile' | 'include' | 'exclude' | 'patch' | 'alias' | 'empty'>>(async (
entry,
options,
) => {
if (process.env.NO_DTS) {

@@ -77,2 +81,3 @@ console.log(`${bgGray(black(' DTS '))} Skipping build due to env NO_DTS`)

const exclude = to_array(options.exclude)
const empty = to_array(options.empty)
const alias = to_dict(to_array(options.alias))

@@ -86,6 +91,7 @@ try {

}
const { build } = await import('./index')
const { build } = await import('./index.js')
const { output, elapsed } = await build(entry, outfile, {
include,
exclude,
empty,
alias,

@@ -92,0 +98,0 @@ })

@@ -10,2 +10,3 @@ import type ts from 'typescript'

import dts, { Options } from 'rollup-plugin-dts'
import { build as esbuild } from 'esbuild'

@@ -70,2 +71,32 @@ export { version } from '../package.json'

stripInternal: true,
// Turn off all strict type checking options so that it can probably pass the type-check.
// The dts plugin will compile type definitions for .ts files, and it will search for
// the tsconfig.json from user's code base. This should be fine, however, in some cases
// it cannot infer some types correctly. Example:
//
// emitter.on('event', (data) => {})
// ^^^^ This type is infered, otherwise it will be `any`.
// However, an `any` type without `noImplicitAny` will cause an error.
//
// I honestly don't know why. But I can turn off all strict options to avoid this.
// This also means that this package should not be used as a type-checking linter.
strict: false,
alwaysStrict: false,
noImplicitAny: false,
noImplicitThis: false,
strictBindCallApply: false,
strictFunctionTypes: false,
strictNullChecks: false,
strictPropertyInitialization: false,
useUnknownInCatchVariables: false,
exactOptionalPropertyTypes: false,
noFallthroughCasesInSwitch: false,
noImplicitOverride: false,
noImplicitReturns: false,
noPropertyAccessFromIndexSignature: false,
noUncheckedIndexedAccess: false,
noUnusedLocals: false,
noUnusedParameters: false,
// Maybe I will be missing some options here, please let me know if you find one.
}

@@ -80,2 +111,4 @@

exclude?: string[]
/// Force ignore a module (treat as empty) in the types bundle.
empty?: string[]
/// Rename external paths to something else.

@@ -99,2 +132,3 @@ alias?: Record<string, string>

const exclude = options.exclude || []
const empty = options.empty || []

@@ -123,2 +157,6 @@ const start = Date.now()

options.alias && alias(options.alias),
// ignore some modules
empty.length > 0 && ignore(new RegExp(`^(${empty.join('|')})(\\/|\\\\|$)`)),
// resolve tsconfig paths with esbuild
resolve(),
// import "./style.css" = nothing

@@ -177,2 +215,36 @@ ignore(CSS_LANGS_RE),

function resolve(): Plugin {
return {
name: 'resolve',
async resolveId(id, importer, options) {
if (options.isEntry || id[0] === '\0' || id.includes('virtual:')) return
let result: string | undefined
await esbuild({
stdin: {
contents: `import ${JSON.stringify(id)}`,
resolveDir: importer ? join(importer, '..') : process.cwd(),
},
write: false,
bundle: true,
platform: 'node',
logLevel: 'silent',
plugins: [
{
name: 'resolve',
setup({ onLoad }) {
onLoad({ filter: /()/ }, args => {
result = args.path
return { contents: '' }
})
},
},
],
}).catch(() => void 0)
return result
},
}
}
function ignore(re: RegExp): Plugin {

@@ -179,0 +251,0 @@ return {

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