rolldown 1.0.0-beta.4-commit.308f68b → 1.0.0-beta.40
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/bin/cli.mjs +2 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +579 -0
- package/dist/config.d.mts +10 -0
- package/dist/config.mjs +10 -0
- package/dist/experimental-index.d.mts +147 -0
- package/dist/experimental-index.mjs +216 -0
- package/dist/experimental-runtime-types.d.ts +71 -0
- package/dist/filter-index.d.mts +4 -0
- package/dist/filter-index.mjs +44 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +5 -0
- package/dist/parallel-plugin-worker.d.mts +1 -0
- package/dist/{esm/parallel-plugin-worker.mjs → parallel-plugin-worker.mjs} +8 -16
- package/dist/parallel-plugin.d.mts +14 -0
- package/dist/{esm/parallel-plugin.mjs → parallel-plugin.mjs} +0 -1
- package/dist/parse-ast-index.d.mts +8 -0
- package/dist/parse-ast-index.mjs +3 -0
- package/dist/shared/binding-BVXbXhPv.d.mts +1413 -0
- package/dist/shared/define-config-0kfJrpvQ.d.mts +1454 -0
- package/dist/shared/load-config-BJ274Wsp.mjs +117 -0
- package/dist/{esm/cli.mjs → shared/logger-CiCY7ucm.mjs} +107 -868
- package/dist/shared/misc-CQeo-AFx.mjs +22 -0
- package/dist/shared/parse-ast-index-C7EYXjEA.mjs +10974 -0
- package/dist/shared/{prompt-CxK9euq3.mjs → prompt-D2FxOcB5.mjs} +243 -245
- package/dist/shared/src-BH2eQDD9.mjs +4282 -0
- package/package.json +62 -76
- package/bin/cli.js +0 -2
- package/dist/cjs/cli.cjs +0 -1753
- package/dist/cjs/experimental-index.cjs +0 -85
- package/dist/cjs/index.cjs +0 -8
- package/dist/cjs/parallel-plugin-worker.cjs +0 -41
- package/dist/cjs/parallel-plugin.cjs +0 -9
- package/dist/cjs/parse-ast-index.cjs +0 -4
- package/dist/esm/experimental-index.mjs +0 -57
- package/dist/esm/index.mjs +0 -4
- package/dist/esm/parse-ast-index.mjs +0 -3
- package/dist/shared/chunk-qZFfknuJ.cjs +0 -40
- package/dist/shared/parse-ast-index-CyX8MVZE.mjs +0 -674
- package/dist/shared/parse-ast-index-D7XtMFo4.cjs +0 -719
- package/dist/shared/prompt-ZZScCEWI.cjs +0 -854
- package/dist/shared/src-DB6mZNTU.mjs +0 -2875
- package/dist/shared/src-y8hk77fd.cjs +0 -3056
- package/dist/types/api/build.d.ts +0 -18
- package/dist/types/api/experimental.d.ts +0 -7
- package/dist/types/api/rolldown/index.d.ts +0 -3
- package/dist/types/api/rolldown/rolldown-build.d.ts +0 -13
- package/dist/types/api/watch/index.d.ts +0 -3
- package/dist/types/api/watch/watch-emitter.d.ts +0 -31
- package/dist/types/api/watch/watcher.d.ts +0 -13
- package/dist/types/binding.d.ts +0 -1456
- package/dist/types/builtin-plugin/alias-plugin.d.ts +0 -10
- package/dist/types/builtin-plugin/constructors.d.ts +0 -21
- package/dist/types/builtin-plugin/replace-plugin.d.ts +0 -28
- package/dist/types/builtin-plugin/transform-plugin.d.ts +0 -9
- package/dist/types/builtin-plugin/utils.d.ts +0 -8
- package/dist/types/cli/arguments/alias.d.ts +0 -16
- package/dist/types/cli/arguments/index.d.ts +0 -15
- package/dist/types/cli/arguments/normalize.d.ts +0 -12
- package/dist/types/cli/arguments/utils.d.ts +0 -8
- package/dist/types/cli/colors.d.ts +0 -11
- package/dist/types/cli/commands/bundle.d.ts +0 -3
- package/dist/types/cli/commands/help.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -1
- package/dist/types/cli/load-config.d.ts +0 -5
- package/dist/types/cli/logger.d.ts +0 -5
- package/dist/types/constants/plugin-context.d.ts +0 -7
- package/dist/types/constants/plugin.d.ts +0 -45
- package/dist/types/experimental-index.d.ts +0 -9
- package/dist/types/index.d.ts +0 -30
- package/dist/types/log/log-handler.d.ts +0 -4
- package/dist/types/log/logger.d.ts +0 -6
- package/dist/types/log/logging.d.ts +0 -12
- package/dist/types/log/logs.d.ts +0 -18
- package/dist/types/options/generated/checks-options.d.ts +0 -57
- package/dist/types/options/input-options.d.ts +0 -177
- package/dist/types/options/normalized-input-options.d.ts +0 -18
- package/dist/types/options/normalized-output-options.d.ts +0 -70
- package/dist/types/options/output-options.d.ts +0 -182
- package/dist/types/options/watch-options.d.ts +0 -5
- package/dist/types/parallel-plugin-worker.d.ts +0 -1
- package/dist/types/parallel-plugin.d.ts +0 -1
- package/dist/types/parse-ast-index.d.ts +0 -5
- package/dist/types/plugin/bindingify-build-hooks.d.ts +0 -10
- package/dist/types/plugin/bindingify-hook-filter.d.ts +0 -7
- package/dist/types/plugin/bindingify-output-hooks.d.ts +0 -14
- package/dist/types/plugin/bindingify-plugin-hook-meta.d.ts +0 -8
- package/dist/types/plugin/bindingify-plugin.d.ts +0 -16
- package/dist/types/plugin/bindingify-watch-hooks.d.ts +0 -5
- package/dist/types/plugin/hook-filter.d.ts +0 -48
- package/dist/types/plugin/index.d.ts +0 -134
- package/dist/types/plugin/minimal-plugin-context.d.ts +0 -23
- package/dist/types/plugin/parallel-plugin-implementation.d.ts +0 -10
- package/dist/types/plugin/parallel-plugin.d.ts +0 -9
- package/dist/types/plugin/plugin-context-data.d.ts +0 -17
- package/dist/types/plugin/plugin-context.d.ts +0 -67
- package/dist/types/plugin/plugin-driver.d.ts +0 -8
- package/dist/types/plugin/transform-plugin-context.d.ts +0 -28
- package/dist/types/types/assert.d.ts +0 -14
- package/dist/types/types/config-export.d.ts +0 -5
- package/dist/types/types/misc.d.ts +0 -40
- package/dist/types/types/module-info.d.ts +0 -15
- package/dist/types/types/module-side-effects.d.ts +0 -12
- package/dist/types/types/output-bundle.d.ts +0 -4
- package/dist/types/types/rolldown-options.d.ts +0 -5
- package/dist/types/types/rolldown-output.d.ts +0 -66
- package/dist/types/types/schema.d.ts +0 -33
- package/dist/types/types/sourcemap.d.ts +0 -14
- package/dist/types/types/utils.d.ts +0 -13
- package/dist/types/utils/asset-source.d.ts +0 -4
- package/dist/types/utils/async-flatten.d.ts +0 -1
- package/dist/types/utils/bindingify-input-options.d.ts +0 -7
- package/dist/types/utils/bindingify-output-options.d.ts +0 -5
- package/dist/types/utils/code-frame.d.ts +0 -1
- package/dist/types/utils/compose-js-plugins.d.ts +0 -2
- package/dist/types/utils/create-bundler-option.d.ts +0 -11
- package/dist/types/utils/create-bundler.d.ts +0 -8
- package/dist/types/utils/define-config.d.ts +0 -5
- package/dist/types/utils/error.d.ts +0 -2
- package/dist/types/utils/initialize-parallel-plugins.d.ts +0 -19
- package/dist/types/utils/misc.d.ts +0 -6
- package/dist/types/utils/normalize-hook.d.ts +0 -7
- package/dist/types/utils/normalize-plugin-option.d.ts +0 -13
- package/dist/types/utils/normalize-string-or-regex.d.ts +0 -2
- package/dist/types/utils/plugin/index.d.ts +0 -2
- package/dist/types/utils/resolved-external.d.ts +0 -4
- package/dist/types/utils/transform-module-info.d.ts +0 -4
- package/dist/types/utils/transform-rendered-chunk.d.ts +0 -4
- package/dist/types/utils/transform-rendered-module.d.ts +0 -3
- package/dist/types/utils/transform-side-effects.d.ts +0 -3
- package/dist/types/utils/transform-sourcemap.d.ts +0 -3
- package/dist/types/utils/transform-to-rollup-output.d.ts +0 -11
- package/dist/types/utils/validator.d.ts +0 -6
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { rolldown } from "./src-BH2eQDD9.mjs";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { readdir } from "node:fs/promises";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
import { cwd } from "node:process";
|
|
7
|
+
|
|
8
|
+
//#region src/utils/load-config.ts
|
|
9
|
+
async function bundleTsConfig(configFile, isEsm) {
|
|
10
|
+
const dirnameVarName = "injected_original_dirname";
|
|
11
|
+
const filenameVarName = "injected_original_filename";
|
|
12
|
+
const importMetaUrlVarName = "injected_original_import_meta_url";
|
|
13
|
+
const bundle = await rolldown({
|
|
14
|
+
input: configFile,
|
|
15
|
+
platform: "node",
|
|
16
|
+
resolve: { mainFields: ["main"] },
|
|
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@][^:]/],
|
|
26
|
+
plugins: [{
|
|
27
|
+
name: "inject-file-scope-variables",
|
|
28
|
+
transform: {
|
|
29
|
+
filter: { id: /\.[cm]?[jt]s$/ },
|
|
30
|
+
async handler(code, id) {
|
|
31
|
+
return {
|
|
32
|
+
code: `const ${dirnameVarName} = ${JSON.stringify(path.dirname(id))};const ${filenameVarName} = ${JSON.stringify(id)};const ${importMetaUrlVarName} = ${JSON.stringify(pathToFileURL(id).href)};` + code,
|
|
33
|
+
map: null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}]
|
|
38
|
+
});
|
|
39
|
+
const outputDir = path.dirname(configFile);
|
|
40
|
+
const fileName = (await bundle.write({
|
|
41
|
+
dir: outputDir,
|
|
42
|
+
format: isEsm ? "esm" : "cjs",
|
|
43
|
+
sourcemap: "inline",
|
|
44
|
+
entryFileNames: `rolldown.config.[hash]${path.extname(configFile).replace("ts", "js")}`
|
|
45
|
+
})).output.find((chunk) => chunk.type === "chunk" && chunk.isEntry).fileName;
|
|
46
|
+
return path.join(outputDir, fileName);
|
|
47
|
+
}
|
|
48
|
+
const SUPPORTED_JS_CONFIG_FORMATS = [
|
|
49
|
+
".js",
|
|
50
|
+
".mjs",
|
|
51
|
+
".cjs"
|
|
52
|
+
];
|
|
53
|
+
const SUPPORTED_TS_CONFIG_FORMATS = [
|
|
54
|
+
".ts",
|
|
55
|
+
".mts",
|
|
56
|
+
".cts"
|
|
57
|
+
];
|
|
58
|
+
const SUPPORTED_CONFIG_FORMATS = [...SUPPORTED_JS_CONFIG_FORMATS, ...SUPPORTED_TS_CONFIG_FORMATS];
|
|
59
|
+
const DEFAULT_CONFIG_BASE = "rolldown.config";
|
|
60
|
+
async function findConfigFileNameInCwd() {
|
|
61
|
+
const filesInWorkingDirectory = new Set(await readdir(cwd()));
|
|
62
|
+
for (const extension of SUPPORTED_CONFIG_FORMATS) {
|
|
63
|
+
const fileName = `${DEFAULT_CONFIG_BASE}${extension}`;
|
|
64
|
+
if (filesInWorkingDirectory.has(fileName)) return fileName;
|
|
65
|
+
}
|
|
66
|
+
throw new Error("No `rolldown.config` configuration file found.");
|
|
67
|
+
}
|
|
68
|
+
async function loadTsConfig(configFile) {
|
|
69
|
+
const isEsm = isFilePathESM(configFile);
|
|
70
|
+
const file = await bundleTsConfig(configFile, isEsm);
|
|
71
|
+
try {
|
|
72
|
+
return (await import(pathToFileURL(file).href)).default;
|
|
73
|
+
} finally {
|
|
74
|
+
fs.unlink(file, () => {});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function isFilePathESM(filePath) {
|
|
78
|
+
if (/\.m[jt]s$/.test(filePath)) return true;
|
|
79
|
+
else if (/\.c[jt]s$/.test(filePath)) return false;
|
|
80
|
+
else {
|
|
81
|
+
const pkg = findNearestPackageData(path.dirname(filePath));
|
|
82
|
+
if (pkg) return pkg.type === "module";
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function findNearestPackageData(basedir) {
|
|
87
|
+
while (basedir) {
|
|
88
|
+
const pkgPath = path.join(basedir, "package.json");
|
|
89
|
+
if (tryStatSync(pkgPath)?.isFile()) try {
|
|
90
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
91
|
+
} catch {}
|
|
92
|
+
const nextBasedir = path.dirname(basedir);
|
|
93
|
+
if (nextBasedir === basedir) break;
|
|
94
|
+
basedir = nextBasedir;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
function tryStatSync(file) {
|
|
99
|
+
try {
|
|
100
|
+
return fs.statSync(file, { throwIfNoEntry: false });
|
|
101
|
+
} catch {}
|
|
102
|
+
}
|
|
103
|
+
async function loadConfig(configPath) {
|
|
104
|
+
const ext = path.extname(configPath = configPath || await findConfigFileNameInCwd());
|
|
105
|
+
try {
|
|
106
|
+
if (SUPPORTED_JS_CONFIG_FORMATS.includes(ext) || process.env.NODE_OPTIONS?.includes("--import=tsx") && SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) return (await import(pathToFileURL(configPath).href)).default;
|
|
107
|
+
else if (SUPPORTED_TS_CONFIG_FORMATS.includes(ext)) {
|
|
108
|
+
const rawConfigPath = path.resolve(configPath);
|
|
109
|
+
return await loadTsConfig(rawConfigPath);
|
|
110
|
+
} else throw new Error(`Unsupported config format. Expected: \`${SUPPORTED_CONFIG_FORMATS.join(",")}\` but got \`${ext}\``);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
throw new Error("Error happened while loading config.", { cause: err });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { loadConfig };
|