Skip to content

Commit

Permalink
Merge pull request #61 from torusresearch:fix/start-script
Browse files Browse the repository at this point in the history
fix start script
  • Loading branch information
chaitanyapotti authored Aug 6, 2024
2 parents 93861c5 + 893b8d8 commit 99e8f37
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
2 changes: 2 additions & 0 deletions packages/config/torus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module.exports = {
esm: true,
cjs: true,
umd: true,
libEsm: true,
libCjs: true,
analyzerMode: "disabled",
browserslistrc: ["supports bigint", "not dead"],
polyfillNodeDeps: {
Expand Down
2 changes: 2 additions & 0 deletions packages/torus-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ interface IOptions {
esm: boolean; // Whether to generate an esm build. Default: true
cjs: boolean; // Whether to generate a cjs build. Default: true
umd: boolean; // Whether to generate an umd build. Default: true
libEsm: boolean; // Whether to generate an lib esm build. Default: true
libCjs: boolean; // Whether to generate a lib cjs build. Default: true
analyzerMode: "disabled" | "static" | "server" | "json"; // Whether to analyze the umd build. Internally uses webpack-bundle-analyzer. Default: "disabled". Refer to full options here: https://github.com/webpack-contrib/webpack-bundle-analyzer
browserslistrc: string | string[]; // The browserlist to target. Default: ["> 0.25%", "not dead", "not ie 11"]. Full list: https://github.com/browserslist/browserslist
// This option allows you to skip polyfilling node deps by default. You can set it to true or a specific path to
Expand Down
6 changes: 5 additions & 1 deletion packages/torus-scripts/config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ const getDefaultConfig = (name) => {
...(baseConfig.plugins || []),
],
};
return [esmCombinedExport, esmOriginalExport, cjsOriginalExport];
const finalTasks = [];
if (torusConfig.esm) finalTasks.push(esmCombinedExport);
if (torusConfig.libEsm) finalTasks.push(esmOriginalExport);
if (torusConfig.libCjs) finalTasks.push(cjsOriginalExport);
return finalTasks;
};

export default (name) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/torus-scripts/config/torus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ defaultConfig.browserslistrc =
defaultConfig.name = generatePackageName(pkg.name);

defaultConfig.umd = process.env.NODE_ENV === "production";
defaultConfig.cjs = process.env.NODE_ENV === "production";
defaultConfig.esm = process.env.NODE_ENV === "production";

const userConfig = await readFile(paths.appTorusConfig);

Expand Down
7 changes: 3 additions & 4 deletions packages/torus-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ async function main() {
await deleteFolder(paths.appBuild);
const tasks = new Listr([], { concurrent: true });
console.log(chalk.yellow("Collating builds..."));
if (torusConfig.esm) {
tasks.add(getRollupTasks());
}
const rollupTasks = getRollupTasks();
if (rollupTasks.length > 0) tasks.add(rollupTasks);
const webpackTasks = getWebpackTasks();
tasks.add(webpackTasks);
if (webpackTasks.length > 0) tasks.add(webpackTasks);
try {
const ctx = await tasks.run();

Expand Down
17 changes: 8 additions & 9 deletions packages/torus-scripts/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,26 @@ function addOutput({ webpackWatcher, rollupWatcher }) {

function getRollupTasks() {
const config = generateRollupConfig(finalArgs.name);
const outputOptions = Array.isArray(config.output) ? config.output : [config.output];
const configOptions = Array.isArray(config) ? config : [config];
config.watch = {
clearScreen: false,
};
return outputOptions.map((outputOption) => {
return configOptions.map((configOption) => {
// use dir option for dynamic imports
const filenameChunks = outputOption.dir ? [outputOption.dir] : outputOption.file.split("/");
const filenameChunks = configOption.output.dir ? configOption.output.dir.split("/") : configOption.output.file.split("/");
const filename = filenameChunks[filenameChunks.length - 1];
return {
title: filename,
task: () => {
return new Observable((observer) => {
const watcher = watch(config);
const watcher = watch(configOption);
watcher.on("event", async (event) => {
const bundle = event.result;
if (event.code === "START") {
observer.next(`Building ${filename}...`);
} else if (bundle && event.code === "BUNDLE_END") {
// If result is present, write it
await bundle.write(outputOption);
await bundle.write(configOption.output);
await bundle.close();
observer.next(`Build complete for ${filename}...`);
} else if (bundle && event.code === "ERROR") {
Expand Down Expand Up @@ -174,11 +174,10 @@ async function main() {
await deleteFolder(paths.appBuild);
const tasks = new Listr([], { concurrent: true });
console.log(chalk.yellow("Collating for dev..."));
if (torusConfig.esm) {
tasks.add(getRollupTasks());
}
const rollupTasks = getRollupTasks();
if (rollupTasks.length > 0) tasks.add(rollupTasks);
const webpackTasks = getWebpackTasks();
tasks.add(webpackTasks);
if (webpackTasks.length > 0) tasks.add(webpackTasks);
try {
await tasks.run();
} catch (error) {
Expand Down

0 comments on commit 99e8f37

Please sign in to comment.