@lwrjs/shared-utils 0.10.0-alpha.14 → 0.10.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.
- package/build/cjs/bundle.cjs +9 -0
- package/build/cjs/env.cjs +1 -1
- package/build/cjs/html-meta.cjs +19 -3
- package/build/cjs/import-metadata.cjs +18 -1
- package/build/es/bundle.d.ts +12 -0
- package/build/es/bundle.js +23 -0
- package/build/es/env.js +2 -2
- package/build/es/html-meta.d.ts +5 -1
- package/build/es/html-meta.js +14 -2
- package/build/es/import-metadata.js +20 -0
- package/package.json +4 -4
package/build/cjs/bundle.cjs
CHANGED
|
@@ -8,6 +8,7 @@ var __export = (target, all) => {
|
|
|
8
8
|
// packages/@lwrjs/shared-utils/src/bundle.ts
|
|
9
9
|
__markAsModule(exports);
|
|
10
10
|
__export(exports, {
|
|
11
|
+
createAmdAlias: () => createAmdAlias,
|
|
11
12
|
getGroupName: () => getGroupName,
|
|
12
13
|
isGroupie: () => isGroupie
|
|
13
14
|
});
|
|
@@ -26,3 +27,11 @@ function isGroupie(rawSpecifier, groupsConfig) {
|
|
|
26
27
|
}
|
|
27
28
|
return false;
|
|
28
29
|
}
|
|
30
|
+
function createAmdAlias(aliasSpecifier, originalSpecifier) {
|
|
31
|
+
const builder = [];
|
|
32
|
+
builder.push(`LWR.define('${aliasSpecifier}',['exports','${originalSpecifier}'],function(e,m){`);
|
|
33
|
+
builder.push(`e.default=m&&'object'==typeof m&&'default'in m?m.default:m;`);
|
|
34
|
+
builder.push(`Object.keys(m).forEach(function(n){'default'===n||e.hasOwnProperty(n)||Object.defineProperty(e,n,{enumerable:!0,get:function(){return m[n]}})});`);
|
|
35
|
+
builder.push("});");
|
|
36
|
+
return builder.join("");
|
|
37
|
+
}
|
package/build/cjs/env.cjs
CHANGED
|
@@ -16,6 +16,6 @@ function getFeatureFlags() {
|
|
|
16
16
|
LEGACY_LOADER: process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER.toLowerCase() === "true" ? true : false,
|
|
17
17
|
SSR_SANDBOX_WORKER: process.env.SSR_SANDBOX_WORKER !== void 0 && process.env.SSR_SANDBOX_WORKER.toLowerCase() === "true" ? true : false,
|
|
18
18
|
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES.toLowerCase() === "true" ? true : false,
|
|
19
|
-
|
|
19
|
+
EXPERIMENTAL_UNVERSIONED_ALIASES: process.env.EXPERIMENTAL_UNVERSIONED_ALIASES !== void 0 && process.env.EXPERIMENTAL_UNVERSIONED_ALIASES.toLowerCase() === "true" ? true : false
|
|
20
20
|
};
|
|
21
21
|
}
|
package/build/cjs/html-meta.cjs
CHANGED
|
@@ -24,9 +24,13 @@ var __toModule = (module2) => {
|
|
|
24
24
|
// packages/@lwrjs/shared-utils/src/html-meta.ts
|
|
25
25
|
__markAsModule(exports);
|
|
26
26
|
__export(exports, {
|
|
27
|
+
HYDRATE_CLIENT_VALUE: () => HYDRATE_CLIENT_VALUE,
|
|
27
28
|
HYDRATE_DIRECTIVE: () => HYDRATE_DIRECTIVE,
|
|
29
|
+
HYDRATE_LOAD_VALUE: () => HYDRATE_LOAD_VALUE,
|
|
28
30
|
extractMetadataFromHtml: () => extractMetadataFromHtml,
|
|
29
|
-
|
|
31
|
+
getHydrateDirective: () => getHydrateDirective,
|
|
32
|
+
isCsrIsland: () => isCsrIsland,
|
|
33
|
+
isHydrateOnLoad: () => isHydrateOnLoad,
|
|
30
34
|
isRelative: () => isRelative,
|
|
31
35
|
isSelfUrl: () => isSelfUrl
|
|
32
36
|
});
|
|
@@ -120,6 +124,18 @@ async function extractMetadataFromHtml(htmlSource) {
|
|
|
120
124
|
});
|
|
121
125
|
}
|
|
122
126
|
var HYDRATE_DIRECTIVE = "lwr:hydrate";
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
var HYDRATE_LOAD_VALUE = "load";
|
|
128
|
+
var HYDRATE_CLIENT_VALUE = "client-only";
|
|
129
|
+
var HYDRATION_VALUES = [HYDRATE_LOAD_VALUE, HYDRATE_CLIENT_VALUE];
|
|
130
|
+
function getHydrateDirective(props = {}) {
|
|
131
|
+
const rawValue = props[HYDRATE_DIRECTIVE];
|
|
132
|
+
const value = rawValue === "true" ? HYDRATE_LOAD_VALUE : rawValue;
|
|
133
|
+
if (HYDRATION_VALUES.includes(value))
|
|
134
|
+
return value;
|
|
135
|
+
}
|
|
136
|
+
function isHydrateOnLoad(props = {}) {
|
|
137
|
+
return getHydrateDirective(props) === HYDRATE_LOAD_VALUE;
|
|
138
|
+
}
|
|
139
|
+
function isCsrIsland(props = {}) {
|
|
140
|
+
return getHydrateDirective(props) === HYDRATE_CLIENT_VALUE;
|
|
125
141
|
}
|
|
@@ -29,6 +29,7 @@ __export(exports, {
|
|
|
29
29
|
});
|
|
30
30
|
var import_es_module_lexer = __toModule(require("es-module-lexer"));
|
|
31
31
|
var import_logger = __toModule(require("./logger.cjs"));
|
|
32
|
+
var IMPORT_META_REGEX = /^import\.meta(\.\w+)+/;
|
|
32
33
|
var ModuleNameType;
|
|
33
34
|
(function(ModuleNameType2) {
|
|
34
35
|
ModuleNameType2["string"] = "string";
|
|
@@ -37,11 +38,13 @@ var ModuleNameType;
|
|
|
37
38
|
async function getImportMetadata(compiledSource) {
|
|
38
39
|
const imports = [];
|
|
39
40
|
const dynamicImports = [];
|
|
41
|
+
const importMeta = [];
|
|
40
42
|
const [moduleImportLocations] = await (0, import_es_module_lexer.parse)(compiledSource);
|
|
41
43
|
for (const moduleImportLocation of moduleImportLocations) {
|
|
42
44
|
let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
|
|
43
45
|
const isStatic = moduleImportLocation.d === -1;
|
|
44
46
|
const isDynamic = moduleImportLocation.d > -1;
|
|
47
|
+
const isMeta = moduleImportLocation.d === -2;
|
|
45
48
|
const location = {
|
|
46
49
|
startColumn: moduleImportLocation.s,
|
|
47
50
|
endColumn: moduleImportLocation.e
|
|
@@ -64,10 +67,24 @@ async function getImportMetadata(compiledSource) {
|
|
|
64
67
|
});
|
|
65
68
|
} else if (isStatic) {
|
|
66
69
|
imports.push({moduleSpecifier, location});
|
|
70
|
+
} else if (isMeta) {
|
|
71
|
+
const metaMatch = IMPORT_META_REGEX.exec(compiledSource.substring(moduleImportLocation.s));
|
|
72
|
+
if (metaMatch) {
|
|
73
|
+
const statement = metaMatch[0];
|
|
74
|
+
const extraLength = statement.length - 11;
|
|
75
|
+
importMeta.push({
|
|
76
|
+
statement,
|
|
77
|
+
location: {
|
|
78
|
+
startColumn: moduleImportLocation.s,
|
|
79
|
+
endColumn: moduleImportLocation.e + extraLength
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
85
|
return {
|
|
70
86
|
imports,
|
|
71
|
-
dynamicImports
|
|
87
|
+
dynamicImports,
|
|
88
|
+
importMeta
|
|
72
89
|
};
|
|
73
90
|
}
|
package/build/es/bundle.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import type { BundleGroups } from '@lwrjs/types';
|
|
2
2
|
export declare function getGroupName(rawSpecifier: string, groupsConfig: BundleGroups): string | undefined;
|
|
3
3
|
export declare function isGroupie(rawSpecifier: string, groupsConfig: BundleGroups): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Create an AMD Alias to another AMD module
|
|
6
|
+
*
|
|
7
|
+
* In the spirit of...
|
|
8
|
+
* LWR.define('alias', 'og', og=>og);
|
|
9
|
+
*
|
|
10
|
+
* But if OG has a default it is exposed as exports.default
|
|
11
|
+
*
|
|
12
|
+
* All enumerable properties of og are exposed as enumerable properties of exports.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare function createAmdAlias(aliasSpecifier: string, originalSpecifier: string): string;
|
|
4
16
|
//# sourceMappingURL=bundle.d.ts.map
|
package/build/es/bundle.js
CHANGED
|
@@ -13,4 +13,27 @@ export function isGroupie(rawSpecifier, groupsConfig) {
|
|
|
13
13
|
}
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Create an AMD Alias to another AMD module
|
|
18
|
+
*
|
|
19
|
+
* In the spirit of...
|
|
20
|
+
* LWR.define('alias', 'og', og=>og);
|
|
21
|
+
*
|
|
22
|
+
* But if OG has a default it is exposed as exports.default
|
|
23
|
+
*
|
|
24
|
+
* All enumerable properties of og are exposed as enumerable properties of exports.
|
|
25
|
+
*
|
|
26
|
+
*/
|
|
27
|
+
export function createAmdAlias(aliasSpecifier, originalSpecifier) {
|
|
28
|
+
const builder = [];
|
|
29
|
+
// Define statement
|
|
30
|
+
builder.push(`LWR.define('${aliasSpecifier}',['exports','${originalSpecifier}'],function(e,m){`);
|
|
31
|
+
// un-wrap default
|
|
32
|
+
builder.push(`e.default=m&&'object'==typeof m&&'default'in m?m.default:m;`);
|
|
33
|
+
// Expose enumerable properties
|
|
34
|
+
builder.push(`Object.keys(m).forEach(function(n){'default'===n||e.hasOwnProperty(n)||Object.defineProperty(e,n,{enumerable:!0,get:function(){return m[n]}})});`);
|
|
35
|
+
// End the define
|
|
36
|
+
builder.push('});');
|
|
37
|
+
return builder.join('');
|
|
38
|
+
}
|
|
16
39
|
//# sourceMappingURL=bundle.js.map
|
package/build/es/env.js
CHANGED
|
@@ -21,8 +21,8 @@ export function getFeatureFlags() {
|
|
|
21
21
|
? true
|
|
22
22
|
: false,
|
|
23
23
|
// AMD Module Bundles include un-versioned aliases
|
|
24
|
-
|
|
25
|
-
process.env.
|
|
24
|
+
EXPERIMENTAL_UNVERSIONED_ALIASES: process.env.EXPERIMENTAL_UNVERSIONED_ALIASES !== undefined &&
|
|
25
|
+
process.env.EXPERIMENTAL_UNVERSIONED_ALIASES.toLowerCase() === 'true'
|
|
26
26
|
? true
|
|
27
27
|
: false,
|
|
28
28
|
};
|
package/build/es/html-meta.d.ts
CHANGED
|
@@ -7,5 +7,9 @@ export declare function isSelfUrl(url: string): boolean;
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function extractMetadataFromHtml(htmlSource: string): Promise<RenderedViewMetadata>;
|
|
9
9
|
export declare const HYDRATE_DIRECTIVE = "lwr:hydrate";
|
|
10
|
-
export declare
|
|
10
|
+
export declare const HYDRATE_LOAD_VALUE = "load";
|
|
11
|
+
export declare const HYDRATE_CLIENT_VALUE = "client-only";
|
|
12
|
+
export declare function getHydrateDirective(props?: Record<string, string>): string | undefined;
|
|
13
|
+
export declare function isHydrateOnLoad(props?: {}): boolean;
|
|
14
|
+
export declare function isCsrIsland(props?: {}): boolean;
|
|
11
15
|
//# sourceMappingURL=html-meta.d.ts.map
|
package/build/es/html-meta.js
CHANGED
|
@@ -106,7 +106,19 @@ export async function extractMetadataFromHtml(htmlSource) {
|
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
export const HYDRATE_DIRECTIVE = 'lwr:hydrate';
|
|
109
|
-
export
|
|
110
|
-
|
|
109
|
+
export const HYDRATE_LOAD_VALUE = 'load';
|
|
110
|
+
export const HYDRATE_CLIENT_VALUE = 'client-only';
|
|
111
|
+
const HYDRATION_VALUES = [HYDRATE_LOAD_VALUE, HYDRATE_CLIENT_VALUE];
|
|
112
|
+
export function getHydrateDirective(props = {}) {
|
|
113
|
+
const rawValue = props[HYDRATE_DIRECTIVE];
|
|
114
|
+
const value = rawValue === 'true' ? HYDRATE_LOAD_VALUE : rawValue; // valueless hyration directives => lwr:hydrate="load"
|
|
115
|
+
if (HYDRATION_VALUES.includes(value))
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
export function isHydrateOnLoad(props = {}) {
|
|
119
|
+
return getHydrateDirective(props) === HYDRATE_LOAD_VALUE;
|
|
120
|
+
}
|
|
121
|
+
export function isCsrIsland(props = {}) {
|
|
122
|
+
return getHydrateDirective(props) === HYDRATE_CLIENT_VALUE;
|
|
111
123
|
}
|
|
112
124
|
//# sourceMappingURL=html-meta.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parse as parseImports } from 'es-module-lexer';
|
|
2
2
|
import { DEBUG, logger, VERBOSE } from './logger.js';
|
|
3
|
+
const IMPORT_META_REGEX = /^import\.meta(\.\w+)+/;
|
|
3
4
|
export var ModuleNameType;
|
|
4
5
|
(function (ModuleNameType) {
|
|
5
6
|
ModuleNameType["string"] = "string";
|
|
@@ -8,6 +9,7 @@ export var ModuleNameType;
|
|
|
8
9
|
export async function getImportMetadata(compiledSource) {
|
|
9
10
|
const imports = [];
|
|
10
11
|
const dynamicImports = [];
|
|
12
|
+
const importMeta = [];
|
|
11
13
|
// Use very fast parser to get the location of the imports/exports
|
|
12
14
|
const [moduleImportLocations] = await parseImports(compiledSource);
|
|
13
15
|
for (const moduleImportLocation of moduleImportLocations) {
|
|
@@ -15,6 +17,7 @@ export async function getImportMetadata(compiledSource) {
|
|
|
15
17
|
let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
|
|
16
18
|
const isStatic = moduleImportLocation.d === -1;
|
|
17
19
|
const isDynamic = moduleImportLocation.d > -1;
|
|
20
|
+
const isMeta = moduleImportLocation.d === -2;
|
|
18
21
|
const location = {
|
|
19
22
|
startColumn: moduleImportLocation.s,
|
|
20
23
|
endColumn: moduleImportLocation.e,
|
|
@@ -40,10 +43,27 @@ export async function getImportMetadata(compiledSource) {
|
|
|
40
43
|
else if (isStatic) {
|
|
41
44
|
imports.push({ moduleSpecifier, location });
|
|
42
45
|
}
|
|
46
|
+
else if (isMeta) {
|
|
47
|
+
// moduleImportLocation.s => moduleImportLocation.e only captures "import.meta"
|
|
48
|
+
// this regex will capture the entire statement, eg: `import.meta.env.SSR"
|
|
49
|
+
const metaMatch = IMPORT_META_REGEX.exec(compiledSource.substring(moduleImportLocation.s));
|
|
50
|
+
if (metaMatch) {
|
|
51
|
+
const statement = metaMatch[0];
|
|
52
|
+
const extraLength = statement.length - 11; // to include meta property, eg: ".env.SSR"
|
|
53
|
+
importMeta.push({
|
|
54
|
+
statement,
|
|
55
|
+
location: {
|
|
56
|
+
startColumn: moduleImportLocation.s,
|
|
57
|
+
endColumn: moduleImportLocation.e + extraLength,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
43
62
|
}
|
|
44
63
|
return {
|
|
45
64
|
imports,
|
|
46
65
|
dynamicImports,
|
|
66
|
+
importMeta,
|
|
47
67
|
};
|
|
48
68
|
}
|
|
49
69
|
//# sourceMappingURL=import-metadata.js.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.0-alpha.
|
|
7
|
+
"version": "0.10.0-alpha.16",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"rollup": "^2.78.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@lwrjs/diagnostics": "0.10.0-alpha.
|
|
66
|
-
"@lwrjs/types": "0.10.0-alpha.
|
|
65
|
+
"@lwrjs/diagnostics": "0.10.0-alpha.16",
|
|
66
|
+
"@lwrjs/types": "0.10.0-alpha.16",
|
|
67
67
|
"@types/mime-types": "2.1.1",
|
|
68
68
|
"@types/path-to-regexp": "^1.7.0"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=16.0.0 <20"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "c5a13d471330c0f738d0c783fd1b69f456c544bd"
|
|
74
74
|
}
|