nowebcli 0.2.14 → 0.2.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nowebcli",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
4
4
  "description": "Create, preview and publish community templates for Noweb",
5
5
  "license": "MIT",
6
6
  "repository": {
package/scripts/noweb.mjs CHANGED
@@ -278,7 +278,7 @@ async function upload() {
278
278
  if (!response.ok) throw new Error(result.error || `Upload failed (${response.status}).`);
279
279
  if (!Number.isInteger(result.id) || result.id < 1) throw new Error("Upload returned an invalid template ID.");
280
280
  await writeFile(join(root, "template.json"), `${JSON.stringify({ id: result.id, slug: template.slug, type: template.type }, null, 2)}\n`);
281
- success(`Uploaded ${template.slug} (unpublished): ${new URL(result.url, apiBase)}`);
281
+ success(`Uploaded ${template.slug} (${result.is_published ? "public" : "unpublished"}): ${new URL(result.url, apiBase)}`);
282
282
  }
283
283
 
284
284
  async function publishUploadedTemplate() {
@@ -1,5 +1,4 @@
1
1
  import { execFile } from "node:child_process";
2
- import { existsSync } from "node:fs";
3
2
  import { createRequire } from "node:module";
4
3
  import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
5
4
  import { tmpdir } from "node:os";
@@ -13,12 +12,9 @@ import { validateTemplateCode } from "./validateTemplateCode.ts";
13
12
 
14
13
  const run = promisify(execFile);
15
14
  const templatesPath = path.dirname(fileURLToPath(import.meta.url));
16
- const packageModulesPath = path.join(path.dirname(templatesPath), "node_modules");
17
- const modulesPath = existsSync(path.join(packageModulesPath, ".bin", "esbuild"))
18
- ? packageModulesPath
19
- : path.join(process.cwd(), "node_modules");
20
-
21
15
  const require = createRequire(import.meta.url);
16
+ const esbuildPath = require.resolve("esbuild/bin/esbuild");
17
+ const modulesPath = path.dirname(path.dirname(require.resolve("react/package.json")));
22
18
 
23
19
  const TEMPLATE_COMPILE_TIMEOUT_MS = 10_000;
24
20
  const TEMPLATE_COMPILE_MAX_BUFFER = 8 * 1024 * 1024;
@@ -46,7 +42,7 @@ export async function compileTemplate(
46
42
  await writeFile(input, withRuntimeImports(code));
47
43
  const nodePath = modulesPath;
48
44
 
49
- await runTemplateCommand(path.join(nodePath, ".bin", "esbuild"), [
45
+ await runTemplateCommand(esbuildPath, [
50
46
  input,
51
47
  "--bundle",
52
48
  "--format=esm",
@@ -121,7 +117,7 @@ window.__nowebRenderTemplate = (element, props) => {
121
117
 
122
118
  const nodePath = modulesPath;
123
119
 
124
- await runTemplateCommand(path.join(nodePath, ".bin", "esbuild"), [
120
+ await runTemplateCommand(esbuildPath, [
125
121
  entry,
126
122
  "--bundle",
127
123
  "--format=iife",
@@ -203,5 +199,9 @@ async function runTemplateCommand(
203
199
  },
204
200
  maxBuffer: TEMPLATE_COMPILE_MAX_BUFFER,
205
201
  timeout: TEMPLATE_COMPILE_TIMEOUT_MS,
202
+ }).catch((error) => {
203
+ throw new Error(error.killed
204
+ ? "Template compilation timed out after 10 seconds."
205
+ : error.stderr?.trim() || "Template compilation failed.");
206
206
  });
207
207
  }