@reliverse/dler 1.7.63 → 1.7.64
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/bin/libs/cfg/cfg-impl/rse-config/rse-impl/rse-define.d.ts +11 -11
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/build.js +260 -286
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-impl/make.js +183 -193
- package/bin/libs/sdk/sdk-impl/build/bundlers/unified/mkdist/mkdist-mod.js +76 -91
- package/bin/libs/sdk/sdk-impl/config/info.js +1 -1
- package/package.json +1 -1
|
@@ -9,12 +9,12 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
9
9
|
projectRepository?: string | undefined;
|
|
10
10
|
projectDomain?: string | undefined;
|
|
11
11
|
projectGitService?: "none" | "github" | "gitlab" | "bitbucket" | undefined;
|
|
12
|
-
projectDeployService?: "none" | "
|
|
13
|
-
projectPackageManager?: "
|
|
12
|
+
projectDeployService?: "none" | "deno" | "vercel" | "netlify" | "railway" | undefined;
|
|
13
|
+
projectPackageManager?: "npm" | "yarn" | "pnpm" | "bun" | undefined;
|
|
14
14
|
projectState?: "creating" | "created" | undefined;
|
|
15
|
-
projectCategory?: "
|
|
15
|
+
projectCategory?: "cli" | "unknown" | "website" | "vscode" | "browser" | "library" | "mobile" | undefined;
|
|
16
16
|
projectSubcategory?: "unknown" | "e-commerce" | "tool" | undefined;
|
|
17
|
-
projectFramework?: "rempts" | "npm-jsr" | "
|
|
17
|
+
projectFramework?: "rempts" | "npm-jsr" | "unknown" | "vscode" | "nextjs" | "vite" | "svelte" | "remix" | "astro" | "nuxt" | "solid" | "qwik" | "vue" | "wxt" | "lynx" | "react-native" | "expo" | "capacitor" | "ionic" | "electron" | "tauri" | "neutralino" | "citty" | "commander" | "cac" | "meow" | "yargs" | "webextension" | "browser-extension" | undefined;
|
|
18
18
|
projectTemplate?: "unknown" | "blefnk/relivator-nextjs-template" | "blefnk/relivator-docker-template" | "blefnk/next-react-ts-src-minimal" | "blefnk/all-in-one-nextjs-template" | "blefnk/create-t3-app" | "blefnk/create-next-app" | "blefnk/astro-starlight-template" | "blefnk/versator-nextjs-template" | "blefnk/relivator-lynxjs-template" | "blefnk/relivator-react-native-template" | "reliverse/template-browser-extension" | "microsoft/vscode-extension-samples" | "microsoft/vscode-extension-template" | "rsetarter-template" | "blefnk/deno-cli-tutorial" | undefined;
|
|
19
19
|
projectTemplateDate?: string | undefined;
|
|
20
20
|
features?: {
|
|
@@ -38,13 +38,13 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
38
38
|
analytics?: "unknown" | "vercel" | undefined;
|
|
39
39
|
authentication?: "unknown" | "better-auth" | "clerk" | "next-auth" | "supabase-auth" | "auth0" | undefined;
|
|
40
40
|
api?: "unknown" | "hono" | "trpc" | "graphql" | "rest" | undefined;
|
|
41
|
-
testing?: "bun" | "
|
|
41
|
+
testing?: "bun" | "unknown" | "vitest" | "jest" | "playwright" | "cypress" | undefined;
|
|
42
42
|
stateManagement?: "unknown" | "zustand" | "jotai" | "redux-toolkit" | undefined;
|
|
43
43
|
formManagement?: "unknown" | "react-hook-form" | "formik" | undefined;
|
|
44
44
|
styling?: "unknown" | "tailwind" | "styled-components" | "css-modules" | "sass" | undefined;
|
|
45
45
|
uiComponents?: "unknown" | "shadcn-ui" | "chakra-ui" | "material-ui" | undefined;
|
|
46
46
|
databaseLibrary?: "unknown" | "drizzle" | "prisma" | "supabase" | undefined;
|
|
47
|
-
databaseProvider?: "
|
|
47
|
+
databaseProvider?: "unknown" | "pg" | "mysql" | "sqlite" | "mongodb" | undefined;
|
|
48
48
|
linting?: "unknown" | "eslint" | undefined;
|
|
49
49
|
formatting?: "unknown" | "biome" | undefined;
|
|
50
50
|
payment?: "unknown" | "stripe" | undefined;
|
|
@@ -57,7 +57,7 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
57
57
|
documentation?: "unknown" | "starlight" | "nextra" | undefined;
|
|
58
58
|
icons?: "unknown" | "lucide" | undefined;
|
|
59
59
|
mail?: "unknown" | "resend" | undefined;
|
|
60
|
-
cache?: "
|
|
60
|
+
cache?: "unknown" | "redis" | undefined;
|
|
61
61
|
storage?: "unknown" | "cloudflare" | undefined;
|
|
62
62
|
cdn?: "unknown" | "cloudflare" | undefined;
|
|
63
63
|
cms?: "unknown" | "contentlayer" | undefined;
|
|
@@ -67,7 +67,7 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
67
67
|
dates?: "unknown" | "dayjs" | undefined;
|
|
68
68
|
markdown?: "unknown" | "mdx" | undefined;
|
|
69
69
|
security?: "unknown" | "auth" | undefined;
|
|
70
|
-
routing?: "
|
|
70
|
+
routing?: "unknown" | "next" | "react-router" | "tanstack-router" | undefined;
|
|
71
71
|
} | undefined;
|
|
72
72
|
codeStyle?: {
|
|
73
73
|
lineWidth?: number | undefined;
|
|
@@ -83,7 +83,7 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
83
83
|
dontRemoveComments?: boolean | undefined;
|
|
84
84
|
shouldAddComments?: boolean | undefined;
|
|
85
85
|
typeOrInterface?: "type" | "interface" | "mixed" | undefined;
|
|
86
|
-
importOrRequire?: "
|
|
86
|
+
importOrRequire?: "require" | "import" | "mixed" | undefined;
|
|
87
87
|
cjsToEsm?: boolean | undefined;
|
|
88
88
|
modernize?: {
|
|
89
89
|
replaceFs?: boolean | undefined;
|
|
@@ -96,7 +96,7 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
96
96
|
importSymbol?: string | undefined;
|
|
97
97
|
} | undefined;
|
|
98
98
|
monorepo?: {
|
|
99
|
-
type?: "none" | "
|
|
99
|
+
type?: "none" | "pnpm" | "bun" | "turborepo" | "nx" | undefined;
|
|
100
100
|
packages?: string[] | undefined;
|
|
101
101
|
sharedPackages?: string[] | undefined;
|
|
102
102
|
} | undefined;
|
|
@@ -113,7 +113,7 @@ export declare const defineConfigRse: (userConfig?: Partial<RseConfig>) => {
|
|
|
113
113
|
repoBranch?: string | undefined;
|
|
114
114
|
repoPrivacy?: "unknown" | "public" | "private" | undefined;
|
|
115
115
|
projectArchitecture?: "unknown" | "fullstack" | "separated" | undefined;
|
|
116
|
-
projectRuntime?: "bun" | "
|
|
116
|
+
projectRuntime?: "bun" | "deno" | "node" | undefined;
|
|
117
117
|
skipPromptsUseAutoBehavior?: boolean | undefined;
|
|
118
118
|
deployBehavior?: "prompt" | "autoYes" | "autoNo" | undefined;
|
|
119
119
|
depsBehavior?: "prompt" | "autoYes" | "autoNo" | undefined;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isAbsolute, normalize, relative, resolve } from "@reliverse/pathkit";
|
|
2
2
|
import { relinka } from "@reliverse/relinka";
|
|
3
|
-
import { useSpinner } from "@reliverse/rempts";
|
|
4
3
|
import { defu } from "defu";
|
|
5
4
|
import { createHooks } from "hookable";
|
|
6
5
|
import { createJiti } from "jiti";
|
|
@@ -73,305 +72,280 @@ export async function unifiedBuild(inputSourceDir, coreIsCLI, isLib, rootDir, in
|
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
async function _build(rootDir, inputConfig, buildConfig, pkg, cleanedDirs, _transpileStubMode, _transpileWatchMode, outDir, showOutLog, isLib) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
dts: {
|
|
105
|
-
compilerOptions: {
|
|
106
|
-
/**
|
|
107
|
-
* @see https://github.com/Swatinem/rollup-plugin-dts/issues/127
|
|
108
|
-
*/
|
|
109
|
-
composite: false,
|
|
110
|
-
/**
|
|
111
|
-
* @see https://github.com/Swatinem/rollup-plugin-dts/issues/143
|
|
112
|
-
*/
|
|
113
|
-
preserveSymlinks: false
|
|
114
|
-
},
|
|
115
|
-
respectExternal: true
|
|
116
|
-
},
|
|
117
|
-
emitCJS: false,
|
|
118
|
-
esbuild: { target: "esnext" },
|
|
119
|
-
inlineDependencies: false,
|
|
120
|
-
json: {
|
|
121
|
-
preferConst: true
|
|
122
|
-
},
|
|
123
|
-
output: {
|
|
124
|
-
/**
|
|
125
|
-
* @see https://v8.dev/features/import-attributes
|
|
126
|
-
*/
|
|
127
|
-
importAttributesKey: "with"
|
|
128
|
-
},
|
|
129
|
-
preserveDynamicImports: true,
|
|
130
|
-
// Plugins
|
|
131
|
-
replace: {
|
|
132
|
-
preventAssignment: true
|
|
133
|
-
},
|
|
134
|
-
resolve: {
|
|
135
|
-
preferBuiltins: true
|
|
136
|
-
},
|
|
137
|
-
watch: false
|
|
138
|
-
},
|
|
139
|
-
rootDir,
|
|
140
|
-
showOutLog: true,
|
|
141
|
-
transpileSourcemap: false,
|
|
142
|
-
transpileStub: _transpileStubMode,
|
|
143
|
-
transpileStubOptions: {
|
|
75
|
+
const timer = createPerfTimer();
|
|
76
|
+
relinka("info", "Resolving build configuration...");
|
|
77
|
+
const preset = await resolvePreset(
|
|
78
|
+
buildConfig.preset || pkg.dler?.preset || pkg.build?.preset || inputConfig.preset || "auto",
|
|
79
|
+
rootDir
|
|
80
|
+
);
|
|
81
|
+
const options = defu(buildConfig, pkg.dler || pkg.build, inputConfig, preset, {
|
|
82
|
+
alias: {},
|
|
83
|
+
clean: false,
|
|
84
|
+
declaration: void 0,
|
|
85
|
+
dependencies: [],
|
|
86
|
+
devDependencies: [],
|
|
87
|
+
entries: [],
|
|
88
|
+
externals: [...Module.builtinModules, ...Module.builtinModules.map((m) => `node:${m}`)],
|
|
89
|
+
transpileFailOnWarn: true,
|
|
90
|
+
name: (pkg?.name || "").split("/").pop() || "default",
|
|
91
|
+
outDir,
|
|
92
|
+
parallel: false,
|
|
93
|
+
peerDependencies: [],
|
|
94
|
+
replace: {},
|
|
95
|
+
rollup: {
|
|
96
|
+
alias: {},
|
|
97
|
+
cjsBridge: false,
|
|
98
|
+
commonjs: {
|
|
99
|
+
ignoreTryCatch: true
|
|
100
|
+
},
|
|
101
|
+
dts: {
|
|
102
|
+
compilerOptions: {
|
|
144
103
|
/**
|
|
145
|
-
* @see https://github.com/
|
|
104
|
+
* @see https://github.com/Swatinem/rollup-plugin-dts/issues/127
|
|
146
105
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
106
|
+
composite: false,
|
|
107
|
+
/**
|
|
108
|
+
* @see https://github.com/Swatinem/rollup-plugin-dts/issues/143
|
|
109
|
+
*/
|
|
110
|
+
preserveSymlinks: false
|
|
151
111
|
},
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
112
|
+
respectExternal: true
|
|
113
|
+
},
|
|
114
|
+
emitCJS: false,
|
|
115
|
+
esbuild: { target: "esnext" },
|
|
116
|
+
inlineDependencies: false,
|
|
117
|
+
json: {
|
|
118
|
+
preferConst: true
|
|
119
|
+
},
|
|
120
|
+
output: {
|
|
121
|
+
/**
|
|
122
|
+
* @see https://v8.dev/features/import-attributes
|
|
123
|
+
*/
|
|
124
|
+
importAttributesKey: "with"
|
|
125
|
+
},
|
|
126
|
+
preserveDynamicImports: true,
|
|
127
|
+
// Plugins
|
|
128
|
+
replace: {
|
|
129
|
+
preventAssignment: true
|
|
130
|
+
},
|
|
131
|
+
resolve: {
|
|
132
|
+
preferBuiltins: true
|
|
133
|
+
},
|
|
134
|
+
watch: false
|
|
135
|
+
},
|
|
136
|
+
rootDir,
|
|
137
|
+
showOutLog: true,
|
|
138
|
+
transpileSourcemap: false,
|
|
139
|
+
transpileStub: _transpileStubMode,
|
|
140
|
+
transpileStubOptions: {
|
|
141
|
+
/**
|
|
142
|
+
* @see https://github.com/unjs/jiti#%EF%B8%8F-options
|
|
143
|
+
*/
|
|
144
|
+
jiti: {
|
|
145
|
+
alias: {},
|
|
146
|
+
interopDefault: true
|
|
184
147
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
148
|
+
},
|
|
149
|
+
transpileWatch: _transpileWatchMode,
|
|
150
|
+
transpileWatchOptions: _transpileWatchMode ? {
|
|
151
|
+
exclude: "node_modules/**",
|
|
152
|
+
include: "src/**"
|
|
153
|
+
} : void 0,
|
|
154
|
+
isLib
|
|
155
|
+
});
|
|
156
|
+
shouldStopAtStep(5);
|
|
157
|
+
relinka("log", "Build-specific configuration merged with defaults");
|
|
158
|
+
relinka("verbose", `Build options: clean=${options.clean}, parallel=${options.parallel}`);
|
|
159
|
+
relinka("verbose", `Declaration files: ${options.declaration ? "enabled" : "disabled"}`);
|
|
160
|
+
options.outDir = resolve(options.rootDir, options.outDir);
|
|
161
|
+
const jiti = createJiti(options.rootDir, { interopDefault: true });
|
|
162
|
+
relinka("info", "Initializing build context...");
|
|
163
|
+
const ctx = {
|
|
164
|
+
buildEntries: [],
|
|
165
|
+
hooks: createHooks(),
|
|
166
|
+
jiti,
|
|
167
|
+
options,
|
|
168
|
+
pkg,
|
|
169
|
+
usedImports: /* @__PURE__ */ new Set(),
|
|
170
|
+
warnings: /* @__PURE__ */ new Set(),
|
|
171
|
+
isLib
|
|
172
|
+
};
|
|
173
|
+
if (preset.hooks) {
|
|
174
|
+
ctx.hooks.addHooks(preset.hooks);
|
|
175
|
+
}
|
|
176
|
+
if (inputConfig.hooks) {
|
|
177
|
+
ctx.hooks.addHooks(inputConfig.hooks);
|
|
178
|
+
}
|
|
179
|
+
if (buildConfig.hooks) {
|
|
180
|
+
ctx.hooks.addHooks(buildConfig.hooks);
|
|
181
|
+
}
|
|
182
|
+
await ctx.hooks.callHook("build:prepare", ctx);
|
|
183
|
+
relinka("info", "Processing build entries...");
|
|
184
|
+
options.entries = options.entries.map(
|
|
185
|
+
(entry) => typeof entry === "string" ? { input: entry, isLib } : entry
|
|
186
|
+
);
|
|
187
|
+
for (const entry of options.entries) {
|
|
188
|
+
if (typeof entry.name !== "string") {
|
|
189
|
+
let relativeInput = isAbsolute(entry.input) ? relative(rootDir, entry.input) : normalize(entry.input);
|
|
190
|
+
if (relativeInput.startsWith("./")) {
|
|
191
|
+
relativeInput = relativeInput.slice(2);
|
|
210
192
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
193
|
+
entry.name = removeExtension(relativeInput.replace(/^src\//, ""));
|
|
194
|
+
}
|
|
195
|
+
if (!entry.input) {
|
|
196
|
+
throw new Error(`Missing entry input: ${dumpObject(entry)}`);
|
|
197
|
+
}
|
|
198
|
+
if (!entry.builder) {
|
|
199
|
+
entry.builder = entry.input.endsWith("/") ? "mkdist" : "rollup";
|
|
200
|
+
}
|
|
201
|
+
if (options.declaration !== void 0 && entry.declaration === void 0) {
|
|
202
|
+
entry.declaration = options.declaration;
|
|
203
|
+
}
|
|
204
|
+
entry.input = resolve(options.rootDir, entry.input);
|
|
205
|
+
entry.outDir = resolve(options.rootDir, entry.outDir || options.outDir);
|
|
206
|
+
entry.isLib = isLib;
|
|
207
|
+
}
|
|
208
|
+
options.dependencies = Object.keys(pkg.dependencies || {});
|
|
209
|
+
options.peerDependencies = Object.keys(pkg.peerDependencies || {});
|
|
210
|
+
options.devDependencies = Object.keys(pkg.devDependencies || {});
|
|
211
|
+
options.externals.push(...inferPkgExternals(pkg));
|
|
212
|
+
options.externals = [...new Set(options.externals)];
|
|
213
|
+
await ctx.hooks.callHook("build:before", ctx);
|
|
214
|
+
relinka(
|
|
215
|
+
"verbose",
|
|
216
|
+
`${options.transpileStub ? "Stubbing" : "[unified] Building"} ${options.name}`
|
|
217
|
+
);
|
|
218
|
+
if (process.env.DEBUG) {
|
|
219
|
+
relinka(
|
|
220
|
+
"log",
|
|
221
|
+
`Root dir: ${options.rootDir}
|
|
225
222
|
Entries:
|
|
226
223
|
${options.entries.map((entry) => ` ${dumpObject(entry)}`).join("\n ")}
|
|
227
224
|
`
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
238
|
-
cleanedDirs.push(dir);
|
|
239
|
-
relinka("log", `Cleaning dist directory: \`./${relative(process.cwd(), dir)}\``);
|
|
240
|
-
await rmdir(dir);
|
|
241
|
-
await fsp.mkdir(dir, { recursive: true });
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const buildTasks = [
|
|
245
|
-
{ name: "Type generation", task: typesBuild },
|
|
246
|
-
{ name: "mkdist build", task: mkdistBuild },
|
|
247
|
-
{ name: "Rollup build", task: rollupBuild },
|
|
248
|
-
{ name: "Copy files", task: copyBuild }
|
|
249
|
-
];
|
|
250
|
-
const activeTasks = buildTasks.filter(({ task }) => {
|
|
251
|
-
if (task === typesBuild) return options.entries.some((e) => e.builder === "untyped");
|
|
252
|
-
if (task === mkdistBuild) return options.entries.some((e) => e.builder === "mkdist");
|
|
253
|
-
if (task === rollupBuild) return options.entries.some((e) => e.builder === "rollup");
|
|
254
|
-
if (task === copyBuild) return options.entries.some((e) => e.builder === "copy");
|
|
255
|
-
return false;
|
|
256
|
-
});
|
|
257
|
-
if (activeTasks.length === 0) {
|
|
258
|
-
buildSpinner.setText("No build tasks to execute");
|
|
259
|
-
} else {
|
|
260
|
-
let completedTasks = 0;
|
|
261
|
-
if (options.parallel) {
|
|
262
|
-
buildSpinner.setText(`Running ${activeTasks.length} build tasks in parallel...`);
|
|
263
|
-
await Promise.all(
|
|
264
|
-
activeTasks.map(async ({ task }) => {
|
|
265
|
-
await task(ctx);
|
|
266
|
-
completedTasks++;
|
|
267
|
-
buildSpinner.setProgress({
|
|
268
|
-
current: completedTasks,
|
|
269
|
-
total: activeTasks.length
|
|
270
|
-
});
|
|
271
|
-
})
|
|
272
|
-
);
|
|
273
|
-
} else {
|
|
274
|
-
for (const { task, name } of activeTasks) {
|
|
275
|
-
completedTasks++;
|
|
276
|
-
buildSpinner.setProgress({
|
|
277
|
-
current: completedTasks,
|
|
278
|
-
total: activeTasks.length
|
|
279
|
-
});
|
|
280
|
-
buildSpinner.setText(`Running ${name}...`);
|
|
281
|
-
await task(ctx);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
if (options.clean) {
|
|
228
|
+
relinka("info", "Cleaning output directories...");
|
|
229
|
+
for (const dir of new Set(
|
|
230
|
+
options.entries.map((e) => e.outDir).filter((p) => !!p).sort()
|
|
231
|
+
)) {
|
|
232
|
+
if (dir === options.rootDir || options.rootDir.startsWith(withTrailingSlash(dir)) || cleanedDirs.some((c) => dir.startsWith(c))) {
|
|
233
|
+
continue;
|
|
284
234
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
235
|
+
cleanedDirs.push(dir);
|
|
236
|
+
relinka("log", `Cleaning dist directory: \`./${relative(process.cwd(), dir)}\``);
|
|
237
|
+
await rmdir(dir);
|
|
238
|
+
await fsp.mkdir(dir, { recursive: true });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
const buildTasks = [
|
|
242
|
+
{ name: "Type generation", task: typesBuild },
|
|
243
|
+
{ name: "mkdist build", task: mkdistBuild },
|
|
244
|
+
{ name: "Rollup build", task: rollupBuild },
|
|
245
|
+
{ name: "Copy files", task: copyBuild }
|
|
246
|
+
];
|
|
247
|
+
const activeTasks = buildTasks.filter(({ task }) => {
|
|
248
|
+
if (task === typesBuild) return options.entries.some((e) => e.builder === "untyped");
|
|
249
|
+
if (task === mkdistBuild) return options.entries.some((e) => e.builder === "mkdist");
|
|
250
|
+
if (task === rollupBuild) return options.entries.some((e) => e.builder === "rollup");
|
|
251
|
+
if (task === copyBuild) return options.entries.some((e) => e.builder === "copy");
|
|
252
|
+
return false;
|
|
253
|
+
});
|
|
254
|
+
if (activeTasks.length === 0) {
|
|
255
|
+
relinka("info", "No build tasks to execute");
|
|
256
|
+
} else {
|
|
257
|
+
if (options.parallel) {
|
|
258
|
+
relinka("info", `Running ${activeTasks.length} build tasks in parallel...`);
|
|
259
|
+
await Promise.all(
|
|
260
|
+
activeTasks.map(async ({ task }) => {
|
|
261
|
+
await task(ctx);
|
|
262
|
+
})
|
|
263
|
+
);
|
|
264
|
+
} else {
|
|
265
|
+
for (const { task, name } of activeTasks) {
|
|
266
|
+
relinka("info", `Running ${name}...`);
|
|
267
|
+
await task(ctx);
|
|
288
268
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (options.transpileStub || options.transpileWatch) {
|
|
272
|
+
await ctx.hooks.callHook("build:done", ctx);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
relinka("info", "Finalizing build output...");
|
|
276
|
+
relinka("success", `Build succeeded for ${options.name}`);
|
|
277
|
+
const outFiles = await glob(["**"], { cwd: options.outDir });
|
|
278
|
+
for (const file of outFiles) {
|
|
279
|
+
let entry = ctx.buildEntries.find((e) => e.path === file);
|
|
280
|
+
if (!entry) {
|
|
281
|
+
entry = {
|
|
282
|
+
chunk: true,
|
|
283
|
+
path: file,
|
|
284
|
+
isLib: ctx.options.isLib
|
|
285
|
+
};
|
|
286
|
+
ctx.buildEntries.push(entry);
|
|
287
|
+
}
|
|
288
|
+
if (!entry.bytes) {
|
|
289
|
+
const stat = await fsp.stat(resolve(options.outDir, file));
|
|
290
|
+
entry.bytes = stat.size;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
const rPath = (p) => relative(process.cwd(), resolve(options.outDir, p));
|
|
294
|
+
if (showOutLog) {
|
|
295
|
+
for (const entry of ctx.buildEntries.filter((e) => !e.chunk)) {
|
|
296
|
+
let totalBytes = entry.bytes || 0;
|
|
297
|
+
for (const chunk of entry.chunks || []) {
|
|
298
|
+
totalBytes += ctx.buildEntries.find((e) => e.path === chunk)?.bytes || 0;
|
|
306
299
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
let line = ` ${rPath(entry.path)} (${[
|
|
315
|
-
totalBytes && `total size: ${prettyBytes(totalBytes)}`,
|
|
316
|
-
entry.bytes && `chunk size: ${prettyBytes(entry.bytes)}`,
|
|
317
|
-
entry.exports?.length && `exports: ${entry.exports.join(", ")}`
|
|
318
|
-
].filter(Boolean).join(", ")})`;
|
|
319
|
-
if (entry.chunks?.length) {
|
|
320
|
-
line += `
|
|
300
|
+
let line = ` ${rPath(entry.path)} (${[
|
|
301
|
+
totalBytes && `total size: ${prettyBytes(totalBytes)}`,
|
|
302
|
+
entry.bytes && `chunk size: ${prettyBytes(entry.bytes)}`,
|
|
303
|
+
entry.exports?.length && `exports: ${entry.exports.join(", ")}`
|
|
304
|
+
].filter(Boolean).join(", ")})`;
|
|
305
|
+
if (entry.chunks?.length) {
|
|
306
|
+
line += `
|
|
321
307
|
${entry.chunks.map((p) => {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
308
|
+
const chunk = ctx.buildEntries.find((e) => e.path === p) || {};
|
|
309
|
+
return ` \u2514\u2500 ${rPath(p)}${chunk.bytes ? ` (${prettyBytes(chunk.bytes)})` : ""}`;
|
|
310
|
+
}).join("\n")}`;
|
|
311
|
+
}
|
|
312
|
+
if (entry.modules?.length) {
|
|
313
|
+
line += `
|
|
328
314
|
${entry.modules.filter((m) => m.id.includes("node_modules")).sort((a, b) => (b.bytes || 0) - (a.bytes || 0)).map((m) => {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
relinka("log", entry.chunk ? line : line);
|
|
333
|
-
}
|
|
334
|
-
const elapsedTime = getElapsedPerfTime(timer);
|
|
335
|
-
const transpileFormattedTime = prettyMilliseconds(elapsedTime, {
|
|
336
|
-
verbose: true
|
|
337
|
-
});
|
|
338
|
-
const totalSize = ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0);
|
|
339
|
-
buildSpinner.setText(
|
|
340
|
-
`Build complete! ${prettyBytes(totalSize)} in ${transpileFormattedTime}`
|
|
341
|
-
);
|
|
342
|
-
relinka(
|
|
343
|
-
"info",
|
|
344
|
-
`\u03A3 Total dist size: ${prettyBytes(totalSize)} (build time: ${transpileFormattedTime})`
|
|
345
|
-
);
|
|
315
|
+
return ` \u{1F4E6} ${rPath(m.id)}${m.bytes ? ` (${prettyBytes(m.bytes)})` : ""}`;
|
|
316
|
+
}).join("\n")}`;
|
|
346
317
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
318
|
+
relinka("log", entry.chunk ? line : line);
|
|
319
|
+
}
|
|
320
|
+
const elapsedTime = getElapsedPerfTime(timer);
|
|
321
|
+
const transpileFormattedTime = prettyMilliseconds(elapsedTime, {
|
|
322
|
+
verbose: true
|
|
323
|
+
});
|
|
324
|
+
const totalSize = ctx.buildEntries.reduce((a, e) => a + (e.bytes || 0), 0);
|
|
325
|
+
relinka("info", `Build complete! ${prettyBytes(totalSize)} in ${transpileFormattedTime}`);
|
|
326
|
+
relinka(
|
|
327
|
+
"info",
|
|
328
|
+
`\u03A3 Total dist size: ${prettyBytes(totalSize)} (build time: ${transpileFormattedTime})`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
validateDependencies(ctx);
|
|
332
|
+
validatePackage(pkg, rootDir, ctx);
|
|
333
|
+
await ctx.hooks.callHook("build:done", ctx);
|
|
334
|
+
if (ctx.warnings.size > 0) {
|
|
335
|
+
relinka("warn", `Build completed with ${ctx.warnings.size} warnings`);
|
|
336
|
+
relinka(
|
|
337
|
+
"warn",
|
|
338
|
+
`Build is done with some warnings:
|
|
356
339
|
${[...ctx.warnings].map((msg) => `- ${msg}`).join("\n")}`
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}
|
|
365
|
-
shouldStopAtStep(15);
|
|
366
|
-
relinka("info", `Build complete (with ${ctx.warnings.size} warnings)`);
|
|
367
|
-
}
|
|
368
|
-
},
|
|
369
|
-
{
|
|
370
|
-
text: _transpileStubMode ? `Stubbing ${pkg?.name || "project"}...` : `Building ${pkg?.name || "project"}...`,
|
|
371
|
-
color: "green",
|
|
372
|
-
successText: `${pkg?.name || "Project"} built successfully!`,
|
|
373
|
-
failText: `Build failed for ${pkg?.name || "project"}`,
|
|
374
|
-
prefixText: "[unified]"
|
|
340
|
+
);
|
|
341
|
+
if (ctx.options.transpileFailOnWarn) {
|
|
342
|
+
relinka(
|
|
343
|
+
"error",
|
|
344
|
+
"Exiting with code (1). You can change this behavior by setting `transpileFailOnWarn: false` ."
|
|
345
|
+
);
|
|
346
|
+
process.exit(1);
|
|
375
347
|
}
|
|
376
|
-
|
|
348
|
+
shouldStopAtStep(15);
|
|
349
|
+
relinka("info", `Build complete (with ${ctx.warnings.size} warnings)`);
|
|
350
|
+
}
|
|
377
351
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolve, extname, join, basename, dirname } from "@reliverse/pathkit";
|
|
2
|
-
import {
|
|
2
|
+
import { relinka } from "@reliverse/relinka";
|
|
3
3
|
import defu from "defu";
|
|
4
4
|
import fsp from "node:fs/promises";
|
|
5
5
|
import { glob } from "tinyglobby";
|
|
@@ -8,206 +8,196 @@ import { getDeclarations, normalizeCompilerOptions } from "./utils/dts.js";
|
|
|
8
8
|
import { copyFileWithStream } from "./utils/fs.js";
|
|
9
9
|
import { getVueDeclarations } from "./utils/vue-dts.js";
|
|
10
10
|
export async function mkdist(options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
const startTime = Date.now();
|
|
12
|
+
options.rootDir = resolve(process.cwd(), options.rootDir || ".");
|
|
13
|
+
options.srcDir = resolve(options.rootDir, options.srcDir || "src");
|
|
14
|
+
options.distDir = resolve(options.rootDir, options.distDir || "dist");
|
|
15
|
+
if (options.cleanDist !== false) {
|
|
16
|
+
relinka("info", "Cleaning distribution directory...");
|
|
17
|
+
await fsp.unlink(options.distDir).catch(() => {
|
|
18
|
+
});
|
|
19
|
+
await fsp.rm(options.distDir, { recursive: true, force: true });
|
|
20
|
+
await fsp.mkdir(options.distDir, { recursive: true });
|
|
21
|
+
}
|
|
22
|
+
relinka("info", "Scanning input files...");
|
|
23
|
+
const filePaths = await glob(options.pattern || "**", {
|
|
24
|
+
absolute: false,
|
|
25
|
+
ignore: ["**/node_modules", "**/coverage", "**/.git"],
|
|
26
|
+
cwd: options.srcDir,
|
|
27
|
+
dot: true,
|
|
28
|
+
...options.globOptions
|
|
29
|
+
});
|
|
30
|
+
const files = filePaths.map((path) => {
|
|
31
|
+
const sourcePath = resolve(options.srcDir, path);
|
|
32
|
+
return {
|
|
33
|
+
path,
|
|
34
|
+
srcPath: sourcePath,
|
|
35
|
+
extension: extname(path),
|
|
36
|
+
getContents: () => fsp.readFile(sourcePath, { encoding: "utf8" })
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
relinka("info", `Found ${files.length} files to process`);
|
|
40
|
+
options.typescript ||= {};
|
|
41
|
+
if (options.typescript.compilerOptions) {
|
|
42
|
+
relinka("info", "Normalizing TypeScript compiler options...");
|
|
43
|
+
options.typescript.compilerOptions = await normalizeCompilerOptions(
|
|
44
|
+
options.typescript.compilerOptions
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
options.typescript.compilerOptions = defu(
|
|
48
|
+
{ noEmit: false },
|
|
49
|
+
options.typescript.compilerOptions,
|
|
50
|
+
{
|
|
51
|
+
allowJs: true,
|
|
52
|
+
declaration: true,
|
|
53
|
+
skipLibCheck: true,
|
|
54
|
+
strictNullChecks: true,
|
|
55
|
+
emitDeclarationOnly: true,
|
|
56
|
+
allowImportingTsExtensions: true,
|
|
57
|
+
allowNonTsExtensions: true
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
relinka("info", "Creating file loaders...");
|
|
61
|
+
const { loadFile } = createLoader(options);
|
|
62
|
+
relinka("info", "Processing files with loaders...");
|
|
63
|
+
const outputs = [];
|
|
64
|
+
let processedCount = 0;
|
|
65
|
+
await Promise.all(
|
|
66
|
+
files.map(async (file) => {
|
|
67
|
+
const result = await loadFile(file);
|
|
68
|
+
if (result) {
|
|
69
|
+
outputs.push(...result);
|
|
22
70
|
}
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
cwd: options.srcDir,
|
|
28
|
-
dot: true,
|
|
29
|
-
...options.globOptions
|
|
30
|
-
});
|
|
31
|
-
const files = filePaths.map((path) => {
|
|
32
|
-
const sourcePath = resolve(options.srcDir, path);
|
|
33
|
-
return {
|
|
34
|
-
path,
|
|
35
|
-
srcPath: sourcePath,
|
|
36
|
-
extension: extname(path),
|
|
37
|
-
getContents: () => fsp.readFile(sourcePath, { encoding: "utf8" })
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
mainSpinner.setText(`Found ${files.length} files to process`);
|
|
41
|
-
options.typescript ||= {};
|
|
42
|
-
if (options.typescript.compilerOptions) {
|
|
43
|
-
mainSpinner.setText("Normalizing TypeScript compiler options...");
|
|
44
|
-
options.typescript.compilerOptions = await normalizeCompilerOptions(
|
|
45
|
-
options.typescript.compilerOptions
|
|
46
|
-
);
|
|
71
|
+
processedCount++;
|
|
72
|
+
const shouldUpdate = processedCount % Math.max(1, Math.floor(files.length / 10)) === 0 || processedCount === files.length;
|
|
73
|
+
if (shouldUpdate) {
|
|
74
|
+
relinka("verbose", `Processing files: ${file.path} (${processedCount}/${files.length})`);
|
|
47
75
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
mainSpinner.setText(`Processing files: ${file.path}`);
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
);
|
|
83
|
-
mainSpinner.setText("Normalizing output extensions...");
|
|
84
|
-
const pathConflicts = [];
|
|
85
|
-
for (const output of outputs.filter((o) => o.extension)) {
|
|
86
|
-
const renamed = basename(output.path, extname(output.path)) + output.extension;
|
|
87
|
-
output.path = join(dirname(output.path), renamed);
|
|
88
|
-
const conflictingOutput = outputs.find((o) => o !== output && o.path === output.path);
|
|
89
|
-
if (conflictingOutput) {
|
|
90
|
-
pathConflicts.push(output.path);
|
|
91
|
-
}
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
relinka("info", "Normalizing output extensions...");
|
|
79
|
+
const pathConflicts = [];
|
|
80
|
+
for (const output of outputs.filter((o) => o.extension)) {
|
|
81
|
+
const renamed = basename(output.path, extname(output.path)) + output.extension;
|
|
82
|
+
output.path = join(dirname(output.path), renamed);
|
|
83
|
+
const conflictingOutput = outputs.find((o) => o !== output && o.path === output.path);
|
|
84
|
+
if (conflictingOutput) {
|
|
85
|
+
pathConflicts.push(output.path);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (pathConflicts.length > 0) {
|
|
89
|
+
const errorMessage = `Output path conflict detected for paths: ${pathConflicts.join(", ")}. Multiple files would write to the same output path.`;
|
|
90
|
+
relinka("error", errorMessage);
|
|
91
|
+
throw new Error(errorMessage);
|
|
92
|
+
}
|
|
93
|
+
const dtsOutputs = outputs.filter((o) => o.declaration && !o.skip);
|
|
94
|
+
if (dtsOutputs.length > 0) {
|
|
95
|
+
relinka("info", `Generating TypeScript declarations for ${dtsOutputs.length} files...`);
|
|
96
|
+
const vfs = new Map(dtsOutputs.map((o) => [o.srcPath, o.contents || ""]));
|
|
97
|
+
const declarations = /* @__PURE__ */ Object.create(null);
|
|
98
|
+
for (const loader of [getVueDeclarations, getDeclarations]) {
|
|
99
|
+
Object.assign(declarations, await loader(vfs, options));
|
|
100
|
+
}
|
|
101
|
+
let dtsProcessed = 0;
|
|
102
|
+
for (const output of dtsOutputs) {
|
|
103
|
+
const result = declarations[output.srcPath];
|
|
104
|
+
output.contents = result?.contents || "";
|
|
105
|
+
if (result.errors) {
|
|
106
|
+
output.errors = result.errors;
|
|
92
107
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
throw new Error(errorMessage);
|
|
108
|
+
dtsProcessed++;
|
|
109
|
+
if (dtsProcessed % Math.max(1, Math.floor(dtsOutputs.length / 5)) === 0) {
|
|
110
|
+
relinka("verbose", `Generated declarations for ${dtsProcessed}/${dtsOutputs.length} files`);
|
|
97
111
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
output.contents = result?.contents || "";
|
|
110
|
-
if (result.errors) {
|
|
111
|
-
output.errors = result.errors;
|
|
112
|
-
}
|
|
113
|
-
dtsProcessed++;
|
|
114
|
-
if (dtsProcessed % Math.max(1, Math.floor(dtsOutputs.length / 5)) === 0) {
|
|
115
|
-
mainSpinner.setProgress({
|
|
116
|
-
current: dtsProcessed,
|
|
117
|
-
total: dtsOutputs.length
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
relinka("info", "Resolving relative imports...");
|
|
115
|
+
const outPaths = new Set(outputs.map((o) => o.path));
|
|
116
|
+
const resolveId = (from, id = "", resolveExtensions) => {
|
|
117
|
+
if (!id.startsWith(".")) {
|
|
118
|
+
return id;
|
|
119
|
+
}
|
|
120
|
+
for (const extension of resolveExtensions) {
|
|
121
|
+
if (outPaths.has(join(dirname(from), id + extension))) {
|
|
122
|
+
return id + extension;
|
|
121
123
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
}
|
|
125
|
+
return id;
|
|
126
|
+
};
|
|
127
|
+
const esmResolveExtensions = ["", "/index.mjs", "/index.js", ".mjs", ".ts", ".js"];
|
|
128
|
+
const esmOutputs = outputs.filter((o) => o.extension === ".mjs" || o.extension === ".js");
|
|
129
|
+
for (const output of esmOutputs) {
|
|
130
|
+
output.contents = output.contents.replace(
|
|
131
|
+
/(import|export)(\s+(?:.+|{[\s\w,]+})\s+from\s+["'])(.*)(["'])/g,
|
|
132
|
+
(_, type, head, id, tail) => type + head + resolveId(output.path, id, esmResolveExtensions) + tail
|
|
133
|
+
).replace(
|
|
134
|
+
/import\((["'])(.*)(["'])\)/g,
|
|
135
|
+
(_, head, id, tail) => "import(" + head + resolveId(output.path, id, esmResolveExtensions) + tail + ")"
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
const cjsResolveExtensions = ["", "/index.cjs", ".cjs"];
|
|
139
|
+
const cjsOutputs = outputs.filter((o) => o.extension === ".cjs");
|
|
140
|
+
for (const output of cjsOutputs) {
|
|
141
|
+
output.contents = output.contents.replace(
|
|
142
|
+
/require\((["'])(.*)(["'])\)/g,
|
|
143
|
+
(_, head, id, tail) => "require(" + head + resolveId(output.path, id, cjsResolveExtensions) + tail + ")"
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
const outputsToWrite = outputs.filter((o) => !o.skip);
|
|
147
|
+
relinka("info", `Writing ${outputsToWrite.length} output files...`);
|
|
148
|
+
const writtenFiles = [];
|
|
149
|
+
const errors = [];
|
|
150
|
+
let writtenCount = 0;
|
|
151
|
+
await Promise.all(
|
|
152
|
+
outputsToWrite.map(async (output) => {
|
|
153
|
+
try {
|
|
154
|
+
const outFile = join(options.distDir, output.path);
|
|
155
|
+
await fsp.mkdir(dirname(outFile), { recursive: true });
|
|
156
|
+
await (output.raw ? (
|
|
157
|
+
// @ts-expect-error TODO: fix ts
|
|
158
|
+
copyFileWithStream(output.srcPath, outFile)
|
|
159
|
+
) : (
|
|
160
|
+
// @ts-expect-error TODO: fix ts
|
|
161
|
+
fsp.writeFile(outFile, output.contents, "utf8")
|
|
162
|
+
));
|
|
163
|
+
writtenFiles.push(outFile);
|
|
164
|
+
if (output.errors) {
|
|
165
|
+
errors.push({ filename: outFile, errors: output.errors });
|
|
132
166
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/(import|export)(\s+(?:.+|{[\s\w,]+})\s+from\s+["'])(.*)(["'])/g,
|
|
140
|
-
(_, type, head, id, tail) => type + head + resolveId(output.path, id, esmResolveExtensions) + tail
|
|
141
|
-
).replace(
|
|
142
|
-
/import\((["'])(.*)(["'])\)/g,
|
|
143
|
-
(_, head, id, tail) => "import(" + head + resolveId(output.path, id, esmResolveExtensions) + tail + ")"
|
|
144
|
-
);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
const errorMessage = `Failed to write file ${output.path}: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
169
|
+
errors.push({
|
|
170
|
+
filename: output.path,
|
|
171
|
+
errors: [new TypeError(errorMessage)]
|
|
172
|
+
});
|
|
145
173
|
}
|
|
146
|
-
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
/require\((["'])(.*)(["'])\)/g,
|
|
151
|
-
(_, head, id, tail) => "require(" + head + resolveId(output.path, id, cjsResolveExtensions) + tail + ")"
|
|
152
|
-
);
|
|
174
|
+
writtenCount++;
|
|
175
|
+
const progressUpdateInterval = Math.max(10, Math.floor(outputsToWrite.length / 10));
|
|
176
|
+
if (writtenCount % progressUpdateInterval === 0 || writtenCount === outputsToWrite.length) {
|
|
177
|
+
relinka("verbose", `Written ${writtenCount}/${outputsToWrite.length} files`);
|
|
153
178
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
await fsp.mkdir(dirname(outFile), { recursive: true });
|
|
164
|
-
await (output.raw ? (
|
|
165
|
-
// @ts-expect-error TODO: fix ts
|
|
166
|
-
copyFileWithStream(output.srcPath, outFile)
|
|
167
|
-
) : (
|
|
168
|
-
// @ts-expect-error TODO: fix ts
|
|
169
|
-
fsp.writeFile(outFile, output.contents, "utf8")
|
|
170
|
-
));
|
|
171
|
-
writtenFiles.push(outFile);
|
|
172
|
-
if (output.errors) {
|
|
173
|
-
errors.push({ filename: outFile, errors: output.errors });
|
|
174
|
-
}
|
|
175
|
-
} catch (error) {
|
|
176
|
-
const errorMessage = `Failed to write file ${output.path}: ${error instanceof Error ? error.message : "Unknown error"}`;
|
|
177
|
-
errors.push({
|
|
178
|
-
filename: output.path,
|
|
179
|
-
errors: [new TypeError(errorMessage)]
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
writtenCount++;
|
|
183
|
-
const progressUpdateInterval = Math.max(10, Math.floor(outputsToWrite.length / 10));
|
|
184
|
-
if (writtenCount % progressUpdateInterval === 0 || writtenCount === outputsToWrite.length) {
|
|
185
|
-
mainSpinner.setProgress({
|
|
186
|
-
current: writtenCount,
|
|
187
|
-
total: outputsToWrite.length
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
})
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
const duration = Date.now() - startTime;
|
|
182
|
+
if (errors.length > 0) {
|
|
183
|
+
relinka("warn", `Build completed with ${errors.length} errors`);
|
|
184
|
+
for (const error of errors.slice(0, 5)) {
|
|
185
|
+
relinka(
|
|
186
|
+
"error",
|
|
187
|
+
`Error in ${error.filename}: ${error.errors[0]?.message || "Unknown error"}`
|
|
191
188
|
);
|
|
192
|
-
if (errors.length > 0) {
|
|
193
|
-
mainSpinner.warn(`Build completed with ${errors.length} errors`);
|
|
194
|
-
for (const error of errors.slice(0, 5)) {
|
|
195
|
-
console.error(`Error in ${error.filename}:`, error.errors[0]?.message || "Unknown error");
|
|
196
|
-
}
|
|
197
|
-
if (errors.length > 5) {
|
|
198
|
-
console.error(`... and ${errors.length - 5} more errors`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return {
|
|
202
|
-
errors,
|
|
203
|
-
writtenFiles
|
|
204
|
-
};
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
text: "Building using mkdist...",
|
|
208
|
-
color: "cyan",
|
|
209
|
-
successText: "Build completed successfully!",
|
|
210
|
-
failText: "Build failed!"
|
|
211
189
|
}
|
|
212
|
-
|
|
190
|
+
if (errors.length > 5) {
|
|
191
|
+
relinka("error", `... and ${errors.length - 5} more errors`);
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
relinka("success", "Build completed successfully!");
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
result: {
|
|
198
|
+
errors,
|
|
199
|
+
writtenFiles
|
|
200
|
+
},
|
|
201
|
+
duration
|
|
202
|
+
};
|
|
213
203
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { relative, dirname as pathDirname } from "@reliverse/pathkit";
|
|
2
2
|
import { relinka } from "@reliverse/relinka";
|
|
3
|
-
import { useSpinner } from "@reliverse/rempts";
|
|
4
3
|
import { rmdir, symlink, warn } from "../utils.js";
|
|
5
4
|
import { mkdist } from "./mkdist-impl/make.js";
|
|
6
5
|
export async function mkdistBuild(ctx) {
|
|
@@ -8,100 +7,86 @@ export async function mkdistBuild(ctx) {
|
|
|
8
7
|
if (entries.length === 0) {
|
|
9
8
|
return;
|
|
10
9
|
}
|
|
11
|
-
await
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
path: distDir,
|
|
64
|
-
isLib: ctx.options.isLib
|
|
65
|
-
});
|
|
66
|
-
await ctx.hooks.callHook("mkdist:entry:build", ctx, entry, output);
|
|
67
|
-
if (output.errors && output.errors.length > 0) {
|
|
68
|
-
totalErrors += output.errors.length;
|
|
69
|
-
for (const error of output.errors) {
|
|
70
|
-
warn(
|
|
71
|
-
ctx,
|
|
72
|
-
`mkdist build failed for \`${relative(ctx.options.rootDir, error.filename)}\`:
|
|
73
|
-
${error.errors.map((e) => ` - ${e}`).join("\n")}`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
} catch (error) {
|
|
78
|
-
totalErrors++;
|
|
10
|
+
await ctx.hooks.callHook("mkdist:entries", ctx, entries);
|
|
11
|
+
let processedEntries = 0;
|
|
12
|
+
let totalWrittenFiles = 0;
|
|
13
|
+
let totalErrors = 0;
|
|
14
|
+
relinka("info", `Processing ${entries.length} mkdist entries...`);
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
processedEntries++;
|
|
17
|
+
relinka("info", `Processing entry ${processedEntries}/${entries.length}: ${entry.input}`);
|
|
18
|
+
const distDir = entry.outDir || entry.input;
|
|
19
|
+
if (ctx.options.transpileStub) {
|
|
20
|
+
await rmdir(distDir);
|
|
21
|
+
await symlink(entry.input, distDir);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
let srcDir;
|
|
25
|
+
if (typeof entry.input === "string" && !entry.input.endsWith("/")) {
|
|
26
|
+
srcDir = ctx.options.isLib ? pathDirname(entry.input) : entry.input;
|
|
27
|
+
relinka(
|
|
28
|
+
"verbose",
|
|
29
|
+
`[mkdist] Using directory from file path: ${srcDir} (from: ${entry.input})`
|
|
30
|
+
);
|
|
31
|
+
} else {
|
|
32
|
+
srcDir = entry.input;
|
|
33
|
+
relinka("verbose", `[mkdist] Using directory directly: ${srcDir}`);
|
|
34
|
+
}
|
|
35
|
+
const mkdistOptions = {
|
|
36
|
+
cleanDist: false,
|
|
37
|
+
distDir,
|
|
38
|
+
rootDir: ctx.options.rootDir,
|
|
39
|
+
srcDir,
|
|
40
|
+
format: "esm",
|
|
41
|
+
ext: entry.ext || "js",
|
|
42
|
+
...entry
|
|
43
|
+
};
|
|
44
|
+
relinka(
|
|
45
|
+
"info",
|
|
46
|
+
`[mkdist] Building with options: srcDir=${mkdistOptions.srcDir}, distDir=${mkdistOptions.distDir}, rootDir=${mkdistOptions.rootDir}`
|
|
47
|
+
);
|
|
48
|
+
await ctx.hooks.callHook("mkdist:entry:options", ctx, entry, mkdistOptions);
|
|
49
|
+
try {
|
|
50
|
+
const { result: output, duration } = await mkdist(mkdistOptions);
|
|
51
|
+
relinka("verbose", `[mkdist] Entry ${processedEntries} completed in ${duration}ms`);
|
|
52
|
+
totalWrittenFiles += output.writtenFiles.length;
|
|
53
|
+
ctx.buildEntries.push({
|
|
54
|
+
chunks: output.writtenFiles.map((p) => relative(ctx.options.outDir, p)),
|
|
55
|
+
path: distDir,
|
|
56
|
+
isLib: ctx.options.isLib
|
|
57
|
+
});
|
|
58
|
+
await ctx.hooks.callHook("mkdist:entry:build", ctx, entry, output);
|
|
59
|
+
if (output.errors && output.errors.length > 0) {
|
|
60
|
+
totalErrors += output.errors.length;
|
|
61
|
+
for (const error of output.errors) {
|
|
79
62
|
warn(
|
|
80
63
|
ctx,
|
|
81
|
-
`mkdist build failed for
|
|
64
|
+
`mkdist build failed for \`${relative(ctx.options.rootDir, error.filename)}\`:
|
|
65
|
+
${error.errors.map((e) => ` - ${e}`).join("\n")}`
|
|
82
66
|
);
|
|
83
67
|
}
|
|
84
68
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
`Processed ${entries.length} entries with ${totalErrors} errors. ${totalWrittenFiles} files written.`
|
|
92
|
-
);
|
|
93
|
-
} else {
|
|
94
|
-
mainSpinner.setText(
|
|
95
|
-
`Successfully processed ${entries.length} entries. ${totalWrittenFiles} files written.`
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
text: entries.length === 1 ? "Processing mkdist entry..." : `Processing ${entries.length} mkdist entries...`,
|
|
101
|
-
color: "blue",
|
|
102
|
-
successText: entries.length === 1 ? "mkdist entry completed!" : `All ${entries.length} mkdist entries completed!`,
|
|
103
|
-
failText: "mkdist build failed!",
|
|
104
|
-
prefixText: "[mkdist]"
|
|
69
|
+
} catch (error) {
|
|
70
|
+
totalErrors++;
|
|
71
|
+
warn(
|
|
72
|
+
ctx,
|
|
73
|
+
`mkdist build failed for entry ${entry.input}: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
74
|
+
);
|
|
105
75
|
}
|
|
106
|
-
|
|
76
|
+
}
|
|
77
|
+
await ctx.hooks.callHook("mkdist:done", ctx);
|
|
78
|
+
if (entries.length > 0 && ctx.options.transpileWatch) {
|
|
79
|
+
relinka("warn", "`mkdist` builder does not support transpileWatch mode yet.");
|
|
80
|
+
}
|
|
81
|
+
if (totalErrors > 0) {
|
|
82
|
+
relinka(
|
|
83
|
+
"warn",
|
|
84
|
+
`Processed ${entries.length} entries with ${totalErrors} errors. ${totalWrittenFiles} files written.`
|
|
85
|
+
);
|
|
86
|
+
} else {
|
|
87
|
+
relinka(
|
|
88
|
+
"success",
|
|
89
|
+
`Successfully processed ${entries.length} entries. ${totalWrittenFiles} files written.`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
107
92
|
}
|