@ms-cloudpack/bundler 0.25.33 → 0.26.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/README.md CHANGED
@@ -1,48 +1,12 @@
1
1
  # @ms-cloudpack/bundler
2
2
 
3
- This library provides an abstraction on bundling a package, assuming that the package is conformant.
3
+ This library provides Cloudpack's implementation of an abstraction on bundling a package, assuming that the package is conformant.
4
4
 
5
5
  Rather than directly depending on Webpack, rollup, or esbuild with large amounts of custom configuration, having an abstraction around bundling provides constraints around having common inputs/outputs.
6
6
 
7
7
  This enforces the code follow consistent constraints, while also ensuring the output can be consumed in the browser or in node depending on supported environments.
8
8
 
9
- Abstraction also allows us to use the right tool for the job. The right tool depends on priorities and capabilities. For dev builds we want the fastest tool, while for production we want optimal output. For library mode builds on commonjs only packages, esbuild doesn't emit named exports while rollup does. Maybe later esbuild will address that issue, so we can adjust the regulation logic accordingly.
10
-
11
- ## Usage
12
-
13
- ### `async function bundlePackage(options)`
14
-
15
- ```tsx
16
- import { bundlePackage } from '@ms-cloudpack/bundler';
17
-
18
- async function start() {
19
- const result = await bundlePackage({
20
- packagePath: process.cwd(),
21
- outputPath: path.join(process.cwd(), 'dist'),
22
- outputType: 'library',
23
- });
24
-
25
- console.log(result);
26
- }
27
-
28
- start();
29
- ```
30
-
31
- ### `bundlePackage` options
32
-
33
- | Name | Type | Description |
34
- | ----------- | ------------------------------ | ------------------------------------------------------------ |
35
- | packagePath | string | Path to the package root where package.json lives. |
36
- | force | boolean | Bypasses the cache to create bundles. |
37
- | hashFrom | `"package-version"` \| `"git"` | Determines how the cache key is computed for bundle results. |
38
- | output | `"library"` \| `"app"` |
39
-
40
- ### Return object
41
-
42
- | Name | Type | Description |
43
- | --------- | ---- | ----------- |
44
- | stats |
45
- | outputMap |
9
+ Abstraction also allows us to use the right tool for the job. The right tool depends on priorities and capabilities. For dev builds we want the fastest tool, while for production we want optimal output.
46
10
 
47
11
  ## Details
48
12
 
@@ -52,24 +16,8 @@ The Cloudpack bundler abstraction is simple and constrained on purpose:
52
16
  2. Emits standard ESM bundle.
53
17
  3. Leverages package.json and convention as much as possible:
54
18
 
55
- This library has only 2 output modes:
56
-
57
- - library mode - produces a bundle of source which externalizes dependencies and is consumable by the target (browser or node) which
58
- can resolve the dependencies through an import maps in the browser or through module resolution in node. The source is unminified.
59
- - production mode - produces a bundle of source which includes dependencies and is also similarly consumed.
60
-
61
- ### Package requirements
62
-
63
- #### Discovering entry points
64
-
65
- Entry points are discovered by analyzing the package.json. This ensures only explicit entries are bundled.
66
-
67
- ### ESM output
68
-
69
- ### Considerations
70
-
71
- #### Leverage existing task runners
72
-
73
- Under the hood, if we want to separate the process into multiple steps, we may consider using task helpers like `just-scripts` or `heft` to execute things in the right order. This might help
19
+ There are three output modes:
74
20
 
75
- #### Splitting the "bundle" abstraction into pre/bundle/post steps
21
+ - library mode - produces a bundle of source which externalizes dependencies and is directly consumable by the target (browser or node), which can resolve the dependencies through an import map in the browser or through module resolution in node. The source is unminified.
22
+ - production mode - produces a bundle of minified source which includes dependencies and is also similarly consumed.
23
+ - development mode - like production mode, but not minified.
@@ -1 +1 @@
1
- {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACb,OAAO,EACP,YAAY,EACZ,aAAa,EACb,eAAe,EAEhB,MAAM,4BAA4B,CAAC;AAOpC;;;GAGG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CA0FlH;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,EAC1C,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,eAAe,CAAC,GAClG,OAAO,CAAC,YAAY,CAAC,CAgDvB"}
1
+ {"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACb,OAAO,EACP,YAAY,EACZ,aAAa,EACb,eAAe,EAEhB,MAAM,4BAA4B,CAAC;AAOpC;;;GAGG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CA2FlH;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,YAAY,EAAE,MAAM,OAAO,CAAC,aAAa,CAAC,EAC1C,OAAO,EAAE,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,eAAe,CAAC,GAClG,OAAO,CAAC,YAAY,CAAC,CAgDvB"}
package/lib/bundle.js CHANGED
@@ -2,7 +2,7 @@ import { chooseBundler } from './chooseBundler.js';
2
2
  import { writeJson } from '@ms-cloudpack/json-utilities';
3
3
  import path from 'path';
4
4
  import { detectModuleType } from '@ms-cloudpack/package-utilities';
5
- import { sourceExtensions, typescriptExtensions } from '@ms-cloudpack/path-utilities';
5
+ import { jsxExtensions, sourceExtensions, typescriptExtensions } from '@ms-cloudpack/path-utilities';
6
6
  import { allBundlers } from './allBundlers.js';
7
7
  /**
8
8
  * Abstracted consumer input to the bundle method for the appropriate bundler. Provides a more
@@ -58,11 +58,11 @@ export async function bundle(options, context) {
58
58
  // Choose the bundler type and bundle.
59
59
  let moduleType;
60
60
  let isTypescript = false;
61
+ let isJsx = false;
61
62
  for (const fileName of Object.values(options.entries)) {
62
63
  const ext = path.extname(fileName);
63
- if (typescriptExtensions.includes(ext)) {
64
- isTypescript = true;
65
- }
64
+ isTypescript ||= typescriptExtensions.includes(ext);
65
+ isJsx ||= jsxExtensions.includes(ext);
66
66
  // Check the module type of each entry, unless we've already found a cjs or amd file.
67
67
  if (!moduleType && sourceExtensions.includes(ext)) {
68
68
  const sourceType = await detectModuleType(path.resolve(options.inputPath, fileName));
@@ -81,7 +81,7 @@ export async function bundle(options, context) {
81
81
  targetEnvironment: options.targetEnvironment,
82
82
  defaultBundler: context.config.defaultBundler,
83
83
  });
84
- const bundleFunc = () => bundler.bundle(options, { ...context, moduleType, isTypescript });
84
+ const bundleFunc = () => bundler.bundle(options, { ...context, moduleType, requiresTranspile: isTypescript || isJsx });
85
85
  return bundleInternal(bundleFunc, {
86
86
  ...options,
87
87
  name: bundler.name,
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;AAWnD,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;AACtF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAsB,EAAE,OAAsC;IACzF,MAAM,YAAY,GAAoB,EAAE,CAAC;IAEzC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QAC/B,YAAY,CAAC,IAAI,CAAC;YAChB,IAAI,EAAE,mCAAmC;YACzC,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;IACL,CAAC;SAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/C,YAAY,CAAC,IAAI,CA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AO,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 {\n BundleContext,\n BundleMessage,\n BundleOptions,\n Bundler,\n BundleResult,\n BundlerResult,\n CloudpackConfig,\n ModuleType,\n} from '@ms-cloudpack/common-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';\nimport { allBundlers } from './allBundlers.js';\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: Pick<BundleContext, 'config'>): Promise<BundleResult> {\n const configErrors: BundleMessage[] = [];\n\n if (!options.inputPath?.length) {\n configErrors.push({\n text: 'No input path provided to bundle.',\n source: 'bundle',\n });\n } else if (!path.isAbsolute(options.inputPath)) {\n configErrors.push({\n text: 'Input path must be absolute.',\n source: 'bundle',\n });\n }\n\n if (!Object.keys(options.entries || {}).length) {\n configErrors.push({\n text: `No entries provided to bundle at inputPath \"${options.inputPath}\".`,\n source: 'bundle',\n });\n } else if (Object.entries(options.entries).some(([k, v]) => path.isAbsolute(k) || path.isAbsolute(v))) {\n configErrors.push({\n text: `Entry paths must be relative.`,\n source: 'bundle',\n });\n }\n\n if (options.bundlerOptions && !options.bundler) {\n configErrors.push({\n text: '`bundlerOptions` are bundler-specific, so a `bundler` must be specified.',\n source: 'bundle',\n });\n }\n\n if (options.targetEnvironment === 'node' && (options.bundler === 'ori' || options.bundler === 'rollup')) {\n configErrors.push({\n text: `The \"${options.bundler}\" bundler does not currently support \\`targetEnvironment: \"node\"\\` (use \"rspack\" or \"webpack\")`,\n source: 'bundle',\n });\n }\n\n if (options.bundler && !allBundlers[options.bundler]) {\n configErrors.push({\n text: `Unknown bundler \"${options.bundler}\".`,\n source: 'bundle',\n });\n }\n\n if (configErrors.length) {\n return { inputPath: options.inputPath, errors: configErrors };\n }\n\n // Choose the bundler type and bundle.\n let moduleType: ModuleType | undefined;\n let isTypescript = false;\n\n for (const fileName of Object.values(options.entries)) {\n const ext = path.extname(fileName);\n\n if (typescriptExtensions.includes(ext)) {\n isTypescript = true;\n }\n\n // Check the module type of each entry, unless we've already found a cjs or amd file.\n if (!moduleType && sourceExtensions.includes(ext)) {\n const sourceType = await detectModuleType(path.resolve(options.inputPath, fileName));\n if (sourceType === 'amd' || sourceType === 'cjs') {\n moduleType = sourceType;\n }\n }\n }\n\n // Default to esm if no cjs or amd files were found\n moduleType ??= 'esm';\n\n const bundler = await chooseBundler({\n bundler: options.bundler,\n mode: context.config.mode,\n moduleType,\n isTypescript,\n targetEnvironment: options.targetEnvironment,\n defaultBundler: context.config.defaultBundler,\n });\n const bundleFunc = () => bundler.bundle(options, { ...context, moduleType, isTypescript });\n return bundleInternal(bundleFunc, {\n ...options,\n name: bundler.name,\n version: bundler.version,\n logBundleInfo: context.config.logBundleInfo,\n });\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<BundlerResult>,\n options: BundleOptions & Pick<Bundler, 'name' | 'version'> & Pick<CloudpackConfig, 'logBundleInfo'>,\n): Promise<BundleResult> {\n const bundler = options.name;\n const bundlerVersion = await options.version;\n let pluginResult: BundlerResult | undefined = undefined;\n\n try {\n pluginResult = await pluginBundle();\n } catch (e) {\n const errorMessage: BundleMessage = { text: `Exception while bundling: ${e}`, source: bundler };\n if (e instanceof Error && e.stack) {\n // remove the message from the stack\n errorMessage.notes = [{ text: e.stack.includes(e.message) ? e.stack.split(e.message)[1] : '' }];\n }\n pluginResult = {\n errors: [errorMessage],\n };\n }\n\n const { rawInput, rawOutput, rebuild, ...rest } = pluginResult || {};\n const { inputPath, entries, outputPath: logOutputPath = inputPath } = options;\n\n if (rest.errors?.length) {\n // If there are errors, always write them to a log file.\n await writeJson(path.join(logOutputPath, `${bundler}-errors.json`), rest.errors);\n }\n\n if (options.logBundleInfo) {\n // Only write the raw input and output to log files if requested.\n // (Raw output in particular can be very large, and it's only used for occasional debugging.)\n await Promise.all([\n rawInput && writeJson(path.join(logOutputPath, `${bundler}-input.json`), rawInput),\n rawOutput && writeJson(path.join(logOutputPath, `${bundler}-output.json`), rawOutput),\n ]);\n }\n\n const result: BundleResult = { bundler, bundlerVersion, inputPath, entries, ...rest };\n if (options.ignoredBundlerWarnings?.length && result.warnings?.length) {\n result.warnings = result.warnings.filter(\n (warning) => !options.ignoredBundlerWarnings?.some((suppressed) => warning.text.includes(suppressed)),\n );\n }\n\n if (rebuild) {\n // Wrap rebuild with proper result handling\n result.rebuild = () => bundleInternal(rebuild, options);\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAWnD,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACrG,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,OAAsB,EAAE,OAAsC;IACzF,MAAM,YAAY,GAAoB,EAAE,CAAC;IAEzC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QAC/B,YAAY,CAAC,IAAI,CAAC;YAChB,IAAI,EAAE,mCAAmC;YACzC,MAA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,EAAE,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CACtG,CAAC;IACJ,CAAC;IAED,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 {\n BundleContext,\n BundleMessage,\n BundleOptions,\n Bundler,\n BundleResult,\n BundlerResult,\n CloudpackConfig,\n ModuleType,\n} from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport path from 'path';\nimport { detectModuleType } from '@ms-cloudpack/package-utilities';\nimport { jsxExtensions, sourceExtensions, typescriptExtensions } from '@ms-cloudpack/path-utilities';\nimport { allBundlers } from './allBundlers.js';\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: Pick<BundleContext, 'config'>): Promise<BundleResult> {\n const configErrors: BundleMessage[] = [];\n\n if (!options.inputPath?.length) {\n configErrors.push({\n text: 'No input path provided to bundle.',\n source: 'bundle',\n });\n } else if (!path.isAbsolute(options.inputPath)) {\n configErrors.push({\n text: 'Input path must be absolute.',\n source: 'bundle',\n });\n }\n\n if (!Object.keys(options.entries || {}).length) {\n configErrors.push({\n text: `No entries provided to bundle at inputPath \"${options.inputPath}\".`,\n source: 'bundle',\n });\n } else if (Object.entries(options.entries).some(([k, v]) => path.isAbsolute(k) || path.isAbsolute(v))) {\n configErrors.push({\n text: `Entry paths must be relative.`,\n source: 'bundle',\n });\n }\n\n if (options.bundlerOptions && !options.bundler) {\n configErrors.push({\n text: '`bundlerOptions` are bundler-specific, so a `bundler` must be specified.',\n source: 'bundle',\n });\n }\n\n if (options.targetEnvironment === 'node' && (options.bundler === 'ori' || options.bundler === 'rollup')) {\n configErrors.push({\n text: `The \"${options.bundler}\" bundler does not currently support \\`targetEnvironment: \"node\"\\` (use \"rspack\" or \"webpack\")`,\n source: 'bundle',\n });\n }\n\n if (options.bundler && !allBundlers[options.bundler]) {\n configErrors.push({\n text: `Unknown bundler \"${options.bundler}\".`,\n source: 'bundle',\n });\n }\n\n if (configErrors.length) {\n return { inputPath: options.inputPath, errors: configErrors };\n }\n\n // Choose the bundler type and bundle.\n let moduleType: ModuleType | undefined;\n let isTypescript = false;\n let isJsx = false;\n\n for (const fileName of Object.values(options.entries)) {\n const ext = path.extname(fileName);\n\n isTypescript ||= typescriptExtensions.includes(ext);\n isJsx ||= jsxExtensions.includes(ext);\n\n // Check the module type of each entry, unless we've already found a cjs or amd file.\n if (!moduleType && sourceExtensions.includes(ext)) {\n const sourceType = await detectModuleType(path.resolve(options.inputPath, fileName));\n if (sourceType === 'amd' || sourceType === 'cjs') {\n moduleType = sourceType;\n }\n }\n }\n\n // Default to esm if no cjs or amd files were found\n moduleType ??= 'esm';\n\n const bundler = await chooseBundler({\n bundler: options.bundler,\n mode: context.config.mode,\n moduleType,\n isTypescript,\n targetEnvironment: options.targetEnvironment,\n defaultBundler: context.config.defaultBundler,\n });\n const bundleFunc = () =>\n bundler.bundle(options, { ...context, moduleType, requiresTranspile: isTypescript || isJsx });\n return bundleInternal(bundleFunc, {\n ...options,\n name: bundler.name,\n version: bundler.version,\n logBundleInfo: context.config.logBundleInfo,\n });\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<BundlerResult>,\n options: BundleOptions & Pick<Bundler, 'name' | 'version'> & Pick<CloudpackConfig, 'logBundleInfo'>,\n): Promise<BundleResult> {\n const bundler = options.name;\n const bundlerVersion = await options.version;\n let pluginResult: BundlerResult | undefined = undefined;\n\n try {\n pluginResult = await pluginBundle();\n } catch (e) {\n const errorMessage: BundleMessage = { text: `Exception while bundling: ${e}`, source: bundler };\n if (e instanceof Error && e.stack) {\n // remove the message from the stack\n errorMessage.notes = [{ text: e.stack.includes(e.message) ? e.stack.split(e.message)[1] : '' }];\n }\n pluginResult = {\n errors: [errorMessage],\n };\n }\n\n const { rawInput, rawOutput, rebuild, ...rest } = pluginResult || {};\n const { inputPath, entries, outputPath: logOutputPath = inputPath } = options;\n\n if (rest.errors?.length) {\n // If there are errors, always write them to a log file.\n await writeJson(path.join(logOutputPath, `${bundler}-errors.json`), rest.errors);\n }\n\n if (options.logBundleInfo) {\n // Only write the raw input and output to log files if requested.\n // (Raw output in particular can be very large, and it's only used for occasional debugging.)\n await Promise.all([\n rawInput && writeJson(path.join(logOutputPath, `${bundler}-input.json`), rawInput),\n rawOutput && writeJson(path.join(logOutputPath, `${bundler}-output.json`), rawOutput),\n ]);\n }\n\n const result: BundleResult = { bundler, bundlerVersion, inputPath, entries, ...rest };\n if (options.ignoredBundlerWarnings?.length && result.warnings?.length) {\n result.warnings = result.warnings.filter(\n (warning) => !options.ignoredBundlerWarnings?.some((suppressed) => warning.text.includes(suppressed)),\n );\n }\n\n if (rebuild) {\n // Wrap rebuild with proper result handling\n result.rebuild = () => bundleInternal(rebuild, options);\n }\n\n return result;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"chooseBundler.d.ts","sourceRoot":"","sources":["../src/chooseBundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGrG;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,uDAAuD;IACvD,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,UAAU,EAAE,UAAU,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,IAAI,EAAE,UAAU,CAAC;CAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAqBnB"}
1
+ {"version":3,"file":"chooseBundler.d.ts","sourceRoot":"","sources":["../src/chooseBundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAGrG;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,uDAAuD;IACvD,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,2DAA2D;IAC3D,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,UAAU,EAAE,UAAU,CAAC;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,IAAI,EAAE,UAAU,CAAC;CAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAyBnB"}
@@ -11,7 +11,11 @@ export async function chooseBundler(params) {
11
11
  bundler = 'webpack';
12
12
  }
13
13
  else if (moduleType === 'cjs' && !isTypescript) {
14
- // TODO do we still need !isTypescript now that rollup handles typescript?
14
+ // We can't use ori for CJS due to https://github.com/evanw/esbuild/issues/1148
15
+ // (esbuild/ori is more pedantic on this point, whereas rollup/webpack/rspack will just
16
+ // hoist the require to a top-level import even though it changes the semantics).
17
+ // Ori is probably safe for .cts files, at least if they only use modern import/export syntax
18
+ // (we can modify this in the future if there's an issue).
15
19
  bundler = 'rollup';
16
20
  }
17
21
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"chooseBundler.js","sourceRoot":"","sources":["../src/chooseBundler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MASnC;IACC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE,cAAc,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC;IAE7F,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;IAElC,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,IAAI,IAAI,KAAK,SAAS,IAAI,UAAU,KAAK,KAAK,IAAI,iBAAiB,KAAK,MAAM,EAAE,CAAC;YAC/E,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC;aAAM,IAAI,UAAU,KAAK,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YACjD,0EAA0E;YAC1E,OAAO,GAAG,QAAQ,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,cAAc,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,YAAY,OAAO,cAAc,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import type { BundleMode, Bundler, ModuleType, TargetEnvironment } from '@ms-cloudpack/common-types';\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 /** Bundler as specified in `BundleOptions` (if any) */\n bundler: string | undefined;\n /** Override for the default bundler from the app config */\n defaultBundler: string | undefined;\n moduleType: ModuleType;\n isTypescript: boolean;\n targetEnvironment: TargetEnvironment;\n mode: BundleMode;\n}): Promise<Bundler> {\n const { moduleType, isTypescript, mode, targetEnvironment, defaultBundler = 'ori' } = params;\n\n let { bundler = 'auto' } = params;\n\n if (bundler === 'auto') {\n if (mode !== 'library' || moduleType === 'amd' || targetEnvironment === 'node') {\n bundler = 'webpack';\n } else if (moduleType === 'cjs' && !isTypescript) {\n // TODO do we still need !isTypescript now that rollup handles typescript?\n bundler = 'rollup';\n } else {\n bundler = defaultBundler;\n }\n }\n\n if (!allBundlers[bundler]) {\n throw new Error(`Bundler \"${bundler}\" not found.`);\n }\n\n return await allBundlers[bundler]();\n}\n"]}
1
+ {"version":3,"file":"chooseBundler.js","sourceRoot":"","sources":["../src/chooseBundler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MASnC;IACC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE,cAAc,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC;IAE7F,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,GAAG,MAAM,CAAC;IAElC,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;QACvB,IAAI,IAAI,KAAK,SAAS,IAAI,UAAU,KAAK,KAAK,IAAI,iBAAiB,KAAK,MAAM,EAAE,CAAC;YAC/E,OAAO,GAAG,SAAS,CAAC;QACtB,CAAC;aAAM,IAAI,UAAU,KAAK,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;YACjD,+EAA+E;YAC/E,uFAAuF;YACvF,iFAAiF;YACjF,6FAA6F;YAC7F,0DAA0D;YAC1D,OAAO,GAAG,QAAQ,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,cAAc,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,YAAY,OAAO,cAAc,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,MAAM,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;AACtC,CAAC","sourcesContent":["import type { BundleMode, Bundler, ModuleType, TargetEnvironment } from '@ms-cloudpack/common-types';\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 /** Bundler as specified in `BundleOptions` (if any) */\n bundler: string | undefined;\n /** Override for the default bundler from the app config */\n defaultBundler: string | undefined;\n moduleType: ModuleType;\n isTypescript: boolean;\n targetEnvironment: TargetEnvironment;\n mode: BundleMode;\n}): Promise<Bundler> {\n const { moduleType, isTypescript, mode, targetEnvironment, defaultBundler = 'ori' } = params;\n\n let { bundler = 'auto' } = params;\n\n if (bundler === 'auto') {\n if (mode !== 'library' || moduleType === 'amd' || targetEnvironment === 'node') {\n bundler = 'webpack';\n } else if (moduleType === 'cjs' && !isTypescript) {\n // We can't use ori for CJS due to https://github.com/evanw/esbuild/issues/1148\n // (esbuild/ori is more pedantic on this point, whereas rollup/webpack/rspack will just\n // hoist the require to a top-level import even though it changes the semantics).\n // Ori is probably safe for .cts files, at least if they only use modern import/export syntax\n // (we can modify this in the future if there's an issue).\n bundler = 'rollup';\n } else {\n bundler = defaultBundler;\n }\n }\n\n if (!allBundlers[bundler]) {\n throw new Error(`Bundler \"${bundler}\" not found.`);\n }\n\n return await allBundlers[bundler]();\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/bundler",
3
- "version": "0.25.33",
3
+ "version": "0.26.0",
4
4
  "description": "An abstraction to bundle source code.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,16 +14,16 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/bundler-ori": "^0.2.68",
18
- "@ms-cloudpack/bundler-rollup": "^0.4.14",
19
- "@ms-cloudpack/bundler-rspack": "^0.3.9",
20
- "@ms-cloudpack/bundler-webpack": "^0.3.9",
21
- "@ms-cloudpack/common-types": "^0.27.7",
22
- "@ms-cloudpack/config": "^0.38.4",
17
+ "@ms-cloudpack/bundler-ori": "^0.2.70",
18
+ "@ms-cloudpack/bundler-rollup": "^0.4.15",
19
+ "@ms-cloudpack/bundler-rspack": "^0.3.10",
20
+ "@ms-cloudpack/bundler-webpack": "^0.3.10",
21
+ "@ms-cloudpack/common-types": "^0.28.0",
22
+ "@ms-cloudpack/config": "^0.38.5",
23
23
  "@ms-cloudpack/json-utilities": "^0.1.11",
24
- "@ms-cloudpack/package-utilities": "^12.5.1",
24
+ "@ms-cloudpack/package-utilities": "^12.5.2",
25
25
  "@ms-cloudpack/path-string-parsing": "^1.2.7",
26
- "@ms-cloudpack/path-utilities": "^3.1.22"
26
+ "@ms-cloudpack/path-utilities": "^3.1.23"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@ms-cloudpack/eslint-plugin-internal": "^0.0.1",