@lwrjs/static 0.11.0-alpha.6 → 0.11.0-alpha.8

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.
@@ -38,14 +38,17 @@ var StaticBundleProvider = class {
38
38
  throw new Error(`[${this.name}] Site metadata was not found`);
39
39
  }
40
40
  this.siteBundles = context.siteMetadata.getSiteBundles();
41
+ this.debugSiteBundles = context.siteMetadata.getDebugSiteBundles();
41
42
  this.siteRootDir = context.siteMetadata.getSiteRootDir();
42
43
  this.bundleConfig = context.config.bundleConfig;
43
44
  this.i18n = context.config.i18n;
44
45
  }
45
46
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
46
47
  const {specifier, name, namespace, version} = moduleId;
47
- const localeId = runtimeParams?.locale || runtimeEnvironment.defaultLocale;
48
- const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, this.siteBundles, localeId, this.i18n);
48
+ const {debug, defaultLocale} = runtimeEnvironment;
49
+ const localeId = runtimeParams?.locale || defaultLocale;
50
+ const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
51
+ const metadata = (0, import_static_utils.getLocalizedBundle)(specifier, siteBundles, localeId, this.i18n);
49
52
  if (!metadata) {
50
53
  if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
51
54
  import_shared_utils.logger.warn(`[${this.name}] did not find requested specifier ${specifier}`);
@@ -37,10 +37,12 @@ var StaticResourceProvider = class {
37
37
  }
38
38
  this.resourceRegistry = context.resourceRegistry;
39
39
  this.siteResources = context.siteMetadata.getSiteResources();
40
+ this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
40
41
  this.siteRootDir = context.siteMetadata.getSiteRootDir();
41
42
  }
42
- async getResource(resourceIdentity, _runtimeEnvironment) {
43
- const metadata = this.siteResources.resources[resourceIdentity.specifier];
43
+ async getResource(resourceIdentity, runtimeEnvironment) {
44
+ const {debug} = runtimeEnvironment;
45
+ const metadata = debug && this.debugSiteResources ? this.debugSiteResources.resources[resourceIdentity.specifier] : this.siteResources.resources[resourceIdentity.specifier];
44
46
  if (!metadata) {
45
47
  import_shared_utils.logger.warn(`[${this.name}] Did not find requested specifier ${resourceIdentity.specifier}`);
46
48
  return void 0;
@@ -31,14 +31,18 @@ var import_fs_extra = __toModule(require("fs-extra"));
31
31
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
32
32
  var SITE_METADATA_PATH = ".metadata";
33
33
  var STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata.json");
34
+ var DEBUG_STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata-debug.json");
34
35
  var STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata.json");
36
+ var DEBUG_STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata-debug.json");
35
37
  var STATIC_ASSET_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/asset-metadata.json");
36
38
  var SiteMetadataImpl = class {
37
39
  constructor(options) {
38
40
  this.options = options;
39
- this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
40
- this.siteResources = this.readStaticResourceMetadata(options.rootDir);
41
- this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
41
+ this.siteBundles = this.readStaticBundleMetadata(options.rootDir, STATIC_BUNDLE_METADATA_PATH);
42
+ this.debugSiteBundles = this.readStaticBundleMetadata(options.rootDir, DEBUG_STATIC_BUNDLE_METADATA_PATH);
43
+ this.siteResources = this.readStaticResourceMetadata(options.rootDir, STATIC_RESOURCE_METADATA_PATH);
44
+ this.debugSiteResources = this.readStaticResourceMetadata(options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
45
+ this.siteAssets = this.readStaticAssetsMetadata(options.rootDir, STATIC_ASSET_METADATA_PATH);
42
46
  }
43
47
  getSiteRootDir() {
44
48
  return this.options.rootDir;
@@ -46,9 +50,15 @@ var SiteMetadataImpl = class {
46
50
  getSiteBundles() {
47
51
  return this.siteBundles;
48
52
  }
53
+ getDebugSiteBundles() {
54
+ return this.debugSiteBundles;
55
+ }
49
56
  getSiteResources() {
50
57
  return this.siteResources;
51
58
  }
59
+ getDebugSiteResources() {
60
+ return this.debugSiteResources;
61
+ }
52
62
  getSiteAssets() {
53
63
  return this.siteAssets;
54
64
  }
@@ -60,8 +70,12 @@ var SiteMetadataImpl = class {
60
70
  }
61
71
  const bundleMetadataPath = import_path.default.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
62
72
  await import_fs_extra.default.writeJSON(bundleMetadataPath, this.siteBundles, {spaces: 2});
73
+ const debugBundleMetadataPath = import_path.default.join(this.options.rootDir, DEBUG_STATIC_BUNDLE_METADATA_PATH);
74
+ await import_fs_extra.default.writeJSON(debugBundleMetadataPath, this.debugSiteBundles, {spaces: 2});
63
75
  const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
64
76
  await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
77
+ const debugResourceMetadataPath = import_path.default.join(this.options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
78
+ await import_fs_extra.default.writeJSON(debugResourceMetadataPath, this.siteResources, {spaces: 2});
65
79
  const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
66
80
  return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
67
81
  } catch (err) {
@@ -69,11 +83,11 @@ var SiteMetadataImpl = class {
69
83
  console.error(err);
70
84
  }
71
85
  }
72
- readStaticBundleMetadata(staticRoot) {
86
+ readStaticBundleMetadata(staticRoot, metadataPath) {
73
87
  let bundleMetadataPath;
74
88
  let siteBundles = {bundles: {}};
75
89
  try {
76
- bundleMetadataPath = import_path.default.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
90
+ bundleMetadataPath = import_path.default.join(staticRoot, metadataPath);
77
91
  const savedMetadata = import_fs_extra.default.readJSONSync(bundleMetadataPath);
78
92
  siteBundles = savedMetadata;
79
93
  } catch (error) {
@@ -85,11 +99,11 @@ var SiteMetadataImpl = class {
85
99
  }
86
100
  return siteBundles;
87
101
  }
88
- readStaticResourceMetadata(staticRoot) {
102
+ readStaticResourceMetadata(staticRoot, metadataPath) {
89
103
  let resourceMetadataPath;
90
104
  let siteResources = {resources: {}};
91
105
  try {
92
- resourceMetadataPath = import_path.default.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
106
+ resourceMetadataPath = import_path.default.join(staticRoot, metadataPath);
93
107
  const savedMetadata = import_fs_extra.default.readJSONSync(resourceMetadataPath);
94
108
  siteResources = savedMetadata;
95
109
  } catch (error) {
@@ -101,13 +115,13 @@ var SiteMetadataImpl = class {
101
115
  }
102
116
  return siteResources;
103
117
  }
104
- readStaticAssetsMetadata(staticRoot) {
118
+ readStaticAssetsMetadata(staticRoot, metadataPath) {
105
119
  let assetMetadataPath;
106
120
  let siteAssets = {
107
121
  assets: {}
108
122
  };
109
123
  try {
110
- assetMetadataPath = import_path.default.join(staticRoot, STATIC_ASSET_METADATA_PATH);
124
+ assetMetadataPath = import_path.default.join(staticRoot, metadataPath);
111
125
  siteAssets = import_fs_extra.default.readJSONSync(assetMetadataPath);
112
126
  } catch (error) {
113
127
  if (error.code === "ENOENT") {
@@ -2,6 +2,7 @@ import type { AbstractModuleId, BundleDefinition, BundleProvider, ProviderContex
2
2
  export default class StaticBundleProvider implements BundleProvider {
3
3
  name: string;
4
4
  siteBundles: import("@lwrjs/types").SiteBundles;
5
+ debugSiteBundles?: import("@lwrjs/types").SiteBundles | undefined;
5
6
  siteRootDir: string;
6
7
  bundleConfig: import("@lwrjs/types").BundleConfig;
7
8
  i18n: import("@lwrjs/types").I18NConfig;
@@ -10,14 +10,17 @@ export default class StaticBundleProvider {
10
10
  throw new Error(`[${this.name}] Site metadata was not found`);
11
11
  }
12
12
  this.siteBundles = context.siteMetadata.getSiteBundles();
13
+ this.debugSiteBundles = context.siteMetadata.getDebugSiteBundles();
13
14
  this.siteRootDir = context.siteMetadata.getSiteRootDir();
14
15
  this.bundleConfig = context.config.bundleConfig;
15
16
  this.i18n = context.config.i18n;
16
17
  }
17
18
  async bundle(moduleId, runtimeEnvironment, runtimeParams) {
18
19
  const { specifier, name, namespace, version } = moduleId;
19
- const localeId = (runtimeParams?.locale || runtimeEnvironment.defaultLocale);
20
- const metadata = getLocalizedBundle(specifier, this.siteBundles, localeId, this.i18n);
20
+ const { debug, defaultLocale } = runtimeEnvironment;
21
+ const localeId = (runtimeParams?.locale || defaultLocale);
22
+ const siteBundles = debug && this.debugSiteBundles ? this.debugSiteBundles : this.siteBundles;
23
+ const metadata = getLocalizedBundle(specifier, siteBundles, localeId, this.i18n);
21
24
  if (!metadata) {
22
25
  // ignore ssr module requests
23
26
  if (!specifier.startsWith(LWR_SSR_BUNDLE_PREFIX)) {
@@ -2,9 +2,10 @@ import type { BootstrapRuntimeEnvironment, ProviderContext, ResourceDefinition,
2
2
  export default class StaticResourceProvider implements ResourceProvider {
3
3
  name: string;
4
4
  siteResources: import("@lwrjs/types").SiteResources;
5
+ debugSiteResources: import("@lwrjs/types").SiteResources;
5
6
  siteRootDir: string;
6
7
  resourceRegistry: import("@lwrjs/types").PublicResourceRegistry;
7
8
  constructor(_config: {}, context: ProviderContext);
8
- getResource<Identifier extends ResourceIdentifier, RuntimeEnvironment extends BootstrapRuntimeEnvironment>(resourceIdentity: Identifier, _runtimeEnvironment: RuntimeEnvironment): Promise<ResourceDefinition | undefined>;
9
+ getResource<Identifier extends ResourceIdentifier, RuntimeEnvironment extends BootstrapRuntimeEnvironment>(resourceIdentity: Identifier, runtimeEnvironment: RuntimeEnvironment): Promise<ResourceDefinition | undefined>;
9
10
  }
10
11
  //# sourceMappingURL=static-resource-provider.d.ts.map
@@ -9,10 +9,14 @@ export default class StaticResourceProvider {
9
9
  }
10
10
  this.resourceRegistry = context.resourceRegistry;
11
11
  this.siteResources = context.siteMetadata.getSiteResources();
12
+ this.debugSiteResources = context.siteMetadata.getDebugSiteResources();
12
13
  this.siteRootDir = context.siteMetadata.getSiteRootDir();
13
14
  }
14
- async getResource(resourceIdentity, _runtimeEnvironment) {
15
- const metadata = this.siteResources.resources[resourceIdentity.specifier];
15
+ async getResource(resourceIdentity, runtimeEnvironment) {
16
+ const { debug } = runtimeEnvironment;
17
+ const metadata = debug && this.debugSiteResources
18
+ ? this.debugSiteResources.resources[resourceIdentity.specifier]
19
+ : this.siteResources.resources[resourceIdentity.specifier];
16
20
  if (!metadata) {
17
21
  logger.warn(`[${this.name}] Did not find requested specifier ${resourceIdentity.specifier}`);
18
22
  return undefined;
@@ -5,12 +5,16 @@ type Options = {
5
5
  export declare class SiteMetadataImpl implements SiteMetadata {
6
6
  private options;
7
7
  private siteBundles;
8
+ private debugSiteBundles;
8
9
  private siteResources;
10
+ private debugSiteResources;
9
11
  private siteAssets;
10
12
  constructor(options: Options);
11
13
  getSiteRootDir(): string;
12
14
  getSiteBundles(): SiteBundles;
15
+ getDebugSiteBundles(): SiteBundles;
13
16
  getSiteResources(): SiteResources;
17
+ getDebugSiteResources(): SiteResources;
14
18
  getSiteAssets(): SiteAssets;
15
19
  persistSiteMetadata(): Promise<void>;
16
20
  private readStaticBundleMetadata;
@@ -3,14 +3,18 @@ import fs from 'fs-extra';
3
3
  import { logger } from '@lwrjs/shared-utils';
4
4
  const SITE_METADATA_PATH = '.metadata';
5
5
  const STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata.json');
6
+ const DEBUG_STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata-debug.json');
6
7
  const STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata.json');
8
+ const DEBUG_STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata-debug.json');
7
9
  const STATIC_ASSET_METADATA_PATH = path.join(SITE_METADATA_PATH, '/asset-metadata.json');
8
10
  export class SiteMetadataImpl {
9
11
  constructor(options) {
10
12
  this.options = options;
11
- this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
12
- this.siteResources = this.readStaticResourceMetadata(options.rootDir);
13
- this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
13
+ this.siteBundles = this.readStaticBundleMetadata(options.rootDir, STATIC_BUNDLE_METADATA_PATH);
14
+ this.debugSiteBundles = this.readStaticBundleMetadata(options.rootDir, DEBUG_STATIC_BUNDLE_METADATA_PATH);
15
+ this.siteResources = this.readStaticResourceMetadata(options.rootDir, STATIC_RESOURCE_METADATA_PATH);
16
+ this.debugSiteResources = this.readStaticResourceMetadata(options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
17
+ this.siteAssets = this.readStaticAssetsMetadata(options.rootDir, STATIC_ASSET_METADATA_PATH);
14
18
  }
15
19
  getSiteRootDir() {
16
20
  return this.options.rootDir;
@@ -18,9 +22,15 @@ export class SiteMetadataImpl {
18
22
  getSiteBundles() {
19
23
  return this.siteBundles;
20
24
  }
25
+ getDebugSiteBundles() {
26
+ return this.debugSiteBundles;
27
+ }
21
28
  getSiteResources() {
22
29
  return this.siteResources;
23
30
  }
31
+ getDebugSiteResources() {
32
+ return this.debugSiteResources;
33
+ }
24
34
  getSiteAssets() {
25
35
  return this.siteAssets;
26
36
  }
@@ -34,9 +44,15 @@ export class SiteMetadataImpl {
34
44
  // Save Bundle Metadata
35
45
  const bundleMetadataPath = path.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
36
46
  await fs.writeJSON(bundleMetadataPath, this.siteBundles, { spaces: 2 });
47
+ // Save Debug Bundle Metadata
48
+ const debugBundleMetadataPath = path.join(this.options.rootDir, DEBUG_STATIC_BUNDLE_METADATA_PATH);
49
+ await fs.writeJSON(debugBundleMetadataPath, this.debugSiteBundles, { spaces: 2 });
37
50
  // Save Resource Metadata
38
51
  const resourceMetadataPath = path.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
39
52
  await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
53
+ // Save Debug Resource Metadata
54
+ const debugResourceMetadataPath = path.join(this.options.rootDir, DEBUG_STATIC_RESOURCE_METADATA_PATH);
55
+ await fs.writeJSON(debugResourceMetadataPath, this.siteResources, { spaces: 2 });
40
56
  // Save Resource Metadata
41
57
  const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
42
58
  return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
@@ -46,11 +62,11 @@ export class SiteMetadataImpl {
46
62
  console.error(err);
47
63
  }
48
64
  }
49
- readStaticBundleMetadata(staticRoot) {
65
+ readStaticBundleMetadata(staticRoot, metadataPath) {
50
66
  let bundleMetadataPath;
51
67
  let siteBundles = { bundles: {} };
52
68
  try {
53
- bundleMetadataPath = path.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
69
+ bundleMetadataPath = path.join(staticRoot, metadataPath);
54
70
  const savedMetadata = fs.readJSONSync(bundleMetadataPath);
55
71
  siteBundles = savedMetadata;
56
72
  }
@@ -67,11 +83,11 @@ export class SiteMetadataImpl {
67
83
  /**
68
84
  * Read the metadata about the pre-built resources of the current site.
69
85
  */
70
- readStaticResourceMetadata(staticRoot) {
86
+ readStaticResourceMetadata(staticRoot, metadataPath) {
71
87
  let resourceMetadataPath;
72
88
  let siteResources = { resources: {} };
73
89
  try {
74
- resourceMetadataPath = path.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
90
+ resourceMetadataPath = path.join(staticRoot, metadataPath);
75
91
  const savedMetadata = fs.readJSONSync(resourceMetadataPath);
76
92
  siteResources = savedMetadata;
77
93
  }
@@ -88,13 +104,13 @@ export class SiteMetadataImpl {
88
104
  /**
89
105
  * Read the metadata about the pre-built assets of the current site.
90
106
  */
91
- readStaticAssetsMetadata(staticRoot) {
107
+ readStaticAssetsMetadata(staticRoot, metadataPath) {
92
108
  let assetMetadataPath;
93
109
  let siteAssets = {
94
110
  assets: {},
95
111
  };
96
112
  try {
97
- assetMetadataPath = path.join(staticRoot, STATIC_ASSET_METADATA_PATH);
113
+ assetMetadataPath = path.join(staticRoot, metadataPath);
98
114
  siteAssets = fs.readJSONSync(assetMetadataPath);
99
115
  }
100
116
  catch (error) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.11.0-alpha.6",
7
+ "version": "0.11.0-alpha.8",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -48,10 +48,10 @@
48
48
  "build/**/*.d.ts"
49
49
  ],
50
50
  "dependencies": {
51
- "@lwrjs/shared-utils": "0.11.0-alpha.6"
51
+ "@lwrjs/shared-utils": "0.11.0-alpha.8"
52
52
  },
53
53
  "devDependencies": {
54
- "@lwrjs/types": "0.11.0-alpha.6",
54
+ "@lwrjs/types": "0.11.0-alpha.8",
55
55
  "@types/express": "^4.17.17",
56
56
  "jest": "^26.6.3",
57
57
  "jest-express": "^1.12.0",
@@ -64,5 +64,5 @@
64
64
  "volta": {
65
65
  "extends": "../../../package.json"
66
66
  },
67
- "gitHead": "571d4bac5650765aa818bcb9d5ed752a8cf041af"
67
+ "gitHead": "bba3cfa996e84ee702f287e7e7b6361b807434db"
68
68
  }