olum-compiler 1.9.1 → 1.9.3

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/bin/copySrc.js CHANGED
@@ -1,12 +1,14 @@
1
1
  const path = require("path");
2
2
  const fs = require("fs");
3
- const { copy, compileRoutes } = require("../lib/helpers");
3
+ const { copy, compileRoutes, ls, isFile } = require("../lib/helpers");
4
4
  const importMap = require("../lib/importMap");
5
5
  const usage = require("../lib/usage");
6
+ const splitJsBarrels = require("../lib/jsBarrels");
6
7
 
7
8
  const cwd = process.cwd();
8
- const entryPoint = path.resolve(cwd.replace(/\/module$/, ""), "src");
9
- const entryPoint2 = path.resolve(cwd.replace(/\/module$/, ""), "public");
9
+ const projectRoot = cwd.replace(/\/module$/, "");
10
+ const entryPoint = path.resolve(projectRoot, "src");
11
+ const entryPoint2 = path.resolve(projectRoot, "public");
10
12
 
11
13
  const devtoolSrc = path.resolve(
12
14
  cwd.replace(/\/module$/, ""),
@@ -36,6 +38,13 @@ function injectIndexHtml(indexHtmlPath) {
36
38
  fs.writeFileSync(indexHtmlPath, indexHtmlContent);
37
39
  }
38
40
 
41
+ function splitCopiedJs() {
42
+ ls(srcDest, { absolute: true }).forEach((file) => {
43
+ if (isFile(file) && file.endsWith(".js"))
44
+ splitJsBarrels.file(file, projectRoot);
45
+ });
46
+ }
47
+
39
48
  function handleMainJs() {
40
49
  if (fs.existsSync(mainJsPathDest)) return;
41
50
  const mainJsContent = compileRoutes(entryPoint);
@@ -61,6 +70,7 @@ function syncFile(event, file) {
61
70
  } else {
62
71
  fs.mkdirSync(path.dirname(dest), { recursive: true });
63
72
  fs.copyFileSync(file, dest);
73
+ if (inSrc && dest.endsWith(".js")) splitJsBarrels.file(dest, projectRoot);
64
74
  if (dest === indexHtmlDest) injectIndexHtml(dest);
65
75
  }
66
76
 
@@ -86,7 +96,10 @@ module.exports = function copySrc(event, file) {
86
96
  fs.rmSync(publicDest, { recursive: true, force: true });
87
97
  fs.rmSync(srcDest, { recursive: true, force: true });
88
98
 
89
- copy(entryPoint, srcDest, () => handleMainJs());
99
+ copy(entryPoint, srcDest, () => {
100
+ splitCopiedJs();
101
+ handleMainJs();
102
+ });
90
103
  copy(entryPoint2, publicDest, () => injectIndexHtml(indexHtmlDest));
91
104
 
92
105
  if (devtoolEnabled) {
package/lib/changes.txt CHANGED
@@ -0,0 +1,8 @@
1
+ change /tmp/olum-dev-test-4y7l2M/src/page.html
2
+ change /tmp/olum-dev-test-4y7l2M/public/main.css
3
+ addDir /tmp/olum-dev-test-4y7l2M/src/blog
4
+ add /tmp/olum-dev-test-4y7l2M/src/blog/page.html
5
+ unlink /tmp/olum-dev-test-4y7l2M/src/blog/page.html
6
+ unlinkDir /tmp/olum-dev-test-4y7l2M/src/blog
7
+ change /tmp/olum-dev-test-4y7l2M/src/util.js
8
+ change /tmp/olum-dev-test-4y7l2M/src/page.html
@@ -0,0 +1,39 @@
1
+ const fs = require("fs");
2
+ const acorn = require("acorn");
3
+ const splitBarrels = require("./barrelSplit");
4
+
5
+ const hasBareImport = (code) => /from\s*["'][^./"']/.test(code);
6
+
7
+ function splitJsBarrels(code, rootDir) {
8
+ if (!hasBareImport(code)) return code;
9
+
10
+ let body;
11
+ try {
12
+ body = acorn.parse(code, {
13
+ ecmaVersion: "latest",
14
+ sourceType: "module",
15
+ }).body;
16
+ } catch (e) {
17
+ return code;
18
+ }
19
+
20
+ const nodes = body.filter((node) => node.type === "ImportDeclaration");
21
+
22
+ for (let i = nodes.length - 1; i >= 0; i--) {
23
+ const { start, end } = nodes[i];
24
+ const statement = code.slice(start, end);
25
+ const split = splitBarrels(statement, rootDir);
26
+ if (split !== statement)
27
+ code = code.slice(0, start) + split + code.slice(end);
28
+ }
29
+ return code;
30
+ }
31
+
32
+ function splitFile(file, rootDir) {
33
+ const code = fs.readFileSync(file, "utf8");
34
+ const split = splitJsBarrels(code, rootDir);
35
+ if (split !== code) fs.writeFileSync(file, split);
36
+ }
37
+
38
+ module.exports = splitJsBarrels;
39
+ module.exports.file = splitFile;
package/lib/parser.js CHANGED
@@ -152,7 +152,7 @@ const parser = (str, counter, filePath) => {
152
152
  return entries.join(",");
153
153
  }
154
154
 
155
- js = js.replace(/params\(/, `params("${filePath}",location.pathname`);
155
+ js = js.replace(/params\(/g, `params("${filePath}",location.pathname`);
156
156
 
157
157
  js = js.replace(/props\(\s*\)/g, "props(_storeKey)");
158
158
  html = html.replace(/props\(\s*\)/g, "props(_storeKey)");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olum-compiler",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "A module for compiling/bundling olumjs projects",
5
5
  "main": "bin/index.js",
6
6
  "bin": {
@@ -238,6 +238,41 @@ check(
238
238
  (out) => /onclick\|a=[^&]*&b=/.test(tmpl(out)) && parses(out),
239
239
  );
240
240
 
241
+ check(
242
+ "several on* attributes on ONE element all survive, joined by OLUM_EVT_SEP",
243
+ comp(
244
+ `<input oninput="draft($event)" onblur="save()" />`,
245
+ `const draft = (e) => 0; const save = () => 0;`,
246
+ ),
247
+ (out) => {
248
+ const t = tmpl(out);
249
+ return (
250
+ /oninput\|draft=/.test(t) &&
251
+ /onblur\|save=/.test(t) &&
252
+ t.split("OLUM_EVT_SEP").length === 2 &&
253
+ parses(out)
254
+ );
255
+ },
256
+ );
257
+
258
+ check(
259
+ "a third event on the same element is appended too (2 separators)",
260
+ comp(
261
+ `<div onmousedown="down()" onmousemove="move()" onmouseup="up()"></div>`,
262
+ `const down = () => 0; const move = () => 0; const up = () => 0;`,
263
+ ),
264
+ (out) => {
265
+ const t = tmpl(out);
266
+ return (
267
+ /onmousedown\|down=/.test(t) &&
268
+ /onmousemove\|move=/.test(t) &&
269
+ /onmouseup\|up=/.test(t) &&
270
+ t.split("OLUM_EVT_SEP").length === 3 &&
271
+ parses(out)
272
+ );
273
+ },
274
+ );
275
+
241
276
  check(
242
277
  "$event is forwarded to the handler",
243
278
  comp(`<input oninput="setVal($event)" />`, `const setVal = (e) => 0;`),
@@ -1279,7 +1314,7 @@ if (failed) {
1279
1314
  console.log("");
1280
1315
  }
1281
1316
 
1282
- const EXPECTED_CHECKS = 108;
1317
+ const EXPECTED_CHECKS = 110;
1283
1318
  const total = passed + failed;
1284
1319
  if (total !== EXPECTED_CHECKS) {
1285
1320
  console.log(