@ms-cloudpack/esm-stub-utilities
Advanced tools
Comparing version 0.13.23 to 0.14.0
/** | ||
* Given entry/stub paths and cjs export info, generates the esm stub content. | ||
* Given entry/stub paths, generates the esm stub content. | ||
* The stubPath is required to generate the proper import statement. | ||
* namedExports is optional, if present, the given export names will be used, | ||
* but if missing, we'll attempt to require the CJS and extract export info. | ||
*/ | ||
@@ -8,3 +10,4 @@ export declare function generateESMStubFromCJS(options: { | ||
stubPath: string; | ||
namedExports?: string[]; | ||
}): string; | ||
//# sourceMappingURL=generateESMStubFromCJS.d.ts.map |
@@ -8,8 +8,12 @@ import { slash } from '@ms-cloudpack/path-string-parsing'; | ||
/** | ||
* Given entry/stub paths and cjs export info, generates the esm stub content. | ||
* Given entry/stub paths, generates the esm stub content. | ||
* The stubPath is required to generate the proper import statement. | ||
* namedExports is optional, if present, the given export names will be used, | ||
* but if missing, we'll attempt to require the CJS and extract export info. | ||
*/ | ||
export function generateESMStubFromCJS(options) { | ||
const { filePath, stubPath } = options; | ||
const exportInfo = getExportInfo(require(filePath)); | ||
const { filePath, stubPath, namedExports } = options; | ||
const exportInfo = namedExports | ||
? { type: 'object', keys: namedExports } | ||
: getExportInfo(require(filePath)); | ||
const { type: exportType } = exportInfo; | ||
@@ -16,0 +20,0 @@ let relativePath; |
import type { BundleOptions } from '@ms-cloudpack/common-types'; | ||
export type WriteESMStubsOptions = Pick<BundleOptions, 'inputPath' | 'entries'>; | ||
export type WriteESMStubsOptions = Pick<BundleOptions, 'inputPath' | 'entries' | 'unsafeCjsExportNames'>; | ||
//# sourceMappingURL=WriteESMStubsOptions.d.ts.map |
@@ -13,3 +13,3 @@ import { slash } from '@ms-cloudpack/path-string-parsing'; | ||
export async function writeESMStubs(options) { | ||
const { inputPath, entries } = options; | ||
const { inputPath, entries, unsafeCjsExportNames } = options; | ||
const result = { | ||
@@ -31,2 +31,3 @@ newEntries: {}, | ||
let stubContent = ''; | ||
const namedExports = unsafeCjsExportNames ? (unsafeCjsExportNames[entryKey] ?? []) : undefined; | ||
if (path.extname(entryPath).toLowerCase() === '.json') { | ||
@@ -36,3 +37,3 @@ stubContent = await generateESMStubFromJSON({ filePath }); | ||
else { | ||
stubContent = generateESMStubFromCJS({ filePath, stubPath }); | ||
stubContent = generateESMStubFromCJS({ filePath, stubPath, namedExports }); | ||
} | ||
@@ -39,0 +40,0 @@ // Attempt to write it to disk. |
@@ -12,3 +12,3 @@ import { getAdjustedTimeout } from '@ms-cloudpack/environment'; | ||
export async function writeESMStubsInWorker(options) { | ||
const { inputPath, entries } = options; | ||
const { inputPath, entries, unsafeCjsExportNames } = options; | ||
// Mapping from entry key to entry absolute path | ||
@@ -54,2 +54,3 @@ const nonStubbedEntries = {}; | ||
entries: entriesToMaybeStub, | ||
unsafeCjsExportNames, | ||
}; | ||
@@ -56,0 +57,0 @@ try { |
{ | ||
"name": "@ms-cloudpack/esm-stub-utilities", | ||
"version": "0.13.23", | ||
"version": "0.14.0", | ||
"description": "Generates ESM stubs for CommonJS entry files.", | ||
@@ -17,6 +17,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"@ms-cloudpack/common-types": "^0.23.7", | ||
"@ms-cloudpack/common-types": "^0.24.0", | ||
"@ms-cloudpack/environment": "^0.1.1", | ||
"@ms-cloudpack/json-utilities": "^0.1.9", | ||
"@ms-cloudpack/package-utilities": "^11.0.1", | ||
"@ms-cloudpack/json-utilities": "^0.1.10", | ||
"@ms-cloudpack/package-utilities": "^11.1.0", | ||
"@ms-cloudpack/path-string-parsing": "^1.2.6", | ||
@@ -23,0 +23,0 @@ "@ms-cloudpack/worker-pool": "^0.3.2", |
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
126440
1086
- Removed@ms-cloudpack/common-types@0.23.7(transitive)