@ms-cloudpack/package-utilities
Advanced tools
Comparing version 0.15.0 to 0.16.0
@@ -5,3 +5,18 @@ { | ||
{ | ||
"date": "Wed, 12 Oct 2022 08:10:23 GMT", | ||
"date": "Wed, 12 Oct 2022 21:49:36 GMT", | ||
"tag": "@ms-cloudpack/package-utilities_v0.16.0", | ||
"version": "0.16.0", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"author": "dzearing@microsoft.com", | ||
"package": "@ms-cloudpack/package-utilities", | ||
"commit": "48a31cb7c0bbd9095fc246a95b453ed49acf7626", | ||
"comment": "Tweaking how exports are generated for browser entries, fixing a variety of other issues." | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Wed, 12 Oct 2022 08:10:43 GMT", | ||
"tag": "@ms-cloudpack/package-utilities_v0.15.0", | ||
@@ -8,0 +23,0 @@ "version": "0.15.0", |
# Change Log - @ms-cloudpack/package-utilities | ||
This log was last generated on Wed, 12 Oct 2022 08:10:23 GMT and should not be manually modified. | ||
This log was last generated on Wed, 12 Oct 2022 21:49:36 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## 0.16.0 | ||
Wed, 12 Oct 2022 21:49:36 GMT | ||
### Minor changes | ||
- Tweaking how exports are generated for browser entries, fixing a variety of other issues. (dzearing@microsoft.com) | ||
## 0.15.0 | ||
Wed, 12 Oct 2022 08:10:23 GMT | ||
Wed, 12 Oct 2022 08:10:43 GMT | ||
@@ -11,0 +19,0 @@ ### Minor changes |
@@ -12,12 +12,23 @@ import path from 'path'; | ||
const isInternal = !isExternalPackage(packagePath); | ||
const sourcePath = await resolveImportFromPackagePath(packagePath, entryPath || importPath, { | ||
packages, | ||
preferSource: isInternal, | ||
ignoreExportsMap: true, | ||
}); | ||
const intermediatePath = sourcePath && sourceToIntermediatePath(sourcePath); | ||
let sourcePath; | ||
let intermediatePath; | ||
let resolvedTypesPath = typesPath; | ||
// If at this point we haven't found what we're looking for, throw an exception. | ||
if (isInternal) { | ||
sourcePath = await resolveImportFromPackagePath(packagePath, entryPath || importPath, { | ||
packages, | ||
preferSource: isInternal, | ||
ignoreExportsMap: true, | ||
}); | ||
intermediatePath = sourcePath && sourceToIntermediatePath(sourcePath); | ||
} | ||
else { | ||
intermediatePath = await resolveImportFromPackagePath(packagePath, entryPath || importPath, { | ||
packages, | ||
preferSource: false, | ||
ignoreExportsMap: true, | ||
}); | ||
} | ||
// If at this point we haven't found what we're looking for, don't change anything. | ||
if (!intermediatePath) { | ||
throw new Error(`Unable to resolve import path ${importPath} in package ${packagePath}`); | ||
return; | ||
} | ||
@@ -33,3 +44,13 @@ // Discover d.ts if available. | ||
} | ||
const exportSet = (exports[importPath] || (exports[importPath] = {})); | ||
const safeImportPath = safeRelativePath(importPath || '.'); | ||
let exportSet = exports[safeImportPath]; | ||
// If the value of this path is a string, convert it to an object. | ||
if (typeof exportSet === 'string') { | ||
exportSet = exports[safeImportPath] = { | ||
default: exportSet, | ||
}; | ||
} | ||
else if (!exportSet) { | ||
exportSet = exports[safeImportPath] = {}; | ||
} | ||
if (resolvedTypesPath) { | ||
@@ -36,0 +57,0 @@ exportSet.types = safeRelativePath(resolvedTypesPath); |
import { describe, expect, it } from '@jest/globals'; | ||
import { addExportsMapEntry } from './addExportsMapEntry.js'; | ||
import { testProject1Path } from './testPaths.js'; | ||
import { createTestFileStructure } from '@ms-cloudpack/test-utilities'; | ||
import path from 'path'; | ||
describe('addExportsMapEntry', () => { | ||
@@ -22,7 +24,22 @@ it('can add an entry to an empty exports map', async () => { | ||
}); | ||
it(' can add an entry to an existing exports map', async () => { | ||
it('can add a non-safe import path', async () => { | ||
const exportsMap = {}; | ||
await addExportsMapEntry({ | ||
exports: exportsMap, | ||
packagePath: testProject1Path, | ||
importPath: 'lib/foo-sub1', | ||
}); | ||
expect(exportsMap).toMatchInlineSnapshot(` | ||
{ | ||
"./lib/foo-sub1": { | ||
"default": "./lib/foo-sub1.js", | ||
"source": "./src/foo-sub1.ts", | ||
"types": "./lib/foo-sub1.d.ts", | ||
}, | ||
} | ||
`); | ||
}); | ||
it('can add an entry to an existing exports map', async () => { | ||
const exportsMap = { | ||
'.': { | ||
default: './lib/index.js', | ||
}, | ||
'.': './lib/index.js', | ||
}; | ||
@@ -36,5 +53,3 @@ await addExportsMapEntry({ | ||
{ | ||
".": { | ||
"default": "./lib/index.js", | ||
}, | ||
".": "./lib/index.js", | ||
"./lib/foo-sub1": { | ||
@@ -48,11 +63,27 @@ "default": "./lib/foo-sub1.js", | ||
}); | ||
it('can throw when the entry does not exist', async () => { | ||
it('can add an entry to an external package like the "debug" package', async () => { | ||
const exportsMap = {}; | ||
await expect(addExportsMapEntry({ | ||
const testPath = await createTestFileStructure({ | ||
'node_modules/debug/package.json': { | ||
name: 'debug', | ||
main: './src/index.js', | ||
browser: './src/browser.js', | ||
}, | ||
'node_modules/debug/src/index.js': '', | ||
'node_modules/debug/src/browser.js': '', | ||
}); | ||
await addExportsMapEntry({ | ||
exports: exportsMap, | ||
packagePath: testProject1Path, | ||
importPath: './lib/foo-sub2', | ||
})).rejects.toThrow(); | ||
packagePath: path.join(testPath, 'node_modules/debug'), | ||
importPath: '.', | ||
}); | ||
expect(exportsMap).toMatchInlineSnapshot(` | ||
{ | ||
".": { | ||
"default": "./src/browser.js", | ||
}, | ||
} | ||
`); | ||
}); | ||
}); | ||
//# sourceMappingURL=addExportsMapEntry.test.js.map |
@@ -9,4 +9,13 @@ import { PackageDefinitions } from './PackageDefinitions.js'; | ||
} | ||
return packageDefinition.exports || (await createExportsMap(packagePath, options)); | ||
let { exports } = packageDefinition; | ||
// If the package definition doesn't have a full object-based exports map, create one. | ||
if (typeof exports === 'string') { | ||
exports = { | ||
'.': { | ||
default: exports, | ||
}, | ||
}; | ||
} | ||
return exports || (await createExportsMap(packagePath, options)); | ||
} | ||
//# sourceMappingURL=getExportsMap.js.map |
@@ -12,5 +12,5 @@ export { PackageDefinitions, type PackageDefinitionTransform } from './PackageDefinitions.js'; | ||
export { resolveImportFromPackage, resolveImportFromPackagePath, type ResolveImportFromPackageOptions, } from './resolveImportFromPackagePath.js'; | ||
export { resolvePackageEntries } from './resolvePackageEntries.js'; | ||
export { getPackageEntries } from './getPackageEntries.js'; | ||
export { detectModuleType, type ModuleType } from './detectModuleType.js'; | ||
export { isExternalPackage } from './isExternalPackage.js'; | ||
export { parseImportString } from './parseImportString.js'; | ||
export { parseImportString, type ImportStringResult } from './parseImportString.js'; |
@@ -16,3 +16,3 @@ // Package definition parsing | ||
export { resolveImportFromPackage, resolveImportFromPackagePath, } from './resolveImportFromPackagePath.js'; | ||
export { resolvePackageEntries } from './resolvePackageEntries.js'; | ||
export { getPackageEntries } from './getPackageEntries.js'; | ||
// Other package utilities | ||
@@ -19,0 +19,0 @@ export { detectModuleType } from './detectModuleType.js'; |
@@ -0,9 +1,10 @@ | ||
import { safeRelativePath } from './safeRelativePath.js'; | ||
export function parseImportString(importString = '') { | ||
const matches = importString.match(/[/]?(@[-_a-z-A-Z0-9.]+\/[-_a-z-A-Z0-9.]+|[-_a-zA-Z0-9.]+)(@([-_a-zA-Z-0-9.]+))?(\/([-_/a-zA-Z0-9.]+))?/) || []; | ||
return { | ||
packageName: matches[1] || undefined, | ||
version: matches[3] || undefined, | ||
importPath: matches[5] || undefined, | ||
packageName: matches[1] || '.', | ||
version: matches[3] || '', | ||
importPath: safeRelativePath(matches[5]), | ||
}; | ||
} | ||
//# sourceMappingURL=parseImportString.js.map |
@@ -5,3 +5,3 @@ import { describe, it, expect } from '@jest/globals'; | ||
it(`can parse a package import`, () => { | ||
expect(parseImportString('package')).toEqual({ packageName: 'package', version: undefined, importPath: undefined }); | ||
expect(parseImportString('package')).toEqual({ packageName: 'package', version: '', importPath: '.' }); | ||
}); | ||
@@ -11,4 +11,4 @@ it(`can parse a package import with a scope`, () => { | ||
packageName: '@scope/package', | ||
version: undefined, | ||
importPath: undefined, | ||
version: '', | ||
importPath: '.', | ||
}); | ||
@@ -19,4 +19,4 @@ }); | ||
packageName: '@scope/package', | ||
version: undefined, | ||
importPath: 'path/to/thing', | ||
version: '', | ||
importPath: './path/to/thing', | ||
}); | ||
@@ -28,3 +28,3 @@ }); | ||
version: '1234567890.1234567890.1234567890-abcdeABCDE', | ||
importPath: 'path/to/thing', | ||
importPath: './path/to/thing', | ||
}); | ||
@@ -35,4 +35,4 @@ }); | ||
packageName: 'package_name', | ||
version: undefined, | ||
importPath: undefined, | ||
version: '', | ||
importPath: '.', | ||
}); | ||
@@ -43,4 +43,4 @@ }); | ||
packageName: 'package-name', | ||
version: undefined, | ||
importPath: undefined, | ||
version: '', | ||
importPath: '.', | ||
}); | ||
@@ -47,0 +47,0 @@ }); |
@@ -6,3 +6,3 @@ import { slash } from '@ms-cloudpack/path-utilities'; | ||
export function safeRelativePath(originalPath) { | ||
if (!originalPath) { | ||
if (!originalPath || originalPath.length === 0 || originalPath === '.') { | ||
return '.'; | ||
@@ -9,0 +9,0 @@ } |
import { describe, it, expect } from '@jest/globals'; | ||
import { safeRelativePath } from './safeRelativePath.js'; | ||
describe('safeRelativePath', () => { | ||
it('can handle undefined', () => { | ||
it('can handle default import paths', () => { | ||
expect(safeRelativePath(undefined)).toEqual('.'); | ||
expect(safeRelativePath('')).toEqual('.'); | ||
expect(safeRelativePath('.')).toEqual('.'); | ||
}); | ||
@@ -7,0 +9,0 @@ it('can handle an absolute path', () => { |
{ | ||
"name": "@ms-cloudpack/package-utilities", | ||
"version": "0.15.0", | ||
"version": "0.16.0", | ||
"description": "Utilities for resolving/parsing packages and their imports.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
191351
116
3085