@ms-cloudpack/cli 0.72.85 → 0.72.87
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 +19 -15
- package/lib/commands/init/evaluateImportsForOverrides.d.ts.map +1 -1
- package/lib/commands/init/evaluateImportsForOverrides.js +7 -2
- package/lib/commands/init/evaluateImportsForOverrides.js.map +1 -1
- package/lib/commands/init/evaluatePath.d.ts +4 -24
- package/lib/commands/init/evaluatePath.d.ts.map +1 -1
- package/lib/commands/init/evaluatePath.js +6 -14
- package/lib/commands/init/evaluatePath.js.map +1 -1
- package/lib/commands/init/init.js +16 -23
- package/lib/commands/init/init.js.map +1 -1
- package/lib/commands/init/types/InitAppOptions.d.ts +16 -0
- package/lib/commands/init/types/InitAppOptions.d.ts.map +1 -0
- package/lib/commands/init/types/InitAppOptions.js +2 -0
- package/lib/commands/init/types/InitAppOptions.js.map +1 -0
- package/lib/commands/start/execute.js +3 -38
- package/lib/commands/start/execute.js.map +1 -1
- package/lib/utilities/createApiServer.d.ts +14 -0
- package/lib/utilities/createApiServer.d.ts.map +1 -0
- package/lib/utilities/createApiServer.js +39 -0
- package/lib/utilities/createApiServer.js.map +1 -0
- package/package.json +13 -13
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import type { BundleInfo } from '@ms-cloudpack/api-server';
|
|
2
|
-
import type { BundleMessage,
|
|
1
|
+
import type { BundleInfo, PartialContext } from '@ms-cloudpack/api-server';
|
|
2
|
+
import type { BundleMessage, PackageImporterContext, PackageJson } from '@ms-cloudpack/common-types';
|
|
3
3
|
import type { GeneratedPackageChanges } from './types/GeneratedPackageChanges.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
export declare function evaluateImportsForOverrides(options: {
|
|
9
|
-
packages: PackageDefinitionsCache;
|
|
4
|
+
export interface EvaluateImportsForOverridesOptions {
|
|
5
|
+
/** Path being evaluated */
|
|
6
|
+
packagePath: string;
|
|
7
|
+
/** Bundle result info for `packagePath` */
|
|
10
8
|
info: BundleInfo;
|
|
9
|
+
/** Package definition for `packagePath` */
|
|
11
10
|
definition: PackageJson;
|
|
12
|
-
packagePath
|
|
13
|
-
/** Config so far. This will be modified if new overrides are needed. */
|
|
14
|
-
config: CloudpackConfig;
|
|
15
|
-
resolveMap: ResolveMap;
|
|
11
|
+
/** Info about how the parent package imported `packagePath` (name and version used) */
|
|
16
12
|
importerContext: PackageImporterContext | undefined;
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
}
|
|
14
|
+
export type EvaluateImportsForOverridesContext = PartialContext<'packages', 'config' | 'resolveMap'>;
|
|
15
|
+
export interface EvaluateImportsForOverridesResult {
|
|
19
16
|
/** Export changes made to the generated config */
|
|
20
17
|
exportsChanges: GeneratedPackageChanges[];
|
|
21
18
|
/** Included dependencies changes made to the generated config */
|
|
@@ -28,5 +25,12 @@ export declare function evaluateImportsForOverrides(options: {
|
|
|
28
25
|
pathsToEvaluate: Map<string, PackageImporterContext | undefined>;
|
|
29
26
|
/** Package paths for which new exports were added, so the package should be re-processed. */
|
|
30
27
|
pathsToRefresh: Set<string>;
|
|
31
|
-
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Evaluate the imports depended on by a package to determine if missing exports map paths need to be added.
|
|
31
|
+
* If so, updates package overrides in the config.
|
|
32
|
+
*
|
|
33
|
+
* **Mutates `context.session.config.generated.packageSettings` and potentially `context.session.resolveMap`.**
|
|
34
|
+
*/
|
|
35
|
+
export declare function evaluateImportsForOverrides(options: EvaluateImportsForOverridesOptions, context: EvaluateImportsForOverridesContext): Promise<EvaluateImportsForOverridesResult>;
|
|
32
36
|
//# sourceMappingURL=evaluateImportsForOverrides.d.ts.map
|
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"evaluateImportsForOverrides.d.ts","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,KAAK,EACV,aAAa,EACb,sBAAsB,EACtB,WAAW,EAEZ,MAAM,4BAA4B,CAAC;AAepC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAMlF,MAAM,WAAW,kCAAkC;IACjD,2BAA2B;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,2CAA2C;IAC3C,IAAI,EAAE,UAAU,CAAC;IACjB,2CAA2C;IAC3C,UAAU,EAAE,WAAW,CAAC;IACxB,uFAAuF;IACvF,eAAe,EAAE,sBAAsB,GAAG,SAAS,CAAC;CACrD;AAED,MAAM,MAAM,kCAAkC,GAAG,cAAc,CAAC,UAAU,EAAE,QAAQ,GAAG,YAAY,CAAC,CAAC;AAErG,MAAM,WAAW,iCAAiC;IAChD,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;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,kCAAkC,EAC3C,OAAO,EAAE,kCAAkC,GAC1C,OAAO,CAAC,iCAAiC,CAAC,CAsR5C"}
|
|
@@ -8,9 +8,14 @@ import path from 'path';
|
|
|
8
8
|
/**
|
|
9
9
|
* Evaluate the imports depended on by a package to determine if missing exports map paths need to be added.
|
|
10
10
|
* If so, updates package overrides in the config.
|
|
11
|
+
*
|
|
12
|
+
* **Mutates `context.session.config.generated.packageSettings` and potentially `context.session.resolveMap`.**
|
|
11
13
|
*/
|
|
12
|
-
export async function evaluateImportsForOverrides(options) {
|
|
13
|
-
const {
|
|
14
|
+
export async function evaluateImportsForOverrides(options, context) {
|
|
15
|
+
const { info, definition, packagePath, importerContext } = options;
|
|
16
|
+
const { packages, session } = context;
|
|
17
|
+
const { config, resolveMap } = session;
|
|
18
|
+
const { appPath } = config;
|
|
14
19
|
const { name: packageName, version: packageVersion } = definition;
|
|
15
20
|
const displayName = `${packageName}@${packageVersion}`;
|
|
16
21
|
if (!packageName || !packageVersion) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateImportsForOverrides.js","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AAUA,OAAO,EACL,iCAAiC,EACjC,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,aAAa,GACd,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,OAUjD;IAcC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE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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 GeneratedPackageSettings,\n ResolveMap,\n} from '@ms-cloudpack/common-types';\nimport {\n ensureGeneratedSettingsForPackage,\n getGeneratedPackageSettings,\n getPackageSettings,\n} from '@ms-cloudpack/config';\nimport {\n addExportsMapEntry,\n ensureResolveMapEntry,\n flattenExportsMap,\n getDependencies,\n getUnusedDependencies,\n getExportsMap,\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 appPath: string;\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, appPath } = 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 // TODO: this line will return nothing due to https://github.com/microsoft/cloudpack/issues/2389, https://github.com/microsoft/cloudpack/issues/2391\n const unusedDependencies = getUnusedDependencies(definition);\n const consumedPaths = getConsumedPaths(info);\n const userExcludedDependencies = getPackageSettings({\n name: packageName,\n version: packageVersion,\n userPackageSettings: config.packageSettings,\n generatedPackageSettings: undefined,\n }).userPackageSettings?.excludedDependencies;\n\n let generatedPackageSettings: GeneratedPackageSettings | undefined;\n\n // Iterate through imports and find their path from the resolve map.\n for (const [dependencyName, dependencyImportPaths] of Object.entries(consumedPaths)) {\n // If the dependency is excluded in the user settings, entirely ignore it.\n if (userExcludedDependencies?.includes(dependencyName)) {\n continue;\n }\n\n // Check if we can resolve the dependency.\n // If we included or removed an excluded dependency, we need to ensure it is in the resolve map.\n // TODO: this is somewhat broken https://github.com/microsoft/cloudpack/issues/2390\n const { dependencyPath, updatedResolution } = await ensureResolveMapEntry(\n {\n definition,\n packagePath,\n dependencyName,\n resolveMap,\n appPath,\n },\n { packages },\n );\n\n // If the dependency is not resolved, add an error.\n if (!dependencyPath) {\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 const dependencyDefinition = await packages.get(dependencyPath);\n\n const { bundlerCapabilities } = dependencyDefinition.cloudpack || {};\n const dependencyResolveWebExtensions =\n // eslint-disable-next-line etc/no-deprecated\n bundlerCapabilities?.['resolve-web-extensions'] ?? Boolean(config.features?.resolveWebExtensions);\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 // TODO: this won't work as expected due to https://github.com/microsoft/cloudpack/issues/2391\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 if appropriate.\n generatedPackageSettings ??= await ensureGeneratedSettingsForPackage({ packagePath }, { config, packages });\n\n // We can skip including the dependency if it is already excluded.\n // This will be handled later during optimize dependencies.\n const handledByOptimize = generatedPackageSettings.excludedDependencies?.includes(dependencyName);\n\n // Add to includedDependencies if it is not already included.\n if (!handledByOptimize && !generatedPackageSettings.includedDependencies?.includes(dependencyName)) {\n generatedPackageSettings.includedDependencies ??= [];\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${updatedResolution ? '-required' : '-optional'}`,\n change: dependencyName,\n reason: `Imported by \"${displayName}\"`,\n },\n ],\n });\n }\n }\n\n const { version } = dependencyDefinition;\n\n // Ensure we use the correct context when evaluating this dependency.\n let dependencyImporterContext: PackageImporterContext | undefined;\n if (dependencyName === packageName) {\n // Self-import (we may still need to evaluate the paths). Use the importer context from options.\n dependencyImporterContext = importerContext;\n } else if (dependencies[dependencyName]) {\n dependencyImporterContext = {\n parentName: packageName,\n parentVersion: packageVersion,\n importedName: dependencyName,\n versionRequirement: dependencies[dependencyName],\n };\n }\n\n // Add the dependency to the list of packages to evaluate.\n pathsToEvaluate.set(dependencyPath, dependencyImporterContext);\n\n // A flattened, bundle-able exports map for this dependency, which is \"built up\" over the course of bundling.\n const workingDependencyExportsList = flattenExportsMap(\n await getExportsMap({ packagePath: dependencyPath }, { packages, config }),\n );\n // The official list of exports claimed by this dependency -- used to determine which exports are never used, so we can drop them.\n const canonicalDependencyExports = flattenExportsMap(\n await getExportsMap(\n { packagePath: dependencyPath, disableTransforms: true, resolveWebExtensions: dependencyResolveWebExtensions },\n { packages, config },\n ),\n );\n\n const initiallyNullExports = getGeneratedPackageSettings({\n name: dependencyName,\n version,\n // Use the generated snapshot to get the previous package settings.\n generatedPackageSettings: config.generatedSnapshot?.packageSettings,\n })?.exports;\n\n let dependencyGeneratedPackageSettings: GeneratedPackageSettings | undefined;\n // iterate through all the import paths.\n for (const dependencyImportPath of dependencyImportPaths) {\n // Imports from paths with trailing slashes are not supported in the exports map.\n if (dependencyImportPath.endsWith('/')) {\n errors.push({\n text: `The import path \"${dependencyImportPath}\" from \"${dependencyName}\" has a trailing slash, which is not supported.`,\n source: 'evaluate imports',\n location: { file: packagePath },\n });\n continue;\n }\n\n if (!config.features?.removeUnusedExports) {\n const dependencyAlreadyBundled = workingDependencyExportsList[dependencyImportPath];\n if (dependencyAlreadyBundled) {\n continue;\n }\n }\n\n if (!dependencyGeneratedPackageSettings) {\n // Start with the package's exports all set to null (indicating they are never imported)\n // If this changes, we'll update the generatedPackageSetting accordingly later.\n const nullifiedExports = config.features?.removeUnusedExports\n ? Object.fromEntries(Object.keys(canonicalDependencyExports).map((k) => [k, null]))\n : {};\n\n dependencyGeneratedPackageSettings = await ensureGeneratedSettingsForPackage(\n {\n packagePath: dependencyPath,\n defaultExportsMap: Object.keys(nullifiedExports).length > 0 ? nullifiedExports : undefined,\n },\n { config, packages },\n );\n }\n\n if (config.features?.removeUnusedExports) {\n const importHasCorrespondingExport = !!canonicalDependencyExports[dependencyImportPath];\n if (importHasCorrespondingExport) {\n // We're about to remove a null export. Before we do, check if it was initially null in\n // the generated config; if so, we need to track the change so that --check exits correctly\n if (dependencyImportPath in (initiallyNullExports || {})) {\n exportsChanges.push({\n name: dependencyName,\n version: dependencyDefinition.version,\n path: dependencyPath,\n changes: [\n {\n type: 'changed-export',\n change: dependencyImportPath,\n reason: `\"${dependencyImportPath}\" was previously an unused export; is now used.`,\n },\n ],\n });\n }\n\n // Since dependencyImportPath is used (and presently set to null),\n // and since we now know it has a corresponding export,\n // delete it from generatePackageSettings.exports so it doesn't get dropped from the bundle\n let deleteSucceeded = false;\n if (\n dependencyGeneratedPackageSettings.exports &&\n dependencyImportPath in dependencyGeneratedPackageSettings.exports\n ) {\n deleteSucceeded = true;\n delete dependencyGeneratedPackageSettings.exports[dependencyImportPath];\n }\n\n if (deleteSucceeded) {\n // If there was actually an export to delete, mark this path for re-evaluation.\n pathsToRefresh.add(dependencyPath);\n\n // Delete the entire exports key if it now has zero entries\n if (Object.keys(dependencyGeneratedPackageSettings.exports ?? {}).length === 0) {\n delete dependencyGeneratedPackageSettings.exports;\n }\n }\n continue;\n }\n }\n\n const dependencyAlreadyBundled = workingDependencyExportsList[dependencyImportPath];\n if (dependencyAlreadyBundled) {\n continue;\n }\n\n dependencyGeneratedPackageSettings.exports ??= {};\n\n const addedEntry = await addExportsMapEntry(\n {\n exports: dependencyGeneratedPackageSettings.exports,\n packagePath: dependencyPath,\n importPath: dependencyImportPath,\n resolveWebExtensions: dependencyResolveWebExtensions,\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 \"bundler\": \"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"]}
|
|
1
|
+
{"version":3,"file":"evaluateImportsForOverrides.js","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,iCAAiC,EACjC,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,aAAa,GACd,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,M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C;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, PartialContext } from '@ms-cloudpack/api-server';\nimport type {\n BundleMessage,\n PackageImporterContext,\n PackageJson,\n GeneratedPackageSettings,\n} from '@ms-cloudpack/common-types';\nimport {\n ensureGeneratedSettingsForPackage,\n getGeneratedPackageSettings,\n getPackageSettings,\n} from '@ms-cloudpack/config';\nimport {\n addExportsMapEntry,\n ensureResolveMapEntry,\n flattenExportsMap,\n getDependencies,\n getUnusedDependencies,\n getExportsMap,\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\nexport interface EvaluateImportsForOverridesOptions {\n /** Path being evaluated */\n packagePath: string;\n /** Bundle result info for `packagePath` */\n info: BundleInfo;\n /** Package definition for `packagePath` */\n definition: PackageJson;\n /** Info about how the parent package imported `packagePath` (name and version used) */\n importerContext: PackageImporterContext | undefined;\n}\n\nexport type EvaluateImportsForOverridesContext = PartialContext<'packages', 'config' | 'resolveMap'>;\n\nexport interface EvaluateImportsForOverridesResult {\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\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 *\n * **Mutates `context.session.config.generated.packageSettings` and potentially `context.session.resolveMap`.**\n */\nexport async function evaluateImportsForOverrides(\n options: EvaluateImportsForOverridesOptions,\n context: EvaluateImportsForOverridesContext,\n): Promise<EvaluateImportsForOverridesResult> {\n const { info, definition, packagePath, importerContext } = options;\n const { packages, session } = context;\n const { config, resolveMap } = session;\n const { appPath } = config;\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 // TODO: this line will return nothing due to https://github.com/microsoft/cloudpack/issues/2389, https://github.com/microsoft/cloudpack/issues/2391\n const unusedDependencies = getUnusedDependencies(definition);\n const consumedPaths = getConsumedPaths(info);\n const userExcludedDependencies = getPackageSettings({\n name: packageName,\n version: packageVersion,\n userPackageSettings: config.packageSettings,\n generatedPackageSettings: undefined,\n }).userPackageSettings?.excludedDependencies;\n\n let generatedPackageSettings: GeneratedPackageSettings | undefined;\n\n // Iterate through imports and find their path from the resolve map.\n for (const [dependencyName, dependencyImportPaths] of Object.entries(consumedPaths)) {\n // If the dependency is excluded in the user settings, entirely ignore it.\n if (userExcludedDependencies?.includes(dependencyName)) {\n continue;\n }\n\n // Check if we can resolve the dependency.\n // If we included or removed an excluded dependency, we need to ensure it is in the resolve map.\n // TODO: this is somewhat broken https://github.com/microsoft/cloudpack/issues/2390\n const { dependencyPath, updatedResolution } = await ensureResolveMapEntry(\n {\n definition,\n packagePath,\n dependencyName,\n resolveMap,\n appPath,\n },\n { packages },\n );\n\n // If the dependency is not resolved, add an error.\n if (!dependencyPath) {\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 const dependencyDefinition = await packages.get(dependencyPath);\n\n const { bundlerCapabilities } = dependencyDefinition.cloudpack || {};\n const dependencyResolveWebExtensions =\n // eslint-disable-next-line etc/no-deprecated\n bundlerCapabilities?.['resolve-web-extensions'] ?? Boolean(config.features?.resolveWebExtensions);\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 // TODO: this won't work as expected due to https://github.com/microsoft/cloudpack/issues/2391\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 if appropriate.\n generatedPackageSettings ??= await ensureGeneratedSettingsForPackage({ packagePath }, { config, packages });\n\n // We can skip including the dependency if it is already excluded.\n // This will be handled later during optimize dependencies.\n const handledByOptimize = generatedPackageSettings.excludedDependencies?.includes(dependencyName);\n\n // Add to includedDependencies if it is not already included.\n if (!handledByOptimize && !generatedPackageSettings.includedDependencies?.includes(dependencyName)) {\n generatedPackageSettings.includedDependencies ??= [];\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${updatedResolution ? '-required' : '-optional'}`,\n change: dependencyName,\n reason: `Imported by \"${displayName}\"`,\n },\n ],\n });\n }\n }\n\n const { version } = dependencyDefinition;\n\n // Ensure we use the correct context when evaluating this dependency.\n let dependencyImporterContext: PackageImporterContext | undefined;\n if (dependencyName === packageName) {\n // Self-import (we may still need to evaluate the paths). Use the importer context from options.\n dependencyImporterContext = importerContext;\n } else if (dependencies[dependencyName]) {\n dependencyImporterContext = {\n parentName: packageName,\n parentVersion: packageVersion,\n importedName: dependencyName,\n versionRequirement: dependencies[dependencyName],\n };\n }\n\n // Add the dependency to the list of packages to evaluate.\n pathsToEvaluate.set(dependencyPath, dependencyImporterContext);\n\n // A flattened, bundle-able exports map for this dependency, which is \"built up\" over the course of bundling.\n const workingDependencyExportsList = flattenExportsMap(\n await getExportsMap({ packagePath: dependencyPath }, { packages, config }),\n );\n // The official list of exports claimed by this dependency -- used to determine which exports are never used, so we can drop them.\n const canonicalDependencyExports = flattenExportsMap(\n await getExportsMap(\n { packagePath: dependencyPath, disableTransforms: true, resolveWebExtensions: dependencyResolveWebExtensions },\n { packages, config },\n ),\n );\n\n const initiallyNullExports = getGeneratedPackageSettings({\n name: dependencyName,\n version,\n // Use the generated snapshot to get the previous package settings.\n generatedPackageSettings: config.generatedSnapshot?.packageSettings,\n })?.exports;\n\n let dependencyGeneratedPackageSettings: GeneratedPackageSettings | undefined;\n // iterate through all the import paths.\n for (const dependencyImportPath of dependencyImportPaths) {\n // Imports from paths with trailing slashes are not supported in the exports map.\n if (dependencyImportPath.endsWith('/')) {\n errors.push({\n text: `The import path \"${dependencyImportPath}\" from \"${dependencyName}\" has a trailing slash, which is not supported.`,\n source: 'evaluate imports',\n location: { file: packagePath },\n });\n continue;\n }\n\n if (!config.features?.removeUnusedExports) {\n const dependencyAlreadyBundled = workingDependencyExportsList[dependencyImportPath];\n if (dependencyAlreadyBundled) {\n continue;\n }\n }\n\n if (!dependencyGeneratedPackageSettings) {\n // Start with the package's exports all set to null (indicating they are never imported)\n // If this changes, we'll update the generatedPackageSetting accordingly later.\n const nullifiedExports = config.features?.removeUnusedExports\n ? Object.fromEntries(Object.keys(canonicalDependencyExports).map((k) => [k, null]))\n : {};\n\n dependencyGeneratedPackageSettings = await ensureGeneratedSettingsForPackage(\n {\n packagePath: dependencyPath,\n defaultExportsMap: Object.keys(nullifiedExports).length > 0 ? nullifiedExports : undefined,\n },\n { config, packages },\n );\n }\n\n if (config.features?.removeUnusedExports) {\n const importHasCorrespondingExport = !!canonicalDependencyExports[dependencyImportPath];\n if (importHasCorrespondingExport) {\n // We're about to remove a null export. Before we do, check if it was initially null in\n // the generated config; if so, we need to track the change so that --check exits correctly\n if (dependencyImportPath in (initiallyNullExports || {})) {\n exportsChanges.push({\n name: dependencyName,\n version: dependencyDefinition.version,\n path: dependencyPath,\n changes: [\n {\n type: 'changed-export',\n change: dependencyImportPath,\n reason: `\"${dependencyImportPath}\" was previously an unused export; is now used.`,\n },\n ],\n });\n }\n\n // Since dependencyImportPath is used (and presently set to null),\n // and since we now know it has a corresponding export,\n // delete it from generatePackageSettings.exports so it doesn't get dropped from the bundle\n let deleteSucceeded = false;\n if (\n dependencyGeneratedPackageSettings.exports &&\n dependencyImportPath in dependencyGeneratedPackageSettings.exports\n ) {\n deleteSucceeded = true;\n delete dependencyGeneratedPackageSettings.exports[dependencyImportPath];\n }\n\n if (deleteSucceeded) {\n // If there was actually an export to delete, mark this path for re-evaluation.\n pathsToRefresh.add(dependencyPath);\n\n // Delete the entire exports key if it now has zero entries\n if (Object.keys(dependencyGeneratedPackageSettings.exports ?? {}).length === 0) {\n delete dependencyGeneratedPackageSettings.exports;\n }\n }\n continue;\n }\n }\n\n const dependencyAlreadyBundled = workingDependencyExportsList[dependencyImportPath];\n if (dependencyAlreadyBundled) {\n continue;\n }\n\n dependencyGeneratedPackageSettings.exports ??= {};\n\n const addedEntry = await addExportsMapEntry(\n {\n exports: dependencyGeneratedPackageSettings.exports,\n packagePath: dependencyPath,\n importPath: dependencyImportPath,\n resolveWebExtensions: dependencyResolveWebExtensions,\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 \"bundler\": \"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"]}
|
|
@@ -1,36 +1,16 @@
|
|
|
1
1
|
import type { EnsurePackageBundledContext } from '@ms-cloudpack/api-server';
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import type { InitSummaryData } from './InitSummaryData.js';
|
|
5
|
-
import type { InitOptions } from './types/InitOptions.js';
|
|
2
|
+
import { type EvaluateImportsForOverridesOptions, type EvaluateImportsForOverridesResult } from './evaluateImportsForOverrides.js';
|
|
3
|
+
import type { InitAppOptions } from './types/InitAppOptions.js';
|
|
6
4
|
/**
|
|
7
5
|
* A helper which given the packagePath, tries to evaluate the path by bundling things, finding imports,
|
|
8
6
|
* and cross checking the imports with explicit exports. If any exports are missing, they are documented
|
|
9
7
|
* in the generated config.
|
|
10
8
|
*/
|
|
11
|
-
export declare function evaluatePath(options: {
|
|
12
|
-
/** Path to evaluate. */
|
|
13
|
-
packagePath: string;
|
|
14
|
-
/** Info about how the parent package */
|
|
15
|
-
importerContext: PackageImporterContext | undefined;
|
|
16
|
-
/** Config so far. This will be modified if new overrides are needed. */
|
|
17
|
-
config: CloudpackConfig;
|
|
18
|
-
appPath: string;
|
|
19
|
-
resolveMap: ResolveMap;
|
|
20
|
-
span: Span;
|
|
21
|
-
initOptions: InitOptions;
|
|
22
|
-
summaryData: InitSummaryData;
|
|
23
|
-
ctx: EnsurePackageBundledContext;
|
|
24
|
-
/** Whether init is running in a multi-app scenario. */
|
|
25
|
-
isMultiApp: boolean;
|
|
9
|
+
export declare function evaluatePath(options: InitAppOptions & Pick<EvaluateImportsForOverridesOptions, 'packagePath' | 'importerContext'> & {
|
|
26
10
|
shouldForce: boolean;
|
|
27
11
|
/** The priority of the package being evaluated. To be used in the task runner. */
|
|
28
12
|
priority: number;
|
|
29
|
-
}): Promise<{
|
|
30
|
-
/** Map from new package path (to be evaluated) to info about the parent. */
|
|
31
|
-
pathsToEvaluate?: Map<string, PackageImporterContext | undefined>;
|
|
32
|
-
/** Package paths for which new exports were added, so the package should be re-processed. */
|
|
33
|
-
pathsToRefresh?: Set<string>;
|
|
13
|
+
}, ctx: EnsurePackageBundledContext): Promise<Partial<Pick<EvaluateImportsForOverridesResult, 'pathsToEvaluate' | 'pathsToRefresh'>> & {
|
|
34
14
|
/** Whether a fatal error was encountered. */
|
|
35
15
|
shouldExit?: boolean;
|
|
36
16
|
}>;
|
|
@@ -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;
|
|
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;AAI5E,OAAO,EAEL,KAAK,kCAAkC,EACvC,KAAK,iCAAiC,EACvC,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;;GAIG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,cAAc,GACrB,IAAI,CAAC,kCAAkC,EAAE,aAAa,GAAG,iBAAiB,CAAC,GAAG;IAC5E,WAAW,EAAE,OAAO,CAAC;IACrB,kFAAkF;IAClF,QAAQ,EAAE,MAAM,CAAC;CAClB,EACH,GAAG,EAAE,2BAA2B,GAC/B,OAAO,CACR,OAAO,CAAC,IAAI,CAAC,iCAAiC,EAAE,iBAAiB,GAAG,gBAAgB,CAAC,CAAC,GAAG;IACvF,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CACF,CA+FA"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { ensurePackageBundled } from '@ms-cloudpack/api-server';
|
|
2
|
-
import { evaluateImportsForOverrides } from './evaluateImportsForOverrides.js';
|
|
2
|
+
import { evaluateImportsForOverrides, } from './evaluateImportsForOverrides.js';
|
|
3
3
|
import { evaluateDynamicImports } from './evaluateDynamicImports.js';
|
|
4
4
|
/**
|
|
5
5
|
* A helper which given the packagePath, tries to evaluate the path by bundling things, finding imports,
|
|
6
6
|
* and cross checking the imports with explicit exports. If any exports are missing, they are documented
|
|
7
7
|
* in the generated config.
|
|
8
8
|
*/
|
|
9
|
-
export async function evaluatePath(options) {
|
|
10
|
-
const { packagePath,
|
|
11
|
-
const { packages } = ctx;
|
|
9
|
+
export async function evaluatePath(options, ctx) {
|
|
10
|
+
const { packagePath, initOptions, span, summaryData, importerContext, shouldForce, isMultiApp, priority } = options;
|
|
11
|
+
const { packages, session } = ctx;
|
|
12
|
+
const { config } = session;
|
|
12
13
|
const { features } = config;
|
|
13
14
|
// This line is the reason we have to track the importerContext for packages to evaluate:
|
|
14
15
|
// otherwise if a non-semver package is read here, we'd lose the modifications from the initial
|
|
@@ -36,16 +37,7 @@ export async function evaluatePath(options) {
|
|
|
36
37
|
return {};
|
|
37
38
|
}
|
|
38
39
|
// Given the package imports, find the missing exports maps and update packageOverrides.
|
|
39
|
-
const { exportsChanges, includedDependenciesChanges, errors: evalErrors, pathsToEvaluate, pathsToRefresh, } = await evaluateImportsForOverrides({
|
|
40
|
-
definition,
|
|
41
|
-
packagePath,
|
|
42
|
-
packages,
|
|
43
|
-
info,
|
|
44
|
-
config,
|
|
45
|
-
resolveMap,
|
|
46
|
-
importerContext,
|
|
47
|
-
appPath,
|
|
48
|
-
});
|
|
40
|
+
const { exportsChanges, includedDependenciesChanges, errors: evalErrors, pathsToEvaluate, pathsToRefresh, } = await evaluateImportsForOverrides({ definition, packagePath, info, importerContext }, ctx);
|
|
49
41
|
if (evalErrors.length) {
|
|
50
42
|
summaryData.addErrors(packagePath, evalErrors);
|
|
51
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluatePath.js","sourceRoot":"","sources":["../../../src/commands/init/evaluatePath.ts"],"names":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AC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAC7C,CAAC;QACD,2BAA2B,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1E,CAAC;IAED,iGAAiG;IACjG,6EAA6E;IAC7E,wFAAwF;IACxF,qEAAqE;IAErE,IAAI,WAAW,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,IAAI,qBAAqB,EAAE,MAAM,CAAC,EAAE,CAAC;QACvG,IAAI,CAAC,QAAQ,CAAC,mBAAmB,EAAE;YACjC,yFAAyF;YACzF,MAAM,EAAE,cAAc,IAAI,qBAAqB,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,4BAA4B;SAC/G,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 { GeneratedPackageChanges } from './types/GeneratedPackageChanges.js';\n\nimport { ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport {\n evaluateImportsForOverrides,\n type EvaluateImportsForOverridesOptions,\n type EvaluateImportsForOverridesResult,\n} from './evaluateImportsForOverrides.js';\nimport { evaluateDynamicImports } from './evaluateDynamicImports.js';\nimport type { InitAppOptions } from './types/InitAppOptions.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(\n options: InitAppOptions &\n Pick<EvaluateImportsForOverridesOptions, 'packagePath' | 'importerContext'> & {\n shouldForce: boolean;\n /** The priority of the package being evaluated. To be used in the task runner. */\n priority: number;\n },\n ctx: EnsurePackageBundledContext,\n): Promise<\n Partial<Pick<EvaluateImportsForOverridesResult, 'pathsToEvaluate' | 'pathsToRefresh'>> & {\n /** Whether a fatal error was encountered. */\n shouldExit?: boolean;\n }\n> {\n const { packagePath, initOptions, span, summaryData, importerContext, shouldForce, isMultiApp, priority } = options;\n const { packages, session } = ctx;\n const { config } = session;\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 console.debug(`Evaluating ${packagePath} with context ${JSON.stringify(importerContext)}`);\n\n // Bundle the package and find the imports it depends on.\n const { result } = await ensurePackageBundled(\n {\n name,\n version,\n isIncremental: false,\n shouldGetBundleInfo: true,\n shouldForce,\n shouldRerun: shouldForce,\n useHashAsId: isMultiApp,\n priority,\n disableCache: !initOptions.cache,\n },\n ctx,\n );\n\n // Record the results for the summary.\n summaryData.recordResult(packagePath, result);\n\n // If there were errors or no imports, return early.\n const { info } = result;\n if (result.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({ definition, packagePath, info, importerContext }, ctx);\n\n if (evalErrors.length) {\n summaryData.addErrors(packagePath, evalErrors);\n }\n summaryData.recordGeneratedChanges(exportsChanges);\n summaryData.recordGeneratedChanges(includedDependenciesChanges);\n\n let dynamicImportsChanges: undefined | GeneratedPackageChanges[] = undefined;\n if (features?.evaluateDynamicImports) {\n const evaluatedDynamicImports = await evaluateDynamicImports({\n definition,\n packagePath,\n info,\n config,\n packages,\n importerContext,\n });\n\n const { pathsToEvaluate: dynamicImportPathsToEvaluate, pathsToRefresh: dynamicImportPathsToRefresh } =\n evaluatedDynamicImports;\n dynamicImportsChanges = evaluatedDynamicImports.dynamicImportsChanges;\n\n summaryData.recordGeneratedChanges(dynamicImportsChanges);\n\n for (const [evalPath, evalContext] of dynamicImportPathsToEvaluate.entries()) {\n pathsToEvaluate.set(evalPath, evalContext);\n }\n dynamicImportPathsToRefresh.forEach((path) => pathsToRefresh.add(path));\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 || dynamicImportsChanges?.length)) {\n span.addEvent('INIT_CHECK_FAILED', {\n // Don't log the specific errors to telemetry, as they may contain sensitive information.\n reason: exportsChanges || dynamicImportsChanges ? 'Config needs to be updated.' : 'Errors found with imports.',\n });\n\n return { shouldExit: true };\n }\n\n return {\n pathsToEvaluate,\n pathsToRefresh,\n };\n}\n"]}
|
|
@@ -12,23 +12,23 @@ import { bulletedList } from '@ms-cloudpack/task-reporter';
|
|
|
12
12
|
* Init execution function.
|
|
13
13
|
*/
|
|
14
14
|
export async function init(params) {
|
|
15
|
-
const { options, summaryData, isMultiApp, config, telemetryClient } = params;
|
|
15
|
+
const { options: initOptions, summaryData, isMultiApp, config, telemetryClient } = params;
|
|
16
16
|
await telemetryClient.tracer.startActiveSpan('INIT_APP', async (span) => {
|
|
17
17
|
// Run prerequisites for the app.
|
|
18
18
|
await runPrerequisites(params);
|
|
19
19
|
// If --reset is specified, reset the generated config.
|
|
20
|
-
if (
|
|
20
|
+
if (initOptions.reset) {
|
|
21
21
|
config.generated = {};
|
|
22
22
|
}
|
|
23
|
-
const
|
|
24
|
-
await initApp({
|
|
23
|
+
const context = await createPartialApiContext(params);
|
|
24
|
+
await initApp({ span, summaryData, initOptions, isMultiApp }, context);
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
async function initApp(
|
|
28
|
-
const {
|
|
29
|
-
const {
|
|
27
|
+
async function initApp(options, context) {
|
|
28
|
+
const { initOptions, summaryData, span, isMultiApp } = options;
|
|
29
|
+
const { match } = initOptions;
|
|
30
|
+
const { config, resolveMap } = context.session;
|
|
30
31
|
const { appPath } = config;
|
|
31
|
-
const resolveMap = apiContext.session.resolveMap;
|
|
32
32
|
// Ensure config.generated.packageSettings is initialized.
|
|
33
33
|
config.generated.packageSettings ??= [];
|
|
34
34
|
let isExitingPrematurely = false;
|
|
@@ -38,9 +38,9 @@ async function initApp(params) {
|
|
|
38
38
|
const refreshPaths = new Set();
|
|
39
39
|
const priorityMap = new Map();
|
|
40
40
|
// Start with the app path or requested matches
|
|
41
|
-
const initialPaths =
|
|
41
|
+
const initialPaths = match ? getFilteredPackages(resolveMap, match) : [appPath];
|
|
42
42
|
if (!initialPaths.length) {
|
|
43
|
-
summaryData.addErrors(appPath, [{ text: `No packages found matching ${
|
|
43
|
+
summaryData.addErrors(appPath, [{ text: `No packages found matching ${match}`, source: 'init' }]);
|
|
44
44
|
resolve();
|
|
45
45
|
}
|
|
46
46
|
enqueuePaths(new Map(initialPaths.map((packagePath) => [packagePath, undefined])));
|
|
@@ -67,21 +67,14 @@ async function initApp(params) {
|
|
|
67
67
|
priorityMap.set(packagePath, priority - 1);
|
|
68
68
|
// Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.
|
|
69
69
|
evaluatePath({
|
|
70
|
-
|
|
70
|
+
...options,
|
|
71
71
|
packagePath,
|
|
72
72
|
importerContext,
|
|
73
|
-
config,
|
|
74
|
-
span,
|
|
75
|
-
resolveMap,
|
|
76
|
-
initOptions: options,
|
|
77
|
-
summaryData,
|
|
78
|
-
ctx: apiContext,
|
|
79
73
|
// No need to force if we're in a multi-app scenario
|
|
80
74
|
// as we'll re-evaluate packages if they are different since we use a different task id.
|
|
81
75
|
shouldForce: !isMultiApp && shouldForce,
|
|
82
|
-
isMultiApp,
|
|
83
76
|
priority,
|
|
84
|
-
})
|
|
77
|
+
}, context)
|
|
85
78
|
.then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {
|
|
86
79
|
pending--;
|
|
87
80
|
if (shouldExit) {
|
|
@@ -127,7 +120,7 @@ async function initApp(params) {
|
|
|
127
120
|
});
|
|
128
121
|
// Log the resolve map to a file if requested. Do this *after* the main init process in case
|
|
129
122
|
// any additional deps were discovered and added.
|
|
130
|
-
if (
|
|
123
|
+
if (initOptions.logResolveMap) {
|
|
131
124
|
console.log('\nWriting resolve map to `resolve-map.json`.');
|
|
132
125
|
await writeJson(path.join(appPath, 'resolve-map.json'), resolveMap);
|
|
133
126
|
}
|
|
@@ -141,11 +134,11 @@ async function initApp(params) {
|
|
|
141
134
|
// include/excludeDependencies automatically, ensuring the dep list
|
|
142
135
|
// is both minimal (remove unused deps) and complete (include
|
|
143
136
|
// specific devDeps.)
|
|
144
|
-
const excludedDependenciesChanges = await optimizeDependencies(summaryData.getResults(),
|
|
137
|
+
const excludedDependenciesChanges = await optimizeDependencies(summaryData.getResults(), context);
|
|
145
138
|
summaryData.recordGeneratedChanges(excludedDependenciesChanges);
|
|
146
139
|
}
|
|
147
140
|
if (config.features?.verifyExports) {
|
|
148
|
-
const packageResults = await verifyExports(summaryData.getResults(),
|
|
141
|
+
const packageResults = await verifyExports(summaryData.getResults(), context);
|
|
149
142
|
for (const [packagePath, errors] of Object.entries(packageResults)) {
|
|
150
143
|
summaryData.addErrors(packagePath, errors);
|
|
151
144
|
}
|
|
@@ -154,7 +147,7 @@ async function initApp(params) {
|
|
|
154
147
|
// The feature "removeUnusedExports" doesn't (yet) write summary changes, but we still
|
|
155
148
|
// want to write the generated config if that featureFlag is on.
|
|
156
149
|
const hasSummaryChanges = config.features?.removeUnusedExports || summaryData.hasChanges();
|
|
157
|
-
if (!
|
|
150
|
+
if (!initOptions.check && hasSummaryChanges) {
|
|
158
151
|
// Update the generated config: either write it if there are settings, or delete it if it
|
|
159
152
|
// previously existed but is no longer needed.
|
|
160
153
|
const generatedResult = await writeGeneratedConfig(config.generated, appPath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version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C,KAAK,IAAI,iBAAiB,EAAE,CAAC;QACxC,yFAAyF;QACzF,8CAA8C;QAC9C,MAAM,eAAe,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9E,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAClC,WAAW,CAAC,sBAAsB,GAAG,IAAI,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { EnsurePackageBundledContext } from '@ms-cloudpack/api-server';\nimport type { PackageImporterContext } from '@ms-cloudpack/common-types';\nimport type { InitOptions } from './types/InitOptions.js';\n\nimport { createPartialApiContext } from '@ms-cloudpack/api-server';\nimport { writeGeneratedConfig } from '@ms-cloudpack/config';\nimport type { InitSummaryData } from './InitSummaryData.js';\nimport { evaluatePath } from './evaluatePath.js';\nimport { verifyExports } from './verifyExports.js';\nimport type { AppCommandContext, CommandActionParams } from '../../types/CommandAction.js';\nimport path from 'path';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { getFilteredPackages } from '../../utilities/getFilteredPackages.js';\nimport { optimizeDependencies } from './optimizeDependencies.js';\nimport { bulletedList } from '@ms-cloudpack/task-reporter';\nimport type { Span } from '@ms-cloudpack/telemetry';\n\n/**\n * Init execution function.\n */\nexport async function init(\n params: Pick<CommandActionParams<InitOptions>, keyof AppCommandContext | 'options' | 'isMultiApp'> & {\n /**\n * App summary object, created ahead of time so that a partial summary can be generated\n * if the process is interrupted.\n */\n summaryData: InitSummaryData;\n },\n): Promise<void> {\n const { options, summaryData, isMultiApp, config, telemetryClient } = params;\n\n await telemetryClient.tracer.startActiveSpan('INIT_APP', async (span) => {\n // Run prerequisites for the app.\n await runPrerequisites(params);\n\n // If --reset is specified, reset the generated config.\n if (options.reset) {\n config.generated = {};\n }\n\n const apiContext = await createPartialApiContext(params);\n\n await initApp({ apiContext, span, summaryData, options, isMultiApp });\n });\n}\n\nasync function initApp(\n params: Pick<Parameters<typeof init>[0], 'summaryData' | 'isMultiApp' | 'options'> & {\n apiContext: EnsurePackageBundledContext;\n span: Span;\n },\n): Promise<void> {\n const { apiContext, options, summaryData, span, isMultiApp } = params;\n const { config } = apiContext.session;\n const { appPath } = config;\n\n const resolveMap = apiContext.session.resolveMap;\n\n // Ensure config.generated.packageSettings is initialized.\n config.generated.packageSettings ??= [];\n\n let isExitingPrematurely = false;\n\n await new Promise<void>((resolve) => {\n let pending = 0;\n const visitedSet = new Set<string>();\n const refreshPaths = new Set<string>();\n const priorityMap = new Map<string, number>();\n\n // Start with the app path or requested matches\n const initialPaths = options.match ? getFilteredPackages(resolveMap, options.match) : [appPath];\n if (!initialPaths.length) {\n summaryData.addErrors(appPath, [{ text: `No packages found matching ${options.match}`, source: 'init' }]);\n resolve();\n }\n\n enqueuePaths(new Map(initialPaths.map((packagePath) => [packagePath, undefined])));\n\n /**\n * Enqueue more paths.\n * @param newPaths Mapping from package path to importer context.\n */\n function enqueuePaths(newPaths: Map<string, PackageImporterContext | undefined>): void {\n if (isExitingPrematurely) {\n return;\n }\n\n // Iterate through the given paths.\n for (const [packagePath, importerContext] of newPaths) {\n if (visitedSet.has(packagePath)) {\n console.debug(`Skipping ${packagePath} as it has already been visited.`);\n continue;\n }\n\n visitedSet.add(packagePath);\n pending++;\n\n const shouldForce = refreshPaths.delete(packagePath);\n\n // Get the priority value for this package path, defaults to 0.\n const priority = priorityMap.get(packagePath) ?? 0;\n // Lower priority of this package path by 1.\n priorityMap.set(packagePath, priority - 1);\n\n // Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.\n evaluatePath({\n appPath,\n packagePath,\n importerContext,\n config,\n span,\n resolveMap,\n initOptions: options,\n summaryData,\n ctx: apiContext,\n // No need to force if we're in a multi-app scenario\n // as we'll re-evaluate packages if they are different since we use a different task id.\n shouldForce: !isMultiApp && shouldForce,\n isMultiApp,\n priority,\n })\n .then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {\n pending--;\n\n if (shouldExit) {\n isExitingPrematurely = true;\n } else if (pathsToEvaluate?.size) {\n // If there are packages that need to be rebuilt, delete them from the visited set to re-enqueue them\n // and add them to the refresh set so that on re-enqueuing we pass the `shouldRerun` flag through\n // on single app runs.\n pathsToRefresh?.forEach((refreshPath) => {\n refreshPaths.add(refreshPath);\n visitedSet.delete(refreshPath);\n });\n\n // Try to enqueue the new paths.\n console.debug(\n `Enqueuing paths found from ${packagePath}:\\n` +\n bulletedList(\n [...pathsToEvaluate].map(([newPath, newContext]) => `${newPath} ${JSON.stringify(newContext)}`),\n ),\n );\n enqueuePaths(pathsToEvaluate);\n }\n\n // If nothing is pending after this call, we're complete.\n if (!pending) {\n resolve();\n }\n })\n .catch((error: unknown) => {\n // Record the exception as an init error for the package.\n // This gives better context than a stack trace which could have come from any package.\n let prefix = 'evaluating package';\n if (importerContext) {\n prefix += ` (context: ${JSON.stringify(importerContext, null, 2).replace(/\\s+/g, ' ')})`;\n }\n summaryData.recordException({ packagePath, error, source: 'init', context: prefix });\n\n // Don't immediately stop evaluation, but don't enqueue more paths.\n isExitingPrematurely = true;\n });\n }\n }\n }).catch((error: unknown) => {\n // If there's an error thrown from some other part of the promise besides evaluatePath (not likely),\n // record it as an init error for the app instead of allowing it to propagate.\n // This allows the overall init summary and any other errors to be logged as usual.\n isExitingPrematurely = true;\n summaryData.recordException({ packagePath: appPath, error, source: 'init', context: 'running init' });\n });\n\n // Log the resolve map to a file if requested. Do this *after* the main init process in case\n // any additional deps were discovered and added.\n if (options.logResolveMap) {\n console.log('\\nWriting resolve map to `resolve-map.json`.');\n await writeJson(path.join(appPath, 'resolve-map.json'), resolveMap);\n }\n\n if (isExitingPrematurely) {\n span.setAttribute('isExitingPrematurely', true);\n } else {\n // Only do extra checks if there's not a major error already\n if (config.features?.optimizeDependencies) {\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 const excludedDependenciesChanges = await optimizeDependencies(summaryData.getResults(), apiContext);\n summaryData.recordGeneratedChanges(excludedDependenciesChanges);\n }\n\n if (config.features?.verifyExports) {\n const packageResults = await verifyExports(summaryData.getResults(), apiContext);\n for (const [packagePath, errors] of Object.entries(packageResults)) {\n summaryData.addErrors(packagePath, errors);\n }\n }\n }\n\n // The feature \"removeUnusedExports\" doesn't (yet) write summary changes, but we still\n // want to write the generated config if that featureFlag is on.\n const hasSummaryChanges = config.features?.removeUnusedExports || summaryData.hasChanges();\n\n if (!options.check && hasSummaryChanges) {\n // Update the generated config: either write it if there are settings, or delete it if it\n // previously existed but is no longer needed.\n const generatedResult = await writeGeneratedConfig(config.generated, appPath);\n if (generatedResult === 'deleted') {\n summaryData.deletedGeneratedConfig = true;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CACxB,MAMC;IAED,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,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AAC,WAAW,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;YAC9E,KAAK,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;gBACnE,WAAW,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IAED,sFAAsF;IACtF,gEAAgE;IAChE,MAAM,iBAAiB,GAAG,MAAM,CAAC,QAAQ,EAAE,mBAAmB,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC;IAE3F,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,iBAAiB,EAAE,CAAC;QAC5C,yFAAyF;QACzF,8CAA8C;QAC9C,MAAM,eAAe,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC9E,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAClC,WAAW,CAAC,sBAAsB,GAAG,IAAI,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import type { EnsurePackageBundledContext } from '@ms-cloudpack/api-server';\nimport type { PackageImporterContext } from '@ms-cloudpack/common-types';\nimport type { InitOptions } from './types/InitOptions.js';\n\nimport { createPartialApiContext } from '@ms-cloudpack/api-server';\nimport { writeGeneratedConfig } from '@ms-cloudpack/config';\nimport type { InitSummaryData } from './InitSummaryData.js';\nimport { evaluatePath } from './evaluatePath.js';\nimport { verifyExports } from './verifyExports.js';\nimport type { AppCommandContext, CommandActionParams } from '../../types/CommandAction.js';\nimport path from 'path';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { getFilteredPackages } from '../../utilities/getFilteredPackages.js';\nimport { optimizeDependencies } from './optimizeDependencies.js';\nimport { bulletedList } from '@ms-cloudpack/task-reporter';\nimport type { InitAppOptions } from './types/InitAppOptions.js';\n\n/**\n * Init execution function.\n */\nexport async function init(\n params: Pick<CommandActionParams<InitOptions>, keyof AppCommandContext | 'options' | 'isMultiApp'> & {\n /**\n * App summary object, created ahead of time so that a partial summary can be generated\n * if the process is interrupted.\n */\n summaryData: InitSummaryData;\n },\n): Promise<void> {\n const { options: initOptions, summaryData, isMultiApp, config, telemetryClient } = params;\n\n await telemetryClient.tracer.startActiveSpan('INIT_APP', async (span) => {\n // Run prerequisites for the app.\n await runPrerequisites(params);\n\n // If --reset is specified, reset the generated config.\n if (initOptions.reset) {\n config.generated = {};\n }\n\n const context = await createPartialApiContext(params);\n\n await initApp({ span, summaryData, initOptions, isMultiApp }, context);\n });\n}\n\nasync function initApp(options: InitAppOptions, context: EnsurePackageBundledContext): Promise<void> {\n const { initOptions, summaryData, span, isMultiApp } = options;\n const { match } = initOptions;\n const { config, resolveMap } = context.session;\n const { appPath } = config;\n\n // Ensure config.generated.packageSettings is initialized.\n config.generated.packageSettings ??= [];\n\n let isExitingPrematurely = false;\n\n await new Promise<void>((resolve) => {\n let pending = 0;\n const visitedSet = new Set<string>();\n const refreshPaths = new Set<string>();\n const priorityMap = new Map<string, number>();\n\n // Start with the app path or requested matches\n const initialPaths = match ? getFilteredPackages(resolveMap, match) : [appPath];\n if (!initialPaths.length) {\n summaryData.addErrors(appPath, [{ text: `No packages found matching ${match}`, source: 'init' }]);\n resolve();\n }\n\n enqueuePaths(new Map(initialPaths.map((packagePath) => [packagePath, undefined])));\n\n /**\n * Enqueue more paths.\n * @param newPaths Mapping from package path to importer context.\n */\n function enqueuePaths(newPaths: Map<string, PackageImporterContext | undefined>): void {\n if (isExitingPrematurely) {\n return;\n }\n\n // Iterate through the given paths.\n for (const [packagePath, importerContext] of newPaths) {\n if (visitedSet.has(packagePath)) {\n console.debug(`Skipping ${packagePath} as it has already been visited.`);\n continue;\n }\n\n visitedSet.add(packagePath);\n pending++;\n\n const shouldForce = refreshPaths.delete(packagePath);\n\n // Get the priority value for this package path, defaults to 0.\n const priority = priorityMap.get(packagePath) ?? 0;\n // Lower priority of this package path by 1.\n priorityMap.set(packagePath, priority - 1);\n\n // Evaluate this path, but don't await - when we're done, we'll re-enqueue newly discovered paths.\n evaluatePath(\n {\n ...options,\n packagePath,\n importerContext,\n // No need to force if we're in a multi-app scenario\n // as we'll re-evaluate packages if they are different since we use a different task id.\n shouldForce: !isMultiApp && shouldForce,\n priority,\n },\n context,\n )\n .then(({ pathsToEvaluate, pathsToRefresh, shouldExit }) => {\n pending--;\n\n if (shouldExit) {\n isExitingPrematurely = true;\n } else if (pathsToEvaluate?.size) {\n // If there are packages that need to be rebuilt, delete them from the visited set to re-enqueue them\n // and add them to the refresh set so that on re-enqueuing we pass the `shouldRerun` flag through\n // on single app runs.\n pathsToRefresh?.forEach((refreshPath) => {\n refreshPaths.add(refreshPath);\n visitedSet.delete(refreshPath);\n });\n\n // Try to enqueue the new paths.\n console.debug(\n `Enqueuing paths found from ${packagePath}:\\n` +\n bulletedList(\n [...pathsToEvaluate].map(([newPath, newContext]) => `${newPath} ${JSON.stringify(newContext)}`),\n ),\n );\n enqueuePaths(pathsToEvaluate);\n }\n\n // If nothing is pending after this call, we're complete.\n if (!pending) {\n resolve();\n }\n })\n .catch((error: unknown) => {\n // Record the exception as an init error for the package.\n // This gives better context than a stack trace which could have come from any package.\n let prefix = 'evaluating package';\n if (importerContext) {\n prefix += ` (context: ${JSON.stringify(importerContext, null, 2).replace(/\\s+/g, ' ')})`;\n }\n summaryData.recordException({ packagePath, error, source: 'init', context: prefix });\n\n // Don't immediately stop evaluation, but don't enqueue more paths.\n isExitingPrematurely = true;\n });\n }\n }\n }).catch((error: unknown) => {\n // If there's an error thrown from some other part of the promise besides evaluatePath (not likely),\n // record it as an init error for the app instead of allowing it to propagate.\n // This allows the overall init summary and any other errors to be logged as usual.\n isExitingPrematurely = true;\n summaryData.recordException({ packagePath: appPath, error, source: 'init', context: 'running init' });\n });\n\n // Log the resolve map to a file if requested. Do this *after* the main init process in case\n // any additional deps were discovered and added.\n if (initOptions.logResolveMap) {\n console.log('\\nWriting resolve map to `resolve-map.json`.');\n await writeJson(path.join(appPath, 'resolve-map.json'), resolveMap);\n }\n\n if (isExitingPrematurely) {\n span.setAttribute('isExitingPrematurely', true);\n } else {\n // Only do extra checks if there's not a major error already\n if (config.features?.optimizeDependencies) {\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 const excludedDependenciesChanges = await optimizeDependencies(summaryData.getResults(), context);\n summaryData.recordGeneratedChanges(excludedDependenciesChanges);\n }\n\n if (config.features?.verifyExports) {\n const packageResults = await verifyExports(summaryData.getResults(), context);\n for (const [packagePath, errors] of Object.entries(packageResults)) {\n summaryData.addErrors(packagePath, errors);\n }\n }\n }\n\n // The feature \"removeUnusedExports\" doesn't (yet) write summary changes, but we still\n // want to write the generated config if that featureFlag is on.\n const hasSummaryChanges = config.features?.removeUnusedExports || summaryData.hasChanges();\n\n if (!initOptions.check && hasSummaryChanges) {\n // Update the generated config: either write it if there are settings, or delete it if it\n // previously existed but is no longer needed.\n const generatedResult = await writeGeneratedConfig(config.generated, appPath);\n if (generatedResult === 'deleted') {\n summaryData.deletedGeneratedConfig = true;\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Span } from '@ms-cloudpack/telemetry';
|
|
2
|
+
import type { CommandActionParams } from '../../../types/CommandAction.js';
|
|
3
|
+
import type { InitSummaryData } from '../InitSummaryData.js';
|
|
4
|
+
import type { InitOptions } from './InitOptions.js';
|
|
5
|
+
export interface InitAppOptions extends Pick<CommandActionParams<object>, 'isMultiApp'> {
|
|
6
|
+
/** CLI options */
|
|
7
|
+
initOptions: InitOptions;
|
|
8
|
+
/**
|
|
9
|
+
* App summary object, created ahead of time so that a partial summary can be generated
|
|
10
|
+
* if the process is interrupted.
|
|
11
|
+
*/
|
|
12
|
+
summaryData: InitSummaryData;
|
|
13
|
+
/** Span for the INIT_APP operation. */
|
|
14
|
+
span: Span;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=InitAppOptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitAppOptions.d.ts","sourceRoot":"","sources":["../../../../src/commands/init/types/InitAppOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,YAAY,CAAC;IACrF,kBAAkB;IAClB,WAAW,EAAE,WAAW,CAAC;IAEzB;;;OAGG;IACH,WAAW,EAAE,eAAe,CAAC;IAE7B,uCAAuC;IACvC,IAAI,EAAE,IAAI,CAAC;CACZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InitAppOptions.js","sourceRoot":"","sources":["../../../../src/commands/init/types/InitAppOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { Span } from '@ms-cloudpack/telemetry';\nimport type { CommandActionParams } from '../../../types/CommandAction.js';\nimport type { InitSummaryData } from '../InitSummaryData.js';\nimport type { InitOptions } from './InitOptions.js';\n\nexport interface InitAppOptions extends Pick<CommandActionParams<object>, 'isMultiApp'> {\n /** CLI options */\n initOptions: InitOptions;\n\n /**\n * App summary object, created ahead of time so that a partial summary can be generated\n * if the process is interrupted.\n */\n summaryData: InitSummaryData;\n\n /** Span for the INIT_APP operation. */\n span: Span;\n}\n"]}
|
|
@@ -2,14 +2,14 @@ import { createApiContext, ensurePackageBundled } from '@ms-cloudpack/api-server
|
|
|
2
2
|
import { writeJson } from '@ms-cloudpack/json-utilities';
|
|
3
3
|
import { isExternalPackage, resolve } from '@ms-cloudpack/path-utilities';
|
|
4
4
|
import { makeUrl } from '@ms-cloudpack/path-string-parsing';
|
|
5
|
-
import {
|
|
5
|
+
import { yellow } from '@ms-cloudpack/task-reporter';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { fileURLToPath } from 'url';
|
|
8
8
|
import { runPrerequisites } from '../../utilities/runPrerequisites.js';
|
|
9
9
|
import { openBrowser } from './openBrowser.js';
|
|
10
10
|
import { trackSession } from './trackSession.js';
|
|
11
|
-
import { getCertificate } from '@ms-cloudpack/setup-utilities';
|
|
12
11
|
import { getCliStartTime } from '../../utilities/getCliStartTime.js';
|
|
12
|
+
import { createApiServer } from '../../utilities/createApiServer.js';
|
|
13
13
|
/**
|
|
14
14
|
* Defines the "start" verb entry point.
|
|
15
15
|
*/
|
|
@@ -44,7 +44,7 @@ export const execute = async (params) => {
|
|
|
44
44
|
await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);
|
|
45
45
|
}
|
|
46
46
|
// Start api server for tracking status and handling remote requests.
|
|
47
|
-
const apiServerResult = await createApiServer(options, apiContext);
|
|
47
|
+
const apiServerResult = await createApiServer({ port: options.apiServerPort }, apiContext);
|
|
48
48
|
if (apiServerResult.hasErrors) {
|
|
49
49
|
return apiServerResult;
|
|
50
50
|
}
|
|
@@ -108,40 +108,5 @@ export const execute = async (params) => {
|
|
|
108
108
|
});
|
|
109
109
|
return null; // the command should keep running
|
|
110
110
|
};
|
|
111
|
-
/**
|
|
112
|
-
* Create the API server, or return an error message if the server could not be created.
|
|
113
|
-
*/
|
|
114
|
-
async function createApiServer(options, apiContext) {
|
|
115
|
-
const { session } = apiContext;
|
|
116
|
-
const { config } = session;
|
|
117
|
-
const { server, appPath } = config;
|
|
118
|
-
// If a cert is needed, check that it exists.
|
|
119
|
-
if (server?.https === true && !(await getCertificate({ domain: server.domain, cwd: appPath }))) {
|
|
120
|
-
return {
|
|
121
|
-
hasErrors: true,
|
|
122
|
-
message: `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\n\n` +
|
|
123
|
-
`Run "${cyan(bold('cloudpack setup'))}" to create the required certificate and try start again.\n`,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
const { createCloudpackServer } = await import('@ms-cloudpack/api-server');
|
|
127
|
-
try {
|
|
128
|
-
const apiServer = await createCloudpackServer({ port: options.apiServerPort }, apiContext);
|
|
129
|
-
return { hasErrors: false, apiServer };
|
|
130
|
-
}
|
|
131
|
-
catch (err) {
|
|
132
|
-
let message;
|
|
133
|
-
if (err.code === 'EADDRNOTAVAIL' && server?.domain) {
|
|
134
|
-
const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];
|
|
135
|
-
message =
|
|
136
|
-
`The domain "${cyan(bold(primaryDomain))}" in cloudpack.config.json is not resolvable.\n\n` +
|
|
137
|
-
`Run "${cyan(bold('cloudpack setup'))}" to add the appropriate entries to your hosts file and ` +
|
|
138
|
-
`try start again.\n`;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
message = `Error creating API server: ${err.stack || err}`;
|
|
142
|
-
}
|
|
143
|
-
return { hasErrors: true, message };
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
111
|
// cspell:ignore Prereqs
|
|
147
112
|
//# sourceMappingURL=execute.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../src/commands/start/execute.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAsC,MAAM,0BAA0B,CAAC;AACtH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACjE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I,CAAC,aAAa,CAAC,CAAC,mDAAmD;oBAC3F,QAAQ,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,0DAA0D;oBAC/F,oBAAoB,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,8BAA+B,GAAa,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;QACxE,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACtC,CAAC;AACH,CAAC;AAED,wBAAwB","sourcesContent":["import { createApiContext, ensurePackageBundled, type CloudpackServer, type Context } from '@ms-cloudpack/api-server';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { isExternalPackage, resolve } from '@ms-cloudpack/path-utilities';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { cyan, yellow, bold } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { openBrowser } from './openBrowser.js';\nimport { trackSession } from './trackSession.js';\nimport type { StartOptions } from './types/StartOptions.js';\nimport { getCertificate } from '@ms-cloudpack/setup-utilities';\nimport { getCliStartTime } from '../../utilities/getCliStartTime.js';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async (params) => {\n const { appPath, config, options, autoDispose } = params;\n\n console.log('App path:', yellow(appPath));\n console.log('Bundle mode:', yellow(options.mode));\n\n await runPrerequisites(params);\n\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n let overlayPath = await resolve('@ms-cloudpack/overlay', currentDir);\n\n // If overlay is an internal package, resolve the overlay from the current package's linked node modules\n // to \"externalize\" it, so that we always use the bundled version of the overlay instead of the source.\n if (overlayPath && !isExternalPackage(overlayPath)) {\n const cliPath = await resolve('@ms-cloudpack/cli', currentDir);\n overlayPath = cliPath ? path.join(cliPath, 'node_modules', '@ms-cloudpack/overlay') : undefined;\n }\n\n const shouldUseRemoteCache = config.features?.enableCloudHosted || config.features?.enableRemoteCacheDownloads;\n const apiContext = autoDispose(\n await createApiContext({\n ...params,\n remoteCacheClientLoginMethod: shouldUseRemoteCache ? options.login : undefined,\n overlayPath,\n }),\n );\n const { packages, session, telemetryClient } = apiContext;\n\n // Increment the session version if caching is disabled.\n if (options.cache === false) {\n session.incrementSessionVersion();\n }\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n // Start api server for tracking status and handling remote requests.\n const apiServerResult = await createApiServer(options, apiContext);\n if (apiServerResult.hasErrors) {\n return apiServerResult;\n }\n const { apiServer } = apiServerResult;\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({ name: definition.name, version: definition.version }, apiContext);\n\n // Then start bundle and app servers for hosting the app.\n const { startServers } = await import('@ms-cloudpack/app-server');\n const servers = await startServers(\n {\n definition,\n bundleServerOptions: { disableCache: !options.cache, port: options.bundleServerPort },\n port: options.appServerPort,\n },\n apiContext,\n );\n\n // Save the session to active sessions.\n const sessionTracker = await trackSession(session);\n\n const cleanup = async () => {\n // Stop tracking the session.\n await sessionTracker.close();\n\n await Promise.all(\n Object.entries({ apiServer, ...servers }).map(async ([name, server]) => {\n if (!server) return;\n\n const desc = `${name} (${server.url})`;\n console.info(`Closing ${desc}`);\n try {\n await server.close();\n console.info(`Closed ${desc}`);\n } catch (err) {\n console.warn(`Error closing ${desc}:`, err);\n }\n }),\n );\n };\n\n autoDispose({ dispose: cleanup });\n\n const defaultUrl = makeUrl(config.server?.defaultPath || '', session.urls.appServer).href;\n\n // Log the time elapsed from when the CLI started until the browser is ready to be opened.\n await telemetryClient.tracer.startActiveSpan(\n 'TIME_TO_OPEN_BROWSER',\n { startTime: getCliStartTime(), attributes: { open: options.open } },\n () => {\n // Open the browser.\n if (options.open === false) {\n console.log('Please open the browser manually to:', defaultUrl);\n } else {\n let urlToOpen: string;\n if (typeof options.open === 'string') {\n // If the string doesn't start with http or https, pick a protocol based on config.server.https\n if (!options.open.startsWith('http://') && !options.open.startsWith('https://')) {\n urlToOpen = `${config.server?.https ? 'https' : 'http'}://${options.open}`;\n } else {\n urlToOpen = options.open;\n }\n } else {\n // Use the default path from the config with the first domain.\n urlToOpen = defaultUrl;\n }\n\n void openBrowser({ url: urlToOpen }, apiContext).catch((err: unknown) => {\n console.warn('Error opening browser:', (err as Error | undefined)?.stack || err);\n console.warn('Please open the browser manually to:', defaultUrl);\n });\n }\n },\n );\n\n return null; // the command should keep running\n};\n\n/**\n * Create the API server, or return an error message if the server could not be created.\n */\nasync function createApiServer(\n options: StartOptions,\n apiContext: Context,\n): Promise<{ hasErrors: false; apiServer: CloudpackServer } | { hasErrors: true; message: string }> {\n const { session } = apiContext;\n const { config } = session;\n const { server, appPath } = config;\n\n // If a cert is needed, check that it exists.\n if (server?.https === true && !(await getCertificate({ domain: server.domain, cwd: appPath }))) {\n return {\n hasErrors: true,\n message:\n `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to create the required certificate and try start again.\\n`,\n };\n }\n\n const { createCloudpackServer } = await import('@ms-cloudpack/api-server');\n\n try {\n const apiServer = await createCloudpackServer({ port: options.apiServerPort }, apiContext);\n return { hasErrors: false, apiServer };\n } catch (err) {\n let message: string;\n if ((err as { code: string }).code === 'EADDRNOTAVAIL' && server?.domain) {\n const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];\n message =\n `The domain \"${cyan(bold(primaryDomain))}\" in cloudpack.config.json is not resolvable.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to add the appropriate entries to your hosts file and ` +\n `try start again.\\n`;\n } else {\n message = `Error creating API server: ${(err as Error).stack || err}`;\n }\n return { hasErrors: true, message };\n }\n}\n\n// cspell:ignore Prereqs\n"]}
|
|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DAA8D;gBAC9D,SAAS,GAAG,UAAU,CAAC;YACzB,CAAC;YAED,KAAK,WAAW,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;gBACtE,OAAO,CAAC,IAAI,CAAC,wBAAwB,EAAG,GAAyB,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC;gBACjF,OAAO,CAAC,IAAI,CAAC,sCAAsC,EAAE,UAAU,CAAC,CAAC;YACnE,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CACF,CAAC;IAEF,OAAO,IAAI,CAAC,CAAC,kCAAkC;AACjD,CAAC,CAAC;AAEF,wBAAwB","sourcesContent":["import { createApiContext, ensurePackageBundled } from '@ms-cloudpack/api-server';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { isExternalPackage, resolve } from '@ms-cloudpack/path-utilities';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport { yellow } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { fileURLToPath } from 'url';\nimport type { CommandAction } from '../../types/CommandAction.js';\nimport { runPrerequisites } from '../../utilities/runPrerequisites.js';\nimport { openBrowser } from './openBrowser.js';\nimport { trackSession } from './trackSession.js';\nimport type { StartOptions } from './types/StartOptions.js';\nimport { getCliStartTime } from '../../utilities/getCliStartTime.js';\nimport { createApiServer } from '../../utilities/createApiServer.js';\n\n/**\n * Defines the \"start\" verb entry point.\n */\nexport const execute: CommandAction<StartOptions> = async (params) => {\n const { appPath, config, options, autoDispose } = params;\n\n console.log('App path:', yellow(appPath));\n console.log('Bundle mode:', yellow(options.mode));\n\n await runPrerequisites(params);\n\n const currentDir = path.dirname(fileURLToPath(import.meta.url));\n let overlayPath = await resolve('@ms-cloudpack/overlay', currentDir);\n\n // If overlay is an internal package, resolve the overlay from the current package's linked node modules\n // to \"externalize\" it, so that we always use the bundled version of the overlay instead of the source.\n if (overlayPath && !isExternalPackage(overlayPath)) {\n const cliPath = await resolve('@ms-cloudpack/cli', currentDir);\n overlayPath = cliPath ? path.join(cliPath, 'node_modules', '@ms-cloudpack/overlay') : undefined;\n }\n\n const shouldUseRemoteCache = config.features?.enableCloudHosted || config.features?.enableRemoteCacheDownloads;\n const apiContext = autoDispose(\n await createApiContext({\n ...params,\n remoteCacheClientLoginMethod: shouldUseRemoteCache ? options.login : undefined,\n overlayPath,\n }),\n );\n const { packages, session, telemetryClient } = apiContext;\n\n // Increment the session version if caching is disabled.\n if (options.cache === false) {\n session.incrementSessionVersion();\n }\n\n // Make sure the package has a valid definition.\n const definition = await packages.get(appPath);\n\n if (options.logResolveMap) {\n // Write the resolve map to disk.\n await writeJson(path.join(appPath, 'resolve-map.json'), session.resolveMap);\n }\n\n // Start api server for tracking status and handling remote requests.\n const apiServerResult = await createApiServer({ port: options.apiServerPort }, apiContext);\n if (apiServerResult.hasErrors) {\n return apiServerResult;\n }\n const { apiServer } = apiServerResult;\n\n // Kick off bundling app package as soon as api server is ready.\n void ensurePackageBundled({ name: definition.name, version: definition.version }, apiContext);\n\n // Then start bundle and app servers for hosting the app.\n const { startServers } = await import('@ms-cloudpack/app-server');\n const servers = await startServers(\n {\n definition,\n bundleServerOptions: { disableCache: !options.cache, port: options.bundleServerPort },\n port: options.appServerPort,\n },\n apiContext,\n );\n\n // Save the session to active sessions.\n const sessionTracker = await trackSession(session);\n\n const cleanup = async () => {\n // Stop tracking the session.\n await sessionTracker.close();\n\n await Promise.all(\n Object.entries({ apiServer, ...servers }).map(async ([name, server]) => {\n if (!server) return;\n\n const desc = `${name} (${server.url})`;\n console.info(`Closing ${desc}`);\n try {\n await server.close();\n console.info(`Closed ${desc}`);\n } catch (err) {\n console.warn(`Error closing ${desc}:`, err);\n }\n }),\n );\n };\n\n autoDispose({ dispose: cleanup });\n\n const defaultUrl = makeUrl(config.server?.defaultPath || '', session.urls.appServer).href;\n\n // Log the time elapsed from when the CLI started until the browser is ready to be opened.\n await telemetryClient.tracer.startActiveSpan(\n 'TIME_TO_OPEN_BROWSER',\n { startTime: getCliStartTime(), attributes: { open: options.open } },\n () => {\n // Open the browser.\n if (options.open === false) {\n console.log('Please open the browser manually to:', defaultUrl);\n } else {\n let urlToOpen: string;\n if (typeof options.open === 'string') {\n // If the string doesn't start with http or https, pick a protocol based on config.server.https\n if (!options.open.startsWith('http://') && !options.open.startsWith('https://')) {\n urlToOpen = `${config.server?.https ? 'https' : 'http'}://${options.open}`;\n } else {\n urlToOpen = options.open;\n }\n } else {\n // Use the default path from the config with the first domain.\n urlToOpen = defaultUrl;\n }\n\n void openBrowser({ url: urlToOpen }, apiContext).catch((err: unknown) => {\n console.warn('Error opening browser:', (err as Error | undefined)?.stack || err);\n console.warn('Please open the browser manually to:', defaultUrl);\n });\n }\n },\n );\n\n return null; // the command should keep running\n};\n\n// cspell:ignore Prereqs\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CloudpackServer, Context } from '@ms-cloudpack/api-server';
|
|
2
|
+
/**
|
|
3
|
+
* Create the API server, or return an error message if the server could not be created.
|
|
4
|
+
*/
|
|
5
|
+
export declare function createApiServer(options: {
|
|
6
|
+
port?: number | number[];
|
|
7
|
+
}, apiContext: Context): Promise<{
|
|
8
|
+
hasErrors: false;
|
|
9
|
+
apiServer: CloudpackServer;
|
|
10
|
+
} | {
|
|
11
|
+
hasErrors: true;
|
|
12
|
+
message: string;
|
|
13
|
+
}>;
|
|
14
|
+
//# sourceMappingURL=createApiServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createApiServer.d.ts","sourceRoot":"","sources":["../../src/utilities/createApiServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAIzE;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAA;CAAE,EACrC,UAAU,EAAE,OAAO,GAClB,OAAO,CAAC;IAAE,SAAS,EAAE,KAAK,CAAC;IAAC,SAAS,EAAE,eAAe,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAkClG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { cyan, bold } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import { getCertificate } from '@ms-cloudpack/setup-utilities';
|
|
3
|
+
/**
|
|
4
|
+
* Create the API server, or return an error message if the server could not be created.
|
|
5
|
+
*/
|
|
6
|
+
export async function createApiServer(options, apiContext) {
|
|
7
|
+
const { port } = options;
|
|
8
|
+
const { session } = apiContext;
|
|
9
|
+
const { config } = session;
|
|
10
|
+
const { server, appPath } = config;
|
|
11
|
+
// If a cert is needed, check that it exists.
|
|
12
|
+
if (server?.https === true && !(await getCertificate({ domain: server.domain, cwd: appPath }))) {
|
|
13
|
+
return {
|
|
14
|
+
hasErrors: true,
|
|
15
|
+
message: `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\n\n` +
|
|
16
|
+
`Run "${cyan(bold('cloudpack setup'))}" to create the required certificate and try start again.\n`,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const { createCloudpackServer } = await import('@ms-cloudpack/api-server');
|
|
20
|
+
try {
|
|
21
|
+
const apiServer = await createCloudpackServer({ port }, apiContext);
|
|
22
|
+
return { hasErrors: false, apiServer };
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
let message;
|
|
26
|
+
if (err.code === 'EADDRNOTAVAIL' && server?.domain) {
|
|
27
|
+
const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];
|
|
28
|
+
message =
|
|
29
|
+
`The domain "${cyan(bold(primaryDomain))}" in cloudpack.config.json is not resolvable.\n\n` +
|
|
30
|
+
`Run "${cyan(bold('cloudpack setup'))}" to add the appropriate entries to your hosts file and ` +
|
|
31
|
+
`try start again.\n`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
message = `Error creating API server: ${err.stack || err}`;
|
|
35
|
+
}
|
|
36
|
+
return { hasErrors: true, message };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=createApiServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createApiServer.js","sourceRoot":"","sources":["../../src/utilities/createApiServer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAAqC,EACrC,UAAmB;IAEnB,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzB,MAAM,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAC/B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAEnC,6CAA6C;IAC7C,IAAI,MAAM,EAAE,KAAK,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,cAAc,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;QAC/F,OAAO;YACL,SAAS,EAAE,IAAI;YACf,OAAO,EACL,gGAAgG;gBAChG,QAAQ,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,6DAA6D;SACrG,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,MAAM,qBAAqB,CAAC,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;QACpE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACzC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,OAAe,CAAC;QACpB,IAAK,GAAwB,CAAC,IAAI,KAAK,eAAe,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;YACzE,MAAM,aAAa,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1F,OAAO;gBACL,eAAe,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,mDAAmD;oBAC3F,QAAQ,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,0DAA0D;oBAC/F,oBAAoB,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,8BAA+B,GAAa,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;QACxE,CAAC;QACD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;IACtC,CAAC;AACH,CAAC","sourcesContent":["import type { CloudpackServer, Context } from '@ms-cloudpack/api-server';\nimport { cyan, bold } from '@ms-cloudpack/task-reporter';\nimport { getCertificate } from '@ms-cloudpack/setup-utilities';\n\n/**\n * Create the API server, or return an error message if the server could not be created.\n */\nexport async function createApiServer(\n options: { port?: number | number[] },\n apiContext: Context,\n): Promise<{ hasErrors: false; apiServer: CloudpackServer } | { hasErrors: true; message: string }> {\n const { port } = options;\n const { session } = apiContext;\n const { config } = session;\n const { server, appPath } = config;\n\n // If a cert is needed, check that it exists.\n if (server?.https === true && !(await getCertificate({ domain: server.domain, cwd: appPath }))) {\n return {\n hasErrors: true,\n message:\n `The local site is configured to use https in cloudpack.config.json, but is missing a cert.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to create the required certificate and try start again.\\n`,\n };\n }\n\n const { createCloudpackServer } = await import('@ms-cloudpack/api-server');\n\n try {\n const apiServer = await createCloudpackServer({ port }, apiContext);\n return { hasErrors: false, apiServer };\n } catch (err) {\n let message: string;\n if ((err as { code: string }).code === 'EADDRNOTAVAIL' && server?.domain) {\n const primaryDomain = (Array.isArray(server.domain) ? server.domain : [server.domain])[0];\n message =\n `The domain \"${cyan(bold(primaryDomain))}\" in cloudpack.config.json is not resolvable.\\n\\n` +\n `Run \"${cyan(bold('cloudpack setup'))}\" to add the appropriate entries to your hosts file and ` +\n `try start again.\\n`;\n } else {\n message = `Error creating API server: ${(err as Error).stack || err}`;\n }\n return { hasErrors: true, message };\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/cli",
|
|
3
|
-
"version": "0.72.
|
|
3
|
+
"version": "0.72.87",
|
|
4
4
|
"description": "The Cloudpack command line interface - a tool for managing fast inner and outer looping in web apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -10,21 +10,21 @@
|
|
|
10
10
|
"cloudpack": "./bin/cloudpack.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@ms-cloudpack/api-server": "^0.61.
|
|
14
|
-
"@ms-cloudpack/app-server": "^0.17.
|
|
15
|
-
"@ms-cloudpack/bundler": "^0.24.
|
|
16
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
17
|
-
"@ms-cloudpack/config": "^0.33.
|
|
13
|
+
"@ms-cloudpack/api-server": "^0.61.27",
|
|
14
|
+
"@ms-cloudpack/app-server": "^0.17.80",
|
|
15
|
+
"@ms-cloudpack/bundler": "^0.24.22",
|
|
16
|
+
"@ms-cloudpack/common-types": "^0.24.14",
|
|
17
|
+
"@ms-cloudpack/config": "^0.33.30",
|
|
18
18
|
"@ms-cloudpack/environment": "^0.1.1",
|
|
19
19
|
"@ms-cloudpack/json-utilities": "^0.1.10",
|
|
20
|
-
"@ms-cloudpack/overlay": "^0.17.
|
|
21
|
-
"@ms-cloudpack/package-utilities": "^12.2.
|
|
20
|
+
"@ms-cloudpack/overlay": "^0.17.160",
|
|
21
|
+
"@ms-cloudpack/package-utilities": "^12.2.2",
|
|
22
22
|
"@ms-cloudpack/path-string-parsing": "^1.2.7",
|
|
23
|
-
"@ms-cloudpack/path-utilities": "^3.0.
|
|
24
|
-
"@ms-cloudpack/remote-cache": "^0.11.
|
|
25
|
-
"@ms-cloudpack/setup-utilities": "^0.5.
|
|
23
|
+
"@ms-cloudpack/path-utilities": "^3.0.11",
|
|
24
|
+
"@ms-cloudpack/remote-cache": "^0.11.5",
|
|
25
|
+
"@ms-cloudpack/setup-utilities": "^0.5.21",
|
|
26
26
|
"@ms-cloudpack/task-reporter": "^0.16.1",
|
|
27
|
-
"@ms-cloudpack/telemetry": "^0.11.
|
|
27
|
+
"@ms-cloudpack/telemetry": "^0.11.9",
|
|
28
28
|
"@yarnpkg/lockfile": "^1.1.0",
|
|
29
29
|
"commander": "^13.0.0",
|
|
30
30
|
"cross-spawn": "^7.0.3",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"workspace-tools": "^0.38.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@ms-cloudpack/common-types": "^0.24.
|
|
40
|
+
"@ms-cloudpack/common-types": "^0.24.14",
|
|
41
41
|
"@ms-cloudpack/common-types-browser": "^0.5.5",
|
|
42
42
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
43
43
|
"@ms-cloudpack/scripts": "^0.0.1",
|