@lwrjs/shared-utils 0.6.0-alpha.1 → 0.6.0-alpha.10
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/fs.cjs +2 -0
- package/build/cjs/html-meta.cjs +29 -4
- package/build/cjs/identity.cjs +7 -2
- package/build/cjs/index.cjs +2 -0
- package/build/cjs/link.cjs +32 -0
- package/build/cjs/mappings.cjs +2 -2
- package/build/cjs/tasks.cjs +72 -0
- package/build/es/fs.d.ts +2 -0
- package/build/es/fs.js +2 -0
- package/build/es/html-meta.js +30 -4
- package/build/es/identity.d.ts +8 -1
- package/build/es/identity.js +11 -1
- package/build/es/index.d.ts +2 -0
- package/build/es/index.js +2 -0
- package/build/es/link.d.ts +3 -0
- package/build/es/link.js +5 -0
- package/build/es/mappings.d.ts +2 -2
- package/build/es/mappings.js +4 -4
- package/build/es/tasks.d.ts +38 -0
- package/build/es/tasks.js +98 -0
- package/build/es/urls.d.ts +3 -9
- package/package.json +9 -6
package/build/cjs/fs.cjs
CHANGED
|
@@ -28,6 +28,7 @@ __export(exports, {
|
|
|
28
28
|
createFileWatcher: () => createFileWatcher,
|
|
29
29
|
getViewSourceFromFile: () => getViewSourceFromFile,
|
|
30
30
|
hashContent: () => hashContent,
|
|
31
|
+
mimeLookup: () => import_mime_types.lookup,
|
|
31
32
|
normalizeDirectory: () => normalizeDirectory,
|
|
32
33
|
normalizeResourcePath: () => normalizeResourcePath,
|
|
33
34
|
readFile: () => readFile,
|
|
@@ -41,6 +42,7 @@ var import_identity = __toModule(require("./identity.cjs"));
|
|
|
41
42
|
var import_object = __toModule(require("./object.cjs"));
|
|
42
43
|
var import_chokidar = __toModule(require("chokidar"));
|
|
43
44
|
var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
|
|
45
|
+
var import_mime_types = __toModule(require("mime-types"));
|
|
44
46
|
function hashContent(source) {
|
|
45
47
|
return import_crypto.default.createHash("md5").update(source).digest("hex");
|
|
46
48
|
}
|
package/build/cjs/html-meta.cjs
CHANGED
|
@@ -46,16 +46,28 @@ function parseAssetLocation(htmlSource, tagName, attrLocation) {
|
|
|
46
46
|
async function extractMetadataFromHtml(htmlSource) {
|
|
47
47
|
return new Promise((resolve, reject) => {
|
|
48
48
|
const customElements = [];
|
|
49
|
+
const openElements = new Set();
|
|
49
50
|
const assetReferences = [];
|
|
50
51
|
const parser = new import_parse5_sax_parser.default({sourceCodeLocationInfo: true});
|
|
52
|
+
const ceRefStack = [];
|
|
51
53
|
parser.on("startTag", ({
|
|
52
54
|
tagName,
|
|
53
55
|
sourceCodeLocation
|
|
54
56
|
}) => {
|
|
55
|
-
if (tagName.includes("-")) {
|
|
56
|
-
|
|
57
|
+
if (tagName.includes("-") && !openElements.has(tagName)) {
|
|
58
|
+
const {startOffset, endOffset} = sourceCodeLocation;
|
|
59
|
+
const ceRef = {tagName, location: {startOffset, endOffset}};
|
|
60
|
+
openElements.add(tagName);
|
|
61
|
+
if (ceRefStack.length) {
|
|
62
|
+
const last = ceRefStack[ceRefStack.length - 1];
|
|
63
|
+
last.children = last.children ? [...last.children, ceRef] : [ceRef];
|
|
64
|
+
ceRefStack.push(ceRef);
|
|
65
|
+
} else {
|
|
66
|
+
customElements.push(ceRef);
|
|
67
|
+
ceRefStack.push(ceRef);
|
|
68
|
+
}
|
|
57
69
|
}
|
|
58
|
-
if (tagName === "img" && sourceCodeLocation.attrs) {
|
|
70
|
+
if ((tagName === "img" || tagName === "script") && sourceCodeLocation.attrs) {
|
|
59
71
|
if (sourceCodeLocation.attrs.src) {
|
|
60
72
|
assetReferences.push(parseAssetLocation(htmlSource, tagName, sourceCodeLocation.attrs.src));
|
|
61
73
|
}
|
|
@@ -66,8 +78,21 @@ async function extractMetadataFromHtml(htmlSource) {
|
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
80
|
});
|
|
81
|
+
parser.on("endTag", ({
|
|
82
|
+
tagName,
|
|
83
|
+
sourceCodeLocation
|
|
84
|
+
}) => {
|
|
85
|
+
if (openElements.has(tagName)) {
|
|
86
|
+
const ceRef = ceRefStack.pop();
|
|
87
|
+
openElements.delete(tagName);
|
|
88
|
+
if (!ceRef) {
|
|
89
|
+
throw new Error(`Error extracting metadata: Unmatched custom element close tag for ${tagName}`);
|
|
90
|
+
}
|
|
91
|
+
ceRef.location.endOffset = sourceCodeLocation.endOffset;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
69
94
|
const inputStream = import_stream.Readable.from(htmlSource);
|
|
70
|
-
inputStream.on("end", () => resolve({customElements
|
|
95
|
+
inputStream.on("end", () => resolve({customElements, assetReferences}));
|
|
71
96
|
inputStream.on("error", (error) => reject(error));
|
|
72
97
|
inputStream.pipe(parser);
|
|
73
98
|
});
|
package/build/cjs/identity.cjs
CHANGED
|
@@ -53,6 +53,7 @@ __export(exports, {
|
|
|
53
53
|
normalizeVersionFromUri: () => normalizeVersionFromUri,
|
|
54
54
|
normalizeVersionToUri: () => normalizeVersionToUri,
|
|
55
55
|
parsePackageSpecifier: () => parsePackageSpecifier,
|
|
56
|
+
prettyModuleUriSuffix: () => prettyModuleUriSuffix,
|
|
56
57
|
slugify: () => slugify
|
|
57
58
|
});
|
|
58
59
|
var import_slugify = __toModule(require("slugify"));
|
|
@@ -74,7 +75,8 @@ var DEFAULT_LWR_BOOTSTRAP_CONFIG = {
|
|
|
74
75
|
syntheticShadow: false,
|
|
75
76
|
workers: {},
|
|
76
77
|
services: [],
|
|
77
|
-
configAsSrc: false
|
|
78
|
+
configAsSrc: false,
|
|
79
|
+
experimentalSSR: false
|
|
78
80
|
};
|
|
79
81
|
function normalizeVersionToUri(version) {
|
|
80
82
|
return version.replace(/\./g, "_");
|
|
@@ -82,6 +84,9 @@ function normalizeVersionToUri(version) {
|
|
|
82
84
|
function normalizeVersionFromUri(version) {
|
|
83
85
|
return version.replace(/_/g, ".");
|
|
84
86
|
}
|
|
87
|
+
function prettyModuleUriSuffix(specifier) {
|
|
88
|
+
return `${specifier.replace(/[\/\.\?\#]/g, "_")}`;
|
|
89
|
+
}
|
|
85
90
|
function explodeSpecifier(rawSpecifier) {
|
|
86
91
|
const decodedSpecifier = decodeURIComponent(rawSpecifier);
|
|
87
92
|
const versionMatch = decodedSpecifier.match(/(.+)\/v\/([a-zA-Z0-9-_.]+)$/);
|
|
@@ -188,7 +193,7 @@ function getModuleUriPrefix({apiVersion, bundle, format, compat}, {locale, envir
|
|
|
188
193
|
return `/${apiVersion}/module/${format}/${compat}${localePart}${environmentPart}/mi/`;
|
|
189
194
|
}
|
|
190
195
|
}
|
|
191
|
-
function getMappingUriPrefix({apiVersion,
|
|
196
|
+
function getMappingUriPrefix({apiVersion, format, compat}, {locale} = {}) {
|
|
192
197
|
const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : "";
|
|
193
198
|
return `/${apiVersion}/mapping/${format}/${compat}${localePart}/mp/`;
|
|
194
199
|
}
|
package/build/cjs/index.cjs
CHANGED
|
@@ -23,8 +23,10 @@ __exportStar(exports, __toModule(require("./fs.cjs")));
|
|
|
23
23
|
__exportStar(exports, __toModule(require("./html-meta.cjs")));
|
|
24
24
|
__exportStar(exports, __toModule(require("./identity.cjs")));
|
|
25
25
|
__exportStar(exports, __toModule(require("./interchangeable-modules.cjs")));
|
|
26
|
+
__exportStar(exports, __toModule(require("./link.cjs")));
|
|
26
27
|
__exportStar(exports, __toModule(require("./object.cjs")));
|
|
27
28
|
__exportStar(exports, __toModule(require("./serialize.cjs")));
|
|
29
|
+
__exportStar(exports, __toModule(require("./tasks.cjs")));
|
|
28
30
|
__exportStar(exports, __toModule(require("./typescript.cjs")));
|
|
29
31
|
__exportStar(exports, __toModule(require("./import-metadata.cjs")));
|
|
30
32
|
__exportStar(exports, __toModule(require("./graph.cjs")));
|
|
@@ -0,0 +1,32 @@
|
|
|
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/link.ts
|
|
25
|
+
__markAsModule(exports);
|
|
26
|
+
__export(exports, {
|
|
27
|
+
createStringBuilder: () => createStringBuilder
|
|
28
|
+
});
|
|
29
|
+
var import_magic_string = __toModule(require("magic-string"));
|
|
30
|
+
function createStringBuilder(source) {
|
|
31
|
+
return new import_magic_string.default(source);
|
|
32
|
+
}
|
package/build/cjs/mappings.cjs
CHANGED
|
@@ -36,10 +36,10 @@ async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeP
|
|
|
36
36
|
index: {}
|
|
37
37
|
};
|
|
38
38
|
for (const moduleId of moduleIds) {
|
|
39
|
-
const specifier = moduleId
|
|
39
|
+
const specifier = (0, import_identity.getSpecifier)(moduleId);
|
|
40
40
|
if (!visitedCache.has(specifier)) {
|
|
41
41
|
const depth = {static: import_graph.GraphDepth.ALL, dynamic: 0};
|
|
42
|
-
const moduleGraph = await (0, import_graph.getModuleGraphs)(
|
|
42
|
+
const moduleGraph = await (0, import_graph.getModuleGraphs)(specifier, {includeUris: true, includeLinkedDefinitions: true, depth}, moduleRegistry, runtimeEnvironment.bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
|
|
43
43
|
importMetadata = await toImportMetadata(moduleGraph, importMetadata, moduleRegistry, runtimeEnvironment, runtimeParams);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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/tasks.ts
|
|
9
|
+
__markAsModule(exports);
|
|
10
|
+
__export(exports, {
|
|
11
|
+
InflightTasks: () => InflightTasks,
|
|
12
|
+
TaskPool: () => TaskPool
|
|
13
|
+
});
|
|
14
|
+
var Task = class {
|
|
15
|
+
constructor(taskFunction, caller, resolve, reject) {
|
|
16
|
+
this.taskFunction = taskFunction;
|
|
17
|
+
this.caller = caller;
|
|
18
|
+
this.resolve = resolve;
|
|
19
|
+
this.reject = reject;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var TaskPool = class {
|
|
23
|
+
constructor(size) {
|
|
24
|
+
this.queue = [];
|
|
25
|
+
this.running = 0;
|
|
26
|
+
this.size = size || 15;
|
|
27
|
+
}
|
|
28
|
+
async execute(taskFunction, caller) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const task = new Task(taskFunction, caller || this, resolve, reject);
|
|
31
|
+
if (this.running >= this.size) {
|
|
32
|
+
this.queue.push(task);
|
|
33
|
+
} else {
|
|
34
|
+
this.start(task);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async start(task) {
|
|
39
|
+
this.running++;
|
|
40
|
+
try {
|
|
41
|
+
const ret = await task.taskFunction.bind(task.caller)();
|
|
42
|
+
task.resolve(ret);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
task.reject(err);
|
|
45
|
+
} finally {
|
|
46
|
+
this.running--;
|
|
47
|
+
this.runNext();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
runNext() {
|
|
51
|
+
const next = this.queue.shift();
|
|
52
|
+
if (next) {
|
|
53
|
+
this.start(next);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var InflightTasks = class {
|
|
58
|
+
constructor() {
|
|
59
|
+
this.tasks = new Map();
|
|
60
|
+
}
|
|
61
|
+
execute(id, taskCtor, caller) {
|
|
62
|
+
if (this.tasks.has(id)) {
|
|
63
|
+
return this.tasks.get(id);
|
|
64
|
+
} else {
|
|
65
|
+
const job = taskCtor.bind(caller || this)().finally(() => {
|
|
66
|
+
this.tasks.delete(id);
|
|
67
|
+
});
|
|
68
|
+
this.tasks.set(id, job);
|
|
69
|
+
return job;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
package/build/es/fs.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ResourcePaths, Watcher, ViewSource } from '@lwrjs/types';
|
|
3
|
+
import { lookup } from 'mime-types';
|
|
3
4
|
/**
|
|
4
5
|
* Create a hash string for a source
|
|
5
6
|
* @param source
|
|
@@ -39,4 +40,5 @@ export declare function canResolveView(source: string, type: string): boolean;
|
|
|
39
40
|
export declare function getViewSourceFromFile(source: string): ViewSource;
|
|
40
41
|
export declare function normalizeDirectory(dir: string, rootDir: string): string;
|
|
41
42
|
export declare function normalizeResourcePath(rawPath: string, { rootDir, assets, contentDir, layoutsDir }: ResourcePaths, allowUnresolvedAlias?: boolean): string;
|
|
43
|
+
export { lookup as mimeLookup };
|
|
42
44
|
//# sourceMappingURL=fs.d.ts.map
|
package/build/es/fs.js
CHANGED
|
@@ -5,6 +5,7 @@ import { slugify } from './identity.js';
|
|
|
5
5
|
import { debounce } from './object.js';
|
|
6
6
|
import chokidar from 'chokidar';
|
|
7
7
|
import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
|
|
8
|
+
import { lookup } from 'mime-types';
|
|
8
9
|
/**
|
|
9
10
|
* Create a hash string for a source
|
|
10
11
|
* @param source
|
|
@@ -135,4 +136,5 @@ export function normalizeResourcePath(rawPath, { rootDir, assets, contentDir, la
|
|
|
135
136
|
return alias;
|
|
136
137
|
});
|
|
137
138
|
}
|
|
139
|
+
export { lookup as mimeLookup };
|
|
138
140
|
//# sourceMappingURL=fs.js.map
|
package/build/es/html-meta.js
CHANGED
|
@@ -24,15 +24,30 @@ function parseAssetLocation(htmlSource, tagName, attrLocation) {
|
|
|
24
24
|
export async function extractMetadataFromHtml(htmlSource) {
|
|
25
25
|
return new Promise((resolve, reject) => {
|
|
26
26
|
const customElements = [];
|
|
27
|
+
const openElements = new Set();
|
|
27
28
|
const assetReferences = [];
|
|
28
29
|
const parser = new SAXParser({ sourceCodeLocationInfo: true }); // TODO: Would we need this in the future?
|
|
30
|
+
const ceRefStack = [];
|
|
29
31
|
parser.on('startTag', ({ tagName, sourceCodeLocation, }) => {
|
|
30
32
|
// custom elements
|
|
31
|
-
if (tagName.includes('-')) {
|
|
32
|
-
|
|
33
|
+
if (tagName.includes('-') && !openElements.has(tagName)) {
|
|
34
|
+
const { startOffset, endOffset } = sourceCodeLocation;
|
|
35
|
+
const ceRef = { tagName, location: { startOffset, endOffset } };
|
|
36
|
+
openElements.add(tagName);
|
|
37
|
+
if (ceRefStack.length) {
|
|
38
|
+
// nested CE
|
|
39
|
+
const last = ceRefStack[ceRefStack.length - 1];
|
|
40
|
+
last.children = last.children ? [...last.children, ceRef] : [ceRef];
|
|
41
|
+
ceRefStack.push(ceRef);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
customElements.push(ceRef);
|
|
45
|
+
ceRefStack.push(ceRef);
|
|
46
|
+
}
|
|
33
47
|
}
|
|
34
48
|
// <img src="asset-url"/>
|
|
35
|
-
|
|
49
|
+
// <script type="text/javascript" src="asset-url"></script>
|
|
50
|
+
if ((tagName === 'img' || tagName === 'script') && sourceCodeLocation.attrs) {
|
|
36
51
|
if (sourceCodeLocation.attrs.src) {
|
|
37
52
|
assetReferences.push(parseAssetLocation(htmlSource, tagName, sourceCodeLocation.attrs.src));
|
|
38
53
|
}
|
|
@@ -47,9 +62,20 @@ export async function extractMetadataFromHtml(htmlSource) {
|
|
|
47
62
|
}
|
|
48
63
|
}
|
|
49
64
|
});
|
|
65
|
+
parser.on('endTag', ({ tagName, sourceCodeLocation, }) => {
|
|
66
|
+
if (openElements.has(tagName)) {
|
|
67
|
+
const ceRef = ceRefStack.pop();
|
|
68
|
+
openElements.delete(tagName);
|
|
69
|
+
if (!ceRef) {
|
|
70
|
+
throw new Error(`Error extracting metadata: Unmatched custom element close tag for ${tagName}`);
|
|
71
|
+
}
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
73
|
+
ceRef.location.endOffset = sourceCodeLocation.endOffset;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
50
76
|
const inputStream = Readable.from(htmlSource);
|
|
51
77
|
// dedupe custom element references
|
|
52
|
-
inputStream.on('end', () => resolve({ customElements
|
|
78
|
+
inputStream.on('end', () => resolve({ customElements, assetReferences }));
|
|
53
79
|
inputStream.on('error', (error) => reject(error));
|
|
54
80
|
inputStream.pipe(parser);
|
|
55
81
|
});
|
package/build/es/identity.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare const DEFAULT_LWR_BOOTSTRAP_CONFIG: {
|
|
|
18
18
|
workers: {};
|
|
19
19
|
services: never[];
|
|
20
20
|
configAsSrc: boolean;
|
|
21
|
+
experimentalSSR: boolean;
|
|
21
22
|
};
|
|
22
23
|
declare type ModuleIdentifierPartial = Partial<AbstractModuleId>;
|
|
23
24
|
/**
|
|
@@ -32,6 +33,12 @@ export declare function normalizeVersionToUri(version: string): string;
|
|
|
32
33
|
* @example '1_0_0' => '1.0.0'
|
|
33
34
|
*/
|
|
34
35
|
export declare function normalizeVersionFromUri(version: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Create the last token for a module URL. Readable specifier for a URI
|
|
38
|
+
*
|
|
39
|
+
* examples/app/scoped/css?scoped=true => examples_app_scoped_css_scoped=true
|
|
40
|
+
*/
|
|
41
|
+
export declare function prettyModuleUriSuffix(specifier: string): string;
|
|
35
42
|
/**
|
|
36
43
|
* Create a partial Module Identifier from a specifier
|
|
37
44
|
* The Module Identifier is partial because the specifier may not contain a version
|
|
@@ -147,7 +154,7 @@ export declare function getModuleUriPrefix({ apiVersion, bundle, format, compat
|
|
|
147
154
|
* @param param0 - URI props from the Runtime Environment
|
|
148
155
|
* @param param1 - URI props from the Runtime Params
|
|
149
156
|
*/
|
|
150
|
-
export declare function getMappingUriPrefix({ apiVersion,
|
|
157
|
+
export declare function getMappingUriPrefix({ apiVersion, format, compat }: RuntimeEnvironment, { locale }?: RuntimeParams): string;
|
|
151
158
|
export { getCacheKeyFromJson };
|
|
152
159
|
export declare function isExternalUrl(url: string): boolean;
|
|
153
160
|
export declare function isBundleDefinition(definition: ModuleDefinition | BundleDefinition): definition is BundleDefinition;
|
package/build/es/identity.js
CHANGED
|
@@ -19,6 +19,7 @@ export const DEFAULT_LWR_BOOTSTRAP_CONFIG = {
|
|
|
19
19
|
workers: {},
|
|
20
20
|
services: [],
|
|
21
21
|
configAsSrc: false,
|
|
22
|
+
experimentalSSR: false,
|
|
22
23
|
};
|
|
23
24
|
/**
|
|
24
25
|
* Turn the dots in a version into underscores
|
|
@@ -36,6 +37,15 @@ export function normalizeVersionToUri(version) {
|
|
|
36
37
|
export function normalizeVersionFromUri(version) {
|
|
37
38
|
return version.replace(/_/g, '.');
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Create the last token for a module URL. Readable specifier for a URI
|
|
42
|
+
*
|
|
43
|
+
* examples/app/scoped/css?scoped=true => examples_app_scoped_css_scoped=true
|
|
44
|
+
*/
|
|
45
|
+
export function prettyModuleUriSuffix(specifier) {
|
|
46
|
+
// eslint-disable-next-line no-useless-escape
|
|
47
|
+
return `${specifier.replace(/[\/\.\?\#]/g, '_')}`;
|
|
48
|
+
}
|
|
39
49
|
export function explodeSpecifier(rawSpecifier) {
|
|
40
50
|
const decodedSpecifier = decodeURIComponent(rawSpecifier);
|
|
41
51
|
// Split up the version and bare specifier
|
|
@@ -245,7 +255,7 @@ export function getModuleUriPrefix({ apiVersion, bundle, format, compat }, { loc
|
|
|
245
255
|
* @param param0 - URI props from the Runtime Environment
|
|
246
256
|
* @param param1 - URI props from the Runtime Params
|
|
247
257
|
*/
|
|
248
|
-
export function getMappingUriPrefix({ apiVersion,
|
|
258
|
+
export function getMappingUriPrefix({ apiVersion, format, compat }, { locale } = {}) {
|
|
249
259
|
const localePart = locale ? `/${LOCALE_SIGIL}/${locale}` : '';
|
|
250
260
|
return `/${apiVersion}/mapping/${format}/${compat}${localePart}/mp/`;
|
|
251
261
|
}
|
package/build/es/index.d.ts
CHANGED
|
@@ -2,8 +2,10 @@ export * from './fs.js';
|
|
|
2
2
|
export * from './html-meta.js';
|
|
3
3
|
export * from './identity.js';
|
|
4
4
|
export * from './interchangeable-modules.js';
|
|
5
|
+
export * from './link.js';
|
|
5
6
|
export * from './object.js';
|
|
6
7
|
export * from './serialize.js';
|
|
8
|
+
export * from './tasks.js';
|
|
7
9
|
export * from './typescript.js';
|
|
8
10
|
export * from './import-metadata.js';
|
|
9
11
|
export * from './graph.js';
|
package/build/es/index.js
CHANGED
|
@@ -2,8 +2,10 @@ export * from './fs.js';
|
|
|
2
2
|
export * from './html-meta.js';
|
|
3
3
|
export * from './identity.js';
|
|
4
4
|
export * from './interchangeable-modules.js';
|
|
5
|
+
export * from './link.js';
|
|
5
6
|
export * from './object.js';
|
|
6
7
|
export * from './serialize.js';
|
|
8
|
+
export * from './tasks.js';
|
|
7
9
|
export * from './typescript.js';
|
|
8
10
|
export * from './import-metadata.js';
|
|
9
11
|
export * from './graph.js';
|
package/build/es/link.js
ADDED
package/build/es/mappings.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractModuleId, FlattenedModuleGraphs, ImportMetadata, ModuleBundler, ModuleRegistry, RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
/**
|
|
3
|
-
* Get the Import Metadata for the LWR Mapping Api (https://rfcs.lwc.dev/rfcs/
|
|
3
|
+
* Get the Import Metadata for the LWR Mapping Api (https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api)
|
|
4
4
|
*/
|
|
5
5
|
export declare function getImportMetadataMappings(moduleIds: AbstractModuleId[], runtimeEnvironment: RuntimeEnvironment, runtimeParams: RuntimeParams, moduleRegistry: ModuleRegistry, moduleBundler: ModuleBundler): Promise<ImportMetadata>;
|
|
6
6
|
/**
|
|
@@ -13,7 +13,7 @@ export declare function getImportMetadataMappings(moduleIds: AbstractModuleId[],
|
|
|
13
13
|
*
|
|
14
14
|
* @param moduleGraph FlattenedModuleGraphs created by the graph shared util
|
|
15
15
|
* @param existingImportMetadata Optional existing ImportMetadata. If provided the results will be a merge the two sets of URI mappings.
|
|
16
|
-
* @returns Returns ImportMetadata from a module graph in the format here -> https://rfcs.lwc.dev/rfcs/
|
|
16
|
+
* @returns Returns ImportMetadata from a module graph in the format here -> https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api#uri-mapping-resource-specification
|
|
17
17
|
*/
|
|
18
18
|
export declare function toImportMetadata(moduleGraph: FlattenedModuleGraphs, existingImportMetadata: ImportMetadata | undefined, moduleRegistry: ModuleRegistry, runtimeEnvironment: RuntimeEnvironment, runtimeParams?: RuntimeParams): Promise<ImportMetadata>;
|
|
19
19
|
//# sourceMappingURL=mappings.d.ts.map
|
package/build/es/mappings.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getModuleGraphs, GraphDepth } from './graph.js';
|
|
2
2
|
import { explodeSpecifier, getSpecifier, isBundleDefinition } from './identity.js';
|
|
3
3
|
/**
|
|
4
|
-
* Get the Import Metadata for the LWR Mapping Api (https://rfcs.lwc.dev/rfcs/
|
|
4
|
+
* Get the Import Metadata for the LWR Mapping Api (https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api)
|
|
5
5
|
*/
|
|
6
6
|
export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, runtimeParams, moduleRegistry, moduleBundler) {
|
|
7
7
|
const visitedCache = new Map();
|
|
@@ -10,13 +10,13 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
|
|
|
10
10
|
index: {},
|
|
11
11
|
};
|
|
12
12
|
for (const moduleId of moduleIds) {
|
|
13
|
-
const specifier = moduleId
|
|
13
|
+
const specifier = getSpecifier(moduleId);
|
|
14
14
|
// Check if we have already visited
|
|
15
15
|
if (!visitedCache.has(specifier)) {
|
|
16
16
|
// Traversal of the Module Graph is done to get all the URLS for discoverable static dependencies.
|
|
17
17
|
const depth = { static: GraphDepth.ALL, dynamic: 0 };
|
|
18
18
|
// eslint-disable-next-line no-await-in-loop
|
|
19
|
-
const moduleGraph = await getModuleGraphs(
|
|
19
|
+
const moduleGraph = await getModuleGraphs(specifier,
|
|
20
20
|
// include uris and linked definitions
|
|
21
21
|
{ includeUris: true, includeLinkedDefinitions: true, depth }, moduleRegistry, runtimeEnvironment.bundle ? moduleBundler : moduleRegistry, runtimeEnvironment, runtimeParams, visitedCache);
|
|
22
22
|
// Root module
|
|
@@ -36,7 +36,7 @@ export async function getImportMetadataMappings(moduleIds, runtimeEnvironment, r
|
|
|
36
36
|
*
|
|
37
37
|
* @param moduleGraph FlattenedModuleGraphs created by the graph shared util
|
|
38
38
|
* @param existingImportMetadata Optional existing ImportMetadata. If provided the results will be a merge the two sets of URI mappings.
|
|
39
|
-
* @returns Returns ImportMetadata from a module graph in the format here -> https://rfcs.lwc.dev/rfcs/
|
|
39
|
+
* @returns Returns ImportMetadata from a module graph in the format here -> https://rfcs.lwc.dev/rfcs/lwr/0000-mapping-api#uri-mapping-resource-specification
|
|
40
40
|
*/
|
|
41
41
|
export async function toImportMetadata(moduleGraph, existingImportMetadata = { imports: {}, index: {} }, moduleRegistry, runtimeEnvironment, runtimeParams = {}) {
|
|
42
42
|
// root module specifier
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pool is created of a given size
|
|
3
|
+
* If more tasks than that are asked to execute they are put in a queue until there is space in the pool
|
|
4
|
+
*/
|
|
5
|
+
export declare class TaskPool {
|
|
6
|
+
private size;
|
|
7
|
+
private queue;
|
|
8
|
+
private running;
|
|
9
|
+
constructor(size?: number);
|
|
10
|
+
/**
|
|
11
|
+
* Add a function that takes no arguments
|
|
12
|
+
* It will run as soon as there is room in the pool
|
|
13
|
+
*
|
|
14
|
+
* @param taskFunction - Function to run when there is space in the pool
|
|
15
|
+
* @param caller - The closer to use when calling the constructor
|
|
16
|
+
**/
|
|
17
|
+
execute(taskFunction: Function, caller?: any): Promise<any>;
|
|
18
|
+
private start;
|
|
19
|
+
private runNext;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Contains a map of tasks that are in progress
|
|
23
|
+
* Calls to execute with the id of a task in progress returns the running tasks
|
|
24
|
+
* If no task of that id is running a new task is created
|
|
25
|
+
*/
|
|
26
|
+
export declare class InflightTasks<Type> {
|
|
27
|
+
private tasks;
|
|
28
|
+
/**
|
|
29
|
+
* Return a promise per id. If one is already in flight return the promise.
|
|
30
|
+
* If not use the constructor to create a new
|
|
31
|
+
*
|
|
32
|
+
* @param id - Unique id for promise in question
|
|
33
|
+
* @param taskCtor - Function that create a promise for the id if needed
|
|
34
|
+
* @param caller - The closer to use when calling the constructor
|
|
35
|
+
*/
|
|
36
|
+
execute(id: string, taskCtor: Function, caller?: any): Promise<Type>;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=tasks.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
class Task {
|
|
2
|
+
constructor(taskFunction, caller, resolve, reject) {
|
|
3
|
+
this.taskFunction = taskFunction;
|
|
4
|
+
this.caller = caller;
|
|
5
|
+
this.resolve = resolve;
|
|
6
|
+
this.reject = reject;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A pool is created of a given size
|
|
11
|
+
* If more tasks than that are asked to execute they are put in a queue until there is space in the pool
|
|
12
|
+
*/
|
|
13
|
+
export class TaskPool {
|
|
14
|
+
constructor(size) {
|
|
15
|
+
this.queue = [];
|
|
16
|
+
this.running = 0;
|
|
17
|
+
this.size = size || 15;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Add a function that takes no arguments
|
|
21
|
+
* It will run as soon as there is room in the pool
|
|
22
|
+
*
|
|
23
|
+
* @param taskFunction - Function to run when there is space in the pool
|
|
24
|
+
* @param caller - The closer to use when calling the constructor
|
|
25
|
+
**/
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
27
|
+
async execute(taskFunction, caller) {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
const task = new Task(taskFunction, caller || this, resolve, reject);
|
|
30
|
+
if (this.running >= this.size) {
|
|
31
|
+
this.queue.push(task);
|
|
32
|
+
// TODO add to profiling
|
|
33
|
+
// console.log('[DEBUG] TaskPool Queue Size: ' + this.queue.length);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.start(task);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async start(task) {
|
|
41
|
+
// Add run next
|
|
42
|
+
this.running++;
|
|
43
|
+
try {
|
|
44
|
+
const ret = await task.taskFunction.bind(task.caller)();
|
|
45
|
+
task.resolve(ret);
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
task.reject(err);
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
this.running--;
|
|
52
|
+
this.runNext();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
runNext() {
|
|
56
|
+
const next = this.queue.shift();
|
|
57
|
+
if (next) {
|
|
58
|
+
// TODO add to profiling
|
|
59
|
+
// console.log('[DEBUG] TaskPool Queue Size: ' + this.queue.length);
|
|
60
|
+
this.start(next);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Contains a map of tasks that are in progress
|
|
66
|
+
* Calls to execute with the id of a task in progress returns the running tasks
|
|
67
|
+
* If no task of that id is running a new task is created
|
|
68
|
+
*/
|
|
69
|
+
export class InflightTasks {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.tasks = new Map();
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Return a promise per id. If one is already in flight return the promise.
|
|
75
|
+
* If not use the constructor to create a new
|
|
76
|
+
*
|
|
77
|
+
* @param id - Unique id for promise in question
|
|
78
|
+
* @param taskCtor - Function that create a promise for the id if needed
|
|
79
|
+
* @param caller - The closer to use when calling the constructor
|
|
80
|
+
*/
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
82
|
+
execute(id, taskCtor, caller) {
|
|
83
|
+
if (this.tasks.has(id)) {
|
|
84
|
+
return this.tasks.get(id);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const job = taskCtor
|
|
88
|
+
.bind(caller || this)()
|
|
89
|
+
.finally(() => {
|
|
90
|
+
// Once fulfilled remove form active jobs
|
|
91
|
+
this.tasks.delete(id);
|
|
92
|
+
});
|
|
93
|
+
this.tasks.set(id, job);
|
|
94
|
+
return job;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=tasks.js.map
|
package/build/es/urls.d.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RuntimeEnvironment, RuntimeParams } from '@lwrjs/types';
|
|
2
2
|
export declare function getClientBootstrapConfigurationUri(routeInfo: {
|
|
3
3
|
id: string;
|
|
4
4
|
url: string;
|
|
5
|
-
}, runtimeEnvironment:
|
|
6
|
-
apiVersion: string;
|
|
7
|
-
format: ModuleFormat;
|
|
8
|
-
}, runtimeParams?: RuntimeParams): string;
|
|
5
|
+
}, runtimeEnvironment: Required<Pick<RuntimeEnvironment, 'apiVersion' | 'format'>>, runtimeParams?: RuntimeParams): string;
|
|
9
6
|
export declare function getClientBootstrapConfigurationUriPrefix(routeInfo: {
|
|
10
7
|
id: string;
|
|
11
|
-
}, runtimeEnvironment:
|
|
12
|
-
apiVersion: string;
|
|
13
|
-
format: ModuleFormat;
|
|
14
|
-
}, runtimeParams?: RuntimeParams): string;
|
|
8
|
+
}, runtimeEnvironment: Required<Pick<RuntimeEnvironment, 'apiVersion' | 'format'>>, runtimeParams?: RuntimeParams): string;
|
|
15
9
|
/**
|
|
16
10
|
* Remove the suffix from config
|
|
17
11
|
*/
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.6.0-alpha.
|
|
8
|
-
"homepage": "https://
|
|
7
|
+
"version": "0.6.0-alpha.10",
|
|
8
|
+
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/salesforce/lwr.git",
|
|
@@ -35,18 +35,21 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"chokidar": "^3.4.0",
|
|
37
37
|
"es-module-lexer": "^0.3.18",
|
|
38
|
-
"esbuild": "^0.
|
|
38
|
+
"esbuild": "^0.9.7",
|
|
39
39
|
"fast-json-stable-stringify": "^2.1.0",
|
|
40
|
+
"magic-string": "^0.25.7",
|
|
41
|
+
"mime-types": "^2.1.33",
|
|
40
42
|
"parse5-sax-parser": "^6.0.1",
|
|
41
43
|
"slugify": "^1.4.5"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
|
-
"@lwrjs/diagnostics": "0.6.0-alpha.
|
|
45
|
-
"@lwrjs/types": "0.6.0-alpha.
|
|
46
|
+
"@lwrjs/diagnostics": "0.6.0-alpha.10",
|
|
47
|
+
"@lwrjs/types": "0.6.0-alpha.10",
|
|
48
|
+
"@types/mime-types": "2.1.1",
|
|
46
49
|
"@types/path-to-regexp": "^1.7.0"
|
|
47
50
|
},
|
|
48
51
|
"engines": {
|
|
49
52
|
"node": ">=14.15.4 <17"
|
|
50
53
|
},
|
|
51
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "85914e17d6214748489426252dd8fa41c8938b8f"
|
|
52
55
|
}
|