@reliverse/dler 1.2.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.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +312 -0
  3. package/bin/cli/args/agg/main.js +0 -0
  4. package/bin/cli/args/conv/README.md +3 -0
  5. package/bin/cli/args/conv/main.js +0 -0
  6. package/bin/cli/args/deps/analyzer.js +42 -0
  7. package/bin/cli/args/deps/filesystem.js +42 -0
  8. package/bin/cli/args/deps/formatter.js +65 -0
  9. package/bin/cli/args/deps/mod.js +48 -0
  10. package/bin/cli/args/deps/parser.js +59 -0
  11. package/bin/cli/args/deps/types.js +0 -0
  12. package/bin/cli/args/init/README.md +121 -0
  13. package/bin/cli/args/init/libs/reinit/reinit-main.js +5 -0
  14. package/bin/cli/args/init/libs/reinit/reint-impl/const.js +26 -0
  15. package/bin/cli/args/init/libs/reinit/reint-impl/mod.txt +395 -0
  16. package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-gitignore.js +9 -0
  17. package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-license.js +22 -0
  18. package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-readme.js +59 -0
  19. package/bin/cli/args/init/libs/reinit/reint-impl/types.js +0 -0
  20. package/bin/cli/args/init/libs/reinit/reint-impl/utils.js +3 -0
  21. package/bin/cli/args/init/main.txt +121 -0
  22. package/bin/cli/args/init/types.js +1 -0
  23. package/bin/cli/args/inject/README.md +148 -0
  24. package/bin/cli/args/inject/arg-ts-expect-error.txt +49 -0
  25. package/bin/cli/args/inject/cli-mod.js +32 -0
  26. package/bin/cli/args/inject/main.txt +28 -0
  27. package/bin/cli/args/inject/reinject.config.js +4 -0
  28. package/bin/cli/args/inject/ts-expect-error.txt +277 -0
  29. package/bin/cli/args/merger/README.md +125 -0
  30. package/bin/cli/args/merger/main.txt +306 -0
  31. package/bin/cli/args/mono/main.js +0 -0
  32. package/bin/cli/args/spells/mod.js +44 -0
  33. package/bin/cli/args/split/README.md +13 -0
  34. package/bin/cli/args/split/split-main.js +26 -0
  35. package/bin/cli/args/split/split-mod.js +117 -0
  36. package/bin/cli/args/tools/index.js +81 -0
  37. package/bin/cli/args/tools/tools-impl.js +296 -0
  38. package/bin/cli.js +111 -0
  39. package/bin/init.js +157 -0
  40. package/bin/libs/cfg/cfg-default.js +50 -0
  41. package/bin/libs/cfg/cfg-main.js +1 -0
  42. package/bin/libs/cfg/cfg-mod.js +4 -0
  43. package/bin/libs/cfg/cfg-types.js +1 -0
  44. package/bin/libs/sdk/sdk-impl/build/build-library.js +865 -0
  45. package/bin/libs/sdk/sdk-impl/build/build-regular.js +373 -0
  46. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/auto.js +110 -0
  47. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +322 -0
  48. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/copy.js +62 -0
  49. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/types.js +0 -0
  50. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist.js +57 -0
  51. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/types.js +0 -0
  52. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/build.js +104 -0
  53. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/config.js +124 -0
  54. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/cjs.js +48 -0
  55. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/esbuild.js +91 -0
  56. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/json.js +17 -0
  57. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/raw.js +20 -0
  58. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/shebang.js +42 -0
  59. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/stub.js +137 -0
  60. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/types.js +0 -0
  61. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/utils.js +41 -0
  62. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/watch.js +33 -0
  63. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/types.js +6 -0
  64. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/index.js +125 -0
  65. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/types.js +0 -0
  66. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/utils.js +158 -0
  67. package/bin/libs/sdk/sdk-impl/build/bundlers/unified/validate.js +68 -0
  68. package/bin/libs/sdk/sdk-impl/library-flow.js +169 -0
  69. package/bin/libs/sdk/sdk-impl/pub/pub-library.js +132 -0
  70. package/bin/libs/sdk/sdk-impl/pub/pub-regular.js +69 -0
  71. package/bin/libs/sdk/sdk-impl/regular-flow.js +219 -0
  72. package/bin/libs/sdk/sdk-impl/spells/spells-executors.js +307 -0
  73. package/bin/libs/sdk/sdk-impl/spells/spells-filesystem.js +72 -0
  74. package/bin/libs/sdk/sdk-impl/spells/spells-main.js +87 -0
  75. package/bin/libs/sdk/sdk-impl/spells/spells-parser.js +60 -0
  76. package/bin/libs/sdk/sdk-impl/spells/spells-types.js +0 -0
  77. package/bin/libs/sdk/sdk-impl/utils/tools/tools-agg.js +149 -0
  78. package/bin/libs/sdk/sdk-impl/utils/tools/tools-impl.js +21 -0
  79. package/bin/libs/sdk/sdk-impl/utils/utils-build.js +102 -0
  80. package/bin/libs/sdk/sdk-impl/utils/utils-bump.js +238 -0
  81. package/bin/libs/sdk/sdk-impl/utils/utils-clean.js +35 -0
  82. package/bin/libs/sdk/sdk-impl/utils/utils-consts.js +17 -0
  83. package/bin/libs/sdk/sdk-impl/utils/utils-cwd.js +36 -0
  84. package/bin/libs/sdk/sdk-impl/utils/utils-deps.js +73 -0
  85. package/bin/libs/sdk/sdk-impl/utils/utils-determine.js +25 -0
  86. package/bin/libs/sdk/sdk-impl/utils/utils-error.js +17 -0
  87. package/bin/libs/sdk/sdk-impl/utils/utils-fs.js +202 -0
  88. package/bin/libs/sdk/sdk-impl/utils/utils-info.js +42 -0
  89. package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.js +51 -0
  90. package/bin/libs/sdk/sdk-impl/utils/utils-paths.js +658 -0
  91. package/bin/libs/sdk/sdk-impl/utils/utils-perf.js +22 -0
  92. package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-libs.js +259 -0
  93. package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-reg.js +207 -0
  94. package/bin/libs/sdk/sdk-impl/utils/utils-tsconfig.js +44 -0
  95. package/bin/libs/sdk/sdk-main.js +114 -0
  96. package/bin/libs/sdk/sdk-types.js +1 -0
  97. package/bin/load.js +27 -0
  98. package/bin/main.js +46 -0
  99. package/bin/tools.txt +92 -0
  100. package/bin/types.js +0 -0
  101. package/package.json +93 -0
@@ -0,0 +1,48 @@
1
+ import { FixDtsDefaultCjsExportsPlugin } from "fix-dts-default-cjs-exports/rollup";
2
+ import MagicString from "magic-string";
3
+ import { findStaticImports } from "mlly";
4
+ export function cjsPlugin() {
5
+ return {
6
+ name: "dler-cjs",
7
+ renderChunk(code, _chunk, opts) {
8
+ if (opts.format === "es") {
9
+ const result = CJSToESM(code);
10
+ return result || null;
11
+ }
12
+ return null;
13
+ }
14
+ };
15
+ }
16
+ export function fixCJSExportTypePlugin(ctx) {
17
+ const regexp = ctx.options.declaration === "node16" ? /\.d\.cts$/ : /\.d\.c?ts$/;
18
+ return FixDtsDefaultCjsExportsPlugin({
19
+ matcher: (info) => {
20
+ return info.type === "chunk" && info.exports?.length > 0 && info.exports.includes("default") && regexp.test(info.fileName) && info.isEntry;
21
+ },
22
+ warn: (msg) => ctx.warnings.add(msg)
23
+ });
24
+ }
25
+ const CJSyntaxRe = /__filename|__dirname|require\(|require\.resolve\(/;
26
+ const CJSShim = `
27
+
28
+ // -- dler CommonJS Shims --
29
+ import __cjs_url__ from 'url';
30
+ import __cjs_path__ from 'path';
31
+ import __cjs_mod__ from 'module';
32
+ const __filename = __cjs_url__.fileURLToPath(import.meta.url);
33
+ const __dirname = __cjs_path__.dirname(__filename);
34
+ const require = __cjs_mod__.createRequire(import.meta.url);
35
+ `;
36
+ function CJSToESM(code) {
37
+ if (code.includes(CJSShim) || !CJSyntaxRe.test(code)) {
38
+ return null;
39
+ }
40
+ const lastESMImport = findStaticImports(code).pop();
41
+ const indexToAppend = lastESMImport ? lastESMImport.end : 0;
42
+ const s = new MagicString(code);
43
+ s.appendRight(indexToAppend, CJSShim);
44
+ return {
45
+ code: s.toString(),
46
+ map: s.generateMap({ hires: true })
47
+ };
48
+ }
@@ -0,0 +1,91 @@
1
+ import { createFilter } from "@rollup/pluginutils";
2
+ import { transform } from "esbuild";
3
+ import { extname, relative } from "pathe";
4
+ const DefaultLoaders = {
5
+ ".cjs": "js",
6
+ ".cts": "ts",
7
+ ".js": "js",
8
+ ".jsx": "jsx",
9
+ ".mjs": "js",
10
+ ".mts": "ts",
11
+ ".ts": "ts",
12
+ ".tsx": "tsx"
13
+ };
14
+ export function esbuild(options) {
15
+ const {
16
+ exclude = /node_modules/,
17
+ include = new RegExp(Object.keys(DefaultLoaders).join("|")),
18
+ loaders: loaderOptions,
19
+ ...transpileEsbuildOptions
20
+ } = options;
21
+ const loaders = { ...DefaultLoaders };
22
+ if (loaderOptions) {
23
+ for (const [key, value] of Object.entries(loaderOptions)) {
24
+ if (typeof value === "string") {
25
+ loaders[key] = value;
26
+ } else if (value === false) {
27
+ delete loaders[key];
28
+ }
29
+ }
30
+ }
31
+ const getLoader = (id = "") => {
32
+ return loaders[extname(id)];
33
+ };
34
+ const filter = createFilter(include, exclude);
35
+ return {
36
+ name: "transpileEsbuild",
37
+ async renderChunk(code, { fileName }) {
38
+ if (!options.minify) {
39
+ return null;
40
+ }
41
+ if (/\.d\.(c|m)?tsx?$/.test(fileName)) {
42
+ return null;
43
+ }
44
+ const loader = getLoader(fileName);
45
+ if (!loader) {
46
+ return null;
47
+ }
48
+ const result = await transform(code, {
49
+ ...transpileEsbuildOptions,
50
+ loader,
51
+ minify: true,
52
+ sourcefile: fileName
53
+ });
54
+ return {
55
+ code: result.code || "",
56
+ map: result.map || null
57
+ };
58
+ },
59
+ async transform(code, id) {
60
+ if (!filter(id)) {
61
+ return null;
62
+ }
63
+ const loader = getLoader(id);
64
+ if (!loader) {
65
+ return null;
66
+ }
67
+ const result = await transform(code, {
68
+ ...transpileEsbuildOptions,
69
+ loader,
70
+ sourcefile: id
71
+ });
72
+ printWarnings(id, result, this);
73
+ return {
74
+ code: result.code || "",
75
+ map: result.map || null
76
+ };
77
+ }
78
+ };
79
+ }
80
+ function printWarnings(id, result, plugin) {
81
+ if (result.warnings) {
82
+ for (const warning of result.warnings) {
83
+ let message = "[transpileEsbuild]";
84
+ if (warning.location) {
85
+ message += ` (${relative(process.cwd(), id)}:${warning.location.line}:${warning.location.column})`;
86
+ }
87
+ message += ` ${warning.text}`;
88
+ plugin.warn(message);
89
+ }
90
+ }
91
+ }
@@ -0,0 +1,17 @@
1
+ const jsonPluginModule = await import("@rollup/plugin-json");
2
+ const jsonPlugin = jsonPluginModule.default || jsonPluginModule;
3
+ const EXPORT_DEFAULT = "export default ";
4
+ export function JSONPlugin(options) {
5
+ const plugin = jsonPlugin(options);
6
+ return {
7
+ ...plugin,
8
+ name: "dler-json",
9
+ transform(code, id) {
10
+ const res = plugin.transform.call(this, code, id);
11
+ if (res && typeof res !== "string" && "code" in res && res.code?.startsWith(EXPORT_DEFAULT)) {
12
+ res.code = res.code.replace(EXPORT_DEFAULT, "module.exports = ");
13
+ }
14
+ return res;
15
+ }
16
+ };
17
+ }
@@ -0,0 +1,20 @@
1
+ import { createFilter } from "@rollup/pluginutils";
2
+ const defaults = {
3
+ exclude: [],
4
+ include: [/\.(md|txt|css|htm|html)$/]
5
+ };
6
+ export function rawPlugin(opts = {}) {
7
+ const options = { ...defaults, ...opts };
8
+ const filter = createFilter(options.include, options.exclude);
9
+ return {
10
+ name: "dler-raw",
11
+ transform(code, id) {
12
+ if (filter(id)) {
13
+ return {
14
+ code: `export default ${JSON.stringify(code)}`,
15
+ map: null
16
+ };
17
+ }
18
+ }
19
+ };
20
+ }
@@ -0,0 +1,42 @@
1
+ import { promises as fsp } from "node:fs";
2
+ import { resolve } from "pathe";
3
+ const SHEBANG_RE = /^#![^\n]*/;
4
+ export function getShebang(code, append = "\n") {
5
+ const m = SHEBANG_RE.exec(code);
6
+ return m ? m[0] + append : "";
7
+ }
8
+ export async function makeExecutable(filePath) {
9
+ await fsp.chmod(
10
+ filePath,
11
+ 493
12
+ /* rwx r-x r-x */
13
+ ).catch(() => {
14
+ });
15
+ }
16
+ export function removeShebangPlugin() {
17
+ return {
18
+ name: "dler-remove-shebang",
19
+ renderChunk(code) {
20
+ return code.replace(SHEBANG_RE, "");
21
+ }
22
+ };
23
+ }
24
+ export function shebangPlugin() {
25
+ return {
26
+ name: "dler-shebang",
27
+ async writeBundle(options, bundle) {
28
+ for (const [fileName, output] of Object.entries(bundle)) {
29
+ if (output.type !== "chunk") {
30
+ continue;
31
+ }
32
+ if (SHEBANG_RE.exec(output.code)) {
33
+ if (!options.dir) {
34
+ throw new Error("options.dir is required for shebang plugin");
35
+ }
36
+ const outFile = resolve(options.dir, fileName);
37
+ await makeExecutable(outFile);
38
+ }
39
+ }
40
+ }
41
+ };
42
+ }
@@ -0,0 +1,137 @@
1
+ import { fileURLToPath, resolveModuleExportNames, resolvePath } from "mlly";
2
+ import { promises as fsp } from "node:fs";
3
+ import { mkdir, writeFile } from "node:fs/promises";
4
+ import { basename, dirname, extname, relative, resolve } from "pathe";
5
+ import { warn } from "../utils.js";
6
+ import { getShebang, makeExecutable } from "./plugins/shebang.js";
7
+ import { DEFAULT_EXTENSIONS, resolveAliases } from "./utils.js";
8
+ export async function rollupStub(ctx) {
9
+ const babelPlugins = ctx.options.transpileStubOptions.jiti.transformOptions?.babel?.plugins;
10
+ const importedBabelPlugins = [];
11
+ const serializedJitiOptions = JSON.stringify(
12
+ {
13
+ ...ctx.options.transpileStubOptions.jiti,
14
+ alias: {
15
+ ...resolveAliases(ctx),
16
+ ...ctx.options.transpileStubOptions.jiti.alias
17
+ },
18
+ transformOptions: {
19
+ ...ctx.options.transpileStubOptions.jiti.transformOptions,
20
+ babel: {
21
+ ...ctx.options.transpileStubOptions.jiti.transformOptions?.babel,
22
+ plugins: "__$BABEL_PLUGINS"
23
+ }
24
+ }
25
+ },
26
+ null,
27
+ 2
28
+ ).replace(
29
+ '"__$BABEL_PLUGINS"',
30
+ Array.isArray(babelPlugins) ? `[${babelPlugins.map((plugin, i) => {
31
+ if (Array.isArray(plugin)) {
32
+ const [name, ...args] = plugin;
33
+ importedBabelPlugins.push(name);
34
+ return `[${[
35
+ `plugin${i}`,
36
+ ...args.map((val) => JSON.stringify(val))
37
+ ].join(", ")}]`;
38
+ }
39
+ importedBabelPlugins.push(plugin);
40
+ return `plugin${i}`;
41
+ }).join(",")}]` : "[]"
42
+ );
43
+ for (const entry of ctx.options.entries.filter(
44
+ (entry2) => entry2.builder === "rollup"
45
+ )) {
46
+ const output = resolve(
47
+ ctx.options.rootDir,
48
+ ctx.options.outDir,
49
+ entry.name || basename(entry.input, extname(entry.input))
50
+ );
51
+ const isESM = ctx.pkg.type === "module";
52
+ const resolvedEntry = fileURLToPath(ctx.jiti.esmResolve(entry.input));
53
+ const resolvedEntryWithoutExt = resolvedEntry.slice(
54
+ 0,
55
+ Math.max(0, resolvedEntry.length - extname(resolvedEntry).length)
56
+ );
57
+ const resolvedEntryForTypeImport = isESM ? resolvedEntry.replace(/(\.m?)(ts)$/, "$1js") : resolvedEntryWithoutExt;
58
+ const code = await fsp.readFile(resolvedEntry, "utf8");
59
+ const shebang = getShebang(code);
60
+ await mkdir(dirname(output), { recursive: true });
61
+ if (ctx.options.rollup.emitCJS) {
62
+ const jitiCJSPath = relative(
63
+ dirname(output),
64
+ await resolvePath("jiti", {
65
+ conditions: ["node", "require"],
66
+ url: import.meta.url
67
+ })
68
+ );
69
+ await writeFile(
70
+ `${output}.cjs`,
71
+ shebang + [
72
+ `const { createJiti } = require(${JSON.stringify(jitiCJSPath)})`,
73
+ ...importedBabelPlugins.map(
74
+ (plugin, i) => `const plugin${i} = require(${JSON.stringify(plugin)})`
75
+ ),
76
+ "",
77
+ `const jiti = createJiti(__filename, ${serializedJitiOptions})`,
78
+ "",
79
+ `/** @type {import(${JSON.stringify(
80
+ resolvedEntryForTypeImport
81
+ )})} */`,
82
+ `module.exports = jiti(${JSON.stringify(resolvedEntry)})`
83
+ ].join("\n")
84
+ );
85
+ }
86
+ const namedExports = await resolveModuleExportNames(
87
+ resolvedEntry,
88
+ {
89
+ extensions: DEFAULT_EXTENSIONS
90
+ }
91
+ ).catch((error) => {
92
+ warn(ctx, `Cannot analyze ${resolvedEntry} for exports:${error}`);
93
+ return [];
94
+ });
95
+ const hasDefaultExport = namedExports.includes("default") || namedExports.length === 0;
96
+ const jitiESMPath = relative(
97
+ dirname(output),
98
+ await resolvePath("jiti", {
99
+ conditions: ["node", "import"],
100
+ url: import.meta.url
101
+ })
102
+ );
103
+ await writeFile(
104
+ `${output}.mjs`,
105
+ shebang + [
106
+ `import { createJiti } from ${JSON.stringify(jitiESMPath)};`,
107
+ ...importedBabelPlugins.map(
108
+ (plugin, i) => `import plugin${i} from ${JSON.stringify(plugin)}`
109
+ ),
110
+ "",
111
+ `const jiti = createJiti(import.meta.url, ${serializedJitiOptions})`,
112
+ "",
113
+ `/** @type {import(${JSON.stringify(resolvedEntryForTypeImport)})} */`,
114
+ `const _module = await jiti.import(${JSON.stringify(
115
+ resolvedEntry
116
+ )});`,
117
+ hasDefaultExport ? "\nexport default _module?.default ?? _module;" : "",
118
+ ...namedExports.filter((name) => name !== "default").map((name) => `export const ${name} = _module.${name};`)
119
+ ].join("\n")
120
+ );
121
+ if (ctx.options.declaration) {
122
+ const dtsContent = [
123
+ `export * from ${JSON.stringify(resolvedEntryForTypeImport)};`,
124
+ hasDefaultExport ? `export { default } from ${JSON.stringify(resolvedEntryForTypeImport)};` : ""
125
+ ].join("\n");
126
+ await writeFile(`${output}.d.cts`, dtsContent);
127
+ await writeFile(`${output}.d.mts`, dtsContent);
128
+ if (ctx.options.declaration === "compatible" || ctx.options.declaration === true) {
129
+ await writeFile(`${output}.d.ts`, dtsContent);
130
+ }
131
+ }
132
+ if (shebang) {
133
+ await makeExecutable(`${output}.cjs`);
134
+ await makeExecutable(`${output}.mjs`);
135
+ }
136
+ }
137
+ }
@@ -0,0 +1,41 @@
1
+ export const DEFAULT_EXTENSIONS = [
2
+ ".ts",
3
+ ".tsx",
4
+ ".mts",
5
+ ".cts",
6
+ ".mjs",
7
+ ".cjs",
8
+ ".js",
9
+ ".jsx",
10
+ ".json"
11
+ ];
12
+ export function getChunkFilename(ctx, chunk, ext) {
13
+ if (chunk.isDynamicEntry) {
14
+ return `chunks/[name].${ext}`;
15
+ }
16
+ return `shared/${ctx.options.name}.[hash].${ext}`;
17
+ }
18
+ export function resolveAliases(ctx) {
19
+ const aliases = {
20
+ ...ctx.pkg.name ? { [ctx.pkg.name]: ctx.options.rootDir } : {},
21
+ ...ctx.options.alias
22
+ };
23
+ if (ctx.options.rollup.alias) {
24
+ if (Array.isArray(ctx.options.rollup.alias.entries)) {
25
+ Object.assign(
26
+ aliases,
27
+ Object.fromEntries(
28
+ ctx.options.rollup.alias.entries.map((entry) => {
29
+ return [entry.find, entry.replacement];
30
+ })
31
+ )
32
+ );
33
+ } else {
34
+ Object.assign(
35
+ aliases,
36
+ ctx.options.rollup.alias.entries || ctx.options.rollup.alias
37
+ );
38
+ }
39
+ }
40
+ return aliases;
41
+ }
@@ -0,0 +1,33 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import { relative } from "pathe";
3
+ import { watch as _rollupWatch } from "rollup";
4
+ export function rollupWatch(rollupOptions) {
5
+ const transpileWatcher = _rollupWatch(rollupOptions);
6
+ let inputs;
7
+ if (Array.isArray(rollupOptions.input)) {
8
+ inputs = rollupOptions.input;
9
+ } else if (typeof rollupOptions.input === "string") {
10
+ inputs = [rollupOptions.input];
11
+ } else {
12
+ inputs = Object.keys(rollupOptions.input || {});
13
+ }
14
+ relinka(
15
+ "info",
16
+ `[dler] [rollup] Starting watchers for entries: ${inputs.map((input) => `./${relative(process.cwd(), input)}`).join(", ")}`
17
+ );
18
+ relinka(
19
+ "warn",
20
+ "[dler] [rollup] Watch mode is experimental and may be unstable"
21
+ );
22
+ transpileWatcher.on("change", (id, { event }) => {
23
+ relinka("info", `${relative(".", id)} was ${event}d`);
24
+ });
25
+ transpileWatcher.on("restart", () => {
26
+ relinka("info", "[dler] [rollup] Rebuilding bundle");
27
+ });
28
+ transpileWatcher.on("event", (event) => {
29
+ if (event.code === "END") {
30
+ relinka("success", "[dler] [rollup] Rebuild finished\n");
31
+ }
32
+ });
33
+ }
@@ -0,0 +1,6 @@
1
+ export function defineBuildConfig(config) {
2
+ return (Array.isArray(config) ? config : [config]).filter(Boolean);
3
+ }
4
+ export function definePreset(preset) {
5
+ return preset;
6
+ }
@@ -0,0 +1,125 @@
1
+ import { relinka } from "@reliverse/relinka";
2
+ import { createJiti } from "jiti";
3
+ import { mkdir, writeFile } from "node:fs/promises";
4
+ import { resolve } from "pathe";
5
+ import { pascalCase } from "scule";
6
+ import {
7
+ generateMarkdown,
8
+ generateTypes,
9
+ resolveSchema
10
+ } from "untyped";
11
+ import untypedPlugin from "untyped/babel-plugin";
12
+ export async function typesBuild(ctx) {
13
+ const entries = ctx.options.entries.filter(
14
+ (entry) => entry.builder === "untyped"
15
+ );
16
+ if (entries.length === 0) {
17
+ return;
18
+ }
19
+ await ctx.hooks.callHook("untyped:entries", ctx, entries);
20
+ for (const entry of entries) {
21
+ try {
22
+ const distDir = entry.outDir;
23
+ if (!distDir) {
24
+ throw new Error(
25
+ `[untyped] Missing 'outDir' for entry '${entry.name}'. Please define an output directory.`
26
+ );
27
+ }
28
+ const jitiOptions = {
29
+ interopDefault: true,
30
+ transformOptions: {
31
+ babel: {
32
+ plugins: [untypedPlugin]
33
+ }
34
+ }
35
+ };
36
+ await ctx.hooks.callHook(
37
+ "untyped:entry:options",
38
+ ctx,
39
+ entry,
40
+ jitiOptions
41
+ );
42
+ const untypedJiti = createJiti(ctx.options.rootDir, jitiOptions);
43
+ const inputPath = resolve(ctx.options.rootDir, entry.input);
44
+ let rawSchemaModule;
45
+ try {
46
+ rawSchemaModule = await untypedJiti.import(inputPath);
47
+ } catch (importError) {
48
+ console.warn(
49
+ `[untyped] Failed to import schema for entry '${entry.name}' from ${inputPath}: ${importError.message}`
50
+ );
51
+ rawSchemaModule = {};
52
+ }
53
+ let rawSchema;
54
+ if (rawSchemaModule && typeof rawSchemaModule === "object" && "default" in rawSchemaModule && // Check if the default export itself is the intended schema object
55
+ typeof rawSchemaModule.default === "object" && rawSchemaModule.default !== null) {
56
+ rawSchema = rawSchemaModule.default;
57
+ } else if (typeof rawSchemaModule === "object" && rawSchemaModule !== null) {
58
+ rawSchema = rawSchemaModule;
59
+ } else {
60
+ console.warn(
61
+ `[untyped] Invalid schema input resolved for entry '${entry.name}' (path: ${entry.input}). Expected an object, got ${typeof rawSchemaModule}. Using empty schema.`
62
+ );
63
+ rawSchema = {};
64
+ }
65
+ const defaults = entry.defaults || {};
66
+ const schema = await resolveSchema(rawSchema, defaults);
67
+ await ctx.hooks.callHook("untyped:entry:schema", ctx, entry, schema);
68
+ const outputs = {
69
+ declaration: entry.declaration ? {
70
+ contents: generateTypes(schema, {
71
+ interfaceName: pascalCase(`${entry.name}-schema`)
72
+ // addDefaults: true, // TODO: Add JSDoc default values (allow to configure via .config/dler.ts)
73
+ // addDescription: true, // TODO: Add JSDoc descriptions (allow to configure via .config/dler.ts)
74
+ }),
75
+ fileName: `${entry.name}.d.ts`
76
+ } : void 0,
77
+ defaults: {
78
+ contents: JSON.stringify(defaults, null, 2),
79
+ fileName: `${entry.name}.defaults.json`
80
+ },
81
+ markdown: {
82
+ contents: generateMarkdown(schema),
83
+ fileName: `${entry.name}.md`
84
+ },
85
+ schema: {
86
+ contents: JSON.stringify(schema, null, 2),
87
+ fileName: `${entry.name}.schema.json`
88
+ }
89
+ };
90
+ await ctx.hooks.callHook("untyped:entry:outputs", ctx, entry, outputs);
91
+ await mkdir(distDir, { recursive: true });
92
+ const writePromises = [];
93
+ for (const output of Object.values(outputs)) {
94
+ if (!output) continue;
95
+ const fullOutputPath = resolve(distDir, output.fileName);
96
+ writePromises.push(
97
+ writeFile(fullOutputPath, output.contents, "utf8").catch(
98
+ (writeError) => {
99
+ console.error(
100
+ `[untyped] Failed to write output file ${fullOutputPath} for entry '${entry.name}': ${writeError.message}`
101
+ );
102
+ }
103
+ )
104
+ );
105
+ }
106
+ await Promise.all(writePromises);
107
+ relinka(
108
+ "verbose",
109
+ `[untyped] Generated outputs for '${entry.name}' in ${distDir}`
110
+ );
111
+ } catch (error) {
112
+ console.error(
113
+ `[untyped] Failed to process entry '${entry.name}': ${error.message}`,
114
+ error.stack
115
+ );
116
+ }
117
+ }
118
+ await ctx.hooks.callHook("untyped:done", ctx);
119
+ if (entries.length > 0 && ctx.options.transpileWatch) {
120
+ relinka(
121
+ "warn",
122
+ "`untyped` builder does not support transpileWatch mode effectively (schema changes may require manual rebuild)."
123
+ );
124
+ }
125
+ }