@ms-cloudpack/bundler 0.17.36 → 0.18.0
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/allBundlers.d.ts +2 -2
- package/lib/allBundlers.d.ts.map +1 -1
- package/lib/allBundlers.js.map +1 -1
- package/lib/bundle.d.ts +9 -1
- package/lib/bundle.d.ts.map +1 -1
- package/lib/bundle.js +25 -32
- package/lib/bundle.js.map +1 -1
- package/lib/chooseBundler.d.ts +3 -3
- package/lib/chooseBundler.d.ts.map +1 -1
- package/lib/chooseBundler.js +1 -1
- package/lib/chooseBundler.js.map +1 -1
- package/lib/getEntriesMapFromPackage.d.ts +1 -1
- package/lib/getEntriesMapFromPackage.d.ts.map +1 -1
- package/lib/getEntriesMapFromPackage.js +8 -8
- package/lib/getEntriesMapFromPackage.js.map +1 -1
- package/package.json +9 -9
package/lib/allBundlers.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const allBundlers: Record<string, () => Promise<
|
|
1
|
+
import type { BundlerPlugin } from '@ms-cloudpack/bundler-types';
|
|
2
|
+
export declare const allBundlers: Record<string, () => Promise<BundlerPlugin>>;
|
|
3
3
|
//# sourceMappingURL=allBundlers.d.ts.map
|
package/lib/allBundlers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allBundlers.d.ts","sourceRoot":"","sources":["../src/allBundlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"allBundlers.d.ts","sourceRoot":"","sources":["../src/allBundlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAEjE,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,CAIpE,CAAC"}
|
package/lib/allBundlers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"allBundlers.js","sourceRoot":"","sources":["../src/allBundlers.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"allBundlers.js","sourceRoot":"","sources":["../src/allBundlers.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAiD;IACvE,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,qCAAqC,CAAC,CAAC,CAAC,OAAO;IACjF,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,kCAAkC,CAAC,CAAC,CAAC,OAAO;IAC3E,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,MAAM,CAAC,sCAAsC,CAAC,CAAC,CAAC,OAAO;CACpF,CAAC","sourcesContent":["import type { BundlerPlugin } from '@ms-cloudpack/bundler-types';\n\nexport const allBundlers: Record<string, () => Promise<BundlerPlugin>> = {\n rollup: async () => (await import('@ms-cloudpack/bundler-plugin-rollup')).default,\n ori: async () => (await import('@ms-cloudpack/bundler-plugin-ori')).default,\n webpack: async () => (await import('@ms-cloudpack/bundler-plugin-webpack')).default,\n};\n"]}
|
package/lib/bundle.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CloudpackConfig } from '@ms-cloudpack/config-types';
|
|
2
|
-
import type { BundleOptions, BundleResult } from '@ms-cloudpack/bundler-types';
|
|
2
|
+
import type { BundleOptions, BundleResult, BundlerPluginResult } from '@ms-cloudpack/bundler-types';
|
|
3
3
|
/**
|
|
4
4
|
* Abstracted consumer input to the bundle method for the appropriate bundler. Provides a more
|
|
5
5
|
* advanced api surface.
|
|
@@ -7,4 +7,12 @@ import type { BundleOptions, BundleResult } from '@ms-cloudpack/bundler-types';
|
|
|
7
7
|
export declare function bundle(options: BundleOptions, context: {
|
|
8
8
|
config: CloudpackConfig;
|
|
9
9
|
}): Promise<BundleResult>;
|
|
10
|
+
/**
|
|
11
|
+
* Wrapper for bundling and normalizing the result. This is separated to allow sharing the logic
|
|
12
|
+
* between normal `bundle()` calls and `result.rebuild()` (if provided by the bundler plugin),
|
|
13
|
+
* and helps with testing.
|
|
14
|
+
*/
|
|
15
|
+
export declare function bundleInternal(pluginBundle: () => Promise<BundlerPluginResult>, options: BundleOptions & {
|
|
16
|
+
bundlerName: string;
|
|
17
|
+
}): Promise<BundleResult>;
|
|
10
18
|
//# sourceMappingURL=bundle.d.ts.map
|
package/lib/bundle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAiB,aAAa,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAiB,aAAa,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAMnH;;;GAGG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE;IAAE,MAAM,EAAE,eAAe,CAAA;CAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CA2ChH;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,OAAO,CAAC,mBAAmB,CAAC,EAChD,OAAO,EAAE,aAAa,GAAG;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,GAC/C,OAAO,CAAC,YAAY,CAAC,CA4BvB"}
|
package/lib/bundle.js
CHANGED
|
@@ -43,44 +43,37 @@ export async function bundle(options, context) {
|
|
|
43
43
|
? await detectModuleType(path.resolve(options.inputPath, firstSourceEntry))
|
|
44
44
|
: undefined;
|
|
45
45
|
const isTypescript = firstSourceEntry ? typescriptExtensions.includes(path.extname(firstSourceEntry)) : false;
|
|
46
|
-
const { outputPath = options.inputPath } = options;
|
|
47
46
|
const bundler = await chooseBundler({ bundlerType: options.bundlerType, moduleType, isTypescript });
|
|
48
|
-
|
|
47
|
+
const bundleFunc = () => bundler.bundle(options, { ...context, moduleType });
|
|
48
|
+
return bundleInternal(bundleFunc, { ...options, bundlerName: bundler.name });
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Wrapper for bundling and normalizing the result. This is separated to allow sharing the logic
|
|
52
|
+
* between normal `bundle()` calls and `result.rebuild()` (if provided by the bundler plugin),
|
|
53
|
+
* and helps with testing.
|
|
54
|
+
*/
|
|
55
|
+
export async function bundleInternal(pluginBundle, options) {
|
|
56
|
+
let pluginResult = undefined;
|
|
49
57
|
try {
|
|
50
|
-
|
|
58
|
+
pluginResult = await pluginBundle();
|
|
51
59
|
}
|
|
52
60
|
catch (e) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
inputPath: options.inputPath,
|
|
56
|
-
entries: options.entries,
|
|
57
|
-
errors: [
|
|
58
|
-
{
|
|
59
|
-
text: `Unexpected exception: ${e}`,
|
|
60
|
-
},
|
|
61
|
-
],
|
|
61
|
+
pluginResult = {
|
|
62
|
+
errors: [{ text: `Exception while bundling: ${e}` }],
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
for (const outputFile of result.outputFiles || []) {
|
|
77
|
-
outputFile.outputPath = path.relative(outputPath, outputFile.outputPath);
|
|
65
|
+
const { rawInput, rawOutput, rebuild, ...rest } = pluginResult || {};
|
|
66
|
+
const { bundlerName, inputPath, entries, outputPath: logOutputPath = inputPath } = options;
|
|
67
|
+
await Promise.all([
|
|
68
|
+
rest.errors?.length && writeJson(path.join(logOutputPath, `${bundlerName}-errors.json`), rest.errors),
|
|
69
|
+
rawInput && writeJson(path.join(logOutputPath, `${bundlerName}-input.json`), rawInput),
|
|
70
|
+
rawOutput && writeJson(path.join(logOutputPath, `${bundlerName}-output.json`), rawOutput),
|
|
71
|
+
]);
|
|
72
|
+
const result = { bundlerName, inputPath, entries, ...rest };
|
|
73
|
+
if (rebuild) {
|
|
74
|
+
// Wrap rebuild with proper result handling
|
|
75
|
+
result.rebuild = () => bundleInternal(rebuild, options);
|
|
78
76
|
}
|
|
79
|
-
return
|
|
80
|
-
bundlerName: bundler.name,
|
|
81
|
-
inputPath: options.inputPath,
|
|
82
|
-
entries: options.entries,
|
|
83
|
-
...result,
|
|
84
|
-
};
|
|
77
|
+
return result;
|
|
85
78
|
}
|
|
86
79
|
//# sourceMappingURL=bundle.js.map
|
package/lib/bundle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAwB,MAAM,4BAA4B,CAAC;AAElE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEtF;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAsB,EAAE,OAAoC;IACvF,MAAM,YAAY,GAAoB,EAAE,CAAC;IAEzC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QAC/B,YAAY,CAAC,IAAI,CAAC;YAChB,IAAI,EA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EAAE,SAAS,CAAC;KAC1F,CAAC,CAAC;IAEH,MAAM,MAAM,GAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC;IAE1E,IAAI,OAAO,EAAE,CAAC;QACZ,2CAA2C;QAC3C,MAAM,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { chooseBundler } from './chooseBundler.js';\nimport { type CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { BundleMessage, BundleOptions, BundleResult, BundlerPluginResult } from '@ms-cloudpack/bundler-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport path from 'path';\nimport { detectModuleType } from '@ms-cloudpack/package-utilities';\nimport { sourceExtensions, typescriptExtensions } from '@ms-cloudpack/path-utilities';\n\n/**\n * Abstracted consumer input to the bundle method for the appropriate bundler. Provides a more\n * advanced api surface.\n */\nexport async function bundle(options: BundleOptions, context: { config: CloudpackConfig }): Promise<BundleResult> {\n const configErrors: BundleMessage[] = [];\n\n if (!options.inputPath?.length) {\n configErrors.push({\n type: 'invalid-input',\n text: 'No input path provided to bundle.',\n });\n } else if (!path.isAbsolute(options.inputPath)) {\n configErrors.push({\n type: 'input-relative',\n text: 'Input path must be absolute.',\n });\n }\n\n if (!Object.keys(options.entries || {}).length) {\n configErrors.push({\n type: 'no-entries',\n text: `No entries provided to bundle at inputPath \"${options.inputPath}\".`,\n });\n } else if (Object.entries(options.entries).some(([k, v]) => path.isAbsolute(k) || path.isAbsolute(v))) {\n configErrors.push({\n type: 'entry-absolute',\n text: `Entry paths must be relative.`,\n });\n }\n\n if (configErrors.length) {\n return { inputPath: options.inputPath, errors: configErrors };\n }\n\n // Choose the bundler type and bundle.\n const firstSourceEntry = Object.values(options.entries).find((fileName) =>\n sourceExtensions.includes(path.extname(fileName)),\n );\n const moduleType = firstSourceEntry\n ? await detectModuleType(path.resolve(options.inputPath, firstSourceEntry))\n : undefined;\n const isTypescript = firstSourceEntry ? typescriptExtensions.includes(path.extname(firstSourceEntry)) : false;\n\n const bundler = await chooseBundler({ bundlerType: options.bundlerType, moduleType, isTypescript });\n const bundleFunc = () => bundler.bundle(options, { ...context, moduleType });\n return bundleInternal(bundleFunc, { ...options, bundlerName: bundler.name });\n}\n\n/**\n * Wrapper for bundling and normalizing the result. This is separated to allow sharing the logic\n * between normal `bundle()` calls and `result.rebuild()` (if provided by the bundler plugin),\n * and helps with testing.\n */\nexport async function bundleInternal(\n pluginBundle: () => Promise<BundlerPluginResult>,\n options: BundleOptions & { bundlerName: string },\n): Promise<BundleResult> {\n let pluginResult: BundlerPluginResult | undefined = undefined;\n\n try {\n pluginResult = await pluginBundle();\n } catch (e) {\n pluginResult = {\n errors: [{ text: `Exception while bundling: ${e}` }],\n };\n }\n\n const { rawInput, rawOutput, rebuild, ...rest } = pluginResult || {};\n const { bundlerName, inputPath, entries, outputPath: logOutputPath = inputPath } = options;\n\n await Promise.all([\n rest.errors?.length && writeJson(path.join(logOutputPath, `${bundlerName}-errors.json`), rest.errors),\n rawInput && writeJson(path.join(logOutputPath, `${bundlerName}-input.json`), rawInput),\n rawOutput && writeJson(path.join(logOutputPath, `${bundlerName}-output.json`), rawOutput),\n ]);\n\n const result: BundleResult = { bundlerName, inputPath, entries, ...rest };\n\n if (rebuild) {\n // Wrap rebuild with proper result handling\n result.rebuild = () => bundleInternal(rebuild, options);\n }\n\n return result;\n}\n"]}
|
package/lib/chooseBundler.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BundlerPlugin } from '@ms-cloudpack/bundler-types';
|
|
2
2
|
import type { ModuleType } from '@ms-cloudpack/package-utilities';
|
|
3
3
|
/**
|
|
4
|
-
* Determines which bundler to use.
|
|
4
|
+
* Determines which bundler plugin to use.
|
|
5
5
|
* @returns A bundler plugin.
|
|
6
6
|
*/
|
|
7
7
|
export declare function chooseBundler(params: {
|
|
8
8
|
bundlerType: string | undefined;
|
|
9
9
|
moduleType: ModuleType;
|
|
10
10
|
isTypescript: boolean;
|
|
11
|
-
}): Promise<
|
|
11
|
+
}): Promise<BundlerPlugin>;
|
|
12
12
|
//# sourceMappingURL=chooseBundler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chooseBundler.d.ts","sourceRoot":"","sources":["../src/chooseBundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"chooseBundler.d.ts","sourceRoot":"","sources":["../src/chooseBundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGlE;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,UAAU,EAAE,UAAU,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;CACvB,GAAG,OAAO,CAAC,aAAa,CAAC,CAazB"}
|
package/lib/chooseBundler.js
CHANGED
package/lib/chooseBundler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chooseBundler.js","sourceRoot":"","sources":["../src/chooseBundler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAInC;IACC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC;IAEpC,IAAI,CAAC,WAAW,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QAC3C,IAAI,UAAU,KAAK,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1C,OAAO,MAAM,MAAM,EAAE,CAAC;QACxB,CAAC;QAED,OAAO,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,OAAO,MAAM,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"chooseBundler.js","sourceRoot":"","sources":["../src/chooseBundler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAInC;IACC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC;IAEpC,IAAI,CAAC,WAAW,IAAI,WAAW,KAAK,MAAM,EAAE,CAAC;QAC3C,IAAI,UAAU,KAAK,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YAC1C,OAAO,MAAM,MAAM,EAAE,CAAC;QACxB,CAAC;QAED,OAAO,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,OAAO,MAAM,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;AAC1C,CAAC","sourcesContent":["import type { BundlerPlugin } from '@ms-cloudpack/bundler-types';\nimport type { ModuleType } from '@ms-cloudpack/package-utilities';\nimport { allBundlers } from './allBundlers.js';\n\n/**\n * Determines which bundler plugin to use.\n * @returns A bundler plugin.\n */\nexport async function chooseBundler(params: {\n bundlerType: string | undefined;\n moduleType: ModuleType;\n isTypescript: boolean;\n}): Promise<BundlerPlugin> {\n const { bundlerType, moduleType, isTypescript } = params;\n const { rollup, ori } = allBundlers;\n\n if (!bundlerType || bundlerType === 'auto') {\n if (moduleType === 'cjs' && !isTypescript) {\n return await rollup();\n }\n\n return await ori();\n }\n\n return await allBundlers[bundlerType]();\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type CloudpackConfig } from '@ms-cloudpack/config-types';
|
|
2
1
|
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
2
|
+
import { type CloudpackConfig } from '@ms-cloudpack/config-types';
|
|
3
3
|
/**
|
|
4
4
|
* Gets the entries map for a given package. An entries map is different from an exports map in that
|
|
5
5
|
* the keys are relative paths to where the output should live, rather than how the entry is imported.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntriesMapFromPackage.d.ts","sourceRoot":"","sources":["../src/getEntriesMapFromPackage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getEntriesMapFromPackage.d.ts","sourceRoot":"","sources":["../src/getEntriesMapFromPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAOlE;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE;IACP,SAAS,EAAE,MAAM,CAAC;CACnB,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;IAClC,MAAM,EAAE,eAAe,CAAC;CACzB,GACA,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAgCjC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { flattenExportsMap, getExportsMap, isExternalPackage } from '@ms-cloudpack/package-utilities';
|
|
2
1
|
import {} from '@ms-cloudpack/config-types';
|
|
2
|
+
import { flattenExportsMap, getExportsMap, isExternalPackage } from '@ms-cloudpack/package-utilities';
|
|
3
|
+
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
3
4
|
import { intermediateToSourcePath, sourceExtensions } from '@ms-cloudpack/path-utilities';
|
|
4
|
-
import { isValidBundleEntry } from './isValidBundleEntry.js';
|
|
5
5
|
import path from 'path';
|
|
6
|
-
import {
|
|
6
|
+
import { isValidBundleEntry } from './isValidBundleEntry.js';
|
|
7
7
|
/**
|
|
8
8
|
* Gets the entries map for a given package. An entries map is different from an exports map in that
|
|
9
9
|
* the keys are relative paths to where the output should live, rather than how the entry is imported.
|
|
@@ -31,25 +31,25 @@ export async function getEntriesMapFromPackage(options, context) {
|
|
|
31
31
|
return Object.fromEntries(Object.entries(flattenedMap)
|
|
32
32
|
.filter(([, value]) => isValidBundleEntry(value))
|
|
33
33
|
.map(([key, value]) => [
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
toNormalizedEntryKey(value),
|
|
35
|
+
toNormalizedRelativePath(inputPath, sourceExportsMap?.[key] || value),
|
|
36
36
|
]));
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* When we derive keys, we want to preserve unknown script extensions. For others, remove them as the bundler
|
|
40
40
|
* will add back `'.js'` for us in the output.
|
|
41
41
|
*/
|
|
42
|
-
function
|
|
42
|
+
function toNormalizedEntryKey(entry) {
|
|
43
43
|
const extension = path.extname(entry);
|
|
44
44
|
if (sourceExtensions.includes(extension)) {
|
|
45
45
|
return entry.slice(0, -extension.length);
|
|
46
46
|
}
|
|
47
47
|
return entry;
|
|
48
48
|
}
|
|
49
|
-
function
|
|
49
|
+
function toNormalizedRelativePath(inputPath, entry) {
|
|
50
50
|
if (path.isAbsolute(entry)) {
|
|
51
51
|
entry = path.relative(inputPath, entry);
|
|
52
52
|
}
|
|
53
|
-
return
|
|
53
|
+
return normalizeRelativePath(entry);
|
|
54
54
|
}
|
|
55
55
|
//# sourceMappingURL=getEntriesMapFromPackage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEntriesMapFromPackage.js","sourceRoot":"","sources":["../src/getEntriesMapFromPackage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getEntriesMapFromPackage.js","sourceRoot":"","sources":["../src/getEntriesMapFromPackage.ts"],"names":[],"mappings":"AACA,O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AED,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC;SACzB,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;SAChD,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC;QACrB,oBAAoB,CAAC,KAAK,CAAC;QAC3B,wBAAwB,CAAC,SAAS,EAAE,gBAAgB,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC;KACtE,CAAC,CACL,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,oBAAoB,CAAC,KAAa;IACzC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC;QACzC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,wBAAwB,CAAC,SAAiB,EAAE,KAAa;IAChE,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { type CloudpackConfig } from '@ms-cloudpack/config-types';\nimport { flattenExportsMap, getExportsMap, isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { intermediateToSourcePath, sourceExtensions } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { isValidBundleEntry } from './isValidBundleEntry.js';\n\n/**\n * Gets the entries map for a given package. An entries map is different from an exports map in that\n * the keys are relative paths to where the output should live, rather than how the entry is imported.\n * The data structure is used for bundler config; not for resolution of imports.\n */\nexport async function getEntriesMapFromPackage(\n options: {\n inputPath: string;\n },\n context: {\n packages: PackageDefinitionsCache;\n config: CloudpackConfig;\n },\n): Promise<Record<string, string>> {\n const { inputPath } = options;\n const isInternal = !isExternalPackage(inputPath);\n const exportsMap = await getExportsMap({ packagePath: inputPath }, context);\n const flattenedMap = flattenExportsMap(exportsMap);\n let sourceExportsMap: Record<string, string>;\n\n // The flattened map values tell us what physical files will show up in the import map on the page. We use these\n // as the keys for the entries map, which results in physical file output from the bundler.\n\n // For internal packages, we want the values (the inputs to the each entry) to use source paths if available. To\n // get these, we can either derive from exports map \"source\" entries, or if those are not available, we can attempt\n // to derive source paths from intermediate paths.\n\n if (isInternal) {\n sourceExportsMap = flattenExportsMap(exportsMap, { conditions: ['source'], requiredConditions: ['source'] });\n\n for (const [key, value] of Object.entries(flattenedMap)) {\n if (!sourceExportsMap[key]) {\n sourceExportsMap[key] = intermediateToSourcePath(value, inputPath) || value;\n }\n }\n }\n\n return Object.fromEntries(\n Object.entries(flattenedMap)\n .filter(([, value]) => isValidBundleEntry(value))\n .map(([key, value]) => [\n toNormalizedEntryKey(value),\n toNormalizedRelativePath(inputPath, sourceExportsMap?.[key] || value),\n ]),\n );\n}\n\n/**\n * When we derive keys, we want to preserve unknown script extensions. For others, remove them as the bundler\n * will add back `'.js'` for us in the output.\n */\nfunction toNormalizedEntryKey(entry: string): string {\n const extension = path.extname(entry);\n if (sourceExtensions.includes(extension)) {\n return entry.slice(0, -extension.length);\n }\n\n return entry;\n}\n\nfunction toNormalizedRelativePath(inputPath: string, entry: string): string {\n if (path.isAbsolute(entry)) {\n entry = path.relative(inputPath, entry);\n }\n\n return normalizeRelativePath(entry);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "An abstraction to bundle source code.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@ms-cloudpack/json-utilities": "^0.1.4",
|
|
18
|
-
"@ms-cloudpack/bundler-plugin-ori": "^0.
|
|
19
|
-
"@ms-cloudpack/bundler-plugin-rollup": "^0.
|
|
20
|
-
"@ms-cloudpack/bundler-plugin-webpack": "^0.
|
|
21
|
-
"@ms-cloudpack/bundler-types": "^0.
|
|
22
|
-
"@ms-cloudpack/config": "^0.17.
|
|
18
|
+
"@ms-cloudpack/bundler-plugin-ori": "^0.15.0",
|
|
19
|
+
"@ms-cloudpack/bundler-plugin-rollup": "^0.11.0",
|
|
20
|
+
"@ms-cloudpack/bundler-plugin-webpack": "^0.2.0",
|
|
21
|
+
"@ms-cloudpack/bundler-types": "^0.25.0",
|
|
22
|
+
"@ms-cloudpack/config": "^0.17.32",
|
|
23
23
|
"@ms-cloudpack/config-types": "^0.5.1",
|
|
24
|
-
"@ms-cloudpack/package-utilities": "^5.11.
|
|
25
|
-
"@ms-cloudpack/path-string-parsing": "^1.
|
|
26
|
-
"@ms-cloudpack/path-utilities": "^2.
|
|
24
|
+
"@ms-cloudpack/package-utilities": "^5.11.1",
|
|
25
|
+
"@ms-cloudpack/path-string-parsing": "^1.2.0",
|
|
26
|
+
"@ms-cloudpack/path-utilities": "^2.6.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@ms-cloudpack/eslint-plugin-internal": "*",
|