@plugjs/plug
Version:
PlugJS Build System ===================
56 lines • 2.15 kB
JavaScript
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
if (typeof path === "string" && /^\.\.?\//.test(path)) {
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
});
}
return path;
};
import { invokeTasks, isBuild } from "../build.js";
import { ForkingPlug } from "../fork.js";
import { $p } from "../logging/colors.js";
import { requireFilename } from "../paths.js";
/** Helper {@link Plug} used by the `invokeBuild` helper. */
export class RunBuildInternal {
_tasks;
_props;
_options;
constructor(_tasks, _props, _options) {
this._tasks = _tasks;
this._props = _props;
this._options = _options;
}
async pipe(files, context) {
const tasks = this._tasks.length === 0 ? ['default'] : this._tasks;
const cwd = this._options.cwd || process.cwd();
for (const file of files.absolutePaths()) {
// Import and check build file
let maybeBuild = await import(__rewriteRelativeImportExtension(file));
while (maybeBuild) {
if (isBuild(maybeBuild))
break;
maybeBuild = maybeBuild.default;
}
// We _need_ a build
if (!isBuild(maybeBuild)) {
context.log.fail(`File ${$p(file)} did not export a proper build`);
}
else {
const dir = process.cwd();
try {
process.chdir(cwd);
await invokeTasks(maybeBuild, tasks, this._props);
}
finally {
process.chdir(dir);
}
}
}
}
}
export class RunBuild extends ForkingPlug {
constructor(tasks, props, options) {
super(requireFilename(import.meta.filename), [tasks, props, options], RunBuildInternal.name);
}
}
//# sourceMappingURL=build.js.map