@lwrjs/shared-utils 0.10.0-alpha.13 → 0.10.0-alpha.15
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 +37 -0
- package/build/cjs/env.cjs +3 -2
- package/build/cjs/html-meta.cjs +22 -0
- package/build/cjs/identity.cjs +2 -2
- package/build/cjs/import-metadata.cjs +23 -2
- package/build/cjs/index.cjs +1 -0
- package/build/es/bundle.d.ts +16 -0
- package/build/es/bundle.js +39 -0
- package/build/es/env.js +13 -8
- package/build/es/html-meta.d.ts +6 -0
- package/build/es/html-meta.js +16 -0
- package/build/es/identity.d.ts +1 -1
- package/build/es/identity.js +2 -2
- package/build/es/import-metadata.d.ts +1 -1
- package/build/es/import-metadata.js +26 -1
- package/build/es/index.d.ts +1 -0
- package/build/es/index.js +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {get: all[name], enumerable: true});
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// packages/@lwrjs/shared-utils/src/bundle.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
createAmdAlias: () => createAmdAlias,
|
|
12
|
+
getGroupName: () => getGroupName,
|
|
13
|
+
isGroupie: () => isGroupie
|
|
14
|
+
});
|
|
15
|
+
function getGroupName(rawSpecifier, groupsConfig) {
|
|
16
|
+
for (const [groupName, groupies] of Object.entries(groupsConfig)) {
|
|
17
|
+
if (groupies.indexOf(rawSpecifier) >= 0) {
|
|
18
|
+
return groupName;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function isGroupie(rawSpecifier, groupsConfig) {
|
|
23
|
+
for (const groupies of Object.values(groupsConfig)) {
|
|
24
|
+
if (groupies.indexOf(rawSpecifier) >= 0) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
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
|
@@ -12,9 +12,10 @@ __export(exports, {
|
|
|
12
12
|
});
|
|
13
13
|
function getFeatureFlags() {
|
|
14
14
|
return {
|
|
15
|
+
ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== void 0 && process.env.ASSETS_ON_LAMBDA.toLowerCase() === "true" ? true : false,
|
|
15
16
|
LEGACY_LOADER: process.env.LEGACY_LOADER !== void 0 && process.env.LEGACY_LOADER.toLowerCase() === "true" ? true : false,
|
|
16
|
-
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== void 0 && process.env.SSR_STATIC_BUNDLES.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
|
+
EXPERIMENTAL_UNVERSIONED_ALIASES: process.env.EXPERIMENTAL_UNVERSIONED_ALIASES !== void 0 && process.env.EXPERIMENTAL_UNVERSIONED_ALIASES.toLowerCase() === "true" ? true : false
|
|
19
20
|
};
|
|
20
21
|
}
|
package/build/cjs/html-meta.cjs
CHANGED
|
@@ -24,7 +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,
|
|
28
|
+
HYDRATE_DIRECTIVE: () => HYDRATE_DIRECTIVE,
|
|
29
|
+
HYDRATE_LOAD_VALUE: () => HYDRATE_LOAD_VALUE,
|
|
27
30
|
extractMetadataFromHtml: () => extractMetadataFromHtml,
|
|
31
|
+
getHydrateDirective: () => getHydrateDirective,
|
|
32
|
+
isCsrIsland: () => isCsrIsland,
|
|
33
|
+
isHydrateOnLoad: () => isHydrateOnLoad,
|
|
28
34
|
isRelative: () => isRelative,
|
|
29
35
|
isSelfUrl: () => isSelfUrl
|
|
30
36
|
});
|
|
@@ -117,3 +123,19 @@ async function extractMetadataFromHtml(htmlSource) {
|
|
|
117
123
|
inputStream.pipe(parser);
|
|
118
124
|
});
|
|
119
125
|
}
|
|
126
|
+
var HYDRATE_DIRECTIVE = "lwr:hydrate";
|
|
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;
|
|
141
|
+
}
|
package/build/cjs/identity.cjs
CHANGED
|
@@ -182,11 +182,11 @@ function slugify(name) {
|
|
|
182
182
|
function getPropFromAttrName(propName) {
|
|
183
183
|
return propName.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
184
184
|
}
|
|
185
|
-
function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}) {
|
|
185
|
+
function getModuleUriPrefix({apiVersion, bundle, format, compat, basePath}, {locale, environment} = {}, bundleId) {
|
|
186
186
|
const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
|
|
187
187
|
const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : "";
|
|
188
188
|
if (bundle) {
|
|
189
|
-
return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}
|
|
189
|
+
return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/${bundleId || "0"}/module/mi/`;
|
|
190
190
|
} else {
|
|
191
191
|
return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
|
|
192
192
|
}
|
|
@@ -28,6 +28,8 @@ __export(exports, {
|
|
|
28
28
|
getImportMetadata: () => getImportMetadata
|
|
29
29
|
});
|
|
30
30
|
var import_es_module_lexer = __toModule(require("es-module-lexer"));
|
|
31
|
+
var import_logger = __toModule(require("./logger.cjs"));
|
|
32
|
+
var IMPORT_META_REGEX = /^import\.meta(\.\w+)+/;
|
|
31
33
|
var ModuleNameType;
|
|
32
34
|
(function(ModuleNameType2) {
|
|
33
35
|
ModuleNameType2["string"] = "string";
|
|
@@ -36,11 +38,13 @@ var ModuleNameType;
|
|
|
36
38
|
async function getImportMetadata(compiledSource) {
|
|
37
39
|
const imports = [];
|
|
38
40
|
const dynamicImports = [];
|
|
41
|
+
const importMeta = [];
|
|
39
42
|
const [moduleImportLocations] = await (0, import_es_module_lexer.parse)(compiledSource);
|
|
40
43
|
for (const moduleImportLocation of moduleImportLocations) {
|
|
41
44
|
let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
|
|
42
45
|
const isStatic = moduleImportLocation.d === -1;
|
|
43
46
|
const isDynamic = moduleImportLocation.d > -1;
|
|
47
|
+
const isMeta = moduleImportLocation.d === -2;
|
|
44
48
|
const location = {
|
|
45
49
|
startColumn: moduleImportLocation.s,
|
|
46
50
|
endColumn: moduleImportLocation.e
|
|
@@ -49,21 +53,38 @@ async function getImportMetadata(compiledSource) {
|
|
|
49
53
|
const isStringLiteral = moduleSpecifier.startsWith("'") || moduleSpecifier.startsWith('"');
|
|
50
54
|
const moduleNameType = isStringLiteral ? ModuleNameType.string : ModuleNameType.unresolved;
|
|
51
55
|
moduleSpecifier = isStringLiteral ? moduleSpecifier.slice(1, -1) : moduleSpecifier;
|
|
56
|
+
if (import_logger.logger.currentLevel === import_logger.DEBUG || import_logger.logger.currentLevel === import_logger.VERBOSE) {
|
|
57
|
+
import_logger.logger.debug(`[import-metadata] Import from dynamic import ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.se)} -> ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.s)}`);
|
|
58
|
+
}
|
|
52
59
|
dynamicImports.push({
|
|
53
60
|
moduleSpecifier,
|
|
54
61
|
moduleNameType,
|
|
55
62
|
location,
|
|
56
63
|
importLocation: {
|
|
57
|
-
startColumn: moduleImportLocation.
|
|
64
|
+
startColumn: moduleImportLocation.ss,
|
|
58
65
|
endColumn: moduleImportLocation.s
|
|
59
66
|
}
|
|
60
67
|
});
|
|
61
68
|
} else if (isStatic) {
|
|
62
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
|
+
}
|
|
63
83
|
}
|
|
64
84
|
}
|
|
65
85
|
return {
|
|
66
86
|
imports,
|
|
67
|
-
dynamicImports
|
|
87
|
+
dynamicImports,
|
|
88
|
+
importMeta
|
|
68
89
|
};
|
|
69
90
|
}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -34,3 +34,4 @@ __exportStar(exports, __toModule(require("./urls.cjs")));
|
|
|
34
34
|
__exportStar(exports, __toModule(require("./env.cjs")));
|
|
35
35
|
__exportStar(exports, __toModule(require("./logger.cjs")));
|
|
36
36
|
__exportStar(exports, __toModule(require("./lwr-app-observer.cjs")));
|
|
37
|
+
__exportStar(exports, __toModule(require("./bundle.cjs")));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BundleGroups } from '@lwrjs/types';
|
|
2
|
+
export declare function getGroupName(rawSpecifier: string, groupsConfig: BundleGroups): string | undefined;
|
|
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;
|
|
16
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function getGroupName(rawSpecifier, groupsConfig) {
|
|
2
|
+
for (const [groupName, groupies] of Object.entries(groupsConfig)) {
|
|
3
|
+
if (groupies.indexOf(rawSpecifier) >= 0) {
|
|
4
|
+
return groupName;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export function isGroupie(rawSpecifier, groupsConfig) {
|
|
9
|
+
for (const groupies of Object.values(groupsConfig)) {
|
|
10
|
+
if (groupies.indexOf(rawSpecifier) >= 0) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
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
|
+
}
|
|
39
|
+
//# sourceMappingURL=bundle.js.map
|
package/build/es/env.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export function getFeatureFlags() {
|
|
2
2
|
// Add any new feature flags here to parse from environment variables
|
|
3
3
|
return {
|
|
4
|
-
//
|
|
5
|
-
|
|
4
|
+
// Should we load load the assets from the lambda on MRT
|
|
5
|
+
ASSETS_ON_LAMBDA: process.env.ASSETS_ON_LAMBDA !== undefined &&
|
|
6
|
+
process.env.ASSETS_ON_LAMBDA.toLowerCase() === 'true'
|
|
6
7
|
? true
|
|
7
8
|
: false,
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
process.env.SSR_STATIC_BUNDLES.toLowerCase() === 'true'
|
|
9
|
+
// DEFAULT LEGACY_LOADER = false;
|
|
10
|
+
LEGACY_LOADER: process.env.LEGACY_LOADER !== undefined && process.env.LEGACY_LOADER.toLowerCase() === 'true'
|
|
11
11
|
? true
|
|
12
12
|
: false,
|
|
13
13
|
// Should we use a js worker for SSR, sand-boxing = false (use locker for ssr sand-boxing)
|
|
@@ -15,9 +15,14 @@ export function getFeatureFlags() {
|
|
|
15
15
|
process.env.SSR_SANDBOX_WORKER.toLowerCase() === 'true'
|
|
16
16
|
? true
|
|
17
17
|
: false,
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
process.env.
|
|
18
|
+
// SSR should concatenate bundles, default = false
|
|
19
|
+
SSR_STATIC_BUNDLES: process.env.SSR_STATIC_BUNDLES !== undefined &&
|
|
20
|
+
process.env.SSR_STATIC_BUNDLES.toLowerCase() === 'true'
|
|
21
|
+
? true
|
|
22
|
+
: false,
|
|
23
|
+
// AMD Module Bundles include un-versioned aliases
|
|
24
|
+
EXPERIMENTAL_UNVERSIONED_ALIASES: process.env.EXPERIMENTAL_UNVERSIONED_ALIASES !== undefined &&
|
|
25
|
+
process.env.EXPERIMENTAL_UNVERSIONED_ALIASES.toLowerCase() === 'true'
|
|
21
26
|
? true
|
|
22
27
|
: false,
|
|
23
28
|
};
|
package/build/es/html-meta.d.ts
CHANGED
|
@@ -6,4 +6,10 @@ export declare function isSelfUrl(url: string): boolean;
|
|
|
6
6
|
* @param htmlSource - An HTML string to parse
|
|
7
7
|
*/
|
|
8
8
|
export declare function extractMetadataFromHtml(htmlSource: string): Promise<RenderedViewMetadata>;
|
|
9
|
+
export declare const HYDRATE_DIRECTIVE = "lwr:hydrate";
|
|
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;
|
|
9
15
|
//# sourceMappingURL=html-meta.d.ts.map
|
package/build/es/html-meta.js
CHANGED
|
@@ -105,4 +105,20 @@ export async function extractMetadataFromHtml(htmlSource) {
|
|
|
105
105
|
inputStream.pipe(parser);
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
|
+
export const HYDRATE_DIRECTIVE = 'lwr:hydrate';
|
|
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;
|
|
123
|
+
}
|
|
108
124
|
//# sourceMappingURL=html-meta.js.map
|
package/build/es/identity.d.ts
CHANGED
|
@@ -129,7 +129,7 @@ export declare function getPropFromAttrName(propName: string): string;
|
|
|
129
129
|
* @param param0 - URI props from the Runtime Environment
|
|
130
130
|
* @param param1 - URI props from the Runtime Params
|
|
131
131
|
*/
|
|
132
|
-
export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams): string;
|
|
132
|
+
export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }: RuntimeEnvironment, { locale, environment }?: RuntimeParams, bundleId?: string): string;
|
|
133
133
|
/**
|
|
134
134
|
* Create a URI Mapping API URI prefix, stopping where the specifiers would be (at "mp/")
|
|
135
135
|
* @param param0 - URI props from the Runtime Environment
|
package/build/es/identity.js
CHANGED
|
@@ -221,11 +221,11 @@ export function getPropFromAttrName(propName) {
|
|
|
221
221
|
* @param param0 - URI props from the Runtime Environment
|
|
222
222
|
* @param param1 - URI props from the Runtime Params
|
|
223
223
|
*/
|
|
224
|
-
export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }, { locale, environment } = {}) {
|
|
224
|
+
export function getModuleUriPrefix({ apiVersion, bundle, format, compat, basePath }, { locale, environment } = {}, bundleId) {
|
|
225
225
|
const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : '';
|
|
226
226
|
const environmentPart = environment ? `/${ENVIRONMENT_SIGIL}/${environment}` : '';
|
|
227
227
|
if (bundle) {
|
|
228
|
-
return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}
|
|
228
|
+
return `${basePath}/${apiVersion}/bundle/${format}${localePart}${environmentPart}/${BUNDLE_SIGIL}/${bundleId || '0'}/module/mi/`;
|
|
229
229
|
}
|
|
230
230
|
else {
|
|
231
231
|
return `${basePath}/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { parse as parseImports } from 'es-module-lexer';
|
|
2
|
+
import { DEBUG, logger, VERBOSE } from './logger.js';
|
|
3
|
+
const IMPORT_META_REGEX = /^import\.meta(\.\w+)+/;
|
|
2
4
|
export var ModuleNameType;
|
|
3
5
|
(function (ModuleNameType) {
|
|
4
6
|
ModuleNameType["string"] = "string";
|
|
@@ -7,6 +9,7 @@ export var ModuleNameType;
|
|
|
7
9
|
export async function getImportMetadata(compiledSource) {
|
|
8
10
|
const imports = [];
|
|
9
11
|
const dynamicImports = [];
|
|
12
|
+
const importMeta = [];
|
|
10
13
|
// Use very fast parser to get the location of the imports/exports
|
|
11
14
|
const [moduleImportLocations] = await parseImports(compiledSource);
|
|
12
15
|
for (const moduleImportLocation of moduleImportLocations) {
|
|
@@ -14,6 +17,7 @@ export async function getImportMetadata(compiledSource) {
|
|
|
14
17
|
let moduleSpecifier = compiledSource.substring(moduleImportLocation.s, moduleImportLocation.e);
|
|
15
18
|
const isStatic = moduleImportLocation.d === -1;
|
|
16
19
|
const isDynamic = moduleImportLocation.d > -1;
|
|
20
|
+
const isMeta = moduleImportLocation.d === -2;
|
|
17
21
|
const location = {
|
|
18
22
|
startColumn: moduleImportLocation.s,
|
|
19
23
|
endColumn: moduleImportLocation.e,
|
|
@@ -22,12 +26,16 @@ export async function getImportMetadata(compiledSource) {
|
|
|
22
26
|
const isStringLiteral = moduleSpecifier.startsWith("'") || moduleSpecifier.startsWith('"');
|
|
23
27
|
const moduleNameType = isStringLiteral ? ModuleNameType.string : ModuleNameType.unresolved;
|
|
24
28
|
moduleSpecifier = isStringLiteral ? moduleSpecifier.slice(1, -1) : moduleSpecifier; // remove quotes
|
|
29
|
+
// Expecting: import(rootSpecifier) -> import(
|
|
30
|
+
if (logger.currentLevel === DEBUG || logger.currentLevel === VERBOSE) {
|
|
31
|
+
logger.debug(`[import-metadata] Import from dynamic import ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.se)} -> ${compiledSource.slice(moduleImportLocation.ss, moduleImportLocation.s)}`);
|
|
32
|
+
}
|
|
25
33
|
dynamicImports.push({
|
|
26
34
|
moduleSpecifier,
|
|
27
35
|
moduleNameType,
|
|
28
36
|
location,
|
|
29
37
|
importLocation: {
|
|
30
|
-
startColumn: moduleImportLocation.
|
|
38
|
+
startColumn: moduleImportLocation.ss,
|
|
31
39
|
endColumn: moduleImportLocation.s,
|
|
32
40
|
},
|
|
33
41
|
});
|
|
@@ -35,10 +43,27 @@ export async function getImportMetadata(compiledSource) {
|
|
|
35
43
|
else if (isStatic) {
|
|
36
44
|
imports.push({ moduleSpecifier, location });
|
|
37
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
|
+
}
|
|
38
62
|
}
|
|
39
63
|
return {
|
|
40
64
|
imports,
|
|
41
65
|
dynamicImports,
|
|
66
|
+
importMeta,
|
|
42
67
|
};
|
|
43
68
|
}
|
|
44
69
|
//# sourceMappingURL=import-metadata.js.map
|
package/build/es/index.d.ts
CHANGED
package/build/es/index.js
CHANGED
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.15",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"build/**/*.d.ts"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"es-module-lexer": "^
|
|
48
|
+
"es-module-lexer": "^1.2.1",
|
|
49
49
|
"fast-json-stable-stringify": "^2.1.0",
|
|
50
50
|
"magic-string": "^0.30.0",
|
|
51
51
|
"mime-types": "^2.1.33",
|
|
@@ -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.15",
|
|
66
|
+
"@lwrjs/types": "0.10.0-alpha.15",
|
|
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": "70557f63a46167c40cf1415f12af69f78ae402d6"
|
|
74
74
|
}
|