sveld 0.26.2 → 0.28.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/README.md +68 -5
- package/cli.js +1 -7
- package/lib/ComponentParser.d.ts +1 -1
- package/lib/index.js +184 -14
- package/package.json +10 -9
- package/lib/ComponentParser.js +0 -2657
- package/lib/cli.js +0 -48
- package/lib/create-exports.js +0 -170
- package/lib/element-tag-map.js +0 -158
- package/lib/get-svelte-entry.js +0 -39
- package/lib/parse-exports.js +0 -112
- package/lib/path.js +0 -12
- package/lib/plugin.js +0 -269
- package/lib/resolve-alias.js +0 -198
- package/lib/sveld.js +0 -33
- package/lib/writer/MarkdownWriterBase.js +0 -70
- package/lib/writer/Writer.js +0 -104
- package/lib/writer/WriterMarkdown.js +0 -65
- package/lib/writer/markdown-format-utils.js +0 -158
- package/lib/writer/markdown-render-utils.js +0 -89
- package/lib/writer/writer-json.js +0 -119
- package/lib/writer/writer-markdown-core.js +0 -44
- package/lib/writer/writer-markdown.js +0 -46
- package/lib/writer/writer-ts-definitions-core.js +0 -753
- package/lib/writer/writer-ts-definitions.js +0 -64
package/lib/cli.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.cli = cli;
|
|
7
|
-
const plugin_node_resolve_1 = __importDefault(require("@rollup/plugin-node-resolve"));
|
|
8
|
-
const rollup_1 = require("rollup");
|
|
9
|
-
const rollup_plugin_svelte_1 = __importDefault(require("rollup-plugin-svelte"));
|
|
10
|
-
const get_svelte_entry_1 = require("./get-svelte-entry");
|
|
11
|
-
const plugin_1 = require("./plugin");
|
|
12
|
-
/**
|
|
13
|
-
* Command-line interface for sveld.
|
|
14
|
-
*
|
|
15
|
-
* Parses command-line arguments, runs Rollup to process the entry point,
|
|
16
|
-
* generates component documentation, and writes output files.
|
|
17
|
-
*
|
|
18
|
-
* @param process - Node.js process object containing command-line arguments
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```ts
|
|
22
|
-
* // Called from CLI: sveld --types --json --glob
|
|
23
|
-
* // Parses: { types: true, json: true, glob: true }
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
async function cli(process) {
|
|
27
|
-
const options = process.argv
|
|
28
|
-
.slice(2)
|
|
29
|
-
.map((arg) => {
|
|
30
|
-
const [flag, value] = arg.split("=");
|
|
31
|
-
const key = flag.slice(2);
|
|
32
|
-
return { [key]: value === undefined ? true : value };
|
|
33
|
-
})
|
|
34
|
-
.reduce((a, c) => {
|
|
35
|
-
for (const key in c) {
|
|
36
|
-
a[key] = c[key];
|
|
37
|
-
}
|
|
38
|
-
return a;
|
|
39
|
-
}, {});
|
|
40
|
-
const input = (0, get_svelte_entry_1.getSvelteEntry)() || "src/index.js";
|
|
41
|
-
const rollup_bundle = await (0, rollup_1.rollup)({
|
|
42
|
-
input,
|
|
43
|
-
plugins: [(0, rollup_plugin_svelte_1.default)(), (0, plugin_node_resolve_1.default)()],
|
|
44
|
-
});
|
|
45
|
-
await rollup_bundle.generate({});
|
|
46
|
-
const result = await (0, plugin_1.generateBundle)(input, options?.glob === true);
|
|
47
|
-
(0, plugin_1.writeOutput)(result, options, input);
|
|
48
|
-
}
|
package/lib/create-exports.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createExports = createExports;
|
|
4
|
-
exports.removeSvelteExt = removeSvelteExt;
|
|
5
|
-
exports.convertSvelteExt = convertSvelteExt;
|
|
6
|
-
const SVELTE_EXT_REGEX = /\.svelte$/;
|
|
7
|
-
/**
|
|
8
|
-
* Creates export statements from parsed export information.
|
|
9
|
-
*
|
|
10
|
-
* Groups exports by source file and generates optimized export statements.
|
|
11
|
-
* Handles special cases like Svelte component exports, default exports,
|
|
12
|
-
* and mixed exports from module context.
|
|
13
|
-
*
|
|
14
|
-
* @param parsed_exports - Map of export names to their source and metadata
|
|
15
|
-
* @returns A string containing all export statements
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* // Input:
|
|
20
|
-
* { Button: { source: "./Button.svelte", default: true } }
|
|
21
|
-
*
|
|
22
|
-
* // Output:
|
|
23
|
-
* // export { default as Button } from "./Button.svelte";
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
function createExports(parsed_exports) {
|
|
27
|
-
/**
|
|
28
|
-
* Group exports by source file.
|
|
29
|
-
* This allows us to combine multiple exports from the same source
|
|
30
|
-
* into a single export statement for better organization.
|
|
31
|
-
*/
|
|
32
|
-
const groupedBySource = new Map();
|
|
33
|
-
for (const [id, exportee] of Object.entries(parsed_exports)) {
|
|
34
|
-
const existing = groupedBySource.get(exportee.source) || [];
|
|
35
|
-
existing.push({ id, exportee });
|
|
36
|
-
groupedBySource.set(exportee.source, existing);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Generate export statements, keeping grouped exports together.
|
|
40
|
-
* Exports from the same source file are combined into single statements
|
|
41
|
-
* when possible for cleaner output.
|
|
42
|
-
*/
|
|
43
|
-
const exportStatements = [];
|
|
44
|
-
for (const [source, exports] of groupedBySource) {
|
|
45
|
-
const isSvelteFile = SVELTE_EXT_REGEX.test(source);
|
|
46
|
-
/**
|
|
47
|
-
* Check if this source has both default and non-default exports (indicates module context exports).
|
|
48
|
-
* Exclude id="default" from this check, as that's just re-exporting the default as-is.
|
|
49
|
-
* Mixed exports occur when a Svelte file has both `<script context="module">` exports
|
|
50
|
-
* and a default component export.
|
|
51
|
-
*/
|
|
52
|
-
const hasDefaultExport = exports.some(({ id, exportee }) => id !== "default" && exportee.default);
|
|
53
|
-
const hasNonDefaultExport = exports.some(({ exportee }) => !exportee.default);
|
|
54
|
-
const hasMixedExports = isSvelteFile && hasDefaultExport && hasNonDefaultExport;
|
|
55
|
-
/**
|
|
56
|
-
* Separate named exports from default exports.
|
|
57
|
-
* Also track "default as X" exports separately as they can be combined with named exports.
|
|
58
|
-
*/
|
|
59
|
-
const namedExports = [];
|
|
60
|
-
const defaultExports = [];
|
|
61
|
-
/**
|
|
62
|
-
* Track "default as X" exports separately.
|
|
63
|
-
* These can be grouped with named exports from the same source.
|
|
64
|
-
*/
|
|
65
|
-
const defaultAsExports = [];
|
|
66
|
-
for (const { id, exportee } of exports) {
|
|
67
|
-
/**
|
|
68
|
-
* If id is "default", always export as default.
|
|
69
|
-
* This handles explicit default re-exports.
|
|
70
|
-
*/
|
|
71
|
-
if (id === "default") {
|
|
72
|
-
defaultExports.push(`export { default } from "${source}";`);
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* If exportee.default is true, we're re-exporting a default export with a new name.
|
|
77
|
-
* Handle mixed exports specially (both default and named from module context).
|
|
78
|
-
*/
|
|
79
|
-
if (exportee.default) {
|
|
80
|
-
if (exportee.mixed) {
|
|
81
|
-
defaultExports.push(`export { default as ${id} } from "${source}";`);
|
|
82
|
-
defaultExports.push(`export { default } from "${source}";`);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
/**
|
|
86
|
-
* Use "default as X" so they can be grouped with named exports from same source.
|
|
87
|
-
* This allows combining default-as-renamed with named exports in one statement.
|
|
88
|
-
*/
|
|
89
|
-
defaultAsExports.push(`default as ${id}`);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else if (isSvelteFile && !hasMixedExports) {
|
|
93
|
-
/**
|
|
94
|
-
* For Svelte files without mixed exports, treat as component (re-export default).
|
|
95
|
-
* Svelte components are default exports, so we re-export them as named exports.
|
|
96
|
-
*/
|
|
97
|
-
defaultAsExports.push(`default as ${id}`);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
/**
|
|
101
|
-
* It's a named export (including named exports from Svelte module context).
|
|
102
|
-
* These come from `<script context="module">` blocks.
|
|
103
|
-
*/
|
|
104
|
-
namedExports.push(id);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Combine default-as-renamed and named exports from same source (for Svelte module exports).
|
|
109
|
-
* This creates statements like: `export { default as Component, namedExport } from "source"`
|
|
110
|
-
*/
|
|
111
|
-
if (defaultAsExports.length > 0 && namedExports.length > 0) {
|
|
112
|
-
/**
|
|
113
|
-
* Combine into single statement: export { default as X, namedExport } from "source".
|
|
114
|
-
* This is more efficient and cleaner than separate statements.
|
|
115
|
-
*/
|
|
116
|
-
exportStatements.push(`export { ${[...defaultAsExports, ...namedExports].join(", ")} } from "${source}";`);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
/**
|
|
120
|
-
* Generate grouped named exports.
|
|
121
|
-
* Multiple named exports from the same source are combined.
|
|
122
|
-
*/
|
|
123
|
-
if (namedExports.length > 0) {
|
|
124
|
-
exportStatements.push(`export { ${namedExports.join(", ")} } from "${source}";`);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Add default-as exports.
|
|
128
|
-
* These are component re-exports: `export { default as ComponentName } from "source"`.
|
|
129
|
-
*/
|
|
130
|
-
if (defaultAsExports.length > 0) {
|
|
131
|
-
exportStatements.push(`export { ${defaultAsExports.join(", ")} } from "${source}";`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Add default exports (these cannot be grouped).
|
|
136
|
-
* Default exports must be in separate statements as they can't be combined
|
|
137
|
-
* with named exports in the same statement.
|
|
138
|
-
*/
|
|
139
|
-
exportStatements.push(...defaultExports);
|
|
140
|
-
}
|
|
141
|
-
return exportStatements.join("\n");
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Removes the `.svelte` extension from a file path.
|
|
145
|
-
*
|
|
146
|
-
* @param filePath - The file path to process
|
|
147
|
-
* @returns The path without the .svelte extension
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```ts
|
|
151
|
-
* removeSvelteExt("./Button.svelte") // Returns: "./Button"
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
function removeSvelteExt(filePath) {
|
|
155
|
-
return filePath.replace(SVELTE_EXT_REGEX, "");
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Converts a `.svelte` file path to a `.svelte.d.ts` TypeScript definition path.
|
|
159
|
-
*
|
|
160
|
-
* @param filePath - The Svelte file path to convert
|
|
161
|
-
* @returns The path with .svelte.d.ts extension
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```ts
|
|
165
|
-
* convertSvelteExt("./Button.svelte") // Returns: "./Button.svelte.d.ts"
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
function convertSvelteExt(filePath) {
|
|
169
|
-
return filePath.replace(SVELTE_EXT_REGEX, ".svelte.d.ts");
|
|
170
|
-
}
|
package/lib/element-tag-map.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getElementByTag = getElementByTag;
|
|
4
|
-
/**
|
|
5
|
-
* Element tag map adapted from TypeScript's `lib.dom.d.ts`.
|
|
6
|
-
*
|
|
7
|
-
* Maps HTML element tag names to their corresponding TypeScript element types.
|
|
8
|
-
* Used for generating proper TypeScript types for element bindings and rest props.
|
|
9
|
-
* See the TypeScript lib.dom.d.ts for the original source.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* ```ts
|
|
13
|
-
* tag_map["button"] // "HTMLButtonElement"
|
|
14
|
-
* tag_map["div"] // "HTMLDivElement"
|
|
15
|
-
* tag_map["input"] // "HTMLInputElement"
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
const tag_map = {
|
|
19
|
-
a: "HTMLAnchorElement",
|
|
20
|
-
abbr: "HTMLElement",
|
|
21
|
-
address: "HTMLElement",
|
|
22
|
-
applet: "HTMLUnknownElement",
|
|
23
|
-
area: "HTMLAreaElement",
|
|
24
|
-
article: "HTMLElement",
|
|
25
|
-
aside: "HTMLElement",
|
|
26
|
-
audio: "HTMLAudioElement",
|
|
27
|
-
b: "HTMLElement",
|
|
28
|
-
base: "HTMLBaseElement",
|
|
29
|
-
basefont: "HTMLElement",
|
|
30
|
-
bdi: "HTMLElement",
|
|
31
|
-
bdo: "HTMLElement",
|
|
32
|
-
blockquote: "HTMLQuoteElement",
|
|
33
|
-
body: "HTMLBodyElement",
|
|
34
|
-
br: "HTMLBRElement",
|
|
35
|
-
button: "HTMLButtonElement",
|
|
36
|
-
canvas: "HTMLCanvasElement",
|
|
37
|
-
caption: "HTMLTableCaptionElement",
|
|
38
|
-
cite: "HTMLElement",
|
|
39
|
-
code: "HTMLElement",
|
|
40
|
-
col: "HTMLTableColElement",
|
|
41
|
-
colgroup: "HTMLTableColElement",
|
|
42
|
-
data: "HTMLDataElement",
|
|
43
|
-
datalist: "HTMLDataListElement",
|
|
44
|
-
dd: "HTMLElement",
|
|
45
|
-
del: "HTMLModElement",
|
|
46
|
-
details: "HTMLDetailsElement",
|
|
47
|
-
dfn: "HTMLElement",
|
|
48
|
-
dialog: "HTMLDialogElement",
|
|
49
|
-
dir: "HTMLDirectoryElement",
|
|
50
|
-
div: "HTMLDivElement",
|
|
51
|
-
dl: "HTMLDListElement",
|
|
52
|
-
dt: "HTMLElement",
|
|
53
|
-
em: "HTMLElement",
|
|
54
|
-
embed: "HTMLEmbedElement",
|
|
55
|
-
fieldset: "HTMLFieldSetElement",
|
|
56
|
-
figcaption: "HTMLElement",
|
|
57
|
-
figure: "HTMLElement",
|
|
58
|
-
font: "HTMLFontElement",
|
|
59
|
-
footer: "HTMLElement",
|
|
60
|
-
form: "HTMLFormElement",
|
|
61
|
-
frame: "HTMLFrameElement",
|
|
62
|
-
frameset: "HTMLFrameSetElement",
|
|
63
|
-
h1: "HTMLHeadingElement",
|
|
64
|
-
h2: "HTMLHeadingElement",
|
|
65
|
-
h3: "HTMLHeadingElement",
|
|
66
|
-
h4: "HTMLHeadingElement",
|
|
67
|
-
h5: "HTMLHeadingElement",
|
|
68
|
-
h6: "HTMLHeadingElement",
|
|
69
|
-
head: "HTMLHeadElement",
|
|
70
|
-
header: "HTMLElement",
|
|
71
|
-
hgroup: "HTMLElement",
|
|
72
|
-
hr: "HTMLHRElement",
|
|
73
|
-
html: "HTMLHtmlElement",
|
|
74
|
-
i: "HTMLElement",
|
|
75
|
-
iframe: "HTMLIFrameElement",
|
|
76
|
-
img: "HTMLImageElement",
|
|
77
|
-
input: "HTMLInputElement",
|
|
78
|
-
ins: "HTMLModElement",
|
|
79
|
-
kbd: "HTMLElement",
|
|
80
|
-
label: "HTMLLabelElement",
|
|
81
|
-
legend: "HTMLLegendElement",
|
|
82
|
-
li: "HTMLLIElement",
|
|
83
|
-
link: "HTMLLinkElement",
|
|
84
|
-
main: "HTMLElement",
|
|
85
|
-
map: "HTMLMapElement",
|
|
86
|
-
mark: "HTMLElement",
|
|
87
|
-
marquee: "HTMLMarqueeElement",
|
|
88
|
-
menu: "HTMLMenuElement",
|
|
89
|
-
meta: "HTMLMetaElement",
|
|
90
|
-
meter: "HTMLMeterElement",
|
|
91
|
-
nav: "HTMLElement",
|
|
92
|
-
noscript: "HTMLElement",
|
|
93
|
-
object: "HTMLObjectElement",
|
|
94
|
-
ol: "HTMLOListElement",
|
|
95
|
-
optgroup: "HTMLOptGroupElement",
|
|
96
|
-
option: "HTMLOptionElement",
|
|
97
|
-
output: "HTMLOutputElement",
|
|
98
|
-
p: "HTMLParagraphElement",
|
|
99
|
-
param: "HTMLParamElement",
|
|
100
|
-
picture: "HTMLPictureElement",
|
|
101
|
-
pre: "HTMLPreElement",
|
|
102
|
-
progress: "HTMLProgressElement",
|
|
103
|
-
q: "HTMLQuoteElement",
|
|
104
|
-
rp: "HTMLElement",
|
|
105
|
-
rt: "HTMLElement",
|
|
106
|
-
ruby: "HTMLElement",
|
|
107
|
-
s: "HTMLElement",
|
|
108
|
-
samp: "HTMLElement",
|
|
109
|
-
script: "HTMLScriptElement",
|
|
110
|
-
search: "HTMLElement",
|
|
111
|
-
section: "HTMLElement",
|
|
112
|
-
select: "HTMLSelectElement",
|
|
113
|
-
slot: "HTMLSlotElement",
|
|
114
|
-
small: "HTMLElement",
|
|
115
|
-
source: "HTMLSourceElement",
|
|
116
|
-
span: "HTMLSpanElement",
|
|
117
|
-
strong: "HTMLElement",
|
|
118
|
-
style: "HTMLStyleElement",
|
|
119
|
-
sub: "HTMLElement",
|
|
120
|
-
summary: "HTMLElement",
|
|
121
|
-
sup: "HTMLElement",
|
|
122
|
-
table: "HTMLTableElement",
|
|
123
|
-
tbody: "HTMLTableSectionElement",
|
|
124
|
-
td: "HTMLTableCellElement",
|
|
125
|
-
template: "HTMLTemplateElement",
|
|
126
|
-
textarea: "HTMLTextAreaElement",
|
|
127
|
-
tfoot: "HTMLTableSectionElement",
|
|
128
|
-
th: "HTMLTableCellElement",
|
|
129
|
-
thead: "HTMLTableSectionElement",
|
|
130
|
-
time: "HTMLTimeElement",
|
|
131
|
-
title: "HTMLTitleElement",
|
|
132
|
-
tr: "HTMLTableRowElement",
|
|
133
|
-
track: "HTMLTrackElement",
|
|
134
|
-
u: "HTMLElement",
|
|
135
|
-
ul: "HTMLUListElement",
|
|
136
|
-
var: "HTMLElement",
|
|
137
|
-
video: "HTMLVideoElement",
|
|
138
|
-
wbr: "HTMLElement",
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Gets the TypeScript element type for a given HTML tag name.
|
|
142
|
-
*
|
|
143
|
-
* Returns the specific element type (e.g., `HTMLButtonElement`) if the tag
|
|
144
|
-
* is in the map, otherwise returns the generic `HTMLElement` type.
|
|
145
|
-
*
|
|
146
|
-
* @param element - The HTML tag name (e.g., "button", "div", "input")
|
|
147
|
-
* @returns The corresponding TypeScript element type name
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```ts
|
|
151
|
-
* getElementByTag("button") // Returns: "HTMLButtonElement"
|
|
152
|
-
* getElementByTag("div") // Returns: "HTMLDivElement"
|
|
153
|
-
* getElementByTag("custom") // Returns: "HTMLElement" (fallback)
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
function getElementByTag(element) {
|
|
157
|
-
return element in tag_map ? tag_map[element] : "HTMLElement";
|
|
158
|
-
}
|
package/lib/get-svelte-entry.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSvelteEntry = getSvelteEntry;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
/**
|
|
7
|
-
* Get the file path entry point for uncompiled Svelte source code
|
|
8
|
-
* Expects a "svelte" field in the consumer's `package.json`
|
|
9
|
-
*/
|
|
10
|
-
function getSvelteEntry(entryPoint) {
|
|
11
|
-
if (entryPoint) {
|
|
12
|
-
const entry_path = (0, node_path_1.join)(process.cwd(), entryPoint);
|
|
13
|
-
if ((0, node_fs_1.existsSync)(entry_path)) {
|
|
14
|
-
return entryPoint;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
console.log(`Invalid entry point: ${entry_path}.`);
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
const pkg_path = (0, node_path_1.join)(process.cwd(), "package.json");
|
|
22
|
-
if (!(0, node_fs_1.existsSync)(pkg_path)) {
|
|
23
|
-
console.log("Could not locate a package.json file.\n");
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
const pkg = JSON.parse((0, node_fs_1.readFileSync)(pkg_path, "utf-8"));
|
|
28
|
-
if (typeof pkg.svelte === "string" && pkg.svelte.trim()) {
|
|
29
|
-
return pkg.svelte;
|
|
30
|
-
}
|
|
31
|
-
console.log("Could not determine an entry point.\n");
|
|
32
|
-
console.log('Specify an entry point to your Svelte code in the "svelte" field of your package.json.\n');
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
console.error("Error reading package.json:", error);
|
|
37
|
-
throw error;
|
|
38
|
-
}
|
|
39
|
-
}
|
package/lib/parse-exports.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseExports = parseExports;
|
|
4
|
-
const node_fs_1 = require("node:fs");
|
|
5
|
-
const node_path_1 = require("node:path");
|
|
6
|
-
const acorn_1 = require("acorn");
|
|
7
|
-
const path_1 = require("./path");
|
|
8
|
-
const resolve_alias_1 = require("./resolve-alias");
|
|
9
|
-
const astCache = new Map();
|
|
10
|
-
/**
|
|
11
|
-
* Parses export statements from JavaScript/TypeScript source code.
|
|
12
|
-
*
|
|
13
|
-
* Extracts all exports (default, named, and re-exports) and resolves
|
|
14
|
-
* their source paths, handling path aliases and directory imports.
|
|
15
|
-
* Caches parsed ASTs for performance.
|
|
16
|
-
*
|
|
17
|
-
* @param source - The source code to parse
|
|
18
|
-
* @param dir - The directory context for resolving relative paths and aliases
|
|
19
|
-
* @returns A map of export names to their source paths and metadata
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* // Source: export { Button } from "./Button.svelte";
|
|
24
|
-
* // export default App from "./App.svelte";
|
|
25
|
-
* parseExports(source, "./src")
|
|
26
|
-
* // Returns: {
|
|
27
|
-
* // Button: { source: "./Button.svelte", default: false },
|
|
28
|
-
* // App: { source: "./App.svelte", default: true }
|
|
29
|
-
* // }
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
function parseExports(source, dir) {
|
|
33
|
-
let ast = astCache.get(source);
|
|
34
|
-
if (!ast) {
|
|
35
|
-
ast = (0, acorn_1.parse)(source, {
|
|
36
|
-
ecmaVersion: "latest",
|
|
37
|
-
sourceType: "module",
|
|
38
|
-
});
|
|
39
|
-
astCache.set(source, ast);
|
|
40
|
-
}
|
|
41
|
-
const exports_by_identifier = {};
|
|
42
|
-
for (const node of ast.body) {
|
|
43
|
-
if (node.type === "ExportDefaultDeclaration") {
|
|
44
|
-
const id = node.declaration.name;
|
|
45
|
-
if (id in exports_by_identifier) {
|
|
46
|
-
exports_by_identifier[id].default = true;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
exports_by_identifier[id] = { source: "", default: true };
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else if (node.type === "ExportAllDeclaration") {
|
|
53
|
-
if (!node.source)
|
|
54
|
-
continue;
|
|
55
|
-
const resolvedSource = (0, resolve_alias_1.resolvePathAliasAbsolute)(node.source.value, dir);
|
|
56
|
-
let file_path = (0, node_path_1.resolve)(dir, resolvedSource);
|
|
57
|
-
if (!(0, node_fs_1.lstatSync)(file_path).isFile()) {
|
|
58
|
-
const files = (0, node_fs_1.readdirSync)(file_path);
|
|
59
|
-
for (const file of files)
|
|
60
|
-
if (file.includes("index")) {
|
|
61
|
-
file_path = (0, node_path_1.join)(file_path, file);
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const export_file = (0, node_fs_1.readFileSync)(file_path, "utf-8");
|
|
66
|
-
const exports = parseExports(export_file, (0, node_path_1.dirname)(file_path));
|
|
67
|
-
for (const [key, value] of Object.entries(exports)) {
|
|
68
|
-
const source = (0, path_1.normalizeSeparators)(`./${(0, node_path_1.join)(node.source.value, value.source)}`);
|
|
69
|
-
exports_by_identifier[key] = {
|
|
70
|
-
...value,
|
|
71
|
-
source,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else if (node.type === "ExportNamedDeclaration") {
|
|
76
|
-
for (const specifier of node.specifiers) {
|
|
77
|
-
const exported_name = specifier.exported.name;
|
|
78
|
-
const local_name = specifier.local.name;
|
|
79
|
-
const id = exported_name || local_name;
|
|
80
|
-
if (id in exports_by_identifier) {
|
|
81
|
-
if (node.type === "ExportNamedDeclaration") {
|
|
82
|
-
exports_by_identifier[id].mixed = true;
|
|
83
|
-
}
|
|
84
|
-
if (!exports_by_identifier[id].source) {
|
|
85
|
-
exports_by_identifier[id].source = (0, resolve_alias_1.resolvePathAlias)(node.source?.value ?? "", dir);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
exports_by_identifier[id] = {
|
|
90
|
-
source: (0, resolve_alias_1.resolvePathAlias)(node.source?.value ?? "", dir),
|
|
91
|
-
default: local_name === "default",
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
else if (node.type === "ImportDeclaration") {
|
|
97
|
-
const id = node.specifiers[0].local.name;
|
|
98
|
-
if (id in exports_by_identifier) {
|
|
99
|
-
if (!exports_by_identifier[id].source) {
|
|
100
|
-
exports_by_identifier[id].source = (0, resolve_alias_1.resolvePathAlias)(node.source?.value ?? "", dir);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
exports_by_identifier[id] = {
|
|
105
|
-
source: (0, resolve_alias_1.resolvePathAlias)(node.source?.value ?? "", dir),
|
|
106
|
-
default: id === "default",
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return exports_by_identifier;
|
|
112
|
-
}
|
package/lib/path.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.normalizeSeparators = normalizeSeparators;
|
|
4
|
-
const node_path_1 = require("node:path");
|
|
5
|
-
/**
|
|
6
|
-
* Normalize directory separators to always use `/`.
|
|
7
|
-
* @param filePath A file path.
|
|
8
|
-
* @returns Path with normalized separators.
|
|
9
|
-
*/
|
|
10
|
-
function normalizeSeparators(filePath) {
|
|
11
|
-
return node_path_1.sep === "/" ? filePath : filePath.split(node_path_1.sep).join("/");
|
|
12
|
-
}
|