@ucdjs/pipelines-loader 0.0.1-beta.6 → 0.0.1-beta.8

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.
@@ -1,18 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __defProp = Object.defineProperty;
3
- var __exportAll = (all, no_symbols) => {
4
- let target = {};
5
- for (var name in all) {
6
- __defProp(target, name, {
7
- get: all[name],
8
- enumerable: true
9
- });
10
- }
11
- if (!no_symbols) {
12
- __defProp(target, Symbol.toStringTag, { value: "Module" });
13
- }
14
- return target;
15
- };
16
-
17
- //#endregion
18
- export { __exportAll as t };
@@ -1,346 +0,0 @@
1
- import { t as __exportAll } from "./chunk-DQk6qfdC.mjs";
2
- import { isPipelineDefinition } from "@ucdjs/pipelines-core";
3
- import path from "node:path";
4
- import { build } from "rolldown";
5
- import { parseSync } from "oxc-parser";
6
- import { readFile } from "node:fs/promises";
7
- import { transform } from "oxc-transform";
8
-
9
- //#region src/bundler/identifiers.ts
10
- function isUrlLike(value) {
11
- return /^[a-z][a-z+.-]*:/i.test(value);
12
- }
13
- function parseRemoteIdentifier(identifier) {
14
- if (!identifier.startsWith("github://") && !identifier.startsWith("gitlab://")) return null;
15
- const url = new URL(identifier);
16
- const provider = url.protocol.replace(":", "");
17
- const owner = url.hostname;
18
- const repo = url.pathname.replace(/^\/+/, "");
19
- if (!owner || !repo) throw new Error(`Invalid remote identifier: ${identifier}`);
20
- return {
21
- provider,
22
- owner,
23
- repo,
24
- ref: url.searchParams.get("ref") ?? "HEAD",
25
- path: url.searchParams.get("path") ?? ""
26
- };
27
- }
28
- function formatRemoteIdentifier(remote) {
29
- const url = new URL(`${remote.provider}://${remote.owner}/${remote.repo}`);
30
- url.searchParams.set("ref", remote.ref);
31
- url.searchParams.set("path", remote.path);
32
- return url.toString();
33
- }
34
- function formatRemoteIdentifierFromParts(provider, owner, repo, ref, filePath) {
35
- return formatRemoteIdentifier({
36
- provider,
37
- owner,
38
- repo,
39
- ref: ref ?? "HEAD",
40
- path: filePath
41
- });
42
- }
43
-
44
- //#endregion
45
- //#region src/bundler/errors.ts
46
- var RemoteNotFoundError = class extends Error {
47
- name = "RemoteNotFoundError";
48
- constructor(message) {
49
- super(message);
50
- }
51
- };
52
-
53
- //#endregion
54
- //#region src/bundler/parse.ts
55
- function getStaticImportSpecifiers(source, identifier) {
56
- let parsed;
57
- try {
58
- parsed = parseSync(identifier ?? "<inline>", source, { sourceType: "module" });
59
- } catch (error) {
60
- const message = error instanceof Error ? error.message : String(error);
61
- throw new Error(`Failed to parse module ${identifier ?? "<inline>"}: ${message}`);
62
- }
63
- const specifiers = /* @__PURE__ */ new Set();
64
- const visit = (value) => {
65
- if (!value) return;
66
- if (Array.isArray(value)) {
67
- for (const item of value) visit(item);
68
- return;
69
- }
70
- if (typeof value !== "object") return;
71
- const node = value;
72
- if (node.type === "ImportDeclaration") {
73
- const sourceNode = node.source;
74
- if (sourceNode?.value) specifiers.add(sourceNode.value);
75
- } else if (node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration") {
76
- const sourceNode = node.source;
77
- if (sourceNode?.value) specifiers.add(sourceNode.value);
78
- } else if (node.type === "ImportExpression") {
79
- const sourceNode = node.source ?? node.argument;
80
- if (sourceNode?.type === "StringLiteral" && sourceNode.value) specifiers.add(sourceNode.value);
81
- }
82
- for (const [key, child] of Object.entries(node)) {
83
- if (key === "parent") continue;
84
- visit(child);
85
- }
86
- };
87
- visit(parsed.program);
88
- return Array.from(specifiers);
89
- }
90
-
91
- //#endregion
92
- //#region src/bundler/resolve.ts
93
- const EXTENSIONS = [
94
- ".ts",
95
- ".mts",
96
- ".js",
97
- ".mjs"
98
- ];
99
- function assertRelativeSpecifier(specifier) {
100
- if (isUrlLike(specifier)) throw new Error(`Unsupported import specifier: ${specifier}`);
101
- if (!specifier.startsWith("./") && !specifier.startsWith("../")) throw new Error(`Unsupported import specifier: ${specifier}`);
102
- }
103
- function stripTrailingSlash(value) {
104
- return value.endsWith("/") ? value.slice(0, -1) : value;
105
- }
106
- function appendSuffix(identifier, suffix) {
107
- const remote = parseRemoteIdentifier(identifier);
108
- if (remote) return formatRemoteIdentifier({
109
- ...remote,
110
- path: `${remote.path}${suffix}`
111
- });
112
- if (isUrlLike(identifier)) {
113
- const url = new URL(identifier);
114
- url.pathname = `${url.pathname}${suffix}`;
115
- return url.toString();
116
- }
117
- return `${identifier}${suffix}`;
118
- }
119
- function resolveRelativeSpecifier(specifier, parentIdentifier) {
120
- const remote = parseRemoteIdentifier(parentIdentifier);
121
- if (remote) {
122
- const parentDir = remote.path ? path.posix.dirname(remote.path) : "";
123
- const cleanPath = path.posix.normalize(path.posix.join(parentDir, specifier)).replace(/^\/+/, "");
124
- return formatRemoteIdentifier({
125
- ...remote,
126
- path: cleanPath
127
- });
128
- }
129
- if (isUrlLike(parentIdentifier)) {
130
- const base = new URL(parentIdentifier);
131
- return new URL(specifier, base).toString();
132
- }
133
- const parentDir = path.dirname(parentIdentifier);
134
- return path.resolve(parentDir, specifier);
135
- }
136
- function getSpecifierExtension(specifier) {
137
- return path.posix.extname(specifier);
138
- }
139
- function buildCandidateIdentifiers(specifier, parentIdentifier) {
140
- const resolvedBase = resolveRelativeSpecifier(specifier, parentIdentifier);
141
- if (getSpecifierExtension(specifier) !== "") return [resolvedBase];
142
- const normalizedBase = stripTrailingSlash(resolvedBase);
143
- const candidates = [];
144
- for (const ext of EXTENSIONS) candidates.push(appendSuffix(normalizedBase, ext));
145
- for (const ext of EXTENSIONS) candidates.push(appendSuffix(`${normalizedBase}/index`, ext));
146
- return candidates;
147
- }
148
-
149
- //#endregion
150
- //#region src/remote/github.ts
151
- var github_exports = /* @__PURE__ */ __exportAll({
152
- fetchFile: () => fetchFile$1,
153
- listFiles: () => listFiles$1
154
- });
155
- const GITHUB_API_BASE = "https://api.github.com";
156
- const GITHUB_ACCEPT_HEADER = "application/vnd.github.v3+json";
157
- async function listFiles$1(repoRef, options = {}) {
158
- const { owner, repo, ref = "HEAD", path = "" } = repoRef;
159
- const { customFetch = fetch } = options;
160
- const response = await customFetch(`${GITHUB_API_BASE}/repos/${owner}/${repo}/git/trees/${ref}?recursive=1`, { headers: { Accept: GITHUB_ACCEPT_HEADER } });
161
- if (!response.ok) throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
162
- const data = await response.json();
163
- const prefix = path ? `${path}/` : "";
164
- return {
165
- files: data.tree.filter((item) => item.type === "blob" && item.path.startsWith(prefix)).map((item) => item.path),
166
- truncated: data.truncated
167
- };
168
- }
169
- async function fetchFile$1(repoRef, filePath, options = {}) {
170
- const { owner, repo, ref = "HEAD" } = repoRef;
171
- const { customFetch = fetch } = options;
172
- const response = await customFetch(`${GITHUB_API_BASE}/repos/${owner}/${repo}/contents/${encodeURIComponent(filePath)}?ref=${ref}`, { headers: { Accept: GITHUB_ACCEPT_HEADER } });
173
- if (!response.ok) {
174
- if (response.status === 404) throw new RemoteNotFoundError(`GitHub file not found: ${filePath}`);
175
- throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
176
- }
177
- const data = await response.json();
178
- if (data.encoding !== "base64") throw new Error(`Unexpected encoding: ${data.encoding}`);
179
- return Buffer.from(data.content, "base64").toString("utf-8");
180
- }
181
-
182
- //#endregion
183
- //#region src/remote/gitlab.ts
184
- var gitlab_exports = /* @__PURE__ */ __exportAll({
185
- fetchFile: () => fetchFile,
186
- listFiles: () => listFiles
187
- });
188
- const GITLAB_API_BASE = "https://gitlab.com/api/v4";
189
- function encodeProjectPath(owner, repo) {
190
- return encodeURIComponent(`${owner}/${repo}`);
191
- }
192
- async function listFiles(repoRef, options = {}) {
193
- const { owner, repo, ref, path } = repoRef;
194
- const refValue = ref ?? "HEAD";
195
- const pathValue = path ?? "";
196
- const { customFetch = fetch } = options;
197
- const projectId = encodeProjectPath(owner, repo);
198
- const encodedPath = encodeURIComponent(pathValue);
199
- const files = [];
200
- let truncated = false;
201
- async function fetchPage(page) {
202
- const response = await customFetch(`${GITLAB_API_BASE}/projects/${projectId}/repository/tree?recursive=true&ref=${refValue}&path=${encodedPath}&per_page=100&page=${page}`);
203
- if (!response.ok) throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
204
- const data = await response.json();
205
- files.push(...data.filter((item) => item.type === "blob").map((item) => item.path));
206
- const nextPage = response.headers.get("x-next-page");
207
- if (!nextPage) return;
208
- const nextPageNumber = Number(nextPage);
209
- if (!Number.isFinite(nextPageNumber) || nextPageNumber <= page) {
210
- truncated = true;
211
- return;
212
- }
213
- await fetchPage(nextPageNumber);
214
- }
215
- await fetchPage(1);
216
- return {
217
- files,
218
- truncated
219
- };
220
- }
221
- async function fetchFile(repoRef, filePath, options = {}) {
222
- const { owner, repo, ref } = repoRef;
223
- const refValue = ref ?? "HEAD";
224
- const { customFetch = fetch } = options;
225
- const response = await customFetch(`${GITLAB_API_BASE}/projects/${encodeProjectPath(owner, repo)}/repository/files/${encodeURIComponent(filePath)}/raw?ref=${refValue}`);
226
- if (!response.ok) {
227
- if (response.status === 404) throw new RemoteNotFoundError(`GitLab file not found: ${filePath}`);
228
- throw new Error(`GitLab API error: ${response.status} ${response.statusText}`);
229
- }
230
- return response.text();
231
- }
232
-
233
- //#endregion
234
- //#region src/bundler/source.ts
235
- async function loadRemoteSource(identifier, customFetch) {
236
- const remote = parseRemoteIdentifier(identifier);
237
- if (!remote) {
238
- if (isUrlLike(identifier)) throw new Error(`Unsupported import specifier: ${identifier}`);
239
- try {
240
- return await readFile(identifier, "utf-8");
241
- } catch (error) {
242
- if (error instanceof Error && "code" in error && error.code === "ENOENT") throw new RemoteNotFoundError(`Module not found: ${identifier}`);
243
- throw error;
244
- }
245
- }
246
- const repoRef = {
247
- owner: remote.owner,
248
- repo: remote.repo,
249
- ref: remote.ref
250
- };
251
- if (remote.provider === "github") return fetchFile$1(repoRef, remote.path, { customFetch });
252
- return fetchFile(repoRef, remote.path, { customFetch });
253
- }
254
- async function compileModuleSource(identifier, source) {
255
- let filename;
256
- try {
257
- const url = new URL(identifier);
258
- filename = url.searchParams.get("path") ?? (url.pathname || identifier);
259
- } catch {
260
- filename = identifier;
261
- }
262
- const result = await transform(filename, source, { sourceType: "module" });
263
- if (result.errors && result.errors.length > 0) {
264
- const message = result.errors.map((error) => error.message).join("\n");
265
- throw new Error(`Failed to parse module ${identifier}: ${message}`);
266
- }
267
- return result.code;
268
- }
269
-
270
- //#endregion
271
- //#region src/bundler/bundle.ts
272
- function createRemotePlugin(input) {
273
- const customFetch = input.customFetch ?? fetch;
274
- const moduleCache = /* @__PURE__ */ new Map();
275
- return {
276
- name: "pipeline-remote-loader",
277
- resolveId: async (specifier, importer) => {
278
- if (!importer) return input.identifier;
279
- assertRelativeSpecifier(specifier);
280
- const candidates = buildCandidateIdentifiers(specifier, importer);
281
- for (const candidate of candidates) try {
282
- const source = await loadRemoteSource(candidate, customFetch);
283
- moduleCache.set(candidate, source);
284
- return candidate;
285
- } catch (err) {
286
- if (err instanceof RemoteNotFoundError) continue;
287
- throw err;
288
- }
289
- throw new Error(`Module not found: ${specifier}`);
290
- },
291
- load: async (id) => {
292
- if (id === input.identifier) return compileModuleSource(id, input.content);
293
- const source = moduleCache.get(id) ?? await loadRemoteSource(id, customFetch);
294
- const code = await compileModuleSource(id, source);
295
- moduleCache.set(id, source);
296
- return code;
297
- }
298
- };
299
- }
300
- async function bundleRemoteModule(input) {
301
- const specifiers = getStaticImportSpecifiers(input.content, input.identifier);
302
- for (const specifier of specifiers) assertRelativeSpecifier(specifier);
303
- const result = await build({
304
- input: input.identifier,
305
- plugins: [createRemotePlugin(input)],
306
- write: false,
307
- output: { format: "esm" }
308
- });
309
- const chunk = (Array.isArray(result) ? result : [result]).flatMap((output) => output.output ?? []).find((item) => item.type === "chunk");
310
- if (!chunk || chunk.type !== "chunk") throw new Error("Failed to bundle remote module");
311
- return chunk.code;
312
- }
313
- function createDataUrl(code) {
314
- return `data:text/javascript;base64,${Buffer.from(code, "utf-8").toString("base64")}`;
315
- }
316
- function identifierForLocalFile(filePath) {
317
- return path.resolve(filePath);
318
- }
319
-
320
- //#endregion
321
- //#region src/insecure.ts
322
- async function loadPipelineFromContent(content, filename, options = {}) {
323
- const module = await import(createDataUrl(await bundleRemoteModule({
324
- content,
325
- identifier: options.identifier ?? identifierForLocalFile(path.resolve(filename)),
326
- customFetch: options.customFetch
327
- })));
328
- const pipelines = [];
329
- const exportNames = [];
330
- const exportedModule = module;
331
- for (const [name, value] of Object.entries(exportedModule)) {
332
- if (name === "default") continue;
333
- if (isPipelineDefinition(value)) {
334
- pipelines.push(value);
335
- exportNames.push(name);
336
- }
337
- }
338
- return {
339
- filePath: filename,
340
- pipelines,
341
- exportNames
342
- };
343
- }
344
-
345
- //#endregion
346
- export { fetchFile$1 as a, formatRemoteIdentifierFromParts as c, listFiles as i, fetchFile as n, github_exports as o, gitlab_exports as r, listFiles$1 as s, loadPipelineFromContent as t };
@@ -1,10 +0,0 @@
1
- import { i as LoadedPipelineFile } from "./types-Br8gGmsN.mjs";
2
-
3
- //#region src/insecure.d.ts
4
- interface LoadPipelineFromContentOptions {
5
- identifier?: string;
6
- customFetch?: typeof fetch;
7
- }
8
- declare function loadPipelineFromContent(content: string, filename: string, options?: LoadPipelineFromContentOptions): Promise<LoadedPipelineFile>;
9
- //#endregion
10
- export { LoadPipelineFromContentOptions, loadPipelineFromContent };
package/dist/insecure.mjs DELETED
@@ -1,3 +0,0 @@
1
- import { t as loadPipelineFromContent } from "./insecure-lzOoh_sk.mjs";
2
-
3
- export { loadPipelineFromContent };
@@ -1,46 +0,0 @@
1
- import { n as GitLabSource, r as LoadPipelinesResult, t as GitHubSource } from "./types-Br8gGmsN.mjs";
2
-
3
- //#region src/remote/types.d.ts
4
- interface RemoteFileList {
5
- files: string[];
6
- truncated: boolean;
7
- }
8
- interface RemoteRequestOptions {
9
- customFetch?: typeof fetch;
10
- }
11
- declare namespace github_d_exports {
12
- export { fetchFile$1 as fetchFile, listFiles$1 as listFiles };
13
- }
14
- interface GitHubRepoRef {
15
- owner: string;
16
- repo: string;
17
- ref?: string;
18
- path?: string;
19
- }
20
- declare function listFiles$1(repoRef: GitHubRepoRef, options?: RemoteRequestOptions): Promise<RemoteFileList>;
21
- declare function fetchFile$1(repoRef: GitHubRepoRef, filePath: string, options?: RemoteRequestOptions): Promise<string>;
22
- declare namespace gitlab_d_exports {
23
- export { GitLabRepoRef, fetchFile, listFiles };
24
- }
25
- interface GitLabRepoRef {
26
- owner: string;
27
- repo: string;
28
- ref?: string;
29
- path?: string;
30
- }
31
- declare function listFiles(repoRef: GitLabRepoRef, options?: RemoteRequestOptions): Promise<RemoteFileList>;
32
- declare function fetchFile(repoRef: GitLabRepoRef, filePath: string, options?: RemoteRequestOptions): Promise<string>;
33
- //#endregion
34
- //#region src/remote.d.ts
35
- interface FindRemotePipelineFilesOptions {
36
- pattern?: string;
37
- customFetch?: typeof fetch;
38
- }
39
- declare function findRemotePipelineFiles(source: GitHubSource | GitLabSource, options?: FindRemotePipelineFilesOptions): Promise<RemoteFileList>;
40
- interface LoadRemotePipelinesOptions {
41
- throwOnError?: boolean;
42
- customFetch?: typeof fetch;
43
- }
44
- declare function loadRemotePipelines(source: GitHubSource | GitLabSource, filePaths: string[], options?: LoadRemotePipelinesOptions): Promise<LoadPipelinesResult>;
45
- //#endregion
46
- export { gitlab_d_exports as a, loadRemotePipelines as i, LoadRemotePipelinesOptions as n, github_d_exports as o, findRemotePipelineFiles as r, FindRemotePipelineFilesOptions as t };
package/dist/remote.d.mts DELETED
@@ -1,3 +0,0 @@
1
- import "./types-Br8gGmsN.mjs";
2
- import { a as gitlab_d_exports, i as loadRemotePipelines, n as LoadRemotePipelinesOptions, o as github_d_exports, r as findRemotePipelineFiles, t as FindRemotePipelineFilesOptions } from "./remote-PQ_FXnt1.mjs";
3
- export { FindRemotePipelineFilesOptions, LoadRemotePipelinesOptions, findRemotePipelineFiles, github_d_exports as github, gitlab_d_exports as gitlab, loadRemotePipelines };
package/dist/remote.mjs DELETED
@@ -1,76 +0,0 @@
1
- import { a as fetchFile, c as formatRemoteIdentifierFromParts, i as listFiles$1, n as fetchFile$1, o as github_exports, r as gitlab_exports, s as listFiles, t as loadPipelineFromContent } from "./insecure-lzOoh_sk.mjs";
2
- import picomatch from "picomatch";
3
-
4
- //#region src/remote.ts
5
- async function findRemotePipelineFiles(source, options = {}) {
6
- const { pattern = "**/*.ucd-pipeline.ts", customFetch = fetch } = options;
7
- const { owner, repo, ref, path } = source;
8
- const repoRef = {
9
- owner,
10
- repo,
11
- ref,
12
- path
13
- };
14
- let fileList;
15
- if (source.type === "github") fileList = await listFiles(repoRef, { customFetch });
16
- else fileList = await listFiles$1(repoRef, { customFetch });
17
- const isMatch = picomatch(pattern, { dot: true });
18
- return {
19
- files: fileList.files.filter((file) => isMatch(file)),
20
- truncated: fileList.truncated
21
- };
22
- }
23
- function buildRemoteIdentifier(provider, owner, repo, ref, filePath) {
24
- return formatRemoteIdentifierFromParts(provider, owner, repo, ref, filePath);
25
- }
26
- async function loadRemotePipelines(source, filePaths, options = {}) {
27
- const { throwOnError = false, customFetch = fetch } = options;
28
- const { owner, repo, ref, type } = source;
29
- const repoRef = {
30
- owner,
31
- repo,
32
- ref
33
- };
34
- if (throwOnError) {
35
- const wrapped = filePaths.map((filePath) => (type === "github" ? fetchFile(repoRef, filePath, { customFetch }) : fetchFile$1(repoRef, filePath, { customFetch })).then((content) => loadPipelineFromContent(content, filePath, {
36
- identifier: buildRemoteIdentifier(type, owner, repo, ref, filePath),
37
- customFetch
38
- })).catch((err) => {
39
- const error = err instanceof Error ? err : new Error(String(err));
40
- throw new Error(`Failed to load pipeline file: ${filePath}`, { cause: error });
41
- }));
42
- const results = await Promise.all(wrapped);
43
- return {
44
- pipelines: results.flatMap((r) => r.pipelines),
45
- files: results,
46
- errors: []
47
- };
48
- }
49
- const settled = await Promise.allSettled(filePaths.map(async (filePath) => {
50
- return loadPipelineFromContent(type === "github" ? await fetchFile(repoRef, filePath, { customFetch }) : await fetchFile$1(repoRef, filePath, { customFetch }), filePath, {
51
- identifier: buildRemoteIdentifier(type, owner, repo, ref, filePath),
52
- customFetch
53
- });
54
- }));
55
- const files = [];
56
- const errors = [];
57
- for (const [i, result] of settled.entries()) {
58
- if (result.status === "fulfilled") {
59
- files.push(result.value);
60
- continue;
61
- }
62
- const error = result.reason instanceof Error ? result.reason : new Error(String(result.reason));
63
- errors.push({
64
- filePath: filePaths[i],
65
- error
66
- });
67
- }
68
- return {
69
- pipelines: files.flatMap((f) => f.pipelines),
70
- files,
71
- errors
72
- };
73
- }
74
-
75
- //#endregion
76
- export { findRemotePipelineFiles, github_exports as github, gitlab_exports as gitlab, loadRemotePipelines };
@@ -1,41 +0,0 @@
1
- import { PipelineDefinition } from "@ucdjs/pipelines-core";
2
-
3
- //#region src/types.d.ts
4
- interface LoadedPipelineFile {
5
- filePath: string;
6
- pipelines: PipelineDefinition[];
7
- exportNames: string[];
8
- }
9
- interface LoadPipelinesResult {
10
- pipelines: PipelineDefinition[];
11
- files: LoadedPipelineFile[];
12
- errors: PipelineLoadError[];
13
- }
14
- interface PipelineLoadError {
15
- filePath: string;
16
- error: Error;
17
- }
18
- interface GitHubSource {
19
- type: "github";
20
- id: string;
21
- owner: string;
22
- repo: string;
23
- ref?: string;
24
- path?: string;
25
- }
26
- interface GitLabSource {
27
- type: "gitlab";
28
- id: string;
29
- owner: string;
30
- repo: string;
31
- ref?: string;
32
- path?: string;
33
- }
34
- interface LocalSource {
35
- type: "local";
36
- id: string;
37
- cwd: string;
38
- }
39
- type PipelineSource = LocalSource | GitHubSource | GitLabSource;
40
- //#endregion
41
- export { LocalSource as a, LoadedPipelineFile as i, GitLabSource as n, PipelineLoadError as o, LoadPipelinesResult as r, PipelineSource as s, GitHubSource as t };