sveld 0.13.4 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -10,6 +10,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  - add isAccessor field to API
11
11
  - update Markdown writer to generate a separate table for accessors -->
12
12
 
13
+ ## [0.15.0](https://github.com/carbon-design-system/sveld/releases/tag/v0.15.0) - 2022-04-14
14
+
15
+ - add `jsonOptions.outDir` option to emit JSON files for individual components
16
+ - add `sveltekit:reload` attributes to props that extend `a` attributes
17
+
18
+ ## [0.14.1](https://github.com/carbon-design-system/sveld/releases/tag/v0.14.1) - 2022-04-09
19
+
20
+ - svg `$$restProps` should extend the correct attributes
21
+
22
+ ## [0.14.0](https://github.com/carbon-design-system/sveld/releases/tag/v0.14.0) - 2022-04-09
23
+
24
+ - add `sveltekit:prefetch`, `sveltekit:noscroll` attributes to props that extend `a` attributes
25
+ - use type-only imports for `SvelteComponentTyped` and extended props
26
+
13
27
  ## [0.13.4](https://github.com/carbon-design-system/sveld/releases/tag/v0.13.4) - 2022-02-26
14
28
 
15
29
  - use file name as module name if library only has a single default export
package/LICENSE CHANGED
@@ -186,7 +186,7 @@
186
186
  same "printed page" as the copyright notice for easier
187
187
  identification within third-party archives.
188
188
 
189
- Copyright [yyyy] [name of copyright owner]
189
+ Copyright 2020 IBM
190
190
 
191
191
  Licensed under the Apache License, Version 2.0 (the "License");
192
192
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -173,11 +173,11 @@ export default {
173
173
  };
174
174
  ```
175
175
 
176
- When building the library with Rollup, TypeScript definitions will be written to the `types` folder by default.
176
+ When building the library, TypeScript definitions are emitted to the `types` folder by default.
177
177
 
178
- Use the `typesOptions.outDir` option to customize the output folder.
178
+ Customize the output folder using the `typesOptions.outDir` option.
179
179
 
180
- For example, specify the following for the output to be emitted to the `dist` folder:
180
+ The following example emits the output to the `dist` folder:
181
181
 
182
182
  ```diff
183
183
  sveld({
@@ -190,6 +190,7 @@ sveld({
190
190
  The [integration](integration) folder contains example set-ups:
191
191
 
192
192
  - [single-export](integration/single-export): library that exports one component
193
+ - [single-export-default-only](integration/single-export-default-only): library that exports one component using the concise `export { default } ...` syntax
193
194
  - [multi-export](integration/multi-export): multi-component library without JSDoc annotations (types are inferred)
194
195
  - [multi-export-typed](integration/multi-export-typed): multi-component library with JSDoc annotations
195
196
  - [multi-export-typed-ts-only](integration/multi-export-typed-ts-only): multi-component library that only generates TS definitions
@@ -237,6 +238,23 @@ sveld({
237
238
  });
238
239
  ```
239
240
 
241
+ #### `jsonOptions.outDir`
242
+
243
+ If `json` is `true`, a `COMPONENT_API.json` file will be generated at the root of your project. This file contains documentation for all components.
244
+
245
+ Use the `jsonOptions.outDir` option to specify the folder for individual JSON files to be emitted.
246
+
247
+ ```js
248
+ sveld({
249
+ json: true,
250
+ jsonOptions: {
251
+ // an individual JSON file will be generated for each component API
252
+ // e.g. "docs/Button.api.json"
253
+ outDir: "docs",
254
+ },
255
+ });
256
+ ```
257
+
240
258
  ### Publishing to NPM
241
259
 
242
260
  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.
package/cli.js CHANGED
@@ -4,6 +4,6 @@
4
4
  try {
5
5
  require("./lib").cli(process);
6
6
  } catch (error) {
7
- process.stderr.write(error + "\n");
7
+ console.error(error);
8
8
  }
9
9
  })();
@@ -1,4 +1,3 @@
1
- import * as commentParser from "comment-parser";
2
1
  interface ComponentParserDiagnostics {
3
2
  moduleName: string;
4
3
  filePath: string;
@@ -34,7 +33,9 @@ interface DispatchedEvent {
34
33
  detail?: any;
35
34
  }
36
35
  declare type ComponentEvent = ForwardedEvent | DispatchedEvent;
37
- interface TypeDef extends Pick<commentParser.Tag, "type" | "name"> {
36
+ interface TypeDef {
37
+ type: string;
38
+ name: string;
38
39
  description?: string;
39
40
  ts: string;
40
41
  }
@@ -10,6 +10,29 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
13
36
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
37
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
38
  if (ar || !(i in from)) {
@@ -21,7 +44,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
21
44
  };
22
45
  exports.__esModule = true;
23
46
  var compiler_1 = require("svelte/compiler");
24
- var commentParser = require("comment-parser");
47
+ var commentParser = __importStar(require("comment-parser"));
25
48
  var element_tag_map_1 = require("./element-tag-map");
26
49
  var DEFAULT_SLOT_NAME = "__default__";
27
50
  var ComponentParser = /** @class */ (function () {
@@ -132,7 +155,7 @@ var ComponentParser = /** @class */ (function () {
132
155
  };
133
156
  ComponentParser.prototype.parseCustomTypes = function () {
134
157
  var _this = this;
135
- commentParser(this.source).forEach(function (_a) {
158
+ commentParser.parse(this.source, { spacing: "preserve" }).forEach(function (_a) {
136
159
  var tags = _a.tags;
137
160
  tags.forEach(function (_a) {
138
161
  var tag = _a.tag, tagType = _a.type, name = _a.name, description = _a.description;
@@ -185,9 +208,9 @@ var ComponentParser = /** @class */ (function () {
185
208
  };
186
209
  ComponentParser.prototype.parseSvelteComponent = function (source, diagnostics) {
187
210
  var _this = this;
188
- var _a, _b;
211
+ var _a, _b, _c;
189
212
  if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.verbose) {
190
- process.stdout.write("[parsing] \"".concat(diagnostics.moduleName, "\" ").concat(diagnostics.filePath, "\n"));
213
+ console.log("[parsing] \"".concat(diagnostics.moduleName, "\" ").concat(diagnostics.filePath));
191
214
  }
192
215
  this.cleanup();
193
216
  this.source = source;
@@ -195,80 +218,84 @@ var ComponentParser = /** @class */ (function () {
195
218
  this.parsed = (0, compiler_1.parse)(source);
196
219
  this.collectReactiveVars();
197
220
  this.parseCustomTypes();
198
- (0, compiler_1.walk)((_b = this.parsed) === null || _b === void 0 ? void 0 : _b.module, {
199
- enter: function (node) {
200
- var _a, _b, _c, _d, _e, _f, _g;
201
- if (node.type === "ExportNamedDeclaration") {
202
- var _h = ((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) ? node.declaration.declarations[0] : node.declaration, declaration_type = _h.type, id = _h.id, init = _h.init, body = _h.body;
203
- var prop_name = id.name;
204
- var value = undefined;
205
- var type = undefined;
206
- var kind = node.declaration.kind;
207
- var description = undefined;
208
- var isFunction = false;
209
- var isFunctionDeclaration = false;
210
- if (init != null) {
211
- if (init.type === "ObjectExpression" ||
212
- init.type === "BinaryExpression" ||
213
- init.type === "ArrayExpression" ||
214
- init.type === "ArrowFunctionExpression") {
215
- value = (_b = _this.sourceAtPos(init.start, init.end)) === null || _b === void 0 ? void 0 : _b.replace(/\n/g, " ");
216
- type = value;
217
- isFunction = init.type === "ArrowFunctionExpression";
218
- if (init.type === "BinaryExpression") {
219
- if ((init === null || init === void 0 ? void 0 : init.left.type) === "Literal" && typeof (init === null || init === void 0 ? void 0 : init.left.value) === "string") {
220
- type = "string";
221
+ if ((_b = this.parsed) === null || _b === void 0 ? void 0 : _b.module) {
222
+ (0, compiler_1.walk)((_c = this.parsed) === null || _c === void 0 ? void 0 : _c.module, {
223
+ enter: function (node) {
224
+ var _a, _b, _c, _d, _e, _f, _g, _h;
225
+ if (node.type === "ExportNamedDeclaration") {
226
+ var _j = ((_a = node.declaration) === null || _a === void 0 ? void 0 : _a.declarations) ? node.declaration.declarations[0] : node.declaration, declaration_type = _j.type, id = _j.id, init = _j.init, body = _j.body;
227
+ var prop_name = id.name;
228
+ var value = undefined;
229
+ var type = undefined;
230
+ var kind = node.declaration.kind;
231
+ var description = undefined;
232
+ var isFunction = false;
233
+ var isFunctionDeclaration = false;
234
+ if (init != null) {
235
+ if (init.type === "ObjectExpression" ||
236
+ init.type === "BinaryExpression" ||
237
+ init.type === "ArrayExpression" ||
238
+ init.type === "ArrowFunctionExpression") {
239
+ value = (_b = _this.sourceAtPos(init.start, init.end)) === null || _b === void 0 ? void 0 : _b.replace(/\n/g, " ");
240
+ type = value;
241
+ isFunction = init.type === "ArrowFunctionExpression";
242
+ if (init.type === "BinaryExpression") {
243
+ if ((init === null || init === void 0 ? void 0 : init.left.type) === "Literal" && typeof (init === null || init === void 0 ? void 0 : init.left.value) === "string") {
244
+ type = "string";
245
+ }
221
246
  }
222
247
  }
223
- }
224
- else {
225
- if (init.type === "UnaryExpression") {
226
- value = _this.sourceAtPos(init.start, init.end);
227
- type = typeof ((_c = init.argument) === null || _c === void 0 ? void 0 : _c.value);
228
- }
229
248
  else {
230
- value = init.raw;
231
- type = init.value == null ? undefined : typeof init.value;
249
+ if (init.type === "UnaryExpression") {
250
+ value = _this.sourceAtPos(init.start, init.end);
251
+ type = typeof ((_c = init.argument) === null || _c === void 0 ? void 0 : _c.value);
252
+ }
253
+ else {
254
+ value = init.raw;
255
+ type = init.value == null ? undefined : typeof init.value;
256
+ }
232
257
  }
233
258
  }
259
+ if (declaration_type === "FunctionDeclaration") {
260
+ value = "() => " + ((_d = _this.sourceAtPos(body.start, body.end)) === null || _d === void 0 ? void 0 : _d.replace(/\n/g, " "));
261
+ type = "() => any";
262
+ kind = "function";
263
+ isFunction = true;
264
+ isFunctionDeclaration = true;
265
+ }
266
+ if (node.leadingComments) {
267
+ var last_comment = node.leadingComments[node.leadingComments.length - 1];
268
+ var comment = commentParser.parse(ComponentParser.formatComment(last_comment.value), {
269
+ spacing: "preserve"
270
+ });
271
+ var tag = (_e = comment[0]) === null || _e === void 0 ? void 0 : _e.tags[((_f = comment[0]) === null || _f === void 0 ? void 0 : _f.tags.length) - 1];
272
+ if ((tag === null || tag === void 0 ? void 0 : tag.tag) === "type")
273
+ type = _this.aliasType(tag.type);
274
+ description = ComponentParser.assignValue((_h = (_g = comment[0]) === null || _g === void 0 ? void 0 : _g.description) === null || _h === void 0 ? void 0 : _h.trim());
275
+ }
276
+ if (!description && _this.typedefs.has(type)) {
277
+ description = _this.typedefs.get(type).description;
278
+ }
279
+ _this.addModuleExport(prop_name, {
280
+ name: prop_name,
281
+ kind: kind,
282
+ description: description,
283
+ type: type,
284
+ value: value,
285
+ isFunction: isFunction,
286
+ isFunctionDeclaration: isFunctionDeclaration,
287
+ constant: kind === "const",
288
+ reactive: false
289
+ });
234
290
  }
235
- if (declaration_type === "FunctionDeclaration") {
236
- value = "() => " + ((_d = _this.sourceAtPos(body.start, body.end)) === null || _d === void 0 ? void 0 : _d.replace(/\n/g, " "));
237
- type = "() => any";
238
- kind = "function";
239
- isFunction = true;
240
- isFunctionDeclaration = true;
241
- }
242
- if (node.leadingComments) {
243
- var last_comment = node.leadingComments[node.leadingComments.length - 1];
244
- var comment = commentParser(ComponentParser.formatComment(last_comment.value));
245
- var tag = (_e = comment[0]) === null || _e === void 0 ? void 0 : _e.tags[((_f = comment[0]) === null || _f === void 0 ? void 0 : _f.tags.length) - 1];
246
- if ((tag === null || tag === void 0 ? void 0 : tag.tag) === "type")
247
- type = _this.aliasType(tag.type);
248
- description = ComponentParser.assignValue((_g = comment[0]) === null || _g === void 0 ? void 0 : _g.description);
249
- }
250
- if (!description && _this.typedefs.has(type)) {
251
- description = _this.typedefs.get(type).description;
252
- }
253
- _this.addModuleExport(prop_name, {
254
- name: prop_name,
255
- kind: kind,
256
- description: description,
257
- type: type,
258
- value: value,
259
- isFunction: isFunction,
260
- isFunctionDeclaration: isFunctionDeclaration,
261
- constant: kind === "const",
262
- reactive: false
263
- });
264
291
  }
265
- }
266
- });
292
+ });
293
+ }
267
294
  var dispatcher_name = undefined;
268
295
  var callees = [];
269
296
  (0, compiler_1.walk)({ html: this.parsed.html, instance: this.parsed.instance }, {
270
297
  enter: function (node, parent, prop) {
271
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
298
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
272
299
  if (node.type === "CallExpression") {
273
300
  if (node.callee.name === "createEventDispatcher") {
274
301
  dispatcher_name = parent === null || parent === void 0 ? void 0 : parent.id.name;
@@ -306,7 +333,7 @@ var ComponentParser = /** @class */ (function () {
306
333
  node.declaration = declaration_1;
307
334
  prop_name = exportedName;
308
335
  }
309
- var _m = node.declaration.declarations ? node.declaration.declarations[0] : node.declaration, declaration_type = _m.type, id = _m.id, init = _m.init, body = _m.body;
336
+ var _o = node.declaration.declarations ? node.declaration.declarations[0] : node.declaration, declaration_type = _o.type, id = _o.id, init = _o.init, body = _o.body;
310
337
  prop_name !== null && prop_name !== void 0 ? prop_name : (prop_name = id.name);
311
338
  var value = undefined;
312
339
  var type = undefined;
@@ -348,11 +375,13 @@ var ComponentParser = /** @class */ (function () {
348
375
  }
349
376
  if (node.leadingComments) {
350
377
  var last_comment = node.leadingComments[node.leadingComments.length - 1];
351
- var comment = commentParser(ComponentParser.formatComment(last_comment.value));
378
+ var comment = commentParser.parse(ComponentParser.formatComment(last_comment.value), {
379
+ spacing: "preserve"
380
+ });
352
381
  var tag = (_e = comment[0]) === null || _e === void 0 ? void 0 : _e.tags[((_f = comment[0]) === null || _f === void 0 ? void 0 : _f.tags.length) - 1];
353
382
  if ((tag === null || tag === void 0 ? void 0 : tag.tag) === "type")
354
383
  type = _this.aliasType(tag.type);
355
- description = ComponentParser.assignValue((_g = comment[0]) === null || _g === void 0 ? void 0 : _g.description);
384
+ description = ComponentParser.assignValue((_h = (_g = comment[0]) === null || _g === void 0 ? void 0 : _g.description) === null || _h === void 0 ? void 0 : _h.trim());
356
385
  }
357
386
  if (!description && _this.typedefs.has(type)) {
358
387
  description = _this.typedefs.get(type).description;
@@ -370,13 +399,13 @@ var ComponentParser = /** @class */ (function () {
370
399
  });
371
400
  }
372
401
  if (node.type === "Comment") {
373
- var data = (_j = (_h = node === null || node === void 0 ? void 0 : node.data) === null || _h === void 0 ? void 0 : _h.trim()) !== null && _j !== void 0 ? _j : "";
402
+ var data = (_k = (_j = node === null || node === void 0 ? void 0 : node.data) === null || _j === void 0 ? void 0 : _j.trim()) !== null && _k !== void 0 ? _k : "";
374
403
  if (/^@component/.test(data)) {
375
404
  _this.componentComment = data.replace(/^@component/, "");
376
405
  }
377
406
  }
378
407
  if (node.type === "Slot") {
379
- var slot_name = (_k = node.attributes.find(function (attr) { return attr.name === "name"; })) === null || _k === void 0 ? void 0 : _k.value[0].data;
408
+ var slot_name = (_l = node.attributes.find(function (attr) { return attr.name === "name"; })) === null || _l === void 0 ? void 0 : _l.value[0].data;
380
409
  var slot_props = node.attributes
381
410
  .filter(function (attr) { return attr.name !== "name"; })
382
411
  .reduce(function (slot_props, _a) {
@@ -413,7 +442,7 @@ var ComponentParser = /** @class */ (function () {
413
442
  }
414
443
  return __assign(__assign({}, slot_props), (_b = {}, _b[name] = slot_prop_value, _b));
415
444
  }, {});
416
- var fallback = (_l = node.children) === null || _l === void 0 ? void 0 : _l.map(function (_a) {
445
+ var fallback = (_m = node.children) === null || _m === void 0 ? void 0 : _m.map(function (_a) {
417
446
  var start = _a.start, end = _a.end;
418
447
  return _this.sourceAtPos(start, end);
419
448
  }).join("").trim();
package/lib/cli.js CHANGED
@@ -10,6 +10,29 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
13
36
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
37
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
38
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,11 +69,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
69
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
70
  }
48
71
  };
72
+ var __importDefault = (this && this.__importDefault) || function (mod) {
73
+ return (mod && mod.__esModule) ? mod : { "default": mod };
74
+ };
49
75
  exports.__esModule = true;
50
76
  exports.cli = void 0;
51
- var Rollup = require("rollup");
52
- var svelte = require("rollup-plugin-svelte");
53
- var plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
77
+ var Rollup = __importStar(require("rollup"));
78
+ var svelte = __importStar(require("rollup-plugin-svelte"));
79
+ var plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
54
80
  var rollup_plugin_1 = require("./rollup-plugin");
55
81
  var get_svelte_entry_1 = require("./get-svelte-entry");
56
82
  function cli(process) {
@@ -1,8 +1,31 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  exports.__esModule = true;
3
26
  exports.getSvelteEntry = void 0;
4
- var fs = require("fs");
5
- var path = require("path");
27
+ var fs = __importStar(require("fs"));
28
+ var path = __importStar(require("path"));
6
29
  /**
7
30
  * Get the file path entry point for uncompiled Svelte source code
8
31
  * Expects a "svelte" field in the consumer's `package.json`
@@ -14,7 +37,7 @@ function getSvelteEntry(entryPoint) {
14
37
  return entryPoint;
15
38
  }
16
39
  else {
17
- process.stdout.write("Invalid entry point: ".concat(entry_path, ".\n"));
40
+ console.log("Invalid entry point: ".concat(entry_path, "."));
18
41
  return null;
19
42
  }
20
43
  }
@@ -23,12 +46,12 @@ function getSvelteEntry(entryPoint) {
23
46
  var pkg = JSON.parse(fs.readFileSync(pkg_path, "utf-8"));
24
47
  if (pkg.svelte !== undefined)
25
48
  return pkg.svelte;
26
- process.stdout.write("Could not determine an entry point.\n");
27
- process.stdout.write('Specify an entry point to your Svelte code in the "svelte" field of your package.json.\n');
49
+ console.log("Could not determine an entry point.\n");
50
+ console.log('Specify an entry point to your Svelte code in the "svelte" field of your package.json.\n');
28
51
  return null;
29
52
  }
30
53
  else {
31
- process.stdout.write("Could not locate a package.json file.\n");
54
+ console.log("Could not locate a package.json file.\n");
32
55
  return null;
33
56
  }
34
57
  }
package/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  exports.__esModule = true;
3
26
  exports.parseExports = void 0;
4
- var acorn = require("acorn");
27
+ var acorn = __importStar(require("acorn"));
5
28
  function parseExports(source) {
6
29
  var ast = acorn.parse(source, {
7
30
  ecmaVersion: "latest",
@@ -10,6 +10,29 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
13
36
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
37
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
38
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,15 +69,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
69
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
70
  }
48
71
  };
72
+ var __importDefault = (this && this.__importDefault) || function (mod) {
73
+ return (mod && mod.__esModule) ? mod : { "default": mod };
74
+ };
49
75
  exports.__esModule = true;
50
76
  exports.writeOutput = exports.generateBundle = void 0;
51
- var fs = require("fs-extra");
52
- var path = require("path");
53
- var fg = require("fast-glob");
54
- var writer_ts_definitions_1 = require("./writer/writer-ts-definitions");
55
- var writer_json_1 = require("./writer/writer-json");
56
- var writer_markdown_1 = require("./writer/writer-markdown");
57
- var ComponentParser_1 = require("./ComponentParser");
77
+ var fs = __importStar(require("fs"));
78
+ var fsp = __importStar(require("fs/promises"));
79
+ var path = __importStar(require("path"));
80
+ var fg = __importStar(require("fast-glob"));
81
+ var writer_ts_definitions_1 = __importDefault(require("./writer/writer-ts-definitions"));
82
+ var writer_json_1 = __importDefault(require("./writer/writer-json"));
83
+ var writer_markdown_1 = __importDefault(require("./writer/writer-markdown"));
84
+ var ComponentParser_1 = __importDefault(require("./ComponentParser"));
58
85
  var get_svelte_entry_1 = require("./get-svelte-entry");
59
86
  var parse_exports_1 = require("./parse-exports");
60
87
  var compiler_1 = require("svelte/compiler");
@@ -123,7 +150,7 @@ function generateBundle(input, glob) {
123
150
  moduleName = name_1;
124
151
  }
125
152
  if (!(ext === ".svelte")) return [3 /*break*/, 4];
126
- return [4 /*yield*/, fs.readFile(path.resolve(dir, filePath), "utf-8")];
153
+ return [4 /*yield*/, fsp.readFile(path.resolve(dir, filePath), "utf-8")];
127
154
  case 2:
128
155
  source = _c.sent();
129
156
  return [4 /*yield*/, (0, compiler_1.preprocess)(source, [(0, svelte_preprocess_1.typescript)(), (0, svelte_preprocess_1.replace)([[/<style.+<\/style>/gims, ""]])], {
@@ -157,7 +184,7 @@ function writeOutput(result, opts, input) {
157
184
  (0, writer_json_1["default"])(result.components, __assign(__assign({ outFile: "COMPONENT_API.json" }, opts === null || opts === void 0 ? void 0 : opts.jsonOptions), { input: input, inputDir: inputDir }));
158
185
  }
159
186
  if (opts === null || opts === void 0 ? void 0 : opts.markdown) {
160
- (0, writer_markdown_1["default"])(result.components, __assign({ outFile: "COMPONENT_INDEX.md" }, opts === null || opts === void 0 ? void 0 : opts.markdownOptions));
187
+ (0, writer_markdown_1["default"])(result.components, __assign({ outFile: path.join(process.cwd(), "COMPONENT_INDEX.md") }, opts === null || opts === void 0 ? void 0 : opts.markdownOptions));
161
188
  }
162
189
  }
163
190
  exports.writeOutput = writeOutput;
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -36,8 +59,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
59
  }
37
60
  };
38
61
  exports.__esModule = true;
39
- var fs = require("fs-extra");
40
- var prettier = require("prettier");
62
+ var path = __importStar(require("path"));
63
+ var fsp = __importStar(require("fs/promises"));
64
+ var prettier = __importStar(require("prettier"));
41
65
  var Writer = /** @class */ (function () {
42
66
  function Writer(options) {
43
67
  this.options = options;
@@ -47,29 +71,21 @@ var Writer = /** @class */ (function () {
47
71
  return prettier.format(raw, this.options);
48
72
  }
49
73
  catch (error) {
50
- process.stderr.write(error + "\n");
74
+ console.error(error);
51
75
  return raw;
52
76
  }
53
77
  };
54
78
  Writer.prototype.write = function (filePath, raw) {
55
79
  return __awaiter(this, void 0, void 0, function () {
56
- var error_1;
57
80
  return __generator(this, function (_a) {
58
81
  switch (_a.label) {
59
- case 0:
60
- _a.trys.push([0, 3, , 4]);
61
- return [4 /*yield*/, fs.ensureFile(filePath)];
82
+ case 0: return [4 /*yield*/, fsp.mkdir(path.parse(filePath).dir, { recursive: true })];
62
83
  case 1:
63
84
  _a.sent();
64
- return [4 /*yield*/, fs.writeFile(filePath, this.format(raw))];
85
+ return [4 /*yield*/, fsp.writeFile(filePath, this.format(raw))];
65
86
  case 2:
66
87
  _a.sent();
67
- return [3 /*break*/, 4];
68
- case 3:
69
- error_1 = _a.sent();
70
- process.stderr.write(error_1 + "\n");
71
- return [3 /*break*/, 4];
72
- case 4: return [2 /*return*/];
88
+ return [2 /*return*/];
73
89
  }
74
90
  });
75
91
  });
@@ -14,8 +14,11 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
17
20
  exports.__esModule = true;
18
- var Writer_1 = require("./Writer");
21
+ var Writer_1 = __importDefault(require("./Writer"));
19
22
  var WriterMarkdown = /** @class */ (function (_super) {
20
23
  __extends(WriterMarkdown, _super);
21
24
  function WriterMarkdown(options) {
@@ -3,5 +3,6 @@ export interface WriteJsonOptions {
3
3
  input: string;
4
4
  inputDir: string;
5
5
  outFile: string;
6
+ outDir?: string;
6
7
  }
7
8
  export default function writeJson(components: ComponentDocs, options: WriteJsonOptions): Promise<void>;
@@ -46,11 +46,38 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
49
52
  exports.__esModule = true;
50
- var path = require("path");
51
- var path_1 = require("../path");
52
- var Writer_1 = require("./Writer");
53
- function writeJson(components, options) {
53
+ var path_1 = __importDefault(require("path"));
54
+ var path_2 = require("../path");
55
+ var Writer_1 = __importDefault(require("./Writer"));
56
+ function writeJsonComponents(components, options) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var output;
59
+ return __generator(this, function (_a) {
60
+ output = Array.from(components, function (_a) {
61
+ var moduleName = _a[0], component = _a[1];
62
+ return (__assign(__assign({}, component), { filePath: (0, path_2.normalizeSeparators)(path_1["default"].join(options.inputDir, path_1["default"].normalize(component.filePath))) }));
63
+ }).sort(function (a, b) {
64
+ if (a.moduleName < b.moduleName)
65
+ return -1;
66
+ if (a.moduleName > b.moduleName)
67
+ return 1;
68
+ return 0;
69
+ });
70
+ output.map(function (c) {
71
+ var outFile = path_1["default"].resolve(path_1["default"].join(options.outDir || "", "".concat(c.moduleName, ".api.json")));
72
+ var writer = new Writer_1["default"]({ parser: "json", printWidth: 80 });
73
+ console.log("created ".concat(outFile, "\"\n"));
74
+ return writer.write(outFile, JSON.stringify(c));
75
+ });
76
+ return [2 /*return*/];
77
+ });
78
+ });
79
+ }
80
+ function writeJsonLocal(components, options) {
54
81
  return __awaiter(this, void 0, void 0, function () {
55
82
  var output, output_path, writer;
56
83
  return __generator(this, function (_a) {
@@ -60,7 +87,7 @@ function writeJson(components, options) {
60
87
  total: components.size,
61
88
  components: Array.from(components, function (_a) {
62
89
  var moduleName = _a[0], component = _a[1];
63
- return (__assign(__assign({}, component), { filePath: (0, path_1.normalizeSeparators)(path.join(options.inputDir, path.normalize(component.filePath))) }));
90
+ return (__assign(__assign({}, component), { filePath: (0, path_2.normalizeSeparators)(path_1["default"].join(options.inputDir, path_1["default"].normalize(component.filePath))) }));
64
91
  }).sort(function (a, b) {
65
92
  if (a.moduleName < b.moduleName)
66
93
  return -1;
@@ -69,15 +96,34 @@ function writeJson(components, options) {
69
96
  return 0;
70
97
  })
71
98
  };
72
- output_path = path.join(process.cwd(), options.outFile);
99
+ output_path = path_1["default"].join(process.cwd(), options.outFile);
73
100
  writer = new Writer_1["default"]({ parser: "json", printWidth: 80 });
74
101
  return [4 /*yield*/, writer.write(output_path, JSON.stringify(output))];
75
102
  case 1:
76
103
  _a.sent();
77
- process.stdout.write("created \"".concat(options.outFile, "\".\n"));
104
+ console.log("created \"".concat(options.outFile, "\".\n"));
78
105
  return [2 /*return*/];
79
106
  }
80
107
  });
81
108
  });
82
109
  }
110
+ function writeJson(components, options) {
111
+ return __awaiter(this, void 0, void 0, function () {
112
+ return __generator(this, function (_a) {
113
+ switch (_a.label) {
114
+ case 0:
115
+ if (!options.outDir) return [3 /*break*/, 2];
116
+ return [4 /*yield*/, writeJsonComponents(components, options)];
117
+ case 1:
118
+ _a.sent();
119
+ return [3 /*break*/, 4];
120
+ case 2: return [4 /*yield*/, writeJsonLocal(components, options)];
121
+ case 3:
122
+ _a.sent();
123
+ _a.label = 4;
124
+ case 4: return [2 /*return*/];
125
+ }
126
+ });
127
+ });
128
+ }
83
129
  exports["default"] = writeJson;
@@ -1,7 +1,8 @@
1
1
  import { ComponentDocs } from "../rollup-plugin";
2
2
  import WriterMarkdown, { AppendType } from "./WriterMarkdown";
3
3
  export interface WriteMarkdownOptions {
4
+ write?: boolean;
4
5
  outFile: string;
5
6
  onAppend?: (type: AppendType, document: WriterMarkdown, components: ComponentDocs) => void;
6
7
  }
7
- export default function writeMarkdown(components: ComponentDocs, options: WriteMarkdownOptions): Promise<void>;
8
+ export default function writeMarkdown(components: ComponentDocs, options: WriteMarkdownOptions): Promise<string>;
@@ -44,9 +44,11 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
44
44
  }
45
45
  return to.concat(ar || Array.prototype.slice.call(from));
46
46
  };
47
+ var __importDefault = (this && this.__importDefault) || function (mod) {
48
+ return (mod && mod.__esModule) ? mod : { "default": mod };
49
+ };
47
50
  exports.__esModule = true;
48
- var path = require("path");
49
- var WriterMarkdown_1 = require("./WriterMarkdown");
51
+ var WriterMarkdown_1 = __importDefault(require("./WriterMarkdown"));
50
52
  var writer_ts_definitions_1 = require("./writer-ts-definitions");
51
53
  var PROP_TABLE_HEADER = "| Prop name | Kind | Reactive | Type | Default value | Description |\n| :- | :- | :- | :- |\n";
52
54
  var SLOT_TABLE_HEADER = "| Slot name | Default | Props | Fallback |\n| :- | :- | :- | :- |\n";
@@ -87,11 +89,11 @@ function formatEventDetail(detail) {
87
89
  }
88
90
  function writeMarkdown(components, options) {
89
91
  return __awaiter(this, void 0, void 0, function () {
90
- var output_path, document, keys;
92
+ var write, document, keys;
91
93
  return __generator(this, function (_a) {
92
94
  switch (_a.label) {
93
95
  case 0:
94
- output_path = path.join(process.cwd(), options.outFile);
96
+ write = (options === null || options === void 0 ? void 0 : options.write) !== false;
95
97
  document = new WriterMarkdown_1["default"]({
96
98
  onAppend: function (type, document) {
97
99
  var _a;
@@ -148,11 +150,13 @@ function writeMarkdown(components, options) {
148
150
  document.append("p", "None.");
149
151
  }
150
152
  });
151
- return [4 /*yield*/, document.write(output_path, document.end())];
153
+ if (!write) return [3 /*break*/, 2];
154
+ return [4 /*yield*/, document.write(options.outFile, document.end())];
152
155
  case 1:
153
156
  _a.sent();
154
- process.stdout.write("created \"".concat(options.outFile, "\".\n"));
155
- return [2 /*return*/];
157
+ console.log("created \"".concat(options.outFile, "\"."));
158
+ _a.label = 2;
159
+ case 2: return [2 /*return*/, document.end()];
156
160
  }
157
161
  });
158
162
  });
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -53,11 +76,14 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
53
76
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
54
77
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
55
78
  };
79
+ var __importDefault = (this && this.__importDefault) || function (mod) {
80
+ return (mod && mod.__esModule) ? mod : { "default": mod };
81
+ };
56
82
  exports.__esModule = true;
57
83
  exports.writeTsDefinition = exports.getTypeDefs = exports.formatTsProps = void 0;
58
- var path = require("path");
84
+ var path = __importStar(require("path"));
59
85
  var create_exports_1 = require("../create-exports");
60
- var Writer_1 = require("./Writer");
86
+ var Writer_1 = __importDefault(require("./Writer"));
61
87
  var ANY_TYPE = "any";
62
88
  var EMPTY_STR = "";
63
89
  function formatTsProps(props) {
@@ -84,8 +110,8 @@ function addCommentLine(value, returnValue) {
84
110
  return "* ".concat(returnValue || value, "\n");
85
111
  }
86
112
  function genPropDef(def) {
87
- var _a;
88
- var props = def.props
113
+ var _a, _b, _c;
114
+ var initial_props = def.props
89
115
  .filter(function (prop) { return !prop.isFunctionDeclaration && prop.kind !== "const"; })
90
116
  .map(function (prop) {
91
117
  var _a;
@@ -105,14 +131,33 @@ function genPropDef(def) {
105
131
  .join("");
106
132
  var prop_value = prop.constant && !prop.isFunction ? prop.value : prop.type;
107
133
  return "\n ".concat(prop_comments.length > 0 ? "/**\n".concat(prop_comments, "*/") : EMPTY_STR, "\n ").concat(prop.name, "?: ").concat(prop_value, ";");
108
- })
109
- .join("\n");
134
+ });
135
+ if (((_a = def.rest_props) === null || _a === void 0 ? void 0 : _a.type) === "Element") {
136
+ var elements = (_b = def.rest_props) === null || _b === void 0 ? void 0 : _b.name.split("|").map(function (element) { return element.replace(/\s+/g, ""); });
137
+ if (elements.includes("a")) {
138
+ initial_props.push([
139
+ "\n",
140
+ "\n /**\n * SvelteKit attribute to enable data prefetching\n * if a link is hovered over or touched on mobile.\n * @see https://kit.svelte.dev/docs/a-options#sveltekit-prefetch\n * @default false\n */\n \"sveltekit:prefetch\"?: boolean;\n ",
141
+ "\n",
142
+ "\n /**\n * SvelteKit attribute to trigger a full page\n * reload after the link is clicked.\n * @see https://kit.svelte.dev/docs/a-options#sveltekit-reload\n * @default false\n */\n \"sveltekit:reload\"?: boolean;\n ",
143
+ "\n",
144
+ "\n /**\n * SvelteKit attribute to prevent scrolling\n * after the link is clicked.\n * @see https://kit.svelte.dev/docs/a-options#sveltekit-noscroll\n * @default false\n */\n \"sveltekit:noscroll\"?: boolean;\n ",
145
+ ].join("\n"));
146
+ }
147
+ }
148
+ var props = initial_props.join("\n");
110
149
  var props_name = "".concat(def.moduleName, "Props");
111
150
  var prop_def = EMPTY_STR;
112
- if (((_a = def.rest_props) === null || _a === void 0 ? void 0 : _a.type) === "Element") {
151
+ if (((_c = def.rest_props) === null || _c === void 0 ? void 0 : _c.type) === "Element") {
113
152
  var extend_tag_map = def.rest_props.name
114
153
  .split("|")
115
- .map(function (name) { return "svelte.JSX.HTMLAttributes<HTMLElementTagNameMap[\"".concat(name.trim(), "\"]>"); })
154
+ .map(function (name) {
155
+ var element = name.trim();
156
+ if (element === "svg") {
157
+ return "svelte.JSX.SVGAttributes<SVGSVGElement>";
158
+ }
159
+ return "svelte.JSX.HTMLAttributes<HTMLElementTagNameMap[\"".concat(element, "\"]>");
160
+ })
116
161
  .join(",");
117
162
  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 ");
118
163
  }
@@ -159,7 +204,7 @@ function genAccessors(def) {
159
204
  function genImports(def) {
160
205
  if (def["extends"] === undefined)
161
206
  return "";
162
- return "import { ".concat(def["extends"].interface, " } from ").concat(def["extends"]["import"], ";");
207
+ return "import type { ".concat(def["extends"].interface, " } from ").concat(def["extends"]["import"], ";");
163
208
  }
164
209
  function genComponentComment(def) {
165
210
  if (!def.componentComment)
@@ -188,7 +233,7 @@ function writeTsDefinition(component) {
188
233
  rest_props: rest_props,
189
234
  "extends": _extends
190
235
  }), props_name = _a.props_name, prop_def = _a.prop_def;
191
- return "\n /// <reference types=\"svelte\" />\n import { SvelteComponentTyped } from \"svelte\";\n ".concat(genImports({ "extends": _extends }), "\n ").concat(genModuleExports({ moduleExports: moduleExports }), "\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 }");
236
+ return "\n /// <reference types=\"svelte\" />\n import type { SvelteComponentTyped } from \"svelte\";\n ".concat(genImports({ "extends": _extends }), "\n ").concat(genModuleExports({ moduleExports: moduleExports }), "\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 }");
192
237
  }
193
238
  exports.writeTsDefinition = writeTsDefinition;
194
239
  function writeTsDefinitions(components, options) {
@@ -237,7 +282,7 @@ function writeTsDefinitions(components, options) {
237
282
  case 13: return [4 /*yield*/, writer.write(ts_base_path, indexDTs)];
238
283
  case 14:
239
284
  _c.sent();
240
- process.stdout.write("created TypeScript definitions.\n");
285
+ console.log("created TypeScript definitions.");
241
286
  return [2 /*return*/];
242
287
  }
243
288
  });
package/package.json CHANGED
@@ -1,44 +1,43 @@
1
1
  {
2
2
  "name": "sveld",
3
- "version": "0.13.4",
3
+ "version": "0.15.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Generate TypeScript definitions for your Svelte components.",
6
6
  "main": "./lib/index.js",
7
7
  "types": "./lib/index.d.ts",
8
8
  "scripts": {
9
- "build": "tsc",
10
- "build:watch": "tsc -w",
11
- "test": "run-p test:*",
12
- "test:unit": "tsnd node_modules/tape/bin/tape tests/*.test.ts",
13
- "test:integration": "node tests/integration",
14
- "format": "prettier --write \"{src,tests}/**/*.{js,ts,svelte}\"",
15
- "prepack": "run-s build test"
16
- },
17
- "peerDependencies": {
18
- "svelte": "^3.31.0"
9
+ "dev": "vite",
10
+ "build": "vite build",
11
+ "preview": "vite preview",
12
+ "test:unit": "vitest",
13
+ "test:snapshot": "node tests/test-snapshot",
14
+ "test:integration": "node tests/test-integration",
15
+ "format": "prettier --write \"{src,tests}/**/*.{js,ts,svelte,md}\"",
16
+ "prepack": "tsc"
19
17
  },
20
18
  "dependencies": {
21
- "@rollup/plugin-node-resolve": "^11.0.1",
22
- "acorn": "^8.4.1",
23
- "comment-parser": "^0.7.6",
24
- "fast-glob": "^3.2.7",
25
- "fs-extra": "^9.0.1",
26
- "prettier": "^2.5.1",
27
- "rollup": "^2.66.0",
19
+ "@rollup/plugin-node-resolve": "^13.2.0",
20
+ "acorn": "^8.7.0",
21
+ "comment-parser": "^1.3.1",
22
+ "fast-glob": "^3.2.11",
23
+ "prettier": "^2.6.2",
24
+ "rollup": "^2.70.1",
28
25
  "rollup-plugin-svelte": "^7.1.0",
29
- "svelte": "^3.46.2",
30
- "svelte-preprocess": "^4.10.2",
31
- "typescript": "^4.5.5"
26
+ "svelte": "^3.47.0",
27
+ "svelte-preprocess": "^4.10.6",
28
+ "typescript": "^4.6.3"
32
29
  },
33
30
  "devDependencies": {
34
- "@types/fs-extra": "^9.0.12",
35
- "@types/node": "^14.14.20",
36
- "@types/prettier": "^2.3.2",
37
- "@types/tape": "^4.13.2",
38
- "npm-run-all": "^4.1.5",
39
- "prettier-plugin-svelte": "^2.4.0",
40
- "tape": "^5.3.1",
41
- "ts-node-dev": "^1.1.1"
31
+ "@sveltejs/vite-plugin-svelte": "1.0.0-next.41",
32
+ "@types/node": "^17.0.24",
33
+ "@types/prettier": "^2.6.0",
34
+ "carbon-components-svelte": "^0.62.3",
35
+ "carbon-preprocess-svelte": "^0.8.2",
36
+ "codemirror": "^5.65.2",
37
+ "prettier-plugin-svelte": "^2.7.0",
38
+ "svelte-highlight": "^6.0.1",
39
+ "vite": "^2.9.5",
40
+ "vitest": "^0.9.3"
42
41
  },
43
42
  "bin": {
44
43
  "sveld": "./cli.js"