rolldown 1.0.0-beta.3-commit.306867e → 1.0.0-beta.3-commit.f65bde3
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 +2 -2
- package/dist/cjs/experimental-index.cjs +2 -2
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/parallel-plugin-worker.cjs +2 -2
- package/dist/cjs/parse-ast-index.cjs +1 -1
- package/dist/esm/cli.mjs +2 -2
- package/dist/esm/experimental-index.mjs +2 -2
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/parallel-plugin-worker.mjs +2 -2
- package/dist/esm/parse-ast-index.mjs +1 -1
- package/dist/shared/{binding-_xN4hdfO.mjs → binding-CFTx0Fs7.mjs} +3 -3
- package/dist/shared/{binding-B9_Bsc0_.cjs → binding-DTKqYZn-.cjs} +3 -3
- package/dist/shared/{src-BGJCTYiA.mjs → src-46qAwcxx.mjs} +54 -17
- package/dist/shared/{src-BL6ftzBh.cjs → src-CoQJ2u3O.cjs} +54 -17
- package/dist/types/binding.d.ts +7 -0
- package/dist/types/index.d.ts +4 -3
- package/dist/types/log/logging.d.ts +1 -0
- package/dist/types/options/input-options.d.ts +2 -2
- package/dist/types/plugin/index.d.ts +1 -0
- package/dist/types/plugin/plugin-context-data.d.ts +2 -1
- package/package.json +19 -19
- 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,13 +0,0 @@
|
|
|
1
|
-
import { createBundler } from '../utils/create-bundler';
|
|
2
|
-
import { handleOutputErrors } from '../utils/transform-to-rollup-output';
|
|
3
|
-
/**
|
|
4
|
-
* This is an experimental API. It's behavior may change in the future.
|
|
5
|
-
*
|
|
6
|
-
* Calling this API will only execute the scan stage of rolldown.
|
|
7
|
-
*/
|
|
8
|
-
export const experimental_scan = async (input) => {
|
|
9
|
-
const { bundler, stopWorkers } = await createBundler(input, {});
|
|
10
|
-
const output = await bundler.scan();
|
|
11
|
-
handleOutputErrors(output);
|
|
12
|
-
await stopWorkers?.();
|
|
13
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { PluginDriver } from '../../plugin/plugin-driver';
|
|
2
|
-
import { RolldownBuild } from './rolldown-build';
|
|
3
|
-
// `async` here is intentional to be compatible with `rollup.rollup`.
|
|
4
|
-
export const rolldown = async (input) => {
|
|
5
|
-
const inputOptions = await PluginDriver.callOptionsHook(input);
|
|
6
|
-
return new RolldownBuild(inputOptions);
|
|
7
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { transformToRollupOutput } from '../../utils/transform-to-rollup-output';
|
|
2
|
-
import { createBundler, } from '../../utils/create-bundler';
|
|
3
|
-
// @ts-expect-error TS2540: the polyfill of `asyncDispose`.
|
|
4
|
-
Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
|
|
5
|
-
export class RolldownBuild {
|
|
6
|
-
#inputOptions;
|
|
7
|
-
#bundler;
|
|
8
|
-
constructor(inputOptions) {
|
|
9
|
-
// TODO: Check if `inputOptions.output` is set. If so, throw an warning that it is ignored.
|
|
10
|
-
this.#inputOptions = inputOptions;
|
|
11
|
-
}
|
|
12
|
-
get closed() {
|
|
13
|
-
// If the bundler has not yet been created, it is not closed.
|
|
14
|
-
return this.#bundler ? this.#bundler.bundler.closed : false;
|
|
15
|
-
}
|
|
16
|
-
// Create bundler for each `bundle.write/generate`
|
|
17
|
-
async #getBundlerWithStopWorker(outputOptions) {
|
|
18
|
-
if (this.#bundler) {
|
|
19
|
-
this.#bundler.stopWorkers?.();
|
|
20
|
-
}
|
|
21
|
-
return (this.#bundler = await createBundler(this.#inputOptions, outputOptions));
|
|
22
|
-
}
|
|
23
|
-
async generate(outputOptions = {}) {
|
|
24
|
-
const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
|
|
25
|
-
const output = await bundler.generate();
|
|
26
|
-
return transformToRollupOutput(output);
|
|
27
|
-
}
|
|
28
|
-
async write(outputOptions = {}) {
|
|
29
|
-
const { bundler } = await this.#getBundlerWithStopWorker(outputOptions);
|
|
30
|
-
const output = await bundler.write();
|
|
31
|
-
return transformToRollupOutput(output);
|
|
32
|
-
}
|
|
33
|
-
async close() {
|
|
34
|
-
const { bundler, stopWorkers } = await this.#getBundlerWithStopWorker({});
|
|
35
|
-
await stopWorkers?.();
|
|
36
|
-
await bundler.close();
|
|
37
|
-
}
|
|
38
|
-
async [Symbol.asyncDispose]() {
|
|
39
|
-
await this.close();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function _assert() {
|
|
43
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { normalizeErrors } from '../../utils/error';
|
|
2
|
-
export class WatcherEmitter {
|
|
3
|
-
listeners = new Map();
|
|
4
|
-
timer;
|
|
5
|
-
constructor() {
|
|
6
|
-
// The rust side already create a thread for watcher, but it isn't at main thread.
|
|
7
|
-
// So here we need to avoid main process exit util the user call `watcher.close()`.
|
|
8
|
-
this.timer = setInterval(() => { }, 1e9 /* Low power usage */);
|
|
9
|
-
}
|
|
10
|
-
on(event, listener) {
|
|
11
|
-
const listeners = this.listeners.get(event);
|
|
12
|
-
if (listeners) {
|
|
13
|
-
listeners.push(listener);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
this.listeners.set(event, [listener]);
|
|
17
|
-
}
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
async onEvent(event) {
|
|
21
|
-
const listeners = this.listeners.get(event.eventKind());
|
|
22
|
-
if (listeners) {
|
|
23
|
-
switch (event.eventKind()) {
|
|
24
|
-
case 'close':
|
|
25
|
-
case 'restart':
|
|
26
|
-
for (const listener of listeners) {
|
|
27
|
-
await listener();
|
|
28
|
-
}
|
|
29
|
-
break;
|
|
30
|
-
case 'event':
|
|
31
|
-
for (const listener of listeners) {
|
|
32
|
-
const code = event.bundleEventKind();
|
|
33
|
-
switch (code) {
|
|
34
|
-
case 'BUNDLE_END':
|
|
35
|
-
const { duration, output } = event.bundleEndData();
|
|
36
|
-
await listener({
|
|
37
|
-
code: 'BUNDLE_END',
|
|
38
|
-
duration,
|
|
39
|
-
output: [output], // rolldown doesn't support arraying configure output
|
|
40
|
-
});
|
|
41
|
-
break;
|
|
42
|
-
case 'ERROR':
|
|
43
|
-
const errors = event.errors();
|
|
44
|
-
await listener({
|
|
45
|
-
code: 'ERROR',
|
|
46
|
-
error: normalizeErrors(errors),
|
|
47
|
-
});
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
await listener({ code });
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
break;
|
|
55
|
-
case 'change':
|
|
56
|
-
for (const listener of listeners) {
|
|
57
|
-
const { path, kind } = event.watchChangeData();
|
|
58
|
-
await listener(path, { event: kind });
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
default:
|
|
62
|
-
throw new Error(`Unknown event: ${event}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async close() {
|
|
67
|
-
clearInterval(this.timer);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { BindingWatcher } from '../../binding';
|
|
2
|
-
import { LOG_LEVEL_WARN } from '../../log/logging';
|
|
3
|
-
import { logMultiplyNotifyOption } from '../../log/logs';
|
|
4
|
-
import { PluginDriver } from '../../plugin/plugin-driver';
|
|
5
|
-
import { createBundlerOptions, } from '../../utils/create-bundler-option';
|
|
6
|
-
import { arraify } from '../../utils/misc';
|
|
7
|
-
export class Watcher {
|
|
8
|
-
closed;
|
|
9
|
-
inner;
|
|
10
|
-
emitter;
|
|
11
|
-
stopWorkers;
|
|
12
|
-
constructor(emitter, inner, stopWorkers) {
|
|
13
|
-
this.closed = false;
|
|
14
|
-
this.inner = inner;
|
|
15
|
-
this.emitter = emitter;
|
|
16
|
-
const originClose = emitter.close.bind(emitter);
|
|
17
|
-
emitter.close = async () => {
|
|
18
|
-
await this.close();
|
|
19
|
-
originClose();
|
|
20
|
-
};
|
|
21
|
-
this.stopWorkers = stopWorkers;
|
|
22
|
-
}
|
|
23
|
-
async close() {
|
|
24
|
-
if (this.closed)
|
|
25
|
-
return;
|
|
26
|
-
this.closed = true;
|
|
27
|
-
for (const stop of this.stopWorkers) {
|
|
28
|
-
await stop?.();
|
|
29
|
-
}
|
|
30
|
-
await this.inner.close();
|
|
31
|
-
}
|
|
32
|
-
start() {
|
|
33
|
-
// run first build after listener is attached
|
|
34
|
-
process.nextTick(() => this.inner.start(this.emitter.onEvent.bind(this.emitter)));
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export async function createWatcher(emitter, input) {
|
|
38
|
-
const options = arraify(input);
|
|
39
|
-
const bundlerOptions = await Promise.all(options
|
|
40
|
-
.map((option) => arraify(option.output || {}).map(async (output) => {
|
|
41
|
-
const inputOptions = await PluginDriver.callOptionsHook(option);
|
|
42
|
-
return createBundlerOptions(inputOptions, output);
|
|
43
|
-
}))
|
|
44
|
-
.flat());
|
|
45
|
-
const notifyOptions = getValidNotifyOption(bundlerOptions);
|
|
46
|
-
const bindingWatcher = new BindingWatcher(bundlerOptions.map((option) => option.bundlerOptions), notifyOptions);
|
|
47
|
-
const watcher = new Watcher(emitter, bindingWatcher, bundlerOptions.map((option) => option.stopWorkers));
|
|
48
|
-
watcher.start();
|
|
49
|
-
}
|
|
50
|
-
function getValidNotifyOption(bundlerOptions) {
|
|
51
|
-
let result;
|
|
52
|
-
for (const option of bundlerOptions) {
|
|
53
|
-
if (option.inputOptions.watch) {
|
|
54
|
-
const notifyOption = option.inputOptions.watch.notify;
|
|
55
|
-
if (notifyOption) {
|
|
56
|
-
if (result) {
|
|
57
|
-
option.onLog(LOG_LEVEL_WARN, logMultiplyNotifyOption());
|
|
58
|
-
return result;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
result = notifyOption;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { makeBuiltinPluginCallable } from './utils';
|
|
2
|
-
export class BuiltinPlugin {
|
|
3
|
-
name;
|
|
4
|
-
_options;
|
|
5
|
-
constructor(name,
|
|
6
|
-
// NOTE: has `_` to avoid conflict with `options` hook
|
|
7
|
-
_options) {
|
|
8
|
-
this.name = name;
|
|
9
|
-
this._options = _options;
|
|
10
|
-
this.name = name;
|
|
11
|
-
this._options = _options;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function modulePreloadPolyfillPlugin(config) {
|
|
15
|
-
return new BuiltinPlugin('builtin:module-preload-polyfill', config);
|
|
16
|
-
}
|
|
17
|
-
export function dynamicImportVarsPlugin() {
|
|
18
|
-
return new BuiltinPlugin('builtin:dynamic-import-vars');
|
|
19
|
-
}
|
|
20
|
-
export function importGlobPlugin(config) {
|
|
21
|
-
return new BuiltinPlugin('builtin:import-glob', config);
|
|
22
|
-
}
|
|
23
|
-
export function manifestPlugin(config) {
|
|
24
|
-
return new BuiltinPlugin('builtin:manifest', config);
|
|
25
|
-
}
|
|
26
|
-
export function wasmHelperPlugin() {
|
|
27
|
-
return new BuiltinPlugin('builtin:wasm-helper');
|
|
28
|
-
}
|
|
29
|
-
export function wasmFallbackPlugin() {
|
|
30
|
-
return new BuiltinPlugin('builtin:wasm-fallback');
|
|
31
|
-
}
|
|
32
|
-
export function loadFallbackPlugin() {
|
|
33
|
-
return new BuiltinPlugin('builtin:load-fallback');
|
|
34
|
-
}
|
|
35
|
-
export function jsonPlugin(config) {
|
|
36
|
-
return new BuiltinPlugin('builtin:json', config);
|
|
37
|
-
}
|
|
38
|
-
export function buildImportAnalysisPlugin(config) {
|
|
39
|
-
return new BuiltinPlugin('builtin:build-import-analysis', config);
|
|
40
|
-
}
|
|
41
|
-
export function viteResolvePlugin(config) {
|
|
42
|
-
const builtinPlugin = new BuiltinPlugin('builtin:vite-resolve', {
|
|
43
|
-
...config,
|
|
44
|
-
runtime: process.versions.deno
|
|
45
|
-
? 'deno'
|
|
46
|
-
: process.versions.bun
|
|
47
|
-
? 'bun'
|
|
48
|
-
: 'node',
|
|
49
|
-
});
|
|
50
|
-
return makeBuiltinPluginCallable(builtinPlugin);
|
|
51
|
-
}
|
|
52
|
-
export function moduleFederationPlugin(config) {
|
|
53
|
-
return new BuiltinPlugin('builtin:module-federation', {
|
|
54
|
-
...config,
|
|
55
|
-
remotes: config.remotes &&
|
|
56
|
-
Object.entries(config.remotes).map(([name, remote]) => {
|
|
57
|
-
if (typeof remote === 'string') {
|
|
58
|
-
const [entryGlobalName] = remote.split('@');
|
|
59
|
-
const entry = remote.replace(entryGlobalName + '@', '');
|
|
60
|
-
return { entry, name };
|
|
61
|
-
}
|
|
62
|
-
return {
|
|
63
|
-
...remote,
|
|
64
|
-
name: remote.name ?? name,
|
|
65
|
-
};
|
|
66
|
-
}),
|
|
67
|
-
});
|
|
68
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BuiltinPlugin } from './constructors';
|
|
2
|
-
/**
|
|
3
|
-
* Replaces targeted strings in files while bundling.
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* // Basic usage
|
|
7
|
-
* ```js
|
|
8
|
-
* replacePlugin({
|
|
9
|
-
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
10
|
-
* __buildDate__: () => JSON.stringify(new Date()),
|
|
11
|
-
* __buildVersion: 15
|
|
12
|
-
* })
|
|
13
|
-
* ```
|
|
14
|
-
* @example
|
|
15
|
-
* // With options
|
|
16
|
-
* ```js
|
|
17
|
-
* replacePlugin({
|
|
18
|
-
* 'process.env.NODE_ENV': JSON.stringify('production'),
|
|
19
|
-
* __buildDate__: () => JSON.stringify(new Date()),
|
|
20
|
-
* __buildVersion: 15
|
|
21
|
-
* }, {
|
|
22
|
-
* preventAssignment: false,
|
|
23
|
-
* })
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
*/
|
|
27
|
-
export function replacePlugin(values = {}, options = {}) {
|
|
28
|
-
return new BuiltinPlugin('builtin:replace', { ...options, values });
|
|
29
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BuiltinPlugin } from './constructors';
|
|
2
|
-
import { normalizedStringOrRegex } from '../utils/normalize-string-or-regex';
|
|
3
|
-
function normalizeEcmaTransformPluginConfig(config) {
|
|
4
|
-
if (!config) {
|
|
5
|
-
return undefined;
|
|
6
|
-
}
|
|
7
|
-
let normalizedConfig = {
|
|
8
|
-
...config,
|
|
9
|
-
exclude: normalizedStringOrRegex(config.exclude),
|
|
10
|
-
include: normalizedStringOrRegex(config.include),
|
|
11
|
-
};
|
|
12
|
-
return normalizedConfig;
|
|
13
|
-
}
|
|
14
|
-
export function transformPlugin(config) {
|
|
15
|
-
return new BuiltinPlugin('builtin:transform', normalizeEcmaTransformPluginConfig(config));
|
|
16
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BindingCallableBuiltinPlugin } from '../binding';
|
|
2
|
-
export function makeBuiltinPluginCallable(plugin) {
|
|
3
|
-
let callablePlugin = new BindingCallableBuiltinPlugin(bindingifyBuiltInPlugin(plugin));
|
|
4
|
-
const wrappedPlugin = plugin;
|
|
5
|
-
for (const key in callablePlugin) {
|
|
6
|
-
// @ts-expect-error
|
|
7
|
-
wrappedPlugin[key] = function (...args) {
|
|
8
|
-
// @ts-expect-error
|
|
9
|
-
return callablePlugin[key](...args);
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
return wrappedPlugin;
|
|
13
|
-
}
|
|
14
|
-
export function bindingifyBuiltInPlugin(plugin) {
|
|
15
|
-
return {
|
|
16
|
-
__name: plugin.name,
|
|
17
|
-
options: plugin._options,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export const alias = {
|
|
2
|
-
config: {
|
|
3
|
-
abbreviation: 'c',
|
|
4
|
-
hint: 'filename',
|
|
5
|
-
},
|
|
6
|
-
help: {
|
|
7
|
-
abbreviation: 'h',
|
|
8
|
-
},
|
|
9
|
-
version: {
|
|
10
|
-
abbreviation: 'v',
|
|
11
|
-
},
|
|
12
|
-
watch: {
|
|
13
|
-
abbreviation: 'w',
|
|
14
|
-
},
|
|
15
|
-
dir: {
|
|
16
|
-
abbreviation: 'd',
|
|
17
|
-
},
|
|
18
|
-
file: {
|
|
19
|
-
abbreviation: 'o',
|
|
20
|
-
},
|
|
21
|
-
external: {
|
|
22
|
-
abbreviation: 'e',
|
|
23
|
-
},
|
|
24
|
-
format: {
|
|
25
|
-
abbreviation: 'f',
|
|
26
|
-
},
|
|
27
|
-
name: {
|
|
28
|
-
abbreviation: 'n',
|
|
29
|
-
},
|
|
30
|
-
globals: {
|
|
31
|
-
abbreviation: 'g',
|
|
32
|
-
},
|
|
33
|
-
sourcemap: {
|
|
34
|
-
abbreviation: 's',
|
|
35
|
-
default: true,
|
|
36
|
-
},
|
|
37
|
-
minify: {
|
|
38
|
-
abbreviation: 'm',
|
|
39
|
-
},
|
|
40
|
-
platform: {
|
|
41
|
-
abbreviation: 'p',
|
|
42
|
-
},
|
|
43
|
-
assetFileNames: {
|
|
44
|
-
hint: 'name',
|
|
45
|
-
},
|
|
46
|
-
chunkFileNames: {
|
|
47
|
-
hint: 'name',
|
|
48
|
-
},
|
|
49
|
-
entryFileNames: {
|
|
50
|
-
hint: 'name',
|
|
51
|
-
},
|
|
52
|
-
externalLiveBindings: {
|
|
53
|
-
default: true,
|
|
54
|
-
reverse: true,
|
|
55
|
-
},
|
|
56
|
-
treeshake: {
|
|
57
|
-
default: true,
|
|
58
|
-
reverse: true,
|
|
59
|
-
},
|
|
60
|
-
moduleTypes: {
|
|
61
|
-
hint: 'types',
|
|
62
|
-
},
|
|
63
|
-
};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { alias } from './alias';
|
|
2
|
-
import { camelCaseToKebabCase, flattenSchema, getSchemaType, kebabCaseToCamelCase, } from './utils';
|
|
3
|
-
import { parseArgs } from 'node:util';
|
|
4
|
-
import { normalizeCliOptions } from './normalize';
|
|
5
|
-
import { logger } from '../logger';
|
|
6
|
-
import { getJsonSchema } from '../../utils/validator';
|
|
7
|
-
const objectSchema = getJsonSchema();
|
|
8
|
-
export const flattenedSchema = flattenSchema(objectSchema.properties);
|
|
9
|
-
export const options = Object.fromEntries(Object.entries(flattenedSchema).map(([key, schema]) => {
|
|
10
|
-
const config = Object.getOwnPropertyDescriptor(alias, key)?.value;
|
|
11
|
-
const type = getSchemaType(schema);
|
|
12
|
-
const result = {
|
|
13
|
-
type: type === 'boolean' ? 'boolean' : 'string',
|
|
14
|
-
// We only support comma separated mode right now.
|
|
15
|
-
// multiple: type === 'object' || type === 'array',
|
|
16
|
-
description: schema?.description ?? config?.description ?? '',
|
|
17
|
-
hint: config?.hint,
|
|
18
|
-
};
|
|
19
|
-
if (config && config?.abbreviation) {
|
|
20
|
-
result.short = config?.abbreviation;
|
|
21
|
-
}
|
|
22
|
-
if (config && config.reverse) {
|
|
23
|
-
if (result.description.startsWith('enable')) {
|
|
24
|
-
result.description = result.description.replace('enable', 'disable');
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
result.description = `disable ${result.description}`;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
key = camelCaseToKebabCase(key);
|
|
31
|
-
// add 'no-' prefix for need reverse options
|
|
32
|
-
return [config?.reverse ? `no-${key}` : key, result];
|
|
33
|
-
}));
|
|
34
|
-
export function parseCliArguments() {
|
|
35
|
-
const { values, tokens, positionals } = parseArgs({
|
|
36
|
-
options,
|
|
37
|
-
tokens: true,
|
|
38
|
-
allowPositionals: true,
|
|
39
|
-
// We can't use `strict` mode because we should handle the default config file name.
|
|
40
|
-
strict: false,
|
|
41
|
-
});
|
|
42
|
-
tokens
|
|
43
|
-
.filter((token) => token.kind === 'option')
|
|
44
|
-
.forEach((option) => {
|
|
45
|
-
let negative = false;
|
|
46
|
-
if (option.name.startsWith('no-')) {
|
|
47
|
-
// stripe `no-` prefix
|
|
48
|
-
const name = kebabCaseToCamelCase(option.name.substring(3));
|
|
49
|
-
if (name in flattenedSchema) {
|
|
50
|
-
// Remove the `no-` in values
|
|
51
|
-
delete values[option.name];
|
|
52
|
-
option.name = name;
|
|
53
|
-
negative = true;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
delete values[option.name]; // Strip the kebab-case options.
|
|
57
|
-
option.name = kebabCaseToCamelCase(option.name);
|
|
58
|
-
let originalType = flattenedSchema[option.name];
|
|
59
|
-
if (!originalType) {
|
|
60
|
-
logger.error(`Invalid option: ${option.rawName}. We will ignore this option.`);
|
|
61
|
-
// We will refuse to handle the invalid option, as it may cause unexpected behavior.
|
|
62
|
-
process.exit(1);
|
|
63
|
-
}
|
|
64
|
-
let type = getSchemaType(originalType);
|
|
65
|
-
if (type === 'string' && typeof option.value !== 'string') {
|
|
66
|
-
let opt = option;
|
|
67
|
-
// We should use the default value.
|
|
68
|
-
let defaultValue = Object.getOwnPropertyDescriptor(alias, opt.name)
|
|
69
|
-
?.value;
|
|
70
|
-
Object.defineProperty(values, opt.name, {
|
|
71
|
-
value: defaultValue.default ?? '',
|
|
72
|
-
enumerable: true,
|
|
73
|
-
configurable: true,
|
|
74
|
-
writable: true,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
else if (type === 'object' && typeof option.value === 'string') {
|
|
78
|
-
const [key, value] = option.value.split(',').map((x) => x.split('='))[0];
|
|
79
|
-
if (!values[option.name]) {
|
|
80
|
-
Object.defineProperty(values, option.name, {
|
|
81
|
-
value: {},
|
|
82
|
-
enumerable: true,
|
|
83
|
-
configurable: true,
|
|
84
|
-
writable: true,
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
if (key && value) {
|
|
88
|
-
// TODO support multiple entries.
|
|
89
|
-
Object.defineProperty(values[option.name], key, {
|
|
90
|
-
value,
|
|
91
|
-
enumerable: true,
|
|
92
|
-
configurable: true,
|
|
93
|
-
writable: true,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else if (type === 'array' && typeof option.value === 'string') {
|
|
98
|
-
if (!values[option.name]) {
|
|
99
|
-
Object.defineProperty(values, option.name, {
|
|
100
|
-
value: [],
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true,
|
|
103
|
-
writable: true,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
;
|
|
107
|
-
values[option.name].push(option.value);
|
|
108
|
-
}
|
|
109
|
-
else if (type === 'boolean') {
|
|
110
|
-
Object.defineProperty(values, option.name, {
|
|
111
|
-
value: !negative,
|
|
112
|
-
enumerable: true,
|
|
113
|
-
configurable: true,
|
|
114
|
-
writable: true,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
Object.defineProperty(values, option.name, {
|
|
119
|
-
value: option.value ?? '',
|
|
120
|
-
enumerable: true,
|
|
121
|
-
configurable: true,
|
|
122
|
-
writable: true,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
return normalizeCliOptions(values, positionals);
|
|
127
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description This file is used for normalize the options.
|
|
3
|
-
* In CLI, the input options and output options are mixed together. We need to tell them apart.
|
|
4
|
-
*/
|
|
5
|
-
import { logger } from '../logger';
|
|
6
|
-
import { setNestedProperty } from './utils';
|
|
7
|
-
import { getInputCliKeys, getOutputCliKeys, validateCliOptions, } from '../../utils/validator';
|
|
8
|
-
export function normalizeCliOptions(cliOptions, positionals) {
|
|
9
|
-
const [data, errors] = validateCliOptions(cliOptions);
|
|
10
|
-
if (errors?.length) {
|
|
11
|
-
errors.forEach((error) => {
|
|
12
|
-
logger.error(`Invalid value for option ${error}. You can use \`rolldown -h\` to see the help.`);
|
|
13
|
-
});
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
const options = data ?? {};
|
|
17
|
-
const result = {
|
|
18
|
-
input: {},
|
|
19
|
-
output: {},
|
|
20
|
-
help: options.help ?? false,
|
|
21
|
-
version: options.version ?? false,
|
|
22
|
-
watch: options.watch ?? false,
|
|
23
|
-
};
|
|
24
|
-
if (typeof options.config === 'string') {
|
|
25
|
-
result.config = options.config;
|
|
26
|
-
}
|
|
27
|
-
const keysOfInput = getInputCliKeys();
|
|
28
|
-
const keysOfOutput = getOutputCliKeys();
|
|
29
|
-
const reservedKeys = ['help', 'version', 'config', 'watch'];
|
|
30
|
-
for (let [key, value] of Object.entries(options)) {
|
|
31
|
-
const keys = key.split('.');
|
|
32
|
-
const [primary] = keys;
|
|
33
|
-
if (keysOfInput.includes(primary)) {
|
|
34
|
-
setNestedProperty(result.input, key, value);
|
|
35
|
-
}
|
|
36
|
-
else if (keysOfOutput.includes(primary)) {
|
|
37
|
-
setNestedProperty(result.output, key, value);
|
|
38
|
-
}
|
|
39
|
-
else if (!reservedKeys.includes(key)) {
|
|
40
|
-
logger.error(`Unknown option: ${key}`);
|
|
41
|
-
process.exit(1);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (!result.config && positionals.length > 0) {
|
|
45
|
-
result.input.input = positionals;
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const priority = [
|
|
2
|
-
'object',
|
|
3
|
-
'array',
|
|
4
|
-
'string',
|
|
5
|
-
'number',
|
|
6
|
-
'boolean',
|
|
7
|
-
];
|
|
8
|
-
export function getSchemaType(schema) {
|
|
9
|
-
if ('anyOf' in schema) {
|
|
10
|
-
const types = schema.anyOf.map(getSchemaType);
|
|
11
|
-
// Order: object > array > string > number > boolean
|
|
12
|
-
let result = priority.find((type) => types.includes(type));
|
|
13
|
-
if (result) {
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if ('type' in schema) {
|
|
18
|
-
return schema.type;
|
|
19
|
-
}
|
|
20
|
-
if ('const' in schema) {
|
|
21
|
-
return typeof schema.const;
|
|
22
|
-
}
|
|
23
|
-
return 'object';
|
|
24
|
-
}
|
|
25
|
-
export function flattenSchema(schema, base = {}, parent = '') {
|
|
26
|
-
if (schema === undefined) {
|
|
27
|
-
return base;
|
|
28
|
-
}
|
|
29
|
-
for (const [k, value] of Object.entries(schema)) {
|
|
30
|
-
const key = parent ? `${parent}.${k}` : k;
|
|
31
|
-
if (getSchemaType(value) === 'object') {
|
|
32
|
-
if ('properties' in value) {
|
|
33
|
-
flattenSchema(value.properties, base, key);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
base[key] = value;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
base[key] = value;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return base;
|
|
44
|
-
}
|
|
45
|
-
export function setNestedProperty(obj, path, value) {
|
|
46
|
-
const keys = path.split('.');
|
|
47
|
-
let current = obj;
|
|
48
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
49
|
-
if (!current[keys[i]]) {
|
|
50
|
-
current[keys[i]] = {};
|
|
51
|
-
}
|
|
52
|
-
current = current[keys[i]];
|
|
53
|
-
}
|
|
54
|
-
const finalKey = keys[keys.length - 1];
|
|
55
|
-
Object.defineProperty(current, finalKey, {
|
|
56
|
-
value: value,
|
|
57
|
-
writable: true,
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
export function camelCaseToKebabCase(str) {
|
|
63
|
-
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
64
|
-
}
|
|
65
|
-
export function kebabCaseToCamelCase(str) {
|
|
66
|
-
return str.replace(/-./g, (match) => match[1].toUpperCase());
|
|
67
|
-
}
|
package/dist/types/cli/colors.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { env } from 'node:process';
|
|
2
|
-
import { createColors } from 'colorette';
|
|
3
|
-
// @see https://no-color.org
|
|
4
|
-
// @see https://www.npmjs.com/package/chalk
|
|
5
|
-
const { bold, cyan, dim, gray, green, red, underline, yellow, } = createColors({
|
|
6
|
-
useColor: env.FORCE_COLOR !== '0' && !env.NO_COLOR,
|
|
7
|
-
});
|
|
8
|
-
export const colors = {
|
|
9
|
-
bold,
|
|
10
|
-
cyan,
|
|
11
|
-
dim,
|
|
12
|
-
gray,
|
|
13
|
-
green,
|
|
14
|
-
red,
|
|
15
|
-
underline,
|
|
16
|
-
yellow,
|
|
17
|
-
};
|