@ms-cloudpack/package-utilities 0.1.6 → 0.3.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 CHANGED
@@ -2,7 +2,88 @@
2
2
  "name": "@ms-cloudpack/package-utilities",
3
3
  "entries": [
4
4
  {
5
- "date": "Sat, 14 May 2022 04:35:56 GMT",
5
+ "date": "Sat, 21 May 2022 00:31:20 GMT",
6
+ "tag": "@ms-cloudpack/package-utilities_v0.3.0",
7
+ "version": "0.3.0",
8
+ "comments": {
9
+ "minor": [
10
+ {
11
+ "author": "dzearing@microsoft.com",
12
+ "package": "@ms-cloudpack/package-utilities",
13
+ "commit": "c26c7bcc7abda501d07180598e3da003b435b03b",
14
+ "comment": "Adding api to generate an import map based on a resolve map."
15
+ }
16
+ ]
17
+ }
18
+ },
19
+ {
20
+ "date": "Fri, 20 May 2022 04:26:15 GMT",
21
+ "tag": "@ms-cloudpack/package-utilities_v0.2.0",
22
+ "version": "0.2.0",
23
+ "comments": {
24
+ "minor": [
25
+ {
26
+ "author": "dzearing@microsoft.com",
27
+ "package": "@ms-cloudpack/package-utilities",
28
+ "commit": "b39bb143fc53e622c39f9e9fd349f71c9ebadd77",
29
+ "comment": "Updating createResolveMap logic."
30
+ },
31
+ {
32
+ "author": "beachball",
33
+ "package": "@ms-cloudpack/package-utilities",
34
+ "comment": "Bump @ms-cloudpack/path-utilities to v0.2.0",
35
+ "commit": "b39bb143fc53e622c39f9e9fd349f71c9ebadd77"
36
+ }
37
+ ]
38
+ }
39
+ },
40
+ {
41
+ "date": "Thu, 19 May 2022 21:04:02 GMT",
42
+ "tag": "@ms-cloudpack/package-utilities_v0.1.7",
43
+ "version": "0.1.7",
44
+ "comments": {
45
+ "patch": [
46
+ {
47
+ "author": "bot@renovateapp.com",
48
+ "package": "@ms-cloudpack/package-utilities",
49
+ "commit": "d701b1fd3997bfb2f2c67f06a94bd79fadbcac6d",
50
+ "comment": "Update babel monorepo to v7.18.0"
51
+ }
52
+ ]
53
+ }
54
+ },
55
+ {
56
+ "date": "Wed, 18 May 2022 03:18:06 GMT",
57
+ "tag": "@ms-cloudpack/package-utilities_v0.1.6",
58
+ "version": "0.1.6",
59
+ "comments": {
60
+ "none": [
61
+ {
62
+ "author": "bot@renovateapp.com",
63
+ "package": "@ms-cloudpack/package-utilities",
64
+ "commit": "not available",
65
+ "comment": "Update `@babel/types` to v7.17.12"
66
+ }
67
+ ]
68
+ }
69
+ },
70
+ {
71
+ "date": "Wed, 18 May 2022 03:16:26 GMT",
72
+ "tag": "@ms-cloudpack/package-utilities_v0.1.6",
73
+ "version": "0.1.6",
74
+ "comments": {
75
+ "none": [
76
+ {
77
+ "author": "bot@renovateapp.com",
78
+ "package": "@ms-cloudpack/package-utilities",
79
+ "commit": "907f44c1dc2779dcbfa2714be29719c41b91dc50",
80
+ "comment": "Update `@babel/types` to v7.17.12"
81
+ }
82
+ ]
83
+ }
84
+ },
85
+ {
86
+ "date": "Sat, 14 May 2022 04:36:11 GMT",
6
87
  "tag": "@ms-cloudpack/package-utilities_v0.1.6",
7
88
  "version": "0.1.6",
8
89
  "comments": {
package/CHANGELOG.md CHANGED
@@ -1,12 +1,37 @@
1
1
  # Change Log - @ms-cloudpack/package-utilities
2
2
 
3
- This log was last generated on Sat, 14 May 2022 04:35:56 GMT and should not be manually modified.
3
+ This log was last generated on Sat, 21 May 2022 00:31:20 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
+ ## 0.3.0
8
+
9
+ Sat, 21 May 2022 00:31:20 GMT
10
+
11
+ ### Minor changes
12
+
13
+ - Adding api to generate an import map based on a resolve map. (dzearing@microsoft.com)
14
+
15
+ ## 0.2.0
16
+
17
+ Fri, 20 May 2022 04:26:15 GMT
18
+
19
+ ### Minor changes
20
+
21
+ - Updating createResolveMap logic. (dzearing@microsoft.com)
22
+ - Bump @ms-cloudpack/path-utilities to v0.2.0
23
+
24
+ ## 0.1.7
25
+
26
+ Thu, 19 May 2022 21:04:02 GMT
27
+
28
+ ### Patches
29
+
30
+ - Update babel monorepo to v7.18.0 (bot@renovateapp.com)
31
+
7
32
  ## 0.1.6
8
33
 
9
- Sat, 14 May 2022 04:35:56 GMT
34
+ Sat, 14 May 2022 04:36:11 GMT
10
35
 
11
36
  ### Patches
12
37
 
@@ -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] = slash(path.join(baseUrl, exportPath));
37
+ }
38
+ }
39
+ }
40
+ }
41
+ else {
42
+ importMap[definition.name] = slash(path.join(baseUrl, definition.module || definition.main || 'index.js'));
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,GAAG,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC;YAE1C,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,YA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AC,UAAU,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,IAAI,IAAI,UAAU,CAAC,CAAC,CAAC;SAC5G;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,GAAG,EAAE;IAC/B,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;QACvD,MAAM,UAAU,GAAe;YAC7B,CAAC,EAAE,oBAAoB;SACxB,CAAC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AAC;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
- import type { InstalledPackagesResult } from './getInstalledPackages.js';
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
- entry: string;
6
+ requiredBy: string[];
6
7
  scopedVersions?: {
7
- [packageNameAndVersion: `${string}@${string}`]: ResolveMapEntry;
8
+ [version: string]: ResolveMapEntry;
8
9
  };
9
10
  };
10
- export declare type ResolveMap = {
11
- [packageName: string]: ResolveMapEntry;
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>;
@@ -1,116 +1,60 @@
1
- import { getInstalledPackages } from './getInstalledPackages.js';
2
- // import fs from 'fs';
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) {
57
4
  const { appPath, additionalPaths = [] } = options;
58
- // First, create a merged dependency list.
59
- // const dependencies = {};
60
- // Grab what's installed, so that we can default to use those packages.
61
- const { installedPackages, stats } = await getInstalledPackages([appPath, ...additionalPaths]);
62
- // await writeFile(
63
- // path.join(appPath, "install-map.json"),
64
- // JSON.stringify({ installedPackages, stats }, null, 2),
65
- // "utf8"
66
- // );
67
- // // Add the dependencies for the appPath.
68
- // await addDependencies(dependencies, appPath, installedPackages);
69
- // // Add deps for additional paths.
70
- // for (let additionalPath of additionalPaths) {
71
- // await addDependencies(dependencies, additionalPath, installedPackages);
72
- // }
73
- // Now that we have the resolved dependency list, optimize it as the resolveMap.
5
+ const visitedPaths = new Set([appPath, ...additionalPaths]);
6
+ const pathsToVisit = [appPath, ...additionalPaths];
7
+ const allEntries = {};
8
+ while (pathsToVisit.length) {
9
+ const packagePath = pathsToVisit.shift();
10
+ if (packagePath) {
11
+ const definition = await getPackageDefinition(packagePath, true);
12
+ if (definition) {
13
+ const packageId = `${definition.name}@${definition.version}`;
14
+ for (const depName of Object.keys(definition?.dependencies || {})) {
15
+ const dependencyPath = findPackagePath(depName, packagePath);
16
+ const dependencyDefinition = await getPackageDefinition(dependencyPath, true);
17
+ if (dependencyDefinition) {
18
+ const dependencyNamedEntries = (allEntries[dependencyDefinition.name] ??= {});
19
+ const dependencyEntry = (dependencyNamedEntries[dependencyDefinition.version] ??= createMapEntry(dependencyDefinition, dependencyPath));
20
+ dependencyEntry.requiredBy.add(packageId);
21
+ if (!visitedPaths.has(dependencyPath)) {
22
+ visitedPaths.add(dependencyPath);
23
+ pathsToVisit.push(dependencyPath);
24
+ }
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }
30
+ // Now we have all entries and relationships. Iterate through the relationships to build
31
+ // The final resolve map.
74
32
  const resolveMap = {};
75
- // Iterate through installed packages.
76
- for (const packageName of Object.keys(installedPackages)) {
77
- // Get installed versions, sorted by the number of dependencies (greatest to least)
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
- }),
33
+ for (const [name, versions] of Object.entries(allEntries)) {
34
+ const [dominantVersion, ...otherVersions] = Object.keys(versions).sort((a, b) => {
35
+ return versions[a].requiredBy.size < versions[b].requiredBy.size ? 1 : -1;
90
36
  });
91
- // If we have additional versions, scope each of those to their specific parents
92
- if (versions.length > 1) {
93
- const scopedVersionEntries = (depResolveEntry.scopedVersions = {});
94
- for (let i = 1; i < versions.length; i++) {
95
- const scopedVersion = versions[i];
96
- const scopedPackage = installedPackages[packageName][scopedVersion];
97
- for (const dep of scopedPackage.requiredBy) {
98
- scopedVersionEntries[`${dep.name}@${dep.version}`] = {
99
- version: scopedVersion,
100
- path: scopedPackage.path,
101
- entry: await resolveImportFromPackagePath(scopedPackage.path, '', {
102
- preferSource: false,
103
- }),
104
- };
105
- }
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
+ const entry = (resolveMap[name] = allEntries[name][dominantVersion]);
39
+ entry.requiredBy = Array.from(entry.requiredBy);
40
+ if (otherVersions?.length) {
41
+ entry.scopedVersions = {};
42
+ for (const otherVersion of otherVersions) {
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ const scopedEntry = (entry.scopedVersions[otherVersion] = versions[otherVersion]);
45
+ scopedEntry.requiredBy = Array.from(scopedEntry.requiredBy);
106
46
  }
107
47
  }
108
48
  }
109
- // await writeFile(
110
- // path.join(appPath, 'resolve-map.json'),
111
- // JSON.stringify(resolveMap, null, 2),
112
- // 'utf8'
113
- // );
114
- return { resolveMap, stats };
49
+ return resolveMap;
50
+ }
51
+ function createMapEntry(packageDefinition, packagePath) {
52
+ const { name, version } = packageDefinition;
53
+ return {
54
+ name,
55
+ version,
56
+ path: packagePath,
57
+ requiredBy: new Set(),
58
+ };
115
59
  }
116
60
  //# sourceMappingURL=createResolveMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"createResolveMap.js","sourceRoot":"","sources":["../src/createResolveMap.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,uBAAuB;AACvB,2BAA2B;AAC3B,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAejF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkDE;AACF,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAGtC;IACC,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAElD,0CAA0C;IAC1C,2BAA2B;IAE3B,uEAAuE;IACvE,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,GAAG,MAAM,oBAAoB,CAAC,CAAC,OAAO,EAAE,GAAG,eAAe,CAAC,CAAC,CAAC;IAE/F,mBAAmB;IACnB,4CAA4C;IAC5C,2DAA2D;IAC3D,WAAW;IACX,KAAK;IAEL,2CAA2C;IAC3C,mEAAmE;IAEnE,oCAAoC;IACpC,gDAAgD;IAChD,4EAA4E;IAC5E,IAAI;IAEJ,gFAAgF;IAChF,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,sCAAsC;IACtC,KAAK,MAAM,WAAW,I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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,26 @@ 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 })).toMatchSnapshot();
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
+ }
28
+ `);
10
29
  });
11
30
  });
12
31
  //# 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,eAAe,EAAE,CAAC;IACtF,CAAC,CAAC,CAAC;AACL,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;;;;;;;;;;;;;;;;;;;KAmBvF,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 prescedence
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 prescedence
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.1.6",
3
+ "version": "0.3.0",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,14 +15,14 @@
15
15
  "dependencies": {
16
16
  "@babel/parser": "^7.16.12",
17
17
  "@babel/traverse": "^7.16.10",
18
- "@ms-cloudpack/path-utilities": "^0.1.0",
18
+ "@ms-cloudpack/path-utilities": "^0.2.0",
19
19
  "resolve": "^1.22.0"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@ms-cloudpack/scripts": "*",
23
23
  "@ms-cloudpack/eslint-config-base": "*",
24
24
  "@types/resolve": "1.20.2",
25
- "@babel/types": "7.17.10"
25
+ "@babel/types": "7.18.0"
26
26
  },
27
27
  "scripts": {
28
28
  "api:update": "cloudpack-scripts api-update",
@@ -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
- }