@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.
- package/LICENSE +21 -0
- package/README.md +312 -0
- package/bin/cli/args/agg/main.js +0 -0
- package/bin/cli/args/conv/README.md +3 -0
- package/bin/cli/args/conv/main.js +0 -0
- package/bin/cli/args/deps/analyzer.js +42 -0
- package/bin/cli/args/deps/filesystem.js +42 -0
- package/bin/cli/args/deps/formatter.js +65 -0
- package/bin/cli/args/deps/mod.js +48 -0
- package/bin/cli/args/deps/parser.js +59 -0
- package/bin/cli/args/deps/types.js +0 -0
- package/bin/cli/args/init/README.md +121 -0
- package/bin/cli/args/init/libs/reinit/reinit-main.js +5 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/const.js +26 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/mod.txt +395 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-gitignore.js +9 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-license.js +22 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/templates/t-readme.js +59 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/types.js +0 -0
- package/bin/cli/args/init/libs/reinit/reint-impl/utils.js +3 -0
- package/bin/cli/args/init/main.txt +121 -0
- package/bin/cli/args/init/types.js +1 -0
- package/bin/cli/args/inject/README.md +148 -0
- package/bin/cli/args/inject/arg-ts-expect-error.txt +49 -0
- package/bin/cli/args/inject/cli-mod.js +32 -0
- package/bin/cli/args/inject/main.txt +28 -0
- package/bin/cli/args/inject/reinject.config.js +4 -0
- package/bin/cli/args/inject/ts-expect-error.txt +277 -0
- package/bin/cli/args/merger/README.md +125 -0
- package/bin/cli/args/merger/main.txt +306 -0
- package/bin/cli/args/mono/main.js +0 -0
- package/bin/cli/args/spells/mod.js +44 -0
- package/bin/cli/args/split/README.md +13 -0
- package/bin/cli/args/split/split-main.js +26 -0
- package/bin/cli/args/split/split-mod.js +117 -0
- package/bin/cli/args/tools/index.js +81 -0
- package/bin/cli/args/tools/tools-impl.js +296 -0
- package/bin/cli.js +111 -0
- package/bin/init.js +157 -0
- package/bin/libs/cfg/cfg-default.js +50 -0
- package/bin/libs/cfg/cfg-main.js +1 -0
- package/bin/libs/cfg/cfg-mod.js +4 -0
- package/bin/libs/cfg/cfg-types.js +1 -0
- package/bin/libs/sdk/sdk-impl/build/build-library.js +865 -0
- package/bin/libs/sdk/sdk-impl/build/build-regular.js +373 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/auto.js +110 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +322 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/copy.js +62 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/copy/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist.js +57 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/build.js +104 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/config.js +124 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/cjs.js +48 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/esbuild.js +91 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/json.js +17 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/raw.js +20 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/plugins/shebang.js +42 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/stub.js +137 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/utils.js +41 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/rollup/watch.js +33 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/types.js +6 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/index.js +125 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/untyped/types.js +0 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/utils.js +158 -0
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/validate.js +68 -0
- package/bin/libs/sdk/sdk-impl/library-flow.js +169 -0
- package/bin/libs/sdk/sdk-impl/pub/pub-library.js +132 -0
- package/bin/libs/sdk/sdk-impl/pub/pub-regular.js +69 -0
- package/bin/libs/sdk/sdk-impl/regular-flow.js +219 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-executors.js +307 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-filesystem.js +72 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-main.js +87 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-parser.js +60 -0
- package/bin/libs/sdk/sdk-impl/spells/spells-types.js +0 -0
- package/bin/libs/sdk/sdk-impl/utils/tools/tools-agg.js +149 -0
- package/bin/libs/sdk/sdk-impl/utils/tools/tools-impl.js +21 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-build.js +102 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-bump.js +238 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-clean.js +35 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-consts.js +17 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-cwd.js +36 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-deps.js +73 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-determine.js +25 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-error.js +17 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-fs.js +202 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-info.js +42 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-jsr-json.js +51 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-paths.js +658 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-perf.js +22 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-libs.js +259 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-pkg-json-reg.js +207 -0
- package/bin/libs/sdk/sdk-impl/utils/utils-tsconfig.js +44 -0
- package/bin/libs/sdk/sdk-main.js +114 -0
- package/bin/libs/sdk/sdk-types.js +1 -0
- package/bin/load.js +27 -0
- package/bin/main.js +46 -0
- package/bin/tools.txt +92 -0
- package/bin/types.js +0 -0
- package/package.json +93 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import { createHooks } from "hookable";
|
|
4
|
+
import { createJiti } from "jiti";
|
|
5
|
+
import { promises as fsp } from "node:fs";
|
|
6
|
+
import Module from "node:module";
|
|
7
|
+
import { isAbsolute, normalize, relative, resolve } from "pathe";
|
|
8
|
+
import prettyBytes from "pretty-bytes";
|
|
9
|
+
import prettyMilliseconds from "pretty-ms";
|
|
10
|
+
import { glob } from "tinyglobby";
|
|
11
|
+
import {
|
|
12
|
+
createPerfTimer,
|
|
13
|
+
getElapsedPerfTime
|
|
14
|
+
} from "../../../utils/utils-perf.js";
|
|
15
|
+
import { copyBuild } from "./copy/copy.js";
|
|
16
|
+
import { mkdistBuild } from "./mkdist/mkdist.js";
|
|
17
|
+
import { rollupBuild } from "./rollup/build.js";
|
|
18
|
+
import { typesBuild } from "./untyped/index.js";
|
|
19
|
+
import {
|
|
20
|
+
dumpObject,
|
|
21
|
+
inferPkgExternals,
|
|
22
|
+
removeExtension,
|
|
23
|
+
resolvePreset,
|
|
24
|
+
rmdir,
|
|
25
|
+
withTrailingSlash
|
|
26
|
+
} from "./utils.js";
|
|
27
|
+
import { validateDependencies, validatePackage } from "./validate.js";
|
|
28
|
+
export async function build(rootDir, inputConfig, outDir, transpileStub = false) {
|
|
29
|
+
const resolvedRootDir = resolve(process.cwd(), rootDir || ".");
|
|
30
|
+
const jiti = createJiti(resolvedRootDir);
|
|
31
|
+
const _buildConfig = await jiti.import(inputConfig?.config || ".config/dler.ts", {
|
|
32
|
+
default: true,
|
|
33
|
+
try: !inputConfig.config
|
|
34
|
+
}) || {};
|
|
35
|
+
const buildConfigs = (Array.isArray(_buildConfig) ? _buildConfig : [_buildConfig]).filter(Boolean);
|
|
36
|
+
const pkg = await jiti.import("./package.json", {
|
|
37
|
+
default: true,
|
|
38
|
+
try: true
|
|
39
|
+
}) || {};
|
|
40
|
+
const cleanedDirs = [];
|
|
41
|
+
const _transpileWatchMode = inputConfig.transpileWatch === true;
|
|
42
|
+
const _transpileStubMode = !_transpileWatchMode && (transpileStub || inputConfig.transpileStub === true);
|
|
43
|
+
if (!_transpileWatchMode && !_transpileStubMode) {
|
|
44
|
+
Object.assign(pkg, pkg.publishConfig);
|
|
45
|
+
}
|
|
46
|
+
for (const buildConfig of buildConfigs) {
|
|
47
|
+
await _build(
|
|
48
|
+
resolvedRootDir,
|
|
49
|
+
inputConfig,
|
|
50
|
+
buildConfig,
|
|
51
|
+
pkg,
|
|
52
|
+
cleanedDirs,
|
|
53
|
+
_transpileStubMode,
|
|
54
|
+
_transpileWatchMode,
|
|
55
|
+
outDir,
|
|
56
|
+
inputConfig.showOutLog || true
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function _build(rootDir, inputConfig, buildConfig, pkg, cleanedDirs, _transpileStubMode, _transpileWatchMode, outDir, showOutLog) {
|
|
61
|
+
const timer = createPerfTimer();
|
|
62
|
+
const preset = await resolvePreset(
|
|
63
|
+
buildConfig.preset || pkg.dler?.preset || pkg.build?.preset || inputConfig.preset || "auto",
|
|
64
|
+
rootDir
|
|
65
|
+
);
|
|
66
|
+
const options = defu(
|
|
67
|
+
buildConfig,
|
|
68
|
+
pkg.dler || pkg.build,
|
|
69
|
+
inputConfig,
|
|
70
|
+
preset,
|
|
71
|
+
{
|
|
72
|
+
alias: {},
|
|
73
|
+
clean: true,
|
|
74
|
+
declaration: void 0,
|
|
75
|
+
dependencies: [],
|
|
76
|
+
devDependencies: [],
|
|
77
|
+
entries: [],
|
|
78
|
+
externals: [
|
|
79
|
+
...Module.builtinModules,
|
|
80
|
+
...Module.builtinModules.map((m) => `node:${m}`)
|
|
81
|
+
],
|
|
82
|
+
failOnWarn: true,
|
|
83
|
+
name: (pkg?.name || "").split("/").pop() || "default",
|
|
84
|
+
outDir,
|
|
85
|
+
parallel: false,
|
|
86
|
+
peerDependencies: [],
|
|
87
|
+
replace: {},
|
|
88
|
+
rollup: {
|
|
89
|
+
alias: {},
|
|
90
|
+
cjsBridge: false,
|
|
91
|
+
commonjs: {
|
|
92
|
+
ignoreTryCatch: true
|
|
93
|
+
},
|
|
94
|
+
dts: {
|
|
95
|
+
compilerOptions: {
|
|
96
|
+
/**
|
|
97
|
+
* @see https://github.com/Swatinem/rollup-plugin-dts/issues/127
|
|
98
|
+
*/
|
|
99
|
+
composite: false,
|
|
100
|
+
/**
|
|
101
|
+
* @see https://github.com/Swatinem/rollup-plugin-dts/issues/143
|
|
102
|
+
*/
|
|
103
|
+
preserveSymlinks: false
|
|
104
|
+
},
|
|
105
|
+
respectExternal: true
|
|
106
|
+
},
|
|
107
|
+
emitCJS: false,
|
|
108
|
+
esbuild: { target: "esnext" },
|
|
109
|
+
inlineDependencies: false,
|
|
110
|
+
json: {
|
|
111
|
+
preferConst: true
|
|
112
|
+
},
|
|
113
|
+
output: {
|
|
114
|
+
/**
|
|
115
|
+
* @see https://v8.dev/features/import-attributes
|
|
116
|
+
*/
|
|
117
|
+
importAttributesKey: "with"
|
|
118
|
+
},
|
|
119
|
+
preserveDynamicImports: true,
|
|
120
|
+
// Plugins
|
|
121
|
+
replace: {
|
|
122
|
+
preventAssignment: true
|
|
123
|
+
},
|
|
124
|
+
resolve: {
|
|
125
|
+
preferBuiltins: true
|
|
126
|
+
},
|
|
127
|
+
watch: false
|
|
128
|
+
},
|
|
129
|
+
rootDir,
|
|
130
|
+
showOutLog: true,
|
|
131
|
+
transpileSourcemap: false,
|
|
132
|
+
transpileStub: _transpileStubMode,
|
|
133
|
+
transpileStubOptions: {
|
|
134
|
+
/**
|
|
135
|
+
* @see https://github.com/unjs/jiti#%EF%B8%8F-options
|
|
136
|
+
*/
|
|
137
|
+
jiti: {
|
|
138
|
+
alias: {},
|
|
139
|
+
interopDefault: true
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
transpileWatch: _transpileWatchMode,
|
|
143
|
+
transpileWatchOptions: _transpileWatchMode ? {
|
|
144
|
+
exclude: "node_modules/**",
|
|
145
|
+
include: "src/**"
|
|
146
|
+
} : void 0
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
options.outDir = resolve(options.rootDir, options.outDir);
|
|
150
|
+
const jiti = createJiti(options.rootDir, { interopDefault: true });
|
|
151
|
+
const ctx = {
|
|
152
|
+
buildEntries: [],
|
|
153
|
+
hooks: createHooks(),
|
|
154
|
+
jiti,
|
|
155
|
+
options,
|
|
156
|
+
pkg,
|
|
157
|
+
usedImports: /* @__PURE__ */ new Set(),
|
|
158
|
+
warnings: /* @__PURE__ */ new Set()
|
|
159
|
+
};
|
|
160
|
+
if (preset.hooks) {
|
|
161
|
+
ctx.hooks.addHooks(preset.hooks);
|
|
162
|
+
}
|
|
163
|
+
if (inputConfig.hooks) {
|
|
164
|
+
ctx.hooks.addHooks(inputConfig.hooks);
|
|
165
|
+
}
|
|
166
|
+
if (buildConfig.hooks) {
|
|
167
|
+
ctx.hooks.addHooks(buildConfig.hooks);
|
|
168
|
+
}
|
|
169
|
+
await ctx.hooks.callHook("build:prepare", ctx);
|
|
170
|
+
options.entries = options.entries.map(
|
|
171
|
+
(entry) => typeof entry === "string" ? { input: entry } : entry
|
|
172
|
+
);
|
|
173
|
+
for (const entry of options.entries) {
|
|
174
|
+
if (typeof entry.name !== "string") {
|
|
175
|
+
let relativeInput = isAbsolute(entry.input) ? relative(rootDir, entry.input) : normalize(entry.input);
|
|
176
|
+
if (relativeInput.startsWith("./")) {
|
|
177
|
+
relativeInput = relativeInput.slice(2);
|
|
178
|
+
}
|
|
179
|
+
entry.name = removeExtension(relativeInput.replace(/^src\//, ""));
|
|
180
|
+
}
|
|
181
|
+
if (!entry.input) {
|
|
182
|
+
throw new Error(`Missing entry input: ${dumpObject(entry)}`);
|
|
183
|
+
}
|
|
184
|
+
if (!entry.builder) {
|
|
185
|
+
entry.builder = entry.input.endsWith("/") ? "mkdist" : "rollup";
|
|
186
|
+
}
|
|
187
|
+
if (options.declaration !== void 0 && entry.declaration === void 0) {
|
|
188
|
+
entry.declaration = options.declaration;
|
|
189
|
+
}
|
|
190
|
+
entry.input = resolve(options.rootDir, entry.input);
|
|
191
|
+
entry.outDir = resolve(options.rootDir, entry.outDir || options.outDir);
|
|
192
|
+
}
|
|
193
|
+
options.dependencies = Object.keys(pkg.dependencies || {});
|
|
194
|
+
options.peerDependencies = Object.keys(pkg.peerDependencies || {});
|
|
195
|
+
options.devDependencies = Object.keys(pkg.devDependencies || {});
|
|
196
|
+
options.externals.push(...inferPkgExternals(pkg));
|
|
197
|
+
options.externals = [...new Set(options.externals)];
|
|
198
|
+
await ctx.hooks.callHook("build:before", ctx);
|
|
199
|
+
relinka(
|
|
200
|
+
"verbose",
|
|
201
|
+
`${options.transpileStub ? "Stubbing" : "[unified] Building"} ${options.name}`
|
|
202
|
+
);
|
|
203
|
+
if (process.env.DEBUG) {
|
|
204
|
+
relinka(
|
|
205
|
+
"info",
|
|
206
|
+
`Root dir: ${options.rootDir}
|
|
207
|
+
Entries:
|
|
208
|
+
${options.entries.map((entry) => ` ${dumpObject(entry)}`).join("\n ")}
|
|
209
|
+
`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
if (options.clean) {
|
|
213
|
+
for (const dir of new Set(
|
|
214
|
+
options.entries.map((e) => e.outDir).filter((p) => !!p).sort()
|
|
215
|
+
)) {
|
|
216
|
+
if (dir === options.rootDir || options.rootDir.startsWith(withTrailingSlash(dir)) || cleanedDirs.some((c) => dir.startsWith(c))) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
cleanedDirs.push(dir);
|
|
220
|
+
relinka(
|
|
221
|
+
"info",
|
|
222
|
+
`Cleaning dist directory: \`./${relative(process.cwd(), dir)}\``
|
|
223
|
+
);
|
|
224
|
+
await rmdir(dir);
|
|
225
|
+
await fsp.mkdir(dir, { recursive: true });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const buildTasks = [
|
|
229
|
+
typesBuild,
|
|
230
|
+
// untyped
|
|
231
|
+
mkdistBuild,
|
|
232
|
+
// mkdist
|
|
233
|
+
rollupBuild,
|
|
234
|
+
// rollup
|
|
235
|
+
copyBuild
|
|
236
|
+
// copy
|
|
237
|
+
];
|
|
238
|
+
if (options.parallel) {
|
|
239
|
+
await Promise.all(buildTasks.map((task) => task(ctx)));
|
|
240
|
+
} else {
|
|
241
|
+
for (const task of buildTasks) {
|
|
242
|
+
await task(ctx);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (options.transpileStub || options.transpileWatch) {
|
|
246
|
+
await ctx.hooks.callHook("build:done", ctx);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
relinka("success", `Build succeeded for ${options.name}`);
|
|
250
|
+
const outFiles = await glob(["**"], { cwd: options.outDir });
|
|
251
|
+
for (const file of outFiles) {
|
|
252
|
+
let entry = ctx.buildEntries.find((e) => e.path === file);
|
|
253
|
+
if (!entry) {
|
|
254
|
+
entry = {
|
|
255
|
+
chunk: true,
|
|
256
|
+
path: file
|
|
257
|
+
};
|
|
258
|
+
ctx.buildEntries.push(entry);
|
|
259
|
+
}
|
|
260
|
+
if (!entry.bytes) {
|
|
261
|
+
const stat = await fsp.stat(resolve(options.outDir, file));
|
|
262
|
+
entry.bytes = stat.size;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const rPath = (p) => relative(process.cwd(), resolve(options.outDir, p));
|
|
266
|
+
if (showOutLog) {
|
|
267
|
+
for (const entry of ctx.buildEntries.filter((e) => !e.chunk)) {
|
|
268
|
+
let totalBytes = entry.bytes || 0;
|
|
269
|
+
for (const chunk of entry.chunks || []) {
|
|
270
|
+
totalBytes += ctx.buildEntries.find((e) => e.path === chunk)?.bytes || 0;
|
|
271
|
+
}
|
|
272
|
+
let line = ` ${rPath(entry.path)} (${[
|
|
273
|
+
totalBytes && `total size: ${prettyBytes(totalBytes)}`,
|
|
274
|
+
entry.bytes && `chunk size: ${prettyBytes(entry.bytes)}`,
|
|
275
|
+
entry.exports?.length && `exports: ${entry.exports.join(", ")}`
|
|
276
|
+
].filter(Boolean).join(", ")})`;
|
|
277
|
+
if (entry.chunks?.length) {
|
|
278
|
+
line += `
|
|
279
|
+
${entry.chunks.map((p) => {
|
|
280
|
+
const chunk = ctx.buildEntries.find((e) => e.path === p) || {};
|
|
281
|
+
return ` \u2514\u2500 ${rPath(p)}${chunk.bytes ? ` (${prettyBytes(chunk.bytes)})` : ""}`;
|
|
282
|
+
}).join("\n")}`;
|
|
283
|
+
}
|
|
284
|
+
if (entry.modules?.length) {
|
|
285
|
+
line += `
|
|
286
|
+
${entry.modules.filter((m) => m.id.includes("node_modules")).sort((a, b) => (b.bytes || 0) - (a.bytes || 0)).map((m) => {
|
|
287
|
+
return ` \u{1F4E6} ${rPath(m.id)}${m.bytes ? ` (${prettyBytes(m.bytes)})` : ""}`;
|
|
288
|
+
}).join("\n")}`;
|
|
289
|
+
}
|
|
290
|
+
relinka("info", entry.chunk ? line : line);
|
|
291
|
+
}
|
|
292
|
+
const elapsedTime = getElapsedPerfTime(timer);
|
|
293
|
+
const transpileFormattedTime = prettyMilliseconds(elapsedTime, {
|
|
294
|
+
verbose: true
|
|
295
|
+
});
|
|
296
|
+
relinka(
|
|
297
|
+
"info",
|
|
298
|
+
"\u03A3 Total dist size:",
|
|
299
|
+
prettyBytes(ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0)),
|
|
300
|
+
`(build time: ${transpileFormattedTime})`
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
validateDependencies(ctx);
|
|
304
|
+
validatePackage(pkg, rootDir, ctx);
|
|
305
|
+
await ctx.hooks.callHook("build:done", ctx);
|
|
306
|
+
relinka("info", "");
|
|
307
|
+
if (ctx.warnings.size > 0) {
|
|
308
|
+
relinka(
|
|
309
|
+
"warn",
|
|
310
|
+
`Build is done with some warnings:
|
|
311
|
+
|
|
312
|
+
${[...ctx.warnings].map((msg) => `- ${msg}`).join("\n")}`
|
|
313
|
+
);
|
|
314
|
+
if (ctx.options.failOnWarn) {
|
|
315
|
+
relinka(
|
|
316
|
+
"error",
|
|
317
|
+
"Exiting with code (1). You can change this behavior by setting `failOnWarn: false` ."
|
|
318
|
+
);
|
|
319
|
+
process.exit(1);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { promises as fsp } from "node:fs";
|
|
3
|
+
import { relative, resolve } from "pathe";
|
|
4
|
+
import { glob } from "tinyglobby";
|
|
5
|
+
import {
|
|
6
|
+
rmdir,
|
|
7
|
+
symlink,
|
|
8
|
+
warn
|
|
9
|
+
} from "../utils.js";
|
|
10
|
+
const copy = fsp.cp || fsp.copyFile;
|
|
11
|
+
export async function copyBuild(ctx) {
|
|
12
|
+
const entries = ctx.options.entries.filter(
|
|
13
|
+
(e) => e.builder === "copy"
|
|
14
|
+
);
|
|
15
|
+
await ctx.hooks.callHook("copy:entries", ctx, entries);
|
|
16
|
+
for (const entry of entries) {
|
|
17
|
+
const distDir = entry.outDir || entry.input;
|
|
18
|
+
if (!distDir || !entry.input) {
|
|
19
|
+
warn(ctx, "Missing required outDir or input for copy entry");
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (ctx.options.transpileStub) {
|
|
23
|
+
await rmdir(distDir);
|
|
24
|
+
await symlink(entry.input, distDir);
|
|
25
|
+
} else {
|
|
26
|
+
const patterns = Array.isArray(entry.pattern) ? entry.pattern : [entry.pattern || "**"];
|
|
27
|
+
const paths = await glob(patterns, {
|
|
28
|
+
absolute: false,
|
|
29
|
+
cwd: resolve(ctx.options.rootDir, entry.input)
|
|
30
|
+
});
|
|
31
|
+
const outputList = await Promise.allSettled(
|
|
32
|
+
paths.map(async (path) => {
|
|
33
|
+
const src = resolve(ctx.options.rootDir, entry.input, path);
|
|
34
|
+
const dist = resolve(ctx.options.rootDir, distDir, path);
|
|
35
|
+
await copy(src, dist);
|
|
36
|
+
return dist;
|
|
37
|
+
})
|
|
38
|
+
);
|
|
39
|
+
for (const output of outputList) {
|
|
40
|
+
if (output.status === "rejected") {
|
|
41
|
+
warn(ctx, output.reason);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
ctx.buildEntries.push({
|
|
45
|
+
chunks: outputList.filter(({ status }) => status === "fulfilled").map(
|
|
46
|
+
(p) => relative(
|
|
47
|
+
ctx.options.outDir,
|
|
48
|
+
p.value
|
|
49
|
+
)
|
|
50
|
+
),
|
|
51
|
+
path: distDir
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
await ctx.hooks.callHook("copy:done", ctx);
|
|
56
|
+
if (entries.length > 0 && ctx.options.transpileWatch) {
|
|
57
|
+
relinka(
|
|
58
|
+
"warn",
|
|
59
|
+
"`untyped` builder does not support transpileWatch mode yet."
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { mkdist } from "mkdist";
|
|
3
|
+
import { relative } from "pathe";
|
|
4
|
+
import {
|
|
5
|
+
rmdir,
|
|
6
|
+
symlink,
|
|
7
|
+
warn
|
|
8
|
+
} from "../utils.js";
|
|
9
|
+
export async function mkdistBuild(ctx) {
|
|
10
|
+
const entries = ctx.options.entries.filter(
|
|
11
|
+
(e) => e.builder === "mkdist"
|
|
12
|
+
);
|
|
13
|
+
await ctx.hooks.callHook("mkdist:entries", ctx, entries);
|
|
14
|
+
for (const entry of entries) {
|
|
15
|
+
const distDir = entry.outDir || entry.input;
|
|
16
|
+
if (ctx.options.transpileStub) {
|
|
17
|
+
await rmdir(distDir);
|
|
18
|
+
await symlink(entry.input, distDir);
|
|
19
|
+
} else {
|
|
20
|
+
const mkdistOptions = {
|
|
21
|
+
cleanDist: false,
|
|
22
|
+
distDir,
|
|
23
|
+
rootDir: ctx.options.rootDir,
|
|
24
|
+
srcDir: entry.input,
|
|
25
|
+
...entry
|
|
26
|
+
};
|
|
27
|
+
await ctx.hooks.callHook(
|
|
28
|
+
"mkdist:entry:options",
|
|
29
|
+
ctx,
|
|
30
|
+
entry,
|
|
31
|
+
mkdistOptions
|
|
32
|
+
);
|
|
33
|
+
const output = await mkdist(mkdistOptions);
|
|
34
|
+
ctx.buildEntries.push({
|
|
35
|
+
chunks: output.writtenFiles.map((p) => relative(ctx.options.outDir, p)),
|
|
36
|
+
path: distDir
|
|
37
|
+
});
|
|
38
|
+
await ctx.hooks.callHook("mkdist:entry:build", ctx, entry, output);
|
|
39
|
+
if (output.errors) {
|
|
40
|
+
for (const error of output.errors) {
|
|
41
|
+
warn(
|
|
42
|
+
ctx,
|
|
43
|
+
`mkdist build failed for \`${relative(ctx.options.rootDir, error.filename)}\`:
|
|
44
|
+
${error.errors.map((e) => ` - ${e}`).join("\n")}`
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
await ctx.hooks.callHook("mkdist:done", ctx);
|
|
51
|
+
if (entries.length > 0 && ctx.options.transpileWatch) {
|
|
52
|
+
relinka(
|
|
53
|
+
"warn",
|
|
54
|
+
"`mkdist` builder does not support transpileWatch mode yet."
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { relinka } from "@reliverse/relinka";
|
|
2
|
+
import { resolve } from "pathe";
|
|
3
|
+
import { rollup } from "rollup";
|
|
4
|
+
import dts from "rollup-plugin-dts";
|
|
5
|
+
import { getRollupOptions } from "./config.js";
|
|
6
|
+
import { fixCJSExportTypePlugin } from "./plugins/cjs.js";
|
|
7
|
+
import { removeShebangPlugin } from "./plugins/shebang.js";
|
|
8
|
+
import { rollupStub } from "./stub.js";
|
|
9
|
+
import { getChunkFilename } from "./utils.js";
|
|
10
|
+
import { rollupWatch } from "./watch.js";
|
|
11
|
+
export async function rollupBuild(ctx) {
|
|
12
|
+
if (ctx.options.transpileStub) {
|
|
13
|
+
await rollupStub(ctx);
|
|
14
|
+
await ctx.hooks.callHook("rollup:done", ctx);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const rollupOptions = getRollupOptions(ctx);
|
|
18
|
+
await ctx.hooks.callHook("rollup:options", ctx, rollupOptions);
|
|
19
|
+
if (Object.keys(rollupOptions.input).length === 0) {
|
|
20
|
+
await ctx.hooks.callHook("rollup:done", ctx);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const buildResult = await rollup(rollupOptions);
|
|
24
|
+
await ctx.hooks.callHook("rollup:build", ctx, buildResult);
|
|
25
|
+
const allOutputOptions = rollupOptions.output;
|
|
26
|
+
for (const outputOptions of allOutputOptions) {
|
|
27
|
+
const { output } = await buildResult.write(outputOptions);
|
|
28
|
+
const chunkFileNames = /* @__PURE__ */ new Set();
|
|
29
|
+
const outputChunks = output.filter((e) => e.type === "chunk");
|
|
30
|
+
for (const entry of outputChunks) {
|
|
31
|
+
chunkFileNames.add(entry.fileName);
|
|
32
|
+
for (const id of entry.imports) {
|
|
33
|
+
ctx.usedImports.add(id);
|
|
34
|
+
}
|
|
35
|
+
if (entry.isEntry) {
|
|
36
|
+
ctx.buildEntries.push({
|
|
37
|
+
bytes: Buffer.byteLength(entry.code, "utf8"),
|
|
38
|
+
chunks: entry.imports.filter(
|
|
39
|
+
(i) => outputChunks.find((c) => c.fileName === i)
|
|
40
|
+
),
|
|
41
|
+
exports: entry.exports,
|
|
42
|
+
modules: Object.entries(entry.modules).map(([id, mod]) => ({
|
|
43
|
+
bytes: mod.renderedLength,
|
|
44
|
+
id
|
|
45
|
+
})),
|
|
46
|
+
path: entry.fileName
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const chunkFileName of chunkFileNames) {
|
|
51
|
+
ctx.usedImports.delete(chunkFileName);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (ctx.options.transpileWatch) {
|
|
55
|
+
rollupWatch(rollupOptions);
|
|
56
|
+
if (ctx.options.declaration && ctx.options.transpileWatch) {
|
|
57
|
+
relinka(
|
|
58
|
+
"warn",
|
|
59
|
+
"`rollup` DTS builder does not support transpileWatch mode yet."
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (ctx.options.declaration) {
|
|
65
|
+
const plugins = [
|
|
66
|
+
dts(ctx.options.rollup.dts),
|
|
67
|
+
removeShebangPlugin(),
|
|
68
|
+
ctx.options.rollup.emitCJS && fixCJSExportTypePlugin(ctx)
|
|
69
|
+
].filter(
|
|
70
|
+
(plugin) => (
|
|
71
|
+
/**
|
|
72
|
+
* Issue: #396
|
|
73
|
+
* rollup-plugin-dts conflicts with rollup-plugin-commonjs:
|
|
74
|
+
* https://github.com/Swatinem/rollup-plugin-dts#what-to-expect
|
|
75
|
+
*/
|
|
76
|
+
!!plugin && (!("name" in plugin) || plugin.name !== "commonjs")
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
rollupOptions.plugins = plugins;
|
|
80
|
+
await ctx.hooks.callHook("rollup:dts:options", ctx, rollupOptions);
|
|
81
|
+
const typesBuild = await rollup(rollupOptions);
|
|
82
|
+
await ctx.hooks.callHook("rollup:dts:build", ctx, typesBuild);
|
|
83
|
+
if (ctx.options.rollup.emitCJS) {
|
|
84
|
+
await typesBuild.write({
|
|
85
|
+
chunkFileNames: (chunk) => getChunkFilename(ctx, chunk, "d.cts"),
|
|
86
|
+
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
87
|
+
entryFileNames: "[name].d.cts"
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
await typesBuild.write({
|
|
91
|
+
chunkFileNames: (chunk) => getChunkFilename(ctx, chunk, "d.mts"),
|
|
92
|
+
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
93
|
+
entryFileNames: "[name].d.mts"
|
|
94
|
+
});
|
|
95
|
+
if (ctx.options.declaration === true || ctx.options.declaration === "compatible") {
|
|
96
|
+
await typesBuild.write({
|
|
97
|
+
chunkFileNames: (chunk) => getChunkFilename(ctx, chunk, "d.ts"),
|
|
98
|
+
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
99
|
+
entryFileNames: "[name].d.ts"
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
await ctx.hooks.callHook("rollup:done", ctx);
|
|
104
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { parseNodeModulePath } from "mlly";
|
|
2
|
+
import { isAbsolute, resolve } from "pathe";
|
|
3
|
+
import { resolveAlias } from "pathe/utils";
|
|
4
|
+
import {
|
|
5
|
+
arrayIncludes,
|
|
6
|
+
getpkg,
|
|
7
|
+
warn
|
|
8
|
+
} from "../utils.js";
|
|
9
|
+
import { cjsPlugin } from "./plugins/cjs.js";
|
|
10
|
+
import { esbuild } from "./plugins/esbuild.js";
|
|
11
|
+
import { JSONPlugin } from "./plugins/json.js";
|
|
12
|
+
import { rawPlugin } from "./plugins/raw.js";
|
|
13
|
+
import { shebangPlugin } from "./plugins/shebang.js";
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_EXTENSIONS,
|
|
16
|
+
getChunkFilename,
|
|
17
|
+
resolveAliases
|
|
18
|
+
} from "./utils.js";
|
|
19
|
+
const replaceModule = await import("@rollup/plugin-replace");
|
|
20
|
+
const replace = replaceModule.default || replaceModule;
|
|
21
|
+
const aliasModule = await import("@rollup/plugin-alias");
|
|
22
|
+
const alias = aliasModule.default || aliasModule;
|
|
23
|
+
const commonjsModule = await import("@rollup/plugin-commonjs");
|
|
24
|
+
const commonjs = commonjsModule.default || commonjsModule;
|
|
25
|
+
const nodeResolveModule = await import("@rollup/plugin-node-resolve");
|
|
26
|
+
const nodeResolve = nodeResolveModule.nodeResolve || nodeResolveModule.default || nodeResolveModule;
|
|
27
|
+
export function getRollupOptions(ctx) {
|
|
28
|
+
const _aliases = resolveAliases(ctx);
|
|
29
|
+
return {
|
|
30
|
+
external(originalId) {
|
|
31
|
+
const resolvedId = resolveAlias(originalId, _aliases);
|
|
32
|
+
const pkgName = parseNodeModulePath(resolvedId)?.name || parseNodeModulePath(originalId)?.name || getpkg(originalId);
|
|
33
|
+
if (arrayIncludes(ctx.options.externals, pkgName) || arrayIncludes(ctx.options.externals, originalId) || arrayIncludes(ctx.options.externals, resolvedId)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
for (const id of [originalId, resolvedId]) {
|
|
37
|
+
if (id.startsWith(".") || isAbsolute(id) || /src[/\\]/.test(id) || ctx.pkg.name && id.startsWith(ctx.pkg.name)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (ctx.options.rollup.inlineDependencies === true || Array.isArray(ctx.options.rollup.inlineDependencies) && (arrayIncludes(ctx.options.rollup.inlineDependencies, pkgName) || arrayIncludes(ctx.options.rollup.inlineDependencies, originalId) || arrayIncludes(ctx.options.rollup.inlineDependencies, resolvedId))) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
warn(ctx, `Implicitly bundling "${originalId}"`);
|
|
45
|
+
return false;
|
|
46
|
+
},
|
|
47
|
+
input: Object.fromEntries(
|
|
48
|
+
ctx.options.entries.filter((entry) => entry.builder === "rollup").map((entry) => [
|
|
49
|
+
entry.name,
|
|
50
|
+
resolve(ctx.options.rootDir, entry.input)
|
|
51
|
+
])
|
|
52
|
+
),
|
|
53
|
+
onwarn(warning, rollupWarn) {
|
|
54
|
+
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
55
|
+
rollupWarn(warning);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
output: [
|
|
59
|
+
ctx.options.rollup.emitCJS && {
|
|
60
|
+
chunkFileNames: (chunk) => getChunkFilename(ctx, chunk, "cjs"),
|
|
61
|
+
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
62
|
+
entryFileNames: "[name].cjs",
|
|
63
|
+
exports: "auto",
|
|
64
|
+
externalLiveBindings: false,
|
|
65
|
+
format: "cjs",
|
|
66
|
+
freeze: false,
|
|
67
|
+
generatedCode: { constBindings: true },
|
|
68
|
+
interop: "compat",
|
|
69
|
+
sourcemap: ctx.options.transpileSourcemap,
|
|
70
|
+
...ctx.options.rollup.output
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
chunkFileNames: (chunk) => getChunkFilename(ctx, chunk, "mjs"),
|
|
74
|
+
dir: resolve(ctx.options.rootDir, ctx.options.outDir),
|
|
75
|
+
entryFileNames: "[name].mjs",
|
|
76
|
+
exports: "auto",
|
|
77
|
+
externalLiveBindings: false,
|
|
78
|
+
format: "esm",
|
|
79
|
+
freeze: false,
|
|
80
|
+
generatedCode: { constBindings: true },
|
|
81
|
+
sourcemap: ctx.options.transpileSourcemap,
|
|
82
|
+
...ctx.options.rollup.output
|
|
83
|
+
}
|
|
84
|
+
].filter(Boolean),
|
|
85
|
+
plugins: [
|
|
86
|
+
ctx.options.rollup.replace && replace({
|
|
87
|
+
...ctx.options.rollup.replace,
|
|
88
|
+
values: {
|
|
89
|
+
...ctx.options.replace,
|
|
90
|
+
...ctx.options.rollup.replace.values
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
ctx.options.rollup.alias && alias({
|
|
94
|
+
...ctx.options.rollup.alias,
|
|
95
|
+
entries: _aliases
|
|
96
|
+
}),
|
|
97
|
+
ctx.options.rollup.resolve && nodeResolve({
|
|
98
|
+
exportConditions: ["production"],
|
|
99
|
+
extensions: DEFAULT_EXTENSIONS,
|
|
100
|
+
...ctx.options.rollup.resolve
|
|
101
|
+
}),
|
|
102
|
+
ctx.options.rollup.json && JSONPlugin({
|
|
103
|
+
...ctx.options.rollup.json
|
|
104
|
+
}),
|
|
105
|
+
shebangPlugin(),
|
|
106
|
+
ctx.options.rollup.esbuild && esbuild({
|
|
107
|
+
sourcemap: ctx.options.transpileSourcemap,
|
|
108
|
+
...ctx.options.rollup.esbuild
|
|
109
|
+
}),
|
|
110
|
+
ctx.options.rollup.commonjs && commonjs({
|
|
111
|
+
extensions: DEFAULT_EXTENSIONS,
|
|
112
|
+
...ctx.options.rollup.commonjs
|
|
113
|
+
}),
|
|
114
|
+
ctx.options.rollup.preserveDynamicImports && {
|
|
115
|
+
name: "dler=preserve-dynamic-imports",
|
|
116
|
+
renderDynamicImport() {
|
|
117
|
+
return { left: "import(", right: ")" };
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
ctx.options.rollup.cjsBridge && cjsPlugin(),
|
|
121
|
+
rawPlugin()
|
|
122
|
+
].filter((p) => !!p)
|
|
123
|
+
};
|
|
124
|
+
}
|