catalyst-core-internal 0.0.1-beta.38 → 0.0.1-beta.39

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/AssetsCache.js ADDED
@@ -0,0 +1,114 @@
1
+ class AssetsCache {
2
+ constructor() {
3
+ this.cssCache = new Map()
4
+ this.preloadJSLinkCache = new Map()
5
+ }
6
+
7
+ async cacheCss(key, data) {
8
+ let pageCss = ""
9
+ let listOfCachedAssets = new Map()
10
+ if (Array.isArray(data)) {
11
+ try {
12
+ if (process.env.NODE_ENV === "production") {
13
+ data.map((assetChunk) => {
14
+ const assetPathArr = assetChunk.key.split("/")
15
+ const assetName = assetPathArr[assetPathArr.length - 1]
16
+ const ext = path.extname(assetName)
17
+
18
+ if (ext === ".css") {
19
+ // if css file has not already been cached, add the content of this CSS file in pageCSS
20
+ if (
21
+ !listOfCachedAssets.get(assetName) &&
22
+ !this.cssCache.get(key)?.listOfCachedAssets?.get(assetName)
23
+ ) {
24
+ pageCss += fs.readFileSync(
25
+ path.resolve(
26
+ process.env.src_path,
27
+ `${process.env.BUILD_OUTPUT_PATH}/public`,
28
+ assetName
29
+ )
30
+ )
31
+ listOfCachedAssets.set(assetName, true)
32
+ }
33
+ }
34
+ })
35
+ } else {
36
+ const cssRequests = data.map((file) => {
37
+ const ext = path.extname(file.key)
38
+ if (ext === ".css") {
39
+ return getAssetFromWebpackDevServer(file.key)
40
+ }
41
+ })
42
+ const resolvedCss = await Promise.all(cssRequests)
43
+ resolvedCss.forEach((cssContent) => {
44
+ pageCss += cssContent
45
+ })
46
+ }
47
+ } catch (error) {
48
+ if (process.env.NODE_ENV == "development") {
49
+ console.log(
50
+ "Error While Extracting The Chunk: ",
51
+ path.resolve(process.env.src_path, `${process.env.BUILD_OUTPUT_PATH}/public`)
52
+ )
53
+ }
54
+ }
55
+ }
56
+ // if css cache exists for a route and there are some uncached css, add that css to the cache
57
+ // this will run on subsequent hits and will add css of uncached widgets to the cache
58
+ if (process.cssCache[key]) {
59
+ if (pageCss !== "") {
60
+ let existingListOfCachedAssets = process.cssCache[key].listOfCachedAssets
61
+ const newPageCSS = process.cssCache[key].pageCss + pageCss
62
+ let newListOfCachedAssets = { ...existingListOfCachedAssets, ...listOfCachedAssets }
63
+ process.cssCache[key] = { pageCss: newPageCSS, listOfCachedAssets: newListOfCachedAssets }
64
+ }
65
+ } else {
66
+ // create css cache for a page. This will run on the first hit.
67
+ this.cssCache.set(key, { pageCss, listOfCachedAssets })
68
+ }
69
+ }
70
+
71
+ fetchCss(key) {
72
+ return this.cssCache.get(key).pageCss
73
+ }
74
+
75
+ cachePreloadJSLinks(key, data) {
76
+ let preloadJSLinks = []
77
+ if (Array.isArray(data)) {
78
+ try {
79
+ preloadJSLinks = data.filter((asset) => asset?.props?.as === "script")
80
+ } catch (error) {
81
+ console.dir({
82
+ service_name: `pwa-${process.env.APPLICATION}-node-server`,
83
+ loglevel: "error",
84
+ version: "v2",
85
+ message: "\n \n =====> Error While Extracting The Chunk: \n ",
86
+ traceback: error,
87
+ })
88
+ }
89
+ }
90
+ console.dir({
91
+ service_name: "pwa-node-server",
92
+ loglevel: "info",
93
+ version: "v2",
94
+ message: `\n========= Cached For preloadJSLinkCache: ${key} ============\n`,
95
+ })
96
+ this.preloadJSLinkCache.set(key, preloadJSLinks)
97
+ }
98
+
99
+ fetchPreloadJSLinks(key) {
100
+ return this.preloadJSLinkCache.get(key)
101
+ }
102
+
103
+ async getAssetFromWebpackDevServer(assetPath = "") {
104
+ try {
105
+ if (process.env.NODE_ENV !== "production") {
106
+ const response = await fetch(assetPath)
107
+ const textContent = await response.text()
108
+ return textContent
109
+ }
110
+ } catch (error) {
111
+ console.log("Unable to fetch asset from webpack dev server", error)
112
+ }
113
+ }
114
+ }
package/changelog.md CHANGED
@@ -1,18 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## [0.0.1-beta.6] - 28-06-2024
3
+ ## [0.0.1-beta.7] - 19-10-2024
4
4
 
5
5
  ### Changes
6
6
 
7
- - Moved router, scripts, server and webpack directories present in root directoy to dist folder
8
- - Removed dependency from user defined module aliases (user can change any module alias without breaking catalyst)
9
- - Module aliases defined for catalyst
10
- - Added exports inside package.json for tree shakeable support for logger, caching and ClientRouter.js
11
- - Hidden unnecessary files from published package:
12
- .prettierrc.json
13
- .eslintrc
14
- .eslintignore
15
- /.husky
16
- /.github
17
- commitlint.config.js
18
- tsconfig.json
7
+ - Added postcss-scss parser to parse scss in dev mode.
8
+ - Removed default meta tags if the user chooses to setup their own document.
9
+ - Fix assets being injected in the documnet sent from the server.
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=_default;function _default(){return{visitor:{CallExpression(nodePath,state){if(nodePath.node.callee.name==="require"&&nodePath.node.arguments.length===1){const argument=nodePath.node.arguments[0];if(argument.type==="StringLiteral"){const requiredPath=argument.value;// Normalize the path for comparison
2
+ const normalizedPath=path.join(path.dirname(state.file.opts.filename),requiredPath);const fullPath=`file://${normalizedPath}${path.extname(normalizedPath)?"":".js"}`;if(clientComponentPaths.has(fullPath)){// Replace with placeholder
3
+ argument.value="/* CLIENT_COMPONENT_PLACEHOLDER */";console.log(`Replaced require for client component: ${fullPath}`);}}}}}};}
@@ -0,0 +1,66 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;const{sources}=require("webpack");const RawSource=sources.RawSource;const PLUGIN_NAME="rsc-client-plugin";class ClientDirectivePlugin{constructor(){this.clientFiles=[];}apply(compiler){compiler.hooks.emit.tapAsync(PLUGIN_NAME,(compilation,callback)=>{compilation.modules.forEach(module=>{const source=module._source?.source();if(source?.includes('"use client"')){this.clientFiles.push(module.resource);const chunkName="rsc-"+module.resource.split("/").pop();compilation.emitAsset(chunkName,new RawSource(source));}});console.log("Client Files:",this.clientFiles);callback();});}}var _default=exports.default=ClientDirectivePlugin;// const acorn = require("acorn")
2
+ // const path = require("path")
3
+ // class UseClientChunkPlugin {
4
+ // constructor() {
5
+ // this.clientFiles = new Map()
6
+ // }
7
+ // apply(compiler) {
8
+ // compiler.hooks.beforeCompile.tap("UseClientChunkPlugin", () => {
9
+ // this.clientFiles.clear()
10
+ // })
11
+ // compiler.hooks.normalModuleFactory.tap("UseClientChunkPlugin", (normalModuleFactory) => {
12
+ // normalModuleFactory.hooks.parser.for("javascript/auto").tap("UseClientChunkPlugin", (parser) => {
13
+ // parser.hooks.program.tap("UseClientChunkPlugin", (ast, { resource }) => {
14
+ // if (this.hasUseClientDirective(ast)) {
15
+ // this.clientFiles.set(resource, null)
16
+ // }
17
+ // })
18
+ // })
19
+ // })
20
+ // compiler.hooks.thisCompilation.tap("UseClientChunkPlugin", (compilation) => {
21
+ // compilation.hooks.optimizeChunks.tap("UseClientChunkPlugin", (chunks) => {
22
+ // const clientChunk = compilation.addChunk("client")
23
+ // chunks.forEach((chunk) => {
24
+ // chunk.modulesIterable.forEach((module) => {
25
+ // if (this.clientFiles.has(module.resource)) {
26
+ // compilation.moveModulesBetweenChunks([module], chunk, clientChunk)
27
+ // this.clientFiles.set(module.resource, clientChunk.id)
28
+ // }
29
+ // })
30
+ // })
31
+ // })
32
+ // compilation.hooks.afterOptimizeChunks.tap("UseClientChunkPlugin", (chunks) => {
33
+ // chunks.forEach((chunk) => {
34
+ // chunk.modulesIterable.forEach((module) => {
35
+ // if (module.dependencies) {
36
+ // module.dependencies.forEach((dependency) => {
37
+ // if (dependency.module && this.clientFiles.has(dependency.module.resource)) {
38
+ // const clientChunkId = this.clientFiles.get(dependency.module.resource)
39
+ // if (clientChunkId !== null) {
40
+ // dependency.weak = true
41
+ // chunk.addChunkId(clientChunkId)
42
+ // }
43
+ // }
44
+ // })
45
+ // }
46
+ // })
47
+ // })
48
+ // })
49
+ // compilation.hooks.afterOptimizeChunks.tap("UseClientChunkPlugin", () => {
50
+ // console.log('Files with "use client" directive:')
51
+ // this.clientFiles.forEach((chunkId, file) => {
52
+ // console.log(`${path.basename(file)}: ${chunkId}`)
53
+ // })
54
+ // })
55
+ // })
56
+ // }
57
+ // hasUseClientDirective(ast) {
58
+ // for (const node of ast.body) {
59
+ // if (node.type === "ExpressionStatement" && node.directive === "use client") {
60
+ // return true
61
+ // }
62
+ // }
63
+ // return false
64
+ // }
65
+ // }
66
+ // module.exports = UseClientChunkPlugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "catalyst-core-internal",
3
- "version": "0.0.1-beta.38",
3
+ "version": "0.0.1-beta.39",
4
4
  "main": "index.js",
5
5
  "description": "Web framework that provides great performance out of the box",
6
6
  "bin": {
@@ -48,7 +48,7 @@
48
48
  "@loadable/webpack-plugin": "^5.15.2",
49
49
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
50
50
  "@svgr/webpack": "^8.1.0",
51
- "@tata1mg/router": "0.0.1-beta.2",
51
+ "@tata1mg/router": "0.0.1-beta.4",
52
52
  "app-root-path": "^3.1.0",
53
53
  "babel-loader": "^9.1.3",
54
54
  "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
@@ -109,4 +109,4 @@
109
109
  "prettier . --write"
110
110
  ]
111
111
  }
112
- }
112
+ }
package/run.sh ADDED
@@ -0,0 +1,4 @@
1
+ npm run prepare
2
+ rm -rf ../1mg_web/mweb/node_modules/catalyst-core-internal/dist
3
+ mv dist ../1mg_web/mweb/node_modules/catalyst-core-internal
4
+
package/caching.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});var _apiCaching=require("@tata1mg/api-caching");Object.keys(_apiCaching).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_apiCaching[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _apiCaching[key];}});});
package/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});var _index=require("./server/renderer/document/index");Object.keys(_index).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_index[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _index[key];}});});
package/logger.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";const winston=require("winston");const DailyRotateFile=require("winston-daily-rotate-file");const pc=require("picocolors");const{createLogger,format,transports}=winston;/**
2
- * @description Logger library with rotational strategy. Creates a logs folder in root.
3
- * With debug, error and info log directories with their respective log files.
4
- *
5
- * @format Logstash with timestamp
6
- * @param config { @enableDebugLogs: Bool // default: true }
7
- * @returns loggerInstance
8
- *
9
- */const configureLogger=(config={})=>{const{enableDebugLogs=true,enableFileLogging=true,enableConsoleLogging=true}=config;const consoleTransport=new transports.Console({level:"debug"});const fileTransport=(type="info")=>{return new DailyRotateFile({filename:`${process.env.src_path}/logs/${type}/%DATE%.${type}.log`,datePattern:"YYYY-MM-DD",maxFiles:"3d",// Logs will be removed after 2days,
10
- loglevel:type,level:type});};const infoLogger=createLogger({format:format.combine(format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),format.json()),defaultMeta:{loglevel:"info"}});const debugLogger=createLogger({format:format.combine(format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),format.json()),defaultMeta:{loglevel:"debug"}});const errorLogger=createLogger({format:format.combine(format.timestamp({format:"YYYY-MM-DD HH:mm:ss"}),format.json()),defaultMeta:{loglevel:"error"}});if(enableConsoleLogging&&JSON.parse(enableConsoleLogging)){infoLogger.add(consoleTransport);debugLogger.add(consoleTransport);errorLogger.add(consoleTransport);}if(enableFileLogging&&JSON.parse(enableFileLogging)){infoLogger.add(fileTransport("info"));debugLogger.add(fileTransport("debug"));errorLogger.add(fileTransport("error"));}const Logger={debug:()=>{},error:msg=>{console.log(pc.red(pc.bold("ERROR: "+JSON.stringify(msg))));errorLogger.error(msg);},info:msg=>{console.log(pc.green(pc.bold("INFO: "+JSON.stringify(msg))));infoLogger.info(msg);}};if(enableDebugLogs&&JSON.parse(enableDebugLogs)){Logger.debug=msg=>{console.log(pc.yellow(pc.bold("DEBUG: "+JSON.stringify(msg))));debugLogger.debug(msg);};}if(global)global.logger=Logger;return Logger;};module.exports={configureLogger};
package/router.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});var _router=require("@tata1mg/router");Object.keys(_router).forEach(function(key){if(key==="default"||key==="__esModule")return;if(key in exports&&exports[key]===_router[key])return;Object.defineProperty(exports,key,{enumerable:true,get:function(){return _router[key];}});});