1 | import { pathnameToOperatingSystemPath } from "@jsenv/operating-system-path"
|
2 | import { createLogger } from "./logger.js"
|
3 | import { createImportFromGlobalRollupPlugin } from "./import-from-global-rollup-plugin.js"
|
4 | import { createJsenvRollupPlugin } from "./jsenv-rollup-plugin.js"
|
5 | import { generateBundleUsingRollup } from "./generate-bundle-using-rollup.js"
|
6 | import { formatToRollupFormat } from "./format-to-rollup-format.js"
|
7 |
|
8 | export 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(`
|
58 | bundle entry points without balancing.
|
59 | format: ${format}
|
60 | entry point names: ${Object.keys(entryPointMap)}
|
61 | dir: ${dir}
|
62 | minify: ${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 |
|
77 | dir,
|
78 |
|
79 | format: formatToRollupFormat(format),
|
80 |
|
81 |
|
82 | sourcemap: true,
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | sourcemapExcludeSources: false,
|
88 | ...rollupGenerateOptions,
|
89 | ...formatOutputOptions,
|
90 | },
|
91 | })
|
92 |
|
93 | return { rollupBundle, relativePathAbstractArray }
|
94 | }
|