@lumeland/core 1.0.0-beta-2 → 1.0.0-beta-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 ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/).
7
+
8
+ ## 1.0.0 - Unreleased
9
+
10
+ First version
@@ -1 +1,2 @@
1
1
  import "temporal-polyfill/global";
2
+ export declare function toBase64(input: ArrayBuffer | Uint8Array): string;
@@ -1 +1,5 @@
1
1
  import "temporal-polyfill/global";
2
+ // Uint8Array.prototype.toBase64() not available in Node 24
3
+ export function toBase64(input) {
4
+ return Buffer.from(input).toString("base64");
5
+ }
@@ -4,6 +4,8 @@ export interface NetworkInterfaceInfo {
4
4
  }
5
5
  /** Returns an array with the network interfaces information */
6
6
  export declare function networkInterfaces(): NetworkInterfaceInfo[];
7
+ /** Check if a port is free */
8
+ export declare function checkPort(port: number): Promise<boolean>;
7
9
  export interface NetAddress {
8
10
  transport: "tcp" | "udp";
9
11
  hostname: string;
@@ -15,6 +15,24 @@ export function networkInterfaces() {
15
15
  }
16
16
  return result;
17
17
  }
18
+ /** Check if a port is free */
19
+ export function checkPort(port) {
20
+ return new Promise((resolve, reject) => {
21
+ const server = createServer(() => { });
22
+ server.once("error", (error) => {
23
+ if (error.code === "EADDRINUSE") {
24
+ resolve(false);
25
+ }
26
+ else {
27
+ reject(error);
28
+ }
29
+ });
30
+ server.once("listening", () => {
31
+ server.close(() => resolve(true));
32
+ });
33
+ server.listen(port, "0.0.0.0");
34
+ });
35
+ }
18
36
  /** Start a new HTTP server */
19
37
  export function serve(options) {
20
38
  const { handler, hostname = "0.0.0.0", port = 8000, signal, onListen, onUpgradeWebSocket, } = options;
@@ -17,3 +17,5 @@ export declare function inspect(value: unknown): string;
17
17
  export declare function runPipedCommand(cmd: string, args?: string[], cwd?: string): [string | undefined, string | undefined];
18
18
  /** Run an command and return if it's success */
19
19
  export declare function runCommand(cmd: string, args?: string[], cwd?: string): Promise<boolean>;
20
+ /** Reload the process */
21
+ export declare function reloadProcess(): void;
@@ -66,3 +66,9 @@ export async function runCommand(cmd, args = [], cwd) {
66
66
  child.on("close", (code) => resolve(code === 0));
67
67
  });
68
68
  }
69
+ /** Reload the process */
70
+ export function reloadProcess() {
71
+ if (process.send) {
72
+ process.send({ type: "reload" });
73
+ }
74
+ }
package/build/src/site.js CHANGED
@@ -6,6 +6,7 @@ import { log } from "./utils/log.js";
6
6
  import { filter404page } from "./utils/page_url.js";
7
7
  import { insertContent } from "./utils/page_content.js";
8
8
  import { getFile, getFiles, isFromCdn } from "./utils/cdn.js";
9
+ import { setCache } from "./utils/read.js";
9
10
  import FS from "./fs.js";
10
11
  import { compileCSS, compileJS, ComponentLoader } from "./components.js";
11
12
  import DataLoader from "./data_loader.js";
@@ -195,6 +196,7 @@ export default class Site {
195
196
  // Initialize the cache if LUME_NOCACHE is not enabled
196
197
  if (envBoolean("LUME_NOCACHE") !== true) {
197
198
  this.cache = new Cache({ folder: this.root("_cache") });
199
+ setCache(this.cache);
198
200
  }
199
201
  // Initialize the debug bar
200
202
  const initDebugBar = this.options.server.debugBar ?? envBoolean("LUME_LIVE_RELOAD");
@@ -422,8 +424,8 @@ export default class Site {
422
424
  }
423
425
  return;
424
426
  }
425
- // Remote files from NPM or GitHub CDN
426
- if (isFromCdn(from)) {
427
+ // Remote files CDN or filesystem
428
+ if (isFromCdn(from) || from.startsWith("file:")) {
427
429
  // It's a pattern
428
430
  if (from.includes("*")) {
429
431
  const pos = from.indexOf("*");
@@ -58,16 +58,15 @@ export function getFile(specifier) {
58
58
  if (specifier.startsWith("npm:")) {
59
59
  return specifier.replace("npm:", "https://cdn.jsdelivr.net/npm/");
60
60
  }
61
- else if (specifier.startsWith("gh:")) {
61
+ if (specifier.startsWith("gh:")) {
62
62
  return specifier.replace("gh:", "https://cdn.jsdelivr.net/gh/");
63
63
  }
64
- else if (specifier.startsWith("https://cdn.jsdelivr.net/npm/") ||
64
+ if (specifier.startsWith("file://") ||
65
+ specifier.startsWith("https://cdn.jsdelivr.net/npm/") ||
65
66
  specifier.startsWith("https://cdn.jsdelivr.net/gh/")) {
66
67
  return specifier;
67
68
  }
68
- else {
69
- throw new Error(`Invalid specifier: ${specifier}`);
70
- }
69
+ throw new Error(`Invalid specifier: ${specifier}`);
71
70
  }
72
71
  export async function getVersion(type, name, version) {
73
72
  // Check if the version is a hash (commit SHA)
@@ -1,10 +1,11 @@
1
+ import type Cache from "../cache.ts";
2
+ export declare function setCache(instance: Cache): void;
1
3
  /**
2
4
  * Read a local or remote file and return its content.
3
5
  * If the file is remote, it will be cached in the `lume_remote_files` cache.
4
6
  */
5
- export declare function read(path: string, isBinary: boolean): Promise<Uint8Array<ArrayBuffer> | string>;
7
+ export declare function read(path: string, isBinary?: false, init?: RequestInit): Promise<string>;
6
8
  export declare function read(path: string, isBinary: true, init?: RequestInit): Promise<Uint8Array<ArrayBuffer>>;
7
- export declare function read(path: string, isBinary: false, init?: RequestInit): Promise<string>;
8
9
  /** Read a text file like a browser */
9
10
  export declare function readFile(path: string): Promise<string>;
10
11
  /**
@@ -1,10 +1,12 @@
1
1
  import { isUrl } from "./path.js";
2
- import { envBoolean } from "./env.js";
3
2
  import { tokens } from "./tokens.js";
4
3
  import { readFile as readFile_, readTextFile } from "../services/fs.js";
5
4
  import { fromFileUrl } from "../../deps/path.js";
6
- const useCache = envBoolean("LUME_NOCACHE") !== true;
7
- export async function read(path, isBinary, init) {
5
+ let cache;
6
+ export function setCache(instance) {
7
+ cache = instance;
8
+ }
9
+ export async function read(path, isBinary = false, init) {
8
10
  if (!isUrl(path)) {
9
11
  if (path.startsWith("data:")) {
10
12
  const response = await fetch(path);
@@ -23,23 +25,9 @@ export async function read(path, isBinary, init) {
23
25
  headers.set("Authorization", authorization);
24
26
  init = { ...init, headers };
25
27
  }
26
- if (!useCache) {
27
- const response = await fetch(url, init);
28
- if (!response.ok) {
29
- throw new Error(`Failed to fetch "${url}"`);
30
- }
31
- return isBinary ? new Uint8Array(await response.arrayBuffer()) : response.text();
32
- }
33
- const cache = await caches.open("lume_remote_files");
34
- // Prevent https://github.com/denoland/deno/issues/19696
35
- try {
36
- const cached = await cache.match(url);
37
- if (cached) {
38
- return isBinary ? new Uint8Array(await cached.arrayBuffer()) : cached.text();
39
- }
40
- }
41
- catch {
42
- // ignore
28
+ const cached = isBinary ? cache?.getBytes([url]) : cache?.getText([url]);
29
+ if (cached) {
30
+ return cached;
43
31
  }
44
32
  const response = await fetch(url, {
45
33
  signal: AbortSignal.timeout(1000 * 10), // 10s
@@ -48,8 +36,9 @@ export async function read(path, isBinary, init) {
48
36
  if (!response.ok) {
49
37
  throw new Error(`Failed to fetch "${url}"`);
50
38
  }
51
- await cache.put(url, response.clone());
52
- return isBinary ? new Uint8Array(await response.arrayBuffer()) : response.text();
39
+ const content = isBinary ? new Uint8Array(await response.arrayBuffer()) : await response.text();
40
+ cache?.set([url], content);
41
+ return content;
53
42
  }
54
43
  /** Read a text file like a browser */
55
44
  export async function readFile(path) {
@@ -63,5 +52,5 @@ export async function readFile(path) {
63
52
  * Clear the cache of remote files.
64
53
  */
65
54
  export async function clearCache() {
66
- await caches.delete("lume_remote_files");
55
+ cache?.clear();
67
56
  }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@lumeland/core",
3
- "version": "1.0.0-beta-2",
3
+ "version": "1.0.0-beta-4",
4
4
  "description": "The core of Lume SSG",
5
5
  "license": "MIT",
6
6
  "files": [
7
- "build"
7
+ "build",
8
+ "CHANGELOG.md"
8
9
  ],
9
10
  "type": "module",
10
11
  "exports": {