cayo 1.1.1 → 1.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.
@@ -70,10 +70,15 @@ export async function getDeps(input, config) {
70
70
  }
71
71
 
72
72
  export async function build(input, config, type = 'page') {
73
- const ssr = (type === 'page' || type === 'template');
73
+ const template = (type === 'page' || type === 'template');
74
74
  const requiredCompilerOptions = {
75
- generate: ssr ? 'ssr' : 'dom',
76
- hydratable: ssr ? false : true,
75
+ generate: template ? 'ssr' : 'dom',
76
+ hydratable: template ? false : true,
77
+ preserveComments: template
78
+ ? false
79
+ : config.svelte.compilerOptions.preserveComments
80
+ ? config.svelte.compilerOptions.preserveComments
81
+ : true,
77
82
  }
78
83
 
79
84
  let bundle;
@@ -95,7 +100,6 @@ export async function build(input, config, type = 'page') {
95
100
  ...preprocessors,
96
101
  ],
97
102
  compilerOptions: {
98
- preserveComments: true,
99
103
  preserveWhitespace: true,
100
104
  ...config.svelte.compilerOptions,
101
105
  ...requiredCompilerOptions,
@@ -11,13 +11,13 @@ export const errorLoggerVite = createLogger('error', {
11
11
  });
12
12
 
13
13
  const errorLogger = (err) => {
14
- let errorMessage = err;
15
14
  // TODO: good reason to write a new logger that is
16
15
  // globally initialized and passed in a runtime object,
17
16
  // so this could have access to _cayo.config options
18
17
  // Only really useful for dev
19
18
  // if (err.stack) errorMessage = err.stack;
20
- console.error(chalk.red.bold(`${errorMessage}`));
19
+ console.error(chalk.red.bold(err));
20
+ console.log(err);
21
21
 
22
22
  if (err.cause && !err.cause.cause) {
23
23
  console.error(`${chalk.red.bold('> Cause:')} ${chalk.red.bold(err.cause)}`);
@@ -36,6 +36,7 @@ const handleCause = (err) => {
36
36
  } else {
37
37
  // console.error(`${prefix} ${chalk.red.bold(err.stack)}`);
38
38
  // console.error(err.stack);
39
+ console.log(err);
39
40
  }
40
41
  }
41
42
 
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import { JSDOM } from 'jsdom';
4
+ import chalk from 'chalk';
4
5
  import { Renderer } from './renderer.js';
5
6
  import { compileCayos } from '../compile/cayos.js';
6
7
  import { generateCayoRuntime, generateRuntimeIssuesScript } from '../codegen.js';
@@ -116,7 +117,16 @@ export async function processPage(content, page, _cayo, logger) {
116
117
  }
117
118
  }
118
119
  const cayoAssetsCssMarker = document.querySelector('link[data-cayo-assets-css]');
119
- cayoAssetsCssMarker.outerHTML = cayoAssetCssElements;
120
+ if (cayoAssetsCssMarker && cayoAssetsCssMarker.outerHTML) {
121
+ cayoAssetsCssMarker.outerHTML = cayoAssetCssElements;
122
+ } else {
123
+ if (cayoAssetCssElements) {
124
+ logger.log.info(
125
+ chalk.yellow.bold('Warning') + chalk.yellow(': No %cayo.css% found in template, but there is CSS used in source files.'),
126
+ { timestamp: true, clear: false, }
127
+ );
128
+ }
129
+ }
120
130
 
121
131
  // Get user-specified entry placeholder
122
132
  const entryScriptPlaceholder = document.querySelector('script[data-cayo-entry]');
@@ -138,7 +148,7 @@ export async function processPage(content, page, _cayo, logger) {
138
148
  log: `Entry file '${entryScriptSrc}' does not exist.`,
139
149
  }
140
150
  // Remove the entry file script because the file doesn't exist
141
- entryScript.remove();
151
+ entryScript?.remove();
142
152
  } else {
143
153
  entry.path = absoluteEntrySrcPath;
144
154
  _cayo.stats.dependencies.pages[page.sourcePath].add(absoluteEntrySrcPath);
@@ -154,7 +164,7 @@ export async function processPage(content, page, _cayo, logger) {
154
164
  }
155
165
  } else {
156
166
  // Remove the entry point script tag because the page doesn't need any JS
157
- entryScript.remove();
167
+ entryScript?.remove();
158
168
  }
159
169
  }
160
170
 
@@ -199,22 +209,32 @@ export async function processPage(content, page, _cayo, logger) {
199
209
  let processedHTML = '';
200
210
  if (tags.doctype) {
201
211
  processedHTML += tags.doctype;
202
- }
212
+ }
213
+
214
+ let html; // html element parts (open/close tag, inner)
215
+ let head;
203
216
  if (tags.html) {
204
- processedHTML += document.documentElement.outerHTML;
217
+ ({groups: html} = document.documentElement.outerHTML
218
+ .match(/(?<open><html[\s\S]*?>)(?<innerHTML>[\s\S]*)(?<close><\/html>)/)
219
+ )
220
+ processedHTML += html.open;
221
+ }
222
+ if (tags.head) {
223
+ ({groups: head} = document.head.outerHTML
224
+ .match(/(?<open><head[\s\S]*?>)(?<innerHTML>[\s\S]*)(?<close><\/head>)/)
225
+ )
226
+ processedHTML += document.head.outerHTML;
205
227
  } else {
206
- if (tags.head) {
207
- processedHTML += document.head.outerHTML;
208
- } else {
209
- processedHTML += document.head.innerHTML;
210
- }
211
-
212
- if (tags.body) {
213
- processedHTML += document.body.outerHTML;
214
- } else {
215
- processedHTML += document.body.innerHTML;
216
- }
228
+ processedHTML += document.head.innerHTML;
217
229
  }
230
+ if (tags.body) {
231
+ processedHTML += document.body.outerHTML;
232
+ } else {
233
+ processedHTML += document.body.innerHTML;
234
+ }
235
+ if (tags.html) {
236
+ processedHTML += html.close;
237
+ }
218
238
 
219
239
  return {
220
240
  html: processedHTML,
@@ -227,14 +247,14 @@ export async function processPage(content, page, _cayo, logger) {
227
247
  }
228
248
 
229
249
  function tagsExist(source) {
230
- const doctype = source.match(/\<!DOCTYPE\s\w*\>/g);
231
- const head = source.match(/\<head[\s\S]*\>(?<innerHTML>[\s\S]*)\<\/head\>/g);
232
- const body = source.match(/\<body[\s\S]*\>(?<innerHTML>[\s\S]*)\<\/body\>/g);
233
- const html = source.match(/\<html[\s\S]*\>(?<innerHTML>[\s\S]*)\<\/html\>/g);
250
+ const doctype = source.match(/<!DOCTYPE[\s\S]*>/);
251
+ const head = source.match(/<head[\s\S]*>(?<innerHTML>[\s\S]*)<\/head>/);
252
+ const body = source.match(/<body[\s\S]*>(?<innerHTML>[\s\S]*)<\/body>/);
253
+ const html = source.match(/<html[\s\S]*>(?<innerHTML>[\s\S]*)<\/html>/);
234
254
  return {
235
255
  doctype: doctype === null ? false : doctype,
236
- head: head === null ? false : true,
237
- body: body === null ? false : true,
238
- html: html === null ? false : true,
256
+ html: html === null ? false : html.groups,
257
+ head: head === null ? false : head.groups,
258
+ body: body === null ? false : body.groups,
239
259
  };
240
260
  }
@@ -37,9 +37,9 @@ export class Renderer {
37
37
  // https://stackoverflow.com/questions/9423722/string-replace-weird-behavior-when-using-dollar-sign-as-replacement
38
38
  return {
39
39
  html: this.template.html
40
- // FIXME#83: this regex is bad; accidentally removes elements like head
41
- // Ignore placeholders wrapped in HTML comments
42
- // .replace(/<!--[^]*\%cayo\.\w+\%[^]*-->/g, '')
40
+ // Strip placeholders wrapped in HTML comments
41
+ .replace(/<!--[\s\S]?%cayo\.\w+%[\s\S]*?(-->)/g, '')
42
+ // Inject markup in the cayo placeholders
43
43
  .replace('%cayo.title%', () => !head.includes('<title>') ? title() : '')
44
44
  .replace('%cayo.head%', () => head)
45
45
  .replace('%cayo.body%', () => html)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cayo",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "start": "node cayo dev --projectRoot test",