@lwrjs/shared-utils 0.9.0-alpha.2 → 0.9.0-alpha.21

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.
@@ -0,0 +1,27 @@
1
+ import type { SiteAssets, SiteBundles, SiteMetadata, SiteResources } from '@lwrjs/types';
2
+ declare type Options = {
3
+ rootDir: string;
4
+ };
5
+ export declare class SiteMetadataImpl implements SiteMetadata {
6
+ private options;
7
+ private siteBundles;
8
+ private siteResources;
9
+ private siteAssets;
10
+ constructor(options: Options);
11
+ getSiteRootDir(): string;
12
+ getSiteBundles(): SiteBundles;
13
+ getSiteResources(): SiteResources;
14
+ getSiteAssets(): SiteAssets;
15
+ persistSiteMetadata(): Promise<void>;
16
+ private readStaticBundleMetadata;
17
+ /**
18
+ * Read the metadata about the pre-built resources of the current site.
19
+ */
20
+ private readStaticResourceMetadata;
21
+ /**
22
+ * Read the metadata about the pre-built assets of the current site.
23
+ */
24
+ private readStaticAssetsMetadata;
25
+ }
26
+ export {};
27
+ //# sourceMappingURL=site-metadata.d.ts.map
@@ -0,0 +1,105 @@
1
+ import path from 'path';
2
+ import fs from 'fs-extra';
3
+ import { logger } from './logger.js';
4
+ const SITE_METADATA_PATH = '.metadata';
5
+ const STATIC_BUNDLE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/bundle-metadata.json');
6
+ const STATIC_RESOURCE_METADATA_PATH = path.join(SITE_METADATA_PATH, '/resource-metadata.json');
7
+ const STATIC_ASSET_METADATA_PATH = path.join(SITE_METADATA_PATH, '/asset-metadata.json');
8
+ export class SiteMetadataImpl {
9
+ constructor(options) {
10
+ this.options = options;
11
+ this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
12
+ this.siteResources = this.readStaticResourceMetadata(options.rootDir);
13
+ this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
14
+ }
15
+ getSiteRootDir() {
16
+ return this.options.rootDir;
17
+ }
18
+ getSiteBundles() {
19
+ return this.siteBundles;
20
+ }
21
+ getSiteResources() {
22
+ return this.siteResources;
23
+ }
24
+ getSiteAssets() {
25
+ return this.siteAssets;
26
+ }
27
+ async persistSiteMetadata() {
28
+ // Create the metadata directory if if does not exist
29
+ const siteMetadataPath = path.join(this.options.rootDir, SITE_METADATA_PATH);
30
+ if (!(await fs.pathExists(siteMetadataPath))) {
31
+ await fs.mkdir(siteMetadataPath, { recursive: true });
32
+ }
33
+ // Save Bundle Metadata
34
+ const bundleMetadataPath = path.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
35
+ await fs.writeJSON(bundleMetadataPath, this.siteBundles, { spaces: 2 });
36
+ // Save Resource Metadata
37
+ const resourceMetadataPath = path.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
38
+ await fs.writeJSON(resourceMetadataPath, this.siteResources, { spaces: 2 });
39
+ // Save Resource Metadata
40
+ const assetMetadataPath = path.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
41
+ return fs.writeJSON(assetMetadataPath, this.siteAssets, { spaces: 2 });
42
+ }
43
+ readStaticBundleMetadata(staticRoot) {
44
+ let bundleMetadataPath;
45
+ let siteBundles = { bundles: {} };
46
+ try {
47
+ bundleMetadataPath = path.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
48
+ const savedMetadata = fs.readJSONSync(bundleMetadataPath);
49
+ siteBundles = savedMetadata;
50
+ }
51
+ catch (error) {
52
+ if (error.code === 'ENOENT') {
53
+ logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
54
+ }
55
+ else {
56
+ throw error;
57
+ }
58
+ }
59
+ return siteBundles;
60
+ }
61
+ /**
62
+ * Read the metadata about the pre-built resources of the current site.
63
+ */
64
+ readStaticResourceMetadata(staticRoot) {
65
+ let resourceMetadataPath;
66
+ let siteResources = { resources: {} };
67
+ try {
68
+ resourceMetadataPath = path.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
69
+ const savedMetadata = fs.readJSONSync(resourceMetadataPath);
70
+ siteResources = savedMetadata;
71
+ }
72
+ catch (error) {
73
+ if (error.code === 'ENOENT') {
74
+ logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
75
+ }
76
+ else {
77
+ throw error;
78
+ }
79
+ }
80
+ return siteResources;
81
+ }
82
+ /**
83
+ * Read the metadata about the pre-built assets of the current site.
84
+ */
85
+ readStaticAssetsMetadata(staticRoot) {
86
+ let assetMetadataPath;
87
+ let siteAssets = {
88
+ assets: {},
89
+ };
90
+ try {
91
+ assetMetadataPath = path.join(staticRoot, STATIC_ASSET_METADATA_PATH);
92
+ siteAssets = fs.readJSONSync(assetMetadataPath);
93
+ }
94
+ catch (error) {
95
+ if (error.code === 'ENOENT') {
96
+ logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
97
+ }
98
+ else {
99
+ throw error;
100
+ }
101
+ }
102
+ return siteAssets;
103
+ }
104
+ }
105
+ //# sourceMappingURL=site-metadata.js.map
@@ -1,8 +1,9 @@
1
1
  import fs from 'fs';
2
2
  import { join, dirname, extname } from 'path';
3
3
  import esbuildEsm from 'esbuild';
4
- // Workaround until this is fixed:
5
4
  // https://github.com/evanw/esbuild/issues/706
5
+ // Fixed in 0.11.0 but upgrading past 0.9.7 has caused breaking changes for consumers...
6
+ // https://github.com/salesforce-experience-platform-emu/lwr/issues/1014
6
7
  let esbuild = esbuildEsm;
7
8
  if (!esbuildEsm) {
8
9
  try {
package/package.json CHANGED
@@ -4,18 +4,18 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.9.0-alpha.2",
7
+ "version": "0.9.0-alpha.21",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/salesforce/lwr.git",
11
+ "url": "https://github.com/salesforce-experience-platform-emu/lwr.git",
12
12
  "directory": "packages/@lwrjs/shared-utils"
13
13
  },
14
14
  "scripts": {
15
15
  "build": "tsc -b"
16
16
  },
17
17
  "bugs": {
18
- "url": "https://github.com/salesforce/lwr/issues"
18
+ "url": "https://github.com/salesforce-experience-platform-emu/lwr/issues"
19
19
  },
20
20
  "type": "module",
21
21
  "types": "build/es/index.d.ts",
@@ -25,6 +25,18 @@
25
25
  ".": {
26
26
  "import": "./build/es/index.js",
27
27
  "require": "./build/cjs/index.cjs"
28
+ },
29
+ "./fs-watch": {
30
+ "import": "./build/es/fs-watch.js",
31
+ "require": "./build/cjs/fs-watch.cjs"
32
+ },
33
+ "./typescript": {
34
+ "import": "./build/es/typescript.js",
35
+ "require": "./build/cjs/typescript.cjs"
36
+ },
37
+ "./compiler": {
38
+ "import": "./build/es/compiler.js",
39
+ "require": "./build/cjs/compiler.cjs"
28
40
  }
29
41
  },
30
42
  "files": [
@@ -33,25 +45,29 @@
33
45
  "build/**/*.d.ts"
34
46
  ],
35
47
  "dependencies": {
36
- "chokidar": "^3.4.0",
37
48
  "es-module-lexer": "^0.3.18",
38
- "esbuild": "^0.9.7",
39
49
  "fast-json-stable-stringify": "^2.1.0",
40
50
  "magic-string": "^0.25.7",
41
51
  "mime-types": "^2.1.33",
52
+ "ms": "^2.1.3",
42
53
  "parse5-sax-parser": "^6.0.1",
43
54
  "path-to-regexp": "^6.2.0",
44
- "slugify": "^1.4.5",
45
- "winston": "^3.7.2"
55
+ "slugify": "^1.4.5"
56
+ },
57
+ "peerDependencies": {
58
+ "@locker/compiler": "0.18.9",
59
+ "chokidar": "^3.5.3",
60
+ "esbuild": "^0.9.7",
61
+ "rollup": "~2.45.2"
46
62
  },
47
63
  "devDependencies": {
48
- "@lwrjs/diagnostics": "0.9.0-alpha.2",
49
- "@lwrjs/types": "0.9.0-alpha.2",
64
+ "@lwrjs/diagnostics": "0.9.0-alpha.21",
65
+ "@lwrjs/types": "0.9.0-alpha.21",
50
66
  "@types/mime-types": "2.1.1",
51
67
  "@types/path-to-regexp": "^1.7.0"
52
68
  },
53
69
  "engines": {
54
70
  "node": ">=14.15.4 <19"
55
71
  },
56
- "gitHead": "bcf63de23d1a2a53fb0e961dba4396e8753710dd"
72
+ "gitHead": "a89adcac80601f657becd6fd734c765e6b2a2745"
57
73
  }