@ms-cloudpack/package-utilities 0.1.7 → 0.4.0
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/CHANGELOG.json +58 -1
- package/CHANGELOG.md +28 -2
- package/lib/createImportMap.d.ts +7 -0
- package/lib/createImportMap.js +47 -0
- package/lib/createImportMap.js.map +1 -0
- package/lib/createImportMap.test.d.ts +1 -0
- package/lib/createImportMap.test.js +176 -0
- package/lib/createImportMap.test.js.map +1 -0
- package/lib/createResolveMap.d.ts +8 -9
- package/lib/createResolveMap.js +54 -107
- package/lib/createResolveMap.js.map +1 -1
- package/lib/createResolveMap.test.js +26 -1
- package/lib/createResolveMap.test.js.map +1 -1
- package/lib/findPackagePath.d.ts +1 -0
- package/lib/findPackagePath.js +14 -0
- package/lib/findPackagePath.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/resolveImportFromPackagePath.d.ts +1 -1
- package/lib/resolveImportFromPackagePath.js +1 -1
- package/package.json +2 -2
- package/lib/tsdoc-metadata.json +0 -11
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,64 @@
|
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Wed, 25 May 2022 21:40:21 GMT",
|
|
6
|
+
"tag": "@ms-cloudpack/package-utilities_v0.4.0",
|
|
7
|
+
"version": "0.4.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "dzearing@microsoft.com",
|
|
12
|
+
"package": "@ms-cloudpack/package-utilities",
|
|
13
|
+
"commit": "c81fea1af8bedcd81366fbddb199dd2c0e6cbaa7",
|
|
14
|
+
"comment": "Updating the entry evaluation to prefer source files for intra-repo packages."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"author": "beachball",
|
|
18
|
+
"package": "@ms-cloudpack/package-utilities",
|
|
19
|
+
"comment": "Bump @ms-cloudpack/path-utilities to v0.3.0",
|
|
20
|
+
"commit": "c81fea1af8bedcd81366fbddb199dd2c0e6cbaa7"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"date": "Sat, 21 May 2022 00:31:32 GMT",
|
|
27
|
+
"tag": "@ms-cloudpack/package-utilities_v0.3.0",
|
|
28
|
+
"version": "0.3.0",
|
|
29
|
+
"comments": {
|
|
30
|
+
"minor": [
|
|
31
|
+
{
|
|
32
|
+
"author": "dzearing@microsoft.com",
|
|
33
|
+
"package": "@ms-cloudpack/package-utilities",
|
|
34
|
+
"commit": "c26c7bcc7abda501d07180598e3da003b435b03b",
|
|
35
|
+
"comment": "Adding api to generate an import map based on a resolve map."
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"date": "Fri, 20 May 2022 04:26:15 GMT",
|
|
42
|
+
"tag": "@ms-cloudpack/package-utilities_v0.2.0",
|
|
43
|
+
"version": "0.2.0",
|
|
44
|
+
"comments": {
|
|
45
|
+
"minor": [
|
|
46
|
+
{
|
|
47
|
+
"author": "dzearing@microsoft.com",
|
|
48
|
+
"package": "@ms-cloudpack/package-utilities",
|
|
49
|
+
"commit": "b39bb143fc53e622c39f9e9fd349f71c9ebadd77",
|
|
50
|
+
"comment": "Updating createResolveMap logic."
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"author": "beachball",
|
|
54
|
+
"package": "@ms-cloudpack/package-utilities",
|
|
55
|
+
"comment": "Bump @ms-cloudpack/path-utilities to v0.2.0",
|
|
56
|
+
"commit": "b39bb143fc53e622c39f9e9fd349f71c9ebadd77"
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"date": "Thu, 19 May 2022 21:04:02 GMT",
|
|
6
63
|
"tag": "@ms-cloudpack/package-utilities_v0.1.7",
|
|
7
64
|
"version": "0.1.7",
|
|
8
65
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
# Change Log - @ms-cloudpack/package-utilities
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Wed, 25 May 2022 21:40:21 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.4.0
|
|
8
|
+
|
|
9
|
+
Wed, 25 May 2022 21:40:21 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Updating the entry evaluation to prefer source files for intra-repo packages. (dzearing@microsoft.com)
|
|
14
|
+
- Bump @ms-cloudpack/path-utilities to v0.3.0
|
|
15
|
+
|
|
16
|
+
## 0.3.0
|
|
17
|
+
|
|
18
|
+
Sat, 21 May 2022 00:31:32 GMT
|
|
19
|
+
|
|
20
|
+
### Minor changes
|
|
21
|
+
|
|
22
|
+
- Adding api to generate an import map based on a resolve map. (dzearing@microsoft.com)
|
|
23
|
+
|
|
24
|
+
## 0.2.0
|
|
25
|
+
|
|
26
|
+
Fri, 20 May 2022 04:26:15 GMT
|
|
27
|
+
|
|
28
|
+
### Minor changes
|
|
29
|
+
|
|
30
|
+
- Updating createResolveMap logic. (dzearing@microsoft.com)
|
|
31
|
+
- Bump @ms-cloudpack/path-utilities to v0.2.0
|
|
32
|
+
|
|
7
33
|
## 0.1.7
|
|
8
34
|
|
|
9
|
-
Thu, 19 May 2022 21:
|
|
35
|
+
Thu, 19 May 2022 21:04:02 GMT
|
|
10
36
|
|
|
11
37
|
### Patches
|
|
12
38
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ResolveMap } from './createResolveMap.js';
|
|
2
|
+
import { type PackageDefinition } from './getPackageDefinition.js';
|
|
3
|
+
export interface ImportMap {
|
|
4
|
+
imports: Record<string, string>;
|
|
5
|
+
scopes?: Record<string, Record<string, string>>;
|
|
6
|
+
}
|
|
7
|
+
export declare function createImportMap(resolveMap: ResolveMap, bundleServerUrl: string, packageDefinitions?: Record<string, PackageDefinition>): Promise<ImportMap>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { slash } from '@ms-cloudpack/path-utilities';
|
|
3
|
+
import { getPackageDefinition } from './getPackageDefinition.js';
|
|
4
|
+
import { getExportPathFromEntry } from './getExportPathFromEntry.js';
|
|
5
|
+
import { merge } from 'merge';
|
|
6
|
+
export async function createImportMap(resolveMap, bundleServerUrl, packageDefinitions) {
|
|
7
|
+
const importMap = {
|
|
8
|
+
imports: {},
|
|
9
|
+
};
|
|
10
|
+
for (const resolveEntry of Object.values(resolveMap)) {
|
|
11
|
+
merge(importMap.imports, await getImportMapFromEntry(resolveEntry, bundleServerUrl, packageDefinitions));
|
|
12
|
+
if (resolveEntry.scopedVersions) {
|
|
13
|
+
// Initialize scopes
|
|
14
|
+
importMap.scopes ?? (importMap.scopes = {});
|
|
15
|
+
for (const scopedEntry of Object.values(resolveEntry.scopedVersions)) {
|
|
16
|
+
for (const requiredById of scopedEntry.requiredBy) {
|
|
17
|
+
const requiredByUrl = `${bundleServerUrl}/${requiredById}/`;
|
|
18
|
+
importMap.scopes[requiredByUrl] = await getImportMapFromEntry(scopedEntry, bundleServerUrl, packageDefinitions);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return importMap;
|
|
24
|
+
}
|
|
25
|
+
async function getImportMapFromEntry(entry, bundleServerUrl, packageDefinitions) {
|
|
26
|
+
const importMap = {};
|
|
27
|
+
const definition = packageDefinitions?.[entry.path] || (await getPackageDefinition(entry.path, true));
|
|
28
|
+
if (definition) {
|
|
29
|
+
const baseUrl = `${bundleServerUrl}/${definition.name}@${definition.version}/`;
|
|
30
|
+
if (definition.exports) {
|
|
31
|
+
for (const [exportKey, exportEntry] of Object.entries(definition.exports)) {
|
|
32
|
+
const importAlias = slash(path.join(definition.name, exportKey));
|
|
33
|
+
if (!importMap[importAlias]) {
|
|
34
|
+
const exportPath = getExportPathFromEntry(exportEntry);
|
|
35
|
+
if (exportPath) {
|
|
36
|
+
importMap[importAlias] = new URL(exportPath, baseUrl).href;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
importMap[definition.name] = new URL(definition.module || definition.main || 'index.js', baseUrl).href;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return importMap;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=createImportMap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createImportMap.js","sourceRoot":"","sources":["../src/createImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAErD,OAAO,EAAE,oBAAoB,EAA0B,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAO9B,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,UAAsB,EACtB,eAAuB,EACvB,kBAAsD;IAEtD,MAAM,SAAS,GAAc;QAC3B,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,KAAK,MAAM,YAAY,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;QACpD,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,qBAAqB,CAAC,YAAY,EAAE,eAAe,EAAE,kBAAkB,CAAC,CAAC,CAAC;QAEzG,IAAI,YAAY,CAAC,cAAc,EAAE;YAC/B,oBAAoB;YACpB,SAAS,CAAC,MAAM,KAAhB,S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,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;qBAC5D;iBACF;aACF;SACF;aAAM;YACL,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,IAAI,IAAI,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;SACxG;KACF;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { createImportMap } from './createImportMap.js';
|
|
2
|
+
const bundleServerUrl = 'http://localhost:12345';
|
|
3
|
+
const basicResolveMapEntry = { name: 'a', version: '1.0.0', path: 'path/a', requiredBy: [] };
|
|
4
|
+
describe('createImportMap', () => {
|
|
5
|
+
it('can translate a package with no entries', async () => {
|
|
6
|
+
const resolveMap = {
|
|
7
|
+
a: basicResolveMapEntry,
|
|
8
|
+
};
|
|
9
|
+
const packages = {
|
|
10
|
+
'path/a': {
|
|
11
|
+
name: 'a',
|
|
12
|
+
version: '1.0.0',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
|
|
16
|
+
Object {
|
|
17
|
+
"imports": Object {
|
|
18
|
+
"a": "http://localhost:12345/a@1.0.0/index.js",
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
`);
|
|
22
|
+
});
|
|
23
|
+
it('can translate a package with 1 main entry', async () => {
|
|
24
|
+
const resolveMap = {
|
|
25
|
+
a: basicResolveMapEntry,
|
|
26
|
+
};
|
|
27
|
+
const packages = {
|
|
28
|
+
'path/a': {
|
|
29
|
+
name: 'a',
|
|
30
|
+
version: '1.0.0',
|
|
31
|
+
main: './foo/main.js',
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
|
|
35
|
+
Object {
|
|
36
|
+
"imports": Object {
|
|
37
|
+
"a": "http://localhost:12345/a@1.0.0/foo/main.js",
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
`);
|
|
41
|
+
});
|
|
42
|
+
it('can translate a package with 1 module entry', async () => {
|
|
43
|
+
const resolveMap = {
|
|
44
|
+
a: basicResolveMapEntry,
|
|
45
|
+
};
|
|
46
|
+
const packages = {
|
|
47
|
+
'path/a': {
|
|
48
|
+
name: 'a',
|
|
49
|
+
version: '1.0.0',
|
|
50
|
+
module: './foo/module.js',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
|
|
54
|
+
Object {
|
|
55
|
+
"imports": Object {
|
|
56
|
+
"a": "http://localhost:12345/a@1.0.0/foo/module.js",
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
it('prefers module over main', async () => {
|
|
62
|
+
const resolveMap = {
|
|
63
|
+
a: basicResolveMapEntry,
|
|
64
|
+
};
|
|
65
|
+
const packages = {
|
|
66
|
+
'path/a': {
|
|
67
|
+
name: 'a',
|
|
68
|
+
version: '1.0.0',
|
|
69
|
+
main: './foo/main.js',
|
|
70
|
+
module: './foo/module.js',
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
|
|
74
|
+
Object {
|
|
75
|
+
"imports": Object {
|
|
76
|
+
"a": "http://localhost:12345/a@1.0.0/foo/module.js",
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
`);
|
|
80
|
+
});
|
|
81
|
+
it('can translate a package with a basic exports map (value = string)', async () => {
|
|
82
|
+
const resolveMap = {
|
|
83
|
+
a: basicResolveMapEntry,
|
|
84
|
+
};
|
|
85
|
+
const packages = {
|
|
86
|
+
'path/a': {
|
|
87
|
+
name: 'a',
|
|
88
|
+
version: '1.0.0',
|
|
89
|
+
exports: {
|
|
90
|
+
'.': './foo/string.js',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
|
|
95
|
+
Object {
|
|
96
|
+
"imports": Object {
|
|
97
|
+
"a": "http://localhost:12345/a@1.0.0/foo/string.js",
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
`);
|
|
101
|
+
});
|
|
102
|
+
it('can translate a package with a basic exports map (value = object, default)', async () => {
|
|
103
|
+
const resolveMap = {
|
|
104
|
+
a: basicResolveMapEntry,
|
|
105
|
+
};
|
|
106
|
+
const packages = {
|
|
107
|
+
'path/a': {
|
|
108
|
+
name: 'a',
|
|
109
|
+
version: '1.0.0',
|
|
110
|
+
exports: {
|
|
111
|
+
'.': { default: './foo/default.js' },
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
|
|
116
|
+
Object {
|
|
117
|
+
"imports": Object {
|
|
118
|
+
"a": "http://localhost:12345/a@1.0.0/foo/default.js",
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
`);
|
|
122
|
+
});
|
|
123
|
+
it('can translate a package with a basic exports map (value = object, prefer import)', async () => {
|
|
124
|
+
const resolveMap = {
|
|
125
|
+
a: basicResolveMapEntry,
|
|
126
|
+
};
|
|
127
|
+
const packages = {
|
|
128
|
+
'path/a': {
|
|
129
|
+
name: 'a',
|
|
130
|
+
version: '1.0.0',
|
|
131
|
+
exports: {
|
|
132
|
+
'.': {
|
|
133
|
+
import: './foo/import.js',
|
|
134
|
+
default: './foo/default.js',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
|
|
140
|
+
Object {
|
|
141
|
+
"imports": Object {
|
|
142
|
+
"a": "http://localhost:12345/a@1.0.0/foo/import.js",
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
`);
|
|
146
|
+
});
|
|
147
|
+
it('can translate a package with a basic exports map (value = object, named export)', async () => {
|
|
148
|
+
const resolveMap = {
|
|
149
|
+
a: basicResolveMapEntry,
|
|
150
|
+
};
|
|
151
|
+
const packages = {
|
|
152
|
+
'path/a': {
|
|
153
|
+
name: 'a',
|
|
154
|
+
version: '1.0.0',
|
|
155
|
+
exports: {
|
|
156
|
+
'.': {
|
|
157
|
+
import: './foo/import.js',
|
|
158
|
+
default: './foo/default.js',
|
|
159
|
+
},
|
|
160
|
+
'./lib/Button': {
|
|
161
|
+
import: './lib/Button.js',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
|
|
167
|
+
Object {
|
|
168
|
+
"imports": Object {
|
|
169
|
+
"a": "http://localhost:12345/a@1.0.0/foo/import.js",
|
|
170
|
+
"a/lib/Button": "http://localhost:12345/a@1.0.0/lib/Button.js",
|
|
171
|
+
},
|
|
172
|
+
}
|
|
173
|
+
`);
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
//# sourceMappingURL=createImportMap.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createImportMap.test.js","sourceRoot":"","sources":["../src/createImportMap.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD,MAAM,eAAe,GAAG,wBAAwB,CAAC;AACjD,MAAM,oBAAoB,GAAoB,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC;AAE9G,QAAQ,CAAC,iBAAiB,EAAE,GAA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,CAAC,CAAC;IAEH,EAAE,CAAC,kFAAkF,EAAE,KAAK,IAAI,EAAE;QAChG,MAAM,UAAU,GAAe;YAC7B,CAAC,EAAE,oBAAoB;SACxB,CAAC;QACF,MAAM,QAAQ,GAAsC;YAClD,QAAQ,EAAE;gBACR,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE;oBACP,GAAG,EAAE;wBACH,MAAM,EAAE,iBAAiB;wBACzB,OAAO,EAAE,kBAAkB;qBAC5B;iBACF;aACF;SACF,CAAC;QAEF,MAAM,CAAC,MAAM,eAAe,CAAC,UAAU,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;KAM1F,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iFAAiF,EAAE,KAAK,IAAI,EAAE;QAC/F,MAAM,UAAU,GAAe;YAC7B,CAAC,EAAE,oBAAoB;SACxB,CAAC;QACF,MAAM,QAAQ,GAAsC;YAClD,QAAQ,EAAE;gBACR,IAAI,EAAE,GAAG;gBACT,OAAO,EAAE,OAAO;gBAChB,OAAO,EAAE;oBACP,GAAG,EAAE;wBACH,MAAM,EAAE,iBAAiB;wBACzB,OAAO,EAAE,kBAAkB;qBAC5B;oBACD,cAAc,EAAE;wBACd,MAAM,EAAE,iBAAiB;qBAC1B;iBACF;aACF;SACF,CAAC;QAEF,MAAM,CAAC,MAAM,eAAe,CAAC,UAAU,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;KAO1F,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
export declare type PackageNameVersion = `${string}@${string}`;
|
|
2
2
|
export declare type ResolveMapEntry = {
|
|
3
|
+
name: string;
|
|
3
4
|
version: string;
|
|
4
5
|
path: string;
|
|
5
|
-
|
|
6
|
+
requiredBy: string[];
|
|
6
7
|
scopedVersions?: {
|
|
7
|
-
[
|
|
8
|
+
[version: string]: ResolveMapEntry;
|
|
8
9
|
};
|
|
9
10
|
};
|
|
10
|
-
export declare type
|
|
11
|
-
|
|
11
|
+
export declare type PartialResolveMapEntry = Omit<ResolveMapEntry, 'requiredBy'> & {
|
|
12
|
+
requiredBy: Set<string>;
|
|
12
13
|
};
|
|
14
|
+
export declare type ResolveMap = Record<string, ResolveMapEntry>;
|
|
13
15
|
export declare function createResolveMap(options: {
|
|
14
16
|
appPath: string;
|
|
15
17
|
additionalPaths?: string[];
|
|
16
|
-
}): Promise<
|
|
17
|
-
resolveMap: ResolveMap;
|
|
18
|
-
stats: InstalledPackagesResult['stats'];
|
|
19
|
-
}>;
|
|
18
|
+
}): Promise<ResolveMap>;
|
package/lib/createResolveMap.js
CHANGED
|
@@ -1,116 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
// import path from 'path';
|
|
4
|
-
import { resolveImportFromPackagePath } from './resolveImportFromPackagePath.js';
|
|
5
|
-
/*
|
|
6
|
-
For each package:
|
|
7
|
-
|
|
8
|
-
1. Resolve the version required from the lockfile.
|
|
9
|
-
2. Determine what version is installed.
|
|
10
|
-
3. If version required was not found, default to the version installed.
|
|
11
|
-
4. If no lockfile version is installed, get metadata and use the latest.
|
|
12
|
-
5. If there is no installed version, or the version installed does not
|
|
13
|
-
satisfy the required version, install the version required.
|
|
14
|
-
|
|
15
|
-
Repeat this process for each *unique* version resolved.
|
|
16
|
-
|
|
17
|
-
{
|
|
18
|
-
react: {
|
|
19
|
-
'7.1.0': { path: '...', requiredBy: [ { name: 'foo', version: '1.1.1' }, { name: 'bar'}],
|
|
20
|
-
'6.9.0': [ { name: 'baz' } ]
|
|
21
|
-
},
|
|
22
|
-
etc...
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
This should be enough to know which dependencies have dupes.
|
|
26
|
-
|
|
27
|
-
Then, optimize the resolve map to top-level the most common/latest versions. This map will provide
|
|
28
|
-
physical paths for resolving dependencies, where each key in the package object represents the scope.
|
|
29
|
-
This is useful because at esbuild resolve time, we can quickly identify which package the import source
|
|
30
|
-
is coming from, and quickly look up the package resolution by:
|
|
31
|
-
|
|
32
|
-
`const packageDetails = resolveMap[requestPackage][sourcePackage] || resolveMap[requestPackage].default`
|
|
33
|
-
|
|
34
|
-
{
|
|
35
|
-
react: {
|
|
36
|
-
version: string;
|
|
37
|
-
path: '/tmp/react/7.1.0',
|
|
38
|
-
entry: './lib/index.js'
|
|
39
|
-
|
|
40
|
-
scopedVersions: {
|
|
41
|
-
baz: { // when bar imports 'react', resolve to this other location.
|
|
42
|
-
path: '/tmp/react/6.9.0'
|
|
43
|
-
entry: './lib/index.js'
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
etc: ...
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
By optimizing the default to be the most common package, we can reduce the scope entries.
|
|
51
|
-
|
|
52
|
-
Note that when we have dupes, this will keep them intact and will not try to optimize. It could be that
|
|
53
|
-
holding back one package could dedupe. In the example above, perhaps "foo" and "bar" packages could be
|
|
54
|
-
downgraded to a build which accepts 6.9.0. But it could also introduce other dupes.
|
|
55
|
-
*/
|
|
1
|
+
import { getPackageDefinition } from './getPackageDefinition.js';
|
|
2
|
+
import { findPackagePath } from './findPackagePath.js';
|
|
56
3
|
export async function createResolveMap(options) {
|
|
4
|
+
var _a, _b, _c, _d;
|
|
57
5
|
const { appPath, additionalPaths = [] } = options;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
6
|
+
const visitedPaths = new Set([appPath, ...additionalPaths]);
|
|
7
|
+
const pathsToVisit = [appPath, ...additionalPaths];
|
|
8
|
+
const allEntries = {};
|
|
9
|
+
while (pathsToVisit.length) {
|
|
10
|
+
const packagePath = pathsToVisit.shift();
|
|
11
|
+
if (packagePath) {
|
|
12
|
+
const definition = await getPackageDefinition(packagePath, true);
|
|
13
|
+
if (definition) {
|
|
14
|
+
const packageId = `${definition.name}@${definition.version}`;
|
|
15
|
+
const namedEntries = (allEntries[_a = definition.name] ?? (allEntries[_a] = {}));
|
|
16
|
+
namedEntries[_b = definition.version] ?? (namedEntries[_b] = createMapEntry(definition, packagePath));
|
|
17
|
+
for (const depName of Object.keys(definition?.dependencies || {})) {
|
|
18
|
+
const dependencyPath = findPackagePath(depName, packagePath);
|
|
19
|
+
const dependencyDefinition = await getPackageDefinition(dependencyPath, true);
|
|
20
|
+
if (dependencyDefinition) {
|
|
21
|
+
const dependencyNamedEntries = (allEntries[_c = dependencyDefinition.name] ?? (allEntries[_c] = {}));
|
|
22
|
+
const dependencyEntry = (dependencyNamedEntries[_d = dependencyDefinition.version] ?? (dependencyNamedEntries[_d] = createMapEntry(dependencyDefinition, dependencyPath)));
|
|
23
|
+
dependencyEntry.requiredBy.add(packageId);
|
|
24
|
+
if (!visitedPaths.has(dependencyPath)) {
|
|
25
|
+
visitedPaths.add(dependencyPath);
|
|
26
|
+
pathsToVisit.push(dependencyPath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Now we have all entries and relationships. Iterate through the relationships to build
|
|
34
|
+
// The final resolve map.
|
|
74
35
|
const resolveMap = {};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const versions = Object.keys(installedPackages[packageName]).sort((a, b) => installedPackages[packageName][a].requiredBy?.length > installedPackages[packageName][b].requiredBy.length
|
|
79
|
-
? -1
|
|
80
|
-
: 1);
|
|
81
|
-
// Default to the most used version to dedupe. All other versions scope to specifics.
|
|
82
|
-
const defaultVersionEntry = installedPackages[packageName][versions[0]];
|
|
83
|
-
// Define the default resolved version for the package.
|
|
84
|
-
const depResolveEntry = (resolveMap[packageName] = {
|
|
85
|
-
version: versions[0],
|
|
86
|
-
path: defaultVersionEntry.path,
|
|
87
|
-
entry: await resolveImportFromPackagePath(defaultVersionEntry.path, '', {
|
|
88
|
-
preferSource: false,
|
|
89
|
-
}),
|
|
36
|
+
for (const [name, versions] of Object.entries(allEntries)) {
|
|
37
|
+
const [dominantVersion, ...otherVersions] = Object.keys(versions).sort((a, b) => {
|
|
38
|
+
return versions[a].requiredBy.size < versions[b].requiredBy.size ? 1 : -1;
|
|
90
39
|
});
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
path: scopedPackage.path,
|
|
101
|
-
entry: await resolveImportFromPackagePath(scopedPackage.path, '', {
|
|
102
|
-
preferSource: false,
|
|
103
|
-
}),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
+
const entry = (resolveMap[name] = allEntries[name][dominantVersion]);
|
|
42
|
+
entry.requiredBy = Array.from(entry.requiredBy);
|
|
43
|
+
if (otherVersions?.length) {
|
|
44
|
+
entry.scopedVersions = {};
|
|
45
|
+
for (const otherVersion of otherVersions) {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
const scopedEntry = (entry.scopedVersions[otherVersion] = versions[otherVersion]);
|
|
48
|
+
scopedEntry.requiredBy = Array.from(scopedEntry.requiredBy);
|
|
106
49
|
}
|
|
107
50
|
}
|
|
108
51
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
52
|
+
return resolveMap;
|
|
53
|
+
}
|
|
54
|
+
function createMapEntry(packageDefinition, packagePath) {
|
|
55
|
+
const { name, version } = packageDefinition;
|
|
56
|
+
return {
|
|
57
|
+
name,
|
|
58
|
+
version,
|
|
59
|
+
path: packagePath,
|
|
60
|
+
requiredBy: new Set(),
|
|
61
|
+
};
|
|
115
62
|
}
|
|
116
63
|
//# sourceMappingURL=createResolveMap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../src/createResolveMap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../src/createResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAA0B,MAAM,2BAA2B,CAAC;AACzF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAoBvD,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAwD;;IAC7F,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAClD,MAAM,YAAY,GAAG,IAAI,GAAG,CAAS,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;IACpE,MAAM,YAAY,GAAa,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,CAAC;IAC7D,MAAM,UAAU,GAA2D,EAAE,CAAC;IAE9E,OAAO,YAAY,CAAC,MAAM,EAAE;QAC1B,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,EAAE,CAAC;QAEzC,IAAI,WAAW,EAAE;YACf,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;YAEjE,IAAI,UAAU,EAAE;gBACd,MAAM,SAAS,GAAuB,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;gBAEjF,MAAM,YAAY,GAAG,CAAC,UAAU,MAAC,UAAU,CAAC,IAAI,MAA1B,UAAU,OAAsB,EAAE,EAAC,CAAC;gBAE1D,YAAY,MAAC,UAAU,CAAC,OAAO,MAA/B,YAAY,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AAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5E,CAAC,CAAC,CAAC;QAEH,8DAA8D;QAC9D,MAAM,KAAK,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,eAAe,CAA2B,CAAC,CAAC;QAE/F,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAEhD,IAAI,aAAa,EAAE,MAAM,EAAE;YACzB,KAAK,CAAC,cAAc,GAAG,EAAE,CAAC;YAE1B,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;gBACxC,8DAA8D;gBAC9D,MAAM,WAAW,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC,YAAY,CAA2B,CAAC,CAAC;gBAE5G,WAAW,CAAC,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;aAC7D;SACF;KACF;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,cAAc,CAAC,iBAAoC,EAAE,WAAmB;IAC/E,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,iBAAiB,CAAC;IAE5C,OAAO;QACL,IAAI;QACJ,OAAO;QACP,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,IAAI,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -6,7 +6,32 @@ import { testProject1Path } from '../src/testPaths.js';
|
|
|
6
6
|
const createResolveMapSafe = async (options) => filterJson(await createResolveMap(options), 'path', (oldPath) => slash(path.relative(testProject1Path, oldPath)));
|
|
7
7
|
describe('createResolveMap', () => {
|
|
8
8
|
it('can create a resolve map', async () => {
|
|
9
|
-
expect(await createResolveMapSafe({ appPath: testProject1Path })).
|
|
9
|
+
expect(await createResolveMapSafe({ appPath: testProject1Path })).toMatchInlineSnapshot(`
|
|
10
|
+
Object {
|
|
11
|
+
"b": Object {
|
|
12
|
+
"name": "b",
|
|
13
|
+
"path": "node_modules/b",
|
|
14
|
+
"requiredBy": Array [
|
|
15
|
+
"test-project-1@0.0.1",
|
|
16
|
+
],
|
|
17
|
+
"version": "1.0.0",
|
|
18
|
+
},
|
|
19
|
+
"c": Object {
|
|
20
|
+
"name": "c",
|
|
21
|
+
"path": "node_modules/c",
|
|
22
|
+
"requiredBy": Array [
|
|
23
|
+
"test-project-1@0.0.1",
|
|
24
|
+
],
|
|
25
|
+
"version": "1.0.0",
|
|
26
|
+
},
|
|
27
|
+
"test-project-1": Object {
|
|
28
|
+
"name": "test-project-1",
|
|
29
|
+
"path": "",
|
|
30
|
+
"requiredBy": Array [],
|
|
31
|
+
"version": "0.0.1",
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
`);
|
|
10
35
|
});
|
|
11
36
|
});
|
|
12
37
|
//# sourceMappingURL=createResolveMap.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResolveMap.test.js","sourceRoot":"","sources":["../src/createResolveMap.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,oBAAoB,GAA4B,KAAK,EAAE,OAAO,EAAE,EAAE,CACtE,UAAU,CAAC,MAAM,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAEpH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QACxC,MAAM,CAAC,MAAM,oBAAoB,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"createResolveMap.test.js","sourceRoot":"","sources":["../src/createResolveMap.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,MAAM,oBAAoB,GAA4B,KAAK,EAAE,OAAO,EAAE,EAAE,CACtE,UAAU,CAAC,MAAM,gBAAgB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;AAEpH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,0BAA0B,EAAE,KAAK,IAAI,EAAE;QACxC,MAAM,CAAC,MAAM,oBAAoB,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;KAyBvF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function findPackagePath(dependencyName: string, cwd: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
export function findPackagePath(dependencyName, cwd) {
|
|
4
|
+
let packagePath = cwd;
|
|
5
|
+
while (path.dirname(packagePath) !== packagePath) {
|
|
6
|
+
const resolvedPath = path.join(packagePath, 'node_modules', dependencyName);
|
|
7
|
+
if (fs.existsSync(path.join(resolvedPath, 'package.json'))) {
|
|
8
|
+
return fs.realpathSync(resolvedPath);
|
|
9
|
+
}
|
|
10
|
+
packagePath = path.dirname(packagePath);
|
|
11
|
+
}
|
|
12
|
+
throw new Error(`Could not resolve "${dependencyName}" from "${cwd}"`);
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=findPackagePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findPackagePath.js","sourceRoot":"","sources":["../src/findPackagePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,UAAU,eAAe,CAAC,cAAsB,EAAE,GAAW;IACjE,IAAI,WAAW,GAAG,GAAG,CAAC;IAEtB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,WAAW,EAAE;QAChD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;QAE5E,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC,EAAE;YAC1D,OAAO,EAAE,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;SACtC;QAED,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;KACzC;IAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,cAAc,WAAW,GAAG,GAAG,CAAC,CAAC;AACzE,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export { resolveImportFromPackage, resolveImportFromPackagePath, type ResolveImp
|
|
|
7
7
|
export { detectModuleType, type ModuleType } from './detectModuleType.js';
|
|
8
8
|
export { resolvePackageEntries } from './resolvePackageEntries.js';
|
|
9
9
|
export { isExternalPackage } from './isExternalPackage.js';
|
|
10
|
+
export { createImportMap, type ImportMap } from './createImportMap.js';
|
package/lib/index.js
CHANGED
|
@@ -6,4 +6,5 @@ export { resolveImportFromPackage, resolveImportFromPackagePath, } from './resol
|
|
|
6
6
|
export { detectModuleType } from './detectModuleType.js';
|
|
7
7
|
export { resolvePackageEntries } from './resolvePackageEntries.js';
|
|
8
8
|
export { isExternalPackage } from './isExternalPackage.js';
|
|
9
|
+
export { createImportMap } from './createImportMap.js';
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAyC,MAAM,uBAAuB,CAAC;AAEhG,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAA6C,MAAM,2BAA2B,CAAC;AAC5G,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,wBAAwB,EACxB,4BAA4B,GAE7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAyC,MAAM,uBAAuB,CAAC;AAEhG,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAA6C,MAAM,2BAA2B,CAAC;AAC5G,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EACL,wBAAwB,EACxB,4BAA4B,GAE7B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,uBAAuB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAkB,MAAM,sBAAsB,CAAC"}
|
|
@@ -15,7 +15,7 @@ export interface ResolveImportFromPackageOptions {
|
|
|
15
15
|
*/
|
|
16
16
|
export declare function resolveImportFromPackagePath(packagePath: string, requestedPath?: string, options?: ResolveImportFromPackageOptions): Promise<string>;
|
|
17
17
|
/**
|
|
18
|
-
* Resolves a requested import path from a package located at the given path. Gives
|
|
18
|
+
* Resolves a requested import path from a package located at the given path. Gives precedence
|
|
19
19
|
* to browser/esm options. This may change in a future iteration.
|
|
20
20
|
*/
|
|
21
21
|
export declare function resolveImportFromPackage(packagePath: string, packageDefinition: PackageDefinition, importPath?: string, options?: ResolveImportFromPackageOptions): Promise<string>;
|
|
@@ -16,7 +16,7 @@ export async function resolveImportFromPackagePath(packagePath, requestedPath =
|
|
|
16
16
|
return resolveImportFromPackage(packagePath, packageDefinition, requestedPath, options);
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Resolves a requested import path from a package located at the given path. Gives
|
|
19
|
+
* Resolves a requested import path from a package located at the given path. Gives precedence
|
|
20
20
|
* to browser/esm options. This may change in a future iteration.
|
|
21
21
|
*/
|
|
22
22
|
export async function resolveImportFromPackage(packagePath, packageDefinition, importPath = '', options = {}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Utilities for resolving/parsing packages and their imports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/parser": "^7.16.12",
|
|
17
17
|
"@babel/traverse": "^7.16.10",
|
|
18
|
-
"@ms-cloudpack/path-utilities": "^0.
|
|
18
|
+
"@ms-cloudpack/path-utilities": "^0.3.0",
|
|
19
19
|
"resolve": "^1.22.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
package/lib/tsdoc-metadata.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.24.0"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|