@ms-cloudpack/cli 0.39.7 → 0.39.9
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/bundleAndGetImports.d.ts +15 -0
- package/lib/commands/init/bundleAndGetImports.d.ts.map +1 -0
- package/lib/commands/init/{getImportsFromBundle.js → bundleAndGetImports.js} +14 -8
- package/lib/commands/init/bundleAndGetImports.js.map +1 -0
- package/lib/commands/init/evaluateImportsForOverrides.d.ts +1 -2
- package/lib/commands/init/evaluateImportsForOverrides.d.ts.map +1 -1
- package/lib/commands/init/evaluateImportsForOverrides.js +4 -2
- package/lib/commands/init/evaluateImportsForOverrides.js.map +1 -1
- package/lib/commands/init/findImports.d.ts +1 -1
- package/lib/commands/init/findImports.d.ts.map +1 -1
- package/lib/commands/init/findImports.js +40 -39
- package/lib/commands/init/findImports.js.map +1 -1
- package/lib/commands/init/index.d.ts.map +1 -1
- package/lib/commands/init/index.js +22 -10
- package/lib/commands/init/index.js.map +1 -1
- package/lib/commands/init/init.d.ts +3 -0
- package/lib/commands/init/init.d.ts.map +1 -1
- package/lib/commands/init/init.js +27 -16
- package/lib/commands/init/init.js.map +1 -1
- package/package.json +4 -4
- package/lib/commands/init/getImportsFromBundle.d.ts +0 -10
- package/lib/commands/init/getImportsFromBundle.d.ts.map +0 -1
- package/lib/commands/init/getImportsFromBundle.js.map +0 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PackageJson, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
2
|
+
/**
|
|
3
|
+
* Bundle the package and return the imports it depends on.
|
|
4
|
+
*/
|
|
5
|
+
export declare function bundleAndGetImports(options: {
|
|
6
|
+
packages: PackageDefinitionsCache;
|
|
7
|
+
packagePath: string;
|
|
8
|
+
definition: PackageJson;
|
|
9
|
+
}): Promise<{
|
|
10
|
+
hasWarnings: boolean;
|
|
11
|
+
hasErrors: boolean;
|
|
12
|
+
/** Map from package name to set of required relative paths */
|
|
13
|
+
imports?: Map<string, Set<string>>;
|
|
14
|
+
}>;
|
|
15
|
+
//# sourceMappingURL=bundleAndGetImports.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleAndGetImports.d.ts","sourceRoot":"","sources":["../../../src/commands/init/bundleAndGetImports.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAMxF;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE;IACjD,QAAQ,EAAE,uBAAuB,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,WAAW,CAAC;CACzB,GAAG,OAAO,CAAC;IACV,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;IACnB,8DAA8D;IAC9D,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;CACpC,CAAC,CAiED"}
|
|
@@ -5,15 +5,15 @@ import { findImports } from './findImports.js';
|
|
|
5
5
|
import { prepareOutputPath } from '../../common/prepareOutputPath.js';
|
|
6
6
|
import { reporter } from '../../reporter.js';
|
|
7
7
|
import { bundleTask } from '../../tasks/bundleTask.js';
|
|
8
|
-
import { bulletedList, formatPackageName } from '@ms-cloudpack/task-reporter';
|
|
8
|
+
import { bulletedList, formatPackageName, plural } from '@ms-cloudpack/task-reporter';
|
|
9
9
|
/**
|
|
10
10
|
* Bundle the package and return the imports it depends on.
|
|
11
11
|
*/
|
|
12
|
-
export async function
|
|
12
|
+
export async function bundleAndGetImports(options) {
|
|
13
13
|
const { packagePath, definition, packages } = options;
|
|
14
14
|
const { outputPath, isExternal } = await getBundleDetails(packagePath);
|
|
15
15
|
if (!isExternal && !definition.exports) {
|
|
16
|
-
console.
|
|
16
|
+
console.debug(`${path.join(packagePath, 'package.json')} does not have an "exports" field.`);
|
|
17
17
|
}
|
|
18
18
|
// Ensure outputPath exists and is empty.
|
|
19
19
|
await prepareOutputPath(outputPath);
|
|
@@ -23,8 +23,10 @@ export async function getImportsFromBundle(options) {
|
|
|
23
23
|
packages,
|
|
24
24
|
});
|
|
25
25
|
if (!Object.keys(entriesMap).length) {
|
|
26
|
-
console.warn(
|
|
27
|
-
|
|
26
|
+
console.warn(`${path.join(packagePath, 'package.json')} does not specify any entry points.`, isExternal
|
|
27
|
+
? ''
|
|
28
|
+
: 'If this package contains code imported by other packages, please consider adding an "exports" field.');
|
|
29
|
+
return { hasWarnings: true, hasErrors: false };
|
|
28
30
|
}
|
|
29
31
|
const bundleRequest = {
|
|
30
32
|
id: packagePath,
|
|
@@ -43,15 +45,19 @@ export async function getImportsFromBundle(options) {
|
|
|
43
45
|
const importCount = imports.size;
|
|
44
46
|
return {
|
|
45
47
|
status: 'complete',
|
|
46
|
-
message: importCount ? `Found ${importCount
|
|
48
|
+
message: importCount ? `Found ${plural(importCount, 'imported package')}` : undefined,
|
|
47
49
|
details: importCount ? `${bulletedList(getImportsList(imports))}` : undefined,
|
|
48
50
|
};
|
|
49
51
|
});
|
|
50
|
-
return
|
|
52
|
+
return {
|
|
53
|
+
hasWarnings: !!bundleRequest.result?.warnings?.length,
|
|
54
|
+
hasErrors: !!bundleRequest.result?.errors?.length,
|
|
55
|
+
imports,
|
|
56
|
+
};
|
|
51
57
|
}
|
|
52
58
|
function getImportsList(imports) {
|
|
53
59
|
return Array.from(imports.keys()).reduce((list, packageName) => {
|
|
54
60
|
return list.concat(Array.from(imports.get(packageName) || []).map((importPath) => `${packageName}${importPath === '.' ? '' : `/${importPath}`}`));
|
|
55
61
|
}, []);
|
|
56
62
|
}
|
|
57
|
-
//# sourceMappingURL=
|
|
63
|
+
//# sourceMappingURL=bundleAndGetImports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundleAndGetImports.js","sourceRoot":"","sources":["../../../src/commands/init/bundleAndGetImports.ts"],"names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M,EAAE,QAAQ,EAAE,MAAM;QACrD,SAAS,EAAE,CAAC,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM;QACjD,OAAO;KACR,CAAC;AACJ,CAAC;AAED,SAAS,cAAc,CAAC,OAAiC;IACvD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE;QAC7D,OAAO,IAAI,CAAC,MAAM,CAChB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAC5C,CAAC,UAAU,EAAE,EAAE,CAAC,GAAG,WAAW,GAAG,UAAU,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,EAAE,CAC9E,CACF,CAAC;IACJ,CAAC,EAAE,EAAc,CAAC,CAAC;AACrB,CAAC","sourcesContent":["import path from 'path';\nimport { getEntriesMapFromPackage } from '@ms-cloudpack/bundler';\nimport { getBundleDetails } from '../../common/getBundleDetails.js';\nimport { findImports } from './findImports.js';\nimport { prepareOutputPath } from '../../common/prepareOutputPath.js';\nimport type { PackageJson, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { reporter } from '../../reporter.js';\nimport type { BundleRequest } from '../../types/BundleRequest.js';\nimport { bundleTask } from '../../tasks/bundleTask.js';\nimport { bulletedList, formatPackageName, plural } from '@ms-cloudpack/task-reporter';\n\n/**\n * Bundle the package and return the imports it depends on.\n */\nexport async function bundleAndGetImports(options: {\n packages: PackageDefinitionsCache;\n packagePath: string;\n definition: PackageJson;\n}): Promise<{\n hasWarnings: boolean;\n hasErrors: boolean;\n /** Map from package name to set of required relative paths */\n imports?: Map<string, Set<string>>;\n}> {\n const { packagePath, definition, packages } = options;\n const { outputPath, isExternal } = await getBundleDetails(packagePath);\n\n if (!isExternal && !definition.exports) {\n console.debug(`${path.join(packagePath, 'package.json')} does not have an \"exports\" field.`);\n }\n\n // Ensure outputPath exists and is empty.\n await prepareOutputPath(outputPath);\n\n // Determine entries.\n const entriesMap = await getEntriesMapFromPackage({\n inputPath: packagePath,\n packages,\n });\n\n if (!Object.keys(entriesMap).length) {\n console.warn(\n `${path.join(packagePath, 'package.json')} does not specify any entry points.`,\n isExternal\n ? ''\n : 'If this package contains code imported by other packages, please consider adding an \"exports\" field.',\n );\n return { hasWarnings: true, hasErrors: false };\n }\n\n const bundleRequest: BundleRequest = {\n id: packagePath,\n packageName: definition.name || '',\n version: definition.version || '',\n packagePath,\n outputPath,\n isExternal,\n packages,\n };\n\n await bundleTask({ bundleRequest, options: { force: true } });\n\n // For each outputFile, find all imports.\n let imports: Map<string, Set<string>> | undefined;\n\n await reporter.runTask(`Evaluate ${formatPackageName(definition)}`, async () => {\n imports = new Map(\n Object.entries(\n (await findImports(\n bundleRequest.result?.outputFiles?.map((file) => path.resolve(outputPath, file.outputPath)) || [],\n )) || {},\n ),\n );\n\n const importCount = imports.size;\n\n return {\n status: 'complete',\n message: importCount ? `Found ${plural(importCount, 'imported package')}` : undefined,\n details: importCount ? `${bulletedList(getImportsList(imports))}` : undefined,\n };\n });\n\n return {\n hasWarnings: !!bundleRequest.result?.warnings?.length,\n hasErrors: !!bundleRequest.result?.errors?.length,\n imports,\n };\n}\n\nfunction getImportsList(imports: Map<string, Set<string>>): string[] {\n return Array.from(imports.keys()).reduce((list, packageName) => {\n return list.concat(\n Array.from(imports.get(packageName) || []).map(\n (importPath) => `${packageName}${importPath === '.' ? '' : `/${importPath}`}`,\n ),\n );\n }, [] as string[]);\n}\n"]}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { PackageJson, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
2
|
-
import type { ResolveMap } from '@ms-cloudpack/package-utilities';
|
|
3
2
|
import type { PackageOverride } from '@ms-cloudpack/config';
|
|
3
|
+
import type { ResolveMap } from '@ms-cloudpack/package-utilities';
|
|
4
4
|
/**
|
|
5
5
|
* Evaluate the imports depended on by a package to determine if missing exports map paths need to be added.
|
|
6
6
|
* If so, updates package overrides to the given packageOverrides array.
|
|
7
7
|
*/
|
|
8
8
|
export declare function evaluateImportsForOverrides(options: {
|
|
9
9
|
packages: PackageDefinitionsCache;
|
|
10
|
-
packagePath: string;
|
|
11
10
|
imports: Map<string, Set<string>>;
|
|
12
11
|
definition: PackageJson;
|
|
13
12
|
packageOverrides: PackageOverride[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateImportsForOverrides.d.ts","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluateImportsForOverrides.d.ts","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACxF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAQ5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGlE;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,OAAO,EAAE;IACzD,QAAQ,EAAE,uBAAuB,CAAC;IAClC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAClC,UAAU,EAAE,WAAW,CAAC;IACxB,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACpC,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/B,UAAU,EAAE,UAAU,CAAC;CACxB,GAAG,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAsErD"}
|
|
@@ -13,7 +13,8 @@ export async function evaluateImportsForOverrides(options) {
|
|
|
13
13
|
for (const [dependencyName, dependencyImportPaths] of imports.entries()) {
|
|
14
14
|
const resolveEntry = findResolveMapEntry({ definition, packageName: dependencyName, resolveMap });
|
|
15
15
|
if (!resolveEntry) {
|
|
16
|
-
const errorMessage = `Package "${displayName}" depends on "${dependencyName}" but it was not found in the resolve map.
|
|
16
|
+
const errorMessage = `Package "${displayName}" depends on "${dependencyName}" but it was not found in the resolve map. ` +
|
|
17
|
+
`Ensure that "${dependencyName}" is listed in dependencies of "${displayName}".`;
|
|
17
18
|
console.error(errorMessage);
|
|
18
19
|
errors.push(errorMessage);
|
|
19
20
|
continue;
|
|
@@ -21,7 +22,8 @@ export async function evaluateImportsForOverrides(options) {
|
|
|
21
22
|
// Load the dependency definition.
|
|
22
23
|
const dependencyDefinition = await packages.get(resolveEntry.path);
|
|
23
24
|
if (!dependencyDefinition) {
|
|
24
|
-
const errorMessage = `Package "${displayName}" depends on "${dependencyName}" at "${resolveEntry.path}"
|
|
25
|
+
const errorMessage = `Package "${displayName}" depends on "${dependencyName}" at "${resolveEntry.path}" ` +
|
|
26
|
+
`but its definition couldn't be loaded.`;
|
|
25
27
|
console.error(errorMessage);
|
|
26
28
|
errors.push(errorMessage);
|
|
27
29
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluateImportsForOverrides.js","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"evaluateImportsForOverrides.js","sourceRoot":"","sources":["../../../src/commands/init/evaluateImportsForOverrides.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE;;;GAGG;AACH,MAAM,CAAC,KAA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OAAO,GAAG,MAAM,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QACrE,MAAM,gBAAgB,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAEpD,KAAK,MAAM,oBAAoB,IAAI,qBAAqB,EAAE;YACxD,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,EAAE;gBAC3C,sBAAsB,CAAC;oBACrB,gBAAgB;oBAChB,oBAAoB;oBACpB,OAAO;oBACP,UAAU,EAAE,CAAC,iBAAiB,CAAC,YAAY,CAAC,IAAI,CAAC;iBAClD,CAAC,CAAC;gBAEH,MAAM,kBAAkB,CAAC;oBACvB,OAAO;oBACP,QAAQ;oBACR,WAAW,EAAE,YAAY,CAAC,IAAI;oBAC9B,UAAU,EAAE,oBAAoB;iBACjC,CAAC,CAAC;gBAEH,yEAAyE;gBACzE,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAEjB,WAAW,EAAE,CAAC;gBAEd,4FAA4F;gBAC5F,sBAAsB,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;gBAC9C,iBAAiB,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;aAC7C;SACF;KACF;IAED,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACjC,CAAC","sourcesContent":["import type { PackageJson, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { PackageOverride } from '@ms-cloudpack/config';\nimport {\n flattenExportsMap,\n addExportsMapEntry,\n getExportsMap,\n findResolveMapEntry,\n isExternalPackage,\n} from '@ms-cloudpack/package-utilities';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport { preparePackageOverride } from './preparePackageOverride.js';\n\n/**\n * Evaluate the imports depended on by a package to determine if missing exports map paths need to be added.\n * If so, updates package overrides to the given packageOverrides array.\n */\nexport async function evaluateImportsForOverrides(options: {\n packages: PackageDefinitionsCache;\n imports: Map<string, Set<string>>;\n definition: PackageJson;\n packageOverrides: PackageOverride[];\n packagePathsToEvaluate: Set<string>;\n evaluatedPackages: Set<string>;\n resolveMap: ResolveMap;\n}): Promise<{ changeCount: number; errors: string[] }> {\n const { packages, imports, definition, packageOverrides, packagePathsToEvaluate, evaluatedPackages, resolveMap } =\n options;\n const displayName = `${definition.name}@${definition.version}`;\n let changeCount = 0;\n const errors: string[] = [];\n\n // Iterate through imports and find their path from the resolve map.\n for (const [dependencyName, dependencyImportPaths] of imports.entries()) {\n const resolveEntry = findResolveMapEntry({ definition, packageName: dependencyName, resolveMap });\n\n if (!resolveEntry) {\n const errorMessage =\n `Package \"${displayName}\" depends on \"${dependencyName}\" but it was not found in the resolve map. ` +\n `Ensure that \"${dependencyName}\" is listed in dependencies of \"${displayName}\".`;\n console.error(errorMessage);\n errors.push(errorMessage);\n\n continue;\n }\n\n // Load the dependency definition.\n const dependencyDefinition = await packages.get(resolveEntry.path);\n\n if (!dependencyDefinition) {\n const errorMessage =\n `Package \"${displayName}\" depends on \"${dependencyName}\" at \"${resolveEntry.path}\" ` +\n `but its definition couldn't be loaded.`;\n console.error(errorMessage);\n errors.push(errorMessage);\n\n continue;\n }\n\n // Make sure to add the package to the list of packages to evaluate.\n packagePathsToEvaluate.add(resolveEntry.path);\n\n // Get the flattened bundle-able exports map for this dependency and iterate through our import paths to ensure nothing is missing.\n const exports = await getExportsMap(resolveEntry.path, { packages });\n const flattenedExports = flattenExportsMap(exports);\n\n for (const dependencyImportPath of dependencyImportPaths) {\n if (!flattenedExports[dependencyImportPath]) {\n preparePackageOverride({\n packageOverrides,\n dependencyDefinition,\n exports,\n isInternal: !isExternalPackage(resolveEntry.path),\n });\n\n await addExportsMapEntry({\n exports,\n packages,\n packagePath: resolveEntry.path,\n importPath: dependencyImportPath,\n });\n\n // Clear cache when we've mutated an override. Transforms need to re-run.\n packages.clear();\n\n changeCount++;\n\n // Since we've found a missing exports, we need to re-enqueue the dependency for evaluation.\n packagePathsToEvaluate.add(resolveEntry.path);\n evaluatedPackages.delete(resolveEntry.path);\n }\n }\n }\n\n return { changeCount, errors };\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns a dictionary where key is the package name and value is a set of required paths.
|
|
3
|
-
* Eg. { '@fluentui/react': new Set([ '.', './lib/Button' ]) }
|
|
3
|
+
* Eg. `{ '@fluentui/react': new Set([ '.', './lib/Button' ]) }`
|
|
4
4
|
*/
|
|
5
5
|
export declare function findImports(filePaths: string[]): Promise<Record<string, Set<string>>>;
|
|
6
6
|
//# sourceMappingURL=findImports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findImports.d.ts","sourceRoot":"","sources":["../../../src/commands/init/findImports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"findImports.d.ts","sourceRoot":"","sources":["../../../src/commands/init/findImports.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CA2D3F"}
|
|
@@ -2,56 +2,57 @@ import { parse } from 'es-module-lexer';
|
|
|
2
2
|
import fsPromises from 'fs/promises';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { parseImportString } from '@ms-cloudpack/path-string-parsing';
|
|
5
|
+
import { builtinModules } from 'module';
|
|
5
6
|
/**
|
|
6
7
|
* Returns a dictionary where key is the package name and value is a set of required paths.
|
|
7
|
-
* Eg. { '@fluentui/react': new Set([ '.', './lib/Button' ]) }
|
|
8
|
+
* Eg. `{ '@fluentui/react': new Set([ '.', './lib/Button' ]) }`
|
|
8
9
|
*/
|
|
9
10
|
export async function findImports(filePaths) {
|
|
10
|
-
var _a;
|
|
11
11
|
const requiredExports = {};
|
|
12
12
|
const visitedPaths = new Set(filePaths);
|
|
13
13
|
const pathsToParse = [...filePaths];
|
|
14
14
|
while (pathsToParse.length) {
|
|
15
15
|
const filePath = pathsToParse.shift();
|
|
16
|
-
if (filePath) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
else if (entry.packageName) {
|
|
51
|
-
requiredExports[_a = entry.packageName] || (requiredExports[_a] = new Set());
|
|
52
|
-
requiredExports[entry.packageName].add(entry.importPath || '.');
|
|
16
|
+
if (!filePath) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const source = await fsPromises.readFile(filePath, 'utf-8');
|
|
20
|
+
const [rawImports] = parse(source);
|
|
21
|
+
const imports = Array.from(new Set(rawImports))
|
|
22
|
+
.map((i) => {
|
|
23
|
+
// The es-module-lexer returns entries where the "n" property equals the import source.
|
|
24
|
+
// This includes the package name and path. For example, in this case:
|
|
25
|
+
//
|
|
26
|
+
// import { Button } from '@fluentui/react/lib/Button';
|
|
27
|
+
//
|
|
28
|
+
// The "n" property would be "@fluentui/react/lib/Button".
|
|
29
|
+
// The "s" and "e" properties represent the start/end character positions of
|
|
30
|
+
// the import source. The "ss" and "se" properties represent the start/end
|
|
31
|
+
// character positions of the import specifier starting with "import". This
|
|
32
|
+
// may be useful for determining if the import is sync or async.
|
|
33
|
+
//
|
|
34
|
+
// Currently when the import source is a backtick string, the "n" property
|
|
35
|
+
// is undefined. This is a bug in es-module-lexer. We may need to handle this
|
|
36
|
+
// at the javascript layer and expand it into multiple potential imports.
|
|
37
|
+
if (!i.n) {
|
|
38
|
+
console.debug(`Found an import that didn't parse correctly:\nFilename:\n${filePath}\n\nImport:\n${source.slice(i.s, i.e)}`);
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
return parseImportString(i.n);
|
|
42
|
+
})
|
|
43
|
+
.filter(Boolean);
|
|
44
|
+
for (const { packageName, importPath } of imports) {
|
|
45
|
+
if (packageName?.startsWith('.')) {
|
|
46
|
+
const localPath = path.resolve(path.dirname(filePath), packageName, importPath || '');
|
|
47
|
+
if (!visitedPaths.has(localPath)) {
|
|
48
|
+
visitedPaths.add(localPath);
|
|
49
|
+
pathsToParse.push(localPath);
|
|
53
50
|
}
|
|
54
51
|
}
|
|
52
|
+
else if (packageName && !packageName.startsWith('node:') && !builtinModules.includes(packageName)) {
|
|
53
|
+
requiredExports[packageName] || (requiredExports[packageName] = new Set());
|
|
54
|
+
requiredExports[packageName].add(importPath || '.');
|
|
55
|
+
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
return requiredExports;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findImports.js","sourceRoot":"","sources":["../../../src/commands/init/findImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAA2B,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"findImports.js","sourceRoot":"","sources":["../../../src/commands/init/findImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAA2B,MAAM,mCAAmC,CAAC;AAC/F,OAAO,EAAE,cAAc,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IAAI,OAAO,EAAE;YACjD,IAAI,WAAW,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE;gBAChC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,WAAW,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC;gBAEtF,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;oBAChC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;oBAC5B,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBAC9B;aACF;iBAAM,IAAI,WAAW,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;gBACnG,eAAe,CAAC,WAAW,MAA3B,eAAe,CAAC,WAAW,IAAM,IAAI,GAAG,EAAE,EAAC;gBAC3C,eAAe,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;aACrD;SACF;KACF;IAED,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import { parse } from 'es-module-lexer';\nimport fsPromises from 'fs/promises';\nimport path from 'path';\nimport { parseImportString, type ImportStringResult } from '@ms-cloudpack/path-string-parsing';\nimport { builtinModules } from 'module';\n\n/**\n * Returns a dictionary where key is the package name and value is a set of required paths.\n * Eg. `{ '@fluentui/react': new Set([ '.', './lib/Button' ]) }`\n */\nexport async function findImports(filePaths: string[]): Promise<Record<string, Set<string>>> {\n const requiredExports: Record<string, Set<string>> = {};\n const visitedPaths = new Set(filePaths);\n const pathsToParse: string[] = [...filePaths];\n\n while (pathsToParse.length) {\n const filePath = pathsToParse.shift();\n if (!filePath) {\n continue;\n }\n\n const source = await fsPromises.readFile(filePath, 'utf-8');\n const [rawImports] = parse(source);\n const imports = Array.from(new Set(rawImports))\n .map((i) => {\n // The es-module-lexer returns entries where the \"n\" property equals the import source.\n // This includes the package name and path. For example, in this case:\n //\n // import { Button } from '@fluentui/react/lib/Button';\n //\n // The \"n\" property would be \"@fluentui/react/lib/Button\".\n // The \"s\" and \"e\" properties represent the start/end character positions of\n // the import source. The \"ss\" and \"se\" properties represent the start/end\n // character positions of the import specifier starting with \"import\". This\n // may be useful for determining if the import is sync or async.\n //\n // Currently when the import source is a backtick string, the \"n\" property\n // is undefined. This is a bug in es-module-lexer. We may need to handle this\n // at the javascript layer and expand it into multiple potential imports.\n if (!i.n) {\n console.debug(\n `Found an import that didn't parse correctly:\\nFilename:\\n${filePath}\\n\\nImport:\\n${source.slice(\n i.s,\n i.e,\n )}`,\n );\n return undefined;\n }\n\n return parseImportString(i.n);\n })\n .filter(Boolean) as ImportStringResult[];\n\n for (const { packageName, importPath } of imports) {\n if (packageName?.startsWith('.')) {\n const localPath = path.resolve(path.dirname(filePath), packageName, importPath || '');\n\n if (!visitedPaths.has(localPath)) {\n visitedPaths.add(localPath);\n pathsToParse.push(localPath);\n }\n } else if (packageName && !packageName.startsWith('node:') && !builtinModules.includes(packageName)) {\n requiredExports[packageName] ||= new Set();\n requiredExports[packageName].add(importPath || '.');\n }\n }\n }\n\n return requiredExports;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/init/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQzC,wBAAgB,IAAI,CAAC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/init/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQzC,wBAAgB,IAAI,CAAC,OAAO,EAAE,OAAO,QAkDpC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { reporter } from '../../reporter.js';
|
|
2
|
-
import { red } from '@ms-cloudpack/task-reporter';
|
|
2
|
+
import { plural, red, yellow } from '@ms-cloudpack/task-reporter';
|
|
3
3
|
import { configFileName } from '@ms-cloudpack/config';
|
|
4
4
|
import { stopTelemetry } from '../../initTelemetry.js';
|
|
5
5
|
/* Defines the "init" verb. */
|
|
@@ -14,24 +14,36 @@ export function init(command) {
|
|
|
14
14
|
const { init } = await import('./init.js');
|
|
15
15
|
let completeReason;
|
|
16
16
|
let hasErrors = false;
|
|
17
|
+
let hasWarnings = false;
|
|
17
18
|
try {
|
|
18
|
-
const { changeCount } = await init(options);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const { changeCount, errorPkgCount, warningPkgCount, successPkgCount } = await init(options);
|
|
20
|
+
hasErrors = errorPkgCount > 0;
|
|
21
|
+
hasWarnings = warningPkgCount > 0;
|
|
22
|
+
const totalCount = errorPkgCount + warningPkgCount + successPkgCount;
|
|
23
|
+
if (hasErrors || hasWarnings) {
|
|
24
|
+
const successPct = ((successPkgCount / totalCount) * 100).toFixed(1);
|
|
25
|
+
completeReason =
|
|
26
|
+
[
|
|
27
|
+
`${successPkgCount}/${totalCount} (${successPct}%) packages bundled successfully`,
|
|
28
|
+
hasErrors && `${errorPkgCount} packages with errors`,
|
|
29
|
+
hasWarnings && `${warningPkgCount} packages with warnings`,
|
|
30
|
+
]
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.join('\n') + '\n';
|
|
22
33
|
}
|
|
23
34
|
else {
|
|
24
|
-
completeReason =
|
|
25
|
-
|
|
26
|
-
|
|
35
|
+
completeReason = `All ${totalCount} packages bundled successfully`;
|
|
36
|
+
}
|
|
37
|
+
if (changeCount) {
|
|
38
|
+
completeReason += `\n\nUpdated "${configFileName}" with ${plural(changeCount, 'change')}.`;
|
|
27
39
|
}
|
|
28
40
|
}
|
|
29
41
|
catch (error) {
|
|
30
42
|
hasErrors = true;
|
|
31
|
-
completeReason = `Unexpected error: ${error.message ||
|
|
43
|
+
completeReason = `Unexpected error: ${error.message || error}`;
|
|
32
44
|
}
|
|
33
45
|
await stopTelemetry();
|
|
34
|
-
reporter.complete(hasErrors ? red(completeReason) : completeReason);
|
|
46
|
+
reporter.complete(hasErrors ? red(completeReason) : hasWarnings ? yellow(completeReason) : completeReason);
|
|
35
47
|
process.exit(hasErrors ? 1 : 0);
|
|
36
48
|
});
|
|
37
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/init/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/init/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,8BAA8B;AAC9B,MAAM,UAAU,IAAI,CAAC,OAAgB;IACnC,OAAO;SACJ,OAAO,CAAC,MAAM,CAAC;SACf,WAAW,CACV,sIAAsI,CACvI;SACA,MAAM,CAAC,OAAO,EAAE,8DAA8D,CAAC;SAC/E,MAAM,CAAC,SAAS,EAAE,0DAA0D,CAAC;SAC7E,MAAM,CAAC,SAAS,EAAE,2CAA2C,CAAC;SAC9D,MAAM,CAAC,KAAK,EAAE,OAAoB,EAAE,EAAE;QACrC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;QAE3C,IAAI,cAAkC,CAAC;QACvC,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,IAAI,WAAW,GAAG,KAAK,CAAC;QACxB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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Command } from 'commander';\nimport type { InitOptions } from './types/InitOptions.js';\nimport { reporter } from '../../reporter.js';\nimport { plural, red, yellow } from '@ms-cloudpack/task-reporter';\nimport { configFileName } from '@ms-cloudpack/config';\nimport { stopTelemetry } from '../../initTelemetry.js';\n\n/* Defines the \"init\" verb. */\nexport function init(command: Command) {\n command\n .command('init')\n .description(\n 'Initializes a given app project and defines the necessary configuration overrides to make an existing app compatible with Cloudpack.',\n )\n .option('--fix', 'Applies fixes to all identified issues in internal packages.')\n .option('--reset', 'Ignores existing overrides when determining all entries.')\n .option('--check', 'Fails if any package exports are missing.')\n .action(async (options: InitOptions) => {\n const { init } = await import('./init.js');\n\n let completeReason: string | undefined;\n let hasErrors = false;\n let hasWarnings = false;\n try {\n const { changeCount, errorPkgCount, warningPkgCount, successPkgCount } = await init(options);\n\n hasErrors = errorPkgCount > 0;\n hasWarnings = warningPkgCount > 0;\n\n const totalCount = errorPkgCount + warningPkgCount + successPkgCount;\n\n if (hasErrors || hasWarnings) {\n const successPct = ((successPkgCount / totalCount) * 100).toFixed(1);\n completeReason =\n [\n `${successPkgCount}/${totalCount} (${successPct}%) packages bundled successfully`,\n hasErrors && `${errorPkgCount} packages with errors`,\n hasWarnings && `${warningPkgCount} packages with warnings`,\n ]\n .filter(Boolean)\n .join('\\n') + '\\n';\n } else {\n completeReason = `All ${totalCount} packages bundled successfully`;\n }\n\n if (changeCount) {\n completeReason += `\\n\\nUpdated \"${configFileName}\" with ${plural(changeCount, 'change')}.`;\n }\n } catch (error) {\n hasErrors = true;\n completeReason = `Unexpected error: ${(error as Error).message || error}`;\n }\n\n await stopTelemetry();\n reporter.complete(hasErrors ? red(completeReason) : hasWarnings ? yellow(completeReason) : completeReason);\n\n process.exit(hasErrors ? 1 : 0);\n });\n}\n"]}
|
|
@@ -2,5 +2,8 @@ import type { InitOptions } from './types/InitOptions.js';
|
|
|
2
2
|
/** Given the path, updates the Cloudpack config with overrides and project settings. */
|
|
3
3
|
export declare function init(options: InitOptions): Promise<{
|
|
4
4
|
changeCount: number;
|
|
5
|
+
errorPkgCount: number;
|
|
6
|
+
warningPkgCount: number;
|
|
7
|
+
successPkgCount: number;
|
|
5
8
|
}>;
|
|
6
9
|
//# sourceMappingURL=init.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,wFAAwF;AACxF,wBAAsB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,wFAAwF;AACxF,wBAAsB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC;IACxD,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC,CAiHD"}
|
|
@@ -4,7 +4,7 @@ import { createPackageOverrideTransform } from '../../common/createPackageOverri
|
|
|
4
4
|
import { rootSpan } from '../../initTelemetry.js';
|
|
5
5
|
import { resolveDependenciesTask } from '../../tasks/resolveDependenciesTask.js';
|
|
6
6
|
import { evaluateImportsForOverrides } from './evaluateImportsForOverrides.js';
|
|
7
|
-
import {
|
|
7
|
+
import { bundleAndGetImports } from './bundleAndGetImports.js';
|
|
8
8
|
import { patchAllInternalPackageExports } from './patchAllInternalPackageExports.js';
|
|
9
9
|
/** Given the path, updates the Cloudpack config with overrides and project settings. */
|
|
10
10
|
export async function init(options) {
|
|
@@ -27,6 +27,9 @@ export async function init(options) {
|
|
|
27
27
|
const packagePathsToEvaluate = new Set([appPath]);
|
|
28
28
|
const evaluatedPackages = new Set();
|
|
29
29
|
let changeCount = 0;
|
|
30
|
+
let errorPkgCount = 0;
|
|
31
|
+
let warningPkgCount = 0;
|
|
32
|
+
let successPkgCount = 0;
|
|
30
33
|
while (packagePathsToEvaluate.size) {
|
|
31
34
|
const packagePath = packagePathsToEvaluate.values().next().value;
|
|
32
35
|
packagePathsToEvaluate.delete(packagePath);
|
|
@@ -37,38 +40,43 @@ export async function init(options) {
|
|
|
37
40
|
evaluatedPackages.add(packagePath);
|
|
38
41
|
const definition = await packages.get(packagePath, { refresh: true });
|
|
39
42
|
if (!definition) {
|
|
43
|
+
// This is very weird and probably won't happen.
|
|
44
|
+
console.error(`Skipping ${packagePath} evaluation because the package.json was not found or not readable.`);
|
|
45
|
+
errorPkgCount++;
|
|
40
46
|
continue;
|
|
41
47
|
}
|
|
42
48
|
// Bundle the package and find the imports it depends on.
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!imports) {
|
|
49
|
-
console.info(`Skipping ${packagePath} evaluation due to no imports returned.`);
|
|
49
|
+
const bundleResult = await bundleAndGetImports({ packagePath, definition, packages });
|
|
50
|
+
if (!bundleResult.imports) {
|
|
51
|
+
// This is expected if the package just doesn't import anything else.
|
|
52
|
+
console.info(`${packagePath} has no additional imports to evaluate.`);
|
|
53
|
+
bundleResult.hasErrors ? errorPkgCount++ : bundleResult.hasWarnings ? warningPkgCount++ : successPkgCount++;
|
|
50
54
|
continue;
|
|
51
55
|
}
|
|
52
56
|
// Given the package imports, find the missing exports maps and update packageOverrides.
|
|
53
|
-
const
|
|
57
|
+
const overridesResult = await evaluateImportsForOverrides({
|
|
54
58
|
definition,
|
|
55
59
|
packages,
|
|
56
|
-
packagePath,
|
|
57
60
|
packagePathsToEvaluate,
|
|
58
61
|
evaluatedPackages,
|
|
59
|
-
imports,
|
|
62
|
+
imports: bundleResult.imports,
|
|
60
63
|
packageOverrides,
|
|
61
64
|
resolveMap,
|
|
62
65
|
});
|
|
63
|
-
if (options.check && (
|
|
66
|
+
if (options.check && (overridesResult.changeCount || overridesResult.errors.length)) {
|
|
64
67
|
rootSpan?.addEvent('INIT_CHECK_FAILED', {
|
|
65
|
-
reason:
|
|
68
|
+
reason: overridesResult.changeCount ? 'Config needs to be updated.' : overridesResult.errors,
|
|
66
69
|
});
|
|
67
|
-
throw Error(
|
|
70
|
+
throw Error(overridesResult.changeCount
|
|
68
71
|
? 'Run "cloudpack init --reset" to update the config.'
|
|
69
|
-
:
|
|
72
|
+
: overridesResult.errors.map((e) => e).join('\n'));
|
|
70
73
|
}
|
|
71
|
-
changeCount +=
|
|
74
|
+
changeCount += overridesResult.changeCount;
|
|
75
|
+
bundleResult.hasErrors || overridesResult.errors.length
|
|
76
|
+
? errorPkgCount++
|
|
77
|
+
: bundleResult.hasWarnings
|
|
78
|
+
? warningPkgCount++
|
|
79
|
+
: successPkgCount++;
|
|
72
80
|
}
|
|
73
81
|
if (options.fix) {
|
|
74
82
|
await patchAllInternalPackageExports({ resolveMap, packageOverrides });
|
|
@@ -82,6 +90,9 @@ export async function init(options) {
|
|
|
82
90
|
}
|
|
83
91
|
return {
|
|
84
92
|
changeCount,
|
|
93
|
+
errorPkgCount,
|
|
94
|
+
warningPkgCount,
|
|
95
|
+
successPkgCount,
|
|
85
96
|
};
|
|
86
97
|
}
|
|
87
98
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../src/commands/init/init.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,gDAA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CAAC,WAAW;gBAC1B,CAAC,CAAC,eAAe,EAAE;gBACnB,CAAC,CAAC,eAAe,EAAE,CAAC;KACvB;IAED,IAAI,OAAO,CAAC,GAAG,EAAE;QACf,MAAM,8BAA8B,CAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC,CAAC;KACxE;IAED,IAAI,WAAW,EAAE;QACf,6BAA6B;QAC7B,OAAO,CAAC,GAAG,CACT,uBAAuB,uBAAuB,8EAA8E,CAC7H,CAAC;QAEF,IAAI,gBAAgB,CAAC,MAAM,EAAE;YAC3B,MAAM,oBAAoB,CAAC,EAAE,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAC;SAC3D;KACF;IAED,OAAO;QACL,WAAW;QACX,aAAa;QACb,eAAe;QACf,eAAe;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageOverride } from '@ms-cloudpack/config';\nimport { generatedConfigFileName, readConfig, writeGeneratedConfig } from '@ms-cloudpack/config';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport { PackageDefinitions } from '@ms-cloudpack/package-utilities';\nimport { createPackageOverrideTransform } from '../../common/createPackageOverrideTransform.js';\nimport { rootSpan } from '../../initTelemetry.js';\nimport { resolveDependenciesTask } from '../../tasks/resolveDependenciesTask.js';\nimport { evaluateImportsForOverrides } from './evaluateImportsForOverrides.js';\nimport { bundleAndGetImports } from './bundleAndGetImports.js';\nimport { patchAllInternalPackageExports } from './patchAllInternalPackageExports.js';\nimport type { InitOptions } from './types/InitOptions.js';\n\n/** Given the path, updates the Cloudpack config with overrides and project settings. */\nexport async function init(options: InitOptions): Promise<{\n changeCount: number;\n errorPkgCount: number;\n warningPkgCount: number;\n successPkgCount: number;\n}> {\n if (options.check && options.fix) {\n throw Error('Cannot use --check and --fix together.');\n }\n\n if (options.check && options.reset) {\n throw Error('Cannot use --check and --reset together.');\n }\n\n const appPath = options.cwd || process.cwd();\n const config = await readConfig(appPath);\n const packageOverrides: PackageOverride[] = (!options.reset && config.packageOverrides) || [];\n const packages = new PackageDefinitions();\n\n packages.registerTransform(createPackageOverrideTransform({ packageOverrides }));\n\n // Try to resolve dependencies.\n const resolveMap = (await resolveDependenciesTask({ appPath, packages })) as ResolveMap;\n\n if (!resolveMap) {\n throw new Error(\"Couldn't resolve dependencies.\");\n }\n\n const packagePathsToEvaluate = new Set<string>([appPath]);\n const evaluatedPackages = new Set<string>();\n let changeCount = 0;\n let errorPkgCount = 0;\n let warningPkgCount = 0;\n let successPkgCount = 0;\n\n while (packagePathsToEvaluate.size) {\n const packagePath = packagePathsToEvaluate.values().next().value as string;\n\n packagePathsToEvaluate.delete(packagePath);\n\n // Skip already-visited packages.\n if (!packagePath || evaluatedPackages.has(packagePath)) {\n continue;\n }\n\n evaluatedPackages.add(packagePath);\n\n const definition = await packages.get(packagePath, { refresh: true });\n\n if (!definition) {\n // This is very weird and probably won't happen.\n console.error(`Skipping ${packagePath} evaluation because the package.json was not found or not readable.`);\n errorPkgCount++;\n continue;\n }\n\n // Bundle the package and find the imports it depends on.\n const bundleResult = await bundleAndGetImports({ packagePath, definition, packages });\n\n if (!bundleResult.imports) {\n // This is expected if the package just doesn't import anything else.\n console.info(`${packagePath} has no additional imports to evaluate.`);\n bundleResult.hasErrors ? errorPkgCount++ : bundleResult.hasWarnings ? warningPkgCount++ : successPkgCount++;\n continue;\n }\n\n // Given the package imports, find the missing exports maps and update packageOverrides.\n const overridesResult = await evaluateImportsForOverrides({\n definition,\n packages,\n packagePathsToEvaluate,\n evaluatedPackages,\n imports: bundleResult.imports,\n packageOverrides,\n resolveMap,\n });\n\n if (options.check && (overridesResult.changeCount || overridesResult.errors.length)) {\n rootSpan?.addEvent('INIT_CHECK_FAILED', {\n reason: overridesResult.changeCount ? 'Config needs to be updated.' : overridesResult.errors,\n });\n throw Error(\n overridesResult.changeCount\n ? 'Run \"cloudpack init --reset\" to update the config.'\n : overridesResult.errors.map((e) => e).join('\\n'),\n );\n }\n\n changeCount += overridesResult.changeCount;\n\n bundleResult.hasErrors || overridesResult.errors.length\n ? errorPkgCount++\n : bundleResult.hasWarnings\n ? warningPkgCount++\n : successPkgCount++;\n }\n\n if (options.fix) {\n await patchAllInternalPackageExports({ resolveMap, packageOverrides });\n }\n\n if (changeCount) {\n // Log the results to a file.\n console.log(\n `Writing updates to \"${generatedConfigFileName}\". If you're in a git repo, this file should be committed with your project.`,\n );\n\n if (packageOverrides.length) {\n await writeGeneratedConfig({ packageOverrides }, appPath);\n }\n }\n\n return {\n changeCount,\n errorPkgCount,\n warningPkgCount,\n successPkgCount,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/cli",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.9",
|
|
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,8 +10,8 @@
|
|
|
10
10
|
"cloudpack": "./bin/cloudpack.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@ms-cloudpack/api-server": "^0.6.
|
|
14
|
-
"@ms-cloudpack/bundler": "^0.13.
|
|
13
|
+
"@ms-cloudpack/api-server": "^0.6.14",
|
|
14
|
+
"@ms-cloudpack/bundler": "^0.13.1",
|
|
15
15
|
"@ms-cloudpack/config": "^0.7.3",
|
|
16
16
|
"@ms-cloudpack/create-express-app": "^1.3.6",
|
|
17
17
|
"@ms-cloudpack/data-bus": "^0.3.0",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@ms-cloudpack/package-utilities": "^3.1.4",
|
|
21
21
|
"@ms-cloudpack/path-string-parsing": "^1.0.2",
|
|
22
22
|
"@ms-cloudpack/path-utilities": "^2.2.3",
|
|
23
|
-
"@ms-cloudpack/task-reporter": "^0.4.
|
|
23
|
+
"@ms-cloudpack/task-reporter": "^0.4.2",
|
|
24
24
|
"@ms-cloudpack/telemetry": "^0.3.3",
|
|
25
25
|
"chokidar": "^3.5.3",
|
|
26
26
|
"commander": "^10.0.0",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { PackageJson, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
2
|
-
/**
|
|
3
|
-
* Bundle the package and return the imports it depends on.
|
|
4
|
-
*/
|
|
5
|
-
export declare function getImportsFromBundle(options: {
|
|
6
|
-
packages: PackageDefinitionsCache;
|
|
7
|
-
packagePath: string;
|
|
8
|
-
definition: PackageJson;
|
|
9
|
-
}): Promise<Map<string, Set<string>> | undefined>;
|
|
10
|
-
//# sourceMappingURL=getImportsFromBundle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getImportsFromBundle.d.ts","sourceRoot":"","sources":["../../../src/commands/init/getImportsFromBundle.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAMxF;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,QAAQ,EAAE,uBAAuB,CAAC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,WAAW,CAAC;CACzB,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,CAAC,CAwDhD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getImportsFromBundle.js","sourceRoot":"","sources":["../../../src/commands/init/getImportsFromBundle.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE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9E,CACF,CAAC;IACJ,CAAC,EAAE,EAAc,CAAC,CAAC;AACrB,CAAC","sourcesContent":["import path from 'path';\nimport { getEntriesMapFromPackage } from '@ms-cloudpack/bundler';\nimport { getBundleDetails } from '../../common/getBundleDetails.js';\nimport { findImports } from './findImports.js';\nimport { prepareOutputPath } from '../../common/prepareOutputPath.js';\nimport type { PackageJson, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { reporter } from '../../reporter.js';\nimport type { BundleRequest } from '../../types/BundleRequest.js';\nimport { bundleTask } from '../../tasks/bundleTask.js';\nimport { bulletedList, formatPackageName } from '@ms-cloudpack/task-reporter';\n\n/**\n * Bundle the package and return the imports it depends on.\n */\nexport async function getImportsFromBundle(options: {\n packages: PackageDefinitionsCache;\n packagePath: string;\n definition: PackageJson;\n}): Promise<Map<string, Set<string>> | undefined> {\n const { packagePath, definition, packages } = options;\n const { outputPath, isExternal } = await getBundleDetails(packagePath);\n\n if (!isExternal && !definition.exports) {\n console.warn(`Package ${path.join(packagePath, 'package.json')} does not have an \"exports\" field.`);\n }\n\n // Ensure outputPath exists and is empty.\n await prepareOutputPath(outputPath);\n\n // Determine entries.\n const entriesMap = await getEntriesMapFromPackage({\n inputPath: packagePath,\n packages,\n });\n\n if (!Object.keys(entriesMap).length) {\n console.warn(`Package ${path.join(packagePath, 'package.json')} does not have any entries.`);\n return;\n }\n\n const bundleRequest: BundleRequest = {\n id: packagePath,\n packageName: definition.name || '',\n version: definition.version || '',\n packagePath,\n outputPath,\n isExternal,\n packages,\n };\n\n await bundleTask({ bundleRequest, options: { force: true } });\n\n // For each outputFile, find all imports.\n let imports: Map<string, Set<string>> | undefined;\n\n await reporter.runTask(`Evaluate ${formatPackageName(definition)}`, async () => {\n imports = new Map(\n Object.entries(\n (await findImports(\n bundleRequest.result?.outputFiles?.map((file) => path.resolve(outputPath, file.outputPath)) || [],\n )) || {},\n ),\n );\n\n const importCount = imports.size;\n\n return {\n status: 'complete',\n message: importCount ? `Found ${importCount} imported package(s)` : undefined,\n details: importCount ? `${bulletedList(getImportsList(imports))}` : undefined,\n };\n });\n\n return imports;\n}\n\nfunction getImportsList(imports: Map<string, Set<string>>): string[] {\n return Array.from(imports.keys()).reduce((list, packageName) => {\n return list.concat(\n Array.from(imports.get(packageName) || []).map(\n (importPath) => `${packageName}${importPath === '.' ? '' : `/${importPath}`}`,\n ),\n );\n }, [] as string[]);\n}\n"]}
|