diff --git a/build/build.ts b/build/build.ts
index 57e1009..87eee76 100644
--- a/build/build.ts
+++ b/build/build.ts
@@ -1,5 +1,5 @@
import esbuild from "esbuild";
-import { readFile, rm, rmdir, writeFile, cp } from "@cross/fs";
+import { cp, readFile, rm, rmdir, writeFile } from "@cross/fs";
import { expandGlob } from "@std/fs";
import { dtsPlugin } from "esbuild-plugin-d.ts";
@@ -100,11 +100,15 @@ if (Deno.args[1] === "clean") {
outdir: resolvedDistPath,
platform: "node",
format: "cjs",
- outExtension: { ".js": ".cjs" }
+ outExtension: { ".js": ".cjs" },
},
{
- outdir: resolvedDistPath,
- outExtension: { ".js": ".umd.js" },
+ entryPoints: [],
+ stdin: {
+ contents: 'import { Cron } from "./croner.ts";module.exports = Cron;',
+ resolveDir: "./src/",
+ },
+ outfile: resolve(resolvedDistPath, "croner.umd.js"),
platform: "browser",
format: "iife",
globalName: "Cron",
@@ -120,7 +124,7 @@ if (Deno.args[1] === "clean") {
declaration: true,
emitDeclarationOnly: true,
allowImportingTsExtensions: true,
- lib: ["es6", "dom"]
+ lib: ["es6", "dom"],
},
},
})],
diff --git a/deno.json b/deno.json
index 4e35b17..17d085e 100644
--- a/deno.json
+++ b/deno.json
@@ -1,6 +1,6 @@
{
"name": "@hexagon/croner",
- "version": "9.0.0-dev.10",
+ "version": "9.0.0-dev.11",
"exports": "./src/croner.ts",
"lint": {
"include": ["src", "build"]
diff --git a/docs/src/installation.md b/docs/src/installation.md
index 3345472..ddfeeae 100644
--- a/docs/src/installation.md
+++ b/docs/src/installation.md
@@ -44,4 +44,4 @@ Make sure to replace `$CRONER_VERSION` with the latest version.
To use Croner in a webpage, you can load it as a UMD module from a CDN:
-``
+``
diff --git a/docs/src/migration.md b/docs/src/migration.md
index 7dc8528..7ded07f 100644
--- a/docs/src/migration.md
+++ b/docs/src/migration.md
@@ -38,6 +38,24 @@ Version `7.x` introduces significant changes, including the introduction of the
Version `8.x` introduces no significant changes in the API for Croner. However, a major change is the discontinuation of support for Node.js versions prior to `18.0`. It is crucial to ensure that your environment is running Node.js `18.0` or higher before upgrading to `8.x`. If you rely on Node <= `16` you should stick with `7.x`.
+### Upgrading from 8.x to 9.x
+
+Version 9.x brings several changes to Croner to fix existing issues and ensure consistency in code:
+
+### Changes to the API
+
+* `new` is no longer optional. Previously, it was possible to instantiate Croner using `Cron(/*...*/)` now, you need to use `new Cron(/* ... */)`.
+
+* The default export is removed. Previously, you could `import Cron from`, now you need to `import { Cron } from`. The same goes for require.
+
+### Changes to the file structure
+
+* Files in the `/dist` directory are always minified, no need to be explicit with that through the file names. As a result, `croner.min.js` is now `croner.js`.
+
+* Typings are moved from `/types` to `/dist`.
+
+* Only the `/src` directory is exposed in the JSR module.
+
## Switching from Cron
If you're currently using the cron package and want to migrate to Croner, the following steps can guide you:
diff --git a/docs/src/usage/basics.md b/docs/src/usage/basics.md
index 9db1f27..912e184 100644
--- a/docs/src/usage/basics.md
+++ b/docs/src/usage/basics.md
@@ -8,10 +8,10 @@ nav_order: 1
---
-Croner uses the function `Cron()` which takes in three arguments:
+Croner uses the function `new Cron()` which takes in three arguments:
```ts
-const job = Cron(
+const job = new Cron(
/* The pattern */
"* * * * * *",
/* Options (optional) */
diff --git a/docs/src/usage/examples.md b/docs/src/usage/examples.md
index 87538f9..452e2b4 100644
--- a/docs/src/usage/examples.md
+++ b/docs/src/usage/examples.md
@@ -16,11 +16,11 @@ nav_order: 3
```ts
// Find next month
-const nextMonth = Cron("@monthly").nextRun(),
- nextSunday = Cron("@weekly").nextRun(),
- nextSat29feb = Cron("0 0 0 29 2 6", { legacyMode: false }).nextRun(),
- nextSunLastOfMonth = Cron("0 0 0 L * 7", { legacyMode: false }).nextRun(),
- nextLastSundayOfMonth = Cron("0 0 0 * * L7").nextRun();
+const nextMonth = new Cron("@monthly").nextRun(),
+ nextSunday = new Cron("@weekly").nextRun(),
+ nextSat29feb = new Cron("0 0 0 29 2 6", { legacyMode: false }).nextRun(),
+ nextSunLastOfMonth = new Cron("0 0 0 L * 7", { legacyMode: false }).nextRun(),
+ nextLastSundayOfMonth = new Cron("0 0 0 * * L7").nextRun();
console.log("First day of next month: " + nextMonth.toLocaleDateString());
console.log("Next sunday: " + nextSunday.toLocaleDateString());
@@ -31,23 +31,23 @@ console.log("Next last sunday of month: " + nextLastSundayOfMonth.toLocaleDateS
### Job controls
```ts
-const job = Cron('* * * * * *', (self) => {
+const job = new Cron('* * * * * *', (self) => {
console.log('This will run every second. Pause on second 10. Resume on 15. And quit on 20.');
console.log('Current second: ', new Date().getSeconds());
console.log('Previous run: ' + self.previousRun());
console.log('Next run: ' + self.nextRun());
});
-Cron('10 * * * * *', {maxRuns: 1}, () => job.pause());
-Cron('15 * * * * *', {maxRuns: 1}, () => job.resume());
-Cron('20 * * * * *', {maxRuns: 1}, () => job.stop());
+new Cron('10 * * * * *', {maxRuns: 1}, () => job.pause());
+new Cron('15 * * * * *', {maxRuns: 1}, () => job.resume());
+new Cron('20 * * * * *', {maxRuns: 1}, () => job.stop());
```
### Options
```ts
import { Cron } from "./dist/croner.js";
-const job = Cron(
+const job = new Cron(
'* * * * *',
{
startAt: "2023-11-01T00:00:00",
@@ -76,11 +76,11 @@ const data = {
what: "stuff"
};
-Cron('* * * * * *', { context: data }, (_self, context) => {
+new Cron('* * * * * *', { context: data }, (_self, context) => {
console.log('This will print stuff: ' + context.what);
});
-Cron('*/5 * * * * *', { context: data }, (self, context) => {
+new Cron('*/5 * * * * *', { context: data }, (self, context) => {
console.log('After this, other stuff will be printed instead');
context.what = "other stuff";
self.stop();
@@ -91,7 +91,7 @@ Cron('*/5 * * * * *', { context: data }, (self, context) => {
```ts
// A javascript date, or a ISO 8601 local time string can be passed, to fire a function once.
// Always specify which timezone the ISO 8601 time string has with the timezone option.
-let job = Cron("2025-01-01T23:00:00",{timezone: "Europe/Stockholm"},() => {
+let job = new Cron("2025-01-01T23:00:00",{timezone: "Europe/Stockholm"},() => {
console.log('This will run at 2025-01-01 23:00:00 in timezone Europe/Stockholm');
});
@@ -104,7 +104,7 @@ if (job.nextRun() === null) {
### Time zone
```ts
-let job = Cron("0 0 14 * * *", { timezone: "Europe/Stockholm" }, () => {
+let job = new Cron("0 0 14 * * *", { timezone: "Europe/Stockholm" }, () => {
console.log('This will every day at 14:00 in time zone Europe/Stockholm');
});
@@ -131,7 +131,7 @@ If a job is stopped using `.stop()`, it will be removed from the scheduledJobs a
(() => {
// As we specify a name for the job, a reference will be kept in `scheduledJobs`
- const job = Cron("* * * * * *", { name: "Job1" }, function () {
+ const job = new Cron("* * * * * *", { name: "Job1" }, function () {
console.log("This will run every second");
});
diff --git a/docs/src/usage/index.md b/docs/src/usage/index.md
index b547058..86737f1 100644
--- a/docs/src/usage/index.md
+++ b/docs/src/usage/index.md
@@ -11,7 +11,7 @@ nav_order: 3
The most basic usage of Croner for scheduling is:
```ts
-Cron("0 12 * * *, () => {
+new Cron("0 12 * * *, () => {
console.log("This will run every day at 12:00");
});
```
@@ -19,6 +19,6 @@ Cron("0 12 * * *, () => {
And the most basic usage of Croner for getting next execution time of a pattern is:
```ts
-console.log(Cron("0 12 * * *).next());
+console.log(new Cron("0 12 * * *).next());
// 2023-07-08T12:00:00
```
\ No newline at end of file