@lwrjs/shared-utils 0.9.0-alpha.8 → 0.9.0
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.
- package/build/cjs/compiler.cjs +80 -0
- package/build/cjs/env.cjs +4 -8
- package/build/cjs/fs-watch.cjs +43 -0
- package/build/cjs/fs.cjs +25 -15
- package/build/cjs/graph.cjs +4 -3
- package/build/cjs/identity.cjs +16 -70
- package/build/cjs/index.cjs +1 -1
- package/build/cjs/interchangeable-modules.cjs +9 -2
- package/build/cjs/logger.cjs +33 -11
- package/build/cjs/object.cjs +2 -1
- package/build/cjs/serialize.cjs +31 -2
- package/build/cjs/site-metadata.cjs +121 -0
- package/build/es/compiler.d.ts +15 -0
- package/build/es/compiler.js +65 -0
- package/build/es/env.d.ts +1 -1
- package/build/es/env.js +19 -11
- package/build/es/fs-watch.d.ts +17 -0
- package/build/es/fs-watch.js +27 -0
- package/build/es/fs.d.ts +5 -10
- package/build/es/fs.js +33 -23
- package/build/es/graph.d.ts +2 -1
- package/build/es/graph.js +3 -3
- package/build/es/identity.d.ts +9 -31
- package/build/es/identity.js +13 -87
- package/build/es/index.d.ts +1 -1
- package/build/es/index.js +1 -1
- package/build/es/interchangeable-modules.d.ts +1 -1
- package/build/es/interchangeable-modules.js +9 -2
- package/build/es/logger.js +36 -10
- package/build/es/mappings.js +2 -0
- package/build/es/object.js +2 -1
- package/build/es/serialize.d.ts +8 -1
- package/build/es/serialize.js +19 -1
- package/build/es/site-metadata.d.ts +27 -0
- package/build/es/site-metadata.js +111 -0
- package/build/es/typescript.js +2 -1
- package/package.json +28 -11
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
11
|
+
};
|
|
12
|
+
var __exportStar = (target, module2, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
__defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toModule = (module2) => {
|
|
21
|
+
return __exportStar(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// packages/@lwrjs/shared-utils/src/site-metadata.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
SiteMetadataImpl: () => SiteMetadataImpl
|
|
28
|
+
});
|
|
29
|
+
var import_path = __toModule(require("path"));
|
|
30
|
+
var import_fs_extra = __toModule(require("fs-extra"));
|
|
31
|
+
var import_logger = __toModule(require("./logger.cjs"));
|
|
32
|
+
var SITE_METADATA_PATH = ".metadata";
|
|
33
|
+
var STATIC_BUNDLE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/bundle-metadata.json");
|
|
34
|
+
var STATIC_RESOURCE_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/resource-metadata.json");
|
|
35
|
+
var STATIC_ASSET_METADATA_PATH = import_path.default.join(SITE_METADATA_PATH, "/asset-metadata.json");
|
|
36
|
+
var SiteMetadataImpl = class {
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.options = options;
|
|
39
|
+
this.siteBundles = this.readStaticBundleMetadata(options.rootDir);
|
|
40
|
+
this.siteResources = this.readStaticResourceMetadata(options.rootDir);
|
|
41
|
+
this.siteAssets = this.readStaticAssetsMetadata(options.rootDir);
|
|
42
|
+
}
|
|
43
|
+
getSiteRootDir() {
|
|
44
|
+
return this.options.rootDir;
|
|
45
|
+
}
|
|
46
|
+
getSiteBundles() {
|
|
47
|
+
return this.siteBundles;
|
|
48
|
+
}
|
|
49
|
+
getSiteResources() {
|
|
50
|
+
return this.siteResources;
|
|
51
|
+
}
|
|
52
|
+
getSiteAssets() {
|
|
53
|
+
return this.siteAssets;
|
|
54
|
+
}
|
|
55
|
+
async persistSiteMetadata() {
|
|
56
|
+
const siteMetadataPath = import_path.default.join(this.options.rootDir, SITE_METADATA_PATH);
|
|
57
|
+
try {
|
|
58
|
+
if (!await import_fs_extra.default.pathExists(siteMetadataPath)) {
|
|
59
|
+
await import_fs_extra.default.mkdir(siteMetadataPath, {recursive: true});
|
|
60
|
+
}
|
|
61
|
+
const bundleMetadataPath = import_path.default.join(this.options.rootDir, STATIC_BUNDLE_METADATA_PATH);
|
|
62
|
+
await import_fs_extra.default.writeJSON(bundleMetadataPath, this.siteBundles, {spaces: 2});
|
|
63
|
+
const resourceMetadataPath = import_path.default.join(this.options.rootDir, STATIC_RESOURCE_METADATA_PATH);
|
|
64
|
+
await import_fs_extra.default.writeJSON(resourceMetadataPath, this.siteResources, {spaces: 2});
|
|
65
|
+
const assetMetadataPath = import_path.default.join(this.options.rootDir, STATIC_ASSET_METADATA_PATH);
|
|
66
|
+
return import_fs_extra.default.writeJSON(assetMetadataPath, this.siteAssets, {spaces: 2});
|
|
67
|
+
} catch (err) {
|
|
68
|
+
console.error(`[SiteMetadata] Failed to save site metadata ${siteMetadataPath}`);
|
|
69
|
+
console.error(err);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
readStaticBundleMetadata(staticRoot) {
|
|
73
|
+
let bundleMetadataPath;
|
|
74
|
+
let siteBundles = {bundles: {}};
|
|
75
|
+
try {
|
|
76
|
+
bundleMetadataPath = import_path.default.join(staticRoot, STATIC_BUNDLE_METADATA_PATH);
|
|
77
|
+
const savedMetadata = import_fs_extra.default.readJSONSync(bundleMetadataPath);
|
|
78
|
+
siteBundles = savedMetadata;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error.code === "ENOENT") {
|
|
81
|
+
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Bundle Metadata: ${bundleMetadataPath}`);
|
|
82
|
+
} else {
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return siteBundles;
|
|
87
|
+
}
|
|
88
|
+
readStaticResourceMetadata(staticRoot) {
|
|
89
|
+
let resourceMetadataPath;
|
|
90
|
+
let siteResources = {resources: {}};
|
|
91
|
+
try {
|
|
92
|
+
resourceMetadataPath = import_path.default.join(staticRoot, STATIC_RESOURCE_METADATA_PATH);
|
|
93
|
+
const savedMetadata = import_fs_extra.default.readJSONSync(resourceMetadataPath);
|
|
94
|
+
siteResources = savedMetadata;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error.code === "ENOENT") {
|
|
97
|
+
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${resourceMetadataPath}`);
|
|
98
|
+
} else {
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return siteResources;
|
|
103
|
+
}
|
|
104
|
+
readStaticAssetsMetadata(staticRoot) {
|
|
105
|
+
let assetMetadataPath;
|
|
106
|
+
let siteAssets = {
|
|
107
|
+
assets: {}
|
|
108
|
+
};
|
|
109
|
+
try {
|
|
110
|
+
assetMetadataPath = import_path.default.join(staticRoot, STATIC_ASSET_METADATA_PATH);
|
|
111
|
+
siteAssets = import_fs_extra.default.readJSONSync(assetMetadataPath);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
if (error.code === "ENOENT") {
|
|
114
|
+
import_logger.logger.debug(`[SiteMetadata] Failed to load Static Resource Metadata: ${assetMetadataPath}`);
|
|
115
|
+
} else {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return siteAssets;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CompilerResult, LwrLockerConfig, ModuleCompiled } from '@lwrjs/types';
|
|
2
|
+
/**
|
|
3
|
+
* When importing these modules make sure the optional dependencies are installed:
|
|
4
|
+
* - 'rollup' for convertToAmd()
|
|
5
|
+
* - '@locker/compiler' for lockerize()
|
|
6
|
+
*/
|
|
7
|
+
export declare const AMD_DEFINE = "LWR.define";
|
|
8
|
+
export declare function convertToAmd(source: string, { id }: {
|
|
9
|
+
id: string;
|
|
10
|
+
}, forceNamedExports?: boolean): Promise<CompilerResult>;
|
|
11
|
+
/** Locker
|
|
12
|
+
* Trusted Components can contain namespaces with wildcard or single component
|
|
13
|
+
*/
|
|
14
|
+
export declare function lockerize({ compiledSource: source, specifier, moduleEntry: { entry: filename } }: ModuleCompiled, { trustedComponents }: LwrLockerConfig, sourcemap?: boolean): CompilerResult;
|
|
15
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { explodeSpecifier } from './identity.js';
|
|
2
|
+
import { Compiler as Locker } from '@locker/compiler';
|
|
3
|
+
import { rollup } from 'rollup';
|
|
4
|
+
/**
|
|
5
|
+
* When importing these modules make sure the optional dependencies are installed:
|
|
6
|
+
* - 'rollup' for convertToAmd()
|
|
7
|
+
* - '@locker/compiler' for lockerize()
|
|
8
|
+
*/
|
|
9
|
+
export const AMD_DEFINE = 'LWR.define';
|
|
10
|
+
const AMD_ROLLUP_PLUGIN = function (rootId, source) {
|
|
11
|
+
return {
|
|
12
|
+
name: 'lwr-amd-inline',
|
|
13
|
+
resolveId(id) {
|
|
14
|
+
return rootId === id ? id : undefined;
|
|
15
|
+
},
|
|
16
|
+
load(id) {
|
|
17
|
+
return rootId === id ? source : undefined;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export async function convertToAmd(source, { id }, forceNamedExports = true) {
|
|
22
|
+
const bundler = await rollup({
|
|
23
|
+
input: id,
|
|
24
|
+
plugins: [AMD_ROLLUP_PLUGIN(id, source)],
|
|
25
|
+
onwarn(warning, warn) {
|
|
26
|
+
// do not print out these: 'a' is imported by b, but could not be resolved – treating it as an external dependency
|
|
27
|
+
if (warning.code === 'UNRESOLVED_IMPORT')
|
|
28
|
+
return;
|
|
29
|
+
warn(warning);
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
const { output } = await bundler.generate({
|
|
33
|
+
amd: { id, define: AMD_DEFINE },
|
|
34
|
+
exports: forceNamedExports ? 'named' : 'auto',
|
|
35
|
+
format: 'amd',
|
|
36
|
+
});
|
|
37
|
+
const { code } = output[0];
|
|
38
|
+
return { code, map: null };
|
|
39
|
+
}
|
|
40
|
+
/** Locker
|
|
41
|
+
* Trusted Components can contain namespaces with wildcard or single component
|
|
42
|
+
*/
|
|
43
|
+
export function lockerize({ compiledSource: source, specifier, moduleEntry: { entry: filename } }, { trustedComponents }, sourcemap = false) {
|
|
44
|
+
const { namespace, name: rawName } = explodeSpecifier(specifier);
|
|
45
|
+
const [name] = rawName.split('#');
|
|
46
|
+
const bareSpecifier = namespace ? `${namespace}/${name}` : name;
|
|
47
|
+
const isJS = filename.endsWith('.js') || filename.endsWith('.mjs') || filename.endsWith('.ts');
|
|
48
|
+
// lockerize if component is JS and is not explicitly trusted or in a trusted namespace
|
|
49
|
+
if (isJS &&
|
|
50
|
+
trustedComponents &&
|
|
51
|
+
!trustedComponents.includes(`${namespace}/*`) &&
|
|
52
|
+
!trustedComponents.includes(bareSpecifier)) {
|
|
53
|
+
const { code } = Locker.compile(source, {
|
|
54
|
+
componentName: name,
|
|
55
|
+
filename,
|
|
56
|
+
// put non-namespaced modules in a single sandbox - this should only be non-lwc npm modules
|
|
57
|
+
sandboxKey: namespace || 'sandbox',
|
|
58
|
+
sourcemap,
|
|
59
|
+
remapDynamicImport: true, // support for dynamic imports
|
|
60
|
+
});
|
|
61
|
+
return { code, map: null };
|
|
62
|
+
}
|
|
63
|
+
return { code: source, map: null };
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=compiler.js.map
|
package/build/es/env.d.ts
CHANGED
package/build/es/env.js
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
export function getFeatureFlags() {
|
|
2
|
-
|
|
3
|
-
try {
|
|
4
|
-
// Use the Shim for MRT since we don't have access to managing environment variables
|
|
5
|
-
if (LWR) {
|
|
6
|
-
legacyLoader = LWR.LEGACY_LOADER;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
catch (e) {
|
|
10
|
-
// No shim, ignore error
|
|
11
|
-
}
|
|
2
|
+
// Add any new feature flags here to parse from environment variables
|
|
12
3
|
return {
|
|
13
4
|
// DEFAULT LEGACY_LOADER = false;
|
|
14
|
-
LEGACY_LOADER:
|
|
5
|
+
LEGACY_LOADER: process.env.LEGACY_LOADER !== undefined && process.env.LEGACY_LOADER.toLowerCase() === 'true'
|
|
6
|
+
? true
|
|
7
|
+
: false,
|
|
8
|
+
// SSR should concatenate bundles, default = false
|
|
9
|
+
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== undefined &&
|
|
10
|
+
process.env.SSR_STATIC_BUNDLES.toLowerCase() === 'true'
|
|
11
|
+
? true
|
|
12
|
+
: false,
|
|
13
|
+
// Should we use a js worker for SSR, sand-boxing = false (use locker for ssr sand-boxing)
|
|
14
|
+
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== undefined &&
|
|
15
|
+
process.env.SSR_SANDBOX_WORKER.toLowerCase() === 'true'
|
|
16
|
+
? true
|
|
17
|
+
: false,
|
|
18
|
+
// Should we load load the assets from the lambda on MRT
|
|
19
|
+
ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== undefined &&
|
|
20
|
+
process.env.ASSETS_ON_LAMBDA.toLowerCase() === 'true'
|
|
21
|
+
? true
|
|
22
|
+
: false,
|
|
15
23
|
};
|
|
16
24
|
}
|
|
17
25
|
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Watcher, WatcherFactory, WatchOptions } from '@lwrjs/types';
|
|
2
|
+
/**
|
|
3
|
+
* Factory comptable with the LWR Runtime to create a file watch library for LWR dev server.
|
|
4
|
+
* When importing this module make sure the optional library 'chokidar' is installed.
|
|
5
|
+
*/
|
|
6
|
+
export declare class WatcherFactoryImpl implements WatcherFactory {
|
|
7
|
+
/**
|
|
8
|
+
* Set up a watcher with the given options
|
|
9
|
+
* @param options
|
|
10
|
+
*/
|
|
11
|
+
createFileWatcher(options?: WatchOptions): Watcher;
|
|
12
|
+
/**
|
|
13
|
+
* Set up file watcher
|
|
14
|
+
*/
|
|
15
|
+
setupWatcher(onModuleChange: Function): Watcher;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=fs-watch.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import chokidar from 'chokidar';
|
|
2
|
+
import { debounce } from './object.js';
|
|
3
|
+
import { logger } from './logger.js';
|
|
4
|
+
/**
|
|
5
|
+
* Factory comptable with the LWR Runtime to create a file watch library for LWR dev server.
|
|
6
|
+
* When importing this module make sure the optional library 'chokidar' is installed.
|
|
7
|
+
*/
|
|
8
|
+
export class WatcherFactoryImpl {
|
|
9
|
+
/**
|
|
10
|
+
* Set up a watcher with the given options
|
|
11
|
+
* @param options
|
|
12
|
+
*/
|
|
13
|
+
createFileWatcher(options = { persistent: true, ignored: '**/node_modules/**' }) {
|
|
14
|
+
return chokidar.watch([], options);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Set up file watcher
|
|
18
|
+
*/
|
|
19
|
+
setupWatcher(onModuleChange) {
|
|
20
|
+
const fileWatcher = this.createFileWatcher();
|
|
21
|
+
fileWatcher.on('change', debounce((file) => onModuleChange(file), 500));
|
|
22
|
+
fileWatcher.on('unlink', debounce((file) => onModuleChange(file), 500));
|
|
23
|
+
fileWatcher.on('add', (file) => logger.info(`Watching: ${file}`));
|
|
24
|
+
return fileWatcher;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=fs-watch.js.map
|
package/build/es/fs.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import type { AssetIdentifier, ResourcePaths, ViewSource } from '@lwrjs/types';
|
|
3
3
|
import { lookup } from 'mime-types';
|
|
4
4
|
/**
|
|
5
5
|
* Create a hash string for a source
|
|
@@ -16,15 +16,6 @@ export declare function readFile(filePath: string): string;
|
|
|
16
16
|
* @param filePath
|
|
17
17
|
*/
|
|
18
18
|
export declare function resolveFileExtension(filePath: string): string;
|
|
19
|
-
/**
|
|
20
|
-
* Set up a watcher with the given options
|
|
21
|
-
* @param options
|
|
22
|
-
*/
|
|
23
|
-
export declare function createFileWatcher(options?: any): Watcher;
|
|
24
|
-
/**
|
|
25
|
-
* Set up file watcher
|
|
26
|
-
*/
|
|
27
|
-
export declare function setupWatcher(onModuleChange: Function): Watcher;
|
|
28
19
|
/**
|
|
29
20
|
* Returns if view of specific type can be resolved
|
|
30
21
|
*
|
|
@@ -41,4 +32,8 @@ export declare function getViewSourceFromFile(source: string): ViewSource;
|
|
|
41
32
|
export declare function normalizeDirectory(dir: string, rootDir: string): string;
|
|
42
33
|
export declare function normalizeResourcePath(rawPath: string, { rootDir, assets, contentDir, layoutsDir }: ResourcePaths, allowUnresolvedAlias?: boolean): string;
|
|
43
34
|
export { lookup as mimeLookup };
|
|
35
|
+
/**
|
|
36
|
+
* Tries to convert any URL or $aliased path into a canonical fs path
|
|
37
|
+
*/
|
|
38
|
+
export declare function normalizeAssetSpecifier(assetId: AssetIdentifier, assetPathMap: Map<string, string>, resourcePaths: ResourcePaths, basePath: string): string;
|
|
44
39
|
//# sourceMappingURL=fs.d.ts.map
|
package/build/es/fs.js
CHANGED
|
@@ -2,8 +2,6 @@ import fs from 'fs';
|
|
|
2
2
|
import pathLib from 'path';
|
|
3
3
|
import crypto from 'crypto';
|
|
4
4
|
import { slugify } from './identity.js';
|
|
5
|
-
import { debounce } from './object.js';
|
|
6
|
-
import chokidar from 'chokidar';
|
|
7
5
|
import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
|
|
8
6
|
import { lookup } from 'mime-types';
|
|
9
7
|
import { DEBUG, logger, VERBOSE } from './logger.js';
|
|
@@ -38,10 +36,10 @@ export function resolveFileExtension(filePath) {
|
|
|
38
36
|
// No extension, if it exist, it can be a dir or a file
|
|
39
37
|
if (fs.existsSync(filePath)) {
|
|
40
38
|
if (fs.statSync(filePath).isFile()) {
|
|
41
|
-
return filePath; //
|
|
39
|
+
return filePath; // extension-less file, which is odd but...
|
|
42
40
|
}
|
|
43
41
|
else {
|
|
44
|
-
filePath = pathLib.join(filePath, 'index'); // if is a dir we will be
|
|
42
|
+
filePath = pathLib.join(filePath, 'index'); // if is a dir we will be testing the extensions
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
// At this point we have a file with no extension so we try for the default (js,ts) or fail
|
|
@@ -55,25 +53,6 @@ export function resolveFileExtension(filePath) {
|
|
|
55
53
|
throw new Error(`Unable to find file "${filePath}"`);
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Set up a watcher with the given options
|
|
60
|
-
* @param options
|
|
61
|
-
*/
|
|
62
|
-
export function createFileWatcher(
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
64
|
-
options = { persistent: true, ignored: '**/node_modules/**' }) {
|
|
65
|
-
return chokidar.watch([], options);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Set up file watcher
|
|
69
|
-
*/
|
|
70
|
-
export function setupWatcher(onModuleChange) {
|
|
71
|
-
const fileWatcher = createFileWatcher();
|
|
72
|
-
fileWatcher.on('change', debounce((file) => onModuleChange(file), 500));
|
|
73
|
-
fileWatcher.on('unlink', debounce((file) => onModuleChange(file), 500));
|
|
74
|
-
fileWatcher.on('add', (file) => logger.info(`Watching: ${file}`));
|
|
75
|
-
return fileWatcher;
|
|
76
|
-
}
|
|
77
56
|
/**
|
|
78
57
|
* Returns if view of specific type can be resolved
|
|
79
58
|
*
|
|
@@ -153,4 +132,35 @@ function logMetrics(filePath) {
|
|
|
153
132
|
}
|
|
154
133
|
}
|
|
155
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Tries to convert any URL or $aliased path into a canonical fs path
|
|
137
|
+
*/
|
|
138
|
+
export function normalizeAssetSpecifier(assetId, assetPathMap, resourcePaths, basePath) {
|
|
139
|
+
const { specifier, importer, type } = assetId;
|
|
140
|
+
if (specifier.startsWith('./') || specifier.startsWith('../')) {
|
|
141
|
+
if (!importer) {
|
|
142
|
+
throw Error(`Unable to resolve relative import "${specifier}" without an importer.`);
|
|
143
|
+
}
|
|
144
|
+
return pathLib.join(pathLib.dirname(importer), specifier);
|
|
145
|
+
}
|
|
146
|
+
if (type === 'content-asset') {
|
|
147
|
+
const originSpecifier = !basePath ? specifier : specifier.split(basePath)[1];
|
|
148
|
+
return pathLib.join(resourcePaths.contentDir, originSpecifier);
|
|
149
|
+
}
|
|
150
|
+
if (specifier[0] === '$') {
|
|
151
|
+
// This is a fs path containing an asset alias
|
|
152
|
+
return normalizeResourcePath(specifier, resourcePaths);
|
|
153
|
+
}
|
|
154
|
+
// This is an absolute path to the server
|
|
155
|
+
// Match in 2 ways:
|
|
156
|
+
// - Directories: the prefix of the asset specifier/path matches a configured assets[i].urlPath
|
|
157
|
+
// - Individual files: the asset specifier is equal to a configured assets[i].urlPath
|
|
158
|
+
for (const [urlPath, fsPath] of assetPathMap.entries()) {
|
|
159
|
+
const slashPath = urlPath.endsWith('/') ? urlPath : `${urlPath}/`;
|
|
160
|
+
if (specifier.startsWith(slashPath) || specifier === urlPath) {
|
|
161
|
+
return specifier.replace(urlPath, fsPath);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return specifier;
|
|
165
|
+
}
|
|
156
166
|
//# sourceMappingURL=fs.js.map
|
package/build/es/graph.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ModuleRegistry, RuntimeEnvironment, RuntimeParams, FlattenedModuleGraphs, GraphNode, GraphOptions, ModuleBundler } from '@lwrjs/types';
|
|
1
|
+
import type { ModuleRegistry, RuntimeEnvironment, RuntimeParams, FlattenedModuleGraphs, GraphNode, GraphOptions, ModuleBundler, PublicModuleRegistry, PublicModuleBundler } from '@lwrjs/types';
|
|
2
2
|
export declare enum GraphDepth {
|
|
3
3
|
ALL = "all",
|
|
4
4
|
DIRECT = "direct",
|
|
5
5
|
NONE = "none"
|
|
6
6
|
}
|
|
7
|
+
export declare function isBundler(registry: PublicModuleRegistry | PublicModuleBundler): registry is PublicModuleBundler;
|
|
7
8
|
export declare function getModuleGraphs(specifier: string, // version | un-versioned specifiers
|
|
8
9
|
options: GraphOptions, moduleRegistry: ModuleRegistry, defRegistry: ModuleRegistry | ModuleBundler, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams, visited?: Map<string, GraphNode>): Promise<FlattenedModuleGraphs>;
|
|
9
10
|
//# sourceMappingURL=graph.d.ts.map
|
package/build/es/graph.js
CHANGED
|
@@ -8,7 +8,7 @@ export var GraphDepth;
|
|
|
8
8
|
GraphDepth["NONE"] = "none";
|
|
9
9
|
})(GraphDepth || (GraphDepth = {}));
|
|
10
10
|
// type guard for ViewDef responses
|
|
11
|
-
function isBundler(registry) {
|
|
11
|
+
export function isBundler(registry) {
|
|
12
12
|
return registry.getModuleBundle !== undefined;
|
|
13
13
|
}
|
|
14
14
|
async function traverse(module, depth, flattened,
|
|
@@ -94,7 +94,7 @@ defRegistry, runtimeEnvironment, runtimeParams) {
|
|
|
94
94
|
}
|
|
95
95
|
async function flatten(versionedSpecifier, flattened, idx, visited) {
|
|
96
96
|
const node = visited.get(versionedSpecifier);
|
|
97
|
-
if (node) {
|
|
97
|
+
if (flattened[idx]?.static && node?.static) {
|
|
98
98
|
node.static.forEach(async (imp) => {
|
|
99
99
|
if (!flattened[idx].static.includes(imp)) {
|
|
100
100
|
flattened[idx].static.push(imp);
|
|
@@ -129,7 +129,7 @@ options, moduleRegistry, defRegistry, runtimeEnvironment, runtimeParams, visited
|
|
|
129
129
|
// eslint-disable-next-line no-await-in-loop
|
|
130
130
|
const moduleId = await getVersionedModuleId(visitedSpecifier, moduleRegistry);
|
|
131
131
|
// eslint-disable-next-line no-await-in-loop
|
|
132
|
-
const uri = await
|
|
132
|
+
const uri = await defRegistry.resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams);
|
|
133
133
|
uriMap[visitedSpecifier] = uri;
|
|
134
134
|
}
|
|
135
135
|
}
|
package/build/es/identity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import getCacheKeyFromJson from 'fast-json-stable-stringify';
|
|
2
|
-
import { AbstractModuleId,
|
|
2
|
+
import { AbstractModuleId, AssetSource, BundleDefinition, ModuleDefinition, NormalizedLwrAppBootstrapConfig, PublicModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
3
3
|
export declare const VERSION_SIGIL = "/v/";
|
|
4
4
|
export declare const LOCALE_SIGIL = "l";
|
|
5
5
|
export declare const ENVIRONMENT_SIGIL = "e";
|
|
@@ -8,6 +8,7 @@ export declare const LATEST_SIGNATURE = "latest";
|
|
|
8
8
|
export declare const DEFAULT_TITLE = "LWR App";
|
|
9
9
|
export declare const IMMUTABLE_ASSET_PREFIX = "/_immutable/";
|
|
10
10
|
export declare const ASSETS_CACHE_DIR = "assetsCache";
|
|
11
|
+
export declare const VERSION_NOT_PROVIDED = "version-not-provided";
|
|
11
12
|
export declare const DEFAULT_LOCKER_TRUSTED_CMP: string[];
|
|
12
13
|
export declare const DEFAULT_LWR_LOCKER_CONFIG: {
|
|
13
14
|
enabled: boolean;
|
|
@@ -57,29 +58,9 @@ export declare function explodeSpecifiers(rawSpecifiers: string): PartialModuleI
|
|
|
57
58
|
* @example - { namespace: '@salesforce', name: 'label/my.label', version: '1' } => '@salesforce/label/my.label/v/1'
|
|
58
59
|
*/
|
|
59
60
|
export declare function getSpecifier({ specifier, namespace, name, version }: ModuleIdentifierPartial): string;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
* @remarks
|
|
64
|
-
* If the incoming specifier is already versioned, it will be returned as is.
|
|
65
|
-
*
|
|
66
|
-
* The returned specifier's version conforms to the format expected to be used
|
|
67
|
-
* external to the framework (e.g. via the identity in the URL, mapping metadata,
|
|
68
|
-
* AMD define module name). This format conforms to the `normalizeVersionToUri`
|
|
69
|
-
* implementation (e.g. version semver format -- major_minor_patch).
|
|
70
|
-
*
|
|
71
|
-
* This method is analogous to `getSpecifier` but supports non-versioned `rawSpecifiers`
|
|
72
|
-
* The inverse of this method is `explodeSpecifier`
|
|
73
|
-
|
|
74
|
-
* @param specifier - the module specifier
|
|
75
|
-
* @param moduleRegistry - the public module registry
|
|
76
|
-
*
|
|
77
|
-
* @returns the specifier for the latest version
|
|
78
|
-
*
|
|
79
|
-
* @example - 'c/form' => 'c/form/v/0_0_1'
|
|
80
|
-
* @example - 'c/form/v/0.0.2' => 'c/form/v/0_0_2'
|
|
81
|
-
*/
|
|
82
|
-
export declare function getVersionedSpecifier(rawSpecifier: string, moduleRegistry: PublicModuleRegistry): Promise<string>;
|
|
61
|
+
interface VersionedAbstractModuleId extends AbstractModuleId {
|
|
62
|
+
version: string;
|
|
63
|
+
}
|
|
83
64
|
/**
|
|
84
65
|
* Create a AbstractModuleId using the module registry to resolve the version
|
|
85
66
|
* if a version is not provided in the `rawSpecifier`
|
|
@@ -100,7 +81,7 @@ export declare function getVersionedSpecifier(rawSpecifier: string, moduleRegist
|
|
|
100
81
|
* @example - 'c/form/v/0.0.2' => {specifier: "c/form", version: "0.0.2"}
|
|
101
82
|
* @example - 'c/form/v/0_0_2' => {specifier: "c/form", version: "0.0.2"}
|
|
102
83
|
*/
|
|
103
|
-
export declare function getVersionedModuleId(rawSpecifier: string, moduleRegistry: PublicModuleRegistry): Promise<
|
|
84
|
+
export declare function getVersionedModuleId(rawSpecifier: string, moduleRegistry: PublicModuleRegistry): Promise<VersionedAbstractModuleId>;
|
|
104
85
|
interface PackageIdentity {
|
|
105
86
|
scope?: string;
|
|
106
87
|
packageName: string;
|
|
@@ -124,9 +105,9 @@ export declare function parsePackageSpecifier(specifier: string): PackageIdentit
|
|
|
124
105
|
* @param name A string in kebab case
|
|
125
106
|
* @example - 'name-of-something' => 'name/ofSomething'
|
|
126
107
|
*/
|
|
127
|
-
export declare function
|
|
108
|
+
export declare function kebabCaseToModuleSpecifier(name: string): string;
|
|
128
109
|
/**
|
|
129
|
-
* Clone of lwr/init, reverse of
|
|
110
|
+
* Clone of lwr/init, reverse of kebabCaseToModuleSpecifier, strips off versions
|
|
130
111
|
* @param specifier
|
|
131
112
|
* @example - 'name/ofSomething/v/1.0.0' => 'name-of-something'
|
|
132
113
|
*/
|
|
@@ -157,9 +138,6 @@ export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat,
|
|
|
157
138
|
export declare function getMappingUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams): string;
|
|
158
139
|
export { getCacheKeyFromJson };
|
|
159
140
|
export declare function isExternalUrl(url: string): boolean;
|
|
141
|
+
export declare function isAssetSourceExternal(assetSource: AssetSource): boolean;
|
|
160
142
|
export declare function isBundleDefinition(definition: ModuleDefinition | BundleDefinition): definition is BundleDefinition;
|
|
161
|
-
export declare function getModuleIdentity(req: MiddlewareRequest): ModuleIdentity;
|
|
162
|
-
export declare function getMappingIdentity(req: MiddlewareRequest): MappingIdentity;
|
|
163
|
-
export declare function getResourceIdentity(req: MiddlewareRequest): ResourceIdentity;
|
|
164
|
-
export declare function getAssetIdentity(req: MiddlewareRequest): AssetIdentity;
|
|
165
143
|
//# sourceMappingURL=identity.d.ts.map
|