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

sveld

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sveld - npm Package Compare versions

Comparing version 0.12.1 to 0.13.0

5

CHANGELOG.md

@@ -13,2 +13,7 @@ # Changelog

## [0.13.0](https://github.com/carbon-design-system/sveld/releases/tag/v0.13.0) - 2022-01-22
- export `sveld` for programmatic usage
- upgrade prettier, rollup, svelte, svelte-preprocess, typescript
## [0.12.1](https://github.com/carbon-design-system/sveld/releases/tag/v0.12.1) - 2022-01-20

@@ -15,0 +20,0 @@

6

lib/ComponentParser.js

@@ -152,3 +152,3 @@ "use strict";

description: ComponentParser.assignValue(description),
ts: /(\}|\};)$/.test(type) ? "interface " + name + " " + type : "type " + name + " = " + type
ts: /(\}|\};)$/.test(type) ? "interface ".concat(name, " ").concat(type) : "type ".concat(name, " = ").concat(type)
});

@@ -177,3 +177,3 @@ break;

if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.verbose) {
process.stdout.write("[parsing] \"" + diagnostics.moduleName + "\" " + diagnostics.filePath + "\n");
process.stdout.write("[parsing] \"".concat(diagnostics.moduleName, "\" ").concat(diagnostics.filePath, "\n"));
}

@@ -400,3 +400,3 @@ this.cleanup();

slot_props_1[key].value = "any";
new_props_1.push(key + ": " + slot_props_1[key].value);
new_props_1.push("".concat(key, ": ").concat(slot_props_1[key].value));
});

@@ -403,0 +403,0 @@ var formatted_slot_props = new_props_1.length === 0 ? "{}" : "{ " + new_props_1.join(", ") + " }";

@@ -9,7 +9,7 @@ "use strict";

if (exportee.mixed) {
return "export { default as " + id + " } from \"" + exportee.source + "\";\nexport { default } from \"" + exportee.source + "\";";
return "export { default as ".concat(id, " } from \"").concat(exportee.source, "\";\nexport { default } from \"").concat(exportee.source, "\";");
}
return "export { default } from \"" + exportee.source + "\";";
return "export { default } from \"".concat(exportee.source, "\";");
}
return "export { default as " + id + " } from \"" + exportee.source + "\";";
return "export { default as ".concat(id, " } from \"").concat(exportee.source, "\";");
});

@@ -16,0 +16,0 @@ return source.join("\n");

export declare type SvelteEntryPoint = string;
/**
* Get the file path entrypoint for uncompiled Svelte source code
* Get the file path entry point for uncompiled Svelte source code
* Expects a "svelte" field in the consumer's `package.json`
*/
export declare function getSvelteEntry(): SvelteEntryPoint | null;
export declare function getSvelteEntry(entryPoint?: SvelteEntryPoint): SvelteEntryPoint | null;

@@ -7,6 +7,16 @@ "use strict";

/**
* Get the file path entrypoint for uncompiled Svelte source code
* Get the file path entry point for uncompiled Svelte source code
* Expects a "svelte" field in the consumer's `package.json`
*/
function getSvelteEntry() {
function getSvelteEntry(entryPoint) {
if (entryPoint) {
var entry_path = path.join(process.cwd(), entryPoint);
if (fs.existsSync(entry_path)) {
return entry_path;
}
else {
process.stdout.write("Invalid entry point: ".concat(entry_path, ".\n"));
return null;
}
}
var pkg_path = path.join(process.cwd(), "package.json");

@@ -17,4 +27,4 @@ if (fs.existsSync(pkg_path)) {

return pkg.svelte;
process.stdout.write("Could not determine an entrypoint.\n");
process.stdout.write('Specify an entrypoint to your Svelte code in the "svelte" field of your package.json.\n');
process.stdout.write("Could not determine an entry point.\n");
process.stdout.write('Specify an entry point to your Svelte code in the "svelte" field of your package.json.\n');
return null;

@@ -21,0 +31,0 @@ }

export { default } from "./rollup-plugin";
export { default as ComponentParser } from "./ComponentParser";
export { cli } from "./cli";
export { sveld } from "./sveld";

@@ -10,3 +10,3 @@ "use strict";

exports.__esModule = true;
exports.cli = exports.ComponentParser = exports["default"] = void 0;
exports.sveld = exports.cli = exports.ComponentParser = exports["default"] = void 0;
var rollup_plugin_1 = require("./rollup-plugin");

@@ -18,1 +18,3 @@ __createBinding(exports, rollup_plugin_1, "default");

__createBinding(exports, cli_1, "cli");
var sveld_1 = require("./sveld");
__createBinding(exports, sveld_1, "sveld");

@@ -103,3 +103,3 @@ "use strict";

if (glob) {
fg.sync([dir + "/**/*.svelte"]).forEach(function (file) {
fg.sync(["".concat(dir, "/**/*.svelte")]).forEach(function (file) {
var moduleName = path.parse(file).name.replace(/\-/g, "");

@@ -106,0 +106,0 @@ var source = (0, path_1.normalizeSeparators)("./" + path.relative(dir, file));

import { PluginSveldOptions } from "./rollup-plugin";
export declare function sveld(opts?: PluginSveldOptions): Promise<void>;
interface SveldOptions extends PluginSveldOptions {
/**
* Specify the input to the uncompiled Svelte source.
* If no value is provided, `sveld` will attempt to infer
* the entry point from the `package.json#svelte` field.
*/
input?: string;
}
export declare function sveld(opts?: SveldOptions): Promise<void>;
export {};

@@ -48,3 +48,3 @@ "use strict";

case 0:
input = (0, get_svelte_entry_1.getSvelteEntry)();
input = (0, get_svelte_entry_1.getSvelteEntry)(opts === null || opts === void 0 ? void 0 : opts.input);
if (input === null)

@@ -51,0 +51,0 @@ return [2 /*return*/];

@@ -77,3 +77,3 @@ "use strict";

_a.sent();
process.stdout.write("created \"" + options.outFile + "\".\n");
process.stdout.write("created \"".concat(options.outFile, "\".\n"));
return [2 /*return*/];

@@ -80,0 +80,0 @@ }

@@ -58,3 +58,3 @@ "use strict";

return MD_TYPE_UNDEFINED;
return "<code>" + type.replace(/\|/g, "&#124;") + "</code>";
return "<code>".concat(type.replace(/\|/g, "&#124;"), "</code>");
}

@@ -66,4 +66,4 @@ function escapeHtml(text) {

if (value === undefined)
return "<code>" + value + "</code>";
return "<code>" + value.replace(/`/g, "\\`").replace(/\|/g, "&#124;") + "</code>";
return "<code>".concat(value, "</code>");
return "<code>".concat(value.replace(/`/g, "\\`").replace(/\|/g, "&#124;"), "</code>");
}

@@ -109,7 +109,7 @@ function formatPropDescription(description) {

var component = components.get(key);
document.append("h2", "`" + component.moduleName + "`");
document.append("h2", "`".concat(component.moduleName, "`"));
if (component.typedefs.length > 0) {
document.append("h3", "Types").append("raw", "```ts\n" + (0, writer_ts_definitions_1.getTypeDefs)({
document.append("h3", "Types").append("raw", "```ts\n".concat((0, writer_ts_definitions_1.getTypeDefs)({
typedefs: component.typedefs
}) + "\n```\n\n");
}), "\n```\n\n"));
}

@@ -127,3 +127,3 @@ document.append("h3", "Props");

.forEach(function (prop) {
document.append("raw", "| " + prop.name + " | " + ("<code>" + prop.kind + "</code>") + " | " + (prop.reactive ? "Yes" : "No") + " | " + formatPropType(prop.type) + " | " + formatPropValue(prop.value) + " | " + formatPropDescription(prop.description) + " |\n");
document.append("raw", "| ".concat(prop.name, " | ").concat("<code>".concat(prop.kind, "</code>"), " | ").concat(prop.reactive ? "Yes" : "No", " | ").concat(formatPropType(prop.type), " | ").concat(formatPropValue(prop.value), " | ").concat(formatPropDescription(prop.description), " |\n"));
});

@@ -138,3 +138,3 @@ }

component.slots.forEach(function (slot) {
document.append("raw", "| " + (slot["default"] ? MD_TYPE_UNDEFINED : slot.name) + " | " + (slot["default"] ? "Yes" : "No") + " | " + formatSlotProps(slot.slot_props) + " | " + formatSlotFallback(slot.fallback) + " |\n");
document.append("raw", "| ".concat(slot["default"] ? MD_TYPE_UNDEFINED : slot.name, " | ").concat(slot["default"] ? "Yes" : "No", " | ").concat(formatSlotProps(slot.slot_props), " | ").concat(formatSlotFallback(slot.fallback), " |\n"));
});

@@ -149,3 +149,3 @@ }

component.events.forEach(function (event) {
document.append("raw", "| " + event.name + " | " + event.type + " | " + (event.type === "dispatched" ? formatEventDetail(event.detail) : MD_TYPE_UNDEFINED) + " |\n");
document.append("raw", "| ".concat(event.name, " | ").concat(event.type, " | ").concat(event.type === "dispatched" ? formatEventDetail(event.detail) : MD_TYPE_UNDEFINED, " |\n"));
});

@@ -160,3 +160,3 @@ }

_a.sent();
process.stdout.write("created \"" + options.outFile + "\".\n");
process.stdout.write("created \"".concat(options.outFile, "\".\n"));
return [2 /*return*/];

@@ -163,0 +163,0 @@ }

@@ -72,3 +72,3 @@ "use strict";

return EMPTY_STR;
return def.typedefs.map(function (typedef) { return "export " + typedef.ts; }).join("\n\n");
return def.typedefs.map(function (typedef) { return "export ".concat(typedef.ts); }).join("\n\n");
}

@@ -78,3 +78,3 @@ exports.getTypeDefs = getTypeDefs;

if (/(\-|\s+|\:)/.test(key)) {
return /(\"|\')/.test(key) ? key : "[\"" + key + "\"]";
return /(\"|\')/.test(key) ? key : "[\"".concat(key, "\"]");
}

@@ -86,3 +86,3 @@ return key;

return undefined;
return "* " + (returnValue || value) + "\n";
return "* ".concat(returnValue || value, "\n");
}

@@ -105,3 +105,3 @@ function genPropDef(def) {

addCommentLine(prop.constant, "@constant"),
"* @default " + defaultValue + "\n",
"* @default ".concat(defaultValue, "\n"),
]

@@ -111,6 +111,6 @@ .filter(Boolean)

var prop_value = prop.constant && !prop.isFunction ? prop.value : prop.type;
return "\n " + (prop_comments.length > 0 ? "/**\n" + prop_comments + "*/" : EMPTY_STR) + "\n " + prop.name + "?: " + prop_value + ";";
return "\n ".concat(prop_comments.length > 0 ? "/**\n".concat(prop_comments, "*/") : EMPTY_STR, "\n ").concat(prop.name, "?: ").concat(prop_value, ";");
})
.join("\n");
var props_name = def.moduleName + "Props";
var props_name = "".concat(def.moduleName, "Props");
var prop_def = EMPTY_STR;

@@ -120,8 +120,8 @@ if (((_a = def.rest_props) === null || _a === void 0 ? void 0 : _a.type) === "Element") {

.split("|")
.map(function (name) { return "svelte.JSX.HTMLAttributes<HTMLElementTagNameMap[\"" + name.trim() + "\"]>"; })
.map(function (name) { return "svelte.JSX.HTMLAttributes<HTMLElementTagNameMap[\"".concat(name.trim(), "\"]>"); })
.join(",");
prop_def = "\n export interface " + props_name + " extends " + (def["extends"] !== undefined ? def["extends"].interface + ", " : "") + extend_tag_map + " {\n " + props + "\n }\n ";
prop_def = "\n export interface ".concat(props_name, " extends ").concat(def["extends"] !== undefined ? "".concat(def["extends"].interface, ", ") : "").concat(extend_tag_map, " {\n ").concat(props, "\n }\n ");
}
else {
prop_def = "\n export interface " + props_name + " " + (def["extends"] !== undefined ? "extends " + def["extends"].interface : "") + " {\n " + props + "\n }\n ";
prop_def = "\n export interface ".concat(props_name, " ").concat(def["extends"] !== undefined ? "extends ".concat(def["extends"].interface) : "", " {\n ").concat(props, "\n }\n ");
}

@@ -138,3 +138,3 @@ return {

var key = rest["default"] ? "default" : clampKey(name);
return clampKey(key) + ": " + formatTsProps(slot_props) + ";";
return "".concat(clampKey(key), ": ").concat(formatTsProps(slot_props), ";");
})

@@ -146,3 +146,3 @@ .join("\n");

.map(function (event) {
return clampKey(event.name) + ": " + (event.type === "dispatched" ? "CustomEvent<" + (event.detail || ANY_TYPE) + ">" : "WindowEventMap[\"" + event.name + "\"]") + ";";
return "".concat(clampKey(event.name), ": ").concat(event.type === "dispatched" ? "CustomEvent<".concat(event.detail || ANY_TYPE, ">") : "WindowEventMap[\"".concat(event.name, "\"]"), ";");
})

@@ -157,3 +157,3 @@ .join("\n");

var prop_comments = [addCommentLine((_a = prop.description) === null || _a === void 0 ? void 0 : _a.replace(/\n/g, "\n* "))].filter(Boolean).join("");
return "\n " + (prop_comments.length > 0 ? "/**\n" + prop_comments + "*/" : EMPTY_STR) + "\n " + prop.name + ": " + prop.type + ";";
return "\n ".concat(prop_comments.length > 0 ? "/**\n".concat(prop_comments, "*/") : EMPTY_STR, "\n ").concat(prop.name, ": ").concat(prop.type, ";");
})

@@ -165,3 +165,3 @@ .join("\n");

return "";
return "import { " + def["extends"].interface + " } from " + def["extends"]["import"] + ";";
return "import { ".concat(def["extends"].interface, " } from ").concat(def["extends"]["import"], ";");
}

@@ -172,7 +172,7 @@ function genComponentComment(def) {

if (!/\n/.test(def.componentComment))
return "/** " + def.componentComment.trim() + " */";
return "/*" + def.componentComment
return "/** ".concat(def.componentComment.trim(), " */");
return "/*".concat(def.componentComment
.split("\n")
.map(function (line) { return "* " + line; })
.join("\n") + "\n*/";
.map(function (line) { return "* ".concat(line); })
.join("\n"), "\n*/");
}

@@ -187,3 +187,3 @@ function writeTsDefinition(component) {

}), props_name = _a.props_name, prop_def = _a.prop_def;
return "\n /// <reference types=\"svelte\" />\n import { SvelteComponentTyped } from \"svelte\";\n " + genImports({ "extends": _extends }) + "\n " + getTypeDefs({ typedefs: typedefs }) + "\n " + prop_def + "\n " + genComponentComment({ componentComment: componentComment }) + "\n export default class " + (moduleName === "default" ? "" : moduleName) + " extends SvelteComponentTyped<\n " + props_name + ",\n {" + genEventDef({ events: events }) + "},\n {" + genSlotDef({ slots: slots }) + "}\n > {\n " + genAccessors({ props: props }) + "\n }";
return "\n /// <reference types=\"svelte\" />\n import { SvelteComponentTyped } from \"svelte\";\n ".concat(genImports({ "extends": _extends }), "\n ").concat(getTypeDefs({ typedefs: typedefs }), "\n ").concat(prop_def, "\n ").concat(genComponentComment({ componentComment: componentComment }), "\n export default class ").concat(moduleName === "default" ? "" : moduleName, " extends SvelteComponentTyped<\n ").concat(props_name, ",\n {").concat(genEventDef({ events: events }), "},\n {").concat(genSlotDef({ slots: slots }), "}\n > {\n ").concat(genAccessors({ props: props }), "\n }");
}

@@ -190,0 +190,0 @@ exports.writeTsDefinition = writeTsDefinition;

@@ -43,5 +43,5 @@ "use strict";

var length_1 = Number(type.slice(-1));
this.source += Array.from({ length: length_1 })
this.source += "".concat(Array.from({ length: length_1 })
.map(function (_) { return "#"; })
.join("") + " " + raw;
.join(""), " ").concat(raw);
if (this.hasToC && type === "h2") {

@@ -55,3 +55,3 @@ this.toc.push({

case "quote":
this.source += "> " + raw;
this.source += "> ".concat(raw);
break;

@@ -83,3 +83,3 @@ case "p":

var array = _a.array, raw = _a.raw;
return array.join(" ") + " - [" + raw + "](#" + raw.toLowerCase().replace(/\`/g, "").replace(/\s+/g, "-") + ")";
return "".concat(array.join(" "), " - [").concat(raw, "](#").concat(raw.toLowerCase().replace(/\`/g, "").replace(/\s+/g, "-"), ")");
})

@@ -86,0 +86,0 @@ .join("\n"));

{
"name": "sveld",
"version": "0.12.1",
"version": "0.13.0",
"license": "Apache-2.0",

@@ -26,8 +26,8 @@ "description": "Generate TypeScript definitions for your Svelte components.",

"fs-extra": "^9.0.1",
"prettier": "^2.3.2",
"rollup": "^2.56.3",
"prettier": "^2.5.1",
"rollup": "^2.66.0",
"rollup-plugin-svelte": "^7.1.0",
"svelte": "^3.42.4",
"svelte-preprocess": "^4.8.0",
"typescript": "^4.4.2"
"svelte": "^3.46.2",
"svelte-preprocess": "^4.10.2",
"typescript": "^4.5.5"
},

@@ -34,0 +34,0 @@ "devDependencies": {

@@ -152,3 +152,3 @@ # sveld

### Set-up with Rollup
### Rollup

@@ -198,5 +198,32 @@ Import and add `sveld` as a plugin to your `rollup.config.js`.

### Node.js
You can also use `sveld` programmatically in Node.js.
If no `input` is specified, `sveld` will infer the entry point based on the `package.json#svelte` field.
```js
const { sveld } = require("sveld");
const pkg = require("./package.json");
sveld({
input: "./src/index.js",
glob: true,
markdown: true,
markdownOptions: {
onAppend: (type, document, components) => {
if (type === "h1")
document.append("quote", `${components.size} components exported from ${pkg.name}@${pkg.version}.`);
},
},
json: true,
jsonOptions: {
outFile: "docs/src/COMPONENT_API.json",
},
});
```
### Publishing to NPM
Specify the entry point for the TypeScript definitions in your `package.json`.
TypeScript definitions are outputted to the `types` folder by default. Don't forget to include the folder in your `package.json` when publishing the package to NPM.

@@ -203,0 +230,0 @@ ```diff

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