UNPKG

2.65 kBJavaScriptView Raw
1import { pathnameToOperatingSystemPath } from "@jsenv/operating-system-path"
2import { createLogger } from "./logger.js"
3import { createImportFromGlobalRollupPlugin } from "./import-from-global-rollup-plugin.js"
4import { createJsenvRollupPlugin } from "./jsenv-rollup-plugin.js"
5import { generateBundleUsingRollup } from "./generate-bundle-using-rollup.js"
6import { formatToRollupFormat } from "./format-to-rollup-format.js"
7
8export const bundleWithoutBalancing = async ({
9 cancellationToken,
10 projectPathname,
11 bundleIntoRelativePath,
12 importDefaultExtension,
13 importMapRelativePath,
14 importMapForBundle,
15 specifierMap,
16 specifierDynamicMap,
17 nativeModulePredicate,
18 entryPointMap,
19 babelPluginMap,
20 convertMap,
21 minify,
22 logLevel,
23 format,
24 formatOutputOptions,
25 writeOnFileSystem,
26}) => {
27 const logger = createLogger({ logLevel })
28
29 const dir = pathnameToOperatingSystemPath(`${projectPathname}${bundleIntoRelativePath}`)
30
31 const {
32 jsenvRollupPlugin,
33 relativePathAbstractArray,
34 getRollupGenerateOptions,
35 } = await createJsenvRollupPlugin({
36 cancellationToken,
37 projectPathname,
38 dir,
39 entryPointMap,
40 importDefaultExtension,
41 importMapRelativePath,
42 importMapForBundle,
43 specifierMap,
44 specifierDynamicMap,
45 babelPluginMap,
46 convertMap,
47 featureNameArray: Object.keys(babelPluginMap),
48 minify,
49 format,
50 logger,
51 })
52
53 const importFromGlobalRollupPlugin = createImportFromGlobalRollupPlugin({
54 platformGlobalName: "globalThis",
55 })
56
57 logger.logTrace(`
58bundle entry points without balancing.
59format: ${format}
60entry point names: ${Object.keys(entryPointMap)}
61dir: ${dir}
62minify: ${minify}
63`)
64
65 const rollupGenerateOptions = await getRollupGenerateOptions()
66
67 const rollupBundle = await generateBundleUsingRollup({
68 cancellationToken,
69 writeOnFileSystem,
70 rollupParseOptions: {
71 input: entryPointMap,
72 plugins: [importFromGlobalRollupPlugin, jsenvRollupPlugin],
73 external: (id) => nativeModulePredicate(id),
74 },
75 rollupGenerateOptions: {
76 // https://rollupjs.org/guide/en#output-dir
77 dir,
78 // https://rollupjs.org/guide/en#output-format
79 format: formatToRollupFormat(format),
80 // entryFileNames: `./[name].js`,
81 // https://rollupjs.org/guide/en#output-sourcemap
82 sourcemap: true,
83 // we could exclude them
84 // but it's better to put them directly
85 // in case source files are not reachable
86 // for whatever reason
87 sourcemapExcludeSources: false,
88 ...rollupGenerateOptions,
89 ...formatOutputOptions,
90 },
91 })
92
93 return { rollupBundle, relativePathAbstractArray }
94}