rolldown 1.0.0-beta.3-commit.306867e → 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-BGJCTYiA.mjs → src-Cis0qYEg.mjs} +33 -13
- package/dist/shared/{src-BL6ftzBh.cjs → src-Z84gVvFu.cjs} +33 -13
- 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 +2 -2
- package/dist/types/plugin/plugin-context-data.d.ts +2 -1
- package/package.json +14 -14
- 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,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
|
-
};
|
|
@@ -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
|
-
}
|