@ms-cloudpack/cli 0.59.0 → 0.59.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/init/evaluateImportsForOverrides.d.ts +3 -3
- package/lib/commands/init/evaluateImportsForOverrides.d.ts.map +1 -1
- package/lib/commands/init/evaluateImportsForOverrides.js +53 -41
- package/lib/commands/init/evaluateImportsForOverrides.js.map +1 -1
- package/lib/commands/init/evaluatePath.d.ts +2 -0
- package/lib/commands/init/evaluatePath.d.ts.map +1 -1
- package/lib/commands/init/evaluatePath.js +6 -17
- package/lib/commands/init/evaluatePath.js.map +1 -1
- package/lib/commands/init/formatInitSummary.d.ts +7 -5
- package/lib/commands/init/formatInitSummary.d.ts.map +1 -1
- package/lib/commands/init/formatInitSummary.js +100 -80
- package/lib/commands/init/formatInitSummary.js.map +1 -1
- package/lib/commands/init/init.js +6 -0
- package/lib/commands/init/init.js.map +1 -1
- package/lib/commands/init/optimizeDependencies.d.ts +3 -10
- package/lib/commands/init/optimizeDependencies.d.ts.map +1 -1
- package/lib/commands/init/optimizeDependencies.js +3 -6
- package/lib/commands/init/optimizeDependencies.js.map +1 -1
- package/lib/commands/init/types/InitPackageIdentifier.d.ts +1 -0
- package/lib/commands/init/types/InitPackageIdentifier.d.ts.map +1 -1
- package/lib/commands/init/types/InitPackageIdentifier.js.map +1 -1
- package/lib/commands/init/verifyExports.d.ts +2 -2
- package/lib/commands/init/verifyExports.d.ts.map +1 -1
- package/lib/commands/init/verifyExports.js +51 -75
- package/lib/commands/init/verifyExports.js.map +1 -1
- package/lib/commands/sync/execute.d.ts +1 -1
- package/lib/commands/sync/execute.d.ts.map +1 -1
- package/lib/commands/sync/execute.js +20 -5
- package/lib/commands/sync/execute.js.map +1 -1
- package/lib/types/CommandAction.d.ts +5 -1
- package/lib/types/CommandAction.d.ts.map +1 -1
- package/lib/types/CommandAction.js +3 -1
- package/lib/types/CommandAction.js.map +1 -1
- package/package.json +12 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BundleInfo } from '@ms-cloudpack/api-server';
|
|
2
|
-
import type { CloudpackConfig, PackageDefinitionsCache, PackageImporterContext, PackageJson } from '@ms-cloudpack/common-types';
|
|
2
|
+
import type { BundleMessage, CloudpackConfig, PackageDefinitionsCache, PackageImporterContext, PackageJson } from '@ms-cloudpack/common-types';
|
|
3
3
|
import type { ResolveMap } from '@ms-cloudpack/package-utilities';
|
|
4
4
|
import type { GeneratedPackageChanges } from './types/GeneratedPackageChanges.js';
|
|
5
5
|
/**
|
|
@@ -21,9 +21,9 @@ export declare function evaluateImportsForOverrides(options: {
|
|
|
21
21
|
/** Included dependencies changes made to the generated config */
|
|
22
22
|
includedDependenciesChanges: GeneratedPackageChanges[];
|
|
23
23
|
/** Any errors encountered */
|
|
24
|
-
errors:
|
|
24
|
+
errors: BundleMessage[];
|
|
25
25
|
/** Any warnings generated */
|
|
26
|
-
warnings:
|
|
26
|
+
warnings: BundleMessage[];
|
|
27
27
|
/** Map from new package path (to be evaluated) to info about the parent. */
|
|
28
28
|
pathsToEvaluate: Map<string, PackageImporterContext | undefined>;
|
|
29
29
|
/** Package paths for which new exports were added, so the package should be re-processed. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateImportsForOverrides.d.ts","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,sBAAsB,EACtB,WAAW,EAEZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAWlE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"evaluateImportsForOverrides.d.ts","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,uBAAuB,EACvB,sBAAsB,EACtB,WAAW,EAEZ,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAWlE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAMlF;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,EAAE;IACzD,QAAQ,EAAE,uBAAuB,CAAC;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,UAAU,EAAE,WAAW,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,MAAM,EAAE,eAAe,CAAC;IACxB,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,sBAAsB,GAAG,SAAS,CAAC;CACrD,GAAG,OAAO,CAAC;IACV,kDAAkD;IAClD,cAAc,EAAE,uBAAuB,EAAE,CAAC;IAC1C,iEAAiE;IACjE,2BAA2B,EAAE,uBAAuB,EAAE,CAAC;IACvD,6BAA6B;IAC7B,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,6BAA6B;IAC7B,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,4EAA4E;IAC5E,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,sBAAsB,GAAG,SAAS,CAAC,CAAC;IACjE,6FAA6F;IAC7F,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC,CAuLD"}
|
|
@@ -4,6 +4,7 @@ import { bulletedList, cyan } from '@ms-cloudpack/task-reporter';
|
|
|
4
4
|
import { isBuiltin } from 'module';
|
|
5
5
|
import { getConsumedPaths } from '@ms-cloudpack/api-server';
|
|
6
6
|
import { neverExclude } from './neverExclude.js';
|
|
7
|
+
import path from 'path';
|
|
7
8
|
/**
|
|
8
9
|
* Evaluate the imports depended on by a package to determine if missing exports map paths need to be added.
|
|
9
10
|
* If so, updates package overrides in the config.
|
|
@@ -29,65 +30,53 @@ export async function evaluateImportsForOverrides(options) {
|
|
|
29
30
|
const resolveEntry = findResolveMapEntry({ definition, packageName: dependencyName, resolveMap });
|
|
30
31
|
const dependencyPath = resolveEntry?.path;
|
|
31
32
|
const dependencyDefinition = dependencyPath ? await packages.get(dependencyPath) : undefined;
|
|
32
|
-
const message = `The package "${dependencyName}" couldn't be found, but it's being imported by the package "${displayName}". ` +
|
|
33
|
-
`Please ensure that "${dependencyName}" is listed in the dependencies of "${displayName}".`;
|
|
34
|
-
const messageBuiltin = `The node built-in "${dependencyName}" is being imported by the package "${displayName}", but no browser-friendly version was found in dependencies. ` +
|
|
35
|
-
`This can be fixed by forcing the package "${displayName}" to use "bundlerType": "rollup" in package settings, or by adding a polyfill browser-friendly dependency.`;
|
|
36
33
|
// If the dependency is not resolved, add an error.
|
|
37
34
|
if (!dependencyPath || !dependencyDefinition) {
|
|
38
|
-
|
|
35
|
+
errors.push(getMissingDepMessage({ dependencyName, displayName, issueType: 'not-found', packagePath }));
|
|
39
36
|
// If the dependency is not resolved, we can't continue to evaluate it.
|
|
40
37
|
continue;
|
|
41
38
|
}
|
|
42
|
-
// If the dependency is not listed
|
|
39
|
+
// If the dependency is not listed, add to includedDependencies.
|
|
43
40
|
if (!dependencies[dependencyName] && dependencyName !== definition.name && !neverExclude(dependencyName, config)) {
|
|
44
41
|
// Survive from the case where it is not a dependency in the package.json
|
|
45
42
|
// and it is resolvable, but warn the user.
|
|
46
43
|
if (!unusedDependencies[dependencyName]) {
|
|
47
|
-
|
|
44
|
+
warnings.push(getMissingDepMessage({ dependencyName, displayName, issueType: 'undeclared', packagePath }));
|
|
48
45
|
}
|
|
49
46
|
// Make sure to add the package to the list of packages to evaluate.
|
|
50
47
|
pathsToEvaluate.set(packagePath, importerContext);
|
|
51
48
|
// Add to includedDependencies
|
|
52
49
|
const packageSettings = (config.generated.packageSettings ??= []);
|
|
53
|
-
let generatedPackageSettings = getPackageSettings({
|
|
50
|
+
let { generatedPackageSettings } = getPackageSettings({
|
|
54
51
|
config: { generated: { packageSettings } },
|
|
55
52
|
name: packageName,
|
|
56
53
|
version: packageVersion,
|
|
57
54
|
firstMatch: true,
|
|
58
|
-
})
|
|
55
|
+
});
|
|
59
56
|
if (!generatedPackageSettings) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
generatedPackageSettings = {
|
|
67
|
-
match: packageName,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
57
|
+
generatedPackageSettings = {
|
|
58
|
+
match: isExternalPackage(packagePath) ? { name: packageName, version: `^${packageVersion}` } : packageName,
|
|
59
|
+
};
|
|
70
60
|
packageSettings.push(generatedPackageSettings);
|
|
71
61
|
}
|
|
72
62
|
generatedPackageSettings.includedDependencies ??= [];
|
|
73
63
|
// Add to includedDependencies if it is not already included.
|
|
74
|
-
if (generatedPackageSettings.includedDependencies.includes(dependencyName)) {
|
|
75
|
-
|
|
64
|
+
if (!generatedPackageSettings.includedDependencies.includes(dependencyName)) {
|
|
65
|
+
generatedPackageSettings.includedDependencies.push(dependencyName);
|
|
66
|
+
includedDependenciesChanges.push({
|
|
67
|
+
name: packageName,
|
|
68
|
+
version: packageVersion,
|
|
69
|
+
path: packagePath,
|
|
70
|
+
changes: [
|
|
71
|
+
{
|
|
72
|
+
type: 'included-dependency',
|
|
73
|
+
change: dependencyName,
|
|
74
|
+
reason: `Imported by "${displayName}"`,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
pathsToRefresh.add(packagePath);
|
|
76
79
|
}
|
|
77
|
-
generatedPackageSettings.includedDependencies.push(dependencyName);
|
|
78
|
-
includedDependenciesChanges.push({
|
|
79
|
-
name: packageName,
|
|
80
|
-
version: packageVersion,
|
|
81
|
-
path: packagePath,
|
|
82
|
-
changes: [
|
|
83
|
-
{
|
|
84
|
-
type: 'included-dependency',
|
|
85
|
-
change: dependencyName,
|
|
86
|
-
reason: `Imported by "${displayName}"`,
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
});
|
|
90
|
-
pathsToRefresh.add(packagePath);
|
|
91
80
|
}
|
|
92
81
|
const { name, version } = dependencyDefinition;
|
|
93
82
|
if (!name || !version) {
|
|
@@ -160,15 +149,38 @@ export async function evaluateImportsForOverrides(options) {
|
|
|
160
149
|
pathsToRefresh.add(dependencyPath);
|
|
161
150
|
}
|
|
162
151
|
else {
|
|
163
|
-
const
|
|
164
|
-
`
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
errors.push(
|
|
152
|
+
const text = `An import couldn't be resolved to a physical file. ` +
|
|
153
|
+
`Check that the import refers to a file that's exported by the package or adjust the "${cyan(dependencyName)}" package version to one that supports this import path.\n${bulletedList([
|
|
154
|
+
`Import: ${cyan(dependencyImportPath.replace('.', dependencyName))}`,
|
|
155
|
+
`Resolved to: ${dependencyName}@${version} (${dependencyImportPath})`,
|
|
156
|
+
], 2)}`;
|
|
157
|
+
errors.push({
|
|
158
|
+
text,
|
|
159
|
+
source: 'evaluate imports',
|
|
160
|
+
location: { file: packagePath },
|
|
161
|
+
});
|
|
169
162
|
}
|
|
170
163
|
}
|
|
171
164
|
}
|
|
172
165
|
return { exportsChanges, includedDependenciesChanges, errors, warnings, pathsToEvaluate, pathsToRefresh };
|
|
173
166
|
}
|
|
167
|
+
function getMissingDepMessage(params) {
|
|
168
|
+
const { dependencyName, displayName, issueType, packagePath } = params;
|
|
169
|
+
let text;
|
|
170
|
+
if (isBuiltin(dependencyName)) {
|
|
171
|
+
text =
|
|
172
|
+
`The node built-in "${dependencyName}" is being imported by "${displayName}", ` +
|
|
173
|
+
`but no browser-friendly version was found in the package's dependencies. ` +
|
|
174
|
+
`This can be fixed by forcing "${displayName}" to use "bundlerType": "rollup" in package settings, ` +
|
|
175
|
+
`or by adding a polyfill browser-friendly dependency.`;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
text = `The package "${dependencyName}" is imported by "${displayName}", but ${issueType === 'not-found' ? "it couldn't be found" : "it's not included in the package's dependencies"}. Please ensure that "${dependencyName}" is listed in the dependencies of "${displayName}"${issueType === 'undeclared' ? ` or add it to "includedDependencies" for "${displayName}" in package settings.` : ''}.`;
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
text,
|
|
182
|
+
source: 'evaluate imports',
|
|
183
|
+
location: { file: path.join(packagePath, 'package.json') },
|
|
184
|
+
};
|
|
185
|
+
}
|
|
174
186
|
//# sourceMappingURL=evaluateImportsForOverrides.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateImportsForOverrides.js","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,OASjD;IAcC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IAEjG,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,GA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AAM,kBAAkB,CACzC;gBACE,OAAO,EAAE,wBAAwB,CAAC,OAAO;gBACzC,WAAW,EAAE,cAAc;gBAC3B,UAAU,EAAE,oBAAoB;aACjC,EACD,EAAE,QAAQ,EAAE,MAAM,EAAE,CACrB,CAAC;YAEF,IAAI,UAAU,EAAE,CAAC;gBACf,cAAc,CAAC,IAAI,CAAC;oBAClB,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE,oBAAoB,CAAC,OAAO,IAAI,EAAE;oBAC3C,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,cAAc;4BACpB,MAAM,EAAE,oBAAoB;4BAC5B,MAAM,EAAE,gBAAgB,WAAW,GAAG;yBACvC;qBACF;iBACF,CAAC,CAAC;gBAEH,2FAA2F;gBAC3F,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;YACrC,CAAC;iBAAM,CAAC;gBACN,MAAM,YAAY,GAAG,2IAA2I,IAAI,CAClK,cAAc,CACf,6DAA6D,YAAY,CACxE;oBACE,WAAW,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE;oBACpE,aAAa,WAAW,EAAE;oBAC1B,gBAAgB,cAAc,IAAI,OAAO,KAAK,oBAAoB,GAAG;iBACtE,EACD,CAAC,CACF,EAAE,CAAC;gBACJ,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAC5G,CAAC","sourcesContent":["import type { BundleInfo } from '@ms-cloudpack/api-server';\nimport type {\n CloudpackConfig,\n PackageDefinitionsCache,\n PackageImporterContext,\n PackageJson,\n PackageSettings,\n} from '@ms-cloudpack/common-types';\nimport { getPackageSettings } from '@ms-cloudpack/config';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n flattenExportsMap,\n getDependencies,\n getUnusedDependencies,\n getExportsMap,\n isExternalPackage,\n} from '@ms-cloudpack/package-utilities';\nimport { bulletedList, cyan } from '@ms-cloudpack/task-reporter';\nimport type { GeneratedPackageChanges } from './types/GeneratedPackageChanges.js';\nimport { isBuiltin } from 'module';\nimport { getConsumedPaths } from '@ms-cloudpack/api-server';\nimport { neverExclude } from './neverExclude.js';\n\n/**\n * Evaluate the imports depended on by a package to determine if missing exports map paths need to be added.\n * If so, updates package overrides in the config.\n */\nexport async function evaluateImportsForOverrides(options: {\n packages: PackageDefinitionsCache;\n info: BundleInfo;\n definition: PackageJson;\n packagePath: string;\n /** Config so far. This will be modified if new overrides are needed. */\n config: CloudpackConfig;\n resolveMap: ResolveMap;\n importerContext: PackageImporterContext | undefined;\n}): Promise<{\n /** Export changes made to the generated config */\n exportsChanges: GeneratedPackageChanges[];\n /** Included dependencies changes made to the generated config */\n includedDependenciesChanges: GeneratedPackageChanges[];\n /** Any errors encountered */\n errors: string[];\n /** Any warnings generated */\n warnings: string[];\n /** Map from new package path (to be evaluated) to info about the parent. */\n pathsToEvaluate: Map<string, PackageImporterContext | undefined>;\n /** Package paths for which new exports were added, so the package should be re-processed. */\n pathsToRefresh: Set<string>;\n}> {\n const { packages, info, definition, packagePath, config, resolveMap, importerContext } = options;\n\n const { name: packageName, version: packageVersion } = definition;\n const displayName = `${packageName}@${packageVersion}`;\n if (!packageName || !packageVersion) {\n throw new Error(`Package \"${displayName}\" is missing a name or version.`);\n }\n\n const exportsChanges: GeneratedPackageChanges[] = [];\n const includedDependenciesChanges: GeneratedPackageChanges[] = [];\n const errors = [];\n const warnings = [];\n const pathsToEvaluate = new Map<string, PackageImporterContext | undefined>();\n const pathsToRefresh = new Set<string>();\n const dependencies = getDependencies(definition);\n const unusedDependencies = getUnusedDependencies(definition);\n const consumedPaths = getConsumedPaths(info);\n\n // Iterate through imports and find their path from the resolve map.\n for (const [dependencyName, dependencyImportPaths] of Object.entries(consumedPaths)) {\n const resolveEntry = findResolveMapEntry({ definition, packageName: dependencyName, resolveMap });\n const dependencyPath = resolveEntry?.path;\n const dependencyDefinition = dependencyPath ? await packages.get(dependencyPath) : undefined;\n\n const message =\n `The package \"${dependencyName}\" couldn't be found, but it's being imported by the package \"${displayName}\". ` +\n `Please ensure that \"${dependencyName}\" is listed in the dependencies of \"${displayName}\".`;\n const messageBuiltin =\n `The node built-in \"${dependencyName}\" is being imported by the package \"${displayName}\", but no browser-friendly version was found in dependencies. ` +\n `This can be fixed by forcing the package \"${displayName}\" to use \"bundlerType\": \"rollup\" in package settings, or by adding a polyfill browser-friendly dependency.`;\n\n // If the dependency is not resolved, add an error.\n if (!dependencyPath || !dependencyDefinition) {\n isBuiltin(dependencyName) ? errors.push(messageBuiltin) : errors.push(message);\n // If the dependency is not resolved, we can't continue to evaluate it.\n continue;\n }\n\n // If the dependency is not listed as a dependency add to includedDependencies.\n if (!dependencies[dependencyName] && dependencyName !== definition.name && !neverExclude(dependencyName, config)) {\n // Survive from the case where it is not a dependency in the package.json\n // and it is resolvable, but warn the user.\n if (!unusedDependencies[dependencyName]) {\n isBuiltin(dependencyName) ? warnings.push(messageBuiltin) : warnings.push(message);\n }\n // Make sure to add the package to the list of packages to evaluate.\n pathsToEvaluate.set(packagePath, importerContext);\n\n // Add to includedDependencies\n const packageSettings = (config.generated.packageSettings ??= []);\n let generatedPackageSettings = getPackageSettings({\n config: { generated: { packageSettings } },\n name: packageName,\n version: packageVersion,\n firstMatch: true,\n }).generatedPackageSettings;\n\n if (!generatedPackageSettings) {\n if (isExternalPackage(packagePath)) {\n generatedPackageSettings = {\n match: { name: packageName, version: `^${packageVersion}` },\n };\n } else {\n generatedPackageSettings = {\n match: packageName,\n };\n }\n packageSettings.push(generatedPackageSettings);\n }\n\n generatedPackageSettings.includedDependencies ??= [];\n\n // Add to includedDependencies if it is not already included.\n if (generatedPackageSettings.includedDependencies.includes(dependencyName)) {\n continue;\n }\n\n generatedPackageSettings.includedDependencies.push(dependencyName);\n\n includedDependenciesChanges.push({\n name: packageName,\n version: packageVersion,\n path: packagePath,\n changes: [\n {\n type: 'included-dependency',\n change: dependencyName,\n reason: `Imported by \"${displayName}\"`,\n },\n ],\n });\n\n pathsToRefresh.add(packagePath);\n }\n\n const { name, version } = dependencyDefinition as Required<PackageJson>;\n if (!name || !version) {\n throw new Error(`Package \"${displayName}\" depends on \"${dependencyName}\" but it is missing a name or version.`);\n }\n\n let dependencyImporterContext: PackageImporterContext | undefined;\n const versionRequirement = dependencies[dependencyName];\n if (versionRequirement && definition.name && definition.version) {\n dependencyImporterContext = {\n parentName: definition.name,\n parentVersion: definition.version,\n importedName: dependencyName,\n versionRequirement,\n };\n }\n\n // Make sure to add the package to the list of packages to evaluate.\n pathsToEvaluate.set(dependencyPath, dependencyImporterContext);\n\n // Get the flattened bundle-able exports map for this dependency and iterate through our import paths to ensure nothing is missing.\n const exports = await getExportsMap({ packagePath: dependencyPath }, { packages, config });\n const flattenedExports = flattenExportsMap(exports);\n const packageSettings = (config.generated.packageSettings ??= []);\n let generatedPackageSettings: PackageSettings | undefined;\n // iterate through all the import paths.\n for (const dependencyImportPath of dependencyImportPaths) {\n if (flattenedExports[dependencyImportPath]) {\n continue;\n }\n\n // We are missing an import path. We need to add this entry to the exports map in package settings.\n generatedPackageSettings ??= getPackageSettings({\n config: { generated: { packageSettings } },\n name,\n version,\n firstMatch: true,\n }).generatedPackageSettings;\n\n if (!generatedPackageSettings) {\n if (isExternalPackage(dependencyPath)) {\n generatedPackageSettings = {\n match: { name, version: `^${version}` },\n exports: {},\n };\n } else {\n generatedPackageSettings = {\n match: name,\n exports: {},\n };\n }\n packageSettings.push(generatedPackageSettings);\n }\n\n generatedPackageSettings.exports ??= {};\n\n const addedEntry = await addExportsMapEntry(\n {\n exports: generatedPackageSettings.exports,\n packagePath: dependencyPath,\n importPath: dependencyImportPath,\n },\n { packages, config },\n );\n\n if (addedEntry) {\n exportsChanges.push({\n name: dependencyName,\n version: dependencyDefinition.version || '',\n path: dependencyPath,\n changes: [\n {\n type: 'added-export',\n change: dependencyImportPath,\n reason: `Imported by \"${displayName}\"`,\n },\n ],\n });\n\n // Since we've found a missing export, we need to re-enqueue the dependency for evaluation.\n pathsToRefresh.add(dependencyPath);\n } else {\n const errorMessage = `An import couldn't be resolved to a physical file. Check that the import refers to a file that's exported by the package or adjust the \"${cyan(\n dependencyName,\n )}\" package version to one that supports this import path.\\n${bulletedList(\n [\n `Import: ${cyan(dependencyImportPath.replace('.', dependencyName))}`,\n `Location: ${packagePath}`,\n `Resolved to: ${dependencyName}@${version} (${dependencyImportPath})`,\n ],\n 2,\n )}`;\n errors.push(errorMessage);\n }\n }\n }\n\n return { exportsChanges, includedDependenciesChanges, errors, warnings, pathsToEvaluate, pathsToRefresh };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evaluateImportsForOverrides.js","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAAC,OASjD;IAcC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,U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C;SAAM,CAAC;QACN,IAAI,GAAG,gBAAgB,cAAc,qBAAqB,WAAW,UACnE,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,iDACvD,yBAAyB,cAAc,uCAAuC,WAAW,IACvF,SAAS,KAAK,YAAY,CAAC,CAAC,CAAC,6CAA6C,WAAW,wBAAwB,CAAC,CAAC,CAAC,EAClH,GAAG,CAAC;IACN,CAAC;IAED,OAAO;QACL,IAAI;QACJ,MAAM,EAAE,kBAAkB;QAC1B,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,EAAE;KAC3D,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleInfo } from '@ms-cloudpack/api-server';\nimport type {\n BundleMessage,\n CloudpackConfig,\n PackageDefinitionsCache,\n PackageImporterContext,\n PackageJson,\n PackageSettings,\n} from '@ms-cloudpack/common-types';\nimport { getPackageSettings } from '@ms-cloudpack/config';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n flattenExportsMap,\n getDependencies,\n getUnusedDependencies,\n getExportsMap,\n isExternalPackage,\n} from '@ms-cloudpack/package-utilities';\nimport { bulletedList, cyan } from '@ms-cloudpack/task-reporter';\nimport type { GeneratedPackageChanges } from './types/GeneratedPackageChanges.js';\nimport { isBuiltin } from 'module';\nimport { getConsumedPaths } from '@ms-cloudpack/api-server';\nimport { neverExclude } from './neverExclude.js';\nimport path from 'path';\n\n/**\n * Evaluate the imports depended on by a package to determine if missing exports map paths need to be added.\n * If so, updates package overrides in the config.\n */\nexport async function evaluateImportsForOverrides(options: {\n packages: PackageDefinitionsCache;\n info: BundleInfo;\n definition: PackageJson;\n packagePath: string;\n /** Config so far. This will be modified if new overrides are needed. */\n config: CloudpackConfig;\n resolveMap: ResolveMap;\n importerContext: PackageImporterContext | undefined;\n}): Promise<{\n /** Export changes made to the generated config */\n exportsChanges: GeneratedPackageChanges[];\n /** Included dependencies changes made to the generated config */\n includedDependenciesChanges: GeneratedPackageChanges[];\n /** Any errors encountered */\n errors: BundleMessage[];\n /** Any warnings generated */\n warnings: BundleMessage[];\n /** Map from new package path (to be evaluated) to info about the parent. */\n pathsToEvaluate: Map<string, PackageImporterContext | undefined>;\n /** Package paths for which new exports were added, so the package should be re-processed. */\n pathsToRefresh: Set<string>;\n}> {\n const { packages, info, definition, packagePath, config, resolveMap, importerContext } = options;\n\n const { name: packageName, version: packageVersion } = definition;\n const displayName = `${packageName}@${packageVersion}`;\n if (!packageName || !packageVersion) {\n throw new Error(`Package \"${displayName}\" is missing a name or version.`);\n }\n\n const exportsChanges: GeneratedPackageChanges[] = [];\n const includedDependenciesChanges: GeneratedPackageChanges[] = [];\n const errors: BundleMessage[] = [];\n const warnings: BundleMessage[] = [];\n const pathsToEvaluate = new Map<string, PackageImporterContext | undefined>();\n const pathsToRefresh = new Set<string>();\n const dependencies = getDependencies(definition);\n const unusedDependencies = getUnusedDependencies(definition);\n const consumedPaths = getConsumedPaths(info);\n\n // Iterate through imports and find their path from the resolve map.\n for (const [dependencyName, dependencyImportPaths] of Object.entries(consumedPaths)) {\n const resolveEntry = findResolveMapEntry({ definition, packageName: dependencyName, resolveMap });\n const dependencyPath = resolveEntry?.path;\n const dependencyDefinition = dependencyPath ? await packages.get(dependencyPath) : undefined;\n\n // If the dependency is not resolved, add an error.\n if (!dependencyPath || !dependencyDefinition) {\n errors.push(getMissingDepMessage({ dependencyName, displayName, issueType: 'not-found', packagePath }));\n // If the dependency is not resolved, we can't continue to evaluate it.\n continue;\n }\n\n // If the dependency is not listed, add to includedDependencies.\n if (!dependencies[dependencyName] && dependencyName !== definition.name && !neverExclude(dependencyName, config)) {\n // Survive from the case where it is not a dependency in the package.json\n // and it is resolvable, but warn the user.\n if (!unusedDependencies[dependencyName]) {\n warnings.push(getMissingDepMessage({ dependencyName, displayName, issueType: 'undeclared', packagePath }));\n }\n // Make sure to add the package to the list of packages to evaluate.\n pathsToEvaluate.set(packagePath, importerContext);\n\n // Add to includedDependencies\n const packageSettings = (config.generated.packageSettings ??= []);\n let { generatedPackageSettings } = getPackageSettings({\n config: { generated: { packageSettings } },\n name: packageName,\n version: packageVersion,\n firstMatch: true,\n });\n\n if (!generatedPackageSettings) {\n generatedPackageSettings = {\n match: isExternalPackage(packagePath) ? { name: packageName, version: `^${packageVersion}` } : packageName,\n };\n packageSettings.push(generatedPackageSettings);\n }\n\n generatedPackageSettings.includedDependencies ??= [];\n\n // Add to includedDependencies if it is not already included.\n if (!generatedPackageSettings.includedDependencies.includes(dependencyName)) {\n generatedPackageSettings.includedDependencies.push(dependencyName);\n\n includedDependenciesChanges.push({\n name: packageName,\n version: packageVersion,\n path: packagePath,\n changes: [\n {\n type: 'included-dependency',\n change: dependencyName,\n reason: `Imported by \"${displayName}\"`,\n },\n ],\n });\n\n pathsToRefresh.add(packagePath);\n }\n }\n\n const { name, version } = dependencyDefinition as Required<PackageJson>;\n if (!name || !version) {\n throw new Error(`Package \"${displayName}\" depends on \"${dependencyName}\" but it is missing a name or version.`);\n }\n\n let dependencyImporterContext: PackageImporterContext | undefined;\n const versionRequirement = dependencies[dependencyName];\n if (versionRequirement && definition.name && definition.version) {\n dependencyImporterContext = {\n parentName: definition.name,\n parentVersion: definition.version,\n importedName: dependencyName,\n versionRequirement,\n };\n }\n\n // Make sure to add the package to the list of packages to evaluate.\n pathsToEvaluate.set(dependencyPath, dependencyImporterContext);\n\n // Get the flattened bundle-able exports map for this dependency and iterate through our import paths to ensure nothing is missing.\n const exports = await getExportsMap({ packagePath: dependencyPath }, { packages, config });\n const flattenedExports = flattenExportsMap(exports);\n const packageSettings = (config.generated.packageSettings ??= []);\n let generatedPackageSettings: PackageSettings | undefined;\n // iterate through all the import paths.\n for (const dependencyImportPath of dependencyImportPaths) {\n if (flattenedExports[dependencyImportPath]) {\n continue;\n }\n\n // We are missing an import path. We need to add this entry to the exports map in package settings.\n generatedPackageSettings ??= getPackageSettings({\n config: { generated: { packageSettings } },\n name,\n version,\n firstMatch: true,\n }).generatedPackageSettings;\n\n if (!generatedPackageSettings) {\n if (isExternalPackage(dependencyPath)) {\n generatedPackageSettings = {\n match: { name, version: `^${version}` },\n exports: {},\n };\n } else {\n generatedPackageSettings = {\n match: name,\n exports: {},\n };\n }\n packageSettings.push(generatedPackageSettings);\n }\n\n generatedPackageSettings.exports ??= {};\n\n const addedEntry = await addExportsMapEntry(\n {\n exports: generatedPackageSettings.exports,\n packagePath: dependencyPath,\n importPath: dependencyImportPath,\n },\n { packages, config },\n );\n\n if (addedEntry) {\n exportsChanges.push({\n name: dependencyName,\n version: dependencyDefinition.version || '',\n path: dependencyPath,\n changes: [\n {\n type: 'added-export',\n change: dependencyImportPath,\n reason: `Imported by \"${displayName}\"`,\n },\n ],\n });\n\n // Since we've found a missing export, we need to re-enqueue the dependency for evaluation.\n pathsToRefresh.add(dependencyPath);\n } else {\n const text =\n `An import couldn't be resolved to a physical file. ` +\n `Check that the import refers to a file that's exported by the package or adjust the \"${cyan(\n dependencyName,\n )}\" package version to one that supports this import path.\\n${bulletedList(\n [\n `Import: ${cyan(dependencyImportPath.replace('.', dependencyName))}`,\n `Resolved to: ${dependencyName}@${version} (${dependencyImportPath})`,\n ],\n 2,\n )}`;\n errors.push({\n text,\n source: 'evaluate imports',\n location: { file: packagePath },\n });\n }\n }\n }\n\n return { exportsChanges, includedDependenciesChanges, errors, warnings, pathsToEvaluate, pathsToRefresh };\n}\n\nfunction getMissingDepMessage(params: {\n dependencyName: string;\n displayName: string;\n issueType: 'not-found' | 'undeclared';\n packagePath: string;\n}): BundleMessage {\n const { dependencyName, displayName, issueType, packagePath } = params;\n\n let text: string;\n if (isBuiltin(dependencyName)) {\n text =\n `The node built-in \"${dependencyName}\" is being imported by \"${displayName}\", ` +\n `but no browser-friendly version was found in the package's dependencies. ` +\n `This can be fixed by forcing \"${displayName}\" to use \"bundlerType\": \"rollup\" in package settings, ` +\n `or by adding a polyfill browser-friendly dependency.`;\n } else {\n text = `The package \"${dependencyName}\" is imported by \"${displayName}\", but ${\n issueType === 'not-found' ? \"it couldn't be found\" : \"it's not included in the package's dependencies\"\n }. Please ensure that \"${dependencyName}\" is listed in the dependencies of \"${displayName}\"${\n issueType === 'undeclared' ? ` or add it to \"includedDependencies\" for \"${displayName}\" in package settings.` : ''\n }.`;\n }\n\n return {\n text,\n source: 'evaluate imports',\n location: { file: path.join(packagePath, 'package.json') },\n };\n}\n"]}
|
|
@@ -21,6 +21,8 @@ export declare function evaluatePath(options: {
|
|
|
21
21
|
initOptions: InitOptions;
|
|
22
22
|
summaryData: InitSummaryData;
|
|
23
23
|
ctx: EnsurePackageBundledContext;
|
|
24
|
+
/** The priority of the package being evaluated. To be used in the task runner. */
|
|
25
|
+
priority: number;
|
|
24
26
|
}): Promise<{
|
|
25
27
|
/** Map from new package path (to be evaluated) to info about the parent. */
|
|
26
28
|
pathsToEvaluate?: Map<string, PackageImporterContext | undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluatePath.d.ts","sourceRoot":"","sources":["../../../src/commands/init/evaluatePath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAM1D;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE;IAC1C,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,eAAe,EAAE,sBAAsB,G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GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC,CAuGD"}
|
|
@@ -7,7 +7,7 @@ import { optimizeDependencies } from './optimizeDependencies.js';
|
|
|
7
7
|
* in the generated config.
|
|
8
8
|
*/
|
|
9
9
|
export async function evaluatePath(options) {
|
|
10
|
-
const { packagePath, config, initOptions, telemetryClient, resolveMap, summaryData, ctx, importerContext } = options;
|
|
10
|
+
const { packagePath, config, initOptions, telemetryClient, resolveMap, summaryData, ctx, importerContext, priority } = options;
|
|
11
11
|
const { packages } = ctx;
|
|
12
12
|
const { features } = config;
|
|
13
13
|
// This line is the reason we have to track the importerContext for packages to evaluate:
|
|
@@ -27,6 +27,7 @@ export async function evaluatePath(options) {
|
|
|
27
27
|
isIncremental: false,
|
|
28
28
|
shouldGetBundleInfo: true,
|
|
29
29
|
useHashAsId: true,
|
|
30
|
+
priority,
|
|
30
31
|
},
|
|
31
32
|
ctx,
|
|
32
33
|
});
|
|
@@ -39,7 +40,7 @@ export async function evaluatePath(options) {
|
|
|
39
40
|
};
|
|
40
41
|
summaryData.recordResult({ packageResult: { ...resultIdentifier, errors, warnings, info } });
|
|
41
42
|
// If there were errors or no imports, return early.
|
|
42
|
-
if (errors?.length || !info
|
|
43
|
+
if (errors?.length || !info) {
|
|
43
44
|
return {};
|
|
44
45
|
}
|
|
45
46
|
// Given the package imports, find the missing exports maps and update packageOverrides.
|
|
@@ -54,10 +55,7 @@ export async function evaluatePath(options) {
|
|
|
54
55
|
});
|
|
55
56
|
if (evalErrors.length) {
|
|
56
57
|
summaryData.recordResult({
|
|
57
|
-
packageResult: {
|
|
58
|
-
...resultIdentifier,
|
|
59
|
-
errors: evalErrors.map((text) => ({ text, source: 'evaluate imports' })),
|
|
60
|
-
},
|
|
58
|
+
packageResult: { ...resultIdentifier, errors: evalErrors },
|
|
61
59
|
append: true,
|
|
62
60
|
});
|
|
63
61
|
}
|
|
@@ -68,16 +66,7 @@ export async function evaluatePath(options) {
|
|
|
68
66
|
// is both minimal (remove unused deps) and complete (include
|
|
69
67
|
// specific devDeps.)
|
|
70
68
|
if (features?.optimizeDependencies) {
|
|
71
|
-
const
|
|
72
|
-
if (excludedDependenciesWarnings.length) {
|
|
73
|
-
summaryData.recordResult({
|
|
74
|
-
packageResult: {
|
|
75
|
-
...resultIdentifier,
|
|
76
|
-
warnings: excludedDependenciesWarnings.map((text) => ({ text, source: 'optimize dependencies' })),
|
|
77
|
-
},
|
|
78
|
-
append: true,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
69
|
+
const excludedDependenciesChanges = optimizeDependencies({ definition, packagePath, info, resolveMap }, { packages, config });
|
|
81
70
|
summaryData.recordGeneratedChanges(excludedDependenciesChanges);
|
|
82
71
|
}
|
|
83
72
|
// Uncomment this when #1694 init does not cache packages correctly after editing config is fixed
|
|
@@ -86,7 +75,7 @@ export async function evaluatePath(options) {
|
|
|
86
75
|
// importPathsToRefresh?.forEach((path) => pathsToRefresh.add(path));
|
|
87
76
|
if (initOptions.check && (exportsChanges.length || evalErrors.length)) {
|
|
88
77
|
telemetryClient.rootSpan.addEvent('INIT_CHECK_FAILED', {
|
|
89
|
-
reason: exportsChanges ? 'Config needs to be updated.' : evalErrors,
|
|
78
|
+
reason: exportsChanges ? 'Config needs to be updated.' : evalErrors.map((e) => e.text),
|
|
90
79
|
});
|
|
91
80
|
return { shouldExit: true };
|
|
92
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluatePath.js","sourceRoot":"","sources":["../../../src/commands/init/evaluatePath.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAA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F,WAAW,CAAC,sBAAsB,CAAC,2BAA2B,CAAC,CAAC;IAClE,CAAC;IAED,iGAAiG;IACjG,6EAA6E;IAC7E,wFAAwF;IACxF,qEAAqE;IAErE,IAAI,WAAW,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACtE,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,EAAE;YACrD,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACvF,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;IAED,OAAO;QACL,eAAe;QACf,cAAc;KACf,CAAC;AACJ,CAAC","sourcesContent":["import type { EnsurePackageBundledContext } from '@ms-cloudpack/api-server';\nimport type { CloudpackConfig, PackageImporterContext } from '@ms-cloudpack/common-types';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { InitSummaryData } from './InitSummaryData.js';\nimport type { InitOptions } from './types/InitOptions.js';\n\nimport { ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport { evaluateImportsForOverrides } from './evaluateImportsForOverrides.js';\nimport { optimizeDependencies } from './optimizeDependencies.js';\n\n/**\n * A helper which given the packagePath, tries to evaluate the path by bundling things, finding imports,\n * and cross checking the imports with explicit exports. If any exports are missing, they are documented\n * in the generated config.\n */\nexport async function evaluatePath(options: {\n /** Path to evaluate. */\n packagePath: string;\n /** Info about how the parent package */\n importerContext: PackageImporterContext | undefined;\n /** Config so far. This will be modified if new overrides are needed. */\n config: CloudpackConfig;\n resolveMap: ResolveMap;\n telemetryClient: TelemetryClient;\n initOptions: InitOptions;\n summaryData: InitSummaryData;\n ctx: EnsurePackageBundledContext;\n /** The priority of the package being evaluated. To be used in the task runner. */\n priority: number;\n}): Promise<{\n /** Map from new package path (to be evaluated) to info about the parent. */\n pathsToEvaluate?: Map<string, PackageImporterContext | undefined>;\n /** Package paths for which new exports were added, so the package should be re-processed. */\n pathsToRefresh?: Set<string>;\n /** Whether a fatal error was encountered. */\n shouldExit?: boolean;\n}> {\n const { packagePath, config, initOptions, telemetryClient, resolveMap, summaryData, ctx, importerContext, priority } =\n options;\n const { packages } = ctx;\n const { features } = config;\n\n // This line is the reason we have to track the importerContext for packages to evaluate:\n // otherwise if a non-semver package is read here, we'd lose the modifications from the initial\n // time the package was read (and getNonSemverTransform was called) when building the resolve map.\n const definition = await packages.get(packagePath, { refresh: true, importerContext });\n const { name, version } = definition || {};\n\n if (!definition || !name || !version) {\n // Unsure why a package would be missing a definition/name/version - we've built the resolve map already.\n throw new Error(\n `${packagePath} evaluation failed because the package.json with a name/version was not found or not readable.`,\n );\n }\n\n // Bundle the package and find the imports it depends on.\n const { result } = await ensurePackageBundled({\n input: {\n name,\n version,\n isIncremental: false,\n shouldGetBundleInfo: true,\n useHashAsId: true,\n priority,\n },\n ctx,\n });\n\n const { errors, warnings, info } = result;\n\n // Record the results for the summary.\n const resultIdentifier = {\n name: definition.name || '',\n version: definition.version || '',\n path: packagePath,\n };\n\n summaryData.recordResult({ packageResult: { ...resultIdentifier, errors, warnings, info } });\n\n // If there were errors or no imports, return early.\n if (errors?.length || !info) {\n return {};\n }\n\n // Given the package imports, find the missing exports maps and update packageOverrides.\n const {\n exportsChanges,\n includedDependenciesChanges,\n errors: evalErrors,\n pathsToEvaluate,\n pathsToRefresh,\n } = await evaluateImportsForOverrides({\n definition,\n packagePath,\n packages,\n info,\n config,\n resolveMap,\n importerContext,\n });\n\n if (evalErrors.length) {\n summaryData.recordResult({\n packageResult: { ...resultIdentifier, errors: evalErrors },\n append: true,\n });\n }\n summaryData.recordGeneratedChanges(exportsChanges);\n summaryData.recordGeneratedChanges(includedDependenciesChanges);\n\n // Conditionally scan dependency usage so that we can populate\n // include/excludeDependencies automatically, ensuring the dep list\n // is both minimal (remove unused deps) and complete (include\n // specific devDeps.)\n if (features?.optimizeDependencies) {\n const excludedDependenciesChanges = optimizeDependencies(\n { definition, packagePath, info, resolveMap },\n { packages, config },\n );\n summaryData.recordGeneratedChanges(excludedDependenciesChanges);\n }\n\n // Uncomment this when #1694 init does not cache packages correctly after editing config is fixed\n // and the heap does not reach the limit as almost every package is enqueued.\n // importPathsToEvaluate?.forEach((path) => pathsToEvaluate.set(path, importerContext));\n // importPathsToRefresh?.forEach((path) => pathsToRefresh.add(path));\n\n if (initOptions.check && (exportsChanges.length || evalErrors.length)) {\n telemetryClient.rootSpan.addEvent('INIT_CHECK_FAILED', {\n reason: exportsChanges ? 'Config needs to be updated.' : evalErrors.map((e) => e.text),\n });\n\n return { shouldExit: true };\n }\n\n return {\n pathsToEvaluate,\n pathsToRefresh,\n };\n}\n"]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { InitOptions } from './types/InitOptions.js';
|
|
2
2
|
import type { InitSummary } from './types/InitSummary.js';
|
|
3
|
-
|
|
4
|
-
* Given an init summary and init options, returns a formatted string message to display to the user via console.
|
|
5
|
-
*/
|
|
6
|
-
export declare function formatInitSummary(params: {
|
|
3
|
+
interface FormatInitSummaryParams {
|
|
7
4
|
summaries: InitSummary[];
|
|
8
5
|
options: InitOptions;
|
|
9
6
|
isInterrupted?: boolean;
|
|
10
|
-
}
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Given init summaries and init options, returns a formatted string message to display to the user via console.
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatInitSummary(params: FormatInitSummaryParams): string;
|
|
12
|
+
export {};
|
|
11
13
|
//# sourceMappingURL=formatInitSummary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatInitSummary.d.ts","sourceRoot":"","sources":["../../../src/commands/init/formatInitSummary.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"formatInitSummary.d.ts","sourceRoot":"","sources":["../../../src/commands/init/formatInitSummary.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAG1D,UAAU,uBAAuB;IAC/B,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,OAAO,EAAE,WAAW,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,UAUhE"}
|
|
@@ -1,97 +1,117 @@
|
|
|
1
|
-
import { bold, bulletedList, cyan, green, lightCyan, plural, red,
|
|
2
|
-
import
|
|
1
|
+
import { bold, bulletedList, cyan, formatTime, green, indent, lightCyan, plural, red, statusCharacter, yellow, } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import { formatLocation } from '@ms-cloudpack/path-utilities';
|
|
3
3
|
/**
|
|
4
|
-
* Given
|
|
4
|
+
* Given init summaries and init options, returns a formatted string message to display to the user via console.
|
|
5
5
|
*/
|
|
6
6
|
export function formatInitSummary(params) {
|
|
7
7
|
const { summaries, options, isInterrupted } = params;
|
|
8
|
-
const summaryString = [];
|
|
9
8
|
const isMultiApp = summaries.length > 1;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
for (const packageWithWarnings of packagesWithWarnings) {
|
|
35
|
-
summaryString.push(`${yellow(`${statusCharacter.warn} ${currentCount++}.`)} ${formatPackageName(packageWithWarnings)} - ${yellow(plural(packageWithWarnings.warnings.length, 'warning'))}, ${packageWithWarnings.path}:`);
|
|
36
|
-
summaryString.push(formatBundleMessages(packageWithWarnings, false), '');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
// Report packages with errors.
|
|
41
|
-
if (packagesWithErrors.length) {
|
|
42
|
-
summaryString.push(`${plural(packagesWithErrors.length, 'package')} ${red('failed')}:\n`);
|
|
43
|
-
let currentCount = 1;
|
|
44
|
-
for (const packageWithErrors of packagesWithErrors) {
|
|
45
|
-
summaryString.push(`${red(`${statusCharacter.fail} ${currentCount++}.`)} ${formatPackageName(packageWithErrors)} - ${red(plural(packageWithErrors.errors.length, 'error'))}, ${packageWithErrors.path}:`);
|
|
46
|
-
summaryString.push(formatBundleMessages(packageWithErrors, true), '');
|
|
47
|
-
}
|
|
9
|
+
return (summaries
|
|
10
|
+
.map((summary) => formatSummary({ summary, options, isInterrupted, isMultiApp }))
|
|
11
|
+
.join('\n')
|
|
12
|
+
// replace >= 3 newlines with 2 newlines
|
|
13
|
+
.replace(/\n{3,}/g, '\n\n'));
|
|
14
|
+
}
|
|
15
|
+
/** Format a single app's init summary. */
|
|
16
|
+
function formatSummary(params) {
|
|
17
|
+
const { summary, options, isInterrupted, isMultiApp } = params;
|
|
18
|
+
const summaryString = [];
|
|
19
|
+
const { totalPackages, totalErrors, totalWarnings, totalChanges, totalRequiredChanges, packagesWithErrors, packagesWithWarnings, generatedFileUpdates, } = summary;
|
|
20
|
+
const { check } = options;
|
|
21
|
+
const incompleteText = isInterrupted ? bold(` (incomplete)`) : ``;
|
|
22
|
+
// Report the "Summary" title if no errors or warnings are listed (seems redundant otherwise.
|
|
23
|
+
if ((!packagesWithErrors.length && !packagesWithWarnings.length) || isMultiApp) {
|
|
24
|
+
summaryString.push(bold(`==== Summary for ${summary.appPath}${incompleteText} ====`));
|
|
25
|
+
}
|
|
26
|
+
if (!isMultiApp) {
|
|
27
|
+
// If there are required changes, updates will be "made" or "needed" with check,
|
|
28
|
+
// else if the changes are not required, only report work done when updates are "made" (check is disabled).
|
|
29
|
+
const updatesRequired = totalRequiredChanges || (totalChanges && !check);
|
|
30
|
+
// Report exports that were or should be added to the generated config.
|
|
31
|
+
if (!packagesWithErrors.length && updatesRequired) {
|
|
32
|
+
summaryString.push(formatAddedExports({ generatedFileUpdates, check }));
|
|
48
33
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
summaryString.push(`${cyan(plural(totalPackages, 'total package'))} evaluated in ${formatTime(summary.duration)}${incompleteText}:`, bulletedList([
|
|
53
|
-
requiresChanges ? `${red(plural(totalRequiredChanges, 'change'))} required` : undefined,
|
|
54
|
-
`${green(plural(totalPackages - blockingIssueCount, 'package'))} built successfully${packagesWithWarnings.length
|
|
55
|
-
? ` (${yellow(plural(packagesWithWarnings.length, 'package'))} with warnings)`
|
|
56
|
-
: ''}`,
|
|
57
|
-
blockingIssueCount ? `${red(plural(blockingIssueCount, 'package'))} failed to build` : undefined,
|
|
58
|
-
`Totals: ${totalErrors ? red(plural(totalErrors, 'error')) : '0 errors'}, ${totalWarnings ? yellow(plural(totalWarnings, 'warning')) : '0 warnings'}`,
|
|
59
|
-
].filter(Boolean)));
|
|
60
|
-
if (isInterrupted) {
|
|
61
|
-
summaryString.push('', yellow(bold('Process was interrupted before all tasks could complete.')));
|
|
34
|
+
// Report packages with warnings.
|
|
35
|
+
if (packagesWithWarnings.length) {
|
|
36
|
+
summaryString.push(formatPackageResults({ results: packagesWithWarnings, issueType: 'warnings' }), '');
|
|
62
37
|
}
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
}
|
|
39
|
+
// Report packages with errors.
|
|
40
|
+
if (packagesWithErrors.length) {
|
|
41
|
+
summaryString.push(formatPackageResults({ results: packagesWithErrors, issueType: 'errors' }), '');
|
|
42
|
+
}
|
|
43
|
+
const blockingIssueCount = packagesWithErrors.length || 0;
|
|
44
|
+
const requiresChanges = (check && totalRequiredChanges) || 0;
|
|
45
|
+
// Add summary.
|
|
46
|
+
summaryString.push(`${cyan(plural(totalPackages, 'total package'))} evaluated in ${formatTime(summary.duration)}${incompleteText}:`, bulletedList([
|
|
47
|
+
requiresChanges ? `${red(plural(totalRequiredChanges, 'change'))} required` : undefined,
|
|
48
|
+
`${green(plural(totalPackages - blockingIssueCount, 'package'))} built successfully${packagesWithWarnings.length
|
|
49
|
+
? ` (${yellow(plural(packagesWithWarnings.length, 'package'))} with warnings)`
|
|
50
|
+
: ''}`,
|
|
51
|
+
blockingIssueCount ? `${red(plural(blockingIssueCount, 'package'))} failed to build` : undefined,
|
|
52
|
+
`Totals: ${totalErrors ? red(plural(totalErrors, 'error')) : '0 errors'}, ${totalWarnings ? yellow(plural(totalWarnings, 'warning')) : '0 warnings'}`,
|
|
53
|
+
].filter(Boolean)));
|
|
54
|
+
if (isInterrupted) {
|
|
55
|
+
summaryString.push('', yellow(bold('Process was interrupted before all tasks could complete.')));
|
|
56
|
+
}
|
|
57
|
+
else if (requiresChanges) {
|
|
58
|
+
summaryString.push(`Run "${yellow('cloudpack init')}" in your application folder to apply changes to the ${cyan('cloudpack.generated.json')} file.`);
|
|
59
|
+
}
|
|
60
|
+
summaryString.push('\n');
|
|
61
|
+
return summaryString.join('\n');
|
|
62
|
+
}
|
|
63
|
+
function formatAddedExports(params) {
|
|
64
|
+
const { generatedFileUpdates, check, isInterrupted } = params;
|
|
65
|
+
const summaryString = [];
|
|
66
|
+
for (const packageUpdates of generatedFileUpdates) {
|
|
67
|
+
const exportsUpdates = packageUpdates.changes.filter((u) => u.type === 'added-export');
|
|
68
|
+
if (exportsUpdates.length) {
|
|
69
|
+
const description = plural(exportsUpdates.length, 'path$s missing from exports map');
|
|
70
|
+
summaryString.push(formatPackageHeader({ ...packageUpdates, isError: false, description }), bulletedList(exportsUpdates.map((u) => `${cyan(u.change)}${u.reason ? ` - ${u.reason}` : ''}`)), '');
|
|
65
71
|
}
|
|
66
|
-
summaryString.push('\n');
|
|
67
72
|
}
|
|
68
|
-
|
|
73
|
+
if (summaryString.length) {
|
|
74
|
+
summaryString.unshift(`Updates ${check || isInterrupted ? 'needed for' : 'made to'} ${cyan(`cloudpack.generated.json`)}:\n`);
|
|
75
|
+
}
|
|
76
|
+
return summaryString.join('\n');
|
|
69
77
|
}
|
|
70
|
-
/** Helper to format
|
|
71
|
-
function
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
/** Helper to format `packagesWithWarnings` or `packagesWithErrors`. */
|
|
79
|
+
function formatPackageResults(params) {
|
|
80
|
+
const { results, issueType } = params;
|
|
81
|
+
if (!results.length) {
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
const isError = issueType === 'errors';
|
|
85
|
+
const color = isError ? red : yellow;
|
|
86
|
+
const statusChar = bold(color(isError ? statusCharacter.error : statusCharacter.warn));
|
|
87
|
+
const summaryString = [bold(color(`${plural(results.length, 'package')} with ${issueType}:`)), ''];
|
|
88
|
+
for (const result of results) {
|
|
89
|
+
const unformattedMessages = result[issueType];
|
|
90
|
+
if (!unformattedMessages?.length) {
|
|
91
|
+
continue;
|
|
79
92
|
}
|
|
80
|
-
|
|
93
|
+
const description = plural(unformattedMessages.length, issueType.slice(0, -1) + '$s');
|
|
94
|
+
summaryString.push(formatPackageHeader({ ...result, isError, description }));
|
|
95
|
+
const messages = unformattedMessages.map(({ location, text, source }) => {
|
|
81
96
|
// Show the whole path so it can be easily opened with ctrl+click.
|
|
82
97
|
// NOTE: location.file should be relative to the package path, not the app path.
|
|
83
|
-
const filePath =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
98
|
+
const filePath = location ? ` ${formatLocation({ ...location, fromPath: result.path })}` : '';
|
|
99
|
+
// Indent the message for readability.
|
|
100
|
+
return `[${source}]${filePath}\n${color(indent(text, 1))}`;
|
|
101
|
+
});
|
|
102
|
+
summaryString.push(bulletedList(messages, undefined, statusChar), '');
|
|
89
103
|
}
|
|
90
|
-
return
|
|
104
|
+
return summaryString.join('\n');
|
|
91
105
|
}
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Helper to format the header for a list of issues in a package:
|
|
108
|
+
* status character, `name@version`, issue description, package path.
|
|
109
|
+
*/
|
|
110
|
+
function formatPackageHeader(params) {
|
|
111
|
+
const { name, version, path: packagePath, description, isError } = params;
|
|
112
|
+
const color = isError ? red : yellow;
|
|
113
|
+
const statusChar = bold(color(isError ? statusCharacter.error : statusCharacter.warn));
|
|
114
|
+
const packageName = bold(lightCyan(`${name}@${version || `<unknown>`}`));
|
|
115
|
+
return `${packageName} - ${packagePath}\n${statusChar} ${bold(color(description))}`;
|
|
96
116
|
}
|
|
97
117
|
//# sourceMappingURL=formatInitSummary.js.map
|