@lwrjs/shared-utils 0.6.0-alpha.4 → 0.6.0-alpha.8
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/identity.cjs +4 -0
- package/build/cjs/index.cjs +1 -0
- package/build/cjs/mappings.cjs +2 -2
- package/build/cjs/tasks.cjs +72 -0
- package/build/es/identity.d.ts +6 -0
- package/build/es/identity.js +9 -0
- package/build/es/index.d.ts +1 -0
- package/build/es/index.js +1 -0
- package/build/es/mappings.js +2 -2
- package/build/es/tasks.d.ts +38 -0
- package/build/es/tasks.js +98 -0
- package/package.json +5 -5
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"));
|
|
@@ -83,6 +84,9 @@ function normalizeVersionToUri(version) {
|
|
|
83
84
|
function normalizeVersionFromUri(version) {
|
|
84
85
|
return version.replace(/_/g, ".");
|
|
85
86
|
}
|
|
87
|
+
function prettyModuleUriSuffix(specifier) {
|
|
88
|
+
return `${specifier.replace(/[\/\.\?\#]/g, "_")}`;
|
|
89
|
+
}
|
|
86
90
|
function explodeSpecifier(rawSpecifier) {
|
|
87
91
|
const decodedSpecifier = decodeURIComponent(rawSpecifier);
|
|
88
92
|
const versionMatch = decodedSpecifier.match(/(.+)\/v\/([a-zA-Z0-9-_.]+)$/);
|
package/build/cjs/index.cjs
CHANGED
|
@@ -26,6 +26,7 @@ __exportStar(exports, __toModule(require("./interchangeable-modules.cjs")));
|
|
|
26
26
|
__exportStar(exports, __toModule(require("./link.cjs")));
|
|
27
27
|
__exportStar(exports, __toModule(require("./object.cjs")));
|
|
28
28
|
__exportStar(exports, __toModule(require("./serialize.cjs")));
|
|
29
|
+
__exportStar(exports, __toModule(require("./tasks.cjs")));
|
|
29
30
|
__exportStar(exports, __toModule(require("./typescript.cjs")));
|
|
30
31
|
__exportStar(exports, __toModule(require("./import-metadata.cjs")));
|
|
31
32
|
__exportStar(exports, __toModule(require("./graph.cjs")));
|
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/identity.d.ts
CHANGED
|
@@ -33,6 +33,12 @@ export declare function normalizeVersionToUri(version: string): string;
|
|
|
33
33
|
* @example '1_0_0' => '1.0.0'
|
|
34
34
|
*/
|
|
35
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;
|
|
36
42
|
/**
|
|
37
43
|
* Create a partial Module Identifier from a specifier
|
|
38
44
|
* The Module Identifier is partial because the specifier may not contain a version
|
package/build/es/identity.js
CHANGED
|
@@ -37,6 +37,15 @@ export function normalizeVersionToUri(version) {
|
|
|
37
37
|
export function normalizeVersionFromUri(version) {
|
|
38
38
|
return version.replace(/_/g, '.');
|
|
39
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
|
+
}
|
|
40
49
|
export function explodeSpecifier(rawSpecifier) {
|
|
41
50
|
const decodedSpecifier = decodeURIComponent(rawSpecifier);
|
|
42
51
|
// Split up the version and bare specifier
|
package/build/es/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './interchangeable-modules.js';
|
|
|
5
5
|
export * from './link.js';
|
|
6
6
|
export * from './object.js';
|
|
7
7
|
export * from './serialize.js';
|
|
8
|
+
export * from './tasks.js';
|
|
8
9
|
export * from './typescript.js';
|
|
9
10
|
export * from './import-metadata.js';
|
|
10
11
|
export * from './graph.js';
|
package/build/es/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './interchangeable-modules.js';
|
|
|
5
5
|
export * from './link.js';
|
|
6
6
|
export * from './object.js';
|
|
7
7
|
export * from './serialize.js';
|
|
8
|
+
export * from './tasks.js';
|
|
8
9
|
export * from './typescript.js';
|
|
9
10
|
export * from './import-metadata.js';
|
|
10
11
|
export * from './graph.js';
|
package/build/es/mappings.js
CHANGED
|
@@ -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
|
|
@@ -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/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.8",
|
|
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",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"slugify": "^1.4.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@lwrjs/diagnostics": "0.6.0-alpha.
|
|
47
|
-
"@lwrjs/types": "0.6.0-alpha.
|
|
46
|
+
"@lwrjs/diagnostics": "0.6.0-alpha.8",
|
|
47
|
+
"@lwrjs/types": "0.6.0-alpha.8",
|
|
48
48
|
"@types/mime-types": "2.1.1",
|
|
49
49
|
"@types/path-to-regexp": "^1.7.0"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
52
|
"node": ">=14.15.4 <17"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "f57b843b079ef42fdd1e727521e5a88e70bf850a"
|
|
55
55
|
}
|