@lwrjs/npm-module-provider 0.10.0 → 0.10.2
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/index.cjs
CHANGED
|
@@ -29,7 +29,6 @@ __export(exports, {
|
|
|
29
29
|
var import_path = __toModule(require("path"));
|
|
30
30
|
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
31
31
|
var import_resolveNpmModules = __toModule(require("./resolveNpmModules.cjs"));
|
|
32
|
-
var import_resolveNpmModulesDeprecated = __toModule(require("./resolveNpmModulesDeprecated.cjs"));
|
|
33
32
|
var NpmModuleProvider = class {
|
|
34
33
|
constructor(providerConfig = {}, {config: {cacheDir}}) {
|
|
35
34
|
this.name = "npm-module-provider";
|
|
@@ -74,8 +73,7 @@ var NpmModuleProvider = class {
|
|
|
74
73
|
return versions.get(version);
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
|
-
const
|
|
78
|
-
const moduleEntry = await resolveNpm(specifier, this.webModulesCacheDir, this.providerConfig);
|
|
76
|
+
const moduleEntry = await (0, import_resolveNpmModules.resolveNpmModuleSpecifier)(specifier, this.webModulesCacheDir, this.providerConfig);
|
|
79
77
|
if (!moduleEntry) {
|
|
80
78
|
return;
|
|
81
79
|
}
|
package/build/es/index.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { AbstractModuleId, ModuleCompiled, ModuleEntry, ModuleProvider, Mod
|
|
|
2
2
|
export interface NpmModuleProviderConfig {
|
|
3
3
|
external?: string[];
|
|
4
4
|
polyfillNode?: boolean;
|
|
5
|
-
useCompatResolution?: boolean;
|
|
6
5
|
}
|
|
7
6
|
export default class NpmModuleProvider implements ModuleProvider {
|
|
8
7
|
name: string;
|
package/build/es/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { hashContent, readFile } from '@lwrjs/shared-utils';
|
|
3
|
-
import { resolveNpmModuleSpecifier } from './resolveNpmModules.js';
|
|
4
|
-
import { resolveNpmModuleSpecifierDeprecated } from './resolveNpmModulesDeprecated.js';
|
|
3
|
+
import { resolveNpmModuleSpecifier as resolveNpm } from './resolveNpmModules.js';
|
|
5
4
|
export default class NpmModuleProvider {
|
|
6
5
|
constructor(providerConfig = {}, { config: { cacheDir } }) {
|
|
7
6
|
this.name = 'npm-module-provider';
|
|
@@ -47,9 +46,6 @@ export default class NpmModuleProvider {
|
|
|
47
46
|
return versions.get(version);
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
const resolveNpm = this.providerConfig.useCompatResolution
|
|
51
|
-
? resolveNpmModuleSpecifierDeprecated
|
|
52
|
-
: resolveNpmModuleSpecifier;
|
|
53
49
|
const moduleEntry = await resolveNpm(specifier, this.webModulesCacheDir, this.providerConfig);
|
|
54
50
|
if (!moduleEntry) {
|
|
55
51
|
return;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.10.
|
|
7
|
+
"version": "0.10.2",
|
|
8
8
|
"homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -36,13 +36,12 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
39
|
-
"@lwrjs/shared-utils": "0.10.
|
|
39
|
+
"@lwrjs/shared-utils": "0.10.2",
|
|
40
40
|
"esbuild": "^0.9.7",
|
|
41
|
-
"esinstall": "^1.1.7",
|
|
42
41
|
"resolve": "^1.22.1"
|
|
43
42
|
},
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"@lwrjs/types": "0.10.
|
|
44
|
+
"@lwrjs/types": "0.10.2",
|
|
46
45
|
"jest": "^26.6.3",
|
|
47
46
|
"ts-jest": "^26.5.6"
|
|
48
47
|
},
|
|
@@ -52,5 +51,5 @@
|
|
|
52
51
|
"volta": {
|
|
53
52
|
"extends": "../../../package.json"
|
|
54
53
|
},
|
|
55
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "40988dfc093a3b9dea859f1bf61a49bca1edb0c5"
|
|
56
55
|
}
|
|
@@ -1,140 +0,0 @@
|
|
|
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/npm-module-provider/src/resolveNpmModulesDeprecated.ts
|
|
25
|
-
__markAsModule(exports);
|
|
26
|
-
__export(exports, {
|
|
27
|
-
resolveNpmModuleSpecifierBlock: () => resolveNpmModuleSpecifierBlock,
|
|
28
|
-
resolveNpmModuleSpecifierDeprecated: () => resolveNpmModuleSpecifierDeprecated
|
|
29
|
-
});
|
|
30
|
-
var import_path = __toModule(require("path"));
|
|
31
|
-
var import_esinstall = __toModule(require("esinstall"));
|
|
32
|
-
var import_fs = __toModule(require("fs"));
|
|
33
|
-
var import_resolve = __toModule(require("resolve"));
|
|
34
|
-
var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
|
|
35
|
-
function getPkgVersion(specifier) {
|
|
36
|
-
const pkgPath = import_resolve.default.sync((0, import_path.join)(specifier, "/package.json"));
|
|
37
|
-
return JSON.parse((0, import_fs.readFileSync)(pkgPath, "utf-8")).version;
|
|
38
|
-
}
|
|
39
|
-
function readModuleMapping(moduleMappingPath) {
|
|
40
|
-
return (0, import_fs.existsSync)(moduleMappingPath) ? JSON.parse((0, import_fs.readFileSync)(moduleMappingPath, "utf-8")) : {imports: {}};
|
|
41
|
-
}
|
|
42
|
-
function writeModuleMapping(loc, importMap) {
|
|
43
|
-
(0, import_fs.writeFileSync)(loc, JSON.stringify(importMap, void 0, 2), {encoding: "utf-8"});
|
|
44
|
-
}
|
|
45
|
-
async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
46
|
-
try {
|
|
47
|
-
const tmpFolder = (0, import_path.join)(dest, "__tmp", specifier.replace(/[/|@]/g, "_"));
|
|
48
|
-
(0, import_fs.mkdirSync)(tmpFolder, {recursive: true});
|
|
49
|
-
const moduleMappingPath = (0, import_path.join)(dest, "import-map-cache.json");
|
|
50
|
-
const currentModuleMapping = readModuleMapping(moduleMappingPath);
|
|
51
|
-
const version = getPkgVersion(specifier);
|
|
52
|
-
const cacheKey = `${specifier}@${version}`;
|
|
53
|
-
if (currentModuleMapping.imports[cacheKey]) {
|
|
54
|
-
return {
|
|
55
|
-
id: cacheKey,
|
|
56
|
-
specifier,
|
|
57
|
-
entry: currentModuleMapping.imports[cacheKey],
|
|
58
|
-
version
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const external = config.external?.filter((e) => e !== specifier) || [];
|
|
62
|
-
const polyfillNode = config.polyfillNode ?? true;
|
|
63
|
-
await (0, import_esinstall.install)([specifier], {
|
|
64
|
-
dest: tmpFolder,
|
|
65
|
-
importMap: currentModuleMapping,
|
|
66
|
-
logger: {
|
|
67
|
-
debug: () => void 0,
|
|
68
|
-
log: () => void 0,
|
|
69
|
-
warn: () => void 0,
|
|
70
|
-
error: () => void 0
|
|
71
|
-
},
|
|
72
|
-
polyfillNode,
|
|
73
|
-
external
|
|
74
|
-
});
|
|
75
|
-
const moduleMapping = readModuleMapping((0, import_path.join)(tmpFolder, "import-map.json"));
|
|
76
|
-
const moduleRelativePath = moduleMapping.imports[specifier];
|
|
77
|
-
const moduleAbsPath = (0, import_path.join)(tmpFolder, moduleRelativePath);
|
|
78
|
-
const moduleEntry = (0, import_path.join)(dest, moduleRelativePath);
|
|
79
|
-
(0, import_fs.mkdirSync)((0, import_path.dirname)(moduleEntry), {recursive: true});
|
|
80
|
-
(0, import_fs.copyFileSync)(moduleAbsPath, moduleEntry);
|
|
81
|
-
const mergedMapping = {
|
|
82
|
-
imports: {
|
|
83
|
-
...currentModuleMapping.imports,
|
|
84
|
-
[cacheKey]: moduleEntry
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
writeModuleMapping(moduleMappingPath, mergedMapping);
|
|
88
|
-
return {
|
|
89
|
-
id: cacheKey,
|
|
90
|
-
entry: moduleEntry,
|
|
91
|
-
specifier,
|
|
92
|
-
version
|
|
93
|
-
};
|
|
94
|
-
} catch (err) {
|
|
95
|
-
import_shared_utils.logger.error(`[npm-module-provider][esintsall] resolveNpmModules: ${specifier} ${dest}`, {err});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
var Queue = class {
|
|
99
|
-
constructor() {
|
|
100
|
-
this.queue = [];
|
|
101
|
-
this.workingOnPromise = false;
|
|
102
|
-
this.pendingPromise = false;
|
|
103
|
-
}
|
|
104
|
-
enqueue(promise) {
|
|
105
|
-
return new Promise((resolve2, reject) => {
|
|
106
|
-
this.queue.push({promise, resolve: resolve2, reject});
|
|
107
|
-
this.dequeue();
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
dequeue() {
|
|
111
|
-
if (this.workingOnPromise) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
const item = this.queue.shift();
|
|
115
|
-
if (!item) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
this.workingOnPromise = true;
|
|
119
|
-
try {
|
|
120
|
-
item.promise().then((value) => {
|
|
121
|
-
this.workingOnPromise = false;
|
|
122
|
-
item.resolve(value);
|
|
123
|
-
this.dequeue();
|
|
124
|
-
}).catch((err) => {
|
|
125
|
-
this.workingOnPromise = false;
|
|
126
|
-
item.reject(err);
|
|
127
|
-
this.dequeue();
|
|
128
|
-
});
|
|
129
|
-
} catch (err) {
|
|
130
|
-
this.workingOnPromise = false;
|
|
131
|
-
item.reject(err);
|
|
132
|
-
this.dequeue();
|
|
133
|
-
}
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var RESOLVER_QUEUE = new Queue();
|
|
138
|
-
async function resolveNpmModuleSpecifierDeprecated(specifier, dest, config) {
|
|
139
|
-
return RESOLVER_QUEUE.enqueue(resolveNpmModuleSpecifierBlock.bind(null, specifier, dest, config));
|
|
140
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { FsModuleEntry } from '@lwrjs/types';
|
|
2
|
-
import type { NpmModuleProviderConfig } from './index';
|
|
3
|
-
export declare function resolveNpmModuleSpecifierBlock(specifier: string, dest: string, config: NpmModuleProviderConfig): Promise<FsModuleEntry | undefined>;
|
|
4
|
-
export declare function resolveNpmModuleSpecifierDeprecated(specifier: string, dest: string, config: NpmModuleProviderConfig): Promise<FsModuleEntry | undefined>;
|
|
5
|
-
//# sourceMappingURL=resolveNpmModulesDeprecated.d.ts.map
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
import { dirname, join } from 'path';
|
|
3
|
-
import { install } from 'esinstall';
|
|
4
|
-
import { readFileSync, copyFileSync, mkdirSync, existsSync, writeFileSync } from 'fs';
|
|
5
|
-
import resolve from 'resolve';
|
|
6
|
-
import { logger } from '@lwrjs/shared-utils';
|
|
7
|
-
function getPkgVersion(specifier) {
|
|
8
|
-
const pkgPath = resolve.sync(join(specifier, '/package.json'));
|
|
9
|
-
return JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
|
|
10
|
-
}
|
|
11
|
-
function readModuleMapping(moduleMappingPath) {
|
|
12
|
-
return existsSync(moduleMappingPath)
|
|
13
|
-
? JSON.parse(readFileSync(moduleMappingPath, 'utf-8'))
|
|
14
|
-
: { imports: {} };
|
|
15
|
-
}
|
|
16
|
-
function writeModuleMapping(loc, importMap) {
|
|
17
|
-
writeFileSync(loc, JSON.stringify(importMap, undefined, 2), { encoding: 'utf-8' });
|
|
18
|
-
}
|
|
19
|
-
export async function resolveNpmModuleSpecifierBlock(specifier, dest, config) {
|
|
20
|
-
try {
|
|
21
|
-
// TODO: file an issue on snowpack so they don't wipe the folder every-time
|
|
22
|
-
// in the mean time we have to do hackery that will be likely to break when upgrading
|
|
23
|
-
const tmpFolder = join(dest, '__tmp', specifier.replace(/[/|@]/g, '_'));
|
|
24
|
-
mkdirSync(tmpFolder, { recursive: true });
|
|
25
|
-
const moduleMappingPath = join(dest, 'import-map-cache.json');
|
|
26
|
-
const currentModuleMapping = readModuleMapping(moduleMappingPath);
|
|
27
|
-
const version = getPkgVersion(specifier);
|
|
28
|
-
const cacheKey = `${specifier}@${version}`;
|
|
29
|
-
if (currentModuleMapping.imports[cacheKey]) {
|
|
30
|
-
return {
|
|
31
|
-
id: cacheKey,
|
|
32
|
-
specifier,
|
|
33
|
-
entry: currentModuleMapping.imports[cacheKey],
|
|
34
|
-
version,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const external = config.external?.filter((e) => e !== specifier) || [];
|
|
38
|
-
const polyfillNode = config.polyfillNode ?? true;
|
|
39
|
-
// Unfortunately esinstall APIs its not very programatic instead its file oriented...
|
|
40
|
-
await install([specifier], {
|
|
41
|
-
dest: tmpFolder,
|
|
42
|
-
importMap: currentModuleMapping,
|
|
43
|
-
logger: {
|
|
44
|
-
debug: () => void 0,
|
|
45
|
-
log: () => void 0,
|
|
46
|
-
warn: () => void 0,
|
|
47
|
-
error: () => void 0,
|
|
48
|
-
},
|
|
49
|
-
polyfillNode,
|
|
50
|
-
external,
|
|
51
|
-
});
|
|
52
|
-
// esinstall produces a new module mapping, read it to get the generated file
|
|
53
|
-
const moduleMapping = readModuleMapping(join(tmpFolder, 'import-map.json'));
|
|
54
|
-
const moduleRelativePath = moduleMapping.imports[specifier];
|
|
55
|
-
const moduleAbsPath = join(tmpFolder, moduleRelativePath);
|
|
56
|
-
const moduleEntry = join(dest, moduleRelativePath);
|
|
57
|
-
// create module's namespaced dir if it's namespaced, i.e.
|
|
58
|
-
// no namespace: 'utils' -> web_modules/utils.js
|
|
59
|
-
// namespace: '@mynamespace/utils' -> web_modules/@mynamespace/utils.js
|
|
60
|
-
mkdirSync(dirname(moduleEntry), { recursive: true });
|
|
61
|
-
// copy from _tmp to main folder and update the importMap for caching
|
|
62
|
-
copyFileSync(moduleAbsPath, moduleEntry);
|
|
63
|
-
const mergedMapping = {
|
|
64
|
-
imports: {
|
|
65
|
-
...currentModuleMapping.imports,
|
|
66
|
-
[cacheKey]: moduleEntry,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
writeModuleMapping(moduleMappingPath, mergedMapping);
|
|
70
|
-
return {
|
|
71
|
-
id: cacheKey,
|
|
72
|
-
entry: moduleEntry,
|
|
73
|
-
specifier,
|
|
74
|
-
version,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
catch (err) {
|
|
78
|
-
logger.error(`[npm-module-provider][esintsall] resolveNpmModules: ${specifier} ${dest}`, { err });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
class Queue {
|
|
82
|
-
constructor() {
|
|
83
|
-
this.queue = [];
|
|
84
|
-
this.workingOnPromise = false;
|
|
85
|
-
this.pendingPromise = false;
|
|
86
|
-
}
|
|
87
|
-
enqueue(promise) {
|
|
88
|
-
return new Promise((resolve, reject) => {
|
|
89
|
-
this.queue.push({ promise, resolve, reject });
|
|
90
|
-
this.dequeue();
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
dequeue() {
|
|
94
|
-
if (this.workingOnPromise) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
const item = this.queue.shift();
|
|
98
|
-
if (!item) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
this.workingOnPromise = true;
|
|
102
|
-
try {
|
|
103
|
-
item.promise()
|
|
104
|
-
.then((value) => {
|
|
105
|
-
this.workingOnPromise = false;
|
|
106
|
-
item.resolve(value);
|
|
107
|
-
this.dequeue();
|
|
108
|
-
})
|
|
109
|
-
.catch((err) => {
|
|
110
|
-
this.workingOnPromise = false;
|
|
111
|
-
item.reject(err);
|
|
112
|
-
this.dequeue();
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
this.workingOnPromise = false;
|
|
117
|
-
item.reject(err);
|
|
118
|
-
this.dequeue();
|
|
119
|
-
}
|
|
120
|
-
return true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
const RESOLVER_QUEUE = new Queue();
|
|
124
|
-
export async function resolveNpmModuleSpecifierDeprecated(specifier, dest, config) {
|
|
125
|
-
return RESOLVER_QUEUE.enqueue(resolveNpmModuleSpecifierBlock.bind(null, specifier, dest, config));
|
|
126
|
-
}
|
|
127
|
-
//# sourceMappingURL=resolveNpmModulesDeprecated.js.map
|