Socket
Socket
Sign inDemoInstall

@ms-cloudpack/package-utilities

Package Overview
Dependencies
Maintainers
2
Versions
203
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/package-utilities - npm Package Compare versions

Comparing version 0.12.3 to 0.13.0

23

CHANGELOG.json

@@ -5,3 +5,24 @@ {

{
"date": "Wed, 28 Sep 2022 08:14:45 GMT",
"date": "Thu, 29 Sep 2022 08:12:54 GMT",
"tag": "@ms-cloudpack/package-utilities_v0.13.0",
"version": "0.13.0",
"comments": {
"minor": [
{
"author": "dzearing@microsoft.com",
"package": "@ms-cloudpack/package-utilities",
"commit": "b3f9e96c9ae7fb07550d8d9ae47b90615ad6722e",
"comment": "Updating a variety of edge cases in package utility exports parsing."
},
{
"author": "beachball",
"package": "@ms-cloudpack/package-utilities",
"comment": "Bump @ms-cloudpack/package-overrides to v0.2.0",
"commit": "965236301e62bda5f94c1f54fa7ee80985e25513"
}
]
}
},
{
"date": "Wed, 28 Sep 2022 08:15:16 GMT",
"tag": "@ms-cloudpack/package-utilities_v0.12.3",

@@ -8,0 +29,0 @@ "version": "0.12.3",

# Change Log - @ms-cloudpack/package-utilities
This log was last generated on Wed, 28 Sep 2022 08:14:45 GMT and should not be manually modified.
This log was last generated on Thu, 29 Sep 2022 08:12:54 GMT and should not be manually modified.
<!-- Start content -->
## 0.13.0
Thu, 29 Sep 2022 08:12:54 GMT
### Minor changes
- Updating a variety of edge cases in package utility exports parsing. (dzearing@microsoft.com)
- Bump @ms-cloudpack/package-overrides to v0.2.0
## 0.12.3
Wed, 28 Sep 2022 08:14:45 GMT
Wed, 28 Sep 2022 08:15:16 GMT

@@ -11,0 +20,0 @@ ### Patches

@@ -30,3 +30,3 @@ import { PackageDefinitions } from './PackageDefinitions.js';

const definition = packageDefinitions?.[entry.path] || (await PackageDefinitions.getInstance().get(entry.path));
// Only add packages wtih names that aren't typings packages.
// Only add packages with names that aren't typings packages.
if (definition?.name && definition?.version && !definition.name.startsWith('@types/')) {

@@ -43,3 +43,13 @@ const exportsMap = getFlattenedExportsMap(definition);

for (const [exportName, exportPath] of Object.entries(exportsMap)) {
importMap[exportName.replace('.', definition.name)] = new URL(exportPath, baseUrl).href;
let ext = path.extname(exportPath);
if (ext === '.mjs') {
ext = '.js';
}
else if (ext !== '.js') {
ext += '.js';
}
// Ensure that things in the import map end with .js
importMap[exportName.replace('.', definition.name)] = new URL(path
.join(path.dirname(exportPath), path.basename(exportPath, path.extname(exportPath)) + ext)
.replace('+', '_'), baseUrl).href;
}

@@ -46,0 +56,0 @@ importMap[definition.name + '/'] = baseUrl;

@@ -183,3 +183,23 @@ import { describe, it, expect } from '@jest/globals';

});
it('can reduce an .mjs file to a .js file', async () => {
const resolveMap = {
a: basicResolveMapEntry,
};
const packages = {
'path/a': {
name: 'a',
version: '1.0.0',
main: './foo/main.mjs',
},
};
expect(await createImportMap(resolveMap, bundleServerUrl, packages)).toMatchInlineSnapshot(`
{
"imports": {
"a": "http://localhost:12345/a@1.0.0/foo/main.js",
"a/": "http://localhost:12345/a@1.0.0/",
},
}
`);
});
});
//# sourceMappingURL=createImportMap.test.js.map

@@ -16,2 +16,10 @@ import path from 'path';

packagePath = path.dirname(packagePath);
// If we moved up into a scope folder, skip over it.
if (path.basename(packagePath).startsWith('@')) {
packagePath = path.dirname(packagePath);
}
// Skip over nested node_modules folders.
if (packagePath.endsWith('node_modules')) {
packagePath = path.dirname(packagePath);
}
} while ((!gitRootPath || packagePath.length >= gitRootPath.length) && path.dirname(packagePath) !== packagePath);

@@ -18,0 +26,0 @@ if (!isOptional) {

import type { PackageJson } from 'type-fest';
/**
* Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.
* Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.
*/
export declare function getFlattenedExportsMap(definition: PackageJson, conditions?: string[]): Record<string, string>;

8

lib/getFlattenedExportsMap.js
import path from 'path';
import { cleanEntry } from './cleanEntry.js';
const defaultConditions = ['browser', 'import', 'module', 'default'];
/**
* Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.
* Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.
*/
export function getFlattenedExportsMap(definition, conditions = ['browser', 'import', 'module', 'default']) {
export function getFlattenedExportsMap(definition, conditions = defaultConditions) {
const exportsMap = {};

@@ -12,4 +14,4 @@ if (typeof definition.browser === 'string') {

extractExports(definition.exports, conditions, exportsMap);
// if we haven't found a default export, fall back to module or main
if (!exportsMap['.']) {
// if the definition doesn't have an exports map, fall back to module or main
if (!definition.exports) {
if (typeof definition.module === 'string') {

@@ -16,0 +18,0 @@ addExportsEntry(exportsMap, '.', definition.module);

@@ -259,3 +259,13 @@ import { describe, it, expect } from '@jest/globals';

});
it(`avoids returning a default entry if an exports map doesn't include it`, () => {
const exportsMap = getFlattenedExportsMap({
name: 'a',
main: 'index.js',
exports: {
'./foo': './foo.js',
},
});
expect(exportsMap['.']).toBeUndefined();
});
});
//# sourceMappingURL=getFlattenedExportsMap.test.js.map
import { describe, it, expect } from '@jest/globals';
import { resolveImportFromPackage, resolveImportFromPackagePath } from './resolveImportFromPackagePath.js';
import { testProject2Path } from '../src/testPaths.js';
import { testProject2Path, testProject3Path } from '../src/testPaths.js';
const defaultPackageDefinition = {

@@ -23,2 +23,14 @@ name: 'package',

});
it('can resolve a main entry using a period for the importPath', async () => {
expect(await resolveImportFromPackage(testProject2Path, {
...defaultPackageDefinition,
main: './lib/main.js',
}, '.')).toEqual('./lib/main.js');
});
it('can resolve a main entry from a sub-package', async () => {
expect(await resolveImportFromPackage(testProject3Path, {
...defaultPackageDefinition,
main: './lib/main.js',
}, '/core')).toEqual('./lib/core-module.js');
});
it('can fall back to a subfolder', async () => {

@@ -25,0 +37,0 @@ expect(await resolveImportFromPackage(testProject2Path, {

@@ -13,4 +13,5 @@ import type { PackageJson } from 'type-fest';

/**
* Resolves a requested import path from a package located at the given path. Gives prescedence
* to browser/esm options. This may change in a future iteration.
* Resolves a requested import path from a package located at the given path. Gives precedence
* to browser/esm options, but will fall back to discover exact path matches, and will fall back
* to source paths (lib to src translation) if the option is provided.
*/

@@ -22,2 +23,2 @@ export declare function resolveImportFromPackagePath(packagePath: string, requestedPath?: string, options?: ResolveImportFromPackageOptions): Promise<string | undefined>;

*/
export declare function resolveImportFromPackage(packagePath: string, packageDefinition: PackageJson, importPath?: string, options?: ResolveImportFromPackageOptions): Promise<string>;
export declare function resolveImportFromPackage(packagePath: string, packageDefinition: PackageJson, importPath?: string, options?: ResolveImportFromPackageOptions): Promise<string | undefined>;

@@ -8,4 +8,5 @@ import path from 'path';

/**
* Resolves a requested import path from a package located at the given path. Gives prescedence
* to browser/esm options. This may change in a future iteration.
* Resolves a requested import path from a package located at the given path. Gives precedence
* to browser/esm options, but will fall back to discover exact path matches, and will fall back
* to source paths (lib to src translation) if the option is provided.
*/

@@ -24,2 +25,6 @@ export async function resolveImportFromPackagePath(packagePath, requestedPath, options = {}) {

export async function resolveImportFromPackage(packagePath, packageDefinition, importPath, options = {}) {
// If the caller passes a period in for the import path, assume it's a package import.
if (importPath === '.') {
importPath = undefined;
}
const originalPackagePath = packagePath;

@@ -33,2 +38,3 @@ const fullRequestedPath = path.join(packagePath, importPath || '');

packagePath = fullRequestedPath;
importPath = undefined;
}

@@ -53,15 +59,13 @@ }

}
if (!importPath) {
candidates.push(packageDefinition.module);
candidates.push(packageDefinition.main);
}
else {
if (!importPath) {
candidates.push(packageDefinition.module);
candidates.push(packageDefinition.main);
}
else {
candidates.push(importPath);
}
// Fallback to index.js
if (!packageDefinition.main && !packageDefinition.module && !importPath) {
candidates.push('index.js');
}
candidates.push(importPath);
}
// Fallback to index.js
if (!packageDefinition.main && !packageDefinition.module && !importPath) {
candidates.push('index.js');
}
// If the package has browser re-mappings, respect them.

@@ -68,0 +72,0 @@ let { browser } = packageDefinition;

@@ -8,8 +8,15 @@ import { getExportPathFromEntry } from './getExportPathFromEntry.js';

if (exports) {
for (const entry of Object.values(exports)) {
const entryPath = getExportPathFromEntry(entry);
if (entryPath) {
entries.add(cleanEntry(entryPath));
if (typeof exports === 'object') {
for (const [key, entry] of Object.entries(exports)) {
if (key.indexOf('*') < 0) {
const entryPath = getExportPathFromEntry(entry);
if (entryPath) {
entries.add(cleanEntry(entryPath));
}
}
}
}
else if (typeof exports === 'string') {
entries.add(cleanEntry(exports));
}
}

@@ -16,0 +23,0 @@ else if (typeof browser === 'string') {

@@ -88,3 +88,16 @@ import { describe, it, expect } from '@jest/globals';

});
it('ignores entries with astrisks', () => {
expect(resolvePackageEntries({
exports: {
'.': './lib/index.js',
'./foo/*': './lib/foo.js',
},
})).toEqual(['./lib/index.js']);
});
it('can handle entries with exports as string', () => {
expect(resolvePackageEntries({
exports: './lib/index.js',
})).toEqual(['./lib/index.js']);
});
});
//# sourceMappingURL=resolvePackageEntries.test.js.map
export declare const testScenariosPath: string;
export declare const testProject1Path: string;
export declare const testProject2Path: string;
export declare const testProject3Path: string;
export declare const testProjectFluentPath: string;

@@ -5,0 +6,0 @@ export declare const testUninstalledProjectPath: string;

@@ -6,2 +6,3 @@ import { fileURLToPath } from 'url';

export const testProject2Path = path.join(testScenariosPath, 'test-project-2');
export const testProject3Path = path.join(testScenariosPath, 'test-project-3');
export const testProjectFluentPath = path.join(testScenariosPath, 'test-project-fluent');

@@ -8,0 +9,0 @@ export const testUninstalledProjectPath = path.join(testScenariosPath, 'test-uninstalled-project');

{
"name": "@ms-cloudpack/package-utilities",
"version": "0.12.3",
"version": "0.13.0",
"description": "Utilities for resolving/parsing packages and their imports.",

@@ -19,3 +19,3 @@ "license": "MIT",

"@ms-cloudpack/json-utilities": "^0.0.3",
"@ms-cloudpack/package-overrides": "^0.1.2",
"@ms-cloudpack/package-overrides": "^0.2.0",
"@ms-cloudpack/path-utilities": "^0.5.0",

@@ -22,0 +22,0 @@ "resolve": "^1.22.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

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

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