htmlemmurt 0.1.2 → 0.2.0

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/README.md CHANGED
@@ -9,7 +9,7 @@ npm i -D htmlemmurt
9
9
  ## Da Node
10
10
 
11
11
  ```js
12
- import { compile, compileFratm, formatError } from 'htmlemmurt';
12
+ import { compile, formatError } from 'htmlemmurt';
13
13
 
14
14
  const { html, dependencies, errors } = compile('<cascett classe="a">Uè</cascett>', {
15
15
  filename: 'index.emmurt',
@@ -17,18 +17,19 @@ const { html, dependencies, errors } = compile('<cascett classe="a">Uè</cascett
17
17
  // html → '<div class="a">Uè</div>'
18
18
  ```
19
19
 
20
- `compile` non lancia mai eccezioni: gli errori stanno in `errors`, con `message`, `file`, `line`, `column` e `suggestion`, in napoletano. Le opzioni sono `filename`, `root` (la cartella per i percorsi che cominciano con `/`), `read` (per leggere i file in un altro modo) e `inline` (incolla nella pagina i file di `<fratm da>`). `compileFratm` compila un modulo FratmScript.
20
+ `compile` non lancia mai eccezioni: gli errori stanno in `errors`, con `message`, `file`, `line`, `column` e `suggestion`, in napoletano. Le opzioni sono `filename`, `root` (la cartella per i percorsi che cominciano con `/`), `read` (per leggere i file in un altro modo) e `inline` (incolla nella pagina i file di `<fratm da>`). I moduli `.fratm` li compila il pacchetto [`fratmscript`](https://www.npmjs.com/package/fratmscript).
21
21
 
22
22
  ## Con Vite
23
23
 
24
24
  ```js
25
25
  // vite.config.js
26
26
  import htmlemmurt from 'htmlemmurt/vite';
27
+ import fratmscript from 'fratmscript/vite';
27
28
 
28
- export default { plugins: [htmlemmurt()] };
29
+ export default { plugins: [htmlemmurt(), fratmscript()] };
29
30
  ```
30
31
 
31
- Ogni `x.emmurt` che comincia con `<cristian>` diventa `x.html`, in sviluppo e in build. Anche i moduli `.fratm` passano dal plugin.
32
+ Ogni `x.emmurt` che comincia con `<cristian>` diventa `x.html`, in sviluppo e in build. I moduli `.fratm` li compila il plugin di FratmScript.
32
33
 
33
34
  ## Nel browser
34
35
 
package/index.d.ts CHANGED
@@ -36,24 +36,16 @@ export interface CompileResult {
36
36
  errors: EmmurtError[];
37
37
  }
38
38
 
39
- export interface FratmResult {
40
- /** The JavaScript, or null when there are errors */
41
- code: string | null;
42
- /** Source map (v3) back to the .fratm file */
43
- map: { version: number; file: string; sources: string[]; sourcesContent: string[]; names: string[]; mappings: string } | null;
44
- errors: EmmurtError[];
45
- }
46
-
47
39
  export interface Vocabulary {
48
- tags: [string, string][];
49
- attributes: { nap: string; html: string; only?: string[]; values?: [string, string][] }[];
50
- events: [string, string][];
40
+ /** [Neapolitan, HTML, description in Neapolitan] */
41
+ tags: [string, string, string][];
42
+ attributes: { nap: string; html: string; react: string; only?: string[]; values?: [string, string][] }[];
43
+ /** [Neapolitan, HTML, React prop] */
44
+ events: [string, string, string][];
51
45
  }
52
46
 
53
47
  /** Compiles htmlemmurt to HTML. Never throws on invalid source: check `errors`. */
54
48
  export function compile(source: string, options?: CompileOptions): CompileResult;
55
- /** Compiles a FratmScript module to JavaScript. */
56
- export function compileFratm(source: string, options?: { filename?: string }): FratmResult;
57
49
  /** Every Neapolitan name and its HTML. */
58
50
  export function vocabulary(): Vocabulary;
59
51
  /** Version of the compiler. */
package/index.js CHANGED
@@ -7,7 +7,7 @@ import { createApi } from './lib/api.js';
7
7
  const wasm = createRequire(import.meta.url)('./wasm/node/emmurt_wasm.js');
8
8
  const api = createApi(wasm);
9
9
 
10
- export const { compileFratm, vocabulary, version, runtimeError } = api;
10
+ export const { vocabulary, version, runtimeError } = api;
11
11
  export { formatError } from './lib/api.js';
12
12
 
13
13
  /**
package/lib/api.js CHANGED
@@ -6,20 +6,7 @@ export function createApi(wasm) {
6
6
  const { filename = 'input.emmurt', read, inline = false } = options;
7
7
  // The bindings take a missing file as anything that is not a string
8
8
  const response = wasm.compile(String(source), filename, read ? (path) => read(path) : undefined, inline);
9
- return { html: response.code, dependencies: response.dependencies, errors: response.errors };
10
- }
11
-
12
- function compileFratm(source, options = {}) {
13
- const filename = options.filename ?? 'input.fratm';
14
- const response = wasm.compileFratm(String(source), filename);
15
- let map = null;
16
- if (response.map) {
17
- map = JSON.parse(response.map);
18
- map.sources = [filename];
19
- map.sourcesContent = [String(source)];
20
- map.file = filename.replace(/\.fratm$/, '') + '.js';
21
- }
22
- return { code: response.code, map, errors: response.errors };
9
+ return { html: response.html, dependencies: response.dependencies, errors: response.errors };
23
10
  }
24
11
 
25
12
  function vocabulary() {
@@ -32,7 +19,7 @@ export function createApi(wasm) {
32
19
  return wasm.runtimeError(name, message);
33
20
  }
34
21
 
35
- return { compile, compileFratm, vocabulary, version: wasm.version, runtimeError };
22
+ return { compile, vocabulary, version: wasm.version, runtimeError };
36
23
  }
37
24
 
38
25
  /** `file:line:column: message`, then the hint on its own line. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "htmlemmurt",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "htmlemmurt compiler (WebAssembly), Vite plugin and browser runtime: HTML, ma comme si deve 🤌",
5
5
  "license": "MIT",
6
6
  "author": "Vito Esposito",
package/vite.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import type { Plugin } from 'vite';
2
2
 
3
3
  /**
4
- * Serves and builds every `x.emmurt` page as `x.html` and compiles `.fratm`
5
- * modules. Pages are the .emmurt files that start with `<cristian>`; set
6
- * `build.rollupOptions.input` to choose them yourself.
4
+ * Serves and builds every `x.emmurt` page as `x.html`. Pages are the .emmurt
5
+ * files that start with `<cristian>`; set `build.rollupOptions.input` to
6
+ * choose them yourself. Add `fratmscript/vite` for the `.fratm` modules.
7
7
  */
8
8
  export default function htmlemmurt(): Plugin;
9
9
  export { htmlemmurt };
package/vite.js CHANGED
@@ -1,12 +1,10 @@
1
- // Vite plugin: .emmurt pages are the app's HTML entries, .fratm files its
2
- // modules. `x.emmurt` is served and built as `x.html`.
1
+ // Vite plugin: .emmurt pages are the app's HTML entries. `x.emmurt` is
2
+ // served and built as `x.html`. The .fratm modules they load are compiled by
3
+ // FratmScript's own plugin, `fratmscript/vite`.
3
4
  import { existsSync, readFileSync, readdirSync } from 'node:fs';
4
5
  import { join, relative, resolve, sep } from 'node:path';
5
- import { compile, compileFratm, formatError } from './index.js';
6
+ import { compile, formatError } from './index.js';
6
7
 
7
- const FRATM = /\.fratm$/;
8
- // A request for a .fratm file that Vite would serve as it is
9
- const RAW_FRATM_REQUEST = /^[^?#]*\.fratm(?:$|[?#])/;
10
8
  // A page starts with <cristian>, maybe after comments
11
9
  const PAGE = /^\s*(?:<!--[\s\S]*?-->\s*)*<cristian[\s>/]/i;
12
10
  const SKIP_DIRS = new Set(['node_modules', 'dist', 'public']);
@@ -59,14 +57,6 @@ export default function htmlemmurt() {
59
57
  return html;
60
58
  },
61
59
 
62
- transform(source, id) {
63
- const file = id.split('?', 1)[0];
64
- if (!FRATM.test(file)) return null;
65
- const { code, map, errors } = compileFratm(source, { filename: file });
66
- if (errors.length > 0) this.error(errorFor(errors[0]));
67
- return { code, map };
68
- },
69
-
70
60
  configureServer(server) {
71
61
  const reload = (file) => {
72
62
  if (file.endsWith('.emmurt')) server.ws.send({ type: 'full-reload' });
@@ -77,12 +67,6 @@ export default function htmlemmurt() {
77
67
 
78
68
  server.middlewares.use(async (req, res, next) => {
79
69
  if (!req.url) return next();
80
- // The dev server only compiles requests it knows are modules. Imports
81
- // between modules get `?import`, the <script src> of a page does not
82
- if (RAW_FRATM_REQUEST.test(req.url) && !/[?&]import(?:[=&#]|$)/.test(req.url)) {
83
- req.url += req.url.includes('?') ? '&import' : '?import';
84
- return next();
85
- }
86
70
  if (req.method !== 'GET' && req.method !== 'HEAD') return next();
87
71
  let path = decodeURIComponent(req.url.split(/[?#]/, 1)[0]);
88
72
  if (path.endsWith('/')) path += 'index.html';
@@ -20,22 +20,6 @@ function compile(source, filename, read, inline) {
20
20
  }
21
21
  exports.compile = compile;
22
22
 
23
- /**
24
- * Compiles a `.fratm` module to JavaScript.
25
- * @param {string} source
26
- * @param {string} filename
27
- * @returns {any}
28
- */
29
- function compileFratm(source, filename) {
30
- const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
31
- const len0 = WASM_VECTOR_LEN;
32
- const ptr1 = passStringToWasm0(filename, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
33
- const len1 = WASM_VECTOR_LEN;
34
- const ret = wasm.compileFratm(ptr0, len0, ptr1, len1);
35
- return ret;
36
- }
37
- exports.compileFratm = compileFratm;
38
-
39
23
  /**
40
24
  * A JavaScript runtime error in Neapolitan, as FratmScript says it.
41
25
  * @param {string} name
Binary file
@@ -19,21 +19,6 @@ export function compile(source, filename, read, inline) {
19
19
  return ret;
20
20
  }
21
21
 
22
- /**
23
- * Compiles a `.fratm` module to JavaScript.
24
- * @param {string} source
25
- * @param {string} filename
26
- * @returns {any}
27
- */
28
- export function compileFratm(source, filename) {
29
- const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
30
- const len0 = WASM_VECTOR_LEN;
31
- const ptr1 = passStringToWasm0(filename, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
32
- const len1 = WASM_VECTOR_LEN;
33
- const ret = wasm.compileFratm(ptr0, len0, ptr1, len1);
34
- return ret;
35
- }
36
-
37
22
  /**
38
23
  * A JavaScript runtime error in Neapolitan, as FratmScript says it.
39
24
  * @param {string} name
Binary file
package/web.d.ts CHANGED
@@ -1,11 +1,10 @@
1
- export type { EmmurtError, CompileResult, FratmResult, Vocabulary } from './index.js';
2
- import type { CompileOptions, CompileResult, FratmResult, Vocabulary, EmmurtError } from './index.js';
1
+ export type { EmmurtError, CompileResult, Vocabulary } from './index.js';
2
+ import type { CompileOptions, CompileResult, Vocabulary, EmmurtError } from './index.js';
3
3
 
4
4
  /** Loads the WebAssembly module (by default the .wasm file next to this one). Call once, await it. */
5
5
  export function init(input?: string | URL | Request | Response | BufferSource | WebAssembly.Module): Promise<void>;
6
6
  /** Compiles htmlemmurt to HTML. Without `read`, includes cannot be resolved. */
7
7
  export function compile(source: string, options?: Omit<CompileOptions, 'root'>): CompileResult;
8
- export function compileFratm(source: string, options?: { filename?: string }): FratmResult;
9
8
  export function vocabulary(): Vocabulary;
10
9
  export function version(): string;
11
10
  export function runtimeError(error: unknown): string;
package/web.js CHANGED
@@ -19,7 +19,6 @@ function loadedApi() {
19
19
  }
20
20
 
21
21
  export const compile = (source, options) => loadedApi().compile(source, options);
22
- export const compileFratm = (source, options) => loadedApi().compileFratm(source, options);
23
22
  export const vocabulary = () => loadedApi().vocabulary();
24
23
  export const version = () => loadedApi().version();
25
24
  export const runtimeError = (error) => loadedApi().runtimeError(error);