balm-core 6.0.0-alpha.2 → 6.0.0-alpha.3
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/CHANGELOG.md +16 -0
- package/dist/index.cjs +395 -111
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +381 -97
- package/dist/index.js.map +1 -1
- package/package.json +38 -1
- package/src/balm.ts +0 -107
- package/src/bundler/esbuild.ts +0 -48
- package/src/bundler/index.ts +0 -3
- package/src/bundler/rollup.ts +0 -46
- package/src/bundler/webpack.ts +0 -125
- package/src/config/constants.ts +0 -12
- package/src/config/defaults.ts +0 -212
- package/src/config/index.ts +0 -112
- package/src/hooks/index.ts +0 -224
- package/src/index.ts +0 -16
- package/src/pipeline/file.ts +0 -69
- package/src/pipeline/index.ts +0 -10
- package/src/pipeline/pipeline.ts +0 -135
- package/src/pipeline/transforms/cache.ts +0 -147
- package/src/pipeline/transforms/htmlmin.ts +0 -18
- package/src/pipeline/transforms/less.ts +0 -75
- package/src/pipeline/transforms/postcss.ts +0 -43
- package/src/pipeline/transforms/rename.ts +0 -38
- package/src/pipeline/transforms/replace.ts +0 -30
- package/src/pipeline/transforms/sass.ts +0 -106
- package/src/pipeline/transforms/terser.ts +0 -20
- package/src/runner/dag.ts +0 -77
- package/src/runner/task.ts +0 -38
- package/src/shims.d.ts +0 -5
- package/src/tasks/cache.ts +0 -84
- package/src/tasks/clean.ts +0 -21
- package/src/tasks/copy.ts +0 -36
- package/src/tasks/ftp.ts +0 -90
- package/src/tasks/html.ts +0 -290
- package/src/tasks/index.ts +0 -14
- package/src/tasks/publish.ts +0 -71
- package/src/tasks/pwa.ts +0 -86
- package/src/tasks/remove.ts +0 -24
- package/src/tasks/replace.ts +0 -34
- package/src/tasks/script.ts +0 -28
- package/src/tasks/server.ts +0 -218
- package/src/tasks/static.ts +0 -77
- package/src/tasks/style.ts +0 -57
- package/src/tasks/zip.ts +0 -77
- package/src/types/index.ts +0 -225
- package/src/utilities/file.ts +0 -140
- package/src/utilities/logger.ts +0 -63
- package/src/utilities/utils.ts +0 -46
- package/src/utilities/workspace.ts +0 -38
- package/src/watcher/index.ts +0 -100
- package/tsconfig.json +0 -8
- package/tsup.config.ts +0 -12
package/dist/index.cjs
CHANGED
|
@@ -93,7 +93,7 @@ __export(index_exports, {
|
|
|
93
93
|
});
|
|
94
94
|
module.exports = __toCommonJS(index_exports);
|
|
95
95
|
|
|
96
|
-
// ../../node_modules/.pnpm/tsup@8.5.
|
|
96
|
+
// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.7.0_postcss@8.5.26_typescript@5.9.3_yaml@2.9.0/node_modules/tsup/assets/cjs_shims.js
|
|
97
97
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
98
98
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
99
99
|
|
|
@@ -182,6 +182,19 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
182
182
|
js: true,
|
|
183
183
|
url: true
|
|
184
184
|
},
|
|
185
|
+
includeJsResource: [],
|
|
186
|
+
excludeUrlResource: [],
|
|
187
|
+
useEsModule: true,
|
|
188
|
+
urlLoaderOptions: {},
|
|
189
|
+
babelLoaderOptions: {},
|
|
190
|
+
htmlLoaderOptions: {},
|
|
191
|
+
postcssLoaderOptions: {},
|
|
192
|
+
sourceMap: false,
|
|
193
|
+
stats: void 0,
|
|
194
|
+
optimization: {},
|
|
195
|
+
extractAllVendors: false,
|
|
196
|
+
vendorName: "vendor",
|
|
197
|
+
extractCss: false,
|
|
185
198
|
options: {},
|
|
186
199
|
esbuildOptions: {},
|
|
187
200
|
rollupOptions: {},
|
|
@@ -220,6 +233,10 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
220
233
|
includes: [],
|
|
221
234
|
excludes: []
|
|
222
235
|
};
|
|
236
|
+
const extras = {
|
|
237
|
+
includes: [],
|
|
238
|
+
excludes: []
|
|
239
|
+
};
|
|
223
240
|
const server = {
|
|
224
241
|
host: null,
|
|
225
242
|
port: 3e3,
|
|
@@ -293,6 +310,7 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
293
310
|
scripts,
|
|
294
311
|
html,
|
|
295
312
|
assets,
|
|
313
|
+
extras,
|
|
296
314
|
server,
|
|
297
315
|
pwa,
|
|
298
316
|
ftp,
|
|
@@ -321,13 +339,18 @@ function isFunction(val) {
|
|
|
321
339
|
function isBoolean(val) {
|
|
322
340
|
return typeof val === "boolean";
|
|
323
341
|
}
|
|
342
|
+
function isPlainObject(val) {
|
|
343
|
+
if (val === null || typeof val !== "object") return false;
|
|
344
|
+
const proto = Object.getPrototypeOf(val);
|
|
345
|
+
return proto === Object.prototype || proto === null;
|
|
346
|
+
}
|
|
324
347
|
function deepMerge(target, ...sources) {
|
|
325
348
|
if (!sources.length) return target;
|
|
326
349
|
const source = sources.shift();
|
|
327
|
-
if (
|
|
350
|
+
if (isPlainObject(target) && isPlainObject(source)) {
|
|
328
351
|
for (const key in source) {
|
|
329
|
-
if (
|
|
330
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
352
|
+
if (isPlainObject(source[key])) {
|
|
353
|
+
if (!isPlainObject(target[key])) Object.assign(target, { [key]: {} });
|
|
331
354
|
deepMerge(target[key], source[key]);
|
|
332
355
|
} else if (isArray(source[key])) {
|
|
333
356
|
target[key] = [...source[key]];
|
|
@@ -1123,6 +1146,172 @@ var StyleTask = class extends BaseTask {
|
|
|
1123
1146
|
// src/bundler/webpack.ts
|
|
1124
1147
|
var import_webpack = __toESM(require("webpack"), 1);
|
|
1125
1148
|
var import_node_path11 = __toESM(require("path"), 1);
|
|
1149
|
+
var import_node_fs3 = require("fs");
|
|
1150
|
+
var import_node_module = require("module");
|
|
1151
|
+
var import_autoprefixer2 = __toESM(require("autoprefixer"), 1);
|
|
1152
|
+
var import_postcss_preset_env2 = __toESM(require("postcss-preset-env"), 1);
|
|
1153
|
+
var coreRequire = (0, import_node_module.createRequire)(importMetaUrl);
|
|
1154
|
+
var BABEL_CONFIG_FILES = [
|
|
1155
|
+
"babel.config.js",
|
|
1156
|
+
"babel.config.cjs",
|
|
1157
|
+
"babel.config.mjs",
|
|
1158
|
+
"babel.config.json",
|
|
1159
|
+
".babelrc",
|
|
1160
|
+
".babelrc.js",
|
|
1161
|
+
".babelrc.cjs",
|
|
1162
|
+
".babelrc.json"
|
|
1163
|
+
];
|
|
1164
|
+
function resolveModule(pkgName, workspace) {
|
|
1165
|
+
try {
|
|
1166
|
+
const workspaceRequire = (0, import_node_module.createRequire)(import_node_path11.default.join(workspace, "package.json"));
|
|
1167
|
+
return workspaceRequire.resolve(pkgName);
|
|
1168
|
+
} catch {
|
|
1169
|
+
return coreRequire.resolve(pkgName);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function resolveWorkspacePaths(paths, workspace) {
|
|
1173
|
+
if (!paths || !paths.length) return [];
|
|
1174
|
+
return paths.map((p) => import_node_path11.default.isAbsolute(p) ? p : import_node_path11.default.resolve(workspace, p));
|
|
1175
|
+
}
|
|
1176
|
+
function hasBabelConfig(config) {
|
|
1177
|
+
if (config.scripts.babelLoaderOptions && Object.keys(config.scripts.babelLoaderOptions).length > 0) {
|
|
1178
|
+
return true;
|
|
1179
|
+
}
|
|
1180
|
+
for (const filename of BABEL_CONFIG_FILES) {
|
|
1181
|
+
if ((0, import_node_fs3.existsSync)(import_node_path11.default.join(config.workspace, filename))) {
|
|
1182
|
+
return true;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
const pkgPath = import_node_path11.default.join(config.workspace, "package.json");
|
|
1186
|
+
if ((0, import_node_fs3.existsSync)(pkgPath)) {
|
|
1187
|
+
try {
|
|
1188
|
+
const pkg = JSON.parse((0, import_node_fs3.readFileSync)(pkgPath, "utf-8"));
|
|
1189
|
+
if (pkg && pkg.babel) {
|
|
1190
|
+
return true;
|
|
1191
|
+
}
|
|
1192
|
+
} catch {
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return false;
|
|
1196
|
+
}
|
|
1197
|
+
function buildDefaultRules(config, dirs, devtool) {
|
|
1198
|
+
const isProd = config.env.isProd;
|
|
1199
|
+
const scripts = config.scripts;
|
|
1200
|
+
const esModule = scripts.useEsModule ?? true;
|
|
1201
|
+
const defaults = {
|
|
1202
|
+
html: true,
|
|
1203
|
+
css: true,
|
|
1204
|
+
js: true,
|
|
1205
|
+
url: true,
|
|
1206
|
+
...scripts.defaultLoaders || {}
|
|
1207
|
+
};
|
|
1208
|
+
const rules = [];
|
|
1209
|
+
if (defaults.html) {
|
|
1210
|
+
rules.push({
|
|
1211
|
+
test: /\.html$/i,
|
|
1212
|
+
exclude: /\.vue\.html$/i,
|
|
1213
|
+
loader: resolveModule("html-loader", config.workspace),
|
|
1214
|
+
options: {
|
|
1215
|
+
minimize: {
|
|
1216
|
+
removeAttributeQuotes: false
|
|
1217
|
+
},
|
|
1218
|
+
esModule,
|
|
1219
|
+
...scripts.htmlLoaderOptions || {}
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
if (defaults.css) {
|
|
1224
|
+
const cssSourceMap = Boolean(devtool);
|
|
1225
|
+
const MiniCssExtractPlugin = coreRequire("mini-css-extract-plugin");
|
|
1226
|
+
const styleLoader = isProd && scripts.extractCss ? {
|
|
1227
|
+
loader: MiniCssExtractPlugin.loader,
|
|
1228
|
+
options: { esModule }
|
|
1229
|
+
} : {
|
|
1230
|
+
loader: resolveModule("style-loader", config.workspace),
|
|
1231
|
+
options: { esModule }
|
|
1232
|
+
};
|
|
1233
|
+
const postcssPlugins = [
|
|
1234
|
+
...config.styles.postcssPlugins || [],
|
|
1235
|
+
(0, import_autoprefixer2.default)(),
|
|
1236
|
+
(0, import_postcss_preset_env2.default)()
|
|
1237
|
+
];
|
|
1238
|
+
const createCssUse = (isModule) => [
|
|
1239
|
+
styleLoader,
|
|
1240
|
+
{
|
|
1241
|
+
loader: resolveModule("css-loader", config.workspace),
|
|
1242
|
+
options: {
|
|
1243
|
+
importLoaders: 1,
|
|
1244
|
+
sourceMap: cssSourceMap,
|
|
1245
|
+
modules: isModule ? { auto: true } : { mode: "icss" },
|
|
1246
|
+
esModule
|
|
1247
|
+
}
|
|
1248
|
+
},
|
|
1249
|
+
{
|
|
1250
|
+
loader: resolveModule("postcss-loader", config.workspace),
|
|
1251
|
+
options: {
|
|
1252
|
+
postcssOptions: {
|
|
1253
|
+
plugins: postcssPlugins
|
|
1254
|
+
},
|
|
1255
|
+
sourceMap: cssSourceMap,
|
|
1256
|
+
...scripts.postcssLoaderOptions || {}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
];
|
|
1260
|
+
rules.push(
|
|
1261
|
+
{
|
|
1262
|
+
test: /\.css$/,
|
|
1263
|
+
exclude: /\.module\.css$/,
|
|
1264
|
+
use: createCssUse(false),
|
|
1265
|
+
sideEffects: true
|
|
1266
|
+
},
|
|
1267
|
+
{
|
|
1268
|
+
test: /\.module\.css$/,
|
|
1269
|
+
use: createCssUse(true)
|
|
1270
|
+
}
|
|
1271
|
+
);
|
|
1272
|
+
}
|
|
1273
|
+
if (defaults.js && hasBabelConfig(config)) {
|
|
1274
|
+
const jsIncludes = [
|
|
1275
|
+
config.src.js,
|
|
1276
|
+
...resolveWorkspacePaths(scripts.includeJsResource, config.workspace)
|
|
1277
|
+
];
|
|
1278
|
+
rules.push({
|
|
1279
|
+
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
|
1280
|
+
include: jsIncludes,
|
|
1281
|
+
loader: resolveModule("babel-loader", config.workspace),
|
|
1282
|
+
options: {
|
|
1283
|
+
cwd: config.workspace,
|
|
1284
|
+
...scripts.babelLoaderOptions || {}
|
|
1285
|
+
}
|
|
1286
|
+
});
|
|
1287
|
+
}
|
|
1288
|
+
if (defaults.url) {
|
|
1289
|
+
const rawLimit = scripts.urlLoaderOptions?.limit ?? (process.env.IMAGE_INLINE_SIZE_LIMIT ? parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT, 10) : 1e4);
|
|
1290
|
+
const maxSize = typeof rawLimit === "number" && rawLimit > 0 ? rawLimit : 0;
|
|
1291
|
+
const excludeUrl = resolveWorkspacePaths(scripts.excludeUrlResource, config.workspace);
|
|
1292
|
+
const createAssetRule = (test, targetDir, exclude) => ({
|
|
1293
|
+
test,
|
|
1294
|
+
...exclude && exclude.length ? { exclude } : {},
|
|
1295
|
+
type: maxSize > 0 ? "asset" : "asset/resource",
|
|
1296
|
+
...maxSize > 0 ? {
|
|
1297
|
+
parser: {
|
|
1298
|
+
dataUrlCondition: {
|
|
1299
|
+
maxSize
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
} : {},
|
|
1303
|
+
generator: {
|
|
1304
|
+
filename: `${targetDir}/[name].[hash:8][ext]`
|
|
1305
|
+
}
|
|
1306
|
+
});
|
|
1307
|
+
rules.push(
|
|
1308
|
+
createAssetRule(/\.(bmp|gif|jpe?g|png|svg|webp)(\?.*)?$/i, dirs.imgDir, excludeUrl),
|
|
1309
|
+
createAssetRule(/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i, dirs.mediaDir),
|
|
1310
|
+
createAssetRule(/\.(woff2?|eot|ttf|otf)(\?.*)?$/i, dirs.fontDir)
|
|
1311
|
+
);
|
|
1312
|
+
}
|
|
1313
|
+
return rules;
|
|
1314
|
+
}
|
|
1126
1315
|
async function runWebpack(config, customOptions = {}) {
|
|
1127
1316
|
const isProd = config.env.isProd;
|
|
1128
1317
|
let entry = customOptions.entry || config.scripts.entry;
|
|
@@ -1135,6 +1324,45 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1135
1324
|
const jsDir = isCustomOutput ? "" : isProd ? config.paths.target.js : config.paths.tmp.js;
|
|
1136
1325
|
const imgDir = isProd ? config.paths.target.img : config.paths.tmp.img;
|
|
1137
1326
|
const fontDir = isProd ? config.paths.target.font : config.paths.tmp.font;
|
|
1327
|
+
const mediaDir = isProd ? config.paths.target.media : config.paths.tmp.media;
|
|
1328
|
+
const devtool = config.scripts.sourceMap ? config.scripts.sourceMap === true ? isProd ? "source-map" : "eval-cheap-module-source-map" : config.scripts.sourceMap : isProd ? false : "eval-cheap-module-source-map";
|
|
1329
|
+
const libraryConfig = config.scripts.library ? typeof config.scripts.library === "string" && config.scripts.libraryTarget && config.scripts.libraryTarget !== "var" ? { name: config.scripts.library, type: config.scripts.libraryTarget } : config.scripts.library : void 0;
|
|
1330
|
+
const defaultRules = buildDefaultRules(config, { imgDir, fontDir, mediaDir }, devtool);
|
|
1331
|
+
const plugins = [...config.scripts.plugins || []];
|
|
1332
|
+
if (isProd && config.scripts.extractCss) {
|
|
1333
|
+
const MiniCssExtractPlugin = coreRequire("mini-css-extract-plugin");
|
|
1334
|
+
const cssDir = config.paths.target.css;
|
|
1335
|
+
const cssFilename = config.assets.cache ? `${cssDir}/async/[name].[contenthash:8].css` : `${cssDir}/async/[name].css`;
|
|
1336
|
+
plugins.push(
|
|
1337
|
+
new MiniCssExtractPlugin({
|
|
1338
|
+
filename: cssFilename,
|
|
1339
|
+
chunkFilename: cssFilename
|
|
1340
|
+
})
|
|
1341
|
+
);
|
|
1342
|
+
}
|
|
1343
|
+
const vendorName = config.scripts.vendorName || "vendor";
|
|
1344
|
+
const defaultOptimization = {
|
|
1345
|
+
minimize: isProd || config.scripts.minify
|
|
1346
|
+
};
|
|
1347
|
+
if (config.scripts.extractAllVendors) {
|
|
1348
|
+
const vendorFilename = isCustomOutput ? `${vendorName}.js` : isProd && config.assets.cache ? `${jsDir}/${vendorName}.[contenthash:8].js` : `${jsDir}/${vendorName}.js`;
|
|
1349
|
+
defaultOptimization.splitChunks = {
|
|
1350
|
+
cacheGroups: {
|
|
1351
|
+
vendors: {
|
|
1352
|
+
name: vendorName,
|
|
1353
|
+
chunks: "initial",
|
|
1354
|
+
test: /[\\/](node_modules|bower_components)[\\/]/,
|
|
1355
|
+
filename: vendorFilename
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
};
|
|
1359
|
+
}
|
|
1360
|
+
const optimization = deepMerge(
|
|
1361
|
+
{},
|
|
1362
|
+
defaultOptimization,
|
|
1363
|
+
config.scripts.optimization || {}
|
|
1364
|
+
);
|
|
1365
|
+
const externals = config.scripts.externals && (typeof config.scripts.externals !== "string" || config.scripts.externals.length > 0) ? config.scripts.externals : void 0;
|
|
1138
1366
|
const defaultWebpackConfig = {
|
|
1139
1367
|
mode: isProd ? "production" : "development",
|
|
1140
1368
|
context: config.workspace,
|
|
@@ -1144,14 +1372,13 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1144
1372
|
filename: isCustomOutput ? "[name].js" : isProd && config.assets.cache ? `${jsDir}/[name].[contenthash:8].js` : `${jsDir}/[name].js`,
|
|
1145
1373
|
chunkFilename: isCustomOutput ? "chunk/[name].js" : isProd && config.assets.cache ? `${jsDir}/chunk/[name].[chunkhash:8].js` : `${jsDir}/chunk/[name].js`,
|
|
1146
1374
|
publicPath: config.assets.virtualDir ? `/${config.assets.virtualDir}/` : "/",
|
|
1147
|
-
...
|
|
1375
|
+
...libraryConfig ? { library: libraryConfig } : {}
|
|
1148
1376
|
},
|
|
1149
1377
|
target: config.scripts.target || "web",
|
|
1150
|
-
externals:
|
|
1151
|
-
plugins
|
|
1152
|
-
...config.scripts.plugins || []
|
|
1153
|
-
],
|
|
1378
|
+
...externals !== void 0 ? { externals } : {},
|
|
1379
|
+
plugins,
|
|
1154
1380
|
resolve: {
|
|
1381
|
+
modules: ["node_modules", config.src.base],
|
|
1155
1382
|
extensions: [
|
|
1156
1383
|
".wasm",
|
|
1157
1384
|
".mjs",
|
|
@@ -1169,28 +1396,11 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1169
1396
|
}
|
|
1170
1397
|
},
|
|
1171
1398
|
module: {
|
|
1172
|
-
rules: [
|
|
1173
|
-
...config.scripts.loaders || [],
|
|
1174
|
-
{
|
|
1175
|
-
test: /\.(png|jpe?g|gif|svg|webp)$/i,
|
|
1176
|
-
type: "asset/resource",
|
|
1177
|
-
generator: {
|
|
1178
|
-
filename: `${imgDir}/[name].[hash:8][ext]`
|
|
1179
|
-
}
|
|
1180
|
-
},
|
|
1181
|
-
{
|
|
1182
|
-
test: /\.(woff2?|eot|ttf|otf)$/i,
|
|
1183
|
-
type: "asset/resource",
|
|
1184
|
-
generator: {
|
|
1185
|
-
filename: `${fontDir}/[name].[hash:8][ext]`
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
]
|
|
1189
|
-
},
|
|
1190
|
-
optimization: {
|
|
1191
|
-
minimize: isProd || config.scripts.minify
|
|
1399
|
+
rules: [...defaultRules, ...config.scripts.loaders || []]
|
|
1192
1400
|
},
|
|
1193
|
-
|
|
1401
|
+
optimization,
|
|
1402
|
+
...config.scripts.stats !== void 0 ? { stats: config.scripts.stats } : {},
|
|
1403
|
+
devtool
|
|
1194
1404
|
};
|
|
1195
1405
|
const webpackConfig = {
|
|
1196
1406
|
...defaultWebpackConfig,
|
|
@@ -1208,14 +1418,21 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1208
1418
|
compiler.run((err, stats) => {
|
|
1209
1419
|
if (err) {
|
|
1210
1420
|
logger.error("webpack", err.stack || err);
|
|
1211
|
-
|
|
1421
|
+
compiler.close(() => reject(err));
|
|
1422
|
+
return;
|
|
1212
1423
|
}
|
|
1213
1424
|
if (stats?.hasErrors()) {
|
|
1214
1425
|
const info = stats.toJson();
|
|
1215
1426
|
logger.error("webpack", info.errors?.map((e) => e.message).join("\n"));
|
|
1216
|
-
|
|
1427
|
+
compiler.close(() => reject(new Error("Webpack compilation errors")));
|
|
1428
|
+
return;
|
|
1217
1429
|
}
|
|
1218
|
-
|
|
1430
|
+
compiler.close((closeErr) => {
|
|
1431
|
+
if (closeErr) {
|
|
1432
|
+
return reject(closeErr);
|
|
1433
|
+
}
|
|
1434
|
+
resolve(stats);
|
|
1435
|
+
});
|
|
1219
1436
|
});
|
|
1220
1437
|
});
|
|
1221
1438
|
}
|
|
@@ -1309,7 +1526,7 @@ var ScriptTask = class extends BaseTask {
|
|
|
1309
1526
|
|
|
1310
1527
|
// src/tasks/html.ts
|
|
1311
1528
|
var import_node_path12 = __toESM(require("path"), 1);
|
|
1312
|
-
var
|
|
1529
|
+
var import_node_fs4 = require("fs");
|
|
1313
1530
|
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
1314
1531
|
|
|
1315
1532
|
// src/pipeline/transforms/htmlmin.ts
|
|
@@ -1341,10 +1558,18 @@ function transformReplace(options, replacement) {
|
|
|
1341
1558
|
return async (file2) => {
|
|
1342
1559
|
let content = file2.toString();
|
|
1343
1560
|
for (const rule of rules) {
|
|
1344
|
-
if (typeof rule.
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1561
|
+
if (typeof rule.substr === "string") {
|
|
1562
|
+
if (typeof rule.replacement === "function") {
|
|
1563
|
+
content = content.replaceAll(rule.substr, rule.replacement);
|
|
1564
|
+
} else {
|
|
1565
|
+
content = content.replaceAll(rule.substr, rule.replacement);
|
|
1566
|
+
}
|
|
1567
|
+
} else if (rule.substr instanceof RegExp) {
|
|
1568
|
+
if (typeof rule.replacement === "function") {
|
|
1569
|
+
content = content.replace(rule.substr, rule.replacement);
|
|
1570
|
+
} else {
|
|
1571
|
+
content = content.replace(rule.substr, rule.replacement);
|
|
1572
|
+
}
|
|
1348
1573
|
}
|
|
1349
1574
|
}
|
|
1350
1575
|
file2.contents = Buffer.from(content);
|
|
@@ -1400,7 +1625,7 @@ var HtmlTask = class extends BaseTask {
|
|
|
1400
1625
|
const patterns = [import_node_path12.default.join(templateDir, "*.html")];
|
|
1401
1626
|
if (config.pwa.manifest) {
|
|
1402
1627
|
const manifestPattern = import_node_path12.default.join(templateDir, config.pwa.manifest);
|
|
1403
|
-
if ((0,
|
|
1628
|
+
if ((0, import_node_fs4.existsSync)(import_node_path12.default.isAbsolute(manifestPattern) ? manifestPattern : import_node_path12.default.join(config.workspace, manifestPattern))) {
|
|
1404
1629
|
patterns.push(manifestPattern);
|
|
1405
1630
|
}
|
|
1406
1631
|
}
|
|
@@ -1486,7 +1711,9 @@ var HtmlTask = class extends BaseTask {
|
|
|
1486
1711
|
pipeline.pipe(async (file2) => {
|
|
1487
1712
|
if (/\.html$/i.test(file2.extname)) {
|
|
1488
1713
|
let content = file2.toString();
|
|
1489
|
-
const
|
|
1714
|
+
const entryNames = typeof config.scripts.entry === "object" && !Array.isArray(config.scripts.entry) ? Object.keys(config.scripts.entry) : ["main"];
|
|
1715
|
+
const vendorName = config.scripts.vendorName || "vendor";
|
|
1716
|
+
const entries = config.scripts.extractAllVendors ? [vendorName, ...entryNames] : entryNames;
|
|
1490
1717
|
const jsDir = config.env.isProd ? config.paths.target.js : config.paths.tmp.js;
|
|
1491
1718
|
const jsPathPrefix = config.assets.virtualDir ? `/${config.assets.virtualDir}/${jsDir}` : `/${jsDir}`;
|
|
1492
1719
|
const destJsFolder = config.dest.js;
|
|
@@ -1496,18 +1723,24 @@ var HtmlTask = class extends BaseTask {
|
|
|
1496
1723
|
)
|
|
1497
1724
|
).map((entryName) => {
|
|
1498
1725
|
let actualFilename = `${entryName}.js`;
|
|
1726
|
+
const hasUnhashed = (0, import_node_fs4.existsSync)(import_node_path12.default.join(destJsFolder, actualFilename));
|
|
1727
|
+
let found = hasUnhashed;
|
|
1499
1728
|
try {
|
|
1500
1729
|
const matched = import_fast_glob3.default.sync(`${entryName}.*.js`, { cwd: destJsFolder });
|
|
1501
1730
|
if (matched.length) {
|
|
1502
1731
|
const valid = matched.find((f) => !f.endsWith(".map") && !f.endsWith(".txt"));
|
|
1503
1732
|
if (valid) {
|
|
1504
1733
|
actualFilename = valid;
|
|
1734
|
+
found = true;
|
|
1505
1735
|
}
|
|
1506
1736
|
}
|
|
1507
1737
|
} catch {
|
|
1508
1738
|
}
|
|
1739
|
+
if (entryName === vendorName && config.scripts.extractAllVendors && !found) {
|
|
1740
|
+
return "";
|
|
1741
|
+
}
|
|
1509
1742
|
return `<script defer src="${jsPathPrefix}/${actualFilename}"></script>`;
|
|
1510
|
-
}).join("\n");
|
|
1743
|
+
}).filter(Boolean).join("\n");
|
|
1511
1744
|
if (scriptTags) {
|
|
1512
1745
|
if (content.includes("</body>")) {
|
|
1513
1746
|
content = content.replace("</body>", `${scriptTags}
|
|
@@ -1895,8 +2128,8 @@ var PublishTask = class extends BaseTask {
|
|
|
1895
2128
|
// src/tasks/pwa.ts
|
|
1896
2129
|
var import_node_path19 = __toESM(require("path"), 1);
|
|
1897
2130
|
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1898
|
-
var
|
|
1899
|
-
var
|
|
2131
|
+
var import_node_fs5 = require("fs");
|
|
2132
|
+
var import_node_module2 = require("module");
|
|
1900
2133
|
var import_workbox_build = require("workbox-build");
|
|
1901
2134
|
var PwaTask = class extends BaseTask {
|
|
1902
2135
|
options;
|
|
@@ -1908,7 +2141,7 @@ var PwaTask = class extends BaseTask {
|
|
|
1908
2141
|
const globDirectory = config.dest.base;
|
|
1909
2142
|
const swDest = import_node_path19.default.join(globDirectory, config.pwa.swDestFilename);
|
|
1910
2143
|
const swSrc = import_node_path19.default.join(config.src.base, config.pwa.swSrcFilename);
|
|
1911
|
-
const require2 = (0,
|
|
2144
|
+
const require2 = (0, import_node_module2.createRequire)(importMetaUrl);
|
|
1912
2145
|
const candidatePaths = [
|
|
1913
2146
|
import_node_path19.default.join(config.workspace, "node_modules/workbox-sw/build/workbox-sw.js"),
|
|
1914
2147
|
import_node_path19.default.join(config.workspace, "node_modules/workbox-sw/controllers/WorkboxSW.mjs")
|
|
@@ -1924,7 +2157,7 @@ var PwaTask = class extends BaseTask {
|
|
|
1924
2157
|
} catch {
|
|
1925
2158
|
}
|
|
1926
2159
|
for (const p of candidatePaths) {
|
|
1927
|
-
if ((0,
|
|
2160
|
+
if ((0, import_node_fs5.existsSync)(p)) {
|
|
1928
2161
|
const destFile = import_node_path19.default.join(globDirectory, "workbox-sw.js");
|
|
1929
2162
|
await import_promises4.default.copyFile(p, destFile);
|
|
1930
2163
|
break;
|
|
@@ -1948,7 +2181,7 @@ var PwaTask = class extends BaseTask {
|
|
|
1948
2181
|
const { count, size } = await (0, import_workbox_build.injectManifest)(mergedOptions);
|
|
1949
2182
|
logger.info("pwa", `Injected manifest into '${swDest}', precaching ${count} files (${size} bytes)`);
|
|
1950
2183
|
}
|
|
1951
|
-
if ((0,
|
|
2184
|
+
if ((0, import_node_fs5.existsSync)(swDest) && config.pwa.version) {
|
|
1952
2185
|
let swContent = await import_promises4.default.readFile(swDest, "utf-8");
|
|
1953
2186
|
swContent = swContent.replaceAll("{{ version }}", config.pwa.version).replaceAll("{{version}}", config.pwa.version);
|
|
1954
2187
|
await import_promises4.default.writeFile(swDest, swContent, "utf-8");
|
|
@@ -1960,7 +2193,7 @@ var PwaTask = class extends BaseTask {
|
|
|
1960
2193
|
};
|
|
1961
2194
|
|
|
1962
2195
|
// src/tasks/zip.ts
|
|
1963
|
-
var
|
|
2196
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
1964
2197
|
var import_node_path20 = __toESM(require("path"), 1);
|
|
1965
2198
|
var import_archiver = __toESM(require("archiver"), 1);
|
|
1966
2199
|
var import_fast_glob5 = __toESM(require("fast-glob"), 1);
|
|
@@ -1977,7 +2210,7 @@ var ZipTask = class extends BaseTask {
|
|
|
1977
2210
|
const zipPath = import_node_path20.default.join(outputDir, filename);
|
|
1978
2211
|
await file.ensureDir(outputDir);
|
|
1979
2212
|
return new Promise((resolve, reject) => {
|
|
1980
|
-
const outputStream =
|
|
2213
|
+
const outputStream = import_node_fs6.default.createWriteStream(zipPath);
|
|
1981
2214
|
const archive = (0, import_archiver.default)("zip", { zlib: { level: 9 } });
|
|
1982
2215
|
outputStream.on("close", () => {
|
|
1983
2216
|
logger.success("zip", `Created ${zipPath} (${archive.pointer()} total bytes)`);
|
|
@@ -2001,8 +2234,8 @@ var ZipTask = class extends BaseTask {
|
|
|
2001
2234
|
}
|
|
2002
2235
|
} else {
|
|
2003
2236
|
const fullPath = import_node_path20.default.isAbsolute(item) ? item : import_node_path20.default.join(config.workspace, item);
|
|
2004
|
-
if (
|
|
2005
|
-
const stat =
|
|
2237
|
+
if (import_node_fs6.default.existsSync(fullPath)) {
|
|
2238
|
+
const stat = import_node_fs6.default.statSync(fullPath);
|
|
2006
2239
|
if (stat.isDirectory()) {
|
|
2007
2240
|
archive.directory(fullPath, false);
|
|
2008
2241
|
} else {
|
|
@@ -2081,15 +2314,16 @@ var FtpTask = class extends BaseTask {
|
|
|
2081
2314
|
|
|
2082
2315
|
// src/tasks/server.ts
|
|
2083
2316
|
var import_node_http = __toESM(require("http"), 1);
|
|
2084
|
-
var
|
|
2085
|
-
var
|
|
2317
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
2318
|
+
var import_node_path23 = __toESM(require("path"), 1);
|
|
2086
2319
|
var import_connect = __toESM(require("connect"), 1);
|
|
2087
2320
|
var import_serve_static = __toESM(require("serve-static"), 1);
|
|
2088
2321
|
var import_ws = require("ws");
|
|
2089
2322
|
var import_http_proxy_middleware = require("http-proxy-middleware");
|
|
2090
2323
|
|
|
2091
2324
|
// src/watcher/index.ts
|
|
2092
|
-
var
|
|
2325
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
2326
|
+
var import_node_path22 = __toESM(require("path"), 1);
|
|
2093
2327
|
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
2094
2328
|
var FileWatcher = class {
|
|
2095
2329
|
config;
|
|
@@ -2099,7 +2333,8 @@ var FileWatcher = class {
|
|
|
2099
2333
|
styleTask;
|
|
2100
2334
|
scriptTask;
|
|
2101
2335
|
htmlTask;
|
|
2102
|
-
|
|
2336
|
+
watchers = [];
|
|
2337
|
+
isRebuilding = false;
|
|
2103
2338
|
constructor(config, broadcast) {
|
|
2104
2339
|
this.config = config;
|
|
2105
2340
|
this.broadcast = broadcast;
|
|
@@ -2107,29 +2342,56 @@ var FileWatcher = class {
|
|
|
2107
2342
|
this.scriptTask = new ScriptTask();
|
|
2108
2343
|
this.htmlTask = new HtmlTask();
|
|
2109
2344
|
}
|
|
2345
|
+
getWatchDirs() {
|
|
2346
|
+
const candidates = [
|
|
2347
|
+
this.config.src.base,
|
|
2348
|
+
...this.config.scripts.includeJsResource || [],
|
|
2349
|
+
...this.config.styles.atImportPaths || []
|
|
2350
|
+
];
|
|
2351
|
+
const resolved = candidates.filter(Boolean).map((dir) => import_node_path22.default.isAbsolute(dir) ? dir : import_node_path22.default.resolve(this.config.workspace, dir)).filter((dir) => import_node_fs7.default.existsSync(dir) && !dir.includes(`${import_node_path22.default.sep}node_modules`));
|
|
2352
|
+
const unique = Array.from(new Set(resolved)).sort((a, b) => a.length - b.length);
|
|
2353
|
+
return unique.filter(
|
|
2354
|
+
(dir, index) => !unique.slice(0, index).some((parent) => dir.startsWith(`${parent}${import_node_path22.default.sep}`))
|
|
2355
|
+
);
|
|
2356
|
+
}
|
|
2110
2357
|
start() {
|
|
2111
|
-
const
|
|
2112
|
-
if (!
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2358
|
+
const watchDirs = this.getWatchDirs();
|
|
2359
|
+
if (!watchDirs.length) return;
|
|
2360
|
+
for (const watchDir of watchDirs) {
|
|
2361
|
+
logger.info("watch", `Watching for file changes in ${import_picocolors3.default.cyan(watchDir)}`);
|
|
2362
|
+
try {
|
|
2363
|
+
const watcher = import_node_fs7.default.watch(watchDir, { recursive: true }, (_eventType, filename) => {
|
|
2364
|
+
if (!filename) return;
|
|
2365
|
+
const normalized = filename.replace(/\\/g, "/");
|
|
2366
|
+
if (normalized.includes("node_modules/") || normalized.startsWith(".git/")) {
|
|
2367
|
+
return;
|
|
2368
|
+
}
|
|
2369
|
+
this.pendingFiles.add(filename);
|
|
2370
|
+
if (this.debounceTimer) clearTimeout(this.debounceTimer);
|
|
2371
|
+
this.debounceTimer = setTimeout(() => {
|
|
2372
|
+
this.handleChanges();
|
|
2373
|
+
}, 50);
|
|
2374
|
+
});
|
|
2375
|
+
this.watchers.push(watcher);
|
|
2376
|
+
} catch (err) {
|
|
2377
|
+
logger.warn("watch", `Native recursive watch failed for ${watchDir}: ${err.message}`);
|
|
2378
|
+
}
|
|
2125
2379
|
}
|
|
2126
2380
|
}
|
|
2127
2381
|
async handleChanges() {
|
|
2382
|
+
if (this.isRebuilding) {
|
|
2383
|
+
this.debounceTimer = setTimeout(() => this.handleChanges(), 50);
|
|
2384
|
+
return;
|
|
2385
|
+
}
|
|
2128
2386
|
const changed = Array.from(this.pendingFiles);
|
|
2129
2387
|
this.pendingFiles.clear();
|
|
2388
|
+
if (!changed.length) return;
|
|
2130
2389
|
const hasStyle = changed.some((f) => /\.(scss|sass|less|css)$/i.test(f));
|
|
2131
|
-
const hasScript = changed.some(
|
|
2390
|
+
const hasScript = changed.some(
|
|
2391
|
+
(f) => /\.(js|mjs|cjs|ts|jsx|tsx|vue|md|json)$/i.test(f)
|
|
2392
|
+
);
|
|
2132
2393
|
const hasHtml = changed.some((f) => /\.html$/i.test(f));
|
|
2394
|
+
this.isRebuilding = true;
|
|
2133
2395
|
try {
|
|
2134
2396
|
if (hasStyle) {
|
|
2135
2397
|
const start = performance.now();
|
|
@@ -2157,13 +2419,19 @@ var FileWatcher = class {
|
|
|
2157
2419
|
}
|
|
2158
2420
|
} catch (err) {
|
|
2159
2421
|
logger.error("watch", `Incremental rebuild failed: ${err?.message || err}`);
|
|
2422
|
+
} finally {
|
|
2423
|
+
this.isRebuilding = false;
|
|
2160
2424
|
}
|
|
2161
2425
|
}
|
|
2162
2426
|
stop() {
|
|
2163
|
-
if (this.
|
|
2164
|
-
this.
|
|
2165
|
-
this.
|
|
2427
|
+
if (this.debounceTimer) {
|
|
2428
|
+
clearTimeout(this.debounceTimer);
|
|
2429
|
+
this.debounceTimer = null;
|
|
2166
2430
|
}
|
|
2431
|
+
for (const watcher of this.watchers) {
|
|
2432
|
+
watcher.close();
|
|
2433
|
+
}
|
|
2434
|
+
this.watchers = [];
|
|
2167
2435
|
}
|
|
2168
2436
|
};
|
|
2169
2437
|
|
|
@@ -2201,13 +2469,13 @@ var ServerTask = class extends BaseTask {
|
|
|
2201
2469
|
app.use((req, res, next) => {
|
|
2202
2470
|
if (req.url === "/manifest.json" || req.url?.endsWith("/manifest.json")) {
|
|
2203
2471
|
const candidates = [
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2472
|
+
import_node_path23.default.join(config.dest.base, "manifest.json"),
|
|
2473
|
+
import_node_path23.default.join(config.src.base, "manifest.json"),
|
|
2474
|
+
import_node_path23.default.join(config.workspace, "manifest.json")
|
|
2207
2475
|
];
|
|
2208
|
-
const file2 = candidates.find((f) =>
|
|
2476
|
+
const file2 = candidates.find((f) => import_node_fs8.default.existsSync(f));
|
|
2209
2477
|
if (file2) {
|
|
2210
|
-
let content =
|
|
2478
|
+
let content = import_node_fs8.default.readFileSync(file2, "utf-8");
|
|
2211
2479
|
const replacement = config.assets.virtualDir ? `/${config.assets.virtualDir}` : "";
|
|
2212
2480
|
content = content.replaceAll("%PUBLIC_URL%", replacement);
|
|
2213
2481
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
@@ -2228,46 +2496,46 @@ var ServerTask = class extends BaseTask {
|
|
|
2228
2496
|
if (config.paths.tmp.js && config.paths.tmp.js !== config.paths.source.js) {
|
|
2229
2497
|
app.use("/" + config.paths.tmp.js, (0, import_serve_static.default)(config.dest.js));
|
|
2230
2498
|
}
|
|
2231
|
-
app.use("/chunk", (0, import_serve_static.default)(
|
|
2232
|
-
app.use("/chunk", (0, import_serve_static.default)(
|
|
2499
|
+
app.use("/chunk", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.js, "chunk")));
|
|
2500
|
+
app.use("/chunk", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.base, "chunk")));
|
|
2233
2501
|
if (config.paths.source.img) {
|
|
2234
2502
|
app.use(
|
|
2235
2503
|
"/" + config.paths.source.img,
|
|
2236
|
-
(0, import_serve_static.default)(
|
|
2504
|
+
(0, import_serve_static.default)(import_node_path23.default.join(config.src.base, config.paths.source.img))
|
|
2237
2505
|
);
|
|
2238
2506
|
}
|
|
2239
2507
|
if (config.paths.tmp.img) {
|
|
2240
2508
|
app.use("/" + config.paths.tmp.img, (0, import_serve_static.default)(config.dest.img));
|
|
2241
2509
|
}
|
|
2242
|
-
app.use("/img", (0, import_serve_static.default)(
|
|
2243
|
-
app.use("/img", (0, import_serve_static.default)(
|
|
2510
|
+
app.use("/img", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.base, "img")));
|
|
2511
|
+
app.use("/img", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.js, "img")));
|
|
2244
2512
|
if (config.paths.source.font) {
|
|
2245
2513
|
app.use(
|
|
2246
2514
|
"/" + config.paths.source.font,
|
|
2247
|
-
(0, import_serve_static.default)(
|
|
2515
|
+
(0, import_serve_static.default)(import_node_path23.default.join(config.src.base, config.paths.source.font))
|
|
2248
2516
|
);
|
|
2249
2517
|
}
|
|
2250
2518
|
if (config.paths.tmp.font) {
|
|
2251
2519
|
app.use("/" + config.paths.tmp.font, (0, import_serve_static.default)(config.dest.font));
|
|
2252
2520
|
}
|
|
2253
|
-
app.use("/font", (0, import_serve_static.default)(
|
|
2254
|
-
app.use("/font", (0, import_serve_static.default)(
|
|
2255
|
-
app.use("/fonts", (0, import_serve_static.default)(
|
|
2256
|
-
app.use("/fonts", (0, import_serve_static.default)(
|
|
2521
|
+
app.use("/font", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.base, "font")));
|
|
2522
|
+
app.use("/font", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.js, "font")));
|
|
2523
|
+
app.use("/fonts", (0, import_serve_static.default)(import_node_path23.default.join(config.src.base, "fonts")));
|
|
2524
|
+
app.use("/fonts", (0, import_serve_static.default)(import_node_path23.default.join(config.dest.base, "fonts")));
|
|
2257
2525
|
if (config.server.serveStatic) {
|
|
2258
2526
|
const staticEntries = Array.isArray(config.server.serveStatic) ? config.server.serveStatic : [config.server.serveStatic];
|
|
2259
2527
|
for (const entry of staticEntries) {
|
|
2260
2528
|
if (typeof entry === "string") {
|
|
2261
|
-
const absoluteDir =
|
|
2262
|
-
if (
|
|
2529
|
+
const absoluteDir = import_node_path23.default.isAbsolute(entry) ? entry : import_node_path23.default.join(config.workspace, entry);
|
|
2530
|
+
if (import_node_fs8.default.existsSync(absoluteDir)) {
|
|
2263
2531
|
app.use((0, import_serve_static.default)(absoluteDir));
|
|
2264
2532
|
}
|
|
2265
2533
|
} else if (entry && typeof entry === "object") {
|
|
2266
2534
|
const route = entry.route ? entry.route.startsWith("/") ? entry.route : `/${entry.route}` : "";
|
|
2267
2535
|
const dirs = Array.isArray(entry.dir) ? entry.dir : [entry.dir];
|
|
2268
2536
|
for (const dir of dirs) {
|
|
2269
|
-
const absoluteDir =
|
|
2270
|
-
if (
|
|
2537
|
+
const absoluteDir = import_node_path23.default.isAbsolute(dir) ? dir : import_node_path23.default.join(config.workspace, dir);
|
|
2538
|
+
if (import_node_fs8.default.existsSync(absoluteDir)) {
|
|
2271
2539
|
if (route) {
|
|
2272
2540
|
app.use(route, (0, import_serve_static.default)(absoluteDir));
|
|
2273
2541
|
} else {
|
|
@@ -2286,15 +2554,15 @@ var ServerTask = class extends BaseTask {
|
|
|
2286
2554
|
const isGetOrHead = req.method === "GET" || req.method === "HEAD";
|
|
2287
2555
|
const isHtmlNav = !req.url?.includes(".") || req.headers.accept?.includes("text/html");
|
|
2288
2556
|
if (isGetOrHead && isHtmlNav) {
|
|
2289
|
-
const indexPath =
|
|
2290
|
-
const srcIndexPath =
|
|
2291
|
-
const fileToServe =
|
|
2292
|
-
if (
|
|
2557
|
+
const indexPath = import_node_path23.default.join(config.dest.html, "index.html");
|
|
2558
|
+
const srcIndexPath = import_node_path23.default.join(config.src.base, "index.html");
|
|
2559
|
+
const fileToServe = import_node_fs8.default.existsSync(indexPath) ? indexPath : srcIndexPath;
|
|
2560
|
+
if (import_node_fs8.default.existsSync(fileToServe)) {
|
|
2293
2561
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
2294
2562
|
if (req.method === "HEAD") {
|
|
2295
2563
|
return res.end();
|
|
2296
2564
|
}
|
|
2297
|
-
return
|
|
2565
|
+
return import_node_fs8.default.createReadStream(fileToServe).pipe(res);
|
|
2298
2566
|
}
|
|
2299
2567
|
}
|
|
2300
2568
|
next();
|
|
@@ -2337,8 +2605,8 @@ var ServerTask = class extends BaseTask {
|
|
|
2337
2605
|
};
|
|
2338
2606
|
|
|
2339
2607
|
// src/tasks/static.ts
|
|
2340
|
-
var
|
|
2341
|
-
var
|
|
2608
|
+
var import_node_path24 = __toESM(require("path"), 1);
|
|
2609
|
+
var import_node_fs9 = require("fs");
|
|
2342
2610
|
var StaticTask = class extends BaseTask {
|
|
2343
2611
|
constructor() {
|
|
2344
2612
|
super({ name: "static", description: "Copy static assets, images, fonts, and manifest" });
|
|
@@ -2347,9 +2615,25 @@ var StaticTask = class extends BaseTask {
|
|
|
2347
2615
|
const srcBase = config.src.base;
|
|
2348
2616
|
const destBase = config.dest.base;
|
|
2349
2617
|
const staticPatterns = [
|
|
2350
|
-
|
|
2351
|
-
`!${
|
|
2618
|
+
import_node_path24.default.join(srcBase, "*.{ico,png,svg,json,txt,xml,webmanifest}"),
|
|
2619
|
+
`!${import_node_path24.default.join(srcBase, "*.html")}`
|
|
2620
|
+
];
|
|
2621
|
+
const extraIncludes = [
|
|
2622
|
+
...config.extras?.includes || [],
|
|
2623
|
+
...config.assets?.includes || []
|
|
2352
2624
|
];
|
|
2625
|
+
const extraExcludes = [
|
|
2626
|
+
...config.extras?.excludes || [],
|
|
2627
|
+
...config.assets?.excludes || []
|
|
2628
|
+
];
|
|
2629
|
+
for (const inc of extraIncludes) {
|
|
2630
|
+
const pattern = import_node_path24.default.isAbsolute(inc) ? inc : import_node_path24.default.join(srcBase, inc);
|
|
2631
|
+
staticPatterns.push(pattern);
|
|
2632
|
+
}
|
|
2633
|
+
for (const exc of extraExcludes) {
|
|
2634
|
+
const pattern = import_node_path24.default.isAbsolute(exc) ? exc : import_node_path24.default.join(srcBase, exc);
|
|
2635
|
+
staticPatterns.push(`!${pattern}`);
|
|
2636
|
+
}
|
|
2353
2637
|
const pipeline = Pipeline.from(staticPatterns, {
|
|
2354
2638
|
cwd: config.workspace,
|
|
2355
2639
|
base: srcBase
|
|
@@ -2364,30 +2648,30 @@ var StaticTask = class extends BaseTask {
|
|
|
2364
2648
|
return file2;
|
|
2365
2649
|
});
|
|
2366
2650
|
await pipeline.dest(destBase);
|
|
2367
|
-
if (config.src.img && (0,
|
|
2368
|
-
const imgPipeline = Pipeline.from(
|
|
2651
|
+
if (config.src.img && (0, import_node_fs9.existsSync)(config.src.img)) {
|
|
2652
|
+
const imgPipeline = Pipeline.from(import_node_path24.default.join(config.src.img, "**/*"), {
|
|
2369
2653
|
cwd: config.workspace,
|
|
2370
2654
|
base: config.src.img
|
|
2371
2655
|
});
|
|
2372
2656
|
await imgPipeline.dest(config.dest.img);
|
|
2373
2657
|
}
|
|
2374
|
-
if (config.src.font && (0,
|
|
2375
|
-
const fontPipeline = Pipeline.from(
|
|
2658
|
+
if (config.src.font && (0, import_node_fs9.existsSync)(config.src.font)) {
|
|
2659
|
+
const fontPipeline = Pipeline.from(import_node_path24.default.join(config.src.font, "**/*"), {
|
|
2376
2660
|
cwd: config.workspace,
|
|
2377
2661
|
base: config.src.font
|
|
2378
2662
|
});
|
|
2379
2663
|
await fontPipeline.dest(config.dest.font);
|
|
2380
2664
|
}
|
|
2381
|
-
if (config.src.media && (0,
|
|
2382
|
-
const mediaPipeline = Pipeline.from(
|
|
2665
|
+
if (config.src.media && (0, import_node_fs9.existsSync)(config.src.media)) {
|
|
2666
|
+
const mediaPipeline = Pipeline.from(import_node_path24.default.join(config.src.media, "**/*"), {
|
|
2383
2667
|
cwd: config.workspace,
|
|
2384
2668
|
base: config.src.media
|
|
2385
2669
|
});
|
|
2386
2670
|
await mediaPipeline.dest(config.dest.media);
|
|
2387
2671
|
}
|
|
2388
|
-
const publicDir =
|
|
2389
|
-
if ((0,
|
|
2390
|
-
const pubPipeline = Pipeline.from(
|
|
2672
|
+
const publicDir = import_node_path24.default.join(config.workspace, "public");
|
|
2673
|
+
if ((0, import_node_fs9.existsSync)(publicDir)) {
|
|
2674
|
+
const pubPipeline = Pipeline.from(import_node_path24.default.join(publicDir, "**/*"), {
|
|
2391
2675
|
cwd: config.workspace,
|
|
2392
2676
|
base: publicDir
|
|
2393
2677
|
});
|
|
@@ -2586,7 +2870,7 @@ var Balm = class {
|
|
|
2586
2870
|
}
|
|
2587
2871
|
try {
|
|
2588
2872
|
if (this.beforeTask) {
|
|
2589
|
-
await this.beforeTask();
|
|
2873
|
+
await this.beforeTask(this._config);
|
|
2590
2874
|
}
|
|
2591
2875
|
if (this._config.useDefaults) {
|
|
2592
2876
|
await this.dag.runSeries(
|
|
@@ -2611,7 +2895,7 @@ var Balm = class {
|
|
|
2611
2895
|
await this.dag.executeTask("serve", this._config);
|
|
2612
2896
|
}
|
|
2613
2897
|
if (this.afterTask) {
|
|
2614
|
-
await this.afterTask();
|
|
2898
|
+
await this.afterTask(this._config);
|
|
2615
2899
|
}
|
|
2616
2900
|
endTimer();
|
|
2617
2901
|
} catch (err) {
|