Socket
Socket
Sign inDemoInstall

@ms-cloudpack/config

Package Overview
Dependencies
Maintainers
3
Versions
152
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/config - npm Package Compare versions

Comparing version 0.24.2 to 0.25.0

2

lib/createPackageSettingsTransform.d.ts

@@ -1,2 +0,2 @@

import type { CloudpackConfig, PackageDefinitionTransform } from '@ms-cloudpack/common-types';
import { type CloudpackConfig, type PackageDefinitionTransform } from '@ms-cloudpack/common-types';
/**

@@ -3,0 +3,0 @@ * Creates a transform to be registered with a PackageDefinitions registry for updating package.json

import { getPackageSettings } from './getPackageSettings.js';
import { getExportsMap } from '@ms-cloudpack/package-utilities';
import { addExportsMapEntry, getExportsMap } from '@ms-cloudpack/package-utilities';
import { mergePackageSettings } from './mergePackageSettings.js';

@@ -83,10 +83,47 @@ /**

const { packagePath, definition, userPackageSettings, generatedPackageSettings } = options;
let exports = userPackageSettings?.exports ||
const { appPath } = context.config;
const exports = [];
// If this is the app package, ensure the routes are part of the exports map.
if (appPath === packagePath) {
const { routes = [] } = context.config;
const routeExports = {};
let hasRouteExports = false;
for (const route of routes) {
const { entry } = route;
if (entry?.length) {
for (const entryItem of entry) {
hasRouteExports =
(await addExportsMapEntry({
exports: routeExports,
packagePath,
environmentCondition: 'browser',
filePath: entryItem.sourcePath,
importPath: entryItem.importPath,
}, context)) || hasRouteExports;
}
}
}
// Insert them at the start, so that future exports have precedence.
if (hasRouteExports) {
// We short circuit here because we don't want to include any unused exports that might
// be pulled from package.json.
return routeExports;
}
}
// Push exports from the package.
exports.push(userPackageSettings?.exports ||
definition.exports ||
(await getExportsMap({ packagePath, disableTransforms: true }, context));
(await getExportsMap({ packagePath, disableTransforms: true }, context)));
// Push generated exports.
if (generatedPackageSettings?.exports) {
exports = [exports, generatedPackageSettings.exports];
exports.push(generatedPackageSettings.exports);
}
if (exports.length === 0) {
return undefined;
}
if (exports.length === 1) {
return exports[0];
}
return exports;
}
//# sourceMappingURL=createPackageSettingsTransform.js.map
import { readAppConfig } from './readAppConfig.js';
import { readGeneratedConfig } from './readGeneratedConfig.js';
import { intermediateToSourcePath, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';
import { flattenExportsMap } from '@ms-cloudpack/package-utilities';
import path from 'path';
import { readJson } from '@ms-cloudpack/json-utilities';
/**

@@ -16,17 +20,28 @@ * Reads the config file asynchronously (and merges generated config into the result.)

// Expands all routes which refer to source files into fully transformed route objects.
expandRouteShorthandEntries(config);
await expandRouteShorthandEntries(config, appPath);
return config;
}
/**
*
* @param config
* Ensure all source entries in route are expanded to fully qualified entry paths.
*/
function expandRouteShorthandEntries(config) {
async function expandRouteShorthandEntries(config, appPath) {
const { routes } = config;
if (routes) {
for (let i = 0; i < routes.length; i++) {
const route = routes[i];
if (typeof route === 'string') {
routes[i] = { match: route, entry: route };
break;
let definition;
if (routes?.length) {
for (const route of routes) {
const shorthandRoute = route;
const renderedRoute = route;
renderedRoute.entry = ensureArray(shorthandRoute.entry)?.map((filePath) => expandRouteEntry({
filePath,
appPath,
}));
// eslint-disable-next-line etc/no-deprecated
if (shorthandRoute.exportEntry) {
if (!definition) {
// We can't use PackageDefinitions.get here because we're reading the config, and definitions
// cache requires config resulting in a cycle.
definition = await readJson(path.join(appPath, 'package.json'));
}
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expandDeprecatedExportEntry(route, definition, appPath);
}

@@ -36,2 +51,53 @@ }

}
/**
* Handle backwards compatibility with moving from exportEntry to entry. When exportEntry is deleted,
* this function can be removed.
*/
function expandDeprecatedExportEntry(route, definition, appPath) {
const shorthandRoute = route;
const renderedRoute = route;
// eslint-disable-next-line etc/no-deprecated
const { exportEntry } = shorthandRoute;
const flattenedExports = flattenExportsMap(definition.exports || {});
if (exportEntry) {
renderedRoute.entry = ensureArray(renderedRoute.entry);
const filePath = flattenedExports[exportEntry] || definition.module || definition.main;
if (!filePath) {
throw new Error(`A route referenced exportEntry "${exportEntry}" but this couldn't be resolved from the package.json.`);
}
// We are converting the exportEntry to an ExpandedSourcePath so that the route
// can be returned as a RenderedRoute.
renderedRoute.entry.push(expandRouteEntry({
importPath: exportEntry,
filePath,
appPath,
}));
// eslint-disable-next-line etc/no-deprecated
delete shorthandRoute.exportEntry;
}
}
/** Ensures the value is an array, or is wrapped in one. If a value is blank, will return a blank array. */
function ensureArray(value) {
if (Array.isArray(value)) {
return value;
}
return (value !== undefined ? [value] : []);
}
/** Expands shorthand route entries into fully qualified ones. */
function expandRouteEntry(options) {
const { filePath, appPath, importPath } = options;
const sourcePath = intermediateToSourcePath(filePath, appPath);
if (!sourcePath) {
throw new Error(`Could not resolve source path for entry: ${filePath}`);
}
const intermediatePath = sourceToIntermediatePath(sourcePath);
return {
// Used to derive bundle entry path
sourcePath,
// Used to derive import map key
importPath: importPath || intermediatePath,
// Used to derive import map value
requestPath: intermediatePath,
};
}
//# sourceMappingURL=readConfig.js.map
{
"name": "@ms-cloudpack/config",
"version": "0.24.2",
"version": "0.25.0",
"description": "Configuration handling for cloudpack.",

@@ -17,5 +17,6 @@ "license": "MIT",

"dependencies": {
"@ms-cloudpack/common-types": "^0.14.0",
"@ms-cloudpack/common-types": "^0.15.0",
"@ms-cloudpack/json-utilities": "^0.1.6",
"@ms-cloudpack/package-utilities": "^8.2.0",
"@ms-cloudpack/package-utilities": "^9.0.0",
"@ms-cloudpack/path-utilities": "^2.7.32",
"import-meta-resolve": "^4.0.0",

@@ -22,0 +23,0 @@ "semver": "^7.6.0"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc