balm-core 6.0.0-alpha.2 → 6.0.0-alpha.4
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 +25 -0
- package/dist/index.cjs +559 -224
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -3
- package/dist/index.d.ts +42 -3
- package/dist/index.js +540 -210
- 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
|
@@ -71,6 +71,7 @@ __export(index_exports, {
|
|
|
71
71
|
isArray: () => isArray,
|
|
72
72
|
isBoolean: () => isBoolean,
|
|
73
73
|
isFunction: () => isFunction,
|
|
74
|
+
isManifestFile: () => isManifestFile,
|
|
74
75
|
isObject: () => isObject,
|
|
75
76
|
isString: () => isString,
|
|
76
77
|
localResolve: () => localResolve,
|
|
@@ -78,11 +79,15 @@ __export(index_exports, {
|
|
|
78
79
|
logger: () => logger,
|
|
79
80
|
resolveConfig: () => resolveConfig,
|
|
80
81
|
resolveDefaultEntry: () => resolveDefaultEntry,
|
|
82
|
+
rewriteCssAssetUrls: () => rewriteCssAssetUrls,
|
|
83
|
+
rewriteHtmlAssetPaths: () => rewriteHtmlAssetPaths,
|
|
81
84
|
runEsbuild: () => runEsbuild,
|
|
82
85
|
runRollup: () => runRollup,
|
|
83
86
|
runWebpack: () => runWebpack,
|
|
84
87
|
setWorkspaces: () => setWorkspaces,
|
|
88
|
+
shouldUseTargetPaths: () => shouldUseTargetPaths,
|
|
85
89
|
toNamespace: () => toNamespace,
|
|
90
|
+
transformCssUrl: () => transformCssUrl,
|
|
86
91
|
transformHtmlmin: () => transformHtmlmin,
|
|
87
92
|
transformLess: () => transformLess,
|
|
88
93
|
transformPostcss: () => transformPostcss,
|
|
@@ -93,7 +98,7 @@ __export(index_exports, {
|
|
|
93
98
|
});
|
|
94
99
|
module.exports = __toCommonJS(index_exports);
|
|
95
100
|
|
|
96
|
-
// ../../node_modules/.pnpm/tsup@8.5.
|
|
101
|
+
// ../../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
102
|
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
103
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
99
104
|
|
|
@@ -182,6 +187,19 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
182
187
|
js: true,
|
|
183
188
|
url: true
|
|
184
189
|
},
|
|
190
|
+
includeJsResource: [],
|
|
191
|
+
excludeUrlResource: [],
|
|
192
|
+
useEsModule: true,
|
|
193
|
+
urlLoaderOptions: {},
|
|
194
|
+
babelLoaderOptions: {},
|
|
195
|
+
htmlLoaderOptions: {},
|
|
196
|
+
postcssLoaderOptions: {},
|
|
197
|
+
sourceMap: false,
|
|
198
|
+
stats: void 0,
|
|
199
|
+
optimization: {},
|
|
200
|
+
extractAllVendors: false,
|
|
201
|
+
vendorName: "vendor",
|
|
202
|
+
extractCss: false,
|
|
185
203
|
options: {},
|
|
186
204
|
esbuildOptions: {},
|
|
187
205
|
rollupOptions: {},
|
|
@@ -220,6 +238,10 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
220
238
|
includes: [],
|
|
221
239
|
excludes: []
|
|
222
240
|
};
|
|
241
|
+
const extras = {
|
|
242
|
+
includes: [],
|
|
243
|
+
excludes: []
|
|
244
|
+
};
|
|
223
245
|
const server = {
|
|
224
246
|
host: null,
|
|
225
247
|
port: 3e3,
|
|
@@ -293,6 +315,7 @@ function createDefaultConfig(workspace = process.cwd()) {
|
|
|
293
315
|
scripts,
|
|
294
316
|
html,
|
|
295
317
|
assets,
|
|
318
|
+
extras,
|
|
296
319
|
server,
|
|
297
320
|
pwa,
|
|
298
321
|
ftp,
|
|
@@ -321,13 +344,18 @@ function isFunction(val) {
|
|
|
321
344
|
function isBoolean(val) {
|
|
322
345
|
return typeof val === "boolean";
|
|
323
346
|
}
|
|
347
|
+
function isPlainObject(val) {
|
|
348
|
+
if (val === null || typeof val !== "object") return false;
|
|
349
|
+
const proto = Object.getPrototypeOf(val);
|
|
350
|
+
return proto === Object.prototype || proto === null;
|
|
351
|
+
}
|
|
324
352
|
function deepMerge(target, ...sources) {
|
|
325
353
|
if (!sources.length) return target;
|
|
326
354
|
const source = sources.shift();
|
|
327
|
-
if (
|
|
355
|
+
if (isPlainObject(target) && isPlainObject(source)) {
|
|
328
356
|
for (const key in source) {
|
|
329
|
-
if (
|
|
330
|
-
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
357
|
+
if (isPlainObject(source[key])) {
|
|
358
|
+
if (!isPlainObject(target[key])) Object.assign(target, { [key]: {} });
|
|
331
359
|
deepMerge(target[key], source[key]);
|
|
332
360
|
} else if (isArray(source[key])) {
|
|
333
361
|
target[key] = [...source[key]];
|
|
@@ -737,7 +765,7 @@ var CleanTask = class extends BaseTask {
|
|
|
737
765
|
};
|
|
738
766
|
|
|
739
767
|
// src/tasks/style.ts
|
|
740
|
-
var
|
|
768
|
+
var import_node_path11 = __toESM(require("path"), 1);
|
|
741
769
|
|
|
742
770
|
// src/pipeline/pipeline.ts
|
|
743
771
|
var import_node_path7 = __toESM(require("path"), 1);
|
|
@@ -821,7 +849,10 @@ var Pipeline = class _Pipeline {
|
|
|
821
849
|
this.transforms.push(async () => {
|
|
822
850
|
const patternArr = Array.isArray(patterns) ? patterns : [patterns];
|
|
823
851
|
const posPatterns = patternArr.filter((p) => !p.startsWith("!"));
|
|
824
|
-
const ignorePatterns =
|
|
852
|
+
const ignorePatterns = [
|
|
853
|
+
"**/.DS_Store",
|
|
854
|
+
...patternArr.filter((p) => p.startsWith("!")).map((p) => p.slice(1))
|
|
855
|
+
];
|
|
825
856
|
const fileList = [];
|
|
826
857
|
for (const p of posPatterns) {
|
|
827
858
|
let patternBase = this.base;
|
|
@@ -1075,6 +1106,96 @@ function transformPostcss(options = {}) {
|
|
|
1075
1106
|
};
|
|
1076
1107
|
}
|
|
1077
1108
|
|
|
1109
|
+
// src/pipeline/transforms/url.ts
|
|
1110
|
+
var import_node_path10 = __toESM(require("path"), 1);
|
|
1111
|
+
var CSS_ASSET_TYPES = ["img", "font", "media"];
|
|
1112
|
+
var HTML_ASSET_TYPES = ["css", "js", "img", "font", "media"];
|
|
1113
|
+
function escapeRegExp(value) {
|
|
1114
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1115
|
+
}
|
|
1116
|
+
function normalizeSegment(value) {
|
|
1117
|
+
return value ? value.replace(/^\/+|\/+$/g, "") : "";
|
|
1118
|
+
}
|
|
1119
|
+
function shouldUseTargetPaths(config) {
|
|
1120
|
+
return Boolean(config.env?.isProd || !config.inFrontend);
|
|
1121
|
+
}
|
|
1122
|
+
function isManifestFile(file2, config) {
|
|
1123
|
+
const manifestFilename = import_node_path10.default.basename(config.pwa?.manifest || "manifest.json");
|
|
1124
|
+
return file2.basename === manifestFilename || file2.extname.toLowerCase() === ".webmanifest";
|
|
1125
|
+
}
|
|
1126
|
+
function rewriteCssAssetUrls(content, config) {
|
|
1127
|
+
if (!shouldUseTargetPaths(config)) {
|
|
1128
|
+
return content;
|
|
1129
|
+
}
|
|
1130
|
+
let updated = content;
|
|
1131
|
+
for (const type of CSS_ASSET_TYPES) {
|
|
1132
|
+
const source = normalizeSegment(config.paths?.source?.[type]);
|
|
1133
|
+
const target = normalizeSegment(config.paths?.target?.[type]);
|
|
1134
|
+
if (!source || !target) continue;
|
|
1135
|
+
const sourceLeaf = source.split("/").pop();
|
|
1136
|
+
const candidates = Array.from(
|
|
1137
|
+
new Set(
|
|
1138
|
+
[source, sourceLeaf].filter(
|
|
1139
|
+
(item) => Boolean(item && item !== target)
|
|
1140
|
+
)
|
|
1141
|
+
)
|
|
1142
|
+
).sort((a, b) => b.length - a.length);
|
|
1143
|
+
if (!candidates.length) continue;
|
|
1144
|
+
const alternation = candidates.map(escapeRegExp).join("|");
|
|
1145
|
+
const relativeRegex = new RegExp(
|
|
1146
|
+
`(^|[\\s('",])((?:\\.{2}\\/)+)(?:${alternation})\\/`,
|
|
1147
|
+
"g"
|
|
1148
|
+
);
|
|
1149
|
+
updated = updated.replace(relativeRegex, `$1$2${target}/`);
|
|
1150
|
+
const rootUrlRegex = new RegExp(
|
|
1151
|
+
`(url\\(\\s*['"]?)\\/(?:${alternation})\\/`,
|
|
1152
|
+
"gi"
|
|
1153
|
+
);
|
|
1154
|
+
updated = updated.replace(rootUrlRegex, `$1/${target}/`);
|
|
1155
|
+
}
|
|
1156
|
+
return updated;
|
|
1157
|
+
}
|
|
1158
|
+
function rewriteHtmlAssetPaths(content, config) {
|
|
1159
|
+
if (!shouldUseTargetPaths(config)) {
|
|
1160
|
+
return content;
|
|
1161
|
+
}
|
|
1162
|
+
const sourceMap = /* @__PURE__ */ new Map();
|
|
1163
|
+
for (const type of HTML_ASSET_TYPES) {
|
|
1164
|
+
const source = normalizeSegment(config.paths?.source?.[type]);
|
|
1165
|
+
const target = normalizeSegment(config.paths?.target?.[type]);
|
|
1166
|
+
if (source && target && source !== target) {
|
|
1167
|
+
sourceMap.set(source, target);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
if (!sourceMap.size) {
|
|
1171
|
+
return content;
|
|
1172
|
+
}
|
|
1173
|
+
const alternation = Array.from(sourceMap.keys()).sort((a, b) => b.length - a.length).map(escapeRegExp).join("|");
|
|
1174
|
+
const virtualDir = normalizeSegment(config.assets?.virtualDir);
|
|
1175
|
+
const virtualPrefix = virtualDir ? `\\/${escapeRegExp(virtualDir)}\\/|` : "";
|
|
1176
|
+
const prefixedRegex = new RegExp(
|
|
1177
|
+
`(^|["'\`=(,\\s])(${virtualPrefix}(?:\\.{1,2}\\/)+|\\/)(${alternation})\\/`,
|
|
1178
|
+
"g"
|
|
1179
|
+
);
|
|
1180
|
+
let updated = content.replace(
|
|
1181
|
+
prefixedRegex,
|
|
1182
|
+
(_, lead, prefix, src) => `${lead}${prefix}${sourceMap.get(src)}/`
|
|
1183
|
+
);
|
|
1184
|
+
const bareQuotedRegex = new RegExp(`(["'\`=])(${alternation})\\/`, "g");
|
|
1185
|
+
updated = updated.replace(
|
|
1186
|
+
bareQuotedRegex,
|
|
1187
|
+
(_, lead, src) => `${lead}${sourceMap.get(src)}/`
|
|
1188
|
+
);
|
|
1189
|
+
return updated;
|
|
1190
|
+
}
|
|
1191
|
+
function transformCssUrl(config) {
|
|
1192
|
+
return async (file2) => {
|
|
1193
|
+
if (!/\.css$/i.test(file2.extname)) return file2;
|
|
1194
|
+
file2.contents = Buffer.from(rewriteCssAssetUrls(file2.toString(), config));
|
|
1195
|
+
return file2;
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1078
1199
|
// src/tasks/style.ts
|
|
1079
1200
|
var StyleTask = class extends BaseTask {
|
|
1080
1201
|
constructor() {
|
|
@@ -1082,9 +1203,9 @@ var StyleTask = class extends BaseTask {
|
|
|
1082
1203
|
}
|
|
1083
1204
|
async run(config) {
|
|
1084
1205
|
const ext = config.styles.extname;
|
|
1085
|
-
const srcPattern =
|
|
1206
|
+
const srcPattern = import_node_path11.default.join(config.src.css, `**/*.${ext}`);
|
|
1086
1207
|
const isProd = config.env.isProd;
|
|
1087
|
-
const pipeline = Pipeline.from([srcPattern, `!${
|
|
1208
|
+
const pipeline = Pipeline.from([srcPattern, `!${import_node_path11.default.join(config.src.css, "**/_*.scss")}`, `!${import_node_path11.default.join(config.src.css, "**/_*.less")}`], {
|
|
1088
1209
|
cwd: config.workspace,
|
|
1089
1210
|
base: config.src.css
|
|
1090
1211
|
});
|
|
@@ -1116,13 +1237,180 @@ var StyleTask = class extends BaseTask {
|
|
|
1116
1237
|
...config.styles.postcssLoaderOptions
|
|
1117
1238
|
})
|
|
1118
1239
|
);
|
|
1240
|
+
pipeline.pipe(transformCssUrl(config));
|
|
1119
1241
|
await pipeline.dest(config.dest.css);
|
|
1120
1242
|
}
|
|
1121
1243
|
};
|
|
1122
1244
|
|
|
1123
1245
|
// src/bundler/webpack.ts
|
|
1124
1246
|
var import_webpack = __toESM(require("webpack"), 1);
|
|
1125
|
-
var
|
|
1247
|
+
var import_node_path12 = __toESM(require("path"), 1);
|
|
1248
|
+
var import_node_fs3 = require("fs");
|
|
1249
|
+
var import_node_module = require("module");
|
|
1250
|
+
var import_autoprefixer2 = __toESM(require("autoprefixer"), 1);
|
|
1251
|
+
var import_postcss_preset_env2 = __toESM(require("postcss-preset-env"), 1);
|
|
1252
|
+
var coreRequire = (0, import_node_module.createRequire)(importMetaUrl);
|
|
1253
|
+
var BABEL_CONFIG_FILES = [
|
|
1254
|
+
"babel.config.js",
|
|
1255
|
+
"babel.config.cjs",
|
|
1256
|
+
"babel.config.mjs",
|
|
1257
|
+
"babel.config.json",
|
|
1258
|
+
".babelrc",
|
|
1259
|
+
".babelrc.js",
|
|
1260
|
+
".babelrc.cjs",
|
|
1261
|
+
".babelrc.json"
|
|
1262
|
+
];
|
|
1263
|
+
function resolveModule(pkgName, workspace) {
|
|
1264
|
+
try {
|
|
1265
|
+
const workspaceRequire = (0, import_node_module.createRequire)(import_node_path12.default.join(workspace, "package.json"));
|
|
1266
|
+
return workspaceRequire.resolve(pkgName);
|
|
1267
|
+
} catch {
|
|
1268
|
+
return coreRequire.resolve(pkgName);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
function resolveWorkspacePaths(paths, workspace) {
|
|
1272
|
+
if (!paths || !paths.length) return [];
|
|
1273
|
+
return paths.map((p) => import_node_path12.default.isAbsolute(p) ? p : import_node_path12.default.resolve(workspace, p));
|
|
1274
|
+
}
|
|
1275
|
+
function hasBabelConfig(config) {
|
|
1276
|
+
if (config.scripts.babelLoaderOptions && Object.keys(config.scripts.babelLoaderOptions).length > 0) {
|
|
1277
|
+
return true;
|
|
1278
|
+
}
|
|
1279
|
+
for (const filename of BABEL_CONFIG_FILES) {
|
|
1280
|
+
if ((0, import_node_fs3.existsSync)(import_node_path12.default.join(config.workspace, filename))) {
|
|
1281
|
+
return true;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
const pkgPath = import_node_path12.default.join(config.workspace, "package.json");
|
|
1285
|
+
if ((0, import_node_fs3.existsSync)(pkgPath)) {
|
|
1286
|
+
try {
|
|
1287
|
+
const pkg = JSON.parse((0, import_node_fs3.readFileSync)(pkgPath, "utf-8"));
|
|
1288
|
+
if (pkg && pkg.babel) {
|
|
1289
|
+
return true;
|
|
1290
|
+
}
|
|
1291
|
+
} catch {
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
return false;
|
|
1295
|
+
}
|
|
1296
|
+
function buildDefaultRules(config, dirs, devtool) {
|
|
1297
|
+
const isProd = config.env.isProd;
|
|
1298
|
+
const scripts = config.scripts;
|
|
1299
|
+
const esModule = scripts.useEsModule ?? true;
|
|
1300
|
+
const defaults = {
|
|
1301
|
+
html: true,
|
|
1302
|
+
css: true,
|
|
1303
|
+
js: true,
|
|
1304
|
+
url: true,
|
|
1305
|
+
...scripts.defaultLoaders || {}
|
|
1306
|
+
};
|
|
1307
|
+
const rules = [];
|
|
1308
|
+
if (defaults.html) {
|
|
1309
|
+
rules.push({
|
|
1310
|
+
test: /\.html$/i,
|
|
1311
|
+
exclude: /\.vue\.html$/i,
|
|
1312
|
+
loader: resolveModule("html-loader", config.workspace),
|
|
1313
|
+
options: {
|
|
1314
|
+
minimize: {
|
|
1315
|
+
removeAttributeQuotes: false
|
|
1316
|
+
},
|
|
1317
|
+
esModule,
|
|
1318
|
+
...scripts.htmlLoaderOptions || {}
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
}
|
|
1322
|
+
if (defaults.css) {
|
|
1323
|
+
const cssSourceMap = Boolean(devtool);
|
|
1324
|
+
const MiniCssExtractPlugin = coreRequire("mini-css-extract-plugin");
|
|
1325
|
+
const styleLoader = isProd && scripts.extractCss ? {
|
|
1326
|
+
loader: MiniCssExtractPlugin.loader,
|
|
1327
|
+
options: { esModule }
|
|
1328
|
+
} : {
|
|
1329
|
+
loader: resolveModule("style-loader", config.workspace),
|
|
1330
|
+
options: { esModule }
|
|
1331
|
+
};
|
|
1332
|
+
const postcssPlugins = [
|
|
1333
|
+
...config.styles.postcssPlugins || [],
|
|
1334
|
+
(0, import_autoprefixer2.default)(),
|
|
1335
|
+
(0, import_postcss_preset_env2.default)()
|
|
1336
|
+
];
|
|
1337
|
+
const createCssUse = (isModule) => [
|
|
1338
|
+
styleLoader,
|
|
1339
|
+
{
|
|
1340
|
+
loader: resolveModule("css-loader", config.workspace),
|
|
1341
|
+
options: {
|
|
1342
|
+
importLoaders: 1,
|
|
1343
|
+
sourceMap: cssSourceMap,
|
|
1344
|
+
modules: isModule ? { auto: true } : { mode: "icss" },
|
|
1345
|
+
esModule
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
{
|
|
1349
|
+
loader: resolveModule("postcss-loader", config.workspace),
|
|
1350
|
+
options: {
|
|
1351
|
+
postcssOptions: {
|
|
1352
|
+
plugins: postcssPlugins
|
|
1353
|
+
},
|
|
1354
|
+
sourceMap: cssSourceMap,
|
|
1355
|
+
...scripts.postcssLoaderOptions || {}
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
];
|
|
1359
|
+
rules.push(
|
|
1360
|
+
{
|
|
1361
|
+
test: /\.css$/,
|
|
1362
|
+
exclude: /\.module\.css$/,
|
|
1363
|
+
use: createCssUse(false),
|
|
1364
|
+
sideEffects: true
|
|
1365
|
+
},
|
|
1366
|
+
{
|
|
1367
|
+
test: /\.module\.css$/,
|
|
1368
|
+
use: createCssUse(true)
|
|
1369
|
+
}
|
|
1370
|
+
);
|
|
1371
|
+
}
|
|
1372
|
+
if (defaults.js && hasBabelConfig(config)) {
|
|
1373
|
+
const jsIncludes = [
|
|
1374
|
+
config.src.js,
|
|
1375
|
+
...resolveWorkspacePaths(scripts.includeJsResource, config.workspace)
|
|
1376
|
+
];
|
|
1377
|
+
rules.push({
|
|
1378
|
+
test: /\.(js|mjs|jsx|ts|tsx)$/,
|
|
1379
|
+
include: jsIncludes,
|
|
1380
|
+
loader: resolveModule("babel-loader", config.workspace),
|
|
1381
|
+
options: {
|
|
1382
|
+
cwd: config.workspace,
|
|
1383
|
+
...scripts.babelLoaderOptions || {}
|
|
1384
|
+
}
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
if (defaults.url) {
|
|
1388
|
+
const rawLimit = scripts.urlLoaderOptions?.limit ?? (process.env.IMAGE_INLINE_SIZE_LIMIT ? parseInt(process.env.IMAGE_INLINE_SIZE_LIMIT, 10) : 1e4);
|
|
1389
|
+
const maxSize = typeof rawLimit === "number" && rawLimit > 0 ? rawLimit : 0;
|
|
1390
|
+
const excludeUrl = resolveWorkspacePaths(scripts.excludeUrlResource, config.workspace);
|
|
1391
|
+
const createAssetRule = (test, targetDir, exclude) => ({
|
|
1392
|
+
test,
|
|
1393
|
+
...exclude && exclude.length ? { exclude } : {},
|
|
1394
|
+
type: maxSize > 0 ? "asset" : "asset/resource",
|
|
1395
|
+
...maxSize > 0 ? {
|
|
1396
|
+
parser: {
|
|
1397
|
+
dataUrlCondition: {
|
|
1398
|
+
maxSize
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
} : {},
|
|
1402
|
+
generator: {
|
|
1403
|
+
filename: `${targetDir}/[name].[hash:8][ext]`
|
|
1404
|
+
}
|
|
1405
|
+
});
|
|
1406
|
+
rules.push(
|
|
1407
|
+
createAssetRule(/\.(bmp|gif|jpe?g|png|svg|webp)(\?.*)?$/i, dirs.imgDir, excludeUrl),
|
|
1408
|
+
createAssetRule(/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i, dirs.mediaDir),
|
|
1409
|
+
createAssetRule(/\.(woff2?|eot|ttf|otf)(\?.*)?$/i, dirs.fontDir)
|
|
1410
|
+
);
|
|
1411
|
+
}
|
|
1412
|
+
return rules;
|
|
1413
|
+
}
|
|
1126
1414
|
async function runWebpack(config, customOptions = {}) {
|
|
1127
1415
|
const isProd = config.env.isProd;
|
|
1128
1416
|
let entry = customOptions.entry || config.scripts.entry;
|
|
@@ -1131,10 +1419,49 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1131
1419
|
}
|
|
1132
1420
|
const rawOutputPath = customOptions.output?.path;
|
|
1133
1421
|
const isCustomOutput = Boolean(rawOutputPath);
|
|
1134
|
-
const outputPath = isCustomOutput ?
|
|
1422
|
+
const outputPath = isCustomOutput ? import_node_path12.default.isAbsolute(rawOutputPath) ? rawOutputPath : import_node_path12.default.resolve(config.workspace, rawOutputPath) : config.dest.base;
|
|
1135
1423
|
const jsDir = isCustomOutput ? "" : isProd ? config.paths.target.js : config.paths.tmp.js;
|
|
1136
1424
|
const imgDir = isProd ? config.paths.target.img : config.paths.tmp.img;
|
|
1137
1425
|
const fontDir = isProd ? config.paths.target.font : config.paths.tmp.font;
|
|
1426
|
+
const mediaDir = isProd ? config.paths.target.media : config.paths.tmp.media;
|
|
1427
|
+
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";
|
|
1428
|
+
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;
|
|
1429
|
+
const defaultRules = buildDefaultRules(config, { imgDir, fontDir, mediaDir }, devtool);
|
|
1430
|
+
const plugins = [...config.scripts.plugins || []];
|
|
1431
|
+
if (isProd && config.scripts.extractCss) {
|
|
1432
|
+
const MiniCssExtractPlugin = coreRequire("mini-css-extract-plugin");
|
|
1433
|
+
const cssDir = config.paths.target.css;
|
|
1434
|
+
const cssFilename = config.assets.cache ? `${cssDir}/async/[name].[contenthash:8].css` : `${cssDir}/async/[name].css`;
|
|
1435
|
+
plugins.push(
|
|
1436
|
+
new MiniCssExtractPlugin({
|
|
1437
|
+
filename: cssFilename,
|
|
1438
|
+
chunkFilename: cssFilename
|
|
1439
|
+
})
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
const vendorName = config.scripts.vendorName || "vendor";
|
|
1443
|
+
const defaultOptimization = {
|
|
1444
|
+
minimize: isProd || config.scripts.minify
|
|
1445
|
+
};
|
|
1446
|
+
if (config.scripts.extractAllVendors) {
|
|
1447
|
+
const vendorFilename = isCustomOutput ? `${vendorName}.js` : isProd && config.assets.cache ? `${jsDir}/${vendorName}.[contenthash:8].js` : `${jsDir}/${vendorName}.js`;
|
|
1448
|
+
defaultOptimization.splitChunks = {
|
|
1449
|
+
cacheGroups: {
|
|
1450
|
+
vendors: {
|
|
1451
|
+
name: vendorName,
|
|
1452
|
+
chunks: "initial",
|
|
1453
|
+
test: /[\\/](node_modules|bower_components)[\\/]/,
|
|
1454
|
+
filename: vendorFilename
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
const optimization = deepMerge(
|
|
1460
|
+
{},
|
|
1461
|
+
defaultOptimization,
|
|
1462
|
+
config.scripts.optimization || {}
|
|
1463
|
+
);
|
|
1464
|
+
const externals = config.scripts.externals && (typeof config.scripts.externals !== "string" || config.scripts.externals.length > 0) ? config.scripts.externals : void 0;
|
|
1138
1465
|
const defaultWebpackConfig = {
|
|
1139
1466
|
mode: isProd ? "production" : "development",
|
|
1140
1467
|
context: config.workspace,
|
|
@@ -1144,14 +1471,13 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1144
1471
|
filename: isCustomOutput ? "[name].js" : isProd && config.assets.cache ? `${jsDir}/[name].[contenthash:8].js` : `${jsDir}/[name].js`,
|
|
1145
1472
|
chunkFilename: isCustomOutput ? "chunk/[name].js" : isProd && config.assets.cache ? `${jsDir}/chunk/[name].[chunkhash:8].js` : `${jsDir}/chunk/[name].js`,
|
|
1146
1473
|
publicPath: config.assets.virtualDir ? `/${config.assets.virtualDir}/` : "/",
|
|
1147
|
-
...
|
|
1474
|
+
...libraryConfig ? { library: libraryConfig } : {}
|
|
1148
1475
|
},
|
|
1149
1476
|
target: config.scripts.target || "web",
|
|
1150
|
-
externals:
|
|
1151
|
-
plugins
|
|
1152
|
-
...config.scripts.plugins || []
|
|
1153
|
-
],
|
|
1477
|
+
...externals !== void 0 ? { externals } : {},
|
|
1478
|
+
plugins,
|
|
1154
1479
|
resolve: {
|
|
1480
|
+
modules: ["node_modules", config.src.base],
|
|
1155
1481
|
extensions: [
|
|
1156
1482
|
".wasm",
|
|
1157
1483
|
".mjs",
|
|
@@ -1169,28 +1495,11 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1169
1495
|
}
|
|
1170
1496
|
},
|
|
1171
1497
|
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
|
|
1498
|
+
rules: [...defaultRules, ...config.scripts.loaders || []]
|
|
1192
1499
|
},
|
|
1193
|
-
|
|
1500
|
+
optimization,
|
|
1501
|
+
...config.scripts.stats !== void 0 ? { stats: config.scripts.stats } : {},
|
|
1502
|
+
devtool
|
|
1194
1503
|
};
|
|
1195
1504
|
const webpackConfig = {
|
|
1196
1505
|
...defaultWebpackConfig,
|
|
@@ -1208,14 +1517,21 @@ async function runWebpack(config, customOptions = {}) {
|
|
|
1208
1517
|
compiler.run((err, stats) => {
|
|
1209
1518
|
if (err) {
|
|
1210
1519
|
logger.error("webpack", err.stack || err);
|
|
1211
|
-
|
|
1520
|
+
compiler.close(() => reject(err));
|
|
1521
|
+
return;
|
|
1212
1522
|
}
|
|
1213
1523
|
if (stats?.hasErrors()) {
|
|
1214
1524
|
const info = stats.toJson();
|
|
1215
1525
|
logger.error("webpack", info.errors?.map((e) => e.message).join("\n"));
|
|
1216
|
-
|
|
1526
|
+
compiler.close(() => reject(new Error("Webpack compilation errors")));
|
|
1527
|
+
return;
|
|
1217
1528
|
}
|
|
1218
|
-
|
|
1529
|
+
compiler.close((closeErr) => {
|
|
1530
|
+
if (closeErr) {
|
|
1531
|
+
return reject(closeErr);
|
|
1532
|
+
}
|
|
1533
|
+
resolve(stats);
|
|
1534
|
+
});
|
|
1219
1535
|
});
|
|
1220
1536
|
});
|
|
1221
1537
|
}
|
|
@@ -1308,8 +1624,8 @@ var ScriptTask = class extends BaseTask {
|
|
|
1308
1624
|
};
|
|
1309
1625
|
|
|
1310
1626
|
// src/tasks/html.ts
|
|
1311
|
-
var
|
|
1312
|
-
var
|
|
1627
|
+
var import_node_path13 = __toESM(require("path"), 1);
|
|
1628
|
+
var import_node_fs4 = require("fs");
|
|
1313
1629
|
var import_fast_glob3 = __toESM(require("fast-glob"), 1);
|
|
1314
1630
|
|
|
1315
1631
|
// src/pipeline/transforms/htmlmin.ts
|
|
@@ -1341,10 +1657,18 @@ function transformReplace(options, replacement) {
|
|
|
1341
1657
|
return async (file2) => {
|
|
1342
1658
|
let content = file2.toString();
|
|
1343
1659
|
for (const rule of rules) {
|
|
1344
|
-
if (typeof rule.
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1660
|
+
if (typeof rule.substr === "string") {
|
|
1661
|
+
if (typeof rule.replacement === "function") {
|
|
1662
|
+
content = content.replaceAll(rule.substr, rule.replacement);
|
|
1663
|
+
} else {
|
|
1664
|
+
content = content.replaceAll(rule.substr, rule.replacement);
|
|
1665
|
+
}
|
|
1666
|
+
} else if (rule.substr instanceof RegExp) {
|
|
1667
|
+
if (typeof rule.replacement === "function") {
|
|
1668
|
+
content = content.replace(rule.substr, rule.replacement);
|
|
1669
|
+
} else {
|
|
1670
|
+
content = content.replace(rule.substr, rule.replacement);
|
|
1671
|
+
}
|
|
1348
1672
|
}
|
|
1349
1673
|
}
|
|
1350
1674
|
file2.contents = Buffer.from(content);
|
|
@@ -1390,17 +1714,17 @@ var HtmlTask = class extends BaseTask {
|
|
|
1390
1714
|
const customTemplate = config.scripts.htmlPluginOptions?.template;
|
|
1391
1715
|
let pipeline;
|
|
1392
1716
|
if (customTemplate) {
|
|
1393
|
-
const templatePath =
|
|
1717
|
+
const templatePath = import_node_path13.default.isAbsolute(customTemplate) ? customTemplate : import_node_path13.default.join(config.workspace, customTemplate);
|
|
1394
1718
|
pipeline = Pipeline.from(templatePath, {
|
|
1395
1719
|
cwd: config.workspace,
|
|
1396
|
-
base:
|
|
1720
|
+
base: import_node_path13.default.dirname(templatePath)
|
|
1397
1721
|
});
|
|
1398
1722
|
} else {
|
|
1399
1723
|
const templateDir = config.scripts.injectHtml ? config.src.base : config.src.html;
|
|
1400
|
-
const patterns = [
|
|
1724
|
+
const patterns = [import_node_path13.default.join(templateDir, "*.html")];
|
|
1401
1725
|
if (config.pwa.manifest) {
|
|
1402
|
-
const manifestPattern =
|
|
1403
|
-
if ((0,
|
|
1726
|
+
const manifestPattern = import_node_path13.default.join(templateDir, config.pwa.manifest);
|
|
1727
|
+
if ((0, import_node_fs4.existsSync)(import_node_path13.default.isAbsolute(manifestPattern) ? manifestPattern : import_node_path13.default.join(config.workspace, manifestPattern))) {
|
|
1404
1728
|
patterns.push(manifestPattern);
|
|
1405
1729
|
}
|
|
1406
1730
|
}
|
|
@@ -1417,67 +1741,10 @@ var HtmlTask = class extends BaseTask {
|
|
|
1417
1741
|
return file2;
|
|
1418
1742
|
});
|
|
1419
1743
|
}
|
|
1420
|
-
if (config
|
|
1744
|
+
if (shouldUseTargetPaths(config)) {
|
|
1421
1745
|
pipeline.pipe(async (file2) => {
|
|
1422
|
-
if (/\.html$/i.test(file2.extname)) {
|
|
1423
|
-
|
|
1424
|
-
if (config.paths.source.css && config.paths.target.css && config.paths.source.css !== config.paths.target.css) {
|
|
1425
|
-
content = content.replaceAll(
|
|
1426
|
-
`/${config.paths.source.css}/`,
|
|
1427
|
-
`/${config.paths.target.css}/`
|
|
1428
|
-
);
|
|
1429
|
-
content = content.replaceAll(
|
|
1430
|
-
`"${config.paths.source.css}/`,
|
|
1431
|
-
`"${config.paths.target.css}/`
|
|
1432
|
-
);
|
|
1433
|
-
content = content.replaceAll(
|
|
1434
|
-
`'${config.paths.source.css}/`,
|
|
1435
|
-
`'${config.paths.target.css}/`
|
|
1436
|
-
);
|
|
1437
|
-
}
|
|
1438
|
-
if (config.paths.source.js && config.paths.target.js && config.paths.source.js !== config.paths.target.js) {
|
|
1439
|
-
content = content.replaceAll(
|
|
1440
|
-
`/${config.paths.source.js}/`,
|
|
1441
|
-
`/${config.paths.target.js}/`
|
|
1442
|
-
);
|
|
1443
|
-
content = content.replaceAll(
|
|
1444
|
-
`"${config.paths.source.js}/`,
|
|
1445
|
-
`"${config.paths.target.js}/`
|
|
1446
|
-
);
|
|
1447
|
-
content = content.replaceAll(
|
|
1448
|
-
`'${config.paths.source.js}/`,
|
|
1449
|
-
`'${config.paths.target.js}/`
|
|
1450
|
-
);
|
|
1451
|
-
}
|
|
1452
|
-
if (config.paths.source.img && config.paths.target.img && config.paths.source.img !== config.paths.target.img) {
|
|
1453
|
-
content = content.replaceAll(
|
|
1454
|
-
`/${config.paths.source.img}/`,
|
|
1455
|
-
`/${config.paths.target.img}/`
|
|
1456
|
-
);
|
|
1457
|
-
content = content.replaceAll(
|
|
1458
|
-
`"${config.paths.source.img}/`,
|
|
1459
|
-
`"${config.paths.target.img}/`
|
|
1460
|
-
);
|
|
1461
|
-
content = content.replaceAll(
|
|
1462
|
-
`'${config.paths.source.img}/`,
|
|
1463
|
-
`'${config.paths.target.img}/`
|
|
1464
|
-
);
|
|
1465
|
-
}
|
|
1466
|
-
if (config.paths.source.font && config.paths.target.font && config.paths.source.font !== config.paths.target.font) {
|
|
1467
|
-
content = content.replaceAll(
|
|
1468
|
-
`/${config.paths.source.font}/`,
|
|
1469
|
-
`/${config.paths.target.font}/`
|
|
1470
|
-
);
|
|
1471
|
-
content = content.replaceAll(
|
|
1472
|
-
`"${config.paths.source.font}/`,
|
|
1473
|
-
`"${config.paths.target.font}/`
|
|
1474
|
-
);
|
|
1475
|
-
content = content.replaceAll(
|
|
1476
|
-
`'${config.paths.source.font}/`,
|
|
1477
|
-
`'${config.paths.target.font}/`
|
|
1478
|
-
);
|
|
1479
|
-
}
|
|
1480
|
-
file2.contents = Buffer.from(content);
|
|
1746
|
+
if (/\.html$/i.test(file2.extname) || isManifestFile(file2, config)) {
|
|
1747
|
+
file2.contents = Buffer.from(rewriteHtmlAssetPaths(file2.toString(), config));
|
|
1481
1748
|
}
|
|
1482
1749
|
return file2;
|
|
1483
1750
|
});
|
|
@@ -1486,7 +1753,9 @@ var HtmlTask = class extends BaseTask {
|
|
|
1486
1753
|
pipeline.pipe(async (file2) => {
|
|
1487
1754
|
if (/\.html$/i.test(file2.extname)) {
|
|
1488
1755
|
let content = file2.toString();
|
|
1489
|
-
const
|
|
1756
|
+
const entryNames = typeof config.scripts.entry === "object" && !Array.isArray(config.scripts.entry) ? Object.keys(config.scripts.entry) : ["main"];
|
|
1757
|
+
const vendorName = config.scripts.vendorName || "vendor";
|
|
1758
|
+
const entries = config.scripts.extractAllVendors ? [vendorName, ...entryNames] : entryNames;
|
|
1490
1759
|
const jsDir = config.env.isProd ? config.paths.target.js : config.paths.tmp.js;
|
|
1491
1760
|
const jsPathPrefix = config.assets.virtualDir ? `/${config.assets.virtualDir}/${jsDir}` : `/${jsDir}`;
|
|
1492
1761
|
const destJsFolder = config.dest.js;
|
|
@@ -1496,18 +1765,24 @@ var HtmlTask = class extends BaseTask {
|
|
|
1496
1765
|
)
|
|
1497
1766
|
).map((entryName) => {
|
|
1498
1767
|
let actualFilename = `${entryName}.js`;
|
|
1768
|
+
const hasUnhashed = (0, import_node_fs4.existsSync)(import_node_path13.default.join(destJsFolder, actualFilename));
|
|
1769
|
+
let found = hasUnhashed;
|
|
1499
1770
|
try {
|
|
1500
1771
|
const matched = import_fast_glob3.default.sync(`${entryName}.*.js`, { cwd: destJsFolder });
|
|
1501
1772
|
if (matched.length) {
|
|
1502
1773
|
const valid = matched.find((f) => !f.endsWith(".map") && !f.endsWith(".txt"));
|
|
1503
1774
|
if (valid) {
|
|
1504
1775
|
actualFilename = valid;
|
|
1776
|
+
found = true;
|
|
1505
1777
|
}
|
|
1506
1778
|
}
|
|
1507
1779
|
} catch {
|
|
1508
1780
|
}
|
|
1781
|
+
if (entryName === vendorName && config.scripts.extractAllVendors && !found) {
|
|
1782
|
+
return "";
|
|
1783
|
+
}
|
|
1509
1784
|
return `<script defer src="${jsPathPrefix}/${actualFilename}"></script>`;
|
|
1510
|
-
}).join("\n");
|
|
1785
|
+
}).filter(Boolean).join("\n");
|
|
1511
1786
|
if (scriptTags) {
|
|
1512
1787
|
if (content.includes("</body>")) {
|
|
1513
1788
|
content = content.replace("</body>", `${scriptTags}
|
|
@@ -1589,36 +1864,36 @@ ${LIVE_RELOAD_SCRIPT}`;
|
|
|
1589
1864
|
};
|
|
1590
1865
|
|
|
1591
1866
|
// src/tasks/copy.ts
|
|
1592
|
-
var
|
|
1867
|
+
var import_node_path15 = __toESM(require("path"), 1);
|
|
1593
1868
|
|
|
1594
1869
|
// src/pipeline/transforms/rename.ts
|
|
1595
|
-
var
|
|
1870
|
+
var import_node_path14 = __toESM(require("path"), 1);
|
|
1596
1871
|
function transformRename(options = {}) {
|
|
1597
1872
|
return async (file2) => {
|
|
1598
1873
|
if (typeof options === "string") {
|
|
1599
|
-
file2.path =
|
|
1874
|
+
file2.path = import_node_path14.default.resolve(import_node_path14.default.dirname(file2.path), options);
|
|
1600
1875
|
return file2;
|
|
1601
1876
|
}
|
|
1602
1877
|
if (typeof options === "function") {
|
|
1603
1878
|
const parsed = {
|
|
1604
|
-
dirname:
|
|
1879
|
+
dirname: import_node_path14.default.dirname(file2.path),
|
|
1605
1880
|
basename: file2.stem,
|
|
1606
1881
|
extname: file2.extname
|
|
1607
1882
|
};
|
|
1608
1883
|
const result = options(parsed);
|
|
1609
1884
|
if (result) {
|
|
1610
|
-
if (result.dirname) file2.path =
|
|
1885
|
+
if (result.dirname) file2.path = import_node_path14.default.join(result.dirname, import_node_path14.default.basename(file2.path));
|
|
1611
1886
|
if (result.basename) file2.stem = result.basename;
|
|
1612
1887
|
if (result.extname) file2.extname = result.extname;
|
|
1613
1888
|
}
|
|
1614
1889
|
return file2;
|
|
1615
1890
|
}
|
|
1616
1891
|
const { dirname, prefix = "", basename, suffix = "", extname } = options;
|
|
1617
|
-
const currentDir = dirname ?
|
|
1892
|
+
const currentDir = dirname ? import_node_path14.default.resolve(file2.cwd, dirname) : import_node_path14.default.dirname(file2.path);
|
|
1618
1893
|
const base = basename !== void 0 ? basename : file2.stem;
|
|
1619
1894
|
const ext = extname !== void 0 ? extname : file2.extname;
|
|
1620
1895
|
const dotExt = ext ? ext.startsWith(".") ? ext : `.${ext}` : "";
|
|
1621
|
-
file2.path =
|
|
1896
|
+
file2.path = import_node_path14.default.join(currentDir, `${prefix}${base}${suffix}${dotExt}`);
|
|
1622
1897
|
return file2;
|
|
1623
1898
|
};
|
|
1624
1899
|
}
|
|
@@ -1637,13 +1912,13 @@ var CopyTask = class extends BaseTask {
|
|
|
1637
1912
|
if (this.options.rename) {
|
|
1638
1913
|
pipeline.pipe(transformRename(this.options.rename));
|
|
1639
1914
|
}
|
|
1640
|
-
const outDir =
|
|
1915
|
+
const outDir = import_node_path15.default.isAbsolute(this.options.output) ? this.options.output : import_node_path15.default.join(config.workspace, this.options.output);
|
|
1641
1916
|
await pipeline.dest(outDir);
|
|
1642
1917
|
}
|
|
1643
1918
|
};
|
|
1644
1919
|
|
|
1645
1920
|
// src/tasks/remove.ts
|
|
1646
|
-
var
|
|
1921
|
+
var import_node_path16 = __toESM(require("path"), 1);
|
|
1647
1922
|
var RemoveTask = class extends BaseTask {
|
|
1648
1923
|
target;
|
|
1649
1924
|
constructor(target) {
|
|
@@ -1653,7 +1928,7 @@ var RemoveTask = class extends BaseTask {
|
|
|
1653
1928
|
async run(config) {
|
|
1654
1929
|
const targets = Array.isArray(this.target) ? this.target : [this.target];
|
|
1655
1930
|
const resolvedTargets = targets.map(
|
|
1656
|
-
(t) =>
|
|
1931
|
+
(t) => import_node_path16.default.isAbsolute(t) ? t : import_node_path16.default.join(config.workspace, t)
|
|
1657
1932
|
);
|
|
1658
1933
|
const deleted = await file.remove(resolvedTargets);
|
|
1659
1934
|
logger.warn("remove", `Removed: ${deleted.join(", ")}`);
|
|
@@ -1661,7 +1936,7 @@ var RemoveTask = class extends BaseTask {
|
|
|
1661
1936
|
};
|
|
1662
1937
|
|
|
1663
1938
|
// src/tasks/replace.ts
|
|
1664
|
-
var
|
|
1939
|
+
var import_node_path17 = __toESM(require("path"), 1);
|
|
1665
1940
|
var ReplaceTask = class extends BaseTask {
|
|
1666
1941
|
taskOptions;
|
|
1667
1942
|
constructor(taskOptions) {
|
|
@@ -1673,7 +1948,7 @@ var ReplaceTask = class extends BaseTask {
|
|
|
1673
1948
|
cwd: config.workspace
|
|
1674
1949
|
});
|
|
1675
1950
|
pipeline.pipe(transformReplace(this.taskOptions.options));
|
|
1676
|
-
const outDir =
|
|
1951
|
+
const outDir = import_node_path17.default.isAbsolute(this.taskOptions.output) ? this.taskOptions.output : import_node_path17.default.join(config.workspace, this.taskOptions.output);
|
|
1677
1952
|
await pipeline.dest(outDir);
|
|
1678
1953
|
}
|
|
1679
1954
|
};
|
|
@@ -1683,12 +1958,12 @@ var import_fast_glob4 = __toESM(require("fast-glob"), 1);
|
|
|
1683
1958
|
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
1684
1959
|
|
|
1685
1960
|
// src/pipeline/transforms/cache.ts
|
|
1686
|
-
var
|
|
1961
|
+
var import_node_path18 = __toESM(require("path"), 1);
|
|
1687
1962
|
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
1688
1963
|
function matchesAny(filePath, rules) {
|
|
1689
1964
|
if (!rules || !rules.length) return false;
|
|
1690
1965
|
const normalized = filePath.replace(/\\/g, "/");
|
|
1691
|
-
const baseName =
|
|
1966
|
+
const baseName = import_node_path18.default.basename(normalized);
|
|
1692
1967
|
for (const rawRule of rules) {
|
|
1693
1968
|
if (typeof rawRule === "string") {
|
|
1694
1969
|
const rule = rawRule.replace(/\\/g, "/");
|
|
@@ -1742,9 +2017,9 @@ var AssetRevisioner = class {
|
|
|
1742
2017
|
const shouldRename = !alreadyHashed && !matchesAny(file2.path, this.options.dontRenameFile) && !matchesAny(file2.relative, this.options.dontRenameFile);
|
|
1743
2018
|
if (shouldRename) {
|
|
1744
2019
|
const fileHash = file.hash(file2.contents, hashLength);
|
|
1745
|
-
const dir =
|
|
2020
|
+
const dir = import_node_path18.default.dirname(file2.path);
|
|
1746
2021
|
const newFilename = `${file2.stem}.${fileHash}${file2.extname}`;
|
|
1747
|
-
file2.path =
|
|
2022
|
+
file2.path = import_node_path18.default.join(dir, newFilename);
|
|
1748
2023
|
}
|
|
1749
2024
|
if (alreadyHashed) {
|
|
1750
2025
|
const unhashedRelative = file2.relative.replace(/\.[a-f0-9]{8}(\.[^.]+)$/i, "$1");
|
|
@@ -1760,8 +2035,8 @@ var AssetRevisioner = class {
|
|
|
1760
2035
|
let content = file2.toString();
|
|
1761
2036
|
for (const [orig, reved] of manifestEntries) {
|
|
1762
2037
|
content = content.replaceAll(orig, reved);
|
|
1763
|
-
const origBase =
|
|
1764
|
-
const revedBase =
|
|
2038
|
+
const origBase = import_node_path18.default.basename(orig);
|
|
2039
|
+
const revedBase = import_node_path18.default.basename(reved);
|
|
1765
2040
|
const escapedBase = origBase.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1766
2041
|
const baseRegex = new RegExp(`${escapedBase}(?![a-zA-Z0-9_])`, "g");
|
|
1767
2042
|
content = content.replace(baseRegex, revedBase);
|
|
@@ -1774,7 +2049,7 @@ var AssetRevisioner = class {
|
|
|
1774
2049
|
const manifestFile = new VirtualFile({
|
|
1775
2050
|
cwd: files[0]?.cwd || process.cwd(),
|
|
1776
2051
|
base: firstBase,
|
|
1777
|
-
path:
|
|
2052
|
+
path: import_node_path18.default.join(firstBase, manifestName),
|
|
1778
2053
|
contents: JSON.stringify(this.manifest, null, 2)
|
|
1779
2054
|
});
|
|
1780
2055
|
outputFiles.push(manifestFile);
|
|
@@ -1850,7 +2125,7 @@ var CacheTask = class extends BaseTask {
|
|
|
1850
2125
|
};
|
|
1851
2126
|
|
|
1852
2127
|
// src/tasks/publish.ts
|
|
1853
|
-
var
|
|
2128
|
+
var import_node_path19 = __toESM(require("path"), 1);
|
|
1854
2129
|
var PublishTask = class extends BaseTask {
|
|
1855
2130
|
options;
|
|
1856
2131
|
constructor(options = {}) {
|
|
@@ -1871,17 +2146,17 @@ var PublishTask = class extends BaseTask {
|
|
|
1871
2146
|
await this.publishItem(config, input, output, renameOptions);
|
|
1872
2147
|
} else {
|
|
1873
2148
|
const srcDir = config.dest.base;
|
|
1874
|
-
const targetDir = config.assets.static ||
|
|
2149
|
+
const targetDir = config.assets.static || import_node_path19.default.join(config.assets.root, config.assets.mainDir);
|
|
1875
2150
|
const pipeline = Pipeline.from(["**/*"], {
|
|
1876
2151
|
cwd: srcDir,
|
|
1877
2152
|
base: srcDir
|
|
1878
2153
|
});
|
|
1879
|
-
await pipeline.dest(
|
|
2154
|
+
await pipeline.dest(import_node_path19.default.resolve(config.workspace, targetDir));
|
|
1880
2155
|
}
|
|
1881
2156
|
}
|
|
1882
2157
|
async publishItem(config, input, output, rename) {
|
|
1883
|
-
const srcPath =
|
|
1884
|
-
const destDir =
|
|
2158
|
+
const srcPath = import_node_path19.default.isAbsolute(input) ? input : import_node_path19.default.join(config.dest.base, input);
|
|
2159
|
+
const destDir = import_node_path19.default.isAbsolute(output) ? output : import_node_path19.default.join(config.workspace, config.assets.root, output);
|
|
1885
2160
|
const pipeline = Pipeline.from(srcPath, {
|
|
1886
2161
|
cwd: config.dest.base
|
|
1887
2162
|
});
|
|
@@ -1893,10 +2168,10 @@ var PublishTask = class extends BaseTask {
|
|
|
1893
2168
|
};
|
|
1894
2169
|
|
|
1895
2170
|
// src/tasks/pwa.ts
|
|
1896
|
-
var
|
|
2171
|
+
var import_node_path20 = __toESM(require("path"), 1);
|
|
1897
2172
|
var import_promises4 = __toESM(require("fs/promises"), 1);
|
|
1898
|
-
var
|
|
1899
|
-
var
|
|
2173
|
+
var import_node_fs5 = require("fs");
|
|
2174
|
+
var import_node_module2 = require("module");
|
|
1900
2175
|
var import_workbox_build = require("workbox-build");
|
|
1901
2176
|
var PwaTask = class extends BaseTask {
|
|
1902
2177
|
options;
|
|
@@ -1906,12 +2181,12 @@ var PwaTask = class extends BaseTask {
|
|
|
1906
2181
|
}
|
|
1907
2182
|
async run(config) {
|
|
1908
2183
|
const globDirectory = config.dest.base;
|
|
1909
|
-
const swDest =
|
|
1910
|
-
const swSrc =
|
|
1911
|
-
const require2 = (0,
|
|
2184
|
+
const swDest = import_node_path20.default.join(globDirectory, config.pwa.swDestFilename);
|
|
2185
|
+
const swSrc = import_node_path20.default.join(config.src.base, config.pwa.swSrcFilename);
|
|
2186
|
+
const require2 = (0, import_node_module2.createRequire)(importMetaUrl);
|
|
1912
2187
|
const candidatePaths = [
|
|
1913
|
-
|
|
1914
|
-
|
|
2188
|
+
import_node_path20.default.join(config.workspace, "node_modules/workbox-sw/build/workbox-sw.js"),
|
|
2189
|
+
import_node_path20.default.join(config.workspace, "node_modules/workbox-sw/controllers/WorkboxSW.mjs")
|
|
1915
2190
|
];
|
|
1916
2191
|
try {
|
|
1917
2192
|
const resolved = require2.resolve("workbox-sw/build/workbox-sw.js");
|
|
@@ -1920,12 +2195,12 @@ var PwaTask = class extends BaseTask {
|
|
|
1920
2195
|
}
|
|
1921
2196
|
try {
|
|
1922
2197
|
const resolvedPkg = require2.resolve("workbox-sw");
|
|
1923
|
-
candidatePaths.push(
|
|
2198
|
+
candidatePaths.push(import_node_path20.default.join(import_node_path20.default.dirname(resolvedPkg), "build/workbox-sw.js"));
|
|
1924
2199
|
} catch {
|
|
1925
2200
|
}
|
|
1926
2201
|
for (const p of candidatePaths) {
|
|
1927
|
-
if ((0,
|
|
1928
|
-
const destFile =
|
|
2202
|
+
if ((0, import_node_fs5.existsSync)(p)) {
|
|
2203
|
+
const destFile = import_node_path20.default.join(globDirectory, "workbox-sw.js");
|
|
1929
2204
|
await import_promises4.default.copyFile(p, destFile);
|
|
1930
2205
|
break;
|
|
1931
2206
|
}
|
|
@@ -1948,7 +2223,7 @@ var PwaTask = class extends BaseTask {
|
|
|
1948
2223
|
const { count, size } = await (0, import_workbox_build.injectManifest)(mergedOptions);
|
|
1949
2224
|
logger.info("pwa", `Injected manifest into '${swDest}', precaching ${count} files (${size} bytes)`);
|
|
1950
2225
|
}
|
|
1951
|
-
if ((0,
|
|
2226
|
+
if ((0, import_node_fs5.existsSync)(swDest) && config.pwa.version) {
|
|
1952
2227
|
let swContent = await import_promises4.default.readFile(swDest, "utf-8");
|
|
1953
2228
|
swContent = swContent.replaceAll("{{ version }}", config.pwa.version).replaceAll("{{version}}", config.pwa.version);
|
|
1954
2229
|
await import_promises4.default.writeFile(swDest, swContent, "utf-8");
|
|
@@ -1960,8 +2235,8 @@ var PwaTask = class extends BaseTask {
|
|
|
1960
2235
|
};
|
|
1961
2236
|
|
|
1962
2237
|
// src/tasks/zip.ts
|
|
1963
|
-
var
|
|
1964
|
-
var
|
|
2238
|
+
var import_node_fs6 = __toESM(require("fs"), 1);
|
|
2239
|
+
var import_node_path21 = __toESM(require("path"), 1);
|
|
1965
2240
|
var import_archiver = __toESM(require("archiver"), 1);
|
|
1966
2241
|
var import_fast_glob5 = __toESM(require("fast-glob"), 1);
|
|
1967
2242
|
var ZipTask = class extends BaseTask {
|
|
@@ -1972,12 +2247,12 @@ var ZipTask = class extends BaseTask {
|
|
|
1972
2247
|
}
|
|
1973
2248
|
async run(config) {
|
|
1974
2249
|
const input = this.options.input || config.dest.base;
|
|
1975
|
-
const outputDir = this.options.output ?
|
|
2250
|
+
const outputDir = this.options.output ? import_node_path21.default.isAbsolute(this.options.output) ? this.options.output : import_node_path21.default.join(config.workspace, this.options.output) : config.workspace;
|
|
1976
2251
|
const filename = this.options.filename || "archive.zip";
|
|
1977
|
-
const zipPath =
|
|
2252
|
+
const zipPath = import_node_path21.default.join(outputDir, filename);
|
|
1978
2253
|
await file.ensureDir(outputDir);
|
|
1979
2254
|
return new Promise((resolve, reject) => {
|
|
1980
|
-
const outputStream =
|
|
2255
|
+
const outputStream = import_node_fs6.default.createWriteStream(zipPath);
|
|
1981
2256
|
const archive = (0, import_archiver.default)("zip", { zlib: { level: 9 } });
|
|
1982
2257
|
outputStream.on("close", () => {
|
|
1983
2258
|
logger.success("zip", `Created ${zipPath} (${archive.pointer()} total bytes)`);
|
|
@@ -1995,18 +2270,18 @@ var ZipTask = class extends BaseTask {
|
|
|
1995
2270
|
const base = item.split("*")[0].replace(/\/+$/, "") || ".";
|
|
1996
2271
|
const matched = import_fast_glob5.default.sync(item, { cwd: config.workspace, onlyFiles: true, dot: true });
|
|
1997
2272
|
for (const relPath of matched) {
|
|
1998
|
-
const fullFilePath =
|
|
1999
|
-
const zipName =
|
|
2273
|
+
const fullFilePath = import_node_path21.default.join(config.workspace, relPath);
|
|
2274
|
+
const zipName = import_node_path21.default.relative(base, relPath);
|
|
2000
2275
|
archive.file(fullFilePath, { name: zipName });
|
|
2001
2276
|
}
|
|
2002
2277
|
} else {
|
|
2003
|
-
const fullPath =
|
|
2004
|
-
if (
|
|
2005
|
-
const stat =
|
|
2278
|
+
const fullPath = import_node_path21.default.isAbsolute(item) ? item : import_node_path21.default.join(config.workspace, item);
|
|
2279
|
+
if (import_node_fs6.default.existsSync(fullPath)) {
|
|
2280
|
+
const stat = import_node_fs6.default.statSync(fullPath);
|
|
2006
2281
|
if (stat.isDirectory()) {
|
|
2007
2282
|
archive.directory(fullPath, false);
|
|
2008
2283
|
} else {
|
|
2009
|
-
archive.file(fullPath, { name:
|
|
2284
|
+
archive.file(fullPath, { name: import_node_path21.default.basename(fullPath) });
|
|
2010
2285
|
}
|
|
2011
2286
|
}
|
|
2012
2287
|
}
|
|
@@ -2017,7 +2292,7 @@ var ZipTask = class extends BaseTask {
|
|
|
2017
2292
|
};
|
|
2018
2293
|
|
|
2019
2294
|
// src/tasks/ftp.ts
|
|
2020
|
-
var
|
|
2295
|
+
var import_node_path22 = __toESM(require("path"), 1);
|
|
2021
2296
|
var import_ssh2 = require("ssh2");
|
|
2022
2297
|
var import_fast_glob6 = __toESM(require("fast-glob"), 1);
|
|
2023
2298
|
var FtpTask = class extends BaseTask {
|
|
@@ -2053,8 +2328,8 @@ var FtpTask = class extends BaseTask {
|
|
|
2053
2328
|
}
|
|
2054
2329
|
let pending = files.length;
|
|
2055
2330
|
for (const file2 of files) {
|
|
2056
|
-
const rel =
|
|
2057
|
-
const remoteFile =
|
|
2331
|
+
const rel = import_node_path22.default.relative(config.workspace, file2);
|
|
2332
|
+
const remoteFile = import_node_path22.default.posix.join(options.remotePath, rel);
|
|
2058
2333
|
sftp.fastPut(file2, remoteFile, (putErr) => {
|
|
2059
2334
|
if (putErr) {
|
|
2060
2335
|
logger.error("ftp", `Failed uploading ${file2}: ${putErr.message}`);
|
|
@@ -2081,15 +2356,16 @@ var FtpTask = class extends BaseTask {
|
|
|
2081
2356
|
|
|
2082
2357
|
// src/tasks/server.ts
|
|
2083
2358
|
var import_node_http = __toESM(require("http"), 1);
|
|
2084
|
-
var
|
|
2085
|
-
var
|
|
2359
|
+
var import_node_fs8 = __toESM(require("fs"), 1);
|
|
2360
|
+
var import_node_path24 = __toESM(require("path"), 1);
|
|
2086
2361
|
var import_connect = __toESM(require("connect"), 1);
|
|
2087
2362
|
var import_serve_static = __toESM(require("serve-static"), 1);
|
|
2088
2363
|
var import_ws = require("ws");
|
|
2089
2364
|
var import_http_proxy_middleware = require("http-proxy-middleware");
|
|
2090
2365
|
|
|
2091
2366
|
// src/watcher/index.ts
|
|
2092
|
-
var
|
|
2367
|
+
var import_node_fs7 = __toESM(require("fs"), 1);
|
|
2368
|
+
var import_node_path23 = __toESM(require("path"), 1);
|
|
2093
2369
|
var import_picocolors3 = __toESM(require("picocolors"), 1);
|
|
2094
2370
|
var FileWatcher = class {
|
|
2095
2371
|
config;
|
|
@@ -2099,7 +2375,8 @@ var FileWatcher = class {
|
|
|
2099
2375
|
styleTask;
|
|
2100
2376
|
scriptTask;
|
|
2101
2377
|
htmlTask;
|
|
2102
|
-
|
|
2378
|
+
watchers = [];
|
|
2379
|
+
isRebuilding = false;
|
|
2103
2380
|
constructor(config, broadcast) {
|
|
2104
2381
|
this.config = config;
|
|
2105
2382
|
this.broadcast = broadcast;
|
|
@@ -2107,29 +2384,56 @@ var FileWatcher = class {
|
|
|
2107
2384
|
this.scriptTask = new ScriptTask();
|
|
2108
2385
|
this.htmlTask = new HtmlTask();
|
|
2109
2386
|
}
|
|
2387
|
+
getWatchDirs() {
|
|
2388
|
+
const candidates = [
|
|
2389
|
+
this.config.src.base,
|
|
2390
|
+
...this.config.scripts.includeJsResource || [],
|
|
2391
|
+
...this.config.styles.atImportPaths || []
|
|
2392
|
+
];
|
|
2393
|
+
const resolved = candidates.filter(Boolean).map((dir) => import_node_path23.default.isAbsolute(dir) ? dir : import_node_path23.default.resolve(this.config.workspace, dir)).filter((dir) => import_node_fs7.default.existsSync(dir) && !dir.includes(`${import_node_path23.default.sep}node_modules`));
|
|
2394
|
+
const unique = Array.from(new Set(resolved)).sort((a, b) => a.length - b.length);
|
|
2395
|
+
return unique.filter(
|
|
2396
|
+
(dir, index) => !unique.slice(0, index).some((parent) => dir.startsWith(`${parent}${import_node_path23.default.sep}`))
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2110
2399
|
start() {
|
|
2111
|
-
const
|
|
2112
|
-
if (!
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2400
|
+
const watchDirs = this.getWatchDirs();
|
|
2401
|
+
if (!watchDirs.length) return;
|
|
2402
|
+
for (const watchDir of watchDirs) {
|
|
2403
|
+
logger.info("watch", `Watching for file changes in ${import_picocolors3.default.cyan(watchDir)}`);
|
|
2404
|
+
try {
|
|
2405
|
+
const watcher = import_node_fs7.default.watch(watchDir, { recursive: true }, (_eventType, filename) => {
|
|
2406
|
+
if (!filename) return;
|
|
2407
|
+
const normalized = filename.replace(/\\/g, "/");
|
|
2408
|
+
if (normalized.includes("node_modules/") || normalized.startsWith(".git/")) {
|
|
2409
|
+
return;
|
|
2410
|
+
}
|
|
2411
|
+
this.pendingFiles.add(filename);
|
|
2412
|
+
if (this.debounceTimer) clearTimeout(this.debounceTimer);
|
|
2413
|
+
this.debounceTimer = setTimeout(() => {
|
|
2414
|
+
this.handleChanges();
|
|
2415
|
+
}, 50);
|
|
2416
|
+
});
|
|
2417
|
+
this.watchers.push(watcher);
|
|
2418
|
+
} catch (err) {
|
|
2419
|
+
logger.warn("watch", `Native recursive watch failed for ${watchDir}: ${err.message}`);
|
|
2420
|
+
}
|
|
2125
2421
|
}
|
|
2126
2422
|
}
|
|
2127
2423
|
async handleChanges() {
|
|
2424
|
+
if (this.isRebuilding) {
|
|
2425
|
+
this.debounceTimer = setTimeout(() => this.handleChanges(), 50);
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2128
2428
|
const changed = Array.from(this.pendingFiles);
|
|
2129
2429
|
this.pendingFiles.clear();
|
|
2430
|
+
if (!changed.length) return;
|
|
2130
2431
|
const hasStyle = changed.some((f) => /\.(scss|sass|less|css)$/i.test(f));
|
|
2131
|
-
const hasScript = changed.some(
|
|
2432
|
+
const hasScript = changed.some(
|
|
2433
|
+
(f) => /\.(js|mjs|cjs|ts|jsx|tsx|vue|md|json)$/i.test(f)
|
|
2434
|
+
);
|
|
2132
2435
|
const hasHtml = changed.some((f) => /\.html$/i.test(f));
|
|
2436
|
+
this.isRebuilding = true;
|
|
2133
2437
|
try {
|
|
2134
2438
|
if (hasStyle) {
|
|
2135
2439
|
const start = performance.now();
|
|
@@ -2157,13 +2461,19 @@ var FileWatcher = class {
|
|
|
2157
2461
|
}
|
|
2158
2462
|
} catch (err) {
|
|
2159
2463
|
logger.error("watch", `Incremental rebuild failed: ${err?.message || err}`);
|
|
2464
|
+
} finally {
|
|
2465
|
+
this.isRebuilding = false;
|
|
2160
2466
|
}
|
|
2161
2467
|
}
|
|
2162
2468
|
stop() {
|
|
2163
|
-
if (this.
|
|
2164
|
-
this.
|
|
2165
|
-
this.
|
|
2469
|
+
if (this.debounceTimer) {
|
|
2470
|
+
clearTimeout(this.debounceTimer);
|
|
2471
|
+
this.debounceTimer = null;
|
|
2472
|
+
}
|
|
2473
|
+
for (const watcher of this.watchers) {
|
|
2474
|
+
watcher.close();
|
|
2166
2475
|
}
|
|
2476
|
+
this.watchers = [];
|
|
2167
2477
|
}
|
|
2168
2478
|
};
|
|
2169
2479
|
|
|
@@ -2201,13 +2511,13 @@ var ServerTask = class extends BaseTask {
|
|
|
2201
2511
|
app.use((req, res, next) => {
|
|
2202
2512
|
if (req.url === "/manifest.json" || req.url?.endsWith("/manifest.json")) {
|
|
2203
2513
|
const candidates = [
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2514
|
+
import_node_path24.default.join(config.dest.base, "manifest.json"),
|
|
2515
|
+
import_node_path24.default.join(config.src.base, "manifest.json"),
|
|
2516
|
+
import_node_path24.default.join(config.workspace, "manifest.json")
|
|
2207
2517
|
];
|
|
2208
|
-
const file2 = candidates.find((f) =>
|
|
2518
|
+
const file2 = candidates.find((f) => import_node_fs8.default.existsSync(f));
|
|
2209
2519
|
if (file2) {
|
|
2210
|
-
let content =
|
|
2520
|
+
let content = import_node_fs8.default.readFileSync(file2, "utf-8");
|
|
2211
2521
|
const replacement = config.assets.virtualDir ? `/${config.assets.virtualDir}` : "";
|
|
2212
2522
|
content = content.replaceAll("%PUBLIC_URL%", replacement);
|
|
2213
2523
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
@@ -2228,46 +2538,46 @@ var ServerTask = class extends BaseTask {
|
|
|
2228
2538
|
if (config.paths.tmp.js && config.paths.tmp.js !== config.paths.source.js) {
|
|
2229
2539
|
app.use("/" + config.paths.tmp.js, (0, import_serve_static.default)(config.dest.js));
|
|
2230
2540
|
}
|
|
2231
|
-
app.use("/chunk", (0, import_serve_static.default)(
|
|
2232
|
-
app.use("/chunk", (0, import_serve_static.default)(
|
|
2541
|
+
app.use("/chunk", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.js, "chunk")));
|
|
2542
|
+
app.use("/chunk", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.base, "chunk")));
|
|
2233
2543
|
if (config.paths.source.img) {
|
|
2234
2544
|
app.use(
|
|
2235
2545
|
"/" + config.paths.source.img,
|
|
2236
|
-
(0, import_serve_static.default)(
|
|
2546
|
+
(0, import_serve_static.default)(import_node_path24.default.join(config.src.base, config.paths.source.img))
|
|
2237
2547
|
);
|
|
2238
2548
|
}
|
|
2239
2549
|
if (config.paths.tmp.img) {
|
|
2240
2550
|
app.use("/" + config.paths.tmp.img, (0, import_serve_static.default)(config.dest.img));
|
|
2241
2551
|
}
|
|
2242
|
-
app.use("/img", (0, import_serve_static.default)(
|
|
2243
|
-
app.use("/img", (0, import_serve_static.default)(
|
|
2552
|
+
app.use("/img", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.base, "img")));
|
|
2553
|
+
app.use("/img", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.js, "img")));
|
|
2244
2554
|
if (config.paths.source.font) {
|
|
2245
2555
|
app.use(
|
|
2246
2556
|
"/" + config.paths.source.font,
|
|
2247
|
-
(0, import_serve_static.default)(
|
|
2557
|
+
(0, import_serve_static.default)(import_node_path24.default.join(config.src.base, config.paths.source.font))
|
|
2248
2558
|
);
|
|
2249
2559
|
}
|
|
2250
2560
|
if (config.paths.tmp.font) {
|
|
2251
2561
|
app.use("/" + config.paths.tmp.font, (0, import_serve_static.default)(config.dest.font));
|
|
2252
2562
|
}
|
|
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)(
|
|
2563
|
+
app.use("/font", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.base, "font")));
|
|
2564
|
+
app.use("/font", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.js, "font")));
|
|
2565
|
+
app.use("/fonts", (0, import_serve_static.default)(import_node_path24.default.join(config.src.base, "fonts")));
|
|
2566
|
+
app.use("/fonts", (0, import_serve_static.default)(import_node_path24.default.join(config.dest.base, "fonts")));
|
|
2257
2567
|
if (config.server.serveStatic) {
|
|
2258
2568
|
const staticEntries = Array.isArray(config.server.serveStatic) ? config.server.serveStatic : [config.server.serveStatic];
|
|
2259
2569
|
for (const entry of staticEntries) {
|
|
2260
2570
|
if (typeof entry === "string") {
|
|
2261
|
-
const absoluteDir =
|
|
2262
|
-
if (
|
|
2571
|
+
const absoluteDir = import_node_path24.default.isAbsolute(entry) ? entry : import_node_path24.default.join(config.workspace, entry);
|
|
2572
|
+
if (import_node_fs8.default.existsSync(absoluteDir)) {
|
|
2263
2573
|
app.use((0, import_serve_static.default)(absoluteDir));
|
|
2264
2574
|
}
|
|
2265
2575
|
} else if (entry && typeof entry === "object") {
|
|
2266
2576
|
const route = entry.route ? entry.route.startsWith("/") ? entry.route : `/${entry.route}` : "";
|
|
2267
2577
|
const dirs = Array.isArray(entry.dir) ? entry.dir : [entry.dir];
|
|
2268
2578
|
for (const dir of dirs) {
|
|
2269
|
-
const absoluteDir =
|
|
2270
|
-
if (
|
|
2579
|
+
const absoluteDir = import_node_path24.default.isAbsolute(dir) ? dir : import_node_path24.default.join(config.workspace, dir);
|
|
2580
|
+
if (import_node_fs8.default.existsSync(absoluteDir)) {
|
|
2271
2581
|
if (route) {
|
|
2272
2582
|
app.use(route, (0, import_serve_static.default)(absoluteDir));
|
|
2273
2583
|
} else {
|
|
@@ -2286,15 +2596,15 @@ var ServerTask = class extends BaseTask {
|
|
|
2286
2596
|
const isGetOrHead = req.method === "GET" || req.method === "HEAD";
|
|
2287
2597
|
const isHtmlNav = !req.url?.includes(".") || req.headers.accept?.includes("text/html");
|
|
2288
2598
|
if (isGetOrHead && isHtmlNav) {
|
|
2289
|
-
const indexPath =
|
|
2290
|
-
const srcIndexPath =
|
|
2291
|
-
const fileToServe =
|
|
2292
|
-
if (
|
|
2599
|
+
const indexPath = import_node_path24.default.join(config.dest.html, "index.html");
|
|
2600
|
+
const srcIndexPath = import_node_path24.default.join(config.src.base, "index.html");
|
|
2601
|
+
const fileToServe = import_node_fs8.default.existsSync(indexPath) ? indexPath : srcIndexPath;
|
|
2602
|
+
if (import_node_fs8.default.existsSync(fileToServe)) {
|
|
2293
2603
|
res.setHeader("Content-Type", "text/html; charset=utf-8");
|
|
2294
2604
|
if (req.method === "HEAD") {
|
|
2295
2605
|
return res.end();
|
|
2296
2606
|
}
|
|
2297
|
-
return
|
|
2607
|
+
return import_node_fs8.default.createReadStream(fileToServe).pipe(res);
|
|
2298
2608
|
}
|
|
2299
2609
|
}
|
|
2300
2610
|
next();
|
|
@@ -2337,8 +2647,8 @@ var ServerTask = class extends BaseTask {
|
|
|
2337
2647
|
};
|
|
2338
2648
|
|
|
2339
2649
|
// src/tasks/static.ts
|
|
2340
|
-
var
|
|
2341
|
-
var
|
|
2650
|
+
var import_node_path25 = __toESM(require("path"), 1);
|
|
2651
|
+
var import_node_fs9 = require("fs");
|
|
2342
2652
|
var StaticTask = class extends BaseTask {
|
|
2343
2653
|
constructor() {
|
|
2344
2654
|
super({ name: "static", description: "Copy static assets, images, fonts, and manifest" });
|
|
@@ -2347,47 +2657,67 @@ var StaticTask = class extends BaseTask {
|
|
|
2347
2657
|
const srcBase = config.src.base;
|
|
2348
2658
|
const destBase = config.dest.base;
|
|
2349
2659
|
const staticPatterns = [
|
|
2350
|
-
|
|
2351
|
-
`!${
|
|
2660
|
+
import_node_path25.default.join(srcBase, "*.{ico,png,svg,json,txt,xml,webmanifest}"),
|
|
2661
|
+
`!${import_node_path25.default.join(srcBase, "*.html")}`
|
|
2662
|
+
];
|
|
2663
|
+
const extraIncludes = [
|
|
2664
|
+
...config.extras?.includes || [],
|
|
2665
|
+
...config.assets?.includes || []
|
|
2352
2666
|
];
|
|
2667
|
+
const extraExcludes = [
|
|
2668
|
+
...config.extras?.excludes || [],
|
|
2669
|
+
...config.assets?.excludes || []
|
|
2670
|
+
];
|
|
2671
|
+
for (const inc of extraIncludes) {
|
|
2672
|
+
const pattern = import_node_path25.default.isAbsolute(inc) ? inc : import_node_path25.default.join(srcBase, inc);
|
|
2673
|
+
staticPatterns.push(pattern);
|
|
2674
|
+
}
|
|
2675
|
+
for (const exc of extraExcludes) {
|
|
2676
|
+
const pattern = import_node_path25.default.isAbsolute(exc) ? exc : import_node_path25.default.join(srcBase, exc);
|
|
2677
|
+
staticPatterns.push(`!${pattern}`);
|
|
2678
|
+
}
|
|
2353
2679
|
const pipeline = Pipeline.from(staticPatterns, {
|
|
2354
2680
|
cwd: config.workspace,
|
|
2355
2681
|
base: srcBase
|
|
2356
2682
|
});
|
|
2357
2683
|
const publicUrlReplacement = config.assets.virtualDir ? `/${config.assets.virtualDir}` : "";
|
|
2358
2684
|
pipeline.pipe(async (file2) => {
|
|
2359
|
-
|
|
2685
|
+
const isManifest = isManifestFile(file2, config);
|
|
2686
|
+
if (isManifest || file2.extname === ".json") {
|
|
2360
2687
|
let content = file2.toString();
|
|
2361
2688
|
content = content.replaceAll(PUBLIC_URL, publicUrlReplacement);
|
|
2689
|
+
if (isManifest) {
|
|
2690
|
+
content = rewriteHtmlAssetPaths(content, config);
|
|
2691
|
+
}
|
|
2362
2692
|
file2.contents = Buffer.from(content);
|
|
2363
2693
|
}
|
|
2364
2694
|
return file2;
|
|
2365
2695
|
});
|
|
2366
2696
|
await pipeline.dest(destBase);
|
|
2367
|
-
if (config.src.img && (0,
|
|
2368
|
-
const imgPipeline = Pipeline.from(
|
|
2697
|
+
if (config.src.img && (0, import_node_fs9.existsSync)(config.src.img)) {
|
|
2698
|
+
const imgPipeline = Pipeline.from(import_node_path25.default.join(config.src.img, "**/*"), {
|
|
2369
2699
|
cwd: config.workspace,
|
|
2370
2700
|
base: config.src.img
|
|
2371
2701
|
});
|
|
2372
2702
|
await imgPipeline.dest(config.dest.img);
|
|
2373
2703
|
}
|
|
2374
|
-
if (config.src.font && (0,
|
|
2375
|
-
const fontPipeline = Pipeline.from(
|
|
2704
|
+
if (config.src.font && (0, import_node_fs9.existsSync)(config.src.font)) {
|
|
2705
|
+
const fontPipeline = Pipeline.from(import_node_path25.default.join(config.src.font, "**/*"), {
|
|
2376
2706
|
cwd: config.workspace,
|
|
2377
2707
|
base: config.src.font
|
|
2378
2708
|
});
|
|
2379
2709
|
await fontPipeline.dest(config.dest.font);
|
|
2380
2710
|
}
|
|
2381
|
-
if (config.src.media && (0,
|
|
2382
|
-
const mediaPipeline = Pipeline.from(
|
|
2711
|
+
if (config.src.media && (0, import_node_fs9.existsSync)(config.src.media)) {
|
|
2712
|
+
const mediaPipeline = Pipeline.from(import_node_path25.default.join(config.src.media, "**/*"), {
|
|
2383
2713
|
cwd: config.workspace,
|
|
2384
2714
|
base: config.src.media
|
|
2385
2715
|
});
|
|
2386
2716
|
await mediaPipeline.dest(config.dest.media);
|
|
2387
2717
|
}
|
|
2388
|
-
const publicDir =
|
|
2389
|
-
if ((0,
|
|
2390
|
-
const pubPipeline = Pipeline.from(
|
|
2718
|
+
const publicDir = import_node_path25.default.join(config.workspace, "public");
|
|
2719
|
+
if ((0, import_node_fs9.existsSync)(publicDir)) {
|
|
2720
|
+
const pubPipeline = Pipeline.from(import_node_path25.default.join(publicDir, "**/*"), {
|
|
2391
2721
|
cwd: config.workspace,
|
|
2392
2722
|
base: publicDir
|
|
2393
2723
|
});
|
|
@@ -2586,7 +2916,7 @@ var Balm = class {
|
|
|
2586
2916
|
}
|
|
2587
2917
|
try {
|
|
2588
2918
|
if (this.beforeTask) {
|
|
2589
|
-
await this.beforeTask();
|
|
2919
|
+
await this.beforeTask(this._config);
|
|
2590
2920
|
}
|
|
2591
2921
|
if (this._config.useDefaults) {
|
|
2592
2922
|
await this.dag.runSeries(
|
|
@@ -2611,7 +2941,7 @@ var Balm = class {
|
|
|
2611
2941
|
await this.dag.executeTask("serve", this._config);
|
|
2612
2942
|
}
|
|
2613
2943
|
if (this.afterTask) {
|
|
2614
|
-
await this.afterTask();
|
|
2944
|
+
await this.afterTask(this._config);
|
|
2615
2945
|
}
|
|
2616
2946
|
endTimer();
|
|
2617
2947
|
} catch (err) {
|
|
@@ -2690,6 +3020,7 @@ var index_default = balm;
|
|
|
2690
3020
|
isArray,
|
|
2691
3021
|
isBoolean,
|
|
2692
3022
|
isFunction,
|
|
3023
|
+
isManifestFile,
|
|
2693
3024
|
isObject,
|
|
2694
3025
|
isString,
|
|
2695
3026
|
localResolve,
|
|
@@ -2697,11 +3028,15 @@ var index_default = balm;
|
|
|
2697
3028
|
logger,
|
|
2698
3029
|
resolveConfig,
|
|
2699
3030
|
resolveDefaultEntry,
|
|
3031
|
+
rewriteCssAssetUrls,
|
|
3032
|
+
rewriteHtmlAssetPaths,
|
|
2700
3033
|
runEsbuild,
|
|
2701
3034
|
runRollup,
|
|
2702
3035
|
runWebpack,
|
|
2703
3036
|
setWorkspaces,
|
|
3037
|
+
shouldUseTargetPaths,
|
|
2704
3038
|
toNamespace,
|
|
3039
|
+
transformCssUrl,
|
|
2705
3040
|
transformHtmlmin,
|
|
2706
3041
|
transformLess,
|
|
2707
3042
|
transformPostcss,
|