@fuzdev/fuz_ui 0.198.1 → 0.199.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/dist/ApiIndex.svelte +2 -2
- package/dist/ApiModule.svelte +1 -1
- package/dist/LibraryDetail.svelte +14 -16
- package/dist/LibraryDetail.svelte.d.ts.map +1 -1
- package/dist/LibrarySummary.svelte +12 -12
- package/dist/Mdz.svelte +2 -2
- package/dist/MdzNodeView.svelte +8 -6
- package/dist/MdzNodeView.svelte.d.ts.map +1 -1
- package/dist/MdzRoot.svelte +30 -0
- package/dist/MdzRoot.svelte.d.ts +12 -0
- package/dist/MdzRoot.svelte.d.ts.map +1 -0
- package/dist/MdzStream.svelte +32 -0
- package/dist/MdzStream.svelte.d.ts +12 -0
- package/dist/MdzStream.svelte.d.ts.map +1 -0
- package/dist/MdzStreamNodeView.svelte +106 -0
- package/dist/MdzStreamNodeView.svelte.d.ts +9 -0
- package/dist/MdzStreamNodeView.svelte.d.ts.map +1 -0
- package/dist/declaration.svelte.js +2 -2
- package/dist/library.svelte.d.ts +9 -70
- package/dist/library.svelte.d.ts.map +1 -1
- package/dist/library.svelte.js +24 -18
- package/dist/library_helpers.d.ts +3 -3
- package/dist/library_helpers.js +3 -3
- package/dist/mdz.d.ts.map +1 -1
- package/dist/mdz.js +37 -29
- package/dist/mdz_components.d.ts +37 -23
- package/dist/mdz_components.d.ts.map +1 -1
- package/dist/mdz_components.js +16 -4
- package/dist/mdz_helpers.d.ts +46 -14
- package/dist/mdz_helpers.d.ts.map +1 -1
- package/dist/mdz_helpers.js +189 -56
- package/dist/mdz_lexer.d.ts.map +1 -1
- package/dist/mdz_lexer.js +18 -22
- package/dist/mdz_opcodes.d.ts +174 -0
- package/dist/mdz_opcodes.d.ts.map +1 -0
- package/dist/mdz_opcodes.js +14 -0
- package/dist/mdz_opcodes_to_nodes.d.ts +20 -0
- package/dist/mdz_opcodes_to_nodes.d.ts.map +1 -0
- package/dist/mdz_opcodes_to_nodes.js +332 -0
- package/dist/mdz_stream_parser.d.ts +80 -0
- package/dist/mdz_stream_parser.d.ts.map +1 -0
- package/dist/mdz_stream_parser.js +354 -0
- package/dist/mdz_stream_parser_block.d.ts +76 -0
- package/dist/mdz_stream_parser_block.d.ts.map +1 -0
- package/dist/mdz_stream_parser_block.js +458 -0
- package/dist/mdz_stream_parser_inline.d.ts +52 -0
- package/dist/mdz_stream_parser_inline.d.ts.map +1 -0
- package/dist/mdz_stream_parser_inline.js +378 -0
- package/dist/mdz_stream_parser_link.d.ts +22 -0
- package/dist/mdz_stream_parser_link.d.ts.map +1 -0
- package/dist/mdz_stream_parser_link.js +215 -0
- package/dist/mdz_stream_parser_state.d.ts +187 -0
- package/dist/mdz_stream_parser_state.d.ts.map +1 -0
- package/dist/mdz_stream_parser_state.js +398 -0
- package/dist/mdz_stream_parser_text.d.ts +14 -0
- package/dist/mdz_stream_parser_text.d.ts.map +1 -0
- package/dist/mdz_stream_parser_text.js +50 -0
- package/dist/mdz_stream_parser_url.d.ts +60 -0
- package/dist/mdz_stream_parser_url.d.ts.map +1 -0
- package/dist/mdz_stream_parser_url.js +307 -0
- package/dist/mdz_stream_state.svelte.d.ts +44 -0
- package/dist/mdz_stream_state.svelte.d.ts.map +1 -0
- package/dist/mdz_stream_state.svelte.js +357 -0
- package/dist/mdz_token_parser.d.ts.map +1 -1
- package/dist/mdz_token_parser.js +8 -39
- package/dist/module.svelte.js +1 -1
- package/dist/site.svelte.d.ts +13 -0
- package/dist/site.svelte.d.ts.map +1 -1
- package/dist/site.svelte.js +8 -2
- package/dist/tsdoc_mdz.d.ts +2 -2
- package/dist/tsdoc_mdz.js +2 -2
- package/dist/vite_plugin_pkg_json.d.ts +63 -0
- package/dist/vite_plugin_pkg_json.d.ts.map +1 -0
- package/dist/vite_plugin_pkg_json.js +126 -0
- package/package.json +6 -5
- package/src/lib/declaration.svelte.ts +2 -2
- package/src/lib/library.svelte.ts +37 -20
- package/src/lib/library_helpers.ts +3 -3
- package/src/lib/mdz.ts +38 -29
- package/src/lib/mdz_components.ts +40 -19
- package/src/lib/mdz_helpers.ts +199 -56
- package/src/lib/mdz_lexer.ts +18 -20
- package/src/lib/mdz_opcodes.ts +205 -0
- package/src/lib/mdz_opcodes_to_nodes.ts +375 -0
- package/src/lib/mdz_stream_parser.ts +415 -0
- package/src/lib/mdz_stream_parser_block.ts +532 -0
- package/src/lib/mdz_stream_parser_inline.ts +414 -0
- package/src/lib/mdz_stream_parser_link.ts +271 -0
- package/src/lib/mdz_stream_parser_state.ts +539 -0
- package/src/lib/mdz_stream_parser_text.ts +77 -0
- package/src/lib/mdz_stream_parser_url.ts +365 -0
- package/src/lib/mdz_stream_state.svelte.ts +387 -0
- package/src/lib/mdz_token_parser.ts +13 -40
- package/src/lib/module.svelte.ts +1 -1
- package/src/lib/site.svelte.ts +17 -2
- package/src/lib/tsdoc_mdz.ts +2 -2
- package/src/lib/vite_plugin_pkg_json.ts +142 -0
- package/dist/package_helpers.d.ts +0 -150
- package/dist/package_helpers.d.ts.map +0 -1
- package/dist/package_helpers.js +0 -179
- package/src/lib/package_helpers.ts +0 -186
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vite plugin serving a curated, publish-safe `package.json` as the virtual
|
|
3
|
+
* module `virtual:pkg.json`.
|
|
4
|
+
*
|
|
5
|
+
* Consumers' `src/routes/library.ts` (and root layouts) need package identity —
|
|
6
|
+
* name, version, the Fuz extension fields — in the client. Importing the root
|
|
7
|
+
* `package.json` directly inlines the *whole* file into the client bundle
|
|
8
|
+
* (`scripts`, `dependencies`, `devDependencies`, private config) and trips
|
|
9
|
+
* SvelteKit's `server.fs.allow` on cold HMR reloads. This plugin reads the
|
|
10
|
+
* project's `package.json` at build time, strips it to `pkg_json_keys`, and
|
|
11
|
+
* serves only that subset. Consumers combine it with `virtual:svelte-docinfo`'s
|
|
12
|
+
* analyzed `modules` via `library_json_from_modules` to build a `LibraryJson`
|
|
13
|
+
* (see `src/routes/library.ts` for the canonical pattern).
|
|
14
|
+
*
|
|
15
|
+
* The `.json` suffix on the virtual id is load-bearing, mirroring how
|
|
16
|
+
* `vite_plugin_fuz_css`'s `virtual:fuz.css` relies on `.css`: `load()` returns
|
|
17
|
+
* raw JSON text and Vite's built-in `vite:json` plugin transforms it into an ES
|
|
18
|
+
* module (default export plus named exports), so consumers write
|
|
19
|
+
* `import package_json from 'virtual:pkg.json'`. Do *not* return a JS module
|
|
20
|
+
* here — the `.json` id would double-transform it.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* // vite.config.ts
|
|
24
|
+
* import {vite_plugin_pkg_json} from '@fuzdev/fuz_ui/vite_plugin_pkg_json.js';
|
|
25
|
+
* export default defineConfig({plugins: [vite_plugin_pkg_json(), sveltekit()]});
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The kept field set defaults to `pkg_json_keys`. To expose extra publish-safe
|
|
29
|
+
* fields, pass a wider `keys` list — typically composed from the default with a
|
|
30
|
+
* spread (`` keys: [...pkg_json_keys, 'keywords'] ``). Because `library_json_from_modules`
|
|
31
|
+
* re-strips at runtime, the *same* list must reach that call (and the consumer's
|
|
32
|
+
* `virtual:pkg.json` ambient type) for the extras to survive end to end — share
|
|
33
|
+
* one const across all three sites:
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* // src/routes/pkg_json_keys.ts
|
|
37
|
+
* import {pkg_json_keys} from '@fuzdev/fuz_util/pkg_json.js';
|
|
38
|
+
* export const pkg_json_keys_custom = [...pkg_json_keys, 'keywords'] as const;
|
|
39
|
+
*
|
|
40
|
+
* // vite.config.ts → vite_plugin_pkg_json({keys: pkg_json_keys_custom})
|
|
41
|
+
* // src/routes/library.ts → library_json_from_modules(pkg_json, modules, pkg_json_keys_custom)
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @module
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
import {readFileSync} from 'node:fs';
|
|
48
|
+
import {join} from 'node:path';
|
|
49
|
+
import type {Plugin, Rollup} from 'vite';
|
|
50
|
+
import type {PackageJson} from '@fuzdev/fuz_util/package_json.js';
|
|
51
|
+
import {pkg_json_from_package_json, pkg_json_keys} from '@fuzdev/fuz_util/pkg_json.js';
|
|
52
|
+
|
|
53
|
+
const VIRTUAL_ID = 'virtual:pkg.json';
|
|
54
|
+
/**
|
|
55
|
+
* Resolved id, `\0`-prefixed — the conventional Rollup marker for "this id is
|
|
56
|
+
* mine," hiding the virtual module from other plugins and the dev module graph.
|
|
57
|
+
*
|
|
58
|
+
* This deliberately diverges from `vite_plugin_fuz_css`, which avoids the `\0`
|
|
59
|
+
* on its resolved id: SvelteKit's dev FOUC prevention inlines `virtual:fuz.css`
|
|
60
|
+
* into the SSR'd `<head>` via URL lookup and can't resolve the `\0`-encoded
|
|
61
|
+
* form, so the page would flash unstyled. JSON is never inlined into `<head>`,
|
|
62
|
+
* so that constraint doesn't apply here and the `\0` is free to do its normal
|
|
63
|
+
* job. The trailing `.json` survives the prefix, so Vite's built-in `vite:json`
|
|
64
|
+
* plugin still matches and transforms the loaded text (see the module comment).
|
|
65
|
+
*/
|
|
66
|
+
const RESOLVED_VIRTUAL_ID = '\0virtual:pkg.json';
|
|
67
|
+
|
|
68
|
+
/** Options for `vite_plugin_pkg_json`. */
|
|
69
|
+
export interface VitePluginPkgJsonOptions {
|
|
70
|
+
/**
|
|
71
|
+
* The `package.json` fields to keep in the served subset. Defaults to the
|
|
72
|
+
* curated, publish-safe `pkg_json_keys`. Pass a wider list — usually
|
|
73
|
+
* `` [...pkg_json_keys, 'extra'] `` — to expose more fields; the same list
|
|
74
|
+
* must reach `library_json_from_modules` (see the module comment).
|
|
75
|
+
*/
|
|
76
|
+
keys?: ReadonlyArray<keyof PackageJson>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Creates the `virtual:pkg.json` plugin. Zero-config for canonical fuz usage —
|
|
81
|
+
* the publish-safe field set defaults to `pkg_json_keys`; widen it via `keys`.
|
|
82
|
+
*/
|
|
83
|
+
export const vite_plugin_pkg_json = (options: VitePluginPkgJsonOptions = {}): Plugin => {
|
|
84
|
+
const {keys = pkg_json_keys} = options;
|
|
85
|
+
let root = '';
|
|
86
|
+
let is_dev = false;
|
|
87
|
+
/** Curated JSON cached for build; left `null` in dev so `load` re-reads. */
|
|
88
|
+
let cached: string | null = null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Reads `package.json`, strips it to the configured `keys` subset via
|
|
92
|
+
* `pkg_json_from_package_json` (the same strip the runtime uses, so the two
|
|
93
|
+
* can't drift), and returns the curated JSON text. Routes failures through the
|
|
94
|
+
* plugin context (`ctx.error`/`ctx.warn`) so a missing or malformed file
|
|
95
|
+
* surfaces as a named, actionable diagnostic rather than a raw
|
|
96
|
+
* `readFileSync`/`JSON.parse` stack trace.
|
|
97
|
+
*/
|
|
98
|
+
const read_curated = (ctx: Rollup.PluginContext): string => {
|
|
99
|
+
const package_json_path = join(root, 'package.json');
|
|
100
|
+
ctx.addWatchFile(package_json_path); // re-emit when package.json changes
|
|
101
|
+
let raw: PackageJson;
|
|
102
|
+
try {
|
|
103
|
+
raw = JSON.parse(readFileSync(package_json_path, 'utf8')) as PackageJson;
|
|
104
|
+
} catch (err) {
|
|
105
|
+
// ctx.error throws, so this never returns
|
|
106
|
+
return ctx.error(
|
|
107
|
+
`vite_plugin_pkg_json: failed to read or parse ${package_json_path}: ${(err as Error).message}`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (raw.name === undefined) {
|
|
111
|
+
ctx.warn(`vite_plugin_pkg_json: ${package_json_path} has no "name" field`);
|
|
112
|
+
}
|
|
113
|
+
return JSON.stringify(pkg_json_from_package_json(raw, keys));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
name: 'vite-plugin-pkg-json',
|
|
118
|
+
// Resolve the virtual id before other plugins claim it.
|
|
119
|
+
enforce: 'pre',
|
|
120
|
+
configResolved(config) {
|
|
121
|
+
root = config.root;
|
|
122
|
+
is_dev = config.command === 'serve';
|
|
123
|
+
},
|
|
124
|
+
buildStart() {
|
|
125
|
+
// Read package.json once up front so a missing or malformed file fails
|
|
126
|
+
// immediately — at build start, or at dev-server startup — rather than
|
|
127
|
+
// only when something first imports the virtual module. In build the
|
|
128
|
+
// result is cached for `load`; in dev `load` re-reads each time so edits
|
|
129
|
+
// to package.json propagate through the `addWatchFile`-driven reload.
|
|
130
|
+
const curated = read_curated(this);
|
|
131
|
+
if (!is_dev) cached = curated;
|
|
132
|
+
},
|
|
133
|
+
resolveId(id) {
|
|
134
|
+
if (id === VIRTUAL_ID) return RESOLVED_VIRTUAL_ID;
|
|
135
|
+
return undefined;
|
|
136
|
+
},
|
|
137
|
+
load(id) {
|
|
138
|
+
if (id !== RESOLVED_VIRTUAL_ID) return undefined;
|
|
139
|
+
return cached ?? read_curated(this);
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
};
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Package and repository URL helpers.
|
|
3
|
-
*
|
|
4
|
-
* Generic utilities for building URLs and parsing package/repository metadata.
|
|
5
|
-
* These functions have no framework dependencies and can be used at build-time or runtime.
|
|
6
|
-
*
|
|
7
|
-
* URL builders:
|
|
8
|
-
* - `url_github_file` - GitHub file permalink
|
|
9
|
-
* - `url_github_org` - GitHub organization page
|
|
10
|
-
* - `url_npm_package` - npm package page
|
|
11
|
-
*
|
|
12
|
-
* Parsers:
|
|
13
|
-
* - `repo_url_parse` - extract repo URL from `package.json` repository field
|
|
14
|
-
* - `repo_name_parse` - extract repo name from scoped package name
|
|
15
|
-
* - `repo_url_github_owner` - extract GitHub owner from repo URL
|
|
16
|
-
*
|
|
17
|
-
* Predicates:
|
|
18
|
-
* - `package_is_published` - check if package is published to npm
|
|
19
|
-
*
|
|
20
|
-
* @module
|
|
21
|
-
*/
|
|
22
|
-
import type { PackageJson } from '@fuzdev/fuz_util/package_json.js';
|
|
23
|
-
/**
|
|
24
|
-
* Build GitHub file URL for a repository.
|
|
25
|
-
*
|
|
26
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
27
|
-
* @param file_path - path to the file (leading './' is stripped)
|
|
28
|
-
* @param line - optional line number for deep linking
|
|
29
|
-
* @returns full GitHub URL to the file on the main branch
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* url_github_file('https://github.com/foo/bar', 'src/index.ts')
|
|
34
|
-
* // => 'https://github.com/foo/bar/blob/main/src/index.ts'
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* url_github_file('https://github.com/foo/bar', './src/index.ts', 42)
|
|
40
|
-
* // => 'https://github.com/foo/bar/blob/main/src/index.ts#L42'
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare const url_github_file: (repo_url: string, file_path: string, line?: number) => string;
|
|
44
|
-
/**
|
|
45
|
-
* Build GitHub organization URL from repo URL and repo name.
|
|
46
|
-
*
|
|
47
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
48
|
-
* @param repo_name - repository name to strip from the URL
|
|
49
|
-
* @returns organization URL, or null if repo_url doesn't end with repo_name
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* url_github_org('https://github.com/fuzdev/fuz_ui', 'fuz_ui')
|
|
54
|
-
* // => 'https://github.com/fuzdev'
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export declare const url_github_org: (repo_url: string, repo_name: string) => string | null;
|
|
58
|
-
/**
|
|
59
|
-
* Extract GitHub owner/org name from repository URL.
|
|
60
|
-
*
|
|
61
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
62
|
-
* @returns owner name, or null if not a valid GitHub URL
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* repo_url_github_owner('https://github.com/fuzdev/fuz_ui')
|
|
67
|
-
* // => 'fuzdev'
|
|
68
|
-
* ```
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* repo_url_github_owner('https://gitlab.com/foo/bar')
|
|
73
|
-
* // => null (not a GitHub URL)
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
export declare const repo_url_github_owner: (repo_url: string) => string | null;
|
|
77
|
-
/**
|
|
78
|
-
* Build npm package URL.
|
|
79
|
-
*
|
|
80
|
-
* @param package_name - package name (can be scoped like '@org/package')
|
|
81
|
-
* @returns full npm package page URL
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```ts
|
|
85
|
-
* url_npm_package('@fuzdev/fuz_ui')
|
|
86
|
-
* // => 'https://www.npmjs.com/package/@fuzdev/fuz_ui'
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
export declare const url_npm_package: (package_name: string) => string;
|
|
90
|
-
/**
|
|
91
|
-
* Check if a package is published to npm.
|
|
92
|
-
*
|
|
93
|
-
* A package is considered published if:
|
|
94
|
-
* - It's not marked as private
|
|
95
|
-
* - It has exports defined
|
|
96
|
-
* - Its version is not the initial '0.0.1'
|
|
97
|
-
*
|
|
98
|
-
* @param package_json - the `package.json` object to check
|
|
99
|
-
* @returns `true` if the package appears to be published
|
|
100
|
-
*/
|
|
101
|
-
export declare const package_is_published: (package_json: PackageJson) => boolean;
|
|
102
|
-
/**
|
|
103
|
-
* Extract repository name without scope from package name.
|
|
104
|
-
*
|
|
105
|
-
* @param name - package name (can be scoped like '@org/package')
|
|
106
|
-
* @returns repository name without scope
|
|
107
|
-
* @throws Error if scoped package name is malformed
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```ts
|
|
111
|
-
* repo_name_parse('@fuzdev/fuz_ui')
|
|
112
|
-
* // => 'fuz_ui'
|
|
113
|
-
* ```
|
|
114
|
-
*
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* repo_name_parse('lodash')
|
|
118
|
-
* // => 'lodash'
|
|
119
|
-
* ```
|
|
120
|
-
*/
|
|
121
|
-
export declare const repo_name_parse: (name: string) => string;
|
|
122
|
-
/**
|
|
123
|
-
* Parse repository URL from `package.json` format.
|
|
124
|
-
*
|
|
125
|
-
* Handles both string format and object format with `url` property.
|
|
126
|
-
* Strips common prefixes ('git+') and suffixes ('.git', '/').
|
|
127
|
-
*
|
|
128
|
-
* @param repository - the repository field from `package.json`
|
|
129
|
-
* @returns clean repository URL, or null if not provided
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* repo_url_parse('https://github.com/foo/bar')
|
|
134
|
-
* // => 'https://github.com/foo/bar'
|
|
135
|
-
* ```
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* repo_url_parse({url: 'git+https://github.com/foo/bar.git'})
|
|
140
|
-
* // => 'https://github.com/foo/bar'
|
|
141
|
-
* ```
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```ts
|
|
145
|
-
* repo_url_parse(undefined)
|
|
146
|
-
* // => null
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
export declare const repo_url_parse: (repository: PackageJson["repository"]) => string | null;
|
|
150
|
-
//# sourceMappingURL=package_helpers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/package_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,kCAAkC,CAAC;AAElE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,WAAW,MAAM,EAAE,OAAO,MAAM,KAAG,MAIpF,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,MAAM,EAAE,WAAW,MAAM,KAAG,MAAM,GAAG,IAE7E,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,KAAG,MAAM,GAAG,IAKjE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,eAAe,GAAI,cAAc,MAAM,KAAG,MACP,CAAC;AAEjD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB,GAAI,cAAc,WAAW,KAAG,OAEhE,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,MAS9C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,cAAc,GAAI,YAAY,WAAW,CAAC,YAAY,CAAC,KAAG,MAAM,GAAG,IAK/E,CAAC"}
|
package/dist/package_helpers.js
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Package and repository URL helpers.
|
|
3
|
-
*
|
|
4
|
-
* Generic utilities for building URLs and parsing package/repository metadata.
|
|
5
|
-
* These functions have no framework dependencies and can be used at build-time or runtime.
|
|
6
|
-
*
|
|
7
|
-
* URL builders:
|
|
8
|
-
* - `url_github_file` - GitHub file permalink
|
|
9
|
-
* - `url_github_org` - GitHub organization page
|
|
10
|
-
* - `url_npm_package` - npm package page
|
|
11
|
-
*
|
|
12
|
-
* Parsers:
|
|
13
|
-
* - `repo_url_parse` - extract repo URL from `package.json` repository field
|
|
14
|
-
* - `repo_name_parse` - extract repo name from scoped package name
|
|
15
|
-
* - `repo_url_github_owner` - extract GitHub owner from repo URL
|
|
16
|
-
*
|
|
17
|
-
* Predicates:
|
|
18
|
-
* - `package_is_published` - check if package is published to npm
|
|
19
|
-
*
|
|
20
|
-
* @module
|
|
21
|
-
*/
|
|
22
|
-
import { strip_end, strip_start } from '@fuzdev/fuz_util/string.js';
|
|
23
|
-
/**
|
|
24
|
-
* Build GitHub file URL for a repository.
|
|
25
|
-
*
|
|
26
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
27
|
-
* @param file_path - path to the file (leading './' is stripped)
|
|
28
|
-
* @param line - optional line number for deep linking
|
|
29
|
-
* @returns full GitHub URL to the file on the main branch
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* url_github_file('https://github.com/foo/bar', 'src/index.ts')
|
|
34
|
-
* // => 'https://github.com/foo/bar/blob/main/src/index.ts'
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```ts
|
|
39
|
-
* url_github_file('https://github.com/foo/bar', './src/index.ts', 42)
|
|
40
|
-
* // => 'https://github.com/foo/bar/blob/main/src/index.ts#L42'
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export const url_github_file = (repo_url, file_path, line) => {
|
|
44
|
-
const clean_path = file_path.replace(/^\.\//, '');
|
|
45
|
-
const base = `${repo_url}/blob/main/${clean_path}`;
|
|
46
|
-
return line ? `${base}#L${line}` : base;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Build GitHub organization URL from repo URL and repo name.
|
|
50
|
-
*
|
|
51
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
52
|
-
* @param repo_name - repository name to strip from the URL
|
|
53
|
-
* @returns organization URL, or null if repo_url doesn't end with repo_name
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* url_github_org('https://github.com/fuzdev/fuz_ui', 'fuz_ui')
|
|
58
|
-
* // => 'https://github.com/fuzdev'
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export const url_github_org = (repo_url, repo_name) => {
|
|
62
|
-
return repo_url.endsWith('/' + repo_name) ? strip_end(repo_url, '/' + repo_name) : null;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Extract GitHub owner/org name from repository URL.
|
|
66
|
-
*
|
|
67
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
68
|
-
* @returns owner name, or null if not a valid GitHub URL
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```ts
|
|
72
|
-
* repo_url_github_owner('https://github.com/fuzdev/fuz_ui')
|
|
73
|
-
* // => 'fuzdev'
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* @example
|
|
77
|
-
* ```ts
|
|
78
|
-
* repo_url_github_owner('https://gitlab.com/foo/bar')
|
|
79
|
-
* // => null (not a GitHub URL)
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
|
-
export const repo_url_github_owner = (repo_url) => {
|
|
83
|
-
const stripped = strip_start(repo_url, 'https://github.com/');
|
|
84
|
-
if (stripped === repo_url)
|
|
85
|
-
return null;
|
|
86
|
-
const parts = stripped.split('/');
|
|
87
|
-
return parts[0] || null;
|
|
88
|
-
};
|
|
89
|
-
/**
|
|
90
|
-
* Build npm package URL.
|
|
91
|
-
*
|
|
92
|
-
* @param package_name - package name (can be scoped like '@org/package')
|
|
93
|
-
* @returns full npm package page URL
|
|
94
|
-
*
|
|
95
|
-
* @example
|
|
96
|
-
* ```ts
|
|
97
|
-
* url_npm_package('@fuzdev/fuz_ui')
|
|
98
|
-
* // => 'https://www.npmjs.com/package/@fuzdev/fuz_ui'
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export const url_npm_package = (package_name) => 'https://www.npmjs.com/package/' + package_name;
|
|
102
|
-
/**
|
|
103
|
-
* Check if a package is published to npm.
|
|
104
|
-
*
|
|
105
|
-
* A package is considered published if:
|
|
106
|
-
* - It's not marked as private
|
|
107
|
-
* - It has exports defined
|
|
108
|
-
* - Its version is not the initial '0.0.1'
|
|
109
|
-
*
|
|
110
|
-
* @param package_json - the `package.json` object to check
|
|
111
|
-
* @returns `true` if the package appears to be published
|
|
112
|
-
*/
|
|
113
|
-
export const package_is_published = (package_json) => {
|
|
114
|
-
return !package_json.private && !!package_json.exports && package_json.version !== '0.0.1';
|
|
115
|
-
};
|
|
116
|
-
/**
|
|
117
|
-
* Extract repository name without scope from package name.
|
|
118
|
-
*
|
|
119
|
-
* @param name - package name (can be scoped like '@org/package')
|
|
120
|
-
* @returns repository name without scope
|
|
121
|
-
* @throws Error if scoped package name is malformed
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```ts
|
|
125
|
-
* repo_name_parse('@fuzdev/fuz_ui')
|
|
126
|
-
* // => 'fuz_ui'
|
|
127
|
-
* ```
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```ts
|
|
131
|
-
* repo_name_parse('lodash')
|
|
132
|
-
* // => 'lodash'
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
export const repo_name_parse = (name) => {
|
|
136
|
-
if (name[0] === '@') {
|
|
137
|
-
const parts = name.split('/');
|
|
138
|
-
if (parts.length < 2) {
|
|
139
|
-
throw new Error(`invalid scoped package name: "${name}" (expected format: @org/package)`);
|
|
140
|
-
}
|
|
141
|
-
return parts[1];
|
|
142
|
-
}
|
|
143
|
-
return name;
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* Parse repository URL from `package.json` format.
|
|
147
|
-
*
|
|
148
|
-
* Handles both string format and object format with `url` property.
|
|
149
|
-
* Strips common prefixes ('git+') and suffixes ('.git', '/').
|
|
150
|
-
*
|
|
151
|
-
* @param repository - the repository field from `package.json`
|
|
152
|
-
* @returns clean repository URL, or null if not provided
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```ts
|
|
156
|
-
* repo_url_parse('https://github.com/foo/bar')
|
|
157
|
-
* // => 'https://github.com/foo/bar'
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```ts
|
|
162
|
-
* repo_url_parse({url: 'git+https://github.com/foo/bar.git'})
|
|
163
|
-
* // => 'https://github.com/foo/bar'
|
|
164
|
-
* ```
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* ```ts
|
|
168
|
-
* repo_url_parse(undefined)
|
|
169
|
-
* // => null
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
export const repo_url_parse = (repository) => {
|
|
173
|
-
if (!repository)
|
|
174
|
-
return null;
|
|
175
|
-
const url = typeof repository === 'string' ? repository : repository.url;
|
|
176
|
-
if (!url)
|
|
177
|
-
return null;
|
|
178
|
-
return strip_end(strip_start(strip_end(url, '.git'), 'git+'), '/');
|
|
179
|
-
};
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Package and repository URL helpers.
|
|
3
|
-
*
|
|
4
|
-
* Generic utilities for building URLs and parsing package/repository metadata.
|
|
5
|
-
* These functions have no framework dependencies and can be used at build-time or runtime.
|
|
6
|
-
*
|
|
7
|
-
* URL builders:
|
|
8
|
-
* - `url_github_file` - GitHub file permalink
|
|
9
|
-
* - `url_github_org` - GitHub organization page
|
|
10
|
-
* - `url_npm_package` - npm package page
|
|
11
|
-
*
|
|
12
|
-
* Parsers:
|
|
13
|
-
* - `repo_url_parse` - extract repo URL from `package.json` repository field
|
|
14
|
-
* - `repo_name_parse` - extract repo name from scoped package name
|
|
15
|
-
* - `repo_url_github_owner` - extract GitHub owner from repo URL
|
|
16
|
-
*
|
|
17
|
-
* Predicates:
|
|
18
|
-
* - `package_is_published` - check if package is published to npm
|
|
19
|
-
*
|
|
20
|
-
* @module
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import {strip_end, strip_start} from '@fuzdev/fuz_util/string.js';
|
|
24
|
-
import type {PackageJson} from '@fuzdev/fuz_util/package_json.js';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Build GitHub file URL for a repository.
|
|
28
|
-
*
|
|
29
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
30
|
-
* @param file_path - path to the file (leading './' is stripped)
|
|
31
|
-
* @param line - optional line number for deep linking
|
|
32
|
-
* @returns full GitHub URL to the file on the main branch
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* ```ts
|
|
36
|
-
* url_github_file('https://github.com/foo/bar', 'src/index.ts')
|
|
37
|
-
* // => 'https://github.com/foo/bar/blob/main/src/index.ts'
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* url_github_file('https://github.com/foo/bar', './src/index.ts', 42)
|
|
43
|
-
* // => 'https://github.com/foo/bar/blob/main/src/index.ts#L42'
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
export const url_github_file = (repo_url: string, file_path: string, line?: number): string => {
|
|
47
|
-
const clean_path = file_path.replace(/^\.\//, '');
|
|
48
|
-
const base = `${repo_url}/blob/main/${clean_path}`;
|
|
49
|
-
return line ? `${base}#L${line}` : base;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Build GitHub organization URL from repo URL and repo name.
|
|
54
|
-
*
|
|
55
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
56
|
-
* @param repo_name - repository name to strip from the URL
|
|
57
|
-
* @returns organization URL, or null if repo_url doesn't end with repo_name
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```ts
|
|
61
|
-
* url_github_org('https://github.com/fuzdev/fuz_ui', 'fuz_ui')
|
|
62
|
-
* // => 'https://github.com/fuzdev'
|
|
63
|
-
* ```
|
|
64
|
-
*/
|
|
65
|
-
export const url_github_org = (repo_url: string, repo_name: string): string | null => {
|
|
66
|
-
return repo_url.endsWith('/' + repo_name) ? strip_end(repo_url, '/' + repo_name) : null;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Extract GitHub owner/org name from repository URL.
|
|
71
|
-
*
|
|
72
|
-
* @param repo_url - repository URL (e.g., 'https://github.com/owner/repo')
|
|
73
|
-
* @returns owner name, or null if not a valid GitHub URL
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* repo_url_github_owner('https://github.com/fuzdev/fuz_ui')
|
|
78
|
-
* // => 'fuzdev'
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* ```ts
|
|
83
|
-
* repo_url_github_owner('https://gitlab.com/foo/bar')
|
|
84
|
-
* // => null (not a GitHub URL)
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export const repo_url_github_owner = (repo_url: string): string | null => {
|
|
88
|
-
const stripped = strip_start(repo_url, 'https://github.com/');
|
|
89
|
-
if (stripped === repo_url) return null;
|
|
90
|
-
const parts = stripped.split('/');
|
|
91
|
-
return parts[0] || null;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Build npm package URL.
|
|
96
|
-
*
|
|
97
|
-
* @param package_name - package name (can be scoped like '@org/package')
|
|
98
|
-
* @returns full npm package page URL
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```ts
|
|
102
|
-
* url_npm_package('@fuzdev/fuz_ui')
|
|
103
|
-
* // => 'https://www.npmjs.com/package/@fuzdev/fuz_ui'
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
export const url_npm_package = (package_name: string): string =>
|
|
107
|
-
'https://www.npmjs.com/package/' + package_name;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Check if a package is published to npm.
|
|
111
|
-
*
|
|
112
|
-
* A package is considered published if:
|
|
113
|
-
* - It's not marked as private
|
|
114
|
-
* - It has exports defined
|
|
115
|
-
* - Its version is not the initial '0.0.1'
|
|
116
|
-
*
|
|
117
|
-
* @param package_json - the `package.json` object to check
|
|
118
|
-
* @returns `true` if the package appears to be published
|
|
119
|
-
*/
|
|
120
|
-
export const package_is_published = (package_json: PackageJson): boolean => {
|
|
121
|
-
return !package_json.private && !!package_json.exports && package_json.version !== '0.0.1';
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Extract repository name without scope from package name.
|
|
126
|
-
*
|
|
127
|
-
* @param name - package name (can be scoped like '@org/package')
|
|
128
|
-
* @returns repository name without scope
|
|
129
|
-
* @throws Error if scoped package name is malformed
|
|
130
|
-
*
|
|
131
|
-
* @example
|
|
132
|
-
* ```ts
|
|
133
|
-
* repo_name_parse('@fuzdev/fuz_ui')
|
|
134
|
-
* // => 'fuz_ui'
|
|
135
|
-
* ```
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* repo_name_parse('lodash')
|
|
140
|
-
* // => 'lodash'
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
export const repo_name_parse = (name: string): string => {
|
|
144
|
-
if (name[0] === '@') {
|
|
145
|
-
const parts = name.split('/');
|
|
146
|
-
if (parts.length < 2) {
|
|
147
|
-
throw new Error(`invalid scoped package name: "${name}" (expected format: @org/package)`);
|
|
148
|
-
}
|
|
149
|
-
return parts[1]!;
|
|
150
|
-
}
|
|
151
|
-
return name;
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Parse repository URL from `package.json` format.
|
|
156
|
-
*
|
|
157
|
-
* Handles both string format and object format with `url` property.
|
|
158
|
-
* Strips common prefixes ('git+') and suffixes ('.git', '/').
|
|
159
|
-
*
|
|
160
|
-
* @param repository - the repository field from `package.json`
|
|
161
|
-
* @returns clean repository URL, or null if not provided
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```ts
|
|
165
|
-
* repo_url_parse('https://github.com/foo/bar')
|
|
166
|
-
* // => 'https://github.com/foo/bar'
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```ts
|
|
171
|
-
* repo_url_parse({url: 'git+https://github.com/foo/bar.git'})
|
|
172
|
-
* // => 'https://github.com/foo/bar'
|
|
173
|
-
* ```
|
|
174
|
-
*
|
|
175
|
-
* @example
|
|
176
|
-
* ```ts
|
|
177
|
-
* repo_url_parse(undefined)
|
|
178
|
-
* // => null
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
export const repo_url_parse = (repository: PackageJson['repository']): string | null => {
|
|
182
|
-
if (!repository) return null;
|
|
183
|
-
const url = typeof repository === 'string' ? repository : repository.url;
|
|
184
|
-
if (!url) return null;
|
|
185
|
-
return strip_end(strip_start(strip_end(url, '.git'), 'git+'), '/');
|
|
186
|
-
};
|