@wavemaker/rn-codegen 11.15.5-rc.647771 → 11.15.5-rc.647878

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.
Files changed (147) hide show
  1. package/command.js +94 -262
  2. package/command.js.map +1 -1
  3. package/index.js +131 -125
  4. package/index.js.map +1 -1
  5. package/npm-shrinkwrap.json +575 -556
  6. package/package-lock.json +575 -556
  7. package/package.json +14 -10
  8. package/scripts/check-deps-compat.js +579 -0
  9. package/src/app.generator.js +438 -159
  10. package/src/app.generator.js.map +1 -1
  11. package/src/increment-builder.js +2 -1
  12. package/src/increment-builder.js.map +1 -1
  13. package/src/pipeline/build-common.js +63 -0
  14. package/src/pipeline/build-common.js.map +1 -0
  15. package/src/pipeline/build-pipeline.js +169 -0
  16. package/src/pipeline/build-pipeline.js.map +1 -0
  17. package/src/pipeline/generation-store.js +309 -0
  18. package/src/pipeline/generation-store.js.map +1 -0
  19. package/src/pipeline/shared-node-modules.js +934 -0
  20. package/src/pipeline/shared-node-modules.js.map +1 -0
  21. package/src/pipeline/web-preview-templates.js +80 -0
  22. package/src/pipeline/web-preview-templates.js.map +1 -0
  23. package/src/pipeline/working-set.js +103 -0
  24. package/src/pipeline/working-set.js.map +1 -0
  25. package/src/profiles/legacy-web-preview.profile.js +15 -0
  26. package/src/profiles/legacy-web-preview.profile.js.map +1 -0
  27. package/src/project.service.js +14 -0
  28. package/src/project.service.js.map +1 -1
  29. package/src/templates/app.template +74 -2
  30. package/src/templates/babel.config.js.template +3 -6
  31. package/src/templates/bootstrap.template +10 -1
  32. package/src/templates/component/component.template +1 -0
  33. package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/date.less +8 -1
  34. package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/datetime.less +8 -1
  35. package/src/templates/foundation-theme/build/android/wavemaker/components/input/epoch/time.less +8 -1
  36. package/src/templates/foundation-theme/build/android/wavemaker/components/input/number.less +14 -0
  37. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/basic/button.less +2 -2
  38. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/checkboxset.less +1 -0
  39. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/chips.less +12 -0
  40. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/input/radioset.less +1 -1
  41. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/studio/input/currency.less +6 -2
  42. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/tokens.light.css +3 -2
  43. package/src/templates/foundation-theme/build/android/wavemaker/design-tokens/variables/button.variant.less +2 -2
  44. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/date.less +8 -1
  45. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/datetime.less +8 -1
  46. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/epoch/time.less +8 -1
  47. package/src/templates/foundation-theme/build/ios/wavemaker/components/input/number.less +14 -0
  48. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/basic/button.less +2 -2
  49. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/checkboxset.less +1 -0
  50. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/chips.less +12 -0
  51. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/input/radioset.less +1 -1
  52. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/studio/input/currency.less +6 -2
  53. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/tokens.light.css +3 -2
  54. package/src/templates/foundation-theme/build/ios/wavemaker/design-tokens/variables/button.variant.less +2 -2
  55. package/src/templates/foundation-theme/dist/android/style.css +5 -4
  56. package/src/templates/foundation-theme/dist/android/style.js +22 -9
  57. package/src/templates/foundation-theme/dist/android/tokens.js +3 -2
  58. package/src/templates/foundation-theme/dist/ios/style.css +5 -4
  59. package/src/templates/foundation-theme/dist/ios/style.js +22 -9
  60. package/src/templates/foundation-theme/dist/ios/tokens.js +3 -2
  61. package/src/templates/foundation-theme/wavemaker/components/input/epoch/date.less +8 -1
  62. package/src/templates/foundation-theme/wavemaker/components/input/epoch/datetime.less +8 -1
  63. package/src/templates/foundation-theme/wavemaker/components/input/epoch/time.less +8 -1
  64. package/src/templates/foundation-theme/wavemaker/components/input/number.less +14 -0
  65. package/src/templates/foundation-theme/wavemaker/design-tokens/basic/button.less +2 -2
  66. package/src/templates/foundation-theme/wavemaker/design-tokens/input/checkboxset.less +1 -0
  67. package/src/templates/foundation-theme/wavemaker/design-tokens/input/chips.less +12 -0
  68. package/src/templates/foundation-theme/wavemaker/design-tokens/input/radioset.less +1 -1
  69. package/src/templates/foundation-theme/wavemaker/design-tokens/studio/input/currency.less +6 -2
  70. package/src/templates/foundation-theme/wavemaker/design-tokens/tokens.light.css +3 -2
  71. package/src/templates/foundation-theme/wavemaker/design-tokens/variables/button.variant.less +2 -2
  72. package/src/templates/package.web.json +17 -7
  73. package/src/templates/page-stub.template +27 -0
  74. package/src/templates/project/.npmrc +1 -0
  75. package/src/templates/project/app.json +2 -1
  76. package/src/templates/project/esbuild/esbuild.script.js +56 -16
  77. package/src/templates/project/metro/container-limits.js +195 -0
  78. package/src/templates/project/metro/metro.script.js +850 -0
  79. package/src/templates/project/metro/module-path.js +237 -0
  80. package/src/templates/project/metro/split.serializer.js +184 -0
  81. package/src/templates/project/metro/split.static.js +633 -0
  82. package/src/templates/project/metro/stable-module-ids.js +54 -0
  83. package/src/templates/project/metro/vendor-cache.js +475 -0
  84. package/src/templates/project/metro/wm-boundary.js +150 -0
  85. package/src/templates/project/metro/wm-crawl-override.js +161 -0
  86. package/src/templates/project/metro/wm-fastbuild.js +196 -0
  87. package/src/templates/project/metro/wm-live-reload.js +482 -0
  88. package/src/templates/project/metro/wm-metro-adapter.js +25 -0
  89. package/src/templates/project/metro/wm-prebuilt.js +31 -0
  90. package/src/templates/project/metro.config.js +13 -2
  91. package/src/templates/project/package-lock.json +15308 -0
  92. package/src/templates/project/package.json +14 -6
  93. package/src/templates/project/patch-utils.js +331 -0
  94. package/src/templates/project/plugins/expo-pull-to-refresh/android/build.gradle +15 -0
  95. package/src/templates/project/plugins/expo-pull-to-refresh/android/src/main/java/expo/modules/pulltorefresh/ExpoPullToRefreshModule.kt +21 -0
  96. package/src/templates/project/plugins/expo-pull-to-refresh/android/src/main/java/expo/modules/pulltorefresh/ExpoPullToRefreshView.kt +221 -0
  97. package/src/templates/project/plugins/expo-pull-to-refresh/expo-module.config.json +16 -0
  98. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefresh.podspec +24 -0
  99. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefreshControlModule.swift +17 -0
  100. package/src/templates/project/plugins/expo-pull-to-refresh/ios/ExpoPullToRefreshControlView.swift +92 -0
  101. package/src/templates/project/plugins/expo-pull-to-refresh/package.json +15 -0
  102. package/src/templates/project/scripts/wm-babel.transform.plugin.js +11 -1
  103. package/src/templates/project/wavepulse/rn2css.json +5 -0
  104. package/src/theme/app-override-css.generator.js +10 -4
  105. package/src/theme/app-override-css.generator.js.map +1 -1
  106. package/src/theme/components/input/epoch/datetime.styledef.js +5 -0
  107. package/src/theme/components/input/epoch/datetime.styledef.js.map +1 -1
  108. package/src/theme/components/input/number.styledef.js +10 -0
  109. package/src/theme/components/input/number.styledef.js.map +1 -1
  110. package/src/theme/rn-stylesheet.transpiler.js +30 -6
  111. package/src/theme/rn-stylesheet.transpiler.js.map +1 -1
  112. package/src/theme/theme.service.js +3 -2
  113. package/src/theme/theme.service.js.map +1 -1
  114. package/src/transpile/bind.ex.transformer.js +55 -37
  115. package/src/transpile/bind.ex.transformer.js.map +1 -1
  116. package/src/transpile/components/container/wizard/wizardstep.transformer.js +10 -2
  117. package/src/transpile/components/container/wizard/wizardstep.transformer.js.map +1 -1
  118. package/src/transpile/components/data/form/form-field.transformer.js +36 -1
  119. package/src/transpile/components/data/form/form-field.transformer.js.map +1 -1
  120. package/src/transpile/components/page/page.transformer.js +11 -1
  121. package/src/transpile/components/page/page.transformer.js.map +1 -1
  122. package/src/transpile/property/property-parser.js +4 -1
  123. package/src/transpile/property/property-parser.js.map +1 -1
  124. package/src/transpile/style.transformer.js +1 -0
  125. package/src/transpile/style.transformer.js.map +1 -1
  126. package/src/transpile/transpile.js +10 -1
  127. package/src/transpile/transpile.js.map +1 -1
  128. package/src/utils.js +8 -1
  129. package/src/utils.js.map +1 -1
  130. package/src/wm-namespace.js +14 -0
  131. package/src/wm-namespace.js.map +1 -0
  132. package/test/pipeline/build-leftovers.test.js +172 -0
  133. package/test/pipeline/build-leftovers.test.js.map +1 -0
  134. package/test/pipeline/chmod-tree.test.js +54 -0
  135. package/test/pipeline/chmod-tree.test.js.map +1 -0
  136. package/test/pipeline/crawl-override.test.js +53 -0
  137. package/test/pipeline/crawl-override.test.js.map +1 -0
  138. package/test/pipeline/live-reload-pacing.test.js +76 -0
  139. package/test/pipeline/live-reload-pacing.test.js.map +1 -0
  140. package/test/pipeline/npm-install-retry.test.js +57 -0
  141. package/test/pipeline/npm-install-retry.test.js.map +1 -0
  142. package/test/pipeline/repair-vendor-packages.test.js +134 -0
  143. package/test/pipeline/repair-vendor-packages.test.js.map +1 -0
  144. package/test/pipeline/web-preview-files.test.js +48 -0
  145. package/test/pipeline/web-preview-files.test.js.map +1 -0
  146. package/web-preview.js +155 -0
  147. package/web-preview.js.map +1 -0
@@ -34,6 +34,7 @@ const execa_1 = __importDefault(require("execa"));
34
34
  const semver_1 = __importDefault(require("semver"));
35
35
  const path_2 = __importDefault(require("path"));
36
36
  const transpile_1 = require("./transpile/transpile");
37
+ const wm_namespace_1 = require("./wm-namespace");
37
38
  const variable_transformer_1 = __importDefault(require("./variables/variable.transformer"));
38
39
  const utils_1 = require("./utils");
39
40
  const bind_ex_transformer_1 = __importDefault(require("./transpile/bind.ex.transformer"));
@@ -41,6 +42,10 @@ const theme_service_1 = require("./theme/theme.service");
41
42
  const profile_1 = __importDefault(require("./profiles/profile"));
42
43
  const app_override_css_generator_1 = require("./theme/app-override-css.generator");
43
44
  const command_1 = require("../command");
45
+ const web_preview_templates_1 = require("./pipeline/web-preview-templates");
46
+ const working_set_1 = require("./pipeline/working-set");
47
+ // Shared with the CLI and the release build (scripts/build.js copies it next to post-build.js).
48
+ const depsCompat = require(path_2.default.join(__dirname, '..', 'scripts', 'check-deps-compat.js'));
44
49
  const APP_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/app.template');
45
50
  const APP_THEME_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/app.theme.template');
46
51
  const BABEL_CONFIG_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/babel.config.js.template');
@@ -52,6 +57,7 @@ const COMPONENT_PROPS_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templat
52
57
  const SCRIPT_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/component/script.template');
53
58
  const STYLE_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/component/style.template');
54
59
  const PAGE_CONFIG_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/pages-config.template');
60
+ const PAGE_STUB_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/page-stub.template');
55
61
  const SERVICE_DEFINITIONS = (0, utils_1.loadTemplate)(__dirname + '/templates/service.defs.template');
56
62
  const FORMATTERS_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/extensions/formatters.template');
57
63
  const VARIABLE_TEMPLATE = (0, utils_1.loadTemplate)(__dirname + '/templates/variables.template');
@@ -115,7 +121,7 @@ let deviceVariables = [];
115
121
  let appVersion;
116
122
  const servicesConfig = [];
117
123
  class AppGenerator {
118
- constructor(projectPath, projectService, appUrl, prefabName = '', incBuilder, options, dynamicPrefabProps) {
124
+ constructor(projectPath, projectService, appUrl, prefabName = '', incBuilder, options, dynamicPrefabProps, isWebPreview = false) {
119
125
  this.projectPath = projectPath;
120
126
  this.projectService = projectService;
121
127
  this.appUrl = appUrl;
@@ -123,6 +129,7 @@ class AppGenerator {
123
129
  this.incBuilder = incBuilder;
124
130
  this.options = options;
125
131
  this.dynamicPrefabProps = dynamicPrefabProps;
132
+ this.isWebPreview = isWebPreview;
126
133
  this.transpiledComponents = {
127
134
  pages: {},
128
135
  partials: {},
@@ -139,6 +146,7 @@ class AppGenerator {
139
146
  this.jsFileImports = new Set();
140
147
  this.shouldNpmInstall = false;
141
148
  this.shouldDoUnwantedPackagesCleanup = false;
149
+ this.forceGenerate = new Set();
142
150
  this.options = options;
143
151
  this.isPrefabApp = !!prefabName;
144
152
  this.wmxComponents = this.projectService.getWMXComponents();
@@ -188,10 +196,12 @@ class AppGenerator {
188
196
  * find all operations/packages (e.g, Camera, Scan, Location)
189
197
  * that are used in the app
190
198
  */
199
+ // Web preview: scan pages once, not once per operation (minutes on large apps).
200
+ const sharedScan = this.isWebPreview ? Promise.all([this.getWidgetImports(), this.getDeviceVariables()]) : null;
191
201
  await Promise.all(operations.map(async (operation) => {
192
202
  let method = "";
193
- const importedWidgets = await this.getWidgetImports();
194
- const deviceVariables = await this.getDeviceVariables();
203
+ const importedWidgets = sharedScan ? (await sharedScan)[0] : await this.getWidgetImports();
204
+ const deviceVariables = sharedScan ? (await sharedScan)[1] : await this.getDeviceVariables();
195
205
  const isWidgetImportedForCurrentOperation = importedWidgets.findIndex((w) => {
196
206
  const widgetName = operation === "File"
197
207
  ? "WmFileupload"
@@ -469,6 +479,26 @@ class AppGenerator {
469
479
  (0, utils_1.writeFile)(`${this.projectPath}/wm_rn_config.json`, JSON.stringify(config, null, 4));
470
480
  });
471
481
  }
482
+ // Copies each enabled profile's pre-built <profile>.json into the generated app, and removes stale ones.
483
+ generateGlobalConfig() {
484
+ if (this.incBuilder) {
485
+ console.log(`Copying Global config.`);
486
+ }
487
+ return this.projectService.getRNConfig().then(data => {
488
+ const config = JSON.parse(data);
489
+ const enabledProfiles = config.enabledProfiles || [];
490
+ // Tracks profiles generated last time, so one removed (or whose file was deleted outright) still gets cleaned up.
491
+ const manifestPath = `${this.projectPath}/.profiles-manifest.json`;
492
+ const previousProfiles = fs_extra_1.default.existsSync(manifestPath) ? JSON.parse(fs_extra_1.default.readFileSync(manifestPath, 'utf8')) : [];
493
+ previousProfiles
494
+ .filter((profileName) => !enabledProfiles.includes(profileName))
495
+ .forEach((profileName) => fs_extra_1.default.removeSync(`${this.projectPath}/${profileName}.json`));
496
+ (0, utils_1.writeFile)(manifestPath, JSON.stringify(enabledProfiles));
497
+ return Promise.all(enabledProfiles.map(profileName => this.projectService.getGlobalConfig(profileName).then(data => {
498
+ (0, utils_1.writeFile)(`${this.projectPath}/${profileName}.json`, data);
499
+ })));
500
+ });
501
+ }
472
502
  removeOldKeys(splash) {
473
503
  const keysToRemove = ['animationSrc', 'width', 'height', 'modifiedSrc'];
474
504
  const filterKeys = (obj) => Object.fromEntries(Object.entries(obj).filter(([key]) => !keysToRemove.includes(key)));
@@ -483,15 +513,16 @@ class AppGenerator {
483
513
  updateInSplashConfig(config, appConfig) {
484
514
  var _a, _b, _c;
485
515
  let filteredSplashConfig = this.removeOldKeys(config.splash);
516
+ const splashAssetPath = (src) => this.isWebPreview ? './assets/' + path_2.default.basename(src) : './assets/' + src;
486
517
  if (filteredSplashConfig.image) {
487
- filteredSplashConfig['image'] = './assets/' + filteredSplashConfig.image;
518
+ filteredSplashConfig['image'] = splashAssetPath(filteredSplashConfig.image);
488
519
  }
489
520
  if ((_a = filteredSplashConfig === null || filteredSplashConfig === void 0 ? void 0 : filteredSplashConfig.dark) === null || _a === void 0 ? void 0 : _a.image) {
490
- filteredSplashConfig['dark']['image'] = './assets/' + ((_b = filteredSplashConfig === null || filteredSplashConfig === void 0 ? void 0 : filteredSplashConfig.dark) === null || _b === void 0 ? void 0 : _b.image);
521
+ filteredSplashConfig['dark']['image'] = splashAssetPath((_b = filteredSplashConfig === null || filteredSplashConfig === void 0 ? void 0 : filteredSplashConfig.dark) === null || _b === void 0 ? void 0 : _b.image);
491
522
  }
492
523
  // support for old projects with splash in src and bgColor
493
524
  if (filteredSplashConfig.src) {
494
- filteredSplashConfig['image'] = './assets/' + filteredSplashConfig.src;
525
+ filteredSplashConfig['image'] = splashAssetPath(filteredSplashConfig.src);
495
526
  delete filteredSplashConfig.src;
496
527
  }
497
528
  if (filteredSplashConfig.src) {
@@ -525,8 +556,9 @@ class AppGenerator {
525
556
  appConfig['expo']['android']['package'] = config.id;
526
557
  appConfig['expo']['ios']['bundleIdentifier'] = config.id;
527
558
  appConfig['expo']['jsEngine'] = ((_a = config.preferences) === null || _a === void 0 ? void 0 : _a.enableHermes) === 'false' ? 'jsc' : 'hermes';
528
- appConfig['expo']['icon'] = './assets/' + config.icon.src;
529
- appConfig['expo']['android']['adaptiveIcon']['foregroundImage'] = './assets/' + config.icon.src;
559
+ const iconPath = this.isWebPreview ? './assets/' + path_2.default.basename(config.icon.src) : './assets/' + config.icon.src;
560
+ appConfig['expo']['icon'] = iconPath;
561
+ appConfig['expo']['android']['adaptiveIcon']['foregroundImage'] = iconPath;
530
562
  appConfig['expo']['orientation'] = config.orientation || 'portrait';
531
563
  const adaptiveColorMode = !!config.enableAdaptiveColorMode;
532
564
  appConfig.expo.userInterfaceStyle = adaptiveColorMode ? 'automatic' : 'light';
@@ -537,6 +569,14 @@ class AppGenerator {
537
569
  var _a, _b;
538
570
  (_b = (_a = appConfigOverride === null || appConfigOverride === void 0 ? void 0 : appConfigOverride.expo) === null || _a === void 0 ? void 0 : _a.plugins) === null || _b === void 0 ? void 0 : _b.forEach((plugin) => {
539
571
  var _a, _b;
572
+ // Expo's web export loads every config plugin; a missing local one fails the preview.
573
+ const pluginName = Array.isArray(plugin) ? plugin[0] : plugin;
574
+ if (this.isWebPreview && typeof pluginName === 'string' && /^\.\.?\//.test(pluginName)
575
+ && !['', '.js', '.ts', '/index.js', '/index.ts', '/app.plugin.js']
576
+ .some(ext => fs_extra_1.default.existsSync(path_2.default.resolve(this.projectPath, pluginName + ext)))) {
577
+ console.warn(`Skipping config plugin ${pluginName} in web preview: no such file in the project.`);
578
+ return;
579
+ }
540
580
  if ((_a = appConfig === null || appConfig === void 0 ? void 0 : appConfig.expo) === null || _a === void 0 ? void 0 : _a.plugins) {
541
581
  const presentInIndex = appConfig.expo.plugins.findIndex((item) => item[0] === plugin[0]);
542
582
  if (presentInIndex > -1 && Array.isArray(appConfig.expo.plugins[presentInIndex])) {
@@ -593,23 +633,30 @@ class AppGenerator {
593
633
  }
594
634
  return this.projectService.getAppVariables().then(variables => {
595
635
  return this.projectService.getAppJs().then(script => {
596
- var _a;
597
- const supportedLocaleVariable = (_a = Object.values(variables).filter((v) => (v.startUpdate || v.category === 'wm.Variable') && v.name === 'supportedLocale')) === null || _a === void 0 ? void 0 : _a[0];
598
- const localeDataset = Object.keys(supportedLocaleVariable === null || supportedLocaleVariable === void 0 ? void 0 : supportedLocaleVariable.dataSet);
599
- const supportedLocales = localeDataset.filter(utils_1.isValidLocale);
600
- const output = APP_TEMPLATE({
601
- script: script,
602
- startUpVariables: Object.values(variables).filter((v) => (v.startUpdate || v.category === 'wm.Variable') && v.category !== 'wm.TimerAction').map((v) => v.name),
603
- startUpActions: Object.values(variables).filter((v) => v.startUpdate && v.category === 'wm.TimerAction').map((v) => v.name),
604
- autoUpdateVariables: Object.values(variables).filter((v) => v.autoUpdate || ((v.category === 'wm.Variable' || v.category === 'wm.LiveVariable') && v.dataBinding && v.dataBinding.length)).map((v) => v.name),
605
- supportedLocales: supportedLocales,
606
- animatedSplash: animatedSplash,
607
- sslPinning: sslPinning,
608
- enableWavePulse: enableWavePulse,
609
- enableDesignTokens: !!config.preferences.enableDesignTokens,
610
- enableAdaptiveColorMode: !!config.enableAdaptiveColorMode
636
+ return this.projectService.getAppWrapperJs().then(appWrapperJs => {
637
+ var _a;
638
+ const supportedLocaleVariable = (_a = Object.values(variables).filter((v) => (v.startUpdate || v.category === 'wm.Variable') && v.name === 'supportedLocale')) === null || _a === void 0 ? void 0 : _a[0];
639
+ const localeDataset = Object.keys(supportedLocaleVariable === null || supportedLocaleVariable === void 0 ? void 0 : supportedLocaleVariable.dataSet);
640
+ const supportedLocales = localeDataset.filter(utils_1.isValidLocale);
641
+ if (appWrapperJs) {
642
+ (0, utils_1.writeFile)(`${this.projectPath}/src/customapp.wrapper.js`, appWrapperJs);
643
+ }
644
+ const output = APP_TEMPLATE({
645
+ script: script,
646
+ startUpVariables: Object.values(variables).filter((v) => (v.startUpdate || v.category === 'wm.Variable') && v.category !== 'wm.TimerAction').map((v) => v.name),
647
+ startUpActions: Object.values(variables).filter((v) => v.startUpdate && v.category === 'wm.TimerAction').map((v) => v.name),
648
+ autoUpdateVariables: Object.values(variables).filter((v) => v.autoUpdate || ((v.category === 'wm.Variable' || v.category === 'wm.LiveVariable') && v.dataBinding && v.dataBinding.length)).map((v) => v.name),
649
+ supportedLocales: supportedLocales,
650
+ animatedSplash: animatedSplash,
651
+ sslPinning: sslPinning,
652
+ enableWavePulse: enableWavePulse,
653
+ enableDesignTokens: !!config.preferences.enableDesignTokens,
654
+ enableAdaptiveColorMode: !!config.enableAdaptiveColorMode,
655
+ enabledProfiles: config.enabledProfiles || [],
656
+ customAppWrapper: !!appWrapperJs
657
+ });
658
+ (0, utils_1.writeFile)(`${this.projectPath}/App.js`, output);
611
659
  });
612
- (0, utils_1.writeFile)(`${this.projectPath}/App.js`, output);
613
660
  });
614
661
  });
615
662
  });
@@ -650,7 +697,9 @@ class AppGenerator {
650
697
  return this.themeService.generateStudioStyles(styles);
651
698
  }
652
699
  async generateComponent(info, type, name, dynamicProps) {
653
- if (this.incBuilder && !this.incBuilder.isFragmentModified(name)) {
700
+ // Also regenerate on an app-config change, not just a page edit: a page's cascaded
701
+ // pulltorefresh value (page.transformer.ts) comes from that config too.
702
+ if (this.incBuilder && !this.incBuilder.isFragmentModified(name) && !this.incBuilder.isConfigModified() && !this.forceGenerate.has(name)) {
654
703
  return Promise.resolve();
655
704
  }
656
705
  if (this.incBuilder) {
@@ -691,6 +740,15 @@ class AppGenerator {
691
740
  });
692
741
  }
693
742
  const imports = (0, lodash_1.sortBy)((0, lodash_1.uniqBy)(transpiledOutput.imports, i => i.name + i.from), i => i.name);
743
+ // Pull-to-refresh invokes this page's flagged variables plus the flagged app variables it references.
744
+ const appVariables = await Promise.resolve(this.projectService.getAppVariables()).catch(() => ({}));
745
+ const pageSource = `${info.markup || ''}\n${info.script || ''}`;
746
+ const pullToRefreshVariables = Array.from(new Set([
747
+ ...Object.values(variables).filter((v) => v.pullToRefreshUpdate).map((v) => v.name),
748
+ ...Object.values(appVariables || {})
749
+ .filter((v) => v.pullToRefreshUpdate && new RegExp(`\\bVariables\\.${(0, lodash_1.escapeRegExp)(v.name)}\\b`).test(pageSource))
750
+ .map((v) => v.name),
751
+ ]));
694
752
  const component = COMPONENT_TEMPLATE({
695
753
  name: name,
696
754
  type: type,
@@ -704,6 +762,7 @@ class AppGenerator {
704
762
  startUpVariables: Object.values(variables).filter((v) => v.startUpdate && v.category !== 'wm.TimerAction').map((v) => v.name),
705
763
  startUpActions: Object.values(variables).filter((v) => v.startUpdate && v.category === 'wm.TimerAction').map((v) => v.name),
706
764
  autoUpdateVariables: Object.values(variables).filter((v) => v.autoUpdate || ((v.category === 'wm.Variable' || v.category === 'wm.LiveVariable') && v.dataBinding && v.dataBinding.length)).map((v) => v.name),
765
+ pullToRefreshVariables: pullToRefreshVariables,
707
766
  eagerImports: imports.filter(i => !i.lazy),
708
767
  lazyImports: imports.filter(i => i.lazy)
709
768
  });
@@ -794,67 +853,103 @@ class AppGenerator {
794
853
  return Promise.all(prefabs === null || prefabs === void 0 ? void 0 : prefabs.map(prefab => this.generatePrefabComponent(prefab, overwrite)));
795
854
  });
796
855
  }
856
+ checkWmxRuntimeDepsCompatibility(componentsPath, reactVersion, reactNativeVersion) {
857
+ const checks = [
858
+ { name: 'react', expected: reactVersion },
859
+ { name: 'react-native', expected: reactNativeVersion },
860
+ ];
861
+ for (const { name, expected } of checks) {
862
+ const pkgPath = `${componentsPath}/node_modules/${name}/package.json`;
863
+ if (!expected || !fs_extra_1.default.existsSync(pkgPath)) {
864
+ continue;
865
+ }
866
+ const installedVersion = fs_extra_1.default.readJsonSync(pkgPath, { encoding: 'utf8' }).version;
867
+ const expectedClean = `${expected}`.replace('^', '').replace('~', '');
868
+ if (installedVersion && semver_1.default.major(installedVersion) !== semver_1.default.major(expectedClean)) {
869
+ console.warn(`Warning: wmx-component's "${name}" version (${installedVersion}) is not compatible with the app's "${name}" version (${expected}) — major version mismatch. `
870
+ + `Update the wmx-component's dependency on "${name}" to a "${semver_1.default.major(expectedClean)}.x" version and rebuild.`);
871
+ }
872
+ }
873
+ }
797
874
  compileXComponentLib() {
798
875
  var _a, _b;
799
876
  const componentsPath = `${this.projectService.path}/extensions/components`;
800
- const componentsPackageJson = `${componentsPath}/package.json`;
801
- const wmxDependenciesMarker = `${componentsPath}/.wmx-dependencies.info`;
877
+ // Under node_modules so it never ships with an exported/downloaded app. Not `.cache`: web preview
878
+ // symlinks every vendor-tree entry into node_modules, and a shared `.cache` would be read-only.
879
+ const npmCacheDir = (0, path_1.join)(this.projectPath, 'node_modules', '.wm-wmx-npm-cache');
880
+ fs_extra_1.default.removeSync((0, path_1.join)(this.projectPath, '.wmx-npm-cache')); // previous location
881
+ const wmxPackageJsonPath = `${componentsPath}/package.json`;
882
+ const readWmxPackageJson = () => {
883
+ if (!fs_extra_1.default.existsSync(wmxPackageJsonPath)) {
884
+ throw new Error(`wmx-components package.json not found at ${wmxPackageJsonPath} — extensions/components must be scaffolded before compiling wmx components.`);
885
+ }
886
+ try {
887
+ return fs_extra_1.default.readJsonSync(wmxPackageJsonPath, { encoding: 'utf8' });
888
+ }
889
+ catch (e) {
890
+ throw new Error(`Failed to parse ${wmxPackageJsonPath}: ${e.message}`);
891
+ }
892
+ };
893
+ const projectPackages = fs_extra_1.default.readJsonSync(`${__dirname}/templates/project/package.json`, {
894
+ encoding: 'utf8'
895
+ });
896
+ const reactVersion = (_a = projectPackages === null || projectPackages === void 0 ? void 0 : projectPackages.dependencies) === null || _a === void 0 ? void 0 : _a['react'];
897
+ const reactNativeVersion = (_b = projectPackages === null || projectPackages === void 0 ? void 0 : projectPackages.dependencies) === null || _b === void 0 ? void 0 : _b['react-native'];
802
898
  if (!this.incBuilder) {
803
- const projectPackages = fs_extra_1.default.readJsonSync(`${__dirname}/templates/project/package.json`, {
804
- encoding: 'utf8'
805
- });
806
- const reactVersion = (_a = projectPackages === null || projectPackages === void 0 ? void 0 : projectPackages.dependencies) === null || _a === void 0 ? void 0 : _a['react'];
807
- const reactNativeVersion = (_b = projectPackages === null || projectPackages === void 0 ? void 0 : projectPackages.dependencies) === null || _b === void 0 ? void 0 : _b['react-native'];
808
- const wmxComponentPackage = fs_extra_1.default.readJsonSync(componentsPackageJson, {
809
- encoding: 'utf8'
810
- });
899
+ const wmxComponentPackage = readWmxPackageJson();
811
900
  // semver considers ^x.x.x and ~x.x.x as invalid package versions.
812
901
  if (semver_1.default.lt(`${wmxComponentPackage.devDependencies['@types/react']}`.replace('^', '').replace('~', ''), reactVersion) ||
813
902
  semver_1.default.lt(`${wmxComponentPackage.devDependencies['react-native']}`.replace('^', '').replace('~', ''), reactNativeVersion)) {
814
903
  wmxComponentPackage.devDependencies['@types/react'] = `${reactVersion}`;
815
904
  wmxComponentPackage.devDependencies['react-native'] = `${reactNativeVersion}`;
816
905
  }
817
- fs_extra_1.default.writeJSONSync(componentsPackageJson, wmxComponentPackage);
818
- if (fs_extra_1.default.existsSync(`${componentsPath}/package-lock.json`)) {
819
- fs_extra_1.default.removeSync(`${componentsPath}/package-lock.json`);
820
- fs_extra_1.default.emptyDirSync(`${componentsPath}/node_modules`);
821
- }
822
- fs_extra_1.default.removeSync(wmxDependenciesMarker);
823
- }
824
- else if (fs_extra_1.default.existsSync(wmxDependenciesMarker)
825
- && fs_extra_1.default.existsSync(`${componentsPath}/node_modules`)
826
- && fs_extra_1.default.existsSync(`${this.projectPath}/wmx-components`)) {
827
- try {
828
- const marker = fs_extra_1.default.readJSONSync(wmxDependenciesMarker);
829
- const currentHash = crypto_1.default.createHash('md5')
830
- .update(fs_extra_1.default.readFileSync(componentsPackageJson, 'utf-8'), 'utf-8')
831
- .digest('hex');
832
- if (marker.packageHash === currentHash) {
833
- console.log('wmx-components package.json unchanged since last build — skipping npm install/build.');
834
- return Promise.resolve();
835
- }
836
- }
837
- catch (e) {
838
- console.error(e);
839
- }
840
- }
841
- return (0, execa_1.default)('npm', ['install'], {
906
+ fs_extra_1.default.writeJSONSync(wmxPackageJsonPath, wmxComponentPackage);
907
+ fs_extra_1.default.removeSync(`${componentsPath}/package-lock.json`);
908
+ fs_extra_1.default.emptyDirSync(`${componentsPath}/node_modules`);
909
+ // Clean build: never trust a previously cached npm tarball — wipe it outright.
910
+ fs_extra_1.default.removeSync(npmCacheDir);
911
+ }
912
+ const wmxComponentPackage = readWmxPackageJson();
913
+ const depsHash = crypto_1.default.createHash('md5')
914
+ .update(JSON.stringify(wmxComponentPackage.dependencies || {}) + JSON.stringify(wmxComponentPackage.devDependencies || {}))
915
+ .digest('hex')
916
+ .slice(0, 8);
917
+ const depsHashFile = (0, path_1.join)(npmCacheDir, '.deps-hash');
918
+ const cachedDepsHash = fs_extra_1.default.existsSync(depsHashFile) ? fs_extra_1.default.readFileSync(depsHashFile, 'utf8') : undefined;
919
+ if (cachedDepsHash !== depsHash) {
920
+ fs_extra_1.default.removeSync(npmCacheDir);
921
+ fs_extra_1.default.mkdirpSync(npmCacheDir);
922
+ fs_extra_1.default.writeFileSync(depsHashFile, depsHash);
923
+ }
924
+ // Same reasoning as npmInstall(): a failed or killed install can leave corrupt cache entries behind.
925
+ const dropCacheOnFailure = (err) => {
926
+ console.warn(`[npm] wmx install failed — removing wmx npm cache at ${npmCacheDir}`);
927
+ fs_extra_1.default.removeSync(npmCacheDir);
928
+ throw err;
929
+ };
930
+ return (0, execa_1.default)('npm', ['install', '--cache', npmCacheDir], {
842
931
  cwd: componentsPath
843
- }).then(() => {
932
+ }).catch(dropCacheOnFailure).then(() => {
844
933
  return (0, execa_1.default)('npm', ['run', 'build'], {
845
934
  cwd: componentsPath
846
935
  });
847
936
  }).then(() => {
848
- fs_extra_1.default.copySync(`${componentsPath}/build`, `${this.projectPath}/wmx-components`);
849
- }).then(() => {
850
- if (fs_extra_1.default.existsSync(`${componentsPath}/node_modules`)) {
851
- fs_extra_1.default.copySync(`${componentsPath}/node_modules`, `${this.projectPath}/wmx-components/node_modules`);
937
+ const wmxComponentsDest = `${this.projectPath}/wmx-components`;
938
+ const wmxNodeModulesDir = `${wmxComponentsDest}/node_modules`;
939
+ fs_extra_1.default.copySync(`${componentsPath}/build`, wmxComponentsDest);
940
+ if (!fs_extra_1.default.existsSync(`${wmxComponentsDest}/package.json`)) {
941
+ return;
852
942
  }
853
- }).then(() => {
854
- const postBuildHash = crypto_1.default.createHash('md5')
855
- .update(fs_extra_1.default.readFileSync(componentsPackageJson, 'utf-8'), 'utf-8')
856
- .digest('hex');
857
- fs_extra_1.default.writeJSONSync(wmxDependenciesMarker, { packageHash: postBuildHash, lastBuild: Date.now() });
943
+ if (!this.incBuilder) {
944
+ fs_extra_1.default.removeSync(wmxNodeModulesDir);
945
+ }
946
+ return (0, execa_1.default)('npm', ['install', '--cache', npmCacheDir], {
947
+ cwd: wmxComponentsDest
948
+ }).catch(dropCacheOnFailure).then(() => {
949
+ this.checkWmxRuntimeDepsCompatibility(wmxComponentsDest, reactVersion, reactNativeVersion);
950
+ }).finally(() => {
951
+ fs_extra_1.default.removeSync(wmxNodeModulesDir);
952
+ });
858
953
  });
859
954
  }
860
955
  async generateWMXComponents(name, overwrite) {
@@ -1048,9 +1143,17 @@ class AppGenerator {
1048
1143
  * @description Get all widget imports in the generated app
1049
1144
  * @returns array of widgets imported (e.g, WmCamera, WmVideo)
1050
1145
  */
1051
- async getWidgetImports() {
1146
+ // Web preview: markup doesn't change mid-build, so every caller shares one scan of all pages.
1147
+ getWidgetImports() {
1148
+ var _a;
1149
+ if (!this.isWebPreview) {
1150
+ return this.scanWidgetImports();
1151
+ }
1152
+ return (_a = this.widgetImportsScan) !== null && _a !== void 0 ? _a : (this.widgetImportsScan = this.scanWidgetImports());
1153
+ }
1154
+ async scanWidgetImports(only) {
1052
1155
  let widgetImports = [];
1053
- const pageConfigs = await this.projectService.getPageConfigs();
1156
+ const pageConfigs = (await this.projectService.getPageConfigs()).filter(p => !only || only(p.name));
1054
1157
  await Promise.all(pageConfigs.map(async (p) => {
1055
1158
  const info = await this.projectService.getPageInfo(p.name);
1056
1159
  const transpileArgs = {
@@ -1091,6 +1194,18 @@ class AppGenerator {
1091
1194
  if (this.incBuilder) {
1092
1195
  console.log(`Checking widget usage in component files.`);
1093
1196
  }
1197
+ // Web preview incremental: only edited pages/partials can bring in a new widget, so scan just those.
1198
+ // A widget removed elsewhere keeps its plugin until the next clean preview, which is harmless.
1199
+ const buildCache = this.isWebPreview && this.incBuilder && !this.shouldDoUnwantedPackagesCleanup
1200
+ ? fs_extra_1.default.readJSONSync(`${this.projectPath}/.build-cache`, { throws: false }) : null;
1201
+ if (buildCache === null || buildCache === void 0 ? void 0 : buildCache.widgetImports) {
1202
+ const known = new Set(buildCache.widgetImports.map((d) => d.name));
1203
+ const changed = await this.scanWidgetImports(name => this.incBuilder.isFragmentModified(name));
1204
+ if (!this.projectPackageDependencies.some((dep) => !known.has(dep.name)
1205
+ && changed.some((i) => { var _a; return (_a = dep.tagName) === null || _a === void 0 ? void 0 : _a.includes(i === null || i === void 0 ? void 0 : i.name); }))) {
1206
+ return;
1207
+ }
1208
+ }
1094
1209
  const projectDependencies = (0, lodash_1.uniq)([...this.projectPackageDependencies]);
1095
1210
  const imports = await this.getWidgetImports();
1096
1211
  projectDependencies.forEach((dep, index) => {
@@ -1189,7 +1304,7 @@ class AppGenerator {
1189
1304
  if (stat.isDirectory()) {
1190
1305
  scanDirectory(fullPath);
1191
1306
  }
1192
- else if (file.endsWith('.js') || file.endsWith('.ts') || file.endsWith('.tsx')) {
1307
+ else if (file.endsWith('.js') || file.endsWith('.jsx') || file.endsWith('.ts') || file.endsWith('.tsx')) {
1193
1308
  try {
1194
1309
  // Ignore checking for package imports in ignore list file names
1195
1310
  if (scanFileIgnoreList.includes(file)) {
@@ -1222,6 +1337,10 @@ class AppGenerator {
1222
1337
  const scanPaths = [
1223
1338
  `${this.projectPath}/src`,
1224
1339
  `${this.projectPath}/assets/resources`,
1340
+ // wmx components (compiled to .jsx) import their own packages, e.g. the barcode scanner's expo-camera.
1341
+ `${this.projectPath}/wmx-components/src`,
1342
+ // Stubbed pages have no generated script; scan their sources so their packages are kept.
1343
+ ...(this.isWebPreview && (0, working_set_1.workingSetEnabled)(this.projectService.path) ? [`${this.projectService.path}/pages`] : []),
1225
1344
  ];
1226
1345
  scanPaths.forEach(scanPath => {
1227
1346
  scanDirectory(scanPath);
@@ -1299,25 +1418,71 @@ class AppGenerator {
1299
1418
  }
1300
1419
  return Promise.resolve();
1301
1420
  }
1421
+ // Web preview: real components only for working-set pages and partials, a stub at the same path for the rest.
1422
+ resolvePreviewWorkingSet(pageConfigs) {
1423
+ if (!this.isWebPreview || this.isPrefabApp || !(0, working_set_1.workingSetEnabled)(this.projectService.path)) {
1424
+ return null;
1425
+ }
1426
+ const pages = pageConfigs.filter(p => p.type === 'PAGE').map(p => p.name);
1427
+ const partials = pageConfigs.filter(p => this.isPartial(p.type)).map(p => p.name);
1428
+ const preview = this.rnConfig.preview;
1429
+ // Default: every page, as a working set (not null) so stubs left from an earlier build are replaced.
1430
+ if ((preview === null || preview === void 0 ? void 0 : preview.allPages) !== false) {
1431
+ return new Set([...pages, ...partials]);
1432
+ }
1433
+ const modified = this.incBuilder
1434
+ ? [...pages, ...partials].filter(p => this.incBuilder.isFragmentModified(p)) : [];
1435
+ return (0, working_set_1.resolveWorkingSet)(this.projectPath, this.projectService.path, pages, partials, modified, Array.isArray(preview === null || preview === void 0 ? void 0 : preview.pages) ? preview.pages : []);
1436
+ }
1437
+ generatePreviewFragment(name, kind, workingSet) {
1438
+ const file = `${this.projectPath}/src/${kind}/${name}/${name}.component.js`;
1439
+ if (workingSet.has(name)) {
1440
+ // A stub (or missing file) has unchanged source, so the incremental check would skip it.
1441
+ if ((0, working_set_1.isStub)(file) || !fs_extra_1.default.existsSync(file)) {
1442
+ this.forceGenerate.add(name);
1443
+ }
1444
+ return kind === 'pages' ? this.generatePageComponent(name) : this.generatePartialComponent(name);
1445
+ }
1446
+ const stub = PAGE_STUB_TEMPLATE({ name, kind: kind === 'pages' ? 'page' : 'partial' });
1447
+ if (!(0, working_set_1.isStub)(file)) {
1448
+ // Drop the previously generated files; they are regenerated when this is built.
1449
+ fs_extra_1.default.emptyDirSync(path_2.default.dirname(file));
1450
+ (0, utils_1.writeFile)(file, stub);
1451
+ }
1452
+ else if (fs_extra_1.default.readFileSync(file, 'utf-8') !== stub) {
1453
+ // A stub written by an older template.
1454
+ (0, utils_1.writeFile)(file, stub);
1455
+ }
1456
+ // Entity metadata is built from every fragment's live variables, stubbed ones included.
1457
+ const variables = fs_extra_1.default.readJSONSync(`${this.projectService.path}/pages/${name}/${name}.variables.json`);
1458
+ this.liveVariables.push(...Object.values(variables).filter((v) => v.category === 'wm.LiveVariable'));
1459
+ return Promise.resolve();
1460
+ }
1302
1461
  generatePagesAndPartials() {
1303
1462
  let pageConfigs = null;
1304
1463
  return this.projectService.getPageConfigs().then(_pageConfigs => {
1305
1464
  pageConfigs = _pageConfigs;
1465
+ const workingSet = this.resolvePreviewWorkingSet(pageConfigs);
1306
1466
  const pageCreationPromises = pageConfigs.map(p => {
1307
1467
  if (p.type === 'PAGE') {
1308
- return this.generatePageComponent(p.name);
1468
+ return workingSet ? this.generatePreviewFragment(p.name, 'pages', workingSet) : this.generatePageComponent(p.name);
1309
1469
  }
1310
1470
  if (this.isPartial(p.type)) {
1311
- return this.generatePartialComponent(p.name);
1471
+ return workingSet ? this.generatePreviewFragment(p.name, 'partials', workingSet) : this.generatePartialComponent(p.name);
1312
1472
  }
1313
1473
  });
1474
+ // Stubs generate no prefabs or WMX components, but a page built later needs them in bootstrap.js
1475
+ // and in the compiled WMX library, which incremental builds do not redo.
1476
+ if (workingSet && !this.incBuilder) {
1477
+ pageCreationPromises.push(this.generateAllPrefabComponents(false), ...this.wmxComponents.map(c => this.generateWMXComponents(c, false)));
1478
+ }
1314
1479
  return Promise.all(pageCreationPromises);
1315
1480
  })
1316
1481
  .then(() => this.generatePageConfig(pageConfigs))
1317
1482
  .then(() => this.generatePartialConfig(pageConfigs));
1318
1483
  }
1319
1484
  async mergePackageJson() {
1320
- var _a;
1485
+ var _a, _b, _c;
1321
1486
  if (this.incBuilder) {
1322
1487
  console.log(`Merging package.json .`);
1323
1488
  }
@@ -1328,14 +1493,26 @@ class AppGenerator {
1328
1493
  packageToOveride.description = config.description;
1329
1494
  if (profile_1.default.targetPlatform === 'web') {
1330
1495
  const webPackageJson = fs_extra_1.default.readJSONSync(`${__dirname}/templates/package.web.json`, { encoding: 'utf-8' });
1331
- // * only merge scripts from package.web.json
1332
- packageToOveride.scripts = (0, lodash_1.merge)(packageToOveride.scripts, webPackageJson.scripts);
1496
+ packageToOveride = (0, lodash_1.merge)(packageToOveride, webPackageJson);
1333
1497
  }
1334
1498
  if (this.wmxComponents.length > 0) {
1335
- packageToOveride.dependencies['@wavemaker/wmx-component'] = 'file:wmx-components';
1499
+ packageToOveride.scripts.postinstall = [
1500
+ 'npm install --prefix ./wmx-components',
1501
+ ...((packageToOveride.scripts.postinstall || '')
1502
+ .split('&&')
1503
+ .filter((s) => s && !!s.trim()))
1504
+ ].join(' && ');
1336
1505
  if (!this.incBuilder || this.incBuilder.isWMXComponentModified()) {
1337
1506
  await this.compileXComponentLib();
1338
1507
  }
1508
+ // wmx-components/node_modules is removed after the build and blocked in metro.config.js, so wmx's
1509
+ // own packages (e.g. react-konva) must be app dependencies. Versions the app declares win.
1510
+ const wmxDependencies = ((_a = fs_extra_1.default.readJsonSync(`${this.projectPath}/wmx-components/package.json`, { throws: false })) === null || _a === void 0 ? void 0 : _a.dependencies) || {};
1511
+ for (const [name, range] of Object.entries(wmxDependencies)) {
1512
+ if (!packageToOveride.dependencies[name] && !((_b = packageToOveride.devDependencies) === null || _b === void 0 ? void 0 : _b[name]) && semver_1.default.validRange(range)) {
1513
+ packageToOveride.dependencies[name] = range;
1514
+ }
1515
+ }
1339
1516
  }
1340
1517
  const packageOverride = await this.projectService.getPackageJSONOverride();
1341
1518
  let packageOverriden = packageOverride ? (0, lodash_1.merge)(packageToOveride, packageOverride) : packageToOveride;
@@ -1345,7 +1522,7 @@ class AppGenerator {
1345
1522
  'npm install --prefix ./wmx-components',
1346
1523
  'npm install --prefix ./wmx-components --cache ./wmx-components/.npm-cache'
1347
1524
  ];
1348
- const remainingSteps = (((_a = packageOverriden.scripts) === null || _a === void 0 ? void 0 : _a.postinstall) || '')
1525
+ const remainingSteps = (((_c = packageOverriden.scripts) === null || _c === void 0 ? void 0 : _c.postinstall) || '')
1349
1526
  .split('&&')
1350
1527
  .map((s) => s.trim())
1351
1528
  .filter((s) => s && !priorWmxInstallForms.includes(s));
@@ -1392,6 +1569,36 @@ class AppGenerator {
1392
1569
  (0, utils_1.writeFile)(`${this.projectPath}/app.json`, JSON.stringify(appJson, null, 4));
1393
1570
  }
1394
1571
  }
1572
+ /**
1573
+ * Packages the project adds itself: wm_rn_config.json plugins, prefab npm:// scripts and wmx component
1574
+ * dependencies. Only WaveMaker's own packages are pruned, so these stay even when the template also ships
1575
+ * them (e.g. expo-camera needed by a custom plugin), and npm keeps whatever they depend on.
1576
+ */
1577
+ async getProjectAddedPackages() {
1578
+ var _a, _b, _c;
1579
+ const names = new Set();
1580
+ const config = fs_extra_1.default.readJsonSync(`${this.projectPath}/wm_rn_config.json`, { throws: false });
1581
+ [...((config === null || config === void 0 ? void 0 : config.plugins) || []), ...((config === null || config === void 0 ? void 0 : config.customPlugins) || [])]
1582
+ .forEach((p) => (p === null || p === void 0 ? void 0 : p.name) && names.add(p.name));
1583
+ const wmxDependencies = (_a = fs_extra_1.default.readJsonSync(`${this.projectPath}/wmx-components/package.json`, { throws: false })) === null || _a === void 0 ? void 0 : _a.dependencies;
1584
+ Object.keys(wmxDependencies || {}).forEach((name) => names.add(name));
1585
+ for (const prefab of Object.keys(this.transpiledComponents.prefabs || {})) {
1586
+ try {
1587
+ const info = await this.projectService.getPrefabInfo(prefab);
1588
+ (((_c = (_b = info === null || info === void 0 ? void 0 : info.config) === null || _b === void 0 ? void 0 : _b.resources) === null || _c === void 0 ? void 0 : _c.scripts) || []).forEach((script) => {
1589
+ var _a;
1590
+ const name = script.includes('npm://') && ((_a = script.match(/[\/]+(.*?)@\d/)) === null || _a === void 0 ? void 0 : _a[1]);
1591
+ if (name) {
1592
+ names.add(name);
1593
+ }
1594
+ });
1595
+ }
1596
+ catch (e) {
1597
+ console.warn(`Could not read prefab ${prefab} config: ${e.message}`);
1598
+ }
1599
+ }
1600
+ return names;
1601
+ }
1395
1602
  /**
1396
1603
  * remove unused dependencies from package.json
1397
1604
  * @param packageJsonData
@@ -1404,6 +1611,7 @@ class AppGenerator {
1404
1611
  let removedPackages = [];
1405
1612
  try {
1406
1613
  const dependencies = (0, lodash_1.cloneDeep)(this.projectPackageDependencies);
1614
+ const projectAddedPackages = await this.getProjectAddedPackages();
1407
1615
  const listOfPackagesUsed = await this.getListOfPackagesUsedInGeneratedApp();
1408
1616
  const operationsUsed = Object.entries(listOfPackagesUsed)
1409
1617
  .map(([key, value]) => {
@@ -1442,6 +1650,10 @@ class AppGenerator {
1442
1650
  if (isPackageUsedByOtherOperation) {
1443
1651
  return;
1444
1652
  }
1653
+ if (projectAddedPackages.has(p)) {
1654
+ console.log(`Keeping package ${p}: added by the project (plugin, prefab or wmx component)`);
1655
+ return;
1656
+ }
1445
1657
  delete updatedPackageJson.dependencies[p];
1446
1658
  if (!removedPackages.includes(p)) {
1447
1659
  removedPackages.push(p);
@@ -1477,19 +1689,33 @@ class AppGenerator {
1477
1689
  }
1478
1690
  fs_extra_1.default.writeFileSync(`${this.projectPath}/package.json`, JSON.stringify(updatedPackageJson, null, 4));
1479
1691
  // * installing packages whenever a package is added or removed
1480
- if (this.shouldNpmInstall && this.incBuilder) {
1481
- (0, command_1.npmInstall)(`${this.projectPath}`);
1692
+ // Web preview installs after generation (installDependencies), so not here as well.
1693
+ if (this.shouldNpmInstall && this.incBuilder && !this.isWebPreview) {
1694
+ await (0, command_1.npmInstall)(`${this.projectPath}`);
1482
1695
  }
1483
1696
  }
1697
+ // Report only; "dependencyCheck": false in wm_rn_config.json turns it off.
1698
+ reportCustomDependencies() {
1699
+ if (this.rnConfig.dependencyCheck === false) {
1700
+ return Promise.resolve();
1701
+ }
1702
+ return depsCompat.reportCustomDependencies(this.projectPath, {
1703
+ baseDir: profile_1.default.packageLockFilePath ? path_2.default.dirname(profile_1.default.packageLockFilePath) : `${__dirname}/templates/project`,
1704
+ ownScope: wm_namespace_1.WM_NPM_SCOPE,
1705
+ });
1706
+ }
1484
1707
  async copyPackageLockJson() {
1485
- if (fs_extra_1.default.existsSync(`${this.projectPath}/package-lock.json`)) {
1708
+ const hadLock = fs_extra_1.default.existsSync(`${this.projectPath}/package-lock.json`);
1709
+ if (!depsCompat.syncBaseLock(this.projectPath, profile_1.default.packageLockFilePath)) {
1486
1710
  return;
1487
1711
  }
1488
1712
  if (this.incBuilder) {
1489
1713
  console.log(`Copying package-lock.json .`);
1490
1714
  }
1491
- if (profile_1.default.packageLockFilePath && fs_extra_1.default.existsSync(profile_1.default.packageLockFilePath)) {
1492
- fs_extra_1.default.copySync(profile_1.default.packageLockFilePath, `${this.projectPath}/package-lock.json`);
1715
+ if (hadLock) {
1716
+ // A replaced lock no longer lists the custom packages, so the next install must run to add them back
1717
+ // (it otherwise only runs when package.json changes).
1718
+ fs_extra_1.default.removeSync(`${this.projectPath}/dependencies.info`);
1493
1719
  }
1494
1720
  if (profile_1.default.yarnLockFilePath && fs_extra_1.default.existsSync(profile_1.default.yarnLockFilePath)) {
1495
1721
  fs_extra_1.default.copySync(profile_1.default.yarnLockFilePath, `${this.projectPath}/yarn.json`);
@@ -1555,6 +1781,50 @@ class AppGenerator {
1555
1781
  }
1556
1782
  fs_extra_1.default.writeJsonSync(appJsonPath, appJson, { spaces: 2 });
1557
1783
  }
1784
+ // Registered as a file: dependency (a native module, unlike expo-screen-capture-plugin's config plugin) so Expo autolinking discovers it.
1785
+ async copyPullToRefreshPluginIfNeeded() {
1786
+ const config = this.rnConfig;
1787
+ const packageJsonPath = `${this.projectPath}/package.json`;
1788
+ const pluginName = '@wavemaker/expo-pull-to-refresh';
1789
+ const pluginDestPath = `${this.projectPath}/plugins/expo-pull-to-refresh`;
1790
+ if (!fs_extra_1.default.existsSync(packageJsonPath)) {
1791
+ console.warn(`Warning: package.json not found at ${packageJsonPath}`);
1792
+ return;
1793
+ }
1794
+ const packageJson = fs_extra_1.default.readJsonSync(packageJsonPath);
1795
+ // Both flags: an animation alone with the feature off shouldn't ship the plugin.
1796
+ if ((config === null || config === void 0 ? void 0 : config.pulltorefresh) && (config === null || config === void 0 ? void 0 : config.pulltorefreshsource)) {
1797
+ const pluginSourcePath = __dirname + '/templates/project/plugins/expo-pull-to-refresh';
1798
+ if (!fs_extra_1.default.existsSync(pluginSourcePath)) {
1799
+ console.warn(`Warning: Pull to refresh plugin source not found at ${pluginSourcePath}`);
1800
+ return;
1801
+ }
1802
+ fs_extra_1.default.mkdirsSync(`${this.projectPath}/plugins`);
1803
+ fs_extra_1.default.copySync(pluginSourcePath, pluginDestPath);
1804
+ console.log(`Copied pull to refresh plugin to ${pluginDestPath}`);
1805
+ if (!packageJson.dependencies) {
1806
+ packageJson.dependencies = {};
1807
+ }
1808
+ if (packageJson.dependencies[pluginName] !== 'file:./plugins/expo-pull-to-refresh') {
1809
+ packageJson.dependencies[pluginName] = 'file:./plugins/expo-pull-to-refresh';
1810
+ console.log(`Added ${pluginName} to package.json`);
1811
+ }
1812
+ }
1813
+ else {
1814
+ if (fs_extra_1.default.existsSync(pluginDestPath)) {
1815
+ fs_extra_1.default.removeSync(pluginDestPath);
1816
+ const pluginsDir = `${this.projectPath}/plugins`;
1817
+ if (fs_extra_1.default.existsSync(pluginsDir) && fs_extra_1.default.readdirSync(pluginsDir).length === 0) {
1818
+ fs_extra_1.default.removeSync(pluginsDir);
1819
+ }
1820
+ }
1821
+ if (packageJson.dependencies && packageJson.dependencies[pluginName]) {
1822
+ delete packageJson.dependencies[pluginName];
1823
+ console.log(`Removed ${pluginName} from package.json`);
1824
+ }
1825
+ }
1826
+ fs_extra_1.default.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 4));
1827
+ }
1558
1828
  async addCustomPluginsToPackageJson() {
1559
1829
  if (this.incBuilder) {
1560
1830
  console.log(`Adding custom plugins.`);
@@ -1571,70 +1841,44 @@ class AppGenerator {
1571
1841
  let plugins = config.plugins;
1572
1842
  let data = fs_extra_1.default.readFileSync(`${this.projectPath}/package.json`, 'utf-8');
1573
1843
  const jsonData = JSON.parse(data);
1574
- let shouldNpmInstall = false;
1575
- const prefabs = [
1576
- ...Object.keys((this.transpiledComponents.prefabs || {}))
1577
- ];
1578
- if (prefabs.length > 0) {
1579
- prefabs.map(async (prefab) => {
1580
- await this.projectService.getPrefabInfo(prefab).then(info => {
1581
- var _a;
1582
- (_a = info.config["resources"]["scripts"]) === null || _a === void 0 ? void 0 : _a.map((script) => {
1583
- if (script.includes('npm://')) {
1584
- if (jsonData['dependencies'][script.match(/[\/]+(.*?)@\d/)[1]] && semver_1.default.lt(jsonData['dependencies'][script.match(/[\/]+(.*?)@\d/)[1]], script.match('.*@(.*?)$')[1])) {
1585
- console.log("adding new version " + script.match('.*@(.*?)$')[1] + "for script.match(/[\/]+(.*?)@\d/)![1] dependency");
1586
- jsonData['dependencies'][script.match(/[\/]+(.*?)@\d/)[1]] = script.match('.*@(.*?)$')[1];
1587
- }
1588
- else {
1589
- jsonData['dependencies'][script.match(/[\/]+(.*?)@\d/)[1]] = script.match('.*@(.*?)$')[1];
1590
- }
1591
- }
1592
- });
1593
- });
1594
- plugins.forEach((p) => {
1595
- if (p.spec) {
1596
- if (p.spec.includes('tgz')) {
1597
- jsonData['dependencies'][p.name] = 'file:' + p.spec;
1598
- shouldNpmInstall = true;
1599
- }
1600
- else if (semver_1.default.valid(p.spec) && !semver_1.default.lt(p.spec, jsonData['dependencies'][p.name] || '0.0.0')) {
1601
- jsonData['dependencies'][p.name] = p.spec;
1602
- shouldNpmInstall = true;
1603
- }
1604
- else if (!semver_1.default.valid(p.spec)) {
1605
- jsonData['dependencies'][p.name] = p.spec;
1606
- shouldNpmInstall = true;
1607
- }
1608
- }
1609
- });
1610
- if (shouldNpmInstall) {
1611
- this.shouldNpmInstall = true;
1612
- }
1613
- fs_extra_1.default.writeFileSync(`${this.projectPath}/package.json`, JSON.stringify(jsonData, null, 4));
1614
- });
1615
- }
1616
- else {
1617
- plugins.forEach((p) => {
1618
- if (p.spec) {
1619
- if (p.spec.includes('tgz')) {
1620
- jsonData['dependencies'][p.name] = 'file:' + p.spec;
1621
- shouldNpmInstall = true;
1622
- }
1623
- else if (semver_1.default.valid(p.spec) && !semver_1.default.lt(p.spec, jsonData['dependencies'][p.name] || '0.0.0')) {
1624
- jsonData['dependencies'][p.name] = p.spec;
1625
- shouldNpmInstall = true;
1626
- }
1627
- else if (!semver_1.default.valid(p.spec)) {
1628
- jsonData['dependencies'][p.name] = p.spec;
1629
- shouldNpmInstall = true;
1630
- }
1844
+ // Plugins added by an earlier build and since removed from wm_rn_config.json are dropped from package.json.
1845
+ const addedPluginsPath = `${this.projectPath}/.wm-config-plugins.json`;
1846
+ const configured = plugins.filter((p) => p.spec).map((p) => p.name);
1847
+ const templateDependencies = fs_extra_1.default.readJSONSync(`${__dirname}/templates/project/package.json`).dependencies;
1848
+ // Only a record of earlier builds: an unreadable one just means nothing is removed this time.
1849
+ (fs_extra_1.default.readJSONSync(addedPluginsPath, { throws: false }) || [])
1850
+ .filter((name) => !configured.includes(name) && !templateDependencies[name] && jsonData.dependencies[name])
1851
+ .forEach((name) => {
1852
+ console.log(`Removing plugin ${name}: no longer in wm_rn_config.json`);
1853
+ delete jsonData.dependencies[name];
1854
+ this.shouldNpmInstall = true;
1855
+ });
1856
+ fs_extra_1.default.writeJSONSync(addedPluginsPath, configured);
1857
+ // Every prefab's npm:// package is in package.json before the compatibility check runs.
1858
+ await Promise.all(Object.keys(this.transpiledComponents.prefabs || {}).map((prefab) => this.projectService.getPrefabInfo(prefab).then(info => {
1859
+ var _a;
1860
+ (_a = info.config["resources"]["scripts"]) === null || _a === void 0 ? void 0 : _a.forEach((script) => {
1861
+ if (script.includes('npm://')) {
1862
+ jsonData['dependencies'][script.match(/[\/]+(.*?)@\d/)[1]] = script.match('.*@(.*?)$')[1];
1631
1863
  }
1632
1864
  });
1633
- if (shouldNpmInstall) {
1634
- this.shouldNpmInstall = true;
1865
+ })));
1866
+ plugins.forEach((p) => {
1867
+ if (!p.spec) {
1868
+ return;
1635
1869
  }
1636
- fs_extra_1.default.writeFileSync(`${this.projectPath}/package.json`, JSON.stringify(jsonData, null, 4));
1637
- }
1870
+ if (p.spec.includes('tgz')) {
1871
+ jsonData['dependencies'][p.name] = 'file:' + p.spec;
1872
+ }
1873
+ else if (!semver_1.default.valid(p.spec) || !semver_1.default.lt(p.spec, semver_1.default.valid(jsonData['dependencies'][p.name]) || '0.0.0')) {
1874
+ jsonData['dependencies'][p.name] = p.spec;
1875
+ }
1876
+ else {
1877
+ return;
1878
+ }
1879
+ this.shouldNpmInstall = true;
1880
+ });
1881
+ fs_extra_1.default.writeFileSync(`${this.projectPath}/package.json`, JSON.stringify(jsonData, null, 4));
1638
1882
  }
1639
1883
  async generateFoundationTheme() {
1640
1884
  await new app_override_css_generator_1.AppOverrideCSSGenerator(this.projectService.path).generate();
@@ -1643,7 +1887,7 @@ class AppGenerator {
1643
1887
  const themePath = `${this.projectService.path}/design-tokens/foundation`;
1644
1888
  try {
1645
1889
  const foundationPath = `${__dirname}/templates/foundation-theme/dist`;
1646
- fs_extra_1.default.copySync(foundationPath, themePath);
1890
+ fs_extra_1.default.copySync(foundationPath, themePath, { preserveTimestamps: true });
1647
1891
  }
1648
1892
  catch (error) {
1649
1893
  console.error(error);
@@ -1743,10 +1987,38 @@ class AppGenerator {
1743
1987
  });
1744
1988
  }).then(() => this.generateResourceResolver());
1745
1989
  }
1990
+ timed(label, fn) {
1991
+ console.time(`App creation: ${label}`);
1992
+ return Promise.resolve(fn()).finally(() => console.timeEnd(`App creation: ${label}`));
1993
+ }
1746
1994
  async generateApp() {
1747
1995
  this.rnConfig = await this.projectService.getRNConfig().then(data => JSON.parse(data));
1748
- this.incBuilder || fs_extra_1.default.copySync(__dirname + '/templates/project', this.projectPath);
1749
- return this.generatePagesAndPartials()
1996
+ const customPackagesChanged = !this.incBuilder || this.incBuilder.isConfigModified() || this.incBuilder.isPrefabModified();
1997
+ // templates/project/metro/ (the split-bundle build) is only needed by
1998
+ // the web-preview profile; every other profile skips it.
1999
+ const templatesRoot = __dirname + '/templates/project';
2000
+ if (this.incBuilder && this.isWebPreview) {
2001
+ this.timed('copy templates: sync', () => (0, web_preview_templates_1.syncWebPreviewTemplates)(templatesRoot, this.projectPath));
2002
+ }
2003
+ this.incBuilder || this.timed('copy templates', () => fs_extra_1.default.copySync(templatesRoot, this.projectPath, {
2004
+ filter: (src) => {
2005
+ const rel = path_2.default.relative(templatesRoot, src);
2006
+ // The template lock is input for the rn-app package, not a project file: copying it
2007
+ // would make copyPackageLockJson skip the rn-app lock the profile points at.
2008
+ if (rel === 'package-lock.json') {
2009
+ return false;
2010
+ }
2011
+ if (this.isWebPreview) {
2012
+ return true;
2013
+ }
2014
+ return rel !== 'metro' && !rel.startsWith(`metro${path_1.sep}`);
2015
+ }
2016
+ }));
2017
+ const customMetroConfig = await this.projectService.getCustomMetroConfig();
2018
+ if (customMetroConfig) {
2019
+ (0, utils_1.writeFile)(`${this.projectPath}/custommetro.config.js`, customMetroConfig);
2020
+ }
2021
+ return this.timed('pages+partials', () => this.generatePagesAndPartials())
1750
2022
  .then(() => this.incBuilder && this.generateAllPrefabComponents())
1751
2023
  .then(() => !this.incBuilder || this.incBuilder.isResourceModified())
1752
2024
  .then((build) => (build && this.generateResourceResolver()))
@@ -1768,6 +2040,8 @@ class AppGenerator {
1768
2040
  .then((build) => (build && this.generateFonts()))
1769
2041
  .then(() => !this.incBuilder || this.incBuilder.isConfigModified())
1770
2042
  .then((build) => (build && this.generateRNConfig()))
2043
+ .then(() => !this.incBuilder || this.incBuilder.isConfigModified() || this.incBuilder.isResourceModified())
2044
+ .then((build) => (build && this.generateGlobalConfig()))
1771
2045
  .then(() => !this.incBuilder || this.incBuilder.isFormatterModified())
1772
2046
  .then((build) => (build && this.generateFormatters()))
1773
2047
  .then(() => !this.incBuilder || this.incBuilder.isConfigModified())
@@ -1775,7 +2049,7 @@ class AppGenerator {
1775
2049
  .then(() => !this.incBuilder || this.incBuilder.isConfigModified())
1776
2050
  .then((build) => (build && this.generateBabelConfig()))
1777
2051
  .then(() => !this.incBuilder || this.incBuilder.isThemeModified() || this.incBuilder.isFoundationThemeModified())
1778
- .then((build) => (build && this.generateAppTheme()))
2052
+ .then((build) => (build && this.timed('theme', () => this.generateAppTheme())))
1779
2053
  .then(() => !this.incBuilder || this.incBuilder.isi18nModified())
1780
2054
  .then((build) => (build && this.copyi18nFiles()))
1781
2055
  .then(() => !this.incBuilder || this.incBuilder.isi18nModified())
@@ -1787,27 +2061,30 @@ class AppGenerator {
1787
2061
  }
1788
2062
  }).then(() => !this.incBuilder)
1789
2063
  .then((build) => (this.prepareDeviceOperationLoader()))
1790
- .then(() => !this.incBuilder
1791
- || this.incBuilder.isConfigModified()
1792
- || this.incBuilder.isPrefabModified())
1793
- .then((build) => (build && this.addCustomPluginsToPackageJson()))
1794
- .then(() => this.mergePackageJson())
2064
+ .then(() => customPackagesChanged ? this.addCustomPluginsToPackageJson() : undefined)
2065
+ .then(() => this.timed('package.json merge (incl. wmx-component npm install+build)', () => this.mergePackageJson()))
1795
2066
  .then(() => this.copyPackageLockJson())
2067
+ .then(() => customPackagesChanged ? this.timed('custom package report', () => this.reportCustomDependencies()) : undefined)
1796
2068
  .then(() => this.checkWidgetUsageInComponentFiles())
1797
2069
  .then(() => this.checkPackageUsageInJSFiles())
1798
- .then(() => !this.incBuilder || this.shouldDoUnwantedPackagesCleanup)
2070
+ // Web preview: mergePackageJson re-adds the project's package.json override every build, which brings
2071
+ // back packages an earlier build removed, so the removal (~0.2s) has to run every build too.
2072
+ .then(() => !this.incBuilder || this.shouldDoUnwantedPackagesCleanup || this.isWebPreview)
1799
2073
  .then((removePackages) => {
1800
2074
  if (removePackages) {
1801
- return this.removeUnusedPackages();
2075
+ return this.timed('remove unused packages', () => this.removeUnusedPackages());
1802
2076
  }
1803
2077
  else {
1804
2078
  return Promise.resolve();
1805
2079
  }
1806
2080
  })
1807
2081
  .then(() => !this.incBuilder)
1808
- .then((build) => (build && this.prettify()))
2082
+ .then((build) => (build
2083
+ && !(this.isWebPreview && process.env.WM_PREVIEW_PRETTIFY !== '1')
2084
+ && this.prettify()))
1809
2085
  .then(() => this.projectService.copyNpmPackages(this.projectPath))
1810
2086
  .then(() => this.copyScreenCapturePluginIfNeeded())
2087
+ .then(() => this.copyPullToRefreshPluginIfNeeded())
1811
2088
  .then(() => console.log('code generated at ' + this.projectPath));
1812
2089
  }
1813
2090
  generateFragment(name) {
@@ -1826,7 +2103,9 @@ class AppGenerator {
1826
2103
  })
1827
2104
  .then(() => this.generatePageConfig(pageConfigs))
1828
2105
  .then(() => this.generatePartialConfig(pageConfigs))
1829
- .then(() => this.prettify(`**/${name}/**/*.js`))
2106
+ .then(() => (this.isWebPreview && process.env.WM_PREVIEW_PRETTIFY !== '1')
2107
+ ? undefined
2108
+ : this.prettify(`**/${name}/**/*.js`))
1830
2109
  .then(() => console.log('code generated at ' + this.projectPath));
1831
2110
  }
1832
2111
  ;