@lwrjs/core 0.6.0-alpha.15 → 0.6.0-alpha.16

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.
@@ -159,9 +159,11 @@ var SiteGenerator = class {
159
159
  const filePath = (0, import_path.join)(dir, "index.html");
160
160
  const fileLocalePath = (0, import_path.join)(localeDir, "index.html");
161
161
  if (siteConfig.locale.toLowerCase().startsWith("en")) {
162
+ siteConfig.viewPaths.add(filePath);
162
163
  await (0, import_stream.writeResponse)(context, filePath);
163
164
  }
164
165
  (0, import_dir.createDir)(localeDir);
166
+ siteConfig.viewPaths.add(fileLocalePath);
165
167
  await (0, import_stream.writeResponse)(context, fileLocalePath);
166
168
  const viewDefinition = context.fs?.metadata?.viewDefinition;
167
169
  if (viewDefinition) {
@@ -286,6 +288,7 @@ var SiteGenerator = class {
286
288
  const experimentalFeatures = this.filterExperimentalFeatures();
287
289
  return {
288
290
  outputDir,
291
+ viewPaths: new Set(),
289
292
  visitedUrls: new Set(),
290
293
  locale,
291
294
  urlRewriteMap,
@@ -309,13 +312,26 @@ var SiteGenerator = class {
309
312
  const index = additionalImportMetadata.index ? JSON.stringify(additionalImportMetadata.index) : "{}";
310
313
  const initIndex = `if (!globalThis.LWR.index) { globalThis.LWR.index = {}; }`;
311
314
  const mergeIndex = `Object.assign(globalThis.LWR.index, ${index})`;
312
- import_fs_extra.default.appendFileSync(siteConfig.viewConfigPath, `
315
+ const oldConfig = import_fs_extra.default.readFileSync(siteConfig.viewConfigPath, "utf-8");
316
+ const newConfig = `${oldConfig}
313
317
  // Appended by Static Site Generator
314
318
  ${initImports}
315
319
  ${mergeImports}
316
320
  ${initIndex}
317
321
  ${mergeIndex}
318
- `);
322
+ `;
323
+ const configHash = (0, import_shared_utils.hashContent)(newConfig);
324
+ const sigRegex = /\/s\/[a-z0-9]+\/config\.js/i;
325
+ const configSuffix = `/s/${configHash}/config.js`;
326
+ const newConfigPath = siteConfig.viewConfigPath.replace(sigRegex, configSuffix);
327
+ import_fs_extra.default.mkdirSync((0, import_path.dirname)(newConfigPath), {recursive: true});
328
+ import_fs_extra.default.writeFileSync(newConfigPath, newConfig, "utf-8");
329
+ import_fs_extra.default.rmSync(siteConfig.viewConfigPath);
330
+ siteConfig.viewPaths.forEach((path) => {
331
+ const oldDoc = import_fs_extra.default.readFileSync(path, "utf-8");
332
+ const newDoc = oldDoc.toString().replace(sigRegex, configSuffix);
333
+ import_fs_extra.default.writeFileSync(path, newDoc, "utf-8");
334
+ });
319
335
  }
320
336
  }
321
337
  };
@@ -1,4 +1,4 @@
1
- import { getSpecifier, getExperimentalFeatures } from '@lwrjs/shared-utils';
1
+ import { getSpecifier, getExperimentalFeatures, hashContent } from '@lwrjs/shared-utils';
2
2
  import { join, dirname, extname } from 'path';
3
3
  import fs from 'fs-extra';
4
4
  import { writeResponse } from './utils/stream.js';
@@ -230,10 +230,12 @@ export default class SiteGenerator {
230
230
  // Default Path (only write once)
231
231
  // The default locale is english
232
232
  if (siteConfig.locale.toLowerCase().startsWith('en')) {
233
+ siteConfig.viewPaths.add(filePath);
233
234
  await writeResponse(context, filePath);
234
235
  }
235
236
  // Language path (always write out)
236
237
  createDir(localeDir);
238
+ siteConfig.viewPaths.add(fileLocalePath);
237
239
  await writeResponse(context, fileLocalePath);
238
240
  // Get the metadata
239
241
  const viewDefinition = context.fs?.metadata?.viewDefinition;
@@ -418,6 +420,7 @@ export default class SiteGenerator {
418
420
  const experimentalFeatures = this.filterExperimentalFeatures();
419
421
  return {
420
422
  outputDir,
423
+ viewPaths: new Set(),
421
424
  visitedUrls: new Set(),
422
425
  locale,
423
426
  urlRewriteMap,
@@ -443,6 +446,7 @@ export default class SiteGenerator {
443
446
  siteConfig.viewConfigPath &&
444
447
  additionalImportMetadata?.imports &&
445
448
  Object.keys(additionalImportMetadata.imports).length > 0) {
449
+ // Build and stringify the new import metadata
446
450
  const imports = additionalImportMetadata.imports
447
451
  ? JSON.stringify(additionalImportMetadata.imports)
448
452
  : '{}';
@@ -453,7 +457,23 @@ export default class SiteGenerator {
453
457
  : '{}';
454
458
  const initIndex = `if (!globalThis.LWR.index) { globalThis.LWR.index = {}; }`;
455
459
  const mergeIndex = `Object.assign(globalThis.LWR.index, ${index})`;
456
- fs.appendFileSync(siteConfig.viewConfigPath, `\n// Appended by Static Site Generator\n${initImports}\n${mergeImports}\n${initIndex}\n${mergeIndex}\n`);
460
+ // Read in the old config and append the new import metadata
461
+ const oldConfig = fs.readFileSync(siteConfig.viewConfigPath, 'utf-8');
462
+ const newConfig = `${oldConfig}\n// Appended by Static Site Generator\n${initImports}\n${mergeImports}\n${initIndex}\n${mergeIndex}\n`;
463
+ const configHash = hashContent(newConfig);
464
+ // Write the updated config to a new filepath containing its hash signature, and delete the old config
465
+ const sigRegex = /\/s\/[a-z0-9]+\/config\.js/i;
466
+ const configSuffix = `/s/${configHash}/config.js`;
467
+ const newConfigPath = siteConfig.viewConfigPath.replace(sigRegex, configSuffix);
468
+ fs.mkdirSync(dirname(newConfigPath), { recursive: true }); // we know this dir does not exist
469
+ fs.writeFileSync(newConfigPath, newConfig, 'utf-8');
470
+ fs.rmSync(siteConfig.viewConfigPath);
471
+ // Update the config script src in the view document(s)
472
+ siteConfig.viewPaths.forEach((path) => {
473
+ const oldDoc = fs.readFileSync(path, 'utf-8');
474
+ const newDoc = oldDoc.toString().replace(sigRegex, configSuffix);
475
+ fs.writeFileSync(path, newDoc, 'utf-8');
476
+ });
457
477
  }
458
478
  }
459
479
  }
@@ -34,6 +34,7 @@ export interface ViewImportMetadata {
34
34
  }
35
35
  export interface SiteConfig {
36
36
  outputDir: string;
37
+ viewPaths: Set<string>;
37
38
  visitedUrls: Set<string>;
38
39
  locale: string;
39
40
  urlRewriteMap: Map<string, string>;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.6.0-alpha.15",
7
+ "version": "0.6.0-alpha.16",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -33,31 +33,31 @@
33
33
  "package.cjs"
34
34
  ],
35
35
  "dependencies": {
36
- "@lwrjs/app-service": "0.6.0-alpha.15",
37
- "@lwrjs/asset-registry": "0.6.0-alpha.15",
38
- "@lwrjs/asset-transformer": "0.6.0-alpha.15",
39
- "@lwrjs/base-template-engine": "0.6.0-alpha.15",
40
- "@lwrjs/base-view-provider": "0.6.0-alpha.15",
41
- "@lwrjs/base-view-transformer": "0.6.0-alpha.15",
42
- "@lwrjs/client-modules": "0.6.0-alpha.15",
43
- "@lwrjs/compiler": "0.6.0-alpha.15",
44
- "@lwrjs/diagnostics": "0.6.0-alpha.15",
45
- "@lwrjs/fs-asset-provider": "0.6.0-alpha.15",
46
- "@lwrjs/html-view-provider": "0.6.0-alpha.15",
47
- "@lwrjs/loader": "0.6.0-alpha.15",
48
- "@lwrjs/lwc-module-provider": "0.6.0-alpha.15",
49
- "@lwrjs/lwc-ssr": "0.6.0-alpha.15",
50
- "@lwrjs/markdown-view-provider": "0.6.0-alpha.15",
51
- "@lwrjs/module-bundler": "0.6.0-alpha.15",
52
- "@lwrjs/module-registry": "0.6.0-alpha.15",
53
- "@lwrjs/npm-module-provider": "0.6.0-alpha.15",
54
- "@lwrjs/nunjucks-view-provider": "0.6.0-alpha.15",
55
- "@lwrjs/o11y": "0.6.0-alpha.15",
56
- "@lwrjs/resource-registry": "0.6.0-alpha.15",
57
- "@lwrjs/router": "0.6.0-alpha.15",
58
- "@lwrjs/server": "0.6.0-alpha.15",
59
- "@lwrjs/shared-utils": "0.6.0-alpha.15",
60
- "@lwrjs/view-registry": "0.6.0-alpha.15",
36
+ "@lwrjs/app-service": "0.6.0-alpha.16",
37
+ "@lwrjs/asset-registry": "0.6.0-alpha.16",
38
+ "@lwrjs/asset-transformer": "0.6.0-alpha.16",
39
+ "@lwrjs/base-template-engine": "0.6.0-alpha.16",
40
+ "@lwrjs/base-view-provider": "0.6.0-alpha.16",
41
+ "@lwrjs/base-view-transformer": "0.6.0-alpha.16",
42
+ "@lwrjs/client-modules": "0.6.0-alpha.16",
43
+ "@lwrjs/compiler": "0.6.0-alpha.16",
44
+ "@lwrjs/diagnostics": "0.6.0-alpha.16",
45
+ "@lwrjs/fs-asset-provider": "0.6.0-alpha.16",
46
+ "@lwrjs/html-view-provider": "0.6.0-alpha.16",
47
+ "@lwrjs/loader": "0.6.0-alpha.16",
48
+ "@lwrjs/lwc-module-provider": "0.6.0-alpha.16",
49
+ "@lwrjs/lwc-ssr": "0.6.0-alpha.16",
50
+ "@lwrjs/markdown-view-provider": "0.6.0-alpha.16",
51
+ "@lwrjs/module-bundler": "0.6.0-alpha.16",
52
+ "@lwrjs/module-registry": "0.6.0-alpha.16",
53
+ "@lwrjs/npm-module-provider": "0.6.0-alpha.16",
54
+ "@lwrjs/nunjucks-view-provider": "0.6.0-alpha.16",
55
+ "@lwrjs/o11y": "0.6.0-alpha.16",
56
+ "@lwrjs/resource-registry": "0.6.0-alpha.16",
57
+ "@lwrjs/router": "0.6.0-alpha.16",
58
+ "@lwrjs/server": "0.6.0-alpha.16",
59
+ "@lwrjs/shared-utils": "0.6.0-alpha.16",
60
+ "@lwrjs/view-registry": "0.6.0-alpha.16",
61
61
  "dompurify": "^2.3.0",
62
62
  "fs-extra": "^10.0.0",
63
63
  "jsdom": "^16.7.0",
@@ -67,7 +67,7 @@
67
67
  "qs": "^6.9.4"
68
68
  },
69
69
  "devDependencies": {
70
- "@lwrjs/types": "0.6.0-alpha.15"
70
+ "@lwrjs/types": "0.6.0-alpha.16"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "lwc": ">= 1.x <= 2.x"
@@ -75,5 +75,5 @@
75
75
  "engines": {
76
76
  "node": ">=14.15.4 <17"
77
77
  },
78
- "gitHead": "ebff01c190ee6f2777028f103e51446a1a8f00f7"
78
+ "gitHead": "2ccfba164126587f8c898da5994b6749ec23aa22"
79
79
  }