rolldown 1.0.0-beta.3-commit.06372d4 → 1.0.0-beta.3-commit.558ea78
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/dist/cjs/cli.cjs +1 -1
- package/dist/cjs/experimental-index.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/parallel-plugin-worker.cjs +1 -1
- package/dist/esm/cli.mjs +1 -1
- package/dist/esm/experimental-index.mjs +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/parallel-plugin-worker.mjs +1 -1
- package/dist/shared/{src-CLOW1Jzp.mjs → src-Cis0qYEg.mjs} +35 -15
- package/dist/shared/{src-D2D9kPjA.cjs → src-Z84gVvFu.cjs} +35 -15
- package/dist/types/binding.d.ts +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/log/logging.d.ts +1 -0
- package/dist/types/options/input-options.d.ts +3 -3
- package/dist/types/plugin/plugin-context-data.d.ts +2 -1
- package/package.json +15 -15
- package/dist/types/api/build.js +0 -22
- package/dist/types/api/experimental.js +0 -13
- package/dist/types/api/rolldown/index.js +0 -7
- package/dist/types/api/rolldown/rolldown-build.js +0 -43
- package/dist/types/api/watch/index.js +0 -8
- package/dist/types/api/watch/watch-emitter.js +0 -69
- package/dist/types/api/watch/watcher.js +0 -66
- package/dist/types/builtin-plugin/alias-plugin.js +0 -4
- package/dist/types/builtin-plugin/constructors.js +0 -68
- package/dist/types/builtin-plugin/replace-plugin.js +0 -29
- package/dist/types/builtin-plugin/transform-plugin.js +0 -16
- package/dist/types/builtin-plugin/utils.js +0 -19
- package/dist/types/cli/arguments/alias.js +0 -63
- package/dist/types/cli/arguments/index.js +0 -127
- package/dist/types/cli/arguments/normalize.js +0 -48
- package/dist/types/cli/arguments/utils.js +0 -67
- package/dist/types/cli/colors.js +0 -17
- package/dist/types/cli/commands/bundle.js +0 -203
- package/dist/types/cli/commands/help.js +0 -88
- package/dist/types/cli/index.js +0 -27
- package/dist/types/cli/load-config.js +0 -95
- package/dist/types/cli/logger.js +0 -35
- package/dist/types/constants/plugin-context.js +0 -7
- package/dist/types/constants/plugin.js +0 -69
- package/dist/types/experimental-index.js +0 -9
- package/dist/types/index.js +0 -7
- package/dist/types/log/logHandler.js +0 -25
- package/dist/types/log/logger.js +0 -107
- package/dist/types/log/logging.js +0 -11
- package/dist/types/log/logs.js +0 -86
- package/dist/types/options/input-options.js +0 -1
- package/dist/types/options/normalized-input-options.js +0 -21
- package/dist/types/options/normalized-output-options.js +0 -99
- package/dist/types/options/output-options.js +0 -1
- package/dist/types/options/watch-options.js +0 -1
- package/dist/types/parallel-plugin-worker.js +0 -31
- package/dist/types/parallel-plugin.js +0 -1
- package/dist/types/parse-ast-index.js +0 -73
- package/dist/types/plugin/bindingify-build-hooks.js +0 -213
- package/dist/types/plugin/bindingify-hook-filter.js +0 -39
- package/dist/types/plugin/bindingify-output-hooks.js +0 -189
- package/dist/types/plugin/bindingify-plugin-hook-meta.js +0 -19
- package/dist/types/plugin/bindingify-plugin.js +0 -124
- package/dist/types/plugin/bindingify-watch-hooks.js +0 -29
- package/dist/types/plugin/hook-filter.js +0 -1
- package/dist/types/plugin/index.js +0 -1
- package/dist/types/plugin/minimal-plugin-context.js +0 -25
- package/dist/types/plugin/parallel-plugin-implementation.js +0 -3
- package/dist/types/plugin/parallel-plugin.js +0 -6
- package/dist/types/plugin/plugin-context-data.js +0 -55
- package/dist/types/plugin/plugin-context.js +0 -124
- package/dist/types/plugin/plugin-driver.js +0 -88
- package/dist/types/plugin/transform-plugin-context.js +0 -37
- package/dist/types/types/assert.js +0 -1
- package/dist/types/types/config-export.js +0 -1
- package/dist/types/types/misc.js +0 -1
- package/dist/types/types/module-info.js +0 -1
- package/dist/types/types/module-side-effects.js +0 -1
- package/dist/types/types/output-bundle.js +0 -1
- package/dist/types/types/rolldown-options.js +0 -1
- package/dist/types/types/rolldown-output.js +0 -1
- package/dist/types/types/schema.js +0 -1
- package/dist/types/types/sourcemap.js +0 -16
- package/dist/types/types/utils.js +0 -1
- package/dist/types/utils/asset-source.js +0 -8
- package/dist/types/utils/async-flatten.js +0 -7
- package/dist/types/utils/bindingify-input-options.js +0 -226
- package/dist/types/utils/bindingify-output-options.js +0 -107
- package/dist/types/utils/code-frame.js +0 -46
- package/dist/types/utils/compose-js-plugins.js +0 -400
- package/dist/types/utils/create-bundler-option.js +0 -53
- package/dist/types/utils/create-bundler.js +0 -15
- package/dist/types/utils/define-config.js +0 -3
- package/dist/types/utils/error.js +0 -65
- package/dist/types/utils/initialize-parallel-plugins.js +0 -54
- package/dist/types/utils/misc.js +0 -22
- package/dist/types/utils/normalize-hook.js +0 -21
- package/dist/types/utils/normalize-plugin-option.js +0 -35
- package/dist/types/utils/normalize-string-or-regex.js +0 -14
- package/dist/types/utils/plugin/index.js +0 -7
- package/dist/types/utils/transform-module-info.js +0 -19
- package/dist/types/utils/transform-rendered-chunk.js +0 -43
- package/dist/types/utils/transform-rendered-module.js +0 -10
- package/dist/types/utils/transform-side-effects.js +0 -16
- package/dist/types/utils/transform-sourcemap.js +0 -29
- package/dist/types/utils/transform-to-rollup-output.js +0 -165
- package/dist/types/utils/validator.js +0 -276
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { performance } from 'node:perf_hooks';
|
|
3
|
-
import { onExit } from 'signal-exit';
|
|
4
|
-
import { colors } from '../colors';
|
|
5
|
-
import { logger } from '../logger';
|
|
6
|
-
import { arraify } from '../../utils/misc';
|
|
7
|
-
import { rolldown } from '../../api/rolldown';
|
|
8
|
-
import { watch as rolldownWatch } from '../../api/watch';
|
|
9
|
-
import { loadConfig } from '../load-config';
|
|
10
|
-
export async function bundleWithConfig(configPath, cliOptions) {
|
|
11
|
-
const config = await loadConfig(configPath);
|
|
12
|
-
if (!config) {
|
|
13
|
-
logger.error(`No configuration found at ${config}`);
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
// TODO: Could add more validation/diagnostics here to emit a nice error message
|
|
17
|
-
if (cliOptions.watch) {
|
|
18
|
-
await watchInner(config, cliOptions);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
await bundleInner(config, cliOptions);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export async function bundleWithCliOptions(cliOptions) {
|
|
25
|
-
if (cliOptions.output.dir || cliOptions.output.file) {
|
|
26
|
-
const operation = cliOptions.watch ? watchInner : bundleInner;
|
|
27
|
-
await operation({}, cliOptions);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (cliOptions.watch) {
|
|
31
|
-
logger.error('You must specify `output.dir` to use watch mode');
|
|
32
|
-
process.exit(1);
|
|
33
|
-
}
|
|
34
|
-
// Rolldown doesn't yet support the following syntax:
|
|
35
|
-
// await using build = await rolldown(cliOptions.input)
|
|
36
|
-
const build = await rolldown(cliOptions.input);
|
|
37
|
-
try {
|
|
38
|
-
const { output: outputs } = await build.generate(cliOptions.output);
|
|
39
|
-
if (outputs.length === 0) {
|
|
40
|
-
logger.error('No output generated');
|
|
41
|
-
process.exit(1);
|
|
42
|
-
}
|
|
43
|
-
for (const file of outputs) {
|
|
44
|
-
if (outputs.length > 1) {
|
|
45
|
-
logger.log(`\n${colors.cyan(colors.bold(`|→ ${file.fileName}:`))}\n`);
|
|
46
|
-
}
|
|
47
|
-
// avoid consola since it doesn't print it as raw string
|
|
48
|
-
// eslint-disable-next-line no-console
|
|
49
|
-
console.log(file.type === 'asset' ? file.source : file.code);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
finally {
|
|
53
|
-
await build.close();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function watchInner(config, cliOptions) {
|
|
57
|
-
// Only if watch is true in CLI can we use watch mode.
|
|
58
|
-
// We should not make it `await`, as it never ends.
|
|
59
|
-
let normalizedConfig = arraify(config).map((option) => {
|
|
60
|
-
return {
|
|
61
|
-
...option,
|
|
62
|
-
...cliOptions.input,
|
|
63
|
-
output: arraify(option.output || {}).map((output) => {
|
|
64
|
-
return {
|
|
65
|
-
...output,
|
|
66
|
-
...cliOptions.output,
|
|
67
|
-
};
|
|
68
|
-
}),
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
const watcher = await rolldownWatch(normalizedConfig);
|
|
72
|
-
onExit((code) => {
|
|
73
|
-
Promise.resolve(watcher.close()).finally(() => {
|
|
74
|
-
process.exit(typeof code === 'number' ? code : 0);
|
|
75
|
-
});
|
|
76
|
-
return true;
|
|
77
|
-
});
|
|
78
|
-
const changedFile = [];
|
|
79
|
-
watcher.on('change', (id, event) => {
|
|
80
|
-
if (event.event === 'update') {
|
|
81
|
-
changedFile.push(id);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
watcher.on('event', (event) => {
|
|
85
|
-
switch (event.code) {
|
|
86
|
-
case 'BUNDLE_START':
|
|
87
|
-
if (changedFile.length > 0) {
|
|
88
|
-
logger.log(`Found ${colors.bold(changedFile.map(relativeId).join(', '))} changed, rebuilding...`);
|
|
89
|
-
}
|
|
90
|
-
changedFile.length = 0;
|
|
91
|
-
break;
|
|
92
|
-
case 'BUNDLE_END':
|
|
93
|
-
logger.success(`Rebuilt ${colors.bold(relativeId(event.output[0]))} in ${colors.bold(ms(event.duration))}.`);
|
|
94
|
-
break;
|
|
95
|
-
case 'ERROR':
|
|
96
|
-
logger.error(event.error);
|
|
97
|
-
break;
|
|
98
|
-
default:
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
logger.log(`Waiting for changes...`);
|
|
103
|
-
}
|
|
104
|
-
async function bundleInner(config, cliOptions) {
|
|
105
|
-
const startTime = performance.now();
|
|
106
|
-
const result = [];
|
|
107
|
-
const configList = arraify(config);
|
|
108
|
-
for (const config of configList) {
|
|
109
|
-
const outputList = arraify(config.output || {});
|
|
110
|
-
const build = await rolldown({ ...config, ...cliOptions.input });
|
|
111
|
-
for (const output of outputList) {
|
|
112
|
-
// run multiply instance at sequential
|
|
113
|
-
try {
|
|
114
|
-
result.push(await build.write({
|
|
115
|
-
...output,
|
|
116
|
-
...cliOptions.output,
|
|
117
|
-
}));
|
|
118
|
-
}
|
|
119
|
-
finally {
|
|
120
|
-
await build.close();
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
result.forEach(printBundleOutputPretty);
|
|
125
|
-
logger.log(``);
|
|
126
|
-
const endTime = performance.now();
|
|
127
|
-
const duration = endTime - startTime;
|
|
128
|
-
// If the build time is more than 1s, we should display it in seconds.
|
|
129
|
-
logger.success(`Finished in ${colors.bold(ms(duration))}`);
|
|
130
|
-
}
|
|
131
|
-
function printBundleOutputPretty(output) {
|
|
132
|
-
const outputEntries = collectOutputEntries(output.output);
|
|
133
|
-
const outputLayoutSizes = collectOutputLayoutAdjustmentSizes(outputEntries);
|
|
134
|
-
printOutputEntries(outputEntries, outputLayoutSizes, '<DIR>');
|
|
135
|
-
}
|
|
136
|
-
function collectOutputEntries(output) {
|
|
137
|
-
return output.map((chunk) => ({
|
|
138
|
-
type: chunk.type,
|
|
139
|
-
fileName: chunk.fileName,
|
|
140
|
-
size: chunk.type === 'chunk' ? chunk.code.length : chunk.source.length,
|
|
141
|
-
}));
|
|
142
|
-
}
|
|
143
|
-
function collectOutputLayoutAdjustmentSizes(entries) {
|
|
144
|
-
let longest = 0;
|
|
145
|
-
let biggestSize = 0;
|
|
146
|
-
for (const entry of entries) {
|
|
147
|
-
if (entry.fileName.length > longest) {
|
|
148
|
-
longest = entry.fileName.length;
|
|
149
|
-
}
|
|
150
|
-
if (entry.size > biggestSize) {
|
|
151
|
-
biggestSize = entry.size;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const sizePad = displaySize(biggestSize).length;
|
|
155
|
-
return {
|
|
156
|
-
longest,
|
|
157
|
-
biggestSize,
|
|
158
|
-
sizePad,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
const numberFormatter = new Intl.NumberFormat('en', {
|
|
162
|
-
maximumFractionDigits: 2,
|
|
163
|
-
minimumFractionDigits: 2,
|
|
164
|
-
});
|
|
165
|
-
function displaySize(bytes) {
|
|
166
|
-
return `${numberFormatter.format(bytes / 1000)} kB`;
|
|
167
|
-
}
|
|
168
|
-
const CHUNK_GROUPS = [
|
|
169
|
-
{ type: 'asset', color: 'green' },
|
|
170
|
-
{ type: 'chunk', color: 'cyan' },
|
|
171
|
-
];
|
|
172
|
-
function printOutputEntries(entries, sizeAdjustment, distPath) {
|
|
173
|
-
for (const group of CHUNK_GROUPS) {
|
|
174
|
-
const filtered = entries.filter((e) => e.type === group.type);
|
|
175
|
-
if (!filtered.length) {
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
for (const entry of filtered.sort((a, z) => a.size - z.size)) {
|
|
179
|
-
// output format: `path/to/xxx type | size: y.yy kB`
|
|
180
|
-
let log = colors.dim(withTrailingSlash(distPath));
|
|
181
|
-
log += colors[group.color](entry.fileName.padEnd(sizeAdjustment.longest + 2));
|
|
182
|
-
log += colors.dim(entry.type);
|
|
183
|
-
log += colors.dim(` │ size: ${displaySize(entry.size).padStart(sizeAdjustment.sizePad)}`);
|
|
184
|
-
logger.log(log);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
function withTrailingSlash(path) {
|
|
189
|
-
if (path[path.length - 1] !== '/') {
|
|
190
|
-
return `${path}/`;
|
|
191
|
-
}
|
|
192
|
-
return path;
|
|
193
|
-
}
|
|
194
|
-
function ms(duration) {
|
|
195
|
-
return duration < 1000
|
|
196
|
-
? `${duration.toFixed(2)} ms`
|
|
197
|
-
: `${(duration / 1000).toFixed(2)} s`;
|
|
198
|
-
}
|
|
199
|
-
function relativeId(id) {
|
|
200
|
-
if (!path.isAbsolute(id))
|
|
201
|
-
return id;
|
|
202
|
-
return path.relative(path.resolve(), id);
|
|
203
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { logger } from '../logger';
|
|
2
|
-
import { version, description, } from '../../../package.json' assert { type: 'json' };
|
|
3
|
-
import { colors } from '../colors';
|
|
4
|
-
import { options } from '../arguments';
|
|
5
|
-
import { camelCaseToKebabCase } from '../arguments/utils';
|
|
6
|
-
const introduction = `${colors.gray(`${description} (rolldown v${version})`)}
|
|
7
|
-
|
|
8
|
-
${colors.bold(colors.underline('USAGE'))} ${colors.cyan('rolldown -c <config>')} or ${colors.cyan('rolldown <input> <options>')}`;
|
|
9
|
-
const examples = [
|
|
10
|
-
{
|
|
11
|
-
title: 'Bundle with a config file `rolldown.config.mjs`',
|
|
12
|
-
command: 'rolldown -c rolldown.config.mjs',
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
title: 'Bundle the `src/main.ts` to `dist` with `cjs` format',
|
|
16
|
-
command: 'rolldown src/main.ts -d dist -f cjs',
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
title: 'Bundle the `src/main.ts` and handle the `.png` assets to Data URL',
|
|
20
|
-
command: 'rolldown src/main.ts -d dist --moduleTypes .png=dataurl',
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
title: 'Bundle the `src/main.tsx` and minify the output with sourcemap',
|
|
24
|
-
command: 'rolldown src/main.tsx -d dist -m -s',
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
title: 'Create self-executing IIFE using external jQuery as `$` and `_`',
|
|
28
|
-
command: 'rolldown src/main.ts -d dist -n bundle -f iife -e jQuery,window._ -g jQuery=$',
|
|
29
|
-
},
|
|
30
|
-
];
|
|
31
|
-
const notes = [
|
|
32
|
-
'Due to the API limitation, you need to pass `-s` for `.map` sourcemap file as the last argument.',
|
|
33
|
-
'If you are using the configuration, please pass the `-c` as the last argument if you ignore the default configuration file.',
|
|
34
|
-
'CLI options will override the configuration file.',
|
|
35
|
-
'For more information, please visit https://rolldown.rs/.',
|
|
36
|
-
];
|
|
37
|
-
export function showHelp() {
|
|
38
|
-
logger.log(introduction);
|
|
39
|
-
logger.log('');
|
|
40
|
-
logger.log(`${colors.bold(colors.underline('OPTIONS'))}`);
|
|
41
|
-
logger.log('');
|
|
42
|
-
logger.log(Object.entries(options)
|
|
43
|
-
.sort(([a], [b]) => {
|
|
44
|
-
// 1. If one of them has a short option, prioritize it.
|
|
45
|
-
if (options[a].short && !options[b].short) {
|
|
46
|
-
return -1;
|
|
47
|
-
}
|
|
48
|
-
if (!options[a].short && options[b].short) {
|
|
49
|
-
return 1;
|
|
50
|
-
}
|
|
51
|
-
// 2. If both of them have a short option, sort by the short letter.
|
|
52
|
-
if (options[a].short && options[b].short) {
|
|
53
|
-
return options[a].short.localeCompare(options[b].short);
|
|
54
|
-
}
|
|
55
|
-
// 3. If none of them has a short option, sort by the long option.
|
|
56
|
-
return a.localeCompare(b);
|
|
57
|
-
})
|
|
58
|
-
.map(([option, { type, short, hint, description }]) => {
|
|
59
|
-
let optionStr = ` --${option} `;
|
|
60
|
-
option = camelCaseToKebabCase(option);
|
|
61
|
-
if (short) {
|
|
62
|
-
optionStr += `-${short}, `;
|
|
63
|
-
}
|
|
64
|
-
if (type === 'string') {
|
|
65
|
-
optionStr += `<${hint ?? option}>`;
|
|
66
|
-
}
|
|
67
|
-
if (description && description.length > 0) {
|
|
68
|
-
description = description[0].toUpperCase() + description.slice(1);
|
|
69
|
-
}
|
|
70
|
-
return (colors.cyan(optionStr.padEnd(30)) +
|
|
71
|
-
description +
|
|
72
|
-
(description && description?.endsWith('.') ? '' : '.'));
|
|
73
|
-
})
|
|
74
|
-
.join('\n'));
|
|
75
|
-
logger.log('');
|
|
76
|
-
logger.log(`${colors.bold(colors.underline('EXAMPLES'))}`);
|
|
77
|
-
logger.log('');
|
|
78
|
-
examples.forEach(({ title, command }, ord) => {
|
|
79
|
-
logger.log(` ${ord + 1}. ${title}:`);
|
|
80
|
-
logger.log(` ${colors.cyan(command)}`);
|
|
81
|
-
logger.log('');
|
|
82
|
-
});
|
|
83
|
-
logger.log(`${colors.bold(colors.underline('NOTES'))}`);
|
|
84
|
-
logger.log('');
|
|
85
|
-
notes.forEach((note) => {
|
|
86
|
-
logger.log(` * ${colors.gray(note)}`);
|
|
87
|
-
});
|
|
88
|
-
}
|
package/dist/types/cli/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import process from 'node:process';
|
|
2
|
-
import { bundleWithCliOptions, bundleWithConfig } from './commands/bundle';
|
|
3
|
-
import { logger } from './logger';
|
|
4
|
-
import { parseCliArguments } from './arguments';
|
|
5
|
-
import { showHelp } from './commands/help';
|
|
6
|
-
import { version } from '../../package.json';
|
|
7
|
-
async function main() {
|
|
8
|
-
const cliOptions = parseCliArguments();
|
|
9
|
-
if (cliOptions.config || cliOptions.config === '') {
|
|
10
|
-
await bundleWithConfig(cliOptions.config, cliOptions);
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if ('input' in cliOptions.input) {
|
|
14
|
-
// If input is specified, we will bundle with the input options
|
|
15
|
-
await bundleWithCliOptions(cliOptions);
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (cliOptions.version) {
|
|
19
|
-
logger.log(`rolldown v${version}`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
showHelp();
|
|
23
|
-
}
|
|
24
|
-
main().catch((err) => {
|
|
25
|
-
logger.error(err);
|
|
26
|
-
process.exit(1);
|
|
27
|
-
});
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { cwd } from 'node:process';
|
|
4
|
-
import { readdir } from 'node:fs/promises';
|
|
5
|
-
import { pathToFileURL } from 'node:url';
|
|
6
|
-
import { rolldown } from '../api/rolldown';
|
|
7
|
-
async function bundleTsConfig(configFile) {
|
|
8
|
-
const dirnameVarName = 'injected_original_dirname';
|
|
9
|
-
const filenameVarName = 'injected_original_filename';
|
|
10
|
-
const importMetaUrlVarName = 'injected_original_import_meta_url';
|
|
11
|
-
const bundle = await rolldown({
|
|
12
|
-
input: configFile,
|
|
13
|
-
platform: 'node',
|
|
14
|
-
resolve: {
|
|
15
|
-
mainFields: ['main'],
|
|
16
|
-
},
|
|
17
|
-
define: {
|
|
18
|
-
__dirname: dirnameVarName,
|
|
19
|
-
__filename: filenameVarName,
|
|
20
|
-
'import.meta.url': importMetaUrlVarName,
|
|
21
|
-
'import.meta.dirname': dirnameVarName,
|
|
22
|
-
'import.meta.filename': filenameVarName,
|
|
23
|
-
},
|
|
24
|
-
treeshake: false,
|
|
25
|
-
external: [/^[\w@][^:]/], // external bare imports
|
|
26
|
-
plugins: [
|
|
27
|
-
{
|
|
28
|
-
name: 'inject-file-scope-variables',
|
|
29
|
-
transform: {
|
|
30
|
-
filter: { id: /\.[cm]?[jt]s$/ },
|
|
31
|
-
async handler(code, id) {
|
|
32
|
-
const injectValues = `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};` +
|
|
33
|
-
`const ${filenameVarName} = ${JSON.stringify(id)};` +
|
|
34
|
-
`const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};`;
|
|
35
|
-
return { code: injectValues + code, map: null };
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
],
|
|
40
|
-
});
|
|
41
|
-
const outputDir = path.dirname(configFile);
|
|
42
|
-
const result = await bundle.write({
|
|
43
|
-
dir: outputDir,
|
|
44
|
-
format: 'esm',
|
|
45
|
-
sourcemap: 'inline',
|
|
46
|
-
entryFileNames: 'rolldown.config.[hash].js',
|
|
47
|
-
});
|
|
48
|
-
const fileName = result.output.find((chunk) => chunk.type === 'chunk' && chunk.isEntry).fileName;
|
|
49
|
-
return path.join(outputDir, fileName);
|
|
50
|
-
}
|
|
51
|
-
const SUPPORTED_JS_CONFIG_FORMATS = ['.js', '.mjs', '.cjs'];
|
|
52
|
-
const SUPPORTED_TS_CONFIG_FORMATS = ['.ts', '.mts', '.cts'];
|
|
53
|
-
const SUPPORTED_CONFIG_FORMATS = [
|
|
54
|
-
...SUPPORTED_JS_CONFIG_FORMATS,
|
|
55
|
-
...SUPPORTED_TS_CONFIG_FORMATS,
|
|
56
|
-
];
|
|
57
|
-
const DEFAULT_CONFIG_BASE = 'rolldown.config';
|
|
58
|
-
async function findConfigFileNameInCwd() {
|
|
59
|
-
const filesInWorkingDirectory = new Set(await readdir(cwd()));
|
|
60
|
-
for (const extension of SUPPORTED_CONFIG_FORMATS) {
|
|
61
|
-
const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
|
|
62
|
-
if (filesInWorkingDirectory.has(fileName))
|
|
63
|
-
return fileName;
|
|
64
|
-
}
|
|
65
|
-
throw new Error('No `rolldown.config` configuration file found.');
|
|
66
|
-
}
|
|
67
|
-
export async function loadTsConfig(configFile) {
|
|
68
|
-
const file = await bundleTsConfig(configFile);
|
|
69
|
-
try {
|
|
70
|
-
return (await import(pathToFileURL(file).href)).default;
|
|
71
|
-
}
|
|
72
|
-
finally {
|
|
73
|
-
fs.unlink(file, () => { }); // Ignore errors
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
export async function loadConfig(configPath) {
|
|
77
|
-
const ext = path.extname((configPath = configPath || (await findConfigFileNameInCwd())));
|
|
78
|
-
try {
|
|
79
|
-
if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) ||
|
|
80
|
-
(process.env.NODE_OPTIONS?.includes('--import=tsx') &&
|
|
81
|
-
SUPPORTED_TS_CONFIG_FORMATS.includes(ext))) {
|
|
82
|
-
return (await import(pathToFileURL(configPath).href)).default;
|
|
83
|
-
}
|
|
84
|
-
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
85
|
-
const rawConfigPath = path.resolve(configPath);
|
|
86
|
-
return await loadTsConfig(rawConfigPath);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(',')}\` but got \`${ext}\``);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
catch (err) {
|
|
93
|
-
throw new Error('Error happened while loading config.', { cause: err });
|
|
94
|
-
}
|
|
95
|
-
}
|
package/dist/types/cli/logger.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { createConsola } from 'consola';
|
|
2
|
-
/**
|
|
3
|
-
* Console logger
|
|
4
|
-
*/
|
|
5
|
-
export const logger = process.env
|
|
6
|
-
.ROLLDOWN_TEST
|
|
7
|
-
? createTestingLogger()
|
|
8
|
-
: createConsola({
|
|
9
|
-
formatOptions: {
|
|
10
|
-
date: false,
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
function createTestingLogger() {
|
|
14
|
-
const types = [
|
|
15
|
-
'silent',
|
|
16
|
-
'fatal',
|
|
17
|
-
'error',
|
|
18
|
-
'warn',
|
|
19
|
-
'log',
|
|
20
|
-
'info',
|
|
21
|
-
'success',
|
|
22
|
-
'fail',
|
|
23
|
-
'ready',
|
|
24
|
-
'start',
|
|
25
|
-
'box',
|
|
26
|
-
'debug',
|
|
27
|
-
'trace',
|
|
28
|
-
'verbose',
|
|
29
|
-
];
|
|
30
|
-
const ret = Object.create(null);
|
|
31
|
-
for (const type of types) {
|
|
32
|
-
ret[type] = console.log;
|
|
33
|
-
}
|
|
34
|
-
return ret;
|
|
35
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* If Composed plugins call `this.resolve` with `skipSelf: true`, the composed plugins will be skipped as a whole.
|
|
3
|
-
* To prevent that, we use this symbol to store the actual caller of `this.resolve` with `skipSelf: true`. And we
|
|
4
|
-
* will modify the skipSelf option to `false` and use this symbol to skip the caller itself in the composed plugins
|
|
5
|
-
* internally.
|
|
6
|
-
*/
|
|
7
|
-
export const SYMBOL_FOR_RESOLVE_CALLER_THAT_SKIP_SELF = Symbol('plugin-context-resolve-caller');
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
export const ENUMERATED_INPUT_PLUGIN_HOOK_NAMES = [
|
|
2
|
-
'options',
|
|
3
|
-
'buildStart',
|
|
4
|
-
'resolveId',
|
|
5
|
-
'load',
|
|
6
|
-
'transform',
|
|
7
|
-
'moduleParsed',
|
|
8
|
-
'buildEnd',
|
|
9
|
-
'onLog',
|
|
10
|
-
'resolveDynamicImport',
|
|
11
|
-
'closeBundle',
|
|
12
|
-
'closeWatcher',
|
|
13
|
-
'watchChange',
|
|
14
|
-
];
|
|
15
|
-
export const ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES = [
|
|
16
|
-
'augmentChunkHash',
|
|
17
|
-
'outputOptions',
|
|
18
|
-
'renderChunk',
|
|
19
|
-
'renderStart',
|
|
20
|
-
'renderError',
|
|
21
|
-
'writeBundle',
|
|
22
|
-
'generateBundle',
|
|
23
|
-
];
|
|
24
|
-
export const ENUMERATED_PLUGIN_HOOK_NAMES = [
|
|
25
|
-
// build hooks
|
|
26
|
-
...ENUMERATED_INPUT_PLUGIN_HOOK_NAMES,
|
|
27
|
-
// generate hooks
|
|
28
|
-
...ENUMERATED_OUTPUT_PLUGIN_HOOK_NAMES,
|
|
29
|
-
// addon hooks
|
|
30
|
-
'footer',
|
|
31
|
-
'banner',
|
|
32
|
-
'intro',
|
|
33
|
-
'outro',
|
|
34
|
-
];
|
|
35
|
-
/**
|
|
36
|
-
* Names of all defined hooks. It's like
|
|
37
|
-
* ```js
|
|
38
|
-
* const DEFINED_HOOK_NAMES ={
|
|
39
|
-
* options: 'options',
|
|
40
|
-
* buildStart: 'buildStart',
|
|
41
|
-
* ...
|
|
42
|
-
* }
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export const DEFINED_HOOK_NAMES = {
|
|
46
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[0]]: ENUMERATED_PLUGIN_HOOK_NAMES[0],
|
|
47
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[1]]: ENUMERATED_PLUGIN_HOOK_NAMES[1],
|
|
48
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[2]]: ENUMERATED_PLUGIN_HOOK_NAMES[2],
|
|
49
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[3]]: ENUMERATED_PLUGIN_HOOK_NAMES[3],
|
|
50
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[4]]: ENUMERATED_PLUGIN_HOOK_NAMES[4],
|
|
51
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[5]]: ENUMERATED_PLUGIN_HOOK_NAMES[5],
|
|
52
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[6]]: ENUMERATED_PLUGIN_HOOK_NAMES[6],
|
|
53
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[7]]: ENUMERATED_PLUGIN_HOOK_NAMES[7],
|
|
54
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[8]]: ENUMERATED_PLUGIN_HOOK_NAMES[8],
|
|
55
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[9]]: ENUMERATED_PLUGIN_HOOK_NAMES[9],
|
|
56
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[10]]: ENUMERATED_PLUGIN_HOOK_NAMES[10],
|
|
57
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[11]]: ENUMERATED_PLUGIN_HOOK_NAMES[11],
|
|
58
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[12]]: ENUMERATED_PLUGIN_HOOK_NAMES[12],
|
|
59
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[13]]: ENUMERATED_PLUGIN_HOOK_NAMES[13],
|
|
60
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[14]]: ENUMERATED_PLUGIN_HOOK_NAMES[14],
|
|
61
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[15]]: ENUMERATED_PLUGIN_HOOK_NAMES[15],
|
|
62
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[16]]: ENUMERATED_PLUGIN_HOOK_NAMES[16],
|
|
63
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[17]]: ENUMERATED_PLUGIN_HOOK_NAMES[17],
|
|
64
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[18]]: ENUMERATED_PLUGIN_HOOK_NAMES[18],
|
|
65
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[19]]: ENUMERATED_PLUGIN_HOOK_NAMES[19],
|
|
66
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[20]]: ENUMERATED_PLUGIN_HOOK_NAMES[20],
|
|
67
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[21]]: ENUMERATED_PLUGIN_HOOK_NAMES[21],
|
|
68
|
-
[ENUMERATED_PLUGIN_HOOK_NAMES[22]]: ENUMERATED_PLUGIN_HOOK_NAMES[22],
|
|
69
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { defineParallelPlugin } from './plugin/parallel-plugin';
|
|
2
|
-
export { experimental_scan as scan } from './api/experimental';
|
|
3
|
-
export { transform } from './binding';
|
|
4
|
-
export { composeJsPlugins as composePlugins } from './utils/compose-js-plugins';
|
|
5
|
-
// Builtin plugin factory
|
|
6
|
-
export { modulePreloadPolyfillPlugin, dynamicImportVarsPlugin, wasmHelperPlugin, wasmFallbackPlugin, importGlobPlugin, manifestPlugin, loadFallbackPlugin, jsonPlugin, buildImportAnalysisPlugin, viteResolvePlugin, moduleFederationPlugin, } from './builtin-plugin/constructors';
|
|
7
|
-
export { transformPlugin } from './builtin-plugin/transform-plugin';
|
|
8
|
-
export { replacePlugin } from './builtin-plugin/replace-plugin';
|
|
9
|
-
export { aliasPlugin } from './builtin-plugin/alias-plugin';
|
package/dist/types/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from './utils/define-config';
|
|
2
|
-
import { rolldown } from './api/rolldown';
|
|
3
|
-
import { watch } from './api/watch';
|
|
4
|
-
import { version } from '../package.json';
|
|
5
|
-
import { build } from './api/build';
|
|
6
|
-
export { defineConfig, rolldown, watch, build };
|
|
7
|
-
export const VERSION = version;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { noop } from '../utils/misc';
|
|
2
|
-
import { LOG_LEVEL_WARN, logLevelPriority, } from './logging';
|
|
3
|
-
import { logInvalidLogPosition } from './logs';
|
|
4
|
-
export const normalizeLog = (log) => typeof log === 'string'
|
|
5
|
-
? { message: log }
|
|
6
|
-
: typeof log === 'function'
|
|
7
|
-
? normalizeLog(log())
|
|
8
|
-
: log;
|
|
9
|
-
export function getLogHandler(level, code, logger, pluginName, logLevel) {
|
|
10
|
-
if (logLevelPriority[level] < logLevelPriority[logLevel]) {
|
|
11
|
-
return noop;
|
|
12
|
-
}
|
|
13
|
-
return (log, pos) => {
|
|
14
|
-
if (pos != null) {
|
|
15
|
-
logger(LOG_LEVEL_WARN, logInvalidLogPosition(pluginName));
|
|
16
|
-
}
|
|
17
|
-
log = normalizeLog(log);
|
|
18
|
-
if (log.code && !log.pluginCode) {
|
|
19
|
-
log.pluginCode = log.code;
|
|
20
|
-
}
|
|
21
|
-
log.code = code;
|
|
22
|
-
log.plugin = pluginName;
|
|
23
|
-
logger(level, log);
|
|
24
|
-
};
|
|
25
|
-
}
|
package/dist/types/log/logger.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARN, LOG_LEVEL_ERROR, logLevelPriority, } from './logging';
|
|
2
|
-
import { error } from './logs';
|
|
3
|
-
import { normalizeLog } from './logHandler';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { VERSION } from '..';
|
|
6
|
-
import { getSortedPlugins } from '../plugin/plugin-driver';
|
|
7
|
-
export function getLogger(plugins, onLog, logLevel) {
|
|
8
|
-
const minimalPriority = logLevelPriority[logLevel];
|
|
9
|
-
const logger = (level, log, skipped = new Set()) => {
|
|
10
|
-
const logPriority = logLevelPriority[level];
|
|
11
|
-
if (logPriority < minimalPriority) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
for (const plugin of getSortedPlugins('onLog', plugins)) {
|
|
15
|
-
if (skipped.has(plugin))
|
|
16
|
-
continue;
|
|
17
|
-
const { onLog: pluginOnLog } = plugin;
|
|
18
|
-
if (pluginOnLog) {
|
|
19
|
-
const getLogHandler = (level) => {
|
|
20
|
-
if (logLevelPriority[level] < minimalPriority) {
|
|
21
|
-
return () => { };
|
|
22
|
-
}
|
|
23
|
-
return (log) => logger(level, normalizeLog(log), new Set(skipped).add(plugin));
|
|
24
|
-
};
|
|
25
|
-
const handler = 'handler' in pluginOnLog ? pluginOnLog.handler : pluginOnLog;
|
|
26
|
-
if (handler.call({
|
|
27
|
-
debug: getLogHandler(LOG_LEVEL_DEBUG),
|
|
28
|
-
error: (log) => error(normalizeLog(log)),
|
|
29
|
-
info: getLogHandler(LOG_LEVEL_INFO),
|
|
30
|
-
meta: {
|
|
31
|
-
rollupVersion: '4.23.0',
|
|
32
|
-
rolldownVersion: VERSION,
|
|
33
|
-
watchMode: false,
|
|
34
|
-
},
|
|
35
|
-
warn: getLogHandler(LOG_LEVEL_WARN),
|
|
36
|
-
pluginName: plugin.name || 'unknown',
|
|
37
|
-
}, level, log) === false) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
onLog(level, log);
|
|
43
|
-
};
|
|
44
|
-
return logger;
|
|
45
|
-
}
|
|
46
|
-
export const getOnLog = (config, logLevel, printLog = defaultPrintLog) => {
|
|
47
|
-
const { onwarn, onLog } = config;
|
|
48
|
-
const defaultOnLog = getDefaultOnLog(printLog, onwarn);
|
|
49
|
-
if (onLog) {
|
|
50
|
-
const minimalPriority = logLevelPriority[logLevel];
|
|
51
|
-
return (level, log) => onLog(level, addLogToString(log), (level, handledLog) => {
|
|
52
|
-
if (level === LOG_LEVEL_ERROR) {
|
|
53
|
-
return error(normalizeLog(handledLog));
|
|
54
|
-
}
|
|
55
|
-
if (logLevelPriority[level] >= minimalPriority) {
|
|
56
|
-
defaultOnLog(level, normalizeLog(handledLog));
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return defaultOnLog;
|
|
61
|
-
};
|
|
62
|
-
const getDefaultOnLog = (printLog, onwarn) => onwarn
|
|
63
|
-
? (level, log) => {
|
|
64
|
-
if (level === LOG_LEVEL_WARN) {
|
|
65
|
-
onwarn(addLogToString(log), (warning) => printLog(LOG_LEVEL_WARN, normalizeLog(warning)));
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
printLog(level, log);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
: printLog;
|
|
72
|
-
const addLogToString = (log) => {
|
|
73
|
-
Object.defineProperty(log, 'toString', {
|
|
74
|
-
value: () => getExtendedLogMessage(log),
|
|
75
|
-
writable: true,
|
|
76
|
-
});
|
|
77
|
-
return log;
|
|
78
|
-
};
|
|
79
|
-
const defaultPrintLog = (level, log) => {
|
|
80
|
-
const message = getExtendedLogMessage(log);
|
|
81
|
-
switch (level) {
|
|
82
|
-
case LOG_LEVEL_WARN: {
|
|
83
|
-
return console.warn(message);
|
|
84
|
-
}
|
|
85
|
-
case LOG_LEVEL_DEBUG: {
|
|
86
|
-
return console.debug(message);
|
|
87
|
-
}
|
|
88
|
-
default: {
|
|
89
|
-
return console.info(message);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const getExtendedLogMessage = (log) => {
|
|
94
|
-
let prefix = '';
|
|
95
|
-
if (log.plugin) {
|
|
96
|
-
prefix += `(${log.plugin} plugin) `;
|
|
97
|
-
}
|
|
98
|
-
if (log.loc) {
|
|
99
|
-
prefix += `${relativeId(log.loc.file)} (${log.loc.line}:${log.loc.column}) `;
|
|
100
|
-
}
|
|
101
|
-
return prefix + log.message;
|
|
102
|
-
};
|
|
103
|
-
function relativeId(id) {
|
|
104
|
-
if (!path.isAbsolute(id))
|
|
105
|
-
return id;
|
|
106
|
-
return path.relative(path.resolve(), id);
|
|
107
|
-
}
|