@ms-cloudpack/package-utilities 0.14.0 → 0.16.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 +46 -1
- package/CHANGELOG.md +18 -2
- package/lib/addExportsMapEntry.d.ts +13 -0
- package/lib/addExportsMapEntry.js +62 -0
- package/lib/addExportsMapEntry.js.map +1 -0
- package/lib/{resolvePackageEntries.test.d.ts → addExportsMapEntry.test.d.ts} +0 -0
- package/lib/addExportsMapEntry.test.js +86 -0
- package/lib/addExportsMapEntry.test.js.map +1 -0
- package/lib/createExportsMap.d.ts +0 -4
- package/lib/createExportsMap.js +34 -65
- package/lib/createExportsMap.js.map +1 -1
- package/lib/createExportsMap.test.js +25 -11
- package/lib/createExportsMap.test.js.map +1 -1
- package/lib/createResolveMap.d.ts +2 -0
- package/lib/createResolveMap.js +4 -5
- package/lib/createResolveMap.js.map +1 -1
- package/lib/findResolveMapEntry.d.ts +6 -0
- package/lib/findResolveMapEntry.js +12 -0
- package/lib/findResolveMapEntry.js.map +1 -0
- package/lib/findResolveMapEntry.test.d.ts +1 -0
- package/lib/findResolveMapEntry.test.js +52 -0
- package/lib/findResolveMapEntry.test.js.map +1 -0
- package/lib/getExportsMap.js +10 -1
- package/lib/getExportsMap.js.map +1 -1
- package/lib/getExportsMap.test.d.ts +1 -0
- package/lib/getExportsMap.test.js +30 -0
- package/lib/getExportsMap.test.js.map +1 -0
- package/lib/{resolvePackageEntries.d.ts → getPackageEntries.d.ts} +1 -1
- package/lib/{resolvePackageEntries.js → getPackageEntries.js} +2 -2
- package/lib/getPackageEntries.js.map +1 -0
- package/lib/getPackageEntries.test.d.ts +1 -0
- package/lib/{resolvePackageEntries.test.js → getPackageEntries.test.js} +12 -15
- package/lib/getPackageEntries.test.js.map +1 -0
- package/lib/index.d.ts +9 -5
- package/lib/index.js +14 -4
- package/lib/index.js.map +1 -1
- package/lib/parseImportString.d.ts +3 -3
- package/lib/parseImportString.js +4 -3
- package/lib/parseImportString.js.map +1 -1
- package/lib/parseImportString.test.js +22 -4
- package/lib/parseImportString.test.js.map +1 -1
- package/lib/resolveImportFromPackage.test.js +8 -34
- package/lib/resolveImportFromPackage.test.js.map +1 -1
- package/lib/resolveImportFromPackagePath.d.ts +4 -2
- package/lib/resolveImportFromPackagePath.js +10 -11
- package/lib/resolveImportFromPackagePath.js.map +1 -1
- package/lib/safeRelativePath.js +1 -1
- package/lib/safeRelativePath.js.map +1 -1
- package/lib/safeRelativePath.test.js +3 -1
- package/lib/safeRelativePath.test.js.map +1 -1
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +2 -2
- package/lib/resolvePackageEntries.js.map +0 -1
- package/lib/resolvePackageEntries.test.js.map +0 -1
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,52 @@
|
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "Wed,
|
|
5
|
+
"date": "Wed, 12 Oct 2022 21:49:36 GMT",
|
|
6
|
+
"tag": "@ms-cloudpack/package-utilities_v0.16.0",
|
|
7
|
+
"version": "0.16.0",
|
|
8
|
+
"comments": {
|
|
9
|
+
"minor": [
|
|
10
|
+
{
|
|
11
|
+
"author": "dzearing@microsoft.com",
|
|
12
|
+
"package": "@ms-cloudpack/package-utilities",
|
|
13
|
+
"commit": "48a31cb7c0bbd9095fc246a95b453ed49acf7626",
|
|
14
|
+
"comment": "Tweaking how exports are generated for browser entries, fixing a variety of other issues."
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Wed, 12 Oct 2022 08:10:43 GMT",
|
|
21
|
+
"tag": "@ms-cloudpack/package-utilities_v0.15.0",
|
|
22
|
+
"version": "0.15.0",
|
|
23
|
+
"comments": {
|
|
24
|
+
"minor": [
|
|
25
|
+
{
|
|
26
|
+
"author": "dzearing@microsoft.com",
|
|
27
|
+
"package": "@ms-cloudpack/package-utilities",
|
|
28
|
+
"commit": "03233b20287555cc8994203f05be01cb8a3fb225",
|
|
29
|
+
"comment": "Overhauling import/export map utilities."
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"date": "Tue, 11 Oct 2022 08:16:37 GMT",
|
|
36
|
+
"tag": "@ms-cloudpack/package-utilities_v0.14.0",
|
|
37
|
+
"version": "0.14.0",
|
|
38
|
+
"comments": {
|
|
39
|
+
"none": [
|
|
40
|
+
{
|
|
41
|
+
"author": "email not defined",
|
|
42
|
+
"package": "@ms-cloudpack/package-utilities",
|
|
43
|
+
"commit": "eaac5bbb36b4cc8105df8146bbe9366b0ed2e7ed",
|
|
44
|
+
"comment": "Update babel monorepo to v7.19.4"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"date": "Wed, 05 Oct 2022 19:39:20 GMT",
|
|
6
51
|
"tag": "@ms-cloudpack/package-utilities_v0.14.0",
|
|
7
52
|
"version": "0.14.0",
|
|
8
53
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
# Change Log - @ms-cloudpack/package-utilities
|
|
2
2
|
|
|
3
|
-
This log was last generated on Wed,
|
|
3
|
+
This log was last generated on Wed, 12 Oct 2022 21:49:36 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 0.16.0
|
|
8
|
+
|
|
9
|
+
Wed, 12 Oct 2022 21:49:36 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Tweaking how exports are generated for browser entries, fixing a variety of other issues. (dzearing@microsoft.com)
|
|
14
|
+
|
|
15
|
+
## 0.15.0
|
|
16
|
+
|
|
17
|
+
Wed, 12 Oct 2022 08:10:43 GMT
|
|
18
|
+
|
|
19
|
+
### Minor changes
|
|
20
|
+
|
|
21
|
+
- Overhauling import/export map utilities. (dzearing@microsoft.com)
|
|
22
|
+
|
|
7
23
|
## 0.14.0
|
|
8
24
|
|
|
9
|
-
Wed, 05 Oct 2022 19:39:
|
|
25
|
+
Wed, 05 Oct 2022 19:39:20 GMT
|
|
10
26
|
|
|
11
27
|
### Minor changes
|
|
12
28
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PackageDefinitions } from './PackageDefinitions.js';
|
|
2
|
+
/**
|
|
3
|
+
* Given an exports map and details about an import path, adds the entry.
|
|
4
|
+
*/
|
|
5
|
+
export declare function addExportsMapEntry(options: {
|
|
6
|
+
exports: Record<string, Record<string, string>>;
|
|
7
|
+
packagePath: string;
|
|
8
|
+
importPath: string;
|
|
9
|
+
entryPath?: string;
|
|
10
|
+
condition?: string;
|
|
11
|
+
typesPath?: string;
|
|
12
|
+
packages?: PackageDefinitions;
|
|
13
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { isFile, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';
|
|
3
|
+
import { isExternalPackage } from './isExternalPackage.js';
|
|
4
|
+
import { resolveImportFromPackagePath } from './resolveImportFromPackagePath.js';
|
|
5
|
+
import { safeRelativePath } from './safeRelativePath.js';
|
|
6
|
+
/**
|
|
7
|
+
* Given an exports map and details about an import path, adds the entry.
|
|
8
|
+
*/
|
|
9
|
+
export async function addExportsMapEntry(options) {
|
|
10
|
+
const { exports, packages, packagePath, importPath, entryPath, typesPath, condition = 'default' } = options;
|
|
11
|
+
const isInternal = !isExternalPackage(packagePath);
|
|
12
|
+
let sourcePath;
|
|
13
|
+
let intermediatePath;
|
|
14
|
+
let resolvedTypesPath = typesPath;
|
|
15
|
+
if (isInternal) {
|
|
16
|
+
sourcePath = await resolveImportFromPackagePath(packagePath, entryPath || importPath, {
|
|
17
|
+
packages,
|
|
18
|
+
preferSource: isInternal,
|
|
19
|
+
ignoreExportsMap: true,
|
|
20
|
+
});
|
|
21
|
+
intermediatePath = sourcePath && sourceToIntermediatePath(sourcePath);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
intermediatePath = await resolveImportFromPackagePath(packagePath, entryPath || importPath, {
|
|
25
|
+
packages,
|
|
26
|
+
preferSource: false,
|
|
27
|
+
ignoreExportsMap: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
// If at this point we haven't found what we're looking for, don't change anything.
|
|
31
|
+
if (!intermediatePath) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
// Discover d.ts if available.
|
|
35
|
+
if (!resolvedTypesPath) {
|
|
36
|
+
const isTypeScriptSource = sourcePath && ['.ts', '.tsx', '.mts', '.cts'].indexOf(path.extname(sourcePath)) >= 0;
|
|
37
|
+
const potentialTypesPath = path.extname(intermediatePath) === '.js' && intermediatePath.replace('.js', '.d.ts');
|
|
38
|
+
if (potentialTypesPath &&
|
|
39
|
+
((isInternal && isTypeScriptSource) || (!isInternal && isFile(path.join(packagePath, potentialTypesPath))))) {
|
|
40
|
+
resolvedTypesPath = potentialTypesPath;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const safeImportPath = safeRelativePath(importPath || '.');
|
|
44
|
+
let exportSet = exports[safeImportPath];
|
|
45
|
+
// If the value of this path is a string, convert it to an object.
|
|
46
|
+
if (typeof exportSet === 'string') {
|
|
47
|
+
exportSet = exports[safeImportPath] = {
|
|
48
|
+
default: exportSet,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else if (!exportSet) {
|
|
52
|
+
exportSet = exports[safeImportPath] = {};
|
|
53
|
+
}
|
|
54
|
+
if (resolvedTypesPath) {
|
|
55
|
+
exportSet.types = safeRelativePath(resolvedTypesPath);
|
|
56
|
+
}
|
|
57
|
+
exportSet[condition] = intermediatePath;
|
|
58
|
+
if (sourcePath && sourcePath !== intermediatePath) {
|
|
59
|
+
exportSet.source = safeRelativePath(sourcePath);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=addExportsMapEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAEhF,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,OAQxC;IACC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;IAC5G,MAAM,UAAU,GAAG,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACnD,IAAI,UAA8B,CAAC;IACnC,IAAI,gBAAoC,CAAC;IACzC,IAAI,iBAAiB,GAAuB,SAAS,CAAC;IAEtD,IAAI,UAAU,EAAE;QACd,UAAU,GAAG,MAAM,4BAA4B,CAAC,WAAW,EAAE,SAAS,IAAI,UAAU,EAAE;YACpF,QAAQ;YACR,YAAY,EAAE,UAAU;YACxB,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;QACH,gBAAgB,GAAG,UAAU,IAAI,wBAAwB,CAAC,UAAU,CAAC,CAAC;KACvE;SAAM;QACL,gBAAgB,GAAG,MAAM,4BAA4B,CAAC,WAAW,EAAE,SAAS,IAAI,UAAU,EAAE;YAC1F,QAAQ;YACR,YAAY,EAAE,KAAK;YACnB,gBAAgB,EAAE,IAAI;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E;QACjD,SAAS,CAAC,MAAM,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;KACjD;AACH,CAAC"}
|
|
File without changes
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, expect, it } from '@jest/globals';
|
|
2
|
+
import { addExportsMapEntry } from './addExportsMapEntry.js';
|
|
3
|
+
import { testProject1Path } from './testPaths.js';
|
|
4
|
+
import { createTestFileStructure } from '@ms-cloudpack/test-utilities';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
describe('addExportsMapEntry', () => {
|
|
7
|
+
it('can add an entry to an empty exports map', async () => {
|
|
8
|
+
const exportsMap = {};
|
|
9
|
+
await addExportsMapEntry({
|
|
10
|
+
exports: exportsMap,
|
|
11
|
+
packagePath: testProject1Path,
|
|
12
|
+
importPath: './lib/foo-sub1',
|
|
13
|
+
});
|
|
14
|
+
expect(exportsMap).toMatchInlineSnapshot(`
|
|
15
|
+
{
|
|
16
|
+
"./lib/foo-sub1": {
|
|
17
|
+
"default": "./lib/foo-sub1.js",
|
|
18
|
+
"source": "./src/foo-sub1.ts",
|
|
19
|
+
"types": "./lib/foo-sub1.d.ts",
|
|
20
|
+
},
|
|
21
|
+
}
|
|
22
|
+
`);
|
|
23
|
+
});
|
|
24
|
+
it('can add a non-safe import path', async () => {
|
|
25
|
+
const exportsMap = {};
|
|
26
|
+
await addExportsMapEntry({
|
|
27
|
+
exports: exportsMap,
|
|
28
|
+
packagePath: testProject1Path,
|
|
29
|
+
importPath: 'lib/foo-sub1',
|
|
30
|
+
});
|
|
31
|
+
expect(exportsMap).toMatchInlineSnapshot(`
|
|
32
|
+
{
|
|
33
|
+
"./lib/foo-sub1": {
|
|
34
|
+
"default": "./lib/foo-sub1.js",
|
|
35
|
+
"source": "./src/foo-sub1.ts",
|
|
36
|
+
"types": "./lib/foo-sub1.d.ts",
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
`);
|
|
40
|
+
});
|
|
41
|
+
it('can add an entry to an existing exports map', async () => {
|
|
42
|
+
const exportsMap = {
|
|
43
|
+
'.': './lib/index.js',
|
|
44
|
+
};
|
|
45
|
+
await addExportsMapEntry({
|
|
46
|
+
exports: exportsMap,
|
|
47
|
+
packagePath: testProject1Path,
|
|
48
|
+
importPath: './lib/foo-sub1',
|
|
49
|
+
});
|
|
50
|
+
expect(exportsMap).toMatchInlineSnapshot(`
|
|
51
|
+
{
|
|
52
|
+
".": "./lib/index.js",
|
|
53
|
+
"./lib/foo-sub1": {
|
|
54
|
+
"default": "./lib/foo-sub1.js",
|
|
55
|
+
"source": "./src/foo-sub1.ts",
|
|
56
|
+
"types": "./lib/foo-sub1.d.ts",
|
|
57
|
+
},
|
|
58
|
+
}
|
|
59
|
+
`);
|
|
60
|
+
});
|
|
61
|
+
it('can add an entry to an external package like the "debug" package', async () => {
|
|
62
|
+
const exportsMap = {};
|
|
63
|
+
const testPath = await createTestFileStructure({
|
|
64
|
+
'node_modules/debug/package.json': {
|
|
65
|
+
name: 'debug',
|
|
66
|
+
main: './src/index.js',
|
|
67
|
+
browser: './src/browser.js',
|
|
68
|
+
},
|
|
69
|
+
'node_modules/debug/src/index.js': '',
|
|
70
|
+
'node_modules/debug/src/browser.js': '',
|
|
71
|
+
});
|
|
72
|
+
await addExportsMapEntry({
|
|
73
|
+
exports: exportsMap,
|
|
74
|
+
packagePath: path.join(testPath, 'node_modules/debug'),
|
|
75
|
+
importPath: '.',
|
|
76
|
+
});
|
|
77
|
+
expect(exportsMap).toMatchInlineSnapshot(`
|
|
78
|
+
{
|
|
79
|
+
".": {
|
|
80
|
+
"default": "./src/browser.js",
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
`);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
//# sourceMappingURL=addExportsMapEntry.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addExportsMapEntry.test.js","sourceRoot":"","sources":["../src/addExportsMapEntry.test.ts"],"names":[],"mappings":"AAAA,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;;;KASxC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kEAAkE,EAAE,KAAK,IAAI,EAAE;QAChF,MAAM,UAAU,GAA2C,EAAE,CAAC;QAC9D,MAAM,QAAQ,GAAG,MAAM,uBAAuB,CAAC;YAC7C,iCAAiC,EAAE;gBACjC,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,kBAAkB;aAC5B;YACD,iCAAiC,EAAE,EAAE;YACrC,mCAAmC,EAAE,EAAE;SACxC,CAAC,CAAC;QAEH,MAAM,kBAAkB,CAAC;YACvB,OAAO,EAAE,UAAU;YACnB,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,oBAAoB,CAAC;YACtD,UAAU,EAAE,GAAG;SAChB,CAAC,CAAC;QAEH,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC;;;;;;KAMxC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -6,7 +6,3 @@ import { PackageDefinitions } from './PackageDefinitions.js';
|
|
|
6
6
|
export declare function createExportsMap(packagePath: string, options?: {
|
|
7
7
|
packages?: PackageDefinitions;
|
|
8
8
|
}): Promise<PackageJson.Exports>;
|
|
9
|
-
/**
|
|
10
|
-
* Given an exports map and details about an import path, adds the entry.
|
|
11
|
-
*/
|
|
12
|
-
export declare function addExportsMapEntry(exports: PackageJson.Exports, importPath: string | undefined, packagePath: string, condition: string | undefined, entryPath: string | undefined, typesPath?: string): Promise<void>;
|
package/lib/createExportsMap.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { isFile } from '@ms-cloudpack/path-utilities';
|
|
3
3
|
import { PackageDefinitions } from './PackageDefinitions.js';
|
|
4
|
-
import {
|
|
5
|
-
import { resolveImportFromPackagePath } from './resolveImportFromPackagePath.js';
|
|
6
|
-
import { safeRelativePath } from './safeRelativePath.js';
|
|
4
|
+
import { addExportsMapEntry } from './addExportsMapEntry.js';
|
|
7
5
|
/**
|
|
8
6
|
* Given a package path, generates an export map for the package.
|
|
9
7
|
*/
|
|
@@ -18,82 +16,53 @@ export async function createExportsMap(packagePath, options = {}) {
|
|
|
18
16
|
return definition.exports;
|
|
19
17
|
}
|
|
20
18
|
const { main, module, browser } = definition;
|
|
21
|
-
const
|
|
19
|
+
const browserString = typeof browser === 'string' ? browser : undefined;
|
|
20
|
+
const rootIndex = isFile(path.join(packagePath, 'index.js')) ? './index.js' : undefined;
|
|
22
21
|
const exports = {};
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const typesPath = definition.types || definition.typings;
|
|
23
|
+
const hasPackageEntry = browserString || module || main || rootIndex;
|
|
24
|
+
if (!hasPackageEntry) {
|
|
25
|
+
if (!browser) {
|
|
26
|
+
return exports;
|
|
27
|
+
}
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
await addExportsMapEntry(
|
|
29
|
+
else {
|
|
30
|
+
await addExportsMapEntry({
|
|
31
|
+
exports,
|
|
32
|
+
importPath: '.',
|
|
33
|
+
packagePath,
|
|
34
|
+
condition: 'default',
|
|
35
|
+
entryPath: browserString || module || main || rootIndex,
|
|
36
|
+
typesPath,
|
|
37
|
+
});
|
|
29
38
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// If we have an entry defined in the package, iterate through exports and update things.
|
|
38
|
-
if (main || module) {
|
|
39
|
-
for (const mapValue of Object.values(exports)) {
|
|
40
|
-
const exportUrl = (mapValue.import || mapValue.default);
|
|
41
|
-
if (browser[exportUrl]) {
|
|
42
|
-
mapValue['browser'] = browser[exportUrl] || '';
|
|
43
|
-
}
|
|
39
|
+
if (typeof browser === 'object') {
|
|
40
|
+
// If we have an entry defined in the package, iterate through exports and update things.
|
|
41
|
+
if (hasPackageEntry) {
|
|
42
|
+
for (const mapValue of Object.values(exports)) {
|
|
43
|
+
const exportUrl = mapValue.import || mapValue.default;
|
|
44
|
+
if (browser[exportUrl]) {
|
|
45
|
+
mapValue['browser'] = browser[exportUrl] || '';
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// When all we have are browser entries, attempt to make exports out of them.
|
|
51
|
+
for (const [key, value] of Object.entries(browser)) {
|
|
52
|
+
if (typeof value === 'string' && path.extname(value) === '.js') {
|
|
53
|
+
exports[makeSafeImportKey(key)] = {
|
|
54
|
+
browser: value,
|
|
55
|
+
};
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
return exports;
|
|
59
61
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Given an exports map and details about an import path, adds the entry.
|
|
62
|
-
*/
|
|
63
|
-
export async function addExportsMapEntry(exports, importPath, packagePath, condition = 'default', entryPath, typesPath) {
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
-
const packageExports = exports;
|
|
66
|
-
if (!entryPath) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
entryPath = safeRelativePath(entryPath);
|
|
70
|
-
const intermediatePath = (importPath && (await resolveImportFromPackagePath(packagePath, importPath))) || entryPath;
|
|
71
|
-
const isInternal = !isExternalPackage(packagePath);
|
|
72
|
-
const sourcePath = isInternal
|
|
73
|
-
? await resolveImportFromPackagePath(packagePath, intermediatePath, { preferSource: true })
|
|
74
|
-
: undefined;
|
|
75
|
-
const potentialTypesPath = path.extname(intermediatePath) === '.js' && intermediatePath.replace('.js', '.d.ts');
|
|
76
|
-
const isTypeScriptSource = sourcePath && ['.ts', '.tsx', '.mts', '.cts'].indexOf(path.extname(sourcePath)) >= 0;
|
|
77
|
-
// Discover d.ts if available.
|
|
78
|
-
if (!typesPath &&
|
|
79
|
-
potentialTypesPath &&
|
|
80
|
-
((isInternal && isTypeScriptSource) || (!isInternal && isFile(path.join(packagePath, potentialTypesPath))))) {
|
|
81
|
-
typesPath = potentialTypesPath;
|
|
82
|
-
}
|
|
83
|
-
importPath = importPath || '.';
|
|
84
|
-
const exportSet = (packageExports[importPath] || (packageExports[importPath] = {}));
|
|
85
|
-
if (typesPath) {
|
|
86
|
-
exportSet.types = safeRelativePath(typesPath);
|
|
87
|
-
}
|
|
88
|
-
exportSet[condition] = intermediatePath;
|
|
89
|
-
if (sourcePath && sourcePath !== intermediatePath) {
|
|
90
|
-
exportSet.source = safeRelativePath(sourcePath);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
62
|
function makeSafeImportKey(key) {
|
|
94
63
|
// if the key starts with a slash, add a dot
|
|
95
64
|
if (key.startsWith('/')) {
|
|
96
|
-
|
|
65
|
+
key = '.' + key;
|
|
97
66
|
}
|
|
98
67
|
// if the key doesn't start with "./", add it
|
|
99
68
|
if (!key.startsWith('./')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;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O,OAAO,KAAK,QAAQ,EAAE;QAC/B,yFAAyF;QACzF,IAAI,eAAe,EAAE;YACnB,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE;gBAC7C,MAAM,SAAS,GAAW,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,OAAO,CAAC;gBAE9D,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;oBACtB,QAAQ,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;iBAChD;aACF;SACF;aAAM;YACL,6EAA6E;YAC7E,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;gBAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,KAAK,EAAE;oBAC7D,OAA+C,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,GAAG;wBACzE,OAAO,EAAE,KAAK;qBACf,CAAC;iBACH;aACF;SACF;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,iBAAiB,CAAC,GAAW;IACpC,4CAA4C;IAC5C,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACvB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KACjB;IAED,6CAA6C;IAC7C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;KAClB;IAED,4BAA4B;IAC5B,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -3,8 +3,9 @@ import { createExportsMap } from './createExportsMap.js';
|
|
|
3
3
|
import { testScenariosPath } from './testPaths.js';
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import { PackageDefinitions } from './PackageDefinitions.js';
|
|
6
|
+
import { createTestFileStructure } from '@ms-cloudpack/test-utilities';
|
|
6
7
|
const testGenerateExportsPath = path.join(testScenariosPath, 'test-generate-exports');
|
|
7
|
-
describe('
|
|
8
|
+
describe('createExportsMap', () => {
|
|
8
9
|
it('can return a blank import map for something with nothing to export', async () => {
|
|
9
10
|
expect(await createExportsMap(path.join(testGenerateExportsPath, 'no-exports'))).toEqual({});
|
|
10
11
|
});
|
|
@@ -49,19 +50,27 @@ describe('generateExportsMap', () => {
|
|
|
49
50
|
expect(await createExportsMap(path.join(testGenerateExportsPath, 'module-export'))).toMatchInlineSnapshot(`
|
|
50
51
|
{
|
|
51
52
|
".": {
|
|
52
|
-
"default": "./
|
|
53
|
-
"import": "./module.js",
|
|
53
|
+
"default": "./module.js",
|
|
54
54
|
},
|
|
55
55
|
}
|
|
56
56
|
`);
|
|
57
57
|
});
|
|
58
58
|
it('can generate an exports map for a package with a browser export', async () => {
|
|
59
|
-
|
|
59
|
+
const testPath = await createTestFileStructure({
|
|
60
|
+
'package.json': {
|
|
61
|
+
name: 'browser-export',
|
|
62
|
+
main: 'main.js',
|
|
63
|
+
module: 'module.js',
|
|
64
|
+
browser: 'browser.js',
|
|
65
|
+
},
|
|
66
|
+
'main.js': '',
|
|
67
|
+
'module.js': '',
|
|
68
|
+
'browser.js': '',
|
|
69
|
+
});
|
|
70
|
+
expect(await createExportsMap(testPath)).toMatchInlineSnapshot(`
|
|
60
71
|
{
|
|
61
72
|
".": {
|
|
62
|
-
"
|
|
63
|
-
"default": "./main.js",
|
|
64
|
-
"import": "./module.js",
|
|
73
|
+
"default": "./browser.js",
|
|
65
74
|
},
|
|
66
75
|
}
|
|
67
76
|
`);
|
|
@@ -100,9 +109,9 @@ describe('generateExportsMap', () => {
|
|
|
100
109
|
`);
|
|
101
110
|
});
|
|
102
111
|
it(`can find exports from browser-only packages like uuid@3.4.0`, async () => {
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
'
|
|
112
|
+
const packages = new PackageDefinitions();
|
|
113
|
+
const testPath = await createTestFileStructure({
|
|
114
|
+
'package.json': {
|
|
106
115
|
name: 'uuid',
|
|
107
116
|
browser: {
|
|
108
117
|
'./lib/rng.js': './lib/rng-browser.js',
|
|
@@ -110,8 +119,13 @@ describe('generateExportsMap', () => {
|
|
|
110
119
|
'./lib/md5.js': './lib/md5-browser.js',
|
|
111
120
|
},
|
|
112
121
|
},
|
|
122
|
+
'lib/rng.js': '',
|
|
123
|
+
'lib/sha1.js': '',
|
|
124
|
+
'lib/md5.js': '',
|
|
113
125
|
});
|
|
114
|
-
const exportsMap = await createExportsMap(
|
|
126
|
+
const exportsMap = (await createExportsMap(testPath, { packages }));
|
|
127
|
+
expect(typeof exportsMap).toEqual('object');
|
|
128
|
+
expect(exportsMap?.['.']).toBeUndefined();
|
|
115
129
|
expect(exportsMap).toMatchInlineSnapshot(`
|
|
116
130
|
{
|
|
117
131
|
"./lib/md5": {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExportsMap.test.js","sourceRoot":"","sources":["../src/createExportsMap.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"createExportsMap.test.js","sourceRoot":"","sources":["../src/createExportsMap.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC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
export declare type PackageNameVersion = `${string}@${string}`;
|
|
2
3
|
export declare type ResolveMapEntry = {
|
|
3
4
|
name: string;
|
|
@@ -14,4 +15,5 @@ export declare function createResolveMap(options: {
|
|
|
14
15
|
additionalPaths?: string[];
|
|
15
16
|
gitRootPath?: string;
|
|
16
17
|
strictVersioning?: boolean;
|
|
18
|
+
packages?: PackageDefinitions;
|
|
17
19
|
}): Promise<ResolveMap>;
|
package/lib/createResolveMap.js
CHANGED
|
@@ -2,13 +2,12 @@ import { PackageDefinitions } from './PackageDefinitions.js';
|
|
|
2
2
|
import { findPackagePath } from './findPackagePath.js';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
const { realpath } = fs.promises;
|
|
5
|
-
const definitions = PackageDefinitions.getInstance();
|
|
6
5
|
export async function createResolveMap(options) {
|
|
7
6
|
var _a, _b, _c, _d;
|
|
8
|
-
const { appPath, additionalPaths = [], gitRootPath, strictVersioning } = options;
|
|
7
|
+
const { appPath, additionalPaths = [], gitRootPath, strictVersioning, packages = PackageDefinitions.getInstance(), } = options;
|
|
9
8
|
const visitedPaths = new Set([appPath, ...additionalPaths]);
|
|
10
9
|
const allEntries = {};
|
|
11
|
-
const appDefinition = await
|
|
10
|
+
const appDefinition = await packages.get(appPath);
|
|
12
11
|
if (!appDefinition) {
|
|
13
12
|
throw new Error(`Could not find package.json for ${appPath}`);
|
|
14
13
|
}
|
|
@@ -22,7 +21,7 @@ export async function createResolveMap(options) {
|
|
|
22
21
|
let packagePath = pathsToVisit.shift();
|
|
23
22
|
if (packagePath) {
|
|
24
23
|
packagePath = await realpath(packagePath);
|
|
25
|
-
const definition = await
|
|
24
|
+
const definition = await packages.get(packagePath);
|
|
26
25
|
if (definition && definition.name && definition.version) {
|
|
27
26
|
const packageId = `${definition.name}@${definition.version}`;
|
|
28
27
|
const namedEntries = (allEntries[_a = definition.name] ?? (allEntries[_a] = {}));
|
|
@@ -35,7 +34,7 @@ export async function createResolveMap(options) {
|
|
|
35
34
|
const requiredVersion = definition?.dependencies?.[depName] || definition?.peerDependencies?.[depName];
|
|
36
35
|
const dependencyPath = await findPackagePath(depName, strictVersioning ? requiredVersion : undefined, packagePath, gitRootPath, !!definition?.peerDependencies?.[depName]);
|
|
37
36
|
if (dependencyPath) {
|
|
38
|
-
const dependencyDefinition = await
|
|
37
|
+
const dependencyDefinition = await packages.get(dependencyPath);
|
|
39
38
|
if (dependencyDefinition?.name && dependencyDefinition.version) {
|
|
40
39
|
const dependencyNamedEntries = (allEntries[_c = dependencyDefinition.name] ?? (allEntries[_c] = {}));
|
|
41
40
|
const dependencyEntry = (dependencyNamedEntries[_d = dependencyDefinition.version] ?? (dependencyNamedEntries[_d] = createMapEntry(dependencyDefinition, dependencyPath)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../src/createResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../src/createResolveMap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC;AAgBjC,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAMtC;;IACC,MAAM,EACJ,OAAO,EACP,eAAe,GAAG,EAAE,EACpB,WAAW,EACX,gBAAgB,EAChB,QAAQ,GAAG,kBAAkB,CAAC,WAAW,EAAE,GAC5C,GAAG,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AAU,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;gBACpD,OAAO,cAAc,CAAC;YACxB,CAAC,EAAE,EAAqC,CAAC,CAAC;SAC3C;KACF;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,cAAc,CAAC,iBAA8B,EAAE,WAAmB;IACzE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,GAAG,iBAAiB,CAAC;IAEtD,OAAO;QACL,IAAI;QACJ,OAAO;QACP,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,EAAE;KACf,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ResolveMap, ResolveMapEntry } from './createResolveMap.js';
|
|
2
|
+
import type { PackageJson } from 'type-fest';
|
|
3
|
+
/**
|
|
4
|
+
* Helper which, given a definition/resolveMap/dependency name, returns the resolve map entry for the dependency.
|
|
5
|
+
*/
|
|
6
|
+
export declare function findResolveMapEntry(definition: PackageJson, packageName: string, resolveMap: ResolveMap): ResolveMapEntry | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper which, given a definition/resolveMap/dependency name, returns the resolve map entry for the dependency.
|
|
3
|
+
*/
|
|
4
|
+
export function findResolveMapEntry(definition, packageName, resolveMap) {
|
|
5
|
+
const resolveEntry = resolveMap[packageName];
|
|
6
|
+
if (!resolveEntry) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const scopedEntry = Object.values(resolveEntry?.scopedVersions || {}).filter((e) => !!e.requiredBy[`${definition.name}@${definition.version}`])[0];
|
|
10
|
+
return scopedEntry || resolveEntry;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=findResolveMapEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findResolveMapEntry.js","sourceRoot":"","sources":["../src/findResolveMapEntry.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,UAAuB,EACvB,WAAmB,EACnB,UAAsB;IAEtB,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAE7C,IAAI,CAAC,YAAY,EAAE;QACjB,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,cAAc,IAAI,EAAE,CAAC,CAAC,MAAM,CAC1E,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC,CAClE,CAAC,CAAC,CAAC,CAAC;IAEL,OAAO,WAAW,IAAI,YAAY,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|