@bigbinary/neeto-commons-frontend 4.13.0-beta.15 → 4.13.0-beta.18

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.
@@ -9,6 +9,16 @@ module.exports = {
9
9
  "../../../",
10
10
  "neetoui/dist/index.css"
11
11
  ),
12
+ "@bigbinary/neeto-form-frontend/dist": path.resolve(
13
+ __dirname,
14
+ "../../../",
15
+ "neeto-form-frontend/dist"
16
+ ),
17
+ "@bigbinary/neeto-time-zones/dist": path.resolve(
18
+ __dirname,
19
+ "../../../",
20
+ "neeto-time-zones/dist"
21
+ ),
12
22
  images: path.resolve(process.cwd(), "app/assets/images"),
13
23
  assert: require.resolve("assert/"),
14
24
  buffer: require.resolve("buffer/"),
@@ -9,9 +9,9 @@ const sass = require("sass");
9
9
 
10
10
  const alias = require("./alias.js");
11
11
  const { babelPlugin } = require("./plugins/babel.js");
12
+ const { entrypointPlugin } = require("./plugins/entrypoint.js");
12
13
  const { prevalPlugin } = require("./plugins/preval.js");
13
14
  const { virtualizedPlugin } = require("./plugins/virtualized.js");
14
- const { watchPlugin } = require("./plugins/watch.js");
15
15
  const { createDefinitions, entryPoint, build, watch } = require("./utils.js");
16
16
 
17
17
  const postCssConfig = require("../../../../../postcss.config.js");
@@ -39,7 +39,7 @@ const config = {
39
39
  chunkNames: "chunks/[name]-[hash].digested",
40
40
  plugins: [
41
41
  rails(),
42
- watchPlugin(isWatchMode),
42
+ entrypointPlugin(isWatchMode),
43
43
  prevalPlugin(),
44
44
  babelPlugin(),
45
45
  virtualizedPlugin(),
@@ -0,0 +1,44 @@
1
+ // Matches:
2
+ // const componentsContext = { App };
3
+ const COMPONENT_CONTEXT = /const\s+componentsContext\s*=\s*{[^}]+};?/;
4
+
5
+ // Matches:
6
+ // const App = React.lazy(() => import("src/App"));
7
+ const LAZY_LOAD_IMPORT =
8
+ /const\s+(\w+)\s*=\s*React\.lazy\(\s*\(\)\s*=>\s*import\(["'](.*?)["']\)\);?/;
9
+
10
+ const entrypointPlugin = isWatch => ({
11
+ name: "entrypoint-plugin",
12
+ setup(build) {
13
+ build.onLoad({ filter: /app\/javascript\/packs\/\w+\.js/ }, async args => {
14
+ const fs = require("fs").promises;
15
+ const contents = await fs.readFile(args.path, "utf8");
16
+
17
+ const eventSrcCode = `new EventSource("http://localhost:${
18
+ process.env.DEVSERVER_PORT || 8000
19
+ }/esbuild").addEventListener('change', () => location.reload());`;
20
+
21
+ const contentsWithEventSource = isWatch
22
+ ? `${eventSrcCode}\n${contents}`
23
+ : contents;
24
+
25
+ const lazyLoadImport = contents.match(LAZY_LOAD_IMPORT);
26
+ const componentContext = contents.match(COMPONENT_CONTEXT);
27
+ if (lazyLoadImport && componentContext) {
28
+ const componentName = lazyLoadImport[1];
29
+ const importPath = lazyLoadImport[2];
30
+ const updatedContext = `const componentsContext = { ${componentName}: require("${importPath}").default };`;
31
+
32
+ const transformedContents = contentsWithEventSource
33
+ .replace(LAZY_LOAD_IMPORT, "")
34
+ .replace(COMPONENT_CONTEXT, updatedContext);
35
+
36
+ return { contents: transformedContents, loader: "js" };
37
+ }
38
+
39
+ return { contents: contentsWithEventSource, loader: "js" };
40
+ });
41
+ },
42
+ });
43
+
44
+ module.exports = { entrypointPlugin };
@@ -6,15 +6,17 @@ const WRONG_CODE = `import { bpfrpt_proptype_WindowScroller } from "../WindowScr
6
6
  const virtualizedPlugin = () => ({
7
7
  name: "flat:react-virtualized",
8
8
  configResolved() {
9
- const file = require
10
- .resolve("react-virtualized")
11
- .replace(
12
- path.join("dist", "commonjs", "index.js"),
13
- path.join("dist", "es", "WindowScroller", "utils", "onScroll.js")
14
- );
15
- const code = fs.readFileSync(file, "utf-8");
16
- const modified = code.replace(WRONG_CODE, "");
17
- fs.writeFileSync(file, modified);
9
+ try {
10
+ const file = require
11
+ .resolve("react-virtualized")
12
+ .replace(
13
+ path.join("dist", "commonjs", "index.js"),
14
+ path.join("dist", "es", "WindowScroller", "utils", "onScroll.js")
15
+ );
16
+ const code = fs.readFileSync(file, "utf-8");
17
+ const modified = code.replace(WRONG_CODE, "");
18
+ fs.writeFileSync(file, modified);
19
+ } catch {}
18
20
  },
19
21
  });
20
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bigbinary/neeto-commons-frontend",
3
- "version": "4.13.0-beta.15",
3
+ "version": "4.13.0-beta.18",
4
4
  "description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
5
5
  "repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
@@ -1,24 +0,0 @@
1
- const EVENT_SRC_CODE = `new EventSource("http://localhost:${
2
- process.env.DEVSERVER_PORT || 8000
3
- }/esbuild").addEventListener('change', () => location.reload());`;
4
-
5
- const watchPlugin = isWatch => ({
6
- name: "watch-plugin",
7
- setup(build) {
8
- build.onLoad(
9
- { filter: /app\/javascript\/packs\/application.js/ },
10
- async args => {
11
- const fs = require("fs").promises;
12
- const contents = await fs.readFile(args.path, "utf8");
13
- const appendedContents = `${EVENT_SRC_CODE}\n${contents}`;
14
-
15
- return {
16
- contents: isWatch ? appendedContents : contents,
17
- loader: "js",
18
- };
19
- }
20
- );
21
- },
22
- });
23
-
24
- module.exports = { watchPlugin };