@rws-framework/client 2.15.0 → 2.15.2

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.
@@ -3,8 +3,8 @@ const chalk = require('chalk');
3
3
  const path = require('path');
4
4
  const tools = require('../../../_tools');
5
5
 
6
- module.exports = async (swPath) => {
7
- const swFilePath = path.resolve(process.cwd(), swPath);
6
+ module.exports = async (appRoot, swPath) => {
7
+ const swFilePath = path.resolve(appRoot, swPath);
8
8
 
9
9
  if(swPath.indexOf('.ts') === -1 || !fs.existsSync(swFilePath)){
10
10
  throw new Error('[RWS] Service worker TS file does not exist');
@@ -15,7 +15,7 @@ module.exports = async function(content) {
15
15
 
16
16
  if(saveFile){
17
17
  try {
18
- const codeData = await plugin.compileScssCode(content, path.dirname(filePath), null, filePath, !isDev);
18
+ const codeData = await plugin.compileScssCode(content, path.dirname(filePath));
19
19
 
20
20
  const code = codeData.code;
21
21
  const deps = codeData.dependencies;
@@ -61,7 +61,7 @@ module.exports = async function(content) {
61
61
  try {
62
62
  if(tagName){
63
63
  const [template, htmlFastImports, templateExists] = await LoadersHelper.getTemplate(filePath, this.addDependency, templateName, isDev);
64
- const styles = await LoadersHelper.getStyles(filePath, this.query?.rwsWorkspaceDir, this.addDependency, templateExists, stylesPath, isDev);
64
+ const styles = await LoadersHelper.getStyles(filePath, this.query?.rwsWorkspaceDir, this.query?.appRootDir,this.addDependency, templateExists, stylesPath, isDev);
65
65
 
66
66
  if(className){
67
67
  const replacedViewDecoratorContent = decoratorExtract.replacedDecorator;
@@ -18,11 +18,12 @@ const { executeRWSStartActions, timingActions, devActions } = require('../../cfg
18
18
  const { webpackDevServer } = require('../../cfg/build_steps/webpack/_dev_servers');
19
19
  const { RWS_WEBPACK_PLUGINS_BAG, addStartPlugins } = require('../../cfg/build_steps/webpack/_plugins');
20
20
 
21
- const _MAIN_PACKAGE = rwsPath.findRootWorkspacePath(process.cwd());
22
21
 
23
22
  // #SECTION INIT OPTIONS
24
23
 
25
- const RWSWebpackWrapper = async (rwsFrontendConfig, _packageDir) => {
24
+ const RWSWebpackWrapper = async (appRoot, rwsFrontendConfig, _packageDir) => {
25
+ const _MAIN_PACKAGE = rwsPath.findRootWorkspacePath(appRoot);
26
+
26
27
  const {
27
28
  executionDir,
28
29
  isWatcher,
@@ -108,12 +109,13 @@ const RWSWebpackWrapper = async (rwsFrontendConfig, _packageDir) => {
108
109
  actions: WEBPACK_AFTER_ACTIONS,
109
110
  error_actions: WEBPACK_AFTER_ERROR_ACTIONS,
110
111
  dev: isDev,
111
- devDebug
112
+ devDebug,
113
+ appRoot
112
114
  }));
113
115
  }
114
116
 
115
117
  // #SECTION RWS WEBPACK BUILD
116
- const cfgExport = createWebpackConfig(
118
+ const cfgExport = createWebpackConfig({
117
119
  executionDir,
118
120
  _packageDir,
119
121
  isDev,
@@ -127,11 +129,12 @@ const RWSWebpackWrapper = async (rwsFrontendConfig, _packageDir) => {
127
129
  modules_setup,
128
130
  aliases,
129
131
  tsConfig,
130
- RWS_WEBPACK_PLUGINS_BAG.getPlugins(),
132
+ WEBPACK_PLUGINS: RWS_WEBPACK_PLUGINS_BAG.getPlugins(),
131
133
  rwsExternals,
132
134
  devExternalsVars,
133
- rwsFrontendConfig.entrypoint
134
- );
135
+ appRootDir: appRoot,
136
+ entrypoint: rwsFrontendConfig.entrypoint
137
+ });
135
138
 
136
139
  if (optimConfig) {
137
140
  // setup production config if it got created above
@@ -16,10 +16,11 @@ class RWSScssPlugin {
16
16
  rwsWorkspaceDir = null;
17
17
 
18
18
  constructor(params = {
19
+ appRootDir: null,
19
20
  rwsWorkspaceDir: null,
20
21
  autoCompile: []
21
22
  }) {
22
- this.node_modules_dir = (fileDir) => path.relative(fileDir, _tools.findRootWorkspacePath(process.cwd() + '/node_modules'))
23
+ this.node_modules_dir = (fileDir) => path.relative(fileDir, path.join(this.getRWSRootDir(), '/node_modules'))
23
24
  _scss_import = _scss_import_builder(this);
24
25
  _scss_fs = _scss_fs_builder(this);
25
26
  _scss_compiler = _scss_compiler_builder(this);
@@ -29,6 +30,7 @@ class RWSScssPlugin {
29
30
  }
30
31
 
31
32
  this.rwsWorkspaceDir = params.rwsWorkspaceDir;
33
+ this.appRootDir = params.appRootDir;
32
34
 
33
35
  if (!!params.autoCompile && params.autoCompile.length > 0) {
34
36
  this.autoCompile = params.autoCompile;
@@ -47,16 +49,16 @@ class RWSScssPlugin {
47
49
  }
48
50
 
49
51
  async compileFile(scssPath) {
50
- scssPath = _scss_import.processImportPath(scssPath, this.rwsWorkspaceDir, path.dirname(scssPath))
52
+ scssPath = _scss_import.processImportPath(scssPath, this.getRWSWorkspaceDir(), this.getRWSRootDir(),path.dirname(scssPath))
51
53
 
52
54
 
53
- let scssCode = _scss_fs.getCodeFromFile(scssPath, this.rwsWorkspaceDir);
55
+ let scssCode = _scss_fs.getCodeFromFile(scssPath, this.getRWSWorkspaceDir());
54
56
 
55
- return await _scss_compiler.compileScssCode(scssCode, path.dirname(scssPath), this.rwsWorkspaceDir);
57
+ return await _scss_compiler.compileScssCode(scssCode, path.dirname(scssPath), this.getRWSWorkspaceDir(), this.getRWSRootDir());
56
58
  }
57
59
 
58
60
  async compileScssCode(scssCode, scssPath){
59
- return await _scss_compiler.compileScssCode(scssCode, scssPath, this.rwsWorkspaceDir);
61
+ return await _scss_compiler.compileScssCode(scssCode, scssPath, this.getRWSWorkspaceDir(), this.getRWSRootDir());
60
62
  }
61
63
 
62
64
  writeCssFile(scssFilePath, cssContent){
@@ -66,6 +68,10 @@ class RWSScssPlugin {
66
68
  getRWSWorkspaceDir() {
67
69
  return this.rwsWorkspaceDir;
68
70
  }
71
+
72
+ getRWSRootDir() {
73
+ return this.rwsWorkspaceDir;
74
+ }
69
75
  }
70
76
 
71
77
  module.exports = RWSScssPlugin;
@@ -3,7 +3,7 @@ const rwsAfterSW = require('./after/sw');
3
3
  const deepmerge = require('deepmerge');
4
4
 
5
5
 
6
- const _DEFAULT_CONFIG = { actions: [], executionDir: process.cwd(), packageDir: process.cwd(), dev: false, devDebug: null }
6
+ const _DEFAULT_CONFIG = { actions: [], executionDir: null, packageDir: null, dev: false, devDebug: null }
7
7
 
8
8
  const _DEFAULT_ACTION = {
9
9
  type: 'copy',
@@ -113,7 +113,7 @@ class RWSWebpackPlugin {
113
113
  case 'service_worker': {
114
114
 
115
115
  const serviceWorkerPath = typeof action === 'function' ? await action() : action;
116
- await rwsAfterSW(serviceWorkerPath);
116
+ await rwsAfterSW(this.config.appRoot, serviceWorkerPath);
117
117
  return;
118
118
  };
119
119
 
@@ -9,10 +9,10 @@ let _scss_fonts = null;
9
9
  const _scss_import_builder = require('./_import');
10
10
  let _scss_import = null;
11
11
 
12
- function compileScssCode(scssCode, fileRootDir, rwsWorkspaceDir) {
12
+ function compileScssCode(scssCode, fileRootDir, rwsWorkspaceDir, appRoot) {
13
13
  _scss_fonts = _scss_fonts_builder(this);
14
14
  _scss_import = _scss_import_builder(this);
15
- const [scssImports] = _scss_import.extractScssImports(scssCode, rwsWorkspaceDir, fileRootDir);
15
+ const [scssImports] = _scss_import.extractScssImports(scssCode, rwsWorkspaceDir, appRoot, fileRootDir);
16
16
 
17
17
  const dependencies = scssImports.map((item) => item[2]);
18
18
 
@@ -38,7 +38,7 @@ function compileScssCode(scssCode, fileRootDir, rwsWorkspaceDir) {
38
38
  const result = sass.compileString(scssCode, { loadPaths: [fileRootDir]});
39
39
 
40
40
  let compiledCode = result.css.toString();
41
- compiledCode = _scss_fonts.replaceFontUrlWithBase64(compiledCode, rwsWorkspaceDir);
41
+ compiledCode = _scss_fonts.replaceFontUrlWithBase64(compiledCode, rwsWorkspaceDir, appRoot);
42
42
  compiledCode = replaceEmojisWithQuestionMark(compiledCode, fileRootDir);
43
43
  return { code: compiledCode, dependencies};
44
44
  } catch (err) {
@@ -44,7 +44,7 @@ function convertFontToBase64(fontPath) {
44
44
  return fs.readFileSync(fontPath, { encoding: 'base64' });
45
45
  }
46
46
 
47
- function replaceFontUrlWithBase64(cssContent, rwsWorkspaceDir) {
47
+ function replaceFontUrlWithBase64(cssContent, rwsWorkspaceDir, appRoot) {
48
48
  const fontFaceRegex = /@font-face\s*\{[^}]*\}/g;
49
49
  let fontFaces = [...cssContent.matchAll(fontFaceRegex)];
50
50
  _scss_import = _scss_import_builder(this);
@@ -58,7 +58,7 @@ function replaceFontUrlWithBase64(cssContent, rwsWorkspaceDir) {
58
58
 
59
59
  while ((match = urlRegex.exec(fontFaceContent)) !== null) {
60
60
  // Create a promise to convert each font to Base64 and replace in CSS
61
- const base64 = convertFontToBase64(_scss_import.processImportPath(match[2], rwsWorkspaceDir, null, true));
61
+ const base64 = convertFontToBase64(_scss_import.processImportPath(match[2], rwsWorkspaceDir, appRoot, null, true));
62
62
  const base64Font = `data:font/woff2;base64,${base64}`;
63
63
 
64
64
  modifiedFontFaceContent = modifiedFontFaceContent.replace(match[2], base64Font);
@@ -47,13 +47,13 @@ function readSCSSFilesFromDirectory(dirPath) {
47
47
  };
48
48
 
49
49
 
50
- function getCodeFromFile(filePath, rwsWorkspaceDir) {
50
+ function getCodeFromFile(filePath, rwsWorkspaceDir, appRootDir) {
51
51
  filePath = filePath.replace('//', '/');
52
52
  const _scss_import_builder = require('./_import');
53
53
  _scss_import = _scss_import_builder(this);
54
54
 
55
55
  if (!fs.existsSync(filePath)) {
56
- const processedImportPath = _scss_import.processImportPath(filePath, rwsWorkspaceDir, path.dirname(filePath));
56
+ const processedImportPath = _scss_import.processImportPath(filePath, rwsWorkspaceDir, appRootDir, path.dirname(filePath));
57
57
 
58
58
  if (!fs.existsSync(processedImportPath)) {
59
59
  throw new Error(`SCSS loader: File path "${filePath}" was not found.`);
@@ -7,14 +7,15 @@ const path = require('path');
7
7
  const CSS_IMPORT_REGEX = /^(?!.*\/\/)(?!.*\/\*).*@import\s+['"]((?![^'"]*:[^'"]*).+?)['"];?/gm;
8
8
  const SCSS_USE_REGEX = /^(?!.*\/\/)(?!.*\/\*).*@use\s+['"]?([^'"\s]+)['"]?;?/gm;
9
9
 
10
- const WORKSPACE_ROOT = rwsPath.findPackageDir(process.cwd());
11
10
 
12
- function processImportPath(importPath, rwsWorkspaceDir, fileRootDir = null, noext = false) {
11
+ function processImportPath(importPath, rwsWorkspaceDir, appRootDir, fileRootDir = null, noext = false) {
12
+
13
13
  _scss_fs = _scss_fs_builder(this);
14
14
  const workspaceDir = this.getRWSWorkspaceDir ? this.getRWSWorkspaceDir() : rwsWorkspaceDir;
15
+ const appRoot = this.getRWSWorkspaceDir ? this.getRWSRootDir() : appRootDir;
15
16
 
16
17
  if (importPath.split('')[0] === '~') {
17
- return fillSCSSExt(replaceWithNodeModules(importPath, null, true), noext);
18
+ return fillSCSSExt(replaceWithNodeModules(importPath, appRootDir, null, true), noext);
18
19
  }
19
20
 
20
21
  if (importPath.indexOf('@rws-mixins') === 0) {
@@ -22,7 +23,7 @@ function processImportPath(importPath, rwsWorkspaceDir, fileRootDir = null, noex
22
23
  }
23
24
 
24
25
  if (importPath.indexOf('@cwd') === 0) {
25
- return fillSCSSExt(path.join(process.cwd(), importPath.slice(4)), noext);
26
+ return fillSCSSExt(path.join(this.appRootDir, importPath.slice(4)), noext);
26
27
  }
27
28
 
28
29
  if (importPath.split('')[0] === '/') {
@@ -110,7 +111,7 @@ function fillSCSSExt(scssPath, noext = false) {
110
111
  return ext;
111
112
  }
112
113
 
113
- function extractScssImports(fileContent, rwsWorkspaceDir, importRootPath) {
114
+ function extractScssImports(fileContent, rwsWorkspaceDir, appRootDir, importRootPath) {
114
115
  _scss_fs = _scss_fs_builder(this);
115
116
  let match;
116
117
  const imports = [];
@@ -123,9 +124,9 @@ function extractScssImports(fileContent, rwsWorkspaceDir, importRootPath) {
123
124
  importRootPath = path.dirname(importRootPath);
124
125
  }
125
126
 
126
- const processedImportPath = processImportPath(importPath, rwsWorkspaceDir, importRootPath);
127
+ const processedImportPath = processImportPath(importPath, rwsWorkspaceDir, appRootDir, importRootPath);
127
128
 
128
- imports.push([processedImportPath, importLine, path.resolve(processedImportPath), rwsWorkspaceDir]);
129
+ imports.push([processedImportPath, importLine, path.resolve(processedImportPath), rwsWorkspaceDir, appRootDir]);
129
130
  }
130
131
 
131
132
  return [imports, fileContent];
@@ -154,9 +155,9 @@ function detectImports(code) {
154
155
  return CSS_IMPORT_REGEX.test(code);
155
156
  }
156
157
 
157
- function replaceWithNodeModules(input, fileDir = null, absolute = false, token = '~') {
158
+ function replaceWithNodeModules(input, appRootDir, fileDir = null, absolute = false, token = '~') {
158
159
  _scss_fs = _scss_fs_builder(this);
159
- return input.replace(token, absolute ? `${path.resolve(WORKSPACE_ROOT, 'node_modules')}/` : this.node_modules_dir(fileDir ? fileDir : process.cwd()));
160
+ return input.replace(token, absolute ? `${path.resolve(appRootDir, 'node_modules')}/` : this.node_modules_dir(fileDir ? fileDir : appRootDir));
160
161
  }
161
162
 
162
163
  function processImports(imports, fileRootDir, rwsWorkspaceDir, importStorage = {}, sub = false) {
@@ -180,12 +181,13 @@ function processImports(imports, fileRootDir, rwsWorkspaceDir, importStorage = {
180
181
  imports.forEach(importData => {
181
182
  const originalImportPath = importData[0];
182
183
  const workspaceDir = this.getRWSWorkspaceDir ? this.getRWSWorkspaceDir() : importData[3];
184
+ const appRoot = this.getRWSWorkspaceDir ? this.getRWSRootDir() : importData[4];
183
185
 
184
- let importPath = processImportPath(originalImportPath, workspaceDir, fileRootDir);
186
+ let importPath = processImportPath(originalImportPath, workspaceDir, appRoot, fileRootDir);
185
187
 
186
188
  let replacedScssContent = getStorage(importPath, _scss_fs.getCodeFromFile(importPath, workspaceDir).replace(/\/\*[\s\S]*?\*\//g, ''));
187
189
 
188
- const recursiveImports = extractScssImports(replacedScssContent, workspaceDir, importPath)[0];
190
+ const recursiveImports = extractScssImports(replacedScssContent, workspaceDir, appRoot, importPath)[0];
189
191
 
190
192
  if (recursiveImports.length) {
191
193
  replacedScssContent = replaceImports(processImports(recursiveImports, path.dirname(importPath), workspaceDir, importStorage, true), replacedScssContent);
@@ -7,7 +7,7 @@ const { _DEFAULT_CONFIG } = require('../../_default.cfg');
7
7
 
8
8
  async function getBuildConfig(rwsFrontBuildConfig, _packageDir){
9
9
  const BuildConfigurator = new RWSConfigBuilder(path.join(rwsPath.findPackageDir(process.cwd()), '.rws.json'), {..._DEFAULT_CONFIG, ...rwsFrontBuildConfig});
10
- const executionDir = rwsPath.relativize(BuildConfigurator.get('executionDir') || rwsFrontBuildConfig.executionDir || process.cwd(), _packageDir);
10
+ const executionDir = rwsPath.relativize(BuildConfigurator.get('executionDir') || rwsFrontBuildConfig.executionDir || process.env.RWS_APP_ROOT || process.cwd(), _packageDir);
11
11
  const isWatcher = process.argv.includes('--watch') || false;
12
12
 
13
13
  const isDev = isWatcher ? true : (BuildConfigurator.get('dev', rwsFrontBuildConfig.dev) || false);
@@ -10,7 +10,7 @@ const chalk = require('chalk');
10
10
  const { timingCounterStart, timingCounterStop } = require('./_timing');
11
11
  const { rwsRuntimeHelper, rwsPath } = require('@rws-framework/console');
12
12
 
13
- function getRWSLoaders(packageDir, executionDir, tsConfig, entrypoint) {
13
+ function getRWSLoaders(packageDir, executionDir, tsConfig, appRootDir, entrypoint) {
14
14
  const scssLoader = path.join(packageDir, 'builder/webpack/loaders/rws_fast_scss_loader.js');
15
15
  const tsLoader = path.join(packageDir, 'builder/webpack/loaders/rws_fast_ts_loader.js');
16
16
  const htmlLoader = path.join(packageDir, 'builder/webpack/loaders/rws_fast_html_loader.js');
@@ -30,27 +30,27 @@ function getRWSLoaders(packageDir, executionDir, tsConfig, entrypoint) {
30
30
  {
31
31
  loader: 'ts-loader',
32
32
  options: {
33
+ ...tsConfig,
33
34
  transpileOnly: false,
34
- logLevel: "info", // Show more detailed errors
35
+ logLevel: "info",
35
36
  logInfoToStdOut: true,
36
37
  context: executionDir,
37
38
  errorFormatter: (message, colors) => {
38
39
  const messageText = message.message || message;
39
40
  return `\nTS Error: ${messageText}\n`;
40
- },
41
- ...tsConfig
41
+ },
42
42
  }
43
43
  },
44
44
  {
45
45
  loader: tsLoader,
46
46
  options: {
47
- rwsWorkspaceDir: executionDir
47
+ rwsWorkspaceDir: executionDir,
48
+ appRootDir
48
49
  }
49
50
  }
50
51
  ],
51
52
  include: [
52
53
  path.resolve(executionDir, 'src'),
53
- path.resolve(executionDir, '@dev', 'client', 'src'),
54
54
  path.resolve(packageDir, 'src'),
55
55
  path.resolve(packageDir, 'foundation', 'rws-foundation.d.ts')
56
56
  ],
@@ -68,6 +68,7 @@ function getRWSLoaders(packageDir, executionDir, tsConfig, entrypoint) {
68
68
  },
69
69
  ];
70
70
 
71
+
71
72
  return loaders;
72
73
  }
73
74
 
@@ -180,7 +181,7 @@ function extractRWSViewArgs(content, noReplace = false) {
180
181
  }
181
182
  }
182
183
 
183
- async function getStyles(filePath, rwsWorkspaceDir, addDependency, templateExists, stylesPath = null, isDev = false) {
184
+ async function getStyles(filePath, rwsWorkspaceDir, appRootDir, addDependency, templateExists, stylesPath = null, isDev = false) {
184
185
  if(!stylesPath){
185
186
  stylesPath = 'styles/layout.scss';
186
187
  }
@@ -191,7 +192,7 @@ async function getStyles(filePath, rwsWorkspaceDir, addDependency, templateExist
191
192
  if (fs.existsSync(stylesFilePath)) {
192
193
  const scsscontent = fs.readFileSync(stylesFilePath, 'utf-8');
193
194
  timingCounterStart();
194
- const plugin = new RWSCssPlugin({ rwsWorkspaceDir });
195
+ const plugin = new RWSCssPlugin({ rwsWorkspaceDir, appRootDir });
195
196
  const codeData = await plugin.compileScssCode(scsscontent, path.join(path.dirname(filePath), 'styles'), null, filePath, !isDev);
196
197
  const elapsed = timingCounterStop();
197
198
  let currentTimingList = rwsRuntimeHelper.getRWSVar('_timer_css');
@@ -1,7 +1,7 @@
1
1
  const { getRWSLoaders } = require('./_loaders');
2
2
  const path = require('path');
3
3
 
4
- function createWebpackConfig(
4
+ function createWebpackConfig({
5
5
  executionDir,
6
6
  _packageDir,
7
7
  isDev,
@@ -18,8 +18,9 @@ function createWebpackConfig(
18
18
  WEBPACK_PLUGINS,
19
19
  rwsExternals,
20
20
  devExternalsVars,
21
+ appRootDir,
21
22
  entrypoint
22
- ) {
23
+ }) {
23
24
  return {
24
25
  context: executionDir,
25
26
  entry: {
@@ -41,7 +42,7 @@ function createWebpackConfig(
41
42
  }
42
43
  },
43
44
  module: {
44
- rules: getRWSLoaders(_packageDir, executionDir, tsConfig, entrypoint),
45
+ rules: getRWSLoaders(_packageDir, executionDir, tsConfig, appRootDir, entrypoint),
45
46
  },
46
47
  plugins: WEBPACK_PLUGINS,
47
48
  externals: rwsExternals(_packageDir, executionDir, modules_setup, automatedChunks, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rws-framework/client",
3
3
  "private": false,
4
- "version": "2.15.0",
4
+ "version": "2.15.2",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
7
7
  "docs": "typedoc --tsconfig ./tsconfig.json"
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@microsoft/fast-element": "^1.12.0",
30
30
  "@microsoft/fast-foundation": "^2.46.2",
31
- "@rws-framework/console": "^0.3.15",
31
+ "@rws-framework/console": "*",
32
32
  "@types/moment": "^2.13.0",
33
33
  "deepmerge": "^4.3.1",
34
34
  "dragula": "^3.7.3",
package/tsconfig.json CHANGED
@@ -7,8 +7,7 @@
7
7
  "moduleResolution": "node",
8
8
  "strict": true,
9
9
  "esModuleInterop": true,
10
- "sourceMap": true,
11
- "outDir": "dist",
10
+ "sourceMap": true,
12
11
  "strictNullChecks": false,
13
12
  "allowSyntheticDefaultImports": true,
14
13
  "lib": [