Skip to content

Commit

Permalink
Bugfix: Build files were returning async functions that were never ge…
Browse files Browse the repository at this point in the history
…tting executed.
  • Loading branch information
cowwoc committed Dec 1, 2023
1 parent ed67fe0 commit 4283247
Showing 1 changed file with 76 additions and 88 deletions.
164 changes: 76 additions & 88 deletions scripts/build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,30 @@ class Build
}
}
});
return async () =>
try
{
try
{
const results = await eslint.lintFiles(["src/**/*.mts"]);
const formatter = await eslint.loadFormatter("stylish");
const resultText = formatter.format(results);
console.log(resultText);
const results = await eslint.lintFiles(["src/**/*.mts"]);
const formatter = await eslint.loadFormatter("stylish");
const resultText = formatter.format(results);
console.log(resultText);

let buildFailed = false;
for (const result of results)
let buildFailed = false;
for (const result of results)
{
if (result.errorCount > 0)
{
if (result.errorCount > 0)
{
buildFailed = true;
break;
}
buildFailed = true;
break;
}
if (buildFailed)
process.exit(1);
}
catch (error)
{
log.error(error);
if (buildFailed)
process.exit(1);
}
};
}
catch (error)
{
log.error(error);
process.exit(1);
}
}

public async compileForNode()
Expand Down Expand Up @@ -145,32 +142,29 @@ class Build
(rollupCommonjs as unknown as Function)({include: "node_modules/**"})
];

return async () =>
{
const bundle = await rollup(
{
input: "src/index.mts",
plugins,
onwarn(warning, warn)
{
// Ignore false alarm about circular dependencies involving internal.mts
const ignoredCircular = ["src/internal/internal.mts"];
const isCircularDependency = warning.code === "CIRCULAR_DEPENDENCY" &&
ignoredCircular.some(predicate =>
warning.message.replace(/\\/g, "/").includes(predicate));
if (isCircularDependency)
return;
warn(warning);
}
});
await bundle.write(
const bundle = await rollup(
{
input: "src/index.mts",
plugins,
onwarn(warning, warn)
{
sourcemap: true,
dir: "target/publish/browser"
});
if (this.mode === "RELEASE")
await this.minifyBrowserSources();
};
// Ignore false alarm about circular dependencies involving internal.mts
const ignoredCircular = ["src/internal/internal.mts"];
const isCircularDependency = warning.code === "CIRCULAR_DEPENDENCY" &&
ignoredCircular.some(predicate =>
warning.message.replace(/\\/g, "/").includes(predicate));
if (isCircularDependency)
return;
warn(warning);
}
});
await bundle.write(
{
sourcemap: true,
dir: "target/publish/browser"
});
if (this.mode === "RELEASE")
await this.minifyBrowserSources();
}

/**
Expand All @@ -188,58 +182,52 @@ class Build
const pathToCode: { [name: string]: string } = {};
for (const file of sourceFiles)
pathToCode[file] = fs.readFileSync(file, "utf8");
return async () =>
{
const {
code,
map
} = await minify(pathToCode, {
ecma: 2020,
compress:
{
/* eslint-disable camelcase */
drop_console: true,
global_defs:
{
"@alert": "console.log"
}
/* eslint-enable camelcase */
},
sourceMap: {
filename: "index.min.mjs.map"
}
const {
code,
map
} = await minify(pathToCode, {
ecma: 2020,
compress:
{
/* eslint-disable camelcase */
drop_console: true,
global_defs:
{
"@alert": "console.log"
}
/* eslint-enable camelcase */
},
sourceMap: {
filename: "index.min.mjs.map"
}
);
assert(typeof (code) === "string");
assert(typeof (map) === "string");
}
);
assert(typeof (code) === "string");
assert(typeof (map) === "string");

fs.writeFileSync(targetDirectory + "index.min.mjs", code);
fs.writeFileSync(targetDirectory + "index.min.mjs.map", map);
};
fs.writeFileSync(targetDirectory + "index.min.mjs", code);
fs.writeFileSync(targetDirectory + "index.min.mjs.map", map);
}

public async generateDocumentation()
{
log.info("generateDocumentation()");
const targetDirectory = "target/apidocs/";

return async () =>
{
const app = await TypeDoc.Application.bootstrapWithPlugins({}, [
new TypeDoc.TypeDocReader(),
new TypeDoc.TSConfigReader()
]);
const app = await TypeDoc.Application.bootstrapWithPlugins({}, [
new TypeDoc.TypeDocReader(),
new TypeDoc.TSConfigReader()
]);

const project = await app.convert();
if (!project)
process.exit(1);
app.validate(project);
if (app.logger.hasErrors())
process.exit(1);
await app.generateDocs(project, targetDirectory);
if (app.logger.hasErrors())
process.exit(1);
};
const project = await app.convert();
if (!project)
process.exit(1);
app.validate(project);
if (app.logger.hasErrors())
process.exit(1);
await app.generateDocs(project, targetDirectory);
if (app.logger.hasErrors())
process.exit(1);
}

public async copyResources()
Expand Down

0 comments on commit 4283247

Please sign in to comment.